1 package FS::cust_refund;
4 use vars qw(@ISA @EXPORT_OK);
6 use Business::CreditCard;
7 use FS::Record qw(fields qsearchs);
8 use FS::UID qw(getotaker);
11 @ISA = qw(FS::Record Exporter);
12 @EXPORT_OK = qw(fields);
16 FS::cust_refund - Object method for cust_refund objects
22 $record = create FS::cust_refund \%hash;
23 $record = create 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. FS::cust_refund inherits from
36 FS::Record. The following fields are currently supported:
40 =item refundnum - primary key (assigned automatically for new refunds)
42 =item crednum - Credit (see L<FS::cust_credit>)
44 =item refund - Amount of the refund
46 =item _date - specified as a UNIX timestamp; see L<perlfunc/"time">. Also see
47 L<Time::Local> and L<Date::Parse> for conversion functions.
49 =item payby - `CARD' (credit cards), `BILL' (billing), or `COMP' (free)
51 =item payinfo - card number, P.O.#, or comp issuer (4-8 lowercase alphanumerics; think username)
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">.
68 my($proto,$hashref)=@_;
70 #now in FS::Record::new
72 #foreach $field (fields('cust_refund')) {
73 # $hashref->{$field}='' unless defined $hashref->{$field};
76 $proto->new('cust_refund',$hashref);
82 Adds this refund to the database, and updates the credit (see
93 return $error if $error;
95 my($old_cust_credit) = qsearchs('cust_credit', {
96 'crednum' => $self->getfield('crednum')
98 return "Unknown crednum" unless $old_cust_credit;
99 my(%hash)=$old_cust_credit->hash;
100 $hash{credited} = sprintf("%.2f",$hash{credited} - $self->getfield('refund') );
101 my($new_cust_credit) = create FS::cust_credit ( \%hash );
103 local $SIG{HUP} = 'IGNORE';
104 local $SIG{INT} = 'IGNORE';
105 local $SIG{QUIT} = 'IGNORE';
106 local $SIG{TERM} = 'IGNORE';
107 local $SIG{TSTP} = 'IGNORE';
109 $error=$new_cust_credit -> replace($old_cust_credit);
110 return "Error modifying cust_credit: $error" if $error;
117 Currently unimplemented (accounting reasons).
122 return "Can't (yet?) delete cust_refund records!";
129 =item replace OLD_RECORD
131 Currently unimplemented (accounting reasons).
136 return "Can't (yet?) modify cust_refund records!";
139 # return "(Old) Not a cust_refund record!" unless $old->table eq "cust_refund";
147 Checks all fields to make sure this is a valid refund. If there is an error,
148 returns the error, otherwise returns false. Called by the insert method.
154 return "Not a cust_refund record!" unless $self->table eq "cust_refund";
157 $self->ut_number('refundnum')
158 || $self->ut_number('crednum')
159 || $self->ut_money('amount')
160 || $self->ut_numbern('_date')
162 return $error if $error;
164 my($recref) = $self->hashref;
166 $recref->{_date} ||= time;
168 $recref->{payby} =~ /^(CARD|BILL|COMP)$/ or return "Illegal payby";
169 $recref->{payby} = $1;
171 if ( $recref->{payby} eq 'CARD' ) {
173 $recref->{payinfo} =~ s/\D//g;
174 if ( $recref->{payinfo} ) {
175 $recref->{payinfo} =~ /^(\d{13,16})$/
176 or return "Illegal (mistyped?) credit card number (payinfo)";
177 $recref->{payinfo} = $1;
178 #validate($recref->{payinfo})
179 # or return "Illegal (checksum) credit card number (payinfo)";
180 my($type)=cardtype($recref->{payinfo});
181 return "Unknown credit card type"
182 unless ( $type =~ /^VISA/ ||
183 $type =~ /^MasterCard/ ||
184 $type =~ /^American Express/ ||
185 $type =~ /^Discover/ );
187 $recref->{payinfo}='N/A';
190 } elsif ( $recref->{payby} eq 'BILL' ) {
192 $recref->{payinfo} =~ /^([\w \-]*)$/
193 or return "Illegal P.O. number (payinfo)";
194 $recref->{payinfo} = $1;
196 } elsif ( $recref->{payby} eq 'COMP' ) {
198 $recref->{payinfo} =~ /^([\w]{2,8})$/
199 or return "Illegal comp account issuer (payinfo)";
200 $recref->{payinfo} = $1;
204 $self->otaker(getotaker);
213 It doesn't properly override FS::Record yet.
215 Delete and replace methods.
219 L<FS::Record>, L<FS::cust_credit>, schema.html from the base documentation.
223 ivan@sisd.com 98-mar-18
225 ->create had wrong tablename ivan@sisd.com 98-jun-16
228 pod and finish up ivan@sisd.com 98-sep-21