refs 6500 rateView
gitea/salix/pipeline/pr-dev This commit looks good Details

This commit is contained in:
Robert Ferrús 2024-03-05 13:21:53 +01:00
parent 9aad1dd6e8
commit e83b0622cf
1 changed files with 14 additions and 20 deletions

View File

@ -2,9 +2,7 @@ DELIMITER $$
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`rateView`() CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`rateView`()
BEGIN BEGIN
DECLARE v10Years DATE DEFAULT util.VN_CURDATE() - INTERVAL 10 YEAR; SELECT
SELECT
t.year, t.year,
t.month, t.month,
pagos.dollars, pagos.dollars,
@ -15,28 +13,24 @@ BEGIN
JOIN time t ON t.dated = ii.issued JOIN time t ON t.dated = ii.issued
JOIN invoiceInTax iit ON ii.id = iit.invoiceInFk JOIN invoiceInTax iit ON ii.id = iit.invoiceInFk
JOIN JOIN
( ( SELECT
SELECT t.year,
t.year, t.month,
t.month, CAST(SUM(divisa) AS DECIMAL(10,2)) dollars,
CAST(SUM(divisa) AS DECIMAL(10,2)) dollars, CAST(SUM(divisa) / SUM(amount) AS DECIMAL(5,4)) changePractical,
CAST(SUM(divisa) / SUM(amount) AS DECIMAL(5,4)) changePractical, CAST(rr.value * 0.998 AS DECIMAL(5,4)) changeOfficial
CAST(rr.value * 0.998 AS DECIMAL(5,4)) changeOfficial FROM payment p
FROM payment p JOIN time t ON t.dated = p.received
JOIN time t ON t.dated = p.received JOIN referenceRate rr ON rr.dated = p.received
JOIN referenceRate rr ON rr.dated = p.received JOIN currency c ON c.id = rr.currencyFk
JOIN currency c ON c.id = rr.currencyFk WHERE divisa
WHERE divisa AND c.code = 'USD'
AND p.received >= v10Years GROUP BY t.year, t.month
AND c.code = 'USD'
GROUP BY t.year, t.month
) pagos ON t.year = pagos.year AND t.month = pagos.MONTH ) pagos ON t.year = pagos.year AND t.month = pagos.MONTH
JOIN currency c ON c.id = ii.currencyFk JOIN currency c ON c.id = ii.currencyFk
WHERE c.code = 'USD' WHERE c.code = 'USD'
AND ii.issued >= v10Years
AND iit.foreignValue AND iit.foreignValue
AND iit.taxableBase AND iit.taxableBase
GROUP BY t.year, t.month; GROUP BY t.year, t.month;
END$$ END$$
DELIMITER ; DELIMITER ;