FIX Replenishment with option STOCK_ALLOW_ADD_LIMIT_STOCK_BY_WAREHOUSE

This commit is contained in:
Laurent Destailleur 2018-12-16 20:29:08 +01:00
parent d8b5cd4bdf
commit af4405c669
2 changed files with 28 additions and 23 deletions

View File

@ -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

View File

@ -288,22 +288,20 @@ if (!empty($conf->global->STOCK_ALLOW_ADD_LIMIT_STOCK_BY_WAREHOUSE) && $fk_entre
$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') . ')';
@ -325,7 +323,7 @@ $sql.= ', p.price_ttc, p.price_base_type,p.fk_product_type, p.tms';
$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' ;
}
@ -364,7 +362,7 @@ if ($usevirtualstock)
$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.'))))';
@ -396,7 +394,6 @@ if (empty($resql))
dol_print_error($db);
exit;
}
//print $sql;
$num = $db->num_rows($resql);
$i = 0;
@ -505,9 +502,12 @@ $param .= '&fk_supplier=' . $fk_supplier;
$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 . '">'.
@ -528,7 +528,7 @@ if (!empty($conf->service->enabled) && $type == 1) print '<td class="liste_titre
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);
@ -600,20 +600,23 @@ while ($i < ($limit ? min($num, $limit) : $num))
//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';
@ -653,12 +656,12 @@ while ($i < ($limit ? min($num, $limit) : $num))
}
// 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