1 package FS::cust_bill_pay;
4 use vars qw( @ISA $conf );
5 use FS::Record qw( qsearch qsearchs dbh );
9 @ISA = qw( FS::Record );
11 #ask FS::UID to run this stuff for us later
12 FS::UID->install_callback( sub {
18 FS::cust_bill_pay - Object methods for cust_bill_pay records
22 use FS::cust_bill_pay;
24 $record = new FS::cust_bill_pay \%hash;
25 $record = new FS::cust_bill_pay { 'column' => 'value' };
27 $error = $record->insert;
29 $error = $new_record->replace($old_record);
31 $error = $record->delete;
33 $error = $record->check;
37 An FS::cust_bill_pay object represents the application of a payment to a
38 specific invoice. FS::cust_bill_pay inherits from FS::Record. The following
39 fields are currently supported:
43 =item billpaynum - primary key (assigned automatically)
45 =item invnum - Invoice (see L<FS::cust_bill>)
47 =item paynum - Payment (see L<FS::cust_pay>)
49 =item amount - Amount of the payment to apply to the specific invoice.
51 =item _date - specified as a UNIX timestamp; see L<perlfunc/"time">. Also see
52 L<Time::Local> and L<Date::Parse> for conversion functions.
62 Creates a new record. To add the record to the database, see L<"insert">.
66 sub table { 'cust_bill_pay'; }
70 Adds this record to the database. If there is an error, returns the error,
71 otherwise returns false.
75 Deletes this payment application, unless the closed flag for the parent payment
76 (see L<FS::cust_pay>) is set.
82 return "Can't delete application for closed payment"
83 if $self->cust_pay->closed =~ /^Y/i;
84 $self->SUPER::delete(@_);
87 =item replace OLD_RECORD
89 Currently unimplemented (accounting reasons).
94 return "Can't (yet?) modify cust_bill_pay records!";
99 Checks all fields to make sure this is a valid payment. If there is an error,
100 returns the error, otherwise returns false. Called by the insert method.
108 $self->ut_numbern('billpaynum')
109 || $self->ut_number('invnum')
110 || $self->ut_number('paynum')
111 || $self->ut_money('amount')
112 || $self->ut_numbern('_date')
114 return $error if $error;
116 return "amount must be > 0" if $self->amount <= 0;
118 return "Unknown invoice"
119 unless my $cust_bill =
120 qsearchs( 'cust_bill', { 'invnum' => $self->invnum } );
122 return "Unknown payment"
123 unless my $cust_pay =
124 qsearchs( 'cust_pay', { 'paynum' => $self->paynum } );
126 $self->_date(time) unless $self->_date;
128 return "Cannot apply more than remaining value of invoice"
129 unless $self->amount <= $cust_bill->owed;
131 return "Cannot apply more than remaining value of payment"
132 unless $self->amount <= $cust_pay->unapplied;
139 Returns the payment (see L<FS::cust_pay>)
145 qsearchs( 'cust_pay', { 'paynum' => $self->paynum } );
150 Returns the invoice (see L<FS::cust_bill>)
156 qsearchs( 'cust_bill', { 'invnum' => $self->invnum } );
163 Delete and replace methods.
165 the checks for over-applied payments could be better done like the ones in
170 L<FS::cust_pay>, L<FS::cust_bill>, L<FS::Record>, schema.html from the