1 package FS::cust_pay_refund;
4 use vars qw( @ISA ); #$conf );
5 use FS::UID qw( getotaker );
6 use FS::Record qw( qsearchs ); # qsearch );
11 @ISA = qw( FS::Record );
13 #ask FS::UID to run this stuff for us later
14 #FS::UID->install_callback( sub {
15 # $conf = new FS::Conf;
20 FS::cust_pay_refund - Object methods for cust_pay_refund records
24 use FS::cust_pay_refund;
26 $record = new FS::cust_pay_refund \%hash;
27 $record = new FS::cust_pay_refund { '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_pay_refund object represents application of a refund (see
40 L<FS::cust_refund>) to an payment (see L<FS::cust_pay>). FS::cust_pay_refund
41 inherits from FS::Record. The following fields are currently supported:
45 =item payrefundnum - primary key
47 =item paynum - credit being applied
49 =item refundnum - invoice to which credit is applied (see L<FS::cust_bill>)
51 =item amount - amount of the credit applied
53 =item _date - specified as a UNIX timestamp; see L<perlfunc/"time">. Also see
54 L<Time::Local> and L<Date::Parse> for conversion functions.
64 Creates a new cust_pay_refund. To add the cust_pay_refund to the database,
69 sub table { 'cust_pay_refund'; }
73 Adds this cust_pay_refund to the database. If there is an error, returns the
74 error, otherwise returns false.
82 return "Can't apply refund to closed payment"
83 if $self->cust_pay->closed =~ /^Y/i;
84 return "Can't apply closed refund"
85 if $self->cust_refund->closed =~ /^Y/i;
86 $self->SUPER::delete(@_);
89 =item replace OLD_RECORD
91 Application of refunds to payments may not be modified.
96 return "Can't modify application of a refund to payment!"
101 Checks all fields to make sure this is a valid refund application to a payment.
102 If there is an error, returns the error, otherwise returns false. Called by
103 the insert and replace methods.
111 $self->ut_numbern('payrefundnum')
112 || $self->ut_number('paynum')
113 || $self->ut_number('refundnum')
114 || $self->ut_numbern('_date')
115 || $self->ut_money('amount')
117 return $error if $error;
119 return "amount must be > 0" if $self->amount <= 0;
121 return "Unknown payment"
122 unless my $cust_pay =
123 qsearchs( 'cust_pay', { 'paynum' => $self->paynum } );
125 return "Unknown refund"
126 unless my $cust_refund =
127 qsearchs( 'cust_refund', { 'refundnum' => $self->refundnum } );
129 $self->_date(time) unless $self->_date;
131 return 'Cannot apply ($'. $self->amount. ') more than'.
132 ' remaining value of refund ($'. $cust_refund->unapplied. ')'
133 unless $self->amount <= $cust_refund->unapplied;
135 return "Cannot apply more than remaining value of payment"
136 unless $self->amount <= $cust_pay->unapplied;
141 =item sub cust_credit
143 Returns the credit (see L<FS::cust_credit>)
149 qsearchs( 'cust_credit', { 'crednum' => $self->crednum } );
154 Returns the invoice (see L<FS::cust_bill>)
160 qsearchs( 'cust_bill', { 'invnum' => $self->invnum } );
171 L<FS::Record>, L<FS::cust_refund>, L<FS::cust_bill>, L<FS::cust_credit>,
172 schema.html from the base documentation.