Para los que nos preguntemos que material de nuestros pedidos aún no están en los almacenes, pueden resolver esa inquietud con esta consulta que aquí les dejo, contempla las OC que van directamente a almacén y las OC que pasan previamente por una factura para después iniciar la o las entradas al almacén.
Select a.docdate, a.DocNum, a.CardCode, a.CardName, b.ItemCode, b.Dscription
, b.WhsCode, b.Quantity, b.InvntSttus, b.LineStatus, b.OpenQty, d.SlpName as [Comprador]
, (select DocNum from OPRQ where DocEntry = (select Top 1 T1.BaseEntry from POR1 T1 inner join OPOR T0 on T0.DocEntry = T1.DocEntry
where T0.Segment = 0 and T1.BaseEntry is not null and T0.DocNum = a.DocNum)) as SC
,(select ReqName from OPRQ where DocEntry = (select Top 1 T1.BaseEntry from POR1 T1 inner join OPOR T0 on T0.DocEntry = T1.DocEntry
where T0.Segment = 0 and T1.BaseEntry is not null and T0.DocNum = a.DocNum)) as Solicitante
from OPOR a
inner join POR1 b on a.DocEntry = b.DocEntry
inner join OITM c on b.ItemCode = c.ItemCode
inner join OSLP d on a.SlpCode = d.SlpCode
and b.InvntSttus = 'O' and b.TargetType in (20,-1)
and a.CANCELED = 'N'
and c.frozenFor = 'N'
and c.validFor = 'Y'
and c.InvntItem = 'Y'
and a.DocStatus <> 'C'
union all
select a.docdate, a.DocNum, a.CardCode, a.CardName, b.ItemCode, b.Dscription
, b.WhsCode, b.Quantity, d.InvntSttus, b.LineStatus, d.OpenQty, f.SlpName as [Comprador]
, (select DocNum from OPRQ where DocEntry = (select Top 1 b.BaseEntry from POR1 b inner join OPOR a on a.DocEntry = b.DocEntry
where a.Segment = 0 and b.BaseEntry is not null and a.DocNum = (select distinct DocNum from OPOR where DocEntry = d.BaseEntry and d.BaseType = 22))) as SC
, (select ReqName from OPRQ where DocEntry = (select Top 1 b.BaseEntry from POR1 b inner join OPOR a on a.DocEntry = b.DocEntry
where a.Segment = 0 and b.BaseEntry is not null and a.DocNum = (select distinct DocNum from OPOR where DocEntry = d.BaseEntry and d.BaseType = 22))) as Solicitante
from OPOR a
inner join POR1 b on a.DocEntry = b.DocEntry
inner join OPCH c on b.TrgetEntry = c.DocEntry
inner join PCH1 d on c.DocEntry = d.DocEntry
inner join OITM e on b.ItemCode = e.ItemCode
inner join OSLP f on a.SlpCode = f.SlpCode
and d.InvntSttus = 'O' and b.TargetType in (18,-1)
and e.frozenFor = 'N'
and e.validFor = 'Y'
and e.InvntItem = 'Y'
and d.BaseLine = b.LineNum and d.ItemCode = b.ItemCode
and a.CANCELED = 'N'