2024-01-15 11:31:03 +00:00
|
|
|
|
DELIMITER $$
|
|
|
|
|
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`entry_splitByShelving`(vShelvingFk VARCHAR(3), vFromEntryFk INT, vToEntryFk INT)
|
|
|
|
|
BEGIN
|
|
|
|
|
/**
|
|
|
|
|
* Divide las compras entre dos entradas de acuerdo con lo ubicado en una matr<EFBFBD>cula
|
|
|
|
|
*
|
|
|
|
|
* @param vShelvingFk Identificador de vn.shelving
|
|
|
|
|
* @param vFromEntryFk Entrada origen
|
|
|
|
|
* @param vToEntryFk Entrada destino
|
|
|
|
|
*/
|
|
|
|
|
DECLARE vBuyFk INT;
|
2024-07-04 06:59:22 +00:00
|
|
|
|
DECLARE vIshStickers INT;
|
|
|
|
|
DECLARE vBuyStickers INT;
|
|
|
|
|
DECLARE vDone BOOLEAN DEFAULT FALSE;
|
|
|
|
|
|
|
|
|
|
DECLARE cur CURSOR FOR
|
|
|
|
|
SELECT bb.id buyFk,
|
2024-08-07 05:12:29 +00:00
|
|
|
|
LEAST(bb.stickers, FLOOR(ish.visible / ish.packing)) ishStickers,
|
2024-07-04 06:59:22 +00:00
|
|
|
|
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
|
|
|
|
|
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;
|
2024-01-15 11:31:03 +00:00
|
|
|
|
|
2024-07-04 06:59:22 +00:00
|
|
|
|
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,
|
2024-01-15 11:31:03 +00:00
|
|
|
|
itemFk,
|
2024-07-04 06:59:22 +00:00
|
|
|
|
quantity,
|
2024-01-15 11:31:03 +00:00
|
|
|
|
buyingValue,
|
|
|
|
|
freightValue,
|
|
|
|
|
isIgnored,
|
2024-07-04 06:59:22 +00:00
|
|
|
|
stickers,
|
2024-01-15 11:31:03 +00:00
|
|
|
|
packing,
|
|
|
|
|
`grouping`,
|
|
|
|
|
groupingMode,
|
|
|
|
|
comissionValue,
|
|
|
|
|
packageValue,
|
|
|
|
|
location,
|
|
|
|
|
packagingFk,
|
|
|
|
|
price1,
|
|
|
|
|
price2,
|
|
|
|
|
price3,
|
|
|
|
|
minPrice,
|
|
|
|
|
workerFk,
|
|
|
|
|
isChecked,
|
|
|
|
|
isPickedOff,
|
|
|
|
|
ektFk,
|
|
|
|
|
weight,
|
|
|
|
|
deliveryFk,
|
2024-07-04 06:59:22 +00:00
|
|
|
|
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
|
2024-07-31 09:31:02 +00:00
|
|
|
|
WHERE shelvingFk = vShelvingFk COLLATE utf8_general_ci;
|
2024-07-04 06:59:22 +00:00
|
|
|
|
END LOOP;
|
|
|
|
|
CLOSE cur;
|
2024-01-15 11:31:03 +00:00
|
|
|
|
END$$
|
|
|
|
|
DELIMITER ;
|