on-demand vs. automatic cards & checks: added DCRD and DCHK payment types
[freeside.git] / httemplate / edit / cust_main.cgi
1 <!-- mason kludge -->
2 <%
3
4   #for misplaced logic below
5   #use FS::part_pkg;
6
7   #for false laziness below (now more properly lazy)
8   #use FS::svc_acct_pop;
9
10   #for (other) false laziness below
11   #use FS::agent;
12   #use FS::type_pkgs;
13
14 my $conf = new FS::Conf;
15
16 #get record
17
18 my $error = '';
19 my($custnum, $username, $password, $popnum, $cust_main, $saved_pkgpart);
20 my(@invoicing_list);
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')
25   } );
26   $custnum = $cust_main->custnum;
27   $saved_pkgpart = $cgi->param('pkgpart_svcpart') || '';
28   if ( $saved_pkgpart =~ /^(\d+)_/ ) {
29     $saved_pkgpart = $1;
30   } else {
31     $saved_pkgpart = '';
32   }
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;
39   $query =~ /^(\d+)$/;
40   $custnum=$1;
41   $cust_main = qsearchs('cust_main', { 'custnum' => $custnum } );
42   $saved_pkgpart = 0;
43   $username = '';
44   $password = '';
45   $popnum = 0;
46   @invoicing_list = $cust_main->invoicing_list;
47 } else {
48   $custnum='';
49   $cust_main = new FS::cust_main ( {} );
50   $cust_main->otaker( &getotaker );
51   $cust_main->referral_custnum( $cgi->param('referral_custnum') );
52   $saved_pkgpart = 0;
53   $username = '';
54   $password = '';
55   $popnum = 0;
56   @invoicing_list = ();
57 }
58 $cgi->delete_all();
59 my $action = $custnum ? 'Edit' : 'Add';
60
61 # top
62
63 my $p1 = popurl(1);
64 print header("Customer $action", '');
65 print qq!<FONT SIZE="+1" COLOR="#ff0000">Error: !, $error, "</FONT>"
66   if $error;
67
68 print qq!<FORM ACTION="${p1}process/cust_main.cgi" METHOD=POST NAME="form1">!,
69       qq!<INPUT TYPE="hidden" NAME="custnum" VALUE="$custnum">!,
70       qq!Customer # !, ( $custnum ? "<B>$custnum</B>" : " (NEW)" ),
71       
72 ;
73
74 # agent
75
76 my $r = qq!<font color="#ff0000">*</font>&nbsp;!;
77
78 my @agents = qsearch( 'agent', {} );
79 #die "No agents created!" unless @agents;
80 eidiot "You have not created any agents.  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;
81 my $agentnum = $cust_main->agentnum || $agents[0]->agentnum; #default to first
82 if ( scalar(@agents) == 1 ) {
83   print qq!<INPUT TYPE="hidden" NAME="agentnum" VALUE="$agentnum">!;
84 } else {
85   print qq!<BR><BR>${r}Agent <SELECT NAME="agentnum" SIZE="1">!;
86   my $agent;
87   foreach $agent (sort {
88     $a->agent cmp $b->agent;
89   } @agents) {
90       print '<OPTION VALUE="', $agent->agentnum, '"',
91       " SELECTED"x($agent->agentnum==$agentnum),
92       ">". $agent->agent;
93       #">", $agent->agentnum,": ", $agent->agent;
94   }
95   print "</SELECT>";
96 }
97
98 #referral
99
100 my $refnum = $cust_main->refnum || $conf->config('referraldefault') || 0;
101 if ( $custnum && ! $conf->exists('editreferrals') ) {
102   print qq!<INPUT TYPE="hidden" NAME="refnum" VALUE="$refnum">!;
103 } else {
104   my(@referrals) = qsearch('part_referral',{});
105   if ( scalar(@referrals) == 0 ) {
106     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.";
107   } elsif ( scalar(@referrals) == 1 ) {
108     $refnum ||= $referrals[0]->refnum;
109     print qq!<INPUT TYPE="hidden" NAME="refnum" VALUE="$refnum">!;
110   } else {
111     print qq!<BR><BR>${r}Advertising source <SELECT NAME="refnum" SIZE="1">!;
112     print "<OPTION> " unless $refnum;
113     my($referral);
114     foreach $referral (sort {
115       $a->refnum <=> $b->refnum;
116     } @referrals) {
117       print "<OPTION" . " SELECTED"x($referral->refnum==$refnum),
118       ">", $referral->refnum, ": ", $referral->referral;
119     }
120     print "</SELECT>";
121   }
122 }
123
124 #referring customer
125
126 #print qq!<BR><BR>Referring Customer: !;
127 if ( $cust_main->referral_custnum ) {
128   my $referring_cust_main =
129     qsearchs('cust_main', { custnum => $cust_main->referral_custnum } );
130   print '<BR><BR>Referring Customer: <A HREF="'. popurl(1). '/cust_main.cgi?'.
131         $cust_main->referral_custnum. '">'.
132         $cust_main->referral_custnum. ': '.
133         ( $referring_cust_main->company
134           || $referring_cust_main->last. ', '. $referring_cust_main->first ).
135         '</A><INPUT TYPE="hidden" NAME="referral_custnum" VALUE="'.
136         $cust_main->referral_custnum. '">';
137 } elsif ( ! $conf->exists('disable_customer_referrals') ) {
138   print '<BR><BR>Referring customer number: <INPUT TYPE="text" NAME="referral_custnum" VALUE="">';
139 } else {
140   print '<INPUT TYPE="hidden" NAME="referral_custnum" VALUE="">';
141 }
142
143 # contact info
144
145 my($last,$first,$ss,$company,$address1,$address2,$city,$zip)=(
146   $cust_main->last,
147   $cust_main->first,
148   $cust_main->ss,
149   $cust_main->company,
150   $cust_main->address1,
151   $cust_main->address2,
152   $cust_main->city,
153   $cust_main->zip,
154 );
155
156 print "<BR><BR>Billing address", &itable("#cccccc"), <<END;
157 <TR><TH ALIGN="right">${r}Contact&nbsp;name<BR>(last,&nbsp;first)</TH><TD COLSPAN=3>
158 END
159
160 print <<END;
161 <INPUT TYPE="text" NAME="last" VALUE="$last"> , 
162 <INPUT TYPE="text" NAME="first" VALUE="$first">
163 </TD>
164 END
165
166 if ( $conf->exists('show_ss') ) {
167   print qq!<TD ALIGN="right">SS#</TD><TD><INPUT TYPE="text" NAME="ss" VALUE="$ss" SIZE=11></TD>!;
168 } else {
169   print qq!<TD><INPUT TYPE="hidden" NAME="ss" VALUE="$ss"></TD>!;
170 }
171
172 print <<END;
173 </TR>
174 <TR><TD ALIGN="right">Company</TD><TD COLSPAN=5><INPUT TYPE="text" NAME="company" VALUE="$company" SIZE=70></TD></TR>
175 <TR><TH ALIGN="right">${r}Address</TH><TD COLSPAN=5><INPUT TYPE="text" NAME="address1" VALUE="$address1" SIZE=70></TD></TR>
176 <TR><TD ALIGN="right">&nbsp;</TD><TD COLSPAN=5><INPUT TYPE="text" NAME="address2" VALUE="$address2" SIZE=70></TD></TR>
177 <TR><TH ALIGN="right">${r}City</TH><TD><INPUT TYPE="text" NAME="city" VALUE="$city"></TD><TH ALIGN="right">${r}State</TH><TD>
178 END
179
180 #false laziness with ship state
181 my $countrydefault = $conf->config('countrydefault') || 'US';
182 $cust_main->country( $countrydefault ) unless $cust_main->country;
183
184 $cust_main->state( $conf->config('statedefault') || 'CA' )
185   unless $cust_main->state || $cust_main->country ne 'US';
186
187 my($county_html, $state_html, $country_html) =
188   FS::cust_main_county::regionselector( $cust_main->county,
189                                         $cust_main->state,
190                                         $cust_main->country );
191
192 print "$county_html $state_html";
193
194 print qq!</TD><TH>${r}Zip</TH><TD><INPUT TYPE="text" NAME="zip" VALUE="$zip" SIZE=10></TD></TR>!;
195
196 my($daytime,$night,$fax)=(
197   $cust_main->daytime,
198   $cust_main->night,
199   $cust_main->fax,
200 );
201
202 my $daytime_label = FS::Msgcat::_gettext('daytime') || 'Day Phone';
203 my $night_label = FS::Msgcat::_gettext('night') || 'Night Phone';
204
205 print <<END;
206 <TR><TH ALIGN="right">${r}Country</TH><TD>$country_html</TD></TR>
207 <TR><TD ALIGN="right">$daytime_label</TD><TD COLSPAN=5><INPUT TYPE="text" NAME="daytime" VALUE="$daytime" SIZE=18></TD></TR>
208 <TR><TD ALIGN="right">$night_label</TD><TD COLSPAN=5><INPUT TYPE="text" NAME="night" VALUE="$night" SIZE=18></TD></TR>
209 <TR><TD ALIGN="right">Fax</TD><TD COLSPAN=5><INPUT TYPE="text" NAME="fax" VALUE="$fax" SIZE=12></TD></TR>
210 END
211
212 print "</TABLE>${r}required fields<BR>";
213
214 # service address
215
216 if ( defined $cust_main->dbdef_table->column('ship_last') ) {
217
218   print "\n", <<END;
219   <SCRIPT>
220   function changed(what) {
221     what.form.same.checked = false;
222   }
223   function samechanged(what) {
224     if ( what.checked ) {
225 END
226 print "      what.form.ship_$_.value = what.form.$_.value;\n"
227   for (qw( last first company address1 address2 city zip daytime night fax ));
228 print <<END;
229       what.form.ship_country.selectedIndex = what.form.country.selectedIndex;
230       ship_country_changed(what.form.ship_country);
231       what.form.ship_state.selectedIndex = what.form.state.selectedIndex;
232       ship_state_changed(what.form.ship_state);
233       what.form.ship_county.selectedIndex = what.form.county.selectedIndex;
234     }
235   }
236   </SCRIPT>
237 END
238
239   print '<BR>Service address ',
240         '(<INPUT TYPE="checkbox" NAME="same" VALUE="Y" onClick="samechanged(this)"';
241   unless ( $cust_main->ship_last && $cgi->param('same') ne 'Y' ) {
242     print ' CHECKED';
243     foreach (
244       qw( last first company address1 address2 city county state zip country
245           daytime night fax )
246     ) {
247       $cust_main->set("ship_$_", $cust_main->get($_) );
248     }
249   }
250   print '>same as billing address)<BR>';
251
252   my($ship_last,$ship_first,$ship_company,$ship_address1,$ship_address2,$ship_city,$ship_zip)=(
253     $cust_main->ship_last,
254     $cust_main->ship_first,
255     $cust_main->ship_company,
256     $cust_main->ship_address1,
257     $cust_main->ship_address2,
258     $cust_main->ship_city,
259     $cust_main->ship_zip,
260   );
261
262   print &itable("#cccccc"), <<END;
263   <TR><TH ALIGN="right">${r}Contact&nbsp;name<BR>(last,&nbsp;first)</TH><TD COLSPAN=5>
264 END
265
266   print <<END;
267   <INPUT TYPE="text" NAME="ship_last" VALUE="$ship_last" onChange="changed(this)"> , 
268   <INPUT TYPE="text" NAME="ship_first" VALUE="$ship_first" onChange="changed(this)">
269 END
270
271   print <<END;
272   </TD></TR>
273   <TR><TD ALIGN="right">Company</TD><TD COLSPAN=5><INPUT TYPE="text" NAME="ship_company" VALUE="$ship_company" SIZE=70 onChange="changed(this)"></TD></TR>
274   <TR><TH ALIGN="right">${r}Address</TH><TD COLSPAN=5><INPUT TYPE="text" NAME="ship_address1" VALUE="$ship_address1" SIZE=70 onChange="changed(this)"></TD></TR>
275   <TR><TD ALIGN="right">&nbsp;</TD><TD COLSPAN=5><INPUT TYPE="text" NAME="ship_address2" VALUE="$ship_address2" SIZE=70 onChange="changed(this)"></TD></TR>
276   <TR><TH ALIGN="right">${r}City</TH><TD><INPUT TYPE="text" NAME="ship_city" VALUE="$ship_city" onChange="changed(this)"></TD><TH ALIGN="right">${r}State</TH><TD>
277 END
278
279   #false laziness with regular state
280   $cust_main->ship_country( $countrydefault ) unless $cust_main->ship_country;
281
282   $cust_main->ship_state( $conf->config('statedefault') || 'CA' )
283     unless $cust_main->ship_state || $cust_main->ship_country ne 'US';
284
285   my($ship_county_html, $ship_state_html, $ship_country_html) =
286     FS::cust_main_county::regionselector( $cust_main->ship_county,
287                                           $cust_main->ship_state,
288                                           $cust_main->ship_country,
289                                           'ship_',
290                                           'changed(this)', );
291
292   print "$ship_county_html $ship_state_html";
293
294   print qq!</TD><TH>${r}Zip</TH><TD><INPUT TYPE="text" NAME="ship_zip" VALUE="$ship_zip" SIZE=10 onChange="changed(this)"></TD></TR>!;
295
296   my($ship_daytime,$ship_night,$ship_fax)=(
297     $cust_main->ship_daytime,
298     $cust_main->ship_night,
299     $cust_main->ship_fax,
300   );
301
302   print <<END;
303   <TR><TH ALIGN="right">${r}Country</TH><TD>$ship_country_html</TD></TR>
304   <TR><TD ALIGN="right">$daytime_label</TD><TD COLSPAN=5><INPUT TYPE="text" NAME="ship_daytime" VALUE="$ship_daytime" SIZE=18 onChange="changed(this)"></TD></TR>
305   <TR><TD ALIGN="right">$night_label</TD><TD COLSPAN=5><INPUT TYPE="text" NAME="ship_night" VALUE="$ship_night" SIZE=18 onChange="changed(this)"></TD></TR>
306   <TR><TD ALIGN="right">Fax</TD><TD COLSPAN=5><INPUT TYPE="text" NAME="ship_fax" VALUE="$ship_fax" SIZE=12 onChange="changed(this)"></TD></TR>
307 END
308
309   print "</TABLE>${r}required fields<BR>";
310
311 }
312
313 # billing info
314
315 sub expselect {
316   my $prefix = shift;
317   my( $m, $y ) = (0, 0);
318   if ( scalar(@_) ) {
319     my $date = shift || '01-2000';
320     if ( $date  =~ /^(\d{4})-(\d{1,2})-\d{1,2}$/ ) { #PostgreSQL date format
321       ( $m, $y ) = ( $2, $1 );
322     } elsif ( $date =~ /^(\d{1,2})-(\d{1,2}-)?(\d{4}$)/ ) {
323       ( $m, $y ) = ( $1, $3 );
324     } else {
325       die "unrecognized expiration date format: $date";
326     }
327   }
328
329   my $return = qq!<SELECT NAME="$prefix!. qq!_month" SIZE="1">!;
330   for ( 1 .. 12 ) {
331     $return .= "<OPTION";
332     $return .= " SELECTED" if $_ == $m;
333     $return .= ">$_";
334   }
335   $return .= qq!</SELECT>/<SELECT NAME="$prefix!. qq!_year" SIZE="1">!;
336   for ( 2001 .. 2037 ) {
337     $return .= "<OPTION";
338     $return .= " SELECTED" if $_ == $y;
339     $return .= ">$_";
340   }
341   $return .= "</SELECT>";
342
343   $return;
344 }
345
346 my $payby_default = $conf->config('payby-default');
347
348 if ( $payby_default eq 'HIDE' ) {
349
350   $cust_main->payby('BILL') unless $cust_main->payby;
351
352   foreach my $field (qw( tax payby )) {
353     print qq!<INPUT TYPE="hidden" NAME="$field" VALUE="!.
354           $cust_main->getfield($field). '">';
355   }
356
357   print qq!<INPUT TYPE="hidden" NAME="invoicing_list" VALUE="!.
358         join(', ', $cust_main->invoicing_list). '">';
359
360   foreach my $payby (qw( CARD DCRD CHEK DCHK LECB BILL COMP )) {
361     foreach my $field (qw( payinfo payname )) {
362       print qq!<INPUT TYPE="hidden" NAME="${payby}_$field" VALUE="!.
363             $cust_main->getfield($field). '">';
364     }
365
366     #false laziness w/expselect
367     my( $m, $y );
368     my $date = $cust_main->paydate || '12-2037';
369     if ( $date  =~ /^(\d{4})-(\d{1,2})-\d{1,2}$/ ) { #PostgreSQL date format
370       ( $m, $y ) = ( $2, $1 );
371     } elsif ( $date =~ /^(\d{1,2})-(\d{1,2}-)?(\d{4}$)/ ) {
372       ( $m, $y ) = ( $1, $3 );
373     } else {
374       die "unrecognized expiration date format: $date";
375     }
376
377     print qq!<INPUT TYPE="hidden" NAME="${payby}_month" VALUE="$m">!.
378           qq!<INPUT TYPE="hidden" NAME="${payby}_year"  VALUE="$y">!;
379
380   }
381
382 } else {
383
384   print "<BR>Billing information", &itable("#cccccc"),
385         qq!<TR><TD><INPUT TYPE="checkbox" NAME="tax" VALUE="Y"!;
386   print qq! CHECKED! if $cust_main->tax eq "Y";
387   print qq!>Tax Exempt</TD></TR><TR><TD>!.
388         qq!<INPUT TYPE="checkbox" NAME="invoicing_list_POST" VALUE="POST"!;
389
390   #my @invoicing_list = $cust_main->invoicing_list;
391   print qq! CHECKED!
392     if ( ! @invoicing_list && ! $conf->exists('disablepostalinvoicedefault') )
393        || grep { $_ eq 'POST' } @invoicing_list;
394   print qq!>Postal mail invoice</TD></TR>!;
395   my $invoicing_list = join(', ', grep { $_ ne 'POST' } @invoicing_list );
396   print qq!<TR><TD>Email invoice <INPUT TYPE="text" NAME="invoicing_list" VALUE="$invoicing_list"></TD></TR>!;
397
398   print "<TR><TD>Billing type</TD></TR>",
399         "</TABLE>",
400         &table("#cccccc"), "<TR>";
401
402   my($payinfo, $payname)=(
403     $cust_main->payinfo,
404     $cust_main->payname,
405   );
406
407   my %payby = (
408     '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="">!,
409     '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="">!,
410     'CHEK' => qq!Electronic check (automatic)<BR>${r}Account number <INPUT TYPE="text" NAME="CHEK_payinfo1" VALUE=""><BR>${r}ABA/Routing code <INPUT TYPE="text" NAME="CHEK_payinfo2" VALUE="" SIZE=10 MAXLENGTH=9><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="">!,
411     'DCHK' => qq!Electronic check (on-demand)<BR>${r}Account number <INPUT TYPE="text" NAME="DCHK_payinfo1" VALUE=""><BR>${r}ABA/Routing code <INPUT TYPE="text" NAME="DCHK_payinfo2" VALUE="" SIZE=10 MAXLENGTH=9><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="">!,
412     '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="">!,
413     '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="">!,
414     'COMP' => qq!Complimentary<BR>${r}Approved by<INPUT TYPE="text" NAME="COMP_payinfo" VALUE=""><BR>${r}Exp !. expselect("COMP"),
415 );
416
417   my( $account, $aba ) = split('@', $payinfo);
418
419   my %paybychecked = (
420     '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">!,
421     '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">!,
422     'CHEK' => qq!Electronic check (automatic)<BR>${r}Account number <INPUT TYPE="text" NAME="CHEK_payinfo1" VALUE="$account"><BR>${r}ABA/Routing code <INPUT TYPE="text" NAME="CHEK_payinfo2" VALUE="$aba" SIZE=10 MAXLENGTH=9><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">!,
423     'DCHK' => qq!Electronic check (on-demand)<BR>${r}Account number <INPUT TYPE="text" NAME="DCHK_payinfo1" VALUE="$account"><BR>${r}ABA/Routing code <INPUT TYPE="text" NAME="DCHK_payinfo2" VALUE="$aba" SIZE=10 MAXLENGTH=9><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">!,
424     '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="">!,
425     '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">!,
426     'COMP' => qq!Complimentary<BR>${r}Approved by<INPUT TYPE="text" NAME="COMP_payinfo" VALUE="$payinfo"><BR>${r}Exp !. expselect("COMP", $cust_main->paydate),
427 );
428
429   $cust_main->payby($payby_default) unless $cust_main->payby;
430   for (qw(CARD DCRD CHEK DCHK LECB BILL COMP)) {
431     print qq!<TD VALIGN=TOP><INPUT TYPE="radio" NAME="payby" VALUE="$_"!;
432     if ($cust_main->payby eq "$_") {
433       print qq! CHECKED> $paybychecked{$_}</TD>!;
434     } else {
435       print qq!> $payby{$_}</TD>!;
436     }
437   }
438
439   print "</TR></TABLE>$r required fields for each billing type";
440
441 }
442
443 if ( defined $cust_main->dbdef_table->column('comments') ) {
444     print "<BR><BR>Comments", &itable("#cccccc"),
445           qq!<TR><TD><TEXTAREA COLS=80 ROWS=5 WRAP="HARD" NAME="comments">!,
446           $cust_main->comments, "</TEXTAREA>",
447           "</TD></TR></TABLE>";
448 }
449
450 unless ( $custnum ) {
451   # pry the wrong place for this logic.  also pretty expensive
452   #use FS::part_pkg;
453
454   #false laziness, copied from FS::cust_pkg::order
455   my $pkgpart;
456   if ( scalar(@agents) == 1 ) {
457     # $pkgpart->{PKGPART} is true iff $custnum may purchase PKGPART
458     my($agent)=qsearchs('agent',{'agentnum'=> $agentnum });
459     $pkgpart = $agent->pkgpart_hashref;
460   } else {
461     #can't know (agent not chosen), so, allow all
462     my %typenum;
463     foreach my $agent ( @agents ) {
464       next if $typenum{$agent->typenum}++;
465       #fixed in 5.004_05 #$pkgpart->{$_}++ foreach keys %{ $agent->pkgpart_hashref }
466       foreach ( keys %{ $agent->pkgpart_hashref } ) { $pkgpart->{$_}++; } #5.004_04 workaround
467     }
468   }
469   #eslaf
470
471   my @part_pkg = grep { $_->svcpart('svc_acct') && $pkgpart->{ $_->pkgpart } }
472     qsearch( 'part_pkg', { 'disabled' => '' } );
473
474   if ( @part_pkg ) {
475
476 #    print "<BR><BR>First package", &itable("#cccccc", "0 ALIGN=LEFT"),
477 #apiabuse & undesirable wrapping
478     print "<BR><BR>First package", &itable("#cccccc"),
479           qq!<TR><TD COLSPAN=2><SELECT NAME="pkgpart_svcpart">!;
480
481     print qq!<OPTION VALUE="">(none)!;
482
483     foreach my $part_pkg ( @part_pkg ) {
484       print qq!<OPTION VALUE="!,
485 #              $part_pkg->pkgpart. "_". $pkgpart{ $part_pkg->pkgpart }, '"';
486               $part_pkg->pkgpart. "_". $part_pkg->svcpart, '"';
487       print " SELECTED" if $saved_pkgpart && ( $part_pkg->pkgpart == $saved_pkgpart );
488       print ">", $part_pkg->pkg, " - ", $part_pkg->comment;
489     }
490     print "</SELECT></TD></TR>";
491
492     #false laziness: (mostly) copied from edit/svc_acct.cgi
493     #$ulen = $svc_acct->dbdef_table->column('username')->length;
494     my $ulen = dbdef->table('svc_acct')->column('username')->length;
495     my $ulen2 = $ulen+2;
496     my $passwordmax = $conf->config('passwordmax') || 8;
497     my $pmax2 = $passwordmax + 2;
498     print <<END;
499 <TR><TD ALIGN="right">Username</TD>
500 <TD><INPUT TYPE="text" NAME="username" VALUE="$username" SIZE=$ulen2 MAXLENGTH=$ulen></TD></TR>
501 <TR><TD ALIGN="right">Password</TD>
502 <TD><INPUT TYPE="text" NAME="_password" VALUE="$password" SIZE=$pmax2 MAXLENGTH=$passwordmax>
503 (blank to generate)</TD></TR>
504 END
505
506     print '<TR><TD ALIGN="right">Access number</TD><TD WIDTH="100%">'
507           .
508           &FS::svc_acct_pop::popselector($popnum).
509           '</TD></TR></TABLE>'
510           ;
511   }
512 }
513
514 my $otaker = $cust_main->otaker;
515 print qq!<INPUT TYPE="hidden" NAME="otaker" VALUE="$otaker">!,
516       qq!<BR><INPUT TYPE="submit" VALUE="!,
517       $custnum ?  "Apply Changes" : "Add Customer", qq!">!,
518       "</FORM></BODY></HTML>",
519 ;
520
521 %>