


CREATE VIEW [dbo].[ApiItemsView] as

select Twr_TwrId Id,  Twr_TwrId ItemId, Twr_TwrId ErpId, cast(Twr_Typ as int) ItemType,
Twr_Nazwa Name, Twr_Kod  Code, Twr_NumerKat CatalogNumber,  
Twr_EAN EAN, Twr_JM UM, Twr_JMZ UM2, cast(Twr_JMCalkowite as int) IntegerFormat,
 cast ( Twr_JMPrzelicznikL/Twr_JmPomPrzelicznikM as decimal) UMRatio,
 ISNULL(csprn.TwC_Wartosc, cast(0 as decimal)) SellPriceNetto,
 ISNULL(csprb.TwC_Wartosc, cast(0 as decimal)) SellPriceBrutto,
  ISNULL(czak.TwC_Wartosc, cast(0 as decimal)) MinPriceNetto,
  ISNULL(czak.TwC_Wartosc, cast(0 as decimal)) BuyPrice,
  ISNULL(csprn.TwC_Waluta,'') Currency,
  --cast ( 0 as decimal) Quantity,
  ISNULL(Twr_WagaKG,0) Weight, cast(Twr_Stawka as varchar)  TaxDesc, Twr_Stawka  TaxValue,
   0 GroupId1, ''GroupName1, 0 GroupId2, ''GroupName2, case when (Twr_Kod LIKE 'WZ.%') then 1 else 0 end as [Status],
   Twr_Opis Description, CURRENT_TIMESTAMP TS,
   cast(0 as decimal) Size,'' FeatureType,  0 WaseItem, '' Material					 
   ,ISNULL(Twr_kntId,0) SupplierId
      ,cast (0 as float) StockMax, cast (0 as float) StockMin
  from CDN.Towary
  LEFT OUTER JOIN  CDN.TwrCeny csprn ON csprn.TwC_TwrID = Twr_TwrId and csprn.TwC_TwCNumer=5
  LEFT OUTER JOIN  CDN.TwrCeny csprb ON csprb.TwC_TwrID = Twr_TwrId and csprb.TwC_TwCNumer=6
  LEFT OUTER JOIN  CDN.TwrCeny czak ON czak.TwC_TwrID = Twr_TwrId and czak.TwC_TwCNumer=1

  
  --where Twr_Kod LIKE 'WZ.%' OR Twr_Kod LIKE 'AK%'

GO


