feat: refs #7654 entry_splitByShelving #2673

Merged
robert merged 8 commits from 7654-entry_splitByShelvingCreateColumn into dev 2024-07-04 09:20:15 +00:00
1 changed files with 82 additions and 82 deletions
Showing only changes of commit 897da1e48a - Show all commits

View File

@ -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 ;