1 package FS::cust_credit_bill;
2 use base qw( FS::cust_main_Mixin FS::cust_bill_ApplicationCommon );
8 #ask FS::UID to run this stuff for us later
9 FS::UID->install_callback( sub {
15 FS::cust_credit_bill - Object methods for cust_credit_bill records
19 use FS::cust_credit_bill;
21 $record = new FS::cust_credit_bill \%hash;
22 $record = new FS::cust_credit_bill { 'column' => 'value' };
24 $error = $record->insert;
26 $error = $new_record->replace($old_record);
28 $error = $record->delete;
30 $error = $record->check;
34 An FS::cust_credit_bill object represents application of a credit (see
35 L<FS::cust_credit>) to an invoice (see L<FS::cust_bill>). FS::cust_credit_bill
36 inherits from FS::cust_bill_ApplicationCommon and FS::Record. The following
37 fields are currently supported:
41 =item creditbillnum - primary key
43 =item crednum - credit being applied
45 =item invnum - invoice to which credit is applied (see L<FS::cust_bill>)
47 =item amount - amount of the credit applied
49 =item _date - specified as a UNIX timestamp; see L<perlfunc/"time">. Also see
50 L<Time::Local> and L<Date::Parse> for conversion functions.
60 Creates a new cust_credit_bill. To add the cust_credit_bill to the database,
65 sub table { 'cust_credit_bill'; }
67 sub _app_source_name { 'credit'; }
68 sub _app_source_table { 'cust_credit'; }
69 sub _app_lineitem_breakdown_table { 'cust_credit_bill_pkg'; }
70 sub _app_part_pkg_weight_column { 'credit_weight'; }
74 Adds this cust_credit_bill to the database ("Posts" all or part of a credit).
75 If there is an error, returns the error, otherwise returns false.
79 Currently unimplemented.
85 return "Can't delete application for closed credit"
86 if $self->cust_credit->closed =~ /^Y/i;
87 return "Can't delete application for closed invoice"
88 if $self->cust_bill->closed =~ /^Y/i;
89 $self->SUPER::delete(@_);
92 =item replace OLD_RECORD
94 Application of credits may not be modified.
99 return "Can't modify application of credit!"
104 Checks all fields to make sure this is a valid credit application. If there
105 is an error, returns the error, otherwise returns false. Called by the insert
114 $self->ut_numbern('creditbillnum')
115 || $self->ut_foreign_key('crednum', 'cust_credit', 'crednum')
116 || $self->ut_foreign_key('invnum', 'cust_bill', 'invnum' )
117 || $self->ut_numbern('_date')
118 || $self->ut_money('amount')
119 || $self->ut_foreign_keyn('pkgnum', 'cust_pkg', 'pkgnum')
121 return $error if $error;
123 return "amount must be > 0" if $self->amount <= 0;
125 $self->_date(time) unless $self->_date;
127 return "Cannot apply more than remaining value of credit"
128 unless $self->amount <= $self->cust_credit->credited;
130 return "Cannot apply more than remaining value of invoice"
131 unless $self->amount <= $self->cust_bill->owed;
136 =item sub cust_credit
138 Returns the credit (see L<FS::cust_credit>)
146 This probably should have been called cust_bill_credit.
150 L<FS::Record>, L<FS::cust_bill>, L<FS::cust_credit>,
151 schema.html from the base documentation.