SET @personal_informationDataGroupId := (SELECT `id` FROM `ohrm_data_group` WHERE `name` = 'personal_information');
SET @personal_attachmentDataGroupId := (SELECT `id` FROM `ohrm_data_group` WHERE `name` = 'personal_attachment');
SET @personal_custom_fieldsDataGroupId := (SELECT `id` FROM `ohrm_data_group` WHERE `name` = 'personal_custom_fields');
SET @contact_detailsDataGroupId := (SELECT `id` FROM `ohrm_data_group` WHERE `name` = 'contact_details');
SET @contact_attachmentDataGroupId := (SELECT `id` FROM `ohrm_data_group` WHERE `name` = 'contact_attachment');
SET @contact_custom_fieldsDataGroupId := (SELECT `id` FROM `ohrm_data_group` WHERE `name` = 'contact_custom_fields');
SET @emergency_contactsDataGroupId := (SELECT `id` FROM `ohrm_data_group` WHERE `name` = 'emergency_contacts');
SET @emergency_attachmentDataGroupId := (SELECT `id` FROM `ohrm_data_group` WHERE `name` = 'emergency_attachment');
SET @emergency_custom_fieldsDataGroupId := (SELECT `id` FROM `ohrm_data_group` WHERE `name` = 'emergency_custom_fields');
SET @dependentsDataGroupId := (SELECT `id` FROM `ohrm_data_group` WHERE `name` = 'dependents');
SET @dependents_attachmentDataGroupId := (SELECT `id` FROM `ohrm_data_group` WHERE `name` = 'dependents_attachment');
SET @dependents_custom_fieldsDataGroupId := (SELECT `id` FROM `ohrm_data_group` WHERE `name` = 'dependents_custom_fields');
SET @immigrationDataGroupId := (SELECT `id` FROM `ohrm_data_group` WHERE `name` = 'immigration');
SET @immigration_attachmentDataGroupId := (SELECT `id` FROM `ohrm_data_group` WHERE `name` = 'immigration_attachment');
SET @immigration_custom_fieldsDataGroupId := (SELECT `id` FROM `ohrm_data_group` WHERE `name` = 'immigration_custom_fields');
SET @job_history_detailsDataGroupId := (SELECT `id` FROM `ohrm_data_group` WHERE `name` = 'job_history_details');
SET @job_attachmentDataGroupId := (SELECT `id` FROM `ohrm_data_group` WHERE `name` = 'job_attachment');
SET @job_custom_fieldsDataGroupId := (SELECT `id` FROM `ohrm_data_group` WHERE `name` = 'job_custom_fields');
SET @salary_history_detailsDataGroupId := (SELECT `id` FROM `ohrm_data_group` WHERE `name` = 'salary_history_details');
SET @salary_attachmentDataGroupId := (SELECT `id` FROM `ohrm_data_group` WHERE `name` = 'salary_attachment');
SET @salary_custom_fieldsDataGroupId := (SELECT `id` FROM `ohrm_data_group` WHERE `name` = 'salary_custom_fields');
SET @supervisorDataGroupId := (SELECT `id` FROM `ohrm_data_group` WHERE `name` = 'supervisor');
SET @subordinatesDataGroupId := (SELECT `id` FROM `ohrm_data_group` WHERE `name` = 'subordinates');
SET @report_to_attachmentDataGroupId := (SELECT `id` FROM `ohrm_data_group` WHERE `name` = 'report-to_attachment');
SET @report_to_custom_fieldsDataGroupId := (SELECT `id` FROM `ohrm_data_group` WHERE `name` = 'report-to_custom_fields');
SET @qualification_workDataGroupId := (SELECT `id` FROM `ohrm_data_group` WHERE `name` = 'qualification_work');
SET @qualification_educationDataGroupId := (SELECT `id` FROM `ohrm_data_group` WHERE `name` = 'qualification_education');
SET @qualification_skillsDataGroupId := (SELECT `id` FROM `ohrm_data_group` WHERE `name` = 'qualification_skills');
SET @qualification_languagesDataGroupId := (SELECT `id` FROM `ohrm_data_group` WHERE `name` = 'qualification_languages');
SET @qualification_licenseDataGroupId := (SELECT `id` FROM `ohrm_data_group` WHERE `name` = 'qualification_license');
SET @qualifications_attachmentDataGroupId := (SELECT `id` FROM `ohrm_data_group` WHERE `name` = 'qualifications_attachment');
SET @qualifications_custom_fieldsDataGroupId := (SELECT `id` FROM `ohrm_data_group` WHERE `name` = 'qualifications_custom_fields');
SET @membershipDataGroupId := (SELECT `id` FROM `ohrm_data_group` WHERE `name` = 'membership');
SET @membership_attachmentDataGroupId := (SELECT `id` FROM `ohrm_data_group` WHERE `name` = 'membership_attachment');
SET @membership_custom_fieldsDataGroupId := (SELECT `id` FROM `ohrm_data_group` WHERE `name` = 'membership_custom_fields');
SET @taxExemptionsDataGroupId := (SELECT `id` FROM `ohrm_data_group` WHERE `name` = 'taxExemptionsDataGroupId');
SET @tax_attachmentDataGroupId := (SELECT `id` FROM `ohrm_data_group` WHERE `name` = 'tax_attachment');
SET @tax_custom_fieldsDataGroupId := (SELECT `id` FROM `ohrm_data_group` WHERE `name` = 'tax_custom_fields');

