1 <% include( 'elements/search.html',
2 'title' => 'Discounts',
5 'count_query' => $count_query,
6 'count_addl' => [ $money_char. '%.2f total', ],
15 FS::UI::Web::cust_header(),
18 #'billpkgdiscountnum',
19 sub { $_[0]->cust_pkg_discount->discount->description },
20 sub { sprintf($money_char.'%.2f', shift->amount ) },
21 sub { my $m = shift->months;
22 $m =~ /\./ ? sprintf('%.2f', $m) : $m;
24 'pkg',#sub { $_[0]->cust_bill_pkg->cust_pkg->part_pkg->pkg },
26 sub { time2str('%b %d %Y', shift->_date ) },
27 \&FS::UI::Web::cust_fields,
39 '', #link to customer discount???
45 ( map { $_ ne 'Cust. Status' ? $clink : '' }
46 FS::UI::Web::cust_header()
49 #'align' => 'rlrrrc'.FS::UI::Web::cust_aligns(),
50 'align' => 'lrrlrr'.FS::UI::Web::cust_aligns(),
59 FS::UI::Web::cust_colors(),
69 FS::UI::Web::cust_styles(),
75 #a little false laziness below w/cust_bill_pkg.cgi
78 unless $FS::CurrentUser::CurrentUser->access_right('Financial reports');
80 my $conf = new FS::Conf;
82 #here is the agent virtualization
84 $FS::CurrentUser::CurrentUser->agentnums_sql( 'table' => 'cust_main' );
86 my @where = ( $agentnums_sql );
88 my($beginning, $ending) = FS::UI::Web::parse_beginning_ending($cgi);
89 push @where, "_date >= $beginning",
92 if ( $cgi->param('agentnum') =~ /^(\d+)$/ ) {
93 push @where, "cust_main.agentnum = $1";
97 if ( $cgi->param('usernum') =~ /^(\d+)$/ ) {
98 push @where, "cust_pkg_discount.usernum = $1";
102 # # not specified: all classes
105 # my $use_override = $cgi->param('use_override');
106 # if ( $cgi->param('classnum') =~ /^(\d+)$/ ) {
107 # my $comparison = '';
109 # $comparison = "IS NULL";
111 # $comparison = "= $1";
114 # if ( $use_override ) {
116 # part_pkg.classnum $comparison AND pkgpart_override IS NULL OR
117 # override.classnum $comparison AND pkgpart_override IS NOT NULL
120 # push @where, "part_pkg.classnum $comparison";
124 my $count_query = "SELECT COUNT(*), SUM(amount)";
126 my $join_cust_pkg_discount =
127 'LEFT JOIN cust_pkg_discount USING (pkgdiscountnum)';
130 ' JOIN cust_bill_pkg USING ( billpkgnum )
131 JOIN cust_bill USING ( invnum )
132 LEFT JOIN cust_main USING ( custnum ) ';
135 ' LEFT JOIN cust_pkg ON ( cust_bill_pkg.pkgnum = cust_pkg.pkgnum )
136 LEFT JOIN part_pkg USING ( pkgpart ) ';
137 #LEFT JOIN part_pkg AS override
138 # ON pkgpart_override = override.pkgpart ';
140 my $where = ' WHERE '. join(' AND ', @where);
143 " FROM cust_bill_pkg_discount $join_cust_pkg_discount $join_cust $join_pkg ".
147 'cust_bill_pkg_discount.*',
152 push @select, 'part_pkg.pkg';
153 push @select, 'cust_main.custnum',
154 FS::UI::Web::cust_sql_fields();
157 'table' => 'cust_bill_pkg_discount',
158 'addl_from' => "$join_cust_pkg_discount $join_cust $join_pkg",
160 'select' => join(', ', @select ),
161 'extra_sql' => $where,
162 'order_by' => 'ORDER BY _date, billpkgdiscountnum',
165 my $ilink = [ "${p}view/cust_bill.cgi?", 'invnum' ];
166 my $clink = [ "${p}view/cust_main.cgi?", 'custnum' ];
168 my $conf = new FS::Conf;
169 my $money_char = $conf->config('money_char') || '$';