salix/services/db/install/changes/1-orderGetTotal.sql

30 lines
689 B
MySQL
Raw Normal View History

2019-02-27 11:03:54 +00:00
USE `hedera`;
DROP procedure IF EXISTS `orderGetTotal`;
DELIMITER $$
USE `hedera`$$
CREATE DEFINER=`root`@`%` PROCEDURE `orderGetTotal`()
BEGIN
/**
* Calcula el total con IVA para un conjunto de orders.
*
* @table tmp.order(orderFk) Identificadores de las ordenes a calcular
* @return tmp.orderTotal Total para cada order
*/
CALL orderGetTax;
DROP TEMPORARY TABLE IF EXISTS tmp.orderTotal;
CREATE TEMPORARY TABLE tmp.orderTotal
(INDEX (orderFk))
ENGINE = MEMORY
2019-03-01 11:19:12 +00:00
SELECT o.orderFk, IFNULL(SUM(ot.taxableBase + ot.tax), 0.0) AS total
2019-02-27 11:03:54 +00:00
FROM tmp.order o
2019-03-01 11:19:12 +00:00
LEFT JOIN tmp.orderAmount ot ON o.orderFk = ot.orderFk
2019-02-27 11:03:54 +00:00
GROUP BY orderFk;
DROP TEMPORARY TABLE IF EXISTS tmp.orderTax;
END$$
DELIMITER ;