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

42 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;
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;
2024-07-10 09:32:41 +00:00
2024-07-12 07:42:10 +00:00
SET vLastWeek = util.VN_CURDATE() - INTERVAL 1 WEEK;
-- Comprobamos si es una prep. previa, ticket, colección o shelving
IF (SELECT TRUE FROM saleGroup WHERE id = vParam) THEN
CALL saleGroup_setParking(vParam, vParkingFk);
ELSEIF (SELECT TRUE FROM ticket WHERE id = vParam AND 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);
ELSEIF (SELECT TRUE FROM shelving WHERE code = vParam COLLATE utf8_unicode_ci) THEN
CALL shelving_setParking(vParam, vParkingFk);
ELSE
2024-07-11 12:50:21 +00:00
CALL util.throw('paramNotExist');
END IF;
END$$
DELIMITER ;