X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=FS%2FFS%2Fcust_main%2FSearch.pm;h=0eb00202b00a41d906cb778d461d444f796d6a00;hb=a989f40712bcbef325a566802118432063315240;hp=14dd4b4696c3e97cc08ecf138e1b18508c813d3a;hpb=c67eaf049134e6f7ab9fe8d33d043d7d397008f3;p=freeside.git diff --git a/FS/FS/cust_main/Search.pm b/FS/FS/cust_main/Search.pm index 14dd4b469..0eb00202b 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) >= 4 ) { + @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) >= 4 ) { @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) >= 4 ) { push @cust_main, qsearch( { table => 'cust_main', @@ -441,7 +444,8 @@ sub smart_search { 'contact.first' => $first }, # %fuzopts ); - } + } + foreach my $field ( 'first', 'last', 'company', 'ship_company' ) { push @cust_main, FS::cust_main::Search->fuzzy_search( { $field => $value }, @@ -862,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 ## @@ -1097,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 = {