SET @pimModuleId := (SELECT `id` FROM `ohrm_module` WHERE `name` = 'pim');

SET @leftMenuScreenId := (SELECT id FROM ohrm_screen 
    WHERE action_url = 'viewPersonalDetails' AND module_id = @pimModuleId);
INSERT INTO `ohrm_menu_item` (`menu_title`,`menu_category`, `screen_id`,
`order_hint`, `status`) VALUES
('Personal Details', 'pim_left_menu', @leftMenuScreenId, 10, 1);
SET @leftMenuItemId := (SELECT LAST_INSERT_ID());
INSERT INTO `ohrm_menu_item_data_group` (`menu_item_id`, `data_group_id`) VALUES
(@leftMenuItemId, @personal_informationDataGroupId),
(@leftMenuItemId, @personal_attachmentDataGroupId),
(@leftMenuItemId, @personal_custom_fieldsDataGroupId);


SET @leftMenuScreenId := (SELECT id FROM ohrm_screen 
    WHERE action_url = 'contactDetails' AND module_id = @pimModuleId);

INSERT INTO `ohrm_menu_item` (`menu_title`,`menu_category`, `screen_id`,
`order_hint`, `status`) VALUES
('Contact Details', 'pim_left_menu', @leftMenuScreenId, 20, 1);
SET @leftMenuItemId := (SELECT LAST_INSERT_ID());
INSERT INTO `ohrm_menu_item_data_group` (`menu_item_id`, `data_group_id`) VALUES
(@leftMenuItemId, @contact_detailsDataGroupId),
(@leftMenuItemId, @contact_attachmentDataGroupId),
(@leftMenuItemId, @contact_custom_fieldsDataGroupId);

SET @leftMenuScreenId := (SELECT id FROM ohrm_screen 
    WHERE action_url = 'viewEmergencyContacts' AND module_id = @pimModuleId);

INSERT INTO `ohrm_menu_item` (`menu_title`,`menu_category`, `screen_id`,
`order_hint`, `status`) VALUES
('Emergency Contacts', 'pim_left_menu', @leftMenuScreenId, 30, 1);
SET @leftMenuItemId := (SELECT LAST_INSERT_ID());
INSERT INTO `ohrm_menu_item_data_group` (`menu_item_id`, `data_group_id`) VALUES
(@leftMenuItemId, @emergency_contactsDataGroupId),
(@leftMenuItemId, @emergency_attachmentDataGroupId),
(@leftMenuItemId, @emergency_custom_fieldsDataGroupId);

