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