FS::cust_main - Object methods for cust_main records
use FS::cust_main;
$record = new FS::cust_main \%hash;
$record = new FS::cust_main { 'column' => 'value' };
$error = $record->insert;
$error = $new_record->replace($old_record);
$error = $record->delete;
$error = $record->check;
@cust_pkg = $record->all_pkgs;
@cust_pkg = $record->ncancelled_pkgs;
@cust_pkg = $record->suspended_pkgs;
$error = $record->bill;
$error = $record->bill %options;
$error = $record->bill 'time' => $time;
$error = $record->collect;
$error = $record->collect %options;
$error = $record->collect 'invoice_time' => $time,
'batch_card' => 'yes',
'report_badcard' => 'yes',
;
An FS::cust_main object represents a customer. FS::cust_main inherits from
FS::Record. The following fields are currently supported:
- custnum - primary key (assigned automatically for new customers)
-
- agentnum - agent (see the FS::agent manpage)
-
- refnum - referral (see the FS::part_referral manpage)
-
- first - name
-
- last - name
-
- ss - social security number (optional)
-
- company - (optional)
-
- address1
-
- address2 - (optional)
-
- city
-
- county - (optional, see the FS::cust_main_county manpage)
-
- state - (see the FS::cust_main_county manpage)
-
- zip
-
- country - (see the FS::cust_main_county manpage)
-
- daytime - phone (optional)
-
- night - phone (optional)
-
- fax - phone (optional)
-
- ship_first - name
-
- ship_last - name
-
- ship_company - (optional)
-
- ship_address1
-
- ship_address2 - (optional)
-
- ship_city
-
- ship_county - (optional, see the FS::cust_main_county manpage)
-
- ship_state - (see the FS::cust_main_county manpage)
-
- ship_zip
-
- ship_country - (see the FS::cust_main_county manpage)
-
- ship_daytime - phone (optional)
-
- ship_night - phone (optional)
-
- ship_fax - phone (optional)
-
- payby - `CARD' (credit cards), `BILL' (billing), `COMP' (free), or `PREPAY' (special billing type: applies a credit - see the FS::prepay_credit manpage and sets billing type to BILL)
-
- payinfo - card number, P.O., comp issuer (4-8 lowercase alphanumerics; think username) or prepayment identifier (see the FS::prepay_credit manpage)
-
- paydate - expiration date, mm/yyyy, m/yyyy, mm/yy or m/yy
-
- payname - name on card or billing name
-
- tax - tax exempt, empty or `Y'
-
- otaker - order taker (assigned automatically, see the FS::UID manpage)
-
- comments - comments (optional)
-
- new HASHREF
-
Creates a new customer. To add the customer to the database, see insert.
Note that this stores the hash reference, not a distinct copy of the hash it
points to. You can ask the object for a copy with the hash method.
- insert [ CUST_PKG_HASHREF [ , INVOICING_LIST_ARYREF ] ]
-
Adds this customer to the database. If there is an error, returns the error,
otherwise returns false.
CUST_PKG_HASHREF: If you pass a Tie::RefHash data structure to the insert
method containing FS::cust_pkg and FS::svc_tablename objects, all records
are inserted atomicly, or the transaction is rolled back. Passing an empty
hash reference is equivalent to not supplying this parameter. There should be
a better explanation of this, but until then, here's an example:
use Tie::RefHash;
tie %hash, 'Tie::RefHash'; #this part is important
%hash = (
$cust_pkg => [ $svc_acct ],
...
);
$cust_main->insert( \%hash );
INVOICING_LIST_ARYREF: If you pass an arrarref to the insert method, it will
be set as the invoicing list (see invoicing_list). Errors return as
expected and rollback the entire transaction; it is not necessary to call
check_invoicing_list first. The invoicing_list is set after the records in the
CUST_PKG_HASHREF above are inserted, so it is now possible to set an
invoicing_list destination to the newly-created svc_acct. Here's an example:
$cust_main->insert( {}, [ $email, 'POST' ] );
- delete NEW_CUSTNUM
-
This deletes the customer. If there is an error, returns the error, otherwise
returns false.
This will completely remove all traces of the customer record. This is not
what you want when a customer cancels service; for that, cancel all of the
customer's packages (see cancel in the FS::cust_pkg manpage).
If the customer has any uncancelled packages, you need to pass a new (valid)
customer number for those packages to be transferred to. Cancelled packages
will be deleted. Did I mention that this is NOT what you want when a customer
cancels service and that you really should be looking see cancel in the FS::cust_pkg manpage?
You can't delete a customer with invoices (see the FS::cust_bill manpage),
or credits (see the FS::cust_credit manpage) or payments (see the FS::cust_pay manpage).
- replace OLD_RECORD [ INVOICING_LIST_ARYREF ]
-
Replaces the OLD_RECORD with this one in the database. If there is an error,
returns the error, otherwise returns false.
INVOICING_LIST_ARYREF: If you pass an arrarref to the insert method, it will
be set as the invoicing list (see invoicing_list). Errors return as
expected and rollback the entire transaction; it is not necessary to call
check_invoicing_list first. Here's an example:
$new_cust_main->replace( $old_cust_main, [ $email, 'POST' ] );
- check
-
Checks all fields to make sure this is a valid customer record. If there is
an error, returns the error, otherwise returns false. Called by the insert
and repalce methods.
- all_pkgs
-
Returns all packages (see the FS::cust_pkg manpage) for this customer.
- ncancelled_pkgs
-
Returns all non-cancelled packages (see the FS::cust_pkg manpage) for this customer.
- suspended_pkgs
-
Returns all suspended packages (see the FS::cust_pkg manpage) for this customer.
- unflagged_suspended_pkgs
-
Returns all unflagged suspended packages (see the FS::cust_pkg manpage) for this
customer (thouse packages without the `manual_flag' set).
- unsuspended_pkgs
-
Returns all unsuspended (and uncancelled) packages (see the FS::cust_pkg manpage) for
this customer.
- unsuspend
-
Unsuspends all unflagged suspended packages (see unflagged_suspended_pkgs
and the FS::cust_pkg manpage) for this customer. Always returns a list: an empty list
on success or a list of errors.
- suspend
-
Suspends all unsuspended packages (see the FS::cust_pkg manpage) for this customer.
Always returns a list: an empty list on success or a list of errors.
- cancel
-
Cancels all uncancelled packages (see the FS::cust_pkg manpage) for this customer.
Always returns a list: an empty list on success or a list of errors.
- bill OPTIONS
-
Generates invoices (see the FS::cust_bill manpage) for this customer. Usually used in
conjunction with the collect method.
Options are passed as name-value pairs.
The only currently available option is `time', which bills the customer as if
it were that time. It is specified as a UNIX timestamp; see
perlfunc/``time''). Also see the Time::Local manpage and the Date::Parse manpage for conversion
functions. For example:
use Date::Parse;
...
$cust_main->bill( 'time' => str2time('April 20th, 2001') );
If there is an error, returns the error, otherwise returns false.
- collect OPTIONS
-
(Attempt to) collect money for this customer's outstanding invoices (see
the FS::cust_bill manpage). Usually used after the bill method.
Depending on the value of `payby', this may print an invoice (`BILL'), charge
a credit card (`CARD'), or just add any necessary (pseudo-)payment (`COMP').
If there is an error, returns the error, otherwise returns false.
Options are passed as name-value pairs.
Currently available options are:
invoice_time - Use this time when deciding when to print invoices and
late notices on those invoices. The default is now. It is specified as a UNIX timestamp; see perlfunc/``time''). Also see the Time::Local manpage and the Date::Parse manpage
for conversion functions.
batch_card - Set this true to batch cards (see the FS::cust_pay_batch manpage). By
default, cards are processed immediately, which will generate an error if
CyberCash is not installed.
report_badcard - Set this true if you want bad card transactions to
return an error. By default, they don't.
force_print - force printing even if invoice has been printed more than once
every 30 days, and don't increment the `printed' field.
- total_owed
-
Returns the total owed for this customer on all invoices
(see owed in the FS::cust_bill manpage).
- total_owed_date TIME
-
Returns the total owed for this customer on all invoices with date earlier than
TIME. TIME is specified as a UNIX timestamp; see perlfunc/``time''). Also
see the Time::Local manpage and the Date::Parse manpage for conversion functions.
- apply_credits
-
Applies (see the FS::cust_credit_bill manpage) unapplied credits (see the FS::cust_credit manpage)
to outstanding invoice balances in chronological order and returns the value
of any remaining unapplied credits available for refund
(see the FS::cust_refund manpage).
- apply_payments
-
Applies (see the FS::cust_bill_pay manpage) unapplied payments (see the FS::cust_pay manpage)
to outstanding invoice balances in chronological order.
#and returns the value of any remaining unapplied payments.
- total_credited
-
Returns the total outstanding credit (see the FS::cust_credit manpage) for this
customer. See credited in the FS::cust_credit manpage.
- total_unapplied_payments
-
Returns the total unapplied payments (see the FS::cust_pay manpage) for this customer.
See unapplied in the FS::cust_pay manpage.
- balance
-
Returns the balance for this customer (total_owed minus total_credited
minus total_unapplied_payments).
- balance_date TIME
-
Returns the balance for this customer, only considering invoices with date
earlier than TIME (total_owed_date minus total_credited minus
total_unapplied_payments). TIME is specified as a UNIX timestamp; see
perlfunc/``time''). Also see the Time::Local manpage and the Date::Parse manpage for conversion
functions.
- invoicing_list [ ARRAYREF ]
-
If an arguement is given, sets these email addresses as invoice recipients
(see the FS::cust_main_invoice manpage). Errors are not fatal and are not reported
(except as warnings), so use check_invoicing_list first.
Returns a list of email addresses (with svcnum entries expanded).
Note: You can clear the invoicing list by passing an empty ARRAYREF. You can
check it without disturbing anything by passing nothing.
This interface may change in the future.
- check_invoicing_list ARRAYREF
-
Checks these arguements as valid input for the invoicing_list method. If there
is an error, returns the error, otherwise returns false.
- default_invoicing_list
-
Sets the invoicing list to all accounts associated with this customer.
- invoicing_list_addpost
-
Adds postal invoicing to this customer. If this customer is already configured
to receive postal invoices, does nothing.
- referral_cust_main [ DEPTH [ EXCLUDE_HASHREF ] ]
-
Returns an array of customers referred by this customer (referral_custnum set
to this custnum). If DEPTH is given, recurses up to the given depth, returning
customers referred by customers referred by this customer and so on, inclusive.
The default behavior is DEPTH 1 (no recursion).
- referral_cust_pkg [ DEPTH ]
-
Like referral_cust_main, except returns a flat list of all unsuspended packages
for each customer. The number of items in this list may be useful for
comission calculations (perhaps after a grep).
- credit AMOUNT, REASON
-
Applies a credit to this customer. If there is an error, returns the error,
otherwise returns false.
- charge AMOUNT PKG COMMENT
-
Creates a one-time charge for this customer. If there is an error, returns
the error, otherwise returns false.
- check_and_rebuild_fuzzyfiles
-
- rebuild_fuzzyfiles
-
- all_last
-
- all_company
-
- append_fuzzyfiles LASTNAME COMPANY
-
$Id: cust_main.html,v 1.2 2002-01-29 16:33:15 ivan Exp $
The delete method.
The delete method should possibly take an FS::cust_main object reference
instead of a scalar customer number.
Bill and collect options should probably be passed as references instead of a
list.
CyberCash v2 forces us to define some variables in package main.
There should probably be a configuration file with a list of allowed credit
card types.
No multiple currency support (probably a larger project than just this module).
the FS::Record manpage, the FS::cust_pkg manpage, the FS::cust_bill manpage, the FS::cust_credit manpage
the FS::cust_pay_batch manpage, the FS::agent manpage, the FS::part_referral manpage,
the FS::cust_main_county manpage, the FS::cust_main_invoice manpage,
the FS::UID manpage, schema.html from the base documentation.