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.
99 return "Can't unapply credit!"
102 =item replace OLD_RECORD
104 Application of credits may not be modified.
109 return "Can't modify application of credit!"
114 Checks all fields to make sure this is a valid credit application. If there
115 is an error, returns the error, otherwise returns false. Called by the insert
124 $self->ut_numbern('creditbillnum')
125 || $self->ut_number('crednum')
126 || $self->ut_number('invnum')
127 || $self->ut_numbern('_date')
128 || $self->ut_money('amount')
130 return $error if $error;
132 return "amount must be > 0" if $self->amount <= 0;
134 return "Unknown credit"
135 unless my $cust_credit =
136 qsearchs( 'cust_credit', { 'crednum' => $self->crednum } );
138 return "Unknown invoice"
139 unless my $cust_bill =
140 qsearchs( 'cust_bill', { 'invnum' => $self->invnum } );
142 $self->_date(time) unless $self->_date;
144 return "Cannot apply more than remaining value of credit"
145 unless $self->amount <= $cust_credit->credited;
147 return "Cannot apply more than remaining value of invoice"
148 unless $self->amount <= $cust_bill->owed;
153 =item sub cust_credit
155 Returns the credit (see L<FS::cust_credit>)
161 qsearchs( 'cust_credit', { 'crednum' => $self->crednum } );
166 Returns the invoice (see L<FS::cust_bill>)
172 qsearchs( 'cust_bill', { 'invnum' => $self->invnum } );
183 L<FS::Record>, L<FS::cust_refund>, L<FS::cust_bill>, L<FS::cust_credit>,
184 schema.html from the base documentation.