[freeside-commits] freeside/FS/FS/Report/Table Monthly.pm, 1.16, 1.17

Jeff Finucane,420,, jeff at wavetail.420.am
Sun Aug 23 22:09:28 PDT 2009


Update of /home/cvs/cvsroot/freeside/FS/FS/Report/Table
In directory wavetail.420.am:/tmp/cvs-serv32112/FS/FS/Report/Table

Modified Files:
	Monthly.pm 
Log Message:
add rated call sales report and option to sales report to count usage separately from recurring #5588

Index: Monthly.pm
===================================================================
RCS file: /home/cvs/cvsroot/freeside/FS/FS/Report/Table/Monthly.pm,v
retrieving revision 1.16
retrieving revision 1.17
diff -u -d -r1.16 -r1.17
--- Monthly.pm	19 Aug 2009 06:15:14 -0000	1.16
+++ Monthly.pm	24 Aug 2009 05:09:26 -0000	1.17
@@ -331,7 +331,9 @@
 
   $agentnum ||= $opt{'agentnum'};
 
-  $self->scalar_sql("
+  my $usage = cust_bill_pkg_detail(@_);
+
+  my $total = $self->scalar_sql("
     SELECT SUM(cust_bill_pkg.setup + cust_bill_pkg.recur)
       FROM cust_bill_pkg
         LEFT JOIN cust_bill USING ( invnum )
@@ -344,6 +346,64 @@
         AND ". $self->in_time_period_and_agent($speriod, $eperiod, $agentnum)
   );
   
+  if ($opt{use_usage} && $opt{use_usage} eq 'recurring') {
+    return $total-$usage;
+  } elsif ($opt{use_usage} && $opt{use_usage} eq 'usage') {
+    return $usage;
+  } else {
+    return $total;
+  }
+}
+
+sub cust_bill_pkg_detail {
+  my( $self, $speriod, $eperiod, $agentnum, %opt ) = @_;
+
+  my @where = ( "cust_bill_pkg.pkgnum != 0" );
+  my $comparison = '';
+  if ( $opt{'classnum'} =~ /^(\d+)$/ ) {
+    if ( $1 == 0 ) {
+      $comparison = "IS NULL";
+    } else {
+      $comparison = "= $1";
+    }
+
+    if ( $opt{'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";
+    }
+  }
+
+  if ( $opt{'usageclass'} =~ /^(\d+)$/ ) {
+    if ( $1 == 0 ) {
+      $comparison = "IS NULL";
+    } else {
+      $comparison = "= $1";
+    }
+
+    push @where, "cust_bill_pkg_detail.classnum $comparison";
+  }
+
+  $agentnum ||= $opt{'agentnum'};
+
+  my $where = join( ' AND ', @where );
+
+  $self->scalar_sql("
+    SELECT SUM(amount)
+      FROM cust_bill_pkg_detail
+        LEFT JOIN cust_bill_pkg USING ( billpkgnum )
+        LEFT JOIN cust_bill ON cust_bill_pkg.invnum = cust_bill.invnum
+        LEFT JOIN cust_main USING ( custnum )
+        LEFT JOIN cust_pkg ON cust_bill_pkg.pkgnum = cust_pkg.pkgnum
+        LEFT JOIN part_pkg USING ( pkgpart )
+        LEFT JOIN part_pkg AS override ON pkgpart_override = override.pkgpart
+      WHERE $where
+        AND ". $self->in_time_period_and_agent($speriod, $eperiod, $agentnum)
+  );
+  
 }
 
 sub setup_pkg  { shift->pkg_field( @_, 'setup' ); }



More information about the freeside-commits mailing list