SET @leftMenuScreenId := (SELECT id FROM ohrm_screen 
    WHERE action_url = 'viewDependents' AND module_id = @pimModuleId);
INSERT INTO `ohrm_menu_item` (`menu_title`,`menu_category`, `screen_id`,
`order_hint`, `status`) VALUES
('Dependents', 'pim_left_menu', @leftMenuScreenId, 40, 1);
SET @leftMenuItemId := (SELECT LAST_INSERT_ID());
INSERT INTO `ohrm_menu_item_data_group` (`menu_item_id`, `data_group_id`) VALUES
(@leftMenuItemId, @dependentsDataGroupId),
(@leftMenuItemId, @dependents_attachmentDataGroupId),
(@leftMenuItemId, @dependents_custom_fieldsDataGroupId);

SET @leftMenuScreenId := (SELECT id FROM ohrm_screen 
    WHERE action_url = 'viewImmigration' AND module_id = @pimModuleId);
INSERT INTO `ohrm_menu_item` (`menu_title`,`menu_category`, `screen_id`,
`order_hint`, `status`) VALUES
('Immigration', 'pim_left_menu', @leftMenuScreenId, 50, 1);
SET @leftMenuItemId := (SELECT LAST_INSERT_ID());
INSERT INTO `ohrm_menu_item_data_group` (`menu_item_id`, `data_group_id`) VALUES
(@leftMenuItemId, @immigrationDataGroupId),
(@leftMenuItemId, @immigration_attachmentDataGroupId),
(@leftMenuItemId, @immigration_custom_fieldsDataGroupId);

SET @leftMenuScreenId := (SELECT id FROM ohrm_screen 
    WHERE action_url = 'viewJobHistory' AND module_id = @pimModuleId);
INSERT INTO `ohrm_menu_item` (`menu_title`,`menu_category`, `screen_id`,
`order_hint`, `status`) VALUES
('Job', 'pim_left_menu', @leftMenuScreenId, 60, 1);
SET @leftMenuItemId := (SELECT LAST_INSERT_ID());
INSERT INTO `ohrm_menu_item_data_group` (`menu_item_id`, `data_group_id`) VALUES
(@leftMenuItemId, @job_history_detailsDataGroupId),
(@leftMenuItemId, @job_attachmentDataGroupId),
(@leftMenuItemId, @job_custom_fieldsDataGroupId);

SET @leftMenuScreenId := (SELECT id FROM ohrm_screen 
    WHERE action_url = 'viewSalaryHistory' AND module_id = @pimModuleId);
INSERT INTO `ohrm_menu_item` (`menu_title`,`menu_category`, `screen_id`,
`order_hint`, `status`) VALUES
('Salary', 'pim_left_menu', @leftMenuScreenId, 70, 1);
SET @leftMenuItemId := (SELECT LAST_INSERT_ID());
INSERT INTO `ohrm_menu_item_data_group` (`menu_item_id`, `data_group_id`) VALUES
(@leftMenuItemId, @salary_history_detailsDataGroupId),
(@leftMenuItemId, @salary_attachmentDataGroupId),
(@leftMenuItemId, @salary_custom_fieldsDataGroupId);

SET @leftMenuScreenId := (SELECT id FROM ohrm_screen
    WHERE action_url = 'viewUsTaxExemptions' AND module_id = @pimModuleId);
INSERT INTO `ohrm_menu_item` (`menu_title`,`menu_category`, `screen_id`,
`order_hint`, `status`) VALUES
('Tax Exemptions', 'pim_left_menu', @leftMenuScreenId, 75, IFNULL((select value from ohrm_config where property = 'pim_show_tax_exemptions'), 0));
SET @leftMenuItemId := (SELECT LAST_INSERT_ID());
INSERT INTO `ohrm_menu_item_data_group` (`menu_item_id`, `data_group_id`) VALUES
(@leftMenuItemId, @taxExemptionsDataGroupId),
(@leftMenuItemId, @tax_attachmentDataGroupId),
(@leftMenuItemId, @tax_custom_fieldsDataGroupId);

