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. FS::cust_refund inherits from
34 FS::Record. The following fields are currently supported:
38 =item refundnum - primary key (assigned automatically for new refunds)
40 =item crednum - Credit (see L<FS::cust_credit>)
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 otaker - order taker (assigned automatically, see L<FS::UID>)
61 Creates a new refund. To add the refund to the database, see L<"insert">.
65 sub table { 'cust_refund'; }
69 Adds this refund to the database, and updates the credit (see
80 return $error if $error;
83 qsearchs( 'cust_credit', { 'crednum' => $self->crednum } );
84 return "Unknown crednum" unless $old_cust_credit;
85 my %hash = $old_cust_credit->hash;
86 $hash{credited} = sprintf("%.2f", $hash{credited} - $self->refund );
87 my($new_cust_credit) = new FS::cust_credit ( \%hash );
89 local $SIG{HUP} = 'IGNORE';
90 local $SIG{INT} = 'IGNORE';
91 local $SIG{QUIT} = 'IGNORE';
92 local $SIG{TERM} = 'IGNORE';
93 local $SIG{TSTP} = 'IGNORE';
94 local $SIG{PIPE} = 'IGNORE';
96 $error = $new_cust_credit->replace($old_cust_credit);
97 return "Error modifying cust_credit: $error" if $error;
104 Currently unimplemented (accounting reasons).
109 return "Can't (yet?) delete cust_refund records!";
112 =item replace OLD_RECORD
114 Currently unimplemented (accounting reasons).
119 return "Can't (yet?) modify cust_refund records!";
124 Checks all fields to make sure this is a valid refund. If there is an error,
125 returns the error, otherwise returns false. Called by the insert method.
135 $self->ut_number('refundnum')
136 || $self->ut_number('crednum')
137 || $self->ut_money('amount')
138 || $self->ut_numbern('_date')
140 return $error if $error;
142 $self->_date(time) unless $self->_date;
144 $self->payby =~ /^(CARD|BILL|COMP)$/ or return "Illegal payby";
147 if ( $self->payby eq 'CARD' ) {
148 my $payinfo = $self->payinfo;
149 $self->payinfo($payinfo =~ s/\D//g);
150 if ( $self->payinfo ) {
151 $self->payinfo =~ /^(\d{13,16})$/
152 or return "Illegal (mistyped?) credit card number (payinfo)";
154 validate($self->payinfo) or return "Illegal credit card number";
155 return "Unknown card type" if cardtype($self->payinfo) eq "Unknown";
157 $self->payinfo('N/A');
161 $error = $self->ut_textn('payinfo');
162 return $error if $error;
165 $self->otaker(getotaker);
174 $Id: cust_refund.pm,v 1.1 1999-08-04 09:03:53 ivan Exp $
178 Delete and replace methods.
182 L<FS::Record>, L<FS::cust_credit>, schema.html from the base documentation.