[freeside-commits] branch master updated. dfeca08f8d935d127d99de4690e2d5edf4f78b95

Ivan Kohler ivan at freeside.biz
Thu Sep 13 13:02:33 PDT 2018


The branch, master has been updated
       via  dfeca08f8d935d127d99de4690e2d5edf4f78b95 (commit)
       via  833cfe5c9938d33c3e6b97ed610c25a7afa6eb04 (commit)
      from  0682747829a56d487155e28675c133cb90f991de (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 dfeca08f8d935d127d99de4690e2d5edf4f78b95
Merge: 833cfe5c9 068274782
Author: Ivan Kohler <ivan at freeside.biz>
Date:   Thu Sep 13 13:02:28 2018 -0700

    Merge branch 'master' of git.freeside.biz:/home/git/freeside


commit 833cfe5c9938d33c3e6b97ed610c25a7afa6eb04
Author: Ivan Kohler <ivan at freeside.biz>
Date:   Thu Sep 13 13:02:25 2018 -0700

    Optimize "Customer has a referring customer" condition, RT#74452

diff --git a/FS/FS/part_event/Condition.pm b/FS/FS/part_event/Condition.pm
index d1d519683..9900acaa9 100644
--- a/FS/FS/part_event/Condition.pm
+++ b/FS/FS/part_event/Condition.pm
@@ -533,6 +533,22 @@ sub condition_sql_option_integer {
        " AS $integer )";
 }
 
+=item condition_sql_option_money OPTION
+
+As I<condition_sql_option>, but cast the option value to DECIMAL so that
+comparison to other monetary values is type-correct.
+
+=cut
+
+sub condition_sql_option_money {
+  my ($class, $option ) = @_;
+
+  'CAST(
+         COALESCE('. $class->condition_sql_option($option).
+                " ,'0') ".
+       " AS DECIMAL(10,2) )";
+}
+
 =head1 NEW CONDITION CLASSES
 
 A module should be added in FS/FS/part_event/Condition/ which implements the
diff --git a/FS/FS/part_event/Condition/has_referral_custnum.pm b/FS/FS/part_event/Condition/has_referral_custnum.pm
index 007ce4548..a56e3faec 100644
--- a/FS/FS/part_event/Condition/has_referral_custnum.pm
+++ b/FS/FS/part_event/Condition/has_referral_custnum.pm
@@ -60,19 +60,20 @@ sub condition {
 sub condition_sql {
   my( $class, $table, %opt ) = @_;
 
+  my $active_sql = FS::cust_main->active_sql;
+  $active_sql =~ s/cust_main.custnum/cust_main.referral_custnum/;
+
+  my $under = $class->condition_sql_option_money('balance');
+
   my $age = $class->condition_sql_option_age_from('age', $opt{'time'});
-  my $balance_sql      = FS::cust_main->balance_sql( $age );
-  my $balance_date_sql = FS::cust_main->balance_date_sql;
-  my $active_sql       = FS::cust_main->active_sql;
-  $balance_sql      =~ s/cust_main.custnum/cust_main.referral_custnum/;
+  my $balance_date_sql = FS::cust_main->balance_date_sql($age);
   $balance_date_sql =~ s/cust_main.custnum/cust_main.referral_custnum/;
-  $active_sql       =~ s/cust_main.custnum/cust_main.referral_custnum/;
-
-  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)";
+  my $bal_sql = "$balance_date_sql <= $under";
 
-  return $sql;
+  "cust_main.referral_custnum IS NOT NULL
+    AND (". $class->condition_sql_option('active').    " IS NULL OR $active_sql)
+    AND (". $class->condition_sql_option('check_bal'). " IS NULL OR $bal_sql   )
+  ";
 }
 
 1;

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

Summary of changes:
 FS/FS/part_event/Condition.pm                      | 16 ++++++++++++++++
 FS/FS/part_event/Condition/has_referral_custnum.pm | 21 +++++++++++----------
 2 files changed, 27 insertions(+), 10 deletions(-)




More information about the freeside-commits mailing list