summaryrefslogtreecommitdiff
path: root/FS
diff options
context:
space:
mode:
Diffstat (limited to 'FS')
-rw-r--r--FS/FS/cust_main/Search.pm23
1 files changed, 23 insertions, 0 deletions
diff --git a/FS/FS/cust_main/Search.pm b/FS/FS/cust_main/Search.pm
index 5c21a8e12..04d97bda9 100644
--- a/FS/FS/cust_main/Search.pm
+++ b/FS/FS/cust_main/Search.pm
@@ -878,6 +878,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
##
@@ -1147,6 +1156,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 = {