SET @leftMenuScreenId := (SELECT id FROM ohrm_screen 
    WHERE action_url = 'viewReportToDetails' AND module_id = @pimModuleId);
INSERT INTO `ohrm_menu_item` (`menu_title`,`menu_category`, `screen_id`,
`order_hint`, `status`) VALUES
('Report-to', 'pim_left_menu', @leftMenuScreenId, 80, 1);
SET @leftMenuItemId := (SELECT LAST_INSERT_ID());
INSERT INTO `ohrm_menu_item_data_group` (`menu_item_id`, `data_group_id`) VALUES
(@leftMenuItemId, @supervisorDataGroupId),
(@leftMenuItemId, @subordinatesDataGroupId),
(@leftMenuItemId, @report_to_attachmentDataGroupId),
(@leftMenuItemId, @report_to_custom_fieldsDataGroupId);

SET @leftMenuScreenId := (SELECT id FROM ohrm_screen 
    WHERE action_url = 'viewQualifications' AND module_id = @pimModuleId);
INSERT INTO `ohrm_menu_item` (`menu_title`,`menu_category`, `screen_id`,
`order_hint`, `status`) VALUES
('Qualifications', 'pim_left_menu', @leftMenuScreenId, 90, 1);
SET @leftMenuItemId := (SELECT LAST_INSERT_ID());
INSERT INTO `ohrm_menu_item_data_group` (`menu_item_id`, `data_group_id`) VALUES
(@leftMenuItemId, @qualification_workDataGroupId),
(@leftMenuItemId, @qualification_educationDataGroupId),
(@leftMenuItemId, @qualification_skillsDataGroupId),
(@leftMenuItemId, @qualification_languagesDataGroupId),
(@leftMenuItemId, @qualification_licenseDataGroupId),
(@leftMenuItemId, @qualifications_attachmentDataGroupId),
(@leftMenuItemId, @qualifications_custom_fieldsDataGroupId);

SET @leftMenuScreenId := (SELECT id FROM ohrm_screen 
    WHERE action_url = 'viewMemberships' AND module_id = @pimModuleId);

INSERT INTO `ohrm_menu_item` (`menu_title`,`menu_category`, `screen_id`,
`order_hint`, `status`) VALUES
('Memberships', 'pim_left_menu', @leftMenuScreenId, 100, 1);
SET @leftMenuItemId := (SELECT LAST_INSERT_ID());
INSERT INTO `ohrm_menu_item_data_group` (`menu_item_id`, `data_group_id`) VALUES
(@leftMenuItemId, @membershipDataGroupId),
(@leftMenuItemId, @membership_attachmentDataGroupId),
(@leftMenuItemId, @membership_custom_fieldsDataGroupId);

INSERT INTO `ohrm_screen` (`name`, `module_id`, `action_url`) VALUES
('Direct Deposit', @pimModuleId, 'viewDirectDepositDetails');
SET @leftMenuScreenId := (SELECT LAST_INSERT_ID());

INSERT INTO ohrm_user_role_screen (user_role_id, screen_id, can_read, can_create, can_update, can_delete)
SELECT id, @leftMenuScreenId, 1, 1, 1, 1 FROM ohrm_user_role WHERE type_id IS NOT NULL;

INSERT INTO `ohrm_default_permitted_screen`(`user_role_type_id`, `screen_id`) VALUES 
(1, @leftMenuScreenId),
(2, @leftMenuScreenId),
(3, @leftMenuScreenId);

INSERT INTO `ohrm_menu_item` (`menu_title`,`menu_category`, `screen_id`,
`order_hint`, `status`) VALUES
('Direct Deposit', 'pim_left_menu', @leftMenuScreenId, 110, 1);
SET @leftMenuItemId := (SELECT LAST_INSERT_ID());
INSERT INTO `ohrm_menu_item_data_group` (`menu_item_id`, `data_group_id`) VALUES
(@leftMenuItemId, @salary_history_detailsDataGroupId);

