Difference between revisions of "Freeside:1.7:Documentation:Developer/FS/cust main"
(import from POD) |
m (Edit via perl MediaWiki framework (1.13)) |
||
Line 37: | Line 37: | ||
; custnum - primary key (assigned automatically for new customers); agentnum - agent (see [[Freeside:1.7:Documentation:Developer/FS/agent|FS::agent]]); refnum - Advertising source (see [[Freeside:1.7:Documentation:Developer/FS/part referral|FS::part_referral]]); first - name; last - name; ss - social security number (optional); company - (optional); address1; address2 - (optional); city; county - (optional, see [[Freeside:1.7:Documentation:Developer/FS/cust main county|FS::cust_main_county]]); state - (see [[Freeside:1.7:Documentation:Developer/FS/cust main county|FS::cust_main_county]]); zip; country - (see [[Freeside:1.7:Documentation:Developer/FS/cust main county|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 [[Freeside:1.7:Documentation:Developer/FS/cust main county|FS::cust_main_county]]); ship_state - (see [[Freeside:1.7:Documentation:Developer/FS/cust main county|FS::cust_main_county]]); ship_zip; ship_country - (see [[Freeside:1.7:Documentation:Developer/FS/cust main county|FS::cust_main_county]]); ship_daytime - phone (optional); ship_night - phone (optional); ship_fax - phone (optional); payby - Payment Type (See [[Freeside:1.7:Documentation:Developer/FS/payinfo Mixin|FS::payinfo_Mixin]] for valid payby values); payinfo - Payment Information (See [[Freeside:1.7:Documentation:Developer/FS/payinfo Mixin|FS::payinfo_Mixin]] for data format); paymask - Masked payinfo (See [[Freeside:1.7:Documentation:Developer/FS/payinfo Mixin|FS::payinfo_Mixin]] for how this works); paycvv | ; custnum - primary key (assigned automatically for new customers); agentnum - agent (see [[Freeside:1.7:Documentation:Developer/FS/agent|FS::agent]]); refnum - Advertising source (see [[Freeside:1.7:Documentation:Developer/FS/part referral|FS::part_referral]]); first - name; last - name; ss - social security number (optional); company - (optional); address1; address2 - (optional); city; county - (optional, see [[Freeside:1.7:Documentation:Developer/FS/cust main county|FS::cust_main_county]]); state - (see [[Freeside:1.7:Documentation:Developer/FS/cust main county|FS::cust_main_county]]); zip; country - (see [[Freeside:1.7:Documentation:Developer/FS/cust main county|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 [[Freeside:1.7:Documentation:Developer/FS/cust main county|FS::cust_main_county]]); ship_state - (see [[Freeside:1.7:Documentation:Developer/FS/cust main county|FS::cust_main_county]]); ship_zip; ship_country - (see [[Freeside:1.7:Documentation:Developer/FS/cust main county|FS::cust_main_county]]); ship_daytime - phone (optional); ship_night - phone (optional); ship_fax - phone (optional); payby - Payment Type (See [[Freeside:1.7:Documentation:Developer/FS/payinfo Mixin|FS::payinfo_Mixin]] for valid payby values); payinfo - Payment Information (See [[Freeside:1.7:Documentation:Developer/FS/payinfo Mixin|FS::payinfo_Mixin]] for data format); paymask - Masked payinfo (See [[Freeside:1.7:Documentation:Developer/FS/payinfo Mixin|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 | :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 [[Freeside:1.7:Documentation:Developer/FS/UID|FS::UID]]); comments - comments (optional); referral_custnum - referring customer number; spool_cdr - Enable individual CDR spooling, empty or `Y' | + | ; 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 [[Freeside:1.7:Documentation:Developer/FS/UID|FS::UID]]); comments - comments (optional); referral_custnum - referring customer number; spool_cdr - Enable individual CDR spooling, empty or `Y'; dundate - a suggestion to events (see [[Freeside:1.7:Documentation:Developer/FS/part bill event"|FS::part_bill_event"]]) to delay until this unix timestamp |
==METHODS== | ==METHODS== | ||
; new HASHREF | ; new HASHREF | ||
Line 67: | Line 67: | ||
: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.) | :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 | + | ; order_pkgs HASHREF [ , 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: | :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: | ||
<code> | <code> | ||
Line 76: | Line 76: | ||
... | ... | ||
); | ); | ||
− | $cust_main->order_pkgs( \%hash | + | $cust_main->order_pkgs( \%hash, 'noexport'=>1 ); |
</code> | </code> | ||
: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. | :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 '' | + | :Currently available options are: ''depend_jobnum'', ''noexport'', ''seconds_ref'', ''upbytes_ref'', ''downbytes_ref'', and ''totalbytes_ref''. |
: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). | :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.) | :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.) | ||
+ | |||
+ | :If ''seconds_ref'', ''upbytes_ref'', ''downbytes_ref'', or ''totalbytes_ref'' is provided, the scalars (provided by references) will be incremented by the values of the prepaid card.` | ||
; recharge_prepay IDENTIFIER | PREPAY_CREDIT_OBJ [ , AMOUNTREF, SECONDSREF, UPBYTEREF, DOWNBYTEREF ] | ; recharge_prepay IDENTIFIER | PREPAY_CREDIT_OBJ [ , AMOUNTREF, SECONDSREF, UPBYTEREF, DOWNBYTEREF ] | ||
:Recharges this (existing) customer with the specified prepaid card (see [[Freeside:1.7:Documentation:Developer/FS/prepay credit|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. | :Recharges this (existing) customer with the specified prepaid card (see [[Freeside:1.7:Documentation:Developer/FS/prepay credit|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, | + | :Optionally, five scalar references can be passed as well. They will have their values filled in with the amount, number of seconds, and number of upload, download, and total bytes applied by this prepaid card. |
− | ; get_prepay IDENTIFIER | PREPAY_CREDIT_OBJ , | + | ; get_prepay IDENTIFIER | PREPAY_CREDIT_OBJ [ , OPTION => VALUE ... ] |
:Looks up and deletes a prepaid card (see [[Freeside:1.7:Documentation:Developer/FS/prepay credit|FS::prepay_credit]]), specified either by ''identifier'' or as an FS::prepay_credit object. | :Looks up and deletes a prepaid card (see [[Freeside:1.7:Documentation:Developer/FS/prepay credit|FS::prepay_credit]]), specified either by ''identifier'' or as an FS::prepay_credit object. | ||
− | : | + | :Available options are: ''amount_ref'', ''seconds_ref'', ''upbytes_ref'', ''downbytes_ref'', and ''totalbytes_ref''. The scalars (provided by references) will be incremented by the values of the prepaid card. |
:If the prepaid card specifies an ''agentnum'' (see [[Freeside:1.7:Documentation:Developer/FS/agent|FS::agent]]), it is used to check or set this customer's ''agentnum''. | :If the prepaid card specifies an ''agentnum'' (see [[Freeside:1.7:Documentation:Developer/FS/agent|FS::agent]]), it is used to check or set this customer's ''agentnum''. | ||
Line 183: | Line 185: | ||
; agent | ; agent | ||
:Returns the agent (see [[Freeside:1.7:Documentation:Developer/FS/agent|FS::agent]]) for this customer. | :Returns the agent (see [[Freeside:1.7:Documentation:Developer/FS/agent|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 [[perlfunc#time|"time" in perlfunc]]). Also see [[Freeside:1.7:Documentation:Developer/Time/Local|Time::Local]] and [[Freeside:1.7:Documentation:Developer/Date/Parse|Date::Parse]] for conversion functions. For example: | ||
+ | <code> | ||
+ | use Date::Parse; | ||
+ | ... | ||
+ | $cust_main->bill( 'time' => str2time('April 20th, 2001') ); | ||
+ | </code> | ||
+ | :; 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. | ||
+ | :; resetup | ||
+ | ::If set true, re-charges setup fees. | ||
+ | :; debug | ||
+ | ::Debugging level. Default is 0 (no debugging), or can be set to 1 (passed-in options), 2 (traces progress), 3 (more information), or 4 (include full search queries) | ||
; bill OPTIONS | ; bill OPTIONS | ||
:Generates invoices (see [[Freeside:1.7:Documentation:Developer/FS/cust bill|FS::cust_bill]]) for this customer. Usually used in conjunction with the collect method. | :Generates invoices (see [[Freeside:1.7:Documentation:Developer/FS/cust bill|FS::cust_bill]]) for this customer. Usually used in conjunction with the collect method. | ||
Line 350: | Line 371: | ||
; ship_name | ; ship_name | ||
:Returns a name string for this (service/shipping) contact, either "Company (Last, First)" or "Last, First". | :Returns a name string for this (service/shipping) contact, either "Company (Last, First)" or "Last, First". | ||
+ | ; name_short | ||
+ | :Returns a name string for this customer, either "Company" or "First Last". | ||
+ | ; ship_name_short | ||
+ | :Returns a name string for this (service/shipping) contact, either "Company" or "First Last". | ||
; contact | ; contact | ||
:Returns this customer's full (billing) contact name only, "Last, First" | :Returns this customer's full (billing) contact name only, "Last, First" | ||
; ship_contact | ; ship_contact | ||
:Returns this customer's full (shipping) contact name only, "Last, First" | :Returns this customer's full (shipping) contact name only, "Last, First" | ||
+ | ; contact_firstlast | ||
+ | :Returns this customers full (billing) contact name only, "First Last". | ||
+ | ; ship_contact_firstlast | ||
+ | :Returns this customer's full (shipping) contact name only, "First Last". | ||
; country_full | ; country_full | ||
:Returns this customer's full country name | :Returns this customer's full country name | ||
Line 364: | Line 393: | ||
==CLASS METHODS== | ==CLASS METHODS== | ||
+ | ; statuses | ||
+ | :Class method that returns the list of possible status strings for customers (see [[#status|the status method]]). For example: | ||
+ | <code> | ||
+ | @statuses = FS::cust_main->statuses(); | ||
+ | </code> | ||
; prospect_sql | ; prospect_sql | ||
:Returns an SQL expression identifying prospective cust_main records (customers with no packages ever ordered) | :Returns an SQL expression identifying prospective cust_main records (customers with no packages ever ordered) | ||
; active_sql | ; active_sql | ||
− | :Returns an SQL expression identifying active cust_main records (customers with | + | :Returns an SQL expression identifying active cust_main records (customers with active recurring packages). |
; inactive_sql | ; inactive_sql | ||
− | :Returns an SQL expression identifying inactive cust_main records (customers with active recurring packages). | + | :Returns an SQL expression identifying inactive cust_main records (customers with no active recurring packages, but otherwise unsuspended/uncancelled). |
; susp_sql =item suspended_sql | ; susp_sql =item suspended_sql | ||
:Returns an SQL expression identifying suspended cust_main records. | :Returns an SQL expression identifying suspended cust_main records. | ||
Line 390: | Line 424: | ||
:If TABLE is "cust_bill" or the unapplied_date option is true, only considers records with date earlier than START_TIME, and optionally not later than END_TIME . | :If TABLE is "cust_bill" or the unapplied_date option is true, only considers records with date earlier than START_TIME, and optionally not later than END_TIME . | ||
+ | ; search_sql HASHREF | ||
+ | :(Class method) | ||
+ | |||
+ | :Returns a qsearch hash expression to search for parameters specified in HREF. Valid parameters are | ||
+ | :; agentnum:; status:; cancelled_pkgs | ||
+ | ::bool | ||
+ | :; signupdate | ||
+ | ::listref of start date, end date | ||
+ | :; payby | ||
+ | ::listref | ||
+ | :; current_balance | ||
+ | ::listref (list returned by FS::UI::Web::parse_lt_gt($cgi, 'current_balance')) | ||
+ | :; cust_fields:; flattened_pkgs | ||
+ | ::bool | ||
+ | ; email_search_sql HASHREF | ||
+ | :(Class method) | ||
+ | |||
+ | :Emails a notice to the specified customers. | ||
+ | |||
+ | :Valid parameters are those of the [[Freeside:1.7:Documentation:Developer/search sql|search_sql]] method, plus the following: | ||
+ | :; from | ||
+ | ::From: address | ||
+ | :; subject | ||
+ | ::Email Subject: | ||
+ | :; html_body | ||
+ | ::HTML body | ||
+ | :; text_body | ||
+ | ::Text body | ||
+ | :; job | ||
+ | ::Optional job queue job for status updates. | ||
+ | |||
+ | :Returns an error message, or false for success. | ||
+ | |||
+ | :If an error occurs during any email, stops the enture send and returns that error. Presumably if you're getting SMTP errors aborting is better than retrying everything. | ||
; fuzzy_search FUZZY_HASHREF [ HASHREF, SELECT, EXTRA_SQL, CACHE_OBJ ] | ; 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). | :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). | ||
Line 405: | Line 473: | ||
:Returns a (possibly empty) array of FS::cust_main objects. | :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 | + | ; email_search |
+ | :Accepts the following options: ''email'', the email address to search for. The email address will be searched for as an email invoice destination and as an svc_acct account. | ||
+ | |||
+ | :#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 (but usually just none or one). | ||
+ | ; check_and_rebuild_fuzzyfiles; rebuild_fuzzyfiles; all_X; append_fuzzyfiles LASTNAME COMPANY; process_batch_import | ||
+ | :Load a batch import as a queued JSRPC job | ||
+ | ; batch_import; batch_charge; notify CUSTOMER_OBJECT TEMPLATE_NAME OPTIONS | ||
:Sends a templated email notification to the customer (see [[Freeside:1.7:Documentation:Developer/Text/Template|Text::Template]]). | :Sends a templated email notification to the customer (see [[Freeside:1.7:Documentation:Developer/Text/Template|Text::Template]]). | ||
Line 461: | Line 537: | ||
Hey! '''The above document had some coding errors, which are explained below:''' | Hey! '''The above document had some coding errors, which are explained below:''' | ||
− | ; Around line | + | ; Around line 3226: |
:'=item' outside of any '=over' | :'=item' outside of any '=over' |
Revision as of 14:00, 23 July 2009
Contents
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'; dundate - a suggestion to events (see FS::part_bill_event") to delay until this unix timestamp
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 [ , 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, '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, noexport, seconds_ref, upbytes_ref, downbytes_ref, and totalbytes_ref.
- 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.)
- If seconds_ref, upbytes_ref, downbytes_ref, or totalbytes_ref is provided, the scalars (provided by references) will be incremented by the values of the prepaid card.`
- 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, five scalar references can be passed as well. They will have their values filled in with the amount, number of seconds, and number of upload, download, and total bytes applied by this prepaid card.
- get_prepay IDENTIFIER | PREPAY_CREDIT_OBJ [ , OPTION => VALUE ... ]
- Looks up and deletes a prepaid card (see FS::prepay_credit), specified either by identifier or as an FS::prepay_credit object.
- Available options are: amount_ref, seconds_ref, upbytes_ref, downbytes_ref, and totalbytes_ref. The scalars (provided by references) 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.
- addr_fields
- Returns a list of fields which have ship_ duplicates.
- has_ship_address
- Returns true if this customer record has a separate shipping address.
- all_pkgs
- Returns all packages (see FS::cust_pkg) for this customer.
- 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 PKGPART [ , PKGPART ... ]
- Suspends all unsuspended packages (see FS::cust_pkg) matching the listed PKGPARTs (see FS::part_pkg).
- Returns a list: an empty list on success or a list of errors.
- suspend_unless_pkgpart PKGPART [ , PKGPART ... ]
- Suspends all unsuspended packages (see FS::cust_pkg) unless they match the listed PKGPARTs (see FS::part_pkg).
- 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, reasonnum, and ban
- quiet can be set true to supress email cancellation notices.
- reasonnum can be set to a cancellation reason (see FS::cancel_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:
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.
- resetup
- If set true, re-charges setup fees.
- debug
- Debugging level. Default is 0 (no debugging), or can be set to 1 (passed-in options), 2 (traces progress), 3 (more information), or 4 (include full search queries)
- bill OPTIONS
- Generates invoices (see FS::cust_bill) for this customer. Usually used in conjunction with the collect method.
- 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') );
- 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.
- Depending on the value of `payby', this may print or email an invoice (BILL, DCRD, or DCHK), charge a credit card (CARD), charge via electronic check/ACH (CHEK), or just add any necessary (pseudo-)payment (COMP).
- Most actions are now triggered by invoice events; see FS::part_bill_event and the invoice events web interface.
- 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.
- freq - "1d" for the traditional, daily events (the default), or "1m" for the new monthly events
- payby - allows for one time override of normal customer billing method
- 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 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, paynum_ref, payunique
- 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.
- paynum_ref can be set to a scalar reference. It will be filled in with the resulting paynum, if any.
- payunique is a unique identifier for this payment.
- (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_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".
- name_short
- Returns a name string for this customer, either "Company" or "First Last".
- ship_name_short
- Returns a name string for this (service/shipping) contact, either "Company" or "First Last".
- 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"
- contact_firstlast
- Returns this customers full (billing) contact name only, "First Last".
- ship_contact_firstlast
- Returns this customer's full (shipping) contact name only, "First Last".
- 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.
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 active recurring packages).
- inactive_sql
- Returns an SQL expression identifying inactive cust_main records (customers with no active recurring packages, but otherwise unsuspended/uncancelled).
- 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 START_TIME [ END_TIME [ OPTION => VALUE ... ] ]
- Returns an SQL fragment to retreive the balance for this customer, only considering invoices with date earlier than START_TIME, and optionally not later than END_TIME (total_owed_date minus total_credited minus total_unapplied_payments).
- Times are specified as SQL fragments or numeric UNIX timestamps; see "time" in perlfunc). Also see Time::Local and Date::Parse for conversion functions. The empty string can be passed to disable that time constraint completely.
- Available options are:
- unapplied_date - set to true to disregard unapplied credits, payments and refunds outside the specified time period - by default the time period restriction only applies to invoices (useful for reporting, probably a bad idea for event triggering)
- ; total - set to true to remove all customer comparison clauses, for totals:; where - WHERE clause hashref (elements "AND"ed together) (typically used with the total option):; join - JOIN clause (typically used with the total option):; ; _money_table_where TABLE START_TIME [ END_TIME [ OPTION => VALUE ... ] ]
- Helper method for balance_date_sql; name (and usage) subject to change (suggestions welcome).
- Returns a WHERE clause for the specified monetary TABLE (cust_bill, cust_refund, cust_credit or cust_pay).
- If TABLE is "cust_bill" or the unapplied_date option is true, only considers records with date earlier than START_TIME, and optionally not later than END_TIME .
- search_sql HASHREF
- (Class method)
- Returns a qsearch hash expression to search for parameters specified in HREF. Valid parameters are
- agentnum
- ; status:; cancelled_pkgs
- bool
- signupdate
- listref of start date, end date
- payby
- listref
- current_balance
- listref (list returned by FS::UI::Web::parse_lt_gt($cgi, 'current_balance'))
- cust_fields
- ; flattened_pkgs
- bool
- email_search_sql HASHREF
- (Class method)
- Emails a notice to the specified customers.
- Valid parameters are those of the search_sql method, plus the following:
- from
- From: address
- subject
- Email Subject:
- html_body
- HTML body
- text_body
- Text body
- job
- Optional job queue job for status updates.
- Returns an error message, or false for success.
- If an error occurs during any email, stops the enture send and returns that error. Presumably if you're getting SMTP errors aborting is better than retrying everything.
- 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.
- email_search
- Accepts the following options: email, the email address to search for. The email address will be searched for as an email invoice destination and as an svc_acct account.
- 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 (but usually just none or one).
- check_and_rebuild_fuzzyfiles; rebuild_fuzzyfiles; all_X; append_fuzzyfiles LASTNAME COMPANY; process_batch_import
- Load a batch import as a queued JSRPC job
- 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.
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.
POD ERRORS
Hey! The above document had some coding errors, which are explained below:
- Around line 3226:
- '=item' outside of any '=over'