2 % $cgi->param('error', $error);
3 <% $cgi->redirect(popurl(2). "cust_refund.cgi?". $cgi->query_string ) %>
6 % if ( $link eq 'popup' ) {
8 <& /elements/header-popup.html, 'Refund entered' &>
9 <SCRIPT TYPE="text/javascript">
15 <% $cgi->redirect(popurl(3). "view/cust_main.cgi?custnum=$custnum;show=payment_history") %>
21 unless $FS::CurrentUser::CurrentUser->access_right('Refund payment')
22 || $FS::CurrentUser::CurrentUser->access_right('Post refund');
24 $cgi->param('custnum') =~ /^(\d*)$/ or die "Illegal custnum!";
26 my $cust_main = qsearchs('cust_main', { 'custnum' => $custnum } )
27 or die "unknown custnum $custnum";
29 my $link = $cgi->param('popup') ? 'popup' : '';
31 my $payby = $cgi->param('payby');
34 unless $FS::CurrentUser::CurrentUser->refund_access_right($payby);
36 $cgi->param('reasonnum') =~ /^(-?\d+)$/ or die "Illegal reasonnum";
37 my ($reasonnum, $error) = $m->comp('/misc/process/elements/reason');
38 $cgi->param('reasonnum', $reasonnum) unless $error;
42 } elsif ( $payby =~ /^(CARD|CHEK)$/ ) {
44 my $bop = $FS::payby::payby2bop{$1};
45 $cgi->param('refund') =~ /^(\d*)(\.\d{2})?$/
46 or die "illegal refund amount ". $cgi->param('refund');
48 $cgi->param('paynum') =~ /^(\d*)$/ or die "Illegal paynum!";
50 my $paydate = $cgi->param('exp_year'). '-'. $cgi->param('exp_month'). '-01';
51 $options{'paydate'} = $paydate if $paydate =~ /^\d{2,4}-\d{1,2}-01$/;
52 $error = $cust_main->realtime_refund_bop( $bop, 'amount' => $refund,
54 'reasonnum' => scalar($cgi->param('reasonnum')),
58 $_, scalar($cgi->param($_))
59 } fields('cust_refund');
60 my $paynum = $cgi->param('paynum');
61 $paynum =~ /^(\d*)$/ or die "Illegal paynum!";
63 my $cust_pay = qsearchs('cust_pay',{ 'paynum' => $paynum });
64 die "Could not find paynum $paynum" unless $cust_pay;
65 $error = $cust_pay->refund(\%hash);
67 my $new = new FS::cust_refund ( \%hash );
68 $error = $new->insert;