INSERT INTO ohrm_requestdesk_request_type_template (`name`, `processor_class`, `template`, `approval_mandatory`, `status`) VALUES
 ('Hiring Requisition', 'RequestDeskHiringRequisitionRequestProcessor','{
  "meta": {
    "terminalHandler": "RequestDeskHiringRequisitionTemplateTerminalHandler",
    "maximumApprovalLevels": 5,
    "enableSubmitForOther": false
  },
  "formData": {
    "sections": [{
      "name": "Extra Custom Fields",
      "displayOrder": 1,
      "isCustomizable": true,
      "defaultFields": []
    },{
      "name": "Vacancy Details",
      "displayOrder": 2,
      "isCustomizable": false,
      "defaultFields": [
        {
          "fieldType": "Text",
          "name": "Vacancy Name",
          "otherData": {
            "length": 100
          },
          "extraData": "",
          "mandatory": true,
          "deletable": false,
          "editable": false
        },
        {
          "fieldType": "Advance Type",
          "name": "Job Title",
          "extraData": "",
          "mandatory": true,
          "deletable": false,
          "editable": false,
          "advancedTypeMap": "Job Title"
        },
        {
          "fieldType": "Advance Type",
          "name": "Location",
          "extraData": "",
          "mandatory": true,
          "deletable": false,
          "editable": false,
          "advancedTypeMap": "Location"
        },
        {
          "fieldType": "Advance Type",
          "name": "Sub Unit",
          "extraData": "",
          "mandatory": false,
          "deletable": false,
          "editable": false,
          "advancedTypeMap": "Sub Unit"
        },
        {
          "fieldType": "Advance Type",
          "name": "Hiring Managers",
          "extraData": "",
          "mandatory": true,
          "deletable": false,
          "editable": false,
          "advancedTypeMap": "Employee Multiple Select"
        },
        {
          "fieldType": "Number",
          "name": "No. of Positions",
          "otherData": {
            "maximum": 1000,
            "exclusiveMaximum": 1000
          },
          "extraData": "",
          "mandatory": false,
          "deletable": false,
          "editable": false
        }
      ]
    }]

  }
}
', 1, 1);

SET @module_id := (SELECT `id` FROM `ohrm_module` WHERE name = 'Request Desk');

INSERT INTO `ohrm_screen` (`name`, `module_id`, `action_url`) VALUES
( 'My Hiring Requisition', @module_id, 'viewMyHiringRequisitions'),
( 'Employee Hiring Requisition', @module_id, 'viewEmployeeHiringRequisitions');

SET @my_hiring_requisitions_screen_id :=(SELECT id from ohrm_screen WHERE action_url = 'viewMyHiringRequisitions');
SET @employee_hiring_requisitions_screen_id :=(SELECT id from ohrm_screen WHERE action_url = 'viewEmployeeHiringRequisitions');

SET @admin_id := (SELECT id FROM ohrm_user_role where name = 'Admin');
SET @sup_id := (SELECT id FROM ohrm_user_role where name = 'Supervisor');
SET @ess_id := (SELECT id FROM ohrm_user_role where name = 'ESS');
SET @requester_id := (SELECT id FROM ohrm_user_role where name = 'Requester');
SET @request_owner_id := (SELECT id FROM ohrm_user_role where name = 'RequestOwner');
SET @request_approver_id := (SELECT id FROM ohrm_user_role where name = 'RequestApprover');

INSERT INTO ohrm_user_role_screen (user_role_id, screen_id, can_read, can_create, can_update, can_delete) VALUES
(@requester_id, @my_hiring_requisitions_screen_id, 1, 1, 1, 1),
(@admin_id, @employee_hiring_requisitions_screen_id, 1, 1, 1, 1),
(@request_owner_id, @employee_hiring_requisitions_screen_id, 1, 1, 1, 1),
(@request_approver_id, @employee_hiring_requisitions_screen_id, 1, 1, 1, 1);

