1 <% include('/elements/header.html',
4 ' onUnload="myclose()"'
7 <% include('/elements/init_overlib.html') %>
8 <SCRIPT SRC="<% $fsurl %>elements/ajaxcontentmws.js" TYPE="text/javascript"></SCRIPT>
10 <% include('/elements/error.html') %>
12 <FORM NAME="topform" STYLE="margin-bottom: 0">
13 <INPUT TYPE="hidden" NAME="custnum" VALUE="<% $custnum %>">
16 Customer #<B><% $cust_main->display_custnum %></B> -
17 <B><FONT COLOR="#<% $cust_main->statuscolor %>">
18 <% ucfirst($cust_main->status) %>
23 <% &ntable("#cccccc") %>
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 ),
35 % if ( $conf->exists('cust_main-edit_agent_custid') ) {
38 <TD ALIGN="right">Customer identifier</TD>
39 <TD><INPUT TYPE="text" NAME="agent_custid" VALUE="<% $cust_main->agent_custid %>"></TD>
44 <INPUT TYPE="hidden" NAME="agent_custid" VALUE="<% $cust_main->agent_custid %>">
48 %# referral (advertising source)
49 %my $refnum = $cust_main->refnum || $conf->config('referraldefault') || 0;
50 %if ( $custnum && ! $conf->exists('editreferrals') ) {
52 <INPUT TYPE="hidden" NAME="refnum" VALUE="<% $refnum %>">
56 <% include('/elements/tr-select-part_referral.html',
57 'curr_value' => $refnum
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 } )
71 <TD ALIGN="right">Referring customer</TD>
73 <A HREF="<% popurl(1) %>/cust_main.cgi?<% $cust_main->referral_custnum %>"><% $cust_main->referral_custnum %>: <% $referring_cust_main->name %></A>
76 <INPUT TYPE="hidden" NAME="referral_custnum" VALUE="<% $cust_main->referral_custnum %>">
77 % } elsif ( ! $conf->exists('disable_customer_referrals') ) {
81 <TD ALIGN="right">Referring customer</TD>
83 <!-- <INPUT TYPE="text" NAME="referral_custnum" VALUE=""> -->
84 <% include('/elements/search-cust_main.html',
85 'field_name' => 'referral_custnum',
93 <INPUT TYPE="hidden" NAME="referral_custnum" VALUE="">
101 % if ( $conf->exists('cust_main-enable_birthdate') ) {
104 <% ntable("#cccccc", 2) %>
105 <% include ('/elements/tr-input-date-field.html',
107 $cust_main->birthdate,
109 $conf->config('date_format') || "%m/%d/%Y",
117 <!-- contact info -->
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"';
125 % qw( last first company address1 address2 city county state zip country
126 % daytime night fax )
128 % $cust_main->set("ship_$_", $cust_main->get($_) );
134 <% include('cust_main/contact.html',
135 'cust_main' => $cust_main,
137 'onchange' => 'bill_changed(this)',
140 'stateid' => $stateid,
141 'same_checked' => $same_checked, #for address2 "Unit #" labeling
146 function bill_changed(what) {
147 if ( what.form.same.checked ) {
148 % for (qw( last first company address1 address2 city zip daytime night fax )) {
150 what.form.ship_<%$_%>.value = what.form.<%$_%>.value;
153 what.form.ship_country.selectedIndex = what.form.country.selectedIndex;
155 function fix_ship_county() {
156 what.form.ship_county.selectedIndex = what.form.county.selectedIndex;
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 );
164 ship_country_changed(what.form.ship_country, fix_ship_state );
168 function samechanged(what) {
169 if ( what.checked ) {
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';
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';
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';
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 = '';
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,
209 'disabled' => $ship_disabled,
214 <!-- billing info -->
216 <% include( 'cust_main/billing.html', $cust_main,
217 'payinfo' => $payinfo,
218 'invoicing_list' => \@invoicing_list,
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?
230 function bottomfixup(what) {
232 //i don't think we need to copy things between two forms anymore, modern
233 //browsers are fine with DIVs inside FORMs
235 var topvars = new Array(
238 'custnum', 'agentnum', 'agent_custid', 'refnum', 'referral_custnum',
240 'last', 'first', 'ss', 'company',
241 'address1', 'address2', 'city',
242 'county', 'state', 'zip', 'country',
243 'daytime', 'night', 'fax',
244 'stateid', 'stateid_state',
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',
258 var layervars = new Array(
260 'payinfo', 'payinfo1', 'payinfo2', 'paytype',
261 'payname', 'paystate', 'exp_month', 'exp_year', 'paycvv',
262 'paystart_month', 'paystart_year', 'payissue',
267 var billing_bottomvars = new Array(
269 'invoicing_list', 'invoicing_list_POST', 'invoicing_list_FAX',
275 for ( f=0; f < topvars.length; f++ ) {
276 var field = topvars[f];
277 copyelement( document.topform.elements[field],
278 document.bottomform.elements[field]
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]
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]
297 //this part does USPS address correction
299 // XXX should this be first and should we update the form fields that are
302 //var state_el = document.bottomform.elements['state'];
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,
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
323 address_standardize( cust_main, update_address );
327 var standardize_address;
329 function update_address(arg) {
331 var argsHash = eval('(' + arg + ')');
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'];
339 standardize_address = function () {
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'];
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'];
363 if ( error || ship_error ) {
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+";";
367 OLgetAJAX( url, update_geocode, 300 );
370 } else if ( changed || ship_changed ) {
372 % if ( $conf->exists('cust_main-auto_standardize_address') ) {
374 standardize_address();
375 document.bottomform.submit();
379 // popup a confirmation popup
382 '<CENTER><BR><B>Confirm address standardization</B><BR><BR>' +
387 confirm_change = confirm_change +
388 '<TR><TH>Entered billing address</TH>' +
389 '<TH>Standardized billing address</TH></TR>';
390 // + '<TR><TD> </TD><TD> </TD></TR>';
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>';
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> </TD><TD> </TD></TR>';
409 if ( ship_changed ) {
411 confirm_change = confirm_change +
412 '<TR><TH>Entered service address</TH>' +
413 '<TH>Standardized service address</TH></TR>';
414 // + '<TR><TD> </TD><TD> </TD></TR>';
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>';
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> </TD><TD> </TD></TR>';
433 var addresses = 'address';
435 if ( changed && ship_changed ) {
436 addresses = 'addresses';
437 height = 396; // #what
440 confirm_change = confirm_change +
442 '<BUTTON TYPE="button" onClick="document.bottomform.submit();"><IMG SRC="<%$p%>images/error.png" ALT=""> Use entered ' + addresses + '</BUTTON>' +
444 '<BUTTON TYPE="button" onClick="standardize_address(); document.bottomform.submit();"><IMG SRC="<%$p%>images/tick.png" ALT=""> Use standardized ' + addresses + '</BUTTON>' +
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>' +
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 );
457 document.bottomform.submit();
463 function update_geocode() {
466 set_geocode = function (what) {
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'];
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 );
483 function copyelement(from, to) {
484 if ( from == undefined ) {
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;
496 if ( from.value == undefined ) {
499 to.value = from.value;
502 //alert(from + " (" + from.type + "): " + to.name + " => " + to.value);
507 <FORM ACTION="<% popurl(1) %>process/cust_main.cgi" METHOD=POST NAME="bottomform" STYLE="margin-top: 0; margin-bottom: 0">
508 % foreach my $hidden (
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',
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',
530 % 'payinfo', 'payinfo1', 'payinfo2', 'paytype',
531 % 'payname', 'paystate', 'exp_month', 'exp_year', 'paycvv',
532 % 'paystart_month', 'paystart_year', 'payissue',
537 % 'invoicing_list', 'invoicing_list_POST', 'invoicing_list_FAX',
544 <INPUT TYPE="hidden" NAME="<% $hidden %>" VALUE="">
547 % my $ro_comments = $conf->exists('cust_main-use_comments')?'':'readonly';
548 % if (!$ro_comments || $cust_main->comments) {
551 <% &ntable("#cccccc") %>
554 <TEXTAREA COLS=80 ROWS=5 WRAP="HARD" NAME="comments" <%$ro_comments%>><% $cust_main->comments %></TEXTAREA>
561 %unless ( $custnum ) {
562 % # pry the wrong place for this logic. also pretty expensive
565 % #false laziness, copied from FS::cust_pkg::order
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;
572 % #can't know (agent not chosen), so, allow all
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
582 % my @part_pkg = grep { $_->svcpart('svc_acct') && $pkgpart->{ $_->pkgpart } }
583 % qsearch( 'part_pkg', { 'disabled' => '' }, '', 'ORDER BY pkg' ); # case?
587 % # print "<BR><BR>First package", &itable("#cccccc", "0 ALIGN=LEFT"),
588 % #apiabuse & undesirable wrapping
593 <% ntable("#cccccc") %>
597 <% include('cust_main/select-domain.html',
598 'pkgparts' => \@part_pkg,
599 'saved_pkgpart' => $saved_pkgpart,
600 'saved_domsvc' => $saved_domsvc,
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;
616 <TD ALIGN="right">Username</TD>
618 <INPUT TYPE="text" NAME="username" VALUE="<% $username %>" SIZE=<% $ulen2 %> MAXLENGTH=<% $ulen %>>
623 <TD ALIGN="right">Domain</TD>
625 <SELECT NAME="domsvc">
626 <OPTION>(none)</OPTION>
632 <TD ALIGN="right">Password</TD>
634 <INPUT TYPE="text" NAME="_password" VALUE="<% $password %>" SIZE=<% $pmax2 %> MAXLENGTH=<% $passwordmax %>>
640 <TD ALIGN="right">Access number</TD>
641 <TD><% FS::svc_acct_pop::popselector($popnum) %></TD>
648 <INPUT TYPE="hidden" NAME="otaker" VALUE="<% $cust_main->otaker %>">
650 <INPUT TYPE="button" NAME="submitButton" ID="submitButton" VALUE="<% $custnum ? "Apply Changes" : "Add Customer" %>" onClick="document.bottomform.submitButton.disabled=true; bottomfixup(this.form);">
654 <% include('/elements/footer.html') %>
659 unless $FS::CurrentUser::CurrentUser->access_right('Edit customer');
661 #for misplaced logic below
664 #for false laziness below (now more properly lazy)
665 #use FS::svc_acct_pop;
667 #for (other) false laziness below
671 my $conf = new FS::Conf;
675 my($custnum, $username, $password, $popnum, $cust_main, $saved_pkgpart, $saved_domsvc);
677 my ($ss,$stateid,$payinfo);
679 if ( $cgi->param('error') ) {
680 $cust_main = new FS::cust_main ( {
681 map { $_, scalar($cgi->param($_)) } fields('cust_main')
683 $custnum = $cust_main->custnum;
684 $saved_domsvc = $cgi->param('domsvc') || '';
685 if ( $saved_domsvc =~ /^(\d+)$/ ) {
690 $saved_pkgpart = $cgi->param('pkgpart_svcpart') || '';
691 if ( $saved_pkgpart =~ /^(\d+)_/ ) {
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;
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;
714 $cust_main->paycvv($paycvv);
721 @invoicing_list = $cust_main->invoicing_list;
722 $ss = $cust_main->masked('ss');
723 $stateid = $cust_main->masked('stateid');
724 $payinfo = $cust_main->paymask;
727 $cust_main = new FS::cust_main ( {} );
728 $cust_main->otaker( &getotaker );
729 $cust_main->referral_custnum( $cgi->param('referral_custnum') );
735 @invoicing_list = ();
736 push @invoicing_list, 'POST'
737 unless $conf->exists('disablepostalinvoicedefault');
743 my $error = $cgi->param('error');
745 $cgi->param('error', $error);
747 my $action = $custnum ? 'Edit' : 'Add';
748 $action .= ": ". $cust_main->name if $custnum;
750 my $r = qq!<font color="#ff0000">*</font> !;