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);
21 %if ( $cgi->param('error') ) {
22 % $error = $cgi->param('error');
23 % $cust_main = new FS::cust_main ( {
24 % map { $_, scalar($cgi->param($_)) } fields('cust_main')
26 % $custnum = $cust_main->custnum;
27 % $saved_pkgpart = $cgi->param('pkgpart_svcpart') || '';
28 % if ( $saved_pkgpart =~ /^(\d+)_/ ) {
29 % $saved_pkgpart = $1;
31 % $saved_pkgpart = '';
33 % $username = $cgi->param('username');
34 % $password = $cgi->param('_password');
35 % $popnum = $cgi->param('popnum');
36 % @invoicing_list = split( /\s*,\s*/, $cgi->param('invoicing_list') );
37 % $same = $cgi->param('same');
38 % $cust_main->setfield('paid' => $cgi->param('paid')) if $cgi->param('paid');
39 %} elsif ( $cgi->keywords ) { #editing
40 % my( $query ) = $cgi->keywords;
41 % $query =~ /^(\d+)$/;
43 % $cust_main = qsearchs('cust_main', { 'custnum' => $custnum } );
44 % if ( $cust_main->dbdef_table->column('paycvv')
45 % && length($cust_main->paycvv) ) {
46 % my $paycvv = $cust_main->paycvv;
48 % $cust_main->paycvv($paycvv);
54 % @invoicing_list = $cust_main->invoicing_list;
57 % $cust_main = new FS::cust_main ( {} );
58 % $cust_main->otaker( &getotaker );
59 % $cust_main->referral_custnum( $cgi->param('referral_custnum') );
64 % @invoicing_list = ();
65 % push @invoicing_list, 'POST'
66 % unless $conf->exists('disablepostalinvoicedefault');
70 %my $action = $custnum ? 'Edit' : 'Add';
71 %$action .= ": ". $cust_main->name if $custnum;
73 %my $r = qq!<font color="#ff0000">*</font> !;
80 <% include('/elements/header.html',
83 ' onUnload="myclose()"'
87 <FONT SIZE="+1" COLOR="#ff0000">Error: <% $error %></FONT><BR><BR>
91 <FORM NAME="topform" STYLE="margin-bottom: 0">
92 <INPUT TYPE="hidden" NAME="custnum" VALUE="<% $custnum %>">
95 Customer #<B><% $custnum %></B> -
96 <B><FONT COLOR="<% $cust_main->statuscolor %>">
97 <% ucfirst($cust_main->status) %>
103 <% &ntable("#cccccc") %>
107 <% include('/elements/tr-select-agent.html', $cust_main->agentnum,
108 'label' => "<B>${r}Agent</B>",
109 'empty_label' => 'Select agent',
113 <!-- referral (advertising source) -->
115 %my $refnum = $cust_main->refnum || $conf->config('referraldefault') || 0;
116 %if ( $custnum && ! $conf->exists('editreferrals') ) {
120 <INPUT TYPE="hidden" NAME="refnum" VALUE="<% $refnum %>">
124 <% include('/elements/tr-select-part_referral.html', $refnum ) %>
128 <!-- referring customer -->
130 %my $referring_cust_main = '';
131 %if ( $cust_main->referral_custnum
132 % and $referring_cust_main =
133 % qsearchs('cust_main', { custnum => $cust_main->referral_custnum } )
139 <TD ALIGN="right">Referring customer</TD>
141 <A HREF="<% popurl(1) %>/cust_main.cgi?<% $cust_main->referral_custnum %>"><% $cust_main->referral_custnum %>: <% $referring_cust_main->name %></A>
144 <INPUT TYPE="hidden" NAME="referral_custnum" VALUE="<% $cust_main->referral_custnum %>">
145 % } elsif ( ! $conf->exists('disable_customer_referrals') ) {
149 <TD ALIGN="right">Referring customer</TD>
151 <!-- <INPUT TYPE="text" NAME="referral_custnum" VALUE=""> -->
152 <% include('/elements/search-cust_main.html',
153 'field_name' => 'referral_custnum',
161 <INPUT TYPE="hidden" NAME="referral_custnum" VALUE="">
169 % if ( $conf->exists('cust_main-enable_birthdate') ) {
172 <% ntable("#cccccc", 2) %>
173 <% include ('/elements/tr-input-date-field.html',
175 $cust_main->birthdate,
177 $conf->config('date_format') || "%m/%d/%Y",
185 <!-- contact info -->
189 <% include('cust_main/contact.html', $cust_main, '', 'bill_changed(this)', '' ) %>
191 <!-- service address -->
192 % if ( defined $cust_main->dbdef_table->column('ship_last') ) {
196 function bill_changed(what) {
197 if ( what.form.same.checked ) {
198 % for (qw( last first company address1 address2 city zip daytime night fax )) {
200 what.form.ship_<%$_%>.value = what.form.<%$_%>.value;
204 what.form.ship_country.selectedIndex = what.form.country.selectedIndex;
205 function fix_ship_state() {
206 what.form.ship_state.selectedIndex = what.form.state.selectedIndex;
208 ship_country_changed(what.form.ship_country, fix_ship_state );
210 function fix_ship_county() {
211 what.form.ship_county.selectedIndex = what.form.county.selectedIndex;
213 ship_state_changed(what.form.ship_state, fix_ship_county );
216 function samechanged(what) {
217 if ( what.checked ) {
219 % for (qw( last first company address1 address2 city county state zip country daytime night fax )) {
221 what.form.ship_<%$_%>.disabled = true;
222 what.form.ship_<%$_%>.style.backgroundColor = '#dddddd';
226 % for (qw( last first company address1 address2 city county state zip country daytime night fax )) {
228 what.form.ship_<%$_%>.disabled = false;
229 what.form.ship_<%$_%>.style.backgroundColor = '#ffffff';
238 % my $disabledselect = '';
239 % unless ( $cust_main->ship_last && $same ne 'Y' ) {
240 % $checked = 'CHECKED';
241 % $disabled = 'DISABLED style="background-color: #dddddd"';
243 % qw( last first company address1 address2 city county state zip country
244 % daytime night fax )
246 % $cust_main->set("ship_$_", $cust_main->get($_) );
254 (<INPUT TYPE="checkbox" NAME="same" VALUE="Y" onClick="samechanged(this)" <%$checked%>>same as billing address)
255 <% include('cust_main/contact.html', $cust_main, 'ship_', '', $disabled ) %>
259 <!-- billing info -->
261 <% include( 'cust_main/billing.html', $cust_main,
262 'invoicing_list' => \@invoicing_list,
267 function bottomfixup(what) {
269 var topvars = new Array(
272 'custnum', 'agentnum', 'refnum', 'referral_custnum',
274 'last', 'first', 'ss', 'company',
275 'address1', 'address2', 'city',
276 'county', 'state', 'zip', 'country',
277 'daytime', 'night', 'fax',
281 'ship_last', 'ship_first', 'ship_company',
282 'ship_address1', 'ship_address2', 'ship_city',
283 'ship_county', 'ship_state', 'ship_zip', 'ship_country',
284 'ship_daytime','ship_night', 'ship_fax',
289 var layervars = new Array(
291 'payinfo', 'payinfo1', 'payinfo2',
292 'payname', 'exp_month', 'exp_year', 'paycvv',
293 'paystart_month', 'paystart_year', 'payissue',
298 var billing_bottomvars = new Array(
300 'invoicing_list', 'invoicing_list_POST', 'invoicing_list_FAX',
304 for ( f=0; f < topvars.length; f++ ) {
305 var field = topvars[f];
306 copyelement( document.topform.elements[field],
307 document.bottomform.elements[field]
311 var layerform = document.topform.select.options[document.topform.select.selectedIndex].value;
312 for ( f=0; f < layervars.length; f++ ) {
313 var field = layervars[f];
314 copyelement( document.forms[layerform].elements[field],
315 document.bottomform.elements[field]
319 for ( f=0; f < billing_bottomvars.length; f++ ) {
320 var field = billing_bottomvars[f];
321 copyelement( document.billing_bottomform.elements[field],
322 document.bottomform.elements[field]
328 function copyelement(from, to) {
329 if ( from == undefined ) {
331 } else if ( from.type == 'select-one' ) {
332 to.value = from.options[from.selectedIndex].value;
333 //alert(from + " (" + from.type + "): " + to.name + " => (" + from.selectedIndex + ") " + to.value);
334 } else if ( from.type == 'checkbox' ) {
335 if ( from.checked ) {
336 to.value = from.value;
341 if ( from.value == undefined ) {
344 to.value = from.value;
347 //alert(from + " (" + from.type + "): " + to.name + " => " + to.value);
352 <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">
353 % foreach my $hidden (
356 % 'custnum', 'agentnum', 'refnum', 'referral_custnum',
357 % 'last', 'first', 'ss', 'company',
358 % 'address1', 'address2', 'city',
359 % 'county', 'state', 'zip', 'country',
360 % 'daytime', 'night', 'fax',
364 % 'ship_last', 'ship_first', 'ship_company',
365 % 'ship_address1', 'ship_address2', 'ship_city',
366 % 'ship_county', 'ship_state', 'ship_zip', 'ship_country',
367 % 'ship_daytime','ship_night', 'ship_fax',
372 % 'payinfo', 'payinfo1', 'payinfo2',
373 % 'payname', 'exp_month', 'exp_year', 'paycvv',
374 % 'paystart_month', 'paystart_year', 'payissue',
379 % 'invoicing_list', 'invoicing_list_POST', 'invoicing_list_FAX',
384 <INPUT TYPE="hidden" NAME="<% $hidden %>" VALUE="">
387 % my $ro_comments = $conf->exists('cust_main-use_comments')?'':'readonly';
388 % if (!$ro_comments || $cust_main->comments) {
391 <% &ntable("#cccccc") %>
394 <TEXTAREA COLS=80 ROWS=5 WRAP="HARD" NAME="comments" <%$ro_comments%>><% $cust_main->comments %></TEXTAREA>
401 %unless ( $custnum ) {
402 % # pry the wrong place for this logic. also pretty expensive
405 % #false laziness, copied from FS::cust_pkg::order
407 % my @agents = $FS::CurrentUser::CurrentUser->agents;
408 % if ( scalar(@agents) == 1 ) {
409 % # $pkgpart->{PKGPART} is true iff $custnum may purchase PKGPART
410 % $pkgpart = $agents[0]->pkgpart_hashref;
412 % #can't know (agent not chosen), so, allow all
414 % foreach my $agent ( @agents ) {
415 % next if $typenum{$agent->typenum}++;
416 % #fixed in 5.004_05 #$pkgpart->{$_}++ foreach keys %{ $agent->pkgpart_hashref }
417 % foreach ( keys %{ $agent->pkgpart_hashref } ) { $pkgpart->{$_}++; } #5.004_04 workaround
422 % my @part_pkg = grep { $_->svcpart('svc_acct') && $pkgpart->{ $_->pkgpart } }
423 % qsearch( 'part_pkg', { 'disabled' => '' } );
427 % # print "<BR><BR>First package", &itable("#cccccc", "0 ALIGN=LEFT"),
428 % #apiabuse & undesirable wrapping
433 <% ntable("#cccccc") %>
437 <SELECT NAME="pkgpart_svcpart">
438 <OPTION VALUE="">(none)
439 % foreach my $part_pkg ( @part_pkg ) {
442 <OPTION VALUE="<% $part_pkg->pkgpart. "_". $part_pkg->svcpart('svc_acct') %>"<% ( $saved_pkgpart && $part_pkg->pkgpart == $saved_pkgpart ) ? ' SELECTED' : '' %>><% $part_pkg->pkg. " - ". $part_pkg->comment %>
449 % #false laziness: (mostly) copied from edit/svc_acct.cgi
450 % #$ulen = $svc_acct->dbdef_table->column('username')->length;
451 % my $ulen = dbdef->table('svc_acct')->column('username')->length;
452 % my $ulen2 = $ulen+2;
453 % my $passwordmax = $conf->config('passwordmax') || 8;
454 % my $pmax2 = $passwordmax + 2;
459 <TD ALIGN="right">Username</TD>
461 <INPUT TYPE="text" NAME="username" VALUE="<% $username %>" SIZE=<% $ulen2 %> MAXLENGTH=<% $ulen %>>
466 <TD ALIGN="right">Password</TD>
468 <INPUT TYPE="text" NAME="_password" VALUE="<% $password %>" SIZE=<% $pmax2 %> MAXLENGTH=<% $passwordmax %>>
474 <TD ALIGN="right">Access number</TD>
475 <TD><% FS::svc_acct_pop::popselector($popnum) %></TD>
482 <INPUT TYPE="hidden" NAME="otaker" VALUE="<% $cust_main->otaker %>">
484 <INPUT TYPE="submit" NAME="submit" VALUE="<% $custnum ? "Apply Changes" : "Add Customer" %>">
488 <% include('/elements/footer.html') %>