
---------ENUM Values
-- Role

SET IDENTITY_INSERT [dbo].[RDM_Role] ON;
INSERT INTO [RDM_Role]
	(RoleID,Name,PwdExpiryInDays,ModifiedBy,IsMigrationRequired)
SELECT	RoleID,Name,PwdExpiryInDays,ModifiedBy,0
FROM	NxGenKeystone..[Role]

SET IDENTITY_INSERT [dbo].[RDM_Role] OFF;


--  KeyMark Level

SET IDENTITY_INSERT [dbo].RDM_KeyMarkLevel ON;
INSERT INTO [dbo].RDM_KeyMarkLevel (KeyMarkLevelID, KeyMarkLevel,IsMigrationRequired)
SELECT KeyMarkLevelID,KeyMarkLevel,0
FROM NxGenKeystone..KeyMarkLevel

SET IDENTITY_INSERT [dbo].RDM_KeyMarkLevel OFF;

--  Mark

SET IDENTITY_INSERT [dbo].RDM_Mark ON;
INSERT INTO [dbo].RDM_Mark (MarkID, Mark,IsMigrationRequired)
SELECT	MarkID,Mark,0
FROM	NxGenKeystone..Mark
SET IDENTITY_INSERT [dbo].RDM_Mark OFF;

--  PinSize

SET IDENTITY_INSERT [dbo].RDM_PinSize ON;
INSERT INTO [dbo].RDM_PinSize (PinSizeID, PinSize,IsMigrationRequired)
SELECT	PinSizeID,PinSize,0
FROM NxGenKeystone..PinSize
SET IDENTITY_INSERT [dbo].RDM_PinSize OFF;

--  System Type

SET IDENTITY_INSERT [dbo].RDM_SystemType ON;
INSERT INTO [dbo].RDM_SystemType (SystemTypeID, SystemType,IsMigrationRequired)
SELECT	SystemTypeID,SystemType,0
FROM NxGenKeystone..SystemType
SET IDENTITY_INSERT [dbo].RDM_SystemType OFF;

--  Product Type

SET IDENTITY_INSERT [dbo].RDM_ProductType ON;
INSERT INTO [dbo].RDM_ProductType (ProductTypeID, ProductType,IsMigrationRequired)
SELECT	ProductTypeID,ProductType,0
FROM NxGenKeystone..ProductType
SET IDENTITY_INSERT [dbo].RDM_ProductType OFF;

------------------

-- Location
SET IDENTITY_INSERT [dbo].RDM_Facility ON; 
INSERT INTO RDM_Facility
	(FacilityID, FacilityName, Path, Description, LastBackup, IsDeleted, ModifiedDate, Notes,IsMigrationRequired)	
SELECT	FacilityID, FacilityName, Path, Description, LastBackup, IsDeleted, ModifiedDate, Notes,0
FROM	NxGenKeystone..Facility	fac
SET IDENTITY_INSERT [dbo].RDM_Facility OFF;

DELETE FROM RDM_Facility;

SET IDENTITY_INSERT [dbo].facility_master ON; 
INSERT INTO facility_master
	(ID, FacilityName)	
SELECT	FacilityID, FacilityName
FROM	NxGenKeystone..Facility	fac
SET IDENTITY_INSERT [dbo].facility_master OFF;

DELETE FROM facility_master;

