thrownewRestException(404,'Thirdparties not found');
$sql="SELECT s.rowid";
if((!DolibarrApiAccess::$user->rights->societe->client->voir&&!$socid)||$search_sale>0)$sql.=", sc.fk_soc, sc.fk_user";// We need these fields in order to filter by sale (including the case where the user can only see his prospects)
$sql.=" FROM ".MAIN_DB_PREFIX."societe as s";
if((!DolibarrApiAccess::$user->rights->societe->client->voir&&!$socid)||$search_sale>0)$sql.=", ".MAIN_DB_PREFIX."societe_commerciaux as sc";// We need this table joined to the select in order to filter by sale
$sql.=", ".MAIN_DB_PREFIX."c_stcomm as st";
$sql.=" WHERE s.fk_stcomm = st.id";
//$sql.= " AND s.client IN (1, 3)";
$sql.=' AND s.entity IN ('.getEntity('societe',1).')';
if((!DolibarrApiAccess::$user->rights->societe->client->voir&&!$socid)||$search_sale>0)$sql.=" AND s.rowid = sc.fk_soc";
if($socid)$sql.=" AND s.rowid = ".$socid;
if($search_sale>0)$sql.=" AND s.rowid = sc.fk_soc";// Join for the needed table to filter by sale