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 ) %>
240 function bottomfixup(what) {
242 var topvars = new Array(
243 'custnum', 'agentnum', 'refnum', 'referral_custnum',
245 'last', 'first', 'ss', 'company',
246 'address1', 'address2', 'city',
247 'county', 'state', 'zip', 'country',
248 'daytime', 'night', 'fax',
252 'ship_last', 'ship_first', 'ship_company',
253 'ship_address1', 'ship_address2', 'ship_city',
254 'ship_county', 'ship_state', 'ship_zip', 'ship_country',
255 'ship_daytime','ship_night', 'ship_fax',
260 var layervars = new Array(
262 'payinfo', 'payinfo1', 'payinfo2',
263 'payname', 'exp_month', 'exp_year', 'paycvv',
264 'paystart_month', 'paystart_year', 'payissue',
269 var billing_bottomvars = new Array(
271 'invoicing_list', 'invoicing_list_POST', 'invoicing_list_FAX'
274 for ( f=0; f < topvars.length; f++ ) {
275 var field = topvars[f];
276 copyelement( document.topform.elements[field],
277 document.bottomform.elements[field]
281 var layerform = document.topform.select.options[document.topform.select.selectedIndex].value;
282 for ( f=0; f < layervars.length; f++ ) {
283 var field = layervars[f];
284 copyelement( document.forms[layerform].elements[field],
285 document.bottomform.elements[field]
289 for ( f=0; f < billing_bottomvars.length; f++ ) {
290 var field = billing_bottomvars[f];
291 copyelement( document.billing_bottomform.elements[field],
292 document.bottomform.elements[field]
298 function copyelement(from, to) {
299 if ( from == undefined ) {
301 } else if ( from.type == 'select-one' ) {
302 to.value = from.options[from.selectedIndex].value;
303 //alert(from + " (" + from.type + "): " + to.name + " => (" + from.selectedIndex + ") " + to.value);
304 } else if ( from.type == 'checkbox' ) {
305 if ( from.checked ) {
306 to.value = from.value;
311 if ( from.value == undefined ) {
314 to.value = from.value;
317 //alert(from + " (" + from.type + "): " + to.name + " => " + to.value);
322 <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">
324 <% foreach my $hidden (
325 'custnum', 'agentnum', 'refnum', 'referral_custnum',
326 'last', 'first', 'ss', 'company',
327 'address1', 'address2', 'city',
328 'county', 'state', 'zip', 'country',
329 'daytime', 'night', 'fax',
333 'ship_last', 'ship_first', 'ship_company',
334 'ship_address1', 'ship_address2', 'ship_city',
335 'ship_county', 'ship_state', 'ship_zip', 'ship_country',
336 'ship_daytime','ship_night', 'ship_fax',
341 'payinfo', 'payinfo1', 'payinfo2',
342 'payname', 'exp_month', 'exp_year', 'paycvv',
343 'paystart_month', 'paystart_year', 'payissue',
348 'invoicing_list', 'invoicing_list_POST', 'invoicing_list_FAX'
351 <INPUT TYPE="hidden" NAME="<%= $hidden %>" VALUE="">
355 <%= &ntable("#cccccc") %>
358 <TEXTAREA COLS=80 ROWS=5 WRAP="HARD" NAME="comments"><%= $cust_main->comments %></TEXTAREA>
365 unless ( $custnum ) {
366 # pry the wrong place for this logic. also pretty expensive
369 #false laziness, copied from FS::cust_pkg::order
371 if ( scalar(@agents) == 1 ) {
372 # $pkgpart->{PKGPART} is true iff $custnum may purchase PKGPART
373 my($agent)=qsearchs('agent',{'agentnum'=> $agentnum });
374 $pkgpart = $agent->pkgpart_hashref;
376 #can't know (agent not chosen), so, allow all
378 foreach my $agent ( @agents ) {
379 next if $typenum{$agent->typenum}++;
380 #fixed in 5.004_05 #$pkgpart->{$_}++ foreach keys %{ $agent->pkgpart_hashref }
381 foreach ( keys %{ $agent->pkgpart_hashref } ) { $pkgpart->{$_}++; } #5.004_04 workaround
386 my @part_pkg = grep { $_->svcpart('svc_acct') && $pkgpart->{ $_->pkgpart } }
387 qsearch( 'part_pkg', { 'disabled' => '' } );
391 # print "<BR><BR>First package", &itable("#cccccc", "0 ALIGN=LEFT"),
392 #apiabuse & undesirable wrapping
393 print "<BR>First package", &ntable("#cccccc"),
394 qq!<TR><TD COLSPAN=2><SELECT NAME="pkgpart_svcpart">!;
396 print qq!<OPTION VALUE="">(none)!;
398 foreach my $part_pkg ( @part_pkg ) {
399 print qq!<OPTION VALUE="!,
400 # $part_pkg->pkgpart. "_". $pkgpart{ $part_pkg->pkgpart }, '"';
401 $part_pkg->pkgpart. "_". $part_pkg->svcpart('svc_acct'), '"';
402 print " SELECTED" if $saved_pkgpart && ( $part_pkg->pkgpart == $saved_pkgpart );
403 print ">", $part_pkg->pkg, " - ", $part_pkg->comment;
405 print "</SELECT></TD></TR>";
407 #false laziness: (mostly) copied from edit/svc_acct.cgi
408 #$ulen = $svc_acct->dbdef_table->column('username')->length;
409 my $ulen = dbdef->table('svc_acct')->column('username')->length;
411 my $passwordmax = $conf->config('passwordmax') || 8;
412 my $pmax2 = $passwordmax + 2;
414 <TR><TD ALIGN="right">Username</TD>
415 <TD><INPUT TYPE="text" NAME="username" VALUE="$username" SIZE=$ulen2 MAXLENGTH=$ulen></TD></TR>
416 <TR><TD ALIGN="right">Password</TD>
417 <TD><INPUT TYPE="text" NAME="_password" VALUE="$password" SIZE=$pmax2 MAXLENGTH=$passwordmax>
418 (blank to generate)</TD></TR>
421 print '<TR><TD ALIGN="right">Access number</TD><TD>'
423 &FS::svc_acct_pop::popselector($popnum).
429 my $otaker = $cust_main->otaker;
430 print qq!<INPUT TYPE="hidden" NAME="otaker" VALUE="$otaker">!,
431 qq!<BR><INPUT TYPE="submit" NAME="submit" VALUE="!,
432 $custnum ? "Apply Changes" : "Add Customer", qq!"><BR>!,
433 "</FORM></DIV></BODY></HTML>",