Skip to content

Commit

Permalink
FIX Replenishment with option STOCK_ALLOW_ADD_LIMIT_STOCK_BY_WAREHOUSE
Browse files Browse the repository at this point in the history
  • Loading branch information
eldy committed Dec 16, 2018
1 parent d8b5cd4 commit af4405c
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 23 deletions.
2 changes: 2 additions & 0 deletions htdocs/langs/en_US/stocks.lang
Expand Up @@ -29,6 +29,8 @@ MovementId=Movement ID
StockMovementForId=Movement ID %d
ListMouvementStockProject=List of stock movements associated to project
StocksArea=Warehouses area
AllWarehouses=All warehouses
IncludeAlsoDraftOrders=Include also draft orders
Location=Location
LocationSummary=Short name location
NumberOfDifferentProducts=Number of different products
Expand Down
49 changes: 26 additions & 23 deletions htdocs/product/stock/replenish.php
Expand Up @@ -288,22 +288,20 @@

$sql = 'SELECT p.rowid, p.ref, p.label, p.description, p.price,';
$sql.= ' p.price_ttc, p.price_base_type,p.fk_product_type,';
$sql.= ' p.tms as datem, p.duration, p.tobuy';
$sql.= ' ,p.desiredstock,p.seuil_stock_alerte';
if(!empty($conf->global->STOCK_ALLOW_ADD_LIMIT_STOCK_BY_WAREHOUSE) && $fk_entrepot > 0) {
$sql.= ', pse.desiredstock' ;
$sql.= ', pse.seuil_stock_alerte' ;
$sql.= ' p.tms as datem, p.duration, p.tobuy,';
$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 desiredstock, '.$sqlalertstock.' as alertstock,';

$sql.= ' '.$sqldesiredtock.' as desiredstockcombined, '.$sqlalertstock.' as seuil_stock_alertecombined,';
$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';
$sql.= ' ON (p.rowid = s.fk_product AND s.fk_entrepot IN (SELECT ent.rowid FROM '.MAIN_DB_PREFIX.'entrepot AS ent WHERE ent.entity IN('.getEntity('stock').')))';
if($fk_supplier > 0) {
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.')';
}
if(!empty($conf->global->STOCK_ALLOW_ADD_LIMIT_STOCK_BY_WAREHOUSE) && $fk_entrepot > 0) {
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 = '.$fk_entrepot.')';
}
$sql.= ' WHERE p.entity IN (' . getEntity('product') . ')';
Expand All @@ -325,7 +323,7 @@
$sql.= ', p.duration, p.tobuy';
$sql.= ', p.desiredstock';
$sql.= ', p.seuil_stock_alerte';
if(!empty($conf->global->STOCK_ALLOW_ADD_LIMIT_STOCK_BY_WAREHOUSE) && $fk_entrepot > 0) {
if (!empty($conf->global->STOCK_ALLOW_ADD_LIMIT_STOCK_BY_WAREHOUSE) && $fk_entrepot > 0) {
$sql.= ', pse.desiredstock' ;
$sql.= ', pse.seuil_stock_alerte' ;
}
Expand Down Expand Up @@ -364,7 +362,7 @@
$sqlReceptionFourn.= " AND fd.fk_product = p.rowid";
$sqlReceptionFourn.= " AND cf.fk_statut IN (3,4))";

$sql.= ' HAVING ((('.$db->ifsql($sqldesiredtock." IS NULL", "0", $sqldesiredtock).' > SUM('.$db->ifsql("s.reel IS NULL", "0", "s.reel").')';
$sql.= ' HAVING (('.$sqldesiredtock.' >= 0 AND ('.$sqldesiredtock.' > SUM('.$db->ifsql("s.reel IS NULL", "0", "s.reel").')';
$sql.= ' - ('.$sqlCommandesCli.' - '.$sqlExpeditionsCli.') + ('.$sqlCommandesFourn.' - '.$sqlReceptionFourn.')))';
$sql.= ' OR ('.$sqlalertstock.' >= 0 AND ('.$sqlalertstock.' > SUM('.$db->ifsql("s.reel IS NULL", "0", "s.reel").')';
$sql.= ' - ('.$sqlCommandesCli.' - '.$sqlExpeditionsCli.') + ('.$sqlCommandesFourn.' - '.$sqlReceptionFourn.'))))';
Expand Down Expand Up @@ -396,7 +394,6 @@
dol_print_error($db);
exit;
}
//print $sql;

