This commit was generated by cvs2svn to compensate for changes in r5562,
[freeside.git] / httemplate / edit / process / cust_bill_pay.cgi
1 %
2 %
3 %$cgi->param('paynum') =~ /^(\d*)$/ or die "Illegal paynum!";
4 %my $paynum = $1;
5 %
6 %my $cust_pay = qsearchs('cust_pay', { 'paynum' => $paynum } )
7 %  or die "No such paynum";
8 %
9 %my $cust_main = qsearchs('cust_main', { 'custnum' => $cust_pay->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'  => 'Refunding payment', #enter reason in UI
18 %    'refund'  => $cgi->param('amount'),
19 %    'payby'   => 'BILL',
20 %    #'_date'   => $cgi->param('_date'),
21 %    'payinfo' => 'Cash', #enter payinfo in UI
22 %    'paynum' => $paynum,
23 %  } );
24 %} else {
25 %  $new = new FS::cust_bill_pay ( {
26 %    map {
27 %      $_, scalar($cgi->param($_));
28 %    #} qw(custnum _date amount invnum)
29 %    } fields('cust_bill_pay')
30 %  } );
31 %}
32 %
33 %my $error = $new->insert;
34 %
35 %if ( $error ) {
36 %
37 %  $cgi->param('error', $error);
38 %  
39 <% $cgi->redirect(popurl(2). "cust_bill_pay.cgi?". $cgi->query_string ) %>
40 %
41 %
42 %} else {
43 %
44 %  #print $cgi->redirect(popurl(3). "view/cust_main.cgi?$custnum");
45 %
46 %  
47 <% header('Payment application sucessful') %>
48   <SCRIPT TYPE="text/javascript">
49     window.top.location.reload();
50   </SCRIPT>
51
52   </BODY></HTML>
53 % } 
54