option to count subpackages outside packages in sales report #5588
authorjeff <jeff>
Wed, 19 Aug 2009 06:15:14 +0000 (06:15 +0000)
committerjeff <jeff>
Wed, 19 Aug 2009 06:15:14 +0000 (06:15 +0000)
FS/FS/Report/Table/Monthly.pm
httemplate/graph/cust_bill_pkg.cgi
httemplate/graph/report_cust_bill_pkg.html
httemplate/search/cust_bill_pkg.cgi

index d75f0be..d015f91 100644 (file)
@@ -311,11 +311,21 @@ sub cust_bill_pkg {
   my( $self, $speriod, $eperiod, $agentnum, %opt ) = @_;
 
   my $where = '';
+  my $comparison = '';
   if ( $opt{'classnum'} =~ /^(\d+)$/ ) {
     if ( $1 == 0 ) {
-      $where = "classnum IS NULL";
+      $comparison = "IS NULL";
     } else {
-      $where = "classnum = $1";
+      $comparison = "= $1";
+    }
+
+    if ( $opt{'use_override'} ) {
+      $where = "(
+        part_pkg.classnum $comparison AND pkgpart_override IS NULL OR
+        override.classnum $comparison AND pkgpart_override IS NOT NULL
+      )";
+    } else {
+      $where = "part_pkg.classnum $comparison";
     }
   }
 
@@ -328,6 +338,7 @@ sub cust_bill_pkg {
         LEFT JOIN cust_main USING ( custnum )
         LEFT JOIN cust_pkg USING ( pkgnum )
         LEFT JOIN part_pkg USING ( pkgpart )
+        LEFT JOIN part_pkg AS override ON pkgpart_override = override.pkgpart
       WHERE pkgnum != 0
         AND $where
         AND ". $self->in_time_period_and_agent($speriod, $eperiod, $agentnum)
index b655f1f..021189a 100644 (file)
@@ -68,6 +68,9 @@ if ( $cgi->param('classnum') =~ /^(\d*)$/ ) {
 }
 #eslaf
 
+my $use_override = 0;
+$use_override = 1 if ( $cgi->param('use_override') );
+
 my $hue = 0;
 #my $hue_increment = 170;
 #my $hue_increment = 145;
@@ -104,11 +107,13 @@ foreach my $agent ( $sel_agent || qsearch('agent', { 'disabled' => '' } ) ) {
 
     my $row_classnum = ref($pkg_class) ? $pkg_class->classnum : 0;
     my $row_agentnum = $agent->agentnum;
-    push @params, [ 'classnum' => $row_classnum,
-                    'agentnum' => $row_agentnum,
+    push @params, [ 'classnum'     => $row_classnum,
+                    'agentnum'     => $row_agentnum,
+                    'use_override' => $use_override,
                   ];
 
-    push @links, "$link;agentnum=$row_agentnum;classnum=$row_classnum;";
+    push @links, "$link;agentnum=$row_agentnum;classnum=$row_classnum;".
+                 "use_override=$use_override;";
 
     @recur_colors = ($col_scheme->colors)[0,4,8,1,5,9]
       unless @recur_colors;
index 5193bf4..073f867 100644 (file)
 </TR>
 -->
 
+<TR>
+  <TD ALIGN="right"><INPUT TYPE="checkbox" NAME="use_override" VALUE="1"></TD>
+  <TD>Separate sub-packages from parents</TD>
+</TR>
+
 </TABLE>
 
 <BR><INPUT TYPE="submit" VALUE="Display">
index 4a31611..8654585 100644 (file)
@@ -16,8 +16,8 @@
                  'fields'      => [
                    'billpkgnum',
                    sub { $_[0]->pkgnum > 0
-                           ? $_[0]->get('pkg')
-                           : $_[0]->get('itemdesc')
+                           ? $_[0]->get('pkg')      # possibly use override.pkg
+                           : $_[0]->get('itemdesc') # but i think this correct
                        },
                    #strikethrough or "N/A ($amount)" or something these when
                    # they're not applicable to pkg_tax search
@@ -87,11 +87,22 @@ if ( $cgi->param('agentnum') =~ /^(\d+)$/ ) {
 # not specified: all classes
 # 0: empty class
 # N: classnum
+my $use_override = $cgi->param('use_override');
 if ( $cgi->param('classnum') =~ /^(\d+)$/ ) {
+  my $comparison = '';
   if ( $1 == 0 ) {
-    push @where, "classnum IS NULL";
+    $comparison = "IS NULL";
   } else {
-    push @where, "classnum = $1";
+    $comparison = "= $1";
+  }
+
+  if ( $use_override ) {
+    push @where, "(
+      part_pkg.classnum $comparison AND pkgpart_override IS NULL OR
+      override.classnum $comparison AND pkgpart_override IS NOT NULL
+    )";
+  } else {
+    push @where, "part_pkg.classnum $comparison";
   }
 }
 
@@ -372,7 +383,9 @@ my $join_pkg;
 if ( $cgi->param('nottax') ) {
 
   $join_pkg =  ' LEFT JOIN cust_pkg USING ( pkgnum )
-                 LEFT JOIN part_pkg USING ( pkgpart ) ';
+                 LEFT JOIN part_pkg USING ( pkgpart )
+                 LEFT JOIN part_pkg AS override
+                   ON pkgpart_override = override.pkgpart ';
   $join_pkg .= ' LEFT JOIN cust_location USING ( locationnum ) '
     if $conf->exists('tax-pkg_address');