X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=FS%2FFS%2Fcust_main_county.pm;h=075ac32789bd10efd23c48e130ff19dce8bc5fcd;hb=35c18f29bc29dedfe2fa4ef037390d90b17f87ba;hp=5c1be7b4657b3756a2692f4bb2d7e2ae3718ed72;hpb=32072dbf59a054529f5304574c0f56f9567d14d0;p=freeside.git diff --git a/FS/FS/cust_main_county.pm b/FS/FS/cust_main_county.pm index 5c1be7b46..075ac3278 100644 --- a/FS/FS/cust_main_county.pm +++ b/FS/FS/cust_main_county.pm @@ -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, });