diff --git a/htdocs/langs/en_US/stocks.lang b/htdocs/langs/en_US/stocks.lang index 49362619f0d..c9fd88f920d 100644 --- a/htdocs/langs/en_US/stocks.lang +++ b/htdocs/langs/en_US/stocks.lang @@ -129,6 +129,7 @@ CurentlyUsingPhysicalStock=Physical stock RuleForStockReplenishment=Rule for stocks replenishment SelectProductWithNotNullQty=Select at least one product with a qty not null and a vendor AlertOnly= Alerts only +IncludeProductWithUndefinedAlerts = Include also negative stock for products with no desired quantity defined, to restore them to 0 WarehouseForStockDecrease=The warehouse %s will be used for stock decrease WarehouseForStockIncrease=The warehouse %s will be used for stock increase ForThisWarehouse=For this warehouse diff --git a/htdocs/product/stock/replenish.php b/htdocs/product/stock/replenish.php index 2195566a6ee..a4fb63ae899 100644 --- a/htdocs/product/stock/replenish.php +++ b/htdocs/product/stock/replenish.php @@ -55,6 +55,7 @@ $sall = trim((GETPOST('search_all', 'alphanohtml') != '') ?GETPOST('search_all', $type = GETPOST('type', 'int'); $tobuy = GETPOST('tobuy', 'int'); $salert = GETPOST('salert', 'alpha'); +$allalert = GETPOST('allalert', 'alpha'); $mode = GETPOST('mode', 'alpha'); $draftorder = GETPOST('draftorder', 'alpha'); @@ -110,6 +111,7 @@ if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x' $search_label = ''; $sall = ''; $salert = ''; + $allalert = ''; $draftorder = ''; } if ($draftorder == 'on') $draftchecked = "checked"; @@ -428,34 +430,65 @@ if ($usevirtualstock) $sql .= ' ('.$sqldesiredtock.' >= 0 AND ('.$sqldesiredtock.' > SUM('.$db->ifsql("s.reel IS NULL", "0", "s.reel").')'; $sql .= ' - ('.$sqlCommandesCli.' - '.$sqlExpeditionsCli.') + ('.$sqlCommandesFourn.' - '.$sqlReceptionFourn.') + ('.$sqlProductionToProduce.' - '.$sqlProductionToConsume.')))'; $sql .= ' OR '; - $sql .= ' ('.$sqlalertstock.' >= 0 AND ('.$sqlalertstock.' > SUM('.$db->ifsql("s.reel IS NULL", "0", "s.reel").')'; + if ($allalert == '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").')'; + } else { + $sql .= ' ('.$sqlalertstock.' >= 0 AND ('.$sqlalertstock.' > SUM('.$db->ifsql("s.reel IS NULL", "0", "s.reel").')'; + } $sql .= ' - ('.$sqlCommandesCli.' - '.$sqlExpeditionsCli.') + ('.$sqlCommandesFourn.' - '.$sqlReceptionFourn.') + ('.$sqlProductionToProduce.' - '.$sqlProductionToConsume.')))'; $sql .= ')'; if ($salert == 'on') // Option to see when stock is lower than alert { - $sql .= ' AND ('; - $sql .= $sqlalertstock.' >= 0 AND ('.$sqlalertstock.' > SUM('.$db->ifsql("s.reel IS NULL", "0", "s.reel").')'; + $sql .= ' AND (('; + if ($allalert == '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").')'; + } else { + $sql .= $sqlalertstock.' >= 0 AND ('.$sqlalertstock.' > SUM('.$db->ifsql("s.reel IS NULL", "0", "s.reel").')'; + } $sql .= ' - ('.$sqlCommandesCli.' - '.$sqlExpeditionsCli.') + ('.$sqlCommandesFourn.' - '.$sqlReceptionFourn.') + ('.$sqlProductionToProduce.' - '.$sqlProductionToConsume.'))'; $sql .= ')'; $alertchecked = 'checked'; } } else { $sql .= ' HAVING (('.$sqldesiredtock.' >= 0 AND ('.$sqldesiredtock.' > SUM('.$db->ifsql("s.reel IS NULL", "0", "s.reel").')))'; - $sql .= ' OR ('.$sqlalertstock.' >= 0 AND ('.$sqlalertstock.' > SUM('.$db->ifsql("s.reel IS NULL", "0", "s.reel").'))))'; + if ($allalert == 'on') { + $sql .= ' OR (('.$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 .= ' OR ('.$sqlalertstock.' >= 0 AND ('.$sqlalertstock.' > SUM('.$db->ifsql("s.reel IS NULL", "0", "s.reel").'))))'; + } if ($salert == 'on') // Option to see when stock is lower than alert { - $sql .= ' AND ('.$sqlalertstock.' >= 0 AND ('.$sqlalertstock.' > SUM('.$db->ifsql("s.reel IS NULL", "0", "s.reel").')))'; + if ($allalert == 'on') { + $sql .= ' AND (('.$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 .= ' AND ('.$sqlalertstock.' >= 0 AND ('.$sqlalertstock.' > SUM('.$db->ifsql("s.reel IS NULL", "0", "s.reel").')))'; + } $alertchecked = 'checked'; } } +$allalertchecked = ''; +if ($allalert == 'on') { + $allalertchecked = 'checked'; +} + // Add where from hooks $parameters = array(); $reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters); // Note that $action and $object may have been modified by hook $sql .= $hookmanager->resPrint; +$nbtotalofrecords = ''; +if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) { + $result = $db->query($sql); + $nbtotalofrecords = $db->num_rows($result); + if (($page * $limit) > $nbtotalofrecords) { + $page = 0; + $offset = 0; + } +} + $sql .= $db->order($sortfield, $sortorder); $sql .= $db->plimit($limit + 1, $offset); @@ -514,8 +547,12 @@ print ''; print ''; print ''; print ''; +print ''; print ''; print ''; +if ($limit > 0 && $limit != $conf->liste_limit) { + print ''; +} if (!empty($conf->global->STOCK_ALLOW_ADD_LIMIT_STOCK_BY_WAREHOUSE)) { print '
'; @@ -536,6 +573,18 @@ print '
'; print ''; +print '
'; +print ''; +print ''; +print ''; +print ''; +print ''; +print ''; +print ''; +print ''; +print ''; + + if ($search_ref || $search_label || $sall || $salert || $draftorder || GETPOST('search', 'alpha')) { $filters = '&search_ref='.$search_ref.'&search_label='.$search_label; $filters .= '&sall='.$sall; @@ -575,11 +624,12 @@ if ($search_ref || $search_label || $sall || $salert || $draftorder || GETPOST(' ); } -print '
'; // You can use div-table-responsive-no-min if you dont need reserved height for your table -print ''; +if ($limit > 0 && $limit != $conf->liste_limit) { + $filters .= '&limit=' . urlencode($limit); +} $param = (isset($type) ? '&type='.$type : ''); -$param .= '&fourn_id='.$fourn_id.'&search_label='.$search_label.'&salert='.$salert.'&draftorder='.$draftorder; +$param .= '&fourn_id='.$fourn_id.'&search_label='.$search_label.'&allalert='.$allalert.'&salert='.$salert.'&draftorder='.$draftorder; $param .= '&search_ref='.$search_ref; $param .= '&mode='.$mode; $param .= '&fk_supplier='.$fk_supplier; @@ -590,18 +640,45 @@ if ($usevirtualstock == 1) $stocklabel = $langs->trans('VirtualStock'); if ($usevirtualstock == 0) $stocklabel = $langs->trans('PhysicalStock'); if (!empty($conf->global->STOCK_ALLOW_ADD_LIMIT_STOCK_BY_WAREHOUSE) && $fk_entrepot > 0) { - $stocklabel .= ' ('.$langs->trans("AllWarehouses").')'; + $stocklabel .= ' ('.$langs->trans("AllWarehouses").')'; } -print ''; -print ''; -print ''; -print ''; -print ''; -print ''; -print ''; -print ''; -print ''; -print ''; +$texte = $langs->trans('Replenishment'); + +print '
'; // You can use div-table-responsive-no-min if you dont need reserved height for your table + +if (!empty($conf->global->REPLENISH_ALLOW_VARIABLESIZELIST)) { + print_barre_liste( + $texte, + $page, + 'replenish.php', + $filters, + $sortfield, + $sortorder, + '', + $num, + $nbtotalofrecords, + 'object_stock.png', + 0, + '', + '', + $limit + ); +} else { + print_barre_liste( + $texte, + $page, + 'replenish.php', + $filters, + $sortfield, + $sortorder, + '', + $num, + $nbtotalofrecords, + 'object_stock.png' + ); +} + +print '
'; // Fields title search print ''; @@ -610,7 +687,7 @@ print ''; if (!empty($conf->service->enabled) && $type == 1) print ''; print ''; -print ''; +print ''; print ''; print ''; print '';
   '.$langs->trans('IncludeProductWithUndefinedAlerts').' '.$langs->trans('AlertOnly').' '.$langs->trans('IncludeAlsoDraftOrders').'