SET @performance_module_id := (SELECT `id` FROM `ohrm_module` WHERE `name`='performance');
INSERT INTO `ohrm_workflow` (`id`, `name`, `label`, `available_to`, `default_available_to`, `group_name`, `group_label`, `module_id`, `order_no`) VALUES
('MAIN APPRAISAL', 'mainAppraisal', NULL, '1,3','2' , 'performance appraisals', 'Appraisals', @performance_module_id, 8),
('SELF REVIEW', 'selfReview', NULL, '1', '2', 'performance appraisals', 'Appraisals', @performance_module_id, 8),
('FINAL REVIEW', 'finalReview', NULL, '1,3', '2', 'performance appraisals', 'Appraisals', @performance_module_id, 8),
('SUPERVISOR REVIEW','supervisorReview', NULL,'1','2', 'performance appraisals', 'Appraisals', @performance_module_id, 8),
('SUBORDINATE REVIEW','subordinateReview', NULL,'1','2', 'performance appraisals', 'Appraisals', @performance_module_id, 8),
('PEER REVIEW','peerReview', NULL,'1','2', 'performance appraisals', 'Appraisals', @performance_module_id, 8),
('APPRAISAL CYCLE','Appraisal Cycle', NULL,'1,3','2', 'performance appraisals', 'Appraisals', @performance_module_id, 8);

INSERT INTO ohrm_performance_evaluator_group (group_name, group_alias, activated, workflow_id, filterclass, precedence, auto_select_allowed, auto_select_enabled) VALUES
('mainEvaluators', 'Main Evaluator', 1, 'FINAL REVIEW', 'DefaultEvaluatorGroup', 1, 0, 0),
('self', 'Self', 1, 'SELF REVIEW', 'SelfEvaluatorGroup', 2, 0, 0),
('supervisors', 'Supervisors', 1, 'SUPERVISOR REVIEW', 'SupervisorEvaluatorGroup', 3, 1, 0),
('peers', 'Peers', 1, 'PEER REVIEW', 'PeerEvaluatorGroup', 5, 1, 0),
('subordinates', 'Subordinates', 1, 'SUBORDINATE REVIEW', 'SubordinateEvaluatorGroup', 4, 1, 0);

INSERT INTO `ohrm_workflow_state_machine`(`workflow`,`state`,`role`,`action`,`resulting_state`, `roles_to_notify`, `screens_to_show`, `priority`)  
                            VALUES ('MAIN APPRAISAL','NOT INITIATED','SYSTEM','Activate','INITIATED', 'AppraisalReviewer.self,AppraisalReviewer.mainEvaluators,AppraisalReviewer.supervisors,AppraisalReviewer.peers,AppraisalReviewer.subordinates,Subscriber', 0, 0),
                                   ('MAIN APPRAISAL','INITIATED','ADMIN','View','INITIATED', '', 1, 0),
                                   ('MAIN APPRAISAL','INITIATED','MAIN-EVALUATOR','View','INITIATED', '', 1, 0),
                                   ('MAIN APPRAISAL','INITIATED','SUPERVISOR','View','INITIATED', '', 1, 0),
                                   ('MAIN APPRAISAL','INITIATED','HeadOfDepartment','View','INITIATED', '', 1, 0),
                                   ('MAIN APPRAISAL','INITIATED','ESS','View','INITIATED', '', 1, 0),
                                   ('MAIN APPRAISAL','INITIATED','SYSTEM','Complete','COMPLETED', 'ess,MainEvaluator,Subscriber', 1, 0);
SELECT @completed_mainappraisal_flow_id := MAX(`id`) FROM `ohrm_workflow_state_machine`;

INSERT INTO `ohrm_workflow_state_machine`(`workflow`,`state`,`role`,`action`,`resulting_state`, `roles_to_notify`, `screens_to_show`, `priority`)  
                            VALUES ('MAIN APPRAISAL','COMPLETED','ADMIN','View','COMPLETED', '', 1, 0),
                                   ('MAIN APPRAISAL','COMPLETED','MAIN-EVALUATOR','View','COMPLETED', '', 1, 0),
                                   ('MAIN APPRAISAL','COMPLETED','ESS','View','COMPLETED', '', 1, 0),
                                   ('MAIN APPRAISAL','COMPLETED','SUPERVISOR','View','COMPLETED', '', 1, 0),
                                   ('MAIN APPRAISAL','COMPLETED','HeadOfDepartment','View','COMPLETED', '', 1, 0),
                                   ('MAIN APPRAISAL','COMPLETED','SYSTEM','Close','CLOSED', '', 0, 0),
                                   ('MAIN APPRAISAL','COMPLETED','SYSTEM','Reject','INITIATED', '', 0, 0),
                                   ('MAIN APPRAISAL','CLOSED','ADMIN','View','CLOSED', '', 1, 0),
                                   ('MAIN APPRAISAL','CLOSED','MAIN-EVALUATOR','View','CLOSED', '', 1, 0),
                                   ('MAIN APPRAISAL','CLOSED','ESS','View','CLOSED', '', 1, 0),
                                   ('MAIN APPRAISAL','CLOSED','SUPERVISOR','View','CLOSED', '', 1, 0),
                                   ('MAIN APPRAISAL','CLOSED','HeadOfDepartment','View','CLOSED', '', 1, 0),
                                   ('MAIN APPRAISAL','CLOSED','SYSTEM','Reopen','COMPLETED', '', 0, 0);
