Merge pull request #25056 from tiaris/FIX_24569

FIX #24569 filters on stockadate page
This commit is contained in:
Laurent Destailleur 2023-06-11 12:28:21 +02:00 committed by GitHub
commit a2b47ca55f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -130,8 +130,9 @@ if ($date && $dateIsValid) { // Avoid heavy sql if mandatory date is not defined
$sql .= " SUM(ps.reel) AS stock";
$sql .= " FROM ".MAIN_DB_PREFIX."product_stock as ps";
$sql .= ", ".MAIN_DB_PREFIX."entrepot as w";
$sql .= ", ".MAIN_DB_PREFIX."product as p";
$sql .= " WHERE w.entity IN (".getEntity('stock').")";
$sql .= " AND w.rowid = ps.fk_entrepot";
$sql .= " AND w.rowid = ps.fk_entrepot AND p.rowid = ps.fk_product ";
if (!empty($conf->global->ENTREPOT_EXTRA_STATUS) && count($warehouseStatus)) {
$sql .= " AND w.statut IN (".$db->sanitize(implode(',', $warehouseStatus)).")";
}
@ -141,6 +142,12 @@ if ($date && $dateIsValid) { // Avoid heavy sql if mandatory date is not defined
if ($fk_warehouse > 0) {
$sql .= " AND ps.fk_entrepot = ".((int) $fk_warehouse);
}
if ($search_ref) {
$sql .= " AND p.ref LIKE '%".$db->escape($search_ref)."%' ";
}
if ($search_nom) {
$sql .= " AND p.label LIKE '%".$db->escape($search_nom)."%' ";
}
$sql .= " GROUP BY fk_product, fk_entrepot";
//print $sql;
@ -180,8 +187,9 @@ if ($date && $dateIsValid) {
$sql = "SELECT sm.fk_product, sm.fk_entrepot, SUM(sm.value) AS stock, COUNT(sm.rowid) AS nbofmovement";
$sql .= " FROM ".MAIN_DB_PREFIX."stock_mouvement as sm";
$sql .= ", ".MAIN_DB_PREFIX."entrepot as w";
$sql .= ", ".MAIN_DB_PREFIX."product as p";
$sql .= " WHERE w.entity IN (".getEntity('stock').")";
$sql .= " AND w.rowid = sm.fk_entrepot";
$sql .= " AND w.rowid = sm.fk_entrepot AND p.rowid = sm.fk_product ";
if (!empty($conf->global->ENTREPOT_EXTRA_STATUS) && count($warehouseStatus)) {
$sql .= " AND w.statut IN (".$db->sanitize(implode(',', $warehouseStatus)).")";
}
@ -196,7 +204,14 @@ if ($date && $dateIsValid) {
if ($fk_warehouse > 0) {
$sql .= " AND sm.fk_entrepot = ".((int) $fk_warehouse);
}
if ($search_ref) {
$sql .= " AND p.ref LIKE '%".$db->escape($search_ref)."%' ";
}
if ($search_nom) {
$sql .= " AND p.label LIKE '%".$db->escape($search_nom)."%' ";
}
$sql .= " GROUP BY sm.fk_product, sm.fk_entrepot";
$resql = $db->query($sql);
if ($resql) {
@ -274,6 +289,12 @@ if (empty($conf->global->STOCK_SUPPORTS_SERVICES)) {
if (!empty($canvas)) {
$sql .= " AND p.canvas = '".$db->escape($canvas)."'";
}
if ($search_ref) {
$sql .= " AND p.ref LIKE '%".$db->escape($search_ref)."%' ";
}
if ($search_nom) {
$sql .= " AND p.label LIKE '%".$db->escape($search_nom)."%' ";
}
if ($fk_warehouse > 0) {
$sql .= ' GROUP BY p.rowid, p.ref, p.label, p.description, p.price, p.price_ttc, p.price_base_type, p.fk_product_type, p.desiredstock, p.seuil_stock_alerte,';
$sql .= ' p.tms, p.duration, p.tobuy, p.stock';