ALTER TABLE `ohrm_performance_appraisal_evaluator`
    ADD `rating` FLOAT NOT NULL AFTER `status`,
    ADD `rating_percentage` FLOAT NOT NULL AFTER `rating`;

INSERT INTO `ohrm_event_listener` (`id`, `event`, `listener_class`, `enabled`, `position`) VALUES
   (NULL, 'appraisal.change', 'VASReviewChangeListener', '1', '100');

INSERT INTO ohrm_config(`property`,`value`) VALUES ('performance.show_evaluator_rating_on_review_status','SUBMITTED,APPROVED');

SET @performance_folder_id := (SELECT id FROM ohrm_report_folder WHERE name = 'Performance');
SET @system_user_role_id := (SELECT `id` FROM `ohrm_user_role` WHERE `name` = 'SYSTEM');
SET @system_user_id := (SELECT `id` FROM `ohrm_user` WHERE `user_role_id` = @system_user_role_id);
UPDATE `ohrm_advanced_report`
SET `folder_id` = @performance_folder_id, `custom_url` = 'report_view_oxd({"id": "Appraisal_Rating_Report", "filters": null})', `created_by`= @system_user_id
WHERE `unique_name` = 'Appraisal_Rating_Report';

-- New data group

SET @admin_id := (SELECT id FROM ohrm_user_role where name = 'Admin');
SET @sup_id := (SELECT id FROM ohrm_user_role where name = 'Supervisor');
SET @hod_id := (SELECT id FROM ohrm_user_role where name = 'HeadOfDepartment');
SET @performance_module_id := (SELECT id FROM ohrm_module WHERE name = 'performance');

INSERT INTO `ohrm_data_group` (`name`, `description`, `can_read`, `can_create`, `can_update`, `can_delete`) VALUES
('appraisal_rating_report', 'Performance - Appraisal Rating Report', 1, 1, 1, 1);

SET @appraisal_rating_report_data_group_id := (SELECT id from ohrm_data_group WHERE name = 'appraisal_rating_report');

INSERT INTO ohrm_user_role_data_group (user_role_id, data_group_id, can_read, can_create, can_update, can_delete, self) VALUES
(@admin_id, @appraisal_rating_report_data_group_id, 1, 0, 0, 0, 0),
(@hod_id, @appraisal_rating_report_data_group_id, 1, 0, 0, 0, 0),
(@sup_id, @appraisal_rating_report_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_id, @appraisal_rating_report_data_group_id, 1, 0, 0, 0),
(@sup_id, @appraisal_rating_report_data_group_id, 1, 0, 0, 0);


INSERT INTO ohrm_screen (name, module_id, action_url) VALUES
( 'Appraisal Rating Report', @performance_module_id, 'viewAppraisalRatingReport');

SET @appraisal_rating_report_screen_id =(SELECT id from ohrm_screen WHERE action_url = 'viewAppraisalRatingReport');

INSERT INTO ohrm_user_role_screen (user_role_id, screen_id, can_read, can_create, can_update, can_delete) VALUES
(@admin_id, @appraisal_rating_report_screen_id, 1, 0, 0, 0),
(@hod_id, @appraisal_rating_report_screen_id, 1, 0, 0, 0),
(@sup_id, @appraisal_rating_report_screen_id, 1, 0, 0, 0);

INSERT INTO ohrm_data_group_screen (data_group_id, screen_id, permission, self) VALUES
(@appraisal_rating_report_data_group_id,@appraisal_rating_report_screen_id ,1 ,0);