X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=FS%2FFS%2Fcust_main%2FSearch.pm;h=5636fc6e4be6896a4bad3d7d949213571ac711a6;hb=dafdfc24616b04a5ff594da31e2cdd03f58634b6;hp=ac170ff1f91240ce73efc6fb5c85365516cc7ba4;hpb=bd35baff8b7b5dcdd44d14a1139ef4d48009274c;p=freeside.git diff --git a/FS/FS/cust_main/Search.pm b/FS/FS/cust_main/Search.pm index ac170ff1f..5636fc6e4 100644 --- a/FS/FS/cust_main/Search.pm +++ b/FS/FS/cust_main/Search.pm @@ -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*$/ ) @@ -462,6 +471,33 @@ sub search { my @where = (); my $orderby; + # initialize these to prevent warnings + $params = { + 'custnum' => '', + 'agentnum' => '', + 'usernum' => '', + 'status' => '', + 'address' => '', + 'paydate_year' => '', + 'invoice_terms' => '', + 'custbatch' => '', + %$params + }; + + ## + # explicit custnum(s) + ## + + if ( $params->{'custnum'} ) { + my @custnums = ref($params->{'custnum'}) ? + @{ $params->{'custnum'} } : + $params->{'custnum'}; + push @where, + 'cust_main.custnum IN (' . + join(',', map { $_ =~ /^(\d+)$/ ? $1 : () } @custnums ) . + ')' if scalar(@custnums) > 0; + } + ## # parse agent ## @@ -658,6 +694,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