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

51 lines
1.3 KiB
MySQL
Raw Normal View History

DELIMITER $$
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`setParking`(
vParam VARCHAR(8),
vParkingCode VARCHAR(8)
)
BEGIN
/**
* Aparca una colección, un ticket, un saleGroup o un shelving en un parking
*
* @param vParam id del ticket, colección, saleGroup o shelving
* @param vParkingCode código del parking
*/
DECLARE vParkingFk INT;
DECLARE vLastWeek DATE;
DECLARE EXIT HANDLER FOR SQLEXCEPTION
BEGIN
ROLLBACK;
RESIGNAL;
END;
SET vParkingCode = REPLACE(vParkingCode, ' ', '');
SELECT id INTO vParkingFk
FROM parking
WHERE code = vParkingCode COLLATE utf8_unicode_ci;
IF vParkingFk IS NULL THEN
CALL util.throw('parkingNotExist');
END IF;
IF vParam REGEXP '^[0-9]+$' THEN
SET vLastWeek = util.VN_CURDATE() - INTERVAL 1 WEEK;
-- Comprobamos si es una prep. previa, ticket o colección
IF (SELECT TRUE FROM saleGroup sg WHERE sg.id = vParam) THEN
CALL saleGroup_setParking(vParam, vParkingFk);
ELSEIF (SELECT TRUE FROM ticket WHERE id = vParam shipped >= vLastWeek) THEN
CALL ticket_setParking(vParam, vParkingFk);
ELSEIF (SELECT TRUE FROM `collection` WHERE id = vParam AND created >= vLastWeek) THEN
CALL collection_setParking(vParam, vParkingFk);
END IF;
ELSE
-- Por descarte, se considera una matrícula
CALL shelving_setParking(vParam, vParkingFk);
END IF;
COMMIT;
END$$
DELIMITER ;