SET @ess_role_id := (SELECT `id`
                     FROM `ohrm_user_role`
                     WHERE `name` = 'ESS');
SET @admin_role_id := (SELECT `id`
                       FROM `ohrm_user_role`
                       WHERE `name` = 'Admin');
SET @supervisor_role_id := (SELECT `id`
                            FROM `ohrm_user_role`
                            WHERE `name` = 'Supervisor');
SET @hod_role_id := (SELECT `id`
                            FROM `ohrm_user_role`
                            WHERE `name` = 'HeadOfDepartment');


INSERT INTO `ohrm_module` (`name`, `status`, `data_group_prefix`) VALUES ('expense', '1', 'Travel and Expense');
SET @module_id := (SELECT LAST_INSERT_ID());

INSERT INTO ohrm_screen (`name`, `module_id`, `action_url`, `route_name`)
VALUES ('Expense Module Default Menu Action', @module_id, 'viewExpenseModule', 'expense_viewExpenseModule');
SET @viewExpenseModule_screen_id := (SELECT LAST_INSERT_ID());

SET @other_pillar_menu_id := (SELECT `id` FROM ohrm_menu_item WHERE `menu_title` = 'Other' AND `level` = 1);

SET @expense_menu_id := (SELECT `id` FROM ohrm_menu_item WHERE `menu_title` = 'Travel and Expense' AND `level` = 2 AND parent_id = @other_pillar_menu_id);

INSERT INTO ohrm_screen (`name`, `module_id`, `action_url`, `route_name`)
VALUES ('view Currency Exchange Rates', @module_id, 'viewCurrencyExchangeRate', 'expense_viewCurrencyExchangeRate');
SET @viewCurrencyExchangeRate_screen_id := (SELECT LAST_INSERT_ID());

INSERT INTO ohrm_menu_item (`menu_title`, `screen_id`, `parent_id`, `level`, `order_hint`, `url_extras`, `status`)
VALUES ('Configuration', NULL, @expense_menu_id, 3, 500, '', 1);
SET @expense_config_menu_id := (SELECT LAST_INSERT_ID());

INSERT INTO ohrm_menu_item (`menu_title`, `screen_id`, `parent_id`, `level`, `order_hint`, `url_extras`, `status`)
VALUES ('Currency Exchange Rates', @viewCurrencyExchangeRate_screen_id, @expense_config_menu_id, 4, 100, '', 1);

INSERT INTO `ohrm_user_role_screen` (`user_role_id`, `screen_id`, `can_read`, `can_create`, `can_update`, `can_delete`)
VALUES
  (@ess_role_id, @viewExpenseModule_screen_id, 1, 1, 1, 1),
  (@admin_role_id, @viewExpenseModule_screen_id, 1, 1, 1, 1),
  (@supervisor_role_id, @viewExpenseModule_screen_id, 1, 1, 1, 1),
  (@hod_role_id, @viewExpenseModule_screen_id, 1, 1, 1, 1),
  (@admin_role_id, @viewCurrencyExchangeRate_screen_id, 1, 1, 1, 1);

INSERT INTO `ohrm_data_group` (`name`, `description`, `can_read`, `can_create`, `can_update`, `can_delete`) VALUES
  ('expense_currency_exchange_rate', 'Travel and Expense - Currency Exchange Rate', 1, 1, 1, 1);
SET @expense_currency_exchange_rate_data_group_id := (SELECT LAST_INSERT_ID());

INSERT INTO `ohrm_user_role_data_group` (`user_role_id`, `data_group_id`, `can_read`, `can_create`, `can_update`, `can_delete`, `self`)
VALUES
  (@admin_role_id, @expense_currency_exchange_rate_data_group_id, 1, 1, 1, 0, 0);


