This commit was generated by cvs2svn to compensate for changes in r6255,
[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
17 $cgi->param('paynum') =~ /^(\d*)$/ or die "Illegal paynum!";
18 my $paynum = $1;
19
20 my $cust_pay = qsearchs('cust_pay', { 'paynum' => $paynum } )
21   or die "No such paynum";
22
23 my $cust_main = qsearchs('cust_main', { 'custnum' => $cust_pay->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'  => 'Refunding payment', #enter reason in UI
32     'refund'  => $cgi->param('amount'),
33     'payby'   => 'BILL',
34     #'_date'   => $cgi->param('_date'),
35     'payinfo' => 'Cash', #enter payinfo in UI
36     'paynum' => $paynum,
37   } );
38 } else {
39   $new = new FS::cust_bill_pay ( {
40     map {
41       $_, scalar($cgi->param($_));
42     #} qw(custnum _date amount invnum)
43     } fields('cust_bill_pay')
44   } );
45 }
46
47 my $error = $new->insert;
48
49 </%init>