[freeside-commits] branch master updated. faced8039212116eb258f6dc1319d6b4aea8463d
Ivan
ivan at 420.am
Sat Aug 26 14:00:51 PDT 2017
The branch, master has been updated
via faced8039212116eb258f6dc1319d6b4aea8463d (commit)
from 99106a6f323b554fb4d6abe5d80f69e48f75ab85 (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 faced8039212116eb258f6dc1319d6b4aea8463d
Author: Ivan Kohler <ivan at freeside.biz>
Date: Sat Aug 26 14:00:50 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