ACLs
[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       || $FS::CurrentUser::CurrentUser->access_right('Post credit'): #remove after 1.7.3
17
18 $cgi->param('crednum') =~ /^(\d*)$/ or die "Illegal crednum!";
19 my $crednum = $1;
20
21 my $cust_credit = qsearchs('cust_credit', { 'crednum' => $crednum } )
22   or die "No such crednum";
23
24 my $cust_main = qsearchs('cust_main', { 'custnum' => $cust_credit->custnum } )
25   or die "Bogus credit:  not attached to customer";
26
27 my $custnum = $cust_main->custnum;
28
29 my $new;
30 if ($cgi->param('invnum') =~ /^Refund$/) {
31   $new = new FS::cust_refund ( {
32     'reason'  => ( $cust_credit->reason || 'refund from credit' ),
33     'refund'  => $cgi->param('amount'),
34     'payby'   => 'BILL',
35     #'_date'   => $cgi->param('_date'),
36     #'payinfo' => 'Cash',
37     'payinfo' => 'Refund',
38     'crednum' => $crednum,
39   } );
40 } else {
41   $new = new FS::cust_credit_bill ( {
42     map {
43       $_, scalar($cgi->param($_));
44     #} qw(custnum _date amount invnum)
45     } fields('cust_credit_bill')
46   } );
47 }
48
49 my $error = $new->insert;
50
51 </%init>