better address searching: disable fuzzy/substring searches when an exact match is...
authorivan <ivan>
Thu, 21 Oct 2010 01:34:52 +0000 (01:34 +0000)
committerivan <ivan>
Thu, 21 Oct 2010 01:34:52 +0000 (01:34 +0000)
FS/FS/Conf.pm
FS/FS/ConfDefaults.pm
FS/FS/cust_main/Search.pm
httemplate/search/cust_main.cgi
httemplate/search/cust_main.html
httemplate/search/report_cust_main.html

index 980bd62..b1f003b 100644 (file)
@@ -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',
   },
 
index 12c82e6..de65b44 100644 (file)
@@ -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)',
index 3813f89..a87928f 100644 (file)
@@ -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
   ##
index 93f960f..a92c12d 100755 (executable)
 %  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
index b6db4e4..57538d8 100755 (executable)
@@ -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 ) {
index eb1a662..5b1b878 100755 (executable)
               )
     %>
 
+    <TR>
+      <TD ALIGN="right" VALIGN="center">Address</TD>
+      <TD><INPUT TYPE="text" NAME="address" SIZE=54></TD>
+    </TR>
+
 %   foreach my $field (qw( signupdate )) {
 
       <TR>