

CREATE VIEW [dbo].[ApiWMSErpToImportList] as
select d.TrN_TrNID ,  d.TrN_NumerPelny  from CDN.TraNag d 
JOIN CDN.DokDefinicje def ON d.TrN_DDfId = def.DDf_DDfID and def.DDf_Klasa in (303,304,306,307,310)
where 
  
	 TrN_Bufor = 0 and def.DDf_KierunekOrg <>0
	 and TrN_DataDok> '2021-09-01'
	-- wykluczyć te co są zrobione z ZD
--	and NOT EXISTS (select * from dbo.RelacjeHandlowe r JOIN dbo.DokHandlowe zd ON r.Nadrzedny = zd.ID where zd.Definicja = 85 and r.Podrzedny = d.ID)
   and NOT EXISTS ( select * from dbo.[ApiSyncItems] s where s.[SchemaId] = -10 and s.ObjectType = 40 and s.[ObjectId] = d.TrN_TrNID and s.Status = 2)
  -- and NOT EXISTS ( select * from dbo.Features where Name='WMS_Niegeneruj' and ParentType='DokHandlowe' and Parent = d.ID and DataKey=1)
GO