$num = $db->num_rows($resql);
$i = 0;
Expand Down Expand Up @@ -505,9 +502,12 @@
$param .= '&fk_entrepot=' . $fk_entrepot;

$stocklabel = $langs->trans('Stock');
if ($usevirtualstock == 1) $stocklabel = 'VirtualStock';
if ($usevirtualstock == 0) $stocklabel = 'PhysicalStock';

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").')';
}
print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST" name="formulaire">'.
'<input type="hidden" name="token" value="' .$_SESSION['newtoken'] . '">'.
'<input type="hidden" name="fk_supplier" value="' . $fk_supplier . '">'.
Expand All @@ -528,7 +528,7 @@
print '<td class="liste_titre">&nbsp;</td>';
print '<td class="liste_titre" align="right">&nbsp;</td>';
print '<td class="liste_titre" align="right">' . $langs->trans('AlertOnly') . '&nbsp;<input type="checkbox" id="salert" name="salert" ' . (!empty($alertchecked)?$alertchecked:'') . '></td>';
print '<td class="liste_titre" align="right">' . $langs->trans('Draft') . '&nbsp;<input type="checkbox" id="draftorder" name="draftorder" ' . (!empty($draftchecked)?$draftchecked:'') . '></td>';
print '<td class="liste_titre" align="right">' . $langs->trans('IncludeAlsoDraftOrders') . '&nbsp;<input type="checkbox" id="draftorder" name="draftorder" ' . (!empty($draftchecked)?$draftchecked:'') . '></td>';
print '<td class="liste_titre">&nbsp;</td>';
print '<td class="liste_titre" align="right">';
$searchpicto=$form->showFilterAndCheckAddButtons(0);
Expand Down Expand Up @@ -600,20 +600,23 @@
//print $prod->stats_reception['qty'];
$ordered = $prod->stats_commande_fournisseur['qty'] - $prod->stats_reception['qty'];

$desiredstock=($objp->desiredstockpse ? $objp->desiredstockpse : $objp->desiredstock);
$alertstock=($objp->seuil_stock_alertepse ? $objp->seuil_stock_alertepse : $objp->seuil_stock_alerte);

$warning='';
if ($objp->alertstock && ($stock < $objp->alertstock))
if ($alertstock && ($stock < $alertstock))
{
$warning = img_warning($langs->trans('StockTooLow')) . ' ';
}

//depending on conf, use either physical stock or
//virtual stock to compute the stock to buy value
$stocktobuy = max(max($objp->desiredstock, $objp->alertstock) - $stock - $ordered, 0);
$stocktobuy = max(max($desiredstock, $alertstock) - $stock - $ordered, 0);
$disabled = '';
if ($ordered > 0)
{
$stockforcompare = $usevirtualstock ? $stock : $stock + $ordered;
if ($stockforcompare >= $objp->desiredstock)
if ($stockforcompare >= $desiredstock)
{
$picto = img_picto('', './img/yes', '', 1);
$disabled = 'disabled';
Expand Down Expand Up @@ -653,12 +656,12 @@
}

// Desired stock
print '<td align="right">' . $objp->desiredstock . '</td>';
print '<td align="right">' . $desiredstock . '</td>';

// Limit stock for alerr
print '<td align="right">' . $objp->alertstock . '</td>';
// Limit stock for alert
print '<td align="right">' . $alertstock . '</td>';

// Current stock
// Current stock (all warehouses)
print '<td align="right">'. $warning . $stock. '</td>';

// Already ordered
Expand Down

0 comments on commit af4405c

Please sign in to comment.