fix: business overlapping #2631

Merged
pablone merged 1 commits from fixBusinessOverlaping into master 2024-06-24 10:21:55 +00:00
1 changed files with 11 additions and 13 deletions

View File

@ -12,23 +12,21 @@ BEGIN
END IF; END IF;
IF !(OLD.started <=> NEW.started AND OLD.ended <=> NEW.ended) THEN IF !(OLD.started <=> NEW.started AND OLD.ended <=> NEW.ended) THEN
SELECT util.hasDateOverlapped(
SELECT COUNT(*) > 0 INTO isOverlapping started,
FROM business b ended,
WHERE (util.hasDateOverlapped( NEW.started,
NEW.started, IFNULL(NEW.ended, b.started)
IFNULL(NEW.ended, b.started), ) isOverlapped INTO isOverlapping
b.started, FROM vn.business b
IFNULL(b.ended, NEW.started)) WHERE workerFk = NEW.workerFK
OR (NEW.ended <=> NULL AND b.ended <=> NULL)) AND b.id <> NEW.id
AND b.id <> OLD.id ORDER BY isOverlapped DESC
AND workerFk = OLD.workerFk; LIMIT 1;
IF isOverlapping THEN IF isOverlapping THEN
CALL util.throw ('IS_OVERLAPPING'); CALL util.throw ('IS_OVERLAPPING');
END IF; END IF;
END IF; END IF;
END$$ END$$
DELIMITER ; DELIMITER ;