30 lines
689 B
SQL
30 lines
689 B
SQL
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
|
|
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 ;
|