X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=FS%2FFS%2Fcust_pkg%2FAPI.pm;h=837cf40cc717f8bc9b48fc08420819800b71ae64;hb=0b2e7bf798685d0d6eb2f7a950783207d686d744;hp=f87eed3457d7f2b80fc6b4912f2709762243939b;hpb=5f8111de04a4a914c72a1642722476db4728339c;p=freeside.git diff --git a/FS/FS/cust_pkg/API.pm b/FS/FS/cust_pkg/API.pm index f87eed345..837cf40cc 100644 --- a/FS/FS/cust_pkg/API.pm +++ b/FS/FS/cust_pkg/API.pm @@ -10,4 +10,66 @@ sub API_getinfo { } +# currently only handles location change... +# eventually have it handle all sorts of package changes +sub API_change { + my $self = shift; + my %opt = @_; + + return { 'error' => 'Cannot change canceled package' } + if $self->get('cancel'); + + my %changeopt; + + # update location--accepts raw fields OR location + my %location_hash; + foreach my $field ( qw( + locationname + address1 + address2 + city + county + state + zip + addr_clean + country + censustract + censusyear + location_type + location_number + location_kind + incorporated + ) ) { + $location_hash{$field} = $opt{$field} if $opt{$field}; + } + return { 'error' => 'Cannot pass both locationnum and location fields' } + if $opt{'locationnum'} && %location_hash; + + if (%location_hash) { + my $cust_location = FS::cust_location->new({ + 'custnum' => $self->custnum, + %location_hash, + }); + $changeopt{'cust_location'} = $cust_location; + } elsif ($opt{'locationnum'}) { + $changeopt{'locationnum'} = $opt{'locationnum'}; + } + + # not quite "nothing changed" because passed changes might be identical to current record, + # we don't currently check for that, don't want to imply that we do...but maybe we should? + return { 'error' => 'No changes passed to method' } + unless $changeopt{'cust_location'} || $changeopt{'locationnum'}; + + $changeopt{'keep_dates'} = 1; + + my $pkg_or_error = $self->change( \%changeopt ); + my $error = ref($pkg_or_error) ? '' : $pkg_or_error; + + return { 'error' => $error } if $error; + + # return all fields? we don't yet expose them through FS::API + return { map { $_ => $pkg_or_error->get($_) } qw( pkgnum locationnum ) }; + +} + 1;