1 package FS::cust_bill_pay;
4 use vars qw( @ISA $conf );
5 use FS::Record qw( qsearchs );
6 use FS::cust_bill_ApplicationCommon;
10 @ISA = qw( FS::cust_bill_ApplicationCommon );
12 #ask FS::UID to run this stuff for us later
13 FS::UID->install_callback( sub {
19 FS::cust_bill_pay - Object methods for cust_bill_pay records
23 use FS::cust_bill_pay;
25 $record = new FS::cust_bill_pay \%hash;
26 $record = new FS::cust_bill_pay { 'column' => 'value' };
28 $error = $record->insert;
30 $error = $new_record->replace($old_record);
32 $error = $record->delete;
34 $error = $record->check;
38 An FS::cust_bill_pay object represents the application of a payment to a
39 specific invoice. FS::cust_bill_pay inherits from
40 FS::cust_bill_ApplicationCommon and FS::Record. The following fields are
45 =item billpaynum - primary key (assigned automatically)
47 =item invnum - Invoice (see L<FS::cust_bill>)
49 =item paynum - Payment (see L<FS::cust_pay>)
51 =item amount - Amount of the payment to apply to the specific invoice.
53 =item _date - specified as a UNIX timestamp; see L<perlfunc/"time">. Also see
54 L<Time::Local> and L<Date::Parse> for conversion functions.
64 Creates a new record. To add the record to the database, see L<"insert">.
68 sub table { 'cust_bill_pay'; }
70 sub _app_source_name { 'payment'; }
71 sub _app_source_table { 'cust_pay'; }
72 sub _app_lineitem_breakdown_table { 'cust_bill_pay_pkg'; }
76 Adds this record to the database. If there is an error, returns the error,
77 otherwise returns false.
81 Deletes this payment application, unless the closed flag for the parent payment
82 (see L<FS::cust_pay>) is set.
88 return "Can't delete application for closed payment"
89 if $self->cust_pay->closed =~ /^Y/i;
90 return "Can't delete application for closed invoice"
91 if $self->cust_bill->closed =~ /^Y/i;
92 $self->SUPER::delete(@_);
95 =item replace OLD_RECORD
97 Currently unimplemented (accounting reasons).
102 return "Can't modify application of payment!";
107 Checks all fields to make sure this is a valid payment application. If there
108 is an error, returns the error, otherwise returns false. Called by the insert
117 $self->ut_numbern('billpaynum')
118 || $self->ut_foreign_key('paynum', 'cust_pay', 'paynum' )
119 || $self->ut_foreign_key('invnum', 'cust_bill', 'invnum' )
120 || $self->ut_numbern('_date')
121 || $self->ut_money('amount')
123 return $error if $error;
125 return "amount must be > 0" if $self->amount <= 0;
127 $self->_date(time) unless $self->_date;
129 return "Cannot apply more than remaining value of invoice"
130 unless $self->amount <= $self->cust_bill->owed;
132 return "Cannot apply more than remaining value of payment"
133 unless $self->amount <= $self->cust_pay->unapplied;
140 Returns the payment (see L<FS::cust_pay>)
146 qsearchs( 'cust_pay', { 'paynum' => $self->paynum } );
153 Delete and replace methods.
157 L<FS::cust_pay>, L<FS::cust_bill>, L<FS::Record>, schema.html from the