
/****** Object:  View [dbo].[ApiFeaturesErpDefsView]    Script Date: 13.09.2021 15:14:37 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO



CREATE VIEW [dbo].[ApiFeaturesErpDefsView]
AS
SELECT     ID AS ErpId, 
CASE WHEN ([TableName] = 'DokHandlowe') THEN 0 ELSE CASE WHEN (TableName = 'Zadania') THEN 1 ELSE 
CASE WHEN ([TableName] = 'PozycjeDokHan') THEN 2 ELSE
CASE WHEN ([TableName] = 'Kontrahenci') THEN 3 ELSE
CASE WHEN ([TableName] = 'Towary') THEN 4 ELSE
CASE WHEN ([TableName] = 'Urzadzenia') THEN 5 ELSE
CASE WHEN ([TableName] = 'Lokalizacje') THEN 7 ELSE
- 1 END END END END END end END AS ObjectType, Name, Description, 
                      CASE WHEN (TypeNumber = 2 AND Dictionary <> '') THEN 10 ELSE CASE WHEN (TypeNumber = 14) THEN 11 ELSE 
                      CASE WHEN (TypeNumber = 13 and  TypeInformation ='Pracownicy') then 206
                      ELSE
                      TypeNumber END END END AS 'TypeNumber'
FROM         dbo.FeatureDefs
WHERE     (Algorithm <=1) AND 
(TableName = 'DokHandlowe' OR TableName = 'Zadania' OR TableName='PozycjeDokHan'
OR TableName = 'Kontrahenci' OR TableName = 'Towary' OR TableName='Urzadzenia'
OR TableName='Lokalizacje'
                      ) AND                       
                      (TypeNumber <> 13
                      OR TypeNumber =13 and (TypeInformation in('Pracownicy') )
                      )
                      
UNION select -1 as ErpId, 0 ObjectType, 'Fotografia' Name, '' Description, 101 TypeNumber
UNION select -2 as ErpId, 1 ObjectType, 'Fotografia' Name, '' Description, 101 TypeNumber
UNION select -3 as ErpId, 2 ObjectType, 'Fotografia' Name, '' Description, 101 TypeNumber	
UNION select -4 as ErpId, 3 ObjectType, 'Fotografia' Name, '' Description, 101 TypeNumber
UNION select -5 as ErpId, 4 ObjectType, 'Fotografia' Name, '' Description, 101 TypeNumber
UNION select -6 as ErpId, 5 ObjectType, 'Fotografia' Name, '' Description, 101 TypeNumber
UNION select -11 as ErpId, 0 ObjectType, 'Podpis' Name, '' Description, 104 TypeNumber
UNION select -12 as ErpId, 1 ObjectType, 'Podpis' Name, '' Description, 104 TypeNumber





GO


