[freeside-commits] branch master updated. 5b7aba597d277efa440c27cdc264bf116e5a477a

Nick Logan nick at 420.am
Wed Nov 1 09:04:20 PDT 2017


The branch, master has been updated
       via  5b7aba597d277efa440c27cdc264bf116e5a477a (commit)
      from  221ec4469fe66fe3f2a91122d887525b0a49fbe6 (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 5b7aba597d277efa440c27cdc264bf116e5a477a
Author: Nick Logan <nick at freeside.biz>
Date:   Wed Nov 1 15:56:29 2017 +0000

    RT# 74452 Optimize referral billing event condition

diff --git a/FS/FS/part_event/Condition/has_referral_custnum.pm b/FS/FS/part_event/Condition/has_referral_custnum.pm
index f8a2b82..564c652 100644
--- a/FS/FS/part_event/Condition/has_referral_custnum.pm
+++ b/FS/FS/part_event/Condition/has_referral_custnum.pm
@@ -1,5 +1,6 @@
 package FS::part_event::Condition::has_referral_custnum;
 
+use v5.14;
 use strict;
 use FS::cust_main;
 
@@ -57,16 +58,17 @@ sub condition {
 
 }
 
-#this is incomplete wrt checking referring customer balances, but that's okay.
-# false positives are acceptable here, its just an optimizaiton
 sub condition_sql {
-  my( $class, $table ) = @_;
+  my( $class, $table, %opt ) = @_;
 
-  my $sql = FS::cust_main->active_sql;
-  $sql =~ s/cust_main.custnum/cust_main.referral_custnum/;
-  $sql = 'cust_main.referral_custnum IS NOT NULL AND ('.
-          $class->condition_sql_option('active') . ' IS NULL OR '.$sql.')';
-  return $sql;
+  my $age              = $class->condition_sql_option_age_from('age', $opt{'time'});
+  my $balance_sql      = FS::cust_main->balance_sql( $age ) =~ s/cust_main.custnum/cust_main.referral_custnum/r;
+  my $balance_date_sql = FS::cust_main->balance_date_sql    =~ s/cust_main.custnum/cust_main.referral_custnum/r;
+  my $active_sql       = FS::cust_main->active_sql          =~ s/cust_main.custnum/cust_main.referral_custnum/r;
+
+  my $sql = "cust_main.referral_custnum IS NOT NULL".
+    " AND ( ". $class->condition_sql_option('active') . " IS NULL OR $active_sql )".
+    " AND ( $balance_date_sql <= $balance_sql )";
 }
 
 1;

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

Summary of changes:
 FS/FS/part_event/Condition/has_referral_custnum.pm |   18 ++++++++++--------
 1 file changed, 10 insertions(+), 8 deletions(-)




More information about the freeside-commits mailing list