INSERT INTO `ohrm_data_group_screen` (`data_group_id`, `screen_id`, `permission`) VALUES
  (@expense_currency_exchange_rate_data_group_id, @viewExpenseModule_screen_id, 1),
  (@expense_currency_exchange_rate_data_group_id, @viewExpenseModule_screen_id, 2),
  (@expense_currency_exchange_rate_data_group_id, @viewExpenseModule_screen_id, 3),
  (@expense_currency_exchange_rate_data_group_id, @viewExpenseModule_screen_id, 4),
  (@expense_currency_exchange_rate_data_group_id, @viewCurrencyExchangeRate_screen_id, 1),
  (@expense_currency_exchange_rate_data_group_id, @viewCurrencyExchangeRate_screen_id, 2),
  (@expense_currency_exchange_rate_data_group_id, @viewCurrencyExchangeRate_screen_id, 3),
  (@expense_currency_exchange_rate_data_group_id, @viewCurrencyExchangeRate_screen_id, 4);


INSERT INTO ohrm_user_role_type_data_group (user_role_type_id, data_group_id, can_delete) VALUES
  (1, @expense_currency_exchange_rate_data_group_id, 0);


--  Define expense type data group
INSERT INTO ohrm_screen (`name`, `module_id`, `action_url`, `route_name`)
VALUES ('view Expense Type', @module_id, 'viewExpenseType', 'expense_viewExpenseType');
SET @viewExpenseType_screen_id := (SELECT LAST_INSERT_ID());

INSERT INTO ohrm_screen (`name`, `module_id`, `action_url`)
VALUES ('add Expense Type', @module_id, 'addExpenseType');
SET @addExpenseType_screen_id := (SELECT LAST_INSERT_ID());

INSERT INTO ohrm_menu_item (`menu_title`, `screen_id`, `parent_id`, `level`, `order_hint`, `url_extras`, `status`)
VALUES ('Expense Types', @viewExpenseType_screen_id, @expense_config_menu_id, 4, 300, '', 1);

