Added natural search to third parties

This commit is contained in:
Raphaël Doursenaud 2013-03-15 15:37:59 +01:00
parent ea442d9351
commit 639c033afb

View File

@ -3,6 +3,7 @@
* Copyright (C) 2004-2011 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2005-2012 Regis Houssin <regis.houssin@capnetworks.com>
* Copyright (C) 2012 Marcos García <marcosgdf@gmail.com>
* Copyright (C) 2013 Raphaël Doursenaud <rdoursenaud@gpcsolutions.fr>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -80,19 +81,25 @@ if ($mode == 'search')
// We'll need this table joined to the select in order to filter by categ
if ($search_categ) $sql.= ", ".MAIN_DB_PREFIX."categorie_societe as cs";
$sql.= " WHERE s.entity IN (".getEntity('societe', 1).")";
$sql.= " AND (";
$sql.= " s.nom LIKE '%".$db->escape($socname)."%'";
$sql.= " OR s.code_client LIKE '%".$db->escape($socname)."%'";
$sql.= " OR s.email LIKE '%".$db->escape($socname)."%'";
$sql.= " OR s.url LIKE '%".$db->escape($socname)."%'";
$sql.= " OR s.siren LIKE '%".$db->escape($socname)."%'";
if (!empty($conf->barcode->enabled))
{
$sql.= "OR s.barcode LIKE '".$db->escape($socname)."'";
}
// For natural search
$scrit = explode(' ', $socname);
foreach ($scrit as $crit) {
$sql.= " AND (";
$sql.= " s.nom LIKE '%".$db->escape($crit)."%'";
$sql.= " OR s.code_client LIKE '%".$db->escape($crit)."%'";
$sql.= " OR s.email LIKE '%".$db->escape($crit)."%'";
$sql.= " OR s.url LIKE '%".$db->escape($crit)."%'";
$sql.= " OR s.siren LIKE '%".$db->escape($crit)."%'";
if (!empty($conf->barcode->enabled))
{
$sql.= "OR s.barcode LIKE '".$db->escape($crit)."'";
}
$sql.= ")";
}
$sql.= ")";
if (!$user->rights->societe->client->voir && !$socid) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
if ($socid) $sql.= " AND s.rowid = ".$socid;
if ($search_sale) $sql.= " AND s.rowid = sc.fk_soc"; // Join for the needed table to filter by sale