USE [IHBoxSystem]
GO
CREATE ROLE LMFHeatAccept AUTHORIZATION dbo 
GO  

CREATE ROLE CAS1HeatAccept AUTHORIZATION dbo 
GO  


USE [IHBoxSystem]
GO
EXEC sp_addrolemember 'LMFHeatAccept', 'admin'
GO

USE [IHBoxSystem]
GO
EXEC sp_addrolemember 'CAS1HeatAccept', 'admin'
GO


USE [IHBoxSystem]
GO
EXEC sp_addrolemember 'LMFHeatAccept', 'SDI/australtek'
GO

USE [IHBoxSystem]
GO
EXEC sp_addrolemember 'CAS1HeatAccept', 'SDI/australtek'
GO






USE [IHBoxSystem]
GO

DECLARE @ModuleId INT

INSERT INTO [SECURITY].[Modules]
		   ([Code]
		   ,[Name])
	 VALUES
		   ('caster_1_accept_ladle'
		   ,'Caster 1 Accept Ladle')

		  SET @ModuleId = @@IDENTITY

INSERT INTO [SECURITY].[ModuleActions]
		   ([ModuleId]
		   ,[Code]
		   ,[Name]
		   ,[Role])
	 VALUES
		   (@ModuleId
		   ,'readWrite'
		   ,'Read/Write'
		   ,'CAS1HeatAccept')
GO


USE [IHBoxSystem]
GO

DECLARE @ModuleId INT

INSERT INTO [SECURITY].[Modules]
		   ([Code]
		   ,[Name])
	 VALUES
		   ('lmf_accept_ladle'
		   ,'LMF Accept Ladle')

		  SET @ModuleId = @@IDENTITY

INSERT INTO [SECURITY].[ModuleActions]
		   ([ModuleId]
		   ,[Code]
		   ,[Name]
		   ,[Role])
	 VALUES
		   (@ModuleId
		   ,'readWrite'
		   ,'Read/Write'
		   ,'LMFHeatAccept')
GO



EXECUTE sys.sp_addextendedproperty 
@level0type = N'USER' -- The object type
,@level0name = [LMFHeatAccept] -- The role
,@name = N'securedsp-MES.TriggerAcceptance' -- the procedure
,@value = N'' 
GO

EXECUTE sys.sp_addextendedproperty 
@level0type = N'USER' -- The object type
,@level0name = [CAS1HeatAccept] -- The role
,@name = N'securedsp-MES.TriggerAcceptance' -- the procedure
,@value = N'' 
GO


EXECUTE sys.sp_addextendedproperty 
@level0type = N'USER' -- The object type
,@level0name = [LMFHeatAccept] -- The role
,@name = N'securedsp-MES.AcceptHeat' -- the procedure
,@value = N'' 
GO

EXECUTE sys.sp_addextendedproperty 
@level0type = N'USER' -- The object type
,@level0name = [CAS1HeatAccept] -- The role
,@name = N'securedsp-MES.AcceptHeat' -- the procedure
,@value = N'' 
GO

ALTER TABLE LAD.Heats
ADD AcceptedInCAS1 BIT NOT NULL DEFAULT 0

ALTER TABLE LAD.Heats
ADD AcceptedInLMF BIT NOT NULL DEFAULT 0

/***********------------------------------***********/
/***********------------------------------***********/
/***********------------------------------***********/
/***********------------------------------***********/
/***********------------------------------***********/
/***********------------------------------***********/
/***********------------------------------***********/
/***********------------------------------***********/
/***********------------------------------***********/
/***********------------------------------***********/
/***********------------------------------***********/

CREATE ROLE UNKHeatDetection AUTHORIZATION dbo 
GO  
USE [IHBoxSystem]
GO
EXEC sp_addrolemember 'UNKHeatDetection', 'admin'
GO

USE [IHBoxSystem]
GO
EXEC sp_addrolemember 'UNKHeatDetection', 'SDI/australtek'
GO


USE [IHBoxSystem]
GO

DECLARE @ModuleId INT

INSERT INTO [SECURITY].[Modules]
		   ([Code]
		   ,[Name])
	 VALUES
		   ('unk_heat_detection'
		   ,'UNK Heat Detection')

		  SET @ModuleId = @@IDENTITY

INSERT INTO [SECURITY].[ModuleActions]
		   ([ModuleId]
		   ,[Code]
		   ,[Name]
		   ,[Role])
	 VALUES
		   (@ModuleId
		   ,'readWrite'
		   ,'Read/Write'
		   ,'UNKHeatDetection')
GO

EXECUTE sys.sp_addextendedproperty 
@level0type = N'USER' -- The object type
,@level0name = [UNKHeatDetection] -- The role
,@name = N'securedsp-MES.TriggerAcceptance' -- the procedure
,@value = N'' 
GO