SET @my_requests_data_group_id := (SELECT id from ohrm_data_group WHERE name = 'my_requests');
SET @employee_requests_data_group_id := (SELECT id from ohrm_data_group WHERE name = 'employee_requests');

SET @request_desk_employee_requests_menu_id := (SELECT id from ohrm_menu_item WHERE menu_title = 'Employee Requests');
SET @request_desk_my_requests_menu_id := (SELECT id from ohrm_menu_item WHERE menu_title = 'My Requests');


INSERT INTO `ohrm_menu_item` (`menu_title`, `screen_id`,`parent_id`, `level`, `order_hint`,  `url_extras`,`status`, `uisref`) VALUES
('My Hiring Requisitions', @my_hiring_requisitions_screen_id,  @request_desk_my_requests_menu_id, '4', '800', null, '1', 'help_desk.my_hiring_requisitions');
INSERT INTO `ohrm_menu_item` (`menu_title`, `screen_id`,`parent_id`, `level`, `order_hint`,  `url_extras`,`status`, `uisref`) VALUES
('Employee Hiring Requisitions', @employee_hiring_requisitions_screen_id,  @request_desk_employee_requests_menu_id, '4', '600', null, '1', 'help_desk.employee_hiring_requisitions');

INSERT INTO `ohrm_data_group_screen`(`data_group_id`, `screen_id`, `permission`, `self`) VALUES
(@my_requests_data_group_id, @my_hiring_requisitions_screen_id, 1, 0),
(@employee_requests_data_group_id, @employee_hiring_requisitions_screen_id, 1, 0);

# list fields configuration
INSERT INTO ohrm_data_list (`name`, `meta_data`)
VALUES
('requestDeskEmployeeHiringRequisitionsList', '{"listFields":{"requestId":"requestId","requestTitle":"requestTitle","requestStatus":"requestStatus","pendingWith":"pendingWith","priority":"priority","requester":"requester","submittedDate":"submittedDate","vacancy":"vacancy","jobTitle":"jobTitle","location":"location","numberOfPositions":"numberOfPositions","resolutionDate":"resolutionDate"},"availableFields":{"requestId":"Request ID","requestTitle":"Request Title","requestStatus":"Request Status","pendingWith":"Pending With","priority":"Priority","requester":"Requester","requestType":"Request Type","requestOwner":"Request Owner","vacancy":"Vacancy","jobTitle":"Job Title","subUnit":"Sub Unit","location":"Location","hiringManagers":"Hiring Managers","numberOfPositions":"Number of Positions","submittedDate":"Submitted Date","resolutionDate":"Resolution Date"},"defaultFields":["pendingWith","vacancy","location","jobTitle","numberOfPositions","resolutionDate"],"mandatoryFields":["requestId","requestTitle","requestStatus","priority","requester","submittedDate"]}'),
('requestDeskMyHiringRequisitionsList', '{"listFields":{"requestId":"requestId","requestTitle":"requestTitle","requestStatus":"requestStatus","pendingWith":"pendingWith","priority":"priority","submittedDate":"submittedDate","vacancy":"vacancy","jobTitle":"jobTitle","location":"location","numberOfPositions":"numberOfPositions","resolutionDate":"resolutionDate"},"availableFields":{"requestId":"Request ID","requestTitle":"Request Title","requestStatus":"Request Status","pendingWith":"Pending With","priority":"Priority","requestType":"Request Type","requestOwner":"Request Owner","vacancy":"Vacancy","jobTitle":"Job Title","subUnit":"Sub Unit","location":"Location","hiringManagers":"Hiring Managers","numberOfPositions":"Number of Positions","submittedDate":"Submitted Date","resolutionDate":"Resolution Date"},"defaultFields":["pendingWith","vacancy","location","jobTitle","numberOfPositions","resolutionDate"],"mandatoryFields":["requestId","requestTitle","requestStatus","priority","submittedDate"]}');
