DECLARE @ExportRecordID UNIQUEIDENTIFIER;
SELECT @ExportRecordID = [ExportRecordID]
FROM [IES].[T_EXPORT_RECORD]
WHERE [ProcessName] = 'MassReport';
DELETE FROM [IES].[T_EXPORT_RECORD_ANSWER]
WHERE [ExportRecordID] = @ExportRecordID;
			
DELETE FROM [IES].[T_EXPORT_RECORD_SERVICE_ROLES]
WHERE [ExportRecordService] = @ExportRecordID;
DELETE FROM [IES].[T_EXPORT_RECORD]
WHERE [ExportRecordID] = @ExportRecordID
GO
DECLARE @NewExportRecordID UNIQUEIDENTIFIER = NEWID();
INSERT INTO [IES].[T_EXPORT_RECORD]
([ExportRecordID]
,[ProcessName]
,[ProcessDescription]
,[Entities]
,[IsSystem]
,[type_])
VALUES
(@NewExportRecordID,
'MassReport',
'Массовая выгрузка отчетов',
			
		NULL
	,
1,
(select te.[EntityID] from [VCLib].[T_ENTITIES] te
where te.[Schema] + '.' + te.[EntName] = 'IES.EXPORT_RECORD_SERVICE'));
			
	INSERT INTO [IES].[T_EXPORT_RECORD_SERVICE_ROLES] ([ExportRecordServiceRolesID], [ExportRecordService], [Roles])
	SELECT NEWID(), @NewExportRecordID, [RoleID] FROM [VCLib].[T_ROLES]
	WHERE [RoleName] = 'Администратор'; 
			
GO
		
DECLARE @ExportRecordID UNIQUEIDENTIFIER;
SELECT @ExportRecordID = [ExportRecordID]
FROM [IES].[T_EXPORT_RECORD]
WHERE [ProcessName] = 'UnloadActsReportPeriod';
DELETE FROM [IES].[T_EXPORT_RECORD_ANSWER]
WHERE [ExportRecordID] = @ExportRecordID;
			
DELETE FROM [IES].[T_EXPORT_RECORD_SERVICE_ROLES]
WHERE [ExportRecordService] = @ExportRecordID;
DELETE FROM [IES].[T_EXPORT_RECORD]
WHERE [ExportRecordID] = @ExportRecordID
GO
DECLARE @NewExportRecordID UNIQUEIDENTIFIER = NEWID();
INSERT INTO [IES].[T_EXPORT_RECORD]
([ExportRecordID]
,[ProcessName]
,[ProcessDescription]
,[Entities]
,[IsSystem]
,[type_])
VALUES
(@NewExportRecordID,
'UnloadActsReportPeriod',
'Выгрузка актов за отчетный период',
			
		NULL
	,
1,
(select te.[EntityID] from [VCLib].[T_ENTITIES] te
where te.[Schema] + '.' + te.[EntName] = 'IES.EXPORT_RECORD_SERVICE'));
			
	INSERT INTO [IES].[T_EXPORT_RECORD_SERVICE_ROLES] ([ExportRecordServiceRolesID], [ExportRecordService], [Roles])
	SELECT NEWID(), @NewExportRecordID, [RoleID] FROM [VCLib].[T_ROLES]
	WHERE [RoleName] = 'Администратор'; 
			
GO
		
DECLARE @ExportRecordID UNIQUEIDENTIFIER;
SELECT @ExportRecordID = [ExportRecordID]
FROM [IES].[T_EXPORT_RECORD]
WHERE [ProcessName] = 'UnloadSchetsToIszl';
DELETE FROM [IES].[T_EXPORT_RECORD_ANSWER]
WHERE [ExportRecordID] = @ExportRecordID;
			
