diff --git a/htdocs/product/stock/replenish.php b/htdocs/product/stock/replenish.php
index 71040557537..8f464034fee 100644
--- a/htdocs/product/stock/replenish.php
+++ b/htdocs/product/stock/replenish.php
@@ -30,11 +30,11 @@
// Load Dolibarr environment
require '../../main.inc.php';
-require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
-require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
-require_once DOL_DOCUMENT_ROOT.'/core/class/html.form.class.php';
-require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.commande.class.php';
-require_once DOL_DOCUMENT_ROOT.'/product/class/html.formproduct.class.php';
+require_once DOL_DOCUMENT_ROOT . '/product/class/product.class.php';
+require_once DOL_DOCUMENT_ROOT . '/core/class/html.formother.class.php';
+require_once DOL_DOCUMENT_ROOT . '/core/class/html.form.class.php';
+require_once DOL_DOCUMENT_ROOT . '/fourn/class/fournisseur.commande.class.php';
+require_once DOL_DOCUMENT_ROOT . '/product/class/html.formproduct.class.php';
require_once './lib/replenishment.lib.php';
// Load translation files required by the page
@@ -54,7 +54,7 @@ $hookmanager->initHooks(array('stockreplenishlist'));
$action = GETPOST('action', 'aZ09');
$search_ref = GETPOST('search_ref', 'alpha');
$search_label = GETPOST('search_label', 'alpha');
-$sall = trim((GETPOST('search_all', 'alphanohtml') != '') ?GETPOST('search_all', 'alphanohtml') : GETPOST('sall', 'alphanohtml'));
+$sall = trim((GETPOST('search_all', 'alphanohtml') != '') ? GETPOST('search_all', 'alphanohtml') : GETPOST('sall', 'alphanohtml'));
$type = GETPOST('type', 'int');
$tobuy = GETPOST('tobuy', 'int');
$salert = GETPOST('salert', 'alpha');
@@ -68,7 +68,7 @@ $fk_supplier = GETPOST('fk_supplier', 'int');
$fk_entrepot = GETPOST('fk_entrepot', 'int');
// List all visible warehouses
-$resWar = $db->query("SELECT rowid FROM " . MAIN_DB_PREFIX . "entrepot WHERE entity IN (" . $db->sanitize(getEntity('stock')) .")");
+$resWar = $db->query("SELECT rowid FROM " . MAIN_DB_PREFIX . "entrepot WHERE entity IN (" . $db->sanitize(getEntity('stock')) . ")");
$listofqualifiedwarehousesid = "";
$count = 0;
while ($tmpobj = $db->fetch_object($resWar)) {
@@ -93,7 +93,7 @@ $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("pa
if (empty($page) || $page == -1) {
$page = 0;
} // If $page is not defined, or '' or -1
-$limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit;
+$limit = GETPOST('limit', 'int') ? GETPOST('limit', 'int') : $conf->liste_limit;
$offset = $limit * $page;
if (!$sortfield) {
@@ -161,15 +161,15 @@ if ($action == 'order' && GETPOST('valid')) {
$db->begin();
$suppliers = array();
- require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.product.class.php';
+ require_once DOL_DOCUMENT_ROOT . '/fourn/class/fournisseur.product.class.php';
$productsupplier = new ProductFournisseur($db);
for ($i = 0; $i < $linecount; $i++) {
- if (GETPOST('choose'.$i, 'alpha') === 'on' && GETPOST('fourn'.$i, 'int') > 0) {
+ if (GETPOST('choose' . $i, 'alpha') === 'on' && GETPOST('fourn' . $i, 'int') > 0) {
//one line
$box = $i;
- $supplierpriceid = GETPOST('fourn'.$i, 'int');
+ $supplierpriceid = GETPOST('fourn' . $i, 'int');
//get all the parameters needed to create a line
- $qty = GETPOST('tobuy'.$i, 'int');
+ $qty = GETPOST('tobuy' . $i, 'int');
$idprod = $productsupplier->get_buyprice($supplierpriceid, $qty);
$res = $productsupplier->fetch($idprod);
if ($res && $idprod > 0) {
@@ -215,7 +215,7 @@ if ($action == 'order' && GETPOST('valid')) {
dol_print_error($db);
}
- unset($_POST['fourn'.$i]);
+ unset($_POST['fourn' . $i]);
}
unset($_POST[$i]);
}
@@ -229,10 +229,10 @@ if ($action == 'order' && GETPOST('valid')) {
$order = new CommandeFournisseur($db);
// Check if an order for the supplier exists
- $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."commande_fournisseur";
- $sql .= " WHERE fk_soc = ".((int) $suppliersid[$i]);
- $sql .= " AND source = ".((int) $order::SOURCE_ID_REPLENISHMENT)." AND fk_statut = ".((int) $order::STATUS_DRAFT);
- $sql .= " AND entity IN (".getEntity('commande_fournisseur').")";
+ $sql = "SELECT rowid FROM " . MAIN_DB_PREFIX . "commande_fournisseur";
+ $sql .= " WHERE fk_soc = " . ((int) $suppliersid[$i]);
+ $sql .= " AND source = " . ((int) $order::SOURCE_ID_REPLENISHMENT) . " AND fk_statut = " . ((int) $order::STATUS_DRAFT);
+ $sql .= " AND entity IN (" . getEntity('commande_fournisseur') . ")";
$sql .= " ORDER BY date_creation DESC";
$resql = $db->query($sql);
if ($resql && $db->num_rows($resql) > 0) {
@@ -269,7 +269,7 @@ if ($action == 'order' && GETPOST('valid')) {
}
if ($result < 0) {
$fail++;
- $msg = $langs->trans('OrderFail')." : ";
+ $msg = $langs->trans('OrderFail') . " : ";
$msg .= $order->error;
setEventMessages($msg, null, 'errors');
} else {
@@ -294,7 +294,7 @@ if ($action == 'order' && GETPOST('valid')) {
$id = $order->create($user);
if ($id < 0) {
$fail++;
- $msg = $langs->trans('OrderFail')." : ";
+ $msg = $langs->trans('OrderFail') . " : ";
$msg .= $order->error;
setEventMessages($msg, null, 'errors');
}
@@ -347,11 +347,11 @@ $sql .= ' p.desiredstock, p.seuil_stock_alerte,';
if (!empty($conf->global->STOCK_ALLOW_ADD_LIMIT_STOCK_BY_WAREHOUSE) && $fk_entrepot > 0) {
$sql .= ' pse.desiredstock as desiredstockpse, pse.seuil_stock_alerte as seuil_stock_alertepse,';
}
-$sql .= " ".$sqldesiredtock." as desiredstockcombined, ".$sqlalertstock." as seuil_stock_alertecombined,";
+$sql .= " " . $sqldesiredtock . " as desiredstockcombined, " . $sqlalertstock . " as seuil_stock_alertecombined,";
$sql .= ' s.fk_product,';
-$sql .= " SUM(".$db->ifsql("s.reel IS NULL", "0", "s.reel").') as stock_physique';
+$sql .= " SUM(" . $db->ifsql("s.reel IS NULL", "0", "s.reel") . ') as stock_physique';
if (!empty($conf->global->STOCK_ALLOW_ADD_LIMIT_STOCK_BY_WAREHOUSE) && $fk_entrepot > 0) {
- $sql .= ", SUM(".$db->ifsql("s.reel IS NULL OR s.fk_entrepot <> ".$fk_entrepot, "0", "s.reel").') as stock_real_warehouse';
+ $sql .= ", SUM(" . $db->ifsql("s.reel IS NULL OR s.fk_entrepot <> " . $fk_entrepot, "0", "s.reel") . ') as stock_real_warehouse';
}
// Add fields from hooks
@@ -359,21 +359,26 @@ $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.'product as p';
-$sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'product_stock as s ON p.rowid = s.fk_product';
$list_warehouse = (empty($listofqualifiedwarehousesid) ? '0' : $listofqualifiedwarehousesid);
-$sql .= ' AND s.fk_entrepot IN ('.$db->sanitize($list_warehouse) .')';
+
+$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 .= ' AND s.fk_entrepot IN (' . $db->sanitize($list_warehouse) . ')';
+
+$list_warehouse_selected = ($fk_entrepot < 0) ? '0' : $fk_entrepot;
+$sql .= ' AND s.fk_entrepot IN (' . $db->sanitize($list_warehouse_selected) . ')';
+
//$sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'entrepot AS ent ON s.fk_entrepot = ent.rowid AND ent.entity IN('.getEntity('stock').')';
if (!empty($conf->global->STOCK_ALLOW_ADD_LIMIT_STOCK_BY_WAREHOUSE) && $fk_entrepot > 0) {
- $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'product_warehouse_properties AS pse ON (p.rowid = pse.fk_product AND pse.fk_entrepot = '.((int) $fk_entrepot).')';
+ $sql .= ' LEFT JOIN ' . MAIN_DB_PREFIX . 'product_warehouse_properties AS pse ON (p.rowid = pse.fk_product AND pse.fk_entrepot = ' . ((int) $fk_entrepot) . ')';
}
// Add fields from hooks
$parameters = array();
$reshook = $hookmanager->executeHooks('printFieldListJoin', $parameters); // Note that $action and $object may have been modified by hook
$sql .= $hookmanager->resPrint;
-$sql .= ' WHERE p.entity IN ('.getEntity('product').')';
+$sql .= ' WHERE p.entity IN (' . getEntity('product') . ')';
if ($sall) {
$sql .= natural_search(array('p.ref', 'p.label', 'p.description', 'p.note'), $sall);
}
@@ -392,11 +397,11 @@ if ($search_label) {
$sql .= natural_search('p.label', $search_label);
}
$sql .= ' AND p.tobuy = 1';
-if (!empty($conf->variants->eabled) && empty($conf->global->VARIANT_ALLOW_STOCK_MOVEMENT_ON_VARIANT_PARENT)) { // Add test to exclude products that has variants
- $sql .= ' AND p.rowid NOT IN (SELECT pac.fk_product_parent FROM '.MAIN_DB_PREFIX.'product_attribute_combination as pac WHERE pac.entity IN ('.getEntity('product').'))';
+if (isModEnabled('variants') && !getDolGlobalString('VARIANT_ALLOW_STOCK_MOVEMENT_ON_VARIANT_PARENT')) { // Add test to exclude products that has variants
+ $sql .= ' AND p.rowid NOT IN (SELECT pac.fk_product_parent FROM ' . MAIN_DB_PREFIX . 'product_attribute_combination as pac WHERE pac.entity IN (' . getEntity('product') . '))';
}
if ($fk_supplier > 0) {
- $sql .= ' AND EXISTS (SELECT pfp.rowid FROM '.MAIN_DB_PREFIX.'product_fournisseur_price as pfp WHERE pfp.fk_product = p.rowid AND pfp.fk_soc = '.((int) $fk_supplier).' AND pfp.entity IN ('.getEntity('product_fournisseur_price').'))';
+ $sql .= ' AND EXISTS (SELECT pfp.rowid FROM ' . MAIN_DB_PREFIX . 'product_fournisseur_price as pfp WHERE pfp.fk_product = p.rowid AND pfp.fk_soc = ' . ((int) $fk_supplier) . ' AND pfp.entity IN (' . getEntity('product_fournisseur_price') . '))';
}
// Add where from hooks
$parameters = array();
@@ -416,9 +421,9 @@ $sql .= ', s.fk_product';
if ($usevirtualstock) {
if (isModEnabled('commande')) {
- $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(!empty($conf->global->STOCK_CALCULATE_VIRTUAL_STOCK_TRANSVERSE_MODE) ? 'stock' : 'commande').")";
+ $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(!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 {
@@ -426,14 +431,14 @@ if ($usevirtualstock) {
}
if (isModEnabled("expedition")) {
- $sqlExpeditionsCli = "(SELECT ".$db->ifsql("SUM(ed2.qty) IS NULL", "0", "SUM(ed2.qty)")." as qty"; // We need the ifsql because if result is 0 for product p.rowid, we must return 0 and not NULL
- $sqlExpeditionsCli .= " FROM ".MAIN_DB_PREFIX."expedition as e2,";
- $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(!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 = "(SELECT " . $db->ifsql("SUM(ed2.qty) IS NULL", "0", "SUM(ed2.qty)") . " as qty"; // We need the ifsql because if result is 0 for product p.rowid, we must return 0 and not NULL
+ $sqlExpeditionsCli .= " FROM " . MAIN_DB_PREFIX . "expedition as e2,";
+ $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(!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";
$sqlExpeditionsCli .= " AND e2.fk_statut IN (1,2))";
} else {
@@ -441,18 +446,18 @@ if ($usevirtualstock) {
}
if (isModEnabled("supplier_order")) {
- $sqlCommandesFourn = "(SELECT ".$db->ifsql("SUM(cd3.qty) IS NULL", "0", "SUM(cd3.qty)")." as qty"; // We need the ifsql because if result is 0 for product p.rowid, we must return 0 and not NULL
- $sqlCommandesFourn .= " FROM ".MAIN_DB_PREFIX."commande_fournisseurdet as cd3,";
- $sqlCommandesFourn .= " ".MAIN_DB_PREFIX."commande_fournisseur as c3";
+ $sqlCommandesFourn = "(SELECT " . $db->ifsql("SUM(cd3.qty) IS NULL", "0", "SUM(cd3.qty)") . " as qty"; // We need the ifsql because if result is 0 for product p.rowid, we must return 0 and not NULL
+ $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(!empty($conf->global->STOCK_CALCULATE_VIRTUAL_STOCK_TRANSVERSE_MODE) ? 'stock' : '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(!empty($conf->global->STOCK_CALCULATE_VIRTUAL_STOCK_TRANSVERSE_MODE) ? 'stock' : 'supplier_order').")";
+ $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(!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 {
@@ -461,18 +466,18 @@ if ($usevirtualstock) {
}
if (isModEnabled('mrp')) {
- $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(!empty($conf->global->STOCK_CALCULATE_VIRTUAL_STOCK_TRANSVERSE_MODE) ? 'stock' : 'mo').")";
+ $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(!empty($conf->global->STOCK_CALCULATE_VIRTUAL_STOCK_TRANSVERSE_MODE) ? 'stock' : 'mo') . ")";
$sqlProductionToConsume .= " AND mp5.fk_product = p.rowid";
$sqlProductionToConsume .= " AND mp5.role IN ('toconsume', 'consumed')";
$sqlProductionToConsume .= " AND mm5.status IN (1,2))";
- $sqlProductionToProduce = "(SELECT GREATEST(0, ".$db->ifsql("SUM(".$db->ifsql("mp5.role = 'toproduce'", 'mp5.qty', '- mp5.qty').") IS NULL", "0", "SUM(".$db->ifsql("mp5.role = 'toproduce'", '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(!empty($conf->global->STOCK_CALCULATE_VIRTUAL_STOCK_TRANSVERSE_MODE) ? 'stock' : 'mo').")";
+ $sqlProductionToProduce = "(SELECT GREATEST(0, " . $db->ifsql("SUM(" . $db->ifsql("mp5.role = 'toproduce'", 'mp5.qty', '- mp5.qty') . ") IS NULL", "0", "SUM(" . $db->ifsql("mp5.role = 'toproduce'", '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(!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))";
@@ -482,45 +487,53 @@ if ($usevirtualstock) {
}
$sql .= ' HAVING (';
- $sql .= " (".$sqldesiredtock." >= 0 AND (".$sqldesiredtock." > SUM(".$db->ifsql("s.reel IS NULL", "0", "s.reel").')';
- $sql .= " - (".$sqlCommandesCli." - ".$sqlExpeditionsCli.") + (".$sqlCommandesFourn." - ".$sqlReceptionFourn.") + (".$sqlProductionToProduce." - ".$sqlProductionToConsume.")))";
+ $sql .= " (" . $sqldesiredtock . " >= 0 AND (" . $sqldesiredtock . " > SUM(" . $db->ifsql("s.reel IS NULL", "0", "s.reel") . ')';
+ $sql .= " - (" . $sqlCommandesCli . " - " . $sqlExpeditionsCli . ") + (" . $sqlCommandesFourn . " - " . $sqlReceptionFourn . ") + (" . $sqlProductionToProduce . " - " . $sqlProductionToConsume . ")))";
$sql .= ' OR';
if ($includeproductswithoutdesiredqty == 'on') {
- $sql .= " ((".$sqlalertstock." >= 0 OR ".$sqlalertstock." IS NULL) AND (".$db->ifsql($sqlalertstock." IS NULL", "0", $sqlalertstock)." > SUM(".$db->ifsql("s.reel IS NULL", "0", "s.reel").")";
+ $sql .= " ((" . $sqlalertstock . " >= 0 OR " . $sqlalertstock . " IS NULL) AND (" . $db->ifsql($sqlalertstock . " IS NULL", "0", $sqlalertstock) . " > SUM(" . $db->ifsql("s.reel IS NULL", "0", "s.reel") . ")";
} else {
- $sql .= " (".$sqlalertstock." >= 0 AND (".$sqlalertstock." > SUM(".$db->ifsql("s.reel IS NULL", "0", "s.reel").')';
+ $sql .= " (" . $sqlalertstock . " >= 0 AND (" . $sqlalertstock . " > SUM(" . $db->ifsql("s.reel IS NULL", "0", "s.reel") . ')';
}
- $sql .= " - (".$sqlCommandesCli." - ".$sqlExpeditionsCli.") + (".$sqlCommandesFourn." - ".$sqlReceptionFourn.") + (".$sqlProductionToProduce." - ".$sqlProductionToConsume.")))";
+ $sql .= " - (" . $sqlCommandesCli . " - " . $sqlExpeditionsCli . ") + (" . $sqlCommandesFourn . " - " . $sqlReceptionFourn . ") + (" . $sqlProductionToProduce . " - " . $sqlProductionToConsume . ")))";
$sql .= ")";
+ if (!empty($conf->global->STOCK_ALLOW_ADD_LIMIT_STOCK_BY_WAREHOUSE) && $fk_entrepot > 0) {
+ $sql .= " AND (";
+ $sql .= " pse.desiredstock > 0)";
+ }
- if ($salert == 'on') { // Option to see when stock is lower than alert
+ if ($salert == 'on') { // Option to see when stock is lower than alert
$sql .= ' AND (';
if ($includeproductswithoutdesiredqty == 'on') {
- $sql .= "(".$sqlalertstock." >= 0 OR ".$sqlalertstock." IS NULL) AND (".$db->ifsql($sqlalertstock." IS NULL", "0", $sqlalertstock)." > SUM(".$db->ifsql("s.reel IS NULL", "0", "s.reel").")";
+ $sql .= "(" . $sqlalertstock . " >= 0 OR " . $sqlalertstock . " IS NULL) AND (" . $db->ifsql($sqlalertstock . " IS NULL", "0", $sqlalertstock) . " > SUM(" . $db->ifsql("s.reel IS NULL", "0", "s.reel") . ")";
} else {
- $sql .= $sqlalertstock." >= 0 AND (".$sqlalertstock." > SUM(".$db->ifsql("s.reel IS NULL", "0", "s.reel").")";
+ $sql .= $sqlalertstock . " >= 0 AND (" . $sqlalertstock . " > SUM(" . $db->ifsql("s.reel IS NULL", "0", "s.reel") . ")";
}
- $sql .= " - (".$sqlCommandesCli." - ".$sqlExpeditionsCli.") + (".$sqlCommandesFourn." - ".$sqlReceptionFourn.") + (".$sqlProductionToProduce." - ".$sqlProductionToConsume."))";
+ $sql .= " - (" . $sqlCommandesCli . " - " . $sqlExpeditionsCli . ") + (" . $sqlCommandesFourn . " - " . $sqlReceptionFourn . ") + (" . $sqlProductionToProduce . " - " . $sqlProductionToConsume . "))";
$sql .= ")";
$alertchecked = 'checked';
}
} else {
$sql .= ' HAVING (';
- $sql .= "(".$sqldesiredtock." >= 0 AND (".$sqldesiredtock." > SUM(".$db->ifsql("s.reel IS NULL", "0", "s.reel").")))";
+ $sql .= "(" . $sqldesiredtock . " >= 0 AND (" . $sqldesiredtock . " > SUM(" . $db->ifsql("s.reel IS NULL", "0", "s.reel") . ")))";
$sql .= ' OR';
if ($includeproductswithoutdesiredqty == 'on') {
- $sql .= " ((".$sqlalertstock." >= 0 OR ".$sqlalertstock." IS NULL) AND (".$db->ifsql($sqlalertstock." IS NULL", "0", $sqlalertstock)." > SUM(".$db->ifsql("s.reel IS NULL", "0", "s.reel").')))';
+ $sql .= " ((" . $sqlalertstock . " >= 0 OR " . $sqlalertstock . " IS NULL) AND (" . $db->ifsql($sqlalertstock . " IS NULL", "0", $sqlalertstock) . " > SUM(" . $db->ifsql("s.reel IS NULL", "0", "s.reel") . ')))';
} else {
- $sql .= " (".$sqlalertstock." >= 0 AND (".$sqlalertstock." > SUM(".$db->ifsql("s.reel IS NULL", "0", "s.reel").')))';
+ $sql .= " (" . $sqlalertstock . " >= 0 AND (" . $sqlalertstock . " > SUM(" . $db->ifsql("s.reel IS NULL", "0", "s.reel") . ')))';
}
$sql .= ')';
+ if (!empty($conf->global->STOCK_ALLOW_ADD_LIMIT_STOCK_BY_WAREHOUSE) && $fk_entrepot > 0) {
+ $sql .= " AND (";
+ $sql .= " pse.desiredstock > 0)";
+ }
- if ($salert == 'on') { // Option to see when stock is lower than alert
+ if ($salert == 'on') { // Option to see when stock is lower than alert
$sql .= " AND (";
if ($includeproductswithoutdesiredqty == 'on') {
- $sql .= " (".$sqlalertstock." >= 0 OR ".$sqlalertstock." IS NULL) AND (".$db->ifsql($sqlalertstock." IS NULL", "0", $sqlalertstock)." > SUM(".$db->ifsql("s.reel IS NULL", "0", "s.reel")."))";
+ $sql .= " (" . $sqlalertstock . " >= 0 OR " . $sqlalertstock . " IS NULL) AND (" . $db->ifsql($sqlalertstock . " IS NULL", "0", $sqlalertstock) . " > SUM(" . $db->ifsql("s.reel IS NULL", "0", "s.reel") . "))";
} else {
- $sql .= " ".$sqlalertstock." >= 0 AND (".$sqlalertstock." > SUM(".$db->ifsql("s.reel IS NULL", "0", "s.reel").'))';
+ $sql .= " " . $sqlalertstock . " >= 0 AND (" . $sqlalertstock . " > SUM(" . $db->ifsql("s.reel IS NULL", "0", "s.reel") . '))';
}
$sql .= ')';
$alertchecked = 'checked';
@@ -562,11 +575,11 @@ llxHeader('', $title, $helpurl, '');
$head = array();
-$head[0][0] = DOL_URL_ROOT.'/product/stock/replenish.php';
+$head[0][0] = DOL_URL_ROOT . '/product/stock/replenish.php';
$head[0][1] = $title;
$head[0][2] = 'replenish';
-$head[1][0] = DOL_URL_ROOT.'/product/stock/replenishorders.php';
+$head[1][0] = DOL_URL_ROOT . '/product/stock/replenishorders.php';
$head[1][1] = $langs->trans("ReplenishmentOrders");
$head[1][2] = 'replenishorders';
@@ -575,48 +588,48 @@ print load_fiche_titre($langs->trans('Replenishment'), '', 'stock');
print dol_get_fiche_head($head, 'replenish', '', -1, '');
-print ''.$langs->trans("ReplenishmentStatusDesc").''."\n";
+print '' . $langs->trans("ReplenishmentStatusDesc") . '' . "\n";
//$link = ''.$langs->trans("MenuNewWarehouse").'';
if (empty($fk_entrepot) && !empty($conf->global->STOCK_ALLOW_ADD_LIMIT_STOCK_BY_WAREHOUSE)) {
- print ''.$langs->trans("ReplenishmentStatusDescPerWarehouse").''."\n";
+ print '' . $langs->trans("ReplenishmentStatusDescPerWarehouse") . '' . "\n";
}
print '
';
if ($usevirtualstock == 1) {
- print $langs->trans("CurentSelectionMode").': ';
- print ''.$langs->trans("UseVirtualStock").'';
- print ' 0 ? '&fk_supplier='.$fk_supplier : '').($fk_entrepot > 0 ? '&fk_entrepot='.$fk_entrepot : '').'">'.$langs->trans("UsePhysicalStock").'';
+ print $langs->trans("CurentSelectionMode") . ': ';
+ print '' . $langs->trans("UseVirtualStock") . '';
+ print ' 0 ? '&fk_supplier=' . $fk_supplier : '') . ($fk_entrepot > 0 ? '&fk_entrepot=' . $fk_entrepot : '') . '">' . $langs->trans("UsePhysicalStock") . '';
print '
';
}
if ($usevirtualstock == 0) {
- print $langs->trans("CurentSelectionMode").': ';
- print ' 0 ? '&fk_supplier='.$fk_supplier : '').($fk_entrepot > 0 ? '&fk_entrepot='.$fk_entrepot : '').'">'.$langs->trans("UseVirtualStock").'';
- print ' '.$langs->trans("UsePhysicalStock").'';
+ print $langs->trans("CurentSelectionMode") . ': ';
+ print ' 0 ? '&fk_supplier=' . $fk_supplier : '') . ($fk_entrepot > 0 ? '&fk_entrepot=' . $fk_entrepot : '') . '">' . $langs->trans("UseVirtualStock") . '';
+ print ' ' . $langs->trans("UsePhysicalStock") . '';
print '
';
}
-print '
'."\n";
+print '
' . "\n";
-print '