2024-01-15 11:31:03 +00:00
|
|
|
DELIMITER $$
|
2024-08-20 08:06:10 +00:00
|
|
|
CREATE OR REPLACE DEFINER=`vn`@`localhost` FUNCTION `vn`.`orderTotalVolume`(vOrderId INT)
|
2024-01-15 11:31:03 +00:00
|
|
|
RETURNS decimal(10,3)
|
|
|
|
NOT DETERMINISTIC
|
|
|
|
READS SQL DATA
|
|
|
|
BEGIN
|
|
|
|
-- Devuelte el volumen total de la orden sumada
|
|
|
|
DECLARE vWarehouseId INTEGER;
|
|
|
|
DECLARE vVolume DECIMAL(10,3);
|
|
|
|
|
|
|
|
SELECT IFNULL(SUM(o.amount * ic.cm3delivery)/1000000,0) INTO vVolume
|
|
|
|
FROM hedera.orderRow o
|
|
|
|
JOIN item i ON i.id = o.itemFk
|
|
|
|
JOIN itemCost ic on ic.itemFk = o.itemFk AND ic.warehouseFk = o.warehouseFk
|
|
|
|
WHERE o.orderFk = vOrderId;
|
|
|
|
|
|
|
|
RETURN vVolume;
|
|
|
|
|
|
|
|
END$$
|
|
|
|
DELIMITER ;
|