DELETE FROM [IES].[T_EXPORT_RECORD_SERVICE_ROLES]
WHERE [ExportRecordService] = @ExportRecordID;
DELETE FROM [IES].[T_EXPORT_RECORD]
WHERE [ExportRecordID] = @ExportRecordID
GO
DECLARE @NewExportRecordID UNIQUEIDENTIFIER = NEWID();
INSERT INTO [IES].[T_EXPORT_RECORD]
([ExportRecordID]
,[ProcessName]
,[ProcessDescription]
,[Entities]
,[IsSystem]
,[type_])
VALUES
(@NewExportRecordID,
'UnloadSchetsToIszl',
'Выгрузка счетов в ИСЗЛ',
			
		NULL
	,
1,
(select te.[EntityID] from [VCLib].[T_ENTITIES] te
where te.[Schema] + '.' + te.[EntName] = 'IES.EXPORT_RECORD_SERVICE'));
			
	INSERT INTO [IES].[T_EXPORT_RECORD_SERVICE_ROLES] ([ExportRecordServiceRolesID], [ExportRecordService], [Roles])
	SELECT NEWID(), @NewExportRecordID, [RoleID] FROM [VCLib].[T_ROLES]
	WHERE [RoleName] = 'Администратор'; 
			
GO
		
DECLARE @ExportRecordID UNIQUEIDENTIFIER;
SELECT @ExportRecordID = [ExportRecordID]
FROM [IES].[T_EXPORT_RECORD]
WHERE [ProcessName] = 'UnloadSMOActsRB';
DELETE FROM [IES].[T_EXPORT_RECORD_ANSWER]
WHERE [ExportRecordID] = @ExportRecordID;
			
DELETE FROM [IES].[T_EXPORT_RECORD_SERVICE_ROLES]
WHERE [ExportRecordService] = @ExportRecordID;
DELETE FROM [IES].[T_EXPORT_RECORD]
WHERE [ExportRecordID] = @ExportRecordID
GO
DECLARE @NewExportRecordID UNIQUEIDENTIFIER = NEWID();
INSERT INTO [IES].[T_EXPORT_RECORD]
([ExportRecordID]
,[ProcessName]
,[ProcessDescription]
,[Entities]
,[IsSystem]
,[type_])
VALUES
(@NewExportRecordID,
'UnloadSMOActsRB',
'Выгрузка актов МЭК, МЭЭ/ЭКМП',
			
		NULL
	,
1,
(select te.[EntityID] from [VCLib].[T_ENTITIES] te
where te.[Schema] + '.' + te.[EntName] = 'IES.EXPORT_RECORD_SERVICE'));
			
	INSERT INTO [IES].[T_EXPORT_RECORD_SERVICE_ROLES] ([ExportRecordServiceRolesID], [ExportRecordService], [Roles])
	SELECT NEWID(), @NewExportRecordID, [RoleID] FROM [VCLib].[T_ROLES]
	WHERE [RoleName] = 'Администратор'; 
			
GO
		
DECLARE @ExportRecordID UNIQUEIDENTIFIER;
SELECT @ExportRecordID = [ExportRecordID]
FROM [IES].[T_EXPORT_RECORD]
WHERE [ProcessName] = 'UnloadSchetsProcessClient';
DELETE FROM [IES].[T_EXPORT_RECORD_ANSWER]
WHERE [ExportRecordID] = @ExportRecordID;
			
DELETE FROM [IES].[T_EXPORT_RECORD_SERVICE_ROLES]
WHERE [ExportRecordService] = @ExportRecordID;
DELETE FROM [IES].[T_EXPORT_RECORD]
WHERE [ExportRecordID] = @ExportRecordID
GO
DECLARE @NewExportRecordID UNIQUEIDENTIFIER = NEWID();
INSERT INTO [IES].[T_EXPORT_RECORD]
([ExportRecordID]
,[ProcessName]
,[ProcessDescription]
,[Entities]
,[IsSystem]
,[type_])
VALUES
(@NewExportRecordID,
'UnloadSchetsProcessClient',
'Выгрузка счетов-реестров',
			
		NULL
	,
1,
(select te.[EntityID] from [VCLib].[T_ENTITIES] te
where te.[Schema] + '.' + te.[EntName] = 'IES.EXPORT_RECORD_SERVICE'));
			
	INSERT INTO [IES].[T_EXPORT_RECORD_SERVICE_ROLES] ([ExportRecordServiceRolesID], [ExportRecordService], [Roles])
	SELECT NEWID(), @NewExportRecordID, [RoleID] FROM [VCLib].[T_ROLES]
	WHERE [RoleName] = 'Администратор'; 
			
