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,
31 '', #link to customer discount???
37 ( map { $_ ne 'Cust. Status' ? $clink : '' }
38 FS::UI::Web::cust_header()
41 #'align' => 'rlrrrc'.FS::UI::Web::cust_aligns(),
42 'align' => 'lrrlrr'.FS::UI::Web::cust_aligns(),
51 FS::UI::Web::cust_colors(),
61 FS::UI::Web::cust_styles(),
67 #a little false laziness below w/cust_bill_pkg.cgi
70 unless $FS::CurrentUser::CurrentUser->access_right('Financial reports');
72 my $conf = new FS::Conf;
74 #here is the agent virtualization
76 $FS::CurrentUser::CurrentUser->agentnums_sql( 'table' => 'cust_main' );
78 my @where = ( $agentnums_sql );
80 my($beginning, $ending) = FS::UI::Web::parse_beginning_ending($cgi);
81 push @where, "_date >= $beginning",
84 if ( $cgi->param('agentnum') =~ /^(\d+)$/ ) {
85 push @where, "cust_main.agentnum = $1";
89 # # not specified: all classes
92 # my $use_override = $cgi->param('use_override');
93 # if ( $cgi->param('classnum') =~ /^(\d+)$/ ) {
94 # my $comparison = '';
96 # $comparison = "IS NULL";
98 # $comparison = "= $1";
101 # if ( $use_override ) {
103 # part_pkg.classnum $comparison AND pkgpart_override IS NULL OR
104 # override.classnum $comparison AND pkgpart_override IS NOT NULL
107 # push @where, "part_pkg.classnum $comparison";
111 my $count_query = "SELECT COUNT(*), SUM(amount)";
113 my $join_cust = ' JOIN cust_bill_pkg USING ( billpkgnum )
114 JOIN cust_bill USING ( invnum )
115 LEFT JOIN cust_main USING ( custnum ) ';
117 my $join_pkg = ' LEFT JOIN cust_pkg USING ( pkgnum )
118 LEFT JOIN part_pkg USING ( pkgpart ) ';
119 #LEFT JOIN part_pkg AS override
120 # ON pkgpart_override = override.pkgpart ';
122 my $where = ' WHERE '. join(' AND ', @where);
124 $count_query .= " FROM cust_bill_pkg_discount $join_cust $join_pkg $where";
127 'cust_bill_pkg_discount.*',
132 push @select, 'part_pkg.pkg';
133 push @select, 'cust_main.custnum',
134 FS::UI::Web::cust_sql_fields();
137 'table' => 'cust_bill_pkg_discount',
138 'addl_from' => "$join_cust $join_pkg",
140 'select' => join(', ', @select ),
141 'extra_sql' => $where,
142 'order_by' => 'ORDER BY _date, billpkgdiscountnum',
145 my $ilink = [ "${p}view/cust_bill.cgi?", 'invnum' ];
146 my $clink = [ "${p}view/cust_main.cgi?", 'custnum' ];
148 my $conf = new FS::Conf;
149 my $money_char = $conf->config('money_char') || '$';