From 64ccb0c8d26c387b323fb34e671b34c62d2c0c81 Mon Sep 17 00:00:00 2001 From: ivan Date: Thu, 10 Feb 2011 01:03:58 +0000 Subject: [PATCH] fix cch tax report for more than one cust_bill_pkg_tax_rate_location per line item, RT#11483 --- httemplate/search/cust_bill_pkg.cgi | 10 ++++++++-- httemplate/search/report_newtax.cgi | 2 +- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/httemplate/search/cust_bill_pkg.cgi b/httemplate/search/cust_bill_pkg.cgi index 96de75ba5..b9743049d 100644 --- a/httemplate/search/cust_bill_pkg.cgi +++ b/httemplate/search/cust_bill_pkg.cgi @@ -463,7 +463,8 @@ if ( $cgi->param('pkg_tax') ) { } else { - $count_query = "SELECT COUNT(*), "; + #$count_query = "SELECT COUNT(*), "; + $count_query = "SELECT COUNT(DISTINCT billpkgnum), "; if ( $use_usage eq 'recurring' ) { $count_query .= "SUM(setup + recur - usage)"; @@ -472,7 +473,12 @@ if ( $cgi->param('pkg_tax') ) { } elsif ( $unearned ) { $count_query .= "SUM(cust_bill_pkg.recur)"; } else { - $count_query .= "SUM(cust_bill_pkg.setup + cust_bill_pkg.recur)"; + if ( scalar( grep( /locationtaxid/, $cgi->param ) ) || + $cgi->param('iscredit') eq 'rate') { + $count_query .= "SUM( COALESCE(amount, cust_bill_pkg.setup + cust_bill_pkg.recur))"; + } else { + $count_query .= "SUM(cust_bill_pkg.setup + cust_bill_pkg.recur)"; + } } if ( $unearned ) { diff --git a/httemplate/search/report_newtax.cgi b/httemplate/search/report_newtax.cgi index 6a2cbb0d1..78514624c 100755 --- a/httemplate/search/report_newtax.cgi +++ b/httemplate/search/report_newtax.cgi @@ -123,7 +123,7 @@ foreach my $t (qsearch({ table => 'cust_bill_pkg', my $taxwhere = "FROM cust_bill_pkg $addl_from $where AND payby != 'COMP' ". "AND ". join( ' AND ', map { "( $_ = ? OR ? = '' AND $_ IS NULL)" } @taxparam ); - my $sql = "SELECT SUM(cust_bill_pkg.setup+cust_bill_pkg.recur) ". + my $sql = "SELECT SUM(COALESCE(amount, cust_bill_pkg.setup+cust_bill_pkg.recur)) ". " $taxwhere AND cust_bill_pkg.pkgnum = 0"; my $x = scalar_sql($t, [ map { $_, $_ } @params ], $sql ); -- 2.11.0