SET @admin_role_id := (SELECT `id` FROM ohrm_user_role WHERE `name` = 'Admin');
SET @hiring_manager_role_id := (SELECT `id` FROM ohrm_user_role WHERE `name` = 'HiringManager');
SET @supervisor_role_id := (SELECT `id` FROM ohrm_user_role WHERE `name` = 'Supervisor');

INSERT INTO `ohrm_module` (`name`, `status`) VALUES ('report', 1);

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

INSERT INTO ohrm_screen (`name`, `module_id`, `action_url`) VALUES
('Employee Leave Report', @module_id, 'displayEmployeeLeaveReportCriteria');

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

INSERT INTO ohrm_screen (`name`, `module_id`, `action_url`) VALUES
('Employee Turnover Termination Report', @module_id, 'displayEmployeeTurnoverTerminationReportCriteria');

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

INSERT INTO ohrm_screen (`name`, `module_id`, `action_url`) VALUES
('Vacancy Succession Report', @module_id, 'displayVacancySuccessionReportCriteria');

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

INSERT INTO ohrm_screen (`name`, `module_id`, `action_url`) VALUES
('Employee Turnover Hiring Report', @module_id, 'displayEmployeeTurnoverHiringReportCriteria');

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

INSERT INTO ohrm_screen (`name`, `module_id`, `action_url`) VALUES
('Head Count Report', @module_id, 'displayHeadCountReportCriteria');

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

INSERT INTO ohrm_screen (`name`, `module_id`, `action_url`) VALUES
('License Expiry Report', @module_id, 'displayLicenseExpiryReportCriteria');

SET @employee_license_expiry_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, @employee_leave_screen_id, 1, 0, 0, 0),
(@admin_role_id, @employee_termination_screen_id, 1, 0, 0, 0),
(@admin_role_id, @employee_vacancy_screen_id, 1, 0, 0, 0),
(@admin_role_id, @employee_hiring_screen_id, 1, 0, 0, 0),
(@admin_role_id, @employee_head_count_screen_id, 1, 0, 0, 0),
(@admin_role_id, @employee_license_expiry_screen_id, 1, 0, 0, 0),
(@hiring_manager_role_id, @employee_vacancy_screen_id, 1, 0, 0, 0),
(@supervisor_role_id, @employee_license_expiry_screen_id, 1, 0, 0, 0);
-- TODO: Need to define home action for Reports module

INSERT INTO ohrm_menu_item (`menu_title`, `screen_id`, `parent_id`, `level`, `order_hint`, `url_extras`, `status`) VALUES
('Reports', @employee_head_count_screen_id, NULL, 1, 1000, '/reportId/9', 1);

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

SET @leave_report_id := (SELECT `report_id` FROM `ohrm_report` WHERE `name` = 'Employee Leave Report');
SET @turnover_terminate_report_id := (SELECT `report_id` FROM `ohrm_report` WHERE `name` = 'Employee Turnover Termination Report');
SET @employee_vacancy_report_id := (SELECT `report_id` FROM `ohrm_report` WHERE `name` = 'Vacancy Succession Report');
SET @turnover_hiring_report_id := (SELECT `report_id` FROM `ohrm_report` WHERE `name` = 'Employee Turnover Hiring Report');
SET @head_count_report_id := (SELECT `report_id` FROM `ohrm_report` WHERE `name` = 'Head Count Report');
SET @license_expiry_report_id := (SELECT `report_id` FROM `ohrm_report` WHERE `name` = 'License Expiry Report');

INSERT INTO ohrm_menu_item (`menu_title`, `screen_id`, `parent_id`, `level`, `order_hint`, `url_extras`, `status`) VALUES
('Employee Leave Report', @employee_leave_screen_id, @reports_menu_id, 2, 100, concat('/reportId/', @leave_report_id), 1),
('Employee Turnover Termination Report', @employee_termination_screen_id, @reports_menu_id, 2, 200, concat('/reportId/', @turnover_terminate_report_id) , 1),
('Vacancy Succession Report', @employee_vacancy_screen_id, @reports_menu_id, 2, 300, concat('/reportId/', @employee_vacancy_report_id), 1),
('Employee Turnover Hiring Report', @employee_hiring_screen_id, @reports_menu_id, 2, 400, concat('/reportId/', @turnover_hiring_report_id), 1),
('Head Count Report', @employee_head_count_screen_id, @reports_menu_id, 2, 500, concat('/reportId/', @head_count_report_id), 1),
('License Expiry Report', @employee_license_expiry_screen_id, @reports_menu_id, 2, 600, concat('/reportId/', @license_expiry_report_id), 1);

