Will things ever be the same again?
[freeside.git] / httemplate / edit / process / cust_credit_bill.cgi
1 %
2 %
3 %$cgi->param('crednum') =~ /^(\d*)$/ or die "Illegal crednum!";
4 %my $crednum = $1;
5 %
6 %my $cust_credit = qsearchs('cust_credit', { 'crednum' => $crednum } )
7 %  or die "No such crednum";
8 %
9 %my $cust_main = qsearchs('cust_main', { 'custnum' => $cust_credit->custnum } )
10 %  or die "Bogus credit:  not attached to customer";
11 %
12 %my $custnum = $cust_main->custnum;
13 %
14 %my $new;
15 %if ($cgi->param('invnum') =~ /^Refund$/) {
16 %  $new = new FS::cust_refund ( {
17 %    'reason'  => ( $cust_credit->reason || 'refund from credit' ),
18 %    'refund'  => $cgi->param('amount'),
19 %    'payby'   => 'BILL',
20 %    #'_date'   => $cgi->param('_date'),
21 %    #'payinfo' => 'Cash',
22 %    'payinfo' => 'Refund',
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 %
38 %  $cgi->param('error', $error);
39 %  
40 <% $cgi->redirect(popurl(2). "cust_credit_bill.cgi?". $cgi->query_string ) %>
41 %
42 %
43 %} else {
44 %
45 %  #print $cgi->redirect(popurl(3). "view/cust_main.cgi?$custnum");
46 %
47 %  
48 <% header('Credit application sucessful') %>
49   <SCRIPT TYPE="text/javascript">
50     window.top.location.reload();
51   </SCRIPT>
52
53   </BODY></HTML>
54 % } 
55