2023-06-14 08:51:22 +00:00
|
|
|
DELIMITER $$
|
2024-08-20 08:06:10 +00:00
|
|
|
CREATE OR REPLACE DEFINER=`vn`@`localhost` PROCEDURE `vn`.`packingSite_startCollection`(vSelf INT, vTicketFk INT)
|
2023-06-14 08:51:22 +00:00
|
|
|
proc: BEGIN
|
|
|
|
/**
|
|
|
|
* @param vSelf packingSite id
|
|
|
|
* @param vTicketFk A ticket id from the collection to start
|
|
|
|
*/
|
2023-06-14 11:15:37 +00:00
|
|
|
DECLARE vExists BOOL;
|
|
|
|
DECLARE vIsAdvanced BOOL;
|
|
|
|
DECLARE vNewCollectionFk INT;
|
|
|
|
DECLARE vOldCollectionFk INT;
|
|
|
|
DECLARE vIsPackingByOther BOOL;
|
|
|
|
|
|
|
|
SELECT id, collectionFk
|
|
|
|
INTO vExists, vOldCollectionFk
|
|
|
|
FROM packingSite
|
|
|
|
WHERE id = vSelf;
|
|
|
|
|
|
|
|
IF NOT vExists THEN
|
|
|
|
CALL util.throw('packingSiteNotExists');
|
|
|
|
END IF;
|
|
|
|
|
|
|
|
SELECT COUNT(*) > 0
|
|
|
|
INTO vIsAdvanced
|
|
|
|
FROM packingSiteAdvanced
|
|
|
|
WHERE ticketFk = vTicketFk;
|
|
|
|
|
|
|
|
IF vIsAdvanced THEN
|
|
|
|
LEAVE proc;
|
|
|
|
END IF;
|
|
|
|
|
|
|
|
SELECT collectionFk INTO vNewCollectionFk
|
|
|
|
FROM ticketCollection WHERE ticketFk = vTicketFk;
|
|
|
|
|
|
|
|
IF vOldCollectionFk IS NOT NULL
|
|
|
|
AND vOldCollectionFk <> vNewCollectionFk THEN
|
|
|
|
SELECT COUNT(*) > 0
|
|
|
|
INTO vIsPackingByOther
|
|
|
|
FROM packingSite
|
|
|
|
WHERE id <> vSelf
|
|
|
|
AND collectionFk = vOldCollectionFk;
|
|
|
|
|
|
|
|
IF NOT vIsPackingByOther AND NOT collection_isPacked(vOldCollectionFk) THEN
|
|
|
|
CALL util.throw('cannotChangeCollection');
|
|
|
|
END IF;
|
|
|
|
END IF;
|
|
|
|
|
|
|
|
UPDATE packingSite SET collectionFk = vNewCollectionFk
|
|
|
|
WHERE id = vSelf;
|
2023-06-14 08:51:22 +00:00
|
|
|
END$$
|
|
|
|
DELIMITER ;
|