1 package FS::cust_refund;
5 use Business::CreditCard;
6 use FS::Record qw( qsearchs dbh );
7 use FS::UID qw(getotaker);
9 use FS::cust_credit_refund;
11 @ISA = qw( FS::Record );
15 FS::cust_refund - Object method for cust_refund objects
21 $record = new FS::cust_refund \%hash;
22 $record = new FS::cust_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_refund represents a refund: the transfer of money to a customer;
35 equivalent to a negative payment (see L<FS::cust_pay>). FS::cust_refund
36 inherits from FS::Record. The following fields are currently supported:
40 =item refundnum - primary key (assigned automatically for new refunds)
42 =item refund - Amount of the refund
44 =item _date - specified as a UNIX timestamp; see L<perlfunc/"time">. Also see
45 L<Time::Local> and L<Date::Parse> for conversion functions.
47 =item payby - `CARD' (credit cards), `BILL' (billing), or `COMP' (free)
49 =item payinfo - card number, P.O.#, or comp issuer (4-8 lowercase alphanumerics; think username)
51 =item paybatch - text field for tracking card processing
53 =item otaker - order taker (assigned automatically, see L<FS::UID>)
63 Creates a new refund. To add the refund to the database, see L<"insert">.
67 sub table { 'cust_refund'; }
71 Adds this refund to the database.
73 For backwards-compatibility and convenience, if the additional field crednum is
74 defined, an FS::cust_credit_refund record for the full amount of the refund
82 local $SIG{HUP} = 'IGNORE';
83 local $SIG{INT} = 'IGNORE';
84 local $SIG{QUIT} = 'IGNORE';
85 local $SIG{TERM} = 'IGNORE';
86 local $SIG{TSTP} = 'IGNORE';
87 local $SIG{PIPE} = 'IGNORE';
89 my $oldAutoCommit = $FS::UID::AutoCommit;
90 local $FS::UID::AutoCommit = 0;
93 my $error = $self->check;
94 return $error if $error;
96 $error = $self->SUPER::insert;
98 $dbh->rollback if $oldAutoCommit;
102 if ( $self->crednum ) {
103 my $cust_credit_refund = new FS::cust_credit_refund {
104 'cred' => $self->cred,
105 'refundnum' => $self->refundnum,
106 'amount' => $self->refund,
107 '_date' => $self->_date,
109 $error = $cust_bill_pay->insert;
111 $dbh->rollback if $oldAutoCommit;
116 $dbh->commit or die $dbh->errstr if $oldAutoCommit;
124 Currently unimplemented (accounting reasons).
129 return "Can't (yet?) delete cust_refund records!";
132 =item replace OLD_RECORD
134 Currently unimplemented (accounting reasons).
139 return "Can't (yet?) modify cust_refund records!";
144 Checks all fields to make sure this is a valid refund. If there is an error,
145 returns the error, otherwise returns false. Called by the insert method.
153 $self->ut_number('refundnum')
154 || $self->ut_money('amount')
155 || $self->ut_numbern('_date')
156 || $self->ut_textn('paybatch')
158 return $error if $error;
160 $self->_date(time) unless $self->_date;
162 $self->payby =~ /^(CARD|BILL|COMP)$/ or return "Illegal payby";
165 if ( $self->payby eq 'CARD' ) {
166 my $payinfo = $self->payinfo;
167 $self->payinfo($payinfo =~ s/\D//g);
168 if ( $self->payinfo ) {
169 $self->payinfo =~ /^(\d{13,16})$/
170 or return "Illegal (mistyped?) credit card number (payinfo)";
172 validate($self->payinfo) or return "Illegal credit card number";
173 return "Unknown card type" if cardtype($self->payinfo) eq "Unknown";
175 $self->payinfo('N/A');
179 $error = $self->ut_textn('payinfo');
180 return $error if $error;
183 $self->otaker(getotaker);
192 $Id: cust_refund.pm,v 1.4 2001-09-01 20:11:07 ivan Exp $
196 Delete and replace methods.
200 L<FS::Record>, L<FS::cust_credit>, schema.html from the base documentation.