From fa80d5673f5ae567506da8177d163c770647b0d4 Mon Sep 17 00:00:00 2001 From: ivan Date: Fri, 18 Sep 2009 22:41:25 +0000 Subject: [PATCH] add active option to has_referral_custnum condition, RT#6150 --- FS/FS/cust_main.pm | 23 +++++++++++++++++++ FS/FS/part_event/Condition/has_referral_custnum.pm | 26 +++++++++++++++++++++- 2 files changed, 48 insertions(+), 1 deletion(-) diff --git a/FS/FS/cust_main.pm b/FS/FS/cust_main.pm index cdfe93848..bf95fa9c9 100644 --- a/FS/FS/cust_main.pm +++ b/FS/FS/cust_main.pm @@ -6951,6 +6951,24 @@ sub invoicing_list_emailonly_scalar { join(', ', $self->invoicing_list_emailonly); } +=item referral_custnum_cust_main + +Returns the customer who referred this customer (or the empty string, if +this customer was not referred). + +Note the difference with referral_cust_main method: This method, +referral_custnum_cust_main returns the single customer (if any) who referred +this customer, while referral_cust_main returns an array of customers referred +BY this customer. + +=cut + +sub referral_custnum_cust_main { + my $self = shift; + return '' unless $self->referral_custnum; + qsearchs('cust_main', { 'custnum' => $self->referral_custnum } ); +} + =item referral_cust_main [ DEPTH [ EXCLUDE_HASHREF ] ] Returns an array of customers referred by this customer (referral_custnum set @@ -6958,6 +6976,11 @@ to this custnum). If DEPTH is given, recurses up to the given depth, returning customers referred by customers referred by this customer and so on, inclusive. The default behavior is DEPTH 1 (no recursion). +Note the difference with referral_custnum_cust_main method: This method, +referral_cust_main, returns an array of customers referred BY this customer, +while referral_custnum_cust_main returns the single customer (if any) who +referred this customer. + =cut sub referral_cust_main { diff --git a/FS/FS/part_event/Condition/has_referral_custnum.pm b/FS/FS/part_event/Condition/has_referral_custnum.pm index d43d6c0c7..61a815579 100644 --- a/FS/FS/part_event/Condition/has_referral_custnum.pm +++ b/FS/FS/part_event/Condition/has_referral_custnum.pm @@ -7,18 +7,42 @@ use base qw( FS::part_event::Condition ); sub description { 'Customer has a referring customer'; } +sub option_fields { + ( + 'active' => { 'label' => 'Referring customer is active', + 'type' => 'checkbox', + 'value' => 'Y', + }, + ); +} + sub condition { my($self, $object) = @_; my $cust_main = $self->cust_main($object); - $cust_main->referral_custnum; + if ( $self->option('active') ) { + + return 0 unless $cust_main->referral_custnum; + + #check for no cust_main for referral_custnum? (deleted?) + + $cust_main->referral_custnum_cust_main->status eq 'active'; + + } else { + + $cust_main->referral_custnum; # ? 1 : 0; + + } + } sub condition_sql { #my( $class, $table ) = @_; "cust_main.referral_custnum IS NOT NULL"; + + #XXX a bit harder to check active status here } 1; -- 2.11.0