RT#41124: Backend Unti Search
authorJonathan Prykop <jonathan@freeside.biz>
Mon, 9 May 2016 22:50:27 +0000 (17:50 -0500)
committerJonathan Prykop <jonathan@freeside.biz>
Mon, 9 May 2016 23:02:48 +0000 (18:02 -0500)
httemplate/edit/process/cust_main.cgi
httemplate/search/cust_main.cgi

index 82ec50c..6961d18 100755 (executable)
@@ -97,8 +97,8 @@ if ( ($cgi->param('same') || '') eq 'Y' ) {
 # but explicitly avoid setting ship_ fields
 
 my $new = new FS::cust_main ( {
-  map { ( $_, scalar($cgi->param($_)) ) } (fields('cust_main')),
-  map { ( "ship_$_", '' ) } (FS::cust_main->location_fields)
+  (map { ( $_, scalar($cgi->param($_)) ) } (fields('cust_main'))),
+  (map { ( "ship_$_", '' ) } (FS::cust_main->location_fields))
 } );
 
 $new->invoice_noemail( ($cgi->param('invoice_email') eq 'Y') ? '' : 'Y' );
index 4e624eb..aa8c079 100755 (executable)
@@ -704,12 +704,20 @@ sub address2search {
       or errorpage(emt("Illegal address2"));
   my $address2 = $1;
 
-  push @cust_main, qsearch( 'cust_main',
-                            { 'address2' => { 'op'    => 'ILIKE',
-                                              'value' => $address2 } } );
-  push @cust_main, qsearch( 'cust_main',
-                            { 'ship_address2' => { 'op'    => 'ILIKE',
-                                                   'value' => $address2 } } );
+  # matching at the start or end of an address, but not in the middle
+  my @where;
+  foreach my $toggle (0,1) {
+    push @where, 'LOWER(cust_location.address2) LIKE LOWER('
+                 . dbh->quote($toggle ? $address2 . '%' : '%' . $address2)
+                 . ')';
+  }
+
+  push @cust_main, qsearch({
+    'debug'     => 1,
+    'table'     => 'cust_main',
+    'addl_from' => 'JOIN cust_location ON (cust_location.locationnum IN (cust_main.bill_locationnum, cust_main.ship_locationnum))',
+    'extra_sql' => 'WHERE ' . join(' OR ',@where),
+  });
 
   \@cust_main;
 }