summaryrefslogtreecommitdiff
path: root/FS/FS/cust_main/Location.pm
diff options
context:
space:
mode:
authorMark Wells <mark@freeside.biz>2013-08-24 15:43:08 -0700
committerMark Wells <mark@freeside.biz>2013-08-24 15:43:08 -0700
commit60724f233fbeb9388f4b2cbb68a4e6297c2b2118 (patch)
tree1388b01758c47e914db4056e8d35997861a041ae /FS/FS/cust_main/Location.pm
parent23f2db6452f097640447b9b35dd106f408dbc20b (diff)
CCH taxes with new customer locations, #21485
Diffstat (limited to 'FS/FS/cust_main/Location.pm')
-rw-r--r--FS/FS/cust_main/Location.pm27
1 files changed, 27 insertions, 0 deletions
diff --git a/FS/FS/cust_main/Location.pm b/FS/FS/cust_main/Location.pm
index 22feaf9c8..5590f8869 100644
--- a/FS/FS/cust_main/Location.pm
+++ b/FS/FS/cust_main/Location.pm
@@ -124,6 +124,11 @@ sub _upgrade_data {
local $DEBUG = 0;
my $error;
+ my $tax_prefix = 'bill_';
+ if ( FS::Conf->new->exists('tax-ship_address') ) {
+ $tax_prefix = 'ship_';
+ }
+
# Step 0: set up contact classes and phone types
my $service_contact_class =
qsearchs('contact_class', { classname => 'Service'})
@@ -198,6 +203,14 @@ sub _upgrade_data {
'last' => $cust_main->get('ship_last'),
'first' => $cust_main->get('ship_first'),
});
+ if ( !$cust_main->get('ship_last') or !$cust_main->get('ship_first') )
+ {
+ warn "customer $custnum has no service contact name; substituting ".
+ "customer name\n";
+ $contact->set('last' => $cust_main->get('last'));
+ $contact->set('first' => $cust_main->get('first'));
+ }
+
if ( $unlike{'company'} ) {
# there's no contact.company field, but keep a record of it
$contact->set(comment => 'Company: '.$cust_main->get('ship_company'));
@@ -224,6 +237,20 @@ sub _upgrade_data {
$cust_main->set("ship_$_" => '') foreach qw(last first company);
} #if %unlike
} #if ship_address1
+
+ # special case: should go with whichever location is used to calculate
+ # taxes, because that's the one it originally came from
+ if ( my $geocode = $cust_main->get('geocode') ) {
+ $bill_location->set('geocode' => '');
+ $ship_location->set('geocode' => '');
+
+ if ( $tax_prefix eq 'bill_' ) {
+ $bill_location->set('geocode', $geocode);
+ } elsif ( $tax_prefix eq 'ship_' ) {
+ $ship_location->set('geocode', $geocode);
+ }
+ }
+
$error = $bill_location->insert;
die "error migrating billing address for customer $custnum: $error"
if $error;