add customer search by billing email, RT10399
[freeside.git] / FS / FS / cust_main / Search.pm
index ac170ff..06a4522 100644 (file)
@@ -112,8 +112,17 @@ sub smart_search {
   # custnum search (also try agent_custid), with some tweaking options if your
   # legacy cust "numbers" have letters
   } 
-
-  if ( $search =~ /^\s*(\d+)\s*$/
+  
+  
+  if ( $search =~ /@/ ) {
+      push @cust_main,
+         map $_->cust_main,
+             qsearch( {
+                        'table'     => 'cust_main_invoice',
+                        'hashref'   => { 'dest' => $search },
+                      }
+                    );
+  } elsif ( $search =~ /^\s*(\d+)\s*$/
          || ( $conf->config('cust_main-agent_custid-format') eq 'ww?d+'
               && $search =~ /^\s*(\w\w?\d+)\s*$/
             )
@@ -658,6 +667,21 @@ sub search {
     push @where,
       "cust_main.custbatch = '$1'";
   }
+  
+  if ( $params->{'tagnum'} ) {
+    my @tagnums = ref( $params->{'tagnum'} ) ? @{ $params->{'tagnum'} } : ( $params->{'tagnum'} );
+
+    @tagnums = grep /^(\d+)$/, @tagnums;
+
+    if ( @tagnums ) {
+       my $tags_where = "0 < (select count(1) from cust_tag where " 
+               . " cust_tag.custnum = cust_main.custnum and tagnum in ("
+               . join(',', @tagnums) . "))";
+
+       push @where, $tags_where;
+    }
+  }
+
 
   ##
   # setup queries, subs, etc. for the search