diff options
author | jeff <jeff> | 2008-04-06 16:12:46 +0000 |
---|---|---|
committer | jeff <jeff> | 2008-04-06 16:12:46 +0000 |
commit | 6626dc2a13c809092aa539c5a72bc72a0c56afdc (patch) | |
tree | e92d2d1ea157b941f090a6f27cfbeb2db8dd12a3 /FS | |
parent | ebfc3f058e29e09631112ee355a2c57dce56914f (diff) |
new tax rating engine
Diffstat (limited to 'FS')
-rw-r--r-- | FS/FS/cust_bill.pm | 11 | ||||
-rw-r--r-- | FS/FS/cust_main.pm | 239 | ||||
-rw-r--r-- | FS/FS/cust_main_county.pm | 141 | ||||
-rw-r--r-- | FS/FS/part_pkg.pm | 31 | ||||
-rw-r--r-- | FS/FS/part_pkg_taxrate.pm | 7 | ||||
-rw-r--r-- | FS/FS/tax_rate.pm | 188 |
6 files changed, 368 insertions, 249 deletions
diff --git a/FS/FS/cust_bill.pm b/FS/FS/cust_bill.pm index eafe930..f536c97 100644 --- a/FS/FS/cust_bill.pm +++ b/FS/FS/cust_bill.pm @@ -2486,9 +2486,18 @@ sub _items_pkg { $self->_items_cust_bill_pkg(\@cust_bill_pkg, %options); } +sub _taxsort { + return 0 unless $a cmp $b; + return -1 if $b eq 'Tax'; + return 1 if $a eq 'Tax'; + return -1 if $b eq 'Other surcharges'; + return 1 if $a eq 'Other surcharges'; + $a cmp $b; +} + sub _items_tax { my $self = shift; - my @cust_bill_pkg = grep { ! $_->pkgnum } $self->cust_bill_pkg; + my @cust_bill_pkg = sort _taxsort grep { ! $_->pkgnum } $self->cust_bill_pkg; $self->_items_cust_bill_pkg(\@cust_bill_pkg, @_); } diff --git a/FS/FS/cust_main.pm b/FS/FS/cust_main.pm index 37f98c6..ceefeaf 100644 --- a/FS/FS/cust_main.pm +++ b/FS/FS/cust_main.pm @@ -45,8 +45,6 @@ use FS::part_pkg; use FS::part_event; use FS::part_event_condition; #use FS::cust_event; -use FS::cust_tax_exempt; -use FS::cust_tax_exempt_pkg; use FS::type_pkgs; use FS::payment_gateway; use FS::agent_payment_gateway; @@ -2078,6 +2076,7 @@ sub bill { my( $total_setup, $total_recur ) = ( 0, 0 ); my %tax; + my %taxlisthash; my @precommit_hooks = (); foreach my $cust_pkg ( @@ -2247,140 +2246,94 @@ sub bill { unless ( $self->tax =~ /Y/i || $self->payby eq 'COMP' ) { + my @taxes = (); + my @taxoverrides = $part_pkg->part_pkg_taxoverride; + my $prefix = ( $conf->exists('tax-ship_address') && length($self->ship_last) ) ? 'ship_' : ''; - my %taxhash = map { $_ => $self->get("$prefix$_") } - qw( state county country ); - $taxhash{'taxclass'} = $part_pkg->taxclass; + if ( $conf->exists('enable_taxproducts') + && (scalar(@taxoverrides) || $part_pkg->taxproductnum ) + ) + { - my @taxes = qsearch( 'cust_main_county', \%taxhash ); + my @taxclassnums = (); + my $geocode = $self->geocode('cch'); - unless ( @taxes ) { - $taxhash{'taxclass'} = ''; - @taxes = qsearch( 'cust_main_county', \%taxhash ); - } + if ( scalar( @taxoverrides ) ) { + @taxclassnums = map { $_->taxclassnum } @taxoverrides; + }elsif ( $part_pkg->taxproductnum ) { + @taxclassnums = map { $_->taxclassnum } + $part_pkg->part_pkg_taxrate('cch', $geocode); + } - #one more try at a whole-country tax rate - unless ( @taxes ) { - $taxhash{$_} = '' foreach qw( state county ); - @taxes = qsearch( 'cust_main_county', \%taxhash ); - } + my $extra_sql = + "AND (". + join(' OR ', map { "taxclassnum = $_" } @taxclassnums ). ")"; + + @taxes = qsearch({ 'table' => 'tax_rate', + 'hashref' => { 'geocode' => $geocode, }, + 'extra_sql' => $extra_sql, + }) + if scalar(@taxclassnums); + + + }else{ + + my %taxhash = map { $_ => $self->get("$prefix$_") } + qw( state county country ); + + $taxhash{'taxclass'} = $part_pkg->taxclass; + + @taxes = qsearch( 'cust_main_county', \%taxhash ); + + unless ( @taxes ) { + $taxhash{'taxclass'} = ''; + @taxes = qsearch( 'cust_main_county', \%taxhash ); + } + + #one more try at a whole-country tax rate + unless ( @taxes ) { + $taxhash{$_} = '' foreach qw( state county ); + @taxes = qsearch( 'cust_main_county', \%taxhash ); + } + + } #if $conf->exists('enable_taxproducts') # maybe eliminate this entirely, along with all the 0% records unless ( @taxes ) { $dbh->rollback if $oldAutoCommit; - return - "fatal: can't find tax rate for state/county/country/taxclass ". - join('/', ( map $self->get("$prefix$_"), - qw(state county country) - ), - $part_pkg->taxclass ). "\n"; + my $error; + if ( $conf->exists('enable_taxproducts') ) { + $error = + "fatal: can't find tax rate for zip/taxproduct/pkgpart ". + join('/', ( map $self->get("$prefix$_"), + qw(zip) + ), + $part_pkg->taxproduct_description, + $part_pkg->pkgpart ). "\n"; + }else{ + $error = + "fatal: can't find tax rate for state/county/country/taxclass ". + join('/', ( map $self->get("$prefix$_"), + qw(state county country) + ), + $part_pkg->taxclass ). "\n"; + } + return $error; } foreach my $tax ( @taxes ) { + my $taxname = ref( $tax ). ' '. $tax->taxnum; + if ( exists( $taxlisthash{ $taxname } ) ) { + push @{ $taxlisthash{ $taxname } }, $cust_bill_pkg; + }else{ + $taxlisthash{ $taxname } = [ $tax, $cust_bill_pkg ]; + } + } - my $taxable_charged = 0; - $taxable_charged += $setup - unless $part_pkg->setuptax =~ /^Y$/i - || $tax->setuptax =~ /^Y$/i; - $taxable_charged += $recur - unless $part_pkg->recurtax =~ /^Y$/i - || $tax->recurtax =~ /^Y$/i; - next unless $taxable_charged; - - if ( $tax->exempt_amount && $tax->exempt_amount > 0 ) { - #my ($mon,$year) = (localtime($sdate) )[4,5]; - my ($mon,$year) = (localtime( $sdate || $cust_bill->_date ) )[4,5]; - $mon++; - my $freq = $part_pkg->freq || 1; - if ( $freq !~ /(\d+)$/ ) { - $dbh->rollback if $oldAutoCommit; - return "daily/weekly package definitions not (yet?)". - " compatible with monthly tax exemptions"; - } - my $taxable_per_month = - sprintf("%.2f", $taxable_charged / $freq ); - - #call the whole thing off if this customer has any old - #exemption records... - my @cust_tax_exempt = - qsearch( 'cust_tax_exempt' => { custnum=> $self->custnum } ); - if ( @cust_tax_exempt ) { - $dbh->rollback if $oldAutoCommit; - return - 'this customer still has old-style tax exemption records; '. - 'run bin/fs-migrate-cust_tax_exempt?'; - } - - foreach my $which_month ( 1 .. $freq ) { - - #maintain the new exemption table now - my $sql = " - SELECT SUM(amount) - FROM cust_tax_exempt_pkg - LEFT JOIN cust_bill_pkg USING ( billpkgnum ) - LEFT JOIN cust_bill USING ( invnum ) - WHERE custnum = ? - AND taxnum = ? - AND year = ? - AND month = ? - "; - my $sth = dbh->prepare($sql) or do { - $dbh->rollback if $oldAutoCommit; - return "fatal: can't lookup exising exemption: ". dbh->errstr; - }; - $sth->execute( - $self->custnum, - $tax->taxnum, - 1900+$year, - $mon, - ) or do { - $dbh->rollback if $oldAutoCommit; - return "fatal: can't lookup exising exemption: ". dbh->errstr; - }; - my $existing_exemption = $sth->fetchrow_arrayref->[0] || 0; - - my $remaining_exemption = - $tax->exempt_amount - $existing_exemption; - if ( $remaining_exemption > 0 ) { - my $addl = $remaining_exemption > $taxable_per_month - ? $taxable_per_month - : $remaining_exemption; - $taxable_charged -= $addl; - - my $cust_tax_exempt_pkg = new FS::cust_tax_exempt_pkg ( { - 'billpkgnum' => $cust_bill_pkg->billpkgnum, - 'taxnum' => $tax->taxnum, - 'year' => 1900+$year, - 'month' => $mon, - 'amount' => sprintf("%.2f", $addl ), - } ); - $error = $cust_tax_exempt_pkg->insert; - if ( $error ) { - $dbh->rollback if $oldAutoCommit; - return "fatal: can't insert cust_tax_exempt_pkg: $error"; - } - } # if $remaining_exemption > 0 - - #++ - $mon++; - #until ( $mon < 12 ) { $mon -= 12; $year++; } - until ( $mon < 13 ) { $mon -= 12; $year++; } - - } #foreach $which_month - - } #if $tax->exempt_amount - - $taxable_charged = sprintf( "%.2f", $taxable_charged); - - #$tax += $taxable_charged * $cust_main_county->tax / 100 - $tax{ $tax->taxname || 'Tax' } += - $taxable_charged * $tax->tax / 100 - - } #foreach my $tax ( @taxes ) } #unless $self->tax =~ /Y/i || $self->payby eq 'COMP' @@ -2410,6 +2363,18 @@ sub bill { my $charged = sprintf( "%.2f", $total_setup + $total_recur ); + foreach my $tax ( keys %taxlisthash ) { + my $tax_object = shift @{ $taxlisthash{$tax} }; + my $listref_or_error = $tax_object->taxline( @{ $taxlisthash{$tax} } ); + unless (ref($listref_or_error)) { + $dbh->rollback if $oldAutoCommit; + return $listref_or_error; + } + + $tax{ $listref_or_error->[0] } += $listref_or_error->[1]; + + } + foreach my $taxname ( grep { $tax{$_} > 0 } keys %tax ) { my $tax = sprintf("%.2f", $tax{$taxname} ); $charged = sprintf( "%.2f", $charged+$tax ); @@ -4862,6 +4827,40 @@ sub country_full { code2country($self->country); } +=item geocode DATA_PROVIDER + +Returns a value for the customer location as encoded by DATA_PROVIDER. +Currently this only makes sense for "CCH" as DATA_PROVIDER. + +=cut + +sub geocode { + my ($self, $data_provider) = (shift, shift); #always cch for now + + my $prefix = ( $conf->exists('tax-ship_address') && length($self->ship_last) ) + ? 'ship_' + : ''; + + my ($zip,$plus4) = split /-/, $self->get("${prefix}zip") + if $self->country eq 'US'; + + #CCH specific location stuff + my $extra_sql = "AND plus4lo <= '$plus4' AND plus4hi >= '$plus4'"; + + my $geocode = ''; + my $cust_tax_location = + qsearchs( { + 'table' => 'cust_tax_location', + 'hashref' => { 'zip' => $zip, 'data_provider' => $data_provider }, + 'extra_sql' => $extra_sql, + } + ); + $geocode = $cust_tax_location->geocode + if $cust_tax_location; + + $geocode; +} + =item cust_status =item status diff --git a/FS/FS/cust_main_county.pm b/FS/FS/cust_main_county.pm index 17f3460..3a0304b 100644 --- a/FS/FS/cust_main_county.pm +++ b/FS/FS/cust_main_county.pm @@ -4,7 +4,13 @@ use strict; use vars qw( @ISA @EXPORT_OK $conf @cust_main_county %cust_main_county $countyflag ); use Exporter; -use FS::Record qw( qsearch ); +use FS::Record qw( qsearch dbh ); +use FS::cust_bill_pkg; +use FS::cust_bill; +use FS::cust_pkg; +use FS::part_pkg; +use FS::cust_tax_exempt; +use FS::cust_tax_exempt_pkg; @ISA = qw( FS::Record ); @EXPORT_OK = qw( regionselector ); @@ -151,6 +157,139 @@ sub recurtax { return ''; } +=item taxline CUST_BILL_PKG, ... + +Returns a listref of a name and an amount of tax calculated for the list of +packages. Returns a scalar error message on error. + +=cut + +sub taxline { + my $self = shift; + + local $SIG{HUP} = 'IGNORE'; + local $SIG{INT} = 'IGNORE'; + local $SIG{QUIT} = 'IGNORE'; + local $SIG{TERM} = 'IGNORE'; + local $SIG{TSTP} = 'IGNORE'; + local $SIG{PIPE} = 'IGNORE'; + + my $oldAutoCommit = $FS::UID::AutoCommit; + local $FS::UID::AutoCommit = 0; + my $dbh = dbh; + + my $name = $self->taxname || 'Tax'; + my $amount = 0; + + foreach my $cust_bill_pkg (@_) { + + my $cust_bill = $cust_bill_pkg->cust_pkg->cust_bill; + my $part_pkg = $cust_bill_pkg->cust_pkg->part_pkg; + + my $taxable_charged = 0; + $taxable_charged += $cust_bill_pkg->setup + unless $part_pkg->setuptax =~ /^Y$/i + || $self->setuptax =~ /^Y$/i; + $taxable_charged += $cust_bill_pkg->recur + unless $part_pkg->recurtax =~ /^Y$/i + || $self->recurtax =~ /^Y$/i; + + return [ $name, 0 ] + unless $taxable_charged; + + if ( $self->exempt_amount && $self->exempt_amount > 0 ) { + #my ($mon,$year) = (localtime($cust_bill_pkg->sdate) )[4,5]; + my ($mon,$year) = + (localtime( $cust_bill_pkg->sdate || $cust_bill->_date ) )[4,5]; + $mon++; + my $freq = $part_pkg->freq || 1; + if ( $freq !~ /(\d+)$/ ) { + $dbh->rollback if $oldAutoCommit; + return "daily/weekly package definitions not (yet?)". + " compatible with monthly tax exemptions"; + } + my $taxable_per_month = + sprintf("%.2f", $taxable_charged / $freq ); + + #call the whole thing off if this customer has any old + #exemption records... + my @cust_tax_exempt = + qsearch( 'cust_tax_exempt' => { custnum=> $cust_bill->custnum } ); + if ( @cust_tax_exempt ) { + $dbh->rollback if $oldAutoCommit; + return + 'this customer still has old-style tax exemption records; '. + 'run bin/fs-migrate-cust_tax_exempt?'; + } + + foreach my $which_month ( 1 .. $freq ) { + + #maintain the new exemption table now + my $sql = " + SELECT SUM(amount) + FROM cust_tax_exempt_pkg + LEFT JOIN cust_bill_pkg USING ( billpkgnum ) + LEFT JOIN cust_bill USING ( invnum ) + WHERE custnum = ? + AND taxnum = ? + AND year = ? + AND month = ? + "; + my $sth = dbh->prepare($sql) or do { + $dbh->rollback if $oldAutoCommit; + return "fatal: can't lookup exising exemption: ". dbh->errstr; + }; + $sth->execute( + $cust_bill->custnum, + $self->taxnum, + 1900+$year, + $mon, + ) or do { + $dbh->rollback if $oldAutoCommit; + return "fatal: can't lookup exising exemption: ". dbh->errstr; + }; + my $existing_exemption = $sth->fetchrow_arrayref->[0] || 0; + + my $remaining_exemption = + $self->exempt_amount - $existing_exemption; + if ( $remaining_exemption > 0 ) { + my $addl = $remaining_exemption > $taxable_per_month + ? $taxable_per_month + : $remaining_exemption; + $taxable_charged -= $addl; + + my $cust_tax_exempt_pkg = new FS::cust_tax_exempt_pkg ( { + 'billpkgnum' => $cust_bill_pkg->billpkgnum, + 'taxnum' => $self->taxnum, + 'year' => 1900+$year, + 'month' => $mon, + 'amount' => sprintf("%.2f", $addl ), + } ); + my $error = $cust_tax_exempt_pkg->insert; + if ( $error ) { + $dbh->rollback if $oldAutoCommit; + return "fatal: can't insert cust_tax_exempt_pkg: $error"; + } + } # if $remaining_exemption > 0 + + #++ + $mon++; + #until ( $mon < 12 ) { $mon -= 12; $year++; } + until ( $mon < 13 ) { $mon -= 12; $year++; } + + } #foreach $which_month + + } #if $tax->exempt_amount + + $taxable_charged = sprintf( "%.2f", $taxable_charged); + + $amount += $taxable_charged * $self->tax / 100 + } + + $dbh->commit or die $dbh->errstr if $oldAutoCommit; + return [ $name, $amount ] +} + =back =head1 SUBROUTINES diff --git a/FS/FS/part_pkg.pm b/FS/FS/part_pkg.pm index dc0a4d5..1e16f29 100644 --- a/FS/FS/part_pkg.pm +++ b/FS/FS/part_pkg.pm @@ -756,6 +756,37 @@ sub taxproduct_description { $part_pkg_taxproduct ? $part_pkg_taxproduct->description : ''; } +=item part_pkg_taxrate DATA_PROVIDER, GEOCODE + +Returns the package to taxrate m2m records for this package in the location +specified by GEOCODE (see L<FS::part_pkg_taxrate> and ). + +=cut + +sub part_pkg_taxrate { + my $self = shift; + my ($data_provider, $geocode) = @_; + + my $dbh = dbh; + # CCH oddness in m2m + my $extra_sql = 'AND ('. + join(' OR ', map{ 'geocode = '. $dbh->quote(substr($geocode, 0, $_)) } + qw(10 5 2) + ). + ')'; + my $order_by = 'ORDER BY taxclassnum, length(geocode) desc'; + my $select = 'DISTINCT ON(taxclassnum) *'; + + qsearch( { 'table' => 'part_pkg_taxrate', + 'select' => 'distinct on(taxclassnum) *', + 'hashref' => { 'data_provider' => $data_provider, + 'taxproductnum' => $self->taxproductnum, + }, + 'extra_sql' => $extra_sql, + 'order_by' => $order_by, + } ); +} + =item _rebless Reblesses the object into the FS::part_pkg::PLAN class (if available), where diff --git a/FS/FS/part_pkg_taxrate.pm b/FS/FS/part_pkg_taxrate.pm index aa1c3df..3e7e7bd 100644 --- a/FS/FS/part_pkg_taxrate.pm +++ b/FS/FS/part_pkg_taxrate.pm @@ -211,11 +211,12 @@ sub batch_import { my $part_pkg_taxproduct = qsearchs( 'part_pkg_taxproduct', { %part_pkg_taxproduct } ); + unless ($part_pkg_taxproduct) { $part_pkg_taxproduct{'description'} = - join(' : ', map{ $hash->{$_} } qw(groupdesc itemdesc), - $providers{$hash->{'provider'}} || 'Unknown', - $customers{$hash->{'customer'}} || 'Unknown', + join(' : ', (map{ $hash->{$_} } qw(groupdesc itemdesc)), + $providers{$hash->{'provider'}}, + $customers{$hash->{'customer'}}, ); $part_pkg_taxproduct = new FS::part_pkg_taxproduct \%part_pkg_taxproduct; my $error = $part_pkg_taxproduct->insert; diff --git a/FS/FS/tax_rate.pm b/FS/FS/tax_rate.pm index 38e5343..3d56a0d 100644 --- a/FS/FS/tax_rate.pm +++ b/FS/FS/tax_rate.pm @@ -1,30 +1,19 @@ package FS::tax_rate; use strict; -use vars qw( @ISA @EXPORT_OK $conf $DEBUG $me +use vars qw( @ISA $DEBUG $me %tax_unittypes %tax_maxtypes %tax_basetypes %tax_authorities - %tax_passtypes - @tax_rate %tax_rate $countyflag ); -use Exporter; + %tax_passtypes ); use Date::Parse; -use Tie::IxHash; -use FS::Record qw( qsearchs qsearch dbh ); +use FS::Record qw( qsearchs dbh ); use FS::tax_class; +use FS::cust_bill_pkg; @ISA = qw( FS::Record ); -@EXPORT_OK = qw( regionselector ); -$DEBUG = 1; +$DEBUG = 0; $me = '[FS::tax_rate]'; -@tax_rate = (); -$countyflag = ''; - -#ask FS::UID to run this stuff for us later -$FS::UID::callback{'FS::tax_rate'} = sub { - $conf = new FS::Conf; -}; - =head1 NAME FS::tax_rate - Object methods for tax_rate objects @@ -44,9 +33,6 @@ FS::tax_rate - Object methods for tax_rate objects $error = $record->check; - ($county_html, $state_html, $country_html) = - FS::tax_rate::regionselector( $county, $state, $country ); - =head1 DESCRIPTION An FS::tax_rate object represents a tax rate, defined by locale. @@ -75,8 +61,7 @@ a location code provided by a tax authority a foreign key into FS::tax_class - the type of tax referenced but FS::part_pkg_taxrate - -=item effective_date +eitem effective_date the time after which the tax applies @@ -349,128 +334,81 @@ sub passtype_name { $tax_passtypes{$self->passtype}; } -=back - -=head1 SUBROUTINES +=item taxline CUST_BILL_PKG, ... -=over 4 - -=item regionselector [ COUNTY STATE COUNTRY [ PREFIX [ ONCHANGE [ DISABLED ] ] ] ] +Returns a listref of a name and an amount of tax calculated for the list +of packages. If an error occurs, a message is returned as a scalar. =cut -sub regionselector { - my ( $selected_county, $selected_state, $selected_country, - $prefix, $onchange, $disabled ) = @_; - - $prefix = '' unless defined $prefix; - - $countyflag = 0; +sub taxline { + my $self = shift; + my @cust_bill_pkg = @_; -# unless ( @tax_rate ) { #cache - @tax_rate = qsearch('tax_rate', {} ); - foreach my $c ( @tax_rate ) { - $countyflag=1 if $c->county; - #push @{$tax_rate{$c->country}{$c->state}}, $c->county; - $tax_rate{$c->country}{$c->state}{$c->county} = 1; - } -# } - $countyflag=1 if $selected_county; - - my $script_html = <<END; - <SCRIPT> - function opt(what,value,text) { - var optionName = new Option(text, value, false, false); - var length = what.length; - what.options[length] = optionName; - } - function ${prefix}country_changed(what) { - country = what.options[what.selectedIndex].text; - for ( var i = what.form.${prefix}state.length; i >= 0; i-- ) - what.form.${prefix}state.options[i] = null; -END - #what.form.${prefix}state.options[0] = new Option('', '', false, true); - - foreach my $country ( sort keys %tax_rate ) { - $script_html .= "\nif ( country == \"$country\" ) {\n"; - foreach my $state ( sort keys %{$tax_rate{$country}} ) { - ( my $dstate = $state ) =~ s/[\n\r]//g; - my $text = $dstate || '(n/a)'; - $script_html .= qq!opt(what.form.${prefix}state, "$dstate", "$text");\n!; - } - $script_html .= "}\n"; + if ($self->passflag eq 'N') { + return "fatal: can't (yet) handle taxes not passed to the customer"; } - $script_html .= <<END; - } - function ${prefix}state_changed(what) { -END - - if ( $countyflag ) { - $script_html .= <<END; - state = what.options[what.selectedIndex].text; - country = what.form.${prefix}country.options[what.form.${prefix}country.selectedIndex].text; - for ( var i = what.form.${prefix}county.length; i >= 0; i-- ) - what.form.${prefix}county.options[i] = null; -END - - foreach my $country ( sort keys %tax_rate ) { - $script_html .= "\nif ( country == \"$country\" ) {\n"; - foreach my $state ( sort keys %{$tax_rate{$country}} ) { - $script_html .= "\nif ( state == \"$state\" ) {\n"; - #foreach my $county ( sort @{$tax_rate{$country}{$state}} ) { - foreach my $county ( sort keys %{$tax_rate{$country}{$state}} ) { - my $text = $county || '(n/a)'; - $script_html .= - qq!opt(what.form.${prefix}county, "$county", "$text");\n!; - } - $script_html .= "}\n"; - } - $script_html .= "}\n"; - } + if ($self->maxtype != 0 && $self->maxtype != 9) { + return qq!fatal: can't (yet) handle tax with "!. $self->maxtype_name. + '" threshold'; } - $script_html .= <<END; - } - </SCRIPT> -END - - my $county_html = $script_html; - if ( $countyflag ) { - $county_html .= qq!<SELECT NAME="${prefix}county" onChange="$onchange" $disabled>!; - $county_html .= '</SELECT>'; - } else { - $county_html .= - qq!<INPUT TYPE="hidden" NAME="${prefix}county" VALUE="$selected_county">!; + if ($self->maxtype == 9) { + return qq!fatal: can't (yet) handle tax with "!. $self->maxtype_name. + '" threshold'; # "texas" tax } - my $state_html = qq!<SELECT NAME="${prefix}state" !. - qq!onChange="${prefix}state_changed(this); $onchange" $disabled>!; - foreach my $state ( sort keys %{ $tax_rate{$selected_country} } ) { - my $text = $state || '(n/a)'; - my $selected = $state eq $selected_state ? 'SELECTED' : ''; - $state_html .= qq(\n<OPTION $selected VALUE="$state">$text</OPTION>); + if ($self->basetype != 0 && $self->basetype != 1 && + $self->basetype != 6 && $self->basetype != 7 && + $self->basetype != 14 + ) { + return qq!fatal: can't (yet) handle tax with "!. $self->basetype_name. + '" basis'; } - $state_html .= '</SELECT>'; - $state_html .= '</SELECT>'; + my $name = $self->taxname; + $name = 'Other surcharges' + if ($self->passtype == 2); + my $amount = 0; + + my $taxable_charged = 0; + unless ($self->setuptax =~ /^Y$/i) { + $taxable_charged += $_->setup foreach @cust_bill_pkg; + } + unless ($self->recurtax =~ /^Y$/i) { + $taxable_charged += $_->recur foreach @cust_bill_pkg; + } - my $country_html = qq!<SELECT NAME="${prefix}country" !. - qq!onChange="${prefix}country_changed(this); $onchange" $disabled>!; - my $countrydefault = $conf->config('countrydefault') || 'US'; - foreach my $country ( - sort { ($b eq $countrydefault) <=> ($a eq $countrydefault) or $a cmp $b } - keys %tax_rate - ) { - my $selected = $country eq $selected_country ? ' SELECTED' : ''; - $country_html .= qq(\n<OPTION$selected VALUE="$country">$country</OPTION>"); + my $taxable_units = 0; + unless ($self->recurtax =~ /^Y$/i) { + $taxable_units += $_->units foreach @cust_bill_pkg; } - $country_html .= '</SELECT>'; - ($county_html, $state_html, $country_html); + # + # XXX insert exemption handling here + # + # the tax or fee is applied to taxbase or feebase and then + # the excessrate or excess fee is applied to taxmax or feemax + # + + $amount += $taxable_charged * $self->tax; + $amount += $taxable_units * $self->fee; + + return [$name, $amount]; } +=back + +=head1 SUBROUTINES + +=over 4 + +=item batch_import + +=cut + sub batch_import { my $param = shift; @@ -518,6 +456,8 @@ sub batch_import { if length($hash->{$_}) > 80; } + ''; + }; } elsif ( $format eq 'extended' ) { |