salix/db/routines/vn/procedures/rateView.sql

39 lines
1.2 KiB
MySQL
Raw Normal View History

2024-03-05 11:41:54 +00:00
DELIMITER $$
CREATE OR REPLACE DEFINER=`vn-admin`@`localhost` PROCEDURE `vn`.`rateView`()
2024-03-05 11:41:54 +00:00
BEGIN
2024-04-12 05:58:18 +00:00
/**
* Muestra información sobre tasas de cambio de Dolares
*/
2024-03-05 12:21:53 +00:00
SELECT
2024-04-17 11:11:28 +00:00
t.year año,
t.month mes,
pay.dollars dolares,
pay.changePractical cambioPractico,
CAST(SUM(iit.foreignValue ) / SUM(iit.taxableBase) AS DECIMAL(5,4))cambioTeorico,
pay.changeOfficial cambioOficial
2024-03-05 11:41:54 +00:00
FROM invoiceIn ii
JOIN time t ON t.dated = ii.issued
JOIN invoiceInTax iit ON ii.id = iit.invoiceInFk
JOIN
2024-03-05 12:21:53 +00:00
( SELECT
t.year,
t.month,
2024-04-12 10:13:07 +00:00
CAST(SUM(p.divisa) AS DECIMAL(10,2)) dollars,
CAST(SUM(p.divisa) / SUM(p.amount) AS DECIMAL(5,4)) changePractical,
2024-03-05 12:21:53 +00:00
CAST(rr.value * 0.998 AS DECIMAL(5,4)) changeOfficial
FROM payment p
JOIN time t ON t.dated = p.received
JOIN referenceRate rr ON rr.dated = p.received
JOIN currency c ON c.id = rr.currencyFk
2024-04-12 10:13:07 +00:00
WHERE p.divisa
2024-03-05 12:21:53 +00:00
AND c.code = 'USD'
GROUP BY t.year, t.month
2024-04-17 09:00:00 +00:00
) pay ON t.year = pay.year AND t.month = pay.month
2024-03-05 11:41:54 +00:00
JOIN currency c ON c.id = ii.currencyFk
WHERE c.code = 'USD'
AND iit.foreignValue
AND iit.taxableBase
GROUP BY t.year, t.month;
END$$
DELIMITER ;