FIX Replenishment with option STOCK_ALLOW_ADD_LIMIT_STOCK_BY_WAREHOUSE
This commit is contained in:
parent
d8b5cd4bdf
commit
af4405c669
@ -29,6 +29,8 @@ MovementId=Movement ID
|
|||||||
StockMovementForId=Movement ID %d
|
StockMovementForId=Movement ID %d
|
||||||
ListMouvementStockProject=List of stock movements associated to project
|
ListMouvementStockProject=List of stock movements associated to project
|
||||||
StocksArea=Warehouses area
|
StocksArea=Warehouses area
|
||||||
|
AllWarehouses=All warehouses
|
||||||
|
IncludeAlsoDraftOrders=Include also draft orders
|
||||||
Location=Location
|
Location=Location
|
||||||
LocationSummary=Short name location
|
LocationSummary=Short name location
|
||||||
NumberOfDifferentProducts=Number of different products
|
NumberOfDifferentProducts=Number of different products
|
||||||
|
|||||||
@ -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 = '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.price_ttc, p.price_base_type,p.fk_product_type,';
|
||||||
$sql.= ' p.tms as datem, p.duration, p.tobuy';
|
$sql.= ' p.tms as datem, p.duration, p.tobuy,';
|
||||||
$sql.= ' ,p.desiredstock,p.seuil_stock_alerte';
|
$sql.= ' p.desiredstock, 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.desiredstock as desiredstockpse, pse.seuil_stock_alerte as seuil_stock_alertepse,';
|
||||||
$sql.= ', pse.seuil_stock_alerte' ;
|
|
||||||
}
|
}
|
||||||
$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.= ' SUM('.$db->ifsql("s.reel IS NULL", "0", "s.reel").') as stock_physique';
|
||||||
$sql.= ' FROM ' . MAIN_DB_PREFIX . 'product as p';
|
$sql.= ' FROM ' . MAIN_DB_PREFIX . 'product as p';
|
||||||
$sql.= ' LEFT JOIN ' . MAIN_DB_PREFIX . 'product_stock as s';
|
$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').')))';
|
$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.')';
|
$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.= ' 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') . ')';
|
$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.duration, p.tobuy';
|
||||||
$sql.= ', p.desiredstock';
|
$sql.= ', p.desiredstock';
|
||||||
$sql.= ', p.seuil_stock_alerte';
|
$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.desiredstock' ;
|
||||||
$sql.= ', pse.seuil_stock_alerte' ;
|
$sql.= ', pse.seuil_stock_alerte' ;
|
||||||
}
|
}
|
||||||
@ -364,7 +362,7 @@ if ($usevirtualstock)
|
|||||||
$sqlReceptionFourn.= " AND fd.fk_product = p.rowid";
|
$sqlReceptionFourn.= " AND fd.fk_product = p.rowid";
|
||||||
$sqlReceptionFourn.= " AND cf.fk_statut IN (3,4))";
|
$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.= ' - ('.$sqlCommandesCli.' - '.$sqlExpeditionsCli.') + ('.$sqlCommandesFourn.' - '.$sqlReceptionFourn.')))';
|
||||||
$sql.= ' OR ('.$sqlalertstock.' >= 0 AND ('.$sqlalertstock.' > 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").')';
|
||||||
$sql.= ' - ('.$sqlCommandesCli.' - '.$sqlExpeditionsCli.') + ('.$sqlCommandesFourn.' - '.$sqlReceptionFourn.'))))';
|
$sql.= ' - ('.$sqlCommandesCli.' - '.$sqlExpeditionsCli.') + ('.$sqlCommandesFourn.' - '.$sqlReceptionFourn.'))))';
|
||||||
@ -396,7 +394,6 @@ if (empty($resql))
|
|||||||
dol_print_error($db);
|
dol_print_error($db);
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
//print $sql;
|
|
||||||
|
|
||||||
$num = $db->num_rows($resql);
|
$num = $db->num_rows($resql);
|
||||||
$i = 0;
|
$i = 0;
|
||||||
@ -505,9 +502,12 @@ $param .= '&fk_supplier=' . $fk_supplier;
|
|||||||
$param .= '&fk_entrepot=' . $fk_entrepot;
|
$param .= '&fk_entrepot=' . $fk_entrepot;
|
||||||
|
|
||||||
$stocklabel = $langs->trans('Stock');
|
$stocklabel = $langs->trans('Stock');
|
||||||
if ($usevirtualstock == 1) $stocklabel = 'VirtualStock';
|
if ($usevirtualstock == 1) $stocklabel = $langs->trans('VirtualStock');
|
||||||
if ($usevirtualstock == 0) $stocklabel = 'PhysicalStock';
|
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">'.
|
print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST" name="formulaire">'.
|
||||||
'<input type="hidden" name="token" value="' .$_SESSION['newtoken'] . '">'.
|
'<input type="hidden" name="token" value="' .$_SESSION['newtoken'] . '">'.
|
||||||
'<input type="hidden" name="fk_supplier" value="' . $fk_supplier . '">'.
|
'<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"> </td>';
|
print '<td class="liste_titre"> </td>';
|
||||||
print '<td class="liste_titre" align="right"> </td>';
|
print '<td class="liste_titre" align="right"> </td>';
|
||||||
print '<td class="liste_titre" align="right">' . $langs->trans('AlertOnly') . ' <input type="checkbox" id="salert" name="salert" ' . (!empty($alertchecked)?$alertchecked:'') . '></td>';
|
print '<td class="liste_titre" align="right">' . $langs->trans('AlertOnly') . ' <input type="checkbox" id="salert" name="salert" ' . (!empty($alertchecked)?$alertchecked:'') . '></td>';
|
||||||
print '<td class="liste_titre" align="right">' . $langs->trans('Draft') . ' <input type="checkbox" id="draftorder" name="draftorder" ' . (!empty($draftchecked)?$draftchecked:'') . '></td>';
|
print '<td class="liste_titre" align="right">' . $langs->trans('IncludeAlsoDraftOrders') . ' <input type="checkbox" id="draftorder" name="draftorder" ' . (!empty($draftchecked)?$draftchecked:'') . '></td>';
|
||||||
print '<td class="liste_titre"> </td>';
|
print '<td class="liste_titre"> </td>';
|
||||||
print '<td class="liste_titre" align="right">';
|
print '<td class="liste_titre" align="right">';
|
||||||
$searchpicto=$form->showFilterAndCheckAddButtons(0);
|
$searchpicto=$form->showFilterAndCheckAddButtons(0);
|
||||||
@ -600,20 +600,23 @@ while ($i < ($limit ? min($num, $limit) : $num))
|
|||||||
//print $prod->stats_reception['qty'];
|
//print $prod->stats_reception['qty'];
|
||||||
$ordered = $prod->stats_commande_fournisseur['qty'] - $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='';
|
$warning='';
|
||||||
if ($objp->alertstock && ($stock < $objp->alertstock))
|
if ($alertstock && ($stock < $alertstock))
|
||||||
{
|
{
|
||||||
$warning = img_warning($langs->trans('StockTooLow')) . ' ';
|
$warning = img_warning($langs->trans('StockTooLow')) . ' ';
|
||||||
}
|
}
|
||||||
|
|
||||||
//depending on conf, use either physical stock or
|
//depending on conf, use either physical stock or
|
||||||
//virtual stock to compute the stock to buy value
|
//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 = '';
|
$disabled = '';
|
||||||
if ($ordered > 0)
|
if ($ordered > 0)
|
||||||
{
|
{
|
||||||
$stockforcompare = $usevirtualstock ? $stock : $stock + $ordered;
|
$stockforcompare = $usevirtualstock ? $stock : $stock + $ordered;
|
||||||
if ($stockforcompare >= $objp->desiredstock)
|
if ($stockforcompare >= $desiredstock)
|
||||||
{
|
{
|
||||||
$picto = img_picto('', './img/yes', '', 1);
|
$picto = img_picto('', './img/yes', '', 1);
|
||||||
$disabled = 'disabled';
|
$disabled = 'disabled';
|
||||||
@ -653,12 +656,12 @@ while ($i < ($limit ? min($num, $limit) : $num))
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Desired stock
|
// Desired stock
|
||||||
print '<td align="right">' . $objp->desiredstock . '</td>';
|
print '<td align="right">' . $desiredstock . '</td>';
|
||||||
|
|
||||||
// Limit stock for alerr
|
// Limit stock for alert
|
||||||
print '<td align="right">' . $objp->alertstock . '</td>';
|
print '<td align="right">' . $alertstock . '</td>';
|
||||||
|
|
||||||
// Current stock
|
// Current stock (all warehouses)
|
||||||
print '<td align="right">'. $warning . $stock. '</td>';
|
print '<td align="right">'. $warning . $stock. '</td>';
|
||||||
|
|
||||||
// Already ordered
|
// Already ordered
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user