salix/db/routines/vn/procedures/itemShelving_transfer.sql

53 lines
1.3 KiB
MySQL
Raw Normal View History

DELIMITER $$
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`itemShelving_transfer`(
vItemShelvingFk INT,
vShelvingFk VARCHAR(10)
)
BEGIN
/**
2024-09-03 05:45:25 +00:00
* Transfiere producto de una ubicación a otra
* fusionando si coincide el packing y la fecha.
*
* @param vItemShelvingFk Identificador de itemShelving
* @param vShelvingFk Identificador de shelving
*/
2024-09-03 05:45:25 +00:00
DECLARE vNewItemShelvingFk INT;
2024-09-03 05:45:25 +00:00
SELECT MAX(ish.id) INTO vNewItemShelvingFk
FROM itemShelving ish
JOIN (
2024-09-03 05:45:25 +00:00
SELECT itemFk,
packing,
created,
buyFk
FROM itemShelving
WHERE id = vItemShelvingFk
) ish2 ON ish2.itemFk = ish.itemFk
AND ish2.packing = ish.packing
2024-09-03 05:45:25 +00:00
AND DATE(ish2.created) = DATE(ish.created)
2024-02-06 12:31:58 +00:00
AND ish2.buyFk = ish.buyFk
WHERE ish.shelvingFk = vShelvingFk COLLATE utf8_unicode_ci;
IF vNewItemShelvingFk THEN
UPDATE itemShelving ish
JOIN itemShelving ish2 ON ish2.id = vItemShelvingFk
SET ish.visible = ish.visible + ish2.visible
WHERE ish.id = vNewItemShelvingFk;
DELETE FROM itemShelving
WHERE id = vItemShelvingFk;
ELSE
2024-09-03 05:45:25 +00:00
IF (SELECT EXISTS(SELECT id FROM shelving
WHERE code = vShelvingFk COLLATE utf8_unicode_ci)) THEN
UPDATE itemShelving
SET shelvingFk = vShelvingFk
WHERE id = vItemShelvingFk;
ELSE
CALL util.throw('The shelving not exists');
END IF;
END IF;
2024-09-03 05:45:25 +00:00
SELECT TRUE;
END$$
2024-09-03 05:45:25 +00:00
DELIMITER ;