[freeside-commits] branch master updated. 8d159e2eda65f2e7b327872580502f37d006c7f8

Ivan ivan at 420.am
Mon May 14 13:14:07 PDT 2012


The branch, master has been updated
       via  8d159e2eda65f2e7b327872580502f37d006c7f8 (commit)
      from  d96c4cc7147cee862e14afee53a3ed69969f5419 (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 8d159e2eda65f2e7b327872580502f37d006c7f8
Author: Ivan Kohler <ivan at freeside.biz>
Date:   Mon May 14 13:14:06 2012 -0700

    add balance_age_under condition and similar referring customer functionality to has_referral_custnum condition, RT#17640

diff --git a/FS/FS/part_event/Condition/balance_age_under.pm b/FS/FS/part_event/Condition/balance_age_under.pm
new file mode 100644
index 0000000..ac6d786
--- /dev/null
+++ b/FS/FS/part_event/Condition/balance_age_under.pm
@@ -0,0 +1,52 @@
+package FS::part_event::Condition::balance_age_under;
+
+use strict;
+use base qw( FS::part_event::Condition );
+
+sub description { 'Customer balance age (under)'; }
+
+sub option_fields {
+  (
+    'balance' => { 'label'      => 'Balance under (or equal to)',
+                   'type'       => 'money',
+                   'value'      => '0.00', #default
+                 },
+    'age'     => { 'label'      => 'Age',
+                   'type'       => 'freq',
+                 },
+  );
+}
+
+sub condition {
+  my($self, $object, %opt) = @_;
+
+  my $cust_main = $self->cust_main($object);
+
+  my $under = $self->option('balance');
+  $under = 0 unless length($under);
+
+  my $age = $self->option_age_from('age', $opt{'time'} );
+
+  $cust_main->balance_date($age) <= $under;
+}
+
+sub condition_sql {
+  my( $class, $table, %opt ) = @_;
+
+  my $under   = $class->condition_sql_option('balance');
+  my $age     = $class->condition_sql_option_age_from('age', $opt{'time'});
+
+  my $balance_sql = FS::cust_main->balance_date_sql( $age );
+
+  "$balance_sql <= CAST( $under AS DECIMAL(10,2) )";
+}
+
+sub order_sql {
+  shift->condition_sql_option_age('age');
+}
+
+sub order_sql_weight {
+  10;
+}
+
+1;
diff --git a/FS/FS/part_event/Condition/has_referral_custnum.pm b/FS/FS/part_event/Condition/has_referral_custnum.pm
index 70c9c7f..dee240f 100644
--- a/FS/FS/part_event/Condition/has_referral_custnum.pm
+++ b/FS/FS/part_event/Condition/has_referral_custnum.pm
@@ -13,30 +13,49 @@ sub option_fields {
                   'type'  => 'checkbox',
                   'value' => 'Y',
                 },
+    'check_bal' => { 'label' => 'Check referring custoemr balance',
+                     'type'  => 'checkbox',
+                     'value' => 'Y',
+                   },
+    'balance' => { 'label'      => 'Referring customer balance under (or equal to)',
+                   'type'       => 'money',
+                   'value'      => '0.00', #default
+                 },
+    'age'     => { 'label'      => 'Referring customer balance age',
+                   'type'       => 'freq',
+                 },
   );
 }
 
 sub condition {
-  my($self, $object) = @_;
+  my($self, $object, %opt) = @_;
 
   my $cust_main = $self->cust_main($object);
 
   if ( $self->option('active') ) {
-
     return 0 unless $cust_main->referral_custnum;
-
     #check for no cust_main for referral_custnum? (deleted?)
+    return 0 unless $cust_main->referral_custnum_cust_main->status eq 'active';
+  } else {
+    return 0 unless $cust_main->referral_custnum; # ? 1 : 0;
+  }
 
-    $cust_main->referral_custnum_cust_main->status eq 'active';
+  return 1 unless $self->option('check_bal');
 
-  } else {
+  my $referring_cust_main = $cust_main->referral_custnum_cust_main;
 
-    $cust_main->referral_custnum; # ? 1 : 0;
+  #false laziness w/ balance_age_under
+  my $under = $self->option('balance');
+  $under = 0 unless length($under);
 
-  }
+  my $age = $self->option_age_from('age', $opt{'time'} );
+
+  $referring_cust_main->balance_date($age) <= $under;
 
 }
 
+#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 ) = @_;
 

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

Summary of changes:
 .../{balance_age.pm => balance_age_under.pm}       |   16 +++++-----
 FS/FS/part_event/Condition/has_referral_custnum.pm |   33 +++++++++++++++----
 2 files changed, 34 insertions(+), 15 deletions(-)
 copy FS/FS/part_event/Condition/{balance_age.pm => balance_age_under.pm} (65%)




More information about the freeside-commits mailing list