Merge pull request #13788 from simicar29/dev-replenish
NEW: Add option to include products without alert in replenish
This commit is contained in:
commit
c80f1c470f
@ -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 <b>%s</b> will be used for stock decrease
|
||||
WarehouseForStockIncrease=The warehouse <b>%s</b> will be used for stock increase
|
||||
ForThisWarehouse=For this warehouse
|
||||
|
||||
@ -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 '<input type="hidden" name="action" value="filter">';
|
||||
print '<input type="hidden" name="search_ref" value="'.$search_ref.'">';
|
||||
print '<input type="hidden" name="search_label" value="'.$search_label.'">';
|
||||
print '<input type="hidden" name="salert" value="'.$salert.'">';
|
||||
print '<input type="hidden" name="allalert" value="'.$allalert.'">';
|
||||
print '<input type="hidden" name="draftorder" value="'.$draftorder.'">';
|
||||
print '<input type="hidden" name="mode" value="'.$mode.'">';
|
||||
if ($limit > 0 && $limit != $conf->liste_limit) {
|
||||
print '<input type="hidden" name="limit" value="'.$limit.'">';
|
||||
}
|
||||
if (!empty($conf->global->STOCK_ALLOW_ADD_LIMIT_STOCK_BY_WAREHOUSE))
|
||||
{
|
||||
print '<div class="inline-block valignmiddle" style="padding-right: 20px;">';
|
||||
@ -536,6 +573,18 @@ print '</div>';
|
||||
|
||||
print '</form>';
|
||||
|
||||
print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST" name="formulaire">';
|
||||
print '<input type="hidden" name="token" value="'.newToken().'">';
|
||||
print '<input type="hidden" name="fk_supplier" value="'.$fk_supplier.'">';
|
||||
print '<input type="hidden" name="fk_entrepot" value="'.$fk_entrepot.'">';
|
||||
print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
|
||||
print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
|
||||
print '<input type="hidden" name="type" value="'.$type.'">';
|
||||
print '<input type="hidden" name="linecount" value="'.$num.'">';
|
||||
print '<input type="hidden" name="action" value="order">';
|
||||
print '<input type="hidden" name="mode" value="'.$mode.'">';
|
||||
|
||||
|
||||
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 '<div class="div-table-responsive">'; // You can use div-table-responsive-no-min if you dont need reserved height for your table
|
||||
print '<table class="liste centpercent">';
|
||||
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 '<form action="'.$_SERVER["PHP_SELF"].'" method="POST" name="formulaire">';
|
||||
print '<input type="hidden" name="token" value="'.newToken().'">';
|
||||
print '<input type="hidden" name="fk_supplier" value="'.$fk_supplier.'">';
|
||||
print '<input type="hidden" name="fk_entrepot" value="'.$fk_entrepot.'">';
|
||||
print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
|
||||
print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
|
||||
print '<input type="hidden" name="type" value="'.$type.'">';
|
||||
print '<input type="hidden" name="linecount" value="'.$num.'">';
|
||||
print '<input type="hidden" name="action" value="order">';
|
||||
print '<input type="hidden" name="mode" value="'.$mode.'">';
|
||||
$texte = $langs->trans('Replenishment');
|
||||
|
||||
print '<div class="div-table-responsive">'; // 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 '<table class="liste centpercent">';
|
||||
|
||||
// Fields title search
|
||||
print '<tr class="liste_titre_filter">';
|
||||
@ -610,7 +687,7 @@ print '<td class="liste_titre"><input class="flat" type="text" name="search_ref"
|
||||
print '<td class="liste_titre"><input class="flat" type="text" name="search_label" size="8" value="'.dol_escape_htmltag($search_label).'"></td>';
|
||||
if (!empty($conf->service->enabled) && $type == 1) print '<td class="liste_titre"> </td>';
|
||||
print '<td class="liste_titre"> </td>';
|
||||
print '<td class="liste_titre right"> </td>';
|
||||
print '<td class="liste_titre right">'.$langs->trans('IncludeProductWithUndefinedAlerts').' <input type="checkbox" id="allalert" name="allalert" '.(!empty($allalertchecked) ? $allalertchecked : '').'></td>';
|
||||
print '<td class="liste_titre right">'.$langs->trans('AlertOnly').' <input type="checkbox" id="salert" name="salert" '.(!empty($alertchecked) ? $alertchecked : '').'></td>';
|
||||
print '<td class="liste_titre right">'.$langs->trans('IncludeAlsoDraftOrders').' <input type="checkbox" id="draftorder" name="draftorder" '.(!empty($draftchecked) ? $draftchecked : '').'></td>';
|
||||
print '<td class="liste_titre"> </td>';
|
||||
|
||||
Loading…
Reference in New Issue
Block a user