Difference between revisions of "Freeside:1.9:Documentation:Developer/FS/cust main"
(import from POD) |
(import from POD) |
||
Line 210: | Line 210: | ||
:Currently available options are: | :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|"time" in perlfunc]]). Also see [[Freeside:1.9:Documentation:Developer/Time/Local|Time::Local]] and [[Freeside:1.9:Documentation:Developer/Date/Parse|Date::Parse]] for conversion functions.:; retry - Retry card/echeck/LEC transactions even when not scheduled by invoice events.:; quiet - set true to surpress email card/ACH decline notices.:; check_freq - "1d" for the traditional, daily events (the default), or "1m" for the new monthly events (part_event.check_freq):; payby - allows for one time override of normal customer billing method | + | :; 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|"time" in perlfunc]]). Also see [[Freeside:1.9:Documentation:Developer/Time/Local|Time::Local]] and [[Freeside:1.9:Documentation:Developer/Date/Parse|Date::Parse]] for conversion functions.:; retry - Retry card/echeck/LEC transactions even when not scheduled by invoice events.:; quiet - set true to surpress email card/ACH decline notices.:; check_freq - "1d" for the traditional, daily events (the default), or "1m" for the new monthly events (part_event.check_freq):; payby - allows for one time override of normal customer billing method; due_cust_event [ HASHREF | OPTION => VALUE ... ] |
− | + | :Inserts database records for and returns an ordered listref of new events due for this customer, as FS::cust_event objects (see [[Freeside:1.9:Documentation:Developer/FS/cust event|FS::cust_event]]). If no events are due, an empty listref is returned. If there is an error, returns a scalar error message. | |
− | + | :To actually run the events, call each event's test_condition method, and if still true, call the event's do_event method. | |
− | + | :Options are passed as a hashref or as a list of name-value pairs. Available options are: | |
− | + | :; check_freq - Search only for events of this check frequency (how often events of this type are checked); currently "1d" (daily, the default) and "1m" (monthly) are recognized.:; time - "Current time" for the events.:; debug - Debugging level. Default is 0 (no debugging), or can be set to 1 (passed-in options), 2 (traces progress), or 3 (more information):; eventtable - Only return events for the specified eventtable (by default, events of all eventtables are returned):; objects - Explicitly pass the objects to be tested (typically used with eventtable).; retry_realtime | |
− | + | :Schedules realtime / batch credit card / electronic check / LEC billing events for for retry. Useful if card information has changed or manual retry is desired. The 'collect' method must be called to actually retry the transaction. | |
− | + | :Implementation details: For either this customer, or for each of this customer's open invoices, changes the status of the first "done" (with statustext error) realtime processing event to "failed". | |
− | + | ; realtime_bop METHOD AMOUNT [ OPTION => VALUE ... ] | |
− | + | :Runs a realtime credit card, ACH (electronic check) or phone bill transaction via a Business::OnlinePayment realtime gateway. See http://420.am/business-onlinepayment for supported gateways. | |
− | + | :Available methods are: ''CC'', ''ECHECK'' and ''LEC'' | |
− | + | :Available options are: ''description'', ''invnum'', ''quiet'' | |
− | + | :The additional options ''payname'', ''address1'', ''address2'', ''city'', ''state'', ''zip'', ''payinfo'' and ''paydate'' are also available. Any of these options, if set, will override the value from the customer record. | |
− | + | :''description'' is a free-text field passed to the gateway. It defaults to "Internet services". | |
− | + | :If an ''invnum'' is specified, this payment (if successful) is applied to the specified invoice. If you don't specify an ''invnum'' you might want to call the '''apply_payments''' method. | |
− | + | :''quiet'' can be set true to surpress email decline notices. | |
− | + | :(moved from cust_bill) (probably should get realtime_{card,ach,lec} here too) | |
− | + | ; default_payment_gateway; remove_cvv | |
− | + | :Removes the ''paycvv'' field from the database directly. | |
− | + | :If there is an error, returns the error, otherwise returns false. | |
− | + | ; realtime_refund_bop METHOD [ OPTION => VALUE ... ] | |
− | + | :Refunds a realtime credit card, ACH (electronic check) or phone bill transaction via a Business::OnlinePayment realtime gateway. See http://420.am/business-onlinepayment for supported gateways. | |
− | + | :Available methods are: ''CC'', ''ECHECK'' and ''LEC'' | |
− | + | :Available options are: ''amount'', ''reason'', ''paynum'', ''paydate'' | |
− | + | :Most gateways require a reference to an original payment transaction to refund, so you probably need to specify a ''paynum''. | |
− | + | :''amount'' defaults to the original amount of the payment if not specified. | |
− | + | :''reason'' specifies a reason for the refund. | |
− | + | :''paydate'' specifies the expiration date for a credit card overriding the value from the customer record or the payment record. Specified as yyyy-mm-dd | |
− | + | :Implementation note: If ''amount'' is unspecified or equal to the amount of the orignal payment, first an attempt is made to "void" the transaction via the gateway (to cancel a not-yet settled transaction) and then if that fails, the normal attempt is made to "refund" ("credit") the transaction via the gateway is attempted. | |
− | + | :#The additional options ''payname'', ''address1'', ''address2'', ''city'', ''state'', #''zip'', ''payinfo'' and ''paydate'' are also available. Any of these options, #if set, will override the value from the customer record. | |
− | + | :#If an ''invnum'' is specified, this payment (if successful) is applied to the #specified invoice. If you don't specify an ''invnum'' you might want to #call the '''apply_payments''' method. | |
− | + | ; batch_card OPTION => VALUE... | |
− | + | :Adds a payment for this invoice to the pending credit card batch (see [[Freeside:1.9:Documentation:Developer/FS/cust pay batch|FS::cust_pay_batch]]), or, if the '''realtime''' option is set to a true value, runs the payment using a realtime gateway. | |
− | + | ; total_owed | |
− | + | :Returns the total owed for this customer on all invoices (see [[Freeside:1.9:Documentation:Developer/FS/cust bill#owed|"owed" in FS/cust bill|FS::cust_bill#owed|"owed" in FS::cust_bill]]). | |
− | + | ; 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|"time" in perlfunc]]). Also see [[Freeside:1.9:Documentation:Developer/Time/Local|Time::Local]] and [[Freeside:1.9:Documentation:Developer/Date/Parse|Date::Parse]] for conversion functions. | |
− | + | ; apply_payments_and_credits | |
− | + | :Applies unapplied payments and credits. | |
− | + | :In most cases, this new method should be used in place of sequential apply_payments and apply_credits methods. | |
− | + | :If there is an error, returns the error, otherwise returns false. | |
− | + | ; apply_credits OPTION => VALUE ... | |
− | + | :Applies (see [[Freeside:1.9:Documentation:Developer/FS/cust credit bill|FS::cust_credit_bill]]) unapplied credits (see [[Freeside:1.9:Documentation:Developer/FS/cust credit|FS::cust_credit]]) to outstanding invoice balances in chronological order (or reverse chronological order if the ''order'' option is set to '''newest''') and returns the value of any remaining unapplied credits available for refund (see [[Freeside:1.9:Documentation:Developer/FS/cust refund|FS::cust_refund]]). | |
− | + | :Dies if there is an error. | |
− | + | ; apply_payments | |
− | + | :Applies (see [[Freeside:1.9:Documentation:Developer/FS/cust bill pay|FS::cust_bill_pay]]) unapplied payments (see [[Freeside:1.9:Documentation:Developer/FS/cust pay|FS::cust_pay]]) to outstanding invoice balances in chronological order. | |
<code> | <code> | ||
#and returns the value of any remaining unapplied payments. | #and returns the value of any remaining unapplied payments. | ||
</code> | </code> | ||
− | + | :Dies if there is an error. | |
− | + | ; total_credited | |
− | + | :Returns the total outstanding credit (see [[Freeside:1.9:Documentation:Developer/FS/cust credit|FS::cust_credit]]) for this customer. See [[Freeside:1.9:Documentation:Developer/FS/cust credit#credited|"credited" in FS/cust credit|FS::cust_credit#credited|"credited" in FS::cust_credit]]. | |
− | + | ; total_unapplied_payments | |
− | + | :Returns the total unapplied payments (see [[Freeside:1.9:Documentation:Developer/FS/cust pay|FS::cust_pay]]) for this customer. See [[Freeside:1.9:Documentation:Developer/FS/cust pay#unapplied|"unapplied" in FS/cust pay|FS::cust_pay#unapplied|"unapplied" in FS::cust_pay]]. | |
− | + | ; total_unapplied_refunds | |
− | + | :Returns the total unrefunded refunds (see [[Freeside:1.9:Documentation:Developer/FS/cust refund|FS::cust_refund]]) for this customer. See [[Freeside:1.9:Documentation:Developer/FS/cust refund#unapplied|"unapplied" in FS/cust refund|FS::cust_refund#unapplied|"unapplied" in FS::cust_refund]]. | |
− | + | ; balance | |
− | + | :Returns the balance for this customer (total_owed plus total_unrefunded, 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|"time" in perlfunc]]). Also see [[Freeside:1.9:Documentation:Developer/Time/Local|Time::Local]] and [[Freeside:1.9:Documentation:Developer/Date/Parse|Date::Parse]] for conversion functions. | |
− | + | ; in_transit_payments | |
− | + | :Returns the total of requests for payments for this customer pending in batches in transit to the bank. See [[Freeside:1.9:Documentation:Developer/FS/pay batch|FS::pay_batch]] and [[Freeside:1.9:Documentation:Developer/FS/cust pay batch|FS::cust_pay_batch]] | |
− | + | ; paydate_monthyear | |
− | + | :Returns a two-element list consisting of the month and year of this customer's paydate (credit card expiration date for CARD customers) | |
− | + | ; invoicing_list [ ARRAYREF ] | |
− | + | :If an arguement is given, sets these email addresses as invoice recipients (see [[Freeside:1.9:Documentation:Developer/FS/cust main invoice|FS::cust_main_invoice]]). 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. | |
− | + | ; set_default_invoicing_list | |
− | + | :Sets the invoicing list to all accounts associated with this customer, overwriting any previous invoicing list. | |
− | + | ; all_emails | |
− | + | :Returns the email addresses of all accounts provisioned for this customer. | |
− | + | ; invoicing_list_addpost | |
− | + | :Adds postal invoicing to this customer. If this customer is already configured to receive postal invoices, does nothing. | |
− | + | ; invoicing_list_emailonly | |
− | + | :Returns the list of email invoice recipients (invoicing_list without non-email destinations such as POST and FAX). | |
− | + | ; invoicing_list_emailonly_scalar | |
− | + | :Returns the list of email invoice recipients (invoicing_list without non-email destinations such as POST and FAX) as a comma-separated scalar. | |
− | + | ; 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_main_ncancelled | |
− | + | :Same as referral_cust_main, except only returns customers with uncancelled packages. | |
− | + | ; referral_cust_pkg [ DEPTH ] | |
− | + | :Like referral_cust_main, except returns a flat list of all unsuspended (and uncancelled) packages for each customer. The number of items in this list may be useful for comission calculations (perhaps after a <tt>grep { my $pkgpart = $_-</tt>pkgpart; grep { $_ == $pkgpart } @commission_worthy_pkgparts> } $cust_main-> ). | |
− | + | ; referring_cust_main | |
− | + | :Returns the single cust_main record for the customer who referred this customer (referral_custnum), or false. | |
− | + | ; credit AMOUNT, REASON | |
− | + | :Applies a credit to this customer. If there is an error, returns the error, otherwise returns false. | |
− | + | ; charge AMOUNT [ PKG [ COMMENT [ TAXCLASS ] ] ] | |
− | + | :Creates a one-time charge for this customer. If there is an error, returns the error, otherwise returns false. | |
− | + | ; cust_bill | |
− | + | :Returns all the invoices (see [[Freeside:1.9:Documentation:Developer/FS/cust bill|FS::cust_bill]]) for this customer. | |
− | + | ; open_cust_bill | |
− | + | :Returns all the open (owed > 0) invoices (see [[Freeside:1.9:Documentation:Developer/FS/cust bill|FS::cust_bill]]) for this customer. | |
− | + | ; cust_credit | |
− | + | :Returns all the credits (see [[Freeside:1.9:Documentation:Developer/FS/cust credit|FS::cust_credit]]) for this customer. | |
− | + | ; cust_pay | |
− | + | :Returns all the payments (see [[Freeside:1.9:Documentation:Developer/FS/cust pay|FS::cust_pay]]) for this customer. | |
− | + | ; cust_pay_void | |
− | + | :Returns all voided payments (see [[Freeside:1.9:Documentation:Developer/FS/cust pay void|FS::cust_pay_void]]) for this customer. | |
− | + | ; cust_pay_batch | |
− | + | :Returns all batched payments (see [[Freeside:1.9:Documentation:Developer/FS/cust pay void|FS::cust_pay_void]]) for this customer. | |
− | + | ; cust_refund | |
− | + | :Returns all the refunds (see [[Freeside:1.9:Documentation:Developer/FS/cust refund|FS::cust_refund]]) for this customer. | |
− | + | ; name | |
− | + | :Returns a name string for this customer, either "Company (Last, First)" or "Last, First". | |
− | + | ; ship_name | |
− | + | :Returns a name string for this (service/shipping) contact, either "Company (Last, First)" or "Last, First". | |
− | + | ; contact | |
− | + | :Returns this customer's full (billing) contact name only, "Last, First" | |
− | + | ; ship_contact | |
− | + | :Returns this customer's full (shipping) contact name only, "Last, First" | |
− | + | ; country_full | |
− | + | :Returns this customer's full country name | |
− | + | ; cust_status; status | |
− | + | :Returns a status string for this customer, currently: | |
− | + | :; prospect - No packages have ever been ordered:; active - One or more recurring packages is active:; inactive - No active recurring packages, but otherwise unsuspended/uncancelled (the inactive status is new - previously inactive customers were mis-identified as cancelled):; suspended - All non-cancelled recurring packages are suspended:; cancelled - All recurring packages are cancelled; ucfirst_cust_status; ucfirst_status | |
− | + | :Returns the status with the first character capitalized. | |
− | + | ; statuscolor | |
− | + | :Returns a hex triplet color string for this customer's status. | |
− | + | ; tickets | |
− | + | :Returns an array of hashes representing the customer's RT tickets. | |
==CLASS METHODS== | ==CLASS METHODS== | ||
Line 452: | Line 452: | ||
==SEE ALSO== | ==SEE ALSO== | ||
[[Freeside:1.9:Documentation:Developer/FS/Record|FS::Record]], [[Freeside:1.9:Documentation:Developer/FS/cust pkg|FS::cust_pkg]], [[Freeside:1.9:Documentation:Developer/FS/cust bill|FS::cust_bill]], [[Freeside:1.9:Documentation:Developer/FS/cust credit|FS::cust_credit]] [[Freeside:1.9:Documentation:Developer/FS/agent|FS::agent]], [[Freeside:1.9:Documentation:Developer/FS/part referral|FS::part_referral]], [[Freeside:1.9:Documentation:Developer/FS/cust main county|FS::cust_main_county]], [[Freeside:1.9:Documentation:Developer/FS/cust main invoice|FS::cust_main_invoice]], [[Freeside:1.9:Documentation:Developer/FS/UID|FS::UID]], schema.html from the base documentation. | [[Freeside:1.9:Documentation:Developer/FS/Record|FS::Record]], [[Freeside:1.9:Documentation:Developer/FS/cust pkg|FS::cust_pkg]], [[Freeside:1.9:Documentation:Developer/FS/cust bill|FS::cust_bill]], [[Freeside:1.9:Documentation:Developer/FS/cust credit|FS::cust_credit]] [[Freeside:1.9:Documentation:Developer/FS/agent|FS::agent]], [[Freeside:1.9:Documentation:Developer/FS/part referral|FS::part_referral]], [[Freeside:1.9:Documentation:Developer/FS/cust main county|FS::cust_main_county]], [[Freeside:1.9:Documentation:Developer/FS/cust main invoice|FS::cust_main_invoice]], [[Freeside:1.9:Documentation:Developer/FS/UID|FS::UID]], schema.html from the base documentation. | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− |
Revision as of 18:25, 3 October 2007
NAME
FS::cust_main - Object methods for cust_main records
SYNOPSIS
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, ;
DESCRIPTION
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 FS::agent); refnum - Advertising source (see FS::part_referral); first - name; last - name; ss - social security number (optional); company - (optional); address1; address2 - (optional); city; county - (optional, see FS::cust_main_county); state - (see FS::cust_main_county); zip; country - (see FS::cust_main_county); 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 FS::cust_main_county); ship_state - (see FS::cust_main_county); ship_zip; ship_country - (see FS::cust_main_county); ship_daytime - phone (optional); ship_night - phone (optional); ship_fax - phone (optional); payby - Payment Type (See FS::payinfo_Mixin for valid payby values); payinfo - Payment Information (See FS::payinfo_Mixin for data format); paymask - Masked payinfo (See FS::payinfo_Mixin for how this works); paycvv
- Card Verification Value, "CVV2" (also known as CVC2 or CID), the 3 or 4 digit number on the back (or front, for American Express) of the credit card
- paydate - expiration date, mm/yyyy, m/yyyy, mm/yy or m/yy; paystart_month - start date month (maestro/solo cards only); paystart_year - start date year (maestro/solo cards only); payissue - issue number (maestro/solo cards only); payname - name on card or billing name; payip - IP address from which payment information was received; tax - tax exempt, empty or `Y'; otaker - order taker (assigned automatically, see FS::UID); comments - comments (optional); referral_custnum - referring customer number; spool_cdr - Enable individual CDR spooling, empty or `Y'
METHODS
- 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 ] [ , OPTION => VALUE ... ] ]
- 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' ] );
- Currently available options are: depend_jobnum and noexport.
- If depend_jobnum is set, all provisioning jobs will have a dependancy on the supplied jobnum (they will not run until the specific job completes). This can be used to defer provisioning until some action completes (such as running the customer's credit card successfully).
- The noexport option is deprecated. If noexport is set true, no provisioning jobs (exports) are scheduled. (You can schedule them later with the reexport method.)
- order_pkgs HASHREF, [ SECONDSREF, [ , OPTION => VALUE ... ] ]
- Like the insert method on an existing record, this method orders a package and included services atomicaly. Pass a Tie::RefHash data structure to this method containing FS::cust_pkg and FS::svc_tablename objects. 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->order_pkgs( \%hash, \'0', 'noexport'=>1 );
- Services can be new, in which case they are inserted, or existing unaudited services, in which case they are linked to the newly-created package.
- Currently available options are: depend_jobnum and noexport.
- If depend_jobnum is set, all provisioning jobs will have a dependancy on the supplied jobnum (they will not run until the specific job completes). This can be used to defer provisioning until some action completes (such as running the customer's credit card successfully).
- The noexport option is deprecated. If noexport is set true, no provisioning jobs (exports) are scheduled. (You can schedule them later with the reexport method for each cust_pkg object. Using the reexport method on the cust_main object is not recommended, as existing services will also be reexported.)
- recharge_prepay IDENTIFIER | PREPAY_CREDIT_OBJ [ , AMOUNTREF, SECONDSREF, UPBYTEREF, DOWNBYTEREF ]
- Recharges this (existing) customer with the specified prepaid card (see FS::prepay_credit), specified either by identifier or as an FS::prepay_credit object. If there is an error, returns the error, otherwise returns false.
- Optionally, four scalar references can be passed as well. They will have their values filled in with the amount, number of seconds, and number of upload and download bytes applied by this prepaid card.
- get_prepay IDENTIFIER | PREPAY_CREDIT_OBJ , AMOUNTREF, SECONDSREF
- Looks up and deletes a prepaid card (see FS::prepay_credit), specified either by identifier or as an FS::prepay_credit object.
- References to amount and seconds scalars should be passed as arguments and will be incremented by the values of the prepaid card.
- If the prepaid card specifies an agentnum (see FS::agent), it is used to check or set this customer's agentnum.
- If there is an error, returns the error, otherwise returns false.
- increment_upbytes SECONDS
- Updates this customer's single or primary account (see FS::svc_acct) by the specified number of upbytes. If there is an error, returns the error, otherwise returns false.
- increment_downbytes SECONDS
- Updates this customer's single or primary account (see FS::svc_acct) by the specified number of downbytes. If there is an error, returns the error, otherwise returns false.
- increment_totalbytes SECONDS
- Updates this customer's single or primary account (see FS::svc_acct) by the specified number of totalbytes. If there is an error, returns the error, otherwise returns false.
- increment_seconds SECONDS
- Updates this customer's single or primary account (see FS::svc_acct) by the specified number of seconds. If there is an error, returns the error, otherwise returns false.
- _increment_column AMOUNT
- Updates this customer's single or primary account (see FS::svc_acct) by the specified number of seconds or bytes. If there is an error, returns the error, otherwise returns false.
- insert_cust_pay_prepay AMOUNT [ PAYINFO ]
- Inserts a prepayment in the specified amount for this customer. An optional second argument can specify the prepayment identifier for tracking purposes. If there is an error, returns the error, otherwise returns false.
- insert_cust_pay_cash AMOUNT [ PAYINFO ]
- Inserts a cash payment in the specified amount for this customer. An optional second argument can specify the payment identifier for tracking purposes. If there is an error, returns the error, otherwise returns false.
- insert_cust_pay_west AMOUNT [ PAYINFO ]
- Inserts a Western Union payment in the specified amount for this customer. An optional second argument can specify the prepayment identifier for tracking purposes. If there is an error, returns the error, otherwise returns false.
- reexport
- This method is deprecated. See the depend_jobnum option to the insert and order_pkgs methods for a better way to defer provisioning.
- Re-schedules all exports by calling the reexport method of all associated packages (see FS::cust_pkg). If there is an error, returns the error; otherwise returns false.
- 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").
- 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 FS/cust pkg|FS::cust_pkg#cancel|"cancel" in FS::cust_pkg?
- You can't delete a customer with invoices (see FS::cust_bill), or credits (see FS::cust_credit), payments (see FS::cust_pay) or refunds (see FS::cust_refund).
- 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' ] );
- queue_fuzzyfiles_update
- Used by insert & replace to update the fuzzy search cache
- 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 replace methods.
- all_pkgs
- Returns all packages (see FS::cust_pkg) for this customer.
- cust_pkg
- Synonym for all_pkgs.
- ncancelled_pkgs
- Returns all non-cancelled packages (see FS::cust_pkg) for this customer.
- suspended_pkgs
- Returns all suspended packages (see FS::cust_pkg) for this customer.
- unflagged_suspended_pkgs
- Returns all unflagged suspended packages (see FS::cust_pkg) for this customer (thouse packages without the `manual_flag' set).
- unsuspended_pkgs
- Returns all unsuspended (and uncancelled) packages (see FS::cust_pkg) for this customer.
- num_cancelled_pkgs
- Returns the number of cancelled packages (see FS::cust_pkg) for this customer.
- unsuspend
- Unsuspends all unflagged suspended packages (see "unflagged_suspended_pkgs" and FS::cust_pkg) for this customer. Always returns a list: an empty list on success or a list of errors.
- suspend
- Suspends all unsuspended packages (see FS::cust_pkg) for this customer.
- Returns a list: an empty list on success or a list of errors.
- suspend_if_pkgpart HASHREF | PKGPART [ , PKGPART ... ]
- Suspends all unsuspended packages (see FS::cust_pkg) matching the listed PKGPARTs (see FS::part_pkg). Preferred usage is to pass a hashref instead of a list of pkgparts; the hashref has the following keys:
- pkgparts - listref of pkgparts
- ; (other options are passed to the suspend method)
- Returns a list: an empty list on success or a list of errors.
- suspend_unless_pkgpart HASHREF | PKGPART [ , PKGPART ... ]
- Suspends all unsuspended packages (see FS::cust_pkg) unless they match the given PKGPARTs (see FS::part_pkg). Preferred usage is to pass a hashref instead of a list of pkgparts; the hashref has the following keys:
- pkgparts - listref of pkgparts
- ; (other options are passed to the suspend method)
- Returns a list: an empty list on success or a list of errors.
- cancel [ OPTION => VALUE ... ]
- Cancels all uncancelled packages (see FS::cust_pkg) for this customer.
- Available options are:
- quiet - can be set true to supress email cancellation notices.
- ; reason - can be set to a cancellation reason (see FS:reason), either a reasonnum of an existing reason, or passing a hashref will create a new reason. The hashref should have the following keys: typenum - Reason type (see FS::reason_type, reason - Text of the new reason.:; ban - can be set true to ban this customer's credit card or ACH information, if present.
- Always returns a list: an empty list on success or a list of errors.
- notes
- Returns all notes (see FS::cust_main_note) for this customer.
- agent
- Returns the agent (see FS::agent) for this customer.
- bill_and_collect
- Cancels and suspends any packages due, generates bills, applies payments and cred
- Warns on errors (Does not currently: If there is an error, returns the error, otherwise returns false.)
- Options are passed as name-value pairs. Currently available options are:
- time - bills the customer as if it were that time. Specified as a UNIX timestamp; see "time" in perlfunc). Also see Time::Local and Date::Parse for conversion functions. For example:
- time - bills the customer as if it were that time. Specified as a UNIX timestamp; see "time" in perlfunc). Also see Time::Local and Date::Parse for conversion functions. For example:
use Date::Parse; ... $cust_main->bill( 'time' => str2time('April 20th, 2001') );
- invoice_time - used in conjunction with the time option, this option specifies the date of for the generated invoices. Other calculations, such as whether or not to generate the invoice in the first place, are not affected.
- ; check_freq - "1d" for the traditional, daily events (the default), or "1m" for the new monthly events (part_event.check_freq):; resetup - if set true, re-charges setup fees.; bill OPTIONS
- Generates invoices (see FS::cust_bill) for this customer. Usually used in conjunction with the collect method by calling bill_and_collect.
- If there is an error, returns the error, otherwise returns false.
- Options are passed as name-value pairs. Currently available options are:
- resetup - if set true, re-charges setup fees.
- ; time - bills the customer as if it were that time. Specified as a UNIX timestamp; see "time" in perlfunc). Also see Time::Local and Date::Parse for conversion functions. For example:
use Date::Parse; ... $cust_main->bill( 'time' => str2time('April 20th, 2001') );
- pkg_list - An array ref of specific packages (objects) to attempt billing, instead trying all of them.
- pkg_list - An array ref of specific packages (objects) to attempt billing, instead trying all of them.
$cust_main->bill( pkg_list => [$pkg1, $pkg2] );
- invoice_time - used in conjunction with the time option, this option specifies the date of for the generated invoices. Other calculations, such as whether or not to generate the invoice in the first place, are not affected.; collect OPTIONS
- (Attempt to) collect money for this customer's outstanding invoices (see FS::cust_bill). Usually used after the bill method.
- Actions are now triggered by billing events; see FS::part_event and the billing events web interface. Old-style invoice events (see FS::part_bill_event) have been deprecated.
- 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 "time" in perlfunc). Also see Time::Local and Date::Parse for conversion functions.
- ; retry - Retry card/echeck/LEC transactions even when not scheduled by invoice events.:; quiet - set true to surpress email card/ACH decline notices.:; check_freq - "1d" for the traditional, daily events (the default), or "1m" for the new monthly events (part_event.check_freq):; payby - allows for one time override of normal customer billing method; due_cust_event [ HASHREF | OPTION => VALUE ... ]
- Inserts database records for and returns an ordered listref of new events due for this customer, as FS::cust_event objects (see FS::cust_event). If no events are due, an empty listref is returned. If there is an error, returns a scalar error message.
- To actually run the events, call each event's test_condition method, and if still true, call the event's do_event method.
- Options are passed as a hashref or as a list of name-value pairs. Available options are:
- check_freq - Search only for events of this check frequency (how often events of this type are checked); currently "1d" (daily, the default) and "1m" (monthly) are recognized.
- ; time - "Current time" for the events.:; debug - Debugging level. Default is 0 (no debugging), or can be set to 1 (passed-in options), 2 (traces progress), or 3 (more information):; eventtable - Only return events for the specified eventtable (by default, events of all eventtables are returned):; objects - Explicitly pass the objects to be tested (typically used with eventtable).; retry_realtime
- Schedules realtime / batch credit card / electronic check / LEC billing events for for retry. Useful if card information has changed or manual retry is desired. The 'collect' method must be called to actually retry the transaction.
- Implementation details: For either this customer, or for each of this customer's open invoices, changes the status of the first "done" (with statustext error) realtime processing event to "failed".
- realtime_bop METHOD AMOUNT [ OPTION => VALUE ... ]
- Runs a realtime credit card, ACH (electronic check) or phone bill transaction via a Business::OnlinePayment realtime gateway. See http://420.am/business-onlinepayment for supported gateways.
- Available methods are: CC, ECHECK and LEC
- Available options are: description, invnum, quiet
- The additional options payname, address1, address2, city, state, zip, payinfo and paydate are also available. Any of these options, if set, will override the value from the customer record.
- description is a free-text field passed to the gateway. It defaults to "Internet services".
- If an invnum is specified, this payment (if successful) is applied to the specified invoice. If you don't specify an invnum you might want to call the apply_payments method.
- quiet can be set true to surpress email decline notices.
- (moved from cust_bill) (probably should get realtime_{card,ach,lec} here too)
- default_payment_gateway; remove_cvv
- Removes the paycvv field from the database directly.
- If there is an error, returns the error, otherwise returns false.
- realtime_refund_bop METHOD [ OPTION => VALUE ... ]
- Refunds a realtime credit card, ACH (electronic check) or phone bill transaction via a Business::OnlinePayment realtime gateway. See http://420.am/business-onlinepayment for supported gateways.
- Available methods are: CC, ECHECK and LEC
- Available options are: amount, reason, paynum, paydate
- Most gateways require a reference to an original payment transaction to refund, so you probably need to specify a paynum.
- amount defaults to the original amount of the payment if not specified.
- reason specifies a reason for the refund.
- paydate specifies the expiration date for a credit card overriding the value from the customer record or the payment record. Specified as yyyy-mm-dd
- Implementation note: If amount is unspecified or equal to the amount of the orignal payment, first an attempt is made to "void" the transaction via the gateway (to cancel a not-yet settled transaction) and then if that fails, the normal attempt is made to "refund" ("credit") the transaction via the gateway is attempted.
- The additional options payname, address1, address2, city, state, #zip, payinfo and paydate are also available. Any of these options, #if set, will override the value from the customer record.
- If an invnum is specified, this payment (if successful) is applied to the #specified invoice. If you don't specify an invnum you might want to #call the apply_payments method.
- batch_card OPTION => VALUE...
- Adds a payment for this invoice to the pending credit card batch (see FS::cust_pay_batch), or, if the realtime option is set to a true value, runs the payment using a realtime gateway.
- total_owed
- Returns the total owed for this customer on all invoices (see "owed" in FS/cust bill|FS::cust_bill#owed|"owed" in FS::cust_bill).
- 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 "time" in perlfunc). Also see Time::Local and Date::Parse for conversion functions.
- apply_payments_and_credits
- Applies unapplied payments and credits.
- In most cases, this new method should be used in place of sequential apply_payments and apply_credits methods.
- If there is an error, returns the error, otherwise returns false.
- apply_credits OPTION => VALUE ...
- Applies (see FS::cust_credit_bill) unapplied credits (see FS::cust_credit) to outstanding invoice balances in chronological order (or reverse chronological order if the order option is set to newest) and returns the value of any remaining unapplied credits available for refund (see FS::cust_refund).
- Dies if there is an error.
- apply_payments
- Applies (see FS::cust_bill_pay) unapplied payments (see FS::cust_pay) to outstanding invoice balances in chronological order.
#and returns the value of any remaining unapplied payments.
- Dies if there is an error.
- total_credited
- Returns the total outstanding credit (see FS::cust_credit) for this customer. See "credited" in FS/cust credit|FS::cust_credit#credited|"credited" in FS::cust_credit.
- total_unapplied_payments
- Returns the total unapplied payments (see FS::cust_pay) for this customer. See "unapplied" in FS/cust pay|FS::cust_pay#unapplied|"unapplied" in FS::cust_pay.
- total_unapplied_refunds
- Returns the total unrefunded refunds (see FS::cust_refund) for this customer. See "unapplied" in FS/cust refund|FS::cust_refund#unapplied|"unapplied" in FS::cust_refund.
- balance
- Returns the balance for this customer (total_owed plus total_unrefunded, 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 "time" in perlfunc). Also see Time::Local and Date::Parse for conversion functions.
- in_transit_payments
- Returns the total of requests for payments for this customer pending in batches in transit to the bank. See FS::pay_batch and FS::cust_pay_batch
- paydate_monthyear
- Returns a two-element list consisting of the month and year of this customer's paydate (credit card expiration date for CARD customers)
- invoicing_list [ ARRAYREF ]
- If an arguement is given, sets these email addresses as invoice recipients (see FS::cust_main_invoice). 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.
- set_default_invoicing_list
- Sets the invoicing list to all accounts associated with this customer, overwriting any previous invoicing list.
- all_emails
- Returns the email addresses of all accounts provisioned for this customer.
- invoicing_list_addpost
- Adds postal invoicing to this customer. If this customer is already configured to receive postal invoices, does nothing.
- invoicing_list_emailonly
- Returns the list of email invoice recipients (invoicing_list without non-email destinations such as POST and FAX).
- invoicing_list_emailonly_scalar
- Returns the list of email invoice recipients (invoicing_list without non-email destinations such as POST and FAX) as a comma-separated scalar.
- 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_main_ncancelled
- Same as referral_cust_main, except only returns customers with uncancelled packages.
- referral_cust_pkg [ DEPTH ]
- Like referral_cust_main, except returns a flat list of all unsuspended (and uncancelled) packages for each customer. The number of items in this list may be useful for comission calculations (perhaps after a grep { my $pkgpart = $_-pkgpart; grep { $_ == $pkgpart } @commission_worthy_pkgparts> } $cust_main-> ).
- referring_cust_main
- Returns the single cust_main record for the customer who referred this customer (referral_custnum), or false.
- credit AMOUNT, REASON
- Applies a credit to this customer. If there is an error, returns the error, otherwise returns false.
- charge AMOUNT [ PKG [ COMMENT [ TAXCLASS ] ] ]
- Creates a one-time charge for this customer. If there is an error, returns the error, otherwise returns false.
- cust_bill
- Returns all the invoices (see FS::cust_bill) for this customer.
- open_cust_bill
- Returns all the open (owed > 0) invoices (see FS::cust_bill) for this customer.
- cust_credit
- Returns all the credits (see FS::cust_credit) for this customer.
- cust_pay
- Returns all the payments (see FS::cust_pay) for this customer.
- cust_pay_void
- Returns all voided payments (see FS::cust_pay_void) for this customer.
- cust_pay_batch
- Returns all batched payments (see FS::cust_pay_void) for this customer.
- cust_refund
- Returns all the refunds (see FS::cust_refund) for this customer.
- name
- Returns a name string for this customer, either "Company (Last, First)" or "Last, First".
- ship_name
- Returns a name string for this (service/shipping) contact, either "Company (Last, First)" or "Last, First".
- contact
- Returns this customer's full (billing) contact name only, "Last, First"
- ship_contact
- Returns this customer's full (shipping) contact name only, "Last, First"
- country_full
- Returns this customer's full country name
- cust_status; status
- Returns a status string for this customer, currently:
- prospect - No packages have ever been ordered
- ; active - One or more recurring packages is active:; inactive - No active recurring packages, but otherwise unsuspended/uncancelled (the inactive status is new - previously inactive customers were mis-identified as cancelled):; suspended - All non-cancelled recurring packages are suspended:; cancelled - All recurring packages are cancelled; ucfirst_cust_status; ucfirst_status
- Returns the status with the first character capitalized.
- statuscolor
- Returns a hex triplet color string for this customer's status.
- tickets
- Returns an array of hashes representing the customer's RT tickets.
CLASS METHODS
- statuses
- Class method that returns the list of possible status strings for customers (see the status method). For example:
@statuses = FS::cust_main->statuses();
- prospect_sql
- Returns an SQL expression identifying prospective cust_main records (customers with no packages ever ordered)
- active_sql
- Returns an SQL expression identifying active cust_main records (customers with no active recurring packages, but otherwise unsuspended/uncancelled).
- inactive_sql
- Returns an SQL expression identifying inactive cust_main records (customers with active recurring packages).
- susp_sql =item suspended_sql
- Returns an SQL expression identifying suspended cust_main records.
- cancel_sql =item cancelled_sql
- Returns an SQL expression identifying cancelled cust_main records.
- uncancel_sql =item uncancelled_sql
- Returns an SQL expression identifying un-cancelled cust_main records.
- balance_sql
- Returns an SQL fragment to retreive the balance.
- balance_date_sql TIME
- Returns an SQL fragment to retreive 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 an SQL fragment or a numeric UNIX timestamp; see "time" in perlfunc). Also see Time::Local and Date::Parse for conversion functions.
- fuzzy_search FUZZY_HASHREF [ HASHREF, SELECT, EXTRA_SQL, CACHE_OBJ ]
- Performs a fuzzy (approximate) search and returns the matching FS::cust_main records. Currently, first, last and/or company may be specified (the appropriate ship_ field is also searched).
- Additional options are the same as FS::Record::qsearch
- masked FIELD
- Returns a masked version of the named field
SUBROUTINES
- smart_search OPTION => VALUE ...
- Accepts the following options: search, the string to search for. The string will be searched for as a customer number, phone number, name or company name, as an exact, or, in some cases, a substring or fuzzy match (see the source code for the exact heuristics used); no_fuzzy_on_exact, causes smart_search to skip fuzzy matching when an exact match is found.
- Any additional options are treated as an additional qualifier on the search (i.e. agentnum).
- Returns a (possibly empty) array of FS::cust_main objects.
- check_and_rebuild_fuzzyfiles; rebuild_fuzzyfiles; all_X; append_fuzzyfiles LASTNAME COMPANY; batch_import; batch_charge; notify CUSTOMER_OBJECT TEMPLATE_NAME OPTIONS
- Sends a templated email notification to the customer (see Text::Template).
- OPTIONS is a hash and may include
- from - the email sender (default is invoice_from)
- to - comma-separated scalar or arrayref of recipients (default is invoicing_list)
- subject - The subject line of the sent email notification (default is "Notice from company_name")
- extra_fields - a hashref of name/value pairs which will be substituted into the template
- The following variables are vavailable in the template.
- $first - the customer first name $last - the customer last name $company - the customer company $payby - a description of the method of payment for the customer # would be nice to use FS::payby::shortname $payinfo - the account information used to collect for this customer $expdate - the expiration of the customer payment in seconds from epoch
- generate_letter CUSTOMER_OBJECT TEMPLATE_NAME OPTIONS
- Generates a templated notification to the customer (see Text::Template).
- OPTIONS is a hash and may include
- extra_fields - a hashref of name/value pairs which will be substituted into the template. These values may override values mentioned below and those from the customer record.
- The following variables are available in the template instead of or in addition to the fields of the customer record.
- $payby - a description of the method of payment for the customer # would be nice to use FS::payby::shortname $payinfo - the masked account information used to collect for this customer $expdate - the expiration of the customer payment method in seconds from epoch $returnaddress - the return address defaults to invoice_latexreturnaddress
- print_ps TEMPLATE
- Returns an postscript letter filled in from TEMPLATE, as a scalar.
- print TEMPLATE
- Prints the filled in template.
- TEMPLATE is the name of a Text::Template to fill in and print.
BUGS
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.
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).
payinfo_masked false laziness with cust_pay.pm and cust_refund.pm
Birthdates rely on negative epoch values.
The payby for card/check batches is broken. With mixed batching, bad things will happen.
collect invoice_time should be renamed time, like bill.
SEE ALSO
FS::Record, FS::cust_pkg, FS::cust_bill, FS::cust_credit FS::agent, FS::part_referral, FS::cust_main_county, FS::cust_main_invoice, FS::UID, schema.html from the base documentation.