use FS::cust_pay;
use FS::cust_credit;
use FS::cust_refund;
+use FS::cust_pkg;
=head1 NAME
Option date for payment
+=item order_number
+
+Optional order number
+
=back
Example:
#optional
'_date' => 1397977200, #UNIX timestamp
+ 'order_number' => '12345',
);
if ( $result->{'error'} ) {
}
+=item customer_list_svcs OPTION => VALUE, ...
+
+Returns customer service information. Takes a list of keys and values as
+parameters with the following keys: custnum, secret
+
+=cut
+
+sub customer_list_svcs {
+ my( $class, %opt ) = @_;
+ return _shared_secret_error() unless _check_shared_secret($opt{secret});
+
+ my $cust_main = qsearchs('cust_main', { 'custnum' => $opt{custnum} })
+ or return { 'error' => 'Unknown custnum' };
+
+ #$cust_main->API_list_svcs;
+
+ #false laziness w/ClientAPI/list_svcs
+
+ my @cust_svc = ();
+ #my @cust_pkg_usage = ();
+ #foreach my $cust_pkg ( $p->{'ncancelled'}
+ # ? $cust_main->ncancelled_pkgs
+ # : $cust_main->unsuspended_pkgs ) {
+ foreach my $cust_pkg ( $cust_main->all_pkgs ) {
+ #next if $pkgnum && $cust_pkg->pkgnum != $pkgnum;
+ push @cust_svc, @{[ $cust_pkg->cust_svc ]}; #@{[ ]} to force array context
+ #push @cust_pkg_usage, $cust_pkg->cust_pkg_usage;
+ }
+
+ return {
+ 'cust_svc' => [ map $_->API_getinfo, @cust_svc ],
+ };
+
+}
+
=item location_info
Returns location specific information for the customer. Takes a list of keys
return \%return;
}
+=item change_package_location
+
+Updates package location. Takes a list of keys and values
+as paramters with the following keys:
+
+pkgnum
+
+secret
+
+locationnum - pass this, or the following keys (don't pass both)
+
+locationname
+
+address1
+
+address2
+
+city
+
+county
+
+state
+
+zip
+
+addr_clean
+
+country
+
+censustract
+
+censusyear
+
+location_type
+
+location_number
+
+location_kind
+
+incorporated
+
+On error, returns a hashref with an 'error' key.
+On success, returns a hashref with 'pkgnum' and 'locationnum' keys,
+containing the new values.
+
+=cut
+
+sub change_package_location {
+ my $class = shift;
+ my %opt = @_;
+ return _shared_secret_error() unless _check_shared_secret($opt{'secret'});
+
+ my $cust_pkg = qsearchs('cust_pkg', { 'pkgnum' => $opt{'pkgnum'} })
+ or return { 'error' => 'Unknown pkgnum' };
+
+ my %changeopt;
+
+ foreach my $field ( qw(
+ locationnum
+ locationname
+ address1
+ address2
+ city
+ county
+ state
+ zip
+ addr_clean
+ country
+ censustract
+ censusyear
+ location_type
+ location_number
+ location_kind
+ incorporated
+ )) {
+ $changeopt{$field} = $opt{$field} if $opt{$field};
+ }
+
+ $cust_pkg->API_change(%changeopt);
+}
+
=item bill_now OPTION => VALUE, ...
Bills a single customer now, in the same fashion as the "Bill now" link in the
}
-#next.. Advertising sources?
+#next.. Delete Advertising sources?
+
+=item list_advertising_sources OPTION => VALUE, ...
+
+Lists all advertising sources.
+
+=over
+
+=item secret
+
+API Secret
+
+=back
+
+Example:
+
+ my $result = FS::API->list_advertising_sources(
+ 'secret' => 'sharingiscaring',
+ );
+
+ if ( $result->{'error'} ) {
+ die $result->{'error'};
+ } else {
+ # list advertising sources returns an array of hashes for sources.
+ print Dumper($result->{'sources'});
+ }
+
+=cut
+
+#list_advertising_sources
+sub list_advertising_sources {
+ my( $class, %opt ) = @_;
+ return _shared_secret_error() unless _check_shared_secret($opt{secret});
+
+ my @sources = qsearch('part_referral', {}, '', "")
+ or return { 'error' => 'No referrals' };
+
+ my $return = {
+ 'sources' => [ map $_->hashref, @sources ],
+ };
+
+ $return;
+}
+
+=item add_advertising_source OPTION => VALUE, ...
+
+Add a new advertising source.
+
+=over
+
+=item secret
+
+API Secret
+
+=item referral
+
+Referral name
+
+=item disabled
+
+Referral disabled, Y for disabled or nothing for enabled
+
+=item agentnum
+
+Agent ID number
+
+=item title
+
+External referral ID
+
+=back
+
+Example:
+
+ my $result = FS::API->add_advertising_source(
+ 'secret' => 'sharingiscaring',
+ 'referral' => 'test referral',
+
+ #optional
+ 'disabled' => 'Y',
+ 'agentnum' => '2', #agent id number
+ 'title' => 'test title',
+ );
+
+ if ( $result->{'error'} ) {
+ die $result->{'error'};
+ } else {
+ # add_advertising_source returns new source upon success.
+ print Dumper($result);
+ }
+
+=cut
+
+#add_advertising_source
+sub add_advertising_source {
+ my( $class, %opt ) = @_;
+ return _shared_secret_error() unless _check_shared_secret($opt{secret});
+
+ use FS::part_referral;
+
+ my $new_source = $opt{source};
+
+ my $source = new FS::part_referral $new_source;
+
+ my $error = $source->insert;
+
+ my $return = {$source->hash};
+ $return = { 'error' => $error, } if $error;
+
+ $return;
+}
+
+=item edit_advertising_source OPTION => VALUE, ...
+
+Edit a advertising source.
+
+=over
+
+=item secret
+
+API Secret
+
+=item refnum
+
+Referral number to edit
+
+=item source
+
+hash of edited source fields.
+
+=over
+
+=item referral
+
+Referral name
+
+=item disabled
+
+Referral disabled, Y for disabled or nothing for enabled
+
+=item agentnum
+
+Agent ID number
+
+=item title
+
+External referral ID
+
+=back
+
+=back
+
+Example:
+
+ my $result = FS::API->edit_advertising_source(
+ 'secret' => 'sharingiscaring',
+ 'refnum' => '4', # referral number to edit
+ 'source' => {
+ #optional
+ 'referral' => 'test referral',
+ 'disabled' => 'Y',
+ 'agentnum' => '2', #agent id number
+ 'title' => 'test title',
+ }
+ );
+
+ if ( $result->{'error'} ) {
+ die $result->{'error'};
+ } else {
+ # edit_advertising_source returns updated source upon success.
+ print Dumper($result);
+ }
+
+=cut
+
+#edit_advertising_source
+sub edit_advertising_source {
+ my( $class, %opt ) = @_;
+ return _shared_secret_error() unless _check_shared_secret($opt{secret});
+
+ use FS::part_referral;
+
+ my $refnum = $opt{refnum};
+ my $source = $opt{source};
+
+ my $old = FS::Record::qsearchs('part_referral', {'refnum' => $refnum,});
+ my $new = new FS::part_referral { $old->hash };
+
+ foreach my $key (keys %$source) {
+ $new->$key($source->{$key});
+ }
+
+ my $error = $new->replace;
+
+ my $return = {$new->hash};
+ $return = { 'error' => $error, } if $error;
+
+ $return;
+}
##