¡Buenos días compañeros!
Me podrían apoyar con este Query de informe de ventas de facturas por artículos, ya funciona todo correcto pero me podrían apoyar que todas las facturas canceladas me aparezca su importe en negativo, agradecería mucho su ayuda, les anexo el Query:
SELECT
T0.[DocDate], T0.[DocNum] AS 'No. Documento',T0.[DocEntry] AS 'ID Interno',
(case when T0.DocStatus = 'O' then 'Abierto'
when T0.DocStatus = 'C' and T0.CANCELED = 'N' then 'Cerrado'
when T0.DocStatus = 'C' and T0.CANCELED = 'Y' then 'Cancelado'
else T0.DocStatus
end) as 'Estatus',
T0.[CardCode] AS 'Codigo del SN',T0.[Comments] AS 'Comentarios',T0.[CardName] AS 'Nombre del SN',T1.[ItemCode],
T1.[Dscription],T0.[NumAtCard] as 'Referencia SN',T1.[U_Marca], T1.[U_Modelo], T1.[U_Serie],
T1.[Quantity], T1.[Price] as 'Precio', (T1.GrossBuyPr * T1.Quantity) as 'U. Costo', T1.[Currency] AS 'Moneda', T0.[DocRate] AS 'Tipo de Cambio',
T1.[LineTotal] AS 'Total linas (MXN)', T0.[VatSum] AS 'Impuesto total (MXN)', T0.[DocTotal] AS 'Total del documento (MXN)',
T2.[SlpName] AS 'Empleado de Ventas', T0.[CANCELED],
(CASE WHEN T1.Currency = 'MXN' THEN ((T1.Price - T1.GrossBuyPr) * T1.Quantity)
WHEN t1.Currency = 'USD' THEN (((T1.Price * T0.DocRate) - T1.GrossBuyPr) * T1.Quantity)
ELSE ' '
END) as 'Utilidad'
FROM OINV T0
INNER JOIN INV1 T1 ON T0.DocEntry = T1.DocEntry
INNER JOIN OSLP T2 ON T0.SlpCode = T2.SlpCode
WHERE T0.[DocDate] >=[%0] and T0.[DocDate] <=[%1]
UNION ALL
SELECT
T0.[DocDate], T0.[DocNum] AS 'No. Documento',T0.[DocEntry] AS 'ID Interno',
(case when T0.DocStatus = 'O' then 'Abierto'
when T0.DocStatus = 'C' and T0.CANCELED = 'N' then 'Cerrado'
when T0.DocStatus = 'C' and T0.CANCELED = 'Y' then 'Cancelado'
else T0.DocStatus
end) as 'Estatus',
T0.[CardCode] AS 'Codigo del SN', T0.[Comments] AS 'Comentarios',T0.[CardName] AS 'Nombre del SN', T1.[ItemCode], T1.[Dscription], T0.[NumAtCard] as 'Referencia SN',
T1.[U_Marca], T1.[U_Modelo], T1.[U_Serie], T1.[Quantity], T1.[Price] as 'Precio', (T1.GrossBuyPr * T1.Quantity) as 'U. Costo',
T1.[Currency] AS 'Moneda', T0.[DocRate] AS 'Tipo de Cambio',
(T1.[LineTotal])*-1 AS 'Total linas (MXN)',
(T0.[VatSum])*-1 AS 'Impuesto total (MXN)',
(T0.[DocTotal])*-1 AS 'Total del documento (MXN)',
T2.[SlpName] AS 'Empleado de Ventas', T0.[CANCELED],
(CASE WHEN T1.Currency = 'MXN' THEN ((T1.Price - T1.GrossBuyPr) * T1.Quantity) *-1
WHEN t1.Currency = 'USD' THEN (((T1.Price * T0.DocRate) - T1.GrossBuyPr) * T1.Quantity) *-1
ELSE ' '
END) as 'Utilidad'
FROM ORIN T0
INNER JOIN RIN1 T1 ON T0.DocEntry = T1.DocEntry
INNER JOIN OSLP T2 ON T0.SlpCode = T2.SlpCode
WHERE T0.[DocDate] >=[%0] and T0.[DocDate] <=[%1]