1 package FS::cust_credit_bill;
5 use FS::UID qw( getotaker );
6 use FS::Record qw( qsearch qsearchs );
12 @ISA = qw( FS::Record );
16 FS::cust_credit_bill - Object methods for cust_credit_bill records
20 use FS::cust_credit_bill;
22 $record = new FS::cust_credit_bill \%hash;
23 $record = new FS::cust_credit_bill { 'column' => 'value' };
25 $error = $record->insert;
27 $error = $new_record->replace($old_record);
29 $error = $record->delete;
31 $error = $record->check;
35 An FS::cust_credit_bill object represents application of a credit (see
36 L<FS::cust_credit>) to an invoice (see L<FS::cust_bill>). FS::cust_credit
37 inherits from FS::Record. The following 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'; }
69 Adds this cust_credit_bill to the database ("Posts" all or part of a credit).
70 If there is an error, returns the error, otherwise returns false.
74 Currently unimplemented.
79 return "Can't unapply credit!"
82 =item replace OLD_RECORD
84 Application of credits may not be modified.
89 return "Can't modify application of credit!"
94 Checks all fields to make sure this is a valid credit application. If there
95 is an error, returns the error, otherwise returns false. Called by the insert
104 $self->ut_numbern('creditbillnum')
105 || $self->ut_number('crednum')
106 || $self->ut_number('invnum')
107 || $self->ut_numbern('_date')
108 || $self->ut_money('amount')
110 return $error if $error;
112 return "amount must be > 0" if $self->amount <= 0;
114 return "Unknown credit"
115 unless my $cust_credit =
116 qsearchs( 'cust_credit', { 'crednum' => $self->crednum } );
118 return "Unknown invoice"
119 unless my $cust_bill =
120 qsearchs( 'cust_bill', { 'invnum' => $self->invnum } );
122 $self->_date(time) unless $self->_date;
124 return "Cannot apply more than remaining value of credit"
125 unless $self->amount <= $cust_credit->credited;
127 return "Cannot apply more than remaining value of invoice"
128 unless $self->amount <= $cust_bill->owed;
133 =item sub cust_credit
135 Returns the credit (see L<FS::cust_credit>)
141 qsearchs( 'cust_credit', { 'crednum' => $self->crednum } );
148 $Id: cust_credit_bill.pm,v 1.7 2002-01-24 16:58:47 ivan Exp $
156 L<FS::Record>, L<FS::cust_refund>, L<FS::cust_bill>, L<FS::cust_credit>,
157 schema.html from the base documentation.