From 53ed077b4901be22b3ca5405a093364b6f6b6407 Mon Sep 17 00:00:00 2001 From: Mark Wells Date: Fri, 6 Mar 2015 15:00:00 -0800 Subject: [PATCH] estimate tax on quotations, #32489 --- FS/FS/Schema.pm | 7 ++++++- FS/FS/cust_main_county.pm | 30 ++++++++++++++++-------------- FS/FS/quotation_pkg.pm | 14 ++------------ FS/FS/quotation_pkg_tax.pm | 6 ------ 4 files changed, 24 insertions(+), 33 deletions(-) diff --git a/FS/FS/Schema.pm b/FS/FS/Schema.pm index cd4f01d3e..6a156a5da 100644 --- a/FS/FS/Schema.pm +++ b/FS/FS/Schema.pm @@ -1980,7 +1980,12 @@ sub tables_hashref { 'primary_key' => 'quotationtaxnum',, 'unique' => [], 'index' => [ [ 'quotationpkgnum' ] ], - }, + 'foreign_keys' => [ + { columns => [ 'quotationpkgnum' ], + table => 'quotation_pkg', + }, + ], +}, 'cust_location' => { #'location' now that its prospects too, but... 'columns' => [ diff --git a/FS/FS/cust_main_county.pm b/FS/FS/cust_main_county.pm index 075ac3278..652ff33ae 100644 --- a/FS/FS/cust_main_county.pm +++ b/FS/FS/cust_main_county.pm @@ -277,7 +277,7 @@ sub taxline { my $cust_bill = $taxables->[0]->cust_bill; 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; + my $cust_main = FS::cust_main->by_key($custnum) if $custnum; # (to avoid complications with estimated tax on quotations, assume it's # taxable if there is no customer) #if (!$cust_main) { @@ -285,18 +285,21 @@ sub taxline { #} # set a flag if the customer is tax-exempt - my $exempt_cust; + my ($exempt_cust, $exempt_cust_taxname); my $conf = FS::Conf->new; - if ( $conf->exists('cust_class-tax_exempt') ) { - my $cust_class = $cust_main->cust_class; - $exempt_cust = $cust_class->tax if $cust_class; - } else { - $exempt_cust = $cust_main->tax; - } + if ( $cust_main ) { + if ( $conf->exists('cust_class-tax_exempt') ) { + my $cust_class = $cust_main->cust_class; + $exempt_cust = $cust_class->tax if $cust_class; + } else { + $exempt_cust = $cust_main->tax; + } - # set a flag if the customer is exempt from this tax here - my $exempt_cust_taxname = $cust_main->tax_exemption($self->taxname) - if $self->taxname; + # set a flag if the customer is exempt from this tax here + if ( $self->taxname ) { + $exempt_cust_taxname = $cust_main->tax_exemption($self->taxname); + } + } # Gather any exemptions that are already attached to these cust_bill_pkgs # so that we can deduct them from the customer's monthly limit. @@ -320,9 +323,8 @@ sub taxline { 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 $locationnum = $cust_bill_pkg->tax_locationnum + || $cust_main->ship_locationnum; my @new_exemptions; my $taxable_charged = $cust_bill_pkg->setup + $cust_bill_pkg->recur diff --git a/FS/FS/quotation_pkg.pm b/FS/FS/quotation_pkg.pm index c579e359b..1c4766e79 100644 --- a/FS/FS/quotation_pkg.pm +++ b/FS/FS/quotation_pkg.pm @@ -442,7 +442,7 @@ Returns the customer (L object). sub cust_main { my $self = shift; - my $quotation = FS::quotation->by_key($self->quotationnum) or return ''; + my $quotation = $self->quotation or return ''; $quotation->cust_main; } @@ -454,20 +454,10 @@ Returns the prospect (L object). sub prospect_main { my $self = shift; - my $quotation = FS::quotation->by_key($self->quotationnum) or return ''; + my $quotation = $self->quotation or return ''; $quotation->prospect_main; } -sub quotation_pkg_tax { - my $self = shift; - qsearch('quotation_pkg_tax', { quotationpkgnum => $self->quotationpkgnum }); -} - -sub cust_location { - my $self = shift; - $self->locationnum ? qsearchs('cust_location', { locationnum => $self->locationnum }) : ''; -} - =back =head1 BUGS diff --git a/FS/FS/quotation_pkg_tax.pm b/FS/FS/quotation_pkg_tax.pm index 3d1dcebbb..f459ed2fc 100644 --- a/FS/FS/quotation_pkg_tax.pm +++ b/FS/FS/quotation_pkg_tax.pm @@ -104,12 +104,6 @@ sub check { $self->SUPER::check; } -#stub for 3.x -sub quotation_pkg { - my $self = shift; - FS::quotation_pkg->by_key($self->quotationpkgnum); -} - =back =head1 SEE ALSO -- 2.11.0