X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=httemplate%2Fsearch%2Freport_tax.cgi;h=bfc76d787e242a817696d57702256c67acec2165;hb=a3493ac498ed57b754f776390fb20239a11e4a04;hp=4edd084492a424dcfc3bf5ad55e89125a1c34b56;hpb=386ec52836abbe32ce2fbf575e851a75f6e112f8;p=freeside.git diff --git a/httemplate/search/report_tax.cgi b/httemplate/search/report_tax.cgi index 4edd08449..bfc76d787 100755 --- a/httemplate/search/report_tax.cgi +++ b/httemplate/search/report_tax.cgi @@ -44,7 +44,8 @@ my $gotcust = " "; my $monthly_exempt_warning = 0; -my($total, $taxable, $owed, $tax) = ( 0, 0, 0, 0, 0 ); +my $taxclass_flag = 0; +my($total, $tot_taxable, $owed, $tax) = ( 0, 0, 0, 0, 0 ); my( $exempt_cust, $exempt_pkg, $exempt_monthly ) = ( 0, 0 ); my $out = 'Out of taxable region(s)'; my %regions = (); @@ -53,7 +54,6 @@ foreach my $r (qsearch('cust_main_county', {}, '', $gotcust) ) { my $label = getlabel($r); $regions{$label}->{'label'} = $label; - $regions{$label}->{'url_param'} = join(';', map "$_=".$r->$_(), qw( county state country ) ); my $fromwhere = $from_join_cust. $join_pkg. $where; @@ -62,7 +62,9 @@ foreach my $r (qsearch('cust_main_county', {}, '', $gotcust) ) { if ( $r->taxclass ) { $fromwhere .= " AND taxclass = ? "; push @param, 'taxclass'; - $regions{$label}->{'url_param'} .= ';taxclass='. $r->taxclass; + $regions{$label}->{'url_param'} .= ';taxclass='. $r->taxclass + if $cgi->param('show_taxclasses'); + $taxclass_flag = 1; } # my $label = getlabel($r); @@ -91,10 +93,10 @@ foreach my $r (qsearch('cust_main_county', {}, '', $gotcust) ) { ## calculate customer-exemption for this region - my($t, $x_cust) = (0, 0); + my($taxable, $x_cust) = (0, 0); foreach my $e ( grep { $r->get($_.'tax') !~ /^Y/i } qw( cust_bill_pkg.setup cust_bill_pkg.recur ) ) { - $t += scalar_sql($r, \@param, + $taxable += scalar_sql($r, \@param, "SELECT SUM($e) $fromwhere AND $nottax AND ( tax != 'Y' OR tax IS NULL )" ); @@ -123,17 +125,17 @@ foreach my $r (qsearch('cust_main_county', {}, '', $gotcust) ) { ); if ( $x_monthly ) { warn $r->taxnum(). ": $x_monthly\n"; - $t -= $x_monthly; + $taxable -= $x_monthly; } $exempt_monthly += $x_monthly; $regions{$label}->{'exempt_monthly'} += $x_monthly; - $taxable += $t; - $regions{$label}->{'taxable'} += $t; + $tot_taxable += $taxable; + $regions{$label}->{'taxable'} += $taxable; - $owed += $t * ($r->tax/100); - $regions{$label}->{'owed'} += $t * ($r->tax/100); + $owed += $taxable * ($r->tax/100); + $regions{$label}->{'owed'} += $taxable * ($r->tax/100); if ( defined($regions{$label}->{'rate'}) && $regions{$label}->{'rate'} != $r->tax.'%' ) { @@ -146,7 +148,7 @@ foreach my $r (qsearch('cust_main_county', {}, '', $gotcust) ) { my $taxwhere = "$from_join_cust $where"; my @taxparam = @base_param; - +my %base_regions = (); #foreach my $label ( keys %regions ) { foreach my $r ( qsearch( 'cust_main_county', @@ -175,12 +177,26 @@ foreach my $r ( $tax += $x; $regions{$label}->{'tax'} += $x; + if ( $cgi->param('show_taxclasses') ) { + my $base_label = getlabel($r, 'no_taxclass'=>1 ); + $base_regions{$base_label}->{'label'} = $base_label; + $base_regions{$base_label}->{'url_param'} = + join(';', map "$_=".$r->$_(), qw( county state country ) ); + $base_regions{$base_label}->{'tax'} += $x; + } + } #ordering -my @regions = map $regions{$_}, - sort { ( ($a eq $out) cmp ($b eq $out) ) || ($b cmp $a) } - keys %regions; +my @regions = + map $regions{$_}, + sort { ( ($a eq $out) cmp ($b eq $out) ) || ($b cmp $a) } + keys %regions; + +my @base_regions = + map $base_regions{$_}, + sort { ( ($a eq $out) cmp ($b eq $out) ) || ($b cmp $a) } + keys %base_regions; push @regions, { 'label' => 'Total', @@ -189,7 +205,7 @@ push @regions, { 'exempt_cust' => $exempt_cust, 'exempt_pkg' => $exempt_pkg, 'exempt_monthly' => $exempt_monthly, - 'taxable' => $taxable, + 'taxable' => $tot_taxable, 'rate' => '', 'owed' => $owed, 'tax' => $tax, @@ -199,6 +215,7 @@ push @regions, { sub getlabel { my $r = shift; + my %opt = @_; my $label; if ( @@ -223,7 +240,10 @@ sub getlabel { $label = $r->country; $label = $r->state.", $label" if $r->state; $label = $r->county." county, $label" if $r->county; - $label = "$label (". $r->taxclass. ")" if $r->taxclass; + $label = "$label (". $r->taxclass. ")" + if $r->taxclass + && $cgi->param('show_taxclasses') + && ! $opt{'no_taxclasses'}; #$label = $r->taxname. " ($label)" if $r->taxname; } return $label; @@ -251,7 +271,7 @@ my $baselink = $p. "search/cust_bill_pkg.cgi?begin=$beginning;end=$ending"; <%= header( "$agentname Sales Tax Report - ". time2str('%h %o %Y through ', $beginning ). - ( $cgi->param('ending') == 4294967295 + ( $ending == 4294967295 ? 'now' : time2str('%h %o %Y', $ending ) ), @@ -262,11 +282,13 @@ my $baselink = $p. "search/cust_bill_pkg.cgi?begin=$beginning;end=$ending"; <%= include('/elements/table-grid.html') %> - - Sales - Rate - Tax owed - Tax invoiced + + Sales + Rate + Tax owed + <% unless ( $cgi->param('show_taxclasses') ) { %> + Tax invoiced + <% } %> Total @@ -298,6 +320,7 @@ my $baselink = $p. "search/cust_bill_pkg.cgi?begin=$beginning;end=$ending"; } } %> + <%= $region->{'label'} %> @@ -319,13 +342,59 @@ my $baselink = $p. "search/cust_bill_pkg.cgi?begin=$beginning;end=$ending"; $<%= sprintf('%.2f', $region->{'owed'} ) %> + <% unless ( $cgi->param('show_taxclasses') ) { %> + + $<%= sprintf('%.2f', $region->{'tax'} ) %> + + <% } %> + + + <% } %> + + + + +<% if ( $cgi->param('show_taxclasses') ) { %> + +
+ <%= include('/elements/table-grid.html') %> + + + Tax invoiced + + + <% #some false laziness w/above + foreach my $region ( @base_regions ) { + + if ( $bgcolor eq $bgcolor1 ) { + $bgcolor = $bgcolor2; + } else { + $bgcolor = $bgcolor1; + } + + my $link = $baselink; + if ( $region->{'label'} ne 'Total' ) { + if ( $region->{'label'} eq $out ) { + $link .= ';out=1'; + } else { + $link .= ';'. $region->{'url_param'}; + } + } + %> + + + <%= $region->{'label'} %> $<%= sprintf('%.2f', $region->{'tax'} ) %> + <% } %> - + + +<% } %> + <% if ( $monthly_exempt_warning ) { %>