SET @pim_module := (SELECT `id` FROM `ohrm_module` WHERE  `name` ='pim');

INSERT INTO ohrm_screen (`name`, `module_id`, `action_url`, `route_name`) VALUES
    ('PIM Work Schedules', @pim_module, 'pimWorkSchedules', NULL);

SET @admin_id := (SELECT id FROM ohrm_user_role where name = 'Admin');
SET @supervisor_id := (SELECT id FROM ohrm_user_role where name = 'Supervisor');
SET @HOD_user_role := (SELECT id FROM ohrm_user_role WHERE `name` = 'HeadOfDepartment');

SET @pim_work_schedules_screen_id := (SELECT id FROM ohrm_screen WHERE name = 'PIM Work Schedules');

INSERT INTO ohrm_user_role_screen (user_role_id, screen_id, can_read, can_create, can_update, can_delete) VALUES
    (@admin_id, @pim_work_schedules_screen_id, 1, 1, 1, 1),
    (@supervisor_id, @pim_work_schedules_screen_id, 1, 1, 1, 1),
    (@HOD_user_role, @pim_work_schedules_screen_id, 1, 1, 1, 1);

SET @work_schedule_data_group_id := (SELECT `id` FROM `ohrm_data_group` WHERE  `name` ='work_schedules');

INSERT INTO `ohrm_data_group_screen`(`data_group_id`, `screen_id`, `permission`) VALUES
    (@work_schedule_data_group_id, @pim_work_schedules_screen_id, 1);

SET @employee_management_module_menu_id := (SELECT id FROM ohrm_menu_item WHERE menu_title = 'Employee Management');
SET @configuration_menu_id := (SELECT id FROM ohrm_menu_item WHERE menu_title = 'Configurations' AND parent_id = @employee_management_module_menu_id);

INSERT INTO ohrm_menu_item (`menu_title`, `screen_id`, `parent_id`, `level`, `order_hint`, `url_extras`, `uisref`, `status`) VALUES
    ('Work Schedules', @pim_work_schedules_screen_id, @configuration_menu_id, 4, 1000, NULL, 'vuepim.work_schedules', 1);