add options to auto-generate agent_custid and display it as the customer number,...
[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     'select' // XXX key
253   );
254
255   var layervars = new Array(
256     'payauto',
257     'payinfo', 'payinfo1', 'payinfo2', 'paytype',
258     'payname', 'paystate', 'exp_month', 'exp_year', 'paycvv',
259     'paystart_month', 'paystart_year', 'payissue',
260     'payip',
261     'paid'
262   );
263
264   var billing_bottomvars = new Array(
265     'tax',
266     'invoicing_list', 'invoicing_list_POST', 'invoicing_list_FAX',
267     'invoice_terms',
268     'spool_cdr',
269     'squelch_cdr'
270   );
271
272   for ( f=0; f < topvars.length; f++ ) {
273     var field = topvars[f];
274     copyelement( document.topform.elements[field],
275                  document.bottomform.elements[field]
276                );
277   }
278
279   var layerform = document.topform.select.options[document.topform.select.selectedIndex].value;
280   for ( f=0; f < layervars.length; f++ ) {
281     var field = layervars[f];
282     copyelement( document.forms[layerform].elements[field],
283                  document.bottomform.elements[field]
284                );
285   }
286
287   for ( f=0; f < billing_bottomvars.length; f++ ) {
288     var field = billing_bottomvars[f];
289     copyelement( document.billing_bottomform.elements[field],
290                  document.bottomform.elements[field]
291                );
292   }
293
294   //this part does USPS address correction
295
296   // XXX should this be first and should we update the form fields that are
297   // displayed???
298
299   //var state_el = document.bottomform.elements['state'];
300
301   //address_standardize(
302   var cust_main = new Array(
303     'company',  document.bottomform.elements['company'].value,
304     'address1', document.bottomform.elements['address1'].value,
305     'address2', document.bottomform.elements['address2'].value,
306     'city',     document.bottomform.elements['city'].value,
307     'state',    document.bottomform.elements['state'].value,
308     //'state',    state_el.options[ state_el.selectedIndex ].value,
309     'zip',      document.bottomform.elements['zip'].value,
310
311     'ship_company',  document.bottomform.elements['ship_company'].value,
312     'ship_address1', document.bottomform.elements['ship_address1'].value,
313     'ship_address2', document.bottomform.elements['ship_address2'].value,
314     'ship_city',     document.bottomform.elements['ship_city'].value,
315     'ship_state',    document.bottomform.elements['ship_state'].value,
316     //'ship_state',    state_el.options[ state_el.selectedIndex ].value,
317     'ship_zip',      document.bottomform.elements['ship_zip'].value
318   );
319
320   address_standardize( cust_main, update_address );
321
322 }
323
324 var standardize_address;
325
326 function update_address(arg) {
327
328   var argsHash = eval('(' + arg + ')');
329
330   var changed  = argsHash['address_standardized'];
331   var ship_changed = argsHash['ship_address_standardized'];
332
333   //yay closures
334   standardize_address = function () {
335
336     if ( changed ) {
337       document.bottomform.elements['company'].value = argsHash['new_company'];
338       document.bottomform.elements['address1'].value = argsHash['new_address1'];
339       document.bottomform.elements['address2'].value = argsHash['new_address2'];
340       document.bottomform.elements['city'].value = argsHash['new_city'];
341       document.bottomform.elements['state'].value = argsHash['new_state'];
342   //'state',    state_el.options[ state_el.selectedIndex ].value,
343       document.bottomform.elements['zip'].value = argsHash['new_zip'];
344     }
345
346     if ( ship_changed ) {
347       document.bottomform.elements['ship_company'].value = argsHash['new_ship_company'];
348       document.bottomform.elements['ship_address1'].value = argsHash['new_ship_address1'];
349       document.bottomform.elements['ship_address2'].value = argsHash['new_ship_address2'];
350       document.bottomform.elements['ship_city'].value = argsHash['new_ship_city'];
351       document.bottomform.elements['ship_state'].value = argsHash['new_ship_state'];
352   //'state',    state_el.options[ state_el.selectedIndex ].value,
353       document.bottomform.elements['ship_zip'].value = argsHash['new_ship_zip'];
354     }
355
356   }
357
358   if ( changed || ship_changed ) {
359
360 %   if ( $conf->exists('cust_main-auto_standardize_address') ) {
361
362     standardize_address();
363     document.bottomform.submit();
364
365 %   } else {
366
367     // popup a confirmation popup
368
369     var confirm_change =
370       '<CENTER><BR><B>Confirm address standardization</B><BR><BR>' +
371       '<TABLE>';
372     
373     if ( changed ) {
374
375       confirm_change = confirm_change + 
376         '<TR><TH>Entered billing address</TH>' +
377           '<TH>Standardized billing address</TH></TR>';
378         // + '<TR><TD>&nbsp;</TD><TD>&nbsp;</TD></TR>';
379       
380       if ( argsHash['company'] || argsHash['new_company'] ) {
381         confirm_change = confirm_change +
382         '<TR><TD>' + argsHash['company'] +
383           '</TD><TD>' + argsHash['new_company'] + '</TD></TR>';
384       }
385       
386       confirm_change = confirm_change +
387         '<TR><TD>' + argsHash['address1'] +
388           '</TD><TD>' + argsHash['new_address1'] + '</TD></TR>' +
389         '<TR><TD>' + argsHash['address2'] +
390           '</TD><TD>' + argsHash['new_address2'] + '</TD></TR>' +
391         '<TR><TD>' + argsHash['city'] + ', ' + argsHash['state'] + '  ' + argsHash['zip'] +
392           '</TD><TD>' + argsHash['new_city'] + ', ' + argsHash['new_state'] + '  ' + argsHash['new_zip'] + '</TD></TR>' +
393           '<TR><TD>&nbsp;</TD><TD>&nbsp;</TD></TR>';
394
395     }
396
397     if ( ship_changed ) {
398
399       confirm_change = confirm_change + 
400         '<TR><TH>Entered service address</TH>' +
401           '<TH>Standardized service address</TH></TR>';
402         // + '<TR><TD>&nbsp;</TD><TD>&nbsp;</TD></TR>';
403       
404       if ( argsHash['ship_company'] || argsHash['new_ship_company'] ) {
405         confirm_change = confirm_change +
406         '<TR><TD>' + argsHash['ship_company'] +
407           '</TD><TD>' + argsHash['new_ship_company'] + '</TD></TR>';
408       }
409       
410       confirm_change = confirm_change +
411         '<TR><TD>' + argsHash['ship_address1'] +
412           '</TD><TD>' + argsHash['new_ship_address1'] + '</TD></TR>' +
413         '<TR><TD>' + argsHash['ship_address2'] +
414           '</TD><TD>' + argsHash['new_ship_address2'] + '</TD></TR>' +
415         '<TR><TD>' + argsHash['ship_city'] + ', ' + argsHash['ship_state'] + '  ' + argsHash['ship_zip'] +
416           '</TD><TD>' + argsHash['new_ship_city'] + ', ' + argsHash['new_ship_state'] + '  ' + argsHash['new_ship_zip'] + '</TD></TR>' +
417         '<TR><TD>&nbsp;</TD><TD>&nbsp;</TD></TR>';
418
419     }
420
421     var addresses = 'address';
422     var height = 268;
423     if ( changed && ship_changed ) {
424       addresses = 'addresses';
425       height = 396; // #what
426     }
427
428     confirm_change = confirm_change +
429       '<TR><TD>' +
430         '<BUTTON TYPE="button" onClick="document.bottomform.submit();"><IMG SRC="<%$p%>images/error.png" ALT=""> Use entered ' + addresses + '</BUTTON>' + 
431       '</TD><TD>' +
432         '<BUTTON TYPE="button" onClick="standardize_address(); document.bottomform.submit();"><IMG SRC="<%$p%>images/tick.png" ALT=""> Use standardized ' + addresses + '</BUTTON>' + 
433       '</TD></TR>' +
434       '<TR><TD COLSPAN=2 ALIGN="center">' +
435         '<BUTTON TYPE="button" onClick="document.bottomform.submitButton.disabled=false; parent.cClick();"><IMG SRC="<%$p%>images/cross.png" ALT=""> Cancel submission</BUTTON></TD></TR>' +
436         
437       '</TABLE></CENTER>';
438
439     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 );
440
441 %   }
442
443   } else {
444
445     document.bottomform.submit();
446
447   }
448
449 }
450
451 function copyelement(from, to) {
452   if ( from == undefined ) {
453     to.value = '';
454   } else if ( from.type == 'select-one' ) {
455     to.value = from.options[from.selectedIndex].value;
456     //alert(from + " (" + from.type + "): " + to.name + " => (" + from.selectedIndex + ") " + to.value);
457   } else if ( from.type == 'checkbox' ) {
458     if ( from.checked ) {
459       to.value = from.value;
460     } else {
461       to.value = '';
462     }
463   } else {
464     if ( from.value == undefined ) {
465       to.value = '';
466     } else {
467       to.value = from.value;
468     }
469   }
470   //alert(from + " (" + from.type + "): " + to.name + " => " + to.value);
471 }
472
473 </SCRIPT>
474
475 <FORM ACTION="<% popurl(1) %>process/cust_main.cgi" METHOD=POST NAME="bottomform" STYLE="margin-top: 0; margin-bottom: 0">
476 % foreach my $hidden (
477 %     'birthdate',
478 %
479 %     'custnum', 'agentnum', 'agent_custid', 'refnum', 'referral_custnum',
480 %     'last', 'first', 'ss', 'company',
481 %     'address1', 'address2', 'city',
482 %     'county', 'state', 'zip', 'country',
483 %     'daytime', 'night', 'fax',
484 %     'stateid', 'stateid_state',
485 %     
486 %     'same',
487 %     
488 %     'ship_last', 'ship_first', 'ship_company',
489 %     'ship_address1', 'ship_address2', 'ship_city',
490 %     'ship_county', 'ship_state', 'ship_zip', 'ship_country',
491 %     'ship_daytime','ship_night', 'ship_fax',
492 %     
493 %     'select', #XXX key
494 %
495 %     'payauto',
496 %     'payinfo', 'payinfo1', 'payinfo2', 'paytype',
497 %     'payname', 'paystate', 'exp_month', 'exp_year', 'paycvv',
498 %     'paystart_month', 'paystart_year', 'payissue',
499 %     'payip',
500 %     'paid',
501 %     
502 %     'tax',
503 %     'invoicing_list', 'invoicing_list_POST', 'invoicing_list_FAX',
504 %     'invoice_terms',
505 %     'spool_cdr',
506 %     'squelch_cdr'
507 %   ) {
508 %
509
510   <INPUT TYPE="hidden" NAME="<% $hidden %>" VALUE="">
511 % } 
512 %
513 % my $ro_comments = $conf->exists('cust_main-use_comments')?'':'readonly';
514 % if (!$ro_comments || $cust_main->comments) {
515
516 <BR>Comments
517 <% &ntable("#cccccc") %>
518   <TR>
519     <TD>
520       <TEXTAREA COLS=80 ROWS=5 WRAP="HARD" NAME="comments" <%$ro_comments%>><% $cust_main->comments %></TEXTAREA>
521     </TD>
522   </TR>
523 </TABLE>
524 %
525 % }
526 %
527 %unless ( $custnum ) {
528 %  # pry the wrong place for this logic.  also pretty expensive
529 %  #use FS::part_pkg;
530 %
531 %  #false laziness, copied from FS::cust_pkg::order
532 %  my $pkgpart;
533 %  my @agents = $FS::CurrentUser::CurrentUser->agents;
534 %  if ( scalar(@agents) == 1 ) {
535 %    # $pkgpart->{PKGPART} is true iff $custnum may purchase PKGPART
536 %    $pkgpart = $agents[0]->pkgpart_hashref;
537 %  } else {
538 %    #can't know (agent not chosen), so, allow all
539 %    my %typenum;
540 %    foreach my $agent ( @agents ) {
541 %      next if $typenum{$agent->typenum}++;
542 %      #fixed in 5.004_05 #$pkgpart->{$_}++ foreach keys %{ $agent->pkgpart_hashref }
543 %      foreach ( keys %{ $agent->pkgpart_hashref } ) { $pkgpart->{$_}++; } #5.004_04 workaround
544 %    }
545 %  }
546 %  #eslaf
547 %
548 %  my @part_pkg = grep { $_->svcpart('svc_acct') && $pkgpart->{ $_->pkgpart } }
549 %    qsearch( 'part_pkg', { 'disabled' => '' }, '', 'ORDER BY pkg' ); # case?
550 %
551 %  if ( @part_pkg ) {
552 %
553 %    #    print "<BR><BR>First package", &itable("#cccccc", "0 ALIGN=LEFT"),
554 %    #apiabuse & undesirable wrapping
555 %
556 %    
557
558     <BR>First package
559     <% ntable("#cccccc") %>
560     
561       <TR>
562         <TD COLSPAN=2>
563           <% include('cust_main/select-domain.html',
564                        'pkgparts'      => \@part_pkg,
565                        'saved_pkgpart' => $saved_pkgpart,
566                        'saved_domsvc' => $saved_domsvc,
567                     )
568           %>
569         </TD>
570       </TR>
571
572 %        #false laziness: (mostly) copied from edit/svc_acct.cgi
573 %        #$ulen = $svc_acct->dbdef_table->column('username')->length;
574 %        my $ulen = dbdef->table('svc_acct')->column('username')->length;
575 %        my $ulen2 = $ulen+2;
576 %        my $passwordmax = $conf->config('passwordmax') || 8;
577 %        my $pmax2 = $passwordmax + 2;
578 %      
579
580     
581       <TR>
582         <TD ALIGN="right">Username</TD>
583         <TD>
584           <INPUT TYPE="text" NAME="username" VALUE="<% $username %>" SIZE=<% $ulen2 %> MAXLENGTH=<% $ulen %>>
585         </TD>
586       </TR>
587     
588       <TR>
589         <TD ALIGN="right">Domain</TD>
590         <TD>
591           <SELECT NAME="domsvc">
592             <OPTION>(none)</OPTION>
593           </SELECT>
594         </TD>
595       </TR>
596     
597       <TR>
598         <TD ALIGN="right">Password</TD>
599         <TD>
600           <INPUT TYPE="text" NAME="_password" VALUE="<% $password %>" SIZE=<% $pmax2 %> MAXLENGTH=<% $passwordmax %>>
601           (blank to generate)
602         </TD>
603       </TR>
604     
605       <TR>
606         <TD ALIGN="right">Access number</TD>
607         <TD><% FS::svc_acct_pop::popselector($popnum) %></TD>
608       </TR>
609     </TABLE>
610 % } 
611 % } 
612
613
614 <INPUT TYPE="hidden" NAME="otaker" VALUE="<% $cust_main->otaker %>">
615 <BR>
616 <INPUT TYPE="button" NAME="submitButton" ID="submitButton" VALUE="<% $custnum ?  "Apply Changes" : "Add Customer" %>" onClick="document.bottomform.submitButton.disabled=true; bottomfixup(this.form);">
617 <BR>
618 </FORM>
619
620 <% include('/elements/footer.html') %>
621
622 <%init>
623
624 die "access denied"
625   unless $FS::CurrentUser::CurrentUser->access_right('Edit customer');
626
627 #for misplaced logic below
628 #use FS::part_pkg;
629
630 #for false laziness below (now more properly lazy)
631 #use FS::svc_acct_pop;
632
633 #for (other) false laziness below
634 #use FS::agent;
635 #use FS::type_pkgs;
636
637 my $conf = new FS::Conf;
638
639 #get record
640
641 my($custnum, $username, $password, $popnum, $cust_main, $saved_pkgpart, $saved_domsvc);
642 my(@invoicing_list);
643 my ($ss,$stateid,$payinfo);
644 my $same = '';
645 if ( $cgi->param('error') ) {
646   $cust_main = new FS::cust_main ( {
647     map { $_, scalar($cgi->param($_)) } fields('cust_main')
648   } );
649   $custnum = $cust_main->custnum;
650   $saved_domsvc = $cgi->param('domsvc') || '';
651   if ( $saved_domsvc =~ /^(\d+)$/ ) {
652     $saved_domsvc = $1;
653   } else {
654     $saved_domsvc = '';
655   }
656   $saved_pkgpart = $cgi->param('pkgpart_svcpart') || '';
657   if ( $saved_pkgpart =~ /^(\d+)_/ ) {
658     $saved_pkgpart = $1;
659   } else {
660     $saved_pkgpart = '';
661   }
662   $username = $cgi->param('username');
663   $password = $cgi->param('_password');
664   $popnum = $cgi->param('popnum');
665   @invoicing_list = split( /\s*,\s*/, $cgi->param('invoicing_list') );
666   $same = $cgi->param('same');
667   $cust_main->setfield('paid' => $cgi->param('paid')) if $cgi->param('paid');
668   $ss = $cust_main->ss;           # don't mask an entered value on errors
669   $stateid = $cust_main->stateid; # don't mask an entered value on errors
670   $payinfo = $cust_main->payinfo; # don't mask an entered value on errors
671 } elsif ( $cgi->keywords ) { #editing
672   my( $query ) = $cgi->keywords;
673   $query =~ /^(\d+)$/;
674   $custnum=$1;
675   $cust_main = qsearchs('cust_main', { 'custnum' => $custnum } );
676   if ( $cust_main->dbdef_table->column('paycvv')
677        && length($cust_main->paycvv)             ) {
678     my $paycvv = $cust_main->paycvv;
679     $paycvv =~ s/./*/g;
680     $cust_main->paycvv($paycvv);
681   }
682   $saved_pkgpart = 0;
683   $saved_domsvc = 0;
684   $username = '';
685   $password = '';
686   $popnum = 0;
687   @invoicing_list = $cust_main->invoicing_list;
688   $ss = $cust_main->masked('ss');
689   $stateid = $cust_main->masked('stateid');
690   $payinfo = $cust_main->paymask;
691 } else {
692   $custnum='';
693   $cust_main = new FS::cust_main ( {} );
694   $cust_main->otaker( &getotaker );
695   $cust_main->referral_custnum( $cgi->param('referral_custnum') );
696   $saved_pkgpart = 0;
697   $saved_domsvc = 0;
698   $username = '';
699   $password = '';
700   $popnum = 0;
701   @invoicing_list = ();
702   push @invoicing_list, 'POST'
703     unless $conf->exists('disablepostalinvoicedefault');
704   $ss = '';
705   $stateid = '';
706   $payinfo = '';
707 }
708
709 my $error = $cgi->param('error');
710 $cgi->delete_all();
711 $cgi->param('error', $error);
712
713 my $action = $custnum ? 'Edit' : 'Add';
714 $action .= ": ". $cust_main->name if $custnum;
715
716 my $r = qq!<font color="#ff0000">*</font>&nbsp;!;
717
718 </%init>