3 % #for misplaced logic below
6 % #for false laziness below (now more properly lazy)
7 % #use FS::svc_acct_pop;
9 % #for (other) false laziness below
13 %my $conf = new FS::Conf;
18 %my($custnum, $username, $password, $popnum, $cust_main, $saved_pkgpart);
22 %if ( $cgi->param('error') ) {
23 % $error = $cgi->param('error');
24 % $cust_main = new FS::cust_main ( {
25 % map { $_, scalar($cgi->param($_)) } fields('cust_main')
27 % $custnum = $cust_main->custnum;
28 % $saved_pkgpart = $cgi->param('pkgpart_svcpart') || '';
29 % if ( $saved_pkgpart =~ /^(\d+)_/ ) {
30 % $saved_pkgpart = $1;
32 % $saved_pkgpart = '';
34 % $username = $cgi->param('username');
35 % $password = $cgi->param('_password');
36 % $popnum = $cgi->param('popnum');
37 % @invoicing_list = split( /\s*,\s*/, $cgi->param('invoicing_list') );
38 % $same = $cgi->param('same');
39 % $cust_main->setfield('paid' => $cgi->param('paid')) if $cgi->param('paid');
40 % $payinfo = $cust_main->payinfo; # don't mask an entered value on errors
41 %} elsif ( $cgi->keywords ) { #editing
42 % my( $query ) = $cgi->keywords;
43 % $query =~ /^(\d+)$/;
45 % $cust_main = qsearchs('cust_main', { 'custnum' => $custnum } );
46 % if ( $cust_main->dbdef_table->column('paycvv')
47 % && length($cust_main->paycvv) ) {
48 % my $paycvv = $cust_main->paycvv;
50 % $cust_main->paycvv($paycvv);
56 % @invoicing_list = $cust_main->invoicing_list;
57 % $payinfo = $cust_main->paymask;
60 % $cust_main = new FS::cust_main ( {} );
61 % $cust_main->otaker( &getotaker );
62 % $cust_main->referral_custnum( $cgi->param('referral_custnum') );
67 % @invoicing_list = ();
68 % push @invoicing_list, 'POST'
69 % unless $conf->exists('disablepostalinvoicedefault');
74 %my $action = $custnum ? 'Edit' : 'Add';
75 %$action .= ": ". $cust_main->name if $custnum;
77 %my $r = qq!<font color="#ff0000">*</font> !;
84 <% include('/elements/header.html',
87 ' onUnload="myclose()"'
91 <FONT SIZE="+1" COLOR="#ff0000">Error: <% $error %></FONT><BR><BR>
95 <FORM NAME="topform" STYLE="margin-bottom: 0">
96 <INPUT TYPE="hidden" NAME="custnum" VALUE="<% $custnum %>">
99 Customer #<B><% $custnum %></B> -
100 <B><FONT COLOR="<% $cust_main->statuscolor %>">
101 <% ucfirst($cust_main->status) %>
107 <% &ntable("#cccccc") %>
111 <% include('/elements/tr-select-agent.html', $cust_main->agentnum,
112 'label' => "<B>${r}Agent</B>",
113 'empty_label' => 'Select agent',
117 <!-- referral (advertising source) -->
119 %my $refnum = $cust_main->refnum || $conf->config('referraldefault') || 0;
120 %if ( $custnum && ! $conf->exists('editreferrals') ) {
124 <INPUT TYPE="hidden" NAME="refnum" VALUE="<% $refnum %>">
128 <% include('/elements/tr-select-part_referral.html', $refnum ) %>
132 <!-- referring customer -->
134 %my $referring_cust_main = '';
135 %if ( $cust_main->referral_custnum
136 % and $referring_cust_main =
137 % qsearchs('cust_main', { custnum => $cust_main->referral_custnum } )
143 <TD ALIGN="right">Referring customer</TD>
145 <A HREF="<% popurl(1) %>/cust_main.cgi?<% $cust_main->referral_custnum %>"><% $cust_main->referral_custnum %>: <% $referring_cust_main->name %></A>
148 <INPUT TYPE="hidden" NAME="referral_custnum" VALUE="<% $cust_main->referral_custnum %>">
149 % } elsif ( ! $conf->exists('disable_customer_referrals') ) {
153 <TD ALIGN="right">Referring customer</TD>
155 <!-- <INPUT TYPE="text" NAME="referral_custnum" VALUE=""> -->
156 <% include('/elements/search-cust_main.html',
157 'field_name' => 'referral_custnum',
165 <INPUT TYPE="hidden" NAME="referral_custnum" VALUE="">
173 % if ( $conf->exists('cust_main-enable_birthdate') ) {
176 <% ntable("#cccccc", 2) %>
177 <% include ('/elements/tr-input-date-field.html',
179 $cust_main->birthdate,
181 $conf->config('date_format') || "%m/%d/%Y",
189 <!-- contact info -->
193 <% include('cust_main/contact.html', $cust_main, '', 'bill_changed(this)', '' ) %>
195 <!-- service address -->
196 % if ( defined $cust_main->dbdef_table->column('ship_last') ) {
200 function bill_changed(what) {
201 if ( what.form.same.checked ) {
202 % for (qw( last first company address1 address2 city zip daytime night fax )) {
204 what.form.ship_<%$_%>.value = what.form.<%$_%>.value;
207 what.form.ship_country.selectedIndex = what.form.country.selectedIndex;
209 function fix_ship_county() {
210 what.form.ship_county.selectedIndex = what.form.county.selectedIndex;
213 function fix_ship_state() {
214 what.form.ship_state.selectedIndex = what.form.state.selectedIndex;
215 ship_state_changed(what.form.ship_state, fix_ship_county );
218 ship_country_changed(what.form.ship_country, fix_ship_state );
222 function samechanged(what) {
223 if ( what.checked ) {
225 % for (qw( last first company address1 address2 city county state zip country daytime night fax )) {
227 what.form.ship_<%$_%>.disabled = true;
228 what.form.ship_<%$_%>.style.backgroundColor = '#dddddd';
232 % for (qw( last first company address1 address2 city county state zip country daytime night fax )) {
234 what.form.ship_<%$_%>.disabled = false;
235 what.form.ship_<%$_%>.style.backgroundColor = '#ffffff';
244 % my $disabledselect = '';
245 % unless ( $cust_main->ship_last && $same ne 'Y' ) {
246 % $checked = 'CHECKED';
247 % $disabled = 'DISABLED STYLE="background-color: #dddddd"';
249 % qw( last first company address1 address2 city county state zip country
250 % daytime night fax )
252 % $cust_main->set("ship_$_", $cust_main->get($_) );
260 (<INPUT TYPE="checkbox" NAME="same" VALUE="Y" onClick="samechanged(this)" <%$checked%>>same as billing address)
261 <% include('cust_main/contact.html', $cust_main, 'ship_', '', $disabled ) %>
265 <!-- billing info -->
267 <% include( 'cust_main/billing.html', $cust_main,
268 'payinfo' => $payinfo,
269 'invoicing_list' => \@invoicing_list,
274 function bottomfixup(what) {
276 var topvars = new Array(
279 'custnum', 'agentnum', 'refnum', 'referral_custnum',
281 'last', 'first', 'ss', 'company',
282 'address1', 'address2', 'city',
283 'county', 'state', 'zip', 'country',
284 'daytime', 'night', 'fax',
288 'ship_last', 'ship_first', 'ship_company',
289 'ship_address1', 'ship_address2', 'ship_city',
290 'ship_county', 'ship_state', 'ship_zip', 'ship_country',
291 'ship_daytime','ship_night', 'ship_fax',
296 var layervars = new Array(
298 'payinfo', 'payinfo1', 'payinfo2',
299 'payname', 'exp_month', 'exp_year', 'paycvv',
300 'paystart_month', 'paystart_year', 'payissue',
305 var billing_bottomvars = new Array(
307 'invoicing_list', 'invoicing_list_POST', 'invoicing_list_FAX',
311 for ( f=0; f < topvars.length; f++ ) {
312 var field = topvars[f];
313 copyelement( document.topform.elements[field],
314 document.bottomform.elements[field]
318 var layerform = document.topform.select.options[document.topform.select.selectedIndex].value;
319 for ( f=0; f < layervars.length; f++ ) {
320 var field = layervars[f];
321 copyelement( document.forms[layerform].elements[field],
322 document.bottomform.elements[field]
326 for ( f=0; f < billing_bottomvars.length; f++ ) {
327 var field = billing_bottomvars[f];
328 copyelement( document.billing_bottomform.elements[field],
329 document.bottomform.elements[field]
335 function copyelement(from, to) {
336 if ( from == undefined ) {
338 } else if ( from.type == 'select-one' ) {
339 to.value = from.options[from.selectedIndex].value;
340 //alert(from + " (" + from.type + "): " + to.name + " => (" + from.selectedIndex + ") " + to.value);
341 } else if ( from.type == 'checkbox' ) {
342 if ( from.checked ) {
343 to.value = from.value;
348 if ( from.value == undefined ) {
351 to.value = from.value;
354 //alert(from + " (" + from.type + "): " + to.name + " => " + to.value);
359 <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">
360 % foreach my $hidden (
363 % 'custnum', 'agentnum', 'refnum', 'referral_custnum',
364 % 'last', 'first', 'ss', 'company',
365 % 'address1', 'address2', 'city',
366 % 'county', 'state', 'zip', 'country',
367 % 'daytime', 'night', 'fax',
371 % 'ship_last', 'ship_first', 'ship_company',
372 % 'ship_address1', 'ship_address2', 'ship_city',
373 % 'ship_county', 'ship_state', 'ship_zip', 'ship_country',
374 % 'ship_daytime','ship_night', 'ship_fax',
379 % 'payinfo', 'payinfo1', 'payinfo2',
380 % 'payname', 'exp_month', 'exp_year', 'paycvv',
381 % 'paystart_month', 'paystart_year', 'payissue',
386 % 'invoicing_list', 'invoicing_list_POST', 'invoicing_list_FAX',
391 <INPUT TYPE="hidden" NAME="<% $hidden %>" VALUE="">
394 % my $ro_comments = $conf->exists('cust_main-use_comments')?'':'readonly';
395 % if (!$ro_comments || $cust_main->comments) {
398 <% &ntable("#cccccc") %>
401 <TEXTAREA COLS=80 ROWS=5 WRAP="HARD" NAME="comments" <%$ro_comments%>><% $cust_main->comments %></TEXTAREA>
408 %unless ( $custnum ) {
409 % # pry the wrong place for this logic. also pretty expensive
412 % #false laziness, copied from FS::cust_pkg::order
414 % my @agents = $FS::CurrentUser::CurrentUser->agents;
415 % if ( scalar(@agents) == 1 ) {
416 % # $pkgpart->{PKGPART} is true iff $custnum may purchase PKGPART
417 % $pkgpart = $agents[0]->pkgpart_hashref;
419 % #can't know (agent not chosen), so, allow all
421 % foreach my $agent ( @agents ) {
422 % next if $typenum{$agent->typenum}++;
423 % #fixed in 5.004_05 #$pkgpart->{$_}++ foreach keys %{ $agent->pkgpart_hashref }
424 % foreach ( keys %{ $agent->pkgpart_hashref } ) { $pkgpart->{$_}++; } #5.004_04 workaround
429 % my @part_pkg = grep { $_->svcpart('svc_acct') && $pkgpart->{ $_->pkgpart } }
430 % qsearch( 'part_pkg', { 'disabled' => '' } );
434 % # print "<BR><BR>First package", &itable("#cccccc", "0 ALIGN=LEFT"),
435 % #apiabuse & undesirable wrapping
440 <% ntable("#cccccc") %>
444 <SELECT NAME="pkgpart_svcpart">
445 <OPTION VALUE="">(none)
446 % foreach my $part_pkg ( @part_pkg ) {
449 <OPTION VALUE="<% $part_pkg->pkgpart. "_". $part_pkg->svcpart('svc_acct') %>"<% ( $saved_pkgpart && $part_pkg->pkgpart == $saved_pkgpart ) ? ' SELECTED' : '' %>><% $part_pkg->pkg. " - ". $part_pkg->comment %>
456 % #false laziness: (mostly) copied from edit/svc_acct.cgi
457 % #$ulen = $svc_acct->dbdef_table->column('username')->length;
458 % my $ulen = dbdef->table('svc_acct')->column('username')->length;
459 % my $ulen2 = $ulen+2;
460 % my $passwordmax = $conf->config('passwordmax') || 8;
461 % my $pmax2 = $passwordmax + 2;
466 <TD ALIGN="right">Username</TD>
468 <INPUT TYPE="text" NAME="username" VALUE="<% $username %>" SIZE=<% $ulen2 %> MAXLENGTH=<% $ulen %>>
473 <TD ALIGN="right">Password</TD>
475 <INPUT TYPE="text" NAME="_password" VALUE="<% $password %>" SIZE=<% $pmax2 %> MAXLENGTH=<% $passwordmax %>>
481 <TD ALIGN="right">Access number</TD>
482 <TD><% FS::svc_acct_pop::popselector($popnum) %></TD>
489 <INPUT TYPE="hidden" NAME="otaker" VALUE="<% $cust_main->otaker %>">
491 <INPUT TYPE="submit" NAME="submit" VALUE="<% $custnum ? "Apply Changes" : "Add Customer" %>">
495 <% include('/elements/footer.html') %>