remove
[freeside.git] / httemplate / edit / process / cust_credit_bill.cgi
1 <!-- $Id: cust_credit_bill.cgi,v 1.3 2002-01-30 14:18:08 ivan Exp $ -->
2 <%
3
4 $cgi->param('crednum') =~ /^(\d*)$/ or die "Illegal crednum!";
5 my $crednum = $1;
6
7 my $cust_credit = qsearchs('cust_credit', { 'crednum' => $crednum } )
8   or die "No such crednum";
9
10 my $cust_main = qsearchs('cust_main', { 'custnum' => $cust_credit->custnum } )
11   or die "Bogus credit:  not attached to customer";
12
13 my $custnum = $cust_main->custnum;
14
15 my $new;
16 if ($cgi->param('invnum') =~ /^Refund$/) {
17   $new = new FS::cust_refund ( {
18     'reason'  => $cust_credit->reason,
19     'refund'  => $cgi->param('amount'),
20     'payby'   => 'BILL',
21     '_date'   => $cgi->param('_date'),
22     'payinfo' => 'Cash',
23     'crednum' => $crednum,
24   } );
25 } else {
26   $new = new FS::cust_credit_bill ( {
27     map {
28       $_, scalar($cgi->param($_));
29     #} qw(custnum _date amount invnum)
30     } fields('cust_credit_bill')
31   } );
32 }
33
34 my $error = $new->insert;
35
36 if ( $error ) {
37   $cgi->param('error', $error);
38   print $cgi->redirect(popurl(2). "cust_credit_bill.cgi?". $cgi->query_string );
39 } else {
40   print $cgi->redirect(popurl(3). "view/cust_main.cgi?$custnum");
41 }
42
43
44 %>