% include( '/elements/header.html', 'Developer Documentation' ) %> <& /elements/menubar.html, 'Freeside Perl Modules' => $fsurl.'docs/library/FS.html', 'Complete Index' => $fsurl.'docs/library/index.html', &>
FS::cust_credit - Object methods for cust_credit records
use FS::cust_credit;
$record = new FS::cust_credit \%hash;
$record = new FS::cust_credit { 'column' => 'value' };
$error = $record->insert;
$error = $new_record->replace($old_record);
$error = $record->delete;
$error = $record->check;
An FS::cust_credit object represents a credit; the equivalent of a negative cust_bill record (see FS::cust_bill). FS::cust_credit inherits from FS::Record. The following fields are currently supported:
Primary key (assigned automatically for new credits)
Customer (see FS::cust_main)
Amount of the credit
Specified as a UNIX timestamp; see "time" in perlfunc. Also see Time::Local and Date::Parse for conversion functions.
Order taker (see FS::access_user)
Text ( deprecated )
Reason (see FS::reason)
Text
Books closed flag, empty or `Y'
Desired pkgnum when using experimental package balances.
Creates a new credit. To add the credit to the database, see "insert".
Adds this credit to the database ("Posts" the credit). If there is an error, returns the error, otherwise returns false.
Ooptions are passed as a list of keys and values. Available options:
FS::reason_type Reason type for newly-inserted reason
An arrayref of FS::cust_credit_source_bill_pkg objects. They will have their crednum set and will be inserted along with this credit.
Unless the closed flag is set, deletes this credit and all associated applications (see FS::cust_credit_bill). In most cases, you want to use the void method instead to leave a record of the deleted credit.
You can, but probably shouldn't modify credits...
Replaces the OLD_RECORD with this one in the database, or, if OLD_RECORD is not supplied, replaces this record. If there is an error, returns the error, otherwise returns false.
Checks all fields to make sure this is a valid credit. If there is an error, returns the error, otherwise returns false. Called by the insert and replace methods.
Voids this credit: deletes the credit and all associated applications and adds a record of the voided credit to the cust_credit_void table.
Returns all refund applications (see FS::cust_credit_refund) for this credit.
Returns all application to invoices (see FS::cust_credit_bill) for this credit.
Returns the amount of this credit that is still unapplied/outstanding; amount minus all refund applications (see FS::cust_credit_refund) and applications to invoices (see FS::cust_credit_bill).
Deprecated name for the unapplied method.
Returns the customer (see FS::cust_main) for this credit.
Returns an SQL fragment to retreive the unapplied amount.
Deprecated name for the unapplied_sql method.
Calculate the amount of tax that needs to be credited as part of a lineitem credit.
PARAMS must include:
- billpkgnums: arrayref identifying the line items to credit - setuprecurs: arrayref of 'setup' or 'recur', indicating which part of the lineitem charge is being credited - amounts: arrayref of the amounts to credit on each line item - custnum: the customer all of these invoices belong to, for error checking
Returns a hash containing: - subtotal: the total non-tax amount to be credited (the sum of the 'amounts') - taxtotal: the total tax amount to be credited - taxlines: an arrayref of hashrefs for each tax line to be credited, each with: - table: "cust_bill_pkg_tax_location" or "cust_bill_pkg_tax_rate_location" - num: the key within that table - credit: the credit amount to apply to that line
Creates a credit to a group of line items, with a specified amount applied to each. This will also calculate the tax adjustments for those amounts and credit the appropriate tax line items.
Example:
my $error = FS::cust_credit->credit_lineitems(
#the lineitems to credit
'billpkgnums' => \@billpkgnums,
'setuprecurs' => \@setuprecurs,
'amounts' => \@amounts,
'apply' => 1, #0 leaves the credit unapplied
'set_source' => 1, #creates credit source records for the line items
#the credit
map { $_ => scalar($cgi->param($_)) }
#fields('cust_credit')
qw( custnum _date amount reasonnum addlinfo ), #pkgnum eventnum
);
billpkgnums, setuprecurs, amounts are required and are parallel arrays. Each one indicates an amount of credit to be applied to either the setup or recur portion of a (non-tax) line item.
custnum, _date, reasonnum, and addlinfo will be set on the credit before it's inserted.
amount is the total amount. If unspecified, the credit will be the sum of the per-line-item amounts and their tax adjustments.
Returns FS::cust_credit_refund objects that will be deleted by "unapply_refund" (all currently applied refunds that aren't closed.) Returns empty list if credit itself is closed.
Deletes all objects returned by "refund_to_unapply".
The delete method. The replace method.
credited and credited_sql are now called unapplied and unapplied_sql. The old method names should start to give warnings.
FS::Record, FS::cust_credit_refund, FS::cust_refund, FS::cust_credit_bill FS::cust_bill, schema.html from the base documentation.