1 package FS::cust_refund;
5 use Business::CreditCard;
6 use FS::Record qw( dbh );
7 use FS::UID qw(getotaker);
9 use FS::cust_credit_refund;
12 @ISA = qw( FS::Record );
16 FS::cust_refund - Object method for cust_refund objects
22 $record = new FS::cust_refund \%hash;
23 $record = new FS::cust_refund { 'column' => 'value' };
25 $error = $record->insert;
27 $error = $new_record->replace($old_record);
29 $error = $record->delete;
31 $error = $record->check;
35 An FS::cust_refund represents a refund: the transfer of money to a customer;
36 equivalent to a negative payment (see L<FS::cust_pay>). FS::cust_refund
37 inherits from FS::Record. The following fields are currently supported:
41 =item refundnum - primary key (assigned automatically for new refunds)
43 =item custnum - customer (see L<FS::cust_main>)
45 =item refund - Amount of the refund
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.
50 =item payby - `CARD' (credit cards), `BILL' (billing), or `COMP' (free)
52 =item payinfo - card number, P.O.#, or comp issuer (4-8 lowercase alphanumerics; think username)
54 =item paybatch - text field for tracking card processing
56 =item otaker - order taker (assigned automatically, see L<FS::UID>)
66 Creates a new refund. To add the refund to the database, see L<"insert">.
70 sub table { 'cust_refund'; }
74 Adds this refund to the database.
76 For backwards-compatibility and convenience, if the additional field crednum is
77 defined, an FS::cust_credit_refund record for the full amount of the refund
78 will be created. In this case, custnum is optional.
85 local $SIG{HUP} = 'IGNORE';
86 local $SIG{INT} = 'IGNORE';
87 local $SIG{QUIT} = 'IGNORE';
88 local $SIG{TERM} = 'IGNORE';
89 local $SIG{TSTP} = 'IGNORE';
90 local $SIG{PIPE} = 'IGNORE';
92 my $oldAutoCommit = $FS::UID::AutoCommit;
93 local $FS::UID::AutoCommit = 0;
96 my $error = $self->check;
97 return $error if $error;
99 if ( $self->crednum ) {
100 my $cust_credit_refund = new FS::cust_credit_refund {
101 'cred' => $self->cred,
102 'refundnum' => $self->refundnum,
103 'amount' => $self->refund,
104 '_date' => $self->_date,
106 $error = $cust_credit_refund->insert;
108 $dbh->rollback if $oldAutoCommit;
111 $self->custnum($cust_credit_refund->cust_credit->custnum);
114 $error = $self->SUPER::insert;
116 $dbh->rollback if $oldAutoCommit;
120 $dbh->commit or die $dbh->errstr if $oldAutoCommit;
128 Currently unimplemented (accounting reasons).
133 return "Can't (yet?) delete cust_refund records!";
136 =item replace OLD_RECORD
138 Currently unimplemented (accounting reasons).
143 return "Can't (yet?) modify cust_refund records!";
148 Checks all fields to make sure this is a valid refund. If there is an error,
149 returns the error, otherwise returns false. Called by the insert method.
157 $self->ut_number('refundnum')
158 || $self->ut_number('custnum')
159 || $self->ut_money('amount')
160 || $self->ut_numbern('_date')
161 || $self->ut_textn('paybatch')
163 return $error if $error;
165 $self->_date(time) unless $self->_date;
167 return "unknown cust_main.custnum: ". $self->custnum
169 || qsearchs( 'cust_main', { 'custnum' => $self->custnum } );
171 $self->payby =~ /^(CARD|BILL|COMP)$/ or return "Illegal payby";
174 if ( $self->payby eq 'CARD' ) {
175 my $payinfo = $self->payinfo;
176 $self->payinfo($payinfo =~ s/\D//g);
177 if ( $self->payinfo ) {
178 $self->payinfo =~ /^(\d{13,16})$/
179 or return "Illegal (mistyped?) credit card number (payinfo)";
181 validate($self->payinfo) or return "Illegal credit card number";
182 return "Unknown card type" if cardtype($self->payinfo) eq "Unknown";
184 $self->payinfo('N/A');
188 $error = $self->ut_textn('payinfo');
189 return $error if $error;
192 $self->otaker(getotaker);
201 $Id: cust_refund.pm,v 1.7 2001-09-02 04:25:55 ivan Exp $
205 Delete and replace methods.
209 L<FS::Record>, L<FS::cust_credit>, schema.html from the base documentation.