ALTER TABLE `ohrm_cron_task` ADD `schedule` VARCHAR(100) NULL DEFAULT NULL;
ALTER TABLE `ohrm_cron_job_audittrail` ADD `unique_id` VARCHAR(50) NULL DEFAULT NULL;


INSERT INTO `ohrm_cron_task` (`name`, `short_description`, `long_description`, `command`, `schedule`, `observer_class`, `status`) VALUES
('Proccess Leave Notification', 'Proccess Leave Notification', 'Proccess Leave Notification', 'php symfony orangehrm:ProcessLeaveNotification', '0 5 * * *', '', 0),
('Attendance Process', 'Attendance Process', 'Attendance Process', 'php symfony orangehrm:AttendanceProcess', '0 5 * * *', '', 0),
('On Boarding Notification', 'OnBoarding Notification', 'On Boarding Notification', 'php symfony orangehrm:OnBoardingNotification', '0 5 * * *', '', 0),
('On Boarding Quick Notification', 'OnBoarding Quick Notification', 'OnBoardingQuickNotification', 'php symfony orangehrm:OnBoardingQuickNotification', '*/15 * * * *', '', 0),
('Log Cleanup', 'Remove and Archives logs', 'Archives logs to encrypted zip files and removed old logs based on a threshold date', 'php symfony orangehrm:cleanup-logs', '0 1 * * *', '', 0);

UPDATE `ohrm_cron_task` SET `schedule` = '*/15 * * * *' WHERE `name` = 'Send Emails';
UPDATE `ohrm_cron_task` SET `schedule` = '0 5 * * *' WHERE `name` = 'Queue Email Notifications To Be Sent';
UPDATE `ohrm_cron_task` SET `schedule` = '*/15 * * * *' WHERE `name` = 'Process Leave Accrual and Carry Forward';
UPDATE `ohrm_cron_task` SET `schedule` = '0 5 * * *' WHERE `name` = 'Terminate Employment';

UPDATE `ohrm_cron_task` SET `status` = 0 WHERE `schedule` IS NOT NULL;

SET @sys_admin_role_id := (SELECT `id` FROM ohrm_user_role WHERE `name` = 'ConfigAdmin');
SET @managementtool_notship_module_id := (SELECT `id` FROM `ohrm_module` WHERE `name` = 'managementtool_notship');
INSERT INTO ohrm_screen (`name`, `module_id`, `action_url`) VALUES ('Scheduled Tasks', @managementtool_notship_module_id, 'viewScheduledCronTasks');
SET @viewScheduledCronTasks_screen_id  := (SELECT id FROM ohrm_screen WHERE `name` = 'Scheduled Tasks');


SET @admin_menu_id := (SELECT `id` FROM ohrm_menu_item WHERE `menu_title` = 'Admin' AND `level` = 1);
SET @management_tools_menu_id := (SELECT `id` FROM ohrm_menu_item WHERE `menu_title` = 'Management Tools' AND `level` = 2);
INSERT INTO ohrm_menu_item (`menu_title`, `screen_id`, `parent_id`, `level`, `order_hint`, `url_extras`, `status`) VALUES ('Scheduled Tasks', @viewScheduledCronTasks_screen_id, @management_tools_menu_id, 3, 1100, '', 1);

INSERT INTO ohrm_user_role_screen (user_role_id, screen_id, can_read, can_create, can_update, can_delete) VALUES
  (@sys_admin_role_id, @viewScheduledCronTasks_screen_id, 1, 0, 1, 0);

SET @test_emulator_data_group_id := (SELECT `id` FROM `ohrm_data_group` WHERE `name` = 'test_emulator');

UPDATE `ohrm_data_group`  SET `can_update` = 1 WHERE `name` = 'test_emulator';
UPDATE `ohrm_user_role_data_group`  SET `can_update` = 1 WHERE `data_group_id` = @test_emulator_data_group_id AND `user_role_id` = @sys_admin_role_id;

INSERT INTO `ohrm_data_group_screen`(`data_group_id`, `screen_id`, `permission`) VALUES
(@test_emulator_data_group_id, @viewScheduledCronTasks_screen_id, 1),
(@test_emulator_data_group_id, @viewScheduledCronTasks_screen_id, 2),
(@test_emulator_data_group_id, @viewScheduledCronTasks_screen_id, 3),
(@test_emulator_data_group_id, @viewScheduledCronTasks_screen_id, 4);

ALTER TABLE `ohrm_cron_job_audittrail` CHANGE `time_stamp` `end_time_stamp` datetime NULL DEFAULT NULL;
ALTER TABLE `ohrm_cron_job_audittrail` ADD `start_time_stamp` datetime NULL DEFAULT NULL;
ALTER TABLE `ohrm_cron_job_audittrail` CHANGE `user_id` `user_id` int(11) DEFAULT NULL;
ALTER TABLE `ohrm_cron_job_audittrail` CHANGE `output` `output` text DEFAULT NULL;
ALTER TABLE `ohrm_cron_job_audittrail` CHANGE `success` `success` BOOLEAN DEFAULT NULL;
ALTER TABLE `ohrm_cron_task` ADD `prevent_overlap` tinyint(1) NOT NULL DEFAULT '0';

UPDATE `ohrm_cron_task` SET `prevent_overlap` = 1 WHERE `name` = 'Send Emails';