X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=FS%2FFS%2Fcust_main_county.pm;h=075ac32789bd10efd23c48e130ff19dce8bc5fcd;hb=35c18f29bc29dedfe2fa4ef037390d90b17f87ba;hp=10a007c57899c50b4cbda2be07c2c69f8b160e03;hpb=83a88f9294aa7db638e316df1ed0964901cdb370;p=freeside.git diff --git a/FS/FS/cust_main_county.pm b/FS/FS/cust_main_county.pm index 10a007c57..075ac3278 100644 --- a/FS/FS/cust_main_county.pm +++ b/FS/FS/cust_main_county.pm @@ -1,7 +1,8 @@ package FS::cust_main_county; +use base qw( FS::Record ); use strict; -use vars qw( @ISA @EXPORT_OK $conf +use vars qw( @EXPORT_OK $conf @cust_main_county %cust_main_county $countyflag ); # $cityflag ); use Exporter; use FS::Record qw( qsearch qsearchs dbh ); @@ -12,7 +13,6 @@ use FS::part_pkg; use FS::cust_tax_exempt; use FS::cust_tax_exempt_pkg; -@ISA = qw( FS::Record ); @EXPORT_OK = qw( regionselector ); @cust_main_county = (); @@ -278,10 +278,11 @@ sub taxline { my $custnum = $cust_bill ? $cust_bill->custnum : $opt{'custnum'}; my $invoice_time = $cust_bill ? $cust_bill->_date : $opt{'invoice_time'}; my $cust_main = FS::cust_main->by_key($custnum) if $custnum > 0; - if (!$cust_main) { - # better way to handle this? should we just assume that it's taxable? - die "unable to calculate taxes for an unknown customer\n"; - } + # (to avoid complications with estimated tax on quotations, assume it's + # taxable if there is no customer) + #if (!$cust_main) { + #die "unable to calculate taxes for an unknown customer\n"; + #} # set a flag if the customer is tax-exempt my $exempt_cust; @@ -313,9 +314,15 @@ sub taxline { my @tax_location; foreach my $cust_bill_pkg (@$taxables) { + # careful... may be a cust_bill_pkg or a quotation_pkg my $cust_pkg = $cust_bill_pkg->cust_pkg; my $part_pkg = $cust_bill_pkg->part_pkg; + my $part_fee = $cust_bill_pkg->part_fee; + + my $locationnum = $cust_pkg + ? $cust_pkg->locationnum + : $cust_main->bill_locationnum; my @new_exemptions; my $taxable_charged = $cust_bill_pkg->setup + $cust_bill_pkg->recur @@ -341,8 +348,13 @@ sub taxline { } - if ( ($part_pkg->setuptax eq 'Y' or $self->setuptax eq 'Y') - and $cust_bill_pkg->setup > 0 and $taxable_charged > 0 ) { + my $setup_exempt = ( ($part_fee and not $part_fee->taxable) + or ($part_pkg and $part_pkg->setuptax) + or $self->setuptax ); + + if ( $setup_exempt + and $cust_bill_pkg->setup > 0 + and $taxable_charged > 0 ) { push @new_exemptions, FS::cust_tax_exempt_pkg->new({ amount => $cust_bill_pkg->setup, @@ -351,8 +363,14 @@ sub taxline { $taxable_charged -= $cust_bill_pkg->setup; } - if ( ($part_pkg->recurtax eq 'Y' or $self->recurtax eq 'Y') - and $cust_bill_pkg->recur > 0 and $taxable_charged > 0 ) { + + my $recur_exempt = ( ($part_fee and not $part_fee->taxable) + or ($part_pkg and $part_pkg->recurtax) + or $self->recurtax ); + + if ( $recur_exempt + and $cust_bill_pkg->recur > 0 + and $taxable_charged > 0 ) { push @new_exemptions, FS::cust_tax_exempt_pkg->new({ amount => $cust_bill_pkg->recur, @@ -363,7 +381,11 @@ sub taxline { } if ( $self->exempt_amount && $self->exempt_amount > 0 - and $taxable_charged > 0 ) { + and $taxable_charged > 0 + and $cust_main ) { + + # XXX monthly exemptions currently don't work on quotations + # If the billing period extends across multiple calendar months, # there may be several months of exemption available. my $sdate = $cust_bill_pkg->sdate || $invoice_time; @@ -477,7 +499,7 @@ sub taxline { } } - } # if exempt_amount + } # if exempt_amount and $cust_main $_->taxnum($self->taxnum) foreach @new_exemptions; @@ -494,7 +516,7 @@ sub taxline { 'taxtype' => ref($self), 'cents' => $this_tax_cents, 'pkgnum' => $cust_bill_pkg->pkgnum, - 'locationnum' => $cust_bill_pkg->cust_pkg->tax_locationnum, + 'locationnum' => $locationnum, 'taxable_cust_bill_pkg' => $cust_bill_pkg, 'tax_cust_bill_pkg' => $tax_item, });