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