ALTER TABLE `ohrm_leave_type`  ADD `include_in_bradford_factor_report` TINYINT(1) NOT NULL DEFAULT '0' AFTER `exclude_in_reports_if_no_entitlement`;

INSERT INTO `ohrm_advanced_report` ( `name`, `unique_name`, `definition`, `enabled`) VALUES
( 'Leave Bradford Factor Report', 'Bradford_Factor_Report', '',1);

SET @max_report_id := (SELECT  `id` FROM ohrm_advanced_report WHERE  unique_name = 'Bradford_Factor_Report');
SET @view_leave_module_screen_id := (SELECT `id` FROM ohrm_screen WHERE `name` = 'View Leave Module');


SET @leave_menu_id := (SELECT id FROM ohrm_menu_item where menu_title = 'Leave');
SET @leave_report_menu_id := (SELECT id FROM ohrm_menu_item where parent_id=@leave_menu_id AND menu_title = 'Reports');
SET @leave_menu_status := (SELECT `status`  FROM `ohrm_menu_item` WHERE `menu_title` LIKE 'Leave Period' limit 1);

SET @leave_module_id := (SELECT `id` FROM `ohrm_module` WHERE `name` = 'leave');
INSERT INTO ohrm_screen (`name`, `module_id`, `action_url`) VALUES
('Bradford Factor Report', @leave_module_id, 'viewBradfordFactorReport');
SET @view_report_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
(1, @view_report_screen_id, 1, 1, 1, 1);
INSERT INTO ohrm_user_role_screen (user_role_id, screen_id, can_read, can_create, can_update, can_delete) VALUES
(3, @view_report_screen_id, 1, 1, 1, 1);
INSERT INTO ohrm_menu_item (`menu_title`, `screen_id`, `parent_id`, `level`, `order_hint`, `url_extras`, `status`) VALUES
('Bradford Factor Report', @view_report_screen_id, @leave_report_menu_id, 3, 2000, concat('/reportId/', @max_report_id ), @leave_menu_status);

INSERT INTO `ohrm_data_group` (`name`, `description`, `can_read`, `can_create`, `can_update`, `can_delete`) VALUES
('leave_bradford_factor_report', 'Leave - Leave Bradford Factor Report', 1, NULL, NULL, NULL);
SET @leave_bradford_factor_report_data_group_id := (SELECT id FROM `ohrm_data_group` WHERE `name` = 'leave_bradford_factor_report');

INSERT INTO `ohrm_user_role_data_group` (`user_role_id`, `data_group_id`, `can_read`, `can_create`, `can_update`, `can_delete`, `self`) VALUES
(1, @leave_bradford_factor_report_data_group_id, 1, NULL, NULL, NULL, 0),
(3, @leave_bradford_factor_report_data_group_id, 1, NULL, NULL, NULL, 0);

INSERT INTO `ohrm_data_group_screen`(`data_group_id`, `screen_id`, `permission`) VALUES
(@leave_bradford_factor_report_data_group_id, @view_report_screen_id, 1),
(@leave_bradford_factor_report_data_group_id, @view_leave_module_screen_id, 1);

INSERT INTO ohrm_user_role_type_data_group(user_role_type_id, data_group_id) VALUES
(1, @leave_bradford_factor_report_data_group_id),
(3, @leave_bradford_factor_report_data_group_id);
