salix/db/routines/vn/procedures/itemShelvingSale_setSaleGro...

34 lines
826 B
SQL

DELIMITER $$
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`itemShelvingSale_setSaleGroup`(
vSaleGroupFk INT(10)
)
BEGIN
/**
* Gestiona la reserva de un vn.saleGroup actualizando vn.itemShelvingSale.isPicked
* y cambiando el estado de la vn.sale
*
* @param vSaleGroupFk Id saleGroupFk
*/
DECLARE EXIT HANDLER FOR SQLEXCEPTION
BEGIN
ROLLBACK;
RESIGNAL;
END;
IF NOT (SELECT COUNT(*) FROM saleGroup WHERE id = vSaleGroupFk) THEN
CALL util.throw('Sale group not exists');
END IF;
START TRANSACTION;
UPDATE itemShelvingSale iss
JOIN sale s ON s.id = iss.saleFk
JOIN saleGroupDetail sg ON sg.saleFk = s.id
SET iss.isPicked = TRUE
WHERE sg.saleGroupFk = vSaleGroupFk;
CALL saleTracking_addPreparedSaleGroup(vSaleGroupFk);
COMMIT;
END$$
DELIMITER ;