From 4f9552379ed043f5d334e588fc9678085e7a9929 Mon Sep 17 00:00:00 2001 From: robert Date: Wed, 3 Jul 2024 13:46:19 +0200 Subject: [PATCH 1/2] feat: refs #7654 entry_splitByShelving --- .../vn/procedures/entry_splitByShelving.sql | 170 ++++++++---------- .../11131-brownPhormium/00-firstScript.sql | 1 + 2 files changed, 80 insertions(+), 91 deletions(-) create mode 100644 db/versions/11131-brownPhormium/00-firstScript.sql diff --git a/db/routines/vn/procedures/entry_splitByShelving.sql b/db/routines/vn/procedures/entry_splitByShelving.sql index 2898141ea..839bf02d1 100644 --- a/db/routines/vn/procedures/entry_splitByShelving.sql +++ b/db/routines/vn/procedures/entry_splitByShelving.sql @@ -9,70 +9,81 @@ BEGIN * @param vToEntryFk Entrada destino */ DECLARE vBuyFk INT; - DECLARE vIshStickers INT; - DECLARE vBuyStickers INT; - DECLARE vDone BOOLEAN DEFAULT FALSE; - - DECLARE cur CURSOR FOR - SELECT bb.id buyFk, - FLOOR(ish.visible / ish.packing) ishStickers, - bb.stickers buyStickers - FROM vn.itemShelving ish - JOIN (SELECT b.id, b.itemFk, b.stickers - FROM vn.buy b - WHERE b.entryFk = vFromEntryFk - ORDER BY b.stickers DESC - LIMIT 10000000000000000000) bb ON bb.itemFk = ish.itemFk - AND bb.stickers >= FLOOR(ish.visible / ish.packing) - WHERE shelvingFk = vShelvingFk COLLATE utf8_general_ci - GROUP BY ish.id; - - DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone = TRUE; + DECLARE vIshStickers INT; + DECLARE vBuyStickers INT; + DECLARE vDone BOOLEAN DEFAULT FALSE; - -- Cantidades de la matrĂ­cula que exceden la de las entradas - SELECT ish.itemFk, - i.longName, - FLOOR(ish.visible / ish.packing) AS etiEnMatricula, - bb.stickers etiEnEntrada - FROM vn.itemShelving ish - JOIN vn.item i ON i.id = ish.itemFk - LEFT JOIN (SELECT b.id, b.itemFk, b.stickers - FROM vn.buy b - WHERE b.entryFk = vFromEntryFk - ORDER BY b.stickers DESC - LIMIT 10000000000000000000) bb ON bb.itemFk = ish.itemFk - WHERE shelvingFk = vShelvingFk COLLATE utf8_general_ci - AND IFNULL(bb.stickers,0) < FLOOR(ish.visible / ish.packing) - GROUP BY ish.id; - - OPEN cur; - - read_loop: LOOP - SET vDone = FALSE; + DECLARE cur CURSOR FOR + SELECT bb.id buyFk, + FLOOR(ish.visible / ish.packing) ishStickers, + bb.stickers buyStickers + FROM itemShelving ish + JOIN (SELECT b.id, b.itemFk, b.stickers + FROM buy b + WHERE b.entryFk = vFromEntryFk + ORDER BY b.stickers DESC + LIMIT 10000000000000000000) bb ON bb.itemFk = ish.itemFk + AND bb.stickers >= FLOOR(ish.visible / ish.packing) + WHERE ish.shelvingFk = vShelvingFk COLLATE utf8_general_ci + AND NOT ish.isSplit + GROUP BY ish.id; + + DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone = TRUE; - FETCH cur INTO vBuyFk, vIshStickers, vBuyStickers; + OPEN cur; - IF vDone THEN - LEAVE read_loop; - END IF; + read_loop: LOOP + SET vDone = FALSE; - IF vIshStickers = vBuyStickers THEN - UPDATE vn.buy - SET entryFk = vToEntryFk - WHERE id = vBuyFk; - ELSE - UPDATE vn.buy - SET stickers = stickers - vIshStickers, - quantity = stickers * packing - WHERE id = vBuyFk; - - INSERT INTO vn.buy(entryFk, + FETCH cur INTO vBuyFk, vIshStickers, vBuyStickers; + + IF vDone THEN + LEAVE read_loop; + END IF; + + IF vIshStickers = vBuyStickers THEN + UPDATE buy + SET entryFk = vToEntryFk + WHERE id = vBuyFk; + ELSE + UPDATE buy + SET stickers = stickers - vIshStickers, + quantity = stickers * packing + WHERE id = vBuyFk; + + INSERT INTO buy(entryFk, + itemFk, + quantity, + buyingValue, + freightValue, + isIgnored, + stickers, + packing, + `grouping`, + groupingMode, + comissionValue, + packageValue, + location, + packagingFk, + price1, + price2, + price3, + minPrice, + workerFk, + isChecked, + isPickedOff, + ektFk, + weight, + deliveryFk, + itemOriginalFk) + SELECT + vToEntryFk, itemFk, - quantity, + vIshStickers * packing, buyingValue, freightValue, isIgnored, - stickers, + vIshStickers, packing, `grouping`, groupingMode, @@ -90,40 +101,17 @@ BEGIN ektFk, weight, deliveryFk, - itemOriginalFk) - SELECT - vToEntryFk, - itemFk, - vIshStickers * packing, - buyingValue, - freightValue, - isIgnored, - vIshStickers, - packing, - `grouping`, - groupingMode, - comissionValue, - packageValue, - location, - packagingFk, - price1, - price2, - price3, - minPrice, - workerFk, - isChecked, - isPickedOff, - ektFk, - weight, - deliveryFk, - itemOriginalFk - FROM vn.buy - WHERE id = vBuyFk; - - UPDATE buy SET printedStickers = vIshStickers WHERE id = LAST_INSERT_ID(); - END IF; - END LOOP; - - CLOSE cur; + itemOriginalFk + FROM buy + WHERE id = vBuyFk; + + UPDATE buy SET printedStickers = vIshStickers WHERE id = LAST_INSERT_ID(); + END IF; + + UPDATE itemShelving + SET isSplit = TRUE + WHERE shelvingFk = vShelvingFk; + END LOOP; + CLOSE cur; END$$ DELIMITER ; diff --git a/db/versions/11131-brownPhormium/00-firstScript.sql b/db/versions/11131-brownPhormium/00-firstScript.sql new file mode 100644 index 000000000..341c9f1a3 --- /dev/null +++ b/db/versions/11131-brownPhormium/00-firstScript.sql @@ -0,0 +1 @@ +ALTER TABLE vn.itemShelving ADD isSplit tinyint(1) NULL COMMENT 'Este valor cambia al splitar un carro que se ha quedado en holanda'; \ No newline at end of file -- 2.40.1 From 897da1e48a70570d6fc172f301b7ac347bc84622 Mon Sep 17 00:00:00 2001 From: robert Date: Thu, 4 Jul 2024 08:59:22 +0200 Subject: [PATCH 2/2] feat: refs #7654 --- .../vn/procedures/entry_splitByShelving.sql | 164 +++++++++--------- 1 file changed, 82 insertions(+), 82 deletions(-) diff --git a/db/routines/vn/procedures/entry_splitByShelving.sql b/db/routines/vn/procedures/entry_splitByShelving.sql index 839bf02d1..eb07c12b7 100644 --- a/db/routines/vn/procedures/entry_splitByShelving.sql +++ b/db/routines/vn/procedures/entry_splitByShelving.sql @@ -9,81 +9,55 @@ BEGIN * @param vToEntryFk Entrada destino */ DECLARE vBuyFk INT; - DECLARE vIshStickers INT; - DECLARE vBuyStickers INT; - DECLARE vDone BOOLEAN DEFAULT FALSE; + DECLARE vIshStickers INT; + DECLARE vBuyStickers INT; + DECLARE vDone BOOLEAN DEFAULT FALSE; + + DECLARE cur CURSOR FOR + SELECT bb.id buyFk, + FLOOR(ish.visible / ish.packing) ishStickers, + bb.stickers buyStickers + FROM itemShelving ish + JOIN (SELECT b.id, b.itemFk, b.stickers + FROM buy b + WHERE b.entryFk = vFromEntryFk + ORDER BY b.stickers DESC + LIMIT 10000000000000000000) bb ON bb.itemFk = ish.itemFk + AND bb.stickers >= FLOOR(ish.visible / ish.packing) + WHERE ish.shelvingFk = vShelvingFk COLLATE utf8_general_ci + AND NOT ish.isSplit + GROUP BY ish.id; + + DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone = TRUE; + + OPEN cur; + + read_loop: LOOP + SET vDone = FALSE; - DECLARE cur CURSOR FOR - SELECT bb.id buyFk, - FLOOR(ish.visible / ish.packing) ishStickers, - bb.stickers buyStickers - FROM itemShelving ish - JOIN (SELECT b.id, b.itemFk, b.stickers - FROM buy b - WHERE b.entryFk = vFromEntryFk - ORDER BY b.stickers DESC - LIMIT 10000000000000000000) bb ON bb.itemFk = ish.itemFk - AND bb.stickers >= FLOOR(ish.visible / ish.packing) - WHERE ish.shelvingFk = vShelvingFk COLLATE utf8_general_ci - AND NOT ish.isSplit - GROUP BY ish.id; - - DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone = TRUE; - - OPEN cur; - - read_loop: LOOP - SET vDone = FALSE; - - FETCH cur INTO vBuyFk, vIshStickers, vBuyStickers; - - IF vDone THEN - LEAVE read_loop; - END IF; - - IF vIshStickers = vBuyStickers THEN - UPDATE buy - SET entryFk = vToEntryFk - WHERE id = vBuyFk; - ELSE - UPDATE buy - SET stickers = stickers - vIshStickers, - quantity = stickers * packing - WHERE id = vBuyFk; - - INSERT INTO buy(entryFk, - itemFk, - quantity, - buyingValue, - freightValue, - isIgnored, - stickers, - packing, - `grouping`, - groupingMode, - comissionValue, - packageValue, - location, - packagingFk, - price1, - price2, - price3, - minPrice, - workerFk, - isChecked, - isPickedOff, - ektFk, - weight, - deliveryFk, - itemOriginalFk) - SELECT - vToEntryFk, + FETCH cur INTO vBuyFk, vIshStickers, vBuyStickers; + + IF vDone THEN + LEAVE read_loop; + END IF; + + IF vIshStickers = vBuyStickers THEN + UPDATE buy + SET entryFk = vToEntryFk + WHERE id = vBuyFk; + ELSE + UPDATE buy + SET stickers = stickers - vIshStickers, + quantity = stickers * packing + WHERE id = vBuyFk; + + INSERT INTO buy(entryFk, itemFk, - vIshStickers * packing, + quantity, buyingValue, freightValue, isIgnored, - vIshStickers, + stickers, packing, `grouping`, groupingMode, @@ -101,17 +75,43 @@ BEGIN ektFk, weight, deliveryFk, - itemOriginalFk - FROM buy - WHERE id = vBuyFk; - - UPDATE buy SET printedStickers = vIshStickers WHERE id = LAST_INSERT_ID(); - END IF; - - UPDATE itemShelving - SET isSplit = TRUE - WHERE shelvingFk = vShelvingFk; - END LOOP; - CLOSE cur; + itemOriginalFk) + SELECT + vToEntryFk, + itemFk, + vIshStickers * packing, + buyingValue, + freightValue, + isIgnored, + vIshStickers, + packing, + `grouping`, + groupingMode, + comissionValue, + packageValue, + location, + packagingFk, + price1, + price2, + price3, + minPrice, + workerFk, + isChecked, + isPickedOff, + ektFk, + weight, + deliveryFk, + itemOriginalFk + FROM buy + WHERE id = vBuyFk; + + UPDATE buy SET printedStickers = vIshStickers WHERE id = LAST_INSERT_ID(); + END IF; + + UPDATE itemShelving + SET isSplit = TRUE + WHERE shelvingFk = vShelvingFk; + END LOOP; + CLOSE cur; END$$ DELIMITER ; -- 2.40.1