diff options
author | Ivan Kohler <ivan@freeside.biz> | 2017-08-26 15:01:21 -0700 |
---|---|---|
committer | Ivan Kohler <ivan@freeside.biz> | 2017-08-26 15:01:21 -0700 |
commit | c742a74ec444c4606006a14e814d06e0b1795ea4 (patch) | |
tree | d1d7427586aa45c74b7e56b3b93d6b881491d683 /FS | |
parent | 6145063b291a18aa9699295d373ccefad627f12e (diff) |
referral status search, RT#75757
Diffstat (limited to 'FS')
-rw-r--r-- | FS/FS/cust_main/Search.pm | 20 |
1 files changed, 17 insertions, 3 deletions
diff --git a/FS/FS/cust_main/Search.pm b/FS/FS/cust_main/Search.pm index 6d7a9b218..7d0e43d64 100644 --- a/FS/FS/cust_main/Search.pm +++ b/FS/FS/cust_main/Search.pm @@ -884,10 +884,24 @@ sub search { ## # with referrals ## - if ( $params->{'with_referrals'} =~ /^\s*(\d+)\s*$/ ) { + if ( $params->{with_referrals} =~ /^\s*(\d+)\s*$/ ) { + + my $n = $1; + + # referral status + my $and_status = ''; + if ( grep { $params->{referral_status} eq $_ } FS::cust_main->statuses() ) { + my $method = $params->{referral_status}. '_sql'; + $and_status = ' AND '. FS::cust_main->$method(); + $and_status =~ s/ cust_main\./ referred_cust_main./g; + } + push @where, - " $1 <= ( SELECT COUNT(*) FROM cust_main AS referred_cust_main - WHERE cust_main.custnum = referred_cust_main.referral_custnum )"; + " $n <= ( SELECT COUNT(*) FROM cust_main AS referred_cust_main + WHERE cust_main.custnum = referred_cust_main.referral_custnum + $and_status + )"; + } ## |