This commit is contained in:
parent
743f317b20
commit
2a6dc0c478
|
@ -198,40 +198,37 @@ BEGIN
|
|||
WHERE mci.id = vXDiarioFk
|
||||
AND e.name = 'Retenciones'
|
||||
AND id.id IS NULL;
|
||||
|
||||
-- SAGE
|
||||
SELECT correctedFk INTO vInvoiceInOriginalFk
|
||||
FROM vn.invoiceInCorrection
|
||||
WHERE correctingFk = vInvoiceInFk;
|
||||
|
||||
IF vInvoiceInOriginalFk THEN
|
||||
|
||||
UPDATE movContaIVA mci
|
||||
JOIN vn.invoiceInRefund iir ON iir.invoiceInRefundFk = vInvoiceInFk
|
||||
JOIN (SELECT issued,
|
||||
SUM(sub.taxableBase) taxableBase,
|
||||
SUM(ROUND((sub.taxableBase * sub.PorcentajeIva) / 100 , 2)) vat
|
||||
FROM(SELECT issued,
|
||||
SUM(iit.taxableBase) taxableBase,
|
||||
ti.PorcentajeIva
|
||||
FROM vn.invoiceIn i
|
||||
JOIN vn.invoiceInTax iit ON iit.invoiceInFk = i.id
|
||||
JOIN sage.TiposIva ti ON ti.CodigoIva = iit.taxTypeSageFk
|
||||
WHERE i.id = vInvoiceInOriginalFk
|
||||
GROUP BY ti.CodigoIva)sub
|
||||
)invoiceInOriginal
|
||||
JOIN ClavesOperacion co ON co.Descripcion = 'Factura rectificativa'
|
||||
SET mci.TipoRectificativa = iir.refundCategoryFk,
|
||||
mci.ClaseAbonoRectificativas = iir.refundType,
|
||||
mci.FechaFacturaOriginal = invoiceInOriginal.issued,
|
||||
mci.FechaOperacion = invoiceInOriginal.issued,
|
||||
mci.BaseImponibleOriginal = invoiceInOriginal.taxableBase,
|
||||
mci.CuotaIvaOriginal = invoiceInOriginal.vat,
|
||||
mci.ClaveOperacionFactura = co.ClaveOperacionFactura_
|
||||
WHERE mci.id = vXDiarioFk;
|
||||
SELECT correctedFk INTO vInvoiceInOriginalFk
|
||||
FROM vn.invoiceInCorrection
|
||||
WHERE correctingFk = vInvoiceInFk;
|
||||
|
||||
END IF;
|
||||
IF vInvoiceInOriginalFk THEN
|
||||
|
||||
UPDATE movContaIVA mci
|
||||
JOIN vn.invoiceInRefund iir ON iir.invoiceInRefundFk = vInvoiceInFk
|
||||
JOIN (SELECT issued,
|
||||
SUM(sub.taxableBase) taxableBase,
|
||||
SUM(ROUND((sub.taxableBase * sub.PorcentajeIva) / 100 , 2)) vat
|
||||
FROM(SELECT issued,
|
||||
SUM(iit.taxableBase) taxableBase,
|
||||
ti.PorcentajeIva
|
||||
FROM vn.invoiceIn i
|
||||
JOIN vn.invoiceInTax iit ON iit.invoiceInFk = i.id
|
||||
JOIN sage.TiposIva ti ON ti.CodigoIva = iit.taxTypeSageFk
|
||||
WHERE i.id = vInvoiceInOriginalFk
|
||||
GROUP BY ti.CodigoIva)sub
|
||||
)invoiceInOriginal
|
||||
JOIN ClavesOperacion co ON co.Descripcion = 'Factura rectificativa'
|
||||
SET mci.TipoRectificativa = iir.refundCategoryFk,
|
||||
mci.ClaseAbonoRectificativas = iir.refundType,
|
||||
mci.FechaFacturaOriginal = invoiceInOriginal.issued,
|
||||
mci.FechaOperacion = invoiceInOriginal.issued,
|
||||
mci.BaseImponibleOriginal = invoiceInOriginal.taxableBase,
|
||||
mci.CuotaIvaOriginal = invoiceInOriginal.vat,
|
||||
mci.ClaveOperacionFactura = co.ClaveOperacionFactura_
|
||||
WHERE mci.id = vXDiarioFk;
|
||||
|
||||
END IF;
|
||||
END$$
|
||||
DELIMITER ;
|
Loading…
Reference in New Issue