1 package FS::cust_credit_bill;
4 use vars qw( @ISA $conf );
5 use FS::UID qw( getotaker );
6 use FS::Record qw( qsearch qsearchs );
7 use FS::cust_main_Mixin;
8 use FS::cust_bill_ApplicationCommon;
13 @ISA = qw( FS::cust_main_Mixin FS::cust_bill_ApplicationCommon );
15 #ask FS::UID to run this stuff for us later
16 FS::UID->install_callback( sub {
22 FS::cust_credit_bill - Object methods for cust_credit_bill records
26 use FS::cust_credit_bill;
28 $record = new FS::cust_credit_bill \%hash;
29 $record = new FS::cust_credit_bill { 'column' => 'value' };
31 $error = $record->insert;
33 $error = $new_record->replace($old_record);
35 $error = $record->delete;
37 $error = $record->check;
41 An FS::cust_credit_bill object represents application of a credit (see
42 L<FS::cust_credit>) to an invoice (see L<FS::cust_bill>). FS::cust_credit_bill
43 inherits from FS::cust_bill_ApplicationCommon and FS::Record. The following
44 fields are currently supported:
48 =item creditbillnum - primary key
50 =item crednum - credit being applied
52 =item invnum - invoice to which credit is applied (see L<FS::cust_bill>)
54 =item amount - amount of the credit applied
56 =item _date - specified as a UNIX timestamp; see L<perlfunc/"time">. Also see
57 L<Time::Local> and L<Date::Parse> for conversion functions.
67 Creates a new cust_credit_bill. To add the cust_credit_bill to the database,
72 sub table { 'cust_credit_bill'; }
74 sub _app_source_name { 'credit'; }
75 sub _app_source_table { 'cust_credit'; }
76 sub _app_lineitem_breakdown_table { 'cust_credit_bill_pkg'; }
77 sub _app_part_pkg_weight_column { 'credit_weight'; }
81 Adds this cust_credit_bill to the database ("Posts" all or part of a credit).
82 If there is an error, returns the error, otherwise returns false.
86 Currently unimplemented.
92 return "Can't delete application for closed credit"
93 if $self->cust_credit->closed =~ /^Y/i;
94 return "Can't delete application for closed invoice"
95 if $self->cust_bill->closed =~ /^Y/i;
96 $self->SUPER::delete(@_);
99 =item replace OLD_RECORD
101 Application of credits may not be modified.
106 return "Can't modify application of credit!"
111 Checks all fields to make sure this is a valid credit application. If there
112 is an error, returns the error, otherwise returns false. Called by the insert
121 $self->ut_numbern('creditbillnum')
122 || $self->ut_foreign_key('crednum', 'cust_credit', 'crednum')
123 || $self->ut_foreign_key('invnum', 'cust_bill', 'invnum' )
124 || $self->ut_numbern('_date')
125 || $self->ut_money('amount')
126 || $self->ut_foreign_keyn('pkgnum', 'cust_pkg', 'pkgnum')
128 return $error if $error;
130 return "amount must be > 0" if $self->amount <= 0;
132 $self->_date(time) unless $self->_date;
134 return "Cannot apply more than remaining value of credit"
135 unless $self->amount <= $self->cust_credit->credited;
137 return "Cannot apply more than remaining value of invoice"
138 unless $self->amount <= $self->cust_bill->owed;
143 =item sub cust_credit
145 Returns the credit (see L<FS::cust_credit>)
151 qsearchs( 'cust_credit', { 'crednum' => $self->crednum } );
160 This probably should have been called cust_bill_credit.
164 L<FS::Record>, L<FS::cust_bill>, L<FS::cust_credit>,
165 schema.html from the base documentation.