[freeside-commits] branch master updated. 900d4d72315d52f8838f397522e0cae238f38811

Ivan ivan at 420.am
Fri Mar 4 15:50:25 PST 2016


The branch, master has been updated
       via  900d4d72315d52f8838f397522e0cae238f38811 (commit)
      from  d256989a19dd100823d35a11929edb1ae07d9883 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit 900d4d72315d52f8838f397522e0cae238f38811
Author: Ivan Kohler <ivan at freeside.biz>
Date:   Fri Mar 4 15:50:24 2016 -0800

    optimize order package (cust_main->next_bill_date), RT#39822

diff --git a/FS/FS/cust_main/Packages.pm b/FS/FS/cust_main/Packages.pm
index 6a69517..5a14e2e 100644
--- a/FS/FS/cust_main/Packages.pm
+++ b/FS/FS/cust_main/Packages.pm
@@ -618,7 +618,36 @@ undef if no billing package has a next bill date.
 
 sub next_bill_date {
   my $self = shift;
-  min( map $_->get('bill'), grep $_->get('bill'), $self->billing_pkgs );
+
+#  super inefficient with lots of packages
+#  min( map $_->get('bill'), grep $_->get('bill'), $self->billing_pkgs );
+
+  my $custnum = $self->custnum;
+
+  $self->scalar_sql("
+    SELECT MIN(bill) FROM cust_pkg
+      LEFT JOIN cust_pkg_option AS cust_suspend_bill_option
+        ON (     cust_pkg.pkgnum = cust_suspend_bill_option.pkgnum
+             AND cust_suspend_bill_option.optionname = 'suspend_bill' )
+      LEFT JOIN cust_pkg_option AS cust_no_suspend_bill_option
+        ON (     cust_pkg.pkgnum = cust_no_suspend_bill_option.pkgnum
+             AND cust_no_suspend_bill_option.optionname = 'no_suspend_bill' )
+      LEFT JOIN part_pkg USING (pkgpart)
+        LEFT JOIN part_pkg_option AS part_suspend_bill_option
+          ON (     part_pkg.pkgpart = part_suspend_bill_option.pkgpart
+               AND part_suspend_bill_option.optionname = 'suspend_bill' )
+    WHERE custnum = $custnum
+      AND bill IS NOT NULL AND bill != 0
+      AND ( cancel IS NULL OR cancel = 0 )
+      AND part_pkg.freq != '' AND part_pkg.freq != '0'
+      AND (    ( susp IS NULL OR susp = 0 )
+            OR COALESCE(cust_suspend_bill_option.optionvalue,'0') = '1'
+            OR (     COALESCE(part_suspend_bill_option.optionvalue,'0') = '1'
+                 AND COALESCE(cust_no_suspend_bill_option.optionvalue,'0') = '0'
+               )
+          )
+  ");
+
 }
 
 =item num_cancelled_pkgs

-----------------------------------------------------------------------

Summary of changes:
 FS/FS/cust_main/Packages.pm |   31 ++++++++++++++++++++++++++++++-
 1 file changed, 30 insertions(+), 1 deletion(-)




More information about the freeside-commits mailing list