GO
		
DECLARE @ExportRecordID UNIQUEIDENTIFIER;
SELECT @ExportRecordID = [ExportRecordID]
FROM [IES].[T_EXPORT_RECORD]
WHERE [ProcessName] = 'MassSchetActUnload';
DELETE FROM [IES].[T_EXPORT_RECORD_ANSWER]
WHERE [ExportRecordID] = @ExportRecordID;
			
DELETE FROM [IES].[T_EXPORT_RECORD_SERVICE_ROLES]
WHERE [ExportRecordService] = @ExportRecordID;
DELETE FROM [IES].[T_EXPORT_RECORD]
WHERE [ExportRecordID] = @ExportRecordID
GO
DECLARE @NewExportRecordID UNIQUEIDENTIFIER = NEWID();
INSERT INTO [IES].[T_EXPORT_RECORD]
([ExportRecordID]
,[ProcessName]
,[ProcessDescription]
,[Entities]
,[IsSystem]
,[type_])
VALUES
(@NewExportRecordID,
'MassSchetActUnload',
'Массовая выгрузка актов',
			
		NULL
	,
1,
(select te.[EntityID] from [VCLib].[T_ENTITIES] te
where te.[Schema] + '.' + te.[EntName] = 'IES.EXPORT_RECORD_SERVICE'));
			
	INSERT INTO [IES].[T_EXPORT_RECORD_SERVICE_ROLES] ([ExportRecordServiceRolesID], [ExportRecordService], [Roles])
	SELECT NEWID(), @NewExportRecordID, [RoleID] FROM [VCLib].[T_ROLES]
	WHERE [RoleName] = 'Администратор'; 
			
GO
		
DECLARE @ExportRecordID UNIQUEIDENTIFIER;
SELECT @ExportRecordID = [ExportRecordID]
FROM [IES].[T_EXPORT_RECORD]
WHERE [ProcessName] = 'UnloadProvideMedicalAssistanceProcessClient';
DELETE FROM [IES].[T_EXPORT_RECORD_ANSWER]
WHERE [ExportRecordID] = @ExportRecordID;
			
DELETE FROM [IES].[T_EXPORT_RECORD_SERVICE_ROLES]
WHERE [ExportRecordService] = @ExportRecordID;
DELETE FROM [IES].[T_EXPORT_RECORD]
WHERE [ExportRecordID] = @ExportRecordID
GO
DECLARE @NewExportRecordID UNIQUEIDENTIFIER = NEWID();
INSERT INTO [IES].[T_EXPORT_RECORD]
([ExportRecordID]
,[ProcessName]
,[ProcessDescription]
,[Entities]
,[IsSystem]
,[type_])
VALUES
(@NewExportRecordID,
'UnloadProvideMedicalAssistanceProcessClient',
'Выгрузка сведений об оказанной медпомощи',
			
		NULL
	,
1,
(select te.[EntityID] from [VCLib].[T_ENTITIES] te
where te.[Schema] + '.' + te.[EntName] = 'IES.EXPORT_RECORD_SERVICE'));
			
	INSERT INTO [IES].[T_EXPORT_RECORD_SERVICE_ROLES] ([ExportRecordServiceRolesID], [ExportRecordService], [Roles])
	SELECT NEWID(), @NewExportRecordID, [RoleID] FROM [VCLib].[T_ROLES]
	WHERE [RoleName] = 'Администратор'; 
			
GO
		

