INSERT INTO `ohrm_data_group` (`name`, `description`, `can_read`, `can_create`, `can_update`, `can_delete`) VALUES
('user_asset_information', 'User Asset Details', 1, 1, 1, 1);

SET @user_asset_info_datagroup_id := (SELECT `id` FROM `ohrm_data_group` WHERE `name`='user_asset_information');
SET @asset_info_datagroup_id := (SELECT `id` FROM `ohrm_data_group` WHERE `name`='asset_information');
SET @ess_user_role_type_id:= (SELECT `id` FROM `ohrm_user_role_type` WHERE `name`='ESS');

SET @module_id := (SELECT `id` FROM `ohrm_module` WHERE `name` = 'asset');
SET @user_asset_screen_id := (SELECT `id` FROM `ohrm_screen` WHERE `module_id` = @module_id AND `action_url`='viewUserAssetList');
SET @asset_screen_id := (SELECT `id` FROM `ohrm_screen` WHERE `module_id` = @module_id AND `action_url`='viewAssets');

INSERT INTO ohrm_data_group_screen (`data_group_id`, `screen_id`, `permission`) VALUES
(@user_asset_info_datagroup_id, @user_asset_screen_id, 1);

UPDATE `ohrm_user_role_data_group` urd
LEFT JOIN `ohrm_user_role` ur ON urd.`user_role_id`=ur.`id`
SET urd.`data_group_id`=@user_asset_info_datagroup_id
WHERE ur.type_id=@ess_user_role_type_id AND urd.`data_group_id`=@asset_info_datagroup_id;

DELETE FROM `ohrm_default_permitted_screen` WHERE `user_role_type_id`= @ess_user_role_type_id AND `screen_id`=@user_asset_screen_id;

DELETE urs FROM `ohrm_user_role_screen` urs
LEFT JOIN `ohrm_user_role` ur ON urs.`user_role_id`=ur.`id`
WHERE urs.screen_id = @asset_screen_id AND ur.type_id=@ess_user_role_type_id;