X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=FS%2FFS%2Fcust_main%2FSearch.pm;h=ef106b560bdd4e4cc6778e11f90d7cccb0cfa996;hb=2c04f1df05a1b14d9539bbae97275c1d3a0995e2;hp=e9a42935d405648f270a9664cb76a189bf1c50bb;hpb=9f80fd85a1bbe4edeb075fc364da2a03edd294af;p=freeside.git diff --git a/FS/FS/cust_main/Search.pm b/FS/FS/cust_main/Search.pm index e9a42935d..ef106b560 100644 --- a/FS/FS/cust_main/Search.pm +++ b/FS/FS/cust_main/Search.pm @@ -358,13 +358,15 @@ sub smart_search { #substring - my @company_hashrefs = ( - { 'company' => { op=>'ILIKE', value=>"%$value%" }, }, - { 'ship_company' => { op=>'ILIKE', value=>"%$value%" }, }, - ); + my @company_hashrefs = (); + if ( length($value) >= 3 ) { + @company_hashrefs = ( + { 'company' => { op=>'ILIKE', value=>"%$value%" }, }, + { 'ship_company' => { op=>'ILIKE', value=>"%$value%" }, }, + ); + } my @hashrefs = (); - if ( $first && $last ) { @hashrefs = ( @@ -373,12 +375,13 @@ sub smart_search { }, ); - } else { + } elsif ( length($value) >= 3 ) { @hashrefs = ( { 'first' => { op=>'ILIKE', value=>"%$value%" }, }, { 'last' => { op=>'ILIKE', value=>"%$value%" }, }, ); + } foreach my $hashref ( @company_hashrefs, @hashrefs ) { @@ -393,7 +396,7 @@ sub smart_search { } - if ( $conf->exists('address1-search') ) { + if ( $conf->exists('address1-search') && length($value) >= 3 ) { push @cust_main, qsearch( { table => 'cust_main', @@ -513,11 +516,9 @@ none or one). sub email_search { my %options = @_; - local($DEBUG) = 1; - my $email = delete $options{'email'}; - #we're only being used by RT at the moment... no agent virtualization yet + #no agent virtualization yet #my $agentnums_sql = $FS::CurrentUser::CurrentUser->agentnums_sql; my @cust_main = (); @@ -703,6 +704,21 @@ sub search { push @where, FS::cust_main->$method(); } + my $current = ''; + unless ( $params->{location_history} ) { + $current = ' + AND ( cust_location.locationnum IN ( cust_main.bill_locationnum, + cust_main.ship_locationnum + ) + OR cust_location.locationnum IN ( + SELECT locationnum FROM cust_pkg + WHERE cust_pkg.custnum = cust_main.custnum + AND locationnum IS NOT NULL + AND '. FS::cust_pkg->ncancelled_recurring_sql.' + ) + )'; + } + ## # address ## @@ -722,6 +738,7 @@ sub search { SELECT 1 FROM cust_location WHERE cust_location.custnum = cust_main.custnum AND (".join(' OR ',@orwhere).") + $current )"; } } @@ -735,6 +752,7 @@ sub search { SELECT 1 FROM cust_location WHERE cust_location.custnum = cust_main.custnum AND cust_location.city = $city + $current )"; } @@ -747,6 +765,7 @@ sub search { SELECT 1 FROM cust_location WHERE cust_location.custnum = cust_main.custnum AND cust_location.county = $county + $current )"; } @@ -759,6 +778,7 @@ sub search { SELECT 1 FROM cust_location WHERE cust_location.custnum = cust_main.custnum AND cust_location.state = $state + $current )"; } @@ -771,6 +791,7 @@ sub search { SELECT 1 FROM cust_location WHERE cust_location.custnum = cust_main.custnum AND cust_location.zip LIKE $zip + $current )"; } @@ -783,6 +804,7 @@ sub search { SELECT 1 FROM cust_location WHERE cust_location.custnum = cust_main.custnum AND cust_location.country = '$country' + $current )"; } @@ -1061,7 +1083,7 @@ sub search { # always make referral available in results # (maybe we should be using FS::UI::Web::join_cust_main instead?) - $addl_from .= ' LEFT JOIN part_referral ON (cust_main.refnum = part_referral.refnum) '; + $addl_from .= ' LEFT JOIN (select refnum, referral from part_referral) AS part_referral_x ON (cust_main.refnum = part_referral_x.refnum) '; my $count_query = "SELECT COUNT(*) FROM cust_main $addl_from $extra_sql";