diff --git a/htdocs/product/class/product.class.php b/htdocs/product/class/product.class.php index 2aa9b3330e3..2427ac74714 100644 --- a/htdocs/product/class/product.class.php +++ b/htdocs/product/class/product.class.php @@ -2627,7 +2627,7 @@ class Product extends CommonObject } $sql .= " WHERE c.rowid = cd.fk_commande"; $sql .= " AND c.fk_soc = s.rowid"; - $sql .= " AND c.entity IN (".getEntity('commande').")"; + $sql .= " AND c.entity IN (".getEntity($forVirtualStock && !empty($conf->global->STOCK_CALCULATE_VIRTUAL_STOCK_TRANSVERSE_MODE) ? 'stock' : 'commande').")"; $sql .= " AND cd.fk_product = ".$this->id; if (!$user->rights->societe->client->voir && !$socid && !$forVirtualStock) { $sql .= " AND c.fk_soc = sc.fk_soc AND sc.fk_user = ".$user->id; @@ -2727,7 +2727,7 @@ class Product extends CommonObject } $sql .= " WHERE c.rowid = cd.fk_commande"; $sql .= " AND c.fk_soc = s.rowid"; - $sql .= " AND c.entity IN (".getEntity('supplier_order').")"; + $sql .= " AND c.entity IN (".getEntity($forVirtualStock && !empty($conf->global->STOCK_CALCULATE_VIRTUAL_STOCK_TRANSVERSE_MODE) ? 'stock' : 'supplier_order').")"; $sql .= " AND cd.fk_product = ".$this->id; if (!$user->rights->societe->client->voir && !$socid && !$forVirtualStock) { $sql .= " AND c.fk_soc = sc.fk_soc AND sc.fk_user = ".$user->id; @@ -2786,7 +2786,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 IN (".getEntity('expedition').")"; + $sql .= " AND e.entity IN (".getEntity($forVirtualStock && !empty($conf->global->STOCK_CALCULATE_VIRTUAL_STOCK_TRANSVERSE_MODE) ? 'stock' : 'expedition').")"; $sql .= " AND ed.fk_origin_line = cd.rowid"; $sql .= " AND cd.fk_product = ".$this->id; if (!$user->rights->societe->client->voir && !$socid && !$forVirtualStock) { @@ -2863,7 +2863,7 @@ class Product extends CommonObject } $sql .= " WHERE cf.rowid = fd.fk_commande"; $sql .= " AND cf.fk_soc = s.rowid"; - $sql .= " AND cf.entity IN (".getEntity('supplier_order').")"; + $sql .= " AND cf.entity IN (".getEntity($forVirtualStock && !empty($conf->global->STOCK_CALCULATE_VIRTUAL_STOCK_TRANSVERSE_MODE) ? 'stock' : 'supplier_order').")"; $sql .= " AND fd.fk_product = ".$this->id; if (!$user->rights->societe->client->voir && !$socid && !$forVirtualStock) { $sql .= " AND cf.fk_soc = sc.fk_soc AND sc.fk_user = ".$user->id; } @@ -2914,7 +2914,7 @@ class Product extends CommonObject $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; } $sql .= " WHERE m.rowid = mp.fk_mo"; - $sql .= " AND m.entity IN (".getEntity('mrp').")"; + $sql .= " AND m.entity IN (".getEntity($forVirtualStock && !empty($conf->global->STOCK_CALCULATE_VIRTUAL_STOCK_TRANSVERSE_MODE) ? 'stock' : 'mrp').")"; $sql .= " AND mp.fk_product = ".$this->id; if (!$user->rights->societe->client->voir && !$socid && !$forVirtualStock) { $sql .= " AND m.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 2518f0ee17d..a5fd94236ad 100644 --- a/htdocs/product/stock/replenish.php +++ b/htdocs/product/stock/replenish.php @@ -366,7 +366,7 @@ if ($usevirtualstock) if (!empty($conf->commande->enabled)) { $sqlCommandesCli = "(SELECT ".$db->ifsql("SUM(cd1.qty) IS NULL", "0", "SUM(cd1.qty)")." as qty"; // We need the ifsql because if result is 0 for product p.rowid, we must return 0 and not NULL $sqlCommandesCli .= " FROM ".MAIN_DB_PREFIX."commandedet as cd1, ".MAIN_DB_PREFIX."commande as c1"; - $sqlCommandesCli .= " WHERE c1.rowid = cd1.fk_commande AND c1.entity IN (".getEntity('commande').")"; + $sqlCommandesCli .= " WHERE c1.rowid = cd1.fk_commande AND c1.entity IN (".getEntity(!empty($conf->global->STOCK_CALCULATE_VIRTUAL_STOCK_TRANSVERSE_MODE) ? 'stock' : 'commande').")"; $sqlCommandesCli .= " AND cd1.fk_product = p.rowid"; $sqlCommandesCli .= " AND c1.fk_statut IN (1,2))"; } else { @@ -379,7 +379,7 @@ if ($usevirtualstock) $sqlExpeditionsCli .= " ".MAIN_DB_PREFIX."expeditiondet as ed2,"; $sqlExpeditionsCli .= " ".MAIN_DB_PREFIX."commande as c2,"; $sqlExpeditionsCli .= " ".MAIN_DB_PREFIX."commandedet as cd2"; - $sqlExpeditionsCli .= " WHERE ed2.fk_expedition = e2.rowid AND cd2.rowid = ed2.fk_origin_line AND e2.entity IN (".getEntity('expedition').")"; + $sqlExpeditionsCli .= " WHERE ed2.fk_expedition = e2.rowid AND cd2.rowid = ed2.fk_origin_line AND e2.entity IN (".getEntity(!empty($conf->global->STOCK_CALCULATE_VIRTUAL_STOCK_TRANSVERSE_MODE) ? 'stock' : 'expedition').")"; $sqlExpeditionsCli .= " AND cd2.fk_commande = c2.rowid"; $sqlExpeditionsCli .= " AND c2.fk_statut IN (1,2)"; $sqlExpeditionsCli .= " AND cd2.fk_product = p.rowid"; @@ -393,14 +393,14 @@ if ($usevirtualstock) $sqlCommandesFourn .= " FROM ".MAIN_DB_PREFIX."commande_fournisseurdet as cd3,"; $sqlCommandesFourn .= " ".MAIN_DB_PREFIX."commande_fournisseur as c3"; $sqlCommandesFourn .= " WHERE c3.rowid = cd3.fk_commande"; - $sqlCommandesFourn .= " AND c3.entity IN (".getEntity('supplier_order').")"; + $sqlCommandesFourn .= " AND c3.entity IN (".getEntity(!empty($conf->global->STOCK_CALCULATE_VIRTUAL_STOCK_TRANSVERSE_MODE) ? 'stock' : 'supplier_order').")"; $sqlCommandesFourn .= " AND cd3.fk_product = p.rowid"; $sqlCommandesFourn .= " AND c3.fk_statut IN (3,4))"; $sqlReceptionFourn = "(SELECT ".$db->ifsql("SUM(fd4.qty) IS NULL", "0", "SUM(fd4.qty)")." as qty"; // We need the ifsql because if result is 0 for product p.rowid, we must return 0 and not NULL $sqlReceptionFourn .= " FROM ".MAIN_DB_PREFIX."commande_fournisseur as cf4,"; $sqlReceptionFourn .= " ".MAIN_DB_PREFIX."commande_fournisseur_dispatch as fd4"; - $sqlReceptionFourn .= " WHERE fd4.fk_commande = cf4.rowid AND cf4.entity IN (".getEntity('supplier_order').")"; + $sqlReceptionFourn .= " WHERE fd4.fk_commande = cf4.rowid AND cf4.entity IN (".getEntity(!empty($conf->global->STOCK_CALCULATE_VIRTUAL_STOCK_TRANSVERSE_MODE) ? 'stock' : 'supplier_order').")"; $sqlReceptionFourn .= " AND fd4.fk_product = p.rowid"; $sqlReceptionFourn .= " AND cf4.fk_statut IN (3,4))"; } else { @@ -412,7 +412,7 @@ if ($usevirtualstock) $sqlProductionToConsume = "(SELECT GREATEST(0, ".$db->ifsql("SUM(".$db->ifsql("mp5.role = 'toconsume'", 'mp5.qty', '- mp5.qty').") IS NULL", "0", "SUM(".$db->ifsql("mp5.role = 'toconsume'", 'mp5.qty', '- mp5.qty').")").") as qty"; // We need the ifsql because if result is 0 for product p.rowid, we must return 0 and not NULL $sqlProductionToConsume .= " FROM ".MAIN_DB_PREFIX."mrp_mo as mm5,"; $sqlProductionToConsume .= " ".MAIN_DB_PREFIX."mrp_production as mp5"; - $sqlProductionToConsume .= " WHERE mm5.rowid = mp5.fk_mo AND mm5.entity IN (".getEntity('mo').")"; + $sqlProductionToConsume .= " WHERE mm5.rowid = mp5.fk_mo AND mm5.entity IN (".getEntity(!empty($conf->global->STOCK_CALCULATE_VIRTUAL_STOCK_TRANSVERSE_MODE) ? 'stock' : 'mo').")"; $sqlProductionToConsume .= " AND mp5.fk_product = p.rowid"; $sqlProductionToConsume .= " AND mp5.role IN ('toconsume', 'consummed')"; $sqlProductionToConsume .= " AND mm5.status IN (1,2))"; @@ -420,7 +420,7 @@ if ($usevirtualstock) $sqlProductionToProduce = "(SELECT GREATEST(0, ".$db->ifsql("SUM(".$db->ifsql("mp5.role = 'toproduce'", 'mp5.qty', '- mp5.qty').") IS NULL", "0", "SUM(".$db->ifsql("mp5.role = 'toconsume'", 'mp5.qty', '- mp5.qty').")").") as qty"; // We need the ifsql because if result is 0 for product p.rowid, we must return 0 and not NULL $sqlProductionToProduce .= " FROM ".MAIN_DB_PREFIX."mrp_mo as mm5,"; $sqlProductionToProduce .= " ".MAIN_DB_PREFIX."mrp_production as mp5"; - $sqlProductionToProduce .= " WHERE mm5.rowid = mp5.fk_mo AND mm5.entity IN (".getEntity('mo').")"; + $sqlProductionToProduce .= " WHERE mm5.rowid = mp5.fk_mo AND mm5.entity IN (".getEntity(!empty($conf->global->STOCK_CALCULATE_VIRTUAL_STOCK_TRANSVERSE_MODE) ? 'stock' : 'mo').")"; $sqlProductionToProduce .= " AND mp5.fk_product = p.rowid"; $sqlProductionToProduce .= " AND mp5.role IN ('toproduce', 'produced')"; $sqlProductionToProduce .= " AND mm5.status IN (1,2))";