X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=httemplate%2Fsearch%2Fcust_bill_pkg.cgi;h=3a3b0feb9d65cdafeb27c79fb92fe02c7d19ae25;hb=a9f4e76c1d2392514c4172dd869fd101e3a9c6ec;hp=42722b1a73d398aba54f47bf01a63b10ef5f34be;hpb=c7286ce9036d71665c2bfed9de93f87309b72d35;p=freeside.git diff --git a/httemplate/search/cust_bill_pkg.cgi b/httemplate/search/cust_bill_pkg.cgi index 42722b1a7..3a3b0feb9 100644 --- a/httemplate/search/cust_bill_pkg.cgi +++ b/httemplate/search/cust_bill_pkg.cgi @@ -191,7 +191,7 @@ my $money_char = $conf->config('money_char') || '$'; my @select = ( 'cust_bill_pkg.*', 'cust_bill._date' ); my @total = ( 'COUNT(*)', 'SUM(cust_bill_pkg.setup + cust_bill_pkg.recur)'); -my @total_desc = ( '%d line items', $money_char.'%.2f total' ); # sprintf strings +my @total_desc = ( $money_char.'%.2f total' ); # sprintf strings my @peritem = ( 'setup', 'recur' ); my @peritem_desc = ( 'Setup charge', 'Recurring charge' ); @@ -222,9 +222,9 @@ if ( $conf->exists('enable_taxclasses') ) { # valid in both the tax and non-tax cases my $join_cust = - " LEFT JOIN cust_bill USING (invnum) - LEFT JOIN cust_main USING (custnum) - "; + " LEFT JOIN cust_bill USING (invnum)". + # use cust_pkg.locationnum if it exists + FS::UI::Web::join_cust_main('cust_bill', 'cust_pkg'); #agent virtualization my $agentnums_sql = @@ -260,13 +260,16 @@ if ( $cgi->param('refnum') =~ /^(\d+)$/ ) { push @where, "cust_main.refnum = $1"; } -# cust_classnum -if ( $cgi->param('cust_classnum') ) { - my @classnums = grep /^\d+$/, $cgi->param('cust_classnum'); - push @where, 'cust_main.classnum IN('.join(',',@classnums).')' +# 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_referral.html, unearned_detail.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; } + # custnum if ( $cgi->param('custnum') =~ /^(\d+)$/ ) { push @where, "cust_main.custnum = $1"; @@ -278,11 +281,11 @@ my $join_pkg = LEFT JOIN part_pkg USING (pkgpart)'; my $part_pkg = 'part_pkg'; -if ( $cgi->param('use_override') ) { +if ( $cgi->param('use_override') ) { #"Separate sub-packages from parents" # still need the real part_pkg for tax applicability, # so alias this one $join_pkg .= " LEFT JOIN part_pkg AS override ON ( - COALESCE(cust_bill_pkg.pkgpart_override, cust_pkg.pkgpart, 0) = part_pkg.pkgpart + COALESCE(cust_bill_pkg.pkgpart_override, cust_pkg.pkgpart, 0) = override.pkgpart )"; $part_pkg = 'override'; } @@ -452,7 +455,7 @@ if ( $cgi->param('nottax') ) { push @select, "($recur_no_usage) AS recur_no_usage"; $peritem[1] = 'recur_no_usage'; $total[1] = "SUM(cust_bill_pkg.setup + $recur_no_usage)"; - $total_desc[1] .= ' (excluding usage)'; + $total_desc[0] .= ' (excluding usage)'; } elsif ( $cgi->param('usage') eq 'usage' ) { @@ -462,7 +465,7 @@ if ( $cgi->param('nottax') ) { $peritem[1] = '_usage'; $peritem_desc[1] = 'Usage charge'; $total[1] = "SUM($usage)"; - $total_desc[1] .= ' usage charges'; + $total_desc[0] .= ' usage charges'; } } elsif ( $cgi->param('istax') ) { @@ -559,12 +562,11 @@ if ( $cgi->param('nottax') ) { #total payments -my $pay_sub = "SELECT SUM(cust_bill_pay_pkg.amount) AS pay_amount, - billpkgnum - FROM cust_bill_pay_pkg - GROUP BY billpkgnum"; -$join_pkg .= " LEFT JOIN ($pay_sub) AS item_pay USING (billpkgnum)"; -push @select, 'item_pay.pay_amount'; +my $pay_sub = "SELECT SUM(cust_bill_pay_pkg.amount) + FROM cust_bill_pay_pkg + WHERE cust_bill_pkg.billpkgnum = cust_bill_pay_pkg.billpkgnum + "; +push @select, "($pay_sub) AS pay_amount"; # credit @@ -630,13 +632,12 @@ if ( $cgi->param('credit') ) { #still want a credit total column - my $credit_sub = "SELECT SUM(cust_credit_bill_pkg.amount) AS credit_amount, - billpkgnum - FROM cust_credit_bill_pkg - GROUP BY billpkgnum"; - $join_pkg .= " LEFT JOIN ($credit_sub) AS item_credit USING (billpkgnum)"; - - push @select, 'item_credit.credit_amount'; + my $credit_sub = " + SELECT SUM(cust_credit_bill_pkg.amount) + FROM cust_credit_bill_pkg + WHERE cust_bill_pkg.billpkgnum = cust_credit_bill_pkg.billpkgnum + "; + push @select, "($credit_sub) AS credit_amount"; } @@ -647,7 +648,7 @@ $where &&= "WHERE $where"; 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, @@ -656,11 +657,9 @@ my $query = { my $count_query = 'SELECT ' . join(',', @total) . - " FROM cust_bill_pkg $join_cust $join_pkg + " FROM cust_bill_pkg $join_pkg $join_cust $where"; -shift @total_desc; #the first one is implicit - @peritem_desc = map {emt($_)} @peritem_desc; my @peritem_sub = map { my $field = $_;