
/****** Object:  View [dbo].[ApiImpDocView]    Script Date: 13.09.2021 14:25:56 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO



CREATE VIEW [dbo].[ApiImpDocView] as
SELECT  d.Id TrN_TrNID ,d.CustId TrN_PodId,  [NumberString] TrN_NumerPelny ,[Number] TrN_Numer,[Year] TrN_Rok,
[Month] TrN_Miesiac,[DefId] TrN_DdfId,[Series] TrN_Seria  ,[Date] TrN_DataDok,[Date] TrN_DataWys,[Date] TrN_DataOpe  ,
d.Description TrN_Opis ,d.vendorId TrN_VendorId,[lines] TrN_Lines,[value] TrN_RazemNetto,
d.RepositoryId TrN_MagId,CustLocId Trn_LocId
,ddef.DDf_Klasa TrN_TypDokumentu,State
--, m.Mag_Symbol MAG_Symbol, p.PaymentType TrN_FPlId, p.DueDate PaymentDueDate
  FROM [dbo].[ApiDocuments] d
  JOIN dbo.ApiDefinitions def ON d.DefId = def.Id --and def.Behaviour<>3
  JOIN CDN.DokDefinicje ddef ON ddef.DDf_DDfID = def.ErpId
--JOIN CDN.DetalStanowiska s ON d.VendorId = s.DSta_DStaId JOIN CDN.Magazyny m ON m.Mag_MagId = s.DSta_MagIdZwrotny
--JOIN dbo.ApiPayments p ON d.DocId = p.DocId and p.VendorId = d.VendorId and d.Date = p.DocumentDate
where State=2

GO


