X-Git-Url: http://git.freeside.biz/gitweb/?p=freeside.git;a=blobdiff_plain;f=FS%2FFS%2Fcust_main%2FSearch.pm;h=4eab474e19a3cb4c18b41c9a655c313af520cd7e;hp=09558b84be044ef472de92faffabdea080cf38cd;hb=ce7d68e984aab0075f87cf3fa5a55ee4083fadd2;hpb=13bcd704deec03008853c18a0258e031b62e2ec6 diff --git a/FS/FS/cust_main/Search.pm b/FS/FS/cust_main/Search.pm index 09558b84b..4eab474e1 100644 --- a/FS/FS/cust_main/Search.pm +++ b/FS/FS/cust_main/Search.pm @@ -872,10 +872,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 + )"; + } ##