Merge branch 'master' of git.freeside.biz:/home/git/freeside
[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' || $payby eq 'CARD') {
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
136 % if ($cust_pay) {
137   <INPUT TYPE="hidden" NAME="payinfo" VALUE="<% $payinfo %>" SIZE=10>
138 % }
139 % else {
140   <& /elements/tr-select-cust_payby.html,
141      'cust_payby' => \@cust_payby,
142      'curr_value' => $custpaybynum,
143      'onchange'   => 'cust_payby_changed(this)',
144   &>
145 % }
146
147 % if ( $conf->exists("batch-enable")
148 %      || grep $payby eq $_, $conf->config('batch-enable_payby')
149 % ) {
150 %     if ( grep $payby eq $_, $conf->config('realtime-disable_payby') ) {
151           <INPUT TYPE="hidden" NAME="batch" VALUE="1">
152 %     } else {
153         <TR>
154           <TD ALIGN="right"><INPUT TYPE="checkbox" NAME="batch" VALUE="1" ID="batch" <% ($batchnum || $batch) ? 'checked' : '' %> ></TD>
155           <TH ALIGN="left">&nbsp;&nbsp;&nbsp;<% mt('Add to current batch') |h %></TH>
156         </TR>
157 %     }
158 % }
159
160     </TABLE>
161 <P>
162
163 %   if ( !$cust_pay ) {
164 <DIV ID="cust_payby"
165   <% $custpaybynum ? 'STYLE="display:none"'
166                    : ''
167   %>
168 >
169 <TABLE class="fsinnerbox">
170
171     <& /elements/cust_payby_new.html,
172         'cust_payby' => \@cust_payby,
173         'curr_value' => $custpaybynum,
174     &>
175
176 </TABLE>
177 </DIV>
178 %   } # end if cust_pay
179
180 %  } else {
181     <INPUT TYPE="hidden" NAME="payinfo" VALUE="">
182     </TABLE>
183 % }
184
185 <P>
186 <TABLE class="fsinnerbox">
187 <& /elements/tr-select-reason.html,
188               'field'          => 'reasonnum',
189               'reason_class'   => 'F',
190               'control_button' => "confirm_refund_button",
191               'cgi'            => $cgi,
192 &>
193
194 </TABLE>
195
196 <BR>
197 <INPUT TYPE="submit" NAME="submitButton" ID="confirm_refund_button" VALUE="<% mt('Post refund') |h %>" DISABLED>
198
199 </FORM>
200
201 % if ( $link eq 'popup' ) { 
202     </BODY>
203     </HTML>
204 % } else { 
205     <% include('/elements/footer.html') %>
206 % } 
207
208 <%init>
209
210 my $conf = new FS::Conf;
211 my $date_format = $conf->config('date_format') || '%m/%d/%Y';
212
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');
220
221 die "access denied"
222   unless $FS::CurrentUser::CurrentUser->refund_access_right($payby);
223
224 my( $paynum, $cust_pay, $batchnum ) = ( '', '', '' );
225 if ( $cgi->param('paynum') =~ /^(\d+)$/ ) {
226   $paynum = $1;
227   $cust_pay = qsearchs('cust_pay', { paynum=>$paynum } )
228     or die "unknown payment # $paynum";
229   $refund ||= $cust_pay->unrefunded;
230   $batchnum = $cust_pay->batchnum;
231   if ( $custnum ) {
232     die "payment # $paynum is not for specified customer # $custnum"
233       unless $custnum == $cust_pay->custnum;
234   } else {
235     $custnum = $cust_pay->custnum;
236   }
237 }
238 die "no custnum or paynum specified!" unless $custnum;
239
240 my $cust_main = qsearchs( 'cust_main', { 'custnum'=>$custnum } );
241 die "unknown custnum $custnum" unless $cust_main;
242
243 my $_date = time;
244
245 my $p1 = popurl(1);
246
247 my $title = 'Refund '. FS::payby->payname($payby). ' payment';
248
249 </%init>