2024-07-22 08:27:24 +00:00
|
|
|
DELIMITER $$
|
2024-10-01 06:51:03 +00:00
|
|
|
CREATE OR REPLACE DEFINER=`vn`@`localhost` PROCEDURE `vn`.`itemMinimumQuantity_check`(
|
2024-07-22 08:27:24 +00:00
|
|
|
vSelf INT,
|
|
|
|
vItemFk INT,
|
|
|
|
vStarted DATE,
|
|
|
|
vEnded DATE,
|
|
|
|
vWarehouseFk INT
|
|
|
|
)
|
|
|
|
BEGIN
|
|
|
|
DECLARE vHasCollision BOOL;
|
|
|
|
|
|
|
|
IF vStarted IS NULL THEN
|
|
|
|
CALL util.throw('The field "started" cannot be null');
|
|
|
|
END IF;
|
|
|
|
|
|
|
|
SELECT COUNT(*) INTO vHasCollision
|
|
|
|
FROM itemMinimumQuantity
|
|
|
|
WHERE vItemFk = itemFk
|
|
|
|
AND ((vStarted <= ended OR ended IS NULL)
|
|
|
|
AND (vStarted >= `started` OR vEnded IS NULL))
|
|
|
|
AND (vWarehouseFk <=> warehouseFk)
|
|
|
|
AND vSelf <> id;
|
|
|
|
|
|
|
|
IF vHasCollision THEN
|
|
|
|
CALL util.throw('A line with the same configuration already exists');
|
|
|
|
END IF;
|
|
|
|
END$$
|
|
|
|
DELIMITER ;
|