From 8d9be02c9965db4c4a48a2221455160685a95462 Mon Sep 17 00:00:00 2001 From: ivan Date: Tue, 26 May 2009 01:35:16 +0000 Subject: [PATCH] add a config option for some basic tax grouping by name, RT#5446 --- FS/FS/Conf.pm | 9 ++++++- httemplate/search/report_tax.cgi | 57 ++++++++++++++++++++++++++++----------- httemplate/search/report_tax.html | 36 ++++++++++++++++++++----- 3 files changed, 79 insertions(+), 23 deletions(-) diff --git a/FS/FS/Conf.pm b/FS/FS/Conf.pm index 87e8517de..8b27610a7 100644 --- a/FS/FS/Conf.pm +++ b/FS/FS/Conf.pm @@ -1380,7 +1380,7 @@ worry that config_items is freeside-specific and icky. { 'key' => 'selfservice_server-base_url', 'section' => '', - 'description' => 'Base URL for the self-service web interface - necessary for special provisioning widgets to find their way.', + 'description' => 'Base URL for the self-service web interface - necessary for some widgets to find their way, including retrieval of non-US state information and phone number provisioning.', 'type' => 'text', }, @@ -2802,6 +2802,13 @@ worry that config_items is freeside-specific and icky. 'type' => 'text', }, + { + 'key' => 'tax-report_groups', + 'section' => '', + 'description' => 'List of grouping possibilities for tax names on reports, one per line, "label op value" (op can be = or !=).', + 'type' => 'textarea', + }, + ); 1; 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%> ALIGN="right"> <% &$money_sprintf( $tax ) %> + ><% &$money_sprintf( $tot_tax ) %> @@ -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 @@ +% if ( $conf->config('tax-report_groups') ) { +% my @lines = $conf->config('tax-report_groups'); + + + + + + +% } + <% 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') ) { % } -% my @pkg_class = qsearch('pkg_class', {}); -% if ( @pkg_class ) { -% +% my @pkg_class = qsearch('pkg_class', {}); +% if ( @pkg_class ) { % } -
Tax group + +
Show tax classes
Show package classes

@@ -39,4 +59,6 @@ die "access denied" unless $FS::CurrentUser::CurrentUser->access_right('Financial reports'); +my $conf = new FS::Conf; + -- 2.11.0