add customer class to A/R report, fix "(none)" selection in other reports, RT#22540
[freeside.git] / httemplate / search / unearned_detail.html
index 02d514c..285fb50 100644 (file)
@@ -114,8 +114,13 @@ if ( $cgi->param('status') =~ /^([a-z]+)$/ ) {
 push @where, "cust_bill._date >= $beginning",
              "cust_bill._date <= $ending";
 
-if ( $cgi->param('agentnum') =~ /^(\d+)$/ ) {
-  push @where, "cust_main.agentnum = $1";
+# cust_classnum (false laziness w/ elements/cust_main_dayranges.html, elements/cust_pay_or_refund.html, prepaid_income.html, cust_bill_pay.html, cust_bill_pkg.html, cust_bill_pkg_referral.html, cust_credit.html, cust_credit_refund.html, cust_main::Search::search_sql)
+if ( grep { $_ eq 'cust_classnum' } $cgi->param ) {
+  my @classnums = grep /^\d*$/, $cgi->param('cust_classnum');
+  push @where, 'COALESCE( cust_main.classnum, 0) IN ( '.
+                   join(',', map { $_ || '0' } @classnums ).
+               ' )'
+    if @classnums;
 }
 
 # no pkgclass, no taxclass, no tax location...
@@ -204,8 +209,8 @@ push @select, '(edate - 82799) AS before_edate';
 #usage always excluded
 
 # always 'nottax', not 'istax'
-$join_cust =  '        JOIN cust_bill USING ( invnum )
-                  LEFT JOIN cust_main USING ( custnum ) ';
+$join_cust =  '        JOIN cust_bill USING ( invnum ) '.
+                  FS::UI::Web::join_cust_main('cust_pkg', 'cust_pkg');
 
 $join_pkg .=  ' LEFT JOIN cust_pkg USING ( pkgnum )
                 LEFT JOIN part_pkg USING ( pkgpart )
@@ -216,7 +221,7 @@ my $where = ' WHERE '. join(' AND ', @where);
 
 my $count_query = "SELECT COUNT(DISTINCT billpkgnum), 
   SUM( $unearned_base ), SUM( $unearned_sql )
-  FROM cust_bill_pkg $join_cust $join_pkg $where";
+  FROM cust_bill_pkg $join_pkg $join_cust $where";
 
 push @select, 'part_pkg.pkg',
               'part_pkg.freq',
@@ -225,7 +230,7 @@ push @select, 'part_pkg.pkg',
 
 my $query = {
   'table'     => 'cust_bill_pkg',
-  'addl_from' => "$join_cust $join_pkg",
+  'addl_from' => "$join_pkg $join_cust",
   'hashref'   => {},
   'select'    => join(",\n", @select ),
   'extra_sql' => $where,
@@ -235,7 +240,8 @@ my $query = {
 my $ilink = [ "${p}view/cust_bill.cgi?", 'invnum' ];
 my $clink = [ "${p}view/cust_main.cgi?", 'custnum' ];
 
-my $money_char;
+my $conf = new FS::Conf;
+my $money_char = $conf->config('money_char') || '$';
 
 sub money_sub {
   $conf ||= new FS::Conf;