INSERT INTO `ohrm_module` (`name`, `status`) VALUES ('directory', 1);  

SET @module_id := (SELECT LAST_INSERT_ID());  
  
INSERT INTO ohrm_screen (`name`, `module_id`, `action_url`, `route_name`) VALUES
('Directory', @module_id, 'viewDirectory', 'directory_viewDirectory');

SET @directory_configuration_screen_id := (SELECT LAST_INSERT_ID());

SET @people_management_pillar_menu_id := (SELECT `id` FROM ohrm_menu_item WHERE `menu_title` = 'People Management' AND parent_id IS NULL AND level = 1);
SET @employee_management_module_menu_id := (SELECT `id` FROM ohrm_menu_item WHERE `menu_title` = 'Employee Management' AND parent_id = @people_management_pillar_menu_id AND level = 2);

INSERT INTO ohrm_menu_item (`menu_title`, `screen_id`, `parent_id`, `level`, `order_hint`, `url_extras`, `uisref`, `status`) VALUES
('Directory', @directory_configuration_screen_id, @employee_management_module_menu_id, 3, 400, '/reset/1', 'corporate_directory.directory', 1);
  
SET @admin_role_id := (SELECT `id` FROM ohrm_user_role WHERE `name` = 'Admin'); 

SET @ess_role_id := (SELECT `id` FROM ohrm_user_role WHERE `name` = 'ESS'); 

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

INSERT INTO `ohrm_default_permitted_screen`(`user_role_type_id`, `screen_id`) VALUES 
(2, @directory_configuration_screen_id);

INSERT INTO `ohrm_token`(`name`, `display_name`, `class_name`, `entity_name`, `value_getters`, `data_group_id`, `is_date`, `localize`,`parameters`) VALUES
('directory.employeeFullName', 'Employee Full Name', null, 'Employee', 'getFullName', null, 0, 0,null),
('directory.employeeId', 'Employee Id', null, 'Employee', 'getEmployeeId', null, 0, 0,'visibility => off'),
('directory.street1','Street 1',null,'Employee','getStreet1',null,0,0,'visibility=> off,group=>employeeAddress'),
('directory.street2','Street 2',null,'Employee','getStreet2',null,0,0,'visibility=> off,group=>employeeAddress'),
('directory.city','City',null,'Employee','getCity',null,0,0,'visibility=> off,group=>employeeAddress'),
('directory.province','Province',null,'Employee','getProvince',null,0,0,'visibility=> off,group=>employeeAddress'),
('directory.country','Country',null,'Employee','getCountry',null,0,0,'visibility=> off,group=>employeeAddress'),
('directory.zipcode','Zipcode',null,'Employee','getEmpZipcode',null,0,0,'visibility=> off,group=>employeeAddress'),
('directory.employeeHomeTelephone','Employee Home Telephone',null,'Employee','getEmpHmTelephone',null,0,0,'visibility=> off,group=>employeeTelephones'),
('directory.employeeWorkTelephone','Employee Work Telephone',null,'Employee','getEmpWorkTelephone',null,0,0,'visibility=> on,group=>employeeTelephones'),
('directory.employeeMobile','Employee Mobile',null,'Employee','getEmpMobile',null,0,0,'visibility=> on,group=>employeeTelephones'),
('directory.employeeWorkEmail','Employee Work Email',null,'Employee','getEmpWorkEmail',null,0,0,'visibility=> on,group=>employeeEmails'),
('directory.employeeOtherEmail','Employee Other Email',null,'Employee','getEmpOthEmail',null,0,0,'visibility=> off,group=>employeeEmails'),
('directory.employeeJobTitle','Employee Job Title',null,'Employee','getJobTitleName',null,0,0,null),
('directory.employeeSubUnit','Employee Sub Unit',null,'Employee','getSubDivision,getName',null,0,0,null),
('directory.employeeLocation','Employee Location',null,'Employee','getLocation,getName',null,0,0,null),
('directory.employeeOpCountry','Employee Operational Location',null,'Employee','getCountryName',null,0,0,null),
('directory.employeeCostCentre','Employee Cost Center',null,'Employee','getJobRecord,getCostCentre,getCostCodeWithName',null,0,0,null);

SET @firstTokenId := (SELECT LAST_INSERT_ID());

INSERT INTO `ohrm_restricted_module_token`(`token_id`,`restricted_module`) 
SELECT `id`,@module_id FROM `ohrm_token` WHERE `id` >=@firstTokenId;

INSERT INTO `ohrm_config` (`property`,`value`) VALUES
('directroy.sort_field', 'lastName'),
('directory.sort_direction', 'ASC'),
('directory.format_contact_number', 'on');

