
/****** Object:  View [dbo].[ApiDeviceServiceLinesView]    Script Date: 13.09.2021 14:53:02 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO



CREATE VIEW [dbo].[ApiDeviceServiceLinesView] 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, t.DefId
 from dbo.UrzadzeniaUzyte uu 
JOIN dbo.ApiCrmTasks t ON uu.Zadanie = t.ErpId and t.DefId = 3
 LEFT OUTER JOIN dbo.ApiDictionaries st ON st.ParentDefId = 2 and st.ErpId = uu.StanZadania
 JOIN dbo.ApiDevicesView d ON d.Id = uu.Urzadzenie
GO


