1 package FS::cust_main::API;
7 =item API_getinfo FIELD => VALUE, ...
11 #some false laziness w/ClientAPI::Myaccount customer_info/customer_info_short
14 @cust_main_addl_fields @cust_main_editable_fields @location_editable_fields
16 @cust_main_addl_fields = qw(
17 agentnum salesnum refnum classnum usernum referral_custnum
19 @cust_main_editable_fields = qw(
20 first last company daytime night fax mobile
23 # payby payinfo payname paystart_month paystart_year payissue payip
24 # ss paytype paystate stateid stateid_state
25 @location_editable_fields = qw(
26 address1 address2 city county state zip country
30 my( $self, %opt ) = @_;
34 'display_custnum' => $self->display_custnum,
35 'name' => $self->first. ' '. $self->get('last'),
36 'balance' => $self->balance,
37 'status' => $self->status,
38 'statuscolor' => $self->statuscolor,
41 $return{$_} = $self->get($_)
42 foreach @cust_main_editable_fields;
44 unless ( $opt{'selfservice'} ) {
45 $return{$_} = $self->get($_)
46 foreach @cust_main_addl_fields;
49 for (@location_editable_fields) {
50 $return{$_} = $self->bill_location->get($_)
51 if $self->bill_locationnum;
52 $return{'ship_'.$_} = $self->ship_location->get($_)
53 if $self->ship_locationnum;
56 my @invoicing_list = $self->invoicing_list;
57 $return{'invoicing_list'} =
58 join(', ', grep { $_ !~ /^(POST|FAX)$/ } @invoicing_list );
59 $return{'postal_invoicing'} =
60 0 < ( grep { $_ eq 'POST' } @invoicing_list );
62 #generally, the more useful data from the cust_main record the better.
63 # well, tell me what you want
70 #or maybe all docs go in FS::API ? argh
74 Class method (constructor).
79 FS::cust_main->API_insert(
84 'address1' => '5354 Pink Rabbit Lane',
89 'invoicing_list' => 'harvey2@example.com',
94 #certainly false laziness w/ClientAPI::Signup new_customer/new_customer_minimal
95 # but approaching this from a clean start / back-office perspective
96 # i.e. no package/service, no immediate credit card run, etc.
99 my( $class, %opt ) = @_;
101 my $conf = new FS::Conf;
103 #default agentnum like signup_server-default_agentnum?
105 #same for refnum like signup_server-default_refnum?
107 my $cust_main = new FS::cust_main ( { # $class->new( {
109 'tagnum' => [ FS::part_tag->default_tags ],
111 map { $_ => $opt{$_} } qw(
112 agentnum refnum agent_custid referral_custnum
114 daytime night fax mobile
115 payby payinfo paydate paycvv payname
120 my @invoicing_list = $opt{'invoicing_list'}
121 ? split( /\s*\,\s*/, $opt{'invoicing_list'} )
123 push @invoicing_list, 'POST' if $opt{'postal_invoicing'};
125 my ($bill_hash, $ship_hash);
126 foreach my $f (FS::cust_main->location_fields) {
127 # avoid having to change this in front-end code
128 $bill_hash->{$f} = $opt{"bill_$f"} || $opt{$f};
129 $ship_hash->{$f} = $opt{"ship_$f"};
132 my $bill_location = FS::cust_location->new($bill_hash);
134 # we don't have an equivalent of the "same" checkbox in selfservice^Wthis API
135 # so is there a ship address, and if so, is it different from the billing
137 if ( length($ship_hash->{address1}) > 0 and
138 grep { $bill_hash->{$_} ne $ship_hash->{$_} } keys(%$ship_hash)
141 $ship_location = FS::cust_location->new( $ship_hash );
144 $ship_location = $bill_location;
147 $cust_main->set('bill_location' => $bill_location);
148 $cust_main->set('ship_location' => $ship_location);
150 my $error = $cust_main->insert( {}, \@invoicing_list );
151 return { 'error' => $error } if $error;
153 return { 'error' => '',
154 'custnum' => $cust_main->custnum,