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 $cust_main->setfield('paid' => $cgi->param('paid')) if $cgi->param('paid');
39 } elsif ( $cgi->keywords ) { #editing
40 my( $query ) = $cgi->keywords;
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') );
67 my $action = $custnum ? 'Edit' : 'Add';
73 <%= header("Customer $action", '', ' onUnload="myclose()"') %>
76 <FONT SIZE="+1" COLOR="#ff0000">Error: <%= $error %></FONT>
79 <FORM NAME="topform" STYLE="margin-bottom: 0">
80 <INPUT TYPE="hidden" NAME="custnum" VALUE="<%= $custnum %>">
81 Customer # <%= $custnum ? "<B>$custnum</B>" : " (NEW)" %>
87 my $r = qq!<font color="#ff0000">*</font> !;
89 my %agent_search = dbdef->table('agent')->column('disabled')
90 ? ( 'disabled' => '' ) : ();
91 my @agents = qsearch( 'agent', \%agent_search );
92 #die "No agents created!" unless @agents;
93 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;
94 my $agentnum = $cust_main->agentnum || $agents[0]->agentnum; #default to first
98 <% if ( scalar(@agents) == 1 ) { %>
99 <INPUT TYPE="hidden" NAME="agentnum" VALUE="<%= $agentnum %>">
101 <BR><BR><%=$r%>Agent <SELECT NAME="agentnum" SIZE="1">
102 <% foreach my $agent (sort { $a->agent cmp $b->agent; } @agents) { %>
103 <OPTION VALUE="<%= $agent->agentnum %>"<%= " SELECTED"x($agent->agentnum==$agentnum) %>><%= $agent->agent %>
108 <!-- referral (advertising source) -->
111 my $refnum = $cust_main->refnum || $conf->config('referraldefault') || 0;
112 if ( $custnum && ! $conf->exists('editreferrals') ) {
115 <INPUT TYPE="hidden" NAME="refnum" VALUE="<%= $refnum %>">
120 my(@referrals) = qsearch('part_referral',{});
121 if ( scalar(@referrals) == 0 ) {
122 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.";
123 } elsif ( scalar(@referrals) == 1 ) {
124 $refnum ||= $referrals[0]->refnum;
127 <INPUT TYPE="hidden" NAME="refnum" VALUE="<%= $refnum %>">
131 <BR><BR><%=$r%>Advertising source
132 <SELECT NAME="refnum" SIZE="1">
133 <%= $refnum ? '' : '<OPTION VALUE="">' %>
134 <% foreach my $referral (sort { $a->refnum <=> $b->refnum } @referrals) { %>
135 <OPTION VALUE="<%= $referral->refnum %>" <%= $referral->refnum == $refnum ? 'SELECTED' : '' %>><%= $referral->refnum %>: <%= $referral->referral %>
142 <!-- referring customer -->
145 my $referring_cust_main = '';
146 if ( $cust_main->referral_custnum
147 and $referring_cust_main =
148 qsearchs('cust_main', { custnum => $cust_main->referral_custnum } )
152 <BR><BR>Referring Customer:
153 <A HREF="<%= popurl(1) %>/cust_main.cgi?<%= $cust_main->referral_custnum %>"><%= $cust_main->referral_custnum %>: <%= $referring_cust_main->name %></A>
154 <INPUT TYPE="hidden" NAME="referral_custnum" VALUE="<%= $cust_main->referral_custnum %>">
156 <% } elsif ( ! $conf->exists('disable_customer_referrals') ) { %>
158 <BR><BR>Referring customer number:
159 <INPUT TYPE="text" NAME="referral_custnum" VALUE="">
163 <INPUT TYPE="hidden" NAME="referral_custnum" VALUE="">
167 <!-- contact info -->
171 <%= include('cust_main/contact.html', $cust_main, '', 'bill_changed(this)', '' ) %>
173 <!-- service address -->
175 <% if ( defined $cust_main->dbdef_table->column('ship_last') ) { %>
178 function bill_changed(what) {
179 if ( what.form.same.checked ) {
180 <% for (qw( last first company address1 address2 city zip daytime night fax )) { %>
181 what.form.ship_<%=$_%>.value = what.form.<%=$_%>.value;
184 what.form.ship_country.selectedIndex = what.form.country.selectedIndex;
185 function fix_ship_state() {
186 what.form.ship_state.selectedIndex = what.form.state.selectedIndex;
188 ship_country_changed(what.form.ship_country, fix_ship_state );
190 function fix_ship_county() {
191 what.form.ship_county.selectedIndex = what.form.county.selectedIndex;
193 ship_state_changed(what.form.ship_state, fix_ship_county );
196 function samechanged(what) {
197 if ( what.checked ) {
199 <% for (qw( last first company address1 address2 city county state zip country daytime night fax )) { %>
200 what.form.ship_<%=$_%>.disabled = true;
201 what.form.ship_<%=$_%>.style.backgroundColor = '#dddddd';
204 <% for (qw( last first company address1 address2 city county state zip country daytime night fax )) { %>
205 what.form.ship_<%=$_%>.disabled = false;
206 what.form.ship_<%=$_%>.style.backgroundColor = '#ffffff';
215 my $disabledselect = '';
216 unless ( $cust_main->ship_last && $same ne 'Y' ) {
217 $checked = 'CHECKED';
218 $disabled = 'DISABLED style="background-color: #dddddd"';
220 qw( last first company address1 address2 city county state zip country
223 $cust_main->set("ship_$_", $cust_main->get($_) );
230 (<INPUT TYPE="checkbox" NAME="same" VALUE="Y" onClick="samechanged(this)" <%=$checked%>>same as billing address)
231 <%= include('cust_main/contact.html', $cust_main, 'ship_', '', $disabled ) %>
235 <!-- billing info -->
237 <%= include( 'cust_main/billing.html', $cust_main,
238 'invoicing_list' => \@invoicing_list,
243 function bottomfixup(what) {
245 var topvars = new Array(
246 'custnum', 'agentnum', 'refnum', 'referral_custnum',
248 'last', 'first', 'ss', 'company',
249 'address1', 'address2', 'city',
250 'county', 'state', 'zip', 'country',
251 'daytime', 'night', 'fax',
255 'ship_last', 'ship_first', 'ship_company',
256 'ship_address1', 'ship_address2', 'ship_city',
257 'ship_county', 'ship_state', 'ship_zip', 'ship_country',
258 'ship_daytime','ship_night', 'ship_fax',
263 var layervars = new Array(
265 'payinfo', 'payinfo1', 'payinfo2',
266 'payname', 'exp_month', 'exp_year', 'paycvv',
267 'paystart_month', 'paystart_year', 'payissue',
272 var billing_bottomvars = new Array(
274 'invoicing_list', 'invoicing_list_POST', 'invoicing_list_FAX'
277 for ( f=0; f < topvars.length; f++ ) {
278 var field = topvars[f];
279 copyelement( document.topform.elements[field],
280 document.bottomform.elements[field]
284 var layerform = document.topform.select.options[document.topform.select.selectedIndex].value;
285 for ( f=0; f < layervars.length; f++ ) {
286 var field = layervars[f];
287 copyelement( document.forms[layerform].elements[field],
288 document.bottomform.elements[field]
292 for ( f=0; f < billing_bottomvars.length; f++ ) {
293 var field = billing_bottomvars[f];
294 copyelement( document.billing_bottomform.elements[field],
295 document.bottomform.elements[field]
301 function copyelement(from, to) {
302 if ( from == undefined ) {
304 } else if ( from.type == 'select-one' ) {
305 to.value = from.options[from.selectedIndex].value;
306 //alert(from + " (" + from.type + "): " + to.name + " => (" + from.selectedIndex + ") " + to.value);
307 } else if ( from.type == 'checkbox' ) {
308 if ( from.checked ) {
309 to.value = from.value;
314 if ( from.value == undefined ) {
317 to.value = from.value;
320 //alert(from + " (" + from.type + "): " + to.name + " => " + to.value);
325 <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">
327 <% foreach my $hidden (
328 'custnum', 'agentnum', 'refnum', 'referral_custnum',
329 'last', 'first', 'ss', 'company',
330 'address1', 'address2', 'city',
331 'county', 'state', 'zip', 'country',
332 'daytime', 'night', 'fax',
336 'ship_last', 'ship_first', 'ship_company',
337 'ship_address1', 'ship_address2', 'ship_city',
338 'ship_county', 'ship_state', 'ship_zip', 'ship_country',
339 'ship_daytime','ship_night', 'ship_fax',
344 'payinfo', 'payinfo1', 'payinfo2',
345 'payname', 'exp_month', 'exp_year', 'paycvv',
346 'paystart_month', 'paystart_year', 'payissue',
351 'invoicing_list', 'invoicing_list_POST', 'invoicing_list_FAX'
354 <INPUT TYPE="hidden" NAME="<%= $hidden %>" VALUE="">
358 <%= &ntable("#cccccc") %>
361 <TEXTAREA COLS=80 ROWS=5 WRAP="HARD" NAME="comments"><%= $cust_main->comments %></TEXTAREA>
368 unless ( $custnum ) {
369 # pry the wrong place for this logic. also pretty expensive
372 #false laziness, copied from FS::cust_pkg::order
374 if ( scalar(@agents) == 1 ) {
375 # $pkgpart->{PKGPART} is true iff $custnum may purchase PKGPART
376 my($agent)=qsearchs('agent',{'agentnum'=> $agentnum });
377 $pkgpart = $agent->pkgpart_hashref;
379 #can't know (agent not chosen), so, allow all
381 foreach my $agent ( @agents ) {
382 next if $typenum{$agent->typenum}++;
383 #fixed in 5.004_05 #$pkgpart->{$_}++ foreach keys %{ $agent->pkgpart_hashref }
384 foreach ( keys %{ $agent->pkgpart_hashref } ) { $pkgpart->{$_}++; } #5.004_04 workaround
389 my @part_pkg = grep { $_->svcpart('svc_acct') && $pkgpart->{ $_->pkgpart } }
390 qsearch( 'part_pkg', { 'disabled' => '' } );
394 # print "<BR><BR>First package", &itable("#cccccc", "0 ALIGN=LEFT"),
395 #apiabuse & undesirable wrapping
396 print "<BR>First package", &ntable("#cccccc"),
397 qq!<TR><TD COLSPAN=2><SELECT NAME="pkgpart_svcpart">!;
399 print qq!<OPTION VALUE="">(none)!;
401 foreach my $part_pkg ( @part_pkg ) {
402 print qq!<OPTION VALUE="!,
403 # $part_pkg->pkgpart. "_". $pkgpart{ $part_pkg->pkgpart }, '"';
404 $part_pkg->pkgpart. "_". $part_pkg->svcpart('svc_acct'), '"';
405 print " SELECTED" if $saved_pkgpart && ( $part_pkg->pkgpart == $saved_pkgpart );
406 print ">", $part_pkg->pkg, " - ", $part_pkg->comment;
408 print "</SELECT></TD></TR>";
410 #false laziness: (mostly) copied from edit/svc_acct.cgi
411 #$ulen = $svc_acct->dbdef_table->column('username')->length;
412 my $ulen = dbdef->table('svc_acct')->column('username')->length;
414 my $passwordmax = $conf->config('passwordmax') || 8;
415 my $pmax2 = $passwordmax + 2;
417 <TR><TD ALIGN="right">Username</TD>
418 <TD><INPUT TYPE="text" NAME="username" VALUE="$username" SIZE=$ulen2 MAXLENGTH=$ulen></TD></TR>
419 <TR><TD ALIGN="right">Password</TD>
420 <TD><INPUT TYPE="text" NAME="_password" VALUE="$password" SIZE=$pmax2 MAXLENGTH=$passwordmax>
421 (blank to generate)</TD></TR>
424 print '<TR><TD ALIGN="right">Access number</TD><TD>'
426 &FS::svc_acct_pop::popselector($popnum).
432 my $otaker = $cust_main->otaker;
433 print qq!<INPUT TYPE="hidden" NAME="otaker" VALUE="$otaker">!,
434 qq!<BR><INPUT TYPE="submit" NAME="submit" VALUE="!,
435 $custnum ? "Apply Changes" : "Add Customer", qq!"><BR>!,
436 "</FORM></DIV></BODY></HTML>",