5 use FS::Record qw( qsearch qsearchs dbh );
8 @ISA = qw( FS::Record );
12 FS::cust_bill_pay - Object methods for cust_bill_pay records
16 use FS::cust_bill_pay;
18 $record = new FS::cust_bill_pay \%hash;
19 $record = new FS::cust_bill_pay { 'column' => 'value' };
21 $error = $record->insert;
23 $error = $new_record->replace($old_record);
25 $error = $record->delete;
27 $error = $record->check;
31 An FS::cust_bill_pay object represents the application of a payment to a
32 specific invoice. FS::cust_bill_pay inherits from FS::Record. The following
33 fields are currently supported:
37 =item billpaynum - primary key (assigned automatically)
39 =item invnum - Invoice (see L<FS::cust_bill>)
41 =item paynum - Payment (see L<FS::cust_pay>)
43 =item amount - Amount of the payment to apply to the specific invoice.
45 =item _date - specified as a UNIX timestamp; see L<perlfunc/"time">. Also see
46 L<Time::Local> and L<Date::Parse> for conversion functions.
56 Creates a new record. To add the record to the database, see L<"insert">.
60 sub table { 'cust_bill_pay'; }
64 Adds this record to the database. If there is an error, returns the error,
65 otherwise returns false.
72 local $SIG{HUP} = 'IGNORE';
73 local $SIG{INT} = 'IGNORE';
74 local $SIG{QUIT} = 'IGNORE';
75 local $SIG{TERM} = 'IGNORE';
76 local $SIG{TSTP} = 'IGNORE';
77 local $SIG{PIPE} = 'IGNORE';
79 my $oldAutoCommit = $FS::UID::AutoCommit;
80 local $FS::UID::AutoCommit = 0;
83 my $error = $self->check;
84 return $error if $error;
86 $error = $self->SUPER::insert;
88 my $cust_pay = qsearchs('cust_pay', { 'paynum' => $self->paynum } ) or do {
89 $dbh->rollback if $oldAutoCommit;
90 return "unknown cust_pay.paynum: ". $self->paynum;
94 $pay_total += $_ foreach map { $_->amount }
95 qsearch('cust_bill_pay', { 'paynum' => $self->paynum } );
97 if ( $pay_total > $cust_pay->paid ) {
98 $dbh->rollback if $oldAutoCommit;
99 return "total cust_bill_pay.amount $pay_total for paynum ". $self->paynum.
100 " greater than cust_pay.paid ". $cust_pay->paid;
103 my $cust_bill = qsearchs('cust_bill', { 'invnum' => $self->invnum } ) or do {
104 $dbh->rollback if $oldAutoCommit;
105 return "unknown cust_bill.invnum: ". $self->invnum;
109 $bill_total += foreach map { $_->amount }
110 qsearch('cust_bill_pay', { 'invnum' => $self->invnum } );
111 $bill_total += foreach map { $_->amount }
112 qsearch('cust_credit_bill', { 'invnum' => $self->invnum } );
113 if ( $bill_total > $cust_bill->charged ) {
114 $dbh->rollback if $oldAutoCommit;
115 return "total cust_bill_pay.amount and cust_credit_bill.amount $bill_total".
116 "for invnum ". $self->invnum.
117 " greater than cust_bill.charged ". $cust_bill->charged;
120 $dbh->commit or die $dbh->errstr if $oldAutoCommit;
127 Currently unimplemented (accounting reasons).
132 return "Can't (yet?) delete cust_bill_pay records!";
135 =item replace OLD_RECORD
137 Currently unimplemented (accounting reasons).
142 return "Can't (yet?) modify cust_bill_pay records!";
147 Checks all fields to make sure this is a valid payment. If there is an error,
148 returns the error, otherwise returns false. Called by the insert method.
156 $self->ut_numbern('billpaynum')
157 || $self->ut_number('invnum')
158 || $self->ut_numner('paynum')
159 || $self->ut_money('amount')
160 || $self->ut_numbern('_date')
162 return $error if $error;
164 $self->_date(time) unless $self->_date;
174 $Id: cust_bill_pay.pm,v 1.2 2001-09-01 21:55:06 jeff Exp $
178 Delete and replace methods.
180 cust_credit_bill isn't checked yet (uncomment around line 111)
184 L<FS::cust_pay>, L<FS::cust_bill>, L<FS::Record>, schema.html from the