
/****** Object:  View [dbo].[ApiImpDocWeryfikacjaView]    Script Date: 13.09.2021 14:26:26 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO




CREATE VIEW [dbo].[ApiImpDocWeryfikacjaView] as
 
select 
 doc.ErpId Id, 'MagazynOpis' Name,0 DefId, 10 Typ, doc.ErpId ObiektId, 0 ObiektTyp,    doc.Description Wartosc     
  from dbo.ApiDocuments doc where Description<>'' and doc.[State]=2 and  DATEDIFF(second,doc.TS,CURRENT_TIMESTAMP) >10
  and doc.VendorId=0
UNION
 select doc.ErpId Id, 'StanWeryfikacji' Name,0 DefId, 10 Typ, doc.ErpId ObiektId, 0 ObiektTyp,    'Zweryfikowany' Wartosc      
  from dbo.ApiDocuments doc          
  JOIN dbo.ApiDefinitions def ON doc.DefId = def.ErpId and def.Behaviour = 3         
  JOIN dbo.[ApiDownloadObjects] do ON doc.ErpId =  do.objectId and do.status>1         
  where [State] =2     and  DATEDIFF(second,doc.TS,CURRENT_TIMESTAMP) >10  
  and doc.VendorId=0 
UNION


 select doc.ErpId Id, 'StanWeryfikacji' Name,0 DefId, 10 Typ, doc.ErpId ObiektId, 0 ObiektTyp,    'Zweryfikowany' Wartosc      
  from dbo.ApiDocuments doc          
  where [State] =4     and  DATEDIFF(second,doc.TS,CURRENT_TIMESTAMP) >10  and DefId = 40


GO


