paydate option for realtime_refund_bop and UI entry for cust_pay records without...
[freeside.git] / httemplate / edit / process / cust_refund.cgi
1 %$cgi->param('custnum') =~ /^(\d*)$/ or die "Illegal custnum!";
2 %my $custnum = $1;
3 %my $cust_main = qsearchs('cust_main', { 'custnum' => $custnum } )
4 %  or die "unknown custnum $custnum";
5 %
6 %my $error = '';
7 %if ( $cgi->param('payby') =~ /^(CARD|CHEK)$/ ) { 
8 %  my %options = ();
9 %  my $bop = $FS::payby::payby2bop{$1};
10 %  $cgi->param('refund') =~ /^(\d*)(\.\d{2})?$/
11 %    or die "illegal refund amount ". $cgi->param('refund');
12 %  my $refund = "$1$2";
13 %  $cgi->param('paynum') =~ /^(\d*)$/ or die "Illegal paynum!";
14 %  my $paynum = $1;
15 %  my $reason = $cgi->param('reason');
16 %  my $paydate = $cgi->param('exp_year'). '-'. $cgi->param('exp_month'). '-01';
17 %  $options{'paydate'} = $paydate if $paydate =~ /^\d{2,4}-\d{1,2}-01$/;
18 %  $error = $cust_main->realtime_refund_bop( $bop, 'amount' => $refund,
19 %                                                  'paynum' => $paynum,
20 %                                                  'reason' => $reason,
21 %                                                  %options );
22 %} else {
23 %  die 'unimplemented';
24 %  #my $new = new FS::cust_refund ( {
25 %  #  map {
26 %  #    $_, scalar($cgi->param($_));
27 %  #  } ( fields('cust_refund'), 'paynum' )
28 %  #} );
29 %  #$error = $new->insert;
30 %}
31 %
32 %
33 %if ( $error ) {
34 %  $cgi->param('error', $error);
35 %  print $cgi->redirect(popurl(2). "cust_refund.cgi?". $cgi->query_string );
36 %} else {
37 %  print $cgi->redirect(popurl(3). "view/cust_main.cgi?$custnum");
38 %}