fix customer package search (fallout from customer classes) & add "not yet billed...
authorivan <ivan>
Wed, 4 Nov 2009 00:53:12 +0000 (00:53 +0000)
committerivan <ivan>
Wed, 4 Nov 2009 00:53:12 +0000 (00:53 +0000)
FS/FS/cust_pkg.pm
httemplate/browse/part_pkg.cgi

index e4846ec..e195ed8 100644 (file)
@@ -2221,6 +2221,7 @@ Returns an SQL expression identifying active packages.
 
 sub active_sql { "
   ". $_[0]->recurring_sql(). "
+  AND cust_pkg.setup IS NOT NULL AND cust_pkg.setup != 0
   AND ( cust_pkg.cancel IS NULL OR cust_pkg.cancel = 0 )
   AND ( cust_pkg.susp   IS NULL OR cust_pkg.susp   = 0 )
 "; }
@@ -2384,8 +2385,8 @@ sub search_sql {
 
     push @where, FS::cust_pkg->active_sql();
 
-  } elsif (    $params->{'magic'}  eq 'not yet billed'
-            || $params->{'status'} eq 'not yet billed' ) {
+  } elsif (    $params->{'magic'}  =~ /^not[ _]yet[ _]billed$/
+            || $params->{'status'} =~ /^not[ _]yet[ _]billed$/ ) {
 
     push @where, FS::cust_pkg->not_yet_billed_sql();
 
@@ -2419,7 +2420,7 @@ sub search_sql {
   {
     $classnum = $1;
     if ( $classnum ) { #a specific class
-      push @where, "classnum = $classnum";
+      push @where, "part_pkg.classnum = $classnum";
 
       #@pkg_class = ( qsearchs('pkg_class', { 'classnum' => $classnum } ) );
       #die "classnum $classnum not found!" unless $pkg_class[0];
@@ -2427,7 +2428,7 @@ sub search_sql {
 
     } elsif ( $classnum eq '' ) { #the empty class
 
-      push @where, "classnum IS NULL";
+      push @where, "part_pkg.classnum IS NULL";
       #$title .= 'Empty class ';
       #@pkg_class = ( '(empty class)' );
     } elsif ( $classnum eq '0' ) {
@@ -2591,9 +2592,9 @@ sub search_sql {
 
   my $extra_sql = scalar(@where) ? ' WHERE '. join(' AND ', @where) : '';
 
-  my $addl_from = 'LEFT JOIN cust_main USING ( custnum  ) '.
-                  'LEFT JOIN part_pkg  USING ( pkgpart  ) '.
-                  'LEFT JOIN pkg_class USING ( classnum ) ';
+  my $addl_from = 'LEFT JOIN part_pkg  USING ( pkgpart  ) '.
+                  'LEFT JOIN pkg_class USING ( classnum ) '.
+                  'LEFT JOIN cust_main USING ( custnum  ) ';
 
   my $count_query = "SELECT COUNT(*) FROM cust_pkg $addl_from $extra_sql";
 
index c6cbb81..d9b90cf 100755 (executable)
@@ -96,8 +96,15 @@ $select = "
   *,
 
   ( $count_cust_pkg
+      AND ( setup  IS NULL OR cancel = 0 )
       AND ( cancel IS NULL OR cancel = 0 )
-      AND ( susp IS NULL OR susp = 0 )
+      AND ( susp   IS NULL OR susp   = 0 )
+  ) AS num_not_yet_billed,
+
+  ( $count_cust_pkg
+      AND setup IS NOT NULL AND setup != 0
+      AND ( cancel IS NULL OR cancel = 0 )
+      AND ( susp   IS NULL OR susp   = 0 )
   ) AS num_active,
 
   ( $count_cust_pkg
@@ -283,6 +290,8 @@ if ( $acl_edit_global ) {
     'cancelled'       => 'FF0000',
     #'one-time charge' => '000000',
     'charge'          => '000000',
+    #'not yet billed'  => '000000',
+    'not&nbsp;yet&nbsp;billed'  => '000000',
   );
   my $cust_pkg_link = $p. 'search/cust_pkg.cgi?pkgpart=';
   push @fields, sub { my $part_pkg = shift;
@@ -294,6 +303,8 @@ if ( $acl_edit_global ) {
                                 $magic = 'inactive';
                                 #$label = 'one-time charge',
                                 $label = 'charge',
+                              } else {
+                                $label =~ s/_/&nbsp;/g;
                               }
                           
                               [
@@ -319,7 +330,7 @@ if ( $acl_edit_global ) {
                                             ),
                                 },
                               ],
-                            } (qw( active suspended cancelled ))
+                            } qw(not_yet_billed active suspended cancelled)
                       ]; };
   $align .= 'r';
 #}