salix/db/routines/vn/functions/orderTotalVolume.sql

21 lines
562 B
MySQL
Raw Permalink Normal View History

DELIMITER $$
2024-08-20 08:06:10 +00:00
CREATE OR REPLACE DEFINER=`vn`@`localhost` FUNCTION `vn`.`orderTotalVolume`(vOrderId INT)
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 ;