1 <& elements/search.html,
2 'title' => 'Package discounts',
5 'count_query' => $count_query,
7 'header' => [ 'Status',
12 FS::UI::Web::cust_header(
13 # $cgi->param('cust_fields')
17 sub { ucfirst( shift->status ) },
18 sub { shift->discount->description },
19 sub { my $m = shift->months_used;
20 $m =~ /\./ ? sprintf('%.2f',$m) : $m;
24 \&FS::UI::Web::cust_fields,
32 ( map { $_ ne 'Cust. Status' ? $clink : ''}
33 FS::UI::Web::cust_header()
36 'align' => 'clrll'. FS::UI::Web::cust_aligns(),
43 FS::UI::Web::cust_colors(),
51 FS::UI::Web::cust_styles(),
58 unless $FS::CurrentUser::CurrentUser->access_right('Financial reports');
60 #my $conf = new FS::Conf;
62 #here is the agent virtualization
64 $FS::CurrentUser::CurrentUser->agentnums_sql( 'table' => 'cust_main' );
66 my @where = ( $agentnums_sql );
69 if ( $cgi->param('status') eq 'active' ) {
70 push @where, " ( cust_pkg_discount.disabled IS NULL
71 OR cust_pkg_discount.disabled != 'Y' )
72 AND ( months IS NULL OR months_used < months ) ";
74 } elsif ( $cgi->param('status') eq 'expired' ) {
75 push @where, " ( cust_pkg_discount.disabled IS NOT NULL
76 AND cust_pkg_discount.disabled = 'Y' )
77 OR ( months IS NOT NULL AND months_used >= months )
82 if ( $cgi->param('usernum') =~ /^(\d+)$/ ) {
83 push @where, "cust_pkg_discount.usernum = $1";
87 if ( $cgi->param('agentnum') =~ /^(\d+)$/ ) {
88 push @where, "cust_main.agentnum = $1";
91 my $count_query = "SELECT COUNT(*), SUM(amount)";
93 my $join = ' LEFT JOIN discount USING ( discountnum )
94 LEFT JOIN cust_pkg USING ( pkgnum )
95 LEFT JOIN part_pkg USING ( pkgpart )
96 LEFT JOIN cust_main USING ( custnum ) ';
98 my $where = ' WHERE '. join(' AND ', @where);
100 $count_query .= " FROM cust_pkg_discount $join $where";
103 'cust_pkg_discount.*',
106 push @select, 'cust_main.custnum',
107 FS::UI::Web::cust_sql_fields();
110 'table' => 'cust_pkg_discount',
111 'addl_from' => $join,
113 'select' => join(', ', @select ),
114 'extra_sql' => $where,
115 'order_by' => 'ORDER BY pkgdiscountnum',
118 my $clink = [ "${p}view/cust_main.cgi?", 'custnum' ];
120 my $conf = new FS::Conf;