1 package FS::cust_main::API;
6 =item API_getinfo FIELD => VALUE, ...
10 #some false laziness w/ClientAPI::Myaccount customer_info/customer_info_short
13 @cust_main_addl_fields @cust_main_editable_fields @location_editable_fields
15 @cust_main_addl_fields = qw(
16 agentnum salesnum refnum classnum usernum referral_custnum
18 @cust_main_editable_fields = qw(
19 first last company daytime night fax mobile
22 # payby payinfo payname paystart_month paystart_year payissue payip
23 # ss paytype paystate stateid stateid_state
24 @location_editable_fields = qw(
25 address1 address2 city county state zip country
29 my( $self, %opt ) = @_;
33 'display_custnum' => $self->display_custnum,
34 'name' => $self->first. ' '. $self->get('last'),
35 'balance' => $self->balance,
36 'status' => $self->status,
37 'statuscolor' => $self->statuscolor,
40 $return{$_} = $self->get($_)
41 foreach @cust_main_editable_fields;
43 unless ( $opt{'selfservice'} ) {
44 $return{$_} = $self->get($_)
45 foreach @cust_main_addl_fields;
48 for (@location_editable_fields) {
49 $return{$_} = $self->bill_location->get($_)
50 if $self->bill_locationnum;
51 $return{'ship_'.$_} = $self->ship_location->get($_)
52 if $self->ship_locationnum;
55 my @invoicing_list = $self->invoicing_list;
56 $return{'invoicing_list'} =
57 join(', ', grep { $_ !~ /^(POST|FAX)$/ } @invoicing_list );
58 $return{'postal_invoicing'} =
59 0 < ( grep { $_ eq 'POST' } @invoicing_list );
61 #generally, the more useful data from the cust_main record the better.
62 # well, tell me what you want
69 #or maybe all docs go in FS::API ? argh
73 Class method (constructor).
78 FS::cust_main->API_insert(
83 'address1' => '5354 Pink Rabbit Lane',
88 'invoicing_list' => 'harvey2@example.com',
93 #certainly false laziness w/ClientAPI::Signup new_customer/new_customer_minimal
94 # but approaching this from a clean start / back-office perspective
95 # i.e. no package/service, no immediate credit card run, etc.
98 my( $class, %opt ) = @_;
100 my $conf = new FS::Conf;
102 #default agentnum like signup_server-default_agentnum?
104 #same for refnum like signup_server-default_refnum?
106 my $cust_main = new FS::cust_main ( { # $class->new( {
109 map { $_ => $opt{$_} } qw(
110 agentnum refnum agent_custid referral_custnum
112 daytime night fax mobile
113 payby payinfo paydate paycvv payname
118 my @invoicing_list = $opt{'invoicing_list'}
119 ? split( /\s*\,\s*/, $opt{'invoicing_list'} )
121 push @invoicing_list, 'POST' if $opt{'postal_invoicing'};
123 my ($bill_hash, $ship_hash);
124 foreach my $f (FS::cust_main->location_fields) {
125 # avoid having to change this in front-end code
126 $bill_hash->{$f} = $opt{"bill_$f"} || $opt{$f};
127 $ship_hash->{$f} = $opt{"ship_$f"};
130 my $bill_location = FS::cust_location->new($bill_hash);
132 # we don't have an equivalent of the "same" checkbox in selfservice^Wthis API
133 # so is there a ship address, and if so, is it different from the billing
135 if ( length($ship_hash->{address1}) > 0 and
136 grep { $bill_hash->{$_} ne $ship_hash->{$_} } keys(%$ship_hash)
139 $ship_location = FS::cust_location->new( $ship_hash );
142 $ship_location = $bill_location;
145 $cust_main->set('bill_location' => $bill_location);
146 $cust_main->set('ship_location' => $ship_location);
148 my $error = $cust_main->insert( {}, \@invoicing_list );
149 return { 'error' => $error } if $error;
151 return { 'error' => '',
152 'custnum' => $cust_main->custnum,