diff options
author | Ivan Kohler <ivan@freeside.biz> | 2017-04-27 13:42:01 -0700 |
---|---|---|
committer | Ivan Kohler <ivan@freeside.biz> | 2017-04-27 13:42:01 -0700 |
commit | c6067e5ce005117ee3239eb00de0adc58efa4ee5 (patch) | |
tree | 6dbfaaa13a286fe883d285d8d2a73fdbfdd5efe7 /FS | |
parent | 6d922e31555a5888a1c070ea403e5d80608d357c (diff) |
customer referral report, RT#75757
Diffstat (limited to 'FS')
-rw-r--r-- | FS/FS/cust_main/Search.pm | 23 |
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 = { |