/* --------------------------  MIGRATE Maintain List Values	--------------------------------------------------- Start */
	
	-- FacilityZone
		SET IDENTITY_INSERT [dbo].RDM_FacilityZone ON;
		INSERT INTO RDM_FacilityZone
			( FacilityZoneID, ZoneName, FacilityID, IsMigrationRequired )
		SELECT FacilityZoneID, ZoneName, FacilityID, 0
		FROM	NxGenKeystone..FacilityZone fzone
		SET IDENTITY_INSERT [dbo].RDM_FacilityZone OFF;

		DELETE FROM RDM_FacilityZone;

	-- DoorType
		SET IDENTITY_INSERT [dbo].[RDM_DoorType] ON;
		INSERT INTO [RDM_DoorType]
			( DoorTypeID, Type, FacilityID, IsMigrationRequired )
		SELECT	DoorTypeID, Type, FacilityID, 0
		FROM	NxGenKeystone..[DoorType] dtypes
		SET IDENTITY_INSERT [dbo].[RDM_DoorType] OFF;

		DELETE FROM [RDM_DoorType];

	-- EmployeeType
		SET IDENTITY_INSERT [dbo].[RDM_EmpType] ON;
		INSERT INTO [RDM_EmpType]
			( EmpTypeID, Type, FacilityID, IsMigrationRequired )
		SELECT	EmpTypeID, Type, FacilityID, 0
		FROM	NxGenKeystone..[EmpType] etypes
		SET IDENTITY_INSERT [dbo].[RDM_EmpType] OFF;

		DELETE FROM [RDM_EmpType];

	-- EmployeeTitle
		SET IDENTITY_INSERT [dbo].[RDM_EmpTitle] ON;
		INSERT INTO [RDM_EmpTitle]
			( EmpTitleID, Title, FacilityID, IsMigrationRequired )
		SELECT	EmpTitleID, Title, FacilityID, 0
		FROM	NxGenKeystone..[EmpTitle] eti
		SET IDENTITY_INSERT [dbo].[RDM_EmpTitle] OFF;

		DELETE FROM [RDM_EmpTitle];

	-- Keyways
		SET IDENTITY_INSERT [dbo].[RDM_Keyway] ON;
		INSERT INTO [RDM_Keyway] 
			( KeywayID, KeywayName, FacilityID, IsMigrationRequired )
		SELECT	KeywayID, KeywayName, FacilityID, 0
		FROM	NxGenKeystone..[Keyway] kwy
		SET IDENTITY_INSERT [dbo].[RDM_Keyway] OFF;

		DELETE FROM [RDM_Keyway];

	-- KeymarkStatus
		SET IDENTITY_INSERT [dbo].[RDM_KeyMarkStatus] ON;
		INSERT INTO [RDM_KeyMarkStatus]
			( KeymarkStatusID, Status, FacilityID, IsMigrationRequired )
		SELECT	KeymarkStatusID, Status, FacilityID, 0
		FROM	NxGenKeystone..[KeyMarkStatus] kms
		SET IDENTITY_INSERT [dbo].[RDM_KeyMarkStatus] OFF;

		DELETE FROM [RDM_KeyMarkStatus];

	-- ProductMfg

		SET IDENTITY_INSERT [dbo].RDM_ProductMfg ON;
		INSERT INTO RDM_ProductMfg
			( MfgID, MfgName, IsMigrationRequired )
		SELECT	MfgID, MfgName, 0
		FROM	NxGenKeystone..ProductMfg mf
		SET IDENTITY_INSERT [dbo].RDM_ProductMfg OFF;

		DELETE FROM RDM_ProductMfg;

