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
gitea/salix/pipeline/head This commit looks good
Details
Reviewed-on: #3390 Reviewed-by: Javi Gallego <jgallego@verdnatura.es>
This commit is contained in:
commit
ec71cb8df6
|
@ -1,11 +1,11 @@
|
|||
DELIMITER $$
|
||||
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `sage`.`accountingMovements_add`(
|
||||
vYear INT,
|
||||
vYear INT,
|
||||
vCompanyFk INT
|
||||
)
|
||||
BEGIN
|
||||
/**
|
||||
* Traslada la info de contabilidad generada en base a vn.XDiario a la tabla sage.movConta
|
||||
* Traslada la info de contabilidad generada en base a vn.XDiario a la tabla sage.movConta
|
||||
* para poder ejecutar posteriormente el proceso de importación de datos de SQL Server
|
||||
* Solo traladará los asientos marcados con el campo vn.XDiario.enlazadoSage = FALSE
|
||||
* @vYear Año contable del que se quiere trasladar la información
|
||||
|
@ -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
|
||||
|
@ -44,12 +45,12 @@ BEGIN
|
|||
FROM taxType
|
||||
WHERE code = 'import4';
|
||||
|
||||
SELECT shipmentTransactionTypeFk,
|
||||
definitiveExportTransactionTypeFk,
|
||||
SELECT shipmentTransactionTypeFk,
|
||||
definitiveExportTransactionTypeFk,
|
||||
pendingServiceTransactionTypeFk,
|
||||
company_getCode(vCompanyFk)
|
||||
INTO vTransactionExportTaxFreeFk,
|
||||
vTransactionExportFk,
|
||||
vTransactionExportFk,
|
||||
vDuaTransactionFk,
|
||||
vCompanyCode
|
||||
FROM config;
|
||||
|
@ -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);
|
||||
|
||||
|
@ -306,8 +325,8 @@ BEGIN
|
|||
mci.FechaFacturaOriginal = x.FECHA_EX,
|
||||
mci.SuFacturaNo = x.FACTURAEX,
|
||||
mci.FechaOperacion = x.FECHA_OP,
|
||||
mci.ImporteFactura = mci.ImporteFactura +
|
||||
x.BASEEURO +
|
||||
mci.ImporteFactura = mci.ImporteFactura +
|
||||
x.BASEEURO +
|
||||
CAST((x.IVA / 100) * x.BASEEURO AS DECIMAL(10, 2))
|
||||
WHERE pm.description = 'HP Iva pendiente'
|
||||
AND mci.enlazadoSage = FALSE
|
||||
|
@ -326,7 +345,7 @@ BEGIN
|
|||
mci.CodigoIva2 = vTaxImportFk,
|
||||
mci.IvaDeducible2 = TRUE,
|
||||
mci.ImporteFactura = mci.ImporteFactura +
|
||||
x.BASEEURO +
|
||||
x.BASEEURO +
|
||||
CAST((x.IVA / 100) * x.BASEEURO AS DECIMAL(10, 2))
|
||||
WHERE pm.description = 'HP Iva pendiente'
|
||||
AND mci.enlazadoSage = FALSE
|
||||
|
@ -344,8 +363,8 @@ BEGIN
|
|||
mci.CodigoTransaccion3 = vDuaTransactionFk ,
|
||||
mci.CodigoIva3 = vTaxImportSuperReducedFk,
|
||||
mci.IvaDeducible3 = TRUE,
|
||||
mci.ImporteFactura = mci.ImporteFactura +
|
||||
x.BASEEURO +
|
||||
mci.ImporteFactura = mci.ImporteFactura +
|
||||
x.BASEEURO +
|
||||
CAST((x.IVA / 100) * x.BASEEURO AS DECIMAL(10, 2))
|
||||
WHERE pm.description = 'HP Iva pendiente'
|
||||
AND mci.enlazadoSage = FALSE
|
||||
|
@ -379,14 +398,14 @@ BEGIN
|
|||
OR CodigoTransaccion2 = vTransactionExportFk
|
||||
OR CodigoTransaccion3 = vTransactionExportFk
|
||||
OR CodigoTransaccion4 = vTransactionExportFk)
|
||||
AND SiglaNacion IN (vCountryCanariasCode COLLATE utf8mb3_unicode_ci,
|
||||
AND SiglaNacion IN (vCountryCanariasCode COLLATE utf8mb3_unicode_ci,
|
||||
vCountryCeutaMelillaCode COLLATE utf8mb3_unicode_ci);
|
||||
|
||||
UPDATE movConta mc
|
||||
SET CodigoDivisa = 'USD',
|
||||
FactorCambio = TRUE,
|
||||
ImporteCambio = ABS( CAST( IF( ImporteDivisa <> 0 AND ImporteCambio = 0,
|
||||
ImporteAsiento / ImporteDivisa,
|
||||
ImporteCambio = ABS( CAST( IF( ImporteDivisa <> 0 AND ImporteCambio = 0,
|
||||
ImporteAsiento / ImporteDivisa,
|
||||
ImporteCambio) AS DECIMAL( 10, 2)))
|
||||
WHERE enlazadoSage = FALSE
|
||||
AND (ImporteCambio <> 0 OR ImporteDivisa <> 0 OR FactorCambio);
|
||||
|
@ -403,20 +422,20 @@ BEGIN
|
|||
WITH client AS(
|
||||
SELECT DISTINCT c.id
|
||||
FROM sage.movConta mc
|
||||
JOIN vn.client c ON c.accountingAccount = mc.CodigoCuenta
|
||||
WHERE NOT enlazadoSage
|
||||
),supplier AS(
|
||||
JOIN vn.client c ON c.accountingAccount = mc.CodigoCuenta
|
||||
WHERE NOT enlazadoSage
|
||||
),supplier AS(
|
||||
SELECT DISTINCT s.id
|
||||
FROM sage.movConta mc
|
||||
JOIN vn.supplier s ON s.account = mc.CodigoCuenta
|
||||
WHERE NOT enlazadoSage
|
||||
JOIN vn.supplier s ON s.account = mc.CodigoCuenta
|
||||
WHERE NOT enlazadoSage
|
||||
),clientSupplierSync AS(
|
||||
SELECT idClientSupplier, `type`
|
||||
FROM sage.clientSupplier cs
|
||||
WHERE isSync
|
||||
FROM sage.clientSupplier cs
|
||||
WHERE isSync
|
||||
)
|
||||
SELECT idClientSupplier, `type`
|
||||
FROM sage.clientSupplier cs
|
||||
FROM sage.clientSupplier cs
|
||||
WHERE NOT isSync
|
||||
UNION
|
||||
SELECT id, 'C'
|
||||
|
@ -424,7 +443,7 @@ BEGIN
|
|||
LEFT JOIN clientSupplierSync cs ON cs.idClientSupplier = c.id
|
||||
AND cs.Type ='C'
|
||||
WHERE cs.idClientSupplier IS NULL
|
||||
UNION
|
||||
UNION
|
||||
SELECT id, 'P'
|
||||
FROM supplier s
|
||||
LEFT JOIN clientSupplierSync cs ON cs.idClientSupplier = s.id
|
||||
|
@ -436,7 +455,7 @@ BEGIN
|
|||
INSERT IGNORE INTO sage.clientSupplier (companyFk, `type`, idClientSupplier, isSync)
|
||||
SELECT vCompanyCode, `type`, idClientSupplier, FALSE
|
||||
FROM tmp.clientSupplier;
|
||||
|
||||
|
||||
DROP TEMPORARY TABLE tmp.clientSupplier;
|
||||
|
||||
CALL pgc_add(vCompanyFk);
|
||||
|
|
Loading…
Reference in New Issue