referral status search, RT#75757
authorIvan Kohler <ivan@freeside.biz>
Sat, 26 Aug 2017 22:00:59 +0000 (15:00 -0700)
committerIvan Kohler <ivan@freeside.biz>
Sat, 26 Aug 2017 22:00:59 +0000 (15:00 -0700)
FS/FS/cust_main/Search.pm
httemplate/search/cust_main.html
httemplate/search/report_cust_main.html

index 09558b8..4eab474 100644 (file)
@@ -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
+              )";
+
   }
 
   ##
index 41309fd..c897879 100755 (executable)
@@ -55,7 +55,7 @@ my @scalars = qw (
   all_tags
   all_pkg_classnums
   any_pkg_status
-  with_referrals
+  with_referrals referral_status
 );
 
 for my $param ( @scalars ) {
index 2a313a1..14e7844 100755 (executable)
         </TD>
       </TR>
 
+  </TABLE>
+  <BR>
+
+  <FONT CLASS="fsinnerbox-title"><% emt('Referral search options') %></FONT>
+  <TABLE CLASS="fsinnerbox">
+
       <& /elements/tr-input-text.html,
-           label     => emt('At least this many referrals'),
+           label     => emt('At least this many'),
            field     => 'with_referrals',
            size      => 4,
            maxlength => 4,
       &>
 
+      <& /elements/tr-select-cust_main-status.html,
+           label => emt('Referral status'),
+           field => 'referral_status',
+      &>
+
   </TABLE>
   <BR>