X-Git-Url: http://git.freeside.biz/gitweb/?p=freeside.git;a=blobdiff_plain;f=FS%2FFS%2Fcust_main%2FSearch.pm;h=0eb00202b00a41d906cb778d461d444f796d6a00;hp=4473aeda2866376b8c919962dd74d0074015de4a;hb=a989f40712bcbef325a566802118432063315240;hpb=1d94d421c28cb157e6cb2f8ff30d1ac85b399b57 diff --git a/FS/FS/cust_main/Search.pm b/FS/FS/cust_main/Search.pm index 4473aeda2..0eb00202b 100644 --- a/FS/FS/cust_main/Search.pm +++ b/FS/FS/cust_main/Search.pm @@ -866,6 +866,15 @@ sub search { if $params->{'no_tax'}; ## + # with referrals + ## + if ( $params->{'with_referrals'} ) { + push @where, + ' EXISTS ( SELECT 1 FROM cust_main AS referred_cust_main + WHERE cust_main.custnum = referred_cust_main.referral_custnum )'; + } + + ## # dates ## @@ -1101,6 +1110,20 @@ sub search { } + if ( $params->{'with_referrals'} ) { + + #XXX next: num for each customer status + + push @select, + '( SELECT COUNT(*) FROM cust_main AS referred_cust_main + WHERE cust_main.custnum = referred_cust_main.referral_custnum + ) AS num_referrals'; + + unshift @extra_headers, 'Referrals'; + unshift @extra_fields, 'num_referrals'; + + } + my $select = join(', ', @select); my $sql_query = {