- }
-
- my @regions = map { $_->{label} }
- sort {
- ($b eq $out) <=> ($a eq $out)
- or $a->{country} cmp $b->{country}
- or $a->{state} cmp $b->{state}
- or $a->{county} cmp $b->{county}
- or $a->{city} cmp $b->{city}
- }
- grep { $_->{sales} > 0 or $_->{tax} > 0 or $_->{credit} > 0 }
- values %regions;
-
- #tax-report_groups filtering
- @regions = grep &{$group_test}($_), @regions
- if $group_op;
-
- #calculate totals
- my %taxclasses = ();
- my %county = ();
- my %state = ();
- my %country = ();
- foreach my $label (@regions) {
- $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 cmp $b }
- @regions;
-
- my @base_regions =
- map $base_regions{$_},
- sort { $a cmp $b }
- keys %base_regions;
-
- #add "Out of taxable" and total lines
- if ( $total{out_sales}{$classnum} ) {
- my %out = (
- 'sales' => $total{out_sales}{$classnum},
- 'label' => $out,
- 'rate' => ''
- );
- push @regions, \%out;
- push @base_regions, \%out;
- }
-
- if ( @regions ) {
- my %class_total = map { $_ => $total{$_}{$classnum} } keys(%total);
- $class_total{is_total} = 1;
- $class_total{sales} = sum(
- @class_total{ 'taxable',
- 'out_sales',
- grep(/^exempt/, keys %class_total) }
- );
-
- push @regions, \%class_total;
- push @base_regions, \%class_total;
- }
-
- $pkgclass_data{$classname} = {
- classnum => $classnum,
- classname => $classname,
- regions => \@regions,
- base_regions => \@base_regions,
- };
-}
-
-if ( $with_pkgclass ) {
- my $class_zero = delete( $pkgclass_data{'Unclassified'} );
- @pkgclasses = map { $pkgclass_data{$_} }
- sort { $a cmp $b }
- keys %pkgclass_data;
- push @pkgclasses, $class_zero;
-
- my %grand_total = map {
- $_ => sum( values(%{ $total{$_} }) )
- } keys(%total);
-
- $grand_total{sales} = $all_sales;
-
- push @pkgclasses, {
- classnum => '',
- classname => 'Total',
- regions => [ \%grand_total ],
- base_regions => [ \%grand_total ],
- }
-} else {
- @pkgclasses = $pkgclass_data{''};
-}
-
-#--