SET @module_id := (SELECT `id` FROM `ohrm_module` WHERE `name` = 'expense');
SET @admin_role_id := (SELECT `id` FROM `ohrm_user_role` WHERE `name` = 'Admin');
SET @supervisor_role_id := (SELECT `id` FROM `ohrm_user_role` WHERE `name` = 'Supervisor');
SET @ess_role_id := (SELECT `id` FROM `ohrm_user_role` WHERE `name` = 'ESS');
SET @hod_id := (SELECT `id` FROM `ohrm_user_role` WHERE `name` = 'HeadOfDepartment');
SET @admin_user_role_type_id := (SELECT id FROM `ohrm_user_role_type` WHERE `name` = 'Admin');
SET @supervisor_role_type_id := (SELECT `id` FROM `ohrm_user_role_type` WHERE `name` = 'Supervisor');
SET @ess_role_type_id := (SELECT `id` FROM `ohrm_user_role_type` WHERE `name` = 'ESS');

-- Add a screen
INSERT INTO ohrm_screen (`name`, `module_id`, `action_url`) VALUES
('Expense Reports', @module_id , 'travelRequestReport');

SET @view_report_screen_id := (SELECT LAST_INSERT_ID());

INSERT INTO ohrm_user_role_screen (user_role_id, screen_id, can_read, can_create, can_update, can_delete) VALUES
(@admin_role_id, @view_report_screen_id, 1, 1, 1, 1);


-- Data Group For Expense Reports
INSERT INTO `ohrm_data_group` (`name`, `description`, `can_read`, `can_create`, `can_update`, `can_delete`) VALUES
('expense_reports', 'Travel and Expense - Reports', 1, 1, 1, 1);
SET @expense_reports_data_group_id := (SELECT LAST_INSERT_ID());

INSERT INTO `ohrm_data_group_screen` (`data_group_id`, `screen_id`, `permission`, `self`) VALUES
(@expense_reports_data_group_id, @view_report_screen_id, 1, 0);

INSERT INTO `ohrm_user_role_data_group` (`user_role_id`, `data_group_id`, `can_read`, `can_create`, `can_update`, `can_delete`, `self`) VALUES
(@admin_role_id, @expense_reports_data_group_id, 1, 1, 1, 1, 0),
(@supervisor_role_id, @expense_reports_data_group_id, 1, 0, 0, 0, 0),
(@ess_role_id, @expense_reports_data_group_id, 1, 0, 0, 0, 1),
(@hod_id, @expense_reports_data_group_id, 1, 0, 0, 0, 0);

INSERT INTO `ohrm_user_role_type_data_group` (`user_role_type_id`, `data_group_id`, `can_read`, `can_create`, `can_update`, `can_delete`) VALUES
(@admin_user_role_type_id, @expense_reports_data_group_id, 1, 1, 1, 1),
(@supervisor_role_type_id, @expense_reports_data_group_id, 1, 0, 0, 0),
(@ess_role_type_id, @expense_reports_data_group_id, 1, 0, 0, 0);
