1 package FS::cust_bill_pay;
4 use vars qw( @ISA $conf );
5 use FS::Record qw( qsearchs );
6 use FS::cust_main_Mixin;
7 use FS::cust_bill_ApplicationCommon;
11 @ISA = qw( FS::cust_main_Mixin FS::cust_bill_ApplicationCommon );
13 #ask FS::UID to run this stuff for us later
14 FS::UID->install_callback( sub {
20 FS::cust_bill_pay - Object methods for cust_bill_pay records
24 use FS::cust_bill_pay;
26 $record = new FS::cust_bill_pay \%hash;
27 $record = new FS::cust_bill_pay { 'column' => 'value' };
29 $error = $record->insert;
31 $error = $new_record->replace($old_record);
33 $error = $record->delete;
35 $error = $record->check;
39 An FS::cust_bill_pay object represents the application of a payment to a
40 specific invoice. FS::cust_bill_pay inherits from
41 FS::cust_bill_ApplicationCommon and FS::Record. The following fields are
46 =item billpaynum - primary key (assigned automatically)
48 =item invnum - Invoice (see L<FS::cust_bill>)
50 =item paynum - Payment (see L<FS::cust_pay>)
52 =item amount - Amount of the payment to apply to the specific invoice.
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 record. To add the record to the database, see L<"insert">.
69 sub table { 'cust_bill_pay'; }
71 sub _app_source_name { 'payment'; }
72 sub _app_source_table { 'cust_pay'; }
73 sub _app_lineitem_breakdown_table { 'cust_bill_pay_pkg'; }
74 sub _app_part_pkg_weight_column { 'pay_weight'; }
78 Adds this record to the database. If there is an error, returns the error,
79 otherwise returns false.
83 Deletes this payment application, unless the closed flag for the parent payment
84 (see L<FS::cust_pay>) is set.
90 return "Can't delete application for closed payment"
91 if $self->cust_pay->closed =~ /^Y/i;
92 return "Can't delete application for closed invoice"
93 if $self->cust_bill->closed =~ /^Y/i;
94 $self->SUPER::delete(@_);
97 =item replace OLD_RECORD
99 Currently unimplemented (accounting reasons).
104 return "Can't modify application of payment!";
109 Checks all fields to make sure this is a valid payment application. If there
110 is an error, returns the error, otherwise returns false. Called by the insert
119 $self->ut_numbern('billpaynum')
120 || $self->ut_foreign_key('paynum', 'cust_pay', 'paynum' )
121 || $self->ut_foreign_key('invnum', 'cust_bill', 'invnum' )
122 || $self->ut_numbern('_date')
123 || $self->ut_money('amount')
125 return $error if $error;
127 return "amount must be > 0" if $self->amount <= 0;
129 $self->_date(time) unless $self->_date;
131 return "Cannot apply more than remaining value of invoice"
132 unless $self->amount <= $self->cust_bill->owed;
134 return "Cannot apply more than remaining value of payment"
135 unless $self->amount <= $self->cust_pay->unapplied;
142 Returns the payment (see L<FS::cust_pay>)
148 qsearchs( 'cust_pay', { 'paynum' => $self->paynum } );
155 Delete and replace methods.
159 L<FS::cust_pay>, L<FS::cust_bill>, L<FS::Record>, schema.html from the