SET @performance_module := (SELECT id FROM ohrm_module WHERE name = 'performance');
SET @culture_pillar_menu_id := (SELECT `id` FROM ohrm_menu_item WHERE `menu_title` = 'Culture' AND parent_id IS NULL AND level = 1);
SET @performance_menu_id := (SELECT id FROM ohrm_menu_item WHERE menu_title = 'Performance' AND level = 2 AND parent_id = @culture_pillar_menu_id);

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

SET @performance_report = (SELECT id FROM ohrm_advanced_report WHERE `unique_name` = 'Reviews and Appraisals Progress');
SET @comparision_report = (SELECT id FROM ohrm_advanced_report WHERE name = 'Performance Comparison Report');
SET @performance_profile = (SELECT id FROM ohrm_advanced_report WHERE `unique_name` = 'Employee Performance Profile');
SET @performance_progress = (SELECT id FROM ohrm_advanced_report WHERE name = 'Performance Progress Report');
SET @performance_result_export_report = (SELECT id FROM ohrm_advanced_report WHERE `unique_name` = 'Performance_Result_Export');

INSERT INTO ohrm_screen (`name`, `module_id`, `action_url`, `route_name`) VALUES('viewPerformanceReport', @performance_module, 'viewPerformanceReport', 'performance_viewPerformanceReport');
SET @view_report_screen_id := (SELECT id FROM ohrm_screen WHERE name = 'viewPerformanceReport');

INSERT INTO ohrm_screen (`name`, `module_id`, `action_url`, `route_name`) VALUES('viewFullComparisonReport', @performance_module, 'viewFullComparisonReport', 'performance_viewFullComparisonReport');
SET @comparion_report_screen_id := (SELECT id FROM ohrm_screen WHERE name = 'viewFullComparisonReport');

INSERT INTO ohrm_screen (`name`, `module_id`, `action_url`, `route_name`) VALUES('viewEmployeePerformanceProfile', @performance_module, 'viewEmployeePerformanceProfile', 'performance_viewEmployeePerformanceProfile');
SET @performance_profile_screen_id := (SELECT id FROM ohrm_screen WHERE name = 'viewEmployeePerformanceProfile');

INSERT INTO ohrm_screen (`name`, `module_id`, `action_url`, `route_name`) VALUES('viewPerformanceProgressReport', @performance_module, 'viewPerformanceProgressReport', 'performance_viewPerformanceProgressReport');
SET @progress_report_screen_id := (SELECT id FROM ohrm_screen WHERE name = 'viewPerformanceProgressReport');

INSERT INTO ohrm_screen (`name`, `module_id`, `action_url`) VALUES('viewPerformanceResultsExport', @performance_module, 'viewPerformanceResultsExport');
SET @performance_results_export_screen_id := (SELECT id FROM ohrm_screen WHERE name = 'viewPerformanceResultsExport');

INSERT INTO `ohrm_user_role_screen` (`id`, `user_role_id`, `screen_id`, `can_read`, `can_create`, `can_update`, `can_delete`) VALUES
(NULL, @admin_role_id, @view_report_screen_id , 1, 0, 0, 0),
(NULL, @admin_role_id, @comparion_report_screen_id , 1, 0, 0, 0),
(NULL, @admin_role_id, @performance_profile_screen_id , 1, 0, 0, 0),
(NULL, @admin_role_id, @progress_report_screen_id , 1, 0, 0, 0),
(NULL, @admin_role_id, @performance_results_export_screen_id , 1, 0, 0, 0);
-- reports data group
INSERT INTO `ohrm_data_group` (`name`, `description`, `can_read`, `can_create`, `can_update`, `can_delete`) VALUES
('Performance_Reports', 'Performance - Reports', 1, 0, 0, 0);
SET @reports_data_group_id := (SELECT LAST_INSERT_ID());
INSERT INTO `ohrm_user_role_data_group` (`user_role_id`, `data_group_id`, `can_read`, `can_create`, `can_update`, `can_delete`, `self`) VALUES
(1, @reports_data_group_id, 1, 0, 0, 0, 0);
INSERT INTO `ohrm_user_role_type_data_group` (`user_role_type_id`, `data_group_id`) VALUES
(1, @reports_data_group_id);


