From 3ceb940d13cbfc54e40e621baa9e8d883d624e6a Mon Sep 17 00:00:00 2001 From: ivan Date: Wed, 27 May 2009 17:18:36 +0000 Subject: [PATCH] fix total line links on tax report when using report_group kludge? (possibly not in all corner cases), RT#5446 --- httemplate/search/cust_bill_pkg.cgi | 42 ++++++++++++++++++++-------- httemplate/search/report_tax.cgi | 56 +++++++++++++++++++++---------------- 2 files changed, 62 insertions(+), 36 deletions(-) diff --git a/httemplate/search/cust_bill_pkg.cgi b/httemplate/search/cust_bill_pkg.cgi index 9d4843281..61f3f3f87 100644 --- a/httemplate/search/cust_bill_pkg.cgi +++ b/httemplate/search/cust_bill_pkg.cgi @@ -83,6 +83,10 @@ if ( $cgi->param('agentnum') =~ /^(\d+)$/ ) { push @where, "cust_main.agentnum = $1"; } +#classnum +# not specified: all classes +# 0: empty class +# N: classnum if ( $cgi->param('classnum') =~ /^(\d+)$/ ) { if ( $1 == 0 ) { push @where, "classnum IS NULL"; @@ -91,6 +95,13 @@ if ( $cgi->param('classnum') =~ /^(\d+)$/ ) { } } +push @where, map ' taxclass = '.dbh->quote($_), $cgi->param('taxclass') + if $cgi->param('taxclass') + && ! $cgi->param('istax'); #no part_pkg.taxclass in this case + #(should we save a taxclass or a link to taxnum + # in cust_bill_pkg or something like + # cust_bill_pkg_tax_location?) + #sub _where { # my $table = shift; # my $prefix = @_ ? shift : ''; @@ -143,7 +154,7 @@ if ( $cgi->param('out') ) { } -} elsif ( $cgi->param('country' ) ) { +} elsif ( $cgi->param('country') ) { my %ph = map { $_ => dbh->quote( $cgi->param($_) ) } qw( county state country ); @@ -168,13 +179,6 @@ if ( $cgi->param('out') ) { #warn "neither nottax nor istax parameters specified"; } - push @where, ' taxclass = '. dbh->quote( $cgi->param('taxclass') ) - if $cgi->param('taxclass') - && ! $cgi->param('istax'); #no part_pkg.taxclass in this case - #(should we save a taxclass or a link to taxnum - # in cust_bill_pkg or something like - # cust_bill_pkg_tax_location?) - if ( $cgi->param('taxclassNULL') ) { my %hash = ( 'country' => scalar($cgi->param('country')) ); @@ -189,7 +193,7 @@ if ( $cgi->param('out') ) { } - } elsif ( scalar( grep( /locationtaxid/, $cgi->param ) ) ) { +} elsif ( scalar( grep( /locationtaxid/, $cgi->param ) ) ) { # this should really be shoved out to FS::cust_pkg->location_sql or something # along with the code in report_newtax.cgi @@ -211,13 +215,27 @@ if ( $cgi->param('out') ) { } -if ($cgi->param('itemdesc')) { - if ($cgi->param('itemdesc') eq 'Tax') { +if ( $cgi->param('itemdesc') ) { + if ( $cgi->param('itemdesc') eq 'Tax' ) { push @where, "(itemdesc='Tax' OR itemdesc is null)"; - }else{ + } else { push @where, 'itemdesc='. dbh->quote($cgi->param('itemdesc')); } } + +if ( $cgi->param('report_group') =~ /^(=|!=) (.*)$/ && $cgi->param('istax') ) { + my ( $group_op, $group_value ) = ( $1, $2 ); + if ( $group_op eq '=' ) { + #push @where, 'itemdesc LIKE '. dbh->quote($group_value.'%'); + push @where, 'itemdesc = '. dbh->quote($group_value); + } elsif ( $group_op eq '!=' ) { + push @where, '( itemdesc != '. dbh->quote($group_value) .' OR itemdesc IS NULL )'; + } else { + die "guru meditation #00de: group_op $group_op\n"; + } + +} + push @where, 'cust_bill_pkg.pkgnum != 0' if $cgi->param('nottax'); push @where, 'cust_bill_pkg.pkgnum = 0' if $cgi->param('istax'); diff --git a/httemplate/search/report_tax.cgi b/httemplate/search/report_tax.cgi index dc93d513b..1d4d8d5ff 100755 --- a/httemplate/search/report_tax.cgi +++ b/httemplate/search/report_tax.cgi @@ -44,12 +44,11 @@ % foreach my $region ( @regions ) { % % my $link = ''; -% if ( $region->{'label'} ne 'Total' ) { -% if ( $region->{'label'} eq $out ) { -% $link = ';out=1'; -% } else { -% $link = ';'. $region->{'url_param'}; -% } +% if ( $region->{'label'} eq $out ) { +% $link = ';out=1'; +% } else { +% $link = ';'. $region->{'url_param'} +% if $region->{'url_param'}; % } % % if ( $bgcolor eq $bgcolor1 ) { @@ -138,13 +137,12 @@ % foreach my $region ( @base_regions ) { % % my $link = ''; -% #if ( $region->{'label'} ne 'Total' ) { -% if ( $region->{'label'} eq $out ) { -% $link = ';out=1'; -% } else { -% $link = ';'. $region->{'url_param'}; -% } -% #} +% if ( $region->{'label'} eq $out ) { +% $link = ';out=1'; +% } else { +% $link = ';'. $region->{'url_param'} +% if $region->{'url_param'}; +% } % % if ( $bgcolor eq $bgcolor1 ) { % $bgcolor = $bgcolor2; @@ -277,6 +275,7 @@ if ( $conf->exists('tax-pkg_address') ) { my $out = 'Out of taxable region(s)'; my %regions = (); +my %taxclasses = (); foreach my $r ( qsearch({ 'table' => 'cust_main_county', 'extra_sql' => $gotcust, @@ -302,6 +301,8 @@ foreach my $r ( qsearch({ 'table' => 'cust_main_county', $regions{$label}->{'url_param'} .= ';taxclass='. uri_escape($r->taxclass); #no, always# if $cgi->param('show_taxclasses'); + $taxclasses{$r->taxclass} = 1; + } else { $regions{$label}->{'url_param'} .= ';taxclassNULL=1' @@ -528,7 +529,18 @@ my @regions = keys %regions; @regions = grep &{$group_test}($_), @regions if $group_op; -#now calculate totals +#ordering +@regions = + map $regions{$_}, + sort { ( ($a eq $out) cmp ($b eq $out) ) || ($b cmp $a) } + @regions; + +my @base_regions = + map $base_regions{$_}, + sort { ( ($a eq $out) cmp ($b eq $out) ) || ($b cmp $a) } + keys %base_regions; + +#totals my( $total, $tot_taxable, $tot_owed ) = ( 0, 0, 0 ); my( $exempt_cust, $exempt_pkg, $exempt_monthly ) = ( 0, 0, 0 ); foreach (@regions) { @@ -540,20 +552,16 @@ foreach (@regions) { $exempt_monthly += $regions{$_}->{'exempt_monthly'}; } -#ordering -@regions = - map $regions{$_}, - sort { ( ($a eq $out) cmp ($b eq $out) ) || ($b cmp $a) } - @regions; +my $total_url_param = ''; -my @base_regions = - map $base_regions{$_}, - sort { ( ($a eq $out) cmp ($b eq $out) ) || ($b cmp $a) } - keys %base_regions; +if ( $group_op ) { + $total_url_param = 'report_group='.uri_escape("$group_op $group_value").';'. + join(';', 'taxclass = '.dbh->quote($_), keys %taxclasses ); +} push @regions, { 'label' => 'Total', - 'url_param' => '', + 'url_param' => $total_url_param, 'total' => $total, 'exempt_cust' => $exempt_cust, 'exempt_pkg' => $exempt_pkg, -- 2.11.0