Merge pull request 'test' (!2466) from test into dev
gitea/salix/pipeline/head This commit looks good Details

Reviewed-on: #2466
Reviewed-by: Javi Gallego <jgallego@verdnatura.es>
This commit is contained in:
Carlos Andrés 2024-05-16 17:21:54 +00:00
commit dab90633db
1 changed files with 28 additions and 22 deletions

View File

@ -1,24 +1,24 @@
DELIMITER $$ DELIMITER $$
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`invoiceInTax_getFromEntries`(IN vInvoiceInFk INT) CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`invoiceInTax_getFromEntries`(
IN vInvoiceInFk INT
)
BEGIN BEGIN
DECLARE vRate DOUBLE DEFAULT 1; DECLARE vRate DOUBLE DEFAULT 1;
DECLARE vDated DATE;
DECLARE vExpenseFk VARCHAR(10); DECLARE vExpenseFk VARCHAR(10);
SELECT MAX(rr.dated) INTO vDated WITH rate AS(
FROM referenceRate rr SELECT MAX(rr.dated) dated, ii.currencyFk
JOIN invoiceIn ii ON ii.id = vInvoiceInFk FROM vn.invoiceIn ii
WHERE rr.dated <= ii.issued JOIN vn.referenceRate rr ON rr.currencyFk = ii.currencyFk
AND rr.currencyFk = ii.currencyFk ; WHERE ii.id = vInvoiceInFk
AND rr.dated <= ii.issued
IF vDated THEN ) SELECT `value` INTO vRate
SELECT `value` INTO vRate FROM vn.referenceRate rr
FROM referenceRate JOIN rate r ON r.dated = rr.dated
WHERE dated = vDated; AND r.currencyFk = rr.currencyFk;
END IF;
SELECT id INTO vExpenseFk SELECT id INTO vExpenseFk
FROM vn.expense FROM expense
WHERE `name` = 'Adquisición mercancia Extracomunitaria' WHERE `name` = 'Adquisición mercancia Extracomunitaria'
GROUP BY id GROUP BY id
LIMIT 1; LIMIT 1;
@ -26,19 +26,25 @@ BEGIN
DELETE FROM invoiceInTax DELETE FROM invoiceInTax
WHERE invoiceInFk = vInvoiceInFk; WHERE invoiceInFk = vInvoiceInFk;
INSERT INTO invoiceInTax(invoiceInFk, taxableBase, expenseFk, foreignValue, taxTypeSageFk, transactionTypeSageFk) INSERT INTO invoiceInTax(
SELECT ii.id, invoiceInFk,
SUM(b.buyingValue * b.quantity) / IFNULL(vRate,1) taxableBase, taxableBase,
expenseFk,
foreignValue,
taxTypeSageFk,
transactionTypeSageFk
)SELECT ii.id,
SUM(b.buyingValue * b.quantity) / vRate taxableBase,
vExpenseFk, vExpenseFk,
IF(ii.currencyFk = 1,NULL,SUM(b.buyingValue * b.quantity )) divisa, IF(ii.currencyFk = 1,
NULL,
SUM(b.buyingValue * b.quantity )),
taxTypeSageFk, taxTypeSageFk,
transactionTypeSageFk transactionTypeSageFk
FROM invoiceIn ii FROM invoiceIn ii
JOIN entry e ON e.invoiceInFk = ii.id JOIN entry e ON e.invoiceInFk = ii.id
JOIN supplier s ON s.id = e.supplierFk JOIN supplier s ON s.id = e.supplierFk
JOIN buy b ON b.entryFk = e.id JOIN buy b ON b.entryFk = e.id
LEFT JOIN referenceRate rr ON rr.currencyFk = ii.currencyFk
AND rr.dated = ii.issued
WHERE ii.id = vInvoiceInFk WHERE ii.id = vInvoiceInFk
HAVING taxableBase IS NOT NULL; HAVING taxableBase IS NOT NULL;
END$$ END$$