From 4dcc8b02a597eb818d79029aa8a3ee6e6cbdc643 Mon Sep 17 00:00:00 2001 From: robert Date: Tue, 9 Jul 2024 10:01:32 +0200 Subject: [PATCH] feat: refs #7685 delivery coordinates --- .../procedures/address_updateCorordinates.sql | 30 +++++++++++++++++++ .../vn/triggers/delivery_beforeInsert.sql | 12 ++------ .../vn/triggers/delivery_beforeUpdate.sql | 12 ++------ 3 files changed, 34 insertions(+), 20 deletions(-) create mode 100644 db/routines/vn/procedures/address_updateCorordinates.sql diff --git a/db/routines/vn/procedures/address_updateCorordinates.sql b/db/routines/vn/procedures/address_updateCorordinates.sql new file mode 100644 index 000000000..2004cd180 --- /dev/null +++ b/db/routines/vn/procedures/address_updateCorordinates.sql @@ -0,0 +1,30 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`address_updateCorordinates`( + vTicketFk INT, + vLongitude INT, + vLatitude INT) +BEGIN +/** + * Actualiza las coordenadas de una direccion + * + * @param vTicketFk id del ticket + * @param vLongitude longitud de la direccion + * @param vLatitude latitud de la dirrecion + */ + DECLARE vAddressFK INT; + + START TRANSACTION; + + SELECT addressFK INTO vAddressFK + FROM ticket + WHERE id = vTicketFk + FOR UPDATE; + + UPDATE address + SET longitude = vLongitude, + latitude = vLatitude + WHERE id = vAddressFK; + + COMMIT; +END$$ +DELIMITER ; diff --git a/db/routines/vn/triggers/delivery_beforeInsert.sql b/db/routines/vn/triggers/delivery_beforeInsert.sql index 89431c30f..c9679ed13 100644 --- a/db/routines/vn/triggers/delivery_beforeInsert.sql +++ b/db/routines/vn/triggers/delivery_beforeInsert.sql @@ -4,16 +4,8 @@ CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`delivery_beforeInsert FOR EACH ROW BEGIN - IF (NEW.longitude IS NOT NULL AND NEW.latitude IS NOT NULL AND NEW.ticketFK IS NOT NULL) - THEN - UPDATE address - SET longitude = NEW.longitude, - latitude = NEW.latitude - WHERE id IN ( - SELECT addressFK - FROM ticket - WHERE id = NEW.ticketFk - ); + IF (NEW.longitude IS NOT NULL AND NEW.latitude IS NOT NULL AND NEW.ticketFK IS NOT NULL) THEN + CALL address_updateCorordinates(NEW.ticketFk,NEW.longitude,NEW.latitude); END IF; END$$ diff --git a/db/routines/vn/triggers/delivery_beforeUpdate.sql b/db/routines/vn/triggers/delivery_beforeUpdate.sql index 7e6aa7d4c..dda0e9dd2 100644 --- a/db/routines/vn/triggers/delivery_beforeUpdate.sql +++ b/db/routines/vn/triggers/delivery_beforeUpdate.sql @@ -4,16 +4,8 @@ CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`delivery_beforeUpdate FOR EACH ROW BEGIN -IF (NEW.longitude IS NOT NULL AND NEW.latitude IS NOT NULL AND NEW.ticketFK IS NOT NULL) - THEN - UPDATE address - SET longitude = NEW.longitude, - latitude = NEW.latitude - WHERE id IN ( - SELECT addressFK - FROM ticket - WHERE id = NEW.ticketFk - ); + IF (NEW.longitude IS NOT NULL AND NEW.latitude IS NOT NULL AND NEW.ticketFK IS NOT NULL) THEN + CALL address_updateCorordinates(NEW.ticketFk,NEW.longitude,NEW.latitude); END IF; END$$