27 lines
677 B
SQL
27 lines
677 B
SQL
|
|
DROP procedure IF EXISTS `hedera`.`orderGetTotal`;
|
|
DELIMITER $$
|
|
CREATE DEFINER=`root`@`%` PROCEDURE `hedera`.`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
|
|
SELECT o.orderFk, IFNULL(SUM(ot.taxableBase + ot.tax), 0.0) AS total
|
|
FROM tmp.order o
|
|
LEFT JOIN tmp.orderAmount ot ON o.orderFk = ot.orderFk
|
|
GROUP BY orderFk;
|
|
|
|
DROP TEMPORARY TABLE IF EXISTS tmp.orderTax;
|
|
END$$
|
|
|
|
DELIMITER ;
|