/***********---------------------------------***********/
/***********---------------------------------***********/
/***********---------------------------------***********/
/***********---------------------------------***********/
/***********-------------10/06/2022----------***********/
/***********-------------10/06/2022----------***********/
/***********-------------10/06/2022----------***********/
/***********---------------------------------***********/
/***********---------------------------------***********/
/***********---------------------------------***********/
/***********---------------------------------***********/









CREATE ROLE WrongMODetection AUTHORIZATION dbo 
GO  

USE [IHBoxSystem]
GO
EXEC sp_addrolemember 'WrongMODetection', 'admin'
GO

USE [IHBoxSystem]
GO
EXEC sp_addrolemember 'WrongMODetection', 'SDI/australtek'
GO


USE [IHBoxSystem]
GO

DECLARE @ModuleId INT

INSERT INTO [SECURITY].[Modules]
		   ([Code]
		   ,[Name])
	 VALUES
		   ('wrong_mo_detection'
		   ,'Wrong Melt Order Detection')

		  SET @ModuleId = @@IDENTITY

INSERT INTO [SECURITY].[ModuleActions]
		   ([ModuleId]
		   ,[Code]
		   ,[Name]
		   ,[Role])
	 VALUES
		   (@ModuleId
		   ,'readWrite'
		   ,'Read/Write'
		   ,'WrongMODetection')
GO


--------------------------------------
--------- Automatic Popup's ----------
--------------------------------------
-- Automatic Popup's:
-- ROLES: WrongMODetection / UNKHeatDetection
-- SPs: LAD.CheckPopupConditions /  LAD.GetPopupMeltOrders / LAD.AcceptHeat


-- LAD.CheckPopupConditions

EXECUTE sys.sp_addextendedproperty 
@level0type = N'USER' -- The object type
,@level0name = [WrongMODetection] -- The role
,@name = N'securedsp-LAD.CheckPopupConditions' -- the procedure
,@value = N'' 
GO
EXECUTE sys.sp_addextendedproperty 
@level0type = N'USER' -- The object type
,@level0name = [UNKHeatDetection] -- The role
,@name = N'securedsp-LAD.CheckPopupConditions' -- the procedure
,@value = N'' 
GO


-- LAD.GetPopupMeltOrders
EXECUTE sys.sp_addextendedproperty 
@level0type = N'USER' -- The object type
,@level0name = [WrongMODetection] -- The role
,@name = N'securedsp-LAD.GetPopupMeltOrders' -- the procedure
,@value = N'' 
GO
EXECUTE sys.sp_addextendedproperty 
@level0type = N'USER' -- The object type
,@level0name = [UNKHeatDetection] -- The role
,@name = N'securedsp-LAD.GetPopupMeltOrders' -- the procedure
,@value = N'' 
GO

-- LAD.AcceptHeat
EXECUTE sys.sp_addextendedproperty 
@level0type = N'USER' -- The object type
,@level0name = [WrongMODetection] -- The role
,@name = N'securedsp-LAD.AcceptHeat' -- the procedure
,@value = N'' 
GO
EXECUTE sys.sp_addextendedproperty 
@level0type = N'USER' -- The object type
,@level0name = [UNKHeatDetection] -- The role
,@name = N'securedsp-LAD.AcceptHeat' -- the procedure
,@value = N'' 
GO




--------------------------------------
--------- Melt Shop Popup's ----------
--------------------------------------
-- Melt shop Popup's:
-- ROLES: LMFHeatAccept / CAS1HeatAccept
-- Main SP : GetMeltShopOverview
-- SPs: LAD.GetPopupMeltOrders / LAD.AcceptHeat


--LAD.GetPopupMeltOrders
EXECUTE sys.sp_addextendedproperty 
@level0type = N'USER' -- The object type
,@level0name = [LMFHeatAccept] -- The role
,@name = N'securedsp-LAD.GetPopupMeltOrders' -- the procedure
,@value = N'' 
GO

EXECUTE sys.sp_addextendedproperty 
@level0type = N'USER' -- The object type
,@level0name = [CAS1HeatAccept] -- The role
,@name = N'securedsp-LAD.GetPopupMeltOrders' -- the procedure
,@value = N'' 
GO

--  LAD.AcceptHeat
EXECUTE sys.sp_addextendedproperty 
@level0type = N'USER' -- The object type
,@level0name = [LMFHeatAccept] -- The role
,@name = N'securedsp-LAD.AcceptHeat' -- the procedure
,@value = N'' 
GO

EXECUTE sys.sp_addextendedproperty 
@level0type = N'USER' -- The object type
,@level0name = [CAS1HeatAccept] -- The role
,@name = N'securedsp-LAD.AcceptHeat' -- the procedure
,@value = N'' 
GO
