[freeside-commits] branch FREESIDE_3_BRANCH updated. 47e56ace89efbf8f603cd6584f177c026241cd22
Mark Wells
mark at 420.am
Thu Aug 21 17:55:19 PDT 2014
The branch, FREESIDE_3_BRANCH has been updated
via 47e56ace89efbf8f603cd6584f177c026241cd22 (commit)
from 1e415f3cfe6ea9004c101d677d29ba8ad539b37d (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commit 47e56ace89efbf8f603cd6584f177c026241cd22
Author: Mark Wells <mark at freeside.biz>
Date: Thu Aug 21 15:30:10 2014 -0400
3.x upgrade needs to deal with more than one cust_main_exemption per customer, #30413
diff --git a/FS/FS/cust_bill_pkg.pm b/FS/FS/cust_bill_pkg.pm
index d529678..f365aad 100644
--- a/FS/FS/cust_bill_pkg.pm
+++ b/FS/FS/cust_bill_pkg.pm
@@ -1184,6 +1184,13 @@ sub upgrade_tax_location {
' WHERE cust_bill_pkg.invnum = cust_bill.invnum'.
' AND exempt_monthly IS NULL';
+ my %all_tax_names = (
+ '' => 1,
+ 'Tax' => 1,
+ map { $_->taxname => 1 }
+ qsearch('h_cust_main_county', { taxname => { op => '!=', value => '' }})
+ );
+
my $search = FS::Cursor->new({
table => 'cust_bill',
hashref => {},
@@ -1221,7 +1228,7 @@ sub upgrade_tax_location {
# invoice date-of-insertion. (Not necessarily the invoice date.)
my $date = $h_cust_bill->history_date;
my $h_cust_main = qsearchs('h_cust_main',
- { custnum => $custnum },
+ { custnum => $custnum },
FS::h_cust_main->sql_h_searchs($date)
);
if (!$h_cust_main ) {
@@ -1233,29 +1240,32 @@ sub upgrade_tax_location {
# This is a historical customer record, so it has a historical address.
# If there's no cust_location matching this custnum and address (there
# probably isn't), create one.
- $pre = 'ship_' if $use_ship and length($h_cust_main->get('ship_last'));
- my %hash = map { $_ => $h_cust_main->get($pre.$_) }
- FS::cust_main->location_fields;
- # not really needed for this, and often result in duplicate locations
- delete @hash{qw(censustract censusyear latitude longitude coord_auto)};
-
- $hash{custnum} = $h_cust_main->custnum;
- my $tax_loc = FS::cust_location->new(\%hash);
- my $error = $tax_loc->find_or_insert || $tax_loc->disable_if_unused;
- if ( $error ) {
- warn "couldn't create historical location record for cust#".
- $h_cust_main->custnum.": $error\n";
- next INVOICE;
+ my $tax_loc;
+ if ( $h_cust_main->bill_locationnum ) {
+ # the location has already been upgraded
+ if ($use_ship) {
+ $tax_loc = $h_cust_main->ship_location;
+ } else {
+ $tax_loc = $h_cust_main->bill_location;
+ }
+ } else {
+ $pre = 'ship_' if $use_ship and length($h_cust_main->get('ship_last'));
+ my %hash = map { $_ => $h_cust_main->get($pre.$_) }
+ FS::cust_main->location_fields;
+ # not really needed for this, and often result in duplicate locations
+ delete @hash{qw(censustract censusyear latitude longitude coord_auto)};
+
+ $hash{custnum} = $h_cust_main->custnum;
+ $tax_loc = FS::cust_location->new(\%hash);
+ my $error = $tax_loc->find_or_insert || $tax_loc->disable_if_unused;
+ if ( $error ) {
+ warn "couldn't create historical location record for cust#".
+ $h_cust_main->custnum.": $error\n";
+ next INVOICE;
+ }
}
my $exempt_cust = 1 if $h_cust_main->tax;
- # Get any per-customer taxname exemptions that were in effect.
- my %exempt_cust_taxname = map {
- $_->taxname => 1
- } qsearch('h_cust_main_exemption', { 'custnum' => $custnum },
- FS::h_cust_main_exemption->sql_h_searchs($date)
- );
-
# classify line items
my @tax_items;
my %nontax_items; # taxclass => array of cust_bill_pkg
@@ -1305,14 +1315,29 @@ sub upgrade_tax_location {
push @{ $nontax_items{$taxclass} }, $item;
}
}
+
printf("%d tax items: \$%.2f\n", scalar(@tax_items), map {$_->setup} @tax_items)
if @tax_items;
+ # Get any per-customer taxname exemptions that were in effect.
+ my %exempt_cust_taxname;
+ foreach (keys %all_tax_names) {
+ my $h_exemption = qsearchs('h_cust_main_exemption', {
+ 'custnum' => $custnum,
+ 'taxname' => $_,
+ },
+ FS::h_cust_main_exemption->sql_h_searchs($date, $date)
+ );
+ if ($h_exemption) {
+ $exempt_cust_taxname{ $_ } = 1;
+ }
+ }
+
# Use a variation on the procedure in
# FS::cust_main::Billing::_handle_taxes to identify taxes that apply
# to this bill.
my @loc_keys = qw( district city county state country );
- my %taxhash = map { $_ => $h_cust_main->get($pre.$_) } @loc_keys;
+ my %taxhash = map { $_ => $tax_loc->get($pre.$_) } @loc_keys;
my %taxdef_by_name; # by name, and then by taxclass
my %est_tax; # by name, and then by taxclass
my %taxable_items; # by taxnum, and then an array
@@ -1430,8 +1455,7 @@ sub upgrade_tax_location {
if ( !exists( $taxdef_by_name{$taxname} ) ) {
# then we didn't find any applicable taxes with this name
- warn "no definition found for tax item '$taxname'.\n".
- '('.join(' ', @hash{qw(country state county city district)}).")\n";
+ warn "no definition found for tax item '$taxname', custnum $custnum\n";
# possibly all of these should be "next TAX_ITEM", but whole invoices
# are transaction protected and we can go back and retry them.
next INVOICE;
-----------------------------------------------------------------------
Summary of changes:
FS/FS/cust_bill_pkg.pm | 72 ++++++++++++++++++++++++++++++++----------------
1 file changed, 48 insertions(+), 24 deletions(-)
More information about the freeside-commits
mailing list