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
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.
81 my $error = $self->SUPER::insert(@_);
82 return $error if $error;
84 if ( $conf->exists('invoice_send_receipts') ) {
85 my $send_error = $self->cust_bill->send;
86 warn "Error sending receipt: $send_error\n" if $send_error;
94 Currently unimplemented.
100 return "Can't delete application for closed credit"
101 if $self->cust_credit->closed =~ /^Y/i;
102 $self->SUPER::delete(@_);
105 =item replace OLD_RECORD
107 Application of credits may not be modified.
112 return "Can't modify application of credit!"
117 Checks all fields to make sure this is a valid credit application. If there
118 is an error, returns the error, otherwise returns false. Called by the insert
127 $self->ut_numbern('creditbillnum')
128 || $self->ut_number('crednum')
129 || $self->ut_number('invnum')
130 || $self->ut_numbern('_date')
131 || $self->ut_money('amount')
133 return $error if $error;
135 return "amount must be > 0" if $self->amount <= 0;
137 return "Unknown credit"
138 unless my $cust_credit =
139 qsearchs( 'cust_credit', { 'crednum' => $self->crednum } );
141 return "Unknown invoice"
142 unless my $cust_bill =
143 qsearchs( 'cust_bill', { 'invnum' => $self->invnum } );
145 $self->_date(time) unless $self->_date;
147 return "Cannot apply more than remaining value of credit"
148 unless $self->amount <= $cust_credit->credited;
150 return "Cannot apply more than remaining value of invoice"
151 unless $self->amount <= $cust_bill->owed;
156 =item sub cust_credit
158 Returns the credit (see L<FS::cust_credit>)
164 qsearchs( 'cust_credit', { 'crednum' => $self->crednum } );
169 Returns the invoice (see L<FS::cust_bill>)
175 qsearchs( 'cust_bill', { 'invnum' => $self->invnum } );
186 L<FS::Record>, L<FS::cust_refund>, L<FS::cust_bill>, L<FS::cust_credit>,
187 schema.html from the base documentation.