Hola chicos, aquí de nuevo dando lata
Tegngo esta consulta a la que solo tengo que agregarle la Orden de venta, ya intenté con ORDR Doc.Num y fallé miserablemente ¿cómo puedo distinguir qué comando usar? No sé programación y me resulta muy confuso
¡Gracias!
-- FACTURAS--
Select '1', NULL AS 'FECHA Contabilización','FACTURAS' AS 'Código Cliente' , null as 'Nombre Cliente', NULL as 'N° Docto',
NULL as 'Base', NULL as 'IVA', NULL as 'Total' --FROM OINV
UNION ALL
Select distinct '2', T0.DocDate as 'Fecha', T0.CardCode as 'Código Cliente',
Case When T0.CANCELED='N'
Then T0.CardName
Else 'CANCELADO'
End as 'Nombre Cliente',
T0.DocNum as 'N° Doc',
Case When T0.CANCELED='N'
then (T0.DocTotal-T0.VatSum-T0.DiscSum)
Else NULL
End as 'Base',
Case When T0.CANCELED='N'
Then T0.VatSum
Else NULL
End as 'IVA',
Case When T0.CANCELED='N'
Then T0.DocTotal
Else NULL
End as 'Total Facturado'
from OINV T0
Where T0.DocSubType <>'DN'
And T0.CANCELED <>'C'
And T0.DocDate Between '[%0]' and '[%1]'
UNION ALL
--SUMA FACTURAS--
SELECT '3', NULL, NULL, 'TOTAL FACTURAS', NULL,
SUM((T0.DocTotal-T0.VatSum-T0.DiscSum)) as 'Base',
SUM(T0.VatSum) as 'IVA',
SUM(T0.DocTotal) as 'Total Facturado'
FROM OINV T0
Where T0.DocSubType <>'DN'
And T0.CANCELED ='N'
And T0.DocDate Between '[%0]' and '[%1]'
Union ALL
Select '4', NULL AS 'FECHA Contabilización','NOTAS CRÉDITO' AS 'Código Cliente' , null as 'Nombre Cliente', NULL as 'N° Docto',
NULL as 'Base', NULL as 'IVA', NULL as 'Total' --FROM OINV
UNION ALL
--Notas de Crédito--
Select distinct '5', T0.DocDate as 'Fecha', T0.CardCode as 'Código Cliente',
Case When T0.CANCELED='N'
Then T0.CardName
Else 'CANCELADO'
End as 'Nombre Cliente',
T0.DocNum as 'N° Doc',
Case When T0.CANCELED='N'
then (T0.DocTotal-T0.VatSum-T0.DiscSum)
Else NULL
End as 'Base',
Case When T0.CANCELED='N'
Then T0.VatSum
Else NULL
End as 'IVA',
Case When T0.CANCELED='N'
Then T0.DocTotal
Else NULL
End as 'Total Facturado'
from ORIN T0
Where T0.CANCELED <>'C'
And T0.DocDate Between '[%0]' and '[%1]'
UNION ALL
--SUMA Notas Crédto--
SELECT '6', NULL, NULL, 'TOTAL NOTAS DE CRÉDITO', NULL,
SUM((T0.DocTotal-T0.VatSum-T0.DiscSum)) as 'Base',
SUM(T0.VatSum) as 'IVA',
SUM(T0.DocTotal) as 'Total Facturado'
FROM ORIN T0
Where T0.DocSubType <>'DN'
And T0.CANCELED ='N'
And T0.DocDate Between '[%0]' and '[%1]'
UNION ALL
Select '7', NULL AS 'FECHA Contabilización','NOTAS DE DEBITO' AS 'Código Cliente' , null as 'Nombre Cliente', NULL as 'N° Docto',
NULL as 'Base', NULL as 'IVA', NULL as 'Total' --FROM OINV
UNION ALL
-- NOTAS DEBITO--
Select distinct '8', T0.DocDate as 'Fecha', T0.CardCode as 'Código Cliente',
Case When T0.CANCELED='N'
Then T0.CardName
Else 'CANCELADO'
End as 'Nombre Cliente',
T0.DocNum as 'N° Doc',
Case When T0.CANCELED='N'
then (T0.DocTotal-T0.VatSum-T0.DiscSum)
Else NULL
End as 'Base',
Case When T0.CANCELED='N'
Then T0.VatSum
Else NULL
End as 'IVA',
Case When T0.CANCELED='N'
Then T0.DocTotal
Else NULL
End as 'Total Facturado'
from OINV T0
Where T0.DocSubType ='DN'
And T0.CANCELED <>'C'
And T0.DocDate Between '[%0]' and '[%1]'
UNION ALL
--SUMA FACTURAS--
SELECT '9', NULL, NULL, 'TOTAL NOTAS DE DÉBITO', NULL,
SUM((T0.DocTotal-T0.VatSum-T0.DiscSum)) as 'Base',
SUM(T0.VatSum) as 'IVA',
SUM(T0.DocTotal) as 'Total Facturado'
FROM OINV T0
Where T0.DocSubType ='DN'
And T0.CANCELED ='N'
And T0.DocDate Between '[%0]' and '[%1]'
Order By 1,5