- $x = &{$_creditamount_sub}($r);
-
- $regions{$label}->{'credit'} += $x;
- $tot_credit += $x unless $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 "$_=". uri_escape($r->$_()),
- qw( county state country taxname )
- );
-
- $base_regions{$base_label}->{'tax'} += $x;
- $tot_tax += $x;
-
- ## calculate credit for this region
-
- $x = &{$_creditamount_sub}($r);
-
- $base_regions{$base_label}->{'credit'} += $x;
- $tot_credit += $x;
-
- }
-
-}
-
-my @regions = keys %regions;
-
-#tax-report_groups filtering
-@regions = grep &{$group_test}($_), @regions
- if $group_op;
-
-#calculate totals
-my( $total, $tot_taxable, $tot_owed ) = ( 0, 0, 0 );
-my( $exempt_cust, $exempt_pkg, $exempt_monthly, $tot_credit ) = ( 0, 0, 0, 0 );
-my %taxclasses = ();
-my %county = ();
-my %state = ();
-my %country = ();
-foreach (@regions) {
- $total += $regions{$_}->{'total'};
- $tot_taxable += $regions{$_}->{'taxable'};
- $tot_owed += $regions{$_}->{'owed'};
- $exempt_cust += $regions{$_}->{'exempt_cust'};
- $exempt_pkg += $regions{$_}->{'exempt_pkg'};
- $exempt_monthly += $regions{$_}->{'exempt_monthly'};
- $tot_credit += $regions{$_}->{'credit'};
- $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 ) {
-
- 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
-@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;
-
-#add total line
-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,
- 'exempt_monthly' => $exempt_monthly,
- 'taxable' => $tot_taxable,
- 'rate' => '',
- 'owed' => $tot_owed,
- 'tax' => $tot_tax,
- 'credit' => $tot_credit,
-};
-
-#--