* 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
...
...
@@ -352,16 +353,17 @@ $parameters=array();
$reshook=$hookmanager->executeHooks('printFieldListSelect',$parameters);// Note that $action and $object may have been modified by hook
$sql.=$hookmanager->resPrint;
$sql.=" FROM ".MAIN_DB_PREFIX."societe as s";
if(is_array($extrafields->attribute_label)&&count($extrafields->attribute_label))$sql.=" LEFT JOIN ".MAIN_DB_PREFIX."societe_extrafields as ef on (s.rowid = ef.fk_object)";
$sql.=" LEFT JOIN ".MAIN_DB_PREFIX."c_country as country on (country.rowid = s.fk_pays) ";
$sql.=" LEFT JOIN ".MAIN_DB_PREFIX."c_typent as typent on (typent.id = s.fk_typent) ";
$sql.=" ,".MAIN_DB_PREFIX."c_stcomm as st";
if(is_array($extrafields->attribute_label)&&count($extrafields->attribute_label))$sql.=" , ".MAIN_DB_PREFIX."societe_extrafields as ef ";
// We'll need this table joined to the select in order to filter by sale
if($search_sale||(!$user->rights->societe->client->voir&&!$socid))$sql.=", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
// We'll need this table joined to the select in order to filter by categ
if($search_categ)$sql.=", ".MAIN_DB_PREFIX."categorie_".($type=='f'?"fournisseur":"societe")." as cs";
$sql.=" WHERE s.fk_stcomm = st.id";
$sql.=" AND s.entity IN (".getEntity('societe',1).")";
if(is_array($extrafields->attribute_label)&&count($extrafields->attribute_label))$sql.=" AND s.rowid = ef.fk_object";
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