4 #for misplaced logic below
7 #for false laziness below (now more properly lazy)
10 #for (other) false laziness below
14 my $conf = new FS::Conf;
19 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 } elsif ( $cgi->keywords ) { #editing
38 my( $query ) = $cgi->keywords;
41 $cust_main = qsearchs('cust_main', { 'custnum' => $custnum } );
42 if ( $cust_main->dbdef_table->column('paycvv')
43 && length($cust_main->paycvv) ) {
44 my $paycvv = $cust_main->paycvv;
46 $cust_main->paycvv($paycvv);
52 @invoicing_list = $cust_main->invoicing_list;
55 $cust_main = new FS::cust_main ( {} );
56 $cust_main->otaker( &getotaker );
57 $cust_main->referral_custnum( $cgi->param('referral_custnum') );
65 my $action = $custnum ? 'Edit' : 'Add';
71 <%= header("Customer $action", '', ' onUnload="myclose()"') %>
74 <FONT SIZE="+1" COLOR="#ff0000">Error: <%= $error %></FONT>
77 <FORM ACTION="<%= popurl(1) %>process/cust_main.cgi" METHOD=POST NAME="form1" onSubmit="document.form1.submit.disabled=true">
78 <INPUT TYPE="hidden" NAME="custnum" VALUE="<%= $custnum %>">
79 Customer # <%= $custnum ? "<B>$custnum</B>" : " (NEW)" %>
85 my $r = qq!<font color="#ff0000">*</font> !;
87 my %agent_search = dbdef->table('agent')->column('disabled')
88 ? ( 'disabled' => '' ) : ();
89 my @agents = qsearch( 'agent', \%agent_search );
90 #die "No agents created!" unless @agents;
91 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;
92 my $agentnum = $cust_main->agentnum || $agents[0]->agentnum; #default to first
96 <% if ( scalar(@agents) == 1 ) { %>
97 <INPUT TYPE="hidden" NAME="agentnum" VALUE="<%= $agentnum %>">
99 <BR><BR><%=$r%>Agent <SELECT NAME="agentnum" SIZE="1">
100 <% foreach my $agent (sort { $a->agent cmp $b->agent; } @agents) { %>
101 <OPTION VALUE="<%= $agent->agentnum %>"<%= " SELECTED"x($agent->agentnum==$agentnum) %>><%= $agent->agent %>
108 # (referral and referring customer still need to be "template"ized)
112 my $refnum = $cust_main->refnum || $conf->config('referraldefault') || 0;
113 if ( $custnum && ! $conf->exists('editreferrals') ) {
114 print qq!<INPUT TYPE="hidden" NAME="refnum" VALUE="$refnum">!;
116 my(@referrals) = qsearch('part_referral',{});
117 if ( scalar(@referrals) == 0 ) {
118 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.";
119 } elsif ( scalar(@referrals) == 1 ) {
120 $refnum ||= $referrals[0]->refnum;
121 print qq!<INPUT TYPE="hidden" NAME="refnum" VALUE="$refnum">!;
123 print qq!<BR><BR>${r}Advertising source <SELECT NAME="refnum" SIZE="1">!;
124 print "<OPTION> " unless $refnum;
126 foreach $referral (sort {
127 $a->refnum <=> $b->refnum;
129 print "<OPTION" . " SELECTED"x($referral->refnum==$refnum),
130 ">", $referral->refnum, ": ", $referral->referral;
138 #print qq!<BR><BR>Referring Customer: !;
139 my $referring_cust_main = '';
140 if ( $cust_main->referral_custnum
141 and $referring_cust_main =
142 qsearchs('cust_main', { custnum => $cust_main->referral_custnum } )
144 print '<BR><BR>Referring Customer: <A HREF="'. popurl(1). '/cust_main.cgi?'.
145 $cust_main->referral_custnum. '">'.
146 $cust_main->referral_custnum. ': '.
147 ( $referring_cust_main->company
148 || $referring_cust_main->last. ', '. $referring_cust_main->first ).
149 '</A><INPUT TYPE="hidden" NAME="referral_custnum" VALUE="'.
150 $cust_main->referral_custnum. '">';
151 } elsif ( ! $conf->exists('disable_customer_referrals') ) {
152 print '<BR><BR>Referring customer number: <INPUT TYPE="text" NAME="referral_custnum" VALUE="">';
154 print '<INPUT TYPE="hidden" NAME="referral_custnum" VALUE="">';
159 <!-- contact info -->
163 <%= include('cust_main/contact.html', $cust_main, '', 'bill_changed(this)', '' ) %>
165 <!-- service address -->
167 <% if ( defined $cust_main->dbdef_table->column('ship_last') ) { %>
170 function bill_changed(what) {
171 if ( what.form.same.checked ) {
172 <% for (qw( last first company address1 address2 city zip daytime night fax )) { %>
173 what.form.ship_<%=$_%>.value = what.form.<%=$_%>.value;
175 what.form.ship_country.selectedIndex = what.form.country.selectedIndex;
176 ship_country_changed(what.form.ship_country);
177 what.form.ship_state.selectedIndex = what.form.state.selectedIndex;
178 ship_state_changed(what.form.ship_state);
179 what.form.ship_county.selectedIndex = what.form.county.selectedIndex;
182 function samechanged(what) {
183 if ( what.checked ) {
185 <% for (qw( last first company address1 address2 city county state zip country daytime night fax )) { %>
186 what.form.ship_<%=$_%>.disabled = true;
187 what.form.ship_<%=$_%>.style.backgroundColor = '#dddddd';
190 <% for (qw( last first company address1 address2 city county state zip country daytime night fax )) { %>
191 what.form.ship_<%=$_%>.disabled = false;
192 what.form.ship_<%=$_%>.style.backgroundColor = '#ffffff';
201 my $disabledselect = '';
202 unless ( $cust_main->ship_last && $cgi->param('same') ne 'Y' ) {
203 $checked = 'CHECKED';
204 $disabled = 'DISABLED style="background-color: #dddddd"';
206 qw( last first company address1 address2 city county state zip country
209 $cust_main->set("ship_$_", $cust_main->get($_) );
216 (<INPUT TYPE="checkbox" NAME="same" VALUE="Y" onClick="samechanged(this)" <%=$checked%>>same as billing address)
217 <%= include('cust_main/contact.html', $cust_main, 'ship_', '', $disabled ) %>
226 my( $m, $y ) = (0, 0);
228 my $date = shift || '01-2000';
229 if ( $date =~ /^(\d{4})-(\d{1,2})-\d{1,2}$/ ) { #PostgreSQL date format
230 ( $m, $y ) = ( $2, $1 );
231 } elsif ( $date =~ /^(\d{1,2})-(\d{1,2}-)?(\d{4}$)/ ) {
232 ( $m, $y ) = ( $1, $3 );
234 die "unrecognized expiration date format: $date";
238 my $return = qq!<SELECT NAME="$prefix!. qq!_month" SIZE="1">!;
240 $return .= "<OPTION";
241 $return .= " SELECTED" if $_ == $m;
244 $return .= qq!</SELECT>/<SELECT NAME="$prefix!. qq!_year" SIZE="1">!;
246 my $thisYear = $t[5] + 1900;
247 for ( ($thisYear > $y && $y > 0 ? $y : $thisYear) .. 2037 ) {
248 $return .= "<OPTION";
249 $return .= " SELECTED" if $_ == $y;
252 $return .= "</SELECT>";
257 my $payby_default = $conf->config('payby-default');
259 if ( $payby_default eq 'HIDE' ) {
261 $cust_main->payby('BILL') unless $cust_main->payby;
263 foreach my $field (qw( tax payby )) {
264 print qq!<INPUT TYPE="hidden" NAME="$field" VALUE="!.
265 $cust_main->getfield($field). '">';
268 print qq!<INPUT TYPE="hidden" NAME="invoicing_list" VALUE="!.
269 join(', ', $cust_main->invoicing_list). '">';
271 foreach my $payby (qw( CARD DCRD CHEK DCHK LECB BILL COMP )) {
272 foreach my $field (qw( payinfo payname )) {
273 print qq!<INPUT TYPE="hidden" NAME="${payby}_$field" VALUE="!.
274 $cust_main->getfield($field). '">';
277 #false laziness w/expselect
279 my $date = $cust_main->paydate || '12-2037';
280 if ( $date =~ /^(\d{4})-(\d{1,2})-\d{1,2}$/ ) { #PostgreSQL date format
281 ( $m, $y ) = ( $2, $1 );
282 } elsif ( $date =~ /^(\d{1,2})-(\d{1,2}-)?(\d{4}$)/ ) {
283 ( $m, $y ) = ( $1, $3 );
285 die "unrecognized expiration date format: $date";
288 print qq!<INPUT TYPE="hidden" NAME="${payby}_month" VALUE="$m">!.
289 qq!<INPUT TYPE="hidden" NAME="${payby}_year" VALUE="$y">!;
295 print "<BR>Billing information", &itable("#cccccc"),
296 qq!<TR><TD><INPUT TYPE="checkbox" NAME="tax" VALUE="Y"!;
297 print qq! CHECKED! if $cust_main->tax eq "Y";
298 print qq!>Tax Exempt</TD></TR><TR><TD>!.
299 qq!<INPUT TYPE="checkbox" NAME="invoicing_list_POST" VALUE="POST"!;
301 #my @invoicing_list = $cust_main->invoicing_list;
303 if ( ! @invoicing_list && ! $conf->exists('disablepostalinvoicedefault') )
304 || grep { $_ eq 'POST' } @invoicing_list;
305 print qq!>Postal mail invoice</TD></TR><TR><TD>!;
306 print qq!<INPUT TYPE="checkbox" NAME="invoicing_list_FAX" VALUE="FAX"!;
307 print qq! CHECKED! if (grep { $_ eq 'FAX' } @invoicing_list);
308 print qq!>FAX invoice</TD></TR>!;
309 my $invoicing_list = join(', ', grep { $_ !~ /^(POST|FAX)$/ } @invoicing_list );
310 print qq!<TR><TD>Email invoice <INPUT TYPE="text" NAME="invoicing_list" VALUE="$invoicing_list"></TD></TR>!;
312 print "<TR><TD>Billing type</TD></TR>",
313 "</TABLE>", '<SCRIPT>
315 function myopen(filename,windowname,properties) {
317 mywindow = window.open(filename,windowname,properties);
320 if ( mywindow != -1 )
325 function achopen(filename,windowname,properties) {
327 achwindow = window.open(filename,windowname,properties);
329 function achclose() {
330 if ( achwindow != -1 )
335 &table("#cccccc"), "<TR>";
337 my($payinfo, $payname)=(
343 'CARD' => qq!Credit card (automatic)<BR>${r}<INPUT TYPE="text" NAME="CARD_payinfo" VALUE="" MAXLENGTH=19><BR>${r}Exp !. expselect("CARD"). qq!<BR>${r}Name on card<BR><INPUT TYPE="text" NAME="CARD_payname" VALUE="">!,
344 'DCRD' => qq!Credit card (on-demand)<BR>${r}<INPUT TYPE="text" NAME="DCRD_payinfo" VALUE="" MAXLENGTH=19><BR>${r}Exp !. expselect("DCRD"). qq!<BR>${r}Name on card<BR><INPUT TYPE="text" NAME="DCRD_payname" VALUE="">!,
345 'CHEK' => qq!Electronic check (automatic)<BR>${r}Account number <INPUT TYPE="text" NAME="CHEK_payinfo1" VALUE=""><BR>${r}ABA/Routing number <INPUT TYPE="text" NAME="CHEK_payinfo2" VALUE="" SIZE=10 MAXLENGTH=9> (<A HREF="javascript:achopen('../docs/ach.html','ach','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=yes,copyhistory=no,width=384,height=256')">help</A>)<INPUT TYPE="hidden" NAME="CHEK_month" VALUE="12"><INPUT TYPE="hidden" NAME="CHEK_year" VALUE="2037"><BR>${r}Bank name <INPUT TYPE="text" NAME="CHEK_payname" VALUE="">!,
346 'DCHK' => qq!Electronic check (on-demand)<BR>${r}Account number <INPUT TYPE="text" NAME="DCHK_payinfo1" VALUE=""><BR>${r}ABA/Routing number <INPUT TYPE="text" NAME="DCHK_payinfo2" VALUE="" SIZE=10 MAXLENGTH=9> (<A HREF="javascript:achopen('../docs/ach.html','ach','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=yes,copyhistory=no,width=384,height=256')">help</A>)<INPUT TYPE="hidden" NAME="DCHK_month" VALUE="12"><INPUT TYPE="hidden" NAME="DCHK_year" VALUE="2037"><BR>${r}Bank name <INPUT TYPE="text" NAME="DCHK_payname" VALUE="">!,
347 'LECB' => qq!Phone bill billing<BR>${r}Phone number <INPUT TYPE="text" BANE="LECB_payinfo" VALUE="" MAXLENGTH=15 SIZE=16><INPUT TYPE="hidden" NAME="LECB_month" VALUE="12"><INPUT TYPE="hidden" NAME="LECB_year" VALUE="2037"><INPUT TYPE="hidden" NAME="LECB_payname" VALUE="">!,
348 'BILL' => qq!Billing<BR>P.O. <INPUT TYPE="text" NAME="BILL_payinfo" VALUE=""><BR><INPUT TYPE="hidden" NAME="BILL_month" VALUE="12"><INPUT TYPE="hidden" NAME="BILL_year" VALUE="2037">Attention<BR><INPUT TYPE="text" NAME="BILL_payname" VALUE="">!,
349 'COMP' => qq!Complimentary<BR>${r}Approved by<INPUT TYPE="text" NAME="COMP_payinfo" VALUE=""><BR>${r}Exp !. expselect("COMP"),
352 if ( $cust_main->dbdef_table->column('paycvv') ) {
353 foreach my $payby ( grep { exists $payby{$_} } qw(CARD DCRD) ) { #1.4/1.5 bs
354 $payby{$payby} .= qq!<BR>CVV2 (<A HREF="javascript:myopen('../docs/cvv2.html','cvv2','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=yes,copyhistory=no,width=480,height=288')">help</A>) <INPUT TYPE="text" NAME=${payby}_paycvv VALUE="" SIZE=4 MAXLENGTH=4>!;
358 my( $account, $aba ) = split('@', $payinfo);
361 'CARD' => qq!Credit card (automatic)<BR>${r}<INPUT TYPE="text" NAME="CARD_payinfo" VALUE="$payinfo" MAXLENGTH=19><BR>${r}Exp !. expselect("CARD", $cust_main->paydate). qq!<BR>${r}Name on card<BR><INPUT TYPE="text" NAME="CARD_payname" VALUE="$payname">!,
362 'DCRD' => qq!Credit card (on-demand)<BR>${r}<INPUT TYPE="text" NAME="DCRD_payinfo" VALUE="$payinfo" MAXLENGTH=19><BR>${r}Exp !. expselect("DCRD", $cust_main->paydate). qq!<BR>${r}Name on card<BR><INPUT TYPE="text" NAME="DCRD_payname" VALUE="$payname">!,
363 'CHEK' => qq!Electronic check (automatic)<BR>${r}Account number <INPUT TYPE="text" NAME="CHEK_payinfo1" VALUE="$account"><BR>${r}ABA/Routing number <INPUT TYPE="text" NAME="CHEK_payinfo2" VALUE="$aba" SIZE=10 MAXLENGTH=9> (<A HREF="javascript:achopen('../docs/ach.html','ach','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=yes,copyhistory=no,width=384,height=256')">help</A>)<INPUT TYPE="hidden" NAME="CHEK_month" VALUE="12"><INPUT TYPE="hidden" NAME="CHEK_year" VALUE="2037"><BR>${r}Bank name <INPUT TYPE="text" NAME="CHEK_payname" VALUE="$payname">!,
364 'DCHK' => qq!Electronic check (on-demand)<BR>${r}Account number <INPUT TYPE="text" NAME="DCHK_payinfo1" VALUE="$account"><BR>${r}ABA/Routing number <INPUT TYPE="text" NAME="DCHK_payinfo2" VALUE="$aba" SIZE=10 MAXLENGTH=9> (<A HREF="javascript:achopen('../docs/ach.html','ach','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=yes,copyhistory=no,width=384,height=256')">help</A>)<INPUT TYPE="hidden" NAME="DCHK_month" VALUE="12"><INPUT TYPE="hidden" NAME="DCHK_year" VALUE="2037"><BR>${r}Bank name <INPUT TYPE="text" NAME="DCHK_payname" VALUE="$payname">!,
365 'LECB' => qq!Phone bill billing<BR>${r}Phone number <INPUT TYPE="text" BANE="LECB_payinfo" VALUE="$payinfo" MAXLENGTH=15 SIZE=16><INPUT TYPE="hidden" NAME="LECB_month" VALUE="12"><INPUT TYPE="hidden" NAME="LECB_year" VALUE="2037"><INPUT TYPE="hidden" NAME="LECB_payname" VALUE="">!,
366 'BILL' => qq!Billing<BR>P.O. <INPUT TYPE="text" NAME="BILL_payinfo" VALUE="$payinfo"><BR><INPUT TYPE="hidden" NAME="BILL_month" VALUE="12"><INPUT TYPE="hidden" NAME="BILL_year" VALUE="2037">Attention<BR><INPUT TYPE="text" NAME="BILL_payname" VALUE="$payname">!,
367 'COMP' => qq!Complimentary<BR>${r}Approved by<INPUT TYPE="text" NAME="COMP_payinfo" VALUE="$payinfo"><BR>${r}Exp !. expselect("COMP", $cust_main->paydate),
370 if ( $cust_main->dbdef_table->column('paycvv') ) {
371 my $paycvv = $cust_main->paycvv;
373 foreach my $payby ( grep { exists $payby{$_} } qw(CARD DCRD) ) { #1.4/1.5 bs
374 $paybychecked{$payby} .= qq!<BR>CVV2 (<A HREF="javascript:myopen('../docs/cvv2.html','cvv2','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=yes,copyhistory=no,width=480,height=288')">help</A>) <INPUT TYPE="text" NAME=${payby}_paycvv VALUE="$paycvv" SIZE=4 MAXLENGTH=4>!;
379 $cust_main->payby($payby_default) unless $cust_main->payby;
380 for (qw(CARD DCRD CHEK DCHK LECB BILL COMP)) {
381 print qq!<TD VALIGN=TOP><INPUT TYPE="radio" NAME="payby" VALUE="$_"!;
382 if ($cust_main->payby eq "$_") {
383 print qq! CHECKED> $paybychecked{$_}</TD>!;
385 print qq!> $payby{$_}</TD>!;
389 print "</TR></TABLE>$r required fields for each billing type";
393 if ( defined $cust_main->dbdef_table->column('comments') ) {
394 print "<BR><BR>Comments", &itable("#cccccc"),
395 qq!<TR><TD><TEXTAREA COLS=80 ROWS=5 WRAP="HARD" NAME="comments">!,
396 $cust_main->comments, "</TEXTAREA>",
397 "</TD></TR></TABLE>";
400 unless ( $custnum ) {
401 # pry the wrong place for this logic. also pretty expensive
404 #false laziness, copied from FS::cust_pkg::order
406 if ( scalar(@agents) == 1 ) {
407 # $pkgpart->{PKGPART} is true iff $custnum may purchase PKGPART
408 my($agent)=qsearchs('agent',{'agentnum'=> $agentnum });
409 $pkgpart = $agent->pkgpart_hashref;
411 #can't know (agent not chosen), so, allow all
413 foreach my $agent ( @agents ) {
414 next if $typenum{$agent->typenum}++;
415 #fixed in 5.004_05 #$pkgpart->{$_}++ foreach keys %{ $agent->pkgpart_hashref }
416 foreach ( keys %{ $agent->pkgpart_hashref } ) { $pkgpart->{$_}++; } #5.004_04 workaround
421 my @part_pkg = grep { $_->svcpart('svc_acct') && $pkgpart->{ $_->pkgpart } }
422 qsearch( 'part_pkg', { 'disabled' => '' } );
426 # print "<BR><BR>First package", &itable("#cccccc", "0 ALIGN=LEFT"),
427 #apiabuse & undesirable wrapping
428 print "<BR><BR>First package", &itable("#cccccc"),
429 qq!<TR><TD COLSPAN=2><SELECT NAME="pkgpart_svcpart">!;
431 print qq!<OPTION VALUE="">(none)!;
433 foreach my $part_pkg ( @part_pkg ) {
434 print qq!<OPTION VALUE="!,
435 # $part_pkg->pkgpart. "_". $pkgpart{ $part_pkg->pkgpart }, '"';
436 $part_pkg->pkgpart. "_". $part_pkg->svcpart('svc_acct'), '"';
437 print " SELECTED" if $saved_pkgpart && ( $part_pkg->pkgpart == $saved_pkgpart );
438 print ">", $part_pkg->pkg, " - ", $part_pkg->comment;
440 print "</SELECT></TD></TR>";
442 #false laziness: (mostly) copied from edit/svc_acct.cgi
443 #$ulen = $svc_acct->dbdef_table->column('username')->length;
444 my $ulen = dbdef->table('svc_acct')->column('username')->length;
446 my $passwordmax = $conf->config('passwordmax') || 8;
447 my $pmax2 = $passwordmax + 2;
449 <TR><TD ALIGN="right">Username</TD>
450 <TD><INPUT TYPE="text" NAME="username" VALUE="$username" SIZE=$ulen2 MAXLENGTH=$ulen></TD></TR>
451 <TR><TD ALIGN="right">Password</TD>
452 <TD><INPUT TYPE="text" NAME="_password" VALUE="$password" SIZE=$pmax2 MAXLENGTH=$passwordmax>
453 (blank to generate)</TD></TR>
456 print '<TR><TD ALIGN="right">Access number</TD><TD WIDTH="100%">'
458 &FS::svc_acct_pop::popselector($popnum).
464 my $otaker = $cust_main->otaker;
465 print qq!<INPUT TYPE="hidden" NAME="otaker" VALUE="$otaker">!,
466 qq!<BR><INPUT NAME="submit" TYPE="submit" VALUE="!,
467 $custnum ? "Apply Changes" : "Add Customer", qq!">!,
468 "</FORM></BODY></HTML>",