From 552a1a33c27d59e91e48026e1f834fda4df35187 Mon Sep 17 00:00:00 2001 From: guillermo Date: Mon, 11 Mar 2024 12:38:52 +0100 Subject: [PATCH 1/2] hotfix: itemProposal --- db/routines/vn/procedures/itemProposal.sql | 28 +++++++++++----------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/db/routines/vn/procedures/itemProposal.sql b/db/routines/vn/procedures/itemProposal.sql index 47a4e9779..d0d98fed7 100644 --- a/db/routines/vn/procedures/itemProposal.sql +++ b/db/routines/vn/procedures/itemProposal.sql @@ -19,17 +19,17 @@ BEGIN DECLARE vTypeFk INT; DECLARE vPriority INT DEFAULT 1; - DECLARE vTag1 VARCHAR(25) CHARACTER SET 'utf8' COLLATE 'utf8_unicode_ci'; - DECLARE vTag5 VARCHAR(25) CHARACTER SET 'utf8' COLLATE 'utf8_unicode_ci'; - DECLARE vTag6 VARCHAR(25) CHARACTER SET 'utf8' COLLATE 'utf8_unicode_ci'; - DECLARE vTag7 VARCHAR(25) CHARACTER SET 'utf8' COLLATE 'utf8_unicode_ci'; - DECLARE vTag8 VARCHAR(25) CHARACTER SET 'utf8' COLLATE 'utf8_unicode_ci'; - - DECLARE vValue1 VARCHAR(50) CHARACTER SET 'utf8' COLLATE 'utf8_unicode_ci'; - DECLARE vValue5 VARCHAR(50) CHARACTER SET 'utf8' COLLATE 'utf8_unicode_ci'; - DECLARE vValue6 VARCHAR(50) CHARACTER SET 'utf8' COLLATE 'utf8_unicode_ci'; - DECLARE vValue7 VARCHAR(50) CHARACTER SET 'utf8' COLLATE 'utf8_unicode_ci'; - DECLARE vValue8 VARCHAR(50) CHARACTER SET 'utf8' COLLATE 'utf8_unicode_ci'; + DECLARE vTag1 VARCHAR(20) COLLATE 'utf8_unicode_ci'; + DECLARE vTag5 VARCHAR(20) COLLATE 'utf8_unicode_ci'; + DECLARE vTag6 VARCHAR(20) COLLATE 'utf8_unicode_ci'; + DECLARE vTag7 VARCHAR(20) COLLATE 'utf8_unicode_ci'; + DECLARE vTag8 VARCHAR(20) COLLATE 'utf8_unicode_ci'; + + DECLARE vValue1 VARCHAR(50) COLLATE 'utf8_unicode_ci'; + DECLARE vValue5 VARCHAR(50) COLLATE 'utf8_unicode_ci'; + DECLARE vValue6 VARCHAR(50) COLLATE 'utf8_unicode_ci'; + DECLARE vValue7 VARCHAR(50) COLLATE 'utf8_unicode_ci'; + DECLARE vValue8 VARCHAR(50) COLLATE 'utf8_unicode_ci'; SELECT warehouseFk, shipped INTO vWarehouseFk, vShipped @@ -86,7 +86,8 @@ BEGIN IF(b.groupingMode = 1, b.grouping, b.packing) minQuantity, iss.visible located FROM item i - JOIN cache.available a ON a.item_id = i.id + STRAIGHT_JOIN cache.available a ON a.item_id = i.id + AND a.calc_id = vCalcFk LEFT JOIN itemProposal ip ON ip.mateFk = i.id AND ip.itemFk = vSelf LEFT JOIN itemTag it ON it.itemFk = i.id @@ -97,8 +98,7 @@ BEGIN LEFT JOIN buy b ON b.id = lb.buy_id LEFT JOIN itemShelvingStock iss ON iss.itemFk = i.id AND iss.warehouseFk = vWarehouseFk - WHERE a.calc_id = vCalcFk - AND a.available > 0 + WHERE a.available > 0 AND IF(vShowType, i.typeFk = vTypeFk, TRUE) AND i.id <> vSelf ORDER BY `counter` DESC, From 319bf314b3ba848299de4c71e4f927a7dccabbb0 Mon Sep 17 00:00:00 2001 From: guillermo Date: Wed, 13 Mar 2024 07:38:14 +0100 Subject: [PATCH 2/2] hotfix: itemProposal --- db/routines/vn/procedures/itemProposal.sql | 96 +++++++++------------- 1 file changed, 38 insertions(+), 58 deletions(-) diff --git a/db/routines/vn/procedures/itemProposal.sql b/db/routines/vn/procedures/itemProposal.sql index d0d98fed7..eb8a7ab33 100644 --- a/db/routines/vn/procedures/itemProposal.sql +++ b/db/routines/vn/procedures/itemProposal.sql @@ -19,98 +19,78 @@ BEGIN DECLARE vTypeFk INT; DECLARE vPriority INT DEFAULT 1; - DECLARE vTag1 VARCHAR(20) COLLATE 'utf8_unicode_ci'; - DECLARE vTag5 VARCHAR(20) COLLATE 'utf8_unicode_ci'; - DECLARE vTag6 VARCHAR(20) COLLATE 'utf8_unicode_ci'; - DECLARE vTag7 VARCHAR(20) COLLATE 'utf8_unicode_ci'; - DECLARE vTag8 VARCHAR(20) COLLATE 'utf8_unicode_ci'; - - DECLARE vValue1 VARCHAR(50) COLLATE 'utf8_unicode_ci'; - DECLARE vValue5 VARCHAR(50) COLLATE 'utf8_unicode_ci'; - DECLARE vValue6 VARCHAR(50) COLLATE 'utf8_unicode_ci'; - DECLARE vValue7 VARCHAR(50) COLLATE 'utf8_unicode_ci'; - DECLARE vValue8 VARCHAR(50) COLLATE 'utf8_unicode_ci'; - SELECT warehouseFk, shipped INTO vWarehouseFk, vShipped FROM ticket WHERE id = vTicketFk; - SELECT typeFk, - tag5, - value5, - tag6, - value6, - tag7, - value7, - tag8, - value8, - t.name, - it.value - INTO vTypeFk, - vTag5, - vValue5, - vTag6, - vValue6, - vTag7, - vValue7, - vTag8, - vValue8, - vTag1, - vValue1 - FROM item i - LEFT JOIN itemTag it ON it.itemFk = i.id - AND it.priority = vPriority - LEFT JOIN tag t ON t.id = it.tagFk - WHERE i.id = vSelf; - CALL cache.available_refresh(vCalcFk, FALSE, vWarehouseFk, vShipped); + WITH itemTags AS ( + SELECT i.id, + typeFk, + tag5, + value5, + tag6, + value6, + tag7, + value7, + tag8, + value8, + t.name, + it.value + FROM vn.item i + LEFT JOIN vn.itemTag it ON it.itemFk = i.id + AND it.priority = vPriority + LEFT JOIN vn.tag t ON t.id = it.tagFk + WHERE i.id = vSelf + ) SELECT i.id itemFk, i.longName, i.subName, i.tag5, i.value5, - (i.value5 <=> vValue5) match5, + (i.value5 <=> its.value5) match5, i.tag6, i.value6, - (i.value6 <=> vValue6) match6, + (i.value6 <=> its.value6) match6, i.tag7, i.value7, - (i.value7 <=> vValue7) match7, + (i.value7 <=> its.value7) match7, i.tag8, i.value8, - (i.value8 <=> vValue8) match8, + (i.value8 <=> its.value8) match8, a.available, IFNULL(ip.counter, 0) `counter`, IF(b.groupingMode = 1, b.grouping, b.packing) minQuantity, iss.visible located - FROM item i - STRAIGHT_JOIN cache.available a ON a.item_id = i.id + FROM vn.item i + JOIN cache.available a ON a.item_id = i.id AND a.calc_id = vCalcFk - LEFT JOIN itemProposal ip ON ip.mateFk = i.id + LEFT JOIN vn.itemProposal ip ON ip.mateFk = i.id AND ip.itemFk = vSelf - LEFT JOIN itemTag it ON it.itemFk = i.id + LEFT JOIN vn.itemTag it ON it.itemFk = i.id AND it.priority = vPriority - LEFT JOIN tag t ON t.id = it.tagFk + LEFT JOIN vn.tag t ON t.id = it.tagFk LEFT JOIN cache.last_buy lb ON lb.item_id = i.id AND lb.warehouse_id = vWarehouseFk - LEFT JOIN buy b ON b.id = lb.buy_id - LEFT JOIN itemShelvingStock iss ON iss.itemFk = i.id + LEFT JOIN vn.buy b ON b.id = lb.buy_id + LEFT JOIN vn.itemShelvingStock iss ON iss.itemFk = i.id AND iss.warehouseFk = vWarehouseFk + JOIN itemTags its WHERE a.available > 0 - AND IF(vShowType, i.typeFk = vTypeFk, TRUE) + AND IF(vShowType, i.typeFk = its.typeFk, TRUE) AND i.id <> vSelf ORDER BY `counter` DESC, - (t.name = vTag1) DESC, - (it.value = vValue1) DESC, - (i.tag5 = vTag5) DESC, + (t.name = its.name) DESC, + (it.value = its.value) DESC, + (i.tag5 = its.tag5) DESC, match5 DESC, - (i.tag6 = vTag6) DESC, + (i.tag6 = its.tag6) DESC, match6 DESC, - (i.tag7 = vTag7) DESC, + (i.tag7 = its.tag7) DESC, match7 DESC, - (i.tag8 = vTag8) DESC, + (i.tag8 = its.tag8) DESC, match8 DESC; END$$ DELIMITER ;