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

27 lines
677 B
MySQL
Raw Normal View History

2019-02-27 11:03:54 +00:00
2019-03-13 08:45:49 +00:00
DROP procedure IF EXISTS `hedera`.`orderGetTotal`;
2019-02-27 11:03:54 +00:00
DELIMITER $$
2019-03-13 08:45:49 +00:00
CREATE DEFINER=`root`@`%` PROCEDURE `hedera`.`orderGetTotal`()
2019-02-27 11:03:54 +00:00
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 ;