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 );
12 @ISA = qw( FS::Record );
14 #ask FS::UID to run this stuff for us later
15 FS::UID->install_callback( sub {
21 FS::cust_credit_bill - Object methods for cust_credit_bill records
25 use FS::cust_credit_bill;
27 $record = new FS::cust_credit_bill \%hash;
28 $record = new FS::cust_credit_bill { 'column' => 'value' };
30 $error = $record->insert;
32 $error = $new_record->replace($old_record);
34 $error = $record->delete;
36 $error = $record->check;
40 An FS::cust_credit_bill object represents application of a credit (see
41 L<FS::cust_credit>) to an invoice (see L<FS::cust_bill>). FS::cust_credit_bill
42 inherits from FS::Record. The following fields are currently supported:
46 =item creditbillnum - primary key
48 =item crednum - credit being applied
50 =item invnum - invoice to which credit is applied (see L<FS::cust_bill>)
52 =item amount - amount of the credit applied
54 =item _date - specified as a UNIX timestamp; see L<perlfunc/"time">. Also see
55 L<Time::Local> and L<Date::Parse> for conversion functions.
65 Creates a new cust_credit_bill. To add the cust_credit_bill to the database,
70 sub table { 'cust_credit_bill'; }
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 $self->SUPER::delete(@_);
90 =item replace OLD_RECORD
92 Application of credits may not be modified.
97 return "Can't modify application of credit!"
102 Checks all fields to make sure this is a valid credit application. If there
103 is an error, returns the error, otherwise returns false. Called by the insert
112 $self->ut_numbern('creditbillnum')
113 || $self->ut_number('crednum')
114 || $self->ut_number('invnum')
115 || $self->ut_numbern('_date')
116 || $self->ut_money('amount')
118 return $error if $error;
120 return "amount must be > 0" if $self->amount <= 0;
122 return "Unknown credit"
123 unless my $cust_credit =
124 qsearchs( 'cust_credit', { 'crednum' => $self->crednum } );
126 return "Unknown invoice"
127 unless my $cust_bill =
128 qsearchs( 'cust_bill', { 'invnum' => $self->invnum } );
130 $self->_date(time) unless $self->_date;
132 return "Cannot apply more than remaining value of credit"
133 unless $self->amount <= $cust_credit->credited;
135 return "Cannot apply more than remaining value of invoice"
136 unless $self->amount <= $cust_bill->owed;
141 =item sub cust_credit
143 Returns the credit (see L<FS::cust_credit>)
149 qsearchs( 'cust_credit', { 'crednum' => $self->crednum } );
154 Returns the invoice (see L<FS::cust_bill>)
160 qsearchs( 'cust_bill', { 'invnum' => $self->invnum } );
171 L<FS::Record>, L<FS::cust_refund>, L<FS::cust_bill>, L<FS::cust_credit>,
172 schema.html from the base documentation.