summaryrefslogtreecommitdiff
path: root/httemplate/search/report_tax.cgi
diff options
context:
space:
mode:
authorjeff <jeff>2009-10-26 07:12:12 +0000
committerjeff <jeff>2009-10-26 07:12:12 +0000
commit64fcb43c61c196766260319cd9219eb70ea27767 (patch)
tree43a4a49ae30ebf1e8662489139604a44626f53ec /httemplate/search/report_tax.cgi
parent08ab7010467cf25578acdf8d9a9a068a87f1c49f (diff)
credits return taxes, but the magic calculation button does not yet work properly (grrr - more sleep required) RT#4729
Diffstat (limited to 'httemplate/search/report_tax.cgi')
-rwxr-xr-xhttemplate/search/report_tax.cgi50
1 files changed, 49 insertions, 1 deletions
diff --git a/httemplate/search/report_tax.cgi b/httemplate/search/report_tax.cgi
index e89c66536..557c29cfa 100755
--- a/httemplate/search/report_tax.cgi
+++ b/httemplate/search/report_tax.cgi
@@ -22,6 +22,7 @@
<TH CLASS="grid" BGCOLOR="#cccccc" ROWSPAN=2>Tax owed</TH>
% unless ( $cgi->param('show_taxclasses') ) {
<TH CLASS="grid" BGCOLOR="#cccccc" ROWSPAN=2>Tax invoiced</TH>
+ <TH CLASS="grid" BGCOLOR="#cccccc" ROWSPAN=2>Tax credited</TH>
% }
</TR>
@@ -118,6 +119,10 @@
<A HREF="<% $baselink. $invlink %>;istax=1"
><% &$money_sprintf( $region->{'tax'} ) %></A>
</TD>
+ <<%$tdh%> ALIGN="right">
+ <A HREF="<% $baselink. $invlink %>;istax=1;iscredit=1"
+ ><% &$money_sprintf( $region->{'credit'} ) %></A>
+ </TD>
% }
</TR>
@@ -132,6 +137,7 @@
<TR>
<TH CLASS="grid" BGCOLOR="#cccccc"></TH>
<TH CLASS="grid" BGCOLOR="#cccccc">Tax invoiced</TH>
+ <TH CLASS="grid" BGCOLOR="#cccccc">Tax credited</TH>
</TR>
% #some false laziness w/above
@@ -463,9 +469,18 @@ if ( $conf->exists('tax-pkg_address') ) {
$taxwhere =~ s/cust_pkg\.locationnum/cust_bill_pkg_tax_location.locationnum/g;
}
+my $creditfromwhere = $taxfromwhere.
+ " JOIN cust_credit_bill_pkg USING (billpkgnum";
+$creditfromwhere .= " ,billpkgtaxlocationnum"
+ if $conf->exists('tax-pkg_address');
+$creditfromwhere .= ")";
+
$taxfromwhere .= " $taxwhere "; #AND payby != 'COMP' ";
+$creditfromwhere .= " $taxwhere AND billpkgtaxratelocationnum IS NULL"; #AND payby != 'COMP' ";
+
my @taxparam = @base_param;
+
#should i be a cust_main_county method or something
#need to pass in $taxfromwhere & @taxparam???
my $_taxamount_sub = sub {
@@ -483,6 +498,21 @@ my $_taxamount_sub = sub {
scalar_sql($r, \@taxparam, $sql );
};
+my $_creditamount_sub = sub {
+ my $r = shift;
+
+ #match itemdesc if necessary!
+ my $named_tax =
+ $r->taxname
+ ? 'AND itemdesc = '. dbh->quote($r->taxname)
+ : "AND ( itemdesc IS NULL OR itemdesc = '' OR itemdesc = 'Tax' )";
+
+ my $sql = "SELECT SUM(cust_credit_bill_pkg.amount) ".
+ " $creditfromwhere AND cust_bill_pkg.pkgnum = 0 $named_tax";
+
+ scalar_sql($r, \@taxparam, $sql );
+};
+
#tax-report_groups filtering
my($group_op, $group_value) = ( '', '' );
if ( $cgi->param('report_group') =~ /^(=|!=) (.*)$/ ) {
@@ -503,6 +533,7 @@ my $group_test = sub {
};
my $tot_tax = 0;
+my $tot_credit = 0;
#foreach my $label ( keys %regions ) {
foreach my $r ( qsearch(\%qsearch) ) {
@@ -521,6 +552,13 @@ foreach my $r ( qsearch(\%qsearch) ) {
$regions{$label}->{'tax'} += $x;
$tot_tax += $x unless $cgi->param('show_taxclasses');
+ ## calculate credit for this region
+
+ $x = &{$_creditamount_sub}($r);
+
+ $regions{$label}->{'credit'} += $x;
+ $tot_credit += $x unless $cgi->param('show_taxclasses');
+
}
my %base_regions = ();
@@ -541,6 +579,14 @@ if ( $cgi->param('show_taxclasses') ) {
$base_regions{$base_label}->{'tax'} += $x;
$tot_tax += $x;
+
+ ## calculate credit for this region
+
+ $x = &{$_creditamount_sub}($r);
+
+ $base_regions{$base_label}->{'credit'} += $x;
+ $tot_credit += $x;
+
}
}
@@ -553,7 +599,7 @@ my @regions = keys %regions;
#calculate totals
my( $total, $tot_taxable, $tot_owed ) = ( 0, 0, 0 );
-my( $exempt_cust, $exempt_pkg, $exempt_monthly ) = ( 0, 0, 0 );
+my( $exempt_cust, $exempt_pkg, $exempt_monthly, $tot_credit ) = ( 0, 0, 0, 0 );
my %taxclasses = ();
my %county = ();
my %state = ();
@@ -565,6 +611,7 @@ foreach (@regions) {
$exempt_cust += $regions{$_}->{'exempt_cust'};
$exempt_pkg += $regions{$_}->{'exempt_pkg'};
$exempt_monthly += $regions{$_}->{'exempt_monthly'};
+ $tot_credit += $regions{$_}->{'credit'};
$taxclasses{$regions{$_}->{'taxclass'}} = 1
if $regions{$_}->{'taxclass'};
$county{$regions{$_}->{'county'}} = 1;
@@ -620,6 +667,7 @@ push @regions, {
'rate' => '',
'owed' => $tot_owed,
'tax' => $tot_tax,
+ 'credit' => $tot_credit,
};
#--