SELECT @admin_mainappraisal_approve_flow_id := MAX(`id`) FROM `ohrm_workflow_state_machine`;
SELECT @main_appraisal_system_reject_flow_id := (SELECT id FROM `ohrm_workflow_state_machine` WHERE `workflow` = 'MAIN APPRAISAL' AND `role`='SYSTEM' AND `action`='Reject');
    

    SELECT @last_id := MAX(`id`) FROM `ohrm_workflow_state_machine`;

    INSERT INTO `ohrm_workflow_state_machine`(`workflow`,`state`,`role`,`action`,`resulting_state`, `roles_to_notify`, `screens_to_show`, `priority`) 
                            VALUES ('SELF REVIEW','INITIATED','ADMIN','Read','INITIATED','','MULTIPLE_VIEW','0'),
                                   ('SELF REVIEW','INITIATED','HeadOfDepartment','Read','INITIATED','','MULTIPLE_VIEW','0'),
                                   ('SELF REVIEW','INITIATED','MAIN-EVALUATOR','Read','INITIATED','','MULTIPLE_VIEW','0'),
                                   ('SELF REVIEW','INITIATED','EVALUATOR','Read','INITIATED','','MULTIPLE_VIEW','0'),
                                   ('SELF REVIEW','INITIATED','EVALUATOR','Save','IN PROGRESS','','SINGLE_VIEW,MULTIPLE_VIEW','0'),
                                   ('SELF REVIEW','INITIATED','EVALUATOR','Submit','SUBMITTED','Subscriber','SINGLE_VIEW,MULTIPLE_VIEW','0'),
                                   ('SELF REVIEW','IN PROGRESS','EVALUATOR','Save','IN PROGRESS','','SINGLE_VIEW,MULTIPLE_VIEW','0'),
                                   ('SELF REVIEW','IN PROGRESS','EVALUATOR','Read','IN PROGRESS','','MULTIPLE_VIEW','0'),
                                   ('SELF REVIEW','IN PROGRESS','ADMIN','Read','IN PROGRESS','','MULTIPLE_VIEW','0'),
                                   ('SELF REVIEW','IN PROGRESS','HeadOfDepartment','Read','IN PROGRESS','','MULTIPLE_VIEW','0'),
                                   ('SELF REVIEW','IN PROGRESS','MAIN-EVALUATOR','Read','IN PROGRESS','','MULTIPLE_VIEW','0'),
                                   ('SELF REVIEW','IN PROGRESS','EVALUATOR','Submit','SUBMITTED','Subscriber','SINGLE_VIEW,MULTIPLE_VIEW','0'),
                                   ('SELF REVIEW','SUBMITTED','ADMIN','Read','SUBMITTED','','MULTIPLE_VIEW','0'),
                                   ('SELF REVIEW','SUBMITTED','HeadOfDepartment','Read','SUBMITTED','','MULTIPLE_VIEW','0'),
                                   ('SELF REVIEW','SUBMITTED','MAIN-EVALUATOR','Read','SUBMITTED','','MULTIPLE_VIEW','0');
    INSERT INTO `ohrm_workflow_state_machine` (`workflow`,`state`,`role`,`action`,`resulting_state`, `roles_to_notify`, `screens_to_show`, `priority`) 
                            VALUES ('SELF REVIEW','SUBMITTED','MAIN-EVALUATOR','Approve','APPROVED','','SINGLE_VIEW,MULTIPLE_VIEW','0');
     SELECT @main_eval_approve_flow_id := MAX(`id`) FROM `ohrm_workflow_state_machine`;

      INSERT INTO `ohrm_workflow_state_machine`(`workflow`,`state`,`role`,`action`,`resulting_state`, `roles_to_notify`, `screens_to_show`, `priority`)  
                            VALUES ('SELF REVIEW','SUBMITTED','MAIN-EVALUATOR','Reject','REJECTED','Evaluator,Subscriber','SINGLE_VIEW,MULTIPLE_VIEW','0'),
                                   ('SELF REVIEW','SUBMITTED','EVALUATOR','Read','SUBMITTED', '', 'MULTIPLE_VIEW', 0),                                   
                                   ('SELF REVIEW','APPROVED','EVALUATOR','Read','APPROVED', '', 'MULTIPLE_VIEW', 0),
                                   ('SELF REVIEW','APPROVED','ADMIN','Read','APPROVED', '', 'MULTIPLE_VIEW', 0),
                                   ('SELF REVIEW','APPROVED','HeadOfDepartment','Read','APPROVED', '', 'MULTIPLE_VIEW', 0),
                                   ('SELF REVIEW','APPROVED','MAIN-EVALUATOR','Read','APPROVED', '', 'MULTIPLE_VIEW', 0),
                                   ('SELF REVIEW','REJECTED','EVALUATOR','Read','REJECTED', '', 'MULTIPLE_VIEW', 0),
                                   ('SELF REVIEW','REJECTED','ADMIN','Read','REJECTED', '', 'MULTIPLE_VIEW', 0),
                                   ('SELF REVIEW','REJECTED','HeadOfDepartment','Read','REJECTED', '', 'MULTIPLE_VIEW', 0),
                                   ('SELF REVIEW','REJECTED','MAIN-EVALUATOR','Read','REJECTED', '', 'MULTIPLE_VIEW', 0),
                                   ('SELF REVIEW','REJECTED','EVALUATOR','Save','IN PROGRESS', '', 'SINGLE_VIEW,MULTIPLE_VIEW', 0),
                                   ('SELF REVIEW','REJECTED','EVALUATOR','Submit','SUBMITTED','Subscriber', 'SINGLE_VIEW,MULTIPLE_VIEW', 0);
    -- -----------------------------
    -- Final Review WorkFlow
    -- -----------------------------
    INSERT INTO `ohrm_workflow_state_machine`(`workflow`,`state`,`role`,`action`,`resulting_state`, `roles_to_notify`, `screens_to_show`, `priority`)  
                            VALUES ('FINAL REVIEW','INITIATED','MAIN-EVALUATOR','Save','IN PROGRESS', '', 'SINGLE_VIEW,MULTIPLE_VIEW', 0),
                                    ('FINAL REVIEW','INITIATED','MAIN-EVALUATOR','Read','INITIATED', '', 'MULTIPLE_VIEW', 0),
                                    ('FINAL REVIEW','INITIATED','MAIN-EVALUATOR','Create IDP','INITIATED', '', 'SINGLE_VIEW', 0),
                                    ('FINAL REVIEW','INITIATED','MAIN-EVALUATOR','View IDP','INITIATED', '', 'SINGLE_VIEW', 0),
                                    ('FINAL REVIEW','INITIATED','ADMIN','Read','INITIATED', '', 'MULTIPLE_VIEW', 0),
                                    ('FINAL REVIEW','INITIATED','HeadOfDepartment','Read','INITIATED', '', 'MULTIPLE_VIEW', 0),
                                    ('FINAL REVIEW','INITIATED','ADMIN','Create IDP','INITIATED', '', 'SINGLE_VIEW', 0),
                                    ('FINAL REVIEW','INITIATED','ADMIN','View IDP','INITIATED', '', 'SINGLE_VIEW', 0),
                                   ('FINAL REVIEW','INITIATED','MAIN-EVALUATOR','Submit','SUBMITTED','Subscriber','SINGLE_VIEW,MULTIPLE_VIEW', 0);
    SELECT @final_review_initiated_mainevaluator_submit_flow_id := MAX(`id`) FROM `ohrm_workflow_state_machine`;
    INSERT INTO `ohrm_workflow_state_machine`(`workflow`,`state`,`role`,`action`,`resulting_state`, `roles_to_notify`, `screens_to_show`, `priority`)
                            VALUES ('FINAL REVIEW','INITIATED','ADMIN','Save','IN PROGRESS', '', 'SINGLE_VIEW,MULTIPLE_VIEW', 0),
                                   ('FINAL REVIEW','INITIATED','ADMIN','Submit','SUBMITTED','Subscriber', 'SINGLE_VIEW,MULTIPLE_VIEW', 0);
    SELECT @final_review_initiated_admin_submit_flow_id := MAX(`id`) FROM `ohrm_workflow_state_machine`;
    INSERT INTO `ohrm_workflow_state_machine`(`workflow`,`state`,`role`,`action`,`resulting_state`, `roles_to_notify`, `screens_to_show`, `priority`)
                            VALUES ('FINAL REVIEW','IN PROGRESS','SUPERVISOR','Read','IN PROGRESS', '', 'MULTIPLE_VIEW', 0),
                                   ('FINAL REVIEW','IN PROGRESS','HeadOfDepartment','Read','IN PROGRESS', '', 'MULTIPLE_VIEW', 0),
                                   ('FINAL REVIEW','IN PROGRESS','ADMIN','Read','IN PROGRESS', '', 'MULTIPLE_VIEW', 0),
                                   ('FINAL REVIEW','IN PROGRESS','ADMIN','Create IDP','IN PROGRESS', '', 'SINGLE_VIEW', 0),
                                   ('FINAL REVIEW','IN PROGRESS','ADMIN','View IDP','IN PROGRESS', '', 'SINGLE_VIEW', 0),
                                   ('FINAL REVIEW','IN PROGRESS','MAIN-EVALUATOR','Read','IN PROGRESS', '', 'MULTIPLE_VIEW', 0),
                                   ('FINAL REVIEW','IN PROGRESS','MAIN-EVALUATOR','Save','IN PROGRESS', '', 'SINGLE_VIEW,MULTIPLE_VIEW', 0),
                                   ('FINAL REVIEW','IN PROGRESS','MAIN-EVALUATOR','Create IDP','IN PROGRESS', '', 'SINGLE_VIEW', 0),
                                   ('FINAL REVIEW','IN PROGRESS','MAIN-EVALUATOR','View IDP','IN PROGRESS', '', 'SINGLE_VIEW', 0),
                                   ('FINAL REVIEW','IN PROGRESS','ADMIN','Save','IN PROGRESS', '', 'SINGLE_VIEW,MULTIPLE_VIEW', 0),
                                   ('FINAL REVIEW','IN PROGRESS','MAIN-EVALUATOR','Submit','SUBMITTED','Subscriber', 'SINGLE_VIEW,MULTIPLE_VIEW', 0);
    SELECT @final_review_mainevaluator_submit_flow_id := MAX(`id`) FROM `ohrm_workflow_state_machine`;
    INSERT INTO `ohrm_workflow_state_machine`(`workflow`,`state`,`role`,`action`,`resulting_state`, `roles_to_notify` , `screens_to_show`, `priority`)
                            VALUES ('FINAL REVIEW','IN PROGRESS','ADMIN','Submit','SUBMITTED','Subscriber', 'SINGLE_VIEW,MULTIPLE_VIEW', 0);
    SELECT @final_review_admin_submit_flow_id := MAX(`id`) FROM `ohrm_workflow_state_machine`;

    INSERT INTO `ohrm_workflow_state_machine`(`workflow`,`state`,`role`,`action`,`resulting_state`, `roles_to_notify`, `screens_to_show`, `priority`)
                            VALUES ('FINAL REVIEW','SUBMITTED','ADMIN','Reject','REJECTED', 'Evaluator,Subscriber', 'SINGLE_VIEW,MULTIPLE_VIEW', 0),
                                   ('FINAL REVIEW','SUBMITTED','ADMIN','Save','SUBMITTED', '', 'SINGLE_VIEW,MULTIPLE_VIEW', 0),
                                   ('FINAL REVIEW','SUBMITTED','ADMIN','Create IDP','SUBMITTED', '', 'SINGLE_VIEW', 0),
                                   ('FINAL REVIEW','SUBMITTED','ADMIN','View IDP','SUBMITTED', '', 'SINGLE_VIEW', 0),
                                   ('FINAL REVIEW','SUBMITTED','ESS','Read','SUBMITTED', '', 'MULTIPLE_VIEW', 0),
                                   ('FINAL REVIEW','SUBMITTED','SUPERVISOR','Read','SUBMITTED', '', 'MULTIPLE_VIEW', 0),
                                   ('FINAL REVIEW','SUBMITTED','HeadOfDepartment','Read','SUBMITTED', '', 'MULTIPLE_VIEW', 0),
                                   ('FINAL REVIEW','SUBMITTED','MAIN-EVALUATOR','Read','SUBMITTED', '', 'MULTIPLE_VIEW', 0),
                                   ('FINAL REVIEW','SUBMITTED','MAIN-EVALUATOR','Create IDP','SUBMITTED', '', 'SINGLE_VIEW', 0),
                                   ('FINAL REVIEW','SUBMITTED','MAIN-EVALUATOR','View IDP','SUBMITTED', '', 'SINGLE_VIEW', 0),
                                   ('FINAL REVIEW','SUBMITTED','ADMIN','Read','SUBMITTED', '', 'MULTIPLE_VIEW', 0),
                                   ('FINAL REVIEW','REJECTED','ESS','Read','REJECTED', '', 'MULTIPLE_VIEW', 0),
                                   ('FINAL REVIEW','REJECTED','SUPERVISOR','Read','REJECTED', '', 'MULTIPLE_VIEW', 0),
                                   ('FINAL REVIEW','REJECTED','HeadOfDepartment','Read','REJECTED', '', 'MULTIPLE_VIEW', 0),
                                   ('FINAL REVIEW','REJECTED','ADMIN','Read','REJECTED', '', 'MULTIPLE_VIEW', 0),
                                   ('FINAL REVIEW','REJECTED','ADMIN','Create IDP','REJECTED', '', 'SINGLE_VIEW', 0),
                                   ('FINAL REVIEW','REJECTED','ADMIN','View IDP','REJECTED', '', 'SINGLE_VIEW', 0),
                                   ('FINAL REVIEW','REJECTED','MAIN-EVALUATOR','Read','REJECTED', '', 'MULTIPLE_VIEW', 0),
                                   ('FINAL REVIEW','REJECTED','MAIN-EVALUATOR','Create IDP','REJECTED', '', 'SINGLE_VIEW', 0),
                                   ('FINAL REVIEW','REJECTED','MAIN-EVALUATOR','View IDP','REJECTED', '', 'SINGLE_VIEW', 0),
                                   ('FINAL REVIEW','REJECTED','ADMIN','Save','IN PROGRESS', '', 'SINGLE_VIEW,MULTIPLE_VIEW', 0),
                                   ('FINAL REVIEW','REJECTED','MAIN-EVALUATOR','Save','IN PROGRESS', '', 'SINGLE_VIEW,MULTIPLE_VIEW', 0),
                                   ('FINAL REVIEW','REJECTED','ADMIN','Submit','SUBMITTED','Subscriber', 'SINGLE_VIEW,MULTIPLE_VIEW', 0);
    SELECT @final_review_rejected_admin_submit_flow_id := MAX(`id`) FROM `ohrm_workflow_state_machine`;  
    INSERT INTO `ohrm_workflow_state_machine`(`workflow`,`state`,`role`,`action`,`resulting_state`, `roles_to_notify` , `screens_to_show`, `priority`)
                            VALUES ('FINAL REVIEW','REJECTED','MAIN-EVALUATOR','Submit','SUBMITTED','Subscriber', 'SINGLE_VIEW,MULTIPLE_VIEW', 0);
    SELECT @final_review_rejected_admin_reject_flow_id := (SELECT id FROM `ohrm_workflow_state_machine` WHERE `workflow` = 'FINAL REVIEW' AND `role`='ADMIN' AND `action`='Reject');
    SELECT @final_review_rejected_mainevaluator_submit_flow_id := MAX(`id`) FROM `ohrm_workflow_state_machine`;


    INSERT INTO `ohrm_workflow_state_machine`(`workflow`,`state`,`role`,`action`,`resulting_state`, `roles_to_notify`, `screens_to_show`, `priority`)  
                            VALUES ('SUPERVISOR REVIEW','INITIATED','ADMIN','Read','INITIATED','','MULTIPLE_VIEW','0'),
                                   ('SUPERVISOR REVIEW','INITIATED','HeadOfDepartment','Read','INITIATED','','MULTIPLE_VIEW','0'),
                                   ('SUPERVISOR REVIEW','INITIATED','ADMIN','Create IDP','INITIATED','','SINGLE_VIEW','0'),
                                   ('SUPERVISOR REVIEW','INITIATED','ADMIN','View IDP','INITIATED','','SINGLE_VIEW','0'),
                                   ('SUPERVISOR REVIEW','INITIATED','MAIN-EVALUATOR','Read','INITIATED','','MULTIPLE_VIEW','0'),
                                   ('SUPERVISOR REVIEW','INITIATED','MAIN-EVALUATOR','Create IDP','INITIATED','','SINGLE_VIEW','0'),
                                   ('SUPERVISOR REVIEW','INITIATED','MAIN-EVALUATOR','View IDP','INITIATED','','SINGLE_VIEW','0'),
                                   ('SUPERVISOR REVIEW','INITIATED','EVALUATOR','Read','INITIATED','','MULTIPLE_VIEW','0'),
                                   ('SUPERVISOR REVIEW','INITIATED','EVALUATOR','Create IDP','INITIATED','','SINGLE_VIEW','0'),
                                   ('SUPERVISOR REVIEW','INITIATED','EVALUATOR','View IDP','INITIATED','','SINGLE_VIEW','0'),
                                   ('SUPERVISOR REVIEW','INITIATED','EVALUATOR','Save','IN PROGRESS','','SINGLE_VIEW,MULTIPLE_VIEW','0'),
                                   ('SUPERVISOR REVIEW','INITIATED','EVALUATOR','Submit','SUBMITTED','Subscriber','SINGLE_VIEW,MULTIPLE_VIEW','0'),
                                   ('SUPERVISOR REVIEW','IN PROGRESS','EVALUATOR','Save','IN PROGRESS','','SINGLE_VIEW,MULTIPLE_VIEW','0'),
                                   ('SUPERVISOR REVIEW','IN PROGRESS','EVALUATOR','Create IDP','IN PROGRESS','','SINGLE_VIEW','0'),
                                   ('SUPERVISOR REVIEW','IN PROGRESS','EVALUATOR','View IDP','IN PROGRESS','','SINGLE_VIEW','0'),
                                   ('SUPERVISOR REVIEW','IN PROGRESS','ADMIN','Read','IN PROGRESS','','MULTIPLE_VIEW','0'),
                                   ('SUPERVISOR REVIEW','IN PROGRESS','HeadOfDepartment','Read','IN PROGRESS','','MULTIPLE_VIEW','0'),
                                   ('SUPERVISOR REVIEW','IN PROGRESS','ADMIN','Create IDP','IN PROGRESS','','SINGLE_VIEW','0'),
                                   ('SUPERVISOR REVIEW','IN PROGRESS','ADMIN','View IDP','IN PROGRESS','','SINGLE_VIEW','0'),
                                   ('SUPERVISOR REVIEW','IN PROGRESS','MAIN-EVALUATOR','Read','IN PROGRESS','','MULTIPLE_VIEW','0'),
                                   ('SUPERVISOR REVIEW','IN PROGRESS','MAIN-EVALUATOR','Create IDP','IN PROGRESS','','SINGLE_VIEW','0'),
                                   ('SUPERVISOR REVIEW','IN PROGRESS','MAIN-EVALUATOR','View IDP','IN PROGRESS','','SINGLE_VIEW','0'),
                                   ('SUPERVISOR REVIEW','IN PROGRESS','EVALUATOR','Read','IN PROGRESS','','MULTIPLE_VIEW','0'),
                                   ('SUPERVISOR REVIEW','IN PROGRESS','EVALUATOR','Submit','SUBMITTED','Subscriber','SINGLE_VIEW,MULTIPLE_VIEW','0'),
                                   ('SUPERVISOR REVIEW','SUBMITTED','ADMIN','Read','SUBMITTED','','MULTIPLE_VIEW','0'),
                                   ('SUPERVISOR REVIEW','SUBMITTED','HeadOfDepartment','Read','SUBMITTED','','MULTIPLE_VIEW','0'),
                                   ('SUPERVISOR REVIEW','SUBMITTED','ADMIN','Create IDP','SUBMITTED','','SINGLE_VIEW','0'),
                                   ('SUPERVISOR REVIEW','SUBMITTED','ADMIN','View IDP','SUBMITTED','','SINGLE_VIEW','0'),
                                   ('SUPERVISOR REVIEW','SUBMITTED','MAIN-EVALUATOR','Read','SUBMITTED','','MULTIPLE_VIEW','0'),
                                   ('SUPERVISOR REVIEW','SUBMITTED','MAIN-EVALUATOR','Create IDP','SUBMITTED','','SINGLE_VIEW','0'),
                                   ('SUPERVISOR REVIEW','SUBMITTED','MAIN-EVALUATOR','View IDP','SUBMITTED','','SINGLE_VIEW','0'),
                                   ('SUPERVISOR REVIEW','SUBMITTED','MAIN-EVALUATOR','Approve','APPROVED','','SINGLE_VIEW,MULTIPLE_VIEW','0'),
                                   ('SUPERVISOR REVIEW','SUBMITTED','MAIN-EVALUATOR','Reject','REJECTED','Evaluator,Subscriber','SINGLE_VIEW,MULTIPLE_VIEW','0'),
                                   ('SUPERVISOR REVIEW','SUBMITTED','EVALUATOR','Read','SUBMITTED', '', 'MULTIPLE_VIEW', 0),                                   
                                   ('SUPERVISOR REVIEW','SUBMITTED','EVALUATOR','Create IDP','SUBMITTED', '', 'SINGLE_VIEW', 0),
                                   ('SUPERVISOR REVIEW','SUBMITTED','EVALUATOR','View IDP','SUBMITTED', '', 'SINGLE_VIEW', 0),
                                   ('SUPERVISOR REVIEW','APPROVED','EVALUATOR','Read','APPROVED', '', 'MULTIPLE_VIEW', 0),
                                   ('SUPERVISOR REVIEW','APPROVED','EVALUATOR','Create IDP','APPROVED', '', 'SINGLE_VIEW', 0),
                                   ('SUPERVISOR REVIEW','APPROVED','EVALUATOR','View IDP','APPROVED', '', 'SINGLE_VIEW', 0),
                                   ('SUPERVISOR REVIEW','APPROVED','ADMIN','Read','APPROVED', '', 'MULTIPLE_VIEW', 0),
                                   ('SUPERVISOR REVIEW','APPROVED','HeadOfDepartment','Read','APPROVED', '', 'MULTIPLE_VIEW', 0),
                                   ('SUPERVISOR REVIEW','APPROVED','ADMIN','Create IDP','APPROVED', '', 'SINGLE_VIEW', 0),
                                   ('SUPERVISOR REVIEW','APPROVED','ADMIN','View IDP','APPROVED', '', 'SINGLE_VIEW', 0),
                                   ('SUPERVISOR REVIEW','APPROVED','MAIN-EVALUATOR','Read','APPROVED', '', 'MULTIPLE_VIEW', 0),
                                   ('SUPERVISOR REVIEW','APPROVED','MAIN-EVALUATOR','Create IDP','APPROVED', '', 'SINGLE_VIEW', 0),
                                   ('SUPERVISOR REVIEW','APPROVED','MAIN-EVALUATOR','View IDP','APPROVED', '', 'SINGLE_VIEW', 0),
                                   ('SUPERVISOR REVIEW','REJECTED','EVALUATOR','Read','REJECTED', '', 'MULTIPLE_VIEW', 0),                                   
                                   ('SUPERVISOR REVIEW','REJECTED','EVALUATOR','Create IDP','REJECTED', '', 'SINGLE_VIEW', 0),
                                   ('SUPERVISOR REVIEW','REJECTED','EVALUATOR','View IDP','REJECTED', '', 'SINGLE_VIEW', 0),
                                   ('SUPERVISOR REVIEW','REJECTED','ADMIN','Read','REJECTED', '', 'MULTIPLE_VIEW', 0),
                                   ('SUPERVISOR REVIEW','REJECTED','HeadOfDepartment','Read','REJECTED', '', 'MULTIPLE_VIEW', 0),
                                   ('SUPERVISOR REVIEW','REJECTED','ADMIN','Create IDP','REJECTED', '', 'SINGLE_VIEW', 0),
                                   ('SUPERVISOR REVIEW','REJECTED','ADMIN','View IDP','REJECTED', '', 'SINGLE_VIEW', 0),
                                   ('SUPERVISOR REVIEW','REJECTED','MAIN-EVALUATOR','Read','REJECTED', '', 'MULTIPLE_VIEW', 0),
                                   ('SUPERVISOR REVIEW','REJECTED','MAIN-EVALUATOR','Create IDP','REJECTED', '', 'SINGLE_VIEW', 0),
                                   ('SUPERVISOR REVIEW','REJECTED','MAIN-EVALUATOR','View IDP','REJECTED', '', 'SINGLE_VIEW', 0),
                                   ('SUPERVISOR REVIEW','REJECTED','EVALUATOR','Save','IN PROGRESS', '', 'SINGLE_VIEW,MULTIPLE_VIEW', 0),
                                   ('SUPERVISOR REVIEW','REJECTED','EVALUATOR','Submit','SUBMITTED','Subscriber', 'SINGLE_VIEW,MULTIPLE_VIEW', 0);  



    INSERT INTO `ohrm_workflow_state_machine`(`workflow`,`state`,`role`,`action`,`resulting_state`, `roles_to_notify`, `screens_to_show`, `priority`)  
                            VALUES ('SUBORDINATE REVIEW','INITIATED','ADMIN','Read','INITIATED','','MULTIPLE_VIEW','0'),
                                   ('SUBORDINATE REVIEW','INITIATED','HeadOfDepartment','Read','INITIATED','','MULTIPLE_VIEW','0'),
                                   ('SUBORDINATE REVIEW','INITIATED','MAIN-EVALUATOR','Read','INITIATED','','MULTIPLE_VIEW','0'),
                                   ('SUBORDINATE REVIEW','INITIATED','EVALUATOR','Read','INITIATED','','MULTIPLE_VIEW','0'),
                                   ('SUBORDINATE REVIEW','INITIATED','EVALUATOR','Save','IN PROGRESS','','SINGLE_VIEW,MULTIPLE_VIEW','0'),
                                   ('SUBORDINATE REVIEW','INITIATED','EVALUATOR','Submit','SUBMITTED','Subscriber','SINGLE_VIEW,MULTIPLE_VIEW','0'),
                                   ('SUBORDINATE REVIEW','IN PROGRESS','EVALUATOR','Save','IN PROGRESS','','SINGLE_VIEW,MULTIPLE_VIEW','0'),
                                   ('SUBORDINATE REVIEW','IN PROGRESS','ADMIN','Read','IN PROGRESS','','MULTIPLE_VIEW','0'),
                                   ('SUBORDINATE REVIEW','IN PROGRESS','HeadOfDepartment','Read','IN PROGRESS','','MULTIPLE_VIEW','0'),
                                   ('SUBORDINATE REVIEW','IN PROGRESS','MAIN-EVALUATOR','Read','IN PROGRESS','','MULTIPLE_VIEW','0'),
                                   ('SUBORDINATE REVIEW','IN PROGRESS','EVALUATOR','Read','IN PROGRESS','','MULTIPLE_VIEW','0'),
                                   ('SUBORDINATE REVIEW','IN PROGRESS','EVALUATOR','Submit','SUBMITTED','Subscriber','SINGLE_VIEW,MULTIPLE_VIEW','0'),
                                   ('SUBORDINATE REVIEW','SUBMITTED','ADMIN','Read','SUBMITTED','','MULTIPLE_VIEW','0'),
                                   ('SUBORDINATE REVIEW','SUBMITTED','HeadOfDepartment','Read','SUBMITTED','','MULTIPLE_VIEW','0'),
                                   ('SUBORDINATE REVIEW','SUBMITTED','MAIN-EVALUATOR','Read','SUBMITTED','','MULTIPLE_VIEW','0'),
                                   ('SUBORDINATE REVIEW','SUBMITTED','MAIN-EVALUATOR','Approve','APPROVED','','SINGLE_VIEW,MULTIPLE_VIEW','0'),
                                   ('SUBORDINATE REVIEW','SUBMITTED','MAIN-EVALUATOR','Reject','REJECTED','Evaluator,Subscriber','SINGLE_VIEW,MULTIPLE_VIEW','0'),
                                   ('SUBORDINATE REVIEW','SUBMITTED','EVALUATOR','Read','SUBMITTED', '', 'MULTIPLE_VIEW', 0),                                   
                                   ('SUBORDINATE REVIEW','APPROVED','EVALUATOR','Read','APPROVED', '', 'MULTIPLE_VIEW', 0),
                                   ('SUBORDINATE REVIEW','APPROVED','ADMIN','Read','APPROVED', '', 'MULTIPLE_VIEW', 0),
                                   ('SUBORDINATE REVIEW','APPROVED','HeadOfDepartment','Read','APPROVED', '', 'MULTIPLE_VIEW', 0),
                                   ('SUBORDINATE REVIEW','APPROVED','MAIN-EVALUATOR','Read','APPROVED', '', 'MULTIPLE_VIEW', 0),
                                   ('SUBORDINATE REVIEW','REJECTED','EVALUATOR','Read','REJECTED', '', 'MULTIPLE_VIEW', 0),                                   
                                   ('SUBORDINATE REVIEW','REJECTED','ADMIN','Read','REJECTED', '', 'MULTIPLE_VIEW', 0),
                                   ('SUBORDINATE REVIEW','REJECTED','HeadOfDepartment','Read','REJECTED', '', 'MULTIPLE_VIEW', 0),
                                   ('SUBORDINATE REVIEW','REJECTED','MAIN-EVALUATOR','Read','REJECTED', '', 'MULTIPLE_VIEW', 0),
                                   ('SUBORDINATE REVIEW','REJECTED','EVALUATOR','Save','IN PROGRESS', '', 'SINGLE_VIEW,MULTIPLE_VIEW', 0),                                  
                                   ('SUBORDINATE REVIEW','REJECTED','EVALUATOR','Submit','SUBMITTED','Subscriber', 'SINGLE_VIEW,MULTIPLE_VIEW', 0);    



    INSERT INTO `ohrm_workflow_state_machine`(`workflow`,`state`,`role`,`action`,`resulting_state`, `roles_to_notify`, `screens_to_show`, `priority`)  
                            VALUES ('PEER REVIEW','INITIATED','ADMIN','Read','INITIATED','','MULTIPLE_VIEW','0'),
                                   ('PEER REVIEW','INITIATED','HeadOfDepartment','Read','INITIATED','','MULTIPLE_VIEW','0'),
                                   ('PEER REVIEW','INITIATED','MAIN-EVALUATOR','Read','INITIATED','','MULTIPLE_VIEW','0'),
                                   ('PEER REVIEW','INITIATED','EVALUATOR','Read','INITIATED','','MULTIPLE_VIEW','0'),
                                   ('PEER REVIEW','INITIATED','EVALUATOR','Save','IN PROGRESS','','SINGLE_VIEW,MULTIPLE_VIEW','0'),
                                   ('PEER REVIEW','INITIATED','EVALUATOR','Submit','SUBMITTED','Subscriber','SINGLE_VIEW,MULTIPLE_VIEW','0'),
                                   ('PEER REVIEW','IN PROGRESS','EVALUATOR','Save','IN PROGRESS','','SINGLE_VIEW,MULTIPLE_VIEW','0'),
                                   ('PEER REVIEW','IN PROGRESS','ADMIN','Read','IN PROGRESS','','MULTIPLE_VIEW','0'),
                                   ('PEER REVIEW','IN PROGRESS','HeadOfDepartment','Read','IN PROGRESS','','MULTIPLE_VIEW','0'),
                                   ('PEER REVIEW','IN PROGRESS','MAIN-EVALUATOR','Read','IN PROGRESS','','MULTIPLE_VIEW','0'),
                                   ('PEER REVIEW','IN PROGRESS','EVALUATOR','Read','IN PROGRESS','','MULTIPLE_VIEW','0'),
                                   ('PEER REVIEW','IN PROGRESS','EVALUATOR','Submit','SUBMITTED','Subscriber','SINGLE_VIEW,MULTIPLE_VIEW','0'),
                                   ('PEER REVIEW','SUBMITTED','ADMIN','Read','SUBMITTED','','MULTIPLE_VIEW','0'),
                                   ('PEER REVIEW','SUBMITTED','HeadOfDepartment','Read','SUBMITTED','','MULTIPLE_VIEW','0'),
                                   ('PEER REVIEW','SUBMITTED','MAIN-EVALUATOR','Read','SUBMITTED','','MULTIPLE_VIEW','0'),
                                   ('PEER REVIEW','SUBMITTED','MAIN-EVALUATOR','Approve','APPROVED','','SINGLE_VIEW,MULTIPLE_VIEW','0'),
                                   ('PEER REVIEW','SUBMITTED','MAIN-EVALUATOR','Reject','REJECTED','Evaluator,Subscriber','SINGLE_VIEW,MULTIPLE_VIEW','0'),
                                   ('PEER REVIEW','SUBMITTED','EVALUATOR','Read','SUBMITTED', '', 'MULTIPLE_VIEW', 0),                                   
                                   ('PEER REVIEW','APPROVED','EVALUATOR','Read','APPROVED', '', 'MULTIPLE_VIEW', 0),
                                   ('PEER REVIEW','APPROVED','ADMIN','Read','APPROVED', '', 'MULTIPLE_VIEW', 0),
                                   ('PEER REVIEW','APPROVED','HeadOfDepartment','Read','APPROVED', '', 'MULTIPLE_VIEW', 0),
                                   ('PEER REVIEW','APPROVED','MAIN-EVALUATOR','Read','APPROVED', '', 'MULTIPLE_VIEW', 0),
                                   ('PEER REVIEW','REJECTED','EVALUATOR','Read','REJECTED', '', 'MULTIPLE_VIEW', 0),                                   
                                   ('PEER REVIEW','REJECTED','ADMIN','Read','REJECTED', '', 'MULTIPLE_VIEW', 0),
                                   ('PEER REVIEW','REJECTED','HeadOfDepartment','Read','REJECTED', '', 'MULTIPLE_VIEW', 0),
                                   ('PEER REVIEW','REJECTED','MAIN-EVALUATOR','Read','REJECTED', '', 'MULTIPLE_VIEW', 0),
                                   ('PEER REVIEW','REJECTED','EVALUATOR','Save','IN PROGRESS', '', 'SINGLE_VIEW,MULTIPLE_VIEW', 0),                                  
                                   ('PEER REVIEW','REJECTED','EVALUATOR','Submit','SUBMITTED','Subscriber', 'SINGLE_VIEW,MULTIPLE_VIEW', 0);       
                                   
    SELECT @last_id := MAX(`id`) FROM `ohrm_workflow_state_machine`;
    -- ---------------------------------
    -- WorkFlow Dependancies
    -- ---------------------------------
