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)
if((!DolibarrApiAccess::$user->rights->societe->client->voir&&!$socids)||$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."commande as s";
$sql.=" FROM ".MAIN_DB_PREFIX."commande 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
if((!DolibarrApiAccess::$user->rights->societe->client->voir&&!$socids)||$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.=' WHERE s.entity IN ('.getEntity('commande',1).')';
$sql.=' WHERE s.entity IN ('.getEntity('commande',1).')';
if((!DolibarrApiAccess::$user->rights->societe->client->voir&&!$socid)||$search_sale>0)$sql.=" AND s.fk_soc = sc.fk_soc";
if((!DolibarrApiAccess::$user->rights->societe->client->voir&&!$socids)||$search_sale>0)$sql.=" AND s.fk_soc = sc.fk_soc";
if($socid)$sql.=" AND s.fk_soc = ".$socid;
if($socids)$sql.=" AND s.fk_soc IN (".$socids.")";
if($search_sale>0)$sql.=" AND s.rowid = sc.fk_soc";// Join for the needed table to filter by sale
if($search_sale>0)$sql.=" AND s.rowid = sc.fk_soc";// Join for the needed table to filter by sale