INSERT INTO `ohrm_data_group_screen`( `data_group_id`, `screen_id`, `permission`) VALUES (@reports_data_group_id,@performance_results_export_screen_id,1);
INSERT INTO `ohrm_data_group_screen`( `data_group_id`, `screen_id`, `permission`) VALUES (@reports_data_group_id,@view_report_screen_id,1);
INSERT INTO `ohrm_data_group_screen`( `data_group_id`, `screen_id`, `permission`) VALUES (@reports_data_group_id,@comparion_report_screen_id,1);
INSERT INTO `ohrm_data_group_screen`( `data_group_id`, `screen_id`, `permission`) VALUES (@reports_data_group_id,@performance_profile_screen_id,1);
INSERT INTO `ohrm_data_group_screen`( `data_group_id`, `screen_id`, `permission`) VALUES (@reports_data_group_id,@progress_report_screen_id,1);

SET @employee_goals_report := (SELECT id FROM ohrm_advanced_report WHERE unique_name = 'pim.Employee_Goals');
SET @employee_okrs_report := (SELECT id FROM ohrm_advanced_report WHERE unique_name = 'pim.Employee_OKRs');
SET @employee_goals_and_okrs_report := (SELECT id FROM ohrm_advanced_report WHERE unique_name = 'pim.Employee_Goals_and_OKRs');
SET @reviews_done_by_each_employee_during_specified_period_report := (SELECT id FROM ohrm_advanced_report WHERE unique_name = 'pim.Reviews_done_by_each_employee_during_specified_period');
SET @average_competency_score_given_by_each_evaluator_across_reviews := (SELECT id FROM ohrm_advanced_report WHERE unique_name = 'pim.Average_competency_score_given_by_each_evaluator_across_reviews');

INSERT INTO ohrm_report_configuration (report_id, configuration) VALUES
     (@employee_goals_report, '{"selectedDisplayFieldGroups":["1","6","51"],"selectedDisplayFields":["9","9_1","77","82","83","pg_1","pg_4","pg_5","pg_6","pg_7","pg_8","pg_9","pg_10","pg_11","pg_19"],"selectedFilterCriteria":{"include":"1","show_only_filtered_records":true,"employee_name":"","job_title":"","location":"","sub_unit":"","goal_category_id":{"1":"Goal"},"goal_level_id":"","goal_priority_id":"","goal_status_id":"","goal_due_date_dynamic_date_group":{"goal_due_date_dynamic_date_group":"goal_due_date_date_more_custom","goal_due_date_date_more_custom":"","goal_due_date_date_more_today":"1","goal_due_date_date_more_from_field":""},"goal_completion":{"from":"","to":"","comparison":"BETWEEN"},"goal_weight":{"from":"","to":"","comparison":"BETWEEN"}}}');
INSERT INTO ohrm_report_configuration (report_id, configuration) VALUES
     (@employee_okrs_report, '{"selectedDisplayFieldGroups":["1","6","51"],"selectedDisplayFields":["9","9_1","77","82","83","pg_4","pg_5","pg_6","pg_7","pg_8","pg_10","pg_11","pg_12","pg_13","pg_16","pg_14","pg_17","pg_15","pg_18","pg_2","pg_19","pg_20"],"selectedFilterCriteria":{"include":"1","show_only_filtered_records":true,"employee_name":"","job_title":"","location":"","sub_unit":"","goal_category_id":{"2":"Objective"},"goal_level_id":"","goal_priority_id":"","goal_status_id":"","goal_due_date_dynamic_date_group":{"goal_due_date_dynamic_date_group":"goal_due_date_date_more_custom","goal_due_date_date_more_custom":"","goal_due_date_date_more_today":"1","goal_due_date_date_more_from_field":""},"goal_completion":{"from":"","to":"","comparison":"BETWEEN"},"goal_weight":{"from":"","to":"","comparison":"BETWEEN"}}}');
