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 %>
109 # (referral and referring customer still need to be "template"ized)
113 my $refnum = $cust_main->refnum || $conf->config('referraldefault') || 0;
114 if ( $custnum && ! $conf->exists('editreferrals') ) {
115 print qq!<INPUT TYPE="hidden" NAME="refnum" VALUE="$refnum">!;
117 my(@referrals) = qsearch('part_referral',{});
118 if ( scalar(@referrals) == 0 ) {
119 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.";
120 } elsif ( scalar(@referrals) == 1 ) {
121 $refnum ||= $referrals[0]->refnum;
122 print qq!<INPUT TYPE="hidden" NAME="refnum" VALUE="$refnum">!;
124 print qq!<BR><BR>${r}Advertising source <SELECT NAME="refnum" SIZE="1">!;
125 print "<OPTION> " unless $refnum;
127 foreach $referral (sort {
128 $a->refnum <=> $b->refnum;
130 print "<OPTION" . " SELECTED"x($referral->refnum==$refnum),
131 ">", $referral->refnum, ": ", $referral->referral;
139 #print qq!<BR><BR>Referring Customer: !;
140 my $referring_cust_main = '';
141 if ( $cust_main->referral_custnum
142 and $referring_cust_main =
143 qsearchs('cust_main', { custnum => $cust_main->referral_custnum } )
145 print '<BR><BR>Referring Customer: <A HREF="'. popurl(1). '/cust_main.cgi?'.
146 $cust_main->referral_custnum. '">'.
147 $cust_main->referral_custnum. ': '.
148 ( $referring_cust_main->company
149 || $referring_cust_main->last. ', '. $referring_cust_main->first ).
150 '</A><INPUT TYPE="hidden" NAME="referral_custnum" VALUE="'.
151 $cust_main->referral_custnum. '">';
152 } elsif ( ! $conf->exists('disable_customer_referrals') ) {
153 print '<BR><BR>Referring customer number: <INPUT TYPE="text" NAME="referral_custnum" VALUE="">';
155 print '<INPUT TYPE="hidden" NAME="referral_custnum" VALUE="">';
160 <!-- contact info -->
164 <%= include('cust_main/contact.html', $cust_main, '', 'bill_changed(this)', '' ) %>
166 <!-- service address -->
168 <% if ( defined $cust_main->dbdef_table->column('ship_last') ) { %>
171 function bill_changed(what) {
172 if ( what.form.same.checked ) {
173 <% for (qw( last first company address1 address2 city zip daytime night fax )) { %>
174 what.form.ship_<%=$_%>.value = what.form.<%=$_%>.value;
176 what.form.ship_country.selectedIndex = what.form.country.selectedIndex;
177 ship_country_changed(what.form.ship_country);
178 what.form.ship_state.selectedIndex = what.form.state.selectedIndex;
179 ship_state_changed(what.form.ship_state);
180 what.form.ship_county.selectedIndex = what.form.county.selectedIndex;
183 function samechanged(what) {
184 if ( what.checked ) {
186 <% for (qw( last first company address1 address2 city county state zip country daytime night fax )) { %>
187 what.form.ship_<%=$_%>.disabled = true;
188 what.form.ship_<%=$_%>.style.backgroundColor = '#dddddd';
191 <% for (qw( last first company address1 address2 city county state zip country daytime night fax )) { %>
192 what.form.ship_<%=$_%>.disabled = false;
193 what.form.ship_<%=$_%>.style.backgroundColor = '#ffffff';
202 my $disabledselect = '';
203 unless ( $cust_main->ship_last && $same ne 'Y' ) {
204 $checked = 'CHECKED';
205 $disabled = 'DISABLED style="background-color: #dddddd"';
207 qw( last first company address1 address2 city county state zip country
210 $cust_main->set("ship_$_", $cust_main->get($_) );
217 (<INPUT TYPE="checkbox" NAME="same" VALUE="Y" onClick="samechanged(this)" <%=$checked%>>same as billing address)
218 <%= include('cust_main/contact.html', $cust_main, 'ship_', '', $disabled ) %>
222 <!-- billing info -->
224 <%= include('cust_main/billing.html', $cust_main ) %>
227 function bottomfixup(what) {
229 var topvars = new Array(
230 'custnum', 'agentnum', 'refnum', 'referral_custnum',
232 'last', 'first', 'ss', 'company',
233 'address1', 'address2', 'city',
234 'county', 'state', 'zip', 'country',
235 'daytime', 'night', 'fax',
239 'ship_last', 'ship_first', 'ship_company',
240 'ship_address1', 'ship_address2', 'ship_city',
241 'ship_county', 'ship_state', 'ship_zip', 'ship_country',
242 'ship_daytime','ship_night', 'ship_fax',
247 var layervars = new Array(
249 'payinfo', 'payinfo1', 'payinfo2',
250 'exp_month', 'exp_year', 'paycvv',
251 'paystart_month', 'paystart_year', 'payissue',
255 var billing_bottomvars = new Array(
257 'invoicing_list', 'invoicing_list_POST', 'invoicing_list_FAX'
260 for ( f=0; f < topvars.length; f++ ) {
261 var field = topvars[f];
262 copyelement( document.topform.elements[field],
263 document.bottomform.elements[field]
267 var layerform = document.topform.select.options[document.topform.select.selectedIndex].value;
268 for ( f=0; f < layervars.length; f++ ) {
269 var field = layervars[f];
270 copyelement( document.forms[layerform].elements[field],
271 document.bottomform.elements[field]
275 for ( f=0; f < billing_bottomvars.length; f++ ) {
276 var field = billing_bottomvars[f];
277 copyelement( document.billing_bottomform.elements[field],
278 document.bottomform.elements[field]
284 function copyelement(from, to) {
285 if ( from == undefined ) {
287 } else if ( from.type == 'select-one' ) {
288 to.value = from.options[from.selectedIndex].value;
289 //alert(from + " (" + from.type + "): " + to.name + " => (" + from.selectedIndex + ") " + to.value);
290 } else if ( from.type == 'checkbox' ) {
291 if ( from.checked ) {
292 to.value = from.value;
297 if ( from.value == undefined ) {
300 to.value = from.value;
303 //alert(from + ": " + to.name + " => " + to.value);
308 <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">
310 <% foreach my $hidden (
311 'custnum', 'agentnum', 'refnum', 'referral_custnum',
312 'last', 'first', 'ss', 'company',
313 'address1', 'address2', 'city',
314 'county', 'state', 'zip', 'country',
315 'daytime', 'night', 'fax',
319 'ship_last', 'ship_first', 'ship_company',
320 'ship_address1', 'ship_address2', 'ship_city',
321 'ship_county', 'ship_state', 'ship_zip', 'ship_country',
322 'ship_daytime','ship_night', 'ship_fax',
327 'payinfo', 'payinfo1', 'payinfo2',
328 'exp_month', 'exp_year', 'paycvv',
329 'paystart_month', 'paystart_year', 'payissue',
333 'invoicing_list', 'invoicing_list_POST', 'invoicing_list_FAX'
336 <INPUT TYPE="hidden" NAME="<%= $hidden %>" VALUE="">
340 <%= &ntable("#cccccc") %>
343 <TEXTAREA COLS=80 ROWS=5 WRAP="HARD" NAME="comments"><%= $cust_main->comments %></TEXTAREA>
350 unless ( $custnum ) {
351 # pry the wrong place for this logic. also pretty expensive
354 #false laziness, copied from FS::cust_pkg::order
356 if ( scalar(@agents) == 1 ) {
357 # $pkgpart->{PKGPART} is true iff $custnum may purchase PKGPART
358 my($agent)=qsearchs('agent',{'agentnum'=> $agentnum });
359 $pkgpart = $agent->pkgpart_hashref;
361 #can't know (agent not chosen), so, allow all
363 foreach my $agent ( @agents ) {
364 next if $typenum{$agent->typenum}++;
365 #fixed in 5.004_05 #$pkgpart->{$_}++ foreach keys %{ $agent->pkgpart_hashref }
366 foreach ( keys %{ $agent->pkgpart_hashref } ) { $pkgpart->{$_}++; } #5.004_04 workaround
371 my @part_pkg = grep { $_->svcpart('svc_acct') && $pkgpart->{ $_->pkgpart } }
372 qsearch( 'part_pkg', { 'disabled' => '' } );
376 # print "<BR><BR>First package", &itable("#cccccc", "0 ALIGN=LEFT"),
377 #apiabuse & undesirable wrapping
378 print "<BR>First package", &ntable("#cccccc"),
379 qq!<TR><TD COLSPAN=2><SELECT NAME="pkgpart_svcpart">!;
381 print qq!<OPTION VALUE="">(none)!;
383 foreach my $part_pkg ( @part_pkg ) {
384 print qq!<OPTION VALUE="!,
385 # $part_pkg->pkgpart. "_". $pkgpart{ $part_pkg->pkgpart }, '"';
386 $part_pkg->pkgpart. "_". $part_pkg->svcpart('svc_acct'), '"';
387 print " SELECTED" if $saved_pkgpart && ( $part_pkg->pkgpart == $saved_pkgpart );
388 print ">", $part_pkg->pkg, " - ", $part_pkg->comment;
390 print "</SELECT></TD></TR>";
392 #false laziness: (mostly) copied from edit/svc_acct.cgi
393 #$ulen = $svc_acct->dbdef_table->column('username')->length;
394 my $ulen = dbdef->table('svc_acct')->column('username')->length;
396 my $passwordmax = $conf->config('passwordmax') || 8;
397 my $pmax2 = $passwordmax + 2;
399 <TR><TD ALIGN="right">Username</TD>
400 <TD><INPUT TYPE="text" NAME="username" VALUE="$username" SIZE=$ulen2 MAXLENGTH=$ulen></TD></TR>
401 <TR><TD ALIGN="right">Password</TD>
402 <TD><INPUT TYPE="text" NAME="_password" VALUE="$password" SIZE=$pmax2 MAXLENGTH=$passwordmax>
403 (blank to generate)</TD></TR>
406 print '<TR><TD ALIGN="right">Access number</TD><TD>'
408 &FS::svc_acct_pop::popselector($popnum).
414 my $otaker = $cust_main->otaker;
415 print qq!<INPUT TYPE="hidden" NAME="otaker" VALUE="$otaker">!,
416 qq!<BR><INPUT TYPE="submit" NAME="submit" VALUE="!,
417 $custnum ? "Apply Changes" : "Add Customer", qq!"><BR>!,
418 "</FORM></DIV></BODY></HTML>",