Estimad@s buenas tardesr
Este Query corre en sap , pero necesito que traiga los montos con impuesto en mi caso seria 1.12 de IVA,
agradezco me puedan apoyar,
Saludos
/*SELECT FROM [dbo].[OINV] T0*/
declare @FInicial as Datetime
/* WHERE */
set @FInicial = /* T0.DocDate */ '[%0]'
/*SELECT FROM [dbo].[OINV] T0*/
declare @FFinal as Datetime
/* WHERE */
set @FFinal = /* T0.DocDate */ '[%1]'
SELECT T0.Fecha As 'Fecha'
, T0.Factura As 'Factura'
, T0.Tipo As 'Tipo'
, T0.Cliente As 'Cliente'
, CASE WHEN SUM(T0.Total_Factura) = 0
THEN '*** ANULADA ***'
ELSE T1.CardName
END 'Nombre'
, T1.U_Nit As 'NIT'
, T0.Descuento
, T0.Financiamiento
, SUM(T0.Total_Factura) As 'Total_Factura'
FROM
(
SELECT T0.TaxDate As 'Fecha'
, 'FAC' As 'Tipo'
, T0.CardCode As 'Cliente'
, T0.DocNum As 'Factura'
, SUM(T0.DocTotal)-SUM(T0.VatSum) As 'SubTotal'
, SUM(T0.VatSum) As 'IVA'
, SUM(T0.DiscSum) As 'Descuento'
, SUM(T0.TotalExpns) As 'Financiamiento'
, SUM(T0.DocTotal) As 'Total_Factura'
FROM [dbo].[OINV] T0
WHERE (T0.DocDate >= @FInicial OR @FInicial = '') AND (T0.DocDate <=@FFinal OR @FFinal = '')
GROUP BY T0.TaxDate, T0.CardCode, T0.DocNum
UNION ALL
SELECT T2.TaxDate As 'Fecha'
, 'N/C' As 'Tipo'
, T2.CardCode As 'Cliente'
, T1.BaseRef As 'Factura'
, -SUM (T1.LineTotal) As 'SubTotal'
, -SUM (T1.LineVat) As 'IVA'
, -SUM(T0.DiscSum) As 'Descuento'
, SUM(T0.TotalExpns) As 'Financiamiento'
, -SUM (T1.LineTotal+T1.LineVat) As 'Total_Factura'
FROM [dbo].[OINV] T0 INNER JOIN [dbo].[RIN1] T1 ON T0.DocEntry = T1.DocEntry
INNER JOIN [dbo].[ORIN] T2 ON T1.DocEntry = T2.DocEntry
WHERE (T2.DocDate >= @FInicial OR @FInicial = '') AND (T2.DocDate <=@FFinal OR @FFinal = '')
GROUP BY T2.TaxDate, T2.CardCode, T1.BaseRef
) T0 INNER JOIN OCRD T1 ON T0.Cliente = T1.CardCode
GROUP BY T0.Fecha
, T0.Factura
, T0.Tipo
, T0.Cliente
, T1.CardName
, T1.U_NIT
, T0.Descuento
, T0.Financiamiento
ORDER BY T0.Fecha
, T0.Factura
, T0.Tipo