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><% $custnum %></B> -
16 <B><FONT COLOR="#<% $cust_main->statuscolor %>">
17 <% ucfirst($cust_main->status) %>
23 <% &ntable("#cccccc") %>
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 ),
35 <!-- referral (advertising source) -->
37 %my $refnum = $cust_main->refnum || $conf->config('referraldefault') || 0;
38 %if ( $custnum && ! $conf->exists('editreferrals') ) {
42 <INPUT TYPE="hidden" NAME="refnum" VALUE="<% $refnum %>">
46 <% include('/elements/tr-select-part_referral.html',
47 'curr_value' => $refnum
53 <!-- referring customer -->
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 } )
64 <TD ALIGN="right">Referring customer</TD>
66 <A HREF="<% popurl(1) %>/cust_main.cgi?<% $cust_main->referral_custnum %>"><% $cust_main->referral_custnum %>: <% $referring_cust_main->name %></A>
69 <INPUT TYPE="hidden" NAME="referral_custnum" VALUE="<% $cust_main->referral_custnum %>">
70 % } elsif ( ! $conf->exists('disable_customer_referrals') ) {
74 <TD ALIGN="right">Referring customer</TD>
76 <!-- <INPUT TYPE="text" NAME="referral_custnum" VALUE=""> -->
77 <% include('/elements/search-cust_main.html',
78 'field_name' => 'referral_custnum',
86 <INPUT TYPE="hidden" NAME="referral_custnum" VALUE="">
94 % if ( $conf->exists('cust_main-enable_birthdate') ) {
97 <% ntable("#cccccc", 2) %>
98 <% include ('/elements/tr-input-date-field.html',
100 $cust_main->birthdate,
102 $conf->config('date_format') || "%m/%d/%Y",
110 <!-- contact info -->
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"';
118 % qw( last first company address1 address2 city county state zip country
119 % daytime night fax )
121 % $cust_main->set("ship_$_", $cust_main->get($_) );
127 <% include('cust_main/contact.html',
128 'cust_main' => $cust_main,
130 'onchange' => 'bill_changed(this)',
133 'stateid' => $stateid,
134 'same_checked' => $same_checked, #for address2 "Unit #" labeling
139 function bill_changed(what) {
140 if ( what.form.same.checked ) {
141 % for (qw( last first company address1 address2 city zip daytime night fax )) {
143 what.form.ship_<%$_%>.value = what.form.<%$_%>.value;
146 what.form.ship_country.selectedIndex = what.form.country.selectedIndex;
148 function fix_ship_county() {
149 what.form.ship_county.selectedIndex = what.form.county.selectedIndex;
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 );
157 ship_country_changed(what.form.ship_country, fix_ship_state );
161 function samechanged(what) {
162 if ( what.checked ) {
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';
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';
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';
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 = '';
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,
202 'disabled' => $ship_disabled,
207 <!-- billing info -->
209 <% include( 'cust_main/billing.html', $cust_main,
210 'payinfo' => $payinfo,
211 'invoicing_list' => \@invoicing_list,
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?
223 function bottomfixup(what) {
225 //i don't think we need to copy things between two forms anymore, modern
226 //browsers are fine with DIVs inside FORMs
228 var topvars = new Array(
231 'custnum', 'agentnum', 'refnum', 'referral_custnum',
233 'last', 'first', 'ss', 'company',
234 'address1', 'address2', 'city',
235 'county', 'state', 'zip', 'country',
236 'daytime', 'night', 'fax',
237 'stateid', 'stateid_state',
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',
249 var layervars = new Array(
251 'payinfo', 'payinfo1', 'payinfo2', 'paytype',
252 'payname', 'paystate', 'exp_month', 'exp_year', 'paycvv',
253 'paystart_month', 'paystart_year', 'payissue',
258 var billing_bottomvars = new Array(
260 'invoicing_list', 'invoicing_list_POST', 'invoicing_list_FAX',
265 for ( f=0; f < topvars.length; f++ ) {
266 var field = topvars[f];
267 copyelement( document.topform.elements[field],
268 document.bottomform.elements[field]
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]
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]
287 //this part does USPS address correction
289 // XXX should this be first and should we update the form fields that are
292 //var state_el = document.bottomform.elements['state'];
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,
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
313 address_standardize( cust_main, update_address );
317 var standardize_address;
319 function update_address(arg) {
321 var argsHash = eval('(' + arg + ')');
323 var changed = argsHash['address_standardized'];
324 var ship_changed = argsHash['ship_address_standardized'];
327 standardize_address = function () {
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'];
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'];
351 if ( changed || ship_changed ) {
353 % if ( $conf->exists('cust_main-auto_standardize_address') ) {
355 standardize_address();
356 document.bottomform.submit();
360 // popup a confirmation popup
363 '<CENTER><BR><B>Confirm address standardization</B><BR><BR>' +
368 confirm_change = confirm_change +
369 '<TR><TH>Entered billing address</TH>' +
370 '<TH>Standardized billing address</TH></TR>';
371 // + '<TR><TD> </TD><TD> </TD></TR>';
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>';
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> </TD><TD> </TD></TR>';
390 if ( ship_changed ) {
392 confirm_change = confirm_change +
393 '<TR><TH>Entered service address</TH>' +
394 '<TH>Standardized service address</TH></TR>';
395 // + '<TR><TD> </TD><TD> </TD></TR>';
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>';
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> </TD><TD> </TD></TR>';
414 var addresses = 'address';
416 if ( changed && ship_changed ) {
417 addresses = 'addresses';
418 height = 396; // #what
421 confirm_change = confirm_change +
423 '<BUTTON TYPE="button" onClick="document.bottomform.submit();"><IMG SRC="<%$p%>images/error.png" ALT=""> Use entered ' + addresses + '</BUTTON>' +
425 '<BUTTON TYPE="button" onClick="standardize_address(); document.bottomform.submit();"><IMG SRC="<%$p%>images/tick.png" ALT=""> Use standardized ' + addresses + '</BUTTON>' +
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>' +
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 );
438 document.bottomform.submit();
444 function copyelement(from, to) {
445 if ( from == undefined ) {
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;
457 if ( from.value == undefined ) {
460 to.value = from.value;
463 //alert(from + " (" + from.type + "): " + to.name + " => " + to.value);
468 <FORM ACTION="<% popurl(1) %>process/cust_main.cgi" METHOD=POST NAME="bottomform" STYLE="margin-top: 0; margin-bottom: 0">
469 % foreach my $hidden (
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',
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',
489 % 'payinfo', 'payinfo1', 'payinfo2', 'paytype',
490 % 'payname', 'paystate', 'exp_month', 'exp_year', 'paycvv',
491 % 'paystart_month', 'paystart_year', 'payissue',
496 % 'invoicing_list', 'invoicing_list_POST', 'invoicing_list_FAX',
502 <INPUT TYPE="hidden" NAME="<% $hidden %>" VALUE="">
505 % my $ro_comments = $conf->exists('cust_main-use_comments')?'':'readonly';
506 % if (!$ro_comments || $cust_main->comments) {
509 <% &ntable("#cccccc") %>
512 <TEXTAREA COLS=80 ROWS=5 WRAP="HARD" NAME="comments" <%$ro_comments%>><% $cust_main->comments %></TEXTAREA>
519 %unless ( $custnum ) {
520 % # pry the wrong place for this logic. also pretty expensive
523 % #false laziness, copied from FS::cust_pkg::order
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;
530 % #can't know (agent not chosen), so, allow all
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
540 % my @part_pkg = grep { $_->svcpart('svc_acct') && $pkgpart->{ $_->pkgpart } }
541 % qsearch( 'part_pkg', { 'disabled' => '' }, '', 'ORDER BY pkg' ); # case?
545 % # print "<BR><BR>First package", &itable("#cccccc", "0 ALIGN=LEFT"),
546 % #apiabuse & undesirable wrapping
551 <% ntable("#cccccc") %>
555 <% include('cust_main/select-domain.html',
556 'pkgparts' => \@part_pkg,
557 'saved_pkgpart' => $saved_pkgpart,
558 'saved_domsvc' => $saved_domsvc,
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;
574 <TD ALIGN="right">Username</TD>
576 <INPUT TYPE="text" NAME="username" VALUE="<% $username %>" SIZE=<% $ulen2 %> MAXLENGTH=<% $ulen %>>
581 <TD ALIGN="right">Domain</TD>
583 <SELECT NAME="domsvc">
584 <OPTION>(none)</OPTION>
590 <TD ALIGN="right">Password</TD>
592 <INPUT TYPE="text" NAME="_password" VALUE="<% $password %>" SIZE=<% $pmax2 %> MAXLENGTH=<% $passwordmax %>>
598 <TD ALIGN="right">Access number</TD>
599 <TD><% FS::svc_acct_pop::popselector($popnum) %></TD>
606 <INPUT TYPE="hidden" NAME="otaker" VALUE="<% $cust_main->otaker %>">
608 <INPUT TYPE="button" NAME="submitButton" ID="submitButton" VALUE="<% $custnum ? "Apply Changes" : "Add Customer" %>" onClick="document.bottomform.submitButton.disabled=true; bottomfixup(this.form);">
612 <% include('/elements/footer.html') %>
617 unless $FS::CurrentUser::CurrentUser->access_right('Edit customer');
619 #for misplaced logic below
622 #for false laziness below (now more properly lazy)
623 #use FS::svc_acct_pop;
625 #for (other) false laziness below
629 my $conf = new FS::Conf;
633 my($custnum, $username, $password, $popnum, $cust_main, $saved_pkgpart, $saved_domsvc);
635 my ($ss,$stateid,$payinfo);
637 if ( $cgi->param('error') ) {
638 $cust_main = new FS::cust_main ( {
639 map { $_, scalar($cgi->param($_)) } fields('cust_main')
641 $custnum = $cust_main->custnum;
642 $saved_domsvc = $cgi->param('domsvc') || '';
643 if ( $saved_domsvc =~ /^(\d+)$/ ) {
648 $saved_pkgpart = $cgi->param('pkgpart_svcpart') || '';
649 if ( $saved_pkgpart =~ /^(\d+)_/ ) {
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;
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;
672 $cust_main->paycvv($paycvv);
679 @invoicing_list = $cust_main->invoicing_list;
680 $ss = $cust_main->masked('ss');
681 $stateid = $cust_main->masked('stateid');
682 $payinfo = $cust_main->paymask;
685 $cust_main = new FS::cust_main ( {} );
686 $cust_main->otaker( &getotaker );
687 $cust_main->referral_custnum( $cgi->param('referral_custnum') );
693 @invoicing_list = ();
694 push @invoicing_list, 'POST'
695 unless $conf->exists('disablepostalinvoicedefault');
701 my $error = $cgi->param('error');
703 $cgi->param('error', $error);
705 my $action = $custnum ? 'Edit' : 'Add';
706 $action .= ": ". $cust_main->name if $custnum;
708 my $r = qq!<font color="#ff0000">*</font> !;