1 <% include('/elements/header.html',
4 ' onUnload="myclose()"'
7 <% include('/elements/init_overlib.html') %>
9 <% include('/elements/error.html') %>
11 <FORM NAME="topform" STYLE="margin-bottom: 0">
12 <INPUT TYPE="hidden" NAME="custnum" VALUE="<% $custnum %>">
15 Customer #<B><% $cust_main->display_custnum %></B> -
16 <B><FONT COLOR="#<% $cust_main->statuscolor %>">
17 <% ucfirst($cust_main->status) %>
22 <% &ntable("#cccccc") %>
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 ),
34 % if ( $conf->exists('cust_main-edit_agent_custid') ) {
37 <TD ALIGN="right">Customer identifier</TD>
38 <TD><INPUT TYPE="text" NAME="agent_custid" VALUE="<% $cust_main->agent_custid %>"></TD>
43 <INPUT TYPE="hidden" NAME="agent_custid" VALUE="<% $cust_main->agent_custid %>">
47 %# referral (advertising source)
48 %my $refnum = $cust_main->refnum || $conf->config('referraldefault') || 0;
49 %if ( $custnum && ! $conf->exists('editreferrals') ) {
51 <INPUT TYPE="hidden" NAME="refnum" VALUE="<% $refnum %>">
55 <% include('/elements/tr-select-part_referral.html',
56 'curr_value' => $refnum
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 } )
70 <TD ALIGN="right">Referring customer</TD>
72 <A HREF="<% popurl(1) %>/cust_main.cgi?<% $cust_main->referral_custnum %>"><% $cust_main->referral_custnum %>: <% $referring_cust_main->name %></A>
75 <INPUT TYPE="hidden" NAME="referral_custnum" VALUE="<% $cust_main->referral_custnum %>">
76 % } elsif ( ! $conf->exists('disable_customer_referrals') ) {
80 <TD ALIGN="right">Referring customer</TD>
82 <!-- <INPUT TYPE="text" NAME="referral_custnum" VALUE=""> -->
83 <% include('/elements/search-cust_main.html',
84 'field_name' => 'referral_custnum',
92 <INPUT TYPE="hidden" NAME="referral_custnum" VALUE="">
100 % if ( $conf->exists('cust_main-enable_birthdate') ) {
103 <% ntable("#cccccc", 2) %>
104 <% include ('/elements/tr-input-date-field.html',
106 $cust_main->birthdate,
108 $conf->config('date_format') || "%m/%d/%Y",
116 <!-- contact info -->
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"';
124 % qw( last first company address1 address2 city county state zip country
125 % daytime night fax )
127 % $cust_main->set("ship_$_", $cust_main->get($_) );
133 <% include('cust_main/contact.html',
134 'cust_main' => $cust_main,
136 'onchange' => 'bill_changed(this)',
139 'stateid' => $stateid,
140 'same_checked' => $same_checked, #for address2 "Unit #" labeling
145 function bill_changed(what) {
146 if ( what.form.same.checked ) {
147 % for (qw( last first company address1 address2 city zip daytime night fax )) {
149 what.form.ship_<%$_%>.value = what.form.<%$_%>.value;
152 what.form.ship_country.selectedIndex = what.form.country.selectedIndex;
154 function fix_ship_county() {
155 what.form.ship_county.selectedIndex = what.form.county.selectedIndex;
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 );
163 ship_country_changed(what.form.ship_country, fix_ship_state );
167 function samechanged(what) {
168 if ( what.checked ) {
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';
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';
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';
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 = '';
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,
208 'disabled' => $ship_disabled,
213 <!-- billing info -->
215 <% include( 'cust_main/billing.html', $cust_main,
216 'payinfo' => $payinfo,
217 'invoicing_list' => \@invoicing_list,
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?
229 function bottomfixup(what) {
231 //i don't think we need to copy things between two forms anymore, modern
232 //browsers are fine with DIVs inside FORMs
234 var topvars = new Array(
237 'custnum', 'agentnum', 'agent_custid', 'refnum', 'referral_custnum',
239 'last', 'first', 'ss', 'company',
240 'address1', 'address2', 'city',
241 'county', 'state', 'zip', 'country',
242 'daytime', 'night', 'fax',
243 'stateid', 'stateid_state',
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',
257 var layervars = new Array(
259 'payinfo', 'payinfo1', 'payinfo2', 'paytype',
260 'payname', 'paystate', 'exp_month', 'exp_year', 'paycvv',
261 'paystart_month', 'paystart_year', 'payissue',
266 var billing_bottomvars = new Array(
268 'invoicing_list', 'invoicing_list_POST', 'invoicing_list_FAX',
274 for ( f=0; f < topvars.length; f++ ) {
275 var field = topvars[f];
276 copyelement( document.topform.elements[field],
277 document.bottomform.elements[field]
281 var layerform = document.topform.select.options[document.topform.select.selectedIndex].value;
282 for ( f=0; f < layervars.length; f++ ) {
283 var field = layervars[f];
284 copyelement( document.forms[layerform].elements[field],
285 document.bottomform.elements[field]
289 for ( f=0; f < billing_bottomvars.length; f++ ) {
290 var field = billing_bottomvars[f];
291 copyelement( document.billing_bottomform.elements[field],
292 document.bottomform.elements[field]
296 //this part does USPS address correction
298 // XXX should this be first and should we update the form fields that are
301 //var state_el = document.bottomform.elements['state'];
303 //address_standardize(
304 var cust_main = new Array(
305 'company', document.bottomform.elements['company'].value,
306 'address1', document.bottomform.elements['address1'].value,
307 'address2', document.bottomform.elements['address2'].value,
308 'city', document.bottomform.elements['city'].value,
309 'state', document.bottomform.elements['state'].value,
310 //'state', state_el.options[ state_el.selectedIndex ].value,
311 'zip', document.bottomform.elements['zip'].value,
313 'ship_company', document.bottomform.elements['ship_company'].value,
314 'ship_address1', document.bottomform.elements['ship_address1'].value,
315 'ship_address2', document.bottomform.elements['ship_address2'].value,
316 'ship_city', document.bottomform.elements['ship_city'].value,
317 'ship_state', document.bottomform.elements['ship_state'].value,
318 //'ship_state', state_el.options[ state_el.selectedIndex ].value,
319 'ship_zip', document.bottomform.elements['ship_zip'].value
322 address_standardize( cust_main, update_address );
326 var standardize_address;
328 function update_address(arg) {
330 var argsHash = eval('(' + arg + ')');
332 var changed = argsHash['address_standardized'];
333 var ship_changed = argsHash['ship_address_standardized'];
334 var error = argsHash['error'];
335 var ship_error = argsHash['ship_error'];
338 standardize_address = function () {
341 document.bottomform.elements['company'].value = argsHash['new_company'];
342 document.bottomform.elements['address1'].value = argsHash['new_address1'];
343 document.bottomform.elements['address2'].value = argsHash['new_address2'];
344 document.bottomform.elements['city'].value = argsHash['new_city'];
345 document.bottomform.elements['state'].value = argsHash['new_state'];
346 //'state', state_el.options[ state_el.selectedIndex ].value,
347 document.bottomform.elements['zip'].value = argsHash['new_zip'];
350 if ( ship_changed ) {
351 document.bottomform.elements['ship_company'].value = argsHash['new_ship_company'];
352 document.bottomform.elements['ship_address1'].value = argsHash['new_ship_address1'];
353 document.bottomform.elements['ship_address2'].value = argsHash['new_ship_address2'];
354 document.bottomform.elements['ship_city'].value = argsHash['new_ship_city'];
355 document.bottomform.elements['ship_state'].value = argsHash['new_ship_state'];
356 //'state', state_el.options[ state_el.selectedIndex ].value,
357 document.bottomform.elements['ship_zip'].value = argsHash['new_ship_zip'];
362 % if ( $conf->exists('enable_taxproducts') ) {
364 if ( ( error || ship_error ) &&
365 ( document.bottomform.elements['country'].value == 'CA' ||
366 document.bottomform.elements['country'].value == 'US'
371 var url = "cust_main/choose_tax_location.html?data_vendor=cch-zip;city="+document.bottomform.elements['city'].value+";state="+document.bottomform.elements['state'].value+";zip="+document.bottomform.elements['zip'].value+";country="+document.bottomform.elements['country'].value+";";
373 OLgetAJAX( url, update_geocode, 300 );
379 if ( changed || ship_changed ) {
381 % if ( $conf->exists('cust_main-auto_standardize_address') ) {
383 standardize_address();
384 document.bottomform.submit();
388 // popup a confirmation popup
391 '<CENTER><BR><B>Confirm address standardization</B><BR><BR>' +
396 confirm_change = confirm_change +
397 '<TR><TH>Entered billing address</TH>' +
398 '<TH>Standardized billing address</TH></TR>';
399 // + '<TR><TD> </TD><TD> </TD></TR>';
401 if ( argsHash['company'] || argsHash['new_company'] ) {
402 confirm_change = confirm_change +
403 '<TR><TD>' + argsHash['company'] +
404 '</TD><TD>' + argsHash['new_company'] + '</TD></TR>';
407 confirm_change = confirm_change +
408 '<TR><TD>' + argsHash['address1'] +
409 '</TD><TD>' + argsHash['new_address1'] + '</TD></TR>' +
410 '<TR><TD>' + argsHash['address2'] +
411 '</TD><TD>' + argsHash['new_address2'] + '</TD></TR>' +
412 '<TR><TD>' + argsHash['city'] + ', ' + argsHash['state'] + ' ' + argsHash['zip'] +
413 '</TD><TD>' + argsHash['new_city'] + ', ' + argsHash['new_state'] + ' ' + argsHash['new_zip'] + '</TD></TR>' +
414 '<TR><TD> </TD><TD> </TD></TR>';
418 if ( ship_changed ) {
420 confirm_change = confirm_change +
421 '<TR><TH>Entered service address</TH>' +
422 '<TH>Standardized service address</TH></TR>';
423 // + '<TR><TD> </TD><TD> </TD></TR>';
425 if ( argsHash['ship_company'] || argsHash['new_ship_company'] ) {
426 confirm_change = confirm_change +
427 '<TR><TD>' + argsHash['ship_company'] +
428 '</TD><TD>' + argsHash['new_ship_company'] + '</TD></TR>';
431 confirm_change = confirm_change +
432 '<TR><TD>' + argsHash['ship_address1'] +
433 '</TD><TD>' + argsHash['new_ship_address1'] + '</TD></TR>' +
434 '<TR><TD>' + argsHash['ship_address2'] +
435 '</TD><TD>' + argsHash['new_ship_address2'] + '</TD></TR>' +
436 '<TR><TD>' + argsHash['ship_city'] + ', ' + argsHash['ship_state'] + ' ' + argsHash['ship_zip'] +
437 '</TD><TD>' + argsHash['new_ship_city'] + ', ' + argsHash['new_ship_state'] + ' ' + argsHash['new_ship_zip'] + '</TD></TR>' +
438 '<TR><TD> </TD><TD> </TD></TR>';
442 var addresses = 'address';
444 if ( changed && ship_changed ) {
445 addresses = 'addresses';
446 height = 396; // #what
449 confirm_change = confirm_change +
451 '<BUTTON TYPE="button" onClick="document.bottomform.submit();"><IMG SRC="<%$p%>images/error.png" ALT=""> Use entered ' + addresses + '</BUTTON>' +
453 '<BUTTON TYPE="button" onClick="standardize_address(); document.bottomform.submit();"><IMG SRC="<%$p%>images/tick.png" ALT=""> Use standardized ' + addresses + '</BUTTON>' +
455 '<TR><TD COLSPAN=2 ALIGN="center">' +
456 '<BUTTON TYPE="button" onClick="document.bottomform.submitButton.disabled=false; parent.cClick();"><IMG SRC="<%$p%>images/cross.png" ALT=""> Cancel submission</BUTTON></TD></TR>' +
460 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 );
466 document.bottomform.submit();
472 function update_geocode() {
475 set_geocode = function (what) {
477 //alert(what.options[what.selectedIndex].value);
478 var argsHash = eval('(' + what.options[what.selectedIndex].value + ')');
479 document.bottomform.elements['city'].value = argsHash['city'];
480 document.bottomform.elements['state'].value = argsHash['state'];
481 document.bottomform.elements['zip'].value = argsHash['zip'];
482 document.bottomform.elements['geocode'].value = argsHash['geocode'];
488 overlib( OLresponseAJAX, CAPTION, 'Select tax location', STICKY, AUTOSTATUSCAP, CLOSETEXT, '', MIDX, 0, MIDY, 0, DRAGGABLE, WIDTH, 576, HEIGHT, 268, BGCOLOR, '#333399', CGCOLOR, '#333399', TEXTSIZE, 3 );
492 function copyelement(from, to) {
493 if ( from == undefined ) {
495 } else if ( from.type == 'select-one' ) {
496 to.value = from.options[from.selectedIndex].value;
497 //alert(from + " (" + from.type + "): " + to.name + " => (" + from.selectedIndex + ") " + to.value);
498 } else if ( from.type == 'checkbox' ) {
499 if ( from.checked ) {
500 to.value = from.value;
505 if ( from.value == undefined ) {
508 to.value = from.value;
511 //alert(from + " (" + from.type + "): " + to.name + " => " + to.value);
516 <FORM ACTION="<% popurl(1) %>process/cust_main.cgi" METHOD=POST NAME="bottomform" STYLE="margin-top: 0; margin-bottom: 0">
517 % foreach my $hidden (
520 % 'custnum', 'agentnum', 'agent_custid', 'refnum', 'referral_custnum',
521 % 'last', 'first', 'ss', 'company',
522 % 'address1', 'address2', 'city',
523 % 'county', 'state', 'zip', 'country',
524 % 'daytime', 'night', 'fax',
525 % 'stateid', 'stateid_state',
529 % 'ship_last', 'ship_first', 'ship_company',
530 % 'ship_address1', 'ship_address2', 'ship_city',
531 % 'ship_county', 'ship_state', 'ship_zip', 'ship_country',
532 % 'ship_daytime','ship_night', 'ship_fax',
539 % 'payinfo', 'payinfo1', 'payinfo2', 'paytype',
540 % 'payname', 'paystate', 'exp_month', 'exp_year', 'paycvv',
541 % 'paystart_month', 'paystart_year', 'payissue',
546 % 'invoicing_list', 'invoicing_list_POST', 'invoicing_list_FAX',
553 <INPUT TYPE="hidden" NAME="<% $hidden %>" VALUE="">
556 % my $ro_comments = $conf->exists('cust_main-use_comments')?'':'readonly';
557 % if (!$ro_comments || $cust_main->comments) {
560 <% &ntable("#cccccc") %>
563 <TEXTAREA COLS=80 ROWS=5 WRAP="HARD" NAME="comments" <%$ro_comments%>><% $cust_main->comments %></TEXTAREA>
570 %unless ( $custnum ) {
571 % # pry the wrong place for this logic. also pretty expensive
574 % #false laziness, copied from FS::cust_pkg::order
577 % my @agents = $FS::CurrentUser::CurrentUser->agents;
578 % if ( scalar(@agents) == 1 ) {
579 % # $pkgpart->{PKGPART} is true iff $custnum may purchase PKGPART
580 % $pkgpart = $agents[0]->pkgpart_hashref;
581 % $agentnum = $agents[0]->agentnum;
583 % #can't know (agent not chosen), so, allow all
586 % foreach my $agent ( @agents ) {
587 % next if $typenum{$agent->typenum}++;
588 % $pkgpart->{$_}++ foreach keys %{ $agent->pkgpart_hashref }
593 % my @part_pkg = grep { $_->svcpart('svc_acct')
594 % && ( $pkgpart->{ $_->pkgpart }
595 % || $agentnum eq 'all'
596 % || ( $agentnum ne 'all'
599 % && $_->agentnum == $agentnum
603 % qsearch( 'part_pkg', { 'disabled' => '' }, '', 'ORDER BY pkg' ); # case?
607 % # print "<BR><BR>First package", &itable("#cccccc", "0 ALIGN=LEFT"),
608 % #apiabuse & undesirable wrapping
613 <% ntable("#cccccc") %>
617 <% include('cust_main/select-domain.html',
618 'pkgparts' => \@part_pkg,
619 'saved_pkgpart' => $saved_pkgpart,
620 'saved_domsvc' => $saved_domsvc,
626 % #false laziness: (mostly) copied from edit/svc_acct.cgi
627 % #$ulen = $svc_acct->dbdef_table->column('username')->length;
628 % my $ulen = dbdef->table('svc_acct')->column('username')->length;
629 % my $ulen2 = $ulen+2;
630 % my $passwordmax = $conf->config('passwordmax') || 8;
631 % my $pmax2 = $passwordmax + 2;
636 <TD ALIGN="right">Username</TD>
638 <INPUT TYPE="text" NAME="username" VALUE="<% $username %>" SIZE=<% $ulen2 %> MAXLENGTH=<% $ulen %>>
643 <TD ALIGN="right">Domain</TD>
645 <SELECT NAME="domsvc">
646 <OPTION>(none)</OPTION>
652 <TD ALIGN="right">Password</TD>
654 <INPUT TYPE="text" NAME="_password" VALUE="<% $password %>" SIZE=<% $pmax2 %> MAXLENGTH=<% $passwordmax %>>
660 <TD ALIGN="right">Access number</TD>
661 <TD><% FS::svc_acct_pop::popselector($popnum) %></TD>
668 <INPUT TYPE="hidden" NAME="otaker" VALUE="<% $cust_main->otaker %>">
670 <INPUT TYPE="button" NAME="submitButton" ID="submitButton" VALUE="<% $custnum ? "Apply Changes" : "Add Customer" %>" onClick="document.bottomform.submitButton.disabled=true; bottomfixup(this.form);">
674 <% include('/elements/footer.html') %>
679 unless $FS::CurrentUser::CurrentUser->access_right('Edit customer');
681 #for misplaced logic below
684 #for false laziness below (now more properly lazy)
685 #use FS::svc_acct_pop;
687 #for (other) false laziness below
691 my $conf = new FS::Conf;
695 my($custnum, $username, $password, $popnum, $cust_main, $saved_pkgpart, $saved_domsvc);
697 my ($ss,$stateid,$payinfo);
699 if ( $cgi->param('error') ) {
700 $cust_main = new FS::cust_main ( {
701 map { $_, scalar($cgi->param($_)) } fields('cust_main')
703 $custnum = $cust_main->custnum;
704 $saved_domsvc = $cgi->param('domsvc') || '';
705 if ( $saved_domsvc =~ /^(\d+)$/ ) {
710 $saved_pkgpart = $cgi->param('pkgpart_svcpart') || '';
711 if ( $saved_pkgpart =~ /^(\d+)_/ ) {
716 $username = $cgi->param('username');
717 $password = $cgi->param('_password');
718 $popnum = $cgi->param('popnum');
719 @invoicing_list = split( /\s*,\s*/, $cgi->param('invoicing_list') );
720 $same = $cgi->param('same');
721 $cust_main->setfield('paid' => $cgi->param('paid')) if $cgi->param('paid');
722 $ss = $cust_main->ss; # don't mask an entered value on errors
723 $stateid = $cust_main->stateid; # don't mask an entered value on errors
724 $payinfo = $cust_main->payinfo; # don't mask an entered value on errors
725 } elsif ( $cgi->keywords ) { #editing
726 my( $query ) = $cgi->keywords;
729 $cust_main = qsearchs('cust_main', { 'custnum' => $custnum } );
730 if ( $cust_main->dbdef_table->column('paycvv')
731 && length($cust_main->paycvv) ) {
732 my $paycvv = $cust_main->paycvv;
734 $cust_main->paycvv($paycvv);
741 @invoicing_list = $cust_main->invoicing_list;
742 $ss = $cust_main->masked('ss');
743 $stateid = $cust_main->masked('stateid');
744 $payinfo = $cust_main->paymask;
747 $cust_main = new FS::cust_main ( {} );
748 $cust_main->otaker( &getotaker );
749 $cust_main->referral_custnum( $cgi->param('referral_custnum') );
755 @invoicing_list = ();
756 push @invoicing_list, 'POST'
757 unless $conf->exists('disablepostalinvoicedefault');
763 my $error = $cgi->param('error');
765 $cgi->param('error', $error);
767 my $action = $custnum ? 'Edit' : 'Add';
768 $action .= ": ". $cust_main->name if $custnum;
770 my $r = qq!<font color="#ff0000">*</font> !;