X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=httemplate%2Fsearch%2Freport_tax.cgi;h=e89c66536c2037ad2d736db4c4875a75d58bf5ec;hb=d1014a727cefa5d9813153594541f62ec15fc8b9;hp=d17adb9aaea6c88e502fbd80977e62199c6b8e3f;hpb=ad723cf8d003a2ef4b19adfa5f46ff78b2423cc7;p=freeside.git diff --git a/httemplate/search/report_tax.cgi b/httemplate/search/report_tax.cgi index d17adb9aa..e89c66536 100755 --- a/httemplate/search/report_tax.cgi +++ b/httemplate/search/report_tax.cgi @@ -110,8 +110,12 @@ % unless ( $cgi->param('show_taxclasses') ) { +% my $invlink = $region->{'url_param_inv'} +% ? ';'. $region->{'url_param_inv'} +% : $link; + <<%$tdh%> ALIGN="right"> - <% &$money_sprintf( $region->{'tax'} ) %> % } @@ -285,6 +289,9 @@ foreach my $r ( qsearch({ 'table' => 'cust_main_county', my $label = getlabel($r); $regions{$label}->{'label'} = $label; + + $regions{$label}->{$_} = $r->$_() for (qw( county state country )); #taxname? + $regions{$label}->{'url_param'} = join(';', map "$_=".uri_escape($r->$_()), qw( county state country taxname ) @@ -348,9 +355,25 @@ foreach my $r ( qsearch({ 'table' => 'cust_main_county', # ); # } + #false laziness -ish w/report_tax.cgi + my $cust_exempt; + if ( $r->taxname ) { + my $q_taxname = dbh->quote($r->taxname); + $cust_exempt = + "( tax = 'Y' + OR EXISTS ( SELECT 1 FROM cust_main_exemption + WHERE cust_main_exemption.custnum = cust_main.custnum + AND cust_main_exemption.taxname = $q_taxname + ) + ) + "; + } else { + $cust_exempt = " tax = 'Y' "; + } + my $x_cust = scalar_sql($r, \@param, "SELECT SUM(cust_bill_pkg.setup+cust_bill_pkg.recur) - $fromwhere AND $nottax AND tax = 'Y' " + $fromwhere AND $nottax AND $cust_exempt " ); $regions{$label}->{'exempt_cust'} += $x_cust; @@ -532,6 +555,9 @@ my @regions = keys %regions; my( $total, $tot_taxable, $tot_owed ) = ( 0, 0, 0 ); my( $exempt_cust, $exempt_pkg, $exempt_monthly ) = ( 0, 0, 0 ); my %taxclasses = (); +my %county = (); +my %state = (); +my %country = (); foreach (@regions) { $total += $regions{$_}->{'total'}; $tot_taxable += $regions{$_}->{'taxable'}; @@ -541,12 +567,33 @@ foreach (@regions) { $exempt_monthly += $regions{$_}->{'exempt_monthly'}; $taxclasses{$regions{$_}->{'taxclass'}} = 1 if $regions{$_}->{'taxclass'}; + $county{$regions{$_}->{'county'}} = 1; + $state{$regions{$_}->{'state'}} = 1; + $country{$regions{$_}->{'country'}} = 1; } my $total_url_param = ''; +my $total_url_param_invoiced = ''; if ( $group_op ) { - $total_url_param = 'report_group='.uri_escape("$group_op $group_value").';'. - join(';', 'taxclass='.dbh->quote($_), keys %taxclasses ); + + my @country = keys %country; + warn "WARNING: multiple countries on this grouped report; total links broken" + if scalar(@country) > 1; + my $country = $country[0]; + + my @state = keys %state; + warn "WARNING: multiple countries on this grouped report; total links broken" + if scalar(@state) > 1; + my $state = $state[0]; + + $total_url_param_invoiced = + $total_url_param = + 'report_group='.uri_escape("$group_op $group_value").';'. + join(';', map 'taxclass='.uri_escape($_), keys %taxclasses ); + $total_url_param .= ';'. + "country=$country;state=".uri_escape($state).';'. + join(';', map 'county='.uri_escape($_), keys %county ) ; + } #ordering @@ -564,6 +611,7 @@ my @base_regions = push @regions, { 'label' => 'Total', 'url_param' => $total_url_param, + 'url_param_inv' => $total_url_param_invoiced, 'total' => $total, 'exempt_cust' => $exempt_cust, 'exempt_pkg' => $exempt_pkg,