[freeside-commits] branch FREESIDE_4_BRANCH updated. bcec9544f1786221b1c87c3f7df21ba87b1d9ab2

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


The branch, FREESIDE_4_BRANCH has been updated
       via  bcec9544f1786221b1c87c3f7df21ba87b1d9ab2 (commit)
      from  d3ccf0b542d3b23f5bd851cdf1edbbc0de81f0b6 (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 bcec9544f1786221b1c87c3f7df21ba87b1d9ab2
Author: Ivan Kohler <ivan at freeside.biz>
Date:   Thu Apr 27 15:29:00 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