From: ivan Date: Tue, 9 Nov 2004 11:42:56 +0000 (+0000) Subject: add handling for texas tax exemption and warning that report might not make sense... X-Git-Tag: BEFORE_FINAL_MASONIZE~869 X-Git-Url: http://git.freeside.biz/gitweb/?p=freeside.git;a=commitdiff_plain;h=bff7161b7d9f6d7218e69333556c2011d57049e1 add handling for texas tax exemption and warning that report might not make sense for partial months other than the current one --- diff --git a/httemplate/search/report_tax.cgi b/httemplate/search/report_tax.cgi index aa85be686..587665740 100755 --- a/httemplate/search/report_tax.cgi +++ b/httemplate/search/report_tax.cgi @@ -77,43 +77,45 @@ foreach my $r (qsearch('cust_main_county', {}, '', $gotcust) ) { $regions{$label}->{'exempt'} += $x; } + my($t, $x) = (0, 0); foreach my $e ( grep { $r->get($_.'tax') !~ /^Y/i } qw( cust_bill_pkg.setup cust_bill_pkg.recur ) ) { - my $t = scalar_sql($r, \@param, + $t += scalar_sql($r, \@param, "SELECT SUM($e) $fromwhere AND $nottax AND ( tax != 'Y' OR tax IS NULL )" ); - my $x = scalar_sql($r, \@param, + $x += scalar_sql($r, \@param, "SELECT SUM($e) $fromwhere AND $nottax AND tax = 'Y'" ); + } - my($sday,$smon,$syear) = (localtime($beginning) )[ 3, 4, 5 ]; - $monthly_exempt_warning=1 if $sday != 1 && $beginning; - $smon++; $syear+=1900; - - my($eday,$emon,$eyear) = (localtime($ending) )[ 3, 4, 5 ]; - $emon++; $eyear+=1900; + my($sday,$smon,$syear) = (localtime($beginning) )[ 3, 4, 5 ]; + $monthly_exempt_warning=1 if $sday != 1 && $beginning; + $smon++; $syear+=1900; - my $monthly_exemption = scalar_sql($r, [ 'taxnum' ], - "SELECT SUM(amount) FROM cust_tax_exempt where taxnum = ? ". - " AND ( year > $syear OR ( year = $syear and month >= $smon ) )". - " AND ( year < $eyear OR ( year = $eyear and month <= $emon ) )" - ); - if ( $monthly_exemption ) { - $t -= $monthly_exemption; - $x += $monthly_exemption; - } + my $eending = ( $ending == 4294967295 ) ? time : $ending; + my($eday,$emon,$eyear) = (localtime($eending) )[ 3, 4, 5 ]; + $emon++; $eyear+=1900; - $taxable += $t; - $regions{$label}->{'taxable'} += $t; + my $monthly_exemption = scalar_sql($r, [ 'taxnum' ], + "SELECT SUM(amount) FROM cust_tax_exempt where taxnum = ? ". + " AND ( year > $syear OR ( year = $syear and month >= $smon ) )". + " AND ( year < $eyear OR ( year = $eyear and month <= $emon ) )" + ); + #warn $r->taxnum(). ": $monthly_exemption\n"; + if ( $monthly_exemption ) { + $t -= $monthly_exemption; + $x += $monthly_exemption; + } - $exempt += $x; - $regions{$label}->{'exempt'} += $x; + $taxable += $t; + $regions{$label}->{'taxable'} += $t; - $owed += $t * ($r->tax/100); - $regions{$label}->{'owed'} += $t * ($r->tax/100); + $exempt += $x; + $regions{$label}->{'exempt'} += $x; - } + $owed += $t * ($r->tax/100); + $regions{$label}->{'owed'} += $t * ($r->tax/100); if ( defined($regions{$label}->{'rate'}) && $regions{$label}->{'rate'} != $r->tax.'%' ) { @@ -168,6 +170,7 @@ push @regions, { 'exempt' => $exempt, 'taxable' => $taxable, 'rate' => '', + 'owed' => $owed, 'tax' => $tax, };