1 <% include('/elements/header.html',
4 ' onUnload="myclose()"'
7 <% include('/elements/error.html') %>
9 <FORM NAME="topform" STYLE="margin-bottom: 0">
10 <INPUT TYPE="hidden" NAME="custnum" VALUE="<% $custnum %>">
13 Customer #<B><% $custnum %></B> -
14 <B><FONT COLOR="#<% $cust_main->statuscolor %>">
15 <% ucfirst($cust_main->status) %>
21 <% &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 ),
33 <!-- referral (advertising source) -->
35 %my $refnum = $cust_main->refnum || $conf->config('referraldefault') || 0;
36 %if ( $custnum && ! $conf->exists('editreferrals') ) {
40 <INPUT TYPE="hidden" NAME="refnum" VALUE="<% $refnum %>">
44 <% include('/elements/tr-select-part_referral.html',
45 'curr_value' => $refnum
51 <!-- referring customer -->
53 %my $referring_cust_main = '';
54 %if ( $cust_main->referral_custnum
55 % and $referring_cust_main =
56 % qsearchs('cust_main', { custnum => $cust_main->referral_custnum } )
62 <TD ALIGN="right">Referring customer</TD>
64 <A HREF="<% popurl(1) %>/cust_main.cgi?<% $cust_main->referral_custnum %>"><% $cust_main->referral_custnum %>: <% $referring_cust_main->name %></A>
67 <INPUT TYPE="hidden" NAME="referral_custnum" VALUE="<% $cust_main->referral_custnum %>">
68 % } elsif ( ! $conf->exists('disable_customer_referrals') ) {
72 <TD ALIGN="right">Referring customer</TD>
74 <!-- <INPUT TYPE="text" NAME="referral_custnum" VALUE=""> -->
75 <% include('/elements/search-cust_main.html',
76 'field_name' => 'referral_custnum',
84 <INPUT TYPE="hidden" NAME="referral_custnum" VALUE="">
92 % if ( $conf->exists('cust_main-enable_birthdate') ) {
95 <% ntable("#cccccc", 2) %>
96 <% include ('/elements/tr-input-date-field.html',
98 $cust_main->birthdate,
100 $conf->config('date_format') || "%m/%d/%Y",
108 <!-- contact info -->
110 % my $same_checked = '';
111 % my $ship_disabled = '';
112 % unless ( $cust_main->ship_last && $same ne 'Y' ) {
113 % $same_checked = 'CHECKED';
114 % $ship_disabled = 'DISABLED STYLE="background-color: #dddddd"';
116 % qw( last first company address1 address2 city county state zip country
117 % daytime night fax )
119 % $cust_main->set("ship_$_", $cust_main->get($_) );
125 <% include('cust_main/contact.html',
126 'cust_main' => $cust_main,
128 'onchange' => 'bill_changed(this)',
131 'stateid' => $stateid,
132 'same_checked' => $same_checked, #for address2 "Unit #" labeling
137 function bill_changed(what) {
138 if ( what.form.same.checked ) {
139 % for (qw( last first company address1 address2 city zip daytime night fax )) {
141 what.form.ship_<%$_%>.value = what.form.<%$_%>.value;
144 what.form.ship_country.selectedIndex = what.form.country.selectedIndex;
146 function fix_ship_county() {
147 what.form.ship_county.selectedIndex = what.form.county.selectedIndex;
150 function fix_ship_state() {
151 what.form.ship_state.selectedIndex = what.form.state.selectedIndex;
152 ship_state_changed(what.form.ship_state, fix_ship_county );
155 ship_country_changed(what.form.ship_country, fix_ship_state );
159 function samechanged(what) {
160 if ( what.checked ) {
163 % for (qw( last first company address1 address2 city county state zip country daytime night fax )) {
164 what.form.ship_<%$_%>.disabled = true;
165 what.form.ship_<%$_%>.style.backgroundColor = '#dddddd';
168 % if ( $conf->exists('cust_main-require_address2') ) {
169 document.getElementById('address2_required').style.visibility = '';
170 document.getElementById('address2_label').style.visibility = '';
171 document.getElementById('ship_address2_required').style.visibility = 'hidden';
172 document.getElementById('ship_address2_label').style.visibility = 'hidden';
177 % for (qw( last first company address1 address2 city county state zip country daytime night fax )) {
178 what.form.ship_<%$_%>.disabled = false;
179 what.form.ship_<%$_%>.style.backgroundColor = '#ffffff';
182 % if ( $conf->exists('cust_main-require_address2') ) {
183 document.getElementById('address2_required').style.visibility = 'hidden';
184 document.getElementById('address2_label').style.visibility = 'hidden';
185 document.getElementById('ship_address2_required').style.visibility = '';
186 document.getElementById('ship_address2_label').style.visibility = '';
195 (<INPUT TYPE="checkbox" NAME="same" VALUE="Y" onClick="samechanged(this)" <%$same_checked%>>same as billing address)
196 <% include('cust_main/contact.html',
197 'cust_main' => $cust_main,
200 'disabled' => $ship_disabled,
205 <!-- billing info -->
207 <% include( 'cust_main/billing.html', $cust_main,
208 'payinfo' => $payinfo,
209 'invoicing_list' => \@invoicing_list,
214 function bottomfixup(what) {
216 var topvars = new Array(
219 'custnum', 'agentnum', 'refnum', 'referral_custnum',
221 'last', 'first', 'ss', 'company',
222 'address1', 'address2', 'city',
223 'county', 'state', 'zip', 'country',
224 'daytime', 'night', 'fax',
225 'stateid', 'stateid_state',
229 'ship_last', 'ship_first', 'ship_company',
230 'ship_address1', 'ship_address2', 'ship_city',
231 'ship_county', 'ship_state', 'ship_zip', 'ship_country',
232 'ship_daytime','ship_night', 'ship_fax',
237 var layervars = new Array(
239 'payinfo', 'payinfo1', 'payinfo2', 'paytype',
240 'payname', 'paystate', 'exp_month', 'exp_year', 'paycvv',
241 'paystart_month', 'paystart_year', 'payissue',
246 var billing_bottomvars = new Array(
248 'invoicing_list', 'invoicing_list_POST', 'invoicing_list_FAX',
253 for ( f=0; f < topvars.length; f++ ) {
254 var field = topvars[f];
255 copyelement( document.topform.elements[field],
256 document.bottomform.elements[field]
260 var layerform = document.topform.select.options[document.topform.select.selectedIndex].value;
261 for ( f=0; f < layervars.length; f++ ) {
262 var field = layervars[f];
263 copyelement( document.forms[layerform].elements[field],
264 document.bottomform.elements[field]
268 for ( f=0; f < billing_bottomvars.length; f++ ) {
269 var field = billing_bottomvars[f];
270 copyelement( document.billing_bottomform.elements[field],
271 document.bottomform.elements[field]
277 function copyelement(from, to) {
278 if ( from == undefined ) {
280 } else if ( from.type == 'select-one' ) {
281 to.value = from.options[from.selectedIndex].value;
282 //alert(from + " (" + from.type + "): " + to.name + " => (" + from.selectedIndex + ") " + to.value);
283 } else if ( from.type == 'checkbox' ) {
284 if ( from.checked ) {
285 to.value = from.value;
290 if ( from.value == undefined ) {
293 to.value = from.value;
296 //alert(from + " (" + from.type + "): " + to.name + " => " + to.value);
301 <FORM ACTION="<% popurl(1) %>process/cust_main.cgi" METHOD=POST NAME="bottomform" onSubmit="document.bottomform.submit.disabled=true; bottomfixup(this.form);" STYLE="margin-top: 0; margin-bottom: 0">
302 % foreach my $hidden (
305 % 'custnum', 'agentnum', 'refnum', 'referral_custnum',
306 % 'last', 'first', 'ss', 'company',
307 % 'address1', 'address2', 'city',
308 % 'county', 'state', 'zip', 'country',
309 % 'daytime', 'night', 'fax',
310 % 'stateid', 'stateid_state',
314 % 'ship_last', 'ship_first', 'ship_company',
315 % 'ship_address1', 'ship_address2', 'ship_city',
316 % 'ship_county', 'ship_state', 'ship_zip', 'ship_country',
317 % 'ship_daytime','ship_night', 'ship_fax',
322 % 'payinfo', 'payinfo1', 'payinfo2', 'paytype',
323 % 'payname', 'paystate', 'exp_month', 'exp_year', 'paycvv',
324 % 'paystart_month', 'paystart_year', 'payissue',
329 % 'invoicing_list', 'invoicing_list_POST', 'invoicing_list_FAX',
335 <INPUT TYPE="hidden" NAME="<% $hidden %>" VALUE="">
338 % my $ro_comments = $conf->exists('cust_main-use_comments')?'':'readonly';
339 % if (!$ro_comments || $cust_main->comments) {
342 <% &ntable("#cccccc") %>
345 <TEXTAREA COLS=80 ROWS=5 WRAP="HARD" NAME="comments" <%$ro_comments%>><% $cust_main->comments %></TEXTAREA>
352 %unless ( $custnum ) {
353 % # pry the wrong place for this logic. also pretty expensive
356 % #false laziness, copied from FS::cust_pkg::order
358 % my @agents = $FS::CurrentUser::CurrentUser->agents;
359 % if ( scalar(@agents) == 1 ) {
360 % # $pkgpart->{PKGPART} is true iff $custnum may purchase PKGPART
361 % $pkgpart = $agents[0]->pkgpart_hashref;
363 % #can't know (agent not chosen), so, allow all
365 % foreach my $agent ( @agents ) {
366 % next if $typenum{$agent->typenum}++;
367 % #fixed in 5.004_05 #$pkgpart->{$_}++ foreach keys %{ $agent->pkgpart_hashref }
368 % foreach ( keys %{ $agent->pkgpart_hashref } ) { $pkgpart->{$_}++; } #5.004_04 workaround
373 % my @part_pkg = grep { $_->svcpart('svc_acct') && $pkgpart->{ $_->pkgpart } }
374 % qsearch( 'part_pkg', { 'disabled' => '' }, '', 'ORDER BY pkg' ); # case?
378 % # print "<BR><BR>First package", &itable("#cccccc", "0 ALIGN=LEFT"),
379 % #apiabuse & undesirable wrapping
384 <% ntable("#cccccc") %>
388 <% include('cust_main/select-domain.html',
389 'pkgparts' => \@part_pkg,
390 'saved_pkgpart' => $saved_pkgpart,
391 'saved_domsvc' => $saved_domsvc,
397 % #false laziness: (mostly) copied from edit/svc_acct.cgi
398 % #$ulen = $svc_acct->dbdef_table->column('username')->length;
399 % my $ulen = dbdef->table('svc_acct')->column('username')->length;
400 % my $ulen2 = $ulen+2;
401 % my $passwordmax = $conf->config('passwordmax') || 8;
402 % my $pmax2 = $passwordmax + 2;
407 <TD ALIGN="right">Username</TD>
409 <INPUT TYPE="text" NAME="username" VALUE="<% $username %>" SIZE=<% $ulen2 %> MAXLENGTH=<% $ulen %>>
414 <TD ALIGN="right">Domain</TD>
416 <SELECT NAME="domsvc">
417 <OPTION>(none)</OPTION>
423 <TD ALIGN="right">Password</TD>
425 <INPUT TYPE="text" NAME="_password" VALUE="<% $password %>" SIZE=<% $pmax2 %> MAXLENGTH=<% $passwordmax %>>
431 <TD ALIGN="right">Access number</TD>
432 <TD><% FS::svc_acct_pop::popselector($popnum) %></TD>
439 <INPUT TYPE="hidden" NAME="otaker" VALUE="<% $cust_main->otaker %>">
441 <INPUT TYPE="submit" NAME="submit" VALUE="<% $custnum ? "Apply Changes" : "Add Customer" %>">
445 <% include('/elements/footer.html') %>
450 unless $FS::CurrentUser::CurrentUser->access_right('Edit customer');
452 #for misplaced logic below
455 #for false laziness below (now more properly lazy)
456 #use FS::svc_acct_pop;
458 #for (other) false laziness below
462 my $conf = new FS::Conf;
466 my($custnum, $username, $password, $popnum, $cust_main, $saved_pkgpart, $saved_domsvc);
468 my ($ss,$stateid,$payinfo);
470 if ( $cgi->param('error') ) {
471 $cust_main = new FS::cust_main ( {
472 map { $_, scalar($cgi->param($_)) } fields('cust_main')
474 $custnum = $cust_main->custnum;
475 $saved_domsvc = $cgi->param('domsvc') || '';
476 if ( $saved_domsvc =~ /^(\d+)$/ ) {
481 $saved_pkgpart = $cgi->param('pkgpart_svcpart') || '';
482 if ( $saved_pkgpart =~ /^(\d+)_/ ) {
487 $username = $cgi->param('username');
488 $password = $cgi->param('_password');
489 $popnum = $cgi->param('popnum');
490 @invoicing_list = split( /\s*,\s*/, $cgi->param('invoicing_list') );
491 $same = $cgi->param('same');
492 $cust_main->setfield('paid' => $cgi->param('paid')) if $cgi->param('paid');
493 $ss = $cust_main->ss; # don't mask an entered value on errors
494 $stateid = $cust_main->stateid; # don't mask an entered value on errors
495 $payinfo = $cust_main->payinfo; # don't mask an entered value on errors
496 } elsif ( $cgi->keywords ) { #editing
497 my( $query ) = $cgi->keywords;
500 $cust_main = qsearchs('cust_main', { 'custnum' => $custnum } );
501 if ( $cust_main->dbdef_table->column('paycvv')
502 && length($cust_main->paycvv) ) {
503 my $paycvv = $cust_main->paycvv;
505 $cust_main->paycvv($paycvv);
512 @invoicing_list = $cust_main->invoicing_list;
513 $ss = $cust_main->masked('ss');
514 $stateid = $cust_main->masked('stateid');
515 $payinfo = $cust_main->paymask;
518 $cust_main = new FS::cust_main ( {} );
519 $cust_main->otaker( &getotaker );
520 $cust_main->referral_custnum( $cgi->param('referral_custnum') );
526 @invoicing_list = ();
527 push @invoicing_list, 'POST'
528 unless $conf->exists('disablepostalinvoicedefault');
534 my $error = $cgi->param('error');
536 $cgi->param('error', $error);
538 my $action = $custnum ? 'Edit' : 'Add';
539 $action .= ": ". $cust_main->name if $custnum;
541 my $r = qq!<font color="#ff0000">*</font> !;