customer referral report, RT#75757
authorIvan Kohler <ivan@freeside.biz>
Thu, 27 Apr 2017 20:41:58 +0000 (13:41 -0700)
committerIvan Kohler <ivan@freeside.biz>
Thu, 27 Apr 2017 20:41:58 +0000 (13:41 -0700)
FS/FS/cust_main/Search.pm
httemplate/elements/menu.html
httemplate/search/cust_main.html

index 4473aed..0eb0020 100644 (file)
@@ -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 = {
index 752c312..58a7d57 100644 (file)
@@ -129,6 +129,7 @@ $report_customers_lists{'by active trouble tickets'} = [ $fsurl. 'search/cust_ma
   if $conf->config('ticket_system');
 $report_customers_lists{'with USPS-unvalidated addresses'} = [ $fsurl. 'search/cust_main.cgi?browse=uspsunvalid', '' ]
   if $conf->config('usps_webtools-userid') && $conf->config('usps_webtools-password');
+$report_customers_lists{'with referrals'} = [ $fsurl. 'search/cust_main.html?with_referrals=1' ];
 
 tie my %report_customers, 'Tie::IxHash';
 $report_customers{'List customers'} = [ \%report_customers_lists, 'List customers' ]
index b0ce31a..41309fd 100755 (executable)
                                                       $cgi->param('cust_fields')
                                                                    )
                                      ),
-                                     map '', @extra_fields
+                                     map  { $_ eq 'num_referrals'
+                                              ? $referral_link
+                                              : ''
+                                          }
+                                       @extra_fields
                                    ],
 &>
 <%init>
@@ -51,6 +55,7 @@ my @scalars = qw (
   all_tags
   all_pkg_classnums
   any_pkg_status
+  with_referrals
 );
 
 for my $param ( @scalars ) {
@@ -111,6 +116,8 @@ my @extra_fields  = @{ delete($sql_query->{'extra_fields'})  };
 
 my $link = [ "${p}view/cust_main.cgi?", 'custnum' ];
 
+my $referral_link = [ "${p}search/cust_main.cgi?referral_custnum=", 'custnum' ];
+
 ###
 # email links
 ###