invoice_sections_with_taxes per-agent, RT#79636
[freeside.git] / httemplate / misc / payment.cgi
1 <& /elements/header-cust_main.html, view=>'payment_history', cust_main=>$cust_main &>
2
3 <h2><% emt("Process [_1] payment",$type{$payby}) %></h2>
4
5 <FORM NAME="OneTrueForm" ACTION="process/payment.cgi" METHOD="POST" onSubmit="document.OneTrueForm.process.disabled=true">
6 <INPUT TYPE="hidden" NAME="custnum"   VALUE="<% $custnum %>">
7 <INPUT TYPE="hidden" NAME="payby"     VALUE="<% $payby %>">
8 <INPUT TYPE="hidden" NAME="payunique" VALUE="<% $payunique %>">
9 <INPUT TYPE="hidden" NAME="balance"   VALUE="<% $balance %>">
10
11 <& /elements/init_overlib.html &>
12
13 <TABLE class="fsinnerbox">
14
15   <& /elements/tr-select-payment_options.html,
16        'custnum'            => $cust_main->custnum,
17        'amount'             => $balance,
18        'process-pkgpart'    => 
19           scalar($conf->config('manual_process-pkgpart', $cust_main->agentnum)),
20        'process-display'    => scalar($conf->config('manual_process-display')),
21        'process-skip_first' => $conf->exists('manual_process-skip_first'),
22        'num_payments'       => scalar($cust_main->cust_pay), 
23        'surcharge_percentage' =>
24          ( $payby eq 'CARD'
25              ? scalar($conf->config('credit-card-surcharge-percentage', $cust_main->agentnum))
26              : 0
27          ),
28   &>
29
30 % if ( $conf->exists('part_pkg-term_discounts') ) {
31     <& /elements/tr-select-discount_term.html,
32          'custnum'   => $custnum,
33          'amount_id' => 'amount',
34     &>
35 % }
36
37 % my $disallow_no_auto_apply = 0;
38 % if ( $conf->exists("batch-enable")
39 %      || grep $payby eq $_, $conf->config('batch-enable_payby')
40 %    ) {
41 %
42 %     if ( grep $payby eq $_, $conf->config('realtime-disable_payby') ) {
43 %       $disallow_no_auto_apply = 1;
44
45           <INPUT TYPE="hidden" NAME="batch" VALUE="1">
46
47 %     } else {
48
49           <TR>
50             <TH ALIGN="right">&nbsp;&nbsp;&nbsp;<% mt('Add to current batch') |h %></TH>
51             <TD>
52               <INPUT TYPE="checkbox" NAME="batch" VALUE="1" ID="batch_checkbox" ONCHANGE="change_batch_checkbox()">
53             </TD>
54           </TR>
55
56 %     }
57 % }
58
59 % unless ($disallow_no_auto_apply) {
60 %   # false laziness with edit/cust_pay.cgi
61
62 <TR ID="apply_box_row">
63   <TH ALIGN="right"><% mt('Auto-apply to invoices') |h %></TH>
64   <TD>
65     <SELECT NAME="apply" ID="apply_box">
66       <OPTION VALUE="yes" SELECTED><% mt('yes') |h %></OPTION> 
67       <OPTION VALUE=""><% mt('not now') |h %></OPTION>
68       <OPTION VALUE="never"><% mt('never') |h %></OPTION>
69     </SELECT>
70   </TD>
71 </TR>
72
73 % # this can go away if no_auto_apply handling gets added to batch payment processing
74 <SCRIPT>
75 function change_batch_checkbox () {
76   if (document.getElementById('batch_checkbox').checked) {
77     document.getElementById('apply_box').disabled = true;
78     document.getElementById('apply_box_row').style.display = 'none';
79   } else {
80     document.getElementById('apply_box').disabled = false;
81     document.getElementById('apply_box_row').style.display = '';
82   }
83 }
84 </SCRIPT>
85
86 % }
87
88 <SCRIPT TYPE="text/javascript">
89   function cust_payby_changed (what) {
90     var custpaybynum = what.options[what.selectedIndex].value
91     if ( custpaybynum == '' || custpaybynum == '0' ) {
92        //what.form.payinfo.disabled = false;
93        $('#cust_payby').slideDown();
94     } else {
95        //what.form.payinfo.value = '';
96        //what.form.payinfo.disabled = true;
97        $('#cust_payby').slideUp();
98     }
99   }
100 </SCRIPT>
101
102 % #can't quite handle CARD/CHEK on the same page yet, but very close
103 % #does it make sense from a UI/usability perspective?
104 %
105 % my @cust_payby = ();
106 % if ( $payby eq 'CARD' ) {
107 %   @cust_payby = $cust_main->cust_payby('CARD','DCRD');
108 % } elsif ( $payby eq 'CHEK' ) {
109 %   @cust_payby = $cust_main->cust_payby('CHEK','DCHK');
110 % } else {
111 %   die "unknown payby $payby";
112 % }
113 %
114 % my $custpaybynum = length(scalar($cgi->param('custpaybynum')))
115 %                      ? scalar($cgi->param('custpaybynum'))
116 %                      : scalar(@cust_payby) && $cust_payby[0]->custpaybynum;
117
118 <& /elements/tr-select-cust_payby.html,
119      'cust_payby' => \@cust_payby,
120      'curr_value' => $custpaybynum,
121      'onchange'   => 'cust_payby_changed(this)',
122 &>
123
124 </TABLE>
125 <BR>
126 <DIV ID="cust_payby"
127   <% $custpaybynum ? 'STYLE="display:none"'
128                    : ''
129   %>
130 >
131 <TABLE class="fsinnerbox">
132
133 % my $auto = 0;
134 % if ( $payby eq 'CARD' ) {
135 %
136 %   my( $payinfo, $paycvv, $month, $year ) = ( '', '', '', '' );
137 %   my $payname = $cust_main->first. ' '. $cust_main->getfield('last');
138 %   my $location = $cust_main->bill_location;
139
140     <TR>
141       <TH ALIGN="right"><% mt('Card number') |h %></TH>
142       <TD COLSPAN=7>
143         <TABLE>
144           <TR>
145             <TD>
146               <INPUT TYPE="text" NAME="payinfo" SIZE=20 MAXLENGTH=19 VALUE="<%$payinfo%>"> </TD>
147             <TH><% mt('Exp.') |h %></TH>
148             <TD>
149               <SELECT NAME="month">
150 % for ( ( map "0$_", 1 .. 9 ), 10 .. 12 ) { 
151
152                   <OPTION<% $_ == $month ? ' SELECTED' : '' %>><% $_ %>
153 % } 
154
155               </SELECT>
156             </TD>
157             <TD> / </TD>
158             <TD>
159               <SELECT NAME="year">
160 % my @a = localtime; for ( $a[5]+1900 .. $a[5]+1915 ) { 
161
162                   <OPTION<% $_ == $year ? ' SELECTED' : '' %>><% $_ %>
163 % } 
164
165               </SELECT>
166             </TD>
167           </TR>
168         </TABLE>
169       </TD>
170     </TR>
171     <TR>
172       <TH ALIGN="right"><% mt('CVV2') |h %></TH>
173       <TD><INPUT TYPE="text" NAME="paycvv" VALUE="<% $paycvv %>" SIZE=4 MAXLENGTH=4>
174           (<A HREF="javascript:void(0);" onClick="overlib( OLiframeContent('../docs/cvv2.html', 480, 352, 'cvv2_popup' ), CAPTION, 'CVV2 Help', STICKY, AUTOSTATUSCAP, CLOSECLICK, DRAGGABLE ); return false;"><% mt('help') |h %></A>)
175       </TD>
176     </TR>
177     <TR>
178       <TH ALIGN="right"><% mt('Exact name on card') |h %></TH>
179       <TD><INPUT TYPE="text" SIZE=32 MAXLENGTH=80 NAME="payname" VALUE="<%$payname%>"></TD>
180     </TR>
181
182     <& /elements/location.html,
183                   'object'         => $location,
184                   'no_asterisks'   => 1,
185                   'address1_label' => emt('Card billing address'),
186     &>
187
188 % } elsif ( $payby eq 'CHEK' ) {
189 %
190 %   my( $account, $aba, $branch, $payname, $ss, $paytype, $paystate,
191 %       $stateid, $stateid_state )
192 %     = ( '', '', '', '', '', '', '', '', '' );
193 %
194 %  #false laziness w/{edit,view}/cust_main/billing.html
195 %  my $routing_label = $conf->config('echeck-country') eq 'US'
196 %                        ? 'ABA/Routing number'
197 %                        : 'Routing number';
198 %  my $routing_size      = $conf->config('echeck-country') eq 'CA' ? 4 : 10;
199 %  my $routing_maxlength = $conf->config('echeck-country') eq 'CA' ? 3 : 9;
200
201     <INPUT TYPE="hidden" NAME="month" VALUE="12">
202     <INPUT TYPE="hidden" NAME="year" VALUE="2037">
203     <TR>
204       <TD ALIGN="right"><% mt('Account number') |h %></TD>
205       <TD><INPUT TYPE="text" SIZE=10 NAME="payinfo1" VALUE="<%$account%>"></TD>
206       <TD ALIGN="right"><% mt('Type') |h %></TD>
207       <TD><SELECT NAME="paytype"><% join('', map { qq!<OPTION VALUE="$_" !.($paytype eq $_ ? 'SELECTED' : '').">$_</OPTION>" } FS::cust_payby->paytypes) %></SELECT></TD>
208     </TR>
209     <TR>
210       <TD ALIGN="right"><% mt($routing_label) |h %></TD>
211       <TD>
212         <INPUT TYPE="text" SIZE="<% $routing_size %>" MAXLENGTH="<% $routing_maxlength %>" NAME="payinfo2" VALUE="<%$aba%>">
213         (<A HREF="javascript:void(0);" onClick="overlib( OLiframeContent('../docs/ach.html', 380, 240, 'ach_popup' ), CAPTION, 'ACH Help', STICKY, AUTOSTATUSCAP, CLOSECLICK, DRAGGABLE ); return false;"><% mt('help') |h %></A>)
214       </TD>
215     </TR>
216 %   if ( $conf->config('echeck-country') eq 'CA' ) {
217       <TR>
218         <TD ALIGN="right"><% mt('Branch number') |h %></TD>
219         <TD>
220           <INPUT TYPE="text" NAME="payinfo3" VALUE="<%$branch%>" SIZE=6 MAXLENGTH=5>
221         </TD>
222       </TR>
223 %   }
224     <TR>
225       <TD ALIGN="right"><% mt('Bank name') |h %></TD>
226       <TD><INPUT TYPE="text" NAME="payname" VALUE="<%$payname%>"></TD>
227     </TR>
228
229 %   if ( $conf->exists('show_bankstate') ) {
230       <TR>
231         <TD ALIGN="right"><% mt('Bank state') |h %></TD>
232         <TD><& /elements/select-state.html,
233                          'disable_empty' => 0,
234                          'empty_label'   => emt('(choose)'),
235                          'state'         => $paystate,
236                          'country'       => $cust_main->country,
237                          'prefix'        => 'pay',
238             &>
239         </TD>
240       </TR>
241 %   } else {
242       <INPUT TYPE="hidden" NAME="paystate" VALUE="<% $paystate %>">
243 %   }
244
245 %   if ( $conf->exists('show_ss') ) {
246       <TR>
247         <TD ALIGN="right">
248           <% mt('Account holder') |h %><BR>
249           <% mt('Social security or tax ID #') |h %> 
250         </TD>
251         <TD><INPUT TYPE="text" NAME="ss" VALUE="<% $ss %>"></TD>
252       </TR>
253 %   } else {
254       <INPUT TYPE="hidden" NAME="ss" VALUE="<% $ss %>"></TD>
255 %   }
256
257 %   if ( $conf->exists('show_stateid') ) {
258       <TR>
259         <TD ALIGN="right">
260           <% mt('Account holder') |h %><BR>
261           <% mt("Driver's license or state ID #") |h %> 
262         </TD>
263         <TD><INPUT TYPE="text" NAME="stateid" VALUE="<% $stateid %>"></TD>
264         <TD ALIGN="right"><% mt('State') |h %></TD>
265         <TD><& /elements/select-state.html,
266                          'disable_empty' => 0,
267                          'empty_label'   => emt('(choose)'),
268                          'state'         => $stateid_state,
269                          'country'       => $cust_main->country,
270                          'prefix'        => 'stateid_',
271             &>
272         </TD>
273       </TR>
274 %   } else {
275       <INPUT TYPE="hidden" NAME="stateid" VALUE="<% $stateid %>">
276       <INPUT TYPE="hidden" NAME="stateid_state" VALUE="<% $stateid_state %>">
277 %   }
278
279 % } #end CARD/CHEK-specific section
280
281
282 <TR>
283   <TD COLSPAN=8>
284     <INPUT TYPE="checkbox" CHECKED NAME="save" VALUE="1">
285     <% mt('Remember this information') |h %>
286   </TD>
287 </TR>
288
289 <TR>
290   <TD COLSPAN=8>
291     <INPUT TYPE="checkbox"<% $auto ? ' CHECKED' : '' %> NAME="auto" VALUE="1" onClick="if (this.checked) { document.OneTrueForm.save.checked=true; }">
292     <% mt("Charge future payments to this [_1] automatically",$type{$payby}) |h %> 
293 % if ( @cust_payby ) {
294     <% mt('as') |h %>
295     <SELECT NAME="weight">
296 %     for ( 1 .. 1+scalar(grep { $_->payby =~ /^(CARD|CHEK)$/ } @cust_payby) ) {
297         <OPTION VALUE="<%$_%>"><% mt( $weight{$_} ) |h %>
298 %     }
299     </SELECT>
300 % } else {
301     <INPUT TYPE="hidden" NAME="weight" VALUE="1">
302 % }
303   </TD>
304 </TR>
305
306 </TABLE>
307 </DIV>
308
309 <BR>
310 <INPUT TYPE="submit" NAME="process" VALUE="<% mt('Process payment') |h %>">
311 </FORM>
312
313 <& /elements/footer-cust_main.html &>
314 <%once>
315
316 my %weight = (
317   1 => 'Primary',
318   2 => 'Secondary',
319   3 => 'Tertiary',
320   4 => 'Fourth',
321   5 => 'Fifth',
322   6 => 'Sixth',
323   7 => 'Seventh',
324 );
325
326 </%once>
327 <%init>
328
329 die "access denied"
330   unless $FS::CurrentUser::CurrentUser->access_right('Process payment');
331
332 my %type = ( 'CARD' => 'credit card',
333              'CHEK' => 'electronic check (ACH)',
334            );
335
336 $cgi->param('payby') =~ /^(CARD|CHEK)$/
337   or die "unknown payby ". $cgi->param('payby');
338 my $payby = $1;
339
340 $cgi->param('custnum') =~ /^(\d+)$/
341   or die "illegal custnum ". $cgi->param('custnum');
342 my $custnum = $1;
343
344 my $cust_main = qsearchs( 'cust_main', { 'custnum'=>$custnum } );
345 die "unknown custnum $custnum" unless $cust_main;
346
347 my $balance = $cust_main->balance;
348
349 my $payinfo = '';
350
351 my $conf = new FS::Conf;
352
353 #false laziness w/selfservice make_payment.html shortcut for one-country
354 my %states = map { $_->state => 1 }
355                qsearch('cust_main_county', {
356                  'country' => $conf->config('countrydefault') || 'US'
357                } );
358 my @states = sort { $a cmp $b } keys %states;
359
360 my $payunique = "webui-payment-". time. "-$$-". rand() * 2**32;
361
362 </%init>