package FS::API;
use FS::Conf;
-use FS::Record qw( qsearchs );
+use FS::Record qw( qsearch qsearchs );
use FS::cust_main;
+use FS::cust_location;
use FS::cust_pay;
use FS::cust_credit;
use FS::cust_refund;
#---
-#Customer data
-# pull customer info
-# The fields needed are:
-#
-# cust_main.custnum
-# cust_main.first
-# cust_main.last
-# cust_main.company
-# cust_main.address1
-# cust_main.address2
-# cust_main.city
-# cust_main.state
-# cust_main.zip
-# cust_main.daytime
-# cust_main.night
-# cust_main_invoice.dest
-#
-# at minimum
-
-#Customer balances
-#Advertising sources?
# "2 way syncing" ? start with non-sync pulling info here, then if necessary
# figure out how to trigger something when those things change
'error' => '',
'display_custnum' => $cust_main->display_custnum,
'name' => $cust_main->first. ' '. $cust_main->get('last'),
+ 'balance' => $cust_main->balance,
+ 'status' => $cust_main->status,
+ 'statuscolor' => $cust_main->statuscolor,
);
$return{$_} = $cust_main->get($_)
foreach @cust_main_editable_fields;
+ for (@location_editable_fields) {
+ $return{$_} = $cust_main->bill_location->get($_)
+ if $cust_main->bill_locationnum;
+ $return{'ship_'.$_} = $cust_main->ship_location->get($_)
+ if $cust_main->ship_locationnum;
+ }
+
+ my @invoicing_list = $cust_main->invoicing_list;
+ $return{'invoicing_list'} =
+ join(', ', grep { $_ !~ /^(POST|FAX)$/ } @invoicing_list );
+ $return{'postal_invoicing'} =
+ 0 < ( grep { $_ eq 'POST' } @invoicing_list );
+
+ #generally, the more useful data from the cust_main record the better.
+ # well, tell me what you want
+
return \%return;
}
+
+#I also monitor for changes to the additional locations that are applied to
+# packages, and would like for those to be exportable as well. basically the
+# location data passed with the custnum.
+sub location_info {
+ my( $class, %opt ) = @_;
+ my $conf = new FS::Conf;
+ return { 'error' => 'Incorrect shared secret' }
+ unless $opt{secret} eq $conf->config('api_shared_secret');
+
+ my @cust_location = qsearch('cust_location', { 'custnum' => $opt{custnum} });
+
+ my %return = (
+ 'error' => '',
+ 'locations' => [ map $_->hashref, @cust_location ],
+ );
+
+ return \%return;
+}
+
+#Advertising sources?
+
=back
1;