From 0c7ae0dd473fa69ec57eee2333f52d67c7a83d7a Mon Sep 17 00:00:00 2001
From: jfefe <jfefe@aternatik.fr>
Date: Sun, 19 Apr 2015 02:38:54 +0200
Subject: [PATCH] Fix: missing getEntity function

---
 htdocs/accountancy/customer/card.php            | 2 +-
 htdocs/accountancy/customer/index.php           | 6 +++---
 htdocs/accountancy/customer/lines.php           | 2 +-
 htdocs/accountancy/customer/list.php            | 2 +-
 htdocs/accountancy/journal/purchasesjournal.php | 2 +-
 htdocs/accountancy/journal/sellsjournal.php     | 2 +-
 htdocs/accountancy/supplier/card.php            | 2 +-
 htdocs/accountancy/supplier/index.php           | 4 ++--
 htdocs/accountancy/supplier/lines.php           | 2 +-
 htdocs/accountancy/supplier/list.php            | 2 +-
 htdocs/admin/tools/listevents.php               | 2 +-
 htdocs/comm/card.php                            | 2 +-
 htdocs/core/lib/sendings.lib.php                | 2 +-
 htdocs/expedition/class/expedition.class.php    | 2 +-
 htdocs/expedition/index.php                     | 4 ++--
 htdocs/expedition/list.php                      | 2 +-
 htdocs/product/class/html.formproduct.class.php | 2 +-
 htdocs/product/class/product.class.php          | 2 +-
 htdocs/product/stock/replenish.php              | 8 ++++----
 19 files changed, 26 insertions(+), 26 deletions(-)

diff --git a/htdocs/accountancy/customer/card.php b/htdocs/accountancy/customer/card.php
index 71afe4ca218..487f4dc2719 100644
--- a/htdocs/accountancy/customer/card.php
+++ b/htdocs/accountancy/customer/card.php
@@ -87,7 +87,7 @@ if (! empty($id)) {
 	$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 39c9d05c833..df635155416 100644
--- a/htdocs/accountancy/customer/index.php
+++ b/htdocs/accountancy/customer/index.php
@@ -159,7 +159,7 @@ $sql .= " WHERE f.datef >= '" . $db->idate(dol_get_first_day($y, 1, false)) . "'
 $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 .= " WHERE f.datef >= '" . $db->idate(dol_get_first_day($y, 1, false)) . "'
 $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 @@ if (! empty($conf->margin->enabled)) {
 	$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 01806db8332..2b523040e6f 100644
--- a/htdocs/accountancy/customer/lines.php
+++ b/htdocs/accountancy/customer/lines.php
@@ -124,7 +124,7 @@ if (strlen(trim(GETPOST("search_account")))) {
 }
 
 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 3d4987bd94a..ac1c3429658 100644
--- a/htdocs/accountancy/customer/list.php
+++ b/htdocs/accountancy/customer/list.php
@@ -132,7 +132,7 @@ $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "accounting_system as accsys ON accsys.
 $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 6d89e8f17a2..6d0e7a6541e 100644
--- a/htdocs/accountancy/journal/purchasesjournal.php
+++ b/htdocs/accountancy/journal/purchasesjournal.php
@@ -96,7 +96,7 @@ $sql .= " JOIN " . MAIN_DB_PREFIX . "facture_fourn as f ON f.rowid = fd.fk_factu
 $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", 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 c2c51bacd42..24ed25f56ed 100644
--- a/htdocs/accountancy/journal/sellsjournal.php
+++ b/htdocs/accountancy/journal/sellsjournal.php
@@ -99,7 +99,7 @@ $sql .= " JOIN " . MAIN_DB_PREFIX . "societe as s ON s.rowid = f.fk_soc";
 $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 70d97b376c5..51d09428c25 100644
--- a/htdocs/accountancy/supplier/card.php
+++ b/htdocs/accountancy/supplier/card.php
@@ -88,7 +88,7 @@ if ($_GET["id"]) {
 	$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 85d1c04cf53..3bdf2f45a7c 100644
--- a/htdocs/accountancy/supplier/index.php
+++ b/htdocs/accountancy/supplier/index.php
@@ -144,7 +144,7 @@ $sql .= "  AND ff.datef <= '" . $db->idate(dol_get_last_day($y, 12, false)) . "'
 $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.datef <= '" . $db->idate(dol_get_last_day($y, 12, false)) . "'
 $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 5df5ee0c06f..df3816c4d4c 100644
--- a/htdocs/accountancy/supplier/lines.php
+++ b/htdocs/accountancy/supplier/lines.php
@@ -121,7 +121,7 @@ if (strlen(trim($_GET["search_account"]))) {
 	$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 656afbd32cc..bf14ebc185e 100644
--- a/htdocs/accountancy/supplier/list.php
+++ b/htdocs/accountancy/supplier/list.php
@@ -135,7 +135,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_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/admin/tools/listevents.php b/htdocs/admin/tools/listevents.php
index 309bf1d935e..373b46c6062 100644
--- a/htdocs/admin/tools/listevents.php
+++ b/htdocs/admin/tools/listevents.php
@@ -123,7 +123,7 @@ $sql.= " e.fk_user, e.description,";
 $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/card.php b/htdocs/comm/card.php
index 81e8b396963..200c731d48a 100644
--- a/htdocs/comm/card.php
+++ b/htdocs/comm/card.php
@@ -684,7 +684,7 @@ if ($id > 0)
         $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/core/lib/sendings.lib.php b/htdocs/core/lib/sendings.lib.php
index 5ce30be59a0..1c0c589870e 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 24ce24bae47..58b6b5c65c2 100644
--- a/htdocs/expedition/class/expedition.class.php
+++ b/htdocs/expedition/class/expedition.class.php
@@ -438,7 +438,7 @@ class Expedition extends CommonObject
 		$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 2b41a939c7b..5ecd563a613 100644
--- a/htdocs/expedition/index.php
+++ b/htdocs/expedition/index.php
@@ -75,7 +75,7 @@ if (!$user->rights->societe->client->voir && !$socid)
 	$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."element_element as el ON e.rowid = el.fk_ta
 $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 195687a4ab7..94eac327fcd 100644
--- a/htdocs/expedition/list.php
+++ b/htdocs/expedition/list.php
@@ -82,7 +82,7 @@ $sql.= ")";
 $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 d67b575023b..4e2da460a74 100644
--- a/htdocs/product/class/html.formproduct.class.php
+++ b/htdocs/product/class/html.formproduct.class.php
@@ -72,7 +72,7 @@ class FormProduct
 			$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 184560b7aad..837dadc5e41 100755
--- a/htdocs/product/class/product.class.php
+++ b/htdocs/product/class/product.class.php
@@ -1900,7 +1900,7 @@ class Product extends CommonObject
 		$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;
diff --git a/htdocs/product/stock/replenish.php b/htdocs/product/stock/replenish.php
index 0f935c0154c..dc12f7d9042 100644
--- a/htdocs/product/stock/replenish.php
+++ b/htdocs/product/stock/replenish.php
@@ -295,7 +295,7 @@ if ($usevirtualstock)
 	$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 @@ if ($usevirtualstock)
 	$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 @@ if ($usevirtualstock)
 	$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))";
 
-- 
GitLab