From 2bb7bb059897fd50bcc34586cfd1a9a4d257eb91 Mon Sep 17 00:00:00 2001 From: ivan Date: Thu, 21 Oct 2010 01:34:52 +0000 Subject: [PATCH] better address searching: disable fuzzy/substring searches when an exact match is found, work around L:EN:NameParse DrainBramage w/two-letter first names like "Ed", add an address1 search to advanced customer search, RT#10254 --- FS/FS/Conf.pm | 2 +- FS/FS/ConfDefaults.pm | 12 ++++++------ FS/FS/cust_main/Search.pm | 18 ++++++++++++++++-- httemplate/search/cust_main.cgi | 4 +++- httemplate/search/cust_main.html | 6 ++++-- httemplate/search/report_cust_main.html | 5 +++++ 6 files changed, 35 insertions(+), 12 deletions(-) diff --git a/FS/FS/Conf.pm b/FS/FS/Conf.pm index 980bd628a..b1f003b54 100644 --- a/FS/FS/Conf.pm +++ b/FS/FS/Conf.pm @@ -2477,7 +2477,7 @@ and customer address. Include units.', { 'key' => 'address1-search', 'section' => 'UI', - 'description' => 'Enable the ability to search the address1 field from customer search.', + 'description' => 'Enable the ability to search the address1 field from the quick customer search. Not recommended in most cases as it tends to bring up too many search results - use explicit address searching from the advanced customer search instead.', 'type' => 'checkbox', }, diff --git a/FS/FS/ConfDefaults.pm b/FS/FS/ConfDefaults.pm index 12c82e69c..de65b44a9 100644 --- a/FS/FS/ConfDefaults.pm +++ b/FS/FS/ConfDefaults.pm @@ -49,22 +49,22 @@ sub cust_fields_avail { ( 'custnum | Status | Last, First | Company | (same for service contact if present)', 'Cust# | Cust. Status | Name | Company | Address 1 | Address 2 | City | State | Zip | Country | Day phone | Night phone | Invoicing email(s)' => - 'custnum | Status | Last, First | Company | (all address fields) | Day phone | Night phone | Invoicing email(s)', + 'custnum | Status | Last, First | Company | (address) | Day phone | Night phone | Invoicing email(s)', 'Cust# | Cust. Status | Name | Company | Address 1 | Address 2 | City | State | Zip | Country | Day phone | Night phone | Fax number | Invoicing email(s) | Payment Type' => - 'custnum | Status | Last, First | Company | (all address fields) | (all phones) | Invoicing email(s) | Payment Type', + 'custnum | Status | Last, First | Company | (address) | (all phones) | Invoicing email(s) | Payment Type', 'Cust# | Cust. Status | Name | Company | Address 1 | Address 2 | City | State | Zip | Country | Day phone | Night phone | Fax number | Invoicing email(s) | Payment Type | Current Balance' => - 'custnum | Status | Last, First | Company | (all address fields) | (all phones) | Invoicing email(s) | Payment Type | Current Balance', + 'custnum | Status | Last, First | Company | (address) | (all phones) | Invoicing email(s) | Payment Type | Current Balance', 'Cust# | Cust. Status | (bill) Name | (bill) Company | (bill) Address 1 | (bill) Address 2 | (bill) City | (bill) State | (bill) Zip | (bill) Country | (bill) Day phone | (bill) Night phone | (service) Name | (service) Company | (service) Address 1 | (service) Address 2 | (service) City | (service) State | (service) Zip | (service) Country | (service) Day phone | (service) Night phone | Invoicing email(s)' => - 'custnum | Status | Last, First | Company | (all address fields) | Day phone | Night phone | (service address) | Invoicing email(s)', + 'custnum | Status | Last, First | Company | (address) | Day phone | Night phone | (service address) | Invoicing email(s)', 'Cust# | Cust. Status | (bill) Name | (bill) Company | (bill) Address 1 | (bill) Address 2 | (bill) City | (bill) State | (bill) Zip | (bill) Country | (bill) Day phone | (bill) Night phone | (bill) Fax number | (service) Name | (service) Company | (service) Address 1 | (service) Address 2 | (service) City | (service) State | (service) Zip | (service) Country | (service) Day phone | (service) Night phone | (service) Fax number | Invoicing email(s) | Payment Type' => - 'custnum | Status | Last, First | Company | (all address fields) | (all phones) | (service address) | Invoicing email(s) | Payment Type', + 'custnum | Status | Last, First | Company | (address) | (all phones) | (service address) | Invoicing email(s) | Payment Type', 'Cust# | Cust. Status | (bill) Name | (bill) Company | (bill) Address 1 | (bill) Address 2 | (bill) City | (bill) State | (bill) Zip | (bill) Country | (bill) Day phone | (bill) Night phone | (bill) Fax number | (service) Name | (service) Company | (service) Address 1 | (service) Address 2 | (service) City | (service) State | (service) Zip | (service) Country | (service) Day phone | (service) Night phone | (service) Fax number | Invoicing email(s) | Payment Type | Current Balance' => - 'custnum | Status | Last, First | Company | (all address fields) | (all phones) | (service address) | Invoicing email(s) | Payment Type | Current Balance', + 'custnum | Status | Last, First | Company | (address) | (all phones) | (service address) | Invoicing email(s) | Payment Type | Current Balance', 'Invoicing email(s)' => 'Invoicing email(s)', 'Cust# | Invoicing email(s)' => 'custnum | Invoicing email(s)', diff --git a/FS/FS/cust_main/Search.pm b/FS/FS/cust_main/Search.pm index 3813f891a..a87928f6a 100644 --- a/FS/FS/cust_main/Search.pm +++ b/FS/FS/cust_main/Search.pm @@ -203,7 +203,7 @@ sub smart_search { } elsif ( ! $NameParse->parse($value) ) { my %name = $NameParse->components; - $first = $name{'given_name_1'}; + $first = $name{'given_name_1'} || $name{'initials_1'}; #wtf NameParse, Ed? $last = $name{'surname_1'}; } @@ -422,6 +422,8 @@ HASHREF. Valid parameters are =item status +=item address + =item cancelled_pkgs bool @@ -488,7 +490,19 @@ sub search { #push @where, $class->$method(); push @where, FS::cust_main->$method(); } - + + ## + # address + ## + if ( $params->{'address'} =~ /\S/ ) { + my $address = dbh->quote('%'. lc($params->{'address'}). '%'); + push @where, '('. join(' OR ', + map "LOWER($_) LIKE $address", + qw(address1 address2 ship_address1 ship_address2) + ). + ')'; + } + ## # parse cancelled package checkbox ## diff --git a/httemplate/search/cust_main.cgi b/httemplate/search/cust_main.cgi index 93f960f5c..a92c12db5 100755 --- a/httemplate/search/cust_main.cgi +++ b/httemplate/search/cust_main.cgi @@ -204,7 +204,9 @@ % if ( $cgi->param('search_cust') ) { % $sortby = \*company_sort; % $orderby = "ORDER BY LOWER(company || ' ' || last || ' ' || first )"; -% push @cust_main, smart_search( 'search' => $cgi->param('search_cust') ); +% push @cust_main, smart_search( 'search' => $cgi->param('search_cust'), +% 'disable_fuzzy_on_exact' => 1, #pref? +% ); % } % % @cust_main = grep { $_->ncancelled_pkgs || ! $_->all_pkgs } @cust_main diff --git a/httemplate/search/cust_main.html b/httemplate/search/cust_main.html index b6db4e434..57538d8ca 100755 --- a/httemplate/search/cust_main.html +++ b/httemplate/search/cust_main.html @@ -44,8 +44,10 @@ my %search_hash = (); #scalars my @scalars = qw ( - agentnum status cancelled_pkgs cust_fields flattened_pkgs custbatch usernum - no_censustract paydate_year paydate_month invoice_terms + agentnum status address paydate_year paydate_month invoice_terms + no_censustract custbatch usernum + cancelled_pkgs + cust_fields flattened_pkgs ); for my $param ( @scalars ) { diff --git a/httemplate/search/report_cust_main.html b/httemplate/search/report_cust_main.html index eb1a66273..5b1b878af 100755 --- a/httemplate/search/report_cust_main.html +++ b/httemplate/search/report_cust_main.html @@ -28,6 +28,11 @@ ) %> + + Address + + + % foreach my $field (qw( signupdate )) { -- 2.11.0