[freeside-commits] branch FREESIDE_4_BRANCH updated. dc4563f6529ffbc7eab505e430cff956d13c5602
Ivan
ivan at 420.am
Sat Aug 26 14:00:53 PDT 2017
The branch, FREESIDE_4_BRANCH has been updated
via dc4563f6529ffbc7eab505e430cff956d13c5602 (commit)
from 5a8140c9027c5c035ac0ed42e053f27231edd0ba (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 dc4563f6529ffbc7eab505e430cff956d13c5602
Author: Ivan Kohler <ivan at freeside.biz>
Date: Sat Aug 26 14:00:52 2017 -0700
condition to consider referred customers base recurring, RT#75356
diff --git a/FS/FS/part_event/Condition/referred_cust_base_recur.pm b/FS/FS/part_event/Condition/referred_cust_base_recur.pm
new file mode 100644
index 0000000..4ad4da7
--- /dev/null
+++ b/FS/FS/part_event/Condition/referred_cust_base_recur.pm
@@ -0,0 +1,51 @@
+package FS::part_event::Condition::referred_cust_base_recur;
+use base qw( FS::part_event::Condition );
+
+use List::Util qw( sum );
+
+sub description { 'Referred customers recurring per month'; }
+
+sub option_fields {
+ (
+ 'recur_times' => { label => 'Base recurring per month of referred customers is at least this many times base recurring per month of referring customer',
+ type => 'text',
+ value => '1',
+ },
+ 'if_pkg_class' => { label => 'Only considering package of class',
+ type => 'select-pkg_class',
+ multiple => 1,
+ },
+ );
+}
+
+sub condition {
+ my($self, $object, %opt) = @_;
+
+ my $cust_main = $self->cust_main($object);
+ my @cust_pkg = $cust_main->billing_pkgs;
+
+ my @referral_cust_main = $cust_main->referral_cust_main;
+ my @referral_cust_pkg = map $_->billing_pkgs, @referral_cust_main;
+
+ my $if_pkg_class = $self->option('if_pkg_class') || {};
+ if ( keys %$if_pkg_class ) {
+ @cust_pkg = grep $_->part_pkg->classnum, @cust_pkg;
+ @referral_cust_pkg = grep $_->part_pkg->classnum, @referral_cust_pkg;
+ }
+
+ return 0 unless @cust_pkg && @referral_cust_pkg;
+
+ my $recur = sum map $_->part_pkg->base_recur_permonth, @cust_pkg;
+ my $ref_recur = sum map $_->part_pkg->base_recur_permonth, @referral_cust_pkg;
+
+ $ref_recur >= $self->option('recur_times') * $recur;
+}
+
+#sub condition_sql {
+# my( $class, $table ) = @_;
+#
+# #XXX TODO: this optimization
+#}
+
+1;
+
-----------------------------------------------------------------------
Summary of changes:
.../Condition/referred_cust_base_recur.pm | 51 ++++++++++++++++++++
1 file changed, 51 insertions(+)
create mode 100644 FS/FS/part_event/Condition/referred_cust_base_recur.pm
More information about the freeside-commits
mailing list