ACLs
[freeside.git] / httemplate / edit / process / cust_bill_pay.cgi
1 %if ( $error ) {
2 %  $cgi->param('error', $error);
3 <% $cgi->redirect(popurl(2). "cust_bill_pay.cgi?". $cgi->query_string ) %>
4 %} else {
5 <% header('Payment 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 payment') #;
16       || $FS::CurrentUser::CurrentUser->access_right('Post payment'): #remove after 1.7.3
17
18 $cgi->param('paynum') =~ /^(\d*)$/ or die "Illegal paynum!";
19 my $paynum = $1;
20
21 my $cust_pay = qsearchs('cust_pay', { 'paynum' => $paynum } )
22   or die "No such paynum";
23
24 my $cust_main = qsearchs('cust_main', { 'custnum' => $cust_pay->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'  => 'Refunding payment', #enter reason in UI
33     'refund'  => $cgi->param('amount'),
34     'payby'   => 'BILL',
35     #'_date'   => $cgi->param('_date'),
36     'payinfo' => 'Cash', #enter payinfo in UI
37     'paynum' => $paynum,
38   } );
39 } else {
40   $new = new FS::cust_bill_pay ( {
41     map {
42       $_, scalar($cgi->param($_));
43     #} qw(custnum _date amount invnum)
44     } fields('cust_bill_pay')
45   } );
46 }
47
48 my $error = $new->insert;
49
50 </%init>