SET @time_module_id := (SELECT `id` FROM `ohrm_module` WHERE `name` = 'time');
SET @ess_user_role_id := (SELECT id FROM ohrm_user_role WHERE name = 'ESS');

INSERT INTO ohrm_screen (`name`, `module_id`, `action_url`) VALUES
('Display My Attendance Details', @time_module_id, 'displayMyAttendanceDetailsReport');

SET @employee_attendance_screen_id := (SELECT id FROM ohrm_screen WHERE name = 'Display My Attendance Details');

INSERT INTO `ohrm_user_role_screen` (`user_role_id`, `screen_id`, `can_read`, `can_create`, `can_update`, `can_delete`)  (SELECT id, @employee_attendance_screen_id , 1 ,0 , 0,0 FROM ohrm_user_role WHERE type_id = 2);

SET @time_menu_id := (SELECT id FROM ohrm_menu_item WHERE menu_title = 'Time');
SET @reports_menu_id := (SELECT id FROM ohrm_menu_item WHERE menu_title = 'Reports' AND parent_id = @time_menu_id);

INSERT INTO ohrm_menu_item (`menu_title`, `screen_id`, `parent_id`, `level`, `order_hint`, `url_extras`, `status`) VALUES
('My Monthly Attendance', @employee_attendance_screen_id, @reports_menu_id, 3, 600, NULL, 1);


INSERT INTO `ohrm_data_group` (`name`, `description`, `can_read`, `can_create`, `can_update`, `can_delete`) VALUES
('my_attendance_report', 'Time - My Monthly Attendance Report', 1, 0, 0, 0);

SET @my_attendance_report_data_group_id := (SELECT id FROM ohrm_data_group WHERE name = 'my_attendance_report');

SET @menu_item_id := (SELECT id FROM ohrm_menu_item WHERE menu_title = 'My Monthly Attendance');
INSERT INTO ohrm_menu_item_data_group( menu_item_id, data_group_id ) VALUES ( @menu_item_id , @my_attendance_report_data_group_id);

INSERT INTO `ohrm_user_role_data_group` (`user_role_id`, `data_group_id`, `can_read`, `can_create`, `can_update`, `can_delete`, `self`)  (SELECT id, @my_attendance_report_data_group_id , 1 ,0 , 0, 0, 1 FROM ohrm_user_role WHERE type_id = 2);

INSERT INTO `ohrm_data_group_screen`(`data_group_id`, `screen_id`, `permission`, `self`) VALUES
(@my_attendance_report_data_group_id, @employee_attendance_screen_id, 1, 1);

INSERT INTO ohrm_user_role_type_data_group(user_role_type_id, data_group_id) VALUES
(@ess_user_role_id, @my_attendance_report_data_group_id);
