new ACL name in 1.9 right away
[freeside.git] / httemplate / edit / process / cust_credit_bill.cgi
1 %if ( $error ) {
2 %  $cgi->param('error', $error);
3 <% $cgi->redirect(popurl(2). "cust_credit_bill.cgi?". $cgi->query_string ) %>
4 %} else {
5 <% header('Credit application sucessful') %>
6   <SCRIPT TYPE="text/javascript">
7     window.top.location.reload();
8   </SCRIPT>
9   </BODY>
10   </HTML>
11 % } 
12 <%init>
13
14 die "access denied"
15   unless $FS::CurrentUser::CurrentUser->access_right('Apply credit');
16
17 $cgi->param('crednum') =~ /^(\d*)$/ or die "Illegal crednum!";
18 my $crednum = $1;
19
20 my $cust_credit = qsearchs('cust_credit', { 'crednum' => $crednum } )
21   or die "No such crednum";
22
23 my $cust_main = qsearchs('cust_main', { 'custnum' => $cust_credit->custnum } )
24   or die "Bogus credit:  not attached to customer";
25
26 my $custnum = $cust_main->custnum;
27
28 my $new;
29 if ($cgi->param('invnum') =~ /^Refund$/) {
30   $new = new FS::cust_refund ( {
31     'reason'  => ( $cust_credit->reason || 'refund from credit' ),
32     'refund'  => $cgi->param('amount'),
33     'payby'   => 'BILL',
34     #'_date'   => $cgi->param('_date'),
35     #'payinfo' => 'Cash',
36     'payinfo' => 'Refund',
37     'crednum' => $crednum,
38   } );
39 } else {
40   $new = new FS::cust_credit_bill ( {
41     map {
42       $_, scalar($cgi->param($_));
43     #} qw(custnum _date amount invnum)
44     } fields('cust_credit_bill')
45   } );
46 }
47
48 my $error = $new->insert;
49
50 </%init>