2024-01-15 11:31:03 +00:00
|
|
|
DELIMITER $$
|
2024-08-20 08:06:10 +00:00
|
|
|
CREATE OR REPLACE DEFINER=`vn`@`localhost` TRIGGER `vn`.`route_afterUpdate`
|
2024-01-15 11:31:03 +00:00
|
|
|
AFTER UPDATE ON `route`
|
|
|
|
FOR EACH ROW
|
2024-11-19 10:15:57 +00:00
|
|
|
BEGIN
|
2024-01-15 11:31:03 +00:00
|
|
|
IF IFNULL(NEW.gestdocFk,0) <> IFNULL(OLD.gestdocFk,0) AND NEW.gestdocFk > 0 THEN
|
|
|
|
-- JGF 09/09/14 cuando se añade un gestdoc a una ruta, se le asigna automagicamente a todos sus Tickets
|
2024-11-19 10:15:57 +00:00
|
|
|
|
2024-01-15 11:31:03 +00:00
|
|
|
-- Inserta el gestdoc en todos los tickets de la ruta
|
|
|
|
INSERT INTO ticketDms(ticketFk,dmsFk)
|
|
|
|
SELECT id, NEW.gestdocFk FROM ticket WHERE routeFk = NEW.id
|
|
|
|
ON DUPLICATE KEY UPDATE dmsFk = NEW.gestdocFk;
|
|
|
|
|
2024-11-19 10:15:57 +00:00
|
|
|
-- Update del firmado
|
|
|
|
UPDATE ticket t
|
|
|
|
JOIN ticketDms tg ON t.id = tg.ticketFk
|
2024-01-15 11:31:03 +00:00
|
|
|
SET isSigned = 1 WHERE t.routeFk = NEW.id;
|
|
|
|
END IF;
|
|
|
|
|
|
|
|
IF !(NEW.kmStart <=> OLD.kmStart)
|
|
|
|
OR !(NEW.kmEnd <=> OLD.kmEnd)
|
|
|
|
OR !(NEW.workerFk <=> OLD.workerFk)
|
|
|
|
OR !(NEW.m3 <=> OLD.m3)
|
2024-11-19 10:15:57 +00:00
|
|
|
OR !(NEW.agencyModeFk <=> OLD.agencyModeFk)
|
|
|
|
OR !(NEW.vehicleFk <=> OLD.vehicleFk)THEN
|
2024-01-15 11:31:03 +00:00
|
|
|
CALL route_calcCommission(NEW.id);
|
|
|
|
END IF;
|
|
|
|
|
|
|
|
END$$
|
|
|
|
DELIMITER ;
|