[freeside-commits] branch FREESIDE_3_BRANCH updated. 2beb8b0c6b404765e1e061b77815dc9123114c94

Ivan ivan at 420.am
Thu Apr 27 15:29:05 PDT 2017


The branch, FREESIDE_3_BRANCH has been updated
       via  2beb8b0c6b404765e1e061b77815dc9123114c94 (commit)
      from  c6067e5ce005117ee3239eb00de0adc58efa4ee5 (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 2beb8b0c6b404765e1e061b77815dc9123114c94
Author: Ivan Kohler <ivan at freeside.biz>
Date:   Thu Apr 27 15:29:03 2017 -0700

    add condition on number of referred customers, RT#75356

diff --git a/FS/FS/part_event/Condition/referred_cust.pm b/FS/FS/part_event/Condition/referred_cust.pm
new file mode 100644
index 0000000..7555bde
--- /dev/null
+++ b/FS/FS/part_event/Condition/referred_cust.pm
@@ -0,0 +1,51 @@
+package FS::part_event::Condition::referred_cust;
+use base qw( FS::part_event::Condition );
+
+sub description { 'Customer referred customers'; }
+
+sub option_fields {
+  (
+    'number_referred' => { label => 'At least this many referred customers',
+                           type  => 'text',
+                           value => '1',
+                         },
+    'active'          => { label => 'Referred customers are active',
+                           type  => 'checkbox',
+                           value => 'Y',
+                         },
+    'if_pkg_class'    => { label    => 'Referred customers have an active package of class',
+                           type     => 'select-pkg_class',
+                           multiple => 1,
+                         },
+  );
+}
+
+sub condition {
+  my($self, $object, %opt) = @_;
+
+  my $cust_main = $self->cust_main($object);
+
+  my @referral_cust_main = $cust_main->referral_cust_main;
+
+  @referral_cust_main = grep $_->status eq 'active', @referral_cust_main
+    if $self->option('active');
+
+  my $if_pkg_class = $self->option('if_pkg_class') || {};
+  if ( keys %$if_pkg_class ) {
+    @referral_cust_main = grep {
+      my $cust = $_;
+      grep $if_pkg_class{$_->part_pkg->classnum}, $cust->active_pkgs;
+    } @referral_cust_main;
+  }
+
+  scalar(@referral_cust_main) >= $self->option('number_referred');
+
+}
+
+#sub condition_sql {
+#  my( $class, $table ) = @_;
+#
+#  #XXX TODO: this optimization
+#}
+
+1;

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

Summary of changes:
 FS/FS/part_event/Condition/referred_cust.pm |   51 +++++++++++++++++++++++++++
 1 file changed, 51 insertions(+)
 create mode 100644 FS/FS/part_event/Condition/referred_cust.pm




More information about the freeside-commits mailing list