
/****** Object:  View [dbo].[ApiDeviceLinesView]    Script Date: 13.09.2021 14:51:41 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO


CREATE VIEW [dbo].[ApiDeviceLinesView] as
select uu.ID Id, uu.ID DeviceLineId, uu.ID   ErpId ,
 t.Id TaskId, 0 DocumentId, 0 DocId, '' CategoryName, '' State, st.Id [StateId],
 0 ModelId, '' ModelSymbol, 0 ManufactureYear, 
 uu.Urzadzenie DeviceId, d.SerialNumber DeviceSerialNumber, d.Code DeviceCode, d.Name DeviceName,
 0 as Counters, cast(0 as decimal) Price,  cast(0 as decimal) Value, cast(0 as decimal) Quantity, 
 '' Description, ISNULL(st.NumberValue,0) ReservationType, t.PlanDateFrom ReservationFrom, uu.DataZamkniecia ReservationTo,
 0 as WarrantyCounter, 0 WarrantyMonths,
 uu.Zadanie ErpTaskId, 0 Modified
 from dbo.UrzadzeniaUzyte uu 
JOIN dbo.ApiCrmTasks t ON uu.Zadanie = t.ErpId and t.DefId = 1
 JOIN dbo.ApiDictionaries st ON st.ParentDefId = 1 and st.ErpId = uu.StanZadania
 JOIN dbo.ApiDevicesView d ON d.Id = uu.Urzadzenie
GO


