1 package FS::cust_credit_refund;
2 use base qw( FS::cust_main_Mixin FS::Record );
8 FS::cust_credit_refund - Object methods for cust_bill_pay records
12 use FS::cust_credit_refund;
14 $record = new FS::cust_credit_refund \%hash;
15 $record = new FS::cust_credit_refund { 'column' => 'value' };
17 $error = $record->insert;
19 $error = $new_record->replace($old_record);
21 $error = $record->delete;
23 $error = $record->check;
27 An FS::cust_credit_refund represents the application of a refund to a specific
28 credit. FS::cust_credit_refund inherits from FS::Record. The following fields
29 are currently supported:
33 =item creditrefundnum - primary key (assigned automatically)
35 =item crednum - Credit (see L<FS::cust_credit>)
37 =item refundnum - Refund (see L<FS::cust_refund>)
39 =item amount - Amount of the refund to apply to the specific credit.
41 =item _date - specified as a UNIX timestamp; see L<perlfunc/"time">. Also see
42 L<Time::Local> and L<Date::Parse> for conversion functions.
52 Creates a new record. To add the record to the database, see L<"insert">.
56 sub table { 'cust_credit_refund'; }
60 Adds this record to the database. If there is an error, returns the error,
61 otherwise returns false.
67 return "Can't apply refund to closed credit"
68 if $self->cust_credit->closed =~ /^Y/i;
69 return "Can't apply credit to closed refund"
70 if $self->cust_refund->closed =~ /^Y/i;
71 $self->SUPER::insert(@_);
76 Remove this cust_credit_refund from the database. If there is an error,
77 returns the error, otherwise returns false.
83 return "Can't remove refund from closed credit"
84 if $self->cust_credit->closed =~ /^Y/i;
85 return "Can't remove credit from closed refund"
86 if $self->cust_refund->closed =~ /^Y/i;
87 $self->SUPER::delete(@_);
90 =item replace OLD_RECORD
92 Currently unimplemented (accounting reasons).
97 return "Can't (yet?) modify cust_credit_refund records!";
102 Checks all fields to make sure this is a valid refund application. If there is
103 an error, returns the error, otherwise returns false. Called by the insert
112 $self->ut_numbern('creditrefundnum')
113 || $self->ut_number('crednum')
114 || $self->ut_number('refundnum')
115 || $self->ut_money('amount')
116 || $self->ut_numbern('_date')
118 return $error if $error;
120 return "amount must be > 0" if $self->amount <= 0;
122 return "unknown cust_credit.crednum: ". $self->crednum
123 unless my $cust_credit = $self->cust_credit;
125 return "Unknown refund"
126 unless my $cust_refund = $self->cust_refund;
128 $self->_date(time) unless $self->_date;
130 return "Cannot apply more than remaining value of credit"
131 unless $self->amount <= $cust_credit->credited;
133 return "Cannot apply more than remaining value of refund"
134 unless $self->amount <= $cust_refund->unapplied;
141 Returns the refund (see L<FS::cust_refund>)
145 Returns the credit (see L<FS::cust_credit>)
151 Delete and replace methods.
153 the checks for over-applied refunds could be better done like the ones in
158 L<FS::cust_credit>, L<FS::cust_refund>, L<FS::Record>, schema.html from the