[freeside-commits] branch master updated. 5a1e08844db8e4278105f0aad7aa3a48a433789c
Ivan
ivan at 420.am
Thu Apr 27 15:29:00 PDT 2017
The branch, master has been updated
via 5a1e08844db8e4278105f0aad7aa3a48a433789c (commit)
from a989f40712bcbef325a566802118432063315240 (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 5a1e08844db8e4278105f0aad7aa3a48a433789c
Author: Ivan Kohler <ivan at freeside.biz>
Date: Thu Apr 27 15:28:59 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