2024-01-15 11:31:03 +00:00
|
|
|
DELIMITER $$
|
2024-08-20 08:06:10 +00:00
|
|
|
CREATE OR REPLACE DEFINER=`vn`@`localhost` FUNCTION `vn`.`invoiceOutAmount`(vInvoiceRef VARCHAR(15))
|
2024-01-15 11:31:03 +00:00
|
|
|
RETURNS decimal(10,2)
|
|
|
|
NOT DETERMINISTIC
|
|
|
|
READS SQL DATA
|
|
|
|
BEGIN
|
|
|
|
DECLARE totalAmount DECIMAL(10,2);
|
|
|
|
|
|
|
|
SELECT SUM(vat) INTO totalAmount
|
|
|
|
FROM (
|
|
|
|
SELECT iot.vat
|
|
|
|
FROM invoiceOutTax iot
|
|
|
|
JOIN invoiceOut io ON io.id = iot.invoiceOutFk
|
|
|
|
WHERE io.ref = vInvoiceRef
|
|
|
|
UNION ALL
|
|
|
|
SELECT ioe.amount
|
|
|
|
FROM invoiceOutExpense ioe
|
|
|
|
JOIN invoiceOut io ON io.id = ioe.invoiceOutFk
|
|
|
|
WHERE io.ref = vInvoiceRef
|
|
|
|
) t1;
|
|
|
|
|
|
|
|
RETURN totalAmount;
|
|
|
|
END$$
|
|
|
|
DELIMITER ;
|