service and package disable!
[freeside.git] / httemplate / edit / cust_main.cgi
index 47e18d7..9588dcb 100755 (executable)
@@ -1,5 +1,5 @@
 <%
-#<!-- $Id: cust_main.cgi,v 1.4 2001-08-28 14:34:14 ivan Exp $ -->
+#<!-- $Id: cust_main.cgi,v 1.17 2001-12-27 09:26:14 ivan Exp $ -->
 
 use vars qw( $cgi $custnum $action $cust_main $p1 @agents $agentnum 
              $last $first $ss $company $address1 $address2 $city $zip 
@@ -22,7 +22,7 @@ use FS::cust_main_county;
   #for misplaced logic below
   use FS::part_pkg;
 
-  #for false laziness below
+  #for false laziness below (now more properly lazy)
   use FS::svc_acct_pop;
 
   #for (other) false laziness below
@@ -74,13 +74,13 @@ $action = $custnum ? 'Edit' : 'Add';
 # top
 
 $p1 = popurl(1);
-print $cgi->header( '-expires' => 'now' ), header("Customer $action", '');
+print header("Customer $action", '');
 print qq!<FONT SIZE="+1" COLOR="#ff0000">Error: !, $error, "</FONT>"
   if $error;
 
 print qq!<FORM ACTION="${p1}process/cust_main.cgi" METHOD=POST NAME="form1">!,
       qq!<INPUT TYPE="hidden" NAME="custnum" VALUE="$custnum">!,
-      qq!Customer # !, ( $custnum ? $custnum : " (NEW)" ),
+      qq!Customer # !, ( $custnum ? "<B>$custnum</B>" : " (NEW)" ),
       
 ;
 
@@ -133,19 +133,21 @@ if ( $custnum && ! $conf->exists('editreferrals') ) {
 
 #referring customer
 
-print qq!<BR><BR>Referring Customer: !;
+#print qq!<BR><BR>Referring Customer: !;
 if ( $cust_main->referral_custnum ) {
   my $referring_cust_main =
     qsearchs('cust_main', { custnum => $cust_main->referral_custnum } );
-  print '<A HREF="'. popurl(1). '/cust_main.cgi?'.
+  print '<BR><BR>Referring Customer: <A HREF="'. popurl(1). '/cust_main.cgi?'.
         $cust_main->referral_custnum. '">'.
         $cust_main->referral_custnum. ': '.
         ( $referring_cust_main->company
           || $referring_cust_main->last. ', '. $referring_cust_main->first ).
         '</A><INPUT TYPE="hidden" NAME="referral_custnum" VALUE="'.
         $cust_main->referral_custnum. '">';
+} elsif ( ! $conf->exists('disable_customer_referrals') ) {
+  print '<BR><BR>Referring customer number: <INPUT TYPE="text" NAME="referral_custnum" VALUE="">';
 } else {
-  print '(none)<INPUT TYPE="hidden" NAME="referral_custnum" VALUE="">';
+  print '<INPUT TYPE="hidden" NAME="referral_custnum" VALUE="">';
 }
 
 # contact info
@@ -178,11 +180,16 @@ print <<END;
 <TR><TH ALIGN="right">${r}City</TH><TD><INPUT TYPE="text" NAME="city" VALUE="$city"></TD><TH ALIGN="right">${r}State/Country</TH><TD><SELECT NAME="state" SIZE="1">
 END
 
-$cust_main->country( $conf->config('countrydefault') || 'US' )
-  unless $cust_main->country;
+my $countrydefault = $conf->config('countrydefault') || 'US';
+$cust_main->country( $countrydefault ) unless $cust_main->country;
 $cust_main->state( $conf->config('statedefault') || 'CA' )
   unless $cust_main->state || $cust_main->country ne 'US';
-foreach ( qsearch('cust_main_county',{}) ) {
+foreach ( sort {
+     ( $b->country eq $countrydefault ) <=> ( $a->country eq $countrydefault )
+  or $a->country                        cmp $b->country
+  or $a->state                          cmp $b->state
+  or $a->county                         cmp $b->county
+} qsearch('cust_main_county',{}) ) {
   print "<OPTION";
   print " SELECTED" if ( $cust_main->state eq $_->state
                          && $cust_main->county eq $_->county 
@@ -340,7 +347,8 @@ print qq!>Tax Exempt</TD></TR>!;
 print qq!<TR><TD><INPUT TYPE="checkbox" NAME="invoicing_list_POST" VALUE="POST"!;
 @invoicing_list = $cust_main->invoicing_list;
 print qq! CHECKED!
-  if ! @invoicing_list || grep { $_ eq 'POST' } @invoicing_list;
+  if ( ! @invoicing_list && ! $conf->exists('disablepostalinvoicedefault') )
+     || grep { $_ eq 'POST' } @invoicing_list;
 print qq!>Postal mail invoice</TD></TR>!;
 $invoicing_list = join(', ', grep { $_ ne 'POST' } @invoicing_list );
 print qq!<TR><TD>Email invoice <INPUT TYPE="text" NAME="invoicing_list" VALUE="$invoicing_list"></TD></TR>!;
@@ -404,10 +412,12 @@ unless ( $custnum ) {
   #eslaf
 
   my @part_pkg = grep { $_->svcpart('svc_acct') && $pkgpart->{ $_->pkgpart } }
-    qsearch( 'part_pkg', {} );
+    qsearch( 'part_pkg', { 'disabled' => '' } );
 
   if ( @part_pkg ) {
 
+#    print "<BR><BR>First package", &itable("#cccccc", "0 ALIGN=LEFT"),
+#apiabuse & undesirable wrapping
     print "<BR><BR>First package", &itable("#cccccc"),
           qq!<TR><TD COLSPAN=2><SELECT NAME="pkgpart_svcpart">!;
 
@@ -426,32 +436,27 @@ unless ( $custnum ) {
     #$ulen = $svc_acct->dbdef_table->column('username')->length;
     $ulen = dbdef->table('svc_acct')->column('username')->length;
     $ulen2 = $ulen+2;
+    my $passwordmax = $conf->config('passwordmax') || 8;
+    my $pmax2 = $passwordmax + 2;
     print <<END;
 <TR><TD ALIGN="right">Username</TD>
 <TD><INPUT TYPE="text" NAME="username" VALUE="$username" SIZE=$ulen2 MAXLENGTH=$ulen></TD></TR>
 <TR><TD ALIGN="right">Password</TD>
-<TD><INPUT TYPE="text" NAME="_password" VALUE="$password" SIZE=10 MAXLENGTH=8>
+<TD><INPUT TYPE="text" NAME="_password" VALUE="$password" SIZE=$pmax2 MAXLENGTH=$passwordmax>
 (blank to generate)</TD></TR>
 END
-    print qq!<TR><TD ALIGN="right">POP</TD><TD><SELECT NAME="popnum" SIZE=1><OPTION> !;
-    my($svc_acct_pop);
-    foreach $svc_acct_pop ( qsearch ('svc_acct_pop',{} ) ) {
-    print qq!<OPTION VALUE="!, $svc_acct_pop->popnum, '"',
-          ( $popnum && $svc_acct_pop->popnum == $popnum ) ? ' SELECTED' : '', ">", 
-          $svc_acct_pop->popnum, ": ", 
-          $svc_acct_pop->city, ", ",
-          $svc_acct_pop->state,
-          " (", $svc_acct_pop->ac, ")/",
-          $svc_acct_pop->exch, "\n"
-        ;
-    }
-    print "</SELECT></TD></TR></TABLE>";
+
+    print '<TR><TD ALIGN="right">Access number</TD><TD WIDTH="100%">'
+          .
+          &FS::svc_acct_pop::popselector($popnum).
+          '</TD></TR></TABLE>'
+          ;
   }
 }
 
 $otaker = $cust_main->otaker;
 print qq!<INPUT TYPE="hidden" NAME="otaker" VALUE="$otaker">!,
-      qq!<BR><BR><INPUT TYPE="submit" VALUE="!,
+      qq!<BR><INPUT TYPE="submit" VALUE="!,
       $custnum ?  "Apply Changes" : "Add Customer", qq!">!,
       "</FORM></BODY></HTML>",
 ;