1 % if ( $link eq 'popup' ) {
2 <% include('/elements/header-popup.html', $title ) %>
4 <% include("/elements/header.html", $title, '') %>
7 <% include('/elements/error.html') %>
9 % unless ( $link eq 'popup' ) {
10 <% small_custview($custnum, $conf->config('countrydefault')) %>
13 <FORM NAME="RefundForm" ACTION="<% $p1 %>process/cust_refund.cgi" METHOD=POST onSubmit="document.RefundForm.submitButton.disabled=true">
14 <INPUT TYPE="hidden" NAME="popup" VALUE="<% $link %>">
15 <INPUT TYPE="hidden" NAME="refundnum" VALUE="">
16 <INPUT TYPE="hidden" NAME="custnum" VALUE="<% $custnum %>">
17 <INPUT TYPE="hidden" NAME="paynum" VALUE="<% $paynum %>">
18 <INPUT TYPE="hidden" NAME="_date" VALUE="<% $_date %>">
19 <INPUT TYPE="hidden" NAME="payby" VALUE="<% $payby %>">
20 <INPUT TYPE="hidden" NAME="paybatch" VALUE="">
21 <INPUT TYPE="hidden" NAME="credited" VALUE="">
27 % #false laziness w/FS/FS/cust_pay.pm
28 % my $payby = FS::payby->payname($cust_pay->payby);
29 % my $paymask = $cust_pay->paymask;
30 % my $paydate = $cust_pay->paydate;
31 % if ( $cgi->param('error') ) {
32 % $paydate = $cgi->param('exp_year'). '-'. $cgi->param('exp_month'). '-01';
33 % $paydate = '' unless ($paydate =~ /^\d{2,4}-\d{1,2}-01$'/);
37 <TABLE class="fsinnerbox">
40 <TD ALIGN="right">Amount</TD><TD BGCOLOR="#ffffff">$<% $cust_pay->paid %></TD>
44 <TD ALIGN="right">Date</TD><TD BGCOLOR="#ffffff"><% time2str($date_format, $cust_pay->_date) %></TD>
48 <TD ALIGN="right">Method</TD><TD BGCOLOR="#ffffff"><% $payby %> # <% $paymask %></TD>
51 % unless ( $paydate || $cust_pay->payby ne 'CARD' ) { # possibly other reasons: i.e. card has since expired
53 <TD ALIGN="right">Expiration</TD><TD BGCOLOR="#ffffff">
54 <% include( '/elements/select-month_year.html',
56 'selected_date' => $paydate,
57 'empty_option' => !$paydate,
62 % if ( $cust_pay->processor ) {
64 <TD ALIGN="right">Processor</TD>
65 <TD BGCOLOR="#ffffff"><% $cust_pay->processor %></TD>
67 % if ( length($cust_pay->auth) ) {
70 <TD ALIGN="right">Authorization</TD>
71 <TD BGCOLOR="#ffffff"><% $cust_pay->auth %></TD>
74 % if ( length($cust_pay->order_number) ) {
77 <TD ALIGN="right">Order number</TD>
78 <TD BGCOLOR="#ffffff"><% $cust_pay->order_number %></TD>
81 % } # if ($cust_pay->processor)
89 <TABLE class="fsinnerbox">
92 <TD ALIGN="right">Date</TD>
93 <TD BGCOLOR="#ffffff"><% time2str($date_format, $_date) %></TD>
97 <TD ALIGN="right">Amount</TD>
98 <TD BGCOLOR="#ffffff">$<INPUT TYPE="text" NAME="refund" VALUE="<% $refund %>" SIZE=8 MAXLENGTH=9> by <B><% FS::payby->payname($payby) %></B></TD>
101 % if ( $payby eq 'BILL' ) {
103 <TD ALIGN="right">Check #</TD>
104 <TD COLSPAN=2><INPUT TYPE="text" NAME="payinfo" VALUE="<% $payinfo %>" SIZE=10></TD>
108 % elsif ($payby eq 'CHEK' || $payby eq 'CARD') {
110 <SCRIPT TYPE="text/javascript">
111 function cust_payby_changed (what) {
112 var custpaybynum = what.options[what.selectedIndex].value
113 if ( custpaybynum == '' || custpaybynum == '0' ) {
114 //what.form.payinfo.disabled = false;
115 $('#cust_payby').slideDown();
117 //what.form.payinfo.value = '';
118 //what.form.payinfo.disabled = true;
119 $('#cust_payby').slideUp();
123 % my @cust_payby = ();
124 % if ( $payby eq 'CARD' ) {
125 % @cust_payby = $cust_main->cust_payby('CARD','DCRD');
126 % } elsif ( $payby eq 'CHEK' ) {
127 % @cust_payby = $cust_main->cust_payby('CHEK','DCHK');
129 % die "unknown payby $payby";
132 % my $custpaybynum = length(scalar($cgi->param('custpaybynum')))
133 % ? scalar($cgi->param('custpaybynum'))
134 % : scalar(@cust_payby) && $cust_payby[0]->custpaybynum;
137 <INPUT TYPE="hidden" NAME="payinfo" VALUE="<% $payinfo %>" SIZE=10>
140 <& /elements/tr-select-cust_payby.html,
141 'cust_payby' => \@cust_payby,
142 'curr_value' => $custpaybynum,
143 'onchange' => 'cust_payby_changed(this)',
147 % if ( $conf->exists("batch-enable")
148 % || grep $payby eq $_, $conf->config('batch-enable_payby')
150 % if ( grep $payby eq $_, $conf->config('realtime-disable_payby') ) {
151 <INPUT TYPE="hidden" NAME="batch" VALUE="1">
154 <TD ALIGN="right"><INPUT TYPE="checkbox" NAME="batch" VALUE="1" ID="batch" <% ($batchnum || $batch) ? 'checked' : '' %> ></TD>
155 <TH ALIGN="left"> <% mt('Add to current batch') |h %></TH>
163 % if ( !$cust_pay ) {
165 <% $custpaybynum ? 'STYLE="display:none"'
169 <TABLE class="fsinnerbox">
171 <& /elements/cust_payby_new.html,
172 'cust_payby' => \@cust_payby,
173 'curr_value' => $custpaybynum,
178 % } # end if cust_pay
181 <INPUT TYPE="hidden" NAME="payinfo" VALUE="">
186 <TABLE class="fsinnerbox">
187 <& /elements/tr-select-reason.html,
188 'field' => 'reasonnum',
189 'reason_class' => 'F',
190 'control_button' => "confirm_refund_button",
197 <INPUT TYPE="submit" NAME="submitButton" ID="confirm_refund_button" VALUE="<% mt('Post refund') |h %>" DISABLED>
201 % if ( $link eq 'popup' ) {
205 <% include('/elements/footer.html') %>
210 my $conf = new FS::Conf;
211 my $date_format = $conf->config('date_format') || '%m/%d/%Y';
213 my $custnum = $cgi->param('custnum');
214 my $refund = $cgi->param('refund');
215 my $payby = $cgi->param('payby');
216 my $payinfo = $cgi->param('payinfo');
217 my $reason = $cgi->param('reason');
218 my $link = $cgi->param('popup') ? 'popup' : '';
219 my $batch = $cgi->param('batch');
222 unless $FS::CurrentUser::CurrentUser->refund_access_right($payby);
224 my( $paynum, $cust_pay, $batchnum ) = ( '', '', '' );
225 if ( $cgi->param('paynum') =~ /^(\d+)$/ ) {
227 $cust_pay = qsearchs('cust_pay', { paynum=>$paynum } )
228 or die "unknown payment # $paynum";
229 $refund ||= $cust_pay->unrefunded;
230 $batchnum = $cust_pay->batchnum;
232 die "payment # $paynum is not for specified customer # $custnum"
233 unless $custnum == $cust_pay->custnum;
235 $custnum = $cust_pay->custnum;
238 die "no custnum or paynum specified!" unless $custnum;
240 my $cust_main = qsearchs( 'cust_main', { 'custnum'=>$custnum } );
241 die "unknown custnum $custnum" unless $cust_main;
247 my $title = 'Refund '. FS::payby->payname($payby). ' payment';