svc_domain needs to import dbh sub from Record
[freeside.git] / htdocs / view / cust_main.cgi
index 2119b3e..ff169fd 100755 (executable)
@@ -1,12 +1,10 @@
 #!/usr/bin/perl -Tw
 #
-# $Id: cust_main.cgi,v 1.11 1999-01-25 12:26:04 ivan Exp $
+# $Id: cust_main.cgi,v 1.19 2001-04-22 01:38:39 ivan Exp $
 #
 # Usage: cust_main.cgi custnum
 #        http://server.name/path/cust_main.cgi?custnum
 #
-# Note: Should be run setuid freeside as user nobody.
-#
 # the payment history section could use some work, see below
 # 
 # ivan@voicenet.com 96-nov-29 -> 96-dec-11
 # lose background, FS::CGI ivan@sisd.com 98-sep-2
 #
 # $Log: cust_main.cgi,v $
-# Revision 1.11  1999-01-25 12:26:04  ivan
+# Revision 1.19  2001-04-22 01:38:39  ivan
+# svc_domain needs to import dbh sub from Record
+# view/cust_main.cgi needs to use ->owed method, not check (depriciated) owed field
+# search/cust_bill.cgi redirect error when there's only one invoice
+#
+# Revision 1.18  1999/08/12 04:16:01  ivan
+# hidecancelledpackages config option
+#
+# Revision 1.17  1999/04/15 16:44:36  ivan
+# delete customers
+#
+# Revision 1.16  1999/04/09 04:22:34  ivan
+# also table()
+#
+# Revision 1.15  1999/04/09 03:52:55  ivan
+# explicit & for table/itable/ntable
+#
+# Revision 1.14  1999/04/08 04:04:37  ivan
+# eliminate double // in links
+#
+# Revision 1.13  1999/02/28 00:04:00  ivan
+# removed misleading comments
+#
+# Revision 1.12  1999/02/07 09:59:40  ivan
+# more mod_perl fixes, and bugfixes Peter Wemm sent via email
+#
+# Revision 1.11  1999/01/25 12:26:04  ivan
 # yet more mod_perl stuff
 #
 # Revision 1.10  1999/01/19 05:14:19  ivan
@@ -69,7 +93,7 @@
 use strict;
 use vars qw ( $cgi $query $custnum $cust_main $hashref $agent $referral 
               @packages $package @history @bills $bill @credits $credit
-              $balance $item @agents @referrals @invoicing_list $n1 ); 
+              $balance $item @agents @referrals @invoicing_list $n1 $conf ); 
 use CGI;
 use CGI::Carp qw(fatalsToBrowser);
 use Date::Format;
@@ -89,6 +113,8 @@ use FS::cust_refund;
 $cgi = new CGI;
 &cgisuidsetup($cgi);
 
+$conf = new FS::Conf;
+
 print $cgi->header( '-expires' => 'now' ), header("Customer View", menubar(
   'Main Menu' => popurl(2)
 ));
@@ -101,11 +127,14 @@ $cust_main = qsearchs('cust_main',{'custnum'=>$custnum});
 die "Customer not found!" unless $cust_main;
 $hashref = $cust_main->hashref;
 
-print itable(), '<TR><TD><A NAME="cust_main"></A>';
+print &itable(), '<TR><TD><A NAME="cust_main"></A>';
 
 print qq!<A HREF="!, popurl(2), 
-      qq!edit/cust_main.cgi?$custnum">Edit this customer</A>!,
-      ntable("#c0c0c0"), "<TR><TD>", ntable("#c0c0c0",2),
+      qq!edit/cust_main.cgi?$custnum">Edit this customer</A>!;
+print qq! | <A HREF="!, popurl(2), 
+      qq!misc/delete-customer.cgi?$custnum"> Delete this customer</A>!
+  if $conf->exists('deletecustomers');
+print &ntable("#c0c0c0"), "<TR><TD>", &ntable("#c0c0c0",2),
       '<TR><TD ALIGN="right">Customer number</TD><TD BGCOLOR="#ffffff">',
       $custnum, '</TD></TR>',
 ;
@@ -133,8 +162,8 @@ print '</TABLE></TD></TR></TABLE>';
 
 print '</TD><TD ROWSPAN=2>';
 
-print "Contact information", ntable("#c0c0c0"), "<TR><TD>",
-      ntable("#c0c0c0",2),
+print "Contact information", &ntable("#c0c0c0"), "<TR><TD>",
+      &ntable("#c0c0c0",2),
   '<TR><TD ALIGN="right">Contact name<BR>(last, first)</TD>',
     '<TD COLSPAN=3 BGCOLOR="#ffffff">',
     $cust_main->last, ', ', $cust_main->first,
@@ -174,7 +203,7 @@ print '</TD></TR><TR><TD>';
 @invoicing_list = $cust_main->invoicing_list;
 print "Billing information (",
       qq!<A HREF="!, popurl(2), qq!/misc/bill.cgi?$custnum">!, "Bill now</A>)",
