diff options
author | ivan <ivan> | 2009-05-26 01:35:16 +0000 |
---|---|---|
committer | ivan <ivan> | 2009-05-26 01:35:16 +0000 |
commit | 8d9be02c9965db4c4a48a2221455160685a95462 (patch) | |
tree | 0d618b0c7cff7dbd43631d1c2d28008479e531b9 /httemplate/search | |
parent | 208add41d52153ccff338fe0f1eafbc0c462a2ed (diff) |
add a config option for some basic tax grouping by name, RT#5446
Diffstat (limited to 'httemplate/search')
-rwxr-xr-x | httemplate/search/report_tax.cgi | 57 | ||||
-rwxr-xr-x | httemplate/search/report_tax.html | 36 |
2 files changed, 71 insertions, 22 deletions
diff --git a/httemplate/search/report_tax.cgi b/httemplate/search/report_tax.cgi index a7630dd2d..643ba52f3 100755 --- a/httemplate/search/report_tax.cgi +++ b/httemplate/search/report_tax.cgi @@ -174,7 +174,7 @@ <<%$td%>>Total</TD> <<%$td%> ALIGN="right"> <A HREF="<% $baselink %>;istax=1" - ><% &$money_sprintf( $tax ) %></A> + ><% &$money_sprintf( $tot_tax ) %></A> </TD> </TR> @@ -275,8 +275,16 @@ if ( $conf->exists('tax-pkg_address') ) { "WHERE 0 < ( SELECT COUNT(*) FROM cust_main WHERE $gotcust LIMIT 1 )"; } -my($total, $tot_taxable, $owed, $tax) = ( 0, 0, 0, 0 ); +#tax-report_groups filtering +my($group_op, $group_value) = ( '', '' ); +if ( $cgi->param('report_group') =~ /^(=|!=) (.*)$/ ) { + ( $group_op, $group_value ) = ( $1, $2 ); +} +my $skipping_out = $group_op ? 1 : 0; #in case there are other reasons + +my( $total, $tot_taxable, $tot_owed ) = ( 0, 0, 0 ); my( $exempt_cust, $exempt_pkg, $exempt_monthly ) = ( 0, 0, 0 ); + my $out = 'Out of taxable region(s)'; my %regions = (); @@ -326,8 +334,8 @@ foreach my $r ( qsearch({ 'table' => 'cust_main_county', my $t_sql = "SELECT SUM(cust_bill_pkg.setup+cust_bill_pkg.recur) $fromwhere AND $nottax"; my $t = scalar_sql($r, \@param, $t_sql); - $total += $t; $regions{$label}->{'total'} += $t; + $total += $t unless $label eq $out && $skipping_out; #if ( $label eq $out ) {# && $t ) { # warn "adding $t for ". @@ -356,8 +364,8 @@ foreach my $r ( qsearch({ 'table' => 'cust_main_county', $fromwhere AND $nottax AND tax = 'Y' " ); - $exempt_cust += $x_cust; $regions{$label}->{'exempt_cust'} += $x_cust; + $exempt_cust += $x_cust unless $label eq $out && $skipping_out; ## calculate package-exemption for this region @@ -384,8 +392,8 @@ foreach my $r ( qsearch({ 'table' => 'cust_main_county', AND ( tax != 'Y' OR tax IS NULL ) " ); - $exempt_pkg += $x_pkg; $regions{$label}->{'exempt_pkg'} += $x_pkg; + $exempt_pkg += $x_pkg unless $label eq $out && $skipping_out; ## calculate monthly exemption (texas tax) for this region @@ -404,16 +412,17 @@ foreach my $r ( qsearch({ 'table' => 'cust_main_county', # $taxable -= $x_monthly; # } - $exempt_monthly += $x_monthly; $regions{$label}->{'exempt_monthly'} += $x_monthly; + $exempt_monthly += $x_monthly unless $label eq $out && $skipping_out; my $taxable = $t - $x_cust - $x_pkg - $x_monthly; - $tot_taxable += $taxable; $regions{$label}->{'taxable'} += $taxable; + $tot_taxable += $taxable unless $label eq $out && $skipping_out; - $owed += $taxable * ($r->tax/100); - $regions{$label}->{'owed'} += $taxable * ($r->tax/100); + my $owed = $taxable * ($r->tax/100); + $regions{$label}->{'owed'} += $owed; + $tot_owed += $owed unless $label eq $out && $skipping_out; if ( defined($regions{$label}->{'rate'}) && $regions{$label}->{'rate'} != $r->tax.'%' ) { @@ -474,6 +483,7 @@ my $_taxamount_sub = sub { scalar_sql($r, \@taxparam, $sql ); }; +my $tot_tax = 0; #foreach my $label ( keys %regions ) { foreach my $r ( qsearch(\%qsearch) ) { @@ -486,8 +496,8 @@ foreach my $r ( qsearch(\%qsearch) ) { my $x = &{$_taxamount_sub}($r); - $tax += $x unless $cgi->param('show_taxclasses'); $regions{$label}->{'tax'} += $x; + $tot_tax += $x unless $cgi->param('show_taxclasses'); } @@ -508,17 +518,34 @@ if ( $cgi->param('show_taxclasses') ) { ); $base_regions{$base_label}->{'tax'} += $x; - $tax += $x; + $tot_tax += $x; } } +my @regions = keys %regions; + +#tax-report_groups filtering +if ( $group_op ) { + @regions = grep { + if ( $_ eq $out ) { #don't display "out of taxable region" in this case + 0; + } elsif ( $group_op eq '=' ) { + $_ =~ /^$group_value \(/; + } elsif ( $group_op eq '!=' ) { + $_ !~ /^$group_value \(/; + } else { + die "guru meditation #00de: group_op $group_op\n"; + } + } @regions; +} + #ordering -my @regions = +@regions = map $regions{$_}, sort { ( ($a eq $out) cmp ($b eq $out) ) || ($b cmp $a) } - keys %regions; + @regions; my @base_regions = map $base_regions{$_}, @@ -534,8 +561,8 @@ push @regions, { 'exempt_monthly' => $exempt_monthly, 'taxable' => $tot_taxable, 'rate' => '', - 'owed' => $owed, - 'tax' => $tax, + 'owed' => $tot_owed, + 'tax' => $tot_tax, }; #-- diff --git a/httemplate/search/report_tax.html b/httemplate/search/report_tax.html index e5ffa9a17..8640e0ee7 100755 --- a/httemplate/search/report_tax.html +++ b/httemplate/search/report_tax.html @@ -4,29 +4,49 @@ <TABLE> +% if ( $conf->config('tax-report_groups') ) { +% my @lines = $conf->config('tax-report_groups'); + + <TR> + <TD>Tax group</TD> + <TD> + <SELECT NAME="report_group"> + + <OPTION VALUE="">all</OPTION> + +% foreach my $line ( @lines ) { +% $line =~ /^\s*(.+)\s+(=|!=)\s+(.*)\s*$/ #or next; +% or do { warn "bad report_group line: $line\n"; next; }; +% my($label, $op, $value) = ($1, $2, $3); + + <OPTION VALUE="<% "$op $value" %>"><% $label %></OPTION> +% } + + </SELECT> + </TD> + </TR> + +% } + <% include( '/elements/tr-select-agent.html', 'disable_empty'=>0 ) %> <% include( '/elements/tr-input-beginning_ending.html' ) %> -% my $conf = new FS::Conf; -% if ( $conf->exists('enable_taxclasses') ) { -% +% if ( $conf->exists('enable_taxclasses') ) { <TR> <TD ALIGN="right"><INPUT TYPE="checkbox" NAME="show_taxclasses" VALUE="1"></TD> <TD>Show tax classes</TD> </TR> % } -% my @pkg_class = qsearch('pkg_class', {}); -% if ( @pkg_class ) { -% +% my @pkg_class = qsearch('pkg_class', {}); +% if ( @pkg_class ) { <TR> <TD ALIGN="right"><INPUT TYPE="checkbox" NAME="show_pkgclasses" VALUE="1"></TD> <TD>Show package classes</TD> </TR> % } - </TABLE> <BR><INPUT TYPE="submit" VALUE="Get Report"> @@ -39,4 +59,6 @@ die "access denied" unless $FS::CurrentUser::CurrentUser->access_right('Financial reports'); +my $conf = new FS::Conf; + </%init> |