This commit was generated by cvs2svn to compensate for changes in r8593,
[freeside.git] / httemplate / edit / process / cust_refund.cgi
1 %if ( $error ) {
2 %  $cgi->param('error', $error);
3 <% $cgi->redirect(popurl(2). "cust_refund.cgi?". $cgi->query_string ) %>
4 %} else {
5 %
6 %  if ( $link eq 'popup' ) {
7 %
8 <% header('Refund entered') %>
9     <SCRIPT TYPE="text/javascript">
10       window.top.location.reload();
11     </SCRIPT>
12
13     </BODY></HTML>
14 %  } else {
15 <% $cgi->redirect(popurl(3). "view/cust_main.cgi?$custnum") %>
16 %  }
17 %}
18 <%init>
19
20 die "access denied"
21   unless $FS::CurrentUser::CurrentUser->access_right('Refund payment')
22       || $FS::CurrentUser::CurrentUser->access_right('Post refund');
23
24 $cgi->param('custnum') =~ /^(\d*)$/ or die "Illegal custnum!";
25 my $custnum = $1;
26 my $cust_main = qsearchs('cust_main', { 'custnum' => $custnum } )
27   or die "unknown custnum $custnum";
28
29 my $link    = $cgi->param('popup') ? 'popup' : '';
30
31 my $error = '';
32 if ( $cgi->param('payby') =~ /^(CARD|CHEK)$/ ) { 
33   my %options = ();
34   my $bop = $FS::payby::payby2bop{$1};
35   $cgi->param('refund') =~ /^(\d*)(\.\d{2})?$/
36     or die "illegal refund amount ". $cgi->param('refund');
37   my $refund = "$1$2";
38   $cgi->param('paynum') =~ /^(\d*)$/ or die "Illegal paynum!";
39   my $paynum = $1;
40   my $reason = $cgi->param('reason');
41   my $paydate = $cgi->param('exp_year'). '-'. $cgi->param('exp_month'). '-01';
42   $options{'paydate'} = $paydate if $paydate =~ /^\d{2,4}-\d{1,2}-01$/;
43   $error = $cust_main->realtime_refund_bop( $bop, 'amount' => $refund,
44                                                   'paynum' => $paynum,
45                                                   'reason' => $reason,
46                                                   %options );
47 } else {
48   my $new = new FS::cust_refund ( {
49     map {
50       $_, scalar($cgi->param($_));
51     } fields('cust_refund') #huh? , 'paynum' )
52   } );
53   $error = $new->insert;
54 }
55
56 </%init>