1 package FS::cust_pay_refund;
2 use base qw(FS::Record);
5 use FS::Record qw( qsearchs ); # qsearch );
8 #ask FS::UID to run this stuff for us later
9 #FS::UID->install_callback( sub {
10 # $conf = new FS::Conf;
15 FS::cust_pay_refund - Object methods for cust_pay_refund records
19 use FS::cust_pay_refund;
21 $record = new FS::cust_pay_refund \%hash;
22 $record = new FS::cust_pay_refund { 'column' => 'value' };
24 $error = $record->insert;
26 $error = $new_record->replace($old_record);
28 $error = $record->delete;
30 $error = $record->check;
34 An FS::cust_pay_refund object represents application of a refund (see
35 L<FS::cust_refund>) to an payment (see L<FS::cust_pay>). FS::cust_pay_refund
36 inherits from FS::Record. The following fields are currently supported:
40 =item payrefundnum - primary key
42 =item paynum - credit being applied
44 =item refundnum - invoice to which credit is applied (see L<FS::cust_bill>)
46 =item amount - amount of the credit applied
48 =item _date - specified as a UNIX timestamp; see L<perlfunc/"time">. Also see
49 L<Time::Local> and L<Date::Parse> for conversion functions.
59 Creates a new cust_pay_refund. To add the cust_pay_refund to the database,
64 sub table { 'cust_pay_refund'; }
68 Adds this cust_pay_refund to the database. If there is an error, returns the
69 error, otherwise returns false.
75 return "Can't apply refund to closed payment"
76 if $self->cust_pay->closed =~ /^Y/i;
77 return "Can't apply payment to closed refund"
78 if $self->cust_refund->closed =~ /^Y/i;
79 $self->SUPER::insert(@_);
88 return "Can't remove refund from closed payment"
89 if $self->cust_pay->closed =~ /^Y/i;
90 return "Can't remove payment from closed refund"
91 if $self->cust_refund->closed =~ /^Y/i;
92 $self->SUPER::delete(@_);
95 =item replace OLD_RECORD
97 Application of refunds to payments may not be modified.
102 return "Can't modify application of a refund to payment!"
107 Checks all fields to make sure this is a valid refund application to a payment.
108 If there is an error, returns the error, otherwise returns false. Called by
109 the insert and replace methods.
117 $self->ut_numbern('payrefundnum')
118 || $self->ut_number('paynum')
119 || $self->ut_number('refundnum')
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 return "Unknown payment"
128 unless my $cust_pay =
129 qsearchs( 'cust_pay', { 'paynum' => $self->paynum } );
131 return "Unknown refund"
132 unless my $cust_refund =
133 qsearchs( 'cust_refund', { 'refundnum' => $self->refundnum } );
135 $self->_date(time) unless $self->_date;
137 return 'Cannot apply ($'. $self->amount. ') more than'.
138 ' remaining value of refund ($'. $cust_refund->unapplied. ')'
139 unless $self->amount <= $cust_refund->unapplied;
141 return "Cannot apply more than remaining value of payment"
142 unless $self->amount <= $cust_pay->unapplied;
149 Returns the payment (see L<FS::cust_pay>)
153 Returns the refund (see L<FS::cust_refund>)
163 L<FS::Record>, L<FS::cust_refund>, L<FS::cust_bill>, L<FS::cust_credit>,
164 schema.html from the base documentation.