X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=httemplate%2Fsearch%2Freport_newtax.cgi;h=6a2cbb0d18e59ee1dc474ed879f8e0c460cb9218;hb=e62acb0f445bbeb356c9577f9327e39ed1221bef;hp=0fb54835213043e056666fee59f1ffc335e93c9f;hpb=794a4505360fec404e2b9d5c6daf79f750186bfe;p=freeside.git
diff --git a/httemplate/search/report_newtax.cgi b/httemplate/search/report_newtax.cgi
index 0fb548352..6a2cbb0d1 100755
--- a/httemplate/search/report_newtax.cgi
+++ b/httemplate/search/report_newtax.cgi
@@ -17,6 +17,9 @@
|
|
Tax collected |
+ |
+ |
+ Tax credited |
% my $bgcolor1 = '#eeeeee';
% my $bgcolor2 = '#ffffff';
@@ -43,6 +46,12 @@
<% $money_char %><% sprintf('%.2f', $tax->{'tax'} ) %>
<% !($tax->{base}) ? qq! | ! : '' %>
+ |
+ <% $tax->{base} ? qq! | ! : '' %>
+
+ <% $money_char %><% sprintf('%.2f', $tax->{'credit'} ) %>
+ |
+ <% !($tax->{base}) ? qq! | ! : '' %>
% }
@@ -90,6 +99,7 @@ my @taxparam = ( 'itemdesc', 'tax_rate_location.state', 'tax_rate_location.count
my $select = 'DISTINCT itemdesc,locationtaxid,tax_rate_location.state,tax_rate_location.county,tax_rate_location.city';
my $tax = 0;
+my $credit = 0;
my %taxes = ();
my %basetaxes = ();
foreach my $t (qsearch({ table => 'cust_bill_pkg',
@@ -120,6 +130,18 @@ foreach my $t (qsearch({ table => 'cust_bill_pkg',
$tax += $x;
$taxes{$label}->{'tax'} += $x;
+ my $creditfrom = " JOIN cust_credit_bill_pkg USING (billpkgnum,billpkgtaxratelocationnum) ";
+ my $creditwhere = "FROM cust_bill_pkg $addl_from $creditfrom $where ".
+ "AND payby != 'COMP' ".
+ "AND ". join( ' AND ', map { "( $_ = ? OR ? = '' AND $_ IS NULL)" } @taxparam );
+
+ $sql = "SELECT SUM(cust_credit_bill_pkg.amount) ".
+ " $creditwhere AND cust_bill_pkg.pkgnum = 0";
+
+ my $y = scalar_sql($t, [ map { $_, $_ } @params ], $sql );
+ $credit += $y;
+ $taxes{$label}->{'credit'} += $y;
+
unless ( exists( $taxes{$baselabel} ) ) {
$basetaxes{$baselabel}->{'label'} = $baselabel;
@@ -129,6 +151,7 @@ foreach my $t (qsearch({ table => 'cust_bill_pkg',
}
$basetaxes{$baselabel}->{'tax'} += $x;
+ $basetaxes{$baselabel}->{'credit'} += $y;
}
@@ -160,6 +183,7 @@ push @taxes, {
'label' => 'Total',
'url_param' => '',
'tax' => $tax,
+ 'credit' => $credit,
'base' => 1,
};