RT# 74435 - fixed errors in posting a echeck refund when no account is listed.
[freeside.git] / httemplate / edit / cust_refund.cgi
1 % if ( $link eq 'popup' ) { 
2   <% include('/elements/header-popup.html', $title ) %>
3 % } else { 
4   <% include("/elements/header.html", $title, '') %>
5 % } 
6
7 <% include('/elements/error.html') %>
8
9 % unless ( $link eq 'popup' ) { 
10     <% small_custview($custnum, $conf->config('countrydefault')) %>
11 % } 
12
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="">
22
23 <BR>
24
25 % if ( $cust_pay ) {
26 %
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$'/);
34 %  }
35
36   <BR>Payment
37   <TABLE class="fsinnerbox">
38
39     <TR>
40       <TD ALIGN="right">Amount</TD><TD BGCOLOR="#ffffff">$<% $cust_pay->paid %></TD>
41     </TR>
42
43   <TR>
44     <TD ALIGN="right">Date</TD><TD BGCOLOR="#ffffff"><% time2str($date_format, $cust_pay->_date) %></TD>
45   </TR>
46
47   <TR>
48     <TD ALIGN="right">Method</TD><TD BGCOLOR="#ffffff"><% $payby %> # <% $paymask %></TD>
49   </TR>
50
51 % unless ( $paydate || $cust_pay->payby ne 'CARD' ) {  # possibly other reasons: i.e. card has since expired
52   <TR>
53     <TD ALIGN="right">Expiration</TD><TD BGCOLOR="#ffffff">
54       <% include( '/elements/select-month_year.html',
55                   'prefix' => 'exp',
56                   'selected_date' => $paydate,
57                   'empty_option' => !$paydate,
58                 ) %>
59     </TD>
60   </TR>
61 % } 
62 % if ( $cust_pay->processor ) {
63     <TR>
64       <TD ALIGN="right">Processor</TD>
65       <TD BGCOLOR="#ffffff"><% $cust_pay->processor %></TD>
66     </TR>
67 % if ( length($cust_pay->auth) ) { 
68
69       <TR>
70         <TD ALIGN="right">Authorization</TD>
71         <TD BGCOLOR="#ffffff"><% $cust_pay->auth %></TD>
72       </TR>
73 % } 
74 % if ( length($cust_pay->order_number) ) { 
75
76       <TR>
77         <TD ALIGN="right">Order number</TD>
78         <TD BGCOLOR="#ffffff"><% $cust_pay->order_number %></TD>
79       </TR>
80 % } 
81 % } # if ($cust_pay->processor)
82
83   </TABLE>
84 % }  #if $cust_pay
85
86
87 <BR>Refund
88
89 <TABLE class="fsinnerbox">
90
91   <TR>
92     <TD ALIGN="right">Date</TD>
93     <TD BGCOLOR="#ffffff"><% time2str($date_format, $_date) %></TD>
94   </TR>
95
96   <TR>
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>
99   </TR>
100
101 % if ( $payby eq 'BILL' ) { 
102     <TR>
103       <TD ALIGN="right">Check #</TD>
104       <TD COLSPAN=2><INPUT TYPE="text" NAME="payinfo" VALUE="<% $payinfo %>" SIZE=10></TD>
105     </TR>
106     </TABLE>
107 % }
108 %  elsif ($payby eq 'CHEK') {
109 %
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();
116     } else {
117        //what.form.payinfo.value = '';
118        //what.form.payinfo.disabled = true;
119        $('#cust_payby').slideUp();
120     }
121   }
122 </SCRIPT>
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');
128 % } else {
129 %   die "unknown payby $payby";
130 % }
131 %
132 % my $custpaybynum = length(scalar($cgi->param('custpaybynum')))
133 %                      ? scalar($cgi->param('custpaybynum'))
134 %                      : scalar(@cust_payby) && $cust_payby[0]->custpaybynum;
135 <& /elements/tr-select-cust_payby.html,
136      'cust_payby' => \@cust_payby,
137      'curr_value' => $custpaybynum,
138      'onchange'   => 'cust_payby_changed(this)',
139 &>
140     <INPUT TYPE="hidden" NAME="batch" VALUE="1">
141     </TABLE>
142 <P>
143 <DIV ID="cust_payby"
144   <% $custpaybynum ? 'STYLE="display:none"'
145                    : ''
146   %>
147 >
148 <TABLE class="fsinnerbox">
149
150 <& /elements/cust_payby_new.html,
151      'cust_payby' => \@cust_payby,
152      'curr_value' => $custpaybynum,
153 &>
154
155 </TABLE>
156 </DIV>
157
158 %  } else {
159     <INPUT TYPE="hidden" NAME="payinfo" VALUE="">
160     </TABLE>
161 % }
162
163 <P>
164 <TABLE class="fsinnerbox">
165 <& /elements/tr-select-reason.html,
166               'field'          => 'reasonnum',
167               'reason_class'   => 'F',
168               'control_button' => "confirm_refund_button",
169               'cgi'            => $cgi,
170 &>
171
172 </TABLE>
173
174 <BR>
175 <INPUT TYPE="submit" NAME="submitButton" ID="confirm_refund_button" VALUE="<% mt('Post refund') |h %>" DISABLED>
176
177 </FORM>
178
179 % if ( $link eq 'popup' ) { 
180     </BODY>
181     </HTML>
182 % } else { 
183     <% include('/elements/footer.html') %>
184 % } 
185
186 <%init>
187
188 my $conf = new FS::Conf;
189 my $date_format = $conf->config('date_format') || '%m/%d/%Y';
190
191 my $custnum = $cgi->param('custnum');
192 my $refund  = $cgi->param('refund');
193 my $payby   = $cgi->param('payby');
194 my $payinfo = $cgi->param('payinfo');
195 my $reason  = $cgi->param('reason');
196 my $link    = $cgi->param('popup') ? 'popup' : '';
197
198 die "access denied"
199   unless $FS::CurrentUser::CurrentUser->refund_access_right($payby);
200
201 my( $paynum, $cust_pay ) = ( '', '' );
202 if ( $cgi->param('paynum') =~ /^(\d+)$/ ) {
203   $paynum = $1;
204   $cust_pay = qsearchs('cust_pay', { paynum=>$paynum } )
205     or die "unknown payment # $paynum";
206   $refund ||= $cust_pay->unrefunded;
207   if ( $custnum ) {
208     die "payment # $paynum is not for specified customer # $custnum"
209       unless $custnum == $cust_pay->custnum;
210   } else {
211     $custnum = $cust_pay->custnum;
212   }
213 }
214 die "no custnum or paynum specified!" unless $custnum;
215
216 my $cust_main = qsearchs( 'cust_main', { 'custnum'=>$custnum } );
217 die "unknown custnum $custnum" unless $cust_main;
218
219 my $_date = time;
220
221 my $p1 = popurl(1);
222
223 my $title = 'Refund '. FS::payby->payname($payby). ' payment';
224
225 </%init>