1 package FS::cust_refund;
5 use Business::CreditCard;
6 use FS::Record qw( qsearchs );
7 use FS::UID qw(getotaker);
10 @ISA = qw( FS::Record );
14 FS::cust_refund - Object method for cust_refund objects
20 $record = new FS::cust_refund \%hash;
21 $record = new FS::cust_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_refund represents a refund: the transfer of money to a customer;
34 equivalent to a negative payment (see L<FS::cust_pay>). FS::cust_refund
35 inherits from FS::Record. The following fields are currently supported:
39 =item refundnum - primary key (assigned automatically for new refunds)
41 =item crednum - Credit (see L<FS::cust_credit>)
43 =item refund - Amount of the refund
45 =item _date - specified as a UNIX timestamp; see L<perlfunc/"time">. Also see
46 L<Time::Local> and L<Date::Parse> for conversion functions.
48 =item payby - `CARD' (credit cards), `BILL' (billing), or `COMP' (free)
50 =item payinfo - card number, P.O.#, or comp issuer (4-8 lowercase alphanumerics; think username)
52 =item otaker - order taker (assigned automatically, see L<FS::UID>)
62 Creates a new refund. To add the refund to the database, see L<"insert">.
66 sub table { 'cust_refund'; }
70 Adds this refund to the database, and updates the credit (see
81 return $error if $error;
84 qsearchs( 'cust_credit', { 'crednum' => $self->crednum } );
85 return "Unknown crednum" unless $old_cust_credit;
86 my %hash = $old_cust_credit->hash;
87 $hash{credited} = sprintf("%.2f", $hash{credited} - $self->refund );
88 my($new_cust_credit) = new FS::cust_credit ( \%hash );
90 local $SIG{HUP} = 'IGNORE';
91 local $SIG{INT} = 'IGNORE';
92 local $SIG{QUIT} = 'IGNORE';
93 local $SIG{TERM} = 'IGNORE';
94 local $SIG{TSTP} = 'IGNORE';
95 local $SIG{PIPE} = 'IGNORE';
97 $error = $new_cust_credit->replace($old_cust_credit);
98 return "Error modifying cust_credit: $error" if $error;
100 $self->SUPER::insert;
105 Currently unimplemented (accounting reasons).
110 return "Can't (yet?) delete cust_refund records!";
113 =item replace OLD_RECORD
115 Currently unimplemented (accounting reasons).
120 return "Can't (yet?) modify cust_refund records!";
125 Checks all fields to make sure this is a valid refund. If there is an error,
126 returns the error, otherwise returns false. Called by the insert method.
136 $self->ut_number('refundnum')
137 || $self->ut_number('crednum')
138 || $self->ut_money('amount')
139 || $self->ut_numbern('_date')
141 return $error if $error;
143 $self->_date(time) unless $self->_date;
145 $self->payby =~ /^(CARD|BILL|COMP)$/ or return "Illegal payby";
148 if ( $self->payby eq 'CARD' ) {
149 my $payinfo = $self->payinfo;
150 $self->payinfo($payinfo =~ s/\D//g);
151 if ( $self->payinfo ) {
152 $self->payinfo =~ /^(\d{13,16})$/
153 or return "Illegal (mistyped?) credit card number (payinfo)";
155 validate($self->payinfo) or return "Illegal credit card number";
156 return "Unknown card type" if cardtype($self->payinfo) eq "Unknown";
158 $self->payinfo('N/A');
162 $error = $self->ut_textn('payinfo');
163 return $error if $error;
166 $self->otaker(getotaker);
175 $Id: cust_refund.pm,v 1.2 2001-02-11 17:17:39 ivan Exp $
179 Delete and replace methods.
183 L<FS::Record>, L<FS::cust_credit>, schema.html from the base documentation.