From eb159453cf35dd611da6af01451bb87e76cb3d63 Mon Sep 17 00:00:00 2001 From: Bernat Date: Thu, 19 Jul 2018 09:44:58 +0200 Subject: [PATCH] update structure --- ...Requery.sql => 09-manaSpellersRequery.sql} | 0 ...triggerTicket.sql => 10-triggerTicket.sql} | 0 .../changes/1.0.8/11-orderTotalVolume.sql | 20 ++++++++++++++ .../1.0.8/12-orderTotalVolumeBoxes.sql | 27 +++++++++++++++++++ 4 files changed, 47 insertions(+) rename services/db/install/changes/1.0.8/{manaSpellersRequery.sql => 09-manaSpellersRequery.sql} (100%) rename services/db/install/changes/1.0.8/{triggerTicket.sql => 10-triggerTicket.sql} (100%) create mode 100644 services/db/install/changes/1.0.8/11-orderTotalVolume.sql create mode 100644 services/db/install/changes/1.0.8/12-orderTotalVolumeBoxes.sql diff --git a/services/db/install/changes/1.0.8/manaSpellersRequery.sql b/services/db/install/changes/1.0.8/09-manaSpellersRequery.sql similarity index 100% rename from services/db/install/changes/1.0.8/manaSpellersRequery.sql rename to services/db/install/changes/1.0.8/09-manaSpellersRequery.sql diff --git a/services/db/install/changes/1.0.8/triggerTicket.sql b/services/db/install/changes/1.0.8/10-triggerTicket.sql similarity index 100% rename from services/db/install/changes/1.0.8/triggerTicket.sql rename to services/db/install/changes/1.0.8/10-triggerTicket.sql diff --git a/services/db/install/changes/1.0.8/11-orderTotalVolume.sql b/services/db/install/changes/1.0.8/11-orderTotalVolume.sql new file mode 100644 index 000000000..185e8ecc1 --- /dev/null +++ b/services/db/install/changes/1.0.8/11-orderTotalVolume.sql @@ -0,0 +1,20 @@ +USE `vn`; +DROP function IF EXISTS `orderTotalVolume`; + +DELIMITER $$ +USE `vn`$$ +CREATE DEFINER=`root`@`%` FUNCTION `orderTotalVolume`(vOrderId INT) RETURNS decimal(10,3) +BEGIN + -- Devuelte el volumen total de la orden sumada + DECLARE vWarehouseId INTEGER; + DECLARE vVolume DECIMAL(10,3); + + SELECT IFNULL(SUM(o.amount * r.cm3)/1000000,0) INTO vVolume + FROM hedera.orderRow o + JOIN bi.rotacion r on r.Id_Article = o.itemFk AND r.warehouse_id = o.warehouseFk + WHERE o.orderFk = vOrderId; + + RETURN vVolume; +END$$ + +DELIMITER ; diff --git a/services/db/install/changes/1.0.8/12-orderTotalVolumeBoxes.sql b/services/db/install/changes/1.0.8/12-orderTotalVolumeBoxes.sql new file mode 100644 index 000000000..69d6697c8 --- /dev/null +++ b/services/db/install/changes/1.0.8/12-orderTotalVolumeBoxes.sql @@ -0,0 +1,27 @@ +USE `vn`; +DROP function IF EXISTS `orderTotalVolumeBoxes`; + +DELIMITER $$ +USE `vn`$$ +CREATE DEFINER=`root`@`%` FUNCTION `orderTotalVolumeBoxes`(vOrderId INT) RETURNS decimal(10,3) +BEGIN + +/* + * Devuelve el volumen estimado del ticket sumado, en cajas + * + * idT Numero de ticket + * + */ + DECLARE vVolumeBoxM3 DOUBLE; + DECLARE vOrderTotalVolumeBoxes DECIMAL(10,1); + DECLARE vVnBoxId VARCHAR(10) DEFAULT '94'; + + SELECT volume / 1000000 INTO vVolumeBoxM3 FROM packaging WHERE id = vVnBoxId; + + SET vOrderTotalVolumeBoxes = orderTotalVolume(vOrderId) / vVolumeBoxM3; + + RETURN vOrderTotalVolumeBoxes; + +END$$ + +DELIMITER ; \ No newline at end of file