diff --git a/htdocs/langs/en_US/stocks.lang b/htdocs/langs/en_US/stocks.lang index 08992207628..7a08148c9ce 100644 --- a/htdocs/langs/en_US/stocks.lang +++ b/htdocs/langs/en_US/stocks.lang @@ -62,8 +62,8 @@ OrderStatusNotReadyToDispatch=Order has not yet or no more a status that allows StockDiffPhysicTeoric=Reason for difference stock physical and theoretical NoPredefinedProductToDispatch=No predefined products for this object. So no dispatching in stock is required. DispatchVerb=Dispatch -StockLimitShort=Limit -StockLimit=Stock limit for alerts +StockLimitShort=Limit for alert +StockLimit=Stock limit for alert PhysicalStock=Physical stock RealStock=Real Stock VirtualStock=Virtual stock diff --git a/htdocs/product/stock/replenish.php b/htdocs/product/stock/replenish.php index fc3591efc71..6aee0bada53 100644 --- a/htdocs/product/stock/replenish.php +++ b/htdocs/product/stock/replenish.php @@ -64,7 +64,7 @@ if (!$sortorder) { $limit = $conf->liste_limit; $offset = $limit * $page ; -// Force limit to non (currently solution to solve loosing selection when using pagination. No pagination on this page) +// Force limit to no (currently solution to solve loosing selection when using pagination. No pagination on this page) $limit = 0; @@ -190,9 +190,10 @@ if ($action == 'order' && isset($_POST['valid'])) $form = new Form($db); $virtualdiffersfromphysical=0; -if (! empty($conf->global->STOCK_CALCULATE_ON_SHIPMENT) - || ! empty($conf->global->STOCK_CALCULATE_ON_SUPPLIER_DISPATCH_ORDER) - ) $virtualdiffersfromphysical=1; // According to increase/decrease stock options, virtual and physical stock may differs. +if (! empty($conf->global->STOCK_CALCULATE_ON_SHIPMENT) || ! empty($conf->global->STOCK_CALCULATE_ON_SUPPLIER_DISPATCH_ORDER)) +{ + $virtualdiffersfromphysical=1; // According to increase/decrease stock options, virtual and physical stock may differs. +} $usevirtualstock=-1; if ($virtualdiffersfromphysical) @@ -206,8 +207,8 @@ $title = $langs->trans('Status'); $sql = 'SELECT p.rowid, p.ref, p.label, p.price,'; $sql.= ' p.price_ttc, p.price_base_type,p.fk_product_type,'; -$sql.= ' p.tms as datem, p.duration, p.tobuy, p.seuil_stock_alerte,'; -$sql.= ' p.desiredstock,'; +$sql.= ' p.tms as datem, p.duration, p.tobuy,'; +$sql.= ' p.desiredstock, p.seuil_stock_alerte as alertstock,'; $sql.= ' SUM('.$db->ifsql("s.reel IS NULL", "0", "s.reel").') as stock_physique'; $sql.= ' FROM ' . MAIN_DB_PREFIX . 'product as p'; $sql.= ' LEFT JOIN ' . MAIN_DB_PREFIX . 'product_stock as s'; @@ -245,10 +246,12 @@ $sql.= ' AND p.tobuy = 1'; if (!empty($canvas)) $sql .= ' AND p.canvas = "' . $db->escape($canvas) . '"'; $sql.= ' GROUP BY p.rowid, p.ref, p.label, p.price'; $sql.= ', p.price_ttc, p.price_base_type,p.fk_product_type, p.tms'; -$sql.= ', p.duration, p.tobuy, p.seuil_stock_alerte'; -$sql.= ', p.desiredstock, s.fk_product'; +$sql.= ', p.duration, p.tobuy'; +$sql.= ', p.desiredstock, p.seuil_stock_alerte'; +$sql.= ', s.fk_product'; -if($usevirtualstock) { +if ($usevirtualstock) +{ $sqlCommandesCli = "(SELECT SUM(cd.qty) as qty"; $sqlCommandesCli.= " FROM ".MAIN_DB_PREFIX."commandedet as cd"; $sqlCommandesCli.= ", ".MAIN_DB_PREFIX."commande as c"; @@ -265,11 +268,14 @@ if($usevirtualstock) { $sqlCommandesFourn.= " AND cd.fk_product = p.rowid"; $sqlCommandesFourn.= " AND c.fk_statut in (3))"; - $sql.= ' HAVING p.desiredstock > SUM('.$db->ifsql("s.reel IS NULL", "0", "s.reel").')'; - $sql.= ' - '.$db->ifsql($sqlCommandesCli.' IS NULL', '0', $sqlCommandesCli).' + '.$db->ifsql($sqlCommandesFourn.' IS NULL', '0', $sqlCommandesFourn); + $sql.= ' HAVING ((p.desiredstock > 0 AND p.desiredstock > (SUM('.$db->ifsql("s.reel IS NULL", "0", "s.reel").')'; + $sql.= ' - '.$db->ifsql($sqlCommandesCli.' IS NULL', '0', $sqlCommandesCli).' + '.$db->ifsql($sqlCommandesFourn.' IS NULL', '0', $sqlCommandesFourn).'))'; + + $sql.= ' OR (p.seuil_stock_alerte > 0 AND p.seuil_stock_alerte > (SUM('.$db->ifsql("s.reel IS NULL", "0", "s.reel").')'; + $sql.= ' - '.$db->ifsql($sqlCommandesCli.' IS NULL', '0', $sqlCommandesCli).' + '.$db->ifsql($sqlCommandesFourn.' IS NULL', '0', $sqlCommandesFourn).'))'; + $sql.= " )"; } else { - $sql.= ' HAVING p.desiredstock > SUM('.$db->ifsql("s.reel IS NULL", "0", "s.reel").')'; - $sql.= ' AND p.desiredstock > 0'; + $sql.= ' HAVING ((p.desiredstock > 0 AND (p.desiredstock > SUM('.$db->ifsql("s.reel IS NULL", "0", "s.reel").'))) OR (p.seuil_stock_alerte > 0 AND (seuil_stock_alerte > SUM('.$db->ifsql("s.reel IS NULL", "0", "s.reel").'))))'; } if ($salert == 'on') // Option to see when stock is lower than alert { @@ -277,8 +283,9 @@ if ($salert == 'on') // Option to see when stock is lower than alert $alertchecked = 'checked="checked"'; } $sql.= $db->order($sortfield,$sortorder); -$sql.= $db->plimit($limit + 1, $offset); +$sql.= $db->plimit($limit, $offset); +//print $sql; dol_syslog('Execute request sql='.$sql); $resql = $db->query($sql); if (empty($resql)) @@ -286,6 +293,7 @@ if (empty($resql)) dol_print_error($db); exit; } +//print $sql; $num = $db->num_rows($resql); $i = 0; @@ -339,7 +347,7 @@ if ($sref || $snom || $sall || $salert || GETPOST('search', 'alpha')) { $filters = '&sref=' . $sref . '&snom=' . $snom; $filters .= '&fourn_id=' . $fourn_id; $filters .= (isset($type)?'&type=' . $type:''); - $filters .= '&salert=' . $salert; + $filters .= '&=' . $salert; $filters .= '&mode=' . $mode; print_barre_liste( $texte, @@ -368,121 +376,42 @@ $param .= '&fourn_id=' . $fourn_id . '&snom='. $snom . '&salert=' . $salert; $param .= '&sref=' . $sref; $param .= '&mode=' . $mode; -// Lines of title -print '