Hola,
Tengo el siguiente inconveniente en un script, necesito generar un código que me sume el iva para declaración el impuesto a la renta
La columna IVA debe ser igual al valor de este reporte, pero no me cuadra porque hay items que se les aplicó nota de crédito, pero no se como ponerlos en negativo
Alguien me de una mano, gracias
SELECT
'FACT' Tipo,
T4.ItemCode,
T0.TaxCode,
T1.DocNum Factura,
T0.Dscription Descripcion,
T0.Quantity Cantidad,
T0.LineTotal ValorAntesIva,
CASE WHEN T0.TaxCode = 'IVA12' THEN
ROUND((T0.LineTotal * 12) / 100, 2)
ELSE
0
END Iva,
CASE WHEN T0.TaxCode = 'IVA12' THEN
ROUND((T0.LineTotal * 1.12), 2)
ELSE
T0.LineTotal
END ValorMasIva
FROM
INV1 T0
INNER JOIN
OITM T4 ON T4.ItemCode = T0.ItemCode
INNER JOIN
OINV T1 ON T1.DocEntry = T0.DocEntry
WHERE
T1.DocDate BETWEEN '20210401' AND '20210430'
AND T0.ItemCode LIKE '%PT%'
AND T1.DocSubType = '--'
UNION ALL
SELECT
'FACT' Tipo,
T4.ItemCode,
T0.TaxCode,
T1.DocNum Factura,
T0.Dscription Descripcion,
T0.Quantity Cantidad,
T0.LineTotal ValorAntesIva,
CASE WHEN T0.TaxCode = 'IVA12' THEN
ROUND((T0.LineTotal * 12) / 100, 2)
ELSE
0
END Iva,
CASE WHEN T0.TaxCode = 'IVA12' THEN
ROUND((T0.LineTotal * 1.12), 2)
ELSE
T0.LineTotal
END ValorMasIva
FROM
INV1 T0
INNER JOIN
OITM T4 ON T4.ItemCode = T0.ItemCode
INNER JOIN
OINV T1 ON T1.DocEntry = T0.DocEntry
WHERE
T1.DocDate BETWEEN '20210401' AND '20210430'
AND T0.ItemCode LIKE '%MP%'
AND T1.DocSubType = '--'
UNION ALL
SELECT
'FACT' Tipo,
T0.TaxCode,
T4.TaxCodeAP,
T1.DocNum Factura,
T0.Dscription Descripcion,
T0.Quantity Cantidad,
T0.LineTotal ValorAntesIva,
CASE WHEN T0.TaxCode = 'IVA12' THEN
ROUND((T0.LineTotal * 12) / 100, 2)
ELSE
0
END Iva,
CASE WHEN T0.TaxCode = 'IVA12' THEN
ROUND((T0.LineTotal * 1.12), 2)
ELSE
T0.LineTotal
END ValorMasIva
FROM
INV1 T0
INNER JOIN
OITM T4 ON T4.ItemCode = T0.ItemCode
INNER JOIN
OINV T1 ON T1.DocEntry = T0.DocEntry
WHERE
T1.DocDate BETWEEN '20210401' AND '20210430'
AND T0.ItemCode LIKE '%SV%'
AND T1.DocSubType = '--'
UNION ALL
SELECT
'ND' Tipo,
T4.AcctCode,
T4.AcctName,
T1.DocNum Factura,
T0.Dscription Descripcion,
T0.Quantity Cantidad,
T0.LineTotal ValorAntesIva,
CASE WHEN T0.TaxCode = 'IVA12' THEN
ROUND((T0.LineTotal * 12) / 100, 2)
ELSE
0
END Iva,
CASE WHEN T0.TaxCode = 'IVA12' THEN
ROUND((T0.LineTotal * 1.12), 2)
ELSE
T0.LineTotal
END ValorMasIva
FROM
INV1 T0
INNER JOIN
OACT T4 ON T4.AcctCode = T0.AcctCode
INNER JOIN
OINV T1 ON T1.DocEntry = T0.DocEntry
WHERE
T1.DocDate BETWEEN '20210401' AND '20210430'
AND T1.DocSubType = 'DN'