X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=httemplate%2Fsearch%2Freport_tax.cgi;h=c3462afbc3590d89a9461b631c3e90a45426abd7;hb=05419e3838b401019fed034f97e63e3d7e83b539;hp=73fdfe3acf78a3c14a6eaa0898859453ec3bf302;hpb=4a621a8ef69cb404a419bab97bc17f18ca5f959b;p=freeside.git diff --git a/httemplate/search/report_tax.cgi b/httemplate/search/report_tax.cgi index 73fdfe3ac..c3462afbc 100755 --- a/httemplate/search/report_tax.cgi +++ b/httemplate/search/report_tax.cgi @@ -289,15 +289,22 @@ if ( $conf->exists('tax-ship_address') ) { } my($total, $tot_taxable, $owed, $tax) = ( 0, 0, 0, 0, 0 ); -my( $exempt_cust, $exempt_pkg, $exempt_monthly ) = ( 0, 0 ); +my( $exempt_cust, $exempt_pkg, $exempt_monthly ) = ( 0, 0, 0 ); my $out = 'Out of taxable region(s)'; my %regions = (); -foreach my $r (qsearch('cust_main_county', {}, '', $gotcust) ) { +foreach my $r ( qsearch({ 'table' => 'cust_main_county', + 'extra_sql' => $gotcust, + }) + ) +{ #warn $r->county. ' '. $r->state. ' '. $r->country. "\n"; my $label = getlabel($r); $regions{$label}->{'label'} = $label; - $regions{$label}->{'url_param'} = join(';', map "$_=".$r->$_(), qw( county state country ) ); + $regions{$label}->{'url_param'} = + join(';', map "$_=".uri_escape($r->$_()), + qw( county state country taxname ) + ); my @param = @base_param; my $mywhere = $where; @@ -306,7 +313,7 @@ foreach my $r (qsearch('cust_main_county', {}, '', $gotcust) ) { $mywhere .= " AND taxclass = ? "; push @param, 'taxclass'; - $regions{$label}->{'url_param'} .= ';taxclass='. $r->taxclass + $regions{$label}->{'url_param'} .= ';taxclass='. uri_escape($r->taxclass) if $cgi->param('show_taxclasses'); } else { @@ -423,37 +430,31 @@ foreach my $r (qsearch('cust_main_county', {}, '', $gotcust) ) { } +my $distinct = "country, state, county, + CASE WHEN taxname IS NULL THEN '' ELSE taxname END AS taxname"; +my $taxclass_distinct = + #a little bit unsure of this part... test? + #ah, it looks like it winds up being irrelevant as ->{'tax'} + # from $regions is not displayed when show_taxclasses is on + ( $cgi->param('show_taxclasses') + ? " CASE WHEN taxclass IS NULL THEN '' ELSE taxclass END " + : " '' " + )." AS taxclass"; + +my %qsearch = ( + 'select' => "DISTINCT $distinct, $taxclass_distinct", + 'table' => 'cust_main_county', + 'hashref' => {}, + 'extra_sql' => $gotcust, +); + my $taxwhere = "$from_join_cust $where AND payby != 'COMP' "; my @taxparam = @base_param; -my %base_regions = (); -#foreach my $label ( keys %regions ) { -foreach my $r ( - qsearch( 'cust_main_county', - {}, - "DISTINCT - country, - state, - county, - CASE WHEN taxname IS NULL THEN '' ELSE taxname END AS taxname,". - - #a little bit unsure of this part... test? - #ah, it looks like it winds up being irrelevant as ->{'tax'} - # from $regions is not displayed when show_taxclasses is on - ( $cgi->param('show_taxclasses') - ? " CASE WHEN taxclass IS NULL THEN '' ELSE taxclass END " - : " '' " - )." AS taxclass" - , - $gotcust - ) -) { - - #warn join('-', map { $r->$_() } qw( country state county taxname ) )."\n"; - - my $label = getlabel($r); - #my $fromwhere = $join_pkg. $where. " AND payby != 'COMP' "; - #my @param = @base_param; +#should i be a cust_main_county method or something +#need to pass in $taxwhere & @taxparam??? +my $_taxamount_sub = sub { + my $r = shift; #match itemdesc if necessary! my $named_tax = @@ -464,20 +465,49 @@ foreach my $r ( my $sql = "SELECT SUM(cust_bill_pkg.setup+cust_bill_pkg.recur) ". " $taxwhere AND pkgnum = 0 $named_tax"; - my $x = scalar_sql($r, \@taxparam, $sql ); - $tax += $x; + scalar_sql($r, \@taxparam, $sql ); +}; + +#foreach my $label ( keys %regions ) { +foreach my $r ( qsearch(\%qsearch) ) { + + #warn join('-', map { $r->$_() } qw( country state county taxname ) )."\n"; + + my $label = getlabel($r); + + #my $fromwhere = $join_pkg. $where. " AND payby != 'COMP' "; + #my @param = @base_param; + + my $x = &{$_taxamount_sub}($r); + + $tax += $x unless $cgi->param('show_taxclasses'); $regions{$label}->{'tax'} += $x; - if ( $cgi->param('show_taxclasses') ) { +} + +my %base_regions = (); +if ( $cgi->param('show_taxclasses') ) { + + $qsearch{'select'} = "DISTINCT $distinct"; + foreach my $r ( qsearch(\%qsearch) ) { + + my $x = &{$_taxamount_sub}($r); + 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 ) ); + join(';', map "$_=". uri_escape($r->$_()), + qw( county state country taxname ) + ); + $base_regions{$base_label}->{'tax'} += $x; + $tax += $x; } } + #ordering my @regions = map $regions{$_},