diff --git a/htdocs/accountancy/customer/card.php b/htdocs/accountancy/customer/card.php index 71afe4ca218d5..487f4dc27190e 100644 --- a/htdocs/accountancy/customer/card.php +++ b/htdocs/accountancy/customer/card.php @@ -87,7 +87,7 @@ $sql .= " WHERE f.fk_statut > 0 AND l.rowid = " . $id; if (! empty($conf->multicompany->enabled)) { - $sql .= " AND f.entity = '" . $conf->entity . "'"; + $sql .= " AND f.entity IN (" . getEntity("facture", 1) . ")"; } dol_syslog("/accounting/customer/card.php sql=" . $sql, LOG_DEBUG); diff --git a/htdocs/accountancy/customer/index.php b/htdocs/accountancy/customer/index.php index 39c9d05c83343..df6351554164c 100644 --- a/htdocs/accountancy/customer/index.php +++ b/htdocs/accountancy/customer/index.php @@ -159,7 +159,7 @@ $sql .= " AND f.datef <= '" . $db->idate(dol_get_last_day($y, 12, false)) . "'"; if (! empty($conf->multicompany->enabled)) { - $sql .= " AND f.entity = '" . $conf->entity . "'"; + $sql .= " AND f.entity IN (" . getEntity("facture", 1) . ")"; } $sql .= " GROUP BY fd.fk_code_ventilation"; @@ -234,7 +234,7 @@ $sql .= " AND f.datef <= '" . $db->idate(dol_get_last_day($y, 12, false)) . "'"; if (! empty($conf->multicompany->enabled)) { - $sql .= " AND f.entity = '" . $conf->entity . "'"; + $sql .= " AND f.entity IN (" . getEntity("facture", 1) . ")"; } dol_syslog('htdocs/accountancy/customer/index.php:: $sql=' . $sql); @@ -307,7 +307,7 @@ $sql .= " AND f.datef <= '" . $db->idate(dol_get_last_day($y, 12, false)) . "'"; if (! empty($conf->multicompany->enabled)) { - $sql .= " AND f.entity = '" . $conf->entity . "'"; + $sql .= " AND f.entity IN (" . getEntity("facture", 1) . ")"; } dol_syslog('htdocs/accountancy/customer/index.php:: $sql=' . $sql); diff --git a/htdocs/accountancy/customer/lines.php b/htdocs/accountancy/customer/lines.php index 01806db83320e..2b523040e6f52 100644 --- a/htdocs/accountancy/customer/lines.php +++ b/htdocs/accountancy/customer/lines.php @@ -124,7 +124,7 @@ } if (! empty($conf->multicompany->enabled)) { - $sql .= " AND f.entity = '" . $conf->entity . "'"; + $sql .= " AND f.entity IN (" . getEntity("facture", 1) . ")"; } $sql .= " ORDER BY l.rowid"; diff --git a/htdocs/accountancy/customer/list.php b/htdocs/accountancy/customer/list.php index 3d4987bd94add..ac1c342965832 100644 --- a/htdocs/accountancy/customer/list.php +++ b/htdocs/accountancy/customer/list.php @@ -132,7 +132,7 @@ $sql .= " WHERE f.fk_statut > 0 AND fk_code_ventilation <= 0"; $sql .= " AND (accsys.rowid='" . $conf->global->CHARTOFACCOUNTS . "' OR p.accountancy_code_sell IS NULL OR p.accountancy_code_sell ='')"; if (! empty($conf->multicompany->enabled)) { - $sql .= " AND f.entity = '" . $conf->entity . "'"; + $sql .= " AND f.entity IN (" . getEntity("facture", 1) . ")"; } $sql .= " ORDER BY l.rowid"; diff --git a/htdocs/accountancy/journal/purchasesjournal.php b/htdocs/accountancy/journal/purchasesjournal.php index 6d89e8f17a2cf..0a000e0183342 100644 --- a/htdocs/accountancy/journal/purchasesjournal.php +++ b/htdocs/accountancy/journal/purchasesjournal.php @@ -96,7 +96,7 @@ $sql .= " JOIN " . MAIN_DB_PREFIX . "societe as s ON s.rowid = f.fk_soc"; $sql .= " WHERE f.fk_statut > 0 "; if (! empty($conf->multicompany->enabled)) { - $sql .= " AND f.entity = " . $conf->entity; + $sql .= " AND f.entity IN (" . getEntity("facture_fourn", 1) . ")"; } if (! empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) $sql .= " AND f.type IN (0,1,2)"; diff --git a/htdocs/accountancy/journal/sellsjournal.php b/htdocs/accountancy/journal/sellsjournal.php index c2c51bacd4225..24ed25f56ed24 100644 --- a/htdocs/accountancy/journal/sellsjournal.php +++ b/htdocs/accountancy/journal/sellsjournal.php @@ -99,7 +99,7 @@ $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "c_tva as ct ON fd.tva_tx = ct.taux AND ct.fk_pays = '" . $idpays . "'"; $sql .= " WHERE fd.fk_code_ventilation > 0 "; if (! empty($conf->multicompany->enabled)) { - $sql .= " AND f.entity = " . $conf->entity; + $sql .= " AND f.entity IN (" . getEntity("facture", 1) . ")"; } $sql .= " AND f.fk_statut > 0"; if (! empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) diff --git a/htdocs/accountancy/supplier/card.php b/htdocs/accountancy/supplier/card.php index 70d97b376c542..51d09428c25a5 100644 --- a/htdocs/accountancy/supplier/card.php +++ b/htdocs/accountancy/supplier/card.php @@ -88,7 +88,7 @@ $sql .= " INNER JOIN " . MAIN_DB_PREFIX . "facture_fourn as f ON f.rowid = l.fk_facture_fourn "; $sql .= " WHERE f.fk_statut > 0 AND l.rowid = " . $id; if (! empty($conf->multicompany->enabled)) { - $sql .= " AND f.entity = '" . $conf->entity . "'"; + $sql .= " AND f.entity IN (" . getEntity("facture_fourn", 1) . ")"; } $result = $db->query($sql); diff --git a/htdocs/accountancy/supplier/index.php b/htdocs/accountancy/supplier/index.php index 85d1c04cf53fa..3bdf2f45a7c11 100644 --- a/htdocs/accountancy/supplier/index.php +++ b/htdocs/accountancy/supplier/index.php @@ -144,7 +144,7 @@ $sql .= " AND ff.fk_statut > 0 "; if (! empty($conf->multicompany->enabled)) { - $sql .= " AND ff.entity = '" . $conf->entity . "'"; + $sql .= " AND ff.entity IN (" . getEntity("facture_fourn", 1) . ")"; } $sql .= " GROUP BY ffd.fk_code_ventilation"; @@ -221,7 +221,7 @@ $sql .= " AND ff.fk_statut > 0 "; if (! empty($conf->multicompany->enabled)) { - $sql .= " AND ff.entity = '" . $conf->entity . "'"; + $sql .= " AND ff.entity IN (" . getEntity("facture_fourn", 1) . ")"; } dol_syslog('/accountancy/supplier/index.php:: sql=' . $sql); diff --git a/htdocs/accountancy/supplier/lines.php b/htdocs/accountancy/supplier/lines.php index 5df5ee0c06f52..df3816c4d4c6c 100644 --- a/htdocs/accountancy/supplier/lines.php +++ b/htdocs/accountancy/supplier/lines.php @@ -121,7 +121,7 @@ $sql .= " AND aa.account_number like '%" . $_GET["search_account"] . "%'"; } if (! empty($conf->multicompany->enabled)) { - $sql .= " AND f.entity = '" . $conf->entity . "'"; + $sql .= " AND f.entity IN (" . getEntity("facture_fourn", 1) . ")"; } $sql .= " ORDER BY l.rowid"; diff --git a/htdocs/accountancy/supplier/list.php b/htdocs/accountancy/supplier/list.php index 656afbd32cc6a..bf14ebc185e6a 100644 --- a/htdocs/accountancy/supplier/list.php +++ b/htdocs/accountancy/supplier/list.php @@ -135,7 +135,7 @@ $sql .= " AND (accsys.rowid='".$conf->global->CHARTOFACCOUNTS."' OR p.accountancy_code_sell IS NULL OR p.accountancy_code_buy ='')"; if (! empty($conf->multicompany->enabled)) { - $sql .= " AND f.entity = '" . $conf->entity . "'"; + $sql .= " AND f.entity IN (" . getEntity("facture_fourn", 1) . ")"; } $sql .= " ORDER BY l.rowid"; diff --git a/htdocs/adherents/class/adherent.class.php b/htdocs/adherents/class/adherent.class.php index 941f7b300fd73..f3c391b5ecde1 100644 --- a/htdocs/adherents/class/adherent.class.php +++ b/htdocs/adherents/class/adherent.class.php @@ -1703,7 +1703,7 @@ function load_state_board() $sql = "SELECT count(a.rowid) as nb"; $sql.= " FROM ".MAIN_DB_PREFIX."adherent as a"; $sql.= " WHERE a.statut > 0"; - $sql.= " AND a.entity = ".$conf->entity; + $sql.= " AND a.entity IN (".getEntity('adherent', 1).")"; $resql=$this->db->query($sql); if ($resql) @@ -1741,7 +1741,7 @@ function load_board($user) $sql = "SELECT a.rowid, a.datefin"; $sql.= " FROM ".MAIN_DB_PREFIX."adherent as a"; $sql.= " WHERE a.statut = 1"; - $sql.= " AND a.entity = ".$conf->entity; + $sql.= " AND a.entity IN (".getEntity('adherent', 1).")"; $sql.= " AND (a.datefin IS NULL or a.datefin < '".$this->db->idate($now)."')"; $resql=$this->db->query($sql); diff --git a/htdocs/adherents/class/adherentstats.class.php b/htdocs/adherents/class/adherentstats.class.php index e64a67d445d47..d3f72d2ea5dc7 100644 --- a/htdocs/adherents/class/adherentstats.class.php +++ b/htdocs/adherents/class/adherentstats.class.php @@ -65,7 +65,7 @@ function __construct($db, $socid=0, $userid=0) $this->field='cotisation'; $this->where.= " m.statut != 0"; - $this->where.= " AND p.fk_adherent = m.rowid AND m.entity = ".$conf->entity; + $this->where.= " AND p.fk_adherent = m.rowid AND m.entity IN (".getEntity('adherent', 1).")"; //if (!$user->rights->societe->client->voir && !$user->societe_id) $this->where .= " AND p.fk_soc = sc.fk_soc AND sc.fk_user = " .$user->id; if($this->memberid) { diff --git a/htdocs/adherents/list.php b/htdocs/adherents/list.php index a94f6750f5549..38ffeae299322 100644 --- a/htdocs/adherents/list.php +++ b/htdocs/adherents/list.php @@ -99,7 +99,7 @@ if ($catid == -2) $sql.= " AND cm.fk_categorie IS NULL"; if ($search_categ > 0) $sql.= " AND cm.fk_categorie = ".$db->escape($search_categ); if ($search_categ == -2) $sql.= " AND cm.fk_categorie IS NULL"; -$sql.= " AND d.entity = ".$conf->entity; +$sql.= " AND d.entity IN (".getEntity('adherent', 1).")"; if ($sall) { // For natural search diff --git a/htdocs/admin/tools/listevents.php b/htdocs/admin/tools/listevents.php index 309bf1d935ee5..373b46c606247 100644 --- a/htdocs/admin/tools/listevents.php +++ b/htdocs/admin/tools/listevents.php @@ -123,7 +123,7 @@ $sql.= " u.login"; $sql.= " FROM ".MAIN_DB_PREFIX."events as e"; $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."user as u ON u.rowid = e.fk_user"; -$sql.= " WHERE e.entity = ".$conf->entity; +$sql.= " WHERE e.entity IN (".getEntity('actioncomm', 1).")"; if ($search_code) { $usefilter++; $sql.=" AND e.type LIKE '%".$db->escape($search_code)."%'"; } if ($search_ip) { $usefilter++; $sql.=" AND e.ip LIKE '%".$db->escape($search_ip)."%'"; } if ($search_user) { $usefilter++; $sql.=" AND u.login LIKE '%".$db->escape($search_user)."%'"; } diff --git a/htdocs/comm/action/class/actioncomm.class.php b/htdocs/comm/action/class/actioncomm.class.php index 543cf862d8fbf..3577edeb27de5 100644 --- a/htdocs/comm/action/class/actioncomm.class.php +++ b/htdocs/comm/action/class/actioncomm.class.php @@ -743,7 +743,7 @@ static function getActions($db, $socid=0, $fk_element=0, $elementtype='', $filte $sql = "SELECT a.id"; $sql.= " FROM ".MAIN_DB_PREFIX."actioncomm as a"; - $sql.= " WHERE a.entity = ".$conf->entity; + $sql.= " WHERE a.entity IN (".getEntity('actioncomm', 1).")"; if (! empty($socid)) $sql.= " AND a.fk_soc = ".$socid; if (! empty($elementtype)) { @@ -794,7 +794,7 @@ function load_board($user) if (! $user->rights->societe->client->voir && ! $user->societe_id) $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON a.fk_soc = sc.fk_soc"; $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON a.fk_soc = s.rowid"; $sql.= " WHERE a.percent >= 0 AND a.percent < 100"; - $sql.= " AND a.entity = ".$conf->entity; + $sql.= " AND a.entity IN (".getEntity('actioncomm', 1).")"; if (! $user->rights->societe->client->voir && ! $user->societe_id) $sql.= " AND (a.fk_soc IS NULL OR sc.fk_user = " .$user->id . ")"; if ($user->societe_id) $sql.=" AND a.fk_soc = ".$user->societe_id; if (! $user->rights->agenda->allactions->read) $sql.= " AND (a.fk_user_author = ".$user->id . " OR a.fk_user_action = ".$user->id . " OR a.fk_user_done = ".$user->id . ")"; @@ -1091,7 +1091,7 @@ function build_exportfile($format,$type,$cachedelay,$filename,$filters) // We must filter on assignement table if ($filters['logint'] || $filters['login']) $sql.=", ".MAIN_DB_PREFIX."actioncomm_resources as ar"; $sql.= " WHERE a.fk_action=c.id"; - $sql.= " AND a.entity = ".$conf->entity; + $sql.= " AND a.entity IN (".getEntity('actioncomm', 1).")"; foreach ($filters as $key => $value) { if ($key == 'notolderthan' && $value != '') $sql.=" AND a.datep >= '".$this->db->idate($now-($value*24*60*60))."'"; diff --git a/htdocs/comm/card.php b/htdocs/comm/card.php index 81e8b39696373..200c731d48a3a 100644 --- a/htdocs/comm/card.php +++ b/htdocs/comm/card.php @@ -684,7 +684,7 @@ $sql.= ', s.rowid as socid'; $sql.= " FROM ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."expedition as e"; $sql.= " WHERE e.fk_soc = s.rowid AND s.rowid = ".$object->id; - $sql.= " AND e.entity = ".$conf->entity; + $sql.= " AND e.entity IN (".getEntity('expedition', 1).")"; $sql.= ' GROUP BY e.rowid'; $sql.= ', e.ref'; $sql.= ', e.date_creation'; diff --git a/htdocs/comm/index.php b/htdocs/comm/index.php index 3924774f7fc0f..acf6ee95f8a7f 100644 --- a/htdocs/comm/index.php +++ b/htdocs/comm/index.php @@ -164,7 +164,7 @@ if (! $user->rights->societe->client->voir && ! $socid) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; $sql.= " WHERE p.fk_statut = 0"; $sql.= " AND p.fk_soc = s.rowid"; - $sql.= " AND p.entity = ".$conf->entity; + $sql.= " AND p.entity IN (".getEntity('propal', 1).")"; 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; @@ -235,7 +235,7 @@ if (! $user->rights->societe->client->voir && ! $socid) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; $sql.= " WHERE c.fk_soc = s.rowid"; $sql.= " AND c.fk_statut = 0"; - $sql.= " AND c.entity = ".$conf->entity; + $sql.= " AND c.entity IN (".getEntity('commande', 1).")"; if (! $user->rights->societe->client->voir && ! $socid) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id; if ($socid) $sql.= " AND c.fk_soc = ".$socid; @@ -440,7 +440,7 @@ $sql.= ", ".MAIN_DB_PREFIX."product as p"; if (! $user->rights->societe->client->voir && ! $socid) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; $sql.= " WHERE c.fk_soc = s.rowid"; - $sql.= " AND c.entity = ".$conf->entity; + $sql.= " AND c.entity IN (".getEntity('contrat', 1).")"; $sql.= " AND c.fk_product = p.rowid"; 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; @@ -496,7 +496,7 @@ $sql.= ", ".MAIN_DB_PREFIX."propal as p"; if (! $user->rights->societe->client->voir && ! $socid) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; $sql.= " WHERE p.fk_soc = s.rowid"; - $sql.= " AND p.entity = ".$conf->entity; + $sql.= " AND p.entity IN (".getEntity('propal', 1).")"; $sql.= " AND p.fk_statut = 1"; 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; @@ -592,7 +592,7 @@ $sql.= ", ".MAIN_DB_PREFIX."commande as c"; if (! $user->rights->societe->client->voir && ! $socid) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; $sql.= " WHERE c.fk_soc = s.rowid"; - $sql.= " AND c.entity = ".$conf->entity; + $sql.= " AND c.entity IN (".getEntity('commande', 1).")"; $sql.= " AND c.fk_statut = 1"; 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; diff --git a/htdocs/comm/propal.php b/htdocs/comm/propal.php index c5cd570c24174..915c4766b98ad 100644 --- a/htdocs/comm/propal.php +++ b/htdocs/comm/propal.php @@ -1554,7 +1554,7 @@ $sql .= " FROM " . MAIN_DB_PREFIX . "propal p"; $sql .= ", " . MAIN_DB_PREFIX . "societe s"; $sql .= " WHERE s.rowid = p.fk_soc"; - $sql .= " AND p.entity = " . $conf->entity; + $sql .= " AND p.entity IN (".getEntity('propal', 1).")"; $sql .= " AND p.fk_statut <> 0"; $sql .= " ORDER BY Id"; diff --git a/htdocs/comm/propal/class/propal.class.php b/htdocs/comm/propal/class/propal.class.php index e7a7421e6eaee..2a02e54298af7 100644 --- a/htdocs/comm/propal/class/propal.class.php +++ b/htdocs/comm/propal/class/propal.class.php @@ -1194,7 +1194,7 @@ function fetch($rowid,$ref='') $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_input_reason as dr ON p.fk_input_reason = dr.rowid'; $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_incoterms as i ON p.fk_incoterms = i.rowid'; $sql.= " WHERE p.fk_statut = c.id"; - $sql.= " AND p.entity = ".$conf->entity; + $sql.= " AND p.entity IN (".getEntity('propal', 1).")"; if ($ref) $sql.= " AND p.ref='".$ref."'"; else $sql.= " AND p.rowid=".$rowid; @@ -2011,7 +2011,7 @@ function liste_array($shortlist=0, $draft=0, $notcurrentuser=0, $socid=0, $limit if (! $user->rights->societe->client->voir && ! $socid) $sql .= ", sc.fk_soc, sc.fk_user"; $sql.= " FROM ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."propal as p, ".MAIN_DB_PREFIX."c_propalst as c"; if (! $user->rights->societe->client->voir && ! $socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; - $sql.= " WHERE p.entity = ".$conf->entity; + $sql.= " WHERE p.entity IN (".getEntity('propal', 1).")"; $sql.= " AND p.fk_soc = s.rowid"; $sql.= " AND p.fk_statut = c.id"; if (! $user->rights->societe->client->voir && ! $socid) //restriction @@ -2466,7 +2466,7 @@ function load_board($user,$mode) $sql.= " WHERE sc.fk_user = " .$user->id; $clause = " AND"; } - $sql.= $clause." p.entity = ".$conf->entity; + $sql.= $clause." p.entity IN (".getEntity('propal', 1).")"; if ($mode == 'opened') $sql.= " AND p.fk_statut = ".self::STATUS_VALIDATED; if ($mode == 'signed') $sql.= " AND p.fk_statut = ".self::STATUS_SIGNED; if ($user->societe_id) $sql.= " AND p.fk_soc = ".$user->societe_id; @@ -2629,7 +2629,7 @@ function load_state_board() $sql.= " WHERE sc.fk_user = " .$user->id; $clause = "AND"; } - $sql.= " ".$clause." p.entity = ".$conf->entity; + $sql.= " ".$clause." p.entity IN (".getEntity('propal', 1).")"; $resql=$this->db->query($sql); if ($resql) diff --git a/htdocs/comm/propal/class/propalestats.class.php b/htdocs/comm/propal/class/propalestats.class.php index 97256c840b147..05ec9c19629a7 100644 --- a/htdocs/comm/propal/class/propalestats.class.php +++ b/htdocs/comm/propal/class/propalestats.class.php @@ -69,7 +69,7 @@ function __construct($db, $socid=0, $userid=0) $this->where.= " p.fk_statut > 0"; //$this->where.= " AND p.fk_soc = s.rowid AND p.entity = ".$conf->entity; - $this->where.= " AND p.entity = ".$conf->entity; + $this->where.= " AND p.entity IN (".getEntity('propal', 1).")"; if (!$user->rights->societe->client->voir && !$this->socid) $this->where .= " AND p.fk_soc = sc.fk_soc AND sc.fk_user = " .$user->id; if($this->socid) { diff --git a/htdocs/comm/propal/index.php b/htdocs/comm/propal/index.php index a0e8a3409ab02..af815ba0473d9 100644 --- a/htdocs/comm/propal/index.php +++ b/htdocs/comm/propal/index.php @@ -83,7 +83,7 @@ $sql.= ", ".MAIN_DB_PREFIX."propal as p"; if (!$user->rights->societe->client->voir && !$socid) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; $sql.= " WHERE p.fk_soc = s.rowid"; -$sql.= " AND p.entity = ".$conf->entity; +$sql.= " AND p.entity IN (".getEntity('propal', 1).")"; if ($user->societe_id) $sql.=' AND p.fk_soc = '.$user->societe_id; if (!$user->rights->societe->client->voir && !$socid) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id; $sql.= " AND p.fk_statut IN (0,1,2,3,4)"; @@ -159,7 +159,7 @@ $sql.= ", ".MAIN_DB_PREFIX."societe as s"; if (!$user->rights->societe->client->voir && !$socid) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; $sql.= " WHERE c.fk_soc = s.rowid"; - $sql.= " AND c.entity = ".$conf->entity; + $sql.= " AND c.entity IN (".getEntity('propal', 1).")"; $sql.= " AND c.fk_statut = 0"; if ($socid) $sql.= " AND c.fk_soc = ".$socid; if (!$user->rights->societe->client->voir && !$socid) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id; @@ -217,7 +217,7 @@ $sql.= ", ".MAIN_DB_PREFIX."societe as s"; if (!$user->rights->societe->client->voir && !$socid) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; $sql.= " WHERE c.fk_soc = s.rowid"; -$sql.= " AND c.entity = ".$conf->entity; +$sql.= " AND c.entity IN (".getEntity('propal', 1).")"; //$sql.= " AND c.fk_statut > 2"; if ($socid) $sql .= " AND c.fk_soc = ".$socid; if (!$user->rights->societe->client->voir && !$socid) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id; @@ -296,7 +296,7 @@ $sql.= ", ".MAIN_DB_PREFIX."propal as p"; if (!$user->rights->societe->client->voir && !$socid) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; $sql.= " WHERE p.fk_soc = s.rowid"; - $sql.= " AND p.entity = ".$conf->entity; + $sql.= " AND p.entity IN (".getEntity('propal', 1).")"; $sql.= " AND p.fk_statut = 1"; 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; diff --git a/htdocs/comm/propal/list.php b/htdocs/comm/propal/list.php index c22b1952f9b11..9fbdb2ffd7ef5 100644 --- a/htdocs/comm/propal/list.php +++ b/htdocs/comm/propal/list.php @@ -162,7 +162,7 @@ $sql.=", ".MAIN_DB_PREFIX."c_type_contact as tc"; } $sql.= ' WHERE p.fk_soc = s.rowid'; -$sql.= ' AND p.entity = '.$conf->entity; +$sql.= ' AND p.entity IN ('.getEntity('propal', 1).')'; if (! $user->rights->societe->client->voir && ! $socid) //restriction { $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id; diff --git a/htdocs/comm/prospect/index.php b/htdocs/comm/prospect/index.php index b27560442101d..0d72eac46e3df 100644 --- a/htdocs/comm/prospect/index.php +++ b/htdocs/comm/prospect/index.php @@ -120,7 +120,7 @@ if (! $user->rights->societe->client->voir && ! $socid) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; $sql.= " WHERE p.fk_statut = 0"; $sql.= " AND p.fk_soc = s.rowid"; - $sql.= " AND p.entity = ".$conf->entity; + $sql.= " AND p.entity IN (".getEntity('propal', 1).")"; if (! $user->rights->societe->client->voir && ! $socid) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id; $resql=$db->query($sql); @@ -183,7 +183,7 @@ $sql.= " WHERE p.fk_soc = s.rowid"; $sql.= " AND p.fk_statut = c.id"; $sql.= " AND p.fk_statut = 1"; - $sql.= " AND p.entity = ".$conf->entity; + $sql.= " AND p.entity IN (".getEntity('propal', 1).")"; 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; $sql.= " ORDER BY p.rowid DESC"; diff --git a/htdocs/commande/class/commande.class.php b/htdocs/commande/class/commande.class.php index eba8a557d25d7..ed5de40dbab55 100644 --- a/htdocs/commande/class/commande.class.php +++ b/htdocs/commande/class/commande.class.php @@ -1466,7 +1466,7 @@ function fetch($id, $ref='', $ref_ext='', $ref_int='') $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_availability as ca ON (c.fk_availability = ca.rowid)'; $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_input_reason as dr ON (c.fk_input_reason = ca.rowid)'; $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_incoterms as i ON c.fk_incoterms = i.rowid'; - $sql.= " WHERE c.entity = ".$conf->entity; + $sql.= " WHERE c.entity IN (".getEntity('commande', 1).")"; if ($id) $sql.= " AND c.rowid=".$id; if ($ref) $sql.= " AND c.ref='".$this->db->escape($ref)."'"; if ($ref_ext) $sql.= " AND c.ref_ext='".$this->db->escape($ref_ext)."'"; @@ -2185,7 +2185,7 @@ function liste_array($shortlist=0, $draft=0, $excluser='', $socid=0, $limit=0, $ if (! $user->rights->societe->client->voir && ! $socid) $sql .= ", sc.fk_soc, sc.fk_user"; $sql.= " FROM ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."commande as c"; if (! $user->rights->societe->client->voir && ! $socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; - $sql.= " WHERE c.entity = ".$conf->entity; + $sql.= " WHERE c.entity IN (".getEntity('commande', 1).")"; $sql.= " AND c.fk_soc = s.rowid"; if (! $user->rights->societe->client->voir && ! $socid) //restriction { @@ -2824,7 +2824,7 @@ function load_board($user) $sql.= " WHERE sc.fk_user = " .$user->id; $clause = " AND"; } - $sql.= $clause." c.entity = ".$conf->entity; + $sql.= $clause." c.entity IN (".getEntity('commande', 1).")"; //$sql.= " AND c.fk_statut IN (1,2,3) AND c.facture = 0"; $sql.= " AND ((c.fk_statut IN (".self::STATUS_VALIDATED.",".self::STATUS_ACCEPTED.")) OR (c.fk_statut = ".self::STATUS_CLOSED." AND c.facture = 0))"; // If status is 2 and facture=1, it must be selected if ($user->societe_id) $sql.=" AND c.fk_soc = ".$user->societe_id; @@ -3161,7 +3161,7 @@ function load_state_board() $sql.= " WHERE sc.fk_user = " .$user->id; $clause = "AND"; } - $sql.= " ".$clause." co.entity = ".$conf->entity; + $sql.= " ".$clause." co.entity IN (".getEntity('commande', 1).")"; $resql=$this->db->query($sql); if ($resql) diff --git a/htdocs/commande/customer.php b/htdocs/commande/customer.php index e4662cc7ee8e9..391962c98cb1c 100644 --- a/htdocs/commande/customer.php +++ b/htdocs/commande/customer.php @@ -73,7 +73,7 @@ $sql.= " FROM ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."c_stcomm as st, ".MAIN_DB_PREFIX."commande as c"; if (!$user->rights->societe->client->voir && !$socid) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; $sql.= " WHERE s.fk_stcomm = st.id AND c.fk_soc = s.rowid"; -$sql.= " AND s.entity = ".$conf->entity; +$sql.= " AND s.entity IN (".getEntity('societe', 1).")"; if (!$user->rights->societe->client->voir && !$socid) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id; if (dol_strlen($stcomm)) { diff --git a/htdocs/commande/index.php b/htdocs/commande/index.php index 40b39ccb66689..30eb31c82ba66 100644 --- a/htdocs/commande/index.php +++ b/htdocs/commande/index.php @@ -82,7 +82,7 @@ $sql.= ", ".MAIN_DB_PREFIX."commande as c"; if (! $user->rights->societe->client->voir && ! $socid) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; $sql.= " WHERE c.fk_soc = s.rowid"; -$sql.= " AND c.entity = ".$conf->entity; +$sql.= " AND c.entity IN (".getEntity('societe', 1).")"; if ($user->societe_id) $sql.=' AND c.fk_soc = '.$user->societe_id; if (! $user->rights->societe->client->voir && ! $socid) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id; $sql.= " GROUP BY c.fk_statut, c.facture"; @@ -171,7 +171,7 @@ $sql.= ", ".MAIN_DB_PREFIX."societe as s"; if (!$user->rights->societe->client->voir && !$socid) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; $sql.= " WHERE c.fk_soc = s.rowid"; - $sql.= " AND c.entity = ".$conf->entity; + $sql.= " AND c.entity IN (".getEntity('commande', 1).")"; $sql.= " AND c.fk_statut = 0"; if ($socid) $sql.= " AND c.fk_soc = ".$socid; if (!$user->rights->societe->client->voir && !$socid) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id; @@ -220,7 +220,7 @@ $sql.= " ".MAIN_DB_PREFIX."societe as s"; if (!$user->rights->societe->client->voir && !$socid) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; $sql.= " WHERE c.fk_soc = s.rowid"; -$sql.= " AND c.entity = ".$conf->entity; +$sql.= " AND c.entity IN (".getEntity('commande', 1).")"; //$sql.= " AND c.fk_statut > 2"; if ($socid) $sql .= " AND c.fk_soc = ".$socid; if (!$user->rights->societe->client->voir && !$socid) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id; @@ -290,7 +290,7 @@ $sql.= ", ".MAIN_DB_PREFIX."societe as s"; if (!$user->rights->societe->client->voir && !$socid) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; $sql.= " WHERE c.fk_soc = s.rowid"; - $sql.= " AND c.entity = ".$conf->entity; + $sql.= " AND c.entity IN (".getEntity('commande', 1).")"; $sql.= " AND c.fk_statut = 1"; if ($socid) $sql.= " AND c.fk_soc = ".$socid; if (!$user->rights->societe->client->voir && !$socid) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id; @@ -361,7 +361,7 @@ $sql.= ", ".MAIN_DB_PREFIX."societe as s"; if (!$user->rights->societe->client->voir && !$socid) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; $sql.= " WHERE c.fk_soc = s.rowid"; - $sql.= " AND c.entity = ".$conf->entity; + $sql.= " AND c.entity IN (".getEntity('commande', 1).")"; $sql.= " AND c.fk_statut = 2 "; if ($socid) $sql.= " AND c.fk_soc = ".$socid; if (!$user->rights->societe->client->voir && !$socid) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id; diff --git a/htdocs/commande/list.php b/htdocs/commande/list.php index 5164b30eed739..351a4171dd6f9 100644 --- a/htdocs/commande/list.php +++ b/htdocs/commande/list.php @@ -127,7 +127,7 @@ $sql.=", ".MAIN_DB_PREFIX."c_type_contact as tc"; } $sql.= ' WHERE c.fk_soc = s.rowid'; -$sql.= ' AND c.entity = '.$conf->entity; +$sql.= ' AND c.entity IN ('.getEntity('commande', 1).')'; if ($socid) $sql.= ' AND s.rowid = '.$socid; if (!$user->rights->societe->client->voir && !$socid) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id; if ($search_ref) { diff --git a/htdocs/commande/orderstoinvoice.php b/htdocs/commande/orderstoinvoice.php index e6a40e1b027fa..064e56f1b4b64 100644 --- a/htdocs/commande/orderstoinvoice.php +++ b/htdocs/commande/orderstoinvoice.php @@ -526,7 +526,7 @@ $sql.= ' FROM '.MAIN_DB_PREFIX.'societe as s'; $sql.= ', '.MAIN_DB_PREFIX.'commande as c'; if (!$user->rights->societe->client->voir && !$socid) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; - $sql.= ' WHERE c.entity = '.$conf->entity; + $sql.= ' WHERE c.entity IN ('.getEntity('commande', 1).')'; $sql.= ' AND c.fk_soc = s.rowid'; // Show orders with status validated, shipping started and delivered (well any order we can bill) diff --git a/htdocs/compta/bank/account.php b/htdocs/compta/bank/account.php index ce2bbc5381ea9..e923f3b3fa10c 100644 --- a/htdocs/compta/bank/account.php +++ b/htdocs/compta/bank/account.php @@ -263,7 +263,7 @@ } $sql.= " WHERE b.fk_account = ".$object->id; $sql.= " AND b.fk_account = ba.rowid"; - $sql.= " AND ba.entity = ".$conf->entity; + $sql.= " AND ba.entity IN (".getEntity('bank_account', 1).")"; $sql.= $sql_rech; dol_syslog("account.php count transactions -", LOG_DEBUG); @@ -511,7 +511,7 @@ } $sql.= " WHERE b.fk_account=".$object->id; $sql.= " AND b.fk_account = ba.rowid"; - $sql.= " AND ba.entity = ".$conf->entity; + $sql.= " AND ba.entity IN (".getEntity('bank_account', 1).")"; $sql.= $sql_rech; $sql.= $db->order("b.datev, b.datec", "ASC"); // We add date of creation to have correct order when everything is done the same day $sql.= $db->plimit($limitsql, 0); diff --git a/htdocs/compta/bank/annuel.php b/htdocs/compta/bank/annuel.php index 0a9cfc79b10c5..6dfbea2979130 100644 --- a/htdocs/compta/bank/annuel.php +++ b/htdocs/compta/bank/annuel.php @@ -80,7 +80,7 @@ $sql.= " FROM ".MAIN_DB_PREFIX."bank as b"; $sql.= ", ".MAIN_DB_PREFIX."bank_account as ba"; $sql.= " WHERE b.fk_account = ba.rowid"; -$sql.= " AND ba.entity = ".$conf->entity; +$sql.= " AND ba.entity IN (".getEntity('bank_account', 1).")"; $sql.= " AND b.amount >= 0"; if (! empty($id)) $sql .= " AND b.fk_account IN (".$db->escape($id).")"; @@ -108,7 +108,7 @@ $sql.= " FROM ".MAIN_DB_PREFIX."bank as b"; $sql.= ", ".MAIN_DB_PREFIX."bank_account as ba"; $sql.= " WHERE b.fk_account = ba.rowid"; -$sql.= " AND ba.entity = ".$conf->entity; +$sql.= " AND ba.entity IN (".getEntity('bank_account', 1).")"; $sql.= " AND b.amount <= 0"; if (! empty($id)) $sql .= " AND b.fk_account IN (".$db->escape($id).")"; @@ -261,7 +261,7 @@ $sql.= " FROM ".MAIN_DB_PREFIX."bank as b"; $sql.= ", ".MAIN_DB_PREFIX."bank_account as ba"; $sql.= " WHERE b.fk_account = ba.rowid"; -$sql.= " AND ba.entity = ".$conf->entity; +$sql.= " AND ba.entity IN (".getEntity('bank_account', 1).")"; if (! empty($id)) $sql.= " AND b.fk_account IN (".$db->escape($id).")"; @@ -302,7 +302,7 @@ $sql.= " FROM ".MAIN_DB_PREFIX."bank as b"; $sql.= ", ".MAIN_DB_PREFIX."bank_account as ba"; $sql.= " WHERE b.fk_account = ba.rowid"; - $sql.= " AND ba.entity = ".$conf->entity; + $sql.= " AND ba.entity IN (".getEntity('bank_account', 1).")"; if ($id && $_GET["option"]!='all') $sql.= " AND b.fk_account IN (".$id.")"; $resql = $db->query($sql); @@ -333,7 +333,7 @@ $sql.= " FROM ".MAIN_DB_PREFIX."bank as b"; $sql.= ", ".MAIN_DB_PREFIX."bank_account as ba"; $sql.= " WHERE b.fk_account = ba.rowid"; - $sql.= " AND ba.entity = ".$conf->entity; + $sql.= " AND ba.entity IN (".getEntity('bank_account', 1).")"; $sql.= " AND b.datev >= '".($year-$annee)."-01-01 00:00:00'"; $sql.= " AND b.datev <= '".($year-$annee)."-12-31 23:59:59'"; $sql.= " AND b.amount > 0"; @@ -422,7 +422,7 @@ $sql.= " FROM ".MAIN_DB_PREFIX."bank as b"; $sql.= ", ".MAIN_DB_PREFIX."bank_account as ba"; $sql.= " WHERE b.fk_account = ba.rowid"; - $sql.= " AND ba.entity = ".$conf->entity; + $sql.= " AND ba.entity IN (".getEntity('bank_account', 1).")"; $sql.= " AND b.datev >= '".($year-$annee)."-01-01 00:00:00'"; $sql.= " AND b.datev <= '".($year-$annee)."-12-31 23:59:59'"; $sql.= " AND b.amount < 0"; diff --git a/htdocs/compta/bank/class/account.class.php b/htdocs/compta/bank/class/account.class.php index b6215165d35fe..c8badb1a880d6 100644 --- a/htdocs/compta/bank/class/account.class.php +++ b/htdocs/compta/bank/class/account.class.php @@ -930,7 +930,7 @@ function load_board($user,$filteraccountid=0) $sql.= " ".MAIN_DB_PREFIX."bank_account as ba"; $sql.= " WHERE b.rappro=0"; $sql.= " AND b.fk_account = ba.rowid"; - $sql.= " AND ba.entity = ".$conf->entity; + $sql.= " AND ba.entity IN (".getEntity('bank_account', 1).")"; $sql.= " AND (ba.rappro = 1 AND ba.courant != 2)"; // Compte rapprochable if ($filteraccountid) $sql.=" AND ba.rowid = ".$filteraccountid; @@ -1191,7 +1191,7 @@ function fetch($rowid,$ref='',$num='') $sql.= " FROM ".MAIN_DB_PREFIX."bank as b,"; $sql.= " ".MAIN_DB_PREFIX."bank_account as ba"; $sql.= " WHERE b.fk_account = ba.rowid"; - $sql.= " AND ba.entity = ".$conf->entity; + $sql.= " AND ba.entity IN (".getEntity('bank_account', 1).")"; if ($num) $sql.= " AND b.num_chq='".$this->db->escape($num)."'"; else if ($ref) $sql.= " AND b.rowid='".$this->db->escape($ref)."'"; else $sql.= " AND b.rowid=".$rowid; diff --git a/htdocs/compta/bank/graph.php b/htdocs/compta/bank/graph.php index 60592085b35fe..d87d95f6026e8 100644 --- a/htdocs/compta/bank/graph.php +++ b/htdocs/compta/bank/graph.php @@ -90,7 +90,7 @@ $sql.= " FROM ".MAIN_DB_PREFIX."bank as b"; $sql.= ", ".MAIN_DB_PREFIX."bank_account as ba"; $sql.= " WHERE b.fk_account = ba.rowid"; - $sql.= " AND ba.entity = ".$conf->entity; + $sql.= " AND ba.entity IN (".getEntity('bank_account', 1).")"; if ($account && $_GET["option"]!='all') $sql.= " AND b.fk_account IN (".$account.")"; $resql = $db->query($sql); @@ -129,7 +129,7 @@ $sql.= " FROM ".MAIN_DB_PREFIX."bank as b"; $sql.= ", ".MAIN_DB_PREFIX."bank_account as ba"; $sql.= " WHERE b.fk_account = ba.rowid"; - $sql.= " AND ba.entity = ".$conf->entity; + $sql.= " AND ba.entity IN (".getEntity('bank_account', 1).")"; $sql.= " AND b.datev >= '".$year."-".$month."-01 00:00:00'"; $sql.= " AND b.datev < '".$yearnext."-".$monthnext."-01 00:00:00'"; if ($account && $_GET["option"]!='all') $sql.= " AND b.fk_account IN (".$account.")"; @@ -160,7 +160,7 @@ $sql.= " FROM ".MAIN_DB_PREFIX."bank as b"; $sql.= ", ".MAIN_DB_PREFIX."bank_account as ba"; $sql.= " WHERE b.fk_account = ba.rowid"; - $sql.= " AND ba.entity = ".$conf->entity; + $sql.= " AND ba.entity IN (".getEntity('bank_account', 1).")"; $sql.= " AND b.datev < '".$year."-".sprintf("%02s",$month)."-01'"; if ($account && $_GET["option"]!='all') $sql.= " AND b.fk_account IN (".$account.")"; @@ -272,7 +272,7 @@ $sql.= " FROM ".MAIN_DB_PREFIX."bank as b"; $sql.= ", ".MAIN_DB_PREFIX."bank_account as ba"; $sql.= " WHERE b.fk_account = ba.rowid"; - $sql.= " AND ba.entity = ".$conf->entity; + $sql.= " AND ba.entity IN (".getEntity('bank_account', 1).")"; $sql.= " AND b.datev >= '".$year."-01-01 00:00:00'"; $sql.= " AND b.datev <= '".$year."-12-31 23:59:59'"; if ($account && $_GET["option"]!='all') $sql.= " AND b.fk_account IN (".$account.")"; @@ -303,7 +303,7 @@ $sql.= " FROM ".MAIN_DB_PREFIX."bank as b"; $sql.= ", ".MAIN_DB_PREFIX."bank_account as ba"; $sql.= " WHERE b.fk_account = ba.rowid"; - $sql.= " AND ba.entity = ".$conf->entity; + $sql.= " AND ba.entity IN (".getEntity('bank_account', 1).")"; $sql.= " AND b.datev < '".$year."-01-01'"; if ($account && $_GET["option"]!='all') $sql.= " AND b.fk_account IN (".$account.")"; @@ -411,7 +411,7 @@ $sql.= " FROM ".MAIN_DB_PREFIX."bank as b"; $sql.= ", ".MAIN_DB_PREFIX."bank_account as ba"; $sql.= " WHERE b.fk_account = ba.rowid"; - $sql.= " AND ba.entity = ".$conf->entity; + $sql.= " AND ba.entity IN (".getEntity('bank_account', 1).")"; if ($account && $_GET["option"]!='all') $sql.= " AND b.fk_account IN (".$account.")"; $sql.= " GROUP BY date_format(b.datev,'%Y%m%d')"; @@ -534,7 +534,7 @@ $sql .= " FROM ".MAIN_DB_PREFIX."bank as b"; $sql.= ", ".MAIN_DB_PREFIX."bank_account as ba"; $sql.= " WHERE b.fk_account = ba.rowid"; - $sql.= " AND ba.entity = ".$conf->entity; + $sql.= " AND ba.entity IN (".getEntity('bank_account', 1).")"; $sql.= " AND b.datev >= '".$year."-".$month."-01 00:00:00'"; $sql.= " AND b.datev < '".$yearnext."-".$monthnext."-01 00:00:00'"; $sql.= " AND b.amount > 0"; @@ -572,7 +572,7 @@ $sql .= " FROM ".MAIN_DB_PREFIX."bank as b"; $sql.= ", ".MAIN_DB_PREFIX."bank_account as ba"; $sql.= " WHERE b.fk_account = ba.rowid"; - $sql.= " AND ba.entity = ".$conf->entity; + $sql.= " AND ba.entity IN (".getEntity('bank_account', 1).")"; $sql.= " AND b.datev >= '".$year."-".$month."-01 00:00:00'"; $sql.= " AND b.datev < '".$yearnext."-".$monthnext."-01 00:00:00'"; $sql.= " AND b.amount < 0"; @@ -652,7 +652,7 @@ $sql.= " FROM ".MAIN_DB_PREFIX."bank as b"; $sql.= ", ".MAIN_DB_PREFIX."bank_account as ba"; $sql.= " WHERE b.fk_account = ba.rowid"; - $sql.= " AND ba.entity = ".$conf->entity; + $sql.= " AND ba.entity IN (".getEntity('bank_account', 1).")"; $sql.= " AND b.datev >= '".$year."-01-01 00:00:00'"; $sql.= " AND b.datev <= '".$year."-12-31 23:59:59'"; $sql.= " AND b.amount > 0"; @@ -681,7 +681,7 @@ $sql.= " FROM ".MAIN_DB_PREFIX."bank as b"; $sql.= ", ".MAIN_DB_PREFIX."bank_account as ba"; $sql.= " WHERE b.fk_account = ba.rowid"; - $sql.= " AND ba.entity = ".$conf->entity; + $sql.= " AND ba.entity IN (".getEntity('bank_account', 1).")"; $sql.= " AND b.datev >= '".$year."-01-01 00:00:00'"; $sql.= " AND b.datev <= '".$year."-12-31 23:59:59'"; $sql.= " AND b.amount < 0"; diff --git a/htdocs/compta/bank/search.php b/htdocs/compta/bank/search.php index 63afe63c03ce5..9c0205c62b3d2 100644 --- a/htdocs/compta/bank/search.php +++ b/htdocs/compta/bank/search.php @@ -110,7 +110,7 @@ $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."bank_url as bu ON bu.fk_bank = b.rowid AND type = 'company'"; $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON bu.url_id = s.rowid"; $sql.= " WHERE b.fk_account = ba.rowid"; -$sql.= " AND ba.entity = ".$conf->entity; +$sql.= " AND ba.entity IN (".getEntity('bank_account', 1).")"; if (GETPOST("req_nb")) { $sql.= " AND b.num_chq LIKE '%".$db->escape(GETPOST("req_nb"))."%'"; diff --git a/htdocs/compta/paiement/cheque/card.php b/htdocs/compta/paiement/cheque/card.php index 4df88871cb9eb..f2af107c7cdc9 100644 --- a/htdocs/compta/paiement/cheque/card.php +++ b/htdocs/compta/paiement/cheque/card.php @@ -376,7 +376,7 @@ $sql.= " ".MAIN_DB_PREFIX."bank_account as ba"; $sql.= " WHERE b.fk_type = 'CHQ'"; $sql.= " AND b.fk_account = ba.rowid"; - $sql.= " AND ba.entity = ".$conf->entity; + $sql.= " AND ba.entity IN (".getEntity('bank_account', 1).")"; $sql.= " AND b.fk_bordereau = 0"; $sql.= " AND b.amount > 0"; if ($filterdate) $sql.=" AND b.dateo = '".$db->idate($filterdate)."'"; @@ -599,7 +599,7 @@ $sql.= ", ".MAIN_DB_PREFIX."bank as b"; $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."paiement as p ON p.fk_bank = b.rowid"; $sql.= " WHERE ba.rowid = b.fk_account"; - $sql.= " AND ba.entity = ".$conf->entity; + $sql.= " AND ba.entity IN (".getEntity('bank_account', 1).")"; $sql.= " AND b.fk_type= 'CHQ'"; $sql.= " AND b.fk_bordereau = ".$object->id; $sql.= " ORDER BY $sortfield $sortorder"; diff --git a/htdocs/compta/paiement/cheque/class/remisecheque.class.php b/htdocs/compta/paiement/cheque/class/remisecheque.class.php index a3fb835f194ce..2dc1efe04b403 100644 --- a/htdocs/compta/paiement/cheque/class/remisecheque.class.php +++ b/htdocs/compta/paiement/cheque/class/remisecheque.class.php @@ -445,7 +445,7 @@ function load_board($user) $sql.= " FROM ".MAIN_DB_PREFIX."bank as b"; $sql.= ", ".MAIN_DB_PREFIX."bank_account as ba"; $sql.= " WHERE b.fk_account = ba.rowid"; - $sql.= " AND ba.entity = ".$conf->entity; + $sql.= " AND ba.entity IN (".getEntity('bank_account', 1).")"; $sql.= " AND b.fk_type = 'CHQ'"; $sql.= " AND b.fk_bordereau = 0"; $sql.= " AND b.amount > 0"; diff --git a/htdocs/compta/resultat/clientfourn.php b/htdocs/compta/resultat/clientfourn.php index a9e140303886c..65e6866befe3c 100644 --- a/htdocs/compta/resultat/clientfourn.php +++ b/htdocs/compta/resultat/clientfourn.php @@ -235,7 +235,7 @@ $sql.= " WHERE pf.rowid IS NULL"; $sql.= " AND p.fk_bank = b.rowid"; $sql.= " AND b.fk_account = ba.rowid"; - $sql.= " AND ba.entity = ".$conf->entity; + $sql.= " AND ba.entity IN (".getEntity('bank_account', 1).")"; if (! empty($date_start) && ! empty($date_end)) $sql.= " AND p.datep >= '".$db->idate($date_start)."' AND p.datep <= '".$db->idate($date_end)."'"; $sql.= " GROUP BY name, idp"; diff --git a/htdocs/compta/resultat/index.php b/htdocs/compta/resultat/index.php index 9f681d5b1ec9c..544c4d8a9e232 100644 --- a/htdocs/compta/resultat/index.php +++ b/htdocs/compta/resultat/index.php @@ -155,7 +155,7 @@ $sql.= " WHERE pf.rowid IS NULL"; $sql.= " AND p.fk_bank = b.rowid"; $sql.= " AND b.fk_account = ba.rowid"; - $sql.= " AND ba.entity = ".$conf->entity; + $sql.= " AND ba.entity IN (".getEntity('bank_account', 1).")"; $sql.= " GROUP BY dm"; $sql.= " ORDER BY dm"; diff --git a/htdocs/compta/stats/cabyuser.php b/htdocs/compta/stats/cabyuser.php index 066967cc2c3f9..385ac1f140c94 100644 --- a/htdocs/compta/stats/cabyuser.php +++ b/htdocs/compta/stats/cabyuser.php @@ -232,7 +232,7 @@ $sql.= " WHERE pf.rowid IS NULL"; $sql.= " AND p.fk_bank = b.rowid"; $sql.= " AND b.fk_account = ba.rowid"; - $sql.= " AND ba.entity = ".$conf->entity; + $sql.= " AND ba.entity IN (".getEntity('bank_account', 1).")"; if ($date_start && $date_end) { $sql.= " AND p.datep >= '".$db->idate($date_start)."' AND p.datep <= '".$db->idate($date_end)."'"; } diff --git a/htdocs/compta/stats/casoc.php b/htdocs/compta/stats/casoc.php index 0f352defc5e35..8131e4b534814 100644 --- a/htdocs/compta/stats/casoc.php +++ b/htdocs/compta/stats/casoc.php @@ -279,7 +279,7 @@ $sql.= " WHERE pf.rowid IS NULL"; $sql.= " AND p.fk_bank = b.rowid"; $sql.= " AND b.fk_account = ba.rowid"; - $sql.= " AND ba.entity = ".$conf->entity; + $sql.= " AND ba.entity IN (".getEntity('bank_account', 1).")"; if ($date_start && $date_end) $sql.= " AND p.datep >= '".$db->idate($date_start)."' AND p.datep <= '".$db->idate($date_end)."'"; $sql.= " GROUP BY socid, name"; $sql.= " ORDER BY name"; diff --git a/htdocs/compta/stats/index.php b/htdocs/compta/stats/index.php index a44cb4ed48e48..eb9a425c2afee 100644 --- a/htdocs/compta/stats/index.php +++ b/htdocs/compta/stats/index.php @@ -146,7 +146,7 @@ $sql.= " WHERE pf.rowid IS NULL"; $sql.= " AND p.fk_bank = b.rowid"; $sql.= " AND b.fk_account = ba.rowid"; - $sql.= " AND ba.entity = ".$conf->entity; + $sql.= " AND ba.entity IN (".getEntity('bank_account', 1).")"; $sql.= " GROUP BY dm"; $sql.= " ORDER BY dm"; diff --git a/htdocs/core/lib/sendings.lib.php b/htdocs/core/lib/sendings.lib.php index 5ce30be59a082..1c0c589870e1c 100644 --- a/htdocs/core/lib/sendings.lib.php +++ b/htdocs/core/lib/sendings.lib.php @@ -167,7 +167,7 @@ function show_list_sending_receive($origin,$origin_id,$filter='') $sql.= ", ".MAIN_DB_PREFIX.$origin."det as obj"; //if ($conf->livraison_bon->enabled) $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."livraison as l ON l.fk_expedition = e.rowid LEFT JOIN ".MAIN_DB_PREFIX."livraisondet as ld ON ld.fk_livraison = l.rowid AND obj.rowid = ld.fk_origin_line"; $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."product as p ON obj.fk_product = p.rowid"; - $sql.= " WHERE e.entity = ".$conf->entity; + $sql.= " WHERE e.entity IN (".getEntity('expedition', 1).")"; $sql.= " AND obj.fk_".$origin." = ".$origin_id; $sql.= " AND obj.rowid = ed.fk_origin_line"; $sql.= " AND ed.fk_expedition = e.rowid"; diff --git a/htdocs/expedition/class/expedition.class.php b/htdocs/expedition/class/expedition.class.php index 24ce24bae477e..58b6b5c65c248 100644 --- a/htdocs/expedition/class/expedition.class.php +++ b/htdocs/expedition/class/expedition.class.php @@ -438,7 +438,7 @@ function fetch($id, $ref='', $ref_ext='', $ref_int='') $sql.= " FROM ".MAIN_DB_PREFIX."expedition as e"; $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."element_element as el ON el.fk_target = e.rowid AND el.targettype = '".$this->element."'"; $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_incoterms as i ON e.fk_incoterms = i.rowid'; - $sql.= " WHERE e.entity = ".$conf->entity; + $sql.= " WHERE e.entity IN (".getEntity('expedition', 1).")"; if ($id) $sql.= " AND e.rowid=".$id; if ($ref) $sql.= " AND e.ref='".$this->db->escape($ref)."'"; if ($ref_ext) $sql.= " AND e.ref_ext='".$this->db->escape($ref_ext)."'"; diff --git a/htdocs/expedition/index.php b/htdocs/expedition/index.php index 2b41a939c7bf6..5ecd563a6136b 100644 --- a/htdocs/expedition/index.php +++ b/htdocs/expedition/index.php @@ -75,7 +75,7 @@ $clause = " AND "; } $sql.= $clause." e.fk_statut = 0"; -$sql.= " AND e.entity = ".$conf->entity; +$sql.= " AND e.entity IN (".getEntity('expedition', 1).")"; if ($socid) $sql.= " AND c.fk_soc = ".$socid; $resql=$db->query($sql); @@ -235,7 +235,7 @@ $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."commande as c ON el.fk_source = c.rowid AND el.sourcetype IN ('commande') AND el.targettype = 'shipping'"; $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON s.rowid = e.fk_soc"; if (! $user->rights->societe->client->voir && ! $socid) $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON e.fk_soc = sc.fk_soc"; -$sql.= " WHERE e.entity = ".$conf->entity; +$sql.= " WHERE e.entity IN (".getEntity('expedition', 1).")"; if (! $user->rights->societe->client->voir && ! $socid) $sql.= " AND sc.fk_user = " .$user->id; $sql.= " AND e.fk_statut = 1"; if ($socid) $sql.= " AND c.fk_soc = ".$socid; diff --git a/htdocs/expedition/list.php b/htdocs/expedition/list.php index 195687a4ab72f..94eac327fcdec 100644 --- a/htdocs/expedition/list.php +++ b/htdocs/expedition/list.php @@ -82,7 +82,7 @@ $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON s.rowid = e.fk_soc"; $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."element_element as ee ON e.rowid = ee.fk_source AND ee.sourcetype = 'shipping' AND ee.targettype = 'delivery'"; $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."livraison as l ON l.rowid = ee.fk_target"; -$sql.= " WHERE e.entity = ".$conf->entity; +$sql.= " WHERE e.entity IN (".getEntity('expedition', 1).")"; if (!$user->rights->societe->client->voir && !$socid) // Internal user with no permission to see all { $sql.= " AND e.fk_soc = sc.fk_soc"; diff --git a/htdocs/product/class/html.formproduct.class.php b/htdocs/product/class/html.formproduct.class.php index d67b575023bf3..4e2da460a74c8 100644 --- a/htdocs/product/class/html.formproduct.class.php +++ b/htdocs/product/class/html.formproduct.class.php @@ -72,7 +72,7 @@ function loadWarehouses($fk_product=0) $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."product_stock as ps on ps.fk_entrepot = e.rowid"; $sql.= " AND ps.fk_product = '".$fk_product."'"; } - $sql.= " WHERE e.entity = ".$conf->entity; + $sql.= " WHERE e.entity IN (".getEntity('stock', 1).")"; $sql.= " AND e.statut = 1"; $sql.= " ORDER BY e.label"; diff --git a/htdocs/product/class/product.class.php b/htdocs/product/class/product.class.php index 184560b7aad0c..e5e24dc2cf6b3 100755 --- a/htdocs/product/class/product.class.php +++ b/htdocs/product/class/product.class.php @@ -1770,7 +1770,7 @@ function load_stats_propale($socid=0) if (!$user->rights->societe->client->voir && !$socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; $sql.= " WHERE p.rowid = pd.fk_propal"; $sql.= " AND p.fk_soc = s.rowid"; - $sql.= " AND p.entity = ".$conf->entity; + $sql.= " AND p.entity IN (".getEntity('propal', 1).")"; $sql.= " AND pd.fk_product = ".$this->id; if (!$user->rights->societe->client->voir && !$socid) $sql .= " AND p.fk_soc = sc.fk_soc AND sc.fk_user = " .$user->id; //$sql.= " AND pr.fk_statut != 0"; @@ -1813,7 +1813,7 @@ function load_stats_commande($socid=0,$filtrestatut='') if (!$user->rights->societe->client->voir && !$socid) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; $sql.= " WHERE c.rowid = cd.fk_commande"; $sql.= " AND c.fk_soc = s.rowid"; - $sql.= " AND c.entity = ".$conf->entity; + $sql.= " AND c.entity IN (".getEntity('commande', 1).")"; $sql.= " AND cd.fk_product = ".$this->id; if (!$user->rights->societe->client->voir && !$socid) $sql.= " AND c.fk_soc = sc.fk_soc AND sc.fk_user = " .$user->id; if ($socid > 0) $sql.= " AND c.fk_soc = ".$socid; @@ -1855,7 +1855,7 @@ function load_stats_commande_fournisseur($socid=0,$filtrestatut='') if (!$user->rights->societe->client->voir && !$socid) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; $sql.= " WHERE c.rowid = cd.fk_commande"; $sql.= " AND c.fk_soc = s.rowid"; - $sql.= " AND c.entity = ".$conf->entity; + $sql.= " AND c.entity IN (".getEntity('commande_fourniseur', 1).")"; $sql.= " AND cd.fk_product = ".$this->id; if (!$user->rights->societe->client->voir && !$socid) $sql.= " AND c.fk_soc = sc.fk_soc AND sc.fk_user = " .$user->id; if ($socid > 0) $sql.= " AND c.fk_soc = ".$socid; @@ -1900,7 +1900,7 @@ function load_stats_sending($socid=0,$filtrestatut='') $sql.= " WHERE e.rowid = ed.fk_expedition"; $sql.= " AND c.rowid = cd.fk_commande"; $sql.= " AND e.fk_soc = s.rowid"; - $sql.= " AND e.entity = ".$conf->entity; + $sql.= " AND e.entity IN (".getEntity('expedition', 1).")"; $sql.= " AND ed.fk_origin_line = cd.rowid"; $sql.= " AND cd.fk_product = ".$this->id; if (!$user->rights->societe->client->voir && !$socid) $sql.= " AND e.fk_soc = sc.fk_soc AND sc.fk_user = " .$user->id; @@ -1943,7 +1943,7 @@ function load_stats_reception($socid=0,$filtrestatut='') if (!$user->rights->societe->client->voir && !$socid) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; $sql.= " WHERE cf.rowid = fd.fk_commande"; $sql.= " AND cf.fk_soc = s.rowid"; - $sql.= " AND cf.entity = ".$conf->entity; + $sql.= " AND cf.entity IN (".getEntity('commande_fournisseur', 1).")"; $sql.= " AND fd.fk_product = ".$this->id; if (!$user->rights->societe->client->voir && !$socid) $sql.= " AND cf.fk_soc = sc.fk_soc AND sc.fk_user = " .$user->id; if ($socid > 0) $sql.= " AND cf.fk_soc = ".$socid; @@ -1985,7 +1985,7 @@ function load_stats_contrat($socid=0) if (!$user->rights->societe->client->voir && !$socid) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; $sql.= " WHERE c.rowid = cd.fk_contrat"; $sql.= " AND c.fk_soc = s.rowid"; - $sql.= " AND c.entity = ".$conf->entity; + $sql.= " AND c.entity IN (".getEntity('contrat', 1).")"; $sql.= " AND cd.fk_product = ".$this->id; if (!$user->rights->societe->client->voir && !$socid) $sql.= " AND c.fk_soc = sc.fk_soc AND sc.fk_user = " .$user->id; //$sql.= " AND c.statut != 0"; @@ -2027,7 +2027,7 @@ function load_stats_facture($socid=0) if (!$user->rights->societe->client->voir && !$socid) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; $sql.= " WHERE f.rowid = fd.fk_facture"; $sql.= " AND f.fk_soc = s.rowid"; - $sql.= " AND f.entity = ".$conf->entity; + $sql.= " AND f.entity IN (".getEntity('facture', 1).")"; $sql.= " AND fd.fk_product = ".$this->id; if (!$user->rights->societe->client->voir && !$socid) $sql.= " AND f.fk_soc = sc.fk_soc AND sc.fk_user = " .$user->id; //$sql.= " AND f.fk_statut != 0"; @@ -2069,7 +2069,7 @@ function load_stats_facture_fournisseur($socid=0) if (!$user->rights->societe->client->voir && !$socid) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; $sql.= " WHERE f.rowid = fd.fk_facture_fourn"; $sql.= " AND f.fk_soc = s.rowid"; - $sql.= " AND f.entity = ".$conf->entity; + $sql.= " AND f.entity IN (".getEntity('facture_fourn', 1).")"; $sql.= " AND fd.fk_product = ".$this->id; if (!$user->rights->societe->client->voir && !$socid) $sql.= " AND f.fk_soc = sc.fk_soc AND sc.fk_user = " .$user->id; //$sql.= " AND f.fk_statut != 0"; @@ -2167,7 +2167,7 @@ function get_nb_vente($socid,$mode) $sql.= " WHERE f.rowid = d.fk_facture"; $sql.= " AND d.fk_product =".$this->id; $sql.= " AND f.fk_soc = s.rowid"; - $sql.= " AND f.entity = ".$conf->entity; + $sql.= " AND f.entity IN (".getEntity('facture', 1).")"; if (!$user->rights->societe->client->voir && !$socid) $sql.= " AND f.fk_soc = sc.fk_soc AND sc.fk_user = " .$user->id; if ($socid > 0) $sql.= " AND f.fk_soc = $socid"; $sql.= " GROUP BY date_format(f.datef,'%Y%m')"; @@ -2196,7 +2196,7 @@ function get_nb_achat($socid,$mode) $sql.= " WHERE f.rowid = d.fk_facture_fourn"; $sql.= " AND d.fk_product =".$this->id; $sql.= " AND f.fk_soc = s.rowid"; - $sql.= " AND f.entity = ".$conf->entity; + $sql.= " AND f.entity IN (".getEntity('facture_fourn', 1).")"; if (!$user->rights->societe->client->voir && !$socid) $sql.= " AND f.fk_soc = sc.fk_soc AND sc.fk_user = " .$user->id; if ($socid > 0) $sql.= " AND f.fk_soc = $socid"; $sql.= " GROUP BY date_format(f.datef,'%Y%m')"; @@ -2225,7 +2225,7 @@ function get_nb_propal($socid,$mode) $sql.= " WHERE p.rowid = d.fk_propal"; $sql.= " AND d.fk_product =".$this->id; $sql.= " AND p.fk_soc = s.rowid"; - $sql.= " AND p.entity = ".$conf->entity; + $sql.= " AND p.entity IN (".getEntity('propal', 1).")"; if (!$user->rights->societe->client->voir && !$socid) $sql.= " AND p.fk_soc = sc.fk_soc AND sc.fk_user = " .$user->id; if ($socid > 0) $sql.= " AND p.fk_soc = ".$socid; $sql.= " GROUP BY date_format(p.datep,'%Y%m')"; @@ -2252,7 +2252,7 @@ function get_nb_order($socid,$mode) $sql.= " WHERE c.rowid = d.fk_commande"; $sql.= " AND d.fk_product =".$this->id; $sql.= " AND c.fk_soc = s.rowid"; - $sql.= " AND c.entity = ".$conf->entity; + $sql.= " AND c.entity IN (".getEntity('commande', 1).")"; if (!$user->rights->societe->client->voir && !$socid) $sql.= " AND c.fk_soc = sc.fk_soc AND sc.fk_user = " .$user->id; if ($socid > 0) $sql.= " AND c.fk_soc = ".$socid; $sql.= " GROUP BY date_format(c.date_commande,'%Y%m')"; @@ -2279,7 +2279,7 @@ function get_nb_ordersupplier($socid,$mode) $sql.= " WHERE c.rowid = d.fk_commande"; $sql.= " AND d.fk_product =".$this->id; $sql.= " AND c.fk_soc = s.rowid"; - $sql.= " AND c.entity = ".$conf->entity; + $sql.= " AND c.entity IN (".getEntity('commande_fournisseur', 1).")"; if (!$user->rights->societe->client->voir && !$socid) $sql.= " AND c.fk_soc = sc.fk_soc AND sc.fk_user = " .$user->id; if ($socid > 0) $sql.= " AND c.fk_soc = ".$socid; $sql.= " GROUP BY date_format(c.date_commande,'%Y%m')"; diff --git a/htdocs/product/index.php b/htdocs/product/index.php index c14d27deb9d90..b00ed56166dda 100644 --- a/htdocs/product/index.php +++ b/htdocs/product/index.php @@ -377,7 +377,7 @@ function activitytrim($product_type) $sql.= " AND pf.fk_facture = f.rowid"; $sql.= " AND pf.fk_paiement= p.rowid"; $sql.= " AND fd.product_type=".$product_type; - $sql.= " AND s.entity = ".$conf->entity; + $sql.= " AND s.entity IN (".getEntity('societe', 1).")"; $sql.= " AND p.datep >= '".$db->idate(dol_get_first_day($yearofbegindate),1)."'"; $sql.= " GROUP BY annee, mois "; $sql.= " ORDER BY annee, mois "; diff --git a/htdocs/product/stats/commande.php b/htdocs/product/stats/commande.php index 7dcf613953470..32fce234bc165 100644 --- a/htdocs/product/stats/commande.php +++ b/htdocs/product/stats/commande.php @@ -137,7 +137,7 @@ $sql.= ", ".MAIN_DB_PREFIX."commandedet as d"; if (!$user->rights->societe->client->voir && !$socid) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; $sql.= " WHERE c.fk_soc = s.rowid"; - $sql.= " AND c.entity = ".$conf->entity; + $sql.= " AND c.entity IN (".getEntity('commande', 1).")"; $sql.= " AND d.fk_commande = c.rowid"; $sql.= " AND d.fk_product =".$product->id; if (! empty($search_month)) diff --git a/htdocs/product/stats/contrat.php b/htdocs/product/stats/contrat.php index d098ca3399b38..bf65a80e64484 100644 --- a/htdocs/product/stats/contrat.php +++ b/htdocs/product/stats/contrat.php @@ -131,7 +131,7 @@ $sql.= ", ".MAIN_DB_PREFIX."contratdet as cd"; $sql.= " WHERE c.rowid = cd.fk_contrat"; $sql.= " AND c.fk_soc = s.rowid"; - $sql.= " AND c.entity = ".$conf->entity; + $sql.= " AND c.entity IN (".getEntity('contrat', 1).")"; $sql.= " AND cd.fk_product =".$product->id; 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; diff --git a/htdocs/product/stats/facture.php b/htdocs/product/stats/facture.php index 1f4e9b985e582..564132270b06e 100644 --- a/htdocs/product/stats/facture.php +++ b/htdocs/product/stats/facture.php @@ -138,7 +138,7 @@ $sql.= ", ".MAIN_DB_PREFIX."facturedet as d"; if (!$user->rights->societe->client->voir && !$socid) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; $sql.= " WHERE f.fk_soc = s.rowid"; - $sql.= " AND f.entity = ".$conf->entity; + $sql.= " AND f.entity IN (".getEntity('facture', 1).")"; $sql.= " AND d.fk_facture = f.rowid"; $sql.= " AND d.fk_product =".$product->id; if (! empty($search_month)) diff --git a/htdocs/product/stats/facture_fournisseur.php b/htdocs/product/stats/facture_fournisseur.php index debb0698c4472..0c1bfb18e9e8d 100644 --- a/htdocs/product/stats/facture_fournisseur.php +++ b/htdocs/product/stats/facture_fournisseur.php @@ -139,7 +139,7 @@ $sql .= ", " . MAIN_DB_PREFIX . "facture_fourn_det as d"; if (! $user->rights->societe->client->voir && ! $socid) $sql .= ", " . MAIN_DB_PREFIX . "societe_commerciaux as sc"; $sql .= " WHERE f.fk_soc = s.rowid"; - $sql .= " AND f.entity = " . $conf->entity; + $sql .= " AND f.entity IN (".getEntity('facture_fourn', 1).")"; $sql .= " AND d.fk_facture_fourn = f.rowid"; $sql .= " AND d.fk_product =" . $product->id; if (! empty($search_month)) diff --git a/htdocs/product/stats/propal.php b/htdocs/product/stats/propal.php index 1776ba571e0d6..c7e2acafb3eb2 100644 --- a/htdocs/product/stats/propal.php +++ b/htdocs/product/stats/propal.php @@ -138,7 +138,7 @@ if (! $user->rights->societe->client->voir && ! $socid) $sql .= ", " . MAIN_DB_PREFIX . "societe_commerciaux as sc"; $sql .= " WHERE p.fk_soc = s.rowid"; - $sql .= " AND p.entity = " . $conf->entity; + $sql .= " AND p.entity IN (".getEntity('propal', 1).")"; $sql .= " AND d.fk_propal = p.rowid"; $sql .= " AND d.fk_product =" . $product->id; if (! empty($search_month)) diff --git a/htdocs/product/stock/replenish.php b/htdocs/product/stock/replenish.php index 0f935c0154c85..dc12f7d9042ee 100644 --- a/htdocs/product/stock/replenish.php +++ b/htdocs/product/stock/replenish.php @@ -295,7 +295,7 @@ $sqlCommandesCli = "(SELECT ".$db->ifsql("SUM(cd.qty) IS NULL", "0", "SUM(cd.qty)")." as qty"; $sqlCommandesCli.= " FROM ".MAIN_DB_PREFIX."commandedet as cd"; $sqlCommandesCli.= " LEFT JOIN ".MAIN_DB_PREFIX."commande as c ON (c.rowid = cd.fk_commande)"; - $sqlCommandesCli.= " WHERE c.entity = ".$conf->entity; + $sqlCommandesCli.= " WHERE c.entity IN (".getEntity('order', 1).")"; $sqlCommandesCli.= " AND cd.fk_product = p.rowid"; $sqlCommandesCli.= " AND c.fk_statut IN (1,2))"; @@ -304,7 +304,7 @@ $sqlExpeditionsCli.= " LEFT JOIN ".MAIN_DB_PREFIX."expeditiondet as ed ON (ed.fk_expedition = e.rowid)"; $sqlExpeditionsCli.= " LEFT JOIN ".MAIN_DB_PREFIX."commandedet as cd ON (cd.rowid = ed.fk_origin_line)"; $sqlExpeditionsCli.= " LEFT JOIN ".MAIN_DB_PREFIX."commande as c ON (c.rowid = cd.fk_commande)"; - $sqlExpeditionsCli.= " WHERE e.entity = ".$conf->entity; + $sqlExpeditionsCli.= " WHERE e.entity IN (".getEntity('expedition', 1).")"; $sqlExpeditionsCli.= " AND cd.fk_product = p.rowid"; $sqlExpeditionsCli.= " AND c.fk_statut IN (1,2))"; @@ -312,14 +312,14 @@ $sqlCommandesFourn.= " FROM ".MAIN_DB_PREFIX."commande_fournisseurdet as cd"; $sqlCommandesFourn.= ", ".MAIN_DB_PREFIX."commande_fournisseur as c"; $sqlCommandesFourn.= " WHERE c.rowid = cd.fk_commande"; - $sqlCommandesFourn.= " AND c.entity = ".$conf->entity; + $sqlCommandesFourn.= " AND c.entity IN (".getEntity('commande_fournisseur', 1).")"; $sqlCommandesFourn.= " AND cd.fk_product = p.rowid"; $sqlCommandesFourn.= " AND c.fk_statut IN (3,4))"; $sqlReceptionFourn = "(SELECT ".$db->ifsql("SUM(fd.qty) IS NULL", "0", "SUM(fd.qty)")." as qty"; $sqlReceptionFourn.= " FROM ".MAIN_DB_PREFIX."commande_fournisseur as cf"; $sqlReceptionFourn.= " LEFT JOIN ".MAIN_DB_PREFIX."commande_fournisseur_dispatch as fd ON (fd.fk_commande = cf.rowid)"; - $sqlReceptionFourn.= " WHERE cf.entity = ".$conf->entity; + $sqlReceptionFourn.= " WHERE cf.entity IN (".getEntity('commande_fournisseur', 1).")"; $sqlReceptionFourn.= " AND fd.fk_product = p.rowid"; $sqlReceptionFourn.= " AND cf.fk_statut IN (3,4))";