-      ntable("#c0c0c0"), "<TR><TD>", ntable("#c0c0c0",2),
+      &ntable("#c0c0c0"), "<TR><TD>", &ntable("#c0c0c0",2),
       '<TR><TD ALIGN="right">Tax exempt</TD><TD BGCOLOR="#ffffff">',
       $cust_main->tax ? 'yes' : 'no',
       '</TD></TR>',
@@ -182,7 +211,7 @@ print "Billing information (",
       ( grep { $_ eq 'POST' } @invoicing_list ) ? 'yes' : 'no',
       '</TD></TR>',
       '<TR><TD ALIGN="right">Email invoices</TD><TD BGCOLOR="#ffffff">',
-      join(', ', grep { $_ ne 'POST' } @invoicing_list ),
+      join(', ', grep { $_ ne 'POST' } @invoicing_list ) || 'no',
       '</TD></TR>',
       '<TR><TD ALIGN="right">Billing type</TD><TD BGCOLOR="#ffffff">',
 ;
@@ -219,13 +248,13 @@ print "</TABLE></TD></TR></TABLE></TD></TR></TABLE>";
 
 print qq!<BR><BR><A NAME="cust_pkg">Packages</A> !,
 #      qq!<BR>Click on package number to view/edit package.!,
-      qq!( <A HREF="!, popurl(2), qq!/edit/cust_pkg.cgi?$custnum">Order and cancel packages</A> )!,
+      qq!( <A HREF="!, popurl(2), qq!edit/cust_pkg.cgi?$custnum">Order and cancel packages</A> )!,
 ;
 
 #display packages
 
 #formatting
-print qq!!, table, "\n",
+print qq!!, &table(), "\n",
       qq!<TR><TH COLSPAN=2 ROWSPAN=2>Package</TH><TH COLSPAN=5>!,
       qq!Dates</TH><TH COLSPAN=2 ROWSPAN=2>Services</TH></TR>\n!,
       qq!<TR><TH><FONT SIZE=-1>Setup</FONT></TH><TH>!,
@@ -236,10 +265,13 @@ print qq!!, table, "\n",
       qq!</TR>\n!;
 
 #get package info
-@packages = $cust_main->all_pkgs;
-#@packages = $cust_main->ncancelled_pkgs;
+if ( $conf->exists('hidecancelledpackages') ) {
+  @packages = $cust_main->ncancelled_pkgs;
+} else {
+  @packages = $cust_main->all_pkgs;
+}
 
-$n1 = '';
+$n1 = '<TR>';
 foreach $package (@packages) {
   my $pkgnum = $package->pkgnum;
   my $pkg = $package->part_pkg->pkg;
@@ -258,7 +290,7 @@ foreach $package (@packages) {
         qq!<TD ROWSPAN=$rowspan><FONT SIZE=-1>!,
         #qq!<A HREF="$pkgview">$pkg - $comment</A>!,
         qq!$pkg - $comment!,
-        qq! ( <A HREF="$pkgview">Edit</A> | <A HREF="$button_url">Customize pricing</A>)</FONT></TD>!,
+        qq! ( <A HREF="$pkgview">Edit</A> | <A HREF="$button_url">Customize pricing</A> )</FONT></TD>!,
   ;
   for ( qw( setup bill susp expire cancel ) ) {
     print "<TD ROWSPAN=$rowspan><FONT SIZE=-1>", ( $package->getfield($_)
@@ -272,7 +304,7 @@ foreach $package (@packages) {
   foreach my $cust_svc ( @cust_svc ) {
      my($label, $value, $svcdb) = $cust_svc->label;
      my($svcnum) = $cust_svc->svcnum;
-     my($sview) = popurl(2). "/view";
+     my($sview) = popurl(2). "view";
      print $n2,qq!<TD><A HREF="$sview/$svcdb.cgi?$svcnum"><FONT SIZE=-1>$label</FONT></A></TD>!,
            qq!<TD><A HREF="$sview/$svcdb.cgi?$svcnum"><FONT SIZE=-1>$value</FONT></A></TD>!;
      $n2="</TR><TR>";
@@ -304,7 +336,7 @@ foreach $bill (@bills) {
   push @history,
     $bref->{_date} . qq!\t<A HREF="!. popurl(2). qq!view/cust_bill.cgi?! .
     $bref->{invnum} . qq!">Invoice #! . $bref->{invnum} .
-    qq! (Balance \$! . $bref->{owed} . qq!)</A>\t! .
+    qq! (Balance \$! . $bill->owed . qq!)</A>\t! .
     $bref->{charged} . qq!\t\t\t!;
 
   my(@payments)=qsearch('cust_pay',{'invnum'=> $bref->{invnum} } );
@@ -342,7 +374,7 @@ foreach $credit (@credits) {
 }
 
         #formatting
-        print table(), <<END;
+        print &table(), <<END;
 <TR>
   <TH>Date</TH>
   <TH>Description</TH>