te mando el query Terminado, Saludos y ojala les puedas servir
Select T0.docdate, 'FC' as 'Tipo Doc', t0.docnum, T0.TransId Asiento, t1.AcctCode,
Case When t1.AcctCode = T2.AcctCode Then T2.AcctName End [Cuenta Ventas], T1.CogsAcct,
--Case When t1.cogsacct = T2.AcctCode Then T2.AcctName End [Nombre Cuenta Costo],
t1.itemcode Codigo, t1.Dscription, t1.Quantity ,
Case when T0.DocCur in ('USD', 'EUR') then (T1.LineTotal * T0.DocRate) else t1.LineTotal end as 'Total MXP',
t1.OcrCode Finca, t1.OcrCode2 'U. de Negocio', t1.OcrCode3 Fase
From OINV T0 Inner Join
INV1 T1 on T0.DocEntry = T1.DocEntry Inner Join
OACT T2 on T1.AcctCode = T2.AcctCode
Where T0.DocDate >= [%0] and T0.DocDate <= [%1] and T0.CANCELED ='N'
union all
Select T0.docdate, 'NCC' as 'Tipo Doc', t0.docnum, T0.TransId Asiento, t1.AcctCode,
Case When t1.AcctCode = T2.AcctCode Then T2.AcctName End [Cuenta Ventas], T1.CogsAcct,
--Case When t1.cogsacct = T2.AcctCode Then T2.AcctName End [Nombre Cuenta Costo],
t1.itemcode Codigo, t1.Dscription, t1.Quantity ,
Case when T0.DocCur in ('USD', 'EUR') then ((T1.LineTotal * T0.DocRate)*-1) else t1.LineTotal end as 'Total MXP',
t1.OcrCode Finca, t1.OcrCode2 'U. de Negocio', t1.OcrCode3 Fase
From ORIN T0 Inner Join
RIN1 T1 on T0.DocEntry = T1.DocEntry Inner Join
OACT T2 on T1.AcctCode = T2.AcctCode
Where T0.DocDate >= [%0] and T0.DocDate <= [%1] and T0.CANCELED ='N'
union all
Select T0.docdate, 'NCC' as 'Tipo Doc', t0.docnum, T0.TransId Asiento, t1.AcctCode,
Case When t1.AcctCode = T2.AcctCode Then T2.AcctName End [Cuenta Ventas], T1.CogsAcct,
--Case When t1.cogsacct = T2.AcctCode Then T2.AcctName End [Nombre Cuenta Costo],
t1.itemcode Codigo, t1.Dscription, t1.Quantity ,
Case when T0.DocCur in ('USD', 'EUR') then ((T1.LineTotal * T0.DocRate)*-1) else t1.LineTotal end as 'Total MXP',
t1.OcrCode Finca, t1.OcrCode2 'U. de Negocio', t1.OcrCode3 Fase
From ORIN T0 Inner Join
RIN1 T1 on T0.DocEntry = T1.DocEntry Inner Join
OACT T2 on T1.AcctCode = T2.AcctCode
Where T0.DocDate >= [%0] and T0.DocDate <= [%1] and T0.CANCELED ='N'
Union all
Select T0.docdate, 'EM' as 'Tipo Doc', t0.docnum, T0.TransId Asiento, t1.AcctCode,
Case When t1.AcctCode = T2.AcctCode Then T2.AcctName End [Cuenta Ventas], T1.CogsAcct,
--Case When t1.cogsacct = T2.AcctCode Then T2.AcctName End [Nombre Cuenta Costo],
t1.itemcode Codigo, t1.Dscription, t1.Quantity ,
Case when T0.DocCur in ('USD', 'EUR') then ((T1.LineTotal * T0.DocRate)*-1) else t1.LineTotal end as 'Total MXP',
t1.OcrCode Finca, t1.OcrCode2 'U. de Negocio', t1.OcrCode3 Fase
From OPDN T0 Inner Join
PDN1 T1 on T0.DocEntry = T1.DocEntry Inner Join
OACT T2 on T1.AcctCode = T2.AcctCode
Where T0.DocDate >= [%0] and T0.DocDate <= [%1] and T0.CANCELED ='N'
union all
Select T0.docdate, 'FP' as 'Tipo Doc', t0.docnum, T0.TransId Asiento, t1.AcctCode,
Case When t1.AcctCode = T2.AcctCode Then T2.AcctName End [Cuenta Ventas], T1.CogsAcct,
--Case When t1.cogsacct = T2.AcctCode Then T2.AcctName End [Nombre Cuenta Costo],
t1.itemcode Codigo, t1.Dscription, t1.Quantity ,
Case when T0.DocCur in ('USD', 'EUR') then ((T1.LineTotal * T0.DocRate)*-1) else t1.LineTotal end as 'Total MXP',
t1.OcrCode Finca, t1.OcrCode2 'U. de Negocio', t1.OcrCode3 Fase
From OPCH T0 Inner Join
PCH1 T1 on T0.DocEntry = T1.DocEntry Inner Join
OACT T2 on T1.AcctCode = T2.AcctCode
Where T0.DocDate >= [%0] and T0.DocDate <= [%1] and T0.CANCELED ='N'
union all
Select T0.docdate, 'NCP' as 'Tipo Doc', t0.docnum, T0.TransId Asiento, t1.AcctCode,
Case When t1.AcctCode = T2.AcctCode Then T2.AcctName End [Cuenta Ventas], T1.CogsAcct,
--Case When t1.cogsacct = T2.AcctCode Then T2.AcctName End [Nombre Cuenta Costo],
t1.itemcode Codigo, t1.Dscription, t1.Quantity ,
Case when T0.DocCur in ('USD', 'EUR') then ((T1.LineTotal * T0.DocRate)*-1) else t1.LineTotal end as 'Total MXP',
t1.OcrCode Finca, t1.OcrCode2 'U. de Negocio', t1.OcrCode3 Fase
From ORPC T0 Inner Join
RPC1 T1 on T0.DocEntry = T1.DocEntry Inner Join
OACT T2 on T1.AcctCode = T2.AcctCode
Where T0.DocDate >= [%0] and T0.DocDate <= [%1] and T0.CANCELED ='N'
union all
Select T0.docdate, 'SM' as 'Tipo Doc', t0.docnum, T0.TransId Asiento, t1.AcctCode,
Case When t1.AcctCode = T2.AcctCode Then T2.AcctName End [Cuenta Ventas], T1.CogsAcct,
--Case When t1.cogsacct = T2.AcctCode Then T2.AcctName End [Nombre Cuenta Costo],
t1.itemcode Codigo, t1.Dscription, t1.Quantity ,
Case when T0.DocCur in ('USD', 'EUR') then ((T1.LineTotal * T0.DocRate)*-1) else t1.LineTotal end as 'Total MXP',
t1.OcrCode Finca, t1.OcrCode2 'U. de Negocio', t1.OcrCode3 Fase
From OIGE T0 Inner Join
IGE1 T1 on T0.DocEntry = T1.DocEntry Inner Join
OACT T2 on T1.AcctCode = T2.AcctCode
Where T0.DocDate >= [%0] and T0.DocDate <= [%1] and T0.CANCELED ='N'
order by t0.docdate