2024-01-15 11:31:03 +00:00
|
|
|
DELIMITER $$
|
2024-08-20 08:06:10 +00:00
|
|
|
CREATE OR REPLACE DEFINER=`vn`@`localhost` PROCEDURE `vn`.`itemShelving_transfer`(
|
2024-05-27 05:46:21 +00:00
|
|
|
vItemShelvingFk INT,
|
2024-06-11 10:44:25 +00:00
|
|
|
vShelvingFk VARCHAR(10)
|
|
|
|
)
|
2024-01-15 11:31:03 +00:00
|
|
|
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.
|
2024-01-15 11:31:03 +00:00
|
|
|
*
|
|
|
|
* @param vItemShelvingFk Identificador de itemShelving
|
|
|
|
* @param vShelvingFk Identificador de shelving
|
|
|
|
*/
|
2024-09-03 05:45:25 +00:00
|
|
|
DECLARE vNewItemShelvingFk INT;
|
2024-01-15 11:31:03 +00:00
|
|
|
|
2024-09-03 05:45:25 +00:00
|
|
|
SELECT MAX(ish.id) INTO vNewItemShelvingFk
|
2024-01-15 11:31:03 +00:00
|
|
|
FROM itemShelving ish
|
|
|
|
JOIN (
|
2024-09-03 05:45:25 +00:00
|
|
|
SELECT itemFk,
|
|
|
|
packing,
|
|
|
|
created,
|
|
|
|
buyFk
|
2024-01-15 11:31:03 +00:00
|
|
|
FROM itemShelving
|
|
|
|
WHERE id = vItemShelvingFk
|
2024-05-27 05:46:21 +00:00
|
|
|
) ish2 ON ish2.itemFk = ish.itemFk
|
2024-01-15 11:31:03 +00:00
|
|
|
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
|
2024-01-15 11:31:03 +00:00
|
|
|
WHERE ish.shelvingFk = vShelvingFk COLLATE utf8_unicode_ci;
|
|
|
|
|
|
|
|
IF vNewItemShelvingFk THEN
|
|
|
|
UPDATE itemShelving ish
|
2024-05-27 05:46:21 +00:00
|
|
|
JOIN itemShelving ish2 ON ish2.id = vItemShelvingFk
|
2024-09-24 14:48:48 +00:00
|
|
|
SET ish.visible = ish.visible + ish2.visible,
|
|
|
|
ish.available = ish.available + ish2.available
|
2024-01-15 11:31:03 +00:00
|
|
|
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;
|
2024-01-15 11:31:03 +00:00
|
|
|
END IF;
|
2024-09-03 05:45:25 +00:00
|
|
|
SELECT TRUE;
|
2024-01-15 11:31:03 +00:00
|
|
|
END$$
|
2024-09-03 05:45:25 +00:00
|
|
|
DELIMITER ;
|