DELIMITER $$ CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`itemShelvingSale_reallocate`( vItemShelvingFk INT(10), vItemFk INT(10) ) BEGIN /** * Elimina reservas de un itemShelving e intenta reservar en otra ubicaciĆ³n * * @param vItemShelvingFk Id itemShelving */ DECLARE EXIT HANDLER FOR SQLEXCEPTION BEGIN ROLLBACK; RESIGNAL; END; START TRANSACTION; SELECT id INTO vItemShelvingFk FROM itemShelving WHERE id = vItemShelvingFk FOR UPDATE; UPDATE itemShelving SET visible = 0, available = 0 WHERE id = vItemShelvingFk AND itemFk = vItemFk; INSERT INTO itemShelvingSaleReserve (saleFk) SELECT DISTINCT iss.saleFk 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$$ DELIMITER ;