Merge pull request 'fix: refs #8492 Sage invoiceInTax Check VAT' (!3390) from 8492-InvoiceInTax-Check-VAT into dev
gitea/salix/pipeline/head This commit looks good Details

Reviewed-on: #3390
Reviewed-by: Javi Gallego <jgallego@verdnatura.es>
This commit is contained in:
Carlos Andrés 2025-01-28 17:58:17 +00:00
commit ec71cb8df6
1 changed files with 42 additions and 23 deletions

View File

@ -23,6 +23,7 @@ BEGIN
DECLARE vInvoiceTypeInformativeCode VARCHAR(1);
DECLARE vCountryCanariasCode, vCountryCeutaMelillaCode VARCHAR(2);
DECLARE vCompanyCode INT;
DECLARE vHasErrorTax BOOL DEFAULT FALSE;
SELECT SiglaNacion INTO vCountryCanariasCode
FROM Naciones
@ -66,6 +67,24 @@ BEGIN
WHERE enlazadoSage = FALSE
AND Asiento <> 1 ;
SELECT EXISTS (
SELECT TRUE
FROM vn.XDiario x
JOIN vn.invoiceIn ii ON ii.id = x.CLAVE
JOIN vn.invoiceInTax it ON it.invoiceInFk = ii.id
LEFT JOIN TiposIva ti ON ti.CodigoIva = it.taxTypeSageFk
LEFT JOIN taxType tt ON tt.id = it.taxTypeSageFk
WHERE x.FECHA BETWEEN vDatedFrom AND vDatedTo
AND NOT x.enlazadoSage
AND x.empresa_id = vCompanyFk
AND it.taxTypeSageFk
AND (ti.CodigoIva IS NULL OR tt.id IS NULL)
) INTO vHasErrorTax;
IF vHasErrorTax tHEN
CALL util.throw ('Error in tables for received invoices tax');
END IF;
CALL invoiceOut_manager(vYear, vCompanyFk);
CALL invoiceIn_manager(vYear, vCompanyFk);