/* --------------------------  MIGRATE Maintain List Values	--------------------------------------------------- End */

	-- Building

		SET IDENTITY_INSERT [dbo].[RDM_Building] ON;
		INSERT INTO [dbo].[RDM_Building]
			( BuildingID, BuildingName, Description, FacilityZoneID, Notes, FacilityID, ModifiedDate, IsMigrationRequired)
		SELECT	BuildingID, BuildingName, Description, FacilityZoneID, Notes, FacilityID, ModifiedDate, 0
		FROM	NxGenKeystone..[Building] bldg
		SET IDENTITY_INSERT [dbo].[RDM_Building] OFF;

		DELETE FROM [RDM_Building];

	--Department
		
		SET IDENTITY_INSERT [dbo].[RDM_Department] ON;
		INSERT INTO [dbo].[RDM_Department]
			( DeptID, DeptName, Description, Notes, FacilityID, ModifiedDate, IsMigrationRequired)
		SELECT	DeptID, DeptName, Description, Notes, FacilityID, ModifiedDate, 0
		FROM	NxGenKeystone..[Department] dept
		SET IDENTITY_INSERT [dbo].[RDM_Department] OFF;

		DELETE FROM [RDM_Department];

	--Cabinet

		SET IDENTITY_INSERT [dbo].[RDM_Cabinet] ON;
		INSERT INTO [dbo].[RDM_Cabinet]
			( CabinetID, CabinetName, CabinetDesription, FacilityID, Notes, ModifiedDate,IsDeleted, IsMigrationRequired)
		SELECT	CabinetID, CabinetName, CabinetDesription, FacilityID, Notes, ModifiedDate,0, 0
		FROM	NxGenKeystone..[Cabinet] cabn
		SET IDENTITY_INSERT [dbo].[RDM_Cabinet] OFF;

		DELETE FROM [RDM_Cabinet];
	
	--Hook
		
		SET IDENTITY_INSERT [dbo].[RDM_Hook] ON;
		INSERT INTO [dbo].[RDM_Hook]
			( HookID, HookUID, HookName, HookDescription, CabinetID, Notes, IsDeleted, DeletedDate, ModifiedDate, IsMigrationRequired)
		SELECT	HookID, HookUID, HookName, HookDescription, CabinetID, Notes, IsDeleted, DeletedDate, ModifiedDate, 0
		FROM	NxGenKeystone..[Hook] hks
		SET IDENTITY_INSERT [dbo].[RDM_Hook] OFF;

		DELETE FROM [RDM_Hook];

	--Door

		SET IDENTITY_INSERT [dbo].[RDM_Door] ON;
		INSERT INTO [dbo].[RDM_Door]
			( DoorID, DoorUID, DoorTypeID, DoorNumber, Area, Description, BuildingID, IsDeleted, DeletedDate, Notes, FacilityID, ModifiedDate, IsMigrationRequired)
		SELECT	DoorID, DoorUID, DoorTypeID, DoorNumber, Area, Description, BuildingID, IsDeleted, DeletedDate, Notes, FacilityID, ModifiedDate, 0
		FROM	NxGenKeystone..[Door] drs
		SET IDENTITY_INSERT [dbo].[RDM_Door] OFF;

		DELETE FROM [RDM_Door];

	--Employee  (EmployeeUID,Notes)		

		SET IDENTITY_INSERT [dbo].[RDM_Employee] ON;
		INSERT INTO [dbo].[RDM_Employee]
			( EmployeeId, EmpTypeID, EmpTitleID, DeptID, IsDeleted, DeletedDate, Notes, FacilityID, ModifiedDate, IsMigrationRequired)
		SELECT	EmployeeId, EmpTypeID, EmpTitleID, DeptID, IsDeleted, DeletedDate, Notes, FacilityID, ModifiedDate, 0
		FROM	NxGenKeystone..[Employee] emp
		SET IDENTITY_INSERT [dbo].[RDM_Employee] OFF;
		
		DELETE FROM [RDM_Employee];		

	-- Product (Refer this Notes for all other Notes)

		SET IDENTITY_INSERT [dbo].RDM_Product ON;
		INSERT INTO RDM_Product
			( ProductID, ProductName, ProductDescription, MfgID, ProductTypeID, NumCores, Notes, ModifiedDate, IsMigrationRequired)
		SELECT	ProductID, ProductName, ProductDescription, MfgID, ProductTypeID, NumCores, Notes, ModifiedDate, 0
		FROM		NxGenKeystone..Product	prd
		SET IDENTITY_INSERT [dbo].RDM_Product OFF;

		DELETE FROM RDM_Product;

	-- Parts (Without Dispositions, Notes has to be imported)

		SET IDENTITY_INSERT [dbo].RDM_Part ON;
		INSERT INTO RDM_Part
			( PartID, SerialNo, PartDescription, ProductID, Notes, CreatedDate, Serialize, DispositionID, DispositionUID, DispositionType, OosDate, FacilityID, IsMigrationRequired)
		SELECT	PartID, SerialNo, PartDescription, ProductID, Notes, CreatedDate, Serialize, DispositionID, DispositionUID, DispositionType, OosDate, FacilityID, 0
		FROM		NxGenKeystone..Part	pt
		SET IDENTITY_INSERT [dbo].RDM_Part OFF;

		DELETE FROM RDM_Part;

	-- MasterKeySystem (Without GM, Control Keys, Notes has to be imported)

		SET IDENTITY_INSERT [dbo].RDM_MasterKeySystem ON;
		INSERT INTO RDM_MasterKeySystem
			( SystemID, SystemName, KeywayID, SystemTypeID, PinsizeID, MarkID, Keystamp, Notes, GM_KeyMarkID, CT_KeyMarkID, FacilityID, IsMigrationRequired)
		SELECT	SystemID, SystemName, KeywayID, SystemTypeID, PinsizeID, MarkID, Keystamp, Notes, NULL, NULL, FacilityID, 0
		FROM		NxGenKeystone..MasterKeySystem	ss
		SET IDENTITY_INSERT [dbo].RDM_MasterKeySystem OFF;

		DELETE FROM RDM_MasterKeySystem;


	-- Keymarks (Need to confirm regarding ParentID, Notes has to be imported)
	
		SET IDENTITY_INSERT [dbo].RDM_KeyMark ON;
		INSERT INTO RDM_KeyMark
			( KeyMarkID, KeyMarkName, KeyMarkStatusID, SystemID, KeyMarkLevelID, ParentID, Notes, FacilityID, ModifiedDate, IsMigrationRequired)
		SELECT	KeyMarkID, KeyMarkName, KeyMarkStatusID, SystemID, KeyMarkLevelID, ParentID, Notes, FacilityID, ModifiedDate, 0
		FROM		NxGenKeystone..KeyMark	km
		SET IDENTITY_INSERT [dbo].RDM_KeyMark OFF;

		DELETE FROM RDM_KeyMark;

	-- Coremarks(Notes has to be imported)

		SET IDENTITY_INSERT [dbo].RDM_CoreMark ON;
		INSERT INTO RDM_CoreMark
			( CoreMarkID, CoreMarkName, KeyMarkID, Notes, FacilityID, OP_By, ModifiedDate, IsMigrationRequired)
		SELECT	CoreMarkID, CoreMarkName, KeyMarkID, Notes, FacilityID, OP_By, ModifiedDate, 0
		FROM		NxGenKeystone..CoreMark cm
		SET IDENTITY_INSERT [dbo].RDM_CoreMark OFF;

		DELETE FROM RDM_CoreMark;

		-- Coremarks_Sel (Notes has to be imported)

		SET IDENTITY_INSERT [dbo].RDM_CoreMark_Sel ON;
		INSERT INTO RDM_CoreMark_Sel
			( SelectivityID, CoreMarkID, KeyMarkID, IsMigrationRequired)
		SELECT	SelectivityID, CoreMarkID, KeyMarkID, 0
		FROM		NxGenKeystone..CoreMark_Sel cm
		SET IDENTITY_INSERT [dbo].RDM_CoreMark_Sel OFF;

		DELETE FROM RDM_CoreMark_Sel;

	-- Keyrings

		SET IDENTITY_INSERT [dbo].RDM_KeyRings ON;
		INSERT INTO RDM_KeyRings
			( KeyRingID, KeyRingUID, KeyRing, Description, DispositionID, DispositionUID, DispositionType, Notes, KeyringOosDate, FacilityID, IsMigrationRequired)
		SELECT	KeyRingID, KeyRingUID, KeyRing, Description, DispositionID, DispositionUID, DispositionType, Notes, KeyringOosDate, FacilityID, 0
		FROM	NxGenKeystone..KeyRings kr
		SET IDENTITY_INSERT [dbo].RDM_KeyRings OFF;

		DELETE FROM RDM_KeyRings;

	-- Key (Notes has to be imported)

		SET IDENTITY_INSERT [dbo].[RDM_Key] ON;
		INSERT INTO [RDM_Key]
			( KeyID, KeyUID, KeySerialNo, KeyDescription, KeyMarkID, ProductID, Notes, KeySerialize, KeyDispositonID, KeyDispositionUID, KeyDispositionType, KeyOosDate, KeyFinalDispID, KeyFinalDispType, FacilityID, ModifiedDate, IsMigrationRequired)
		SELECT	KeyID, KeyUID, KeySerialNo, KeyDescription, KeyMarkID, ProductID, Notes, KeySerialize, KeyDispositonID, KeyDispositionUID, KeyDispositionType, KeyOosDate, KeyFinalDispID, KeyFinalDispType, FacilityID, ModifiedDate, 0
		FROM	NxGenKeystone..[Key] ky
		SET IDENTITY_INSERT [dbo].[RDM_Key] OFF;

		DELETE FROM [RDM_Key];

	-- Core 

		SET IDENTITY_INSERT [dbo].RDM_Core ON;
		INSERT INTO RDM_Core
			( CoreID, CoreUID, CoreSerialNo, CoreMarkID, ProductID, Notes, CoreSerialize, CoreDispositionID, CoreDispositionUID, CoreDispositionType, CoreOosDate, CoreFinalDispID, CoreFinalDispType, ModifiedDate,  IsMigrationRequired)
		SELECT	CoreID, CoreUID, CoreSerialNo, CoreMarkID, ProductID, Notes, CoreSerialize, CoreDispositionID, CoreDispositionUID, CoreDispositionType, CoreOosDate, CoreFinalDispID, CoreFinalDispType, ModifiedDate,  0
		FROM	NxGenKeystone..Core cr
		SET IDENTITY_INSERT [dbo].RDM_Core OFF;

		DELETE FROM RDM_Core;

	-- Users (Password to be encrypted from front end)

	SET IDENTITY_INSERT [dbo].RDM_User ON;
	INSERT INTO RDM_User
		( UserID,UserLogin, Email, HashedPassword, Description, Notes, Salt, IsLocked, RoleID, GeneralPermissionId, UpdatePermissionId, TransactionPermissionId, ModifiedDate, EmployeeID, PwdChangedDate, IsMigrationRequired)
	SELECT	UserID,UserLogin, Email, HashedPassword, Description, Notes, Salt, IsLocked, RoleID, GeneralPermissionId, UpdatePermissionId, TransactionPermissionId, ModifiedDate, EmployeeID, PwdChangedDate, 0
	FROM NxGenKeystone..[User]
	SET IDENTITY_INSERT [dbo].RDM_User OFF;

	--DELETE FROM RDM_User;

	-- User Permissions

	SET IDENTITY_INSERT [dbo].RDM_UserPermissions ON;
	INSERT INTO RDM_UserPermissions
		( PERMISSIONID, USERID, CLONED_FROM, IsMigrationRequired)--, PERMIT_VIEW_DASHBOARD, PERMIT_VIEW_MASTERKEY, PERMIT_VIEW_DEPARTMENT, PERMIT_VIEW_EMPLOYEE, PERMIT_VIEW_KEY, PERMIT_VIEW_BUILDING, PERMIT_VIEW_DOOR, PERMIT_VIEW_CORE, PERMIT_VIEW_CABINET, PERMIT_VIEW_HOOK, PERMIT_VIEW_KEYRING, PERMIT_VIEW_PRODUCT, PERMIT_VIEW_PART, PERMIT_VIEW_OOS, PERMIT_VIEW_UNASSIGNED, PERMIT_VIEW_REPORTS, PERMIT_VIEW_KEYSTONECONNECT, PERMIT_VIEW_FACILITY, PERMIT_UPDATE_DASHBOARD, PERMIT_UPDATE_MASTERKEY, PERMIT_UPDATE_DEPARTMENT, PERMIT_UPDATE_EMPLOYEE, PERMIT_UPDATE_KEY, PERMIT_UPDATE_BUILDING, PERMIT_UPDATE_DOOR, PERMIT_UPDATE_CORE, PERMIT_UPDATE_CABINET, PERMIT_UPDATE_HOOK, PERMIT_UPDATE_KEYRING, PERMIT_UPDATE_PRODUCT, PERMIT_UPDATE_PART, PERMIT_UPDATE_OOS, PERMIT_UPDATE_UNASSIGNED, PERMIT_UPDATE_REPORTS, PERMIT_DELETE_MASTERKEY, PERMIT_DELETE_DEPARTMENT, PERMIT_DELETE_EMPLOYEE, PERMIT_DELETE_KEY, PERMIT_DELETE_BUILDING, PERMIT_DELETE_DOOR, PERMIT_DELETE_CORE, PERMIT_DELETE_CABINET, PERMIT_DELETE_HOOK, PERMIT_DELETE_KEYRING, PERMIT_DELETE_PRODUCT, PERMIT_DELETE_PART, PERMIT_DELETE_OOS, PERMIT_DELETE_UNASSIGNED, PERMIT_DELETE_REPORTS, PERMIT_TRANS_EMP_ISSUENEWKEY, PERMIT_TRANS_EMP_RETURNKEY, PERMIT_TRANS_EMP_ISSUEEXISTINGKEY, PERMIT_TRANS_EMP_TRANSFERKEY, PERMIT_TRANS_HOOK_TRANSFERKEY, PERMIT_TRANS_OOS_TRANSFERKEY, PERMIT_TRANS_UNA_TRANSFERKEY, PERMIT_TRANS_KEYRING_ATTACHNEWKEY, PERMIT_TRANS_KEYRING_DETACHKEY, PERMIT_TRANS_KEYRING_ATTACHEXISTINGKEY, PERMIT_TRANS_DOOR_INSTALLNEWCORE, PERMIT_TRANS_DOOR_REMOVECORE, PERMIT_TRANS_DOOR_INSTALLEXISTINGCORE, PERMIT_TRANS_PART_INSTALLNEWCORE, PERMIT_TRANS_PART_REMOVECORE, PERMIT_TRANS_PART_INSTALLEXISTINGCORE, PERMIT_TRANS_EMP_TRANSFERCORE, PERMIT_TRANS_DOOR_TRANSFERCORE, PERMIT_TRANS_HOOK_TRANSFERCORE, PERMIT_TRANS_OOS_TRANSFERCORE, PERMIT_TRANS_UNA_TRANSFERCORE, PERMIT_TRANS_EMP_ISSUENEWCORE, PERMIT_TRANS_EMP_RETURNCORE, PERMIT_TRANS_EMP_ISSUEEXISTINGCORE, PERMIT_TRANS_EMP_ISSUENEWKEYRING, PERMIT_TRANS_EMP_RETURNKEYRING, PERMIT_TRANS_EMP_ISSUEEXISTINGKEYRING, PERMIT_TRANS_EMP_TRANSFERKEYRING, PERMIT_TRANS_HOOK_TRANSFERKEYRING, PERMIT_TRANS_OOS_TRANSFERKEYRING, PERMIT_TRANS_UNA_TRANSFERKEYRING, PERMIT_TRANS_DOOR_INSTALLNEWPART, PERMIT_TRANS_DOOR_REMOVEPART, PERMIT_TRANS_DOOR_INSTALLEXISTINGPART, PERMIT_TRANS_EMP_TRANSFERPART, PERMIT_TRANS_HOOK_TRANSFERPART, PERMIT_TRANS_OOS_TRANSFERPART, PERMIT_TRANS_UNA_TRANSFERPART, PERMIT_TRANS_EMP_ISSUENEWPART, PERMIT_TRANS_EMP_RETURNPART, PERMIT_TRANS_EMP_ISSUEEXISTINGPART, PERMIT_TRANS_HOOK_ISSUENEWKEY, PERMIT_TRANS_HOOK_ISSUENEWKEYRING, PERMIT_TRANS_HOOK_ISSUENEWCORE, PERMIT_TRANS_HOOK_ISSUENEWPART, PERMIT_VIEW_CODES)
	SELECT	PERMISSIONID, USERID, CLONED_FROM, 0 --, PERMIT_VIEW_DASHBOARD, PERMIT_VIEW_MASTERKEY, PERMIT_VIEW_DEPARTMENT, PERMIT_VIEW_EMPLOYEE, PERMIT_VIEW_KEY, PERMIT_VIEW_BUILDING, PERMIT_VIEW_DOOR, PERMIT_VIEW_CORE, PERMIT_VIEW_CABINET, PERMIT_VIEW_HOOK, PERMIT_VIEW_KEYRING, PERMIT_VIEW_PRODUCT, PERMIT_VIEW_PART, PERMIT_VIEW_OOS, PERMIT_VIEW_UNASSIGNED, PERMIT_VIEW_REPORTS, PERMIT_VIEW_KEYSTONECONNECT, PERMIT_VIEW_FACILITY, PERMIT_UPDATE_DASHBOARD, PERMIT_UPDATE_MASTERKEY, PERMIT_UPDATE_DEPARTMENT, PERMIT_UPDATE_EMPLOYEE, PERMIT_UPDATE_KEY, PERMIT_UPDATE_BUILDING, PERMIT_UPDATE_DOOR, PERMIT_UPDATE_CORE, PERMIT_UPDATE_CABINET, PERMIT_UPDATE_HOOK, PERMIT_UPDATE_KEYRING, PERMIT_UPDATE_PRODUCT, PERMIT_UPDATE_PART, PERMIT_UPDATE_OOS, PERMIT_UPDATE_UNASSIGNED, PERMIT_UPDATE_REPORTS, PERMIT_DELETE_MASTERKEY, PERMIT_DELETE_DEPARTMENT, PERMIT_DELETE_EMPLOYEE, PERMIT_DELETE_KEY, PERMIT_DELETE_BUILDING, PERMIT_DELETE_DOOR, PERMIT_DELETE_CORE, PERMIT_DELETE_CABINET, PERMIT_DELETE_HOOK, PERMIT_DELETE_KEYRING, PERMIT_DELETE_PRODUCT, PERMIT_DELETE_PART, PERMIT_DELETE_OOS, PERMIT_DELETE_UNASSIGNED, PERMIT_DELETE_REPORTS, PERMIT_TRANS_EMP_ISSUENEWKEY, PERMIT_TRANS_EMP_RETURNKEY, PERMIT_TRANS_EMP_ISSUEEXISTINGKEY, PERMIT_TRANS_EMP_TRANSFERKEY, PERMIT_TRANS_HOOK_TRANSFERKEY, PERMIT_TRANS_OOS_TRANSFERKEY, PERMIT_TRANS_UNA_TRANSFERKEY, PERMIT_TRANS_KEYRING_ATTACHNEWKEY, PERMIT_TRANS_KEYRING_DETACHKEY, PERMIT_TRANS_KEYRING_ATTACHEXISTINGKEY, PERMIT_TRANS_DOOR_INSTALLNEWCORE, PERMIT_TRANS_DOOR_REMOVECORE, PERMIT_TRANS_DOOR_INSTALLEXISTINGCORE, PERMIT_TRANS_PART_INSTALLNEWCORE, PERMIT_TRANS_PART_REMOVECORE, PERMIT_TRANS_PART_INSTALLEXISTINGCORE, PERMIT_TRANS_EMP_TRANSFERCORE, PERMIT_TRANS_DOOR_TRANSFERCORE, PERMIT_TRANS_HOOK_TRANSFERCORE, PERMIT_TRANS_OOS_TRANSFERCORE, PERMIT_TRANS_UNA_TRANSFERCORE, PERMIT_TRANS_EMP_ISSUENEWCORE, PERMIT_TRANS_EMP_RETURNCORE, PERMIT_TRANS_EMP_ISSUEEXISTINGCORE, PERMIT_TRANS_EMP_ISSUENEWKEYRING, PERMIT_TRANS_EMP_RETURNKEYRING, PERMIT_TRANS_EMP_ISSUEEXISTINGKEYRING, PERMIT_TRANS_EMP_TRANSFERKEYRING, PERMIT_TRANS_HOOK_TRANSFERKEYRING, PERMIT_TRANS_OOS_TRANSFERKEYRING, PERMIT_TRANS_UNA_TRANSFERKEYRING, PERMIT_TRANS_DOOR_INSTALLNEWPART, PERMIT_TRANS_DOOR_REMOVEPART, PERMIT_TRANS_DOOR_INSTALLEXISTINGPART, PERMIT_TRANS_EMP_TRANSFERPART, PERMIT_TRANS_HOOK_TRANSFERPART, PERMIT_TRANS_OOS_TRANSFERPART, PERMIT_TRANS_UNA_TRANSFERPART, PERMIT_TRANS_EMP_ISSUENEWPART, PERMIT_TRANS_EMP_RETURNPART, PERMIT_TRANS_EMP_ISSUEEXISTINGPART, PERMIT_TRANS_HOOK_ISSUENEWKEY, PERMIT_TRANS_HOOK_ISSUENEWKEYRING, PERMIT_TRANS_HOOK_ISSUENEWCORE, PERMIT_TRANS_HOOK_ISSUENEWPART, PERMIT_VIEW_CODES
	FROM NxGenKeystone..UserPermissions
	SET IDENTITY_INSERT [dbo].RDM_UserPermissions OFF;

	DELETE FROM RDM_UserPermissions;

	-- User Facilities

	SET IDENTITY_INSERT [dbo].RDM_UserFacilities ON;
	INSERT INTO RDM_UserFacilities
		( ID, UserID, FacilityID, IsDefault, BuildingDefault, CabinetDefault, CoreDefault, CoremarkDefault, DepartmentDefault, OutOfServiceDefault, DoorDefault, EmployeeDefault, FacilityDefault, HookDefault, KeyDefault, KeymarkDefault, KeyringDefault, PartDefault, MasterkeyDefault, ProductDefault, ReportDefault, SiteDefault, UnassignedDefault, UserDefault, IsMigrationRequired)
	SELECT	ID, UserID, FacilityID, IsDefault, BuildingDefault, CabinetDefault, CoreDefault, CoremarkDefault, DepartmentDefault, OutOfServiceDefault, DoorDefault, EmployeeDefault, FacilityDefault, HookDefault, KeyDefault, KeymarkDefault, KeyringDefault, PartDefault, MasterkeyDefault, ProductDefault, ReportDefault, SiteDefault, UnassignedDefault, UserDefault, 0
	FROM NxGenKeystone..UserFacilities
	SET IDENTITY_INSERT [dbo].RDM_UserFacilities OFF;

	DELETE FROM RDM_UserFacilities;

	-- Dashboard Settings

	SET IDENTITY_INSERT [dbo].RDM_DashboardSettings ON;
	INSERT INTO RDM_DashboardSettings
		( ID, TileName, Position, Visibility, UserID, IsMigrationRequired)
	SELECT	ID, TileName, Position, Visibility, UserID, 0
	FROM NxGenKeystone..DashboardSettings
	SET IDENTITY_INSERT [dbo].RDM_DashboardSettings OFF;

	DELETE FROM RDM_DashboardSettings;

	-- ItemHistory ( change Identity value)

		SET IDENTITY_INSERT [dbo].RDM_ItemHistory ON;
		INSERT INTO RDM_ItemHistory
			( HistoryID, ItemID, ToID, UserID, DatetimeWhen, DateReturn, DateDue, Comment, ItemParentID, ItemParentType, ToParentID, ToParentType, FacilityID, IsMigrationRequired )
		SELECT	HistoryID, ItemID, ToID, UserID, DatetimeWhen, DateReturn, DateDue, Comment, ItemParentID, ItemParentType, ToParentID, ToParentType, FacilityID, 0
		FROM		NxGenKeystone..ItemHistory hst
		SET IDENTITY_INSERT [dbo].RDM_ItemHistory OFF;

		DELETE FROM RDM_ItemHistory;
				

	-- Facility Configuration
	SET IDENTITY_INSERT [dbo].RDM_Facility_Configuration ON;
	INSERT  INTO [dbo].RDM_Facility_Configuration
				( id, FacilityID, CoreSerial, KeySerial, LockSerial )
	SELECT ID,FacilityID, 0, 0, 0 
	FROM	NxGenKeystone..Facility_Configuration;
	SET IDENTITY_INSERT [dbo].RDM_Facility_Configuration OFF;

	DELETE FROM RDM_Facility_Configuration;

