blob: 837cf40cc717f8bc9b48fc08420819800b71ae64 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
|
package FS::cust_pkg::API;
use strict;
sub API_getinfo {
my $self = shift;
+{ ( map { $_=>$self->$_ } $self->fields ),
};
}
# 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;
|