From b78f83ae303bc2d309cb51701bd56f87b59945aa Mon Sep 17 00:00:00 2001 From: Bernat Date: Wed, 27 Jun 2018 14:22:07 +0200 Subject: [PATCH] add new procedure in the DB --- .../1.0.7/agencyHourGetFirstShipped.sql | 40 +++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 services/db/install/changes/1.0.7/agencyHourGetFirstShipped.sql diff --git a/services/db/install/changes/1.0.7/agencyHourGetFirstShipped.sql b/services/db/install/changes/1.0.7/agencyHourGetFirstShipped.sql new file mode 100644 index 000000000..50bb2a1e8 --- /dev/null +++ b/services/db/install/changes/1.0.7/agencyHourGetFirstShipped.sql @@ -0,0 +1,40 @@ +USE `vn`; +DROP procedure IF EXISTS `agencyHourGetFirstShipped`; + +DELIMITER $$ +USE `vn`$$ +CREATE DEFINER=`root`@`%` PROCEDURE `agencyHourGetFirstShipped`(vAgencyMode INT, vAddress INT, vWarehouse INT) +BEGIN +/** +* Devuelve la primera fecha de envio disponible para una agencia en una direccion y un warehouse +* +* @param vAgencyMode id de la agencia en vn.agencyMode +* @param vAddress id de la direccion +* @param vWarehouse id del warehouse +* @return vShipped la primera fecha disponible y vLanded la fecha de llegada/recojida +*/ +DECLARE vAgency INT; +DECLARE vShipped DATE; +DECLARE vLanded DATE DEFAULT CURDATE(); + SELECT agencyFk INTO vAgency FROM agencyMode WHERE id= vAgencyMode; + + l: LOOP + + CALL agencyHourGetShipped(vLanded,vAddress,vAgency); + SELECT shipped INTO vShipped + FROM tmp.agencyHourGetShipped + WHERE warehouseFk = vWarehouse LIMIT 1; + + IF vShipped THEN + LEAVE l; + END IF; + + SET vLanded = DATE_ADD(vLanded, INTERVAL +1 DAY); + + END LOOP; + + SELECT vShipped,vLanded; +END$$ + +DELIMITER ; +