1 <& elements/search.html,
2 'title' => 'Package discounts',
5 'count_query' => $count_query,
7 'header' => [ 'Status',
13 FS::UI::Web::cust_header(
14 # $cgi->param('cust_fields')
18 sub { ucfirst( shift->status ) },
19 sub { shift->discount->description },
20 sub { shift->discount->classname },
21 sub { my $m = shift->months_used;
22 $m =~ /\./ ? sprintf('%.2f',$m) : $m;
26 \&FS::UI::Web::cust_fields,
35 ( map { $_ ne 'Cust. Status' ? $clink : ''}
36 FS::UI::Web::cust_header()
39 'align' => 'clcrll'. FS::UI::Web::cust_aligns(),
47 FS::UI::Web::cust_colors(),
56 FS::UI::Web::cust_styles(),
63 unless $FS::CurrentUser::CurrentUser->access_right('Financial reports');
65 #my $conf = new FS::Conf;
67 #here is the agent virtualization
69 $FS::CurrentUser::CurrentUser->agentnums_sql( 'table' => 'cust_main' );
71 my @where = ( $agentnums_sql );
74 if ( $cgi->param('status') eq 'active' ) {
75 push @where, " ( cust_pkg_discount.disabled IS NULL
76 OR cust_pkg_discount.disabled != 'Y' )
77 AND ( months IS NULL OR months_used < months ) ";
79 } elsif ( $cgi->param('status') eq 'expired' ) {
80 push @where, " ( cust_pkg_discount.disabled IS NOT NULL
81 AND cust_pkg_discount.disabled = 'Y' )
82 OR ( months IS NOT NULL AND months_used >= months )
87 #false laziness w/cust_pkg.pm::search
88 if ( grep { $_ eq 'classnum' } $cgi->param ) {
91 # if ( ref($params->{'classnum'}) ) {
93 # if ( ref($params->{'classnum'}) eq 'HASH' ) {
94 # @classnum = grep $params->{'classnum'}{$_}, keys %{ $params->{'classnum'} };
95 # } elsif ( ref($params->{'classnum'}) eq 'ARRAY' ) {
96 # @classnum = @{ $params->{'classnum'} };
98 # die 'unhandled classnum ref '. $params->{'classnum'};
102 # } elsif ( $params->{'classnum'} =~ /^(\d*)$/ && $1 ne '0' ) {
103 # @classnum = ( $1 );
108 if ( $cgi->param('classnum') =~ /^(\d*)$/ && $1 ne '0' ) {
109 my @classnum = ( $1 );
112 my @nums = grep $_, @classnum;
113 push @c_where, 'discount.classnum IN ('. join(',',@nums). ')' if @nums;
114 my $null = scalar( grep { $_ eq '' } @classnum );
115 push @c_where, 'discount.classnum IS NULL' if $null;
117 if ( scalar(@c_where) == 1 ) {
118 push @where, @c_where;
119 } elsif ( @c_where ) {
120 push @where, ' ( '. join(' OR ', @c_where). ' ) ';
128 if ( $cgi->param('usernum') =~ /^(\d+)$/ ) {
129 push @where, "cust_pkg_discount.usernum = $1";
133 if ( $cgi->param('agentnum') =~ /^(\d+)$/ ) {
134 push @where, "cust_main.agentnum = $1";
137 my $count_query = "SELECT COUNT(*), SUM(amount)";
139 my $join = ' LEFT JOIN discount USING ( discountnum )
140 LEFT JOIN cust_pkg USING ( pkgnum )
141 LEFT JOIN part_pkg USING ( pkgpart ) '.
142 FS::UI::Web::join_cust_main('cust_pkg', 'cust_pkg');
144 my $where = ' WHERE '. join(' AND ', @where);
146 $count_query .= " FROM cust_pkg_discount $join $where";
149 'cust_pkg_discount.*',
152 push @select, 'cust_main.custnum',
153 FS::UI::Web::cust_sql_fields();
156 'table' => 'cust_pkg_discount',
157 'addl_from' => $join,
159 'select' => join(', ', @select ),
160 'extra_sql' => $where,
161 'order_by' => 'ORDER BY pkgdiscountnum',
164 my $clink = [ "${p}view/cust_main.cgi?", 'custnum' ];
166 my $conf = new FS::Conf;