salix/db/routines/vn/triggers/business_beforeUpdate.sql

33 lines
734 B
MySQL
Raw Normal View History

DELIMITER $$
CREATE OR REPLACE DEFINER=`vn-admin`@`localhost` TRIGGER `vn`.`business_beforeUpdate`
BEFORE UPDATE ON `business`
FOR EACH ROW
BEGIN
DECLARE isOverlapping BOOL;
SET NEW.editorFk = account.myUser_getId();
IF NEW.ended IS NULL THEN
SET NEW.payedHolidays = 0;
END IF;
IF !(OLD.started <=> NEW.started AND OLD.ended <=> NEW.ended) THEN
2024-06-24 06:08:39 +00:00
SELECT util.hasDateOverlapped(
started,
ended,
NEW.started,
IFNULL(NEW.ended, b.started)
) isOverlapped INTO isOverlapping
FROM vn.business b
WHERE workerFk = NEW.workerFK
AND b.id <> NEW.id
ORDER BY isOverlapped DESC
LIMIT 1;
IF isOverlapping THEN
CALL util.throw ('IS_OVERLAPPING');
END IF;
END IF;
END$$
DELIMITER ;