summaryrefslogtreecommitdiff
path: root/FS/FS/cust_main/API.pm
diff options
context:
space:
mode:
authorJeremy Davis <jeremyd@freeside.biz>2015-01-28 22:25:23 -0600
committerJeremy Davis <jeremyd@freeside.biz>2015-01-28 22:25:23 -0600
commitfc937dac3920ddbf5d009bb28c75ff1eb529c625 (patch)
tree9bcbf01da5e951c0dcedc2a021cb31a1427b92a7 /FS/FS/cust_main/API.pm
parent92a327b2bc09344a7e0db93f40e34b71547bf075 (diff)
Ticket #33252 API customer update
Diffstat (limited to 'FS/FS/cust_main/API.pm')
-rw-r--r--FS/FS/cust_main/API.pm63
1 files changed, 63 insertions, 0 deletions
diff --git a/FS/FS/cust_main/API.pm b/FS/FS/cust_main/API.pm
index 283683b..4a09b93 100644
--- a/FS/FS/cust_main/API.pm
+++ b/FS/FS/cust_main/API.pm
@@ -3,6 +3,7 @@ package FS::cust_main::API;
use strict;
use FS::Conf;
use FS::part_tag;
+use FS::Record qw( qsearchs );
=item API_getinfo FIELD => VALUE, ...
@@ -156,4 +157,66 @@ sub API_insert {
}
+sub API_update {
+
+ my( $class, %opt ) = @_;
+
+ my $conf = new FS::Conf;
+
+
+ my $custnum = $opt{'custnum'}
+ or return { 'error' => "no customer record" };
+
+ my $cust_main = qsearchs('cust_main', { 'custnum' => $custnum } )
+ or return { 'error' => "unknown custnum $custnum" };
+
+ my $new = new FS::cust_main { $cust_main->hash };
+
+ $new->set( $_ => $opt{$_} )
+ foreach grep { exists $opt{$_} } qw(
+ agentnum salesnum refnum agent_custid referral_custnum
+ last first company
+ daytime night fax mobile
+ payby payinfo paydate paycvv payname
+ ),
+
+
+ my @invoicing_list = $opt{'invoicing_list'}
+ ? split( /\s*\,\s*/, $opt{'invoicing_list'} )
+ : ();
+ push @invoicing_list, 'POST' if $opt{'postal_invoicing'};
+
+ my ($bill_hash, $ship_hash);
+ foreach my $f (FS::cust_main->location_fields) {
+ # avoid having to change this in front-end code
+ $bill_hash->{$f} = $opt{"bill_$f"} || $opt{$f};
+ $ship_hash->{$f} = $opt{"ship_$f"};
+ }
+
+ my $bill_location = FS::cust_location->new($bill_hash);
+ my $ship_location;
+ # we don't have an equivalent of the "same" checkbox in selfservice^Wthis API
+ # so is there a ship address, and if so, is it different from the billing
+ # address?
+ if ( length($ship_hash->{address1}) > 0 and
+ grep { $bill_hash->{$_} ne $ship_hash->{$_} } keys(%$ship_hash)
+ ) {
+
+ $ship_location = FS::cust_location->new( $ship_hash );
+
+ } else {
+ $ship_location = $bill_location;
+ }
+
+ $new->set('bill_location' => $bill_location);
+ $new->set('ship_location' => $ship_location);
+
+ my $error = $new->replace( $cust_main, \@invoicing_list );
+ return { 'error' => $error } if $error;
+
+ return { 'error' => '',
+ };
+
+}
+
1;