fix total line links on tax report when using report_group kludge? (possibly not...
[freeside.git] / httemplate / search / report_tax.cgi
index dc93d51..1d4d8d5 100755 (executable)
 % 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 ) {
 %   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,