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;
12 @ISA = qw( FS::cust_main_Mixin FS::cust_bill_ApplicationCommon );
14 #ask FS::UID to run this stuff for us later
15 FS::UID->install_callback( sub {
21 FS::cust_bill_pay - Object methods for cust_bill_pay records
25 use FS::cust_bill_pay;
27 $record = new FS::cust_bill_pay \%hash;
28 $record = new FS::cust_bill_pay { 'column' => 'value' };
30 $error = $record->insert;
32 $error = $new_record->replace($old_record);
34 $error = $record->delete;
36 $error = $record->check;
40 An FS::cust_bill_pay object represents the application of a payment to a
41 specific invoice. FS::cust_bill_pay inherits from
42 FS::cust_bill_ApplicationCommon and FS::Record. The following fields are
47 =item billpaynum - primary key (assigned automatically)
49 =item invnum - Invoice (see L<FS::cust_bill>)
51 =item paynum - Payment (see L<FS::cust_pay>)
53 =item amount - Amount of the payment to apply to the specific invoice.
55 =item _date - specified as a UNIX timestamp; see L<perlfunc/"time">. Also see
56 L<Time::Local> and L<Date::Parse> for conversion functions.
66 Creates a new record. To add the record to the database, see L<"insert">.
70 sub table { 'cust_bill_pay'; }
72 sub _app_source_name { 'payment'; }
73 sub _app_source_table { 'cust_pay'; }
74 sub _app_lineitem_breakdown_table { 'cust_bill_pay_pkg'; }
75 sub _app_part_pkg_weight_column { 'pay_weight'; }
79 Adds this record to the database. If there is an error, returns the error,
80 otherwise returns false.
84 Deletes this payment application, unless the closed flag for the parent payment
85 (see L<FS::cust_pay>) is set.
91 return "Can't delete application for closed payment"
92 if $self->cust_pay && $self->cust_pay->closed =~ /^Y/i;
93 return "Can't delete application for closed invoice"
94 if $self->cust_bill && $self->cust_bill->closed =~ /^Y/i;
95 $self->SUPER::delete(@_);
98 =item replace OLD_RECORD
100 Currently unimplemented (accounting reasons).
105 return "Can't modify application of payment!";
110 Checks all fields to make sure this is a valid payment application. If there
111 is an error, returns the error, otherwise returns false. Called by the insert
120 $self->ut_numbern('billpaynum')
121 || $self->ut_foreign_key('paynum', 'cust_pay', 'paynum' )
122 || $self->ut_foreign_key('invnum', 'cust_bill', 'invnum' )
123 || $self->ut_numbern('_date')
124 || $self->ut_money('amount')
125 || $self->ut_foreign_keyn('pkgnum', 'cust_pkg', 'pkgnum')
127 return $error if $error;
129 return "amount must be > 0" if $self->amount <= 0;
131 $self->_date(time) unless $self->_date;
133 return "Cannot apply more than remaining value of invoice"
134 unless $self->amount <= $self->cust_bill->owed;
136 return "Cannot apply more than remaining value of payment"
137 unless $self->amount <= $self->cust_pay->unapplied;
144 Returns the payment (see L<FS::cust_pay>)
150 qsearchs( 'cust_pay', { 'paynum' => $self->paynum } );
153 =item send_receipt HASHREF | OPTION => VALUE ...
155 Sends a payment receipt for the associated payment, against this specific
156 invoice. If there is an error, returns the error, otherwise returns false.
158 See L<FS::cust_pay/send_receipt>.
164 my $opt = ref($_[0]) ? shift : { @_ };
165 $self->cust_pay->send_receipt(
166 'cust_bill' => $self->cust_bill,
175 Delete and replace methods.
179 L<FS::cust_pay>, L<FS::cust_bill>, L<FS::Record>, schema.html from the