INSERT INTO ohrm_report_configuration (report_id, configuration) VALUES
     (@employee_goals_and_okrs_report, '{"selectedDisplayFieldGroups":["1","6","51"],"selectedDisplayFields":["9","9_1","77","82","83","pg_4","pg_5","pg_6","pg_7","pg_8","pg_10","pg_11","pg_12","pg_13","pg_16","pg_14","pg_17","pg_15","pg_18","pg_3","pg_9","pg_19","pg_20"],"selectedFilterCriteria":{"include":"1","show_only_filtered_records":true,"employee_name":"","job_title":"","location":"","sub_unit":"","goal_category_id":{"1":"Goal","2":"Objective"},"goal_level_id":"","goal_priority_id":"","goal_status_id":"","goal_due_date_dynamic_date_group":{"goal_due_date_dynamic_date_group":"goal_due_date_date_more_custom","goal_due_date_date_more_custom":"","goal_due_date_date_more_today":"1","goal_due_date_date_more_from_field":""},"goal_completion":{"from":"","to":"","comparison":"BETWEEN"},"goal_weight":{"from":"","to":"","comparison":"BETWEEN"}}}');
INSERT INTO ohrm_report_configuration (report_id, configuration) VALUES
     (@reviews_done_by_each_employee_during_specified_period_report, '{"selectedDisplayFieldGroups":["1","52"],"selectedDisplayFields":["9","9_1","appraisalDescription","appraisalDueDate","appraisalFromDate","appraisalToDate","evaluatorName","evaluatorJobTitle","evaluatorGroup","weightedCompetencyScore","weightedGoalScore","reviewRating"],"selectedFilterCriteria":{"include":"1","show_only_filtered_records":true,"employee_name":"","appraisal_evaluator":"","appraisal_to_date_dynamic_date_group_func_year_group":{"appraisal_to_date_dynamic_date_group_func_year_group":"appraisal_to_date_year_current","appraisal_to_date_year_custom":"","appraisal_to_date_year_current":"1","appraisal_to_date_year_from_field":""},"appraisal_from_date_dynamic_date_group_func_year_group":{"appraisal_from_date_dynamic_date_group_func_year_group":"appraisal_from_date_year_current","appraisal_from_date_year_custom":"","appraisal_from_date_year_current":"1","appraisal_from_date_year_from_field":""},"evaluator_group_id":{"1":"Main Evaluator"},"appraisal_status":{"2":"COMPLETED","3":"APPROVED"},"appraisal_cycle":{"-1":"All Open Appraisal Cycles"}},"summaryConfiguration":{"summaryId":"dynamic_chart","chartType":"bar_chart","groupByFieldId":"evaluatorName","aggregateFieldId":"-1","aggregateType":"count","showSummaryTable":true,"hideDetailedData":false}}');
INSERT INTO ohrm_report_configuration (report_id, configuration) VALUES
     (@average_competency_score_given_by_each_evaluator_across_reviews, '{"selectedDisplayFieldGroups":["1","52"],"selectedDisplayFields":["9","9_1","appraisalDescription","appraisalDueDate","appraisalFromDate","appraisalToDate","evaluatorName","evaluatorJobTitle","evaluatorGroup","weightedCompetencyScore","weightedGoalScore","reviewRating"],"selectedFilterCriteria":{"include":"1","show_only_filtered_records":true,"employee_name":"","appraisal_evaluator":"","appraisal_from_date_dynamic_date_group_func_year_group":{"appraisal_from_date_dynamic_date_group_func_year_group":"appraisal_from_date_year_current","appraisal_from_date_year_custom":"","appraisal_from_date_year_current":"1","appraisal_from_date_year_from_field":""},"appraisal_to_date_dynamic_date_group_func_year_group":{"appraisal_to_date_dynamic_date_group_func_year_group":"appraisal_to_date_year_current","appraisal_to_date_year_custom":"","appraisal_to_date_year_current":"1","appraisal_to_date_year_from_field":""},"evaluator_group_id":{"1":"Main Evaluator"},"appraisal_status":{"2":"COMPLETED","3":"APPROVED"},"appraisal_cycle":{"-1":"All Open Appraisal Cycles"}},"summaryConfiguration":{"summaryId":"dynamic_chart","chartType":"bar_chart","groupByFieldId":"evaluatorName","aggregateFieldId":"weightedCompetencyScore","aggregateType":"avg","showSummaryTable":true,"hideDetailedData":false}}');

INSERT INTO ohrm_report_share (report_id, role_type_id) VALUES
    (@employee_goals_report, 1),
    (@employee_okrs_report, 1),
    (@employee_goals_and_okrs_report, 1),
    (@reviews_done_by_each_employee_during_specified_period_report, 1),
    (@average_competency_score_given_by_each_evaluator_across_reviews, 1);
