From 74cb9e1c3974d8899bf9745564d0dfce5875454c Mon Sep 17 00:00:00 2001 From: ivan Date: Mon, 22 Jun 2009 10:06:11 +0000 Subject: [PATCH] finish basic implemention of tax exemption by tax name hack, RT#5127 --- FS/FS/Conf.pm | 2 +- FS/FS/cust_main.pm | 30 +++++++++++++++++++++--------- httemplate/search/cust_bill_pkg.cgi | 19 ++++++++++++++++++- httemplate/search/report_tax.cgi | 18 +++++++++++++++++- 4 files changed, 57 insertions(+), 12 deletions(-) diff --git a/FS/FS/Conf.pm b/FS/FS/Conf.pm index 543c77027..a9b891c8b 100644 --- a/FS/FS/Conf.pm +++ b/FS/FS/Conf.pm @@ -2830,7 +2830,7 @@ worry that config_items is freeside-specific and icky. { 'key' => 'tax-cust_exempt-groups', 'section' => '', - 'description' => 'List of grouping possibilities for tax names, for per-customer exemption purposes, one tax name prefix for line. For example, "GST" would indicate the ability to exempt customers individually from taxes starting with "GST" (but not other taxes).', + 'description' => 'List of grouping possibilities for tax names, for per-customer exemption purposes, one tax name per line. For example, "GST" would indicate the ability to exempt customers individually from taxes named "GST" (but not other taxes).', 'type' => 'textarea', }, diff --git a/FS/FS/cust_main.pm b/FS/FS/cust_main.pm index 51ba20920..ed16e1b9e 100644 --- a/FS/FS/cust_main.pm +++ b/FS/FS/cust_main.pm @@ -2972,6 +2972,10 @@ sub _handle_taxes { @taxes = qsearch( 'cust_main_county', \%taxhash_elim ); } + @taxes = grep { ! $_->taxname or ! $self->tax_exemption($_->taxname) } + @taxes + if $self->cust_main_exemption; #just to be safe + if ( $conf->exists('tax-pkg_address') && $cust_pkg->locationnum ) { foreach (@taxes) { $_->set('pkgnum', $cust_pkg->pkgnum ); @@ -2984,12 +2988,12 @@ sub _handle_taxes { $taxes{'recur'} = [ @taxes ]; $taxes{$_} = [ @taxes ] foreach (@classes); - # maybe eliminate this entirely, along with all the 0% records - unless ( @taxes ) { - return - "fatal: can't find tax rate for state/county/country/taxclass ". - join('/', map $taxhash{$_}, qw(state county country taxclass) ); - } + # # maybe eliminate this entirely, along with all the 0% records + # unless ( @taxes ) { + # return + # "fatal: can't find tax rate for state/county/country/taxclass ". + # join('/', map $taxhash{$_}, qw(state county country taxclass) ); + # } } #if $conf->exists('enable_taxproducts') ... @@ -6384,12 +6388,20 @@ sub tax_exemption { my( $self, $taxname ) = @_; qsearchs( 'cust_main_exemption', { 'custnum' => $self->custnum, - 'taxname' => { 'op' => 'LIKE', - 'value' => $taxname.'%' }, - }, + 'taxname' => $taxname, + }, ); } +=item cust_main_exemption + +=cut + +sub cust_main_exemption { + my $self = shift; + qsearch( 'cust_main_exemption', { 'custnum' => $self->custnum } ); +} + =item invoicing_list [ ARRAYREF ] If an arguement is given, sets these email addresses as invoice recipients diff --git a/httemplate/search/cust_bill_pkg.cgi b/httemplate/search/cust_bill_pkg.cgi index 4654425c9..4a31611cd 100644 --- a/httemplate/search/cust_bill_pkg.cgi +++ b/httemplate/search/cust_bill_pkg.cgi @@ -274,7 +274,24 @@ if ( $cgi->param('report_group') =~ /^(=|!=) (.*)$/ && $cgi->param('istax') ) { push @where, 'cust_bill_pkg.pkgnum != 0' if $cgi->param('nottax'); push @where, 'cust_bill_pkg.pkgnum = 0' if $cgi->param('istax'); -push @where, " tax = 'Y' " if $cgi->param('cust_tax'); +if ( $cgi->param('cust_tax') ) { + #false laziness -ish w/report_tax.cgi + my $cust_exempt; + if ( $cgi->param('taxname') ) { + my $q_taxname = dbh->quote($cgi->param('taxname')); + $cust_exempt = + "( tax = 'Y' + OR EXISTS ( SELECT 1 FROM cust_main_exemption + WHERE cust_main_exemption.custnum = cust_main.custnum + AND cust_main_exemption.taxname = $q_taxname ) + ) + "; + } else { + $cust_exempt = " tax = 'Y' "; + } + + push @where, $cust_exempt; +} my $count_query; if ( $cgi->param('pkg_tax') ) { diff --git a/httemplate/search/report_tax.cgi b/httemplate/search/report_tax.cgi index bcceaf175..e89c66536 100755 --- a/httemplate/search/report_tax.cgi +++ b/httemplate/search/report_tax.cgi @@ -355,9 +355,25 @@ foreach my $r ( qsearch({ 'table' => 'cust_main_county', # ); # } + #false laziness -ish w/report_tax.cgi + my $cust_exempt; + if ( $r->taxname ) { + my $q_taxname = dbh->quote($r->taxname); + $cust_exempt = + "( tax = 'Y' + OR EXISTS ( SELECT 1 FROM cust_main_exemption + WHERE cust_main_exemption.custnum = cust_main.custnum + AND cust_main_exemption.taxname = $q_taxname + ) + ) + "; + } else { + $cust_exempt = " tax = 'Y' "; + } + my $x_cust = scalar_sql($r, \@param, "SELECT SUM(cust_bill_pkg.setup+cust_bill_pkg.recur) - $fromwhere AND $nottax AND tax = 'Y' " + $fromwhere AND $nottax AND $cust_exempt " ); $regions{$label}->{'exempt_cust'} += $x_cust; -- 2.11.0