diff --git a/htdocs/product/stock/replenish.php b/htdocs/product/stock/replenish.php index c9109b348d6..ab95c29eadd 100644 --- a/htdocs/product/stock/replenish.php +++ b/htdocs/product/stock/replenish.php @@ -6,6 +6,7 @@ * Copyright (C) 2016 ATM Consulting * Copyright (C) 2019 Frédéric France * Copyright (C) 2021 Ferran Marcet + * Copyright (C) 2021 Antonin MARCHAL * * 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 @@ -64,6 +65,20 @@ $draftorder = GETPOST('draftorder', 'alpha'); $fourn_id = GETPOST('fourn_id', 'int'); $fk_supplier = GETPOST('fk_supplier', 'int'); $fk_entrepot = GETPOST('fk_entrepot', 'int'); + +//MultiCompany : If only 1 Warehouse is visible, filter will automatically be set to it. +if ($fk_entrepot == "-1" && !empty($conf->global->MULTICOMPANY_PRODUCT_SHARING_ENABLED)) { + global $mc; + $visibleWarehousesEntities = $conf->entity; + if (isset($mc->sharings['stock']) && !empty($mc->sharings['stock'])) { + $visibleWarehousesEntities .= "," . implode(",", $mc->sharings['stock']); + } + $resWar = $db->query ("SELECT rowid FROM " . MAIN_DB_PREFIX . "entrepot WHERE entity IN (" . $db->sanitize($visibleWarehousesEntities) .")"); + if($db->num_rows($resWar) == 1){ + $fk_entrepot = $db->fetch_object($resWar)->rowid; + } +}; + $texte = ''; $sortfield = GETPOST('sortfield', 'aZ09comma'); @@ -324,8 +339,8 @@ $reshook = $hookmanager->executeHooks('printFieldListSelect', $parameters); // N $sql .= $hookmanager->resPrint; $sql .= ' FROM '.MAIN_DB_PREFIX.'product as p'; -$sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'product_stock as s ON p.rowid = s.fk_product'; -$sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'entrepot AS ent ON s.fk_entrepot = ent.rowid AND ent.entity IN('.getEntity('stock').')'; +$sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'entrepot AS ent ON ent.entity IN('.getEntity('stock').')'; +$sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'product_stock as s ON p.rowid = s.fk_product AND s.fk_entrepot = ent.rowid'; if ($fk_supplier > 0) { $sql .= ' INNER JOIN '.MAIN_DB_PREFIX.'product_fournisseur_price pfp ON (pfp.fk_product = p.rowid AND pfp.fk_soc = '.$fk_supplier.')'; }