3 #for misplaced logic below
6 #for false laziness below (now more properly lazy)
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+)_/ ) {
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 } elsif ( $cgi->keywords ) { #editing
39 my( $query ) = $cgi->keywords;
42 $cust_main = qsearchs('cust_main', { 'custnum' => $custnum } );
43 if ( $cust_main->dbdef_table->column('paycvv')
44 && length($cust_main->paycvv) ) {
45 my $paycvv = $cust_main->paycvv;
47 $cust_main->paycvv($paycvv);
53 @invoicing_list = $cust_main->invoicing_list;
56 $cust_main = new FS::cust_main ( {} );
57 $cust_main->otaker( &getotaker );
58 $cust_main->referral_custnum( $cgi->param('referral_custnum') );
66 my $action = $custnum ? 'Edit' : 'Add';
72 <%= header("Customer $action", '', ' onUnload="myclose()"') %>
75 <FONT SIZE="+1" COLOR="#ff0000">Error: <%= $error %></FONT>
78 <FORM NAME="topform" STYLE="margin-bottom: 0">
79 <INPUT TYPE="hidden" NAME="custnum" VALUE="<%= $custnum %>">
80 Customer # <%= $custnum ? "<B>$custnum</B>" : " (NEW)" %>
86 my $r = qq!<font color="#ff0000">*</font> !;
88 my %agent_search = dbdef->table('agent')->column('disabled')
89 ? ( 'disabled' => '' ) : ();
90 my @agents = qsearch( 'agent', \%agent_search );
91 #die "No agents created!" unless @agents;
92 eidiot "You have not created any agents (or all agents are disabled). You must create at least one agent before adding a customer. Go to ". popurl(2). "browse/agent.cgi and create one or more agents." unless @agents;
93 my $agentnum = $cust_main->agentnum || $agents[0]->agentnum; #default to first
97 <% if ( scalar(@agents) == 1 ) { %>
98 <INPUT TYPE="hidden" NAME="agentnum" VALUE="<%= $agentnum %>">
100 <BR><BR><%=$r%>Agent <SELECT NAME="agentnum" SIZE="1">
101 <% foreach my $agent (sort { $a->agent cmp $b->agent; } @agents) { %>
102 <OPTION VALUE="<%= $agent->agentnum %>"<%= " SELECTED"x($agent->agentnum==$agentnum) %>><%= $agent->agent %>
107 <!-- referral (advertising source) -->
110 my $refnum = $cust_main->refnum || $conf->config('referraldefault') || 0;
111 if ( $custnum && ! $conf->exists('editreferrals') ) {
114 <INPUT TYPE="hidden" NAME="refnum" VALUE="<%= $refnum %>">
119 my(@referrals) = qsearch('part_referral',{});
120 if ( scalar(@referrals) == 0 ) {
121 eidiot "You have not created any advertising sources. You must create at least one advertising source before adding a customer. Go to ". popurl(2). "browse/part_referral.cgi and create one or more advertising sources.";
122 } elsif ( scalar(@referrals) == 1 ) {
123 $refnum ||= $referrals[0]->refnum;
126 <INPUT TYPE="hidden" NAME="refnum" VALUE="<%= $refnum %>">
130 <BR><BR><%=$r%>Advertising source
131 <SELECT NAME="refnum" SIZE="1">
132 <%= $refnum ? '' : '<OPTION VALUE="">' %>
133 <% foreach my $referral (sort { $a->refnum <=> $b->refnum } @referrals) { %>
134 <OPTION VALUE="<%= $referral->refnum %>" <%= $referral->refnum == $refnum ? 'SELECTED' : '' %>><%= $referral->refnum %>: <%= $referral->referral %>
141 <!-- referring customer -->
144 my $referring_cust_main = '';
145 if ( $cust_main->referral_custnum
146 and $referring_cust_main =
147 qsearchs('cust_main', { custnum => $cust_main->referral_custnum } )
151 <BR><BR>Referring Customer:
152 <A HREF="<%= popurl(1) %>/cust_main.cgi?<%= $cust_main->referral_custnum %>"><%= $cust_main->referral_custnum %>: <%= $referring_cust_main->name %></A>
153 <INPUT TYPE="hidden" NAME="referral_custnum" VALUE="<%= $cust_main->referral_custnum %>">
155 <% } elsif ( ! $conf->exists('disable_customer_referrals') ) { %>
157 <BR><BR>Referring customer number:
158 <INPUT TYPE="text" NAME="referral_custnum" VALUE="">
162 <INPUT TYPE="hidden" NAME="referral_custnum" VALUE="">
166 <!-- contact info -->
170 <%= include('cust_main/contact.html', $cust_main, '', 'bill_changed(this)', '' ) %>
172 <!-- service address -->
174 <% if ( defined $cust_main->dbdef_table->column('ship_last') ) { %>
177 function bill_changed(what) {
178 if ( what.form.same.checked ) {
179 <% for (qw( last first company address1 address2 city zip daytime night fax )) { %>
180 what.form.ship_<%=$_%>.value = what.form.<%=$_%>.value;
183 what.form.ship_country.selectedIndex = what.form.country.selectedIndex;
184 function fix_ship_state() {
185 what.form.ship_state.selectedIndex = what.form.state.selectedIndex;
187 ship_country_changed(what.form.ship_country, fix_ship_state );
189 function fix_ship_county() {
190 what.form.ship_county.selectedIndex = what.form.county.selectedIndex;
192 ship_state_changed(what.form.ship_state, fix_ship_county );
195 function samechanged(what) {
196 if ( what.checked ) {
198 <% for (qw( last first company address1 address2 city county state zip country daytime night fax )) { %>
199 what.form.ship_<%=$_%>.disabled = true;
200 what.form.ship_<%=$_%>.style.backgroundColor = '#dddddd';
203 <% for (qw( last first company address1 address2 city county state zip country daytime night fax )) { %>
204 what.form.ship_<%=$_%>.disabled = false;
205 what.form.ship_<%=$_%>.style.backgroundColor = '#ffffff';
214 my $disabledselect = '';
215 unless ( $cust_main->ship_last && $same ne 'Y' ) {
216 $checked = 'CHECKED';
217 $disabled = 'DISABLED style="background-color: #dddddd"';
219 qw( last first company address1 address2 city county state zip country
222 $cust_main->set("ship_$_", $cust_main->get($_) );
229 (<INPUT TYPE="checkbox" NAME="same" VALUE="Y" onClick="samechanged(this)" <%=$checked%>>same as billing address)
230 <%= include('cust_main/contact.html', $cust_main, 'ship_', '', $disabled ) %>
234 <!-- billing info -->
236 <%= include('cust_main/billing.html', $cust_main ) %>
239 function bottomfixup(what) {
241 var topvars = new Array(
242 'custnum', 'agentnum', 'refnum', 'referral_custnum',
244 'last', 'first', 'ss', 'company',
245 'address1', 'address2', 'city',
246 'county', 'state', 'zip', 'country',
247 'daytime', 'night', 'fax',
251 'ship_last', 'ship_first', 'ship_company',
252 'ship_address1', 'ship_address2', 'ship_city',
253 'ship_county', 'ship_state', 'ship_zip', 'ship_country',
254 'ship_daytime','ship_night', 'ship_fax',
259 var layervars = new Array(
261 'payinfo', 'payinfo1', 'payinfo2',
262 'payname', 'exp_month', 'exp_year', 'paycvv',
263 'paystart_month', 'paystart_year', 'payissue',
267 var billing_bottomvars = new Array(
269 'invoicing_list', 'invoicing_list_POST', 'invoicing_list_FAX'
272 for ( f=0; f < topvars.length; f++ ) {
273 var field = topvars[f];
274 copyelement( document.topform.elements[field],
275 document.bottomform.elements[field]
279 var layerform = document.topform.select.options[document.topform.select.selectedIndex].value;
280 for ( f=0; f < layervars.length; f++ ) {
281 var field = layervars[f];
282 copyelement( document.forms[layerform].elements[field],
283 document.bottomform.elements[field]
287 for ( f=0; f < billing_bottomvars.length; f++ ) {
288 var field = billing_bottomvars[f];
289 copyelement( document.billing_bottomform.elements[field],
290 document.bottomform.elements[field]
296 function copyelement(from, to) {
297 if ( from == undefined ) {
299 } else if ( from.type == 'select-one' ) {
300 to.value = from.options[from.selectedIndex].value;
301 //alert(from + " (" + from.type + "): " + to.name + " => (" + from.selectedIndex + ") " + to.value);
302 } else if ( from.type == 'checkbox' ) {
303 if ( from.checked ) {
304 to.value = from.value;
309 if ( from.value == undefined ) {
312 to.value = from.value;
315 //alert(from + " (" + from.type + "): " + to.name + " => " + to.value);
320 <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">
322 <% foreach my $hidden (
323 'custnum', 'agentnum', 'refnum', 'referral_custnum',
324 'last', 'first', 'ss', 'company',
325 'address1', 'address2', 'city',
326 'county', 'state', 'zip', 'country',
327 'daytime', 'night', 'fax',
331 'ship_last', 'ship_first', 'ship_company',
332 'ship_address1', 'ship_address2', 'ship_city',
333 'ship_county', 'ship_state', 'ship_zip', 'ship_country',
334 'ship_daytime','ship_night', 'ship_fax',
339 'payinfo', 'payinfo1', 'payinfo2',
340 'payname', 'exp_month', 'exp_year', 'paycvv',
341 'paystart_month', 'paystart_year', 'payissue',
345 'invoicing_list', 'invoicing_list_POST', 'invoicing_list_FAX'
348 <INPUT TYPE="hidden" NAME="<%= $hidden %>" VALUE="">
352 <%= &ntable("#cccccc") %>
355 <TEXTAREA COLS=80 ROWS=5 WRAP="HARD" NAME="comments"><%= $cust_main->comments %></TEXTAREA>
362 unless ( $custnum ) {
363 # pry the wrong place for this logic. also pretty expensive
366 #false laziness, copied from FS::cust_pkg::order
368 if ( scalar(@agents) == 1 ) {
369 # $pkgpart->{PKGPART} is true iff $custnum may purchase PKGPART
370 my($agent)=qsearchs('agent',{'agentnum'=> $agentnum });
371 $pkgpart = $agent->pkgpart_hashref;
373 #can't know (agent not chosen), so, allow all
375 foreach my $agent ( @agents ) {
376 next if $typenum{$agent->typenum}++;
377 #fixed in 5.004_05 #$pkgpart->{$_}++ foreach keys %{ $agent->pkgpart_hashref }
378 foreach ( keys %{ $agent->pkgpart_hashref } ) { $pkgpart->{$_}++; } #5.004_04 workaround
383 my @part_pkg = grep { $_->svcpart('svc_acct') && $pkgpart->{ $_->pkgpart } }
384 qsearch( 'part_pkg', { 'disabled' => '' } );
388 # print "<BR><BR>First package", &itable("#cccccc", "0 ALIGN=LEFT"),
389 #apiabuse & undesirable wrapping
390 print "<BR>First package", &ntable("#cccccc"),
391 qq!<TR><TD COLSPAN=2><SELECT NAME="pkgpart_svcpart">!;
393 print qq!<OPTION VALUE="">(none)!;
395 foreach my $part_pkg ( @part_pkg ) {
396 print qq!<OPTION VALUE="!,
397 # $part_pkg->pkgpart. "_". $pkgpart{ $part_pkg->pkgpart }, '"';
398 $part_pkg->pkgpart. "_". $part_pkg->svcpart('svc_acct'), '"';
399 print " SELECTED" if $saved_pkgpart && ( $part_pkg->pkgpart == $saved_pkgpart );
400 print ">", $part_pkg->pkg, " - ", $part_pkg->comment;
402 print "</SELECT></TD></TR>";
404 #false laziness: (mostly) copied from edit/svc_acct.cgi
405 #$ulen = $svc_acct->dbdef_table->column('username')->length;
406 my $ulen = dbdef->table('svc_acct')->column('username')->length;
408 my $passwordmax = $conf->config('passwordmax') || 8;
409 my $pmax2 = $passwordmax + 2;
411 <TR><TD ALIGN="right">Username</TD>
412 <TD><INPUT TYPE="text" NAME="username" VALUE="$username" SIZE=$ulen2 MAXLENGTH=$ulen></TD></TR>
413 <TR><TD ALIGN="right">Password</TD>
414 <TD><INPUT TYPE="text" NAME="_password" VALUE="$password" SIZE=$pmax2 MAXLENGTH=$passwordmax>
415 (blank to generate)</TD></TR>
418 print '<TR><TD ALIGN="right">Access number</TD><TD>'
420 &FS::svc_acct_pop::popselector($popnum).
426 my $otaker = $cust_main->otaker;
427 print qq!<INPUT TYPE="hidden" NAME="otaker" VALUE="$otaker">!,
428 qq!<BR><INPUT TYPE="submit" NAME="submit" VALUE="!,
429 $custnum ? "Apply Changes" : "Add Customer", qq!"><BR>!,
430 "</FORM></DIV></BODY></HTML>",