1 package FS::cust_credit_refund;
5 use FS::Record qw( qsearch qsearchs dbh );
6 #use FS::UID qw(getotaker);
10 @ISA = qw( FS::Record );
14 FS::cust_credit_refund - Object methods for cust_bill_pay records
18 use FS::cust_credit_refund;
20 $record = new FS::cust_credit_refund \%hash;
21 $record = new FS::cust_credit_refund { 'column' => 'value' };
23 $error = $record->insert;
25 $error = $new_record->replace($old_record);
27 $error = $record->delete;
29 $error = $record->check;
33 An FS::cust_credit_refund represents the application of a refund to a specific
34 credit. FS::cust_credit_refund inherits from FS::Record. The following fields
35 are currently supported:
39 =item creditrefundnum - primary key (assigned automatically)
41 =item crednum - Credit (see L<FS::cust_credit>)
43 =item refundnum - Refund (see L<FS::cust_refund>)
45 =item amount - Amount of the refund to apply to the specific credit.
47 =item _date - specified as a UNIX timestamp; see L<perlfunc/"time">. Also see
48 L<Time::Local> and L<Date::Parse> for conversion functions.
58 Creates a new record. To add the record to the database, see L<"insert">.
62 sub table { 'cust_credit_refund'; }
66 Adds this record to the database. If there is an error, returns the error,
67 otherwise returns false.
73 my $error = $self->SUPER::insert;
74 return $error if $error;
81 Currently unimplemented (accounting reasons).
86 return "Can't (yet?) delete cust_credit_refund records!";
89 =item replace OLD_RECORD
91 Currently unimplemented (accounting reasons).
96 return "Can't (yet?) modify cust_credit_refund records!";
101 Checks all fields to make sure this is a valid refund application. If there is
102 an error, returns the error, otherwise returns false. Called by the insert
111 $self->ut_numbern('creditrefundnum')
112 || $self->ut_number('crednum')
113 || $self->ut_number('refundnum')
114 || $self->ut_money('amount')
115 || $self->ut_numbern('_date')
117 return $error if $error;
119 return "amount must be > 0" if $self->amount <= 0;
121 return "unknown cust_credit.crednum: ". $self->crednum
122 unless my $cust_credit =
123 qsearchs( 'cust_credit', { 'crednum' => $self->crednum } );
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 more than remaining value of credit"
132 unless $self->amount <= $cust_credit->credited;
134 return "Cannot apply more than remaining value of refund"
135 unless $self->amount <= $cust_refund->unapplied;
142 Returns the refund (see L<FS::cust_refund>)
148 qsearchs( 'cust_refund', { 'refundnum' => $self->refundnum } );
153 Returns the credit (see L<FS::cust_credit>)
159 qsearchs( 'cust_credit', { 'crednum' => $self->crednum } );
166 Delete and replace methods.
168 the checks for over-applied refunds could be better done like the ones in
173 L<FS::cust_credit>, L<FS::cust_refund>, L<FS::Record>, schema.html from the