
/****** Object:  View [dbo].[ApiCustomerView]    Script Date: 13.09.2021 14:18:33 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

CREATE VIEW [dbo].[ApiCustomerView] as
select Knt_KntId Id,Knt_KntId CustId ,Knt_KntId ErpId, RTRIM(Knt_Nazwa1 + ' '+ Knt_Nazwa2 + ' '+ Knt_Nazwa3) Name, Knt_Kod Code, Knt_NipE TAXID, 0 as [Type] ,
Knt_KodPocztowy AdrrZip , Knt_Miasto AdrrCity, Knt_Ulica AdrrStreet , Knt_NrDomu AdrrNumber,  Knt_NrLokalu AdrrAppNumber, Knt_Kraj AdrrCountry,
Knt_Telefon1 Phone, Knt_Telefon2 Phone2, Knt_Email Email, Knt_Opis Notes, Knt_Grupa CategoryName, 0 CategoryId, cast( Knt_BlokadaDok as bit) Locked,

ISNULL(fpd.Value,'') payment, cast( Knt_Termin as int) paymentTime,  ISNULL(fpd.Id,0) paymentId,
Knt_LimitKredytu PaymentLimit,  Knt_Waluta PaymentCurrency,
0 as vendorId, Knt_EAN EAN, cast( 0 as float) geolat,cast( 0 as float) geolong, cast ( 0 as decimal) LoyaltyScore, ''  LoyaltyPasswd,
'' VendorName,'' VendorPhone,'' VendorMail, '' WWW, 0 Status, CURRENT_TIMESTAMP TS, 0 SaveTS, '' DeviceUid, 0 State, ISNULL(Rab_Rabat,0) Discount
, ISNULL((select top 1 Id from dbo.ApiDictionaries where ParentDefId = 31 and ErpKey LIKE '%'+ Knt_KrajISO+',%'),0)
RegionId, '' Features, Knt_KrajISO, cast(Knt_Ceny as int)  PriceId
from CDN.Kontrahenci
LEFT OUTER JOIN CDN.Rabaty ON  Rab_Typ=2 and  Rab_PodmiotId = Knt_KntId



/*   
 
        public string DeviceUid { get; set; }
        public int State { get; set; }
*/


GO


