8524-devToTest #3415
|
@ -0,0 +1,21 @@
|
|||
DELIMITER $$
|
||||
CREATE OR REPLACE DEFINER=`vn`@`localhost` TRIGGER `vn`.`roadmapStop_beforeDelete`
|
||||
BEFORE DELETE ON `roadmapStop`
|
||||
FOR EACH ROW
|
||||
BEGIN
|
||||
DECLARE vMaxEta DATETIME;
|
||||
|
||||
IF OLD.roadmapFk IS NOT NULL THEN
|
||||
SELECT MAX(eta) INTO vMaxEta
|
||||
FROM roadmapStop
|
||||
WHERE roadmapFk = OLD.roadmapFk
|
||||
AND id <> OLD.id;
|
||||
|
||||
IF OLD.eta > vMaxEta OR vMaxEta IS NULL THEN
|
||||
UPDATE roadmap
|
||||
SET eta = COALESCE(vMaxEta, OLD.eta)
|
||||
WHERE id = OLD.roadmapFk;
|
||||
END IF;
|
||||
END IF;
|
||||
END$$
|
||||
DELIMITER ;
|
|
@ -3,12 +3,30 @@ CREATE OR REPLACE DEFINER=`vn`@`localhost` TRIGGER `vn`.`roadmapStop_beforeInser
|
|||
BEFORE INSERT ON `roadmapStop`
|
||||
FOR EACH ROW
|
||||
BEGIN
|
||||
DECLARE vMaxEta DATETIME;
|
||||
|
||||
SET NEW.editorFk = account.myUser_getId();
|
||||
SET NEW.description = UCASE(NEW.description);
|
||||
|
||||
IF NEW.description IS NOT NULL THEN
|
||||
SET NEW.description = UCASE(NEW.description);
|
||||
END IF;
|
||||
|
||||
IF NEW.roadmapFk IS NOT NULL THEN
|
||||
IF NEW.eta < (SELECT etd FROM roadmap WHERE id = NEW.roadmapFk) THEN
|
||||
CALL util.throw('Departure time can not be after arrival time');
|
||||
END IF;
|
||||
END IF;
|
||||
|
||||
IF NEW.roadmapFk IS NOT NULL AND NEW.eta IS NOT NULL THEN
|
||||
SELECT MAX(eta) INTO vMaxEta
|
||||
FROM roadmapStop
|
||||
WHERE roadmapFk = NEW.roadmapFk;
|
||||
|
||||
IF NEW.eta > vMaxEta OR vMaxEta IS NOT NULL THEN
|
||||
UPDATE roadmap
|
||||
SET eta = GREATEST(COALESCE(vMaxEta, NEW.eta), NEW.eta)
|
||||
WHERE id = NEW.roadmapFk;
|
||||
END IF;
|
||||
END IF;
|
||||
END$$
|
||||
DELIMITER ;
|
|
@ -3,14 +3,30 @@ CREATE OR REPLACE DEFINER=`vn`@`localhost` TRIGGER `vn`.`roadmapStop_beforeUpdat
|
|||
BEFORE UPDATE ON `roadmapStop`
|
||||
FOR EACH ROW
|
||||
BEGIN
|
||||
DECLARE vMaxEta DATETIME;
|
||||
|
||||
SET NEW.editorFk = account.myUser_getId();
|
||||
SET NEW.description = UCASE(NEW.description);
|
||||
|
||||
IF NOT (NEW.description <=> OLD.description) THEN
|
||||
SET NEW.description = UCASE(NEW.description);
|
||||
END IF;
|
||||
|
||||
IF (NOT (NEW.roadmapFk <=> OLD.roadmapFk) AND NEW.roadmapFk IS NOT NULL)
|
||||
OR (NOT (NEW.eta <=> OLD.eta) AND NEW.eta IS NOT NULL) THEN
|
||||
|
||||
IF NEW.eta < (SELECT etd FROM roadmap WHERE id = NEW.roadmapFk) THEN
|
||||
CALL util.throw('Departure time can not be after arrival time');
|
||||
END IF;
|
||||
|
||||
SELECT MAX(eta) INTO vMaxEta
|
||||
FROM roadmapStop
|
||||
WHERE roadmapFk = NEW.roadmapFk;
|
||||
|
||||
IF NEW.eta > vMaxEta OR vMaxEta IS NULL THEN
|
||||
UPDATE roadmap
|
||||
SET eta = COALESCE(vMaxEta, NEW.eta)
|
||||
WHERE id = NEW.roadmapFk;
|
||||
END IF;
|
||||
END IF;
|
||||
END$$
|
||||
DELIMITER ;
|
||||
|
|
|
@ -9,10 +9,6 @@ BEGIN
|
|||
SET NEW.name = UCASE(NEW.name);
|
||||
END IF;
|
||||
|
||||
IF NEW.etd > NEW.eta AND NEW.etd IS NOT NULL AND NEW.eta IS NOT NULL THEN
|
||||
CALL util.throw('Departure time can not be after arrival time');
|
||||
END IF;
|
||||
|
||||
IF NEW.trailerPlate IS NOT NULL OR NEW.tugPlate IS NOT NULL THEN
|
||||
SET NEW.m3 = (SELECT SUM(m3) FROM vehicle WHERE numberPlate IN (NEW.trailerPlate, NEW.tugPlate));
|
||||
END IF;
|
||||
|
|
|
@ -9,10 +9,6 @@ BEGIN
|
|||
SET NEW.name = UCASE(NEW.name);
|
||||
END IF;
|
||||
|
||||
IF NEW.etd > NEW.eta AND NEW.etd IS NOT NULL AND NEW.eta IS NOT NULL THEN
|
||||
CALL util.throw('Departure time can not be after arrival time');
|
||||
END IF;
|
||||
|
||||
IF NOT (NEW.trailerPlate <=> OLD.trailerPlate) OR NOT (NEW.tugPlate <=> OLD.tugPlate) THEN
|
||||
SET NEW.m3 = (SELECT SUM(m3) FROM vehicle WHERE numberPlate IN (NEW.trailerPlate, NEW.tugPlate));
|
||||
END IF;
|
||||
|
|
Loading…
Reference in New Issue