CREATE TABLE `ohrm_position_hierarchy` (
  `id` int(13) NOT NULL AUTO_INCREMENT,
  `job_title_sup` int(13) NOT NULL DEFAULT '0',
  `job_title_sub` int(13) NOT NULL DEFAULT '0',
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=105 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;

CREATE TABLE `ohrm_reporting_method` (
  `id` int(7) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;

INSERT INTO `ohrm_reporting_method` VALUES (0);


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 @ess_role_id := (SELECT `id` FROM ohrm_user_role WHERE `name` = 'ESS');   
      
INSERT INTO `ohrm_module` (`name`, `status`) VALUES ('orgChart', 1);  
      
SET @module_id := (SELECT LAST_INSERT_ID());  
      
INSERT INTO ohrm_screen (`name`, `module_id`, `action_url`) VALUES  
('Config', @module_id, 'configReportingMethod');  
SET @config_screen_id := (SELECT LAST_INSERT_ID());  

INSERT INTO ohrm_screen (`name`, `module_id`, `action_url`) VALUES  
('Define Position', @module_id, 'defineJobTitleHierarchy');  
SET @position_screen_id := (SELECT LAST_INSERT_ID());

INSERT INTO ohrm_screen (`name`, `module_id`, `action_url`) VALUES  
('View', @module_id, 'orgchartView');  
SET @view_screen_id := (SELECT LAST_INSERT_ID());

SET @more_menu_id := (SELECT id FROM ohrm_menu_item where menu_title = 'More');

INSERT INTO ohrm_menu_item (`menu_title`, `screen_id`, `parent_id`, `level`, `order_hint`, `url_extras`, `status`) VALUES  
('Organization Chart', @view_screen_id, @more_menu_id, 2, 1000, '', 1);

SET @orgChart_menu_id := (SELECT LAST_INSERT_ID());
      
INSERT INTO ohrm_menu_item (`menu_title`, `screen_id`, `parent_id`, `level`, `order_hint`, `url_extras`, `status`) VALUES  
('Config', @config_screen_id, @orgChart_menu_id, 3, 100 , '', 1);
      
INSERT INTO ohrm_user_role_screen (user_role_id, screen_id, can_read, can_create, can_update, can_delete) VALUES  
(@admin_role_id, @config_screen_id, 1, 0, 0, 0),
(@supervisor_role_id, @config_screen_id, 0, 0, 0, 0),
(@ess_role_id, @config_screen_id, 0, 0, 0, 0);

INSERT INTO ohrm_menu_item (`menu_title`, `screen_id`, `parent_id`, `level`, `order_hint`, `url_extras`, `status`) VALUES  
('Define Position', @position_screen_id, @orgChart_menu_id, 3, 101 , '', 1);
      
INSERT INTO ohrm_user_role_screen (user_role_id, screen_id, can_read, can_create, can_update, can_delete) VALUES  
(@admin_role_id, @position_screen_id, 1, 0, 0, 0),
(@supervisor_role_id, @position_screen_id, 0, 0, 0, 0),
(@ess_role_id, @position_screen_id, 0, 0, 0, 0);

INSERT INTO ohrm_menu_item (`menu_title`, `screen_id`, `parent_id`, `level`, `order_hint`, `url_extras`, `status`) VALUES  
('View', @view_screen_id, @orgChart_menu_id, 3, 102 , '', 1);
      
INSERT INTO ohrm_user_role_screen (user_role_id, screen_id, can_read, can_create, can_update, can_delete) VALUES  
(@admin_role_id, @view_screen_id, 1, 0, 0, 0),
(@supervisor_role_id, @view_screen_id, 1, 0, 0, 0),
(@ess_role_id, @view_screen_id, 1, 0, 0, 0);
