Freeside:1.9:Documentation:Developer/FS/cust pkg

From Freeside
< Freeside:1.9:Documentation:Developer‎ | FS
Revision as of 16:48, 3 October 2007 by Ivan (talk | contribs) (import from POD)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

NAME

FS::cust_pkg - Object methods for cust_pkg objects

SYNOPSIS

 use FS::cust_pkg;

 $record = new FS::cust_pkg \%hash;
 $record = new FS::cust_pkg { 'column' => 'value' };

 $error = $record->insert;

 $error = $new_record->replace($old_record);

 $error = $record->delete;

 $error = $record->check;

 $error = $record->cancel;

 $error = $record->suspend;

 $error = $record->unsuspend;

 $part_pkg = $record->part_pkg;

 @labels = $record->labels;

 $seconds = $record->seconds_since($timestamp);

 $error = FS::cust_pkg::order( $custnum, \@pkgparts );
 $error = FS::cust_pkg::order( $custnum, \@pkgparts, \@remove_pkgnums ] );

DESCRIPTION

An FS::cust_pkg object represents a customer billing item. FS::cust_pkg inherits from FS::Record. The following fields are currently supported:

pkgnum - primary key (assigned automatically for new billing items); custnum - Customer (see FS::cust_main); pkgpart - Billing item definition (see FS::part_pkg); setup - date; bill - date (next bill date); last_bill - last bill date; adjourn - date; susp - date; expire - date; cancel - date; otaker - order taker (assigned automatically if null, see FS::UID); manual_flag - If this field is set to 1, disables the automatic unsuspension of this package when using the unsuspendauto config file.

Note: setup, bill, adjourn, susp, expire and cancel are specified as UNIX timestamps; see "time" in perlfunc|perlfunc#time|"time" in perlfunc. Also see Time::Local and Date::Parse for conversion functions.

METHODS

