INSERT INTO `ohrm_workflow_state_machine` (`workflow`, `state`, `role`, `action`, `resulting_state`, `roles_to_notify`, `screens_to_show`, `priority`)
VALUES
  ('CLAIM_REQUEST', 'INITIAL', 'HEADOFDEPARTMENT', 'Create', 'DRAFT', '', 'INVISIBLE', 0),
  ('CLAIM_REQUEST', 'DRAFT', 'HEADOFDEPARTMENT', 'Delete', 'DELETED', '', 'INVISIBLE', 0),
  ('CLAIM_REQUEST', 'DRAFT', 'HEADOFDEPARTMENT', 'Update', 'DRAFT', '', 'INVISIBLE', 0),
  ('CLAIM_REQUEST', 'DRAFT', 'HEADOFDEPARTMENT', 'Submit', 'PENDING FINAL APPROVAL', '', '', 0),
  ('CLAIM_REQUEST', 'PENDING SUPERVISOR APPROVAL', 'HEADOFDEPARTMENT', 'Approve', 'PENDING FINAL APPROVAL', '', '', 0),
  ('CLAIM_REQUEST', 'PENDING SUPERVISOR APPROVAL', 'HEADOFDEPARTMENT', 'Update', 'PENDING SUPERVISOR APPROVAL', '', 'INVISIBLE', 0),
  ('CLAIM_REQUEST', 'PENDING SUPERVISOR APPROVAL', 'HEADOFDEPARTMENT', 'Reject', 'REJECTED', '', '', 0),
  ('CLAIM_REQUEST', 'REJECTED', 'HEADOFDEPARTMENT', 'Read', 'REJECTED', '', 'INVISIBLE', 0),
  ('CLAIM_REQUEST', 'APPROVED', 'HEADOFDEPARTMENT', 'Read', 'APPROVED', '', 'INVISIBLE', 0),
  ('CLAIM_REQUEST', 'PENDING FINAL APPROVAL', 'HEADOFDEPARTMENT', 'Read', 'PENDING FINAL APPROVAL', '', 'INVISIBLE', 0);


SET @viewExpenseModule_screen_id := (select id from ohrm_screen where `name`='Expense Module Default Menu Action');

SET @assignExpenseClaims_screen_id := (select id from ohrm_screen where `name` = 'Assign Expense Claims');


SET @hod_role_id := (SELECT `id`
                            FROM `ohrm_user_role`
                            WHERE `name` = 'HeadOfDepartment');

SET @module_id := (SELECT id from `ohrm_module` where name = 'expense');

SET @estimate_request_workflow_id := 'ESTIMATE_REQUEST';

SET @expense_expense_claims_data_group_id := (select id from `ohrm_data_group` where `name`='expense_expense_claims');

SET @assignEmployeeEstimateRequest_screen_id := (select id from ohrm_screen where `name`='Assign Estimate Requests');

SET @expense_estimate_request_data_group_id := (select  id from `ohrm_data_group` where `name`='expense_estimate_request');

SET @manageEstimateRequests_screen_id := (select id from ohrm_screen where `name`='Employee Estimate Requests');


SET @viewExpenseClaims_screen_id := (SELECT `id` from `ohrm_screen` where name = 'Expense Claims List');

INSERT INTO `ohrm_user_role_screen` (`user_role_id`, `screen_id`, `can_read`, `can_create`, `can_update`, `can_delete`)
VALUES
  (@hod_role_id, @viewExpenseModule_screen_id, 1, 1, 1, 1),
  (@hod_role_id, @viewExpenseClaims_screen_id, 1, 1, 1, 1),
  (@hod_role_id, @assignExpenseClaims_screen_id, 1, 1, 1, 1),
  (@hod_role_id, @manageEstimateRequests_screen_id, 1, 1, 1, 1),
  (@hod_role_id, @assignEmployeeEstimateRequest_screen_id, 1, 1, 1, 1);


INSERT INTO `ohrm_user_role_data_group` (`user_role_id`, `data_group_id`, `can_read`, `can_create`, `can_update`, `can_delete`, `self`)
VALUES
  (@hod_role_id, @expense_expense_claims_data_group_id, 1, 0, 0, 0, 0),
  (@hod_role_id, @expense_estimate_request_data_group_id, 1, 0, 0, 0, 0);



INSERT INTO `ohrm_workflow_state_machine` (`workflow`, `state`, `role`, `action`, `resulting_state`, `roles_to_notify`, `screens_to_show`, `priority`)
VALUES
(@estimate_request_workflow_id, 'INITIAL', 'HEADOFDEPARTMENT', 'Create', 'DRAFT', '', 'INVISIBLE', 0),
(@estimate_request_workflow_id, 'DRAFT', 'HEADOFDEPARTMENT', 'Delete', 'DELETED', '', 'INVISIBLE', 0),
(@estimate_request_workflow_id, 'DRAFT', 'HEADOFDEPARTMENT', 'Save', 'DRAFT', '', 'EDITABLE', 0),
(@estimate_request_workflow_id, 'DRAFT', 'HEADOFDEPARTMENT', 'Assign', 'PENDING FINAL APPROVAL', '', '', 0),
(@estimate_request_workflow_id, 'PENDING SUPERVISOR APPROVAL', 'HEADOFDEPARTMENT', 'Approve', 'PENDING FINAL APPROVAL', '', '', 0),
(@estimate_request_workflow_id, 'PENDING SUPERVISOR APPROVAL', 'HEADOFDEPARTMENT', 'Save', 'PENDING SUPERVISOR APPROVAL', '', 'EDITABLE', 0),
(@estimate_request_workflow_id, 'PENDING SUPERVISOR APPROVAL', 'HEADOFDEPARTMENT', 'Reject', 'REJECTED', '', '', 0),
(@estimate_request_workflow_id, 'REJECTED', 'HEADOFDEPARTMENT', 'Read', 'REJECTED', '', 'INVISIBLE', 0),
(@estimate_request_workflow_id, 'APPROVED', 'HEADOFDEPARTMENT', 'Read', 'APPROVED', '', 'INVISIBLE', 0),
(@estimate_request_workflow_id, 'PENDING FINAL APPROVAL', 'HEADOFDEPARTMENT', 'Read', 'PENDING FINAL APPROVAL', '', 'INVISIBLE', 0),
(@estimate_request_workflow_id, 'CANCELED', 'HEADOFDEPARTMENT', 'Read', 'CANCELED', '', 'INVISIBLE', 0);

INSERT INTO ohrm_module_default_page (`module_id`, `user_role_id`, `action`, `enable_class`, `priority`)
VALUES (@module_id, @hod_role_id, 'expense/viewExpenseClaims', NULL, 70);



