support a default tax location outside us/ca with cch data and better handling of...
[freeside.git] / httemplate / edit / cust_main.cgi
1 <% include('/elements/header.html',
2       "Customer $action",
3       '',
4       ' onUnload="myclose()"'
5 ) %>
6
7 <% include('/elements/init_overlib.html') %>
8
9 <% include('/elements/error.html') %>
10
11 <FORM NAME="topform" STYLE="margin-bottom: 0">
12 <INPUT TYPE="hidden" NAME="custnum" VALUE="<% $custnum %>">
13
14 % if ( $custnum ) { 
15   Customer #<B><% $cust_main->display_custnum %></B> - 
16   <B><FONT COLOR="#<% $cust_main->statuscolor %>">
17     <% ucfirst($cust_main->status) %>
18   </FONT></B>
19   <BR><BR>
20 % } 
21
22 <% &ntable("#cccccc") %>
23
24 %# agent
25 <% include('/elements/tr-select-agent.html', 
26               'curr_value'    => $cust_main->agentnum,
27               'label'         => "<B>${r}Agent</B>",
28               'empty_label'   => 'Select agent',
29               'disable_empty' => ( $cust_main->agentnum ? 1 : 0 ),
30            )
31 %>
32
33 %# agent_custid
34 % if ( $conf->exists('cust_main-edit_agent_custid') ) {
35
36     <TR>
37       <TD ALIGN="right">Customer identifier</TD>
38       <TD><INPUT TYPE="text" NAME="agent_custid" VALUE="<% $cust_main->agent_custid %>"></TD>
39     </TR>
40
41 % } else {
42
43     <INPUT TYPE="hidden" NAME="agent_custid" VALUE="<% $cust_main->agent_custid %>">
44
45 % }
46
47 %# referral (advertising source)
48 %my $refnum = $cust_main->refnum || $conf->config('referraldefault') || 0;
49 %if ( $custnum && ! $conf->exists('editreferrals') ) {
50
51   <INPUT TYPE="hidden" NAME="refnum" VALUE="<% $refnum %>">
52
53 % } else { 
54
55    <% include('/elements/tr-select-part_referral.html',
56                 'curr_value' => $refnum
57              )
58    %>
59 % } 
60
61
62 %# referring customer
63 %my $referring_cust_main = '';
64 %if ( $cust_main->referral_custnum
65 %     and $referring_cust_main =
66 %           qsearchs('cust_main', { custnum => $cust_main->referral_custnum } )
67 %) {
68
69   <TR>
70     <TD ALIGN="right">Referring customer</TD>
71     <TD>
72       <A HREF="<% popurl(1) %>/cust_main.cgi?<% $cust_main->referral_custnum %>"><% $cust_main->referral_custnum %>: <% $referring_cust_main->name %></A>
73     </TD>
74   </TR>
75   <INPUT TYPE="hidden" NAME="referral_custnum" VALUE="<% $cust_main->referral_custnum %>">
76 % } elsif ( ! $conf->exists('disable_customer_referrals') ) { 
77
78
79   <TR>
80     <TD ALIGN="right">Referring customer</TD>
81     <TD>
82       <!-- <INPUT TYPE="text" NAME="referral_custnum" VALUE=""> -->
83       <% include('/elements/search-cust_main.html',
84                     'field_name' => 'referral_custnum',
85                  )
86       %>
87     </TD>
88   </TR>
89 % } else { 
90
91
92   <INPUT TYPE="hidden" NAME="referral_custnum" VALUE="">
93 % } 
94
95
96 </TABLE>
97
98 <!-- birthdate -->
99
100 % if ( $conf->exists('cust_main-enable_birthdate') ) {
101
102   <BR>
103   <% ntable("#cccccc", 2) %>
104   <% include ('/elements/tr-input-date-field.html',
105               'birthdate',
106               $cust_main->birthdate,
107               'Date of Birth',
108               $conf->config('date_format') || "%m/%d/%Y",
109               1)
110   %>
111
112   </TABLE>
113
114 % }
115
116 <!-- contact info -->
117
118 %  my $same_checked = '';
119 %  my $ship_disabled = '';
120 %  unless ( $cust_main->ship_last && $same ne 'Y' ) {
121 %    $same_checked = 'CHECKED';
122 %    $ship_disabled = 'DISABLED STYLE="background-color: #dddddd"';
123 %    foreach (
124 %      qw( last first company address1 address2 city county state zip country
125 %          daytime night fax )
126 %    ) {
127 %      $cust_main->set("ship_$_", $cust_main->get($_) );
128 %    }
129 %  }
130
131 <BR><BR>
132 Billing address
133 <% include('cust_main/contact.html',
134              'cust_main'    => $cust_main,
135              'pre'          => '',
136              'onchange'     => 'bill_changed(this)',
137              'disabled'     => '',
138              'ss'           => $ss,
139              'stateid'      => $stateid,
140              'same_checked' => $same_checked, #for address2 "Unit #" labeling
141           )
142 %>
143
144 <SCRIPT>
145 function bill_changed(what) {
146   if ( what.form.same.checked ) {
147 % for (qw( last first company address1 address2 city zip daytime night fax )) { 
148
149     what.form.ship_<%$_%>.value = what.form.<%$_%>.value;
150 % } 
151
152     what.form.ship_country.selectedIndex = what.form.country.selectedIndex;
153
154     function fix_ship_county() {
155       what.form.ship_county.selectedIndex = what.form.county.selectedIndex;
156     }
157
158     function fix_ship_state() {
159       what.form.ship_state.selectedIndex = what.form.state.selectedIndex;
160       ship_state_changed(what.form.ship_state, fix_ship_county );
161     }
162
163     ship_country_changed(what.form.ship_country, fix_ship_state );
164
165   }
166 }
167 function samechanged(what) {
168   if ( what.checked ) {
169     bill_changed(what);
170
171 %   for (qw( last first company address1 address2 city county state zip country daytime night fax )) { 
172       what.form.ship_<%$_%>.disabled = true;
173       what.form.ship_<%$_%>.style.backgroundColor = '#dddddd';
174 %   } 
175
176 %   if ( $conf->exists('cust_main-require_address2') ) {
177       document.getElementById('address2_required').style.visibility = '';
178       document.getElementById('address2_label').style.visibility = '';
179       document.getElementById('ship_address2_required').style.visibility = 'hidden';
180       document.getElementById('ship_address2_label').style.visibility = 'hidden';
181 %   }
182
183   } else {
184
185 %   for (qw( last first company address1 address2 city county state zip country daytime night fax )) { 
186       what.form.ship_<%$_%>.disabled = false;
187       what.form.ship_<%$_%>.style.backgroundColor = '#ffffff';
188 %   } 
189
190 %   if ( $conf->exists('cust_main-require_address2') ) {
191       document.getElementById('address2_required').style.visibility = 'hidden';
192       document.getElementById('address2_label').style.visibility = 'hidden';
193       document.getElementById('ship_address2_required').style.visibility = '';
194       document.getElementById('ship_address2_label').style.visibility = '';
195 %   }
196
197   }
198 }
199 </SCRIPT>
200
201 <BR>
202 Service address 
203 (<INPUT TYPE="checkbox" NAME="same" VALUE="Y" onClick="samechanged(this)" <%$same_checked%>>same as billing address)
204 <% include('cust_main/contact.html',
205              'cust_main' => $cust_main,
206              'pre'       => 'ship_',
207              'onchange'  => '',
208              'disabled'  => $ship_disabled,
209           )
210 %>
211
212
213 <!-- billing info -->
214
215 <% include( 'cust_main/billing.html', $cust_main,
216                'payinfo'        => $payinfo,
217                'invoicing_list' => \@invoicing_list,
218            )
219 %>
220
221 <% include( '/elements/xmlhttp.html',
222               'url'  => $p.'misc/xmlhttp-cust_main-address_standardize.html',
223               'subs' => [ 'address_standardize' ],
224               #'method' => 'POST', #could get too long?
225           )
226 %>
227
228 <SCRIPT>
229 function bottomfixup(what) {
230
231   //i don't think we need to copy things between two forms anymore, modern
232   //browsers are fine with DIVs inside FORMs
233
234   var topvars = new Array(
235     'birthdate',
236
237     'custnum', 'agentnum', 'agent_custid', 'refnum', 'referral_custnum',
238
239     'last', 'first', 'ss', 'company',
240     'address1', 'address2', 'city',
241     'county', 'state', 'zip', 'country',
242     'daytime', 'night', 'fax',
243     'stateid', 'stateid_state',
244
245     'same',
246
247     'ship_last', 'ship_first', 'ship_company',
248     'ship_address1', 'ship_address2', 'ship_city',
249     'ship_county', 'ship_state', 'ship_zip', 'ship_country',
250     'ship_daytime','ship_night', 'ship_fax',
251
252     'geocode',
253
254     'select' // XXX key
255   );
256
257   var layervars = new Array(
258     'payauto',
259     'payinfo', 'payinfo1', 'payinfo2', 'paytype',
260     'payname', 'paystate', 'exp_month', 'exp_year', 'paycvv',
261     'paystart_month', 'paystart_year', 'payissue',
262     'payip',
263     'paid'
264   );
265
266   var billing_bottomvars = new Array(
267     'tax',
268     'invoicing_list', 'invoicing_list_POST', 'invoicing_list_FAX',
269     'invoice_terms',
270     'spool_cdr',
271     'squelch_cdr'
272   );
273
274   for ( f=0; f < topvars.length; f++ ) {
275     var field = topvars[f];
276     copyelement( document.topform.elements[field],
277                  document.bottomform.elements[field]
278                );
279   }
280
281   var layerform = document.topform.select.options[document.topform.select.selectedIndex].value;
282   for ( f=0; f < layervars.length; f++ ) {
283     var field = layervars[f];
284     copyelement( document.forms[layerform].elements[field],
285                  document.bottomform.elements[field]
286                );
287   }
288
289   for ( f=0; f < billing_bottomvars.length; f++ ) {
290     var field = billing_bottomvars[f];
291     copyelement( document.billing_bottomform.elements[field],
292                  document.bottomform.elements[field]
293                );
294   }
295
296   //this part does USPS address correction
297
298   // XXX should this be first and should we update the form fields that are
299   // displayed???
300
301   //var state_el = document.bottomform.elements['state'];
302
303   //address_standardize(
304   var cust_main = new Array(
305     'company',  document.bottomform.elements['company'].value,
306     'address1', document.bottomform.elements['address1'].value,
307     'address2', document.bottomform.elements['address2'].value,
308     'city',     document.bottomform.elements['city'].value,
309     'state',    document.bottomform.elements['state'].value,
310     //'state',    state_el.options[ state_el.selectedIndex ].value,
311     'zip',      document.bottomform.elements['zip'].value,
312
313     'ship_company',  document.bottomform.elements['ship_company'].value,
314     'ship_address1', document.bottomform.elements['ship_address1'].value,
315     'ship_address2', document.bottomform.elements['ship_address2'].value,
316     'ship_city',     document.bottomform.elements['ship_city'].value,
317     'ship_state',    document.bottomform.elements['ship_state'].value,
318     //'ship_state',    state_el.options[ state_el.selectedIndex ].value,
319     'ship_zip',      document.bottomform.elements['ship_zip'].value
320   );
321
322   address_standardize( cust_main, update_address );
323
324 }
325
326 var standardize_address;
327
328 function update_address(arg) {
329
330   var argsHash = eval('(' + arg + ')');
331
332   var changed  = argsHash['address_standardized'];
333   var ship_changed = argsHash['ship_address_standardized'];
334   var error = argsHash['error'];
335   var ship_error = argsHash['ship_error'];
336
337   //yay closures
338   standardize_address = function () {
339
340     if ( changed ) {
341       document.bottomform.elements['company'].value = argsHash['new_company'];
342       document.bottomform.elements['address1'].value = argsHash['new_address1'];
343       document.bottomform.elements['address2'].value = argsHash['new_address2'];
344       document.bottomform.elements['city'].value = argsHash['new_city'];
345       document.bottomform.elements['state'].value = argsHash['new_state'];
346   //'state',    state_el.options[ state_el.selectedIndex ].value,
347       document.bottomform.elements['zip'].value = argsHash['new_zip'];
348     }
349
350     if ( ship_changed ) {
351       document.bottomform.elements['ship_company'].value = argsHash['new_ship_company'];
352       document.bottomform.elements['ship_address1'].value = argsHash['new_ship_address1'];
353       document.bottomform.elements['ship_address2'].value = argsHash['new_ship_address2'];
354       document.bottomform.elements['ship_city'].value = argsHash['new_ship_city'];
355       document.bottomform.elements['ship_state'].value = argsHash['new_ship_state'];
356   //'state',    state_el.options[ state_el.selectedIndex ].value,
357       document.bottomform.elements['ship_zip'].value = argsHash['new_ship_zip'];
358     }
359
360   }
361
362 % if ( $conf->exists('enable_taxproducts') ) {
363
364   if ( <% $taxpre %>error ) {
365
366     if ( document.bottomform.elements['country'].value == 'CA' ||
367          document.bottomform.elements['country'].value == 'US'
368        )
369     {
370
371       var url = "cust_main/choose_tax_location.html?data_vendor=cch-zip;city="+document.bottomform.elements['city'].value+";state="+document.bottomform.elements['state'].value+";zip="+document.bottomform.elements['zip'].value+";country="+document.bottomform.elements['country'].value+";";
372       // popup a chooser
373       OLgetAJAX( url, update_geocode, 300 );
374
375     } else {
376
377       document.bottomform.elements['geocode'].value = 'DEFAULT';
378       document.bottomform.submit();
379
380     }
381
382   } else
383
384 % }
385
386   if ( changed || ship_changed ) {
387
388 %   if ( $conf->exists('cust_main-auto_standardize_address') ) {
389
390     standardize_address();
391     document.bottomform.submit();
392
393 %   } else {
394
395     // popup a confirmation popup
396
397     var confirm_change =
398       '<CENTER><BR><B>Confirm address standardization</B><BR><BR>' +
399       '<TABLE>';
400     
401     if ( changed ) {
402
403       confirm_change = confirm_change + 
404         '<TR><TH>Entered billing address</TH>' +
405           '<TH>Standardized billing address</TH></TR>';
406         // + '<TR><TD>&nbsp;</TD><TD>&nbsp;</TD></TR>';
407       
408       if ( argsHash['company'] || argsHash['new_company'] ) {
409         confirm_change = confirm_change +
410         '<TR><TD>' + argsHash['company'] +
411           '</TD><TD>' + argsHash['new_company'] + '</TD></TR>';
412       }
413       
414       confirm_change = confirm_change +
415         '<TR><TD>' + argsHash['address1'] +
416           '</TD><TD>' + argsHash['new_address1'] + '</TD></TR>' +
417         '<TR><TD>' + argsHash['address2'] +
418           '</TD><TD>' + argsHash['new_address2'] + '</TD></TR>' +
419         '<TR><TD>' + argsHash['city'] + ', ' + argsHash['state'] + '  ' + argsHash['zip'] +
420           '</TD><TD>' + argsHash['new_city'] + ', ' + argsHash['new_state'] + '  ' + argsHash['new_zip'] + '</TD></TR>' +
421           '<TR><TD>&nbsp;</TD><TD>&nbsp;</TD></TR>';
422
423     }
424
425     if ( ship_changed ) {
426
427       confirm_change = confirm_change + 
428         '<TR><TH>Entered service address</TH>' +
429           '<TH>Standardized service address</TH></TR>';
430         // + '<TR><TD>&nbsp;</TD><TD>&nbsp;</TD></TR>';
431       
432       if ( argsHash['ship_company'] || argsHash['new_ship_company'] ) {
433         confirm_change = confirm_change +
434         '<TR><TD>' + argsHash['ship_company'] +
435           '</TD><TD>' + argsHash['new_ship_company'] + '</TD></TR>';
436       }
437       
438       confirm_change = confirm_change +
439         '<TR><TD>' + argsHash['ship_address1'] +
440           '</TD><TD>' + argsHash['new_ship_address1'] + '</TD></TR>' +
441         '<TR><TD>' + argsHash['ship_address2'] +
442           '</TD><TD>' + argsHash['new_ship_address2'] + '</TD></TR>' +
443         '<TR><TD>' + argsHash['ship_city'] + ', ' + argsHash['ship_state'] + '  ' + argsHash['ship_zip'] +
444           '</TD><TD>' + argsHash['new_ship_city'] + ', ' + argsHash['new_ship_state'] + '  ' + argsHash['new_ship_zip'] + '</TD></TR>' +
445         '<TR><TD>&nbsp;</TD><TD>&nbsp;</TD></TR>';
446
447     }
448
449     var addresses = 'address';
450     var height = 268;
451     if ( changed && ship_changed ) {
452       addresses = 'addresses';
453       height = 396; // #what
454     }
455
456     confirm_change = confirm_change +
457       '<TR><TD>' +
458         '<BUTTON TYPE="button" onClick="document.bottomform.submit();"><IMG SRC="<%$p%>images/error.png" ALT=""> Use entered ' + addresses + '</BUTTON>' + 
459       '</TD><TD>' +
460         '<BUTTON TYPE="button" onClick="standardize_address(); document.bottomform.submit();"><IMG SRC="<%$p%>images/tick.png" ALT=""> Use standardized ' + addresses + '</BUTTON>' + 
461       '</TD></TR>' +
462       '<TR><TD COLSPAN=2 ALIGN="center">' +
463         '<BUTTON TYPE="button" onClick="document.bottomform.submitButton.disabled=false; parent.cClick();"><IMG SRC="<%$p%>images/cross.png" ALT=""> Cancel submission</BUTTON></TD></TR>' +
464         
465       '</TABLE></CENTER>';
466
467     overlib( confirm_change, CAPTION, 'Confirm address standardization', STICKY, AUTOSTATUSCAP, CLOSETEXT, '', MIDX, 0, MIDY, 0, DRAGGABLE, WIDTH, 576, HEIGHT, height, BGCOLOR, '#333399', CGCOLOR, '#333399', TEXTSIZE, 3 );
468
469 %   }
470
471   } else {
472
473     document.bottomform.submit();
474
475   }
476
477 }
478
479 function update_geocode() {
480
481   //yay closures
482   set_geocode = function (what) {
483
484     //alert(what.options[what.selectedIndex].value);
485     var argsHash = eval('(' + what.options[what.selectedIndex].value + ')');
486     document.bottomform.elements['city'].value = argsHash['city'];
487     document.bottomform.elements['state'].value = argsHash['state'];
488     document.bottomform.elements['zip'].value = argsHash['zip'];
489     document.bottomform.elements['geocode'].value = argsHash['geocode'];
490
491   }
492
493   // popup a chooser
494
495   overlib( OLresponseAJAX, CAPTION, 'Select tax location', STICKY, AUTOSTATUSCAP, CLOSETEXT, '', MIDX, 0, MIDY, 0, DRAGGABLE, WIDTH, 576, HEIGHT, 268, BGCOLOR, '#333399', CGCOLOR, '#333399', TEXTSIZE, 3 );
496
497 }
498
499 function copyelement(from, to) {
500   if ( from == undefined ) {
501     to.value = '';
502   } else if ( from.type == 'select-one' ) {
503     to.value = from.options[from.selectedIndex].value;
504     //alert(from + " (" + from.type + "): " + to.name + " => (" + from.selectedIndex + ") " + to.value);
505   } else if ( from.type == 'checkbox' ) {
506     if ( from.checked ) {
507       to.value = from.value;
508     } else {
509       to.value = '';
510     }
511   } else {
512     if ( from.value == undefined ) {
513       to.value = '';
514     } else {
515       to.value = from.value;
516     }
517   }
518   //alert(from + " (" + from.type + "): " + to.name + " => " + to.value);
519 }
520
521 </SCRIPT>
522
523 <FORM ACTION="<% popurl(1) %>process/cust_main.cgi" METHOD=POST NAME="bottomform" STYLE="margin-top: 0; margin-bottom: 0">
524 % foreach my $hidden (
525 %     'birthdate',
526 %
527 %     'custnum', 'agentnum', 'agent_custid', 'refnum', 'referral_custnum',
528 %     'last', 'first', 'ss', 'company',
529 %     'address1', 'address2', 'city',
530 %     'county', 'state', 'zip', 'country',
531 %     'daytime', 'night', 'fax',
532 %     'stateid', 'stateid_state',
533 %     
534 %     'same',
535 %     
536 %     'ship_last', 'ship_first', 'ship_company',
537 %     'ship_address1', 'ship_address2', 'ship_city',
538 %     'ship_county', 'ship_state', 'ship_zip', 'ship_country',
539 %     'ship_daytime','ship_night', 'ship_fax',
540 %     
541 %     'geocode',
542 %     
543 %     'select', #XXX key
544 %
545 %     'payauto',
546 %     'payinfo', 'payinfo1', 'payinfo2', 'paytype',
547 %     'payname', 'paystate', 'exp_month', 'exp_year', 'paycvv',
548 %     'paystart_month', 'paystart_year', 'payissue',
549 %     'payip',
550 %     'paid',
551 %     
552 %     'tax',
553 %     'invoicing_list', 'invoicing_list_POST', 'invoicing_list_FAX',
554 %     'invoice_terms',
555 %     'spool_cdr',
556 %     'squelch_cdr'
557 %   ) {
558 %
559
560   <INPUT TYPE="hidden" NAME="<% $hidden %>" VALUE="">
561 % } 
562 %
563 % my $ro_comments = $conf->exists('cust_main-use_comments')?'':'readonly';
564 % if (!$ro_comments || $cust_main->comments) {
565
566 <BR>Comments
567 <% &ntable("#cccccc") %>
568   <TR>
569     <TD>
570       <TEXTAREA COLS=80 ROWS=5 WRAP="HARD" NAME="comments" <%$ro_comments%>><% $cust_main->comments %></TEXTAREA>
571     </TD>
572   </TR>
573 </TABLE>
574 %
575 % }
576 %
577 %unless ( $custnum ) {
578 %  # pry the wrong place for this logic.  also pretty expensive
579 %  #use FS::part_pkg;
580 %
581 %  #false laziness, copied from FS::cust_pkg::order
582 %  my $pkgpart;
583 %  my $agentnum = '';
584 %  my @agents = $FS::CurrentUser::CurrentUser->agents;
585 %  if ( scalar(@agents) == 1 ) {
586 %    # $pkgpart->{PKGPART} is true iff $custnum may purchase PKGPART
587 %    $pkgpart = $agents[0]->pkgpart_hashref;
588 %    $agentnum = $agents[0]->agentnum;
589 %  } else {
590 %    #can't know (agent not chosen), so, allow all
591 %    $agentnum = 'all';
592 %    my %typenum;
593 %    foreach my $agent ( @agents ) {
594 %      next if $typenum{$agent->typenum}++;
595 %      $pkgpart->{$_}++ foreach keys %{ $agent->pkgpart_hashref }
596 %    }
597 %  }
598 %  #eslaf
599 %
600 %  my @part_pkg = grep { $_->svcpart('svc_acct')
601 %                        && ( $pkgpart->{ $_->pkgpart } 
602 %                             || $agentnum eq 'all'
603 %                             || ( $agentnum ne 'all'
604 %                                  && $agentnum
605 %                                  && $_->agentnum
606 %                                  && $_->agentnum == $agentnum
607 %                                )
608 %                           )
609 %                      }
610 %    qsearch( 'part_pkg', { 'disabled' => '' }, '', 'ORDER BY pkg' ); # case?
611 %
612 %  if ( @part_pkg ) {
613 %
614 %    #    print "<BR><BR>First package", &itable("#cccccc", "0 ALIGN=LEFT"),
615 %    #apiabuse & undesirable wrapping
616 %
617 %    
618
619     <BR>First package
620     <% ntable("#cccccc") %>
621     
622       <TR>
623         <TD COLSPAN=2>
624           <% include('cust_main/select-domain.html',
625                        'pkgparts'      => \@part_pkg,
626                        'saved_pkgpart' => $saved_pkgpart,
627                        'saved_domsvc' => $saved_domsvc,
628                     )
629           %>
630         </TD>
631       </TR>
632
633 %        #false laziness: (mostly) copied from edit/svc_acct.cgi
634 %        #$ulen = $svc_acct->dbdef_table->column('username')->length;
635 %        my $ulen = dbdef->table('svc_acct')->column('username')->length;
636 %        my $ulen2 = $ulen+2;
637 %        my $passwordmax = $conf->config('passwordmax') || 8;
638 %        my $pmax2 = $passwordmax + 2;
639 %      
640
641     
642       <TR>
643         <TD ALIGN="right">Username</TD>
644         <TD>
645           <INPUT TYPE="text" NAME="username" VALUE="<% $username %>" SIZE=<% $ulen2 %> MAXLENGTH=<% $ulen %>>
646         </TD>
647       </TR>
648     
649       <TR>
650         <TD ALIGN="right">Domain</TD>
651         <TD>
652           <SELECT NAME="domsvc">
653             <OPTION>(none)</OPTION>
654           </SELECT>
655         </TD>
656       </TR>
657     
658       <TR>
659         <TD ALIGN="right">Password</TD>
660         <TD>
661           <INPUT TYPE="text" NAME="_password" VALUE="<% $password %>" SIZE=<% $pmax2 %> MAXLENGTH=<% $passwordmax %>>
662           (blank to generate)
663         </TD>
664       </TR>
665     
666       <TR>
667         <TD ALIGN="right">Access number</TD>
668         <TD><% FS::svc_acct_pop::popselector($popnum) %></TD>
669       </TR>
670     </TABLE>
671 % } 
672 % } 
673
674
675 <INPUT TYPE="hidden" NAME="otaker" VALUE="<% $cust_main->otaker %>">
676 <BR>
677 <INPUT TYPE="button" NAME="submitButton" ID="submitButton" VALUE="<% $custnum ?  "Apply Changes" : "Add Customer" %>" onClick="document.bottomform.submitButton.disabled=true; bottomfixup(this.form);">
678 <BR>
679 </FORM>
680
681 <% include('/elements/footer.html') %>
682
683 <%init>
684
685 die "access denied"
686   unless $FS::CurrentUser::CurrentUser->access_right('Edit customer');
687
688 #for misplaced logic below
689 #use FS::part_pkg;
690
691 #for false laziness below (now more properly lazy)
692 #use FS::svc_acct_pop;
693
694 #for (other) false laziness below
695 #use FS::agent;
696 #use FS::type_pkgs;
697
698 my $conf = new FS::Conf;
699
700 my $taxpre = $conf->exists('tax-ship_address') ? 'ship_' : '';
701 #get record
702
703 my($custnum, $username, $password, $popnum, $cust_main, $saved_pkgpart, $saved_domsvc);
704 my(@invoicing_list);
705 my ($ss,$stateid,$payinfo);
706 my $same = '';
707 if ( $cgi->param('error') ) {
708   $cust_main = new FS::cust_main ( {
709     map { $_, scalar($cgi->param($_)) } fields('cust_main')
710   } );
711   $custnum = $cust_main->custnum;
712   $saved_domsvc = $cgi->param('domsvc') || '';
713   if ( $saved_domsvc =~ /^(\d+)$/ ) {
714     $saved_domsvc = $1;
715   } else {
716     $saved_domsvc = '';
717   }
718   $saved_pkgpart = $cgi->param('pkgpart_svcpart') || '';
719   if ( $saved_pkgpart =~ /^(\d+)_/ ) {
720     $saved_pkgpart = $1;
721   } else {
722     $saved_pkgpart = '';
723   }
724   $username = $cgi->param('username');
725   $password = $cgi->param('_password');
726   $popnum = $cgi->param('popnum');
727   @invoicing_list = split( /\s*,\s*/, $cgi->param('invoicing_list') );
728   $same = $cgi->param('same');
729   $cust_main->setfield('paid' => $cgi->param('paid')) if $cgi->param('paid');
730   $ss = $cust_main->ss;           # don't mask an entered value on errors
731   $stateid = $cust_main->stateid; # don't mask an entered value on errors
732   $payinfo = $cust_main->payinfo; # don't mask an entered value on errors
733 } elsif ( $cgi->keywords ) { #editing
734   my( $query ) = $cgi->keywords;
735   $query =~ /^(\d+)$/;
736   $custnum=$1;
737   $cust_main = qsearchs('cust_main', { 'custnum' => $custnum } );
738   if ( $cust_main->dbdef_table->column('paycvv')
739        && length($cust_main->paycvv)             ) {
740     my $paycvv = $cust_main->paycvv;
741     $paycvv =~ s/./*/g;
742     $cust_main->paycvv($paycvv);
743   }
744   $saved_pkgpart = 0;
745   $saved_domsvc = 0;
746   $username = '';
747   $password = '';
748   $popnum = 0;
749   @invoicing_list = $cust_main->invoicing_list;
750   $ss = $cust_main->masked('ss');
751   $stateid = $cust_main->masked('stateid');
752   $payinfo = $cust_main->paymask;
753 } else {
754   $custnum='';
755   $cust_main = new FS::cust_main ( {} );
756   $cust_main->otaker( &getotaker );
757   $cust_main->referral_custnum( $cgi->param('referral_custnum') );
758   $saved_pkgpart = 0;
759   $saved_domsvc = 0;
760   $username = '';
761   $password = '';
762   $popnum = 0;
763   @invoicing_list = ();
764   push @invoicing_list, 'POST'
765     unless $conf->exists('disablepostalinvoicedefault');
766   $ss = '';
767   $stateid = '';
768   $payinfo = '';
769 }
770
771 my $error = $cgi->param('error');
772 $cgi->delete_all();
773 $cgi->param('error', $error);
774
775 my $action = $custnum ? 'Edit' : 'Add';
776 $action .= ": ". $cust_main->name if $custnum;
777
778 my $r = qq!<font color="#ff0000">*</font>&nbsp;!;
779
780 </%init>