2024-07-30 10:14:15 +00:00
|
|
|
DELIMITER $$
|
2024-08-20 08:07:33 +00:00
|
|
|
CREATE OR REPLACE DEFINER=`vn`@`localhost` PROCEDURE `vn`.`itemShelvingSale_reallocate`(
|
2024-07-30 10:14:15 +00:00
|
|
|
vItemShelvingFk INT(10),
|
|
|
|
vItemFk INT(10),
|
|
|
|
vSectorFk INT
|
|
|
|
)
|
|
|
|
BEGIN
|
|
|
|
/**
|
|
|
|
* Elimina reservas de un itemShelving e intenta reservar en otra ubicación
|
|
|
|
*
|
|
|
|
* @param vItemShelvingFk Id itemShelving
|
|
|
|
* @param vItemFk Id del artículo
|
|
|
|
* @param vSectorFk Id del sector
|
|
|
|
*/
|
|
|
|
DECLARE EXIT HANDLER FOR SQLEXCEPTION
|
|
|
|
BEGIN
|
|
|
|
ROLLBACK;
|
|
|
|
RESIGNAL;
|
|
|
|
END;
|
|
|
|
|
|
|
|
START TRANSACTION;
|
|
|
|
|
|
|
|
UPDATE itemShelving
|
|
|
|
SET visible = 0,
|
|
|
|
available = 0
|
|
|
|
WHERE id = vItemShelvingFk
|
|
|
|
AND itemFk = vItemFk;
|
|
|
|
|
|
|
|
SELECT iss.id
|
|
|
|
FROM itemShelvingSale iss
|
|
|
|
JOIN itemShelving ish ON ish.id = iss.itemShelvingFk
|
|
|
|
WHERE iss.itemShelvingFk = vItemShelvingFk
|
2024-07-30 11:04:33 +00:00
|
|
|
AND ish.itemFk = vItemFk
|
2024-07-30 10:14:15 +00:00
|
|
|
AND NOT iss.isPicked
|
|
|
|
FOR UPDATE;
|
|
|
|
|
|
|
|
INSERT INTO itemShelvingSaleReserve (saleFk, sectorFk)
|
|
|
|
SELECT DISTINCT iss.saleFk, vSectorFk
|
|
|
|
FROM itemShelvingSale iss
|
|
|
|
JOIN itemShelving ish ON ish.id = iss.itemShelvingFk
|
|
|
|
WHERE iss.itemShelvingFk = vItemShelvingFk
|
|
|
|
AND ish.itemFk = vItemFk
|
|
|
|
AND NOT iss.isPicked;
|
|
|
|
|
|
|
|
DELETE iss
|
|
|
|
FROM itemShelvingSale iss
|
|
|
|
JOIN itemShelving ish ON ish.id = iss.itemShelvingFk
|
|
|
|
WHERE iss.itemShelvingFk = vItemShelvingFk
|
|
|
|
AND ish.itemFk = vItemFk
|
|
|
|
AND NOT iss.isPicked;
|
|
|
|
COMMIT;
|
|
|
|
|
|
|
|
CALL itemShelvingSale_doReserve();
|
|
|
|
END$$
|
2024-06-11 10:44:25 +00:00
|
|
|
DELIMITER ;
|