Merge branch 'patch-18' of https://github.com/gjones2/Freeside
[freeside.git] / httemplate / edit / cust_main / billing.html
1 %if ( $payby_default eq 'HIDE' ) {
2 %  $cust_main->payby('BILL') unless $cust_main->payby;
3 %  my $payby = $cust_main->payby;
4
5   <INPUT TYPE="hidden" NAME="payby" VALUE="<% $payby %>">
6
7   <INPUT TYPE="hidden" NAME="<%$payby%>_payinfo" VALUE="<% $cust_main->paymask %>">
8
9 % foreach my $field (qw( payname paycvv paystart_month paystart_year payissue payip paytype paystate billday )) { 
10
11     <INPUT TYPE="hidden" NAME="<% $payby.'_'.$field %>" VALUE="<% $cust_main->get($field) %>">
12
13 % } 
14
15 %  #false laziness w/elements/select-month_year.html & view/cust_main/billing.html
16 %  my( $mon, $year );
17 %  my $date = $cust_main->paydate || '12-2037';
18 %  if ( $date  =~ /^(\d{4})-(\d{1,2})-\d{1,2}$/ ) { #PostgreSQL date format
19 %    ( $mon, $year ) = ( $2, $1 );
20 %  } elsif ( $date =~ /^(\d{1,2})-(\d{1,2}-)?(\d{4}$)/ ) {
21 %    ( $mon, $year ) = ( $1, $3 );
22 %  } else {
23 %    die "unrecognized expiration date format: $date";
24 %  }
25
26   <INPUT TYPE="hidden" NAME="<%$payby%>_exp_month" VALUE="<% $mon %>">
27   <INPUT TYPE="hidden" NAME="<%$payby%>_exp_year"  VALUE="<% $year %>">
28
29   <INPUT TYPE="hidden" NAME="tax" VALUE="<% $cust_main->tax %>">
30
31   <INPUT TYPE="hidden" NAME="invoicing_list" VALUE="<% join(', ', @invoicing_list) %>">
32
33 % } else {
34 %
35 %  my $r = qq!<font color="#ff0000">*</font>&nbsp;!;
36
37   <BR><FONT CLASS="fsinnerbox-title"><% mt('Billing information') |h %></FONT>
38   <% &ntable("#cccccc") %>
39
40     <TR>
41       <TD ALIGN="right" WIDTH="200"><%$r%><% mt('Billing type') |h %></TD>
42
43   <SCRIPT>
44
45     var mywindow = -1;
46     function myopen(filename,windowname,properties) {
47       myclose();
48       mywindow = window.open(filename,windowname,properties);
49     }
50     function myclose() {
51       if ( mywindow != -1 )
52         mywindow.close();
53       mywindow = -1;
54     }
55
56     var achwindow = -1;
57     function achopen(filename,windowname,properties) {
58       achclose();
59       achwindow = window.open(filename,windowname,properties);
60     }
61     function achclose() {
62       if ( achwindow != -1 )
63         achwindow.close();
64       achwindow = -1;
65     }
66
67     function card_changed(what) {
68       if (
69              what.form.payinfo.value.substring(0, 4) == '4093' 
70           || what.form.payinfo.value.substring(0, 4) == '4911' 
71           || what.form.payinfo.value.substring(0, 4) == '4936' 
72           || what.form.payinfo.value.substring(0, 6) == '564132' 
73           || what.form.payinfo.value.substring(0, 2) == '63' 
74           || what.form.payinfo.value.substring(0, 2) == '67' 
75          )
76       {
77         what.form.paystart_month.disabled = false;
78         what.form.paystart_year.disabled = false;
79         what.form.payissue.disabled = false;
80         what.form.paystart_month.style.backgroundColor = '#ffffff';
81         what.form.paystart_year.style.backgroundColor = '#ffffff';
82         what.form.payissue.style.backgroundColor = '#ffffff';
83         document.getElementById('paystart_label').style.color = '#000000';
84         document.getElementById('payissue_label').style.color = '#000000';
85       } else {
86         what.form.paystart_month.disabled = true;
87         what.form.paystart_year.disabled = true;
88         what.form.payissue.disabled = true;
89         what.form.paystart_month.style.backgroundColor = '#dddddd';
90         what.form.paystart_year.style.backgroundColor = '#dddddd';
91         what.form.payissue.style.backgroundColor = '#dddddd';
92         document.getElementById('paystart_label').style.color = '#999999';
93         document.getElementById('payissue_label').style.color = '#999999';
94       }
95       return true;
96     }
97
98     function init_payauto_changed(){
99         var f = document.getElementById('CARD_payauto');
100         if(f != null) payauto_changed(f);
101         f = document.getElementById('CHEK_payauto');
102         if(f != null) payauto_changed(f);
103     }
104
105     function payauto_changed(payauto_field){
106         var select = (payauto_field.name == 'CARD_payauto') ? 'CARD_billday' : 'CHEK_billday';
107         var span = document.getElementById('td_'+select);
108         select = document.getElementById(select);
109         if (span == null || select == null) return;
110         if(payauto_field.checked) {
111             span.style.color = '#000000';
112             select.disabled = false;
113         }
114         else {
115             span.style.color = '#999999';
116             select.disabled = true;
117             //why? select.selectedIndex = 0;
118         }
119     }
120
121     function tax_changed(what) {
122       var num = document.getElementById(what.id + '_num'); 
123       if ( what.checked ) {
124         num.disabled = false;
125       } else {
126         num.disabled = true;
127       }
128     }
129     
130   </SCRIPT>
131
132   <& /elements/init_overlib.html &>
133
134 %  my $payby = $cust_main->payby;
135 %  my $paytype = $cust_main->paytype;
136 %  my( $account, $aba ) = split('@', $payinfo);
137 %  my $branch = '';
138 %  ($branch,$aba) = split('\.',$aba)
139 %    if $conf->config('echeck-country') eq 'CA';
140 %
141 %  my $disabled = 'DISABLED style="background-color: #dddddd"';
142 %  my $text_disabled = 'style="color: #999999"';
143 %
144 %  if ( $payby =~ /^(CARD|DCRD)$/ && cardtype($payinfo) =~ /^(Switch|Solo)$/ ) {
145 %    $disabled = 'style="background-color: #ffffff"';
146 %    $text_disabled = 'style="color: #000000";'
147 %  }
148 %
149 %  my $disable_payauto = $conf->exists('disable_payauto_default');
150 %  my $CARD_payauto_checked =   $payby eq 'DCRD' ? ''
151 %                             : $payby eq 'CARD' ? 'CHECKED'
152 %                             : $disable_payauto ? '' : 'CHECKED';
153 %  my $CHEK_payauto_checked =   $payby eq 'DCHK' ? ''
154 %                             : $payby eq 'CHEK' ? 'CHECKED'
155 %                             : $disable_payauto ? '' : 'CHECKED';
156 %
157 %  sub billday_options {
158 %   my $curr_value = shift;
159 %   my $ret = '';
160 %   for my $billday ( 1 .. 28 ) {
161 %       my $sel = '';
162 %       $sel = "SELECTED='SELECTED'" if $curr_value == $billday;
163 %       $ret .= "<OPTION VALUE='$billday' $sel>$billday</OPTION>";
164 %   }
165 %   $ret;
166 %  }
167 %
168 %  my $card_billday_style = $payby eq 'CARD' ? '' : 'style="color: #999999"';
169 %  my $chek_billday_style = $payby eq 'CHEK' ? '' : 'style="color: #999999"';
170 %  my $card_billday_select_disabled = $payby eq 'CARD' ? '' : 'DISABLED';
171 %  my $chek_billday_select_disabled = $payby eq 'CHEK' ? '' : 'DISABLED';
172 %
173 %  #false laziness w/view/cust_main/billing.html and misc/payment.cgi
174 %  my $routing_label = $conf->config('echeck-country') eq 'US'
175 %                        ? 'ABA/Routing number'
176 %                        : 'Routing number';
177 %  my $routing_size      = $conf->config('echeck-country') eq 'CA' ? 4 : 10;
178 %  my $routing_maxlength = $conf->config('echeck-country') eq 'CA' ? 3 : 9;
179 %
180 %
181 %  my %payby = (
182 %
183 %    'CARD' =>
184 %
185 %      '<TABLE BGCOLOR="#cccccc" BORDER=0 CELLSPACING=0 HEIGHT=192>'.
186 %
187 %        qq!<TR><TD ALIGN="right" WIDTH="200">${r}!.emt('Card number').qq! </TD>!.
188 %          qq!<TD WIDTH="408"><INPUT TYPE="text" NAME="CARD_payinfo" VALUE="!. ( $payby =~ /^(CARD|DCRD)$/ ? $payinfo : '' ). qq!" MAXLENGTH=19 onChange="card_changed(this)" onKeyUp="card_changed(this)"></TD></TR>!.
189 %
190 %        qq!<TR><TD ALIGN="right" WIDTH="200">${r}!.emt('Expiration').qq! </TD>!.
191 %          '<TD WIDTH="408">'.
192 %
193 %          include('/elements/select-month_year.html',
194 %                    'prefix' => 'CARD_exp',
195 %                    'selected_date' =>
196 %                      ( $payby =~ /^(CARD|DCRD)$/ ? $cust_main->paydate : '' ),
197 %                 ).
198 %
199 %          '</TD></TR>'.
200 %
201 %        qq!<TR><TD ALIGN="right" WIDTH="200">!.emt('CVV2').qq!&nbsp;!.
202 %
203 %          qq!(<A HREF="javascript:void(0);" onClick="overlib( OLiframeContent('../docs/cvv2.html', 480, 352, 'cvv2_popup' ), CAPTION, 'CVV2 Help', STICKY, AUTOSTATUSCAP, CLOSECLICK, DRAGGABLE ); return false;">!.emt('help').qq!</A>)!.
204 %          qq!</TD>!.
205 %          '<TD WIDTH="408"><INPUT TYPE="text" NAME="CARD_paycvv" VALUE="'. ( $payby =~ /^(CARD|DCRD)$/ && !$cust_main->is_encrypted($cust_main->paycvv) ? $cust_main->paycvv : '' ). '" SIZE=4 MAXLENGTH=4>'.
206 %
207 %        qq!<TR><TD ALIGN="right" WIDTH="200"><SPAN ID="paystart_label" $text_disabled>!.emt('Start date').qq! </SPAN></TD>!.
208 %          '<TD WIDTH="408">'.
209 %
210 %          include('/elements/select-month_year.html',
211 %                    'prefix' => 'CARD_paystart',
212 %                    'disabled' => $disabled,
213 %                    'empty_option' => 1,
214 %                    'start_year' => 2000,
215 %                    'end_year'   => (localtime())[5] + 1900,
216 %                    'selected_date' => (
217 %                      ( $payby =~ /^(CARD|DCRD)$/
218 %                        && cardtype($payinfo) =~ /^(Switch|Solo)$/ )
219 %                          ? $cust_main->paystart_month. '-'.
220 %                            $cust_main->paystart_year 
221 %                          : ''
222 %                    )
223 %                 ).
224 %
225 %        qq!<SPAN ID="payissue_label" $text_disabled>!.emt('or Issue number').qq! </SPAN>!.
226 %          '<INPUT TYPE="text" NAME="CARD_payissue" VALUE="'. ( $payby =~ /^(CARD|DCRD)$/ ? $cust_main->payissue : '' ). qq!" SIZE=3 MAXLENGTH=2 $disabled></TD></TR>!.
227 %
228 %        qq!<TR><TD ALIGN="right" WIDTH="200">${r}!.emt('Exact name on card').qq! </TD>!.
229 %          qq!<TD WIDTH="408"><INPUT TYPE="text" NAME="CARD_payname" VALUE="!. ( $payby =~ /^(CARD|DCRD)$/ ? $cust_main->payname : '' ). qq!"></TD></TR>!.
230 %
231 %        qq!<TR><TD COLSPAN=2 WIDTH="608">!.
232 %           qq!<INPUT TYPE="checkbox" onchange="payauto_changed(this);" ID="CARD_payauto" NAME="CARD_payauto" $CARD_payauto_checked> !.
233 %           emt('Charge future payments to this [_1] automatically','credit card').'</TD></TR>'.
234 %
235 %      ( $conf->exists('cust_main-select-billday') ?
236 %        qq!<TR><TD ALIGN="RIGHT" id="td_CARD_billday" $card_billday_style>
237 %                    Charge on this day of each month</TD><TD> &nbsp; 
238 %                   <SELECT id="CARD_billday" $card_billday_select_disabled NAME="CARD_billday">!
239 %                . billday_options($cust_main->billday) . qq!</SELECT> </TD></TR>!
240 %        : ''
241 %      ).
242 %
243 %      '</TABLE>',
244 %
245 %    'CHEK' => 
246 %
247 %      '<TABLE BGCOLOR="#cccccc" BORDER=0 CELLSPACING=0 HEIGHT=192>'.
248 %
249 %        qq!<TR><TD ALIGN="right" WIDTH="200">${r}!.emt('Account number').qq! </TD>!.
250 %          qq!<TD><INPUT TYPE="text" SIZE=12 NAME="CHEK_payinfo1" VALUE="!. ( $payby =~ /^(CHEK|DCHK)$/ ? $account : '' ). '"></TD>'.
251 %          qq!<TD ALIGN="right">!.emt('Type').qq!</TD><TD><SELECT NAME="CHEK_paytype">!.
252 %            join('', map { qq!<OPTION VALUE="$_" !.($paytype eq $_ ? 'SELECTED' : '').">$_</OPTION>" } @FS::cust_main::paytypes).
253 %          qq!</SELECT></TD></TR>!.
254 %
255 %        qq!<TR><TD ALIGN="right" WIDTH="200">${r}!.emt($routing_label).qq! </TD>!.
256 %          qq!<TD COLSPAN="3" WIDTH="408"><INPUT TYPE="text" SIZE=$routing_size MAXLENGTH=$routing_maxlength NAME="CHEK_payinfo2" VALUE="!. ( $payby =~ /^(CHEK|DCHK)$/ ? $aba : '' ). qq!"> !.
257 %          qq!(<A HREF="javascript:void(0);" onClick="overlib( OLiframeContent('../docs/ach.html', 380, 240, 'ach_popup' ), CAPTION, 'ACH Help', STICKY, AUTOSTATUSCAP, CLOSECLICK, DRAGGABLE ); return false;">!.emt('help').qq!</A>)!.
258 %          qq!</TD></TR>!.
259 %
260 %        qq!<INPUT TYPE="hidden" NAME="CHEK_exp_month" VALUE="12">!.
261 %        qq!<INPUT TYPE="hidden" NAME="CHEK_exp_year" VALUE="2037">!.
262 %
263 %        ( $conf->config('echeck-country') eq 'CA' ? 
264 %               qq!<TR><TD ALIGN="right">$r !.emt('Branch number').qq!</TD><TD COLSPAN="3">
265 %                   <INPUT TYPE="text" name="CHEK_payinfo3" VALUE="$branch" SIZE=6 MAXLENGTH=5></TD></TR>! : '' ).
266 %   
267 %        qq!<TR><TD ALIGN="right" WIDTH="200">${r}!.emt('Bank name').qq! </TD>!.
268 %          qq!<TD COLSPAN="3" WIDTH="408"><INPUT TYPE="text" NAME="CHEK_payname" VALUE="!. ( $payby =~ /^(CHEK|DCHK)$/ ? $cust_main->payname : '' ). qq!"></TD></TR>!.
269 %      ( $conf->exists('show_bankstate') ?
270 %          qq!<TR><TD ALIGN="right" WIDTH="200">$paystate_label</TD>!.
271 %          qq!<TD COLSPAN="3" WIDTH="408">!.
272 %          include('/elements/select-state.html',
273 %                    'empty'   => emt('(choose)'),
274 %                    'state'   => $cust_main->paystate,
275 %                    'country' => $cust_main->country,
276 %                    'prefix'  => 'CHEK_pay',
277 %                 ). "</TD></TR>"
278 %         : '<INPUT TYPE="hidden" NAME="CHEK_paystate" VALUE="'.
279 %            $cust_main->paystate. '">'
280 %       ).
281 %
282 %
283 %        qq!<TR><TD COLSPAN=4 WIDTH="608">!.
284 %           qq!<INPUT TYPE="checkbox" onchange="payauto_changed(this);" ID="CHEK_payauto" NAME="CHEK_payauto" $CHEK_payauto_checked> !.
285 %           emt('Charge future payments to this [_1] automatically','electronic check').'</TD></TR>'.
286 %
287 %      ( $conf->exists('cust_main-select-billday') ?
288 %        qq!<TR><TD ALIGN="RIGHT" id="td_CHEK_billday" $chek_billday_style>
289 %                    Charge on this day of each month</TD><TD> &nbsp;
290 %                   <SELECT id="CHEK_billday" $chek_billday_select_disabled NAME="CHEK_billday">!
291 %                . billday_options($cust_main->billday) . qq!</SELECT> </TD></TR>!
292 %        : ''
293 %      ).
294 %
295 %      '</TABLE>',
296 %
297 %    'LECB' =>  
298 %
299 %      '<TABLE BGCOLOR="#cccccc" BORDER=0 CELLSPACING=0 HEIGHT=192>'.
300 %
301 %        qq!<TR><TD ALIGN="right" WIDTH="200">${r}!.emt('Phone number').qq! </TD>!.
302 %          qq!<TD WIDTH="408"><INPUT TYPE="text" NAME="LECB_payinfo" VALUE="!. ( $payby eq 'LECB' ? $cust_main->payinfo : '' ). qq!" MAXLENGTH=15 SIZE=16></TD></TR>!.
303 %
304 %        qq!<INPUT TYPE="hidden" NAME="LECB_exp_month" VALUE="12">!.
305 %        qq!<INPUT TYPE="hidden" NAME="LECB_exp_year" VALUE="2037">!.
306 %        qq!<INPUT TYPE="hidden" NAME="LECB_payname" VALUE="">!.
307 %
308 %        '<TR><TD>&nbsp;</TD></TR>'.
309 %        '<TR><TD>&nbsp;</TD></TR>'.
310 %        '<TR><TD>&nbsp;</TD></TR>'.
311 %        '<TR><TD>&nbsp;</TD></TR>'.
312 %        '<TR><TD>&nbsp;</TD></TR>'.
313 %        '<TR><TD>&nbsp;</TD></TR>'.
314 %
315 %      '</TABLE>',
316 %
317 %    'BILL' =>  
318 %
319 %      '<TABLE BGCOLOR="#cccccc" BORDER=0 CELLSPACING=0 HEIGHT=192>'.
320 %
321 %        qq!<TR><TD ALIGN="right" WIDTH="200">!.emt('P.O.').qq! </TD>!.
322 %          qq!<TD WIDTH="408"><INPUT TYPE="text" NAME="BILL_payinfo" VALUE="!. ( $payby eq 'BILL' ? $cust_main->payinfo : '' ). qq!"></TD></TR>!.
323 %
324 %        qq!<INPUT TYPE="hidden" NAME="BILL_exp_month" VALUE="12">!.
325 %        qq!<INPUT TYPE="hidden" NAME="BILL_exp_year" VALUE="2037">!.
326 %
327 %        qq!<TR><TD ALIGN="right" WIDTH="200">!.emt('Attention').qq! </TD>!.
328 %          qq!<TD WIDTH="408"><INPUT TYPE="text" NAME="BILL_payname" VALUE="!. encode_entities( $payby eq 'BILL' ? $cust_main->payname : '' ). qq!"></TD></TR>!.
329 %
330 %        '<TR><TD>&nbsp;</TD></TR>'.
331 %        '<TR><TD>&nbsp;</TD></TR>'.
332 %        '<TR><TD>&nbsp;</TD></TR>'.
333 %        '<TR><TD>&nbsp;</TD></TR>'.
334 %        '<TR><TD>&nbsp;</TD></TR>'.
335 %
336 %      '</TABLE>',
337 %
338 %    'COMP' =>   
339 %
340 %      '<TABLE BGCOLOR="#cccccc" BORDER=0 CELLSPACING=0 HEIGHT=192>'.
341 %
342 %        qq!<TR><TD ALIGN="right" WIDTH="200">${r}!.emt('Approved by').qq! </TD>!.
343 %          qq!<TD WIDTH="408"><INPUT TYPE="text" NAME="COMP_payinfo" VALUE=""></TD></TR>!.
344 %
345 %        qq!<TR><TD ALIGN="right" WIDTH="200">${r}!.emt('Expiration').qq! </TD>!.
346 %          '<TD WIDTH="408">'.
347 %
348 %          include('/elements/select-month_year.html',
349 %                    'prefix' => 'COMP_exp',
350 %                    'selected_date' =>
351 %                      ( $payby eq 'COMP' ? $cust_main->paydate : '' ),
352 %                 ).
353 %
354 %          '</TD></TR>'.
355 %
356 %        '<TR><TD>&nbsp;</TD></TR>'.
357 %        '<TR><TD>&nbsp;</TD></TR>'.
358 %        '<TR><TD>&nbsp;</TD></TR>'.
359 %        '<TR><TD>&nbsp;</TD></TR>'.
360 %        '<TR><TD>&nbsp;</TD></TR>'.
361 %
362 %      '</TABLE>',
363 %
364 %    'CASH' =>
365 %
366 %      '<TABLE BGCOLOR="#cccccc" BORDER=0 CELLSPACING=0 HEIGHT=192>'.
367 %
368 %        qq!<TR><TD ALIGN="right" WIDTH="200">${r}!.emt('Amount').qq! </TD>!.
369 %          qq!<TD WIDTH="408"><INPUT TYPE="text" NAME="CASH_paid" VALUE="!. ( $payby eq 'CASH' ? $cust_main->paid : '' ). qq!"></TD></TR>!.
370 %
371 %        '<TR><TD>&nbsp;</TD></TR>'.
372 %        '<TR><TD>&nbsp;</TD></TR>'.
373 %        '<TR><TD>&nbsp;</TD></TR>'.
374 %        '<TR><TD>&nbsp;</TD></TR>'.
375 %        '<TR><TD>&nbsp;</TD></TR>'.
376 %        '<TR><TD>&nbsp;</TD></TR>'.
377 %
378 %      '</TABLE>',
379 %
380 %    'WEST' =>
381 %
382 %      '<TABLE BGCOLOR="#cccccc" BORDER=0 CELLSPACING=0 HEIGHT=192>'.
383 %
384 %        qq!<TR><TD ALIGN="right" WIDTH="200">${r}!.emt('Amount').qq! </TD>!.
385 %          qq!<TD WIDTH="408"><INPUT TYPE="text" NAME="WEST_paid" VALUE="!. ( $payby eq 'WEST' ? $cust_main->paid : '' ). qq!"></TD></TR>!.
386 %
387 %        '<TR><TD>&nbsp;</TD></TR>'.
388 %        '<TR><TD>&nbsp;</TD></TR>'.
389 %        '<TR><TD>&nbsp;</TD></TR>'.
390 %        '<TR><TD>&nbsp;</TD></TR>'.
391 %        '<TR><TD>&nbsp;</TD></TR>'.
392 %        '<TR><TD>&nbsp;</TD></TR>'.
393 %
394 %      '</TABLE>',
395 %
396 %    'MCRD' =>
397 %
398 %      '<TABLE BGCOLOR="#cccccc" BORDER=0 CELLSPACING=0 HEIGHT=192>'.
399 %
400 %        qq!<TR><TD ALIGN="right" WIDTH="200">${r}!.emt('Amount').qq! </TD>!.
401 %          qq!<TD WIDTH="408"><INPUT TYPE="text" NAME="MCRD_paid" VALUE="!. ( $payby eq 'MCRD' ? $cust_main->paid : '' ). qq!"></TD></TR>!.
402 %
403 %        '<TR><TD>&nbsp;</TD></TR>'.
404 %        '<TR><TD>&nbsp;</TD></TR>'.
405 %        '<TR><TD>&nbsp;</TD></TR>'.
406 %        '<TR><TD>&nbsp;</TD></TR>'.
407 %        '<TR><TD>&nbsp;</TD></TR>'.
408 %        '<TR><TD>&nbsp;</TD></TR>'.
409 %
410 %      '</TABLE>',
411 %
412 %  );
413 %
414 %  #this should use FS::payby
415 %  my @allopt = qw( CARD CHEK LECB BILL CASH WEST MCRD COMP );
416 %
417 %  my %allopt = map { $_ => FS::payby->shortname($_) } @allopt;
418 %
419 %  if ( $cust_main->custnum ) {
420 %    #don't offer CASH/WEST/MCRD initial payment types when editing customer
421 %    delete $allopt{$_} for qw(CASH WEST MCRD);
422 %  }
423 %  
424 %  my @options = grep exists( $allopt{$_} ), @payby;
425 %
426 %  my %payby2option = (
427 %    ( map { $_ => $_ } @options ),
428 %    'DCRD' => 'CARD',
429 %    'DCHK' => 'CHEK',
430 %  );
431
432   <TD WIDTH="408">
433     <& /elements/selectlayers.html,
434                   'field'      => 'payby',
435                   'curr_value' => $payby2option{$payby || $payby_default || $payby[0] },
436                   'options'    => \@options,
437                   'labels'     => \%allopt,
438                   'html_between' => '</TD></TR></TABLE>',
439                   'layer_callback' => sub { my $layer = shift; $payby{$layer}; },
440                   'onchange'    => 'init_payauto_changed();',
441     &>
442
443   <% &ntable("#cccccc") %>
444
445     <TR><TD>&nbsp;</TD></TR>
446
447 %   my $curuser = $FS::CurrentUser::CurrentUser;
448 %   my @exempt_groups = grep /\S/, $conf->config('tax-cust_exempt-groups');
449 %   if (    $conf->exists('cust_class-tax_exempt')
450 %        || $conf->exists('tax-cust_exempt-groups-require_individual_nums')
451 %        || ! $curuser->access_right('Edit customer tax exemptions')
452 %      )
453 %   {
454
455       <INPUT TYPE="hidden" NAME="tax" VALUE="<% $cust_main->tax eq 'Y' ? 'Y' : '' %>">
456
457 %   } else {
458
459       <TR>
460         <TD WIDTH="608" COLSPAN="2"><INPUT TYPE="checkbox" NAME="tax" VALUE="Y" <% $cust_main->tax eq "Y" ? 'CHECKED' : '' %>> Tax Exempt<% @exempt_groups ? ' (all taxes)' : '' %></TD>
461       </TR>
462
463 %   }
464
465 %   if ( $curuser->access_right('Edit customer tax exemptions') ) {
466 %     foreach my $exempt_group ( @exempt_groups ) {
467 %       my $cust_main_exemption = $cust_main->tax_exemption($exempt_group);
468 %       #escape $exempt_group for NAME etc.
469 %       my $checked = ($cust_main_exemption || $cgi->param("tax_$exempt_group"));
470         <TR>
471           <TD>&nbsp;&nbsp;<INPUT TYPE="checkbox" NAME="tax_<% $exempt_group %>" ID="tax_<% $exempt_group %>" VALUE="Y" <% $checked ? 'CHECKED' : '' %> onChange="tax_changed(this)"> Tax Exempt (<% $exempt_group %> taxes)</TD>
472           <TD> - Exemption number <INPUT TYPE="text" NAME="tax_<% $exempt_group %>_num" ID="tax_<% $exempt_group %>_num" VALUE="<% $cgi->param("tax_$exempt_group".'_num') || ( $cust_main_exemption ? $cust_main_exemption->exempt_number : '' ) |h %>" <% $checked ? '' : 'DISABLED' %>></TD>
473         </TR>
474 %     }
475 %   }
476
477 % unless ( $conf->exists('emailinvoiceonly') ) {
478
479     <TR>
480       <TD WIDTH="608" COLSPAN="2"><INPUT TYPE="checkbox" NAME="invoicing_list_POST" VALUE="POST" <%
481
482         ( grep { $_ eq 'POST' } @invoicing_list )
483
484           ? 'CHECKED'
485           : ''
486
487         %>> <% mt('Postal mail invoices') |h %> 
488
489       </TD>
490     </TR>
491
492     <TR>
493       <TD WIDTH="608" COLSPAN="2"><INPUT TYPE="checkbox" NAME="invoicing_list_FAX" VALUE="FAX" <%
494
495         ( grep { $_ eq 'FAX' } @invoicing_list )
496           ? 'CHECKED'
497           : ''
498
499         %>> <% mt('Fax invoices') |h %> 
500
501       </TD>
502     </TR>
503
504 % }
505
506     <TR>
507       <TD WIDTH="608" COLSPAN="2"><INPUT TYPE="checkbox" NAME="invoice_email" VALUE="Y" <%
508
509         ( $cust_main->invoice_noemail eq 'Y' )
510           ? ''
511           : 'CHECKED'
512
513         %>> <% mt('Email invoices') |h %> 
514
515       </TD>
516     </TR>
517
518 % unless ( $conf->exists('cust-email-high-visibility')) {
519    <TR>
520       <TD ALIGN="right" WIDTH="200">
521         <% $conf->exists('cust_main-require_invoicing_list_email', $agentnum) 
522             ? $r : '' %>Email address(es)
523       </TD>
524       <TD WIDTH="408"><INPUT TYPE="text" NAME="invoicing_list" VALUE="<% join(', ', grep { $_ !~ /^(POST|FAX)$/ } @invoicing_list ) %>">
525       <INPUT TYPE="checkbox" NAME="message_noemail" VALUE="Y" <%
526         ( $cust_main->message_noemail eq 'Y' )
527           ? 'CHECKED'
528           : ''
529         %>> <% emt('Do not send notices') %>
530       </TD>
531     </TR>
532 % }
533
534 % if ( $conf->exists('cust_main-select-prorate_day') ) {
535     <TR>
536       <TD ALIGN="right" WIDTH="200"><% mt('Prorate day (1-28)') |h %> </TD>
537       <TD>
538         <INPUT TYPE="text" NAME="prorate_day" VALUE="<% $cust_main->prorate_day %>" SIZE=3 MAXLENGTH=2>
539       </TD>
540     </TR>
541 % } else {
542     <INPUT TYPE="hidden" NAME="prorate_day" VALUE="<% $cust_main->prorate_day %>">
543 % }
544
545     <TR>
546       <TD ALIGN="right" WIDTH="200"><% mt('Invoice terms') |h %> </TD>
547       <TD WIDTH="408">
548         <& /elements/select-terms.html,
549                      'curr_value' => $cust_main->invoice_terms,
550         &>
551       </TD>
552     </TR>
553
554     <TR>
555       <TD ALIGN="right" WIDTH="200"><% mt('Credit limit') |h %> </TD>
556       <TD WIDTH="408">
557         <SCRIPT TYPE="text/javascript">
558 function toggle(obj) {
559   obj.form.credit_limit.disabled = obj.checked;
560 }
561         </SCRIPT>
562         <INPUT TYPE="text" NAME="credit_limit" VALUE=<% sprintf('"%.2f"', $cust_main->credit_limit) %><% length($cust_main->credit_limit) ? '' : ' DISABLED' %>>
563         <INPUT TYPE="checkbox" NAME="no_credit_limit" VALUE=1 onclick="toggle(this)"<% length($cust_main->credit_limit) ? '' : ' CHECKED'%>> <% mt('Unlimited') |h %> 
564       </TD>
565     </TR>
566
567 % if ( $conf->exists('voip-cust_cdr_spools') ) { 
568       <TR>
569        <TD COLSPAN="2"><INPUT TYPE="checkbox" NAME="spool_cdr" VALUE="Y" <% $cust_main->spool_cdr eq "Y" ? 'CHECKED' : '' %>> <% mt('Spool CDRs') |h %></TD>
570       </TR>
571 % } else { 
572       <INPUT TYPE="hidden" NAME="spool_cdr" VALUE="<% $cust_main->spool_cdr %>">
573 % }
574
575 % if ( $conf->exists('voip-cust_cdr_squelch') ) { 
576       <TR>
577        <TD COLSPAN="2"><INPUT TYPE="checkbox" NAME="squelch_cdr" VALUE="Y" <% $cust_main->squelch_cdr eq "Y" ? 'CHECKED' : '' %>> <% mt($conf->exists('voip-cdr_email') ? 'Omit CDRs from printed invoices' : 'Omit CDRs from invoices') |h %></TD>
578       </TR>
579 % } else { 
580       <INPUT TYPE="hidden" NAME="squelch_cdr" VALUE="<% $cust_main->squelch_cdr %>">
581 % }
582
583 % if ( $conf->exists('voip-cust_email_csv_cdr') ) { 
584       <TR>
585        <TD COLSPAN="2"><INPUT TYPE="checkbox" NAME="email_csv_cdr" VALUE="Y" <% $cust_main->email_csv_cdr eq "Y" ? 'CHECKED' : '' %>> <% mt('Attach CDRs as CSV to emailed invoices') |h %></TD>
586       </TR>
587 % } else { 
588       <INPUT TYPE="hidden" NAME="email_csv_cdr" VALUE="<% $cust_main->email_csv_cdr %>">
589 % }
590
591 % if ( $conf->exists('voip-cust_accountcode_cdr') ) { 
592        <TR>
593         <TD COLSPAN="2">
594             <INPUT TYPE="checkbox" 
595                    NAME="accountcode_cdr" 
596                    VALUE="Y" 
597                    <% $cust_main->accountcode_cdr eq "Y" ? 'CHECKED' : '' %>
598             > <% mt('Breakdown CDRs by accountcode') |h %></TD>
599        </TR>
600 % } else { 
601        <INPUT TYPE="hidden" NAME="accountcode_cdr" VALUE="<% $cust_main->accountcode_cdr %>">
602 % }
603
604 % if ( $show_term || $cust_main->cdr_termination_percentage ) {
605       <TR>
606        <TD ALIGN="right"><% mt('CDR termination settlement') |h %></TD>
607        <TD><INPUT TYPE  = "text"
608                   NAME  = "cdr_termination_percentage"
609                   SIZE  = 6
610                   VALUE = "<% $cust_main->cdr_termination_percentage %>"
611                   STYLE = "text-align:right;"
612         ><B>%</B></TD>
613       </TR>
614 % } else {
615       <INPUT TYPE="hidden" NAME="cdr_termination_percentage" VALUE="<% $cust_main->cdr_termination_percentage %>">
616 % }
617
618 %my @available_locales = $conf->config('available-locales');
619 %if ( scalar(@available_locales) ) {
620 %  push @available_locales, ''
621 %    unless $cust_main->locale && $conf->exists('cust_main-require_locale');
622 %  my %locale_labels = map { 
623 %    my %ll;
624 %    my %info = FS::Locales->locale_info($_);
625 %    $ll{$_} = $info{name} . " (" . $info{country} . ")";
626 %    %ll;
627 %  } FS::Locales->locales;
628 %    
629 %  my $label = ( $conf->exists('cust_main-require_locale') ? $r : '' ).
630 %              emt('Invoicing locale');
631
632     <& /elements/tr-select.html, 
633          'label'         => $label,
634          'field'         => 'locale',
635          'options'       => \@available_locales,
636          'labels'        => \%locale_labels,
637          'curr_value'    => $cust_main->locale,
638     &>
639 % }
640
641   </TABLE>
642
643   <% $r %><% mt('required fields') |h %> 
644 % } 
645
646 <script type="text/javascript">
647     init_payauto_changed();
648 </script>
649
650 <%once>
651
652 my $paystate_label = FS::Msgcat::_gettext('paystate');
653 $paystate_label = 'Bank state' if $paystate_label =~/^paystate$/;
654
655 </%once>
656 <%init>
657
658 my( $cust_main, %options ) = @_;
659 my @invoicing_list = @{ $options{'invoicing_list'} };
660 my $payinfo = $options{'payinfo'};
661 my $conf = new FS::Conf;
662 my $payby_default = $conf->config('payby-default');
663
664 my @payby = grep /\w/, $conf->config('payby');
665 #@payby = (qw( CARD DCRD CHEK DCHK LECB BILL CASH WEST COMP ))
666 @payby = (qw( CARD DCRD CHEK DCHK LECB BILL CASH COMP ))
667   unless @payby;
668
669 my $show_term = '';
670 if ( $cust_main->custnum ) {
671   #false laziness w/view/cust_main/billing.html
672   my $term_sql = "SELECT COUNT(*) FROM cust_pkg LEFT JOIN part_pkg USING ( pkgpart ) WHERE custnum = ? AND plan = 'cdr_termination' LIMIT 1";
673   my $term_sth = dbh->prepare($term_sql)  or die dbh->errstr;
674   $term_sth->execute($cust_main->custnum) or die $term_sth->errstr;
675   $show_term = $term_sth->fetchrow_arrayref->[0];
676 }
677
678 my $agentnum = $cust_main->agentnum if $cust_main->custnum;
679
680 </%init>