
/****** Object:  View [dbo].[ApiLinesInfoView]    Script Date: 13.09.2021 15:17:28 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO





CREATE VIEW [dbo].[ApiLinesInfoView]
AS
SELECT     p.ID AS Id, p.ID AS ErpId, p.ID AS lineId, p.Dokument AS documentId, p.Dokument AS IdDocId, 
p.Lp AS lp, t.ID AS itemId, ISNULL(p.Nazwa,t.Nazwa) AS itemName, t.Kod AS itemCode, 
                      p.Opis AS itemDescription, p.IloscMagazynuSymbol AS itemUM,'' itemUM2, 
					  case when (p.IloscMagazynuValue<>0) then  CAST(p.SumaNetto / p.IloscMagazynuValue AS Decimal(18, 2))else 0 end AS itemPrice, 
                      CAST(p.CenaValue AS Decimal(18, 2)) AS itemOrgPrice, CAST(p.Rabat AS Decimal(18, 2)) AS discount, 
					  CAST( p.IloscMagazynuValue  AS Decimal(18, 2)) AS quantity, 
                      CAST(p.SumaNetto AS Decimal(18, 2)) AS value, CAST(0 AS decimal) AS veryfiedQuantity, t.EAN AS itemEAN, 0 vendorId,
                      ''  LocationName, '' Batch, 0 BatchId, '' BatchEAN, 0 Status, 0 CategoryId,'' CategoryName,
					  0 as ItemStatus,'' lineStatus, 0 lineChance,'' CategoryName2, '' LineType
					  ,p.SumaNetto Netto, p.SumaBrutto Brutto, 
					   ISNULL(stawka.Kod, '') AS TaxDesc, ISNULL(CONVERT(DECIMAL(16, 4),  stawka.StawkaProcent * 100), 0) AS TaxRate
					    , 0 ReservationType, 0 Direction, 0 RepositoryId
FROM         dbo.PozycjeDokHan AS p INNER JOIN
                      dbo.Towary AS t ON t.ID = p.Towar 
					  JOIN dbo.DefStawekVat AS stawka ON t.DefinicjaStawki = stawka.ID 	
                      
		


                 











GO