new HASHREF
Create a new billing item. To add the item to the database, see "insert"|#insert|"insert".
insert [ OPTION => VALUE ... ]
Adds this billing item to the database ("Orders" the item). If there is an error, returns the error, otherwise returns false.
If the additional field promo_code is defined instead of pkgpart, it will be used to look up the package definition and agent restrictions will be ignored.
If the additional field refnum is defined, an FS::pkg_referral record will be created and inserted. Multiple FS::pkg_referral records can be created by setting refnum to an array reference of refnums or a hash reference with refnums as keys. If no refnum is defined, a default FS::pkg_referral record will be created corresponding to cust_main.refnum.
The following options are available: change
change, if set true, supresses any referral credit to a referring customer.
delete
This method now works but you probably shouldn't use it.
You don't want to delete billing items, because there would then be no record the customer ever purchased the item. Instead, see the cancel method.
replace OLD_RECORD
Replaces the OLD_RECORD with this one in the database. If there is an error, returns the error, otherwise returns false.
Currently, custnum, setup, bill, adjourn, susp, expire, and cancel may be changed.
Changing pkgpart may have disasterous effects. See the order subroutine.
setup and bill are normally updated by calling the bill method of a customer object (see FS::cust_main).
suspend is normally updated by the suspend and unsuspend methods.
cancel is normally updated by the cancel method (and also the order subroutine in some cases).
Calls
check
Checks all fields to make sure this is a valid billing item. If there is an error, returns the error, otherwise returns false. Called by the insert and replace methods.
cancel [ OPTION => VALUE ... ]
Cancels and removes all services (see FS::cust_svc and FS::part_svc) in this package, then cancels the package itself (sets the cancel field to now).
Available options are:
quiet - can be set true to supress email cancellation notices.
; time - can be set to cancel the package based on a specific future or historical date. Using time ensures that the remaining amount is calculated correctly. Note however that this is an immediate cancel and just changes the date. You are PROBABLY looking to expire the account instead of using this.:; 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.
If there is an error, returns the error, otherwise returns false.
cancel_if_expired [ NOW_TIMESTAMP ]
Cancels this package if its expire date has been reached.
suspend [ OPTION => VALUE ... ]
Suspends all services (see FS::cust_svc and FS::part_svc) in this package, then suspends the package itself (sets the susp field to now).
Available options are:
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.
If there is an error, returns the error, otherwise returns false.
unsuspend [ OPTION => VALUE ... ]
Unsuspends all services (see FS::cust_svc and FS::part_svc) in this package, then unsuspends the package itself (clears the susp field and the adjourn field if it is in the past).
Available options are: adjust_next_bill.
adjust_next_bill can be set true to adjust the next bill date forward by the amount of time the account was inactive. This was set true by default since 1.4.2 and 1.5.0pre6; however, starting with 1.7.0 this needs to be explicitly requested. Price plans for which this makes sense (anniversary-date based than prorate or subscription) could have an option to enable this behaviour?
If there is an error, returns the error, otherwise returns false.
last_bill
Returns the last bill date, or if there is no last bill date, the setup date. Useful for billing metered services.
last_reason
Returns the most recent FS::reason associated with the package.
part_pkg
Returns the definition for this billing item, as an FS::part_pkg object (see FS::part_pkg).
old_cust_pkg
Returns the cancelled package this package was changed from, if any.
calc_setup
Calls the calc_setup of the FS::part_pkg object associated with this billing item.
calc_recur
Calls the calc_recur of the FS::part_pkg object associated with this billing item.
calc_remain
Calls the calc_remain of the FS::part_pkg object associated with this billing item.
calc_cancel
Calls the calc_cancel of the FS::part_pkg object associated with this billing item.
cust_bill_pkg
Returns any invoice line items for this package (see FS::cust_bill_pkg).
cust_event
Returns the new-style customer billing events (see FS::cust_event) for this invoice.
num_cust_event
Returns the number of new-style customer billing events (see FS::cust_event) for this invoice.
cust_svc [ SVCPART ]
Returns the services for this package, as FS::cust_svc objects (see FS::cust_svc). If a svcpart is specified, return only the matching services.
overlimit [ SVCPART ]
Returns the services for this package which have exceeded their usage limit as FS::cust_svc objects (see FS::cust_svc). If a svcpart is specified, return only the matching services.
h_cust_svc END_TIMESTAMP [ START_TIMESTAMP ]
Returns historical services for this package created before END TIMESTAMP and (optionally) not cancelled before START_TIMESTAMP, as FS::h_cust_svc objects (see FS::h_cust_svc).
num_cust_svc [ SVCPART ]
Returns the number of provisioned services for this package. If a svcpart is specified, counts only the matching services.
available_part_svc
Returns a list of FS::part_svc objects representing services included in this package but not yet provisioned. Each FS::part_svc object also has an extra field, num_avail, which specifies the number of available services.
part_svc
Returns a list of FS::part_svc objects representing provisioned and available services included in this package. Each FS::part_svc object also has the following extra fields:
num_cust_svc (count)
; num_avail (quantity - count):; cust_pkg_svc (services) - array reference containing the provisioned services, as cust_svc objects
svcnum label -> ($cust_svc->label)[1]
extra_part_svc
Returns a list of FS::part_svc objects corresponding to services in this package which are still provisioned but not (any longer) available in the package definition.
status
Returns a short status string for this package, currently:
not yet billed
; one-time charge:; active:; suspended:; cancelled; statuses
Class method that returns the list of possible status strings for packages (see the status method|#status|the status method). For example:

 @statuses = FS::cust_pkg->statuses();

statuscolor
Returns a hex triplet color string for this package's status.
labels
Returns a list of lists, calling the label method for all services (see FS::cust_svc) of this billing item.
h_labels END_TIMESTAMP [ START_TIMESTAMP ]
Like the labels method, but returns historical information on services that were active as of END_TIMESTAMP and (optionally) not cancelled before START_TIMESTAMP.
Returns a list of lists, calling the label method for all (historical) services (see FS::h_cust_svc) of this billing item.
h_labels_short END_TIMESTAMP [ START_TIMESTAMP ]
Like h_labels, except returns a simple flat list, and shortens long (currently >5) lists of identical services to one line that lists the service label and the number of individual services rather than individual items.
cust_main
Returns the parent customer object (see FS::cust_main).
seconds_since TIMESTAMP
Returns the number of seconds all accounts (see FS::svc_acct) in this package have been online since TIMESTAMP, according to the session monitor.
TIMESTAMP is specified as a UNIX timestamp; see "time" in perlfunc|perlfunc#time|"time" in perlfunc. Also see Time::Local and Date::Parse for conversion functions.
seconds_since_sqlradacct TIMESTAMP_START TIMESTAMP_END
Returns the numbers of seconds all accounts (see FS::svc_acct) in this package have been online between TIMESTAMP_START (inclusive) and TIMESTAMP_END (exclusive).
TIMESTAMP_START and TIMESTAMP_END are specified as UNIX timestamps; see "time" in perlfunc|perlfunc#time|"time" in perlfunc. Also see Time::Local and Date::Parse for conversion functions.
attribute_since_sqlradacct TIMESTAMP_START TIMESTAMP_END ATTRIBUTE
Returns the sum of the given attribute for all accounts (see FS::svc_acct) in this package for sessions ending between TIMESTAMP_START (inclusive) and TIMESTAMP_END (exclusive).
TIMESTAMP_START and TIMESTAMP_END are specified as UNIX timestamps; see "time" in perlfunc|perlfunc#time|"time" in perlfunc. Also see Time::Local and Date::Parse for conversion functions.
transfer DEST_PKGNUM | DEST_CUST_PKG, [ OPTION => VALUE ... ]
Transfers as many services as possible from this package to another package.
The destination package can be specified by pkgnum by passing an FS::cust_pkg object. The destination package must already exist.
Services are moved only if the destination allows services with the correct svcpart (not svcdb), unless the change_svcpart option is set true. Use this option with caution! No provision is made for export differences between the old and new service definitions. Probably only should be used when your exports for all service definitions of a given svcdb are identical. (attempt a transfer without it first, to move all possible svcpart-matching services)
Any services that can't be moved remain in the original package.
Returns an error, if there is one; otherwise, returns the number of services that couldn't be moved.
reexport
This method is deprecated. See the depend_jobnum option to the insert and order_pkgs methods in FS::cust_main for a better way to defer provisioning.

CLASS METHODS

recurring_sql
Returns an SQL expression identifying recurring packages.
onetime_sql
Returns an SQL expression identifying one-time packages.
active_sql
Returns an SQL expression identifying active packages.
inactive_sql
Returns an SQL expression identifying inactive packages (one-time packages that are otherwise unsuspended/uncancelled).
susp_sql =item suspended_sql
Returns an SQL expression identifying suspended packages.
cancel_sql =item cancelled_sql
Returns an SQL exprression identifying cancelled packages.

SUBROUTINES

order CUSTNUM, PKGPARTS_ARYREF, [ REMOVE_PKGNUMS_ARYREF [ RETURN_CUST_PKG_ARRAYREF [ REFNUM ] ] ]
CUSTNUM is a customer (see FS::cust_main)
PKGPARTS is a list of pkgparts specifying the the billing item definitions (see FS::part_pkg) to order for this customer. Duplicates are of course permitted.
REMOVE_PKGNUMS is an optional list of pkgnums specifying the billing items to remove for this customer. The services (see FS::cust_svc) are moved to the new billing items. An error is returned if this is not possible (see FS::pkg_svc). An empty arrayref is equivalent to not specifying this parameter.
RETURN_CUST_PKG_ARRAYREF, if specified, will be filled in with the newly-created cust_pkg objects.
REFNUM, if specified, will specify the FS::pkg_referral record to be created and inserted. Multiple FS::pkg_referral records can be created by setting refnum to an array reference of refnums or a hash reference with refnums as keys. If no refnum is defined, a default FS::pkg_referral record will be created corresponding to cust_main.refnum.
insert_reason
Associates this package with a (suspension or cancellation) reason (see FS::cust_pkg_reason, possibly inserting a new reason on the fly (see FS::reason).
Available options are:
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.:; date
If there is an error, returns the error, otherwise returns false.
set_usage USAGE_VALUE_HASHREF
USAGE_VALUE_HASHREF is a hashref of svc_acct usage columns and the amounts to which they should be set (see FS::svc_acct). Currently seconds, upbytes, downbytes, and totalbytes are appropriate keys.
All svc_accts which are part of this package have their values reset.

BUGS

sub order is not OO. Perhaps it should be moved to FS::cust_main and made so?

In sub order, the @pkgparts array (passed by reference) is clobbered.

Also in sub order, no money is adjusted. Once FS::part_pkg defines a standard method to pass dates to the recur_prog expression, it should do so.

FS::svc_acct, FS::svc_domain, FS::svc_www, FS::svc_ip and FS::svc_forward are loaded via 'use' at compile time, rather than via 'require' in sub { setup, suspend, unsuspend, cancel } because they use %FS::UID::callback to load configuration values. Probably need a subroutine which decides what to do based on whether or not we've fetched the user yet, rather than a hash. See FS::UID and the TODO.

Now that things are transactional should the check in the insert method be moved to check ?

SEE ALSO

FS::Record, FS::cust_main, FS::part_pkg, FS::cust_svc, FS::pkg_svc, schema.html from the base documentation

POD ERRORS

Hey! The above document had some coding errors, which are explained below:

Around line 1550:
You forgot a '=back' before '=head1'