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