INSERT INTO `ohrm_workflow_state_machine_dependancy` (`master_state_change_id` ,`slave_state_change_id` ,`trigger_verification`)
                    VALUES ( @final_review_initiated_mainevaluator_submit_flow_id, @completed_mainappraisal_flow_id, 'MainEvaluatorApraisalCompletionVerifier'),
                     ( @final_review_initiated_admin_submit_flow_id, @completed_mainappraisal_flow_id, 'MainEvaluatorApraisalCompletionVerifier'),
                     ( @final_review_mainevaluator_submit_flow_id, @completed_mainappraisal_flow_id, 'MainEvaluatorApraisalCompletionVerifier'),
                     ( @final_review_admin_submit_flow_id, @completed_mainappraisal_flow_id, 'MainEvaluatorApraisalCompletionVerifier'),
                     ( @final_review_rejected_admin_submit_flow_id, @completed_mainappraisal_flow_id, 'MainEvaluatorApraisalCompletionVerifier'),
                     ( @final_review_rejected_mainevaluator_submit_flow_id, @completed_mainappraisal_flow_id, 'MainEvaluatorApraisalCompletionVerifier'),
                     ( @final_review_rejected_admin_reject_flow_id, @main_appraisal_system_reject_flow_id, 'DefaultApraisalCompletionVerifier');

