summaryrefslogtreecommitdiff
path: root/FS/FS/cust_pkg
diff options
context:
space:
mode:
authorJonathan Prykop <jonathan@freeside.biz>2016-04-18 21:47:51 -0500
committerJonathan Prykop <jonathan@freeside.biz>2016-04-22 12:10:09 -0500
commit5c321cb0e6488b0b76fec03395ec815703867b22 (patch)
tree56f2476f724f7d8b38f4d34d7107ac1260cce8b9 /FS/FS/cust_pkg
parentfd0483007b898b9944cc31fd5d6e90932fe2c8c0 (diff)
RT#29296: API stuff: Add new locations [change_package_location API call]
Diffstat (limited to 'FS/FS/cust_pkg')
-rw-r--r--FS/FS/cust_pkg/API.pm48
1 files changed, 48 insertions, 0 deletions
diff --git a/FS/FS/cust_pkg/API.pm b/FS/FS/cust_pkg/API.pm
index f87eed3..6e03b8e 100644
--- a/FS/FS/cust_pkg/API.pm
+++ b/FS/FS/cust_pkg/API.pm
@@ -2,6 +2,8 @@ package FS::cust_pkg::API;
use strict;
+use FS::cust_location::API;
+
sub API_getinfo {
my $self = shift;
@@ -10,4 +12,50 @@ 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->cancel;
+
+ my %changeopt;
+
+ # update location--accepts raw fields OR location
+ my %location_hash;
+ foreach my $field (FS::cust_location::API::API_editable_fields()) {
+ $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;