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;
177 what.form.ship_country.selectedIndex = what.form.country.selectedIndex;
178 function fix_ship_state() {
179 what.form.ship_state.selectedIndex = what.form.state.selectedIndex;
181 ship_country_changed(what.form.ship_country, fix_ship_state );
183 function fix_ship_county() {
184 what.form.ship_county.selectedIndex = what.form.county.selectedIndex;
186 ship_state_changed(what.form.ship_state, fix_ship_county );
189 function samechanged(what) {
190 if ( what.checked ) {
192 <% for (qw( last first company address1 address2 city county state zip country daytime night fax )) { %>
193 what.form.ship_<%=$_%>.disabled = true;
194 what.form.ship_<%=$_%>.style.backgroundColor = '#dddddd';
197 <% for (qw( last first company address1 address2 city county state zip country daytime night fax )) { %>
198 what.form.ship_<%=$_%>.disabled = false;
199 what.form.ship_<%=$_%>.style.backgroundColor = '#ffffff';
208 my $disabledselect = '';
209 unless ( $cust_main->ship_last && $same ne 'Y' ) {
210 $checked = 'CHECKED';
211 $disabled = 'DISABLED style="background-color: #dddddd"';
213 qw( last first company address1 address2 city county state zip country
216 $cust_main->set("ship_$_", $cust_main->get($_) );
223 (<INPUT TYPE="checkbox" NAME="same" VALUE="Y" onClick="samechanged(this)" <%=$checked%>>same as billing address)
224 <%= include('cust_main/contact.html', $cust_main, 'ship_', '', $disabled ) %>
228 <!-- billing info -->
230 <%= include('cust_main/billing.html', $cust_main ) %>
233 function bottomfixup(what) {
235 var topvars = new Array(
236 'custnum', 'agentnum', 'refnum', 'referral_custnum',
238 'last', 'first', 'ss', 'company',
239 'address1', 'address2', 'city',
240 'county', 'state', 'zip', 'country',
241 'daytime', 'night', 'fax',
245 'ship_last', 'ship_first', 'ship_company',
246 'ship_address1', 'ship_address2', 'ship_city',
247 'ship_county', 'ship_state', 'ship_zip', 'ship_country',
248 'ship_daytime','ship_night', 'ship_fax',
253 var layervars = new Array(
255 'payinfo', 'payinfo1', 'payinfo2',
256 'payname', 'exp_month', 'exp_year', 'paycvv',
257 'paystart_month', 'paystart_year', 'payissue',
261 var billing_bottomvars = new Array(
263 'invoicing_list', 'invoicing_list_POST', 'invoicing_list_FAX'
266 for ( f=0; f < topvars.length; f++ ) {
267 var field = topvars[f];
268 copyelement( document.topform.elements[field],
269 document.bottomform.elements[field]
273 var layerform = document.topform.select.options[document.topform.select.selectedIndex].value;
274 for ( f=0; f < layervars.length; f++ ) {
275 var field = layervars[f];
276 copyelement( document.forms[layerform].elements[field],
277 document.bottomform.elements[field]
281 for ( f=0; f < billing_bottomvars.length; f++ ) {
282 var field = billing_bottomvars[f];
283 copyelement( document.billing_bottomform.elements[field],
284 document.bottomform.elements[field]
290 function copyelement(from, to) {
291 if ( from == undefined ) {
293 } else if ( from.type == 'select-one' ) {
294 to.value = from.options[from.selectedIndex].value;
295 //alert(from + " (" + from.type + "): " + to.name + " => (" + from.selectedIndex + ") " + to.value);
296 } else if ( from.type == 'checkbox' ) {
297 if ( from.checked ) {
298 to.value = from.value;
303 if ( from.value == undefined ) {
306 to.value = from.value;
309 //alert(from + ": " + to.name + " => " + to.value);
314 <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">
316 <% foreach my $hidden (
317 'custnum', 'agentnum', 'refnum', 'referral_custnum',
318 'last', 'first', 'ss', 'company',
319 'address1', 'address2', 'city',
320 'county', 'state', 'zip', 'country',
321 'daytime', 'night', 'fax',
325 'ship_last', 'ship_first', 'ship_company',
326 'ship_address1', 'ship_address2', 'ship_city',
327 'ship_county', 'ship_state', 'ship_zip', 'ship_country',
328 'ship_daytime','ship_night', 'ship_fax',
333 'payinfo', 'payinfo1', 'payinfo2',
334 'payname', 'exp_month', 'exp_year', 'paycvv',
335 'paystart_month', 'paystart_year', 'payissue',
339 'invoicing_list', 'invoicing_list_POST', 'invoicing_list_FAX'
342 <INPUT TYPE="hidden" NAME="<%= $hidden %>" VALUE="">
346 <%= &ntable("#cccccc") %>
349 <TEXTAREA COLS=80 ROWS=5 WRAP="HARD" NAME="comments"><%= $cust_main->comments %></TEXTAREA>
356 unless ( $custnum ) {
357 # pry the wrong place for this logic. also pretty expensive
360 #false laziness, copied from FS::cust_pkg::order
362 if ( scalar(@agents) == 1 ) {
363 # $pkgpart->{PKGPART} is true iff $custnum may purchase PKGPART
364 my($agent)=qsearchs('agent',{'agentnum'=> $agentnum });
365 $pkgpart = $agent->pkgpart_hashref;
367 #can't know (agent not chosen), so, allow all
369 foreach my $agent ( @agents ) {
370 next if $typenum{$agent->typenum}++;
371 #fixed in 5.004_05 #$pkgpart->{$_}++ foreach keys %{ $agent->pkgpart_hashref }
372 foreach ( keys %{ $agent->pkgpart_hashref } ) { $pkgpart->{$_}++; } #5.004_04 workaround
377 my @part_pkg = grep { $_->svcpart('svc_acct') && $pkgpart->{ $_->pkgpart } }
378 qsearch( 'part_pkg', { 'disabled' => '' } );
382 # print "<BR><BR>First package", &itable("#cccccc", "0 ALIGN=LEFT"),
383 #apiabuse & undesirable wrapping
384 print "<BR>First package", &ntable("#cccccc"),
385 qq!<TR><TD COLSPAN=2><SELECT NAME="pkgpart_svcpart">!;
387 print qq!<OPTION VALUE="">(none)!;
389 foreach my $part_pkg ( @part_pkg ) {
390 print qq!<OPTION VALUE="!,
391 # $part_pkg->pkgpart. "_". $pkgpart{ $part_pkg->pkgpart }, '"';
392 $part_pkg->pkgpart. "_". $part_pkg->svcpart('svc_acct'), '"';
393 print " SELECTED" if $saved_pkgpart && ( $part_pkg->pkgpart == $saved_pkgpart );
394 print ">", $part_pkg->pkg, " - ", $part_pkg->comment;
396 print "</SELECT></TD></TR>";
398 #false laziness: (mostly) copied from edit/svc_acct.cgi
399 #$ulen = $svc_acct->dbdef_table->column('username')->length;
400 my $ulen = dbdef->table('svc_acct')->column('username')->length;
402 my $passwordmax = $conf->config('passwordmax') || 8;
403 my $pmax2 = $passwordmax + 2;
405 <TR><TD ALIGN="right">Username</TD>
406 <TD><INPUT TYPE="text" NAME="username" VALUE="$username" SIZE=$ulen2 MAXLENGTH=$ulen></TD></TR>
407 <TR><TD ALIGN="right">Password</TD>
408 <TD><INPUT TYPE="text" NAME="_password" VALUE="$password" SIZE=$pmax2 MAXLENGTH=$passwordmax>
409 (blank to generate)</TD></TR>
412 print '<TR><TD ALIGN="right">Access number</TD><TD>'
414 &FS::svc_acct_pop::popselector($popnum).
420 my $otaker = $cust_main->otaker;
421 print qq!<INPUT TYPE="hidden" NAME="otaker" VALUE="$otaker">!,
422 qq!<BR><INPUT TYPE="submit" NAME="submit" VALUE="!,
423 $custnum ? "Apply Changes" : "Add Customer", qq!"><BR>!,
424 "</FORM></DIV></BODY></HTML>",