update hs_hr_unique_id set last_id  = @last_id+1 where table_name  ='ohrm_workflow_state_machine'; 




INSERT INTO `ohrm_workflow_state_machine`(`workflow`,`state`,`role`,`action`,`resulting_state`, `roles_to_notify`, `screens_to_show`, `priority`)  VALUES
('APPRAISAL CYCLE', 'CREATED', 'ADMIN', 'Create Appraisals', 'APPRAISALS CREATED', NULL , 'ADD_SCREEN', '0'),
('APPRAISAL CYCLE', 'CREATED', 'ADMIN', 'Save', 'CREATED', NULL , 'ADD_SCREEN', '0'),
('APPRAISAL CYCLE', 'APPRAISALS CREATED', 'ADMIN', 'Save', 'APPRAISALS CREATED', NULL , 'ADD_SCREEN', '0'),
('APPRAISAL CYCLE', 'APPRAISALS CREATED', 'ADMIN', 'Activate', 'ACTIVATED', NULL , 'ADD_SCREEN', '0'),
('APPRAISAL CYCLE', 'ACTIVATED', 'ADMIN', 'Save', 'ACTIVATED', NULL , 'ADD_SCREEN', '0'),
('APPRAISAL CYCLE', 'ACTIVATED', 'ADMIN', 'Close', 'CLOSED', NULL , 'ADD_SCREEN', '0'),
('APPRAISAL CYCLE', 'CLOSED', 'ADMIN', 'Reopen', 'REOPENED', NULL , 'ADD_SCREEN', '0'),
('APPRAISAL CYCLE', 'REOPENED', 'ADMIN', 'Close', 'CLOSED', NULL , 'ADD_SCREEN', '0'),
('APPRAISAL CYCLE', 'CREATED', 'Supervisor', 'Create Appraisals', 'APPRAISALS CREATED', NULL , 'ADD_SCREEN', '0'),
('APPRAISAL CYCLE', 'CREATED', 'Supervisor', 'Save', 'CREATED', NULL , 'ADD_SCREEN', '0'),
('APPRAISAL CYCLE', 'APPRAISALS CREATED', 'Supervisor', 'Save', 'APPRAISALS CREATED', NULL , 'ADD_SCREEN', '0'),
('APPRAISAL CYCLE', 'APPRAISALS CREATED', 'Supervisor', 'Activate', 'ACTIVATED', NULL , 'ADD_SCREEN', '0'),
('APPRAISAL CYCLE', 'ACTIVATED', 'Supervisor', 'Save', 'ACTIVATED', NULL , 'ADD_SCREEN', '0'),
('APPRAISAL CYCLE', 'ACTIVATED', 'Supervisor', 'Close', 'CLOSED', NULL , 'ADD_SCREEN', '0'),
('APPRAISAL CYCLE', 'CLOSED', 'Supervisor', 'Reopen', 'REOPENED', NULL , 'ADD_SCREEN', '0'),
('APPRAISAL CYCLE', 'REOPENED', 'Supervisor', 'Close', 'CLOSED', NULL , 'ADD_SCREEN', '0'),
('APPRAISAL CYCLE', 'CREATED', 'HeadOfDepartment', 'Create Appraisals', 'APPRAISALS CREATED', NULL , 'ADD_SCREEN', '0'),
('APPRAISAL CYCLE', 'CREATED', 'HeadOfDepartment', 'Save', 'CREATED', NULL , 'ADD_SCREEN', '0'),
('APPRAISAL CYCLE', 'APPRAISALS CREATED', 'HeadOfDepartment', 'Save', 'APPRAISALS CREATED', NULL , 'ADD_SCREEN', '0'),
('APPRAISAL CYCLE', 'APPRAISALS CREATED', 'HeadOfDepartment', 'Activate', 'ACTIVATED', NULL , 'ADD_SCREEN', '0'),
('APPRAISAL CYCLE', 'ACTIVATED', 'HeadOfDepartment', 'Save', 'ACTIVATED', NULL , 'ADD_SCREEN', '0'),
('APPRAISAL CYCLE', 'ACTIVATED', 'HeadOfDepartment', 'Close', 'CLOSED', NULL , 'ADD_SCREEN', '0'),
('APPRAISAL CYCLE', 'CLOSED', 'HeadOfDepartment', 'Reopen', 'REOPENED', NULL , 'ADD_SCREEN', '0'),
('APPRAISAL CYCLE', 'REOPENED', 'HeadOfDepartment', 'Close', 'CLOSED', NULL , 'ADD_SCREEN', '0');

SET @appraisal_cycle_activation_id_admin := (SELECT `id` FROM ohrm_workflow_state_machine WHERE `workflow` = 'APPRAISAL CYCLE' AND `action` = 'Activate' AND `role` = 'ADMIN');
SET @appraisal_cycle_activation_id_supervisor := (SELECT `id` FROM ohrm_workflow_state_machine WHERE `workflow` = 'APPRAISAL CYCLE' AND `action` = 'Activate' AND `role` = 'Supervisor');
SET @appraisal_cycle_activation_id_hod := (SELECT `id` FROM ohrm_workflow_state_machine WHERE `workflow` = 'APPRAISAL CYCLE' AND `action` = 'Activate' AND `role` = 'HeadOfDepartment');
SET @main_appraisal_initiation_id := (SELECT `id` FROM ohrm_workflow_state_machine WHERE `workflow` = 'MAIN APPRAISAl' AND `action` = 'Activate' AND `role` = 'SYSTEM');

INSERT INTO `ohrm_workflow_state_machine_dependancy` (`master_state_change_id` ,`slave_state_change_id` ,`trigger_verification`)
                    VALUES ( @appraisal_cycle_activation_id_admin, @main_appraisal_initiation_id, 'VerifyApprisalCycleStateChange');
INSERT INTO `ohrm_workflow_state_machine_dependancy` (`master_state_change_id` ,`slave_state_change_id` ,`trigger_verification`)
                    VALUES ( @appraisal_cycle_activation_id_supervisor, @main_appraisal_initiation_id, 'VerifyApprisalCycleStateChange');
INSERT INTO `ohrm_workflow_state_machine_dependancy` (`master_state_change_id` ,`slave_state_change_id` ,`trigger_verification`)
                    VALUES ( @appraisal_cycle_activation_id_hod, @main_appraisal_initiation_id, 'VerifyApprisalCycleStateChange');

SET @appraisal_cycle_close_id_admin := (SELECT `id` FROM ohrm_workflow_state_machine WHERE `workflow` = 'APPRAISAL CYCLE' AND `action` = 'Close' AND `role` = 'ADMIN' AND `state` = 'ACTIVATED');
SET @appraisal_cycle_close_id_supervisor := (SELECT `id` FROM ohrm_workflow_state_machine WHERE `workflow` = 'APPRAISAL CYCLE' AND `action` = 'Close' AND `role` = 'Supervisor' AND `state` = 'ACTIVATED');
SET @appraisal_cycle_close_id_hod := (SELECT `id` FROM ohrm_workflow_state_machine WHERE `workflow` = 'APPRAISAL CYCLE' AND `action` = 'Close' AND `role` = 'HeadOfDepartment' AND `state` = 'ACTIVATED');
SET @appraisal_cycle_close_after_reopen_id_admin := (SELECT `id` FROM ohrm_workflow_state_machine WHERE `workflow` = 'APPRAISAL CYCLE' AND `action` = 'Close' AND `role` = 'ADMIN' AND `state` = 'REOPENED');
SET @appraisal_cycle_close_after_reopen_id_supervisor := (SELECT `id` FROM ohrm_workflow_state_machine WHERE `workflow` = 'APPRAISAL CYCLE' AND `action` = 'Close' AND `role` = 'Supervisor' AND `state` = 'REOPENED');
SET @appraisal_cycle_close_after_reopen_id_hod := (SELECT `id` FROM ohrm_workflow_state_machine WHERE `workflow` = 'APPRAISAL CYCLE' AND `action` = 'Close' AND `role` = 'HeadOfDepartment' AND `state` = 'REOPENED');
SET @main_appraisal_close_id := (SELECT `id` FROM ohrm_workflow_state_machine WHERE `workflow` = 'MAIN APPRAISAl' AND `action` = 'Close' AND `role` = 'SYSTEM');

INSERT INTO `ohrm_workflow_state_machine_dependancy` (`master_state_change_id` ,`slave_state_change_id` ,`trigger_verification`)
                    VALUES ( @appraisal_cycle_close_id_admin, @main_appraisal_close_id, 'VerifyApprisalCycleStateChange');
INSERT INTO `ohrm_workflow_state_machine_dependancy` (`master_state_change_id` ,`slave_state_change_id` ,`trigger_verification`)
                    VALUES ( @appraisal_cycle_close_id_supervisor, @main_appraisal_close_id, 'VerifyApprisalCycleStateChange');
INSERT INTO `ohrm_workflow_state_machine_dependancy` (`master_state_change_id` ,`slave_state_change_id` ,`trigger_verification`)
                    VALUES ( @appraisal_cycle_close_id_hod, @main_appraisal_close_id, 'VerifyApprisalCycleStateChange');

SET @appraisal_cycle_reopen_id_admin := (SELECT `id` FROM ohrm_workflow_state_machine WHERE `workflow` = 'APPRAISAL CYCLE' AND `action` = 'Reopen' AND `role` = 'ADMIN');
SET @appraisal_cycle_reopen_id_supervisor := (SELECT `id` FROM ohrm_workflow_state_machine WHERE `workflow` = 'APPRAISAL CYCLE' AND `action` = 'Reopen' AND `role` = 'Supervisor');
SET @appraisal_cycle_reopen_id_hod := (SELECT `id` FROM ohrm_workflow_state_machine WHERE `workflow` = 'APPRAISAL CYCLE' AND `action` = 'Reopen' AND `role` = 'Supervisor');
SET @main_appraisal_reopen_id := (SELECT `id` FROM ohrm_workflow_state_machine WHERE `workflow` = 'MAIN APPRAISAl' AND `action` = 'Reopen' AND `role` = 'SYSTEM');

INSERT INTO `ohrm_workflow_state_machine_dependancy` (`master_state_change_id` ,`slave_state_change_id` ,`trigger_verification`)
                    VALUES ( @appraisal_cycle_reopen_id_admin, @main_appraisal_reopen_id, 'VerifyApprisalCycleStateChange');
INSERT INTO `ohrm_workflow_state_machine_dependancy` (`master_state_change_id` ,`slave_state_change_id` ,`trigger_verification`)
                    VALUES ( @appraisal_cycle_reopen_id_supervisor, @main_appraisal_reopen_id, 'VerifyApprisalCycleStateChange');
INSERT INTO `ohrm_workflow_state_machine_dependancy` (`master_state_change_id` ,`slave_state_change_id` ,`trigger_verification`)
                    VALUES ( @appraisal_cycle_reopen_id_hod, @main_appraisal_reopen_id, 'VerifyApprisalCycleStateChange');

INSERT INTO `ohrm_workflow_state_machine_dependancy` (`master_state_change_id` ,`slave_state_change_id` ,`trigger_verification`)
                    VALUES ( @appraisal_cycle_close_after_reopen_id_admin, @main_appraisal_close_id, 'VerifyApprisalCycleStateChange');
INSERT INTO `ohrm_workflow_state_machine_dependancy` (`master_state_change_id` ,`slave_state_change_id` ,`trigger_verification`)
                    VALUES ( @appraisal_cycle_close_after_reopen_id_supervisor, @main_appraisal_close_id, 'VerifyApprisalCycleStateChange');
INSERT INTO `ohrm_workflow_state_machine_dependancy` (`master_state_change_id` ,`slave_state_change_id` ,`trigger_verification`)
                    VALUES ( @appraisal_cycle_close_after_reopen_id_hod, @main_appraisal_close_id, 'VerifyApprisalCycleStateChange');


INSERT INTO `ohrm_workflow` (`id`, `name`, `label`, `available_to`, `default_available_to`, `group_name`, `group_label`, `module_id`, `order_no`) VALUES
('PERFORMANCE GOAL', 'performanceGoal', NULL, '1,3','2' , 'performance goals', 'Goals', @performance_module_id, 8);

INSERT INTO `ohrm_workflow_state_machine`(`workflow`,`state`,`role`,`action`,`resulting_state`, `roles_to_notify`, `screens_to_show`, `priority`) VALUES
('PERFORMANCE GOAL','INITIAL','ESS User','Save','SAVED', '', NULL, 0),
('PERFORMANCE GOAL','INITIAL','ESS User','Submit','PENDING_SUPERVISOR_APPROVAL', '', NULL, 0),
('PERFORMANCE GOAL','SAVED','ESS User','Update','SAVED', '', NULL, 0),
('PERFORMANCE GOAL','SAVED','ESS User','Submit','PENDING_SUPERVISOR_APPROVAL', '', NULL, 0),
('PERFORMANCE GOAL','PENDING_SUPERVISOR_APPROVAL','ESS User','Update','PENDING_SUPERVISOR_APPROVAL', '', NULL, 0),
('PERFORMANCE GOAL','REJECTED','ESS User','Save','REJECTED', '', NULL, 0),
('PERFORMANCE GOAL','REJECTED','ESS User','Submit','PENDING_SUPERVISOR_APPROVAL', '', NULL, 0),
('PERFORMANCE GOAL','APPROVED','ESS User','Update','APPROVED', '', NULL, 0),
('PERFORMANCE GOAL','INITIAL','ADMIN','Save','APPROVED', '', NULL, 3),
('PERFORMANCE GOAL','SAVED','ADMIN','Save','APPROVED', '', NULL, 3),
('PERFORMANCE GOAL','APPROVED','ADMIN','Update','APPROVED', '', NULL, 3),
('PERFORMANCE GOAL','PENDING_SUPERVISOR_APPROVAL','ADMIN','Approve','APPROVED', '', NULL, 3),
('PERFORMANCE GOAL','PENDING_SUPERVISOR_APPROVAL','ADMIN','Reject','REJECTED', '', NULL, 3),
('PERFORMANCE GOAL','INITIAL','SUPERVISOR','Save','APPROVED', '', NULL, 2),
('PERFORMANCE GOAL','SAVED','SUPERVISOR','Save','APPROVED', '', NULL, 2),
('PERFORMANCE GOAL','APPROVED','SUPERVISOR','Update','APPROVED', '', NULL, 2),
('PERFORMANCE GOAL','PENDING_SUPERVISOR_APPROVAL','SUPERVISOR','Approve','APPROVED', '', NULL, 2),
('PERFORMANCE GOAL','PENDING_SUPERVISOR_APPROVAL','SUPERVISOR','Reject','REJECTED', '', NULL, 2),
('PERFORMANCE GOAL','INITIAL','HEADOFDEPARTMENT','Save','APPROVED', '', NULL, 1),
('PERFORMANCE GOAL','SAVED','HEADOFDEPARTMENT','Save','APPROVED', '', NULL, 1),
('PERFORMANCE GOAL','APPROVED','HEADOFDEPARTMENT','Update','APPROVED', '', NULL, 1),
('PERFORMANCE GOAL','PENDING_SUPERVISOR_APPROVAL','HEADOFDEPARTMENT','Approve','APPROVED', '', NULL, 1),
('PERFORMANCE GOAL','PENDING_SUPERVISOR_APPROVAL','HEADOFDEPARTMENT','Reject','REJECTED', '', NULL, 1);

INSERT INTO `ohrm_workflow_state_machine` (`workflow`, `state`, `role`, `action`, `resulting_state`, `roles_to_notify`, `screens_to_show`, `priority`) VALUES
('MAIN APPRAISAL', 'SUBMITTED', 'ADMIN', 'View', 'SUBMITTED', '', '1', 0),
('MAIN APPRAISAL', 'SUBMITTED', 'MAIN-EVALUATOR', 'View', 'SUBMITTED', '', '1', 0),
('MAIN APPRAISAL', 'SUBMITTED', 'ESS', 'View', 'SUBMITTED', '', '1', 0),
('MAIN APPRAISAL', 'SUBMITTED', 'SUPERVISOR', 'View', 'SUBMITTED', '', '1', 0),
('MAIN APPRAISAL', 'INITIATED', 'EVALUATOR', 'View', 'INITIATED', '', '1', 0),
('MAIN APPRAISAL', 'COMPLETED', 'EVALUATOR', 'View', 'COMPLETED', '', '1', 0),
('MAIN APPRAISAL', 'CLOSED', 'EVALUATOR', 'View', 'CLOSED', '', '1', 0),
('MAIN APPRAISAL', 'SUBMITTED', 'EVALUATOR', 'View', 'SUBMITTED', '', '1', 0);

DELETE FROM `ohrm_workflow_state_machine` WHERE `workflow` = 'MAIN APPRAISAL' AND `role` = 'ESS' AND `action` = 'View';

INSERT INTO `ohrm_workflow_state_machine` (`workflow`, `state`, `role`, `action`, `resulting_state`, `roles_to_notify`, `screens_to_show`, `priority`) VALUES
('MAIN APPRAISAL','INITIATED','ADMIN','Reassign','INITIATED','', '', 0),
('MAIN APPRAISAL','INITIATED','MAIN-EVALUATOR','Reassign','INITIATED','', '', 0),
('MAIN APPRAISAL','INITIATED','SUPERVISOR','Reassign','INITIATED','', '', 0),
('MAIN APPRAISAL','COMPLETED','ADMIN','Reassign','COMPLETED','', '', 0),
('MAIN APPRAISAL','COMPLETED','MAIN-EVALUATOR','Reassign','COMPLETED','', '', 0),
('MAIN APPRAISAL','COMPLETED','SUPERVISOR','Reassign','COMPLETED','', '', 0),
('MAIN APPRAISAL','CLOSED','ADMIN','Reassign','CLOSED','', '', 0),
('MAIN APPRAISAL','CLOSED','MAIN-EVALUATOR','Reassign','CLOSED','', '', 0),
('MAIN APPRAISAL','CLOSED','SUPERVISOR','Reassign','CLOSED','', '', 0),
('FINAL REVIEW','IN PROGRESS','ADMIN','Reassign','IN PROGRESS','', '', 0),
('FINAL REVIEW','SUBMITTED','ADMIN','Reassign','SUBMITTED','', '', 0),
('FINAL REVIEW','REJECTED','ADMIN','Reassign','REJECTED','', '', 0),
('FINAL REVIEW','IN PROGRESS','SUPERVISOR','Reassign','IN PROGRESS','', '', 0),
('FINAL REVIEW','SUBMITTED','SUPERVISOR','Reassign','SUBMITTED','', '', 0),
('FINAL REVIEW','REJECTED','SUPERVISOR','Reassign','REJECTED','', '', 0),
('FINAL REVIEW','IN PROGRESS','MAIN-EVALUATOR','Reassign','IN PROGRESS','', '', 0),
('FINAL REVIEW','SUBMITTED','MAIN-EVALUATOR','Reassign','SUBMITTED','', '', 0),
('FINAL REVIEW','REJECTED','MAIN-EVALUATOR','Reassign','REJECTED','', '', 0),
('SUPERVISOR REVIEW','IN PROGRESS','ADMIN','Reassign','IN PROGRESS','', '', 0),
('SUPERVISOR REVIEW','SUBMITTED','ADMIN','Reassign','SUBMITTED','', '', 0),
('SUPERVISOR REVIEW','APPROVED','ADMIN','Reassign','APPROVED','', '', 0),
('SUPERVISOR REVIEW','REJECTED','ADMIN','Reassign','REJECTED','', '', 0),
('SUPERVISOR REVIEW','IN PROGRESS','MAIN-EVALUATOR','Reassign','IN PROGRESS','', '', 0),
('SUPERVISOR REVIEW','SUBMITTED','MAIN-EVALUATOR','Reassign','SUBMITTED','', '', 0),
('SUPERVISOR REVIEW','APPROVED','MAIN-EVALUATOR','Reassign','APPROVED','', '', 0),
('SUPERVISOR REVIEW','REJECTED','MAIN-EVALUATOR','Reassign','REJECTED','', '', 0),
('SUPERVISOR REVIEW','IN PROGRESS','SUPERVISOR','Reassign','IN PROGRESS','', '', 0),
('SUPERVISOR REVIEW','SUBMITTED','SUPERVISOR','Reassign','SUBMITTED','', '', 0),
('SUPERVISOR REVIEW','APPROVED','SUPERVISOR','Reassign','APPROVED','', '', 0),
('SUPERVISOR REVIEW','REJECTED','SUPERVISOR','Reassign','REJECTED','', '', 0),
('PEER REVIEW','IN PROGRESS','ADMIN','Reassign','IN PROGRESS','', '', 0),
('PEER REVIEW','SUBMITTED','ADMIN','Reassign','SUBMITTED','', '', 0),
('PEER REVIEW','APPROVED','ADMIN','Reassign','APPROVED','', '', 0),
('PEER REVIEW','REJECTED','ADMIN','Reassign','REJECTED','', '', 0),
('PEER REVIEW','IN PROGRESS','MAIN-EVALUATOR','Reassign','IN PROGRESS','', '', 0),
('PEER REVIEW','SUBMITTED','MAIN-EVALUATOR','Reassign','SUBMITTED','', '', 0),
('PEER REVIEW','APPROVED','MAIN-EVALUATOR','Reassign','APPROVED','', '', 0),
('PEER REVIEW','REJECTED','MAIN-EVALUATOR','Reassign','REJECTED','', '', 0),
('PEER REVIEW','IN PROGRESS','SUPERVISOR','Reassign','IN PROGRESS','', '', 0),
('PEER REVIEW','SUBMITTED','SUPERVISOR','Reassign','SUBMITTED','', '', 0),
('PEER REVIEW','APPROVED','SUPERVISOR','Reassign','APPROVED','', '', 0),
('PEER REVIEW','REJECTED','SUPERVISOR','Reassign','REJECTED','', '', 0),
('SUBORDINATE REVIEW','IN PROGRESS','ADMIN','Reassign','IN PROGRESS','', '', 0),
('SUBORDINATE REVIEW','SUBMITTED','ADMIN','Reassign','SUBMITTED','', '', 0),
('SUBORDINATE REVIEW','APPROVED','ADMIN','Reassign','APPROVED','', '', 0),
('SUBORDINATE REVIEW','REJECTED','ADMIN','Reassign','REJECTED','', '', 0),
('SUBORDINATE REVIEW','IN PROGRESS','MAIN-EVALUATOR','Reassign','IN PROGRESS','', '', 0),
('SUBORDINATE REVIEW','SUBMITTED','MAIN-EVALUATOR','Reassign','SUBMITTED','', '', 0),
('SUBORDINATE REVIEW','APPROVED','MAIN-EVALUATOR','Reassign','APPROVED','', '', 0),
('SUBORDINATE REVIEW','REJECTED','MAIN-EVALUATOR','Reassign','REJECTED','', '', 0),
('SUBORDINATE REVIEW','IN PROGRESS','SUPERVISOR','Reassign','IN PROGRESS','', '', 0),
('SUBORDINATE REVIEW','SUBMITTED','SUPERVISOR','Reassign','SUBMITTED','', '', 0),
('SUBORDINATE REVIEW','APPROVED','SUPERVISOR','Reassign','APPROVED','', '', 0),
('SUBORDINATE REVIEW','REJECTED','SUPERVISOR','Reassign','REJECTED','', '', 0);