INSERT INTO `ohrm_user_role_screen` (`user_role_id`, `screen_id`, `can_read`, `can_create`, `can_update`, `can_delete`)
VALUES (@admin_role_id, @addExpenseType_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 (@admin_role_id, @viewExpenseType_screen_id, 1, 1, 1, 1);

INSERT INTO `ohrm_data_group` (`name`, `description`, `can_read`, `can_create`, `can_update`, `can_delete`)
VALUES ('expense_expense_type', 'Travel and Expense - Expense Type', 1, 1, 1, 1);
SET @expense_expense_type_data_group_id := (SELECT LAST_INSERT_ID());

INSERT INTO `ohrm_user_role_data_group` (`user_role_id`, `data_group_id`, `can_read`, `can_create`, `can_update`, `can_delete`, `self`)
VALUES (@admin_role_id, @expense_expense_type_data_group_id, 1, 1, 1, 1, 0);


INSERT INTO `ohrm_data_group_screen` (`data_group_id`, `screen_id`, `permission`) VALUES
  (@expense_expense_type_data_group_id, @viewExpenseModule_screen_id, 1),
  (@expense_expense_type_data_group_id, @viewExpenseModule_screen_id, 2),
  (@expense_expense_type_data_group_id, @viewExpenseModule_screen_id, 3),
  (@expense_expense_type_data_group_id, @viewExpenseModule_screen_id, 4),
  (@expense_expense_type_data_group_id, @viewExpenseType_screen_id, 1),
  (@expense_expense_type_data_group_id, @viewExpenseType_screen_id, 2),
  (@expense_expense_type_data_group_id, @viewExpenseType_screen_id, 3),
  (@expense_expense_type_data_group_id, @viewExpenseType_screen_id, 4),
  (@expense_expense_type_data_group_id, @addExpenseType_screen_id, 1),
  (@expense_expense_type_data_group_id, @addExpenseType_screen_id, 2),
  (@expense_expense_type_data_group_id, @addExpenseType_screen_id, 3),
  (@expense_expense_type_data_group_id, @addExpenseType_screen_id, 4);

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

-- Employee Group

INSERT INTO ohrm_screen (`name`, `module_id`, `action_url`, `route_name`)
VALUES ('view Employee Group', @module_id, 'viewEmployeeGroup', 'expense_viewEmployeeGroup');
SET @viewEmployeeGroup_screen_id := (SELECT LAST_INSERT_ID());

INSERT INTO ohrm_menu_item (`menu_title`, `screen_id`, `parent_id`, `level`, `order_hint`, `url_extras`, `status`)
VALUES ('Eligibility Groups', @viewEmployeeGroup_screen_id, @expense_config_menu_id, 4, 200, '', 1);

INSERT INTO `ohrm_user_role_screen` (`user_role_id`, `screen_id`, `can_read`, `can_create`, `can_update`, `can_delete`)
VALUES (@admin_role_id, @viewEmployeeGroup_screen_id, 1, 1, 1, 1);

INSERT INTO `ohrm_data_group` (`name`, `description`, `can_read`, `can_create`, `can_update`, `can_delete`)
VALUES ('expense_employee_group', 'Travel and Expense - Eligibility Groups', 1, 1, 1, 1);
SET @expense_expense_employee_group_data_group_id := (SELECT LAST_INSERT_ID());

INSERT INTO `ohrm_user_role_data_group` (`user_role_id`, `data_group_id`, `can_read`, `can_create`, `can_update`, `can_delete`, `self`)
VALUES (@admin_role_id, @expense_expense_employee_group_data_group_id, 1, 1, 1, 1, 0);


INSERT INTO `ohrm_data_group_screen` (`data_group_id`, `screen_id`, `permission`) VALUES
  (@expense_expense_employee_group_data_group_id, @viewExpenseModule_screen_id, 1),
  (@expense_expense_employee_group_data_group_id, @viewExpenseModule_screen_id, 2),
  (@expense_expense_employee_group_data_group_id, @viewExpenseModule_screen_id, 3),
  (@expense_expense_employee_group_data_group_id, @viewExpenseModule_screen_id, 4),
  (@expense_expense_employee_group_data_group_id, @viewEmployeeGroup_screen_id, 1),
  (@expense_expense_employee_group_data_group_id, @viewEmployeeGroup_screen_id, 2),
  (@expense_expense_employee_group_data_group_id, @viewEmployeeGroup_screen_id, 3),
  (@expense_expense_employee_group_data_group_id, @viewEmployeeGroup_screen_id, 4);


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

-- Expense Claims

INSERT INTO ohrm_screen (`name`, `module_id`, `action_url`)
VALUES ('Submit Expense Claims', @module_id, 'applyExpenseClaims');
SET @applyExpenseClaims_screen_id := (SELECT LAST_INSERT_ID());

INSERT INTO ohrm_screen (`name`, `module_id`, `action_url`)
VALUES ('Assign Expense Claims', @module_id, 'assignExpenseClaims');
SET @assignExpenseClaims_screen_id := (SELECT LAST_INSERT_ID());

INSERT INTO ohrm_screen (`name`, `module_id`, `action_url`, `route_name`)
VALUES ('Expense Claims List', @module_id, 'viewExpenseClaims', 'expense_viewExpenseClaims');
SET @viewExpenseClaims_screen_id := (SELECT LAST_INSERT_ID());

INSERT INTO ohrm_screen (`name`, `module_id`, `action_url`, `route_name`)
VALUES ('View My Expense Claims', @module_id, 'viewMyExpenseClaims', 'expense_viewMyExpenseClaims');
SET @viewMyExpenseClaims_screen_id := (SELECT LAST_INSERT_ID());

INSERT INTO ohrm_menu_item (`menu_title`, `screen_id`, `parent_id`, `level`, `order_hint`, `url_extras`, `status`)
VALUES ('Employee Claims', @viewExpenseClaims_screen_id, @expense_menu_id, 3, 200, '', 1);

INSERT INTO ohrm_menu_item (`menu_title`, `screen_id`, `parent_id`, `level`, `order_hint`, `url_extras`, `status`)
VALUES ('My Claims', @viewMyExpenseClaims_screen_id, @expense_menu_id, 3, 400, '', 1);

-- admin
INSERT INTO `ohrm_user_role_screen` (`user_role_id`, `screen_id`, `can_read`, `can_create`, `can_update`, `can_delete`)
VALUES (@admin_role_id, @viewExpenseClaims_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 (@admin_role_id, @assignExpenseClaims_screen_id, 1, 1, 1, 1);

-- supervisor
INSERT INTO `ohrm_user_role_screen` (`user_role_id`, `screen_id`, `can_read`, `can_create`, `can_update`, `can_delete`)
VALUES (@supervisor_role_id, @viewExpenseClaims_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 (@supervisor_role_id, @assignExpenseClaims_screen_id, 1, 1, 1, 1);

-- Head of Department

INSERT INTO `ohrm_user_role_screen` (`user_role_id`, `screen_id`, `can_read`, `can_create`, `can_update`, `can_delete`)
VALUES (@hod_role_id, @viewExpenseClaims_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 (@hod_role_id, @assignExpenseClaims_screen_id, 1, 1, 1, 1);


-- ess
INSERT INTO `ohrm_user_role_screen` (`user_role_id`, `screen_id`, `can_read`, `can_create`, `can_update`, `can_delete`)
VALUES (@ess_role_id, @applyExpenseClaims_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 (@ess_role_id, @viewMyExpenseClaims_screen_id, 1, 1, 1, 1);

--

INSERT INTO `ohrm_data_group` (`name`, `description`, `can_read`, `can_create`, `can_update`, `can_delete`)
VALUES ('expense_expense_claims', 'Travel and Expense - Expense Claims', 1, 0, 0, 0);
SET @expense_expense_claims_data_group_id := (SELECT LAST_INSERT_ID());

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

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

-- Head of Department

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);


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


INSERT INTO `ohrm_data_group_screen` (`data_group_id`, `screen_id`, `permission`, `self`) VALUES
  (@expense_expense_claims_data_group_id, @viewExpenseModule_screen_id, 1, 0),
  (@expense_expense_claims_data_group_id, @viewExpenseModule_screen_id, 2, 0),
  (@expense_expense_claims_data_group_id, @viewExpenseModule_screen_id, 3, 0),
  (@expense_expense_claims_data_group_id, @viewExpenseModule_screen_id, 4, 0),
  (@expense_expense_claims_data_group_id, @viewExpenseModule_screen_id, 1, 1),
  (@expense_expense_claims_data_group_id, @viewExpenseModule_screen_id, 2, 1),
  (@expense_expense_claims_data_group_id, @viewExpenseModule_screen_id, 3, 1),
  (@expense_expense_claims_data_group_id, @viewExpenseModule_screen_id, 4, 1),
  (@expense_expense_claims_data_group_id, @applyExpenseClaims_screen_id, 1, 1),
  (@expense_expense_claims_data_group_id, @applyExpenseClaims_screen_id, 2, 1),
  (@expense_expense_claims_data_group_id, @applyExpenseClaims_screen_id, 3, 1),
  (@expense_expense_claims_data_group_id, @applyExpenseClaims_screen_id, 4, 1),
  (@expense_expense_claims_data_group_id, @assignExpenseClaims_screen_id, 1, 0),
  (@expense_expense_claims_data_group_id, @assignExpenseClaims_screen_id, 2, 0),
  (@expense_expense_claims_data_group_id, @assignExpenseClaims_screen_id, 3, 0),
  (@expense_expense_claims_data_group_id, @assignExpenseClaims_screen_id, 4, 0),
  (@expense_expense_claims_data_group_id, @viewExpenseClaims_screen_id, 1, 0),
  (@expense_expense_claims_data_group_id, @viewExpenseClaims_screen_id, 2, 0),
  (@expense_expense_claims_data_group_id, @viewExpenseClaims_screen_id, 3, 0),
  (@expense_expense_claims_data_group_id, @viewExpenseClaims_screen_id, 4, 0),
  (@expense_expense_claims_data_group_id, @viewMyExpenseClaims_screen_id, 1, 1),
  (@expense_expense_claims_data_group_id, @viewMyExpenseClaims_screen_id, 2, 1),
  (@expense_expense_claims_data_group_id, @viewMyExpenseClaims_screen_id, 3, 1),
  (@expense_expense_claims_data_group_id, @viewMyExpenseClaims_screen_id, 4, 1);


INSERT INTO ohrm_user_role_type_data_group (user_role_type_id, data_group_id, can_read, can_create, can_update, can_delete)
VALUES (1, @expense_expense_claims_data_group_id, 1, 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 (2, @expense_expense_claims_data_group_id, 1, 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 (3, @expense_expense_claims_data_group_id, 1, 0, 0, 0);

-- Estimate Request

INSERT INTO ohrm_screen (`name`, `module_id`, `action_url`)
VALUES ('Apply Estimate', @module_id, 'myEstimateRequest');
SET @myEstimateRequest_screen_id := (SELECT LAST_INSERT_ID());

INSERT INTO ohrm_screen (`name`, `module_id`, `action_url`, `route_name`)
VALUES ('My Estimate Requests', @module_id, 'viewEstimateRequest', 'expense_viewEstimateRequest');
SET @viewEstimateRequests_screen_id := (SELECT LAST_INSERT_ID());

INSERT INTO ohrm_screen (`name`, `module_id`, `action_url`, `route_name`)
VALUES ('Employee Estimate Requests', @module_id, 'viewEmployeeEstimateRequest', 'expense_viewEmployeeEstimateRequest');
SET @manageEstimateRequests_screen_id := (SELECT LAST_INSERT_ID());

INSERT INTO ohrm_screen (`name`, `module_id`, `action_url`)
VALUES ('Assign Estimate Requests', @module_id, 'assignEmployeeEstimateRequest');
SET @assignEmployeeEstimateRequest_screen_id := (SELECT LAST_INSERT_ID());

INSERT INTO ohrm_menu_item (`menu_title`, `screen_id`, `parent_id`, `level`, `order_hint`, `url_extras`, `status`)
VALUES ('My Travel Requests', @viewEstimateRequests_screen_id, @expense_menu_id, 3, 300, '', 1);

INSERT INTO ohrm_menu_item (`menu_title`, `screen_id`, `parent_id`, `level`, `order_hint`, `url_extras`, `status`)
VALUES ('Employee Travel Requests', @manageEstimateRequests_screen_id, @expense_menu_id, 3, 100, '', 1);

-- admin

INSERT INTO `ohrm_user_role_screen` (`user_role_id`, `screen_id`, `can_read`, `can_create`, `can_update`, `can_delete`)
VALUES (@admin_role_id, @manageEstimateRequests_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 (@admin_role_id, @assignEmployeeEstimateRequest_screen_id, 1, 1, 1, 1);

-- supervisor

INSERT INTO `ohrm_user_role_screen` (`user_role_id`, `screen_id`, `can_read`, `can_create`, `can_update`, `can_delete`)
VALUES (@supervisor_role_id, @manageEstimateRequests_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 (@supervisor_role_id, @assignEmployeeEstimateRequest_screen_id, 1, 1, 1, 1);

-- Head of Department

INSERT INTO `ohrm_user_role_screen` (`user_role_id`, `screen_id`, `can_read`, `can_create`, `can_update`, `can_delete`)
VALUES (@hod_role_id, @manageEstimateRequests_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 (@hod_role_id, @assignEmployeeEstimateRequest_screen_id, 1, 1, 1, 1);


-- ess

INSERT INTO `ohrm_user_role_screen` (`user_role_id`, `screen_id`, `can_read`, `can_create`, `can_update`, `can_delete`)
VALUES (@ess_role_id, @viewEstimateRequests_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 (@ess_role_id, @myEstimateRequest_screen_id, 1, 1, 1, 1);

--

INSERT INTO `ohrm_data_group` (`name`, `description`, `can_read`, `can_create`, `can_update`, `can_delete`)
VALUES ('expense_estimate_request', 'Travel and Expense - Travel Request', 1, 0, 0, 0);
SET @expense_estimate_request_data_group_id := (SELECT LAST_INSERT_ID());

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

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

-- Head of Department

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_estimate_request_data_group_id, 1, 0, 0, 0, 0);


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

INSERT INTO `ohrm_data_group_screen` (`data_group_id`, `screen_id`, `permission`, `self`) VALUES
  (@expense_estimate_request_data_group_id, @viewExpenseModule_screen_id, 1, 1),
  (@expense_estimate_request_data_group_id, @viewExpenseModule_screen_id, 2, 1),
  (@expense_estimate_request_data_group_id, @viewExpenseModule_screen_id, 3, 1),
  (@expense_estimate_request_data_group_id, @viewExpenseModule_screen_id, 4, 1),
  (@expense_estimate_request_data_group_id, @myEstimateRequest_screen_id, 1, 1),
  (@expense_estimate_request_data_group_id, @myEstimateRequest_screen_id, 2, 1),
  (@expense_estimate_request_data_group_id, @myEstimateRequest_screen_id, 3, 1),
  (@expense_estimate_request_data_group_id, @myEstimateRequest_screen_id, 4, 1),
  (@expense_estimate_request_data_group_id, @viewEstimateRequests_screen_id, 1, 1),
  (@expense_estimate_request_data_group_id, @viewEstimateRequests_screen_id, 2, 1),
  (@expense_estimate_request_data_group_id, @viewEstimateRequests_screen_id, 3, 1),
  (@expense_estimate_request_data_group_id, @viewEstimateRequests_screen_id, 4, 1),
  (@expense_estimate_request_data_group_id, @manageEstimateRequests_screen_id, 1, 0),
  (@expense_estimate_request_data_group_id, @manageEstimateRequests_screen_id, 2, 0),
  (@expense_estimate_request_data_group_id, @manageEstimateRequests_screen_id, 3, 0),
  (@expense_estimate_request_data_group_id, @manageEstimateRequests_screen_id, 4, 0),
  (@expense_estimate_request_data_group_id, @assignEmployeeEstimateRequest_screen_id, 1, 0),
  (@expense_estimate_request_data_group_id, @assignEmployeeEstimateRequest_screen_id, 2, 0),
  (@expense_estimate_request_data_group_id, @assignEmployeeEstimateRequest_screen_id, 3, 0),
  (@expense_estimate_request_data_group_id, @assignEmployeeEstimateRequest_screen_id, 4, 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 (1, @expense_estimate_request_data_group_id, 1, 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 (2, @expense_estimate_request_data_group_id, 1, 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 (3, @expense_estimate_request_data_group_id, 1, 0, 0, 0);

-- Workflow sate machine configuration for estimate request

SET @estimate_request_workflow_id := 'ESTIMATE_REQUEST';

INSERT INTO `ohrm_workflow` (`id`, `name`, `label`, `available_to`, `default_available_to`, `group_name`, `group_label`, `module_id`, `order_no`)
VALUES
  (@estimate_request_workflow_id, 'estimateRequest', 'Travel Request', '1,3', '2', NULL, NULL, (SELECT `id` FROM `ohrm_module` WHERE `name`='expense'), '14');

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', 'ESS USER', 'Create', 'DRAFT', '', '{"visibility":false}', 0),
(@estimate_request_workflow_id, 'INITIAL', 'SUPERVISOR', 'Create', 'DRAFT', '', '{"visibility":false}', 0),
(@estimate_request_workflow_id, 'INITIAL', 'ADMIN', 'Create', 'DRAFT', '', '{"visibility":false}', 0),
(@estimate_request_workflow_id, 'DRAFT', 'ESS USER', 'Delete', 'DELETED', '', '{"visibility":false}', 0),
(@estimate_request_workflow_id, 'DRAFT', 'SUPERVISOR', 'Delete', 'DELETED', '', '{"visibility":false}', 0),
(@estimate_request_workflow_id, 'DRAFT', 'ADMIN', 'Delete', 'DELETED', '', '{"visibility":false}', 0),
(@estimate_request_workflow_id, 'DRAFT', 'ESS USER', 'Save', 'DRAFT', '', '{"editability":true,"viewPriorityOrder":300}', 0),
(@estimate_request_workflow_id, 'DRAFT', 'SUPERVISOR', 'Save', 'DRAFT', '', '{"editability":true,"viewPriorityOrder":300}', 0),
(@estimate_request_workflow_id, 'DRAFT', 'ADMIN', 'Save', 'DRAFT', '', '{"editability":true,"viewPriorityOrder":300}', 0),
(@estimate_request_workflow_id, 'DRAFT', 'ESS USER', 'Submit', 'PENDING SUPERVISOR APPROVAL', '', '{"viewPriorityOrder":400}', 0),
(@estimate_request_workflow_id, 'DRAFT', 'SUPERVISOR', 'Assign', 'PENDING FINAL APPROVAL', '', '{"viewPriorityOrder":600}', 0),
(@estimate_request_workflow_id, 'DRAFT', 'ADMIN', 'Assign', 'APPROVED', '', '{"viewPriorityOrder":600}', 0),
(@estimate_request_workflow_id, 'PENDING SUPERVISOR APPROVAL', 'SUPERVISOR', 'Approve', 'PENDING FINAL APPROVAL', '', '{"viewPriorityOrder":500}', 0),
(@estimate_request_workflow_id, 'PENDING SUPERVISOR APPROVAL', 'ADMIN', 'Approve', 'APPROVED', '', '{"viewPriorityOrder":500}', 0),
(@estimate_request_workflow_id, 'PENDING SUPERVISOR APPROVAL', 'SUPERVISOR', 'Reject', 'REJECTED', '', '{"viewPriorityOrder":100}', 0),
(@estimate_request_workflow_id, 'PENDING SUPERVISOR APPROVAL', 'ADMIN', 'Reject', 'REJECTED', '', '{"viewPriorityOrder":100}', 0),
(@estimate_request_workflow_id, 'PENDING SUPERVISOR APPROVAL', 'ADMIN', 'Save', 'PENDING SUPERVISOR APPROVAL', '', '{"editability":true,"viewPriorityOrder":300}', 0),
(@estimate_request_workflow_id, 'PENDING SUPERVISOR APPROVAL', 'SUPERVISOR', 'Save', 'PENDING SUPERVISOR APPROVAL', '', '{"editability":true,"viewPriorityOrder":300}', 0),
(@estimate_request_workflow_id, 'PENDING SUPERVISOR APPROVAL', 'ADMIN', 'Cancel', 'CANCELED', '', '{"viewPriorityOrder":200}', 0),
(@estimate_request_workflow_id, 'PENDING FINAL APPROVAL', 'ADMIN', 'Approve', 'APPROVED', '', '{"viewPriorityOrder":500}', 0),
(@estimate_request_workflow_id, 'PENDING FINAL APPROVAL', 'ADMIN', 'Reject', 'REJECTED', '', '{"viewPriorityOrder":200}', 0),
(@estimate_request_workflow_id, 'PENDING FINAL APPROVAL', 'ADMIN', 'Save', 'PENDING FINAL APPROVAL', '', '{"editability":true,"viewPriorityOrder":300}', 0),
(@estimate_request_workflow_id, 'PENDING FINAL APPROVAL', 'ADMIN', 'Cancel', 'CANCELED', '', '{"viewPriorityOrder":100}', 0),
(@estimate_request_workflow_id, 'REJECTED', 'ESS USER', 'Save', 'REJECTED', '', '{"editability":true,"viewPriorityOrder":300}', 0),
(@estimate_request_workflow_id, 'REJECTED', 'ESS USER', 'Submit', 'PENDING SUPERVISOR APPROVAL', '', '{"viewPriorityOrder":400}', 0),
(@estimate_request_workflow_id, 'REJECTED', 'ADMIN', 'Read', 'REJECTED', '', '{"visibility":false}', 0),
(@estimate_request_workflow_id, 'REJECTED', 'SUPERVISOR', 'Read', 'REJECTED', '', '{"visibility":false}', 0),
(@estimate_request_workflow_id, 'APPROVED', 'ADMIN', 'Read', 'APPROVED', '', '{"visibility":false}', 0),
(@estimate_request_workflow_id, 'APPROVED', 'SUPERVISOR', 'Read', 'APPROVED', '', '{"visibility":false}', 0),
(@estimate_request_workflow_id, 'APPROVED', 'ADMIN', 'Cancel', 'CANCELED', '', '{"viewPriorityOrder":200}', 0),
(@estimate_request_workflow_id, 'PENDING FINAL APPROVAL', 'SUPERVISOR', 'Read', 'PENDING FINAL APPROVAL', '', '{"visibility":false}', 0),
(@estimate_request_workflow_id, 'CANCELED', 'ADMIN', 'Read', 'CANCELED', '', '{"visibility":false}', 0),
(@estimate_request_workflow_id, 'CANCELED', 'SUPERVISOR', 'Read', 'CANCELED', '', '{"visibility":false}', 0),
(@estimate_request_workflow_id, 'CANCELED', 'ESS USER', 'Read', 'CANCELED', '', '{"visibility":false}', 0),
(@estimate_request_workflow_id, 'INITIAL', 'HEADOFDEPARTMENT', 'Create', 'DRAFT', '', '{"visibility":false}', 0),
(@estimate_request_workflow_id, 'DRAFT', 'HEADOFDEPARTMENT', 'Delete', 'DELETED', '', '{"visibility":false}', 0),
(@estimate_request_workflow_id, 'DRAFT', 'HEADOFDEPARTMENT', 'Save', 'DRAFT', '', '{"editability":true,"viewPriorityOrder":300}', 0),
(@estimate_request_workflow_id, 'DRAFT', 'HEADOFDEPARTMENT', 'Assign', 'PENDING FINAL APPROVAL', '', '{"viewPriorityOrder":600}', 0),
(@estimate_request_workflow_id, 'PENDING SUPERVISOR APPROVAL', 'HEADOFDEPARTMENT', 'Approve', 'PENDING FINAL APPROVAL', '', '{"viewPriorityOrder":500}', 0),
(@estimate_request_workflow_id, 'PENDING SUPERVISOR APPROVAL', 'HEADOFDEPARTMENT', 'Reject', 'REJECTED', '', '{"viewPriorityOrder":100}', 0),
(@estimate_request_workflow_id, 'PENDING SUPERVISOR APPROVAL', 'HEADOFDEPARTMENT', 'Save', 'PENDING SUPERVISOR APPROVAL', '', '{"editability":true,"viewPriorityOrder":300}', 0),
(@estimate_request_workflow_id, 'REJECTED', 'HEADOFDEPARTMENT', 'Read', 'REJECTED', '', '{"visibility":false}', 0),
(@estimate_request_workflow_id, 'APPROVED', 'HEADOFDEPARTMENT', 'Read', 'APPROVED', '', '{"visibility":false}', 0),
(@estimate_request_workflow_id, 'PENDING FINAL APPROVAL', 'HEADOFDEPARTMENT', 'Read', 'PENDING FINAL APPROVAL', '', '{"visibility":false}', 0),
(@estimate_request_workflow_id, 'CANCELED', 'HEADOFDEPARTMENT', 'Read', 'CANCELED', '', '{"visibility":false}', 0);

-- Default page redirecting

INSERT INTO ohrm_module_default_page (`module_id`, `user_role_id`, `action`, `enable_class`, `priority`) VALUES
  (@module_id, @admin_role_id, 'expense/viewExpenseClaims', NULL, 100),
  (@module_id, @hod_role_id, 'expense/viewExpenseClaims', NULL, 70),
  (@module_id, @supervisor_role_id, 'expense/viewExpenseClaims', NULL, 50),
  (@module_id, @ess_role_id, 'expense/viewMyExpenseClaims', NULL, 25);
