 CREATE TABLE `tbl_project_plan_data` (
  `id` int(11) NOT NULL,
  `project_id` int(11) NOT NULL,
  `wcif_alignment` varchar(500) NOT NULL,
  `sector_priority_term` varchar(255) NOT NULL,
  `start_date_target` date DEFAULT NULL,
  `end_date_target` date DEFAULT NULL,
  `progress_target` decimal(5,2) DEFAULT 0.00,
  `target` varchar(100) DEFAULT NULL,
  `start_date` date DEFAULT NULL,
  `end_date` date DEFAULT NULL,
  `progress` decimal(5,2) DEFAULT 0.00,
  `capex_original` decimal(15,2) DEFAULT 0.00,
  `opex_original` decimal(15,2) DEFAULT 0.00,
  `total_budget` decimal(15,2) DEFAULT 0.00,
  `capex_committed` decimal(15,2) DEFAULT 0.00,
  `opex_committed` decimal(15,2) DEFAULT 0.00,
  `total_committed` decimal(15,2) DEFAULT 0.00,
  `invoiced` decimal(15,2) DEFAULT 0.00,
  `capex_additional` decimal(15,2) DEFAULT 0.00,
  `opex_additional` decimal(15,2) DEFAULT 0.00,
  `total_additional` decimal(15,2) DEFAULT 0.00,
  `capex_adjusted` decimal(15,2) DEFAULT 0.00,
  `opex_adjusted` decimal(15,2) DEFAULT 0.00,
  `total_adjusted` decimal(15,2) DEFAULT 0.00,
  `created_at` datetime NOT NULL DEFAULT current_timestamp(),
  `updated_at` datetime NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
 
-- tbl_project_dept_phase_tasks DEV[DONE] QA[DONE]
ALTER TABLE `tbl_project_dept_phase_tasks` ADD `at_risk` ENUM('Yes','No') NOT NULL DEFAULT 'No' AFTER `status`;


--- DATE 26-11-2025 
-- Insert data into lookup DEV[DONE] QA[DONE]
INSERT INTO `tbl_lookup` (`keyid`, `dev_name`, `display_name`, `display_name_ml`, `description`, `is_active`, `translate`, `creation_date`, `created_by`, `updation_date`, `updated_by`) VALUES
(87, 'wcif_2050_strategic_alignment', 'WCIF 2050 Strategic Alignment', 'wcif-2050-strategic-alignment-ml', '', 1, 'No', '2025-11-19 11:30:00', 1, '2025-11-19 11:30:00', 1),
(88, 'project_tasks_status', 'Project Tasks Status', 'project-tasks-status-ml', '', 1, 'No', '2025-11-19 11:30:00', 1, '2025-11-19 11:30:00', 1);

-- Insert data into lookup_detail DEV[DONE] QA[DONE]
INSERT INTO `tbl_lookup_detail` (`optionid`, `keyid`, `data_value`, `data_key`, `display_name`, `display_name_ml`, `sequence`, `item_data`, `parent_datakey`, `is_active`, `creation_date`, `created_by`, `updation_date`, `updated_by`) VALUES
(842, 87, '1', 'wcif_2050_strategic_alignment_1', 'Spatial Transformation', 'spatial-transformation-ml', 1, '{\"description\":\"Promote equitable access to infrastructure across urban and rural areas \\n Support integrated human settlements and reduce spatial inequality\"}', '', 'active', '2025-11-19 10:30:00', 1, '2025-11-19 10:30:00', 1),
(843, 87, '2', 'wcif_2050_strategic_alignment_2', 'Economic Enablement', 'economic-enablement-ml', 2, '{\"description\":\"Invest in infrastructure that supports job creation, trade, and innovation \\n Prioritize logistics, agri-processing, and digital connectivity\"}', '', 'active', '2025-11-19 10:30:00', 1, '2025-11-19 10:30:00', 1),
(844, 87, '3', 'wcif_2050_strategic_alignment_3', 'Social Infrastructure', 'social-infrastructure-ml', 3, '{\"description\":\"Expand and modernize health, education, and community facilities \\n Ensure infrastructure supports dignity, safety, and well-being\"}', '', 'active', '2025-11-19 10:30:00', 1, '2025-11-19 10:30:00', 1),
(845, 87, '4', 'wcif_2050_strategic_alignment_4', 'Environmental Sustainability', 'environmental-sustainability-ml', 4, '{\"description\":\"Embed climate resilience and green infrastructure principles \\n Promote water conservation, renewable energy, and biodiversity protection\"}', '', 'active', '2025-11-19 10:30:00', 1, '2025-11-19 10:30:00', 1),
(846, 87, '5', 'wcif_2050_strategic_alignment_5', 'Governance and Delivery Capacity', 'governance-delivery-capacity-ml', 5, '{\"description\":\"Strengthen intergovernmental coordination and planning systems \\n Improve procurement, project management, and maintenance practices\"}', '', 'active', '2025-11-19 10:30:00', 1, '2025-11-19 10:30:00', 1),
(847, 87, '6', 'wcif_2050_strategic_alignment_6', 'Digital and Smart Infrastructure', 'digital-smart-infrastructure-ml', 6, '{\"description\":\"Enable digital transformation of public services \\n Invest in broadband, smart grids, and data-driven infrastructure systems\"}', '', 'active', '2025-11-19 10:30:00', 1, '2025-11-19 10:30:00', 1),
(848, 87, '7', 'wcif_2050_strategic_alignment_7', 'Resilience and Adaptability', 'resilience-adaptability-ml', 7, '{\"description\":\"Design infrastructure to withstand shocks (climate, economic, social) \\n Build flexibility into systems to respond to future needs\"}', '', 'active', '2025-11-19 10:30:00', 1, '2025-11-19 10:30:00', 1),
(849, 88, '1', 'project_tasks_status_1', 'Not Started', 'not-started-ml', 1, '{\"color\":\"#fff2cc\"}', '', 'active', '2025-11-19 10:30:00', 1, '2025-11-19 10:30:00', 1),
(850, 88, '2', 'project_tasks_status_2', 'In Progress', 'in-progress-ml', 2, '{\"color\":\"#92d050\"}', '', 'active', '2025-11-19 10:30:00', 1, '2025-11-19 10:30:00', 1),
(851, 88, '3', 'project_tasks_status_3', 'Complete', 'complete-ml', 3, '{\"color\":\"#03c25b\"}', '', 'active', '2025-11-19 10:30:00', 1, '2025-11-19 10:30:00', 1),
(852, 88, '4', 'project_tasks_status_4', 'Needs Review', 'needs-review-ml', 4, '{\"color\":\"#abefea\"}', '', 'active', '2025-11-19 10:30:00', 1, '2025-11-19 10:30:00', 1),
(853, 88, '5', 'project_tasks_status_5', 'Approved', 'approved-ml', 5, '{\"color\":\"#5ee9e7\"}', '', 'active', '2025-11-19 10:30:00', 1, '2025-11-19 10:30:00', 1),
(854, 88, '6', 'project_tasks_status_6', 'Overdue', 'overdue-ml', 6, '{\"color\":\"#ffd966\"}', '', 'active', '2025-11-19 10:30:00', 1, '2025-11-19 10:30:00', 1),
(855, 88, '7', 'project_tasks_status_7', 'On Hold', 'on-hold-ml', 7, '{\"color\":\"#d9d9d9\"}', '', 'active', '2025-11-19 10:30:00', 1, '2025-11-19 10:30:00', 1);

--
-- Table structure for table `tbl_role_master` DEV[DONE] QA[DONE]
--

CREATE TABLE `tbl_role_master` (
  `role_id` int(11) NOT NULL,
  `app_id` int(11) NOT NULL COMMENT 'FK tbl_apps',
  `role_type` enum('global','project') NOT NULL DEFAULT 'project',
  `role_name` varchar(255) NOT NULL,
  `role_short_name` varchar(200) NOT NULL,
  `isAdmin` int(11) NOT NULL DEFAULT 0,
  `isActive` int(11) NOT NULL DEFAULT 1,
  `creation_date` datetime DEFAULT current_timestamp(),
  `created_by` varchar(50) DEFAULT NULL,
  `updation_date` datetime DEFAULT NULL ON UPDATE current_timestamp(),
  `updated_by` varchar(50) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci;

--
-- Dumping data for table `tbl_role_master` DEV[DONE] QA[DONE]
--

INSERT INTO `tbl_role_master` (`role_id`, `app_id`, `role_type`, `role_name`, `role_short_name`, `isAdmin`, `isActive`, `creation_date`, `created_by`, `updation_date`, `updated_by`) VALUES
(1, 0, 'global', 'User', 'User', 0, 1, '2025-07-07 18:39:06', NULL, '2025-11-24 11:54:14', NULL),
(2, 2, 'global', 'Admin', 'Admin                  ', 1, 1, '2025-07-07 18:34:28', NULL, '2025-11-24 11:54:14', ''),
(3, 2, 'project', 'Evaluator', 'Evaluator', 0, 1, '2025-07-07 13:45:08', '1', '2025-07-09 17:29:07', NULL),
(4, 1, 'project', 'Approver-Level 1', 'Approver-Level 1', 0, 1, '2025-07-16 17:57:17', '1', NULL, NULL),
(5, 1, 'project', 'Approver-Level 2', 'Approver-Level 2', 0, 1, '2025-07-16 17:57:51', '1', NULL, NULL),
(6, 1, 'project', 'Approver-Level 3', 'Approver-Level 3', 0, 1, '2025-07-16 17:58:27', '1', '2025-07-16 18:00:08', NULL),
(7, 1, 'project', 'Project Manager', 'Project Manager', 0, 1, '2025-07-16 17:59:47', '1', '2025-11-24 11:16:06', NULL),
(8, 1, 'project', 'Agricultural Engineer', 'Agricultural Engineer', 0, 1, '2025-07-16 17:59:47', '1', '2025-11-24 11:16:06', NULL),
(9, 1, 'project', 'Agricultural Strategist', 'Agricultural Strategist', 0, 1, '2025-07-16 17:59:47', '1', '2025-11-24 11:16:06', NULL),
(10, 1, 'project', 'Agri-Economist', 'Agri-Economist', 0, 1, '2025-07-16 17:59:47', '1', '2025-11-24 11:16:06', NULL),
(11, 1, 'project', 'Agri-Tech Designer', 'Agri-Tech Designer', 0, 1, '2025-07-16 17:59:47', '1', '2025-11-24 11:16:06', NULL),
(12, 1, 'project', 'Agri-Tech Lead', 'Agri-Tech Lead', 0, 1, '2025-07-16 17:59:47', '1', '2025-11-24 11:16:06', NULL),
(13, 1, 'project', 'Architect', 'Architect', 0, 1, '2025-07-16 17:59:47', '1', '2025-11-24 11:16:06', NULL),
(14, 1, 'project', 'Community Liaison', 'Community Liaison', 0, 1, '2025-07-16 17:59:47', '1', '2025-11-24 11:16:06', NULL),
(15, 1, 'project', 'Community Planner', 'Community Planner', 0, 1, '2025-07-16 17:59:47', '1', '2025-11-24 11:16:06', NULL),
(16, 1, 'project', 'Construction Manager', 'Construction Manager', 0, 1, '2025-07-16 17:59:47', '1', '2025-11-24 11:16:06', NULL),
(17, 1, 'project', 'Crime Analyst', 'Crime Analyst', 0, 1, '2025-07-16 17:59:47', '1', '2025-11-24 11:16:06', NULL),
(18, 1, 'project', 'Cultural Strategist', 'Cultural Strategist', 0, 1, '2025-07-16 17:59:47', '1', '2025-11-24 11:16:06', NULL),
(19, 1, 'project', 'Data Analyst', 'Data Analyst', 0, 1, '2025-07-16 17:59:47', '1', '2025-11-24 11:16:06', NULL),
(20, 1, 'project', 'Development Coordinator', 'Development Coordinator', 0, 1, '2025-07-16 17:59:47', '1', '2025-11-24 11:16:06', NULL),
(21, 1, 'project', 'Digital Infrastructure Planner', 'Digital Infrastructure Planner', 0, 1, '2025-07-16 17:59:47', '1', '2025-11-24 11:16:06', NULL),
(22, 1, 'project', 'Digital Planner', 'Digital Planner', 0, 1, '2025-07-16 17:59:47', '1', '2025-11-24 11:16:06', NULL),
(23, 1, 'project', 'ECD Specialist', 'ECD Specialist', 0, 1, '2025-07-16 17:59:47', '1', '2025-11-24 11:16:06', NULL),
(24, 1, 'project', 'Education Economist', 'Education Economist', 0, 1, '2025-07-16 17:59:47', '1', '2025-11-24 11:16:06', NULL),
(25, 1, 'project', 'Education Planner', 'Education Planner', 0, 1, '2025-07-16 17:59:47', '1', '2025-11-24 11:16:06', NULL),
(26, 1, 'project', 'Education Strategist', 'Education Strategist', 0, 1, '2025-07-16 17:59:47', '1', '2025-11-24 11:16:06', NULL),
(27, 1, 'project', 'Engineers', 'Engineers', 0, 1, '2025-07-16 17:59:47', '1', '2025-11-24 11:16:06', NULL),
(28, 1, 'project', 'Engineers (Civil, Structural, etc.)', 'Engineers (Civil, Structural, etc.)', 0, 1, '2025-07-16 17:59:47', '1', '2025-11-24 11:16:06', NULL),
(29, 1, 'project', 'Environmental & Social Risk Assessor', 'Environmental & Social Risk Assessor', 0, 1, '2025-07-16 17:59:47', '1', '2025-11-24 11:16:06', NULL),
(30, 1, 'project', 'Environmental Assessor', 'Environmental Assessor', 0, 1, '2025-07-16 17:59:47', '1', '2025-11-24 11:16:06', NULL),
(31, 1, 'project', 'Environmental Risk Assessor', 'Environmental Risk Assessor', 0, 1, '2025-07-16 17:59:47', '1', '2025-11-24 11:16:06', NULL),
(32, 1, 'project', 'Extension Officer', 'Extension Officer', 0, 1, '2025-07-16 17:59:47', '1', '2025-11-24 11:16:06', NULL),
(33, 1, 'project', 'Facility Manager', 'Facility Manager', 0, 1, '2025-07-16 17:59:47', '1', '2025-11-24 11:16:06', NULL),
(34, 1, 'project', 'GIS Analyst', 'GIS Analyst', 0, 1, '2025-07-16 17:59:47', '1', '2025-11-24 11:16:06', NULL),
(35, 1, 'project', 'Health IT Specialist', 'Health IT Specialist', 0, 1, '2025-07-16 17:59:47', '1', '2025-11-24 11:16:06', NULL),
(36, 1, 'project', 'Health Planner', 'Health Planner', 0, 1, '2025-07-16 17:59:47', '1', '2025-11-24 11:16:06', NULL),
(37, 1, 'project', 'Heritage Advisor', 'Heritage Advisor', 0, 1, '2025-07-16 17:59:47', '1', '2025-11-24 11:16:06', NULL),
(38, 1, 'project', 'Housing Economist', 'Housing Economist', 0, 1, '2025-07-16 17:59:47', '1', '2025-11-24 11:16:06', NULL),
(39, 1, 'project', 'Housing Strategist', 'Housing Strategist', 0, 1, '2025-07-16 17:59:47', '1', '2025-11-24 11:16:06', NULL),
(40, 1, 'project', 'HR Strategist', 'HR Strategist', 0, 1, '2025-07-16 17:59:47', '1', '2025-11-24 11:16:06', NULL),
(41, 1, 'project', 'ICT Installer', 'ICT Installer', 0, 1, '2025-07-16 17:59:47', '1', '2025-11-24 11:16:06', NULL),
(42, 1, 'project', 'ICT Planner', 'ICT Planner', 0, 1, '2025-07-16 17:59:47', '1', '2025-11-24 11:16:06', NULL),
(43, 1, 'project', 'Inclusion Specialist', 'Inclusion Specialist', 0, 1, '2025-07-16 17:59:47', '1', '2025-11-24 11:16:06', NULL),
(44, 1, 'project', 'Infrastructure Manager', 'Infrastructure Manager', 0, 1, '2025-07-16 17:59:47', '1', '2025-11-24 11:16:06', NULL),
(45, 1, 'project', 'Infrastructure Strategist', 'Infrastructure Strategist', 0, 1, '2025-07-16 17:59:47', '1', '2025-11-24 11:16:06', NULL),
(46, 1, 'project', 'Innovation Lead', 'Innovation Lead', 0, 1, '2025-07-16 17:59:47', '1', '2025-11-24 11:16:06', NULL),
(47, 1, 'project', 'Irrigation Specialist', 'Irrigation Specialist', 0, 1, '2025-07-16 17:59:47', '1', '2025-11-24 11:16:06', NULL),
(48, 1, 'project', 'Legal Advisor', 'Legal Advisor', 0, 1, '2025-07-16 17:59:47', '1', '2025-11-24 11:16:06', NULL),
(49, 1, 'project', 'Mobility Strategist', 'Mobility Strategist', 0, 1, '2025-07-16 17:59:47', '1', '2025-11-24 11:16:06', NULL),
(50, 1, 'project', 'Monitoring Specialist', 'Monitoring Specialist', 0, 1, '2025-07-16 17:59:47', '1', '2025-11-24 11:16:06', NULL),
(51, 1, 'project', 'Operations Manager', 'Operations Manager', 0, 1, '2025-07-16 17:59:47', '1', '2025-11-24 11:16:06', NULL),
(52, 1, 'project', 'Operations Planner', 'Operations Planner', 0, 1, '2025-07-16 17:59:47', '1', '2025-11-24 11:16:06', NULL),
(53, 1, 'project', 'Procurement Officer', 'Procurement Officer', 0, 1, '2025-07-16 17:59:47', '1', '2025-11-24 11:16:06', NULL),
(55, 1, 'project', 'Quality Officer', 'Quality Officer', 0, 1, '2025-07-16 17:59:47', '1', '2025-11-24 11:16:06', NULL),
(56, 1, 'project', 'Resilience Specialist', 'Resilience Specialist', 0, 1, '2025-07-16 17:59:47', '1', '2025-11-24 11:16:06', NULL),
(57, 1, 'project', 'Safety Analyst', 'Safety Analyst', 0, 1, '2025-07-16 17:59:47', '1', '2025-11-24 11:16:06', NULL),
(58, 1, 'project', 'Safety Planner', 'Safety Planner', 0, 1, '2025-07-16 17:59:47', '1', '2025-11-24 11:16:06', NULL),
(59, 1, 'project', 'Safety Strategist', 'Safety Strategist', 0, 1, '2025-07-16 17:59:47', '1', '2025-11-24 11:16:06', NULL),
(60, 1, 'project', 'Security Engineer', 'Security Engineer', 0, 1, '2025-07-16 17:59:47', '1', '2025-11-24 11:16:06', NULL),
(61, 1, 'project', 'Security Installer', 'Security Installer', 0, 1, '2025-07-16 17:59:47', '1', '2025-11-24 11:16:06', NULL),
(62, 1, 'project', 'Skills Coordinator', 'Skills Coordinator', 0, 1, '2025-07-16 17:59:47', '1', '2025-11-24 11:16:06', NULL),
(63, 1, 'project', 'Skills Development Coordinator', 'Skills Development Coordinator', 0, 1, '2025-07-16 17:59:47', '1', '2025-11-24 11:16:06', NULL),
(64, 1, 'project', 'Smart Mobility Engineer', 'Smart Mobility Engineer', 0, 1, '2025-07-16 17:59:47', '1', '2025-11-24 11:16:06', NULL),
(65, 1, 'project', 'Smart Mobility Lead', 'Smart Mobility Lead', 0, 1, '2025-07-16 17:59:47', '1', '2025-11-24 11:16:06', NULL),
(66, 1, 'project', 'Social Impact Assessor', 'Social Impact Assessor', 0, 1, '2025-07-16 17:59:47', '1', '2025-11-24 11:16:06', NULL),
(67, 1, 'project', 'Social Infrastructure Strategist', 'Social Infrastructure Strategist', 0, 1, '2025-07-16 17:59:47', '1', '2025-11-24 11:16:06', NULL),
(68, 1, 'project', 'Social Officer', 'Social Officer', 0, 1, '2025-07-16 17:59:47', '1', '2025-11-24 11:16:06', NULL),
(69, 1, 'project', 'Social Services Planner', 'Social Services Planner', 0, 1, '2025-07-16 17:59:47', '1', '2025-11-24 11:16:06', NULL),
(70, 1, 'project', 'Stakeholder Engagement Lead', 'Stakeholder Engagement Lead', 0, 1, '2025-07-16 17:59:47', '1', '2025-11-24 11:16:06', NULL),
(71, 1, 'project', 'Sustainability Engineer', 'Sustainability Engineer', 0, 1, '2025-07-16 17:59:47', '1', '2025-11-24 11:16:06', NULL),
(72, 1, 'project', 'Sustainability Specialist', 'Sustainability Specialist', 0, 1, '2025-07-16 17:59:47', '1', '2025-11-24 11:16:06', NULL),
(73, 1, 'project', 'Traffic Modeller', 'Traffic Modeller', 0, 1, '2025-07-16 17:59:47', '1', '2025-11-24 11:16:06', NULL),
(74, 1, 'project', 'Training Coordinator', 'Training Coordinator', 0, 1, '2025-07-16 17:59:47', '1', '2025-11-24 11:16:06', NULL),
(75, 1, 'project', 'Transport Economist', 'Transport Economist', 0, 1, '2025-07-16 17:59:47', '1', '2025-11-24 11:16:06', NULL),
(76, 1, 'project', 'Transport Engineer', 'Transport Engineer', 0, 1, '2025-07-16 17:59:47', '1', '2025-11-24 11:16:06', NULL),
(77, 1, 'project', 'Transport Planner', 'Transport Planner', 0, 1, '2025-07-16 17:59:47', '1', '2025-11-24 11:16:06', NULL),
(78, 1, 'project', 'Urban Planner', 'Urban Planner', 0, 1, '2025-07-16 17:59:47', '1', '2025-11-24 11:16:06', NULL),
(79, 1, 'project', 'Workforce Planner', 'Workforce Planner', 0, 1, '2025-07-16 17:59:47', '1', '2025-11-24 11:16:06', NULL);

--
-- Triggers `tbl_role_master` DEV[DONE] QA[DONE]
--
DROP TRIGGER IF EXISTS `tr_role_right_association_delete`;
DELIMITER $$
CREATE TRIGGER `tr_role_right_association_delete` AFTER DELETE ON `tbl_role_master` FOR EACH ROW BEGIN

  delete from tbl_role_right_association where role_id=old.role_id;

END
$$
DELIMITER ;
DROP TRIGGER IF EXISTS `tr_role_right_association_insert`;
DELIMITER $$
CREATE TRIGGER `tr_role_right_association_insert` AFTER INSERT ON `tbl_role_master` FOR EACH ROW BEGIN



  INSERT INTO tbl_role_right_association(role_id, right_id, value)  

   SELECT new.role_id, b.right_id,-1 FROM tbl_right_master as b;



END
$$
DELIMITER ;

-- Indexes for table `tbl_role_master`  DEV[DONE] QA[DONE]
ALTER TABLE `tbl_role_master`
  ADD PRIMARY KEY (`role_id`),
  ADD UNIQUE KEY `app_id_role_name` (`app_id`,`role_name`);
COMMIT;

--
-- Table structure for table `tbl_departments` DEV[DONE] QA[DONE]
--

CREATE TABLE `tbl_departments` (
  `department_id` int(11) NOT NULL COMMENT 'PK tbl_departments',
  `department_name` varchar(255) NOT NULL,
  `department_short_name` varchar(200) NOT NULL,
  `descrpition` text DEFAULT NULL,
  `is_active` tinyint(4) NOT NULL DEFAULT 1 COMMENT '0=inactive, 1=active',
  `creation_date` datetime DEFAULT current_timestamp(),
  `created_by` int(11) DEFAULT NULL,
  `updation_date` datetime DEFAULT NULL ON UPDATE current_timestamp(),
  `updated_by` int(11) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

--
-- Dumping data for table `tbl_departments` DEV[DONE] QA[DONE]
--

INSERT INTO `tbl_departments` (`department_id`, `department_name`, `department_short_name`, `descrpition`, `is_active`, `creation_date`, `created_by`, `updation_date`, `updated_by`) VALUES
(1, 'Department of Agriculture', 'DOA', 'Supports farming, food security, and rural development.', 1, '2025-11-25 17:36:04', 1, '2025-11-24 14:39:17', 0),
(2, 'Department of Health', 'DOH', 'Provides public healthcare services and facilities.', 1, '2025-11-25 17:36:04', 1, '2025-11-24 14:39:32', 0),
(3, 'Department of Education', 'DOE', 'Manages schools, curriculum, and learning outcomes.', 1, '2025-11-25 17:36:04', 1, '2025-11-24 14:39:43', 0),
(4, 'Department Of Infrastructure', 'DOI', '\\N', 1, '2025-11-25 17:36:04', 1, '2025-08-25 04:22:58', 0),
(5, 'Provincial Treasury', '', 'Manages budgeting, financial planning, and accountability.', 1, '2025-11-25 17:36:04', 1, '2025-11-24 12:37:23', 0),
(6, 'Local Government', '', 'Supports municipalities and service delivery.', 1, '2025-11-25 17:36:04', 1, '2025-11-24 12:44:50', 0),
(7, 'Department of Mobility', 'DOM', 'Develops roads, public transport, and infrastructure.', 1, '2025-11-25 17:36:04', 1, '2025-11-24 12:51:14', 0),
(8, 'Government Motor Transport', 'GMT', '\\N', 1, '2025-11-25 17:36:04', 1, '2025-07-09 13:21:04', 0),
(9, 'Department of Premier', 'DoTP', 'Strategic leadership, policy coordination, and intergovernmental relations.', 1, '2025-11-25 17:36:04', 1, '2025-11-24 14:40:13', 0),
(10, 'Tourism, Environmental Affairs & Development Planning', 'DEDAT', 'Focuses on sustainability, land use, and climate resilience.', 1, '2025-11-25 17:36:04', 1, '2025-11-24 12:46:25', 0),
(11, 'Department of Social Development', 'DSD', 'Supports vulnerable groups and social welfare programs.', 1, '2025-11-25 17:36:04', 1, '2025-11-24 14:40:28', 0),
(12, 'Department of Human Settlements', 'DHS', 'Plans and delivers housing and urban development.', 1, '2025-11-25 17:36:04', 1, '2025-11-24 14:40:43', 0),
(13, 'Western Cape Liquor Authority', '', '\\N', 1, '2025-11-25 17:36:04', 1, '2025-07-09 13:23:29', 0),
(14, 'Department of Police Oversight & Community Safety', 'DPOCS', 'Monitors policing and promotes community safety.', 1, '2025-11-25 17:36:04', 1, '2025-11-24 14:41:01', 0),
(15, 'Department of Cultural Affairs and Sport', 'DCAS', 'Promotes arts, heritage, and sports development.', 1, '2025-11-25 17:36:04', 1, '2025-11-24 12:53:07', 0),
(16, 'Department of Environmental Affairs and DevelopmentÂ Planning', 'DOEADP', 'Focuses on sustainability, land use, and climate resilience.', 1, '2025-11-25 17:36:04', 1, '2025-11-24 14:41:45', 0),
(17, 'Western Cape Government', '', '\\N', 1, '2025-11-25 17:36:04', 1, '2025-08-25 13:23:48', 0),
(18, 'Other', 'Other', '\\N', 1, '2025-11-25 17:36:04', 1, '2025-11-25 12:22:06', 0),
(19, 'Private Sector', 'PS', '\\N', 1, '2025-11-25 17:36:04', 152, '2025-11-25 12:21:56', 0),
(20, 'Other_1', 'Other_1', '\\N', 1, '2025-11-25 17:36:04', 152, '2025-11-25 12:21:49', 0),
(21, 'Department of Economic Development and Tourism', 'DTI', '\\N', 1, '2025-11-25 17:36:04', 152, '2025-11-25 12:21:27', 0);

-- Indexes for table `tbl_departments` DEV[DONE] QA[DONE]
ALTER TABLE `tbl_departments`
  ADD PRIMARY KEY (`department_id`);
COMMIT;

--- Add Procedure DEV[DONE] QA[DONE]

DELIMITER $$

DROP PROCEDURE IF EXISTS clone_project_tasks_by_department $$
CREATE PROCEDURE clone_project_tasks_by_department(
    IN source_project_id INT,
    IN target_project_id INT,
    IN dept_id INT
 )
BEGIN
    DECLARE done INT DEFAULT 0;
    DECLARE src_id INT;
    DECLARE src_parent INT;
    DECLARE new_id INT;

    DECLARE cur CURSOR FOR
        SELECT id, parent_id
        FROM tbl_project_dept_phase_tasks
        WHERE project_id = source_project_id
          AND department_id = dept_id
        ORDER BY parent_id, id;

    DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = 1;

    -- mapping table 1
    DROP TEMPORARY TABLE IF EXISTS temp_task_map;
    CREATE TEMPORARY TABLE temp_task_map (
        old_id INT NOT NULL,
        new_id INT NOT NULL,
        parent_old_id INT DEFAULT 0
    ) ENGINE=MEMORY;

    OPEN cur;

    read_loop: LOOP
        FETCH cur INTO src_id, src_parent;
        IF done = 1 THEN
            LEAVE read_loop;
        END IF;

        INSERT INTO tbl_project_dept_phase_tasks (
            project_id,
            department_id,
            phase_id,
            task_name,
            parent_id,
            document_id,
            role_id,
            no_of_resources,
            allocated_budget,
            rate_per_hour,
            hours_of_work,
            type,
            start_date,
            end_date,
            progress,
            status,
            at_risk
        )
        SELECT
            target_project_id,
            department_id,
            phase_id,
            task_name,
            0,
            document_id,
            role_id,
            no_of_resources,
            allocated_budget,
            rate_per_hour,
            hours_of_work,
            type,
            start_date,
            end_date,
            progress,
            status,
            at_risk
        FROM tbl_project_dept_phase_tasks
        WHERE id = src_id
        LIMIT 1;

        SET new_id = LAST_INSERT_ID();

        INSERT INTO temp_task_map (old_id, new_id, parent_old_id)
        VALUES (src_id, new_id, src_parent);
    END LOOP;

    CLOSE cur;

    DROP TEMPORARY TABLE IF EXISTS temp_task_map_parent;
    CREATE TEMPORARY TABLE temp_task_map_parent AS
    SELECT * FROM temp_task_map;

    -- final update using two independent tables
    UPDATE tbl_project_dept_phase_tasks t
    JOIN temp_task_map m ON t.id = m.new_id
    LEFT JOIN temp_task_map_parent pm ON pm.old_id = m.parent_old_id
    SET t.parent_id = IFNULL(pm.new_id, 0)
    WHERE t.project_id = target_project_id
      AND t.department_id = dept_id;

    DROP TEMPORARY TABLE IF EXISTS temp_task_map;
    DROP TEMPORARY TABLE IF EXISTS temp_task_map_parent;

END $$
DELIMITER ;

-- Remove unwanted columns from tbl_project_stg5 table. DEV[DONE] QA[DONE]
ALTER TABLE `tbl_project_stg5`
  DROP `summary_of_preliminary_impacts_and_ranking`,
  DROP `summary_of_preliminary_impacts_and_ranking_motivation`,
  DROP `financial_feasibility_preferred_option`,
  DROP `financial_feasibility_preferred_option_motivation`;

-- Add new column to table tbl_project_stg5 DEV[DONE] QA[DONE]
ALTER TABLE `tbl_project_stg5` ADD `conclusion` TEXT NULL AFTER `site_description`;

-- Update tbl_project_dept_phase_tasks with new column duration DEV[DONE] QA[DONE]
ALTER TABLE `tbl_project_dept_phase_tasks` ADD `duration` BIGINT NOT NULL AFTER `hours_of_work`;
ALTER TABLE `tbl_project_dept_phase_tasks` ADD `created_by` INT NOT NULL AFTER `at_risk`;
INSERT INTO `tbl_categories` (`cat_id`, `cat_name`, `type`, `creation_date`, `created_by`, `updation_date`, `updated_by`) VALUES ('55', 'Project Planning', 'project', '2025-11-17 10:10:59', NULL, NULL, NULL)

--- DATE 27-11-2025 
-- Updated document_id column to support multiple file ids DEV[DONE] QA[DONE]
ALTER TABLE `tbl_project_dept_phase_tasks` CHANGE `document_id` `document_id` VARCHAR(100) NULL DEFAULT NULL;

-- Add new column to tbl_project_dept_phase_tasks DEV[DONE] QA[DONE]
ALTER TABLE `tbl_project_dept_phase_tasks` ADD `additional_budget` BIGINT NULL AFTER `allocated_budget`;

-- Updated table tbl_project_plan_data DEV[DONE] QA[DONE]
ALTER TABLE `tbl_project_plan_data`
	CHANGE COLUMN `wcif_alignment` `wcif_alignment` VARCHAR(500) NULL COLLATE 'utf8mb4_general_ci' AFTER `project_id`,
	CHANGE COLUMN `sector_priority_term` `sector_priority_term` VARCHAR(255) NULL COLLATE 'utf8mb4_general_ci' AFTER `wcif_alignment`;

-- Add primary key as id in table tbl_project_plan_data DEV[DONE] QA[DONE]
ALTER TABLE `tbl_project_plan_data` CHANGE `id` `id` INT(11) NOT NULL AUTO_INCREMENT, add PRIMARY KEY (`id`);

-- Update datatype in table: tbl_project_plan_data DEV[DONE] QA[DONE]
ALTER TABLE `tbl_project_plan_data` CHANGE `start_date_target` `start_date_target` VARCHAR(50) NULL DEFAULT NULL;
ALTER TABLE `tbl_project_plan_data` CHANGE `end_date_target` `end_date_target` VARCHAR(50) NULL DEFAULT NULL;
ALTER TABLE `tbl_project_plan_data` CHANGE `progress_target` `progress_target` VARCHAR(50) NULL DEFAULT NULL;

-- update weight 16 for each question with question ID 8
UPDATE tbl_project_questions 
SET weight = 16
WHERE q_id = 8;

-- update weight 20 for each question with question ID 9
UPDATE tbl_project_questions 
SET weight = 20
WHERE q_id = 9;

-- update weighted_score by new formula for old data
UPDATE tbl_project_questions
SET weighted_score = ROUND((score/5*weight),2);

-- update eval_percentage for each project which is completed (project_status_2)
UPDATE tbl_projects p
SET p.eval_percentage = IFNULL((
        SELECT SUM(q.weighted_score) / 5
        FROM tbl_project_questions q
        WHERE q.project_id = p.project_id
    ), 0.00)
WHERE p.eval_status = 'project_status_2';

-- DATE 27-11-2025 Updating existing geographic coverage updated tables DEV[DONE] QA[DONE]
--SOURCE FILE geographic-coverage-updated-tables.sql

-- Update tbl_projects from staging table DEV[Done] QA[DONE]
UPDATE tbl_projects p
JOIN tbl_project_stg0 s ON p.project_id = s.project_id
SET
    p.name = s.name,
    p.desc = s.desc,
    p.sector_id = s.sector_id,
    p.sub_sector_id = s.sub_sector_id,
    p.location_id = s.location_id,
    p.department_id = s.department_id,
    p.project_owner = s.project_owner,
    p.project_manager = s.project_manager;

ALTER TABLE `tbl_project_stg0`
DROP COLUMN `name`,
DROP COLUMN `desc`,
DROP COLUMN `sector_id`,
DROP COLUMN `sub_sector_id`,
DROP COLUMN `location_id`,
DROP COLUMN `department_id`,
DROP COLUMN `project_owner`,
DROP COLUMN `project_manager`;

-- DATE 28-11-2025 update tbl_project_dept_phase_tasks DEV[DONE] QA[DONE]

ALTER TABLE `tbl_project_dept_phase_tasks` CHANGE `duration` `duration` BIGINT(20) NULL DEFAULT NULL;
ALTER TABLE `tbl_project_dept_phase_tasks` CHANGE `created_by` `created_by` INT(11) NULL DEFAULT NULL;

ALTER TABLE `tbl_project_plan_data` CHANGE `start_date_target` `start_date_target` VARCHAR(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT 'Q';
ALTER TABLE `tbl_project_plan_data` CHANGE `end_date_target` `end_date_target` VARCHAR(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT 'Q';
ALTER TABLE `tbl_project_plan_data` CHANGE `progress_target` `progress_target` VARCHAR(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT 'R';
ALTER TABLE `tbl_project_plan_data` CHANGE `target` `target` VARCHAR(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT 'X';

-- Updated maxid as after adding lookups this was not updated and faced error in UI|
-- Updated table maxids where table name = tbl_lookup_detail
UPDATE `tbl_maxids` SET `max_id`=855 WHERE `id`=4;

-- DATE 28-11-2025 Create Project - Enhancements

CREATE TABLE `tbl_sa_provinces` (
    `province_id` INT AUTO_INCREMENT PRIMARY KEY,
    `province_name` VARCHAR(100) NOT NULL,
    `short_name` VARCHAR(10) NOT NULL,
    `creation_date` timestamp NULL DEFAULT current_timestamp(),
    `created_by` INT(11) NULL DEFAULT NULL,
    `updation_date` timestamp NULL DEFAULT NULL ON UPDATE current_timestamp(),    
    `updated_by` INT(11) NULL DEFAULT NULL,
);

INSERT INTO `tbl_sa_provinces` (`province_name`, `short_name`) VALUES
('Eastern Cape', 'EC'),
('Free State', 'FS'),
('Gauteng', 'GP'),
('KwaZulu-Natal', 'KZN'),
('Limpopo', 'LP'),
('Mpumalanga', 'MP'),
('Northern Cape', 'NC'),
('North West', 'NW'),
('Western Cape', 'WC');

ALTER TABLE `tbl_projects` ADD `short_name` VARCHAR(50) NOT NULL AFTER `name`;
ALTER TABLE `tbl_projects` ADD `province_id` INT NOT NULL DEFAULT '9' AFTER `desc`;
ALTER TABLE `tbl_projects` ADD `project_ref_no` VARCHAR(50) NULL DEFAULT NULL AFTER `short_name`;

-- DATE 03-12-2025 Update priority_id in tbl_projects
UPDATE tbl_projects
SET priority_id = CASE priority_id
    WHEN 'project_priority_1' THEN 'wcg_sector_priorities_1'
    WHEN 'project_priority_2' THEN 'wcg_sector_priorities_2'
    WHEN 'project_priority_3' THEN 'wcg_sector_priorities_3'
END
WHERE priority_id IN (
    'project_priority_1',
    'project_priority_2',
    'project_priority_3'
);


DROP TRIGGER IF EXISTS tbl_project_stages_after_insert;
DELIMITER $$

CREATE TRIGGER tbl_project_stages_after_insert
AFTER INSERT ON tbl_projects
FOR EACH ROW
BEGIN
  -- Insert tbl_project_stg0
  INSERT INTO `tbl_project_stg0` (`project_id`, `background_justification`, `scope_of_work`, `ballpark_project_cost`, `estimated_project_duration_years`, `estimated_project_duration_months`, `estimated_project_start_date`, `is_active`, `creation_date`, `created_by`, `updation_date`, `updated_by`)
  VALUES (NEW.project_id, '', '', NULL, NULL, NULL, NULL, '1', NOW(), NEW.created_by, NULL, NULL);
  
  -- Insert tbl_project_users
  -- INSERT INTO `tbl_project_users` (`project_id`, `user_id`, `role_id`, `total_questions`, `attempted_questions`, `eval_status`, `project_rights`, `creation_date`, `created_by`)
  -- VALUES (NEW.project_id, NEW.created_by, 'project_team_roles_2', 0, 0, 'pending', 'edit', NOW(), NEW.created_by);
 
  IF NEW.project_manager!=NEW.project_owner THEN
    -- Insert project_owner as project_owner in tbl_project_users
    INSERT INTO `tbl_project_users` (`project_id`, `user_id`, `role_id`, `total_questions`, `attempted_questions`, `eval_status`, `project_rights`, `creation_date`, `created_by`)
    VALUES (NEW.project_id, NEW.project_owner, 'project_team_roles_3', 0, 0, 'pending', 'edit', NOW(), NEW.created_by);
  END IF;
  -- Insert project_manager as project_manager in tbl_project_users
  INSERT INTO `tbl_project_users` (`project_id`, `user_id`, `role_id`, `total_questions`, `attempted_questions`, `eval_status`, `project_rights`, `creation_date`, `created_by`)
  VALUES (NEW.project_id, NEW.project_manager, 'project_team_roles_4', 0, 0, 'pending', 'edit', NOW(), NEW.created_by);

  -- Insert tbl_project_additonal_stages add intermediate/additional checks for stages with user_id as 0. 
  INSERT INTO tbl_project_additonal_stages (additional_check_datakey,project_id,stage_id,user_id)
  values ('project_additional_stages_1',NEW.project_id,'project_stage_1','0'),
  ('project_additional_stages_2',NEW.project_id,'project_stage_2','0');
 
-- Insert project_stage_0
  INSERT INTO tbl_project_stages (
    project_stage_id, project_id, stage_id, stage_status, active_gate, created_by, prerequisites_stages, creation_date
  )
  SELECT IFNULL(MAX(project_stage_id), 0) + 1,
         NEW.project_id,
         'project_stage_0',
         'stage_status_1',
         1,
         NEW.created_by,
         '',
         NOW()
  FROM tbl_project_stages;
 
  -- Insert project_stage_1 to project_stage_9
  INSERT INTO tbl_project_stages(project_stage_id, project_id, stage_id, stage_status, active_gate, additional_check, created_by, prerequisites_stages, creation_date)
  SELECT IFNULL(MAX(project_stage_id), 0) + 1, NEW.project_id, 'project_stage_1', 'stage_status_1', 0, 'na', NEW.created_by, 'project_stage_0', NOW() FROM tbl_project_stages;
  
  INSERT INTO tbl_project_stages(project_stage_id, project_id, stage_id, stage_status, active_gate, created_by, prerequisites_stages, creation_date)
  SELECT IFNULL(MAX(project_stage_id), 0) + 1, NEW.project_id, 'project_stage_2', 'stage_status_1', 0, NEW.created_by, 'project_stage_1', NOW() FROM tbl_project_stages;
  
  INSERT INTO tbl_project_stages(project_stage_id, project_id, stage_id, stage_status, active_gate, additional_check, created_by, prerequisites_stages, creation_date)
  SELECT IFNULL(MAX(project_stage_id), 0) + 1, NEW.project_id, 'project_stage_3', 'stage_status_1', 0, 'na', NEW.created_by, 'project_stage_2', NOW() FROM tbl_project_stages;
  
  INSERT INTO tbl_project_stages(project_stage_id, project_id, stage_id, stage_status, active_gate, created_by, prerequisites_stages, creation_date)
  SELECT IFNULL(MAX(project_stage_id), 0) + 1, NEW.project_id, 'project_stage_4', 'stage_status_1', 0, NEW.created_by, 'project_stage_3', NOW() FROM tbl_project_stages;
  
  INSERT INTO tbl_project_stages(project_stage_id, project_id, stage_id, stage_status, active_gate, created_by, prerequisites_stages, creation_date)
  SELECT IFNULL(MAX(project_stage_id), 0) + 1, NEW.project_id, 'project_stage_5', 'stage_status_1', 0, NEW.created_by, 'project_stage_4', NOW() FROM tbl_project_stages;
  
  INSERT INTO tbl_project_stages(project_stage_id, project_id, stage_id, stage_status, active_gate, created_by, prerequisites_stages, creation_date)
  SELECT IFNULL(MAX(project_stage_id), 0) + 1, NEW.project_id, 'project_stage_6', 'stage_status_1', 0, NEW.created_by, 'project_stage_5', NOW() FROM tbl_project_stages;
  
  INSERT INTO tbl_project_stages(project_stage_id, project_id, stage_id, stage_status, active_gate, created_by, prerequisites_stages, creation_date)
  SELECT IFNULL(MAX(project_stage_id), 0) + 1, NEW.project_id, 'project_stage_7', 'stage_status_1', 0, NEW.created_by, 'project_stage_6', NOW() FROM tbl_project_stages;
  
  INSERT INTO tbl_project_stages(project_stage_id, project_id, stage_id, stage_status, active_gate, created_by, prerequisites_stages, creation_date)
  SELECT IFNULL(MAX(project_stage_id), 0) + 1, NEW.project_id, 'project_stage_8', 'stage_status_1', 0, NEW.created_by, 'project_stage_7', NOW() FROM tbl_project_stages;
  
  INSERT INTO tbl_project_stages(project_stage_id, project_id, stage_id, stage_status, active_gate, created_by, prerequisites_stages, creation_date)
  SELECT IFNULL(MAX(project_stage_id), 0) + 1, NEW.project_id, 'project_stage_9', 'stage_status_1', 0, NEW.created_by, 'project_stage_8', NOW() FROM tbl_project_stages;
 
END$$
DELIMITER ;

-- DATE 03-12-2025 Create Trigger for project_ref_no DEV[DONE] QA[DONE]
DROP TRIGGER IF EXISTS trg_project_before_insert;
DELIMITER $$

CREATE TRIGGER trg_project_before_insert
BEFORE INSERT ON tbl_projects
FOR EACH ROW
BEGIN
    DECLARE deptShort VARCHAR(50);
    DECLARE sectorShort VARCHAR(50);

    -- Get department short name
    SELECT department_short_name 
    INTO deptShort 
    FROM tbl_departments 
    WHERE department_id = NEW.department_id;

    -- Get sector short name (uppercase + no space)
    SELECT UPPER(REPLACE(name, ' ', ''))
    INTO sectorShort
    FROM tbl_sectors
    WHERE sector_id = NEW.sector_id;

    SET NEW.project_ref_no = CONCAT(
        NEW.short_name, '/',
        deptShort, '/',
        sectorShort, '/',
        NEW.project_id
    );
END$$

DELIMITER ;

DROP TRIGGER IF EXISTS trg_projects_before_update;
DELIMITER $$

CREATE TRIGGER trg_projects_before_update
BEFORE UPDATE ON tbl_projects
FOR EACH ROW
BEGIN
    DECLARE projShort VARCHAR(50);
    DECLARE deptShort VARCHAR(50);
    DECLARE sectorShort VARCHAR(50);

    -- Only regenerate if related fields changed
    IF NEW.short_name <> OLD.short_name
       OR NEW.department_id <> OLD.department_id
       OR NEW.sector_id <> OLD.sector_id THEN

        SELECT department_short_name 
        INTO deptShort 
        FROM tbl_departments 
        WHERE department_id = NEW.department_id;

        SELECT UPPER(REPLACE(name, ' ', ''))
        INTO sectorShort
        FROM tbl_sectors
        WHERE sector_id = NEW.sector_id;

        SET projShort = UPPER(NEW.short_name);

        SET NEW.project_ref_no = CONCAT(
            projShort, '/',
            deptShort, '/',
            sectorShort, '/',
            NEW.project_id
        );
    END IF;

END$$
DELIMITER ;
-- DATE 29-11-2025

-- RISK MANAGEMENT SQL UPDATES

-- tbl_lookup and tbl_lookup_detail updates DEV[DONE] QA[DONE]

INSERT INTO `tbl_lookup`
(`keyid`, `dev_name`, `display_name`, `display_name_ml`, `description`, `is_active`, `translate`, `creation_date`, `created_by`, `updation_date`, `updated_by`)
VALUES
(89, 'risk_probability', 'Risk Probability', 'risk-probability-ml', '', 1, 'No', '2025-11-29 11:30:00', 1, '2025-11-29 11:30:00', 1);



INSERT INTO `tbl_lookup_detail`
(`optionid`, `keyid`, `data_value`, `data_key`, `display_name`, `display_name_ml`, `sequence`, `item_data`, `parent_datakey`, `is_active`, `creation_date`, `created_by`, `updation_date`, `updated_by`)
VALUES
(865, 89, 1, 'risk_probability_1', 'Very Low', 'risk-probability-1-ml', 1, '{"description":"Rare occurrence; less than 10% chance"}', '', 1, '2025-11-29 11:30:00', 1, '2025-11-29 11:30:00', 1);

INSERT INTO `tbl_lookup_detail`
(`optionid`, `keyid`, `data_value`, `data_key`, `display_name`, `display_name_ml`, `sequence`, `item_data`, `parent_datakey`, `is_active`, `creation_date`, `created_by`, `updation_date`, `updated_by`)
VALUES
(866, 89, 2, 'risk_probability_2', 'Low', 'risk-probability-2-ml', 2, '{"description":"Unlikely; 10–30% chance"}', '', 1, '2025-11-29 11:30:00', 1, '2025-11-29 11:30:00', 1);

INSERT INTO `tbl_lookup_detail`
(`optionid`, `keyid`, `data_value`, `data_key`, `display_name`, `display_name_ml`, `sequence`, `item_data`, `parent_datakey`, `is_active`, `creation_date`, `created_by`, `updation_date`, `updated_by`)
VALUES
(867, 89, 3, 'risk_probability_3', 'Medium', 'risk-probability-3-ml', 3, '{"description":"Possible; 30–60% chance"}', '', 1, '2025-11-29 11:30:00', 1, '2025-11-29 11:30:00', 1);

INSERT INTO `tbl_lookup_detail`
(`optionid`, `keyid`, `data_value`, `data_key`, `display_name`, `display_name_ml`, `sequence`, `item_data`, `parent_datakey`, `is_active`, `creation_date`, `created_by`, `updation_date`, `updated_by`)
VALUES
(868, 89, 4, 'risk_probability_4', 'High', 'risk-probability-4-ml', 4, '{"description":"Likely; 60–80% chance"}', '', 1, '2025-11-29 11:30:00', 1, '2025-11-29 11:30:00', 1);

INSERT INTO `tbl_lookup_detail`
(`optionid`, `keyid`, `data_value`, `data_key`, `display_name`, `display_name_ml`, `sequence`, `item_data`, `parent_datakey`, `is_active`, `creation_date`, `created_by`, `updation_date`, `updated_by`)
VALUES
(869, 89, 5, 'risk_probability_5', 'Very High', 'risk-probability-5-ml', 5, '{"description":"Almost certain; over 80% chance"}', '', 1, '2025-11-29 11:30:00', 1, '2025-11-29 11:30:00', 1);



INSERT INTO `tbl_lookup`
(`keyid`, `dev_name`, `display_name`, `display_name_ml`, `description`, `is_active`, `translate`, `creation_date`, `created_by`, `updation_date`, `updated_by`)
VALUES
(90, 'risk_impact', 'Risk Impact', 'risk-impact-ml', '', 1, 'No', '2025-11-29 11:30:00', 1, '2025-11-29 11:30:00', 1);

INSERT INTO `tbl_lookup_detail`
(`optionid`, `keyid`, `data_value`, `data_key`, `display_name`, `display_name_ml`, `sequence`, `item_data`, `parent_datakey`, `is_active`, `creation_date`, `created_by`, `updation_date`, `updated_by`)
VALUES
(870, 90, 1, 'risk_impact_1', 'Insignificant', 'risk-impact-1-ml', 1, '{"description":"Minimal effect; negligible cost or delay"}', '', 1, '2025-11-29 11:30:00', 1, '2025-11-29 11:30:00', 1);

INSERT INTO `tbl_lookup_detail`
(`optionid`, `keyid`, `data_value`, `data_key`, `display_name`, `display_name_ml`, `sequence`, `item_data`, `parent_datakey`, `is_active`, `creation_date`, `created_by`, `updation_date`, `updated_by`)
VALUES
(871, 90, 2, 'risk_impact_2', 'Minor', 'risk-impact-2-ml', 2, '{"description":"Small impact; slight cost increase or short delay"}', '', 1, '2025-11-29 11:30:00', 1, '2025-11-29 11:30:00', 1);


INSERT INTO `tbl_lookup_detail`
(`optionid`, `keyid`, `data_value`, `data_key`, `display_name`, `display_name_ml`, `sequence`, `item_data`, `parent_datakey`, `is_active`, `creation_date`, `created_by`, `updation_date`, `updated_by`)
VALUES
(872, 90, 3, 'risk_impact_3', 'Moderate', 'risk-impact-3-ml', 3, '{"description":"Noticeable impact; moderate cost or schedule disruption"}', '', 1, '2025-11-29 11:30:00', 1, '2025-11-29 11:30:00', 1);


INSERT INTO `tbl_lookup_detail`
(`optionid`, `keyid`, `data_value`, `data_key`, `display_name`, `display_name_ml`, `sequence`, `item_data`, `parent_datakey`, `is_active`, `creation_date`, `created_by`, `updation_date`, `updated_by`)
VALUES
(873, 90, 4, 'risk_impact_4', 'Major', 'risk-impact-4-ml', 4, '{"description":"Significant impact; high cost or long delay"}', '', 1, '2025-11-29 11:30:00', 1, '2025-11-29 11:30:00', 1);


INSERT INTO `tbl_lookup_detail`
(`optionid`, `keyid`, `data_value`, `data_key`, `display_name`, `display_name_ml`, `sequence`, `item_data`, `parent_datakey`, `is_active`, `creation_date`, `created_by`, `updation_date`, `updated_by`)
VALUES
(874, 90, 5, 'risk_impact_5', 'Critical', 'risk-impact-5-ml', 5, '{"description":"Severe impact; threatens project or organizational objectives"}', '', 1, '2025-11-29 11:30:00', 1, '2025-11-29 11:30:00', 1);


-- Add new table table tbl_project_risk_category  DEV[DONE] QA[DONE]

START TRANSACTION;

CREATE TABLE `tbl_project_risk_category` (
  `id` int(11) NOT NULL,
  `category_name` varchar(500) NOT NULL,
  `description` text DEFAULT NULL,
  `is_active` int(11) NOT NULL DEFAULT 1,

  `creation_date` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
  `created_by` INT(11) NULL,
  `updation_date` TIMESTAMP NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
  `updated_by` INT(11) NULL,

  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Dumping data for table `tbl_project_risk_category`  DEV[DONE] QA[DONE]
INSERT INTO `tbl_project_risk_category` 
(`id`, `category_name`, `description`, `is_active`)
VALUES
(1, 'Strategic and Governance Risks', 'These are high-level risks related to the project\'s alignment with government objectives, decision-making, and oversight.', 1),
(2, 'Financial and Economic Risks', 'These risks impact the project\'s budget, funding, and overall economic viability.', 1),
(3, 'Technical and Design Risks', 'These are risks inherent in the design, technology, and physical construction of the project.', 1),
(4, 'Operational and Implementation Risks', 'These risks arise during the procurement and construction phases of the project.', 1),
(5, 'Legal and Contractual Risks', 'These risks are associated with the contractual agreements governing the project.', 1),
(6, 'External and Force Majeure Risks', 'These are largely outside the direct control of the project team.', 1),
(7, 'Health, Safety, and Environmental (HSE) Risks', 'These are non-negotiable categories with zero-tolerance targets for the WCG.', 1);

COMMIT;


-- Add new table tbl_project_risks DEV[DONE] QA[DONE]
START TRANSACTION;

-- Table structure for table `tbl_project_risks` DEV[DONE] QA[DONE]

CREATE TABLE `tbl_project_risks` (
  `id` int(11) NOT NULL,
  `project_id` int(11) NOT NULL DEFAULT 0,
  `risk_cat_id` int(11) NOT NULL,
  `risk_name` varchar(500) NOT NULL,
  `description` text NOT NULL,
  `is_active` int(11) NOT NULL DEFAULT 1,

  `creation_date` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
  `created_by` INT(11) NULL,
  `updation_date` TIMESTAMP NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
  `updated_by` INT(11) NULL,

  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

COMMIT;

-- Dumping data for table `tbl_project_risks`DEV[DONE] QA[DONE]

INSERT INTO `tbl_project_risks`
(`id`, `project_id`, `risk_cat_id`, `risk_name`, `description`, `is_active`)
VALUES
(1, 0, 1, 'Project Justification & Alignment', 'The project is not aligned with provincial strategic goals (e.g., Provincial Strategic Plan), spatial development frameworks, or integrated development plans (IDPs).', 1),
(2, 0, 1, 'Stakeholder Management & Political Interference', 'Poor communication and engagement with communities, political stakeholders, or other government departments leading to delays, protests, or scope changes. This also includes undue political influence on ', 1),
(3, 0, 1, 'Governance & Accountability', 'Weak project steering committees, unclear roles and responsibilities, and lack of senior management oversight.', 1),
(4, 0, 1, 'Regulatory & Policy Compliance', 'Failure to comply with legislation such as the Municipal Finance Management Act (MFMA), Public Finance Management Act (PFMA), Broad-Based Black Economic Empowerment (B-BBEE) codes, and construction ', 1),
(5, 0, 2, 'Funding & Budgetary Constraints', 'Unreliable or insufficient funding streams, budget cuts, or delays in the release of funds from provincial or national treasury.', 1),
(6, 0, 2, 'Cost Overruns & Escalation', 'Inaccurate initial cost estimates, price inflation of materials (e.g., steel, cement), currency fluctuations affecting imported materials, and unforeseen ground conditions leading to increased costs.', 1),
(7, 0, 2, 'Economic Viability', 'The project fails to deliver the intended economic benefits (e.g., job creation, economic stimulation) or the operational costs become unsustainable for the department.', 1),
(8, 0, 3, 'Inadequate Site Investigation', 'Poor geotechnical studies leading to unexpected ground conditions, soil instability, or contamination, requiring expensive design changes.', 1),
(9, 0, 3, 'Design Errors & Omissions', 'Flaws, inconsistencies, or lack of detail in the design documents, leading to rework, delays, and claims during construction.', 1),
(10, 0, 3, 'Technology & Constructability', 'Selecting unproven or inappropriate construction methods or technologies for the local context.', 1),
(11, 0, 3, 'Environmental & Heritage Issues', 'Unforeseen environmental impacts (e.g., protected species, wetlands) or the discovery of cultural or paleontological heritage artifacts, which can halt work.', 1),
(12, 0, 4, 'Procurement Delays', 'Lengthy or contested tender processes, unsuccessful bids, or legal challenges from unsuccessful bidders.', 1),
(13, 0, 4, 'Contractor Performance', 'Contractor insolvency, poor workmanship, inadequate resources, or failure to meet safety and quality standards.', 1),
(14, 0, 4, 'Project Management Failure', 'Inadequate planning, scheduling, risk management, and change control by the WCG''s project management team.', 1),
(15, 0, 4, 'Supply Chain & Logistics', 'Shortages or delays in the delivery of critical materials, equipment breakdowns, or logistical challenges in remote areas.', 1),
(16, 0, 5, 'Contractual Disputes & Claims', 'Disagreements between the WCG and contractors over variations, extensions of time, and payment, potentially leading to litigation or arbitration.', 1),
(17, 0, 5, 'Non-Compliance with Contract Conditions', 'Failure by either party to meet their contractual obligations.', 1),
(18, 0, 5, 'Land Acquisition & Servitudes', 'Delays or inability to secure the necessary land rights, servitudes, or way-leaves from private landowners or other state entities.', 1),
(19, 0, 6, 'Weather & Natural Disasters', 'Extreme weather events, floods, fires, or droughts (a significant risk in the Western Cape) that damage works or cause prolonged stoppages.', 1),
(20, 0, 6, 'Community Protest & Social Unrest', 'Service delivery protests, labour strikes, or community demands for local employment and subcontracting that disrupt site access and progress.', 1),
(21, 0, 6, 'Pandemic & Health Crises', 'Events like COVID-19 that cause lockdowns, supply chain disruptions, and workforce illness.', 1),
(22, 0, 6, 'Macro-economic Shocks', 'National economic crises impacting inflation, interest rates, and market stability.', 1),
(23, 0, 7, 'Construction Site Safety', 'Risk of accidents, injuries, or fatalities to workers and the public.', 1),
(24, 0, 7, 'Environmental Damage', 'Pollution of water sources, dust, noise, and destruction of ecosystems during construction.', 1),
(25, 0, 7, 'Public Safety', 'Ensuring public areas around the construction site are safe and accessible.', 1);

COMMIT;

-- Add table entry to tbl_maxids DEV[DONE] QA[DONE]
INSERT INTO `tbl_maxids` (`id`, `tbl_name`, `max_id`) VALUES ('19', 'tbl_project_risks', '25');


-- Add new table tbl_project_stg5_risk_management DEV[DONE] QA[DONE]

CREATE TABLE `tbl_project_stg5_risk_management` (
    `id` INT NOT NULL,
    `project_id` INT NOT NULL,
    `risk_category_id` INT NOT NULL,
    `risk_id` INT NOT NULL,
    `impact_key` VARCHAR(500) NOT NULL,
    `impact_value` INT NOT NULL,
    `probability_key` VARCHAR(500) NOT NULL,
    `probability_value` INT NOT NULL,
    `rating` DECIMAL(10,2) NOT NULL DEFAULT '0.00',
    `mitigating_action` TEXT NOT NULL,
    `issue` TEXT NOT NULL,
    `action_to_resolve` TEXT NOT NULL,

    `creation_date` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
    `created_by` INT NULL,
    `updation_date` TIMESTAMP NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
    `updated_by` INT NULL,

    PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Add table entry into tbl_maxids
INSERT INTO `tbl_maxids` (`id`, `tbl_name`, `max_id`) VALUES ('20', 'tbl_project_stg5_risk_management', '0');


-- Updated table maxids where table name = tbl_lookup_detail
-- Check Maxids for tbl_lookup_detail after the latest lookup_detail record of risk_management where data_key = risk_impact_5


--- DATE 01-12-2025
-- Add new columns into tbl_projects DEV[DONE] QA[DONE]
ALTER TABLE `tbl_projects` ADD `progress` DECIMAL(15,2) NULL AFTER `eval_percentage`;
ALTER TABLE `tbl_projects` ADD `elevator_pitch_doc_id` INT NULL DEFAULT NULL AFTER `progress`;
ALTER TABLE `tbl_projects` ADD `exec_summary_doc_id` INT NULL DEFAULT NULL AFTER `elevator_pitch_doc_id`;
ALTER TABLE `tbl_projects` ADD `inc_desc` TEXT NULL DEFAULT NULL AFTER `exec_summary_doc_id`;

-- Update tbl_categories with new categories related to project_portfolio API DEV[DONE] QA[DONE]
INSERT INTO `tbl_categories` (`cat_id`, `cat_name`, `type`, `creation_date`, `created_by`, `updation_date`, `updated_by`) VALUES ('56', 'Elevator Pitch', 'project', '2025-11-17 10:10:59', NULL, NULL, NULL);
INSERT INTO `tbl_categories` (`cat_id`, `cat_name`, `type`, `creation_date`, `created_by`, `updation_date`, `updated_by`) VALUES ('57', 'Executive Summary', 'project', '2025-11-17 10:10:59', NULL, NULL, NULL);

-- DATE 03-12-2025
-- Drop trigger DEV[DONE] QA[DONE]
DROP TRIGGER IF EXISTS `tbl_project_users_after_insert`

-- DATE 04-12-2025
-- use tbl-department-roles.sql for adding roles and updating maxids DEV[PENDING] QA[DONE]


-- DATE 05-12-2025

-- update table schema DEV[DONE] QA[DONE]
ALTER TABLE `tbl_project_stg5` CHANGE `purpose_of_document` `purpose_of_document` TEXT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT NULL;

UPDATE tbl_project_stg0
SET ballpark_project_cost = 0
WHERE ballpark_project_cost IS NULL;

ALTER TABLE tbl_project_stg0
CHANGE ballpark_project_cost ballpark_project_cost
DECIMAL(25,0) NOT NULL DEFAULT 0;

-- Update table tbl_lookup_detail DEV[DONE] QA[DONE]
UPDATE `tbl_lookup_detail` SET `display_name` = 'Long Term 15-30 YRS' WHERE `tbl_lookup_detail`.`optionid` = 49;
UPDATE `tbl_lookup_detail` SET `display_name` = 'Medium Term 5-15 YRS' WHERE `tbl_lookup_detail`.`optionid` = 48;
UPDATE `tbl_lookup_detail` SET `display_name` = 'Short Term 1-5 YRS' WHERE `tbl_lookup_detail`.`optionid` = 47;


-- Add triggers on tbl_project_stg0 DEV[DONE] QA[DONE]
DELIMITER $$

CREATE TRIGGER trg_stg0_before_insert
BEFORE INSERT ON tbl_project_stg0
FOR EACH ROW
BEGIN
    SET NEW.ballpark_project_cost = 
        COALESCE(NEW.capax, 0) + COALESCE(NEW.opax, 0);
END$$

DELIMITER ;

-----------------------------------------------------
DELIMITER $$

CREATE TRIGGER trg_stg0_before_update
BEFORE UPDATE ON tbl_project_stg0
FOR EACH ROW
BEGIN
    SET NEW.ballpark_project_cost =
        COALESCE(NEW.capax, 0) + COALESCE(NEW.opax, 0);
END$$

DELIMITER ;

-- DATE 08-12-2025
ALTER TABLE tbl_project_questions
MODIFY weighted_score DECIMAL(10,2);

-- Update tbl_sectors to add color column DEV[DONE] QA[DONE]
ALTER TABLE `tbl_sectors` ADD `color` VARCHAR(50) NULL DEFAULT NULL AFTER `desc`;
UPDATE `tbl_sectors` SET `color` = '#0080ff' WHERE `tbl_sectors`.`sector_id` = 6;
UPDATE `tbl_sectors` SET `color` = '#f44336' WHERE `tbl_sectors`.`sector_id` = 3;
UPDATE `tbl_sectors` SET `color` = '#ff9800' WHERE `tbl_sectors`.`sector_id` = 9;
UPDATE `tbl_sectors` SET `color` = '#9c27b0' WHERE `tbl_sectors`.`sector_id` = 11;
UPDATE `tbl_sectors` SET `color` = '#28a745' WHERE `tbl_sectors`.`sector_id` = 10;

-- DATE 09-12-2025
-- Track user active stage and steps DEV[PENDING] QA[DONE]
START TRANSACTION;
-- Table structure for table `tbl_frontend_active_stage`
CREATE TABLE `tbl_frontend_active_stage` (
  `id` int(11) NOT NULL,
  `stage` varchar(100) NOT NULL,
  `active_step` varchar(100) NOT NULL,
  `project_id` int(11) NOT NULL,
  `created_at` timestamp NOT NULL DEFAULT current_timestamp(),
  `created_by` int(11) DEFAULT NULL,
  `updated_at` timestamp NOT NULL DEFAULT current_timestamp(),
  `updated_by` int(11) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Indexes for table `tbl_frontend_active_stage`
ALTER TABLE `tbl_frontend_active_stage`
  ADD PRIMARY KEY (`id`);

ALTER TABLE `tbl_frontend_active_stage` ADD UNIQUE `project_id_stage` 
(`project_id`, `stage`) USING BTREE;

INSERT INTO `tbl_maxids` (`id`, `tbl_name`, `max_id`) VALUES ('21', 'tbl_frontend_active_stage', '0');

COMMIT;

-- DATE 10-12-2025 Updated SP with stg-5 tables: Use sp_deleteprojectusingprojectid. DEV[DONE] QA[DONE]

-- Lookup and lookup_detail update DEV[DONE] QA[DONE]
START TRANSACTION;

UPDATE tbl_lookup
SET dev_name = 'risk_likelihood',
    display_name = 'Risk Likelihood',
    display_name_ml = 'risk-likelihood-ml'
WHERE dev_name = 'risk_probability';

UPDATE tbl_lookup
SET dev_name = 'risk_severity',
    display_name = 'Risk Severity',
    display_name_ml = 'risk-severity-ml'
WHERE dev_name = 'risk_impact';

-- update lookup_detail DEV[DONE] QA[DONE]
UPDATE tbl_lookup_detail
SET 
    data_key = REPLACE(data_key, 'risk_probability_', 'risk_likelihood_'),
    display_name_ml = REPLACE(display_name_ml, 'risk-probability-', 'risk-likelihood-')
WHERE data_key LIKE 'risk_probability_%';

UPDATE tbl_lookup_detail
SET 
    data_key = REPLACE(data_key, 'risk_impact_', 'risk_severity_'),
    display_name_ml = REPLACE(display_name_ml, 'risk-impact-', 'risk-severity-')
WHERE data_key LIKE 'risk_impact_%';
COMMIT;

-- new risk-management enhancement tables: DEV[DONE] QA[DONE]
START TRANSACTION;
CREATE TABLE IF NOT EXISTS `tbl_mitigate_risks` (
  `id` int(11) NOT NULL,
  `project_id` int(11) DEFAULT NULL,
  `risk_cat_id` int(11) DEFAULT NULL,
  `risk_name` varchar(250) DEFAULT NULL,
  `description` text DEFAULT NULL,
  `is_active` int(11) DEFAULT 1,
  `creation_date` timestamp NOT NULL DEFAULT current_timestamp(),
  `created_by` int(11) DEFAULT NULL,
  `updation_date` timestamp NOT NULL DEFAULT current_timestamp(),
  `updated_by` int(11) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

ALTER TABLE `tbl_mitigate_risks` ADD PRIMARY KEY(`id`);
ALTER TABLE `tbl_mitigate_risks` CHANGE `project_id` `project_id` INT(11) NULL DEFAULT '0';

-- Data exporting was unselected.

-- Dumping structure for table doi_platform_dev_db.tbl_risk_level_master DEV[DONE] QA[DONE]
CREATE TABLE IF NOT EXISTS `tbl_risk_level_master` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `level_name` varchar(50) NOT NULL,
  `score_min` int(11) NOT NULL,
  `score_max` int(11) NOT NULL,
  `action_text` varchar(255) DEFAULT NULL,
  `is_active` tinyint(1) DEFAULT 1,
  `creation_at` timestamp NOT NULL DEFAULT current_timestamp(),
  `created_by` int(11) DEFAULT NULL,
  `updation_at` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(),
  `updated_by` int(11) DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;


-- Dumping data for table doi_platform_dev_db.tbl_risk_level_master DEV[DONE] QA[DONE]
INSERT INTO `tbl_risk_level_master` (`id`, `level_name`, `score_min`, `score_max`, `action_text`, `is_active`, `creation_at`, `created_by`, `updation_at`, `updated_by`) VALUES
	(1, 'Low', 1, 4, 'Monitor', 1, '2025-12-11 05:37:31', NULL, '2025-12-11 07:12:35', NULL),
	(2, 'Medium', 5, 9, 'Mitigation', 1, '2025-12-11 05:37:31', NULL, '2025-12-11 07:12:40', NULL),
	(3, 'High', 10, 16, 'Immediate Action', 1, '2025-12-11 05:37:31', NULL, '2025-12-11 07:13:25', NULL),
	(4, 'Extreme', 17, 25, 'Escalate to Governance', 1, '2025-12-11 05:37:31', NULL, '2025-12-11 07:13:26', NULL);
COMMIT;

-- Update tbl_project_stg5_risk_management DEV[DONE] QA[DONE]

START TRANSACTION;

CREATE TABLE IF NOT EXISTS `tbl_project_stg5_risk_management` (
  `id` int(11) NOT NULL,
  `project_id` int(11) NOT NULL,
  `risk_category_id` int(11) NOT NULL,
  `risk_id` int(11) NOT NULL,
  `severity_key` varchar(100) NOT NULL,
  `severity_value` int(11) NOT NULL,
  `likelihood_key` varchar(500) NOT NULL,
  `likelihood_value` int(11) NOT NULL,
  `risk_level_id` int(11) NOT NULL,
  `mitigate_risk_id` int(11) NOT NULL,
  `residual_likelihood_key` varchar(50) NOT NULL,
  `residual_likelihood_value` int(11) NOT NULL,
  `residual_severity_key` varchar(50) NOT NULL,
  `residual_severity_value` int(11) NOT NULL,
  `mitigate_risk_level_id` int(11) NOT NULL,
  `risk_strategy_id` int(11) DEFAULT NULL,
  `description` text NOT NULL,
  `created_at` timestamp NOT NULL DEFAULT current_timestamp(),
  `created_by` int(11) DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL ON UPDATE current_timestamp(),
  `updated_by` int(11) DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

COMMIT;
 
--- DATE 15-12-2025 Update Lookup DEV[DONE] QA[DONE]

INSERT INTO `tbl_lookup`
(`keyid`, `dev_name`, `display_name`, `display_name_ml`, `description`, `is_active`, `translate`, `creation_date`, `created_by`, `updation_date`, `updated_by`)
VALUES
(91, 'acceptance_criteria_risk_for_budget', 'Acceptance Criteria Risk for Budget', 'acceptance-criteria-risk-for-budget-ml', '', 1, 'No', '2025-12-11 11:30:00', 1, '2025-12-11 11:30:00', 1);


INSERT INTO `tbl_lookup_detail`
(`optionid`, `keyid`, `data_value`, `data_key`, `display_name`, `display_name_ml`, `sequence`, `item_data`, `parent_datakey`, `is_active`, `creation_date`, `created_by`, `updation_date`, `updated_by`)
VALUES
(875, 91, 1, 'acceptance_criteria_risk_for_budget_1', 'Not at Risk', 'acceptance-criteria-risk-for-budget-1-ml', 1, '', '', 1, '2025-12-11 11:30:00', 1, '2025-12-11 11:30:00', 1);

INSERT INTO `tbl_lookup_detail`
(`optionid`, `keyid`, `data_value`, `data_key`, `display_name`, `display_name_ml`, `sequence`, `item_data`, `parent_datakey`, `is_active`, `creation_date`, `created_by`, `updation_date`, `updated_by`)
VALUES
(876, 91, 2, 'acceptance_criteria_risk_for_budget_2', 'Potentially at Risk', 'acceptance-criteria-risk-for-budget-2-ml', 2, '', '', 1, '2025-12-11 11:30:00', 1, '2025-12-11 11:30:00', 1);

INSERT INTO `tbl_lookup_detail`
(`optionid`, `keyid`, `data_value`, `data_key`, `display_name`, `display_name_ml`, `sequence`, `item_data`, `parent_datakey`, `is_active`, `creation_date`, `created_by`, `updation_date`, `updated_by`)
VALUES
(877, 91, 3, 'acceptance_criteria_risk_for_budget_3', 'Is at Risk', 'acceptance-criteria-risk-for-budget-3-ml', 3, '', '', 1, '2025-12-11 11:30:00', 1, '2025-12-11 11:30:00', 1);

-- Update tbl_project_risks DEV[DONE] QA[DONE]
SET AUTO_COMMIT 0;
START TRANSACTION;
ALTER TABLE `tbl_project_risks` ADD `risk_type` ENUM('risk','mitigate','strategy') NOT NULL AFTER `risk_name`;

-- Risk Category and Risk Types as on 15Dec2025 DEV[DONE] QA[DONE]

DELETE FROM `tbl_project_risk_category`
WHERE `id` IN (1, 2, 3, 4, 5, 6, 7);


INSERT INTO `tbl_project_risk_category`
(`id`, `category_name`, `description`, `creation_date`)
VALUES
(1, 'Financial Risk', 'Budget overruns, funding delays', '2025-12-15 13:07:04'),
(2, 'Compliance Risk', 'Non-adherence to ISO9001, environmental regulations', '2025-12-15 13:13:37'),
(3, 'Stakeholder Risk', 'Poor engagement, political interference', '2025-12-15 13:14:31'),
(4, 'Technical Risk', 'Design flaws, technology failure', '2025-12-15 13:15:23'),
(5, 'Schedule Risk', 'Delays due to procurement or contractor performance', '2025-12-15 13:16:11'),
(6, 'Climate and Environmental Risk', 'Flooding, drought impact on construction', '2025-12-15 13:17:58');

DELETE FROM `tbl_project_risks` WHERE `id` IN ( 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,  16, 17, 18, 19, 20,21, 22, 23, 24, 25);
-- DEV[DONE] QA[DONE]
INSERT INTO `tbl_project_risks`
(`id`, `risk_cat_id`, `risk_name`, `description`, `creation_date`)
VALUES
(1, 1, 'Funding and Budgetary Constraints',
 'Unreliable or insufficient funding streams, budget cuts, or delays in the release of funds from provincial or national treasury.',
 '2025-12-15 13:45:44'),
(2, 1, 'Cost Overruns and Escalation',
 'Inaccurate initial cost estimates, price inflation of materials (e.g., steel, cement), currency fluctuations affecting imported materials, and unforeseen ground conditions leading to increased costs.',
 '2025-12-15 13:47:09'),
(3, 1, 'Economic Viability',
 'The project fails to deliver the intended economic benefits (e.g., job creation, economic stimulation) or the operational costs become unsustainable for the department.',
 '2025-12-15 13:48:07'),
(4, 2, 'Construction Site Safety',
 'Risk of accidents, injuries, or fatalities to workers and the public.',
 '2025-12-15 13:49:21'),
(5, 2, 'Environmental Damage',
 'Pollution of water sources, dust, noise, and destruction of ecosystems during construction.',
 '2025-12-15 13:50:17'),
(6, 2, 'Public Safety',
 'Ensuring public areas around the construction site are safe and accessible.',
 '2025-12-15 13:51:20'),
(7, 2, 'Contractual Disputes and Claims',
 'Disagreements between the WCG and contractors over variations, extensions of time, and payment, potentially leading to litigation or arbitration.',
 '2025-12-15 13:52:21'),
(8, 2, 'Non-Compliance with Contract Conditions',
 'Failure by either party to meet their contractual obligations.',
 '2025-12-15 13:53:15'),
(9, 2, 'Land Acquisition and Servitudes',
 'Delays or inability to secure the necessary land rights, servitudes, or way-leaves from private landowners or other state entities.',
 '2025-12-15 13:54:11'),
(10, 3, 'Project Justification and Alignment',
 'The project is not aligned with provincial strategic goals (e.g., Provincial Strategic Plan), spatial development frameworks, or integrated development plans (IDPs).',
 '2025-12-15 13:55:53'),
(11, 3, 'Stakeholder Management and Political Interference',
 'Poor communication and engagement with communities, political stakeholders, or other government departments leading to delays, protests, or scope changes.',
 '2025-12-15 13:56:51'),
(12, 3, 'Governance and Accountability',
 'Weak project steering committees, unclear roles and responsibilities, and lack of senior management oversight.',
 '2025-12-15 13:57:37'),
(13, 3, 'Regulatory and Policy Compliance',
 'Failure to comply with legislation such as the MFMA, PFMA, B-BBEE codes, and construction industry regulations.',
 '2025-12-15 08:52:09'),
(14, 4, 'Inadequate Site Investigation',
 'Poor geotechnical studies leading to unexpected ground conditions, soil instability, or contamination, requiring expensive design changes.',
 '2025-12-15 08:52:09'),
(15, 4, 'Design Errors and Omissions',
 'Flaws, inconsistencies, or lack of detail in the design documents, leading to rework, delays, and claims during construction.',
 '2025-12-15 14:00:28'),
(16, 4, 'Technology and Constructability',
 'Selecting unproven or inappropriate construction methods or technologies for the local context.',
 '2025-12-15 14:01:11'),
(17, 4, 'Environmental and Heritage Issues',
 'Unforeseen environmental impacts or the discovery of heritage artifacts that can halt work.',
 '2025-12-15 14:01:54'),
(18, 5, 'Procurement Delays',
 'Lengthy or contested tender processes, unsuccessful bids, or legal challenges.',
 '2025-12-15 14:02:53'),
(19, 5, 'Contractor Performance',
 'Contractor insolvency, poor workmanship, inadequate resources, or failure to meet standards.',
 '2025-12-15 14:03:33'),
(20, 5, 'Project Management Failure',
 'Inadequate planning, scheduling, risk management, and change control.',
 '2025-12-15 14:04:19'),
(21, 5, 'Supply Chain and Logistics',
 'Shortages or delays in critical materials, equipment breakdowns, or logistical challenges.',
 '2025-12-15 14:05:00'),
(22, 6, 'Weather and Natural Disasters',
 'Extreme weather events, floods, fires, or droughts that damage works or cause stoppages.',
 '2025-12-15 14:06:03'),
(23, 6, 'Community Protest and Social Unrest',
 'Service delivery protests, labour strikes, or community demands disrupting progress.',
 '2025-12-15 14:06:44'),
(24, 6, 'Pandemic and Health Crises',
 'Events like COVID-19 causing lockdowns, supply chain disruptions, and illness.',
 '2025-12-15 14:07:25'),
(25, 6, 'Macro-economic Shocks',
 'National economic crises impacting inflation, interest rates, and stability.',
 '2025-12-15 14:08:05');
-- DEV[DONE] QA[DONE]
INSERT INTO `tbl_project_risks`
(`id`, `risk_cat_id`, `risk_name`, `risk_type`, `description`, `creation_date`)
VALUES
(26, 1, 'Avoid unnecessary costs and transfer risk via insurance', 'mitigate', '', '2025-12-15 17:01:29'),
(27, 2, 'Ensure adherence through audits and enforce penalties', 'mitigate', '', '2025-12-15 17:02:25'),
(28, 3, 'Collaborate and communicate to reduce resistance', 'mitigate', '', '2025-12-15 17:03:47'),
(29, 4, 'Reduce complexity and outsource specialized tasks', 'mitigate', '', '2025-12-15 17:04:42'),
(30, 5, 'Accelerate critical tasks and allocate extra resources', 'mitigate', '', '2025-12-15 17:05:33'),
(31, 6, 'Adapt design and prepare contingency plans', 'mitigate', '', '2025-12-15 17:06:30'),
(32, 1, 'Implement strict budget monitoring and contingency reserves', 'strategy', '', '2025-12-15 17:07:24'),
(33, 2, 'Regular audits and compliance training', 'strategy', '', '2025-12-15 17:08:10'),
(34, 3, 'Engage stakeholders through monthly progress meetings', 'strategy', '', '2025-12-15 17:08:57'),
(35, 4, 'Conduct design reviews and quality assurance checks', 'strategy', '', '2025-12-15 17:09:51'),
(36, 5, 'Develop detailed project timeline and monitor milestones', 'strategy', '', '2025-12-15 17:10:39'),
(37, 6, 'Include climate resilience measures and environmental impact assessments', 'strategy', '', '2025-12-15 17:11:34');
COMMIT;
SET AUTO_COMMIT = 1;

-- DATE 17-12-2025 Project manager not required updates.
ALTER TABLE `tbl_projects`CHANGE COLUMN `project_manager` `project_manager` INT(11) NULL DEFAULT NULL AFTER `project_owner`;


-- DATE 19-12-2025 Update trigger tbl_project_stages_after_insert

BEGIN
  -- Insert tbl_project_stg0
  INSERT INTO `tbl_project_stg0` (`project_id`, `background_justification`, `scope_of_work`, `ballpark_project_cost`, `estimated_project_duration_years`, `estimated_project_duration_months`, `estimated_project_start_date`, `is_active`, `creation_date`, `created_by`, `updation_date`, `updated_by`)
  VALUES (NEW.project_id, '', '', NULL, NULL, NULL, NULL, '1', NOW(), NEW.created_by, NULL, NULL);
  
  -- Insert tbl_project_users
  -- INSERT INTO `tbl_project_users` (`project_id`, `user_id`, `role_id`, `total_questions`, `attempted_questions`, `eval_status`, `project_rights`, `creation_date`, `created_by`)
  -- VALUES (NEW.project_id, NEW.created_by, 'project_team_roles_2', 0, 0, 'pending', 'edit', NOW(), NEW.created_by);
 
  IF NEW.project_manager!=NEW.project_owner THEN
    -- Insert project_owner as project_owner in tbl_project_users
    INSERT INTO `tbl_project_users` (`project_id`, `user_id`, `role_id`, `total_questions`, `attempted_questions`, `eval_status`, `project_rights`, `creation_date`, `created_by`)
    VALUES (NEW.project_id, NEW.project_owner, 'project_team_roles_3', 0, 0, 'pending', 'edit', NOW(), NEW.created_by);
  END IF;
	-- Insert project_manager as project_manager in tbl_project_users (optional)
	IF NEW.project_manager IS NOT NULL AND NEW.project_manager != 0 THEN
	    INSERT INTO `tbl_project_users`
	    (`project_id`, `user_id`, `role_id`, `total_questions`, `attempted_questions`,
	     `eval_status`, `project_rights`, `creation_date`, `created_by`)
	    VALUES
	    (NEW.project_id, NEW.project_manager, 'project_team_roles_4',
	     0, 0, 'pending', 'edit', NOW(), NEW.created_by);
	END IF;

  -- Insert tbl_project_additonal_stages add intermediate/additional checks for stages with user_id as 0. 
  INSERT INTO tbl_project_additonal_stages (additional_check_datakey,project_id,stage_id,user_id)
  values ('project_additional_stages_1',NEW.project_id,'project_stage_1','0'),
  ('project_additional_stages_2',NEW.project_id,'project_stage_2','0');
 
-- Insert project_stage_0
  INSERT INTO tbl_project_stages (
    project_stage_id, project_id, stage_id, stage_status, active_gate, created_by, prerequisites_stages, creation_date
  )
  SELECT IFNULL(MAX(project_stage_id), 0) + 1,
         NEW.project_id,
         'project_stage_0',
         'stage_status_1',
         1,
         NEW.created_by,
         '',
         NOW()
  FROM tbl_project_stages;
 
  -- Insert project_stage_1 to project_stage_9
  INSERT INTO tbl_project_stages(project_stage_id, project_id, stage_id, stage_status, active_gate, additional_check, created_by, prerequisites_stages, creation_date)
  SELECT IFNULL(MAX(project_stage_id), 0) + 1, NEW.project_id, 'project_stage_1', 'stage_status_1', 0, 'na', NEW.created_by, 'project_stage_0', NOW() FROM tbl_project_stages;
  
  INSERT INTO tbl_project_stages(project_stage_id, project_id, stage_id, stage_status, active_gate, created_by, prerequisites_stages, creation_date)
  SELECT IFNULL(MAX(project_stage_id), 0) + 1, NEW.project_id, 'project_stage_2', 'stage_status_1', 0, NEW.created_by, 'project_stage_1', NOW() FROM tbl_project_stages;
  
  INSERT INTO tbl_project_stages(project_stage_id, project_id, stage_id, stage_status, active_gate, additional_check, created_by, prerequisites_stages, creation_date)
  SELECT IFNULL(MAX(project_stage_id), 0) + 1, NEW.project_id, 'project_stage_3', 'stage_status_1', 0, 'na', NEW.created_by, 'project_stage_2', NOW() FROM tbl_project_stages;
  
  INSERT INTO tbl_project_stages(project_stage_id, project_id, stage_id, stage_status, active_gate, created_by, prerequisites_stages, creation_date)
  SELECT IFNULL(MAX(project_stage_id), 0) + 1, NEW.project_id, 'project_stage_4', 'stage_status_1', 0, NEW.created_by, 'project_stage_3', NOW() FROM tbl_project_stages;
  
  INSERT INTO tbl_project_stages(project_stage_id, project_id, stage_id, stage_status, active_gate, created_by, prerequisites_stages, creation_date)
  SELECT IFNULL(MAX(project_stage_id), 0) + 1, NEW.project_id, 'project_stage_5', 'stage_status_1', 0, NEW.created_by, 'project_stage_4', NOW() FROM tbl_project_stages;
  
  INSERT INTO tbl_project_stages(project_stage_id, project_id, stage_id, stage_status, active_gate, created_by, prerequisites_stages, creation_date)
  SELECT IFNULL(MAX(project_stage_id), 0) + 1, NEW.project_id, 'project_stage_6', 'stage_status_1', 0, NEW.created_by, 'project_stage_5', NOW() FROM tbl_project_stages;
  
  INSERT INTO tbl_project_stages(project_stage_id, project_id, stage_id, stage_status, active_gate, created_by, prerequisites_stages, creation_date)
  SELECT IFNULL(MAX(project_stage_id), 0) + 1, NEW.project_id, 'project_stage_7', 'stage_status_1', 0, NEW.created_by, 'project_stage_6', NOW() FROM tbl_project_stages;
  
  INSERT INTO tbl_project_stages(project_stage_id, project_id, stage_id, stage_status, active_gate, created_by, prerequisites_stages, creation_date)
  SELECT IFNULL(MAX(project_stage_id), 0) + 1, NEW.project_id, 'project_stage_8', 'stage_status_1', 0, NEW.created_by, 'project_stage_7', NOW() FROM tbl_project_stages;
  
  INSERT INTO tbl_project_stages(project_stage_id, project_id, stage_id, stage_status, active_gate, created_by, prerequisites_stages, creation_date)
  SELECT IFNULL(MAX(project_stage_id), 0) + 1, NEW.project_id, 'project_stage_9', 'stage_status_1', 0, NEW.created_by, 'project_stage_8', NOW() FROM tbl_project_stages;
 
END

-- DATE 22-12-2025 Update Primary index on tbl_project_users
ALTER TABLE `tbl_project_users` DROP PRIMARY KEY, ADD PRIMARY KEY (`project_id`, `user_id`, `role_id`) USING BTREE;

-- Project Plan APIs SQL DEV[Done] QA[DONE]
-- Date 30-12-2025 created table `tbl_dept_phase_tasks` for new Project plan apis
CREATE TABLE `tbl_dept_phase_tasks` (
    `dept_task_id` INT NOT NULL,
    `department_id` INT NOT NULL,
    `phase_id` INT NOT NULL,
    `task_name` VARCHAR(500) NOT NULL,
    `parent_id` INT NOT NULL DEFAULT 0,
    `created_by` INT DEFAULT NULL,
    `updated_by` INT DEFAULT NULL,
    `creation_date` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
    `updation_date` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP 
        ON UPDATE CURRENT_TIMESTAMP,
    PRIMARY KEY (`dept_task_id`)
) ENGINE=InnoDB
  DEFAULT CHARSET=utf8mb4
  COLLATE=utf8mb4_unicode_ci;

-- Date 30-12-2025 created table `tbl_project_tasks` for new Project plan apis
CREATE TABLE `tbl_project_tasks` (
    `project_task_id` INT NOT NULL,
    `project_id` INT NOT NULL DEFAULT 0,
    `task_name` VARCHAR(500) NOT NULL,
    `allocated_budget` DECIMAL(15,2) NOT NULL DEFAULT 0.00,
    `additional_budget` DECIMAL(15,2) NOT NULL DEFAULT 0.00,
    `duration` BIGINT DEFAULT NULL,
    `type` ENUM('capex', 'opex') DEFAULT NULL,
    `start_date` DATE DEFAULT NULL,
    `end_date` DATE DEFAULT NULL,
    `progress` DECIMAL(5,2) NOT NULL DEFAULT 0.00,
    `status` VARCHAR(50) DEFAULT NULL,
    `at_risk` ENUM('Yes', 'No') NOT NULL DEFAULT 'No',
    `created_by` INT DEFAULT NULL,
    `updated_by` INT DEFAULT NULL,
    `creation_date` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
    `updation_date` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP 
        ON UPDATE CURRENT_TIMESTAMP,
    PRIMARY KEY (`project_task_id`)
) ENGINE=InnoDB
  DEFAULT CHARSET=utf8mb4
  COLLATE=utf8mb4_unicode_ci;

-- Date 30-12-2025 created table `tbl_project_task_resources` for new Project plan apis
CREATE TABLE `tbl_project_task_resources` (
    `project_task_id` INT NOT NULL,
    `department_role_id` INT DEFAULT NULL,
    `no_of_resources` INT DEFAULT NULL,
    `rate_per_hour` DECIMAL(10,2) NOT NULL DEFAULT 0.00,
    `hours_of_work` DECIMAL(10,2) NOT NULL DEFAULT 0.00,
    `created_by` INT DEFAULT NULL,
    `updated_by` INT DEFAULT NULL,
    `creation_date` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
    `updation_date` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP 
        ON UPDATE CURRENT_TIMESTAMP,
    PRIMARY KEY (`project_task_id`)
) ENGINE=InnoDB
  DEFAULT CHARSET=utf8mb4
  COLLATE=utf8mb4_unicode_ci;

-- Date 30-12-2025 created table `tbl_proof_of_evidence` for new Project plan apis
CREATE TABLE `tbl_proof_of_evidence` (
    `poe_id` INT NOT NULL AUTO_INCREMENT,
    `poe_name` VARCHAR(500) NOT NULL,
    `is_active` ENUM('0', '1') NOT NULL DEFAULT '1',
    `created_by` INT DEFAULT NULL,
    `updated_by` INT DEFAULT NULL,
    `creation_date` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
    `updation_date` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP 
        ON UPDATE CURRENT_TIMESTAMP,
    PRIMARY KEY (`poe_id`)
) ENGINE=InnoDB
  DEFAULT CHARSET=utf8mb4
  COLLATE=utf8mb4_unicode_ci;

-- Date 30-12-2025 created table `tbl_poe_task` for new Project plan apis
CREATE TABLE `tbl_poe_task` (
    `poe_id` INT NOT NULL,
    `dept_task_id` INT NOT NULL,
    `created_by` INT DEFAULT NULL,
    `updated_by` INT DEFAULT NULL,
    `creation_date` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
    `updation_date` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP 
        ON UPDATE CURRENT_TIMESTAMP
) ENGINE=InnoDB
  DEFAULT CHARSET=utf8mb4
  COLLATE=utf8mb4_unicode_ci;

-- Date 30-12-2025 created table `tbl_project_task_poe_documents` for new Project plan apis
CREATE TABLE `tbl_project_task_poe_documents` (
    `project_task_id` INT NOT NULL,
    `poe_id` INT NOT NULL,
    `document_id` INT NOT NULL,
    `created_by` INT DEFAULT NULL,
    `updated_by` INT DEFAULT NULL,
    `creation_date` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
    `updation_date` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP 
        ON UPDATE CURRENT_TIMESTAMP
) ENGINE=InnoDB
  DEFAULT CHARSET=utf8mb4
  COLLATE=utf8mb4_unicode_ci;

-- add dept_task_id column to tbl_project_tasks
ALTER TABLE `tbl_project_tasks` ADD `dept_task_id` INT NULL DEFAULT NULL AFTER `project_id`;

-- update role_type in tbl_role_master to add responsible_party
ALTER TABLE `tbl_role_master` CHANGE `role_type` `role_type` ENUM('global','project','responsible_party') CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT 'project';

-- DATE 31-12-2025 insert department phase tasks for all Department
INSERT INTO `tbl_dept_phase_tasks`
(`dept_task_id`, `department_id`, `phase_id`, `task_name`, `parent_id`, `created_by`, `creation_date`, `updated_by`, `updation_date`)
VALUES
(1, 14, 1, 'Prepare the site for construction with safety and accessibility in mind', 0, 110, '2025-11-26 05:00:29', NULL, '2025-11-26 05:00:29'),
(2, 14, 1, 'Site selection based on crime data and community needs', 1, 110, '2025-11-26 05:00:29', NULL, '2025-11-26 05:00:29'),
(3, 14, 1, 'Environmental and social impact assessments', 1, 110, '2025-11-26 05:00:29', NULL, '2025-11-26 05:00:29'),
(4, 14, 1, 'Stakeholder consultations (SAPS, CPF, local communities)', 1, 110, '2025-11-26 05:00:29', NULL, '2025-11-26 05:00:29'),
(5, 14, 1, 'Site clearance and grading', 1, 110, '2025-11-26 05:00:29', NULL, '2025-11-26 05:00:29'),
(6, 14, 1, 'Temporary access roads, fencing, and security', 1, 110, '2025-11-26 05:00:29', NULL, '2025-11-26 05:00:29'),
(7, 14, 1, 'Utility connections (electricity, water, ICT for surveillance systems)', 1, 110, '2025-11-26 05:00:29', NULL, '2025-11-26 05:00:29'),
(8, 14, 1, 'Planning for service continuity and temporary safety measures', 1, 110, '2025-11-26 05:00:29', NULL, '2025-11-26 05:00:29'),

(9, 14, 2, 'Build infrastructure that supports policing oversight and community safety', 0, 110, '2025-11-26 05:00:29', NULL, '2025-11-26 05:00:29'),
(10, 14, 2, 'Foundation and structural works (safety centers, mobile command units, community safety offices)', 9, 110, '2025-11-26 05:00:29', NULL, '2025-11-26 05:00:29'),
(11, 14, 2, 'Construction of public safety amenities (safe zones, lighting, emergency kiosks)', 9, 110, '2025-11-26 05:00:29', NULL, '2025-11-26 05:00:29'),
(12, 14, 2, 'Installation of surveillance systems (CCTV, license plate recognition, panic buttons)', 9, 110, '2025-11-26 05:00:29', NULL, '2025-11-26 05:00:29'),
(13, 14, 2, 'ICT infrastructure for data sharing, case tracking, and public reporting', 9, 110, '2025-11-26 05:00:29', NULL, '2025-11-26 05:00:29'),
(14, 14, 2, 'Accessibility features (universal design, signage, multilingual interfaces)', 9, 110, '2025-11-26 05:00:29', NULL, '2025-11-26 05:00:29'),
(15, 14, 2, 'Renewable energy systems (solar-powered lighting, backup systems)', 9, 110, '2025-11-26 05:00:29', NULL, '2025-11-26 05:00:29'),
(16, 14, 2, 'Safety systems (fire suppression, secure access control, perimeter monitoring)', 9, 110, '2025-11-26 05:00:29', NULL, '2025-11-26 05:00:29'),
(17, 14, 2, 'Landscaping and urban integration (green buffers, pedestrian zones', 9, 110, '2025-11-26 05:00:29', NULL, '2025-11-26 05:00:29'),

(18, 14, 3, 'Operationalize the infrastructure and transfer to oversight and community teams', 0, 110, '2025-11-26 05:00:29', NULL, '2025-11-26 05:00:29'),
(19, 14, 3, 'Final inspections and compliance testing', 18, 110, '2025-11-26 05:00:29', NULL, '2025-11-26 05:00:29'),
(20, 14, 3, 'Defect resolution and quality assurance', 18, 110, '2025-11-26 05:00:29', NULL, '2025-11-26 05:00:29'),
(21, 14, 3, 'Handover documentation (as-built drawings, O&M manuals, surveillance protocols)', 18, 110, '2025-11-26 05:00:29', NULL, '2025-11-26 05:00:29'),
(22, 14, 3, 'Staff training and induction (oversight officers, community safety volunteers)', 18, 110, '2025-11-26 05:00:29', NULL, '2025-11-26 05:00:29'),
(23, 14, 3, 'Community orientation and safety awareness campaigns', 18, 110, '2025-11-26 05:00:29', NULL, '2025-11-26 05:00:29'),
(24, 14, 3, 'Monitoring and evaluation framework setup', 18, 110, '2025-11-26 05:00:29', NULL, '2025-11-26 05:00:29'),
(25, 14, 3, 'Official launch and stakeholder engagement event', 18, 110, '2025-11-26 05:00:29', NULL, '2025-11-26 05:00:29'),

(26, 7, 1, 'Prepare the site for transport infrastructure development', 0, 0, '2025-11-26 05:00:29', NULL, '2025-11-26 05:00:29'),
(27, 7, 1, 'Route and site selection based on transport demand and spatial equity', 26, 0, '2025-11-26 05:00:29', NULL, '2025-11-26 05:00:29'),
(28, 7, 1, 'Environmental and traffic impact assessments', 26, 0, '2025-11-26 05:00:29', NULL, '2025-11-26 05:00:29'),
(29, 7, 1, 'Stakeholder consultations (municipalities, commuters, operators)', 26, 0, '2025-11-26 05:00:29', NULL, '2025-11-26 05:00:29'),
(30, 7, 1, 'Site clearance and grading', 26, 0, '2025-11-26 05:00:29', NULL, '2025-11-26 05:00:29'),
(31, 7, 1, 'Temporary access roads, fencing, and signage', 26, 0, '2025-11-26 05:00:29', NULL, '2025-11-26 05:00:29'),
(32, 7, 1, 'Utility connections (electricity, water, ICT for smart systems)', 26, 0, '2025-11-26 05:00:29', NULL, '2025-11-26 05:00:29'),
(33, 7, 1, 'Planning for service continuity and detour routes', 26, 0, '2025-11-26 05:00:29', NULL, '2025-11-26 05:00:29'),

(34, 7, 2, 'Build core mobility infrastructure', 0, 0, '2025-11-26 05:00:29', NULL, '2025-11-26 05:00:29'),
(35, 7, 2, 'Roadworks and paving (bus lanes, cycle paths, pedestrian walkways)', 34, 0, '2025-11-26 05:00:29', NULL, '2025-11-26 05:00:29'),
(36, 7, 2, 'Construction of transport hubs (interchanges, taxi ranks, bus terminals)', 34, 0, '2025-11-26 05:00:29', NULL, '2025-11-26 05:00:29'),
(37, 7, 2, 'Installation of smart mobility systems (real-time tracking, ticketing tech)', 34, 0, '2025-11-26 05:00:29', NULL, '2025-11-26 05:00:29'),
(38, 7, 2, 'Electrical and mechanical systems (lighting, ventilation, solar panels)', 34, 0, '2025-11-26 05:00:29', NULL, '2025-11-26 05:00:29'),
(39, 7, 2, 'Accessibility features (ramps, tactile paving, multilingual signage)', 34, 0, '2025-11-26 05:00:29', NULL, '2025-11-26 05:00:29'),
(40, 7, 2, 'Safety systems (CCTV, emergency call points, traffic calming measures)', 34, 0, '2025-11-26 05:00:29', NULL, '2025-11-26 05:00:29'),
(41, 7, 2, 'Landscaping and urban integration (green buffers, seating, shade structures)', 34, 0, '2025-11-26 05:00:29', NULL, '2025-11-26 05:00:29'),

(42, 7, 3, 'Operationalize the infrastructure and transfer to transport authorities', 0, 0, '2025-11-26 05:00:29', NULL, '2025-11-26 05:00:29'),
(43, 7, 3, 'Final inspections and compliance testing', 42, 0, '2025-11-26 05:00:29', NULL, '2025-11-26 05:00:29'),
(44, 7, 3, 'Defect resolution and quality assurance', 42, 0, '2025-11-26 05:00:29', NULL, '2025-11-26 05:00:29'),
(45, 7, 3, 'Handover documentation (as-built drawings, O&M manuals)', 42, 0, '2025-11-26 05:00:29', NULL, '2025-11-26 05:00:29'),
(46, 7, 3, 'Staff training and induction for operators and maintenance teams', 42, 0, '2025-11-26 05:00:29', NULL, '2025-11-26 05:00:29'),
(47, 7, 3, 'Public orientation and commuter education campaigns', 42, 0, '2025-11-26 05:00:29', NULL, '2025-11-26 05:00:29'),
(48, 7, 3, 'Monitoring and evaluation framework setup', 42, 0, '2025-11-26 05:00:29', NULL, '2025-11-26 05:00:29'),
(49, 7, 3, 'Official launch and stakeholder engagement event', 42, 0, '2025-11-26 05:00:29', NULL, '2025-11-26 05:00:29'),

(50, 12, 1, 'Prepare the site for housing development', 0, 0, '2025-11-26 05:00:29', NULL, '2025-11-26 05:00:29'),
(51, 12, 1, 'Land acquisition and zoning verification', 50, 0, '2025-11-26 05:00:29', NULL, '2025-11-26 05:00:29'),
(52, 12, 1, 'Environmental and social impact assessments', 50, 0, '2025-11-26 05:00:29', NULL, '2025-11-26 05:00:29'),
(53, 12, 1, 'Community engagement and relocation planning', 50, 0, '2025-11-26 05:00:29', NULL, '2025-11-26 05:00:29'),
(54, 12, 1, 'Site clearance and grading', 50, 0, '2025-11-26 05:00:29', NULL, '2025-11-26 05:00:29'),
(55, 12, 1, 'Temporary access roads, fencing, and security', 50, 0, '2025-11-26 05:00:29', NULL, '2025-11-26 05:00:29'),
(56, 12, 1, 'Utility connections (water, electricity, sanitation, ICT)', 50, 0, '2025-11-26 05:00:29', NULL, '2025-11-26 05:00:29'),
(57, 12, 1, 'Planning for service continuity and transitional housing if needed', 50, 0, '2025-11-26 05:00:29', NULL, '2025-11-26 05:00:29'),

(58, 12, 2, 'Build housing and supporting infrastructure', 0, 0, '2025-11-26 05:00:29', NULL, '2025-11-26 05:00:29'),
(59, 12, 2, 'Foundation and structural works (housing units, multi-storey buildings)', 58, 0, '2025-11-26 05:00:29', NULL, '2025-11-26 05:00:29'),
(60, 12, 2, 'Installation of basic services (water, sanitation, electricity)', 58, 0, '2025-11-26 05:00:29', NULL, '2025-11-26 05:00:29'),
(61, 12, 2, 'Construction of public amenities (parks, community halls, schools)', 58, 0, '2025-11-26 05:00:29', NULL, '2025-11-26 05:00:29'),
(62, 12, 2, 'Road and transport infrastructure (internal roads, pedestrian paths)', 58, 0, '2025-11-26 05:00:29', NULL, '2025-11-26 05:00:29'),
(63, 12, 2, 'ICT infrastructure for digital inclusion', 58, 0, '2025-11-26 05:00:29', NULL, '2025-11-26 05:00:29'),
(64, 12, 2, 'Safety systems (street lighting, fire safety, surveillance)', 58, 0, '2025-11-26 05:00:29', NULL, '2025-11-26 05:00:29'),
(65, 12, 2, 'Landscaping and green infrastructure (trees, stormwater systems, recreational spaces)', 58, 0, '2025-11-26 05:00:29', NULL, '2025-11-26 05:00:29'),

(66, 12, 3, 'Transfer completed housing and infrastructure to residents and municipalities', 0, 0, '2025-11-26 05:00:29', NULL, '2025-11-26 05:00:29'),
(67, 12, 3, 'Final inspections and compliance testing', 66, 0, '2025-11-26 05:00:29', NULL, '2025-11-26 05:00:29'),
(68, 12, 3, 'Defect resolution and quality assurance', 66, 0, '2025-11-26 05:00:29', NULL, '2025-11-26 05:00:29'),
(69, 12, 3, 'Handover documentation (title deeds, service manuals, O&M plans)', 66, 0, '2025-11-26 05:00:29', NULL, '2025-11-26 05:00:29'),
(70, 12, 3, 'Resident orientation and community integration programs', 66, 0, '2025-11-26 05:00:29', NULL, '2025-11-26 05:00:29'),
(71, 12, 3, 'Monitoring and evaluation framework setup', 66, 0, '2025-11-26 05:00:29', NULL, '2025-11-26 05:00:29'),
(72, 12, 3, 'Official handover and community launch event', 66, 0, '2025-11-26 05:00:29', NULL, '2025-11-26 05:00:29'),

(73, 2, 1, 'Prepare the site and ensure readiness for construction', 0, 0, '2025-11-26 05:00:29', NULL, '2025-11-26 05:00:29'),
(74, 2, 1, 'Site selection and zoning verification', 73, 0, '2025-11-26 05:00:29', NULL, '2025-11-26 05:00:29'),
(75, 2, 1, 'Environmental and health impact assessments', 73, 0, '2025-11-26 05:00:29', NULL, '2025-11-26 05:00:29'),
(76, 2, 1, 'Stakeholder consultations (health workers, communities, planners)', 73, 0, '2025-11-26 05:00:29', NULL, '2025-11-26 05:00:29'),
(77, 2, 1, 'Site clearance and grading', 73, 0, '2025-11-26 05:00:29', NULL, '2025-11-26 05:00:29'),
(78, 2, 1, 'Temporary access roads, fencing, and security', 73, 0, '2025-11-26 05:00:29', NULL, '2025-11-26 05:00:29'),
(79, 2, 1, 'Utility connections (water, electricity, ICT)', 73, 0, '2025-11-26 05:00:29', NULL, '2025-11-26 05:00:29'),
(80, 2, 1, 'Planning for service continuity during construction', 73, 0, '2025-11-26 05:00:29', NULL, '2025-11-26 05:00:29'),

(81, 2, 2, 'Build core health infrastructure', 0, 0, '2025-11-26 05:00:29', NULL, '2025-11-26 05:00:29'),
(82, 2, 2, 'Foundation and structural works (clinics, hospitals, mobile units)', 81, 0, '2025-11-26 05:00:29', NULL, '2025-11-26 05:00:29'),
(83, 2, 2, 'Specialized areas (emergency rooms, operating theatres, maternity wards)', 81, 0, '2025-11-26 05:00:29', NULL, '2025-11-26 05:00:29'),
(84, 2, 2, 'Electrical and mechanical systems (HVAC, backup power, medical gas)', 81, 0, '2025-11-26 05:00:29', NULL, '2025-11-26 05:00:29'),
(85, 2, 2, 'ICT infrastructure for digital health records, telemedicine, diagnostics', 81, 0, '2025-11-26 05:00:29', NULL, '2025-11-26 05:00:29'),
(86, 2, 2, 'Accessibility features (universal design, ramps, signage, inclusive toilets)', 81, 0, '2025-11-26 05:00:29', NULL, '2025-11-26 05:00:29'),
(87, 2, 2, 'Renewable energy systems (solar panels, energy-efficient lighting)', 81, 0, '2025-11-26 05:00:29', NULL, '2025-11-26 05:00:29'),
(88, 2, 2, 'Safety systems (fire suppression, infection control zones, surveillance)', 81, 0, '2025-11-26 05:00:29', NULL, '2025-11-26 05:00:29'),

(89, 2, 3, 'Operationalize the facility and transfer to health service teams', 0, 0, '2025-11-26 05:00:29', NULL, '2025-11-26 05:00:29'),
(90, 2, 3, 'Final inspections and compliance testing', 89, 0, '2025-11-26 05:00:29', NULL, '2025-11-26 05:00:29'),
(91, 2, 3, 'Defect resolution and quality assurance', 89, 0, '2025-11-26 05:00:29', NULL, '2025-11-26 05:00:29'),
(92, 2, 3, 'Handover documentation (as-built drawings, O&M manuals)', 89, 0, '2025-11-26 05:00:29', NULL, '2025-11-26 05:00:29'),
(93, 2, 3, 'Staff training and induction', 89, 0, '2025-11-26 05:00:29', NULL, '2025-11-26 05:00:29'),
(94, 2, 3, 'Community orientation and health education programs', 89, 0, '2025-11-26 05:00:29', NULL, '2025-11-26 05:00:29'),
(95, 2, 3, 'Monitoring and evaluation framework setup', 89, 0, '2025-11-26 05:00:29', NULL, '2025-11-26 05:00:29'),
(96, 2, 3, 'Official handover and launch event', 89, 0, '2025-11-26 05:00:29', NULL, '2025-11-26 05:00:29'),

(97, 16, 1, 'Prepare the site with minimal ecological disruption', 0, 0, '2025-11-26 05:00:29', NULL, '2025-11-26 05:00:29'),
(98, 16, 1, 'Site selection based on environmental sensitivity', 97, 0, '2025-11-26 05:00:29', NULL, '2025-11-26 05:00:29'),
(99, 16, 1, 'Environmental impact assessments (EIA) and heritage screening', 97, 0, '2025-11-26 05:00:29', NULL, '2025-11-26 05:00:29'),
(100, 16, 1, 'Stakeholder consultations (communities, conservation bodies, planners)', 97, 0, '2025-11-26 05:00:29', NULL, '2025-11-26 05:00:29'),
(101, 16, 1, 'Site clearance with biodiversity preservation protocols', 97, 0, '2025-11-26 05:00:29', NULL, '2025-11-26 05:00:29'),
(102, 16, 1, 'Installation of erosion and sediment control systems', 97, 0, '2025-11-26 05:00:29', NULL, '2025-11-26 05:00:29'),
(103, 16, 1, 'Temporary access roads and fencing with minimal footprint', 97, 0, '2025-11-26 05:00:29', NULL, '2025-11-26 05:00:29'),
(104, 16, 1, 'Utility connections using low-impact methods (solar, greywater systems)', 97, 0, '2025-11-26 05:00:29', NULL, '2025-11-26 05:00:29'),

(105, 16, 2, 'Build infrastructure that supports environmental and planning goals', 0, 0, '2025-11-26 05:00:29', NULL, '2025-11-26 05:00:29'),
(106, 16, 2, 'Foundation and structural works using sustainable materials', 105, 0, '2025-11-26 05:00:29', NULL, '2025-11-26 05:00:29'),
(107, 16, 2, 'Construction of green buildings (offices, monitoring stations, eco-centers)', 105, 0, '2025-11-26 05:00:29', NULL, '2025-11-26 05:00:29'),
(108, 16, 2, 'Installation of renewable energy systems (solar, wind, biogas)', 105, 0, '2025-11-26 05:00:29', NULL, '2025-11-26 05:00:29'),
(109, 16, 2, 'Stormwater management systems (bioswales, permeable paving)', 105, 0, '2025-11-26 05:00:29', NULL, '2025-11-26 05:00:29'),
(110, 16, 2, 'Waste management infrastructure (recycling stations, composting units)', 105, 0, '2025-11-26 05:00:29', NULL, '2025-11-26 05:00:29'),
(111, 16, 2, 'ICT systems for environmental monitoring and spatial planning', 105, 0, '2025-11-26 05:00:29', NULL, '2025-11-26 05:00:29'),
(112, 16, 2, 'Landscaping with indigenous vegetation and habitat restoration', 105, 0, '2025-11-26 05:00:29', NULL, '2025-11-26 05:00:29'),

(113, 16, 3, 'Operationalize the facility and integrate with planning systems', 0, 0, '2025-11-26 05:00:29', NULL, '2025-11-26 05:00:29'),
(114, 16, 3, 'Final inspections and environmental compliance audits', 113, 0, '2025-11-26 05:00:29', NULL, '2025-11-26 05:00:29'),
(115, 16, 3, 'Defect resolution and quality assurance', 113, 0, '2025-11-26 05:00:29', NULL, '2025-11-26 05:00:29'),
(116, 16, 3, 'Handover documentation (as-built drawings, environmental management plans)', 113, 0, '2025-11-26 05:00:29', NULL, '2025-11-26 05:00:29'),
(117, 16, 3, 'Staff training on sustainable operations and monitoring tools', 113, 0, '2025-11-26 05:00:29', NULL, '2025-11-26 05:00:29'),
(118, 16, 3, 'Community orientation and environmental education programs', 113, 0, '2025-11-26 05:00:29', NULL, '2025-11-26 05:00:29'),
(119, 16, 3, 'Monitoring and evaluation framework setup', 113, 0, '2025-11-26 05:00:29', NULL, '2025-11-26 05:00:29'),
(120, 16, 3, 'Official handover and awareness launch event', 113, 0, '2025-11-26 05:00:29', NULL, '2025-11-26 05:00:29'),

(121, 3, 1, 'Prepare the site and ensure readiness for construction', 0, 0, '2025-11-26 05:00:29', NULL, '2025-11-26 05:00:29'),
(122, 3, 1, 'Site selection and zoning verification', 121, 0, '2025-11-26 05:00:29', NULL, '2025-11-26 05:00:29'),
(123, 3, 1, 'Environmental and social impact assessments', 121, 0, '2025-11-26 05:00:29', NULL, '2025-11-26 05:00:29'),
(124, 3, 1, 'Stakeholder consultations (school boards, communities, learners)', 121, 0, '2025-11-26 05:00:29', NULL, '2025-11-26 05:00:29'),
(125, 3, 1, 'Site clearance and grading', 121, 0, '2025-11-26 05:00:29', NULL, '2025-11-26 05:00:29'),
(126, 3, 1, 'Temporary access roads, fencing, and security', 121, 0, '2025-11-26 05:00:29', NULL, '2025-11-26 05:00:29'),
(127, 3, 1, 'Utility connections (water, electricity, ICT)', 121, 0, '2025-11-26 05:00:29', NULL, '2025-11-26 05:00:29'),
(128, 3, 1, 'Planning for learning continuity during construction', 121, 0, '2025-11-26 05:00:29', NULL, '2025-11-26 05:00:29'),

(129, 3, 2, 'Build core education infrastructure', 0, 0, '2025-11-26 05:00:29', NULL, '2025-11-26 05:00:29'),
(130, 3, 2, 'Foundation and structural works (classrooms, admin blocks, libraries)', 129, 0, '2025-11-26 05:00:29', NULL, '2025-11-26 05:00:29'),
(131, 3, 2, 'Specialized spaces (science labs, computer rooms, inclusive education units)', 129, 0, '2025-11-26 05:00:29', NULL, '2025-11-26 05:00:29'),
(132, 3, 2, 'ICT infrastructure for e-learning, smart boards, and connectivity', 129, 0, '2025-11-26 05:00:29', NULL, '2025-11-26 05:00:29'),
(133, 3, 2, 'Accessibility features (universal design, ramps, signage, inclusive toilets)', 129, 0, '2025-11-26 05:00:29', NULL, '2025-11-26 05:00:29'),
(134, 3, 2, 'Renewable energy systems (solar panels, energy-efficient lighting)', 129, 0, '2025-11-26 05:00:29', NULL, '2025-11-26 05:00:29'),
(135, 3, 2, 'Safety systems (fire suppression, emergency exits, surveillance)', 129, 0, '2025-11-26 05:00:29', NULL, '2025-11-26 05:00:29'),
(136, 3, 2, 'Landscaping and green infrastructure (playgrounds, gardens, stormwater systems)', 129, 0, '2025-11-26 05:00:29', NULL, '2025-11-26 05:00:29'),

(137, 3, 3, 'Operationalize the facility and transfer to education teams', 0, 0, '2025-11-26 05:00:29', NULL, '2025-11-26 05:00:29'),
(138, 3, 3, 'Final inspections and compliance testing', 137, 0, '2025-11-26 05:00:29', NULL, '2025-11-26 05:00:29'),
(139, 3, 3, 'Defect resolution and quality assurance', 137, 0, '2025-11-26 05:00:29', NULL, '2025-11-26 05:00:29'),
(140, 3, 3, 'Handover documentation (as-built drawings, O&M manuals)', 137, 0, '2025-11-26 05:00:29', NULL, '2025-11-26 05:00:29'),
(141, 3, 3, 'Staff training and induction', 137, 0, '2025-11-26 05:00:29', NULL, '2025-11-26 05:00:29'),
(142, 3, 3, 'Learner and community orientation', 137, 0, '2025-11-26 05:00:29', NULL, '2025-11-26 05:00:29'),
(143, 3, 3, 'Monitoring and evaluation framework setup', 137, 0, '2025-11-26 05:00:29', NULL, '2025-11-26 05:00:29'),
(144, 3, 3, 'Official handover and school opening event', 137, 0, '2025-11-26 05:00:29', NULL, '2025-11-26 05:00:29'),

(145, 10, 1, 'Prepare the site for construction and ensure regulatory readiness', 0, 0, '2025-11-26 05:00:29', NULL, '2025-11-26 05:00:29'),
(146, 10, 1, 'Site selection and zoning verification', 145, 0, '2025-11-26 05:00:29', NULL, '2025-11-26 05:00:29'),
(147, 10, 1, 'Environmental and economic impact assessments', 145, 0, '2025-11-26 05:00:29', NULL, '2025-11-26 05:00:29'),
(148, 10, 1, 'Stakeholder consultations (local businesses, tourism boards, communities)', 145, 0, '2025-11-26 05:00:29', NULL, '2025-11-26 05:00:29'),
(149, 10, 1, 'Site clearance and grading', 145, 0, '2025-11-26 05:00:29', NULL, '2025-11-26 05:00:29'),
(150, 10, 1, 'Temporary access roads, fencing, and security', 145, 0, '2025-11-26 05:00:29', NULL, '2025-11-26 05:00:29'),
(151, 10, 1, 'Utility connections (water, electricity, ICT)', 145, 0, '2025-11-26 05:00:29', NULL, '2025-11-26 05:00:29'),
(152, 10, 1, 'Planning for business continuity and local engagement', 145, 0, '2025-11-26 05:00:29', NULL, '2025-11-26 05:00:29'),

(153, 10, 2, 'Build infrastructure that supports economic and tourism development', 0, 0, '2025-11-26 05:00:29', NULL, '2025-11-26 05:00:29'),
(154, 10, 2, 'Foundation and structural works (business parks, tourism centers, marketplaces)', 153, 0, '2025-11-26 05:00:29', NULL, '2025-11-26 05:00:29'),
(155, 10, 2, 'Construction of tourism amenities (visitor centers, trails, signage, rest areas)', 153, 0, '2025-11-26 05:00:29', NULL, '2025-11-26 05:00:29'),
(156, 10, 2, 'ICT infrastructure for digital tourism and smart business services', 153, 0, '2025-11-26 05:00:29', NULL, '2025-11-26 05:00:29'),
(157, 10, 2, 'Accessibility features (universal design, transport links, signage)', 153, 0, '2025-11-26 05:00:29', NULL, '2025-11-26 05:00:29'),
(158, 10, 2, 'Renewable energy systems and green building practices', 153, 0, '2025-11-26 05:00:29', NULL, '2025-11-26 05:00:29'),
(159, 10, 2, 'Safety systems (fire suppression, surveillance, crowd control)', 153, 0, '2025-11-26 05:00:29', NULL, '2025-11-26 05:00:29'),
(160, 10, 2, 'Landscaping and beautification (green spaces, public art, lighting)', 153, 0, '2025-11-26 05:00:29', NULL, '2025-11-26 05:00:29'),

(161, 10, 3, 'Operationalize the facility and transfer to economic development teams or operators', 0, 0, '2025-11-26 05:00:29', NULL, '2025-11-26 05:00:29'),
(162, 10, 3, 'Final inspections and compliance testing', 161, 0, '2025-11-26 05:00:29', NULL, '2025-11-26 05:00:29'),
(163, 10, 3, 'Defect resolution and quality assurance', 161, 0, '2025-11-26 05:00:29', NULL, '2025-11-26 05:00:29'),
(164, 10, 3, 'Handover documentation (as-built drawings, O&M manuals)', 161, 0, '2025-11-26 05:00:29', NULL, '2025-11-26 05:00:29'),
(165, 10, 3, 'Staff and operator training', 161, 0, '2025-11-26 05:00:29', NULL, '2025-11-26 05:00:29'),
(166, 10, 3, 'Community orientation and business activation programs', 161, 0, '2025-11-26 05:00:29', NULL, '2025-11-26 05:00:29'),
(167, 10, 3, 'Monitoring and evaluation framework setup', 161, 0, '2025-11-26 05:00:29', NULL, '2025-11-26 05:00:29'),
(168, 10, 3, 'Official launch and promotional event', 161, 0, '2025-11-26 05:00:29', NULL, '2025-11-26 05:00:29'),

(169, 15, 1, 'Prepare the site and ensure readiness for construction', 0, 0, '2025-11-26 05:00:29', NULL, '2025-11-26 05:00:29'),
(170, 15, 1, 'Site selection and zoning verification', 169, 0, '2025-11-26 05:00:29', NULL, '2025-11-26 05:00:29'),
(171, 15, 1, 'Environmental and heritage impact assessments', 169, 0, '2025-11-26 05:00:29', NULL, '2025-11-26 05:00:29'),
(172, 15, 1, 'Community engagement and stakeholder consultations', 169, 0, '2025-11-26 05:00:29', NULL, '2025-11-26 05:00:29'),
(173, 15, 1, 'Site clearance and grading', 169, 0, '2025-11-26 05:00:29', NULL, '2025-11-26 05:00:29'),
(174, 15, 1, 'Temporary access roads, fencing, and security', 169, 0, '2025-11-26 05:00:29', NULL, '2025-11-26 05:00:29'),
(175, 15, 1, 'Utility connections (water, electricity, ICT)', 169, 0, '2025-11-26 05:00:29', NULL, '2025-11-26 05:00:29'),
(176, 15, 1, 'Planning for service continuity during construction', 169, 0, '2025-11-26 05:00:29', NULL, '2025-11-26 05:00:29'),

(177, 15, 2, 'Build core infrastructure for cultural and sports activities', 0, 0, '2025-11-26 05:00:29', NULL, '2025-11-26 05:00:29'),
(178, 15, 2, 'Foundation and structural works (community halls, libraries, museums, sports fields)', 177, 0, '2025-11-26 05:00:29', NULL, '2025-11-26 05:00:29'),
(179, 15, 2, 'Indoor and outdoor recreational spaces (courts, stages, amphitheaters)', 177, 0, '2025-11-26 05:00:29', NULL, '2025-11-26 05:00:29'),
(180, 15, 2, 'Accessibility features (universal design, ramps, signage)', 177, 0, '2025-11-26 05:00:29', NULL, '2025-11-26 05:00:29'),
(181, 15, 2, 'Electrical and mechanical systems (lighting, sound, HVAC, backup power)', 177, 0, '2025-11-26 05:00:29', NULL, '2025-11-26 05:00:29'),
(182, 15, 2, 'ICT infrastructure for digital exhibitions, e-learning, and event management', 177, 0, '2025-11-26 05:00:29', NULL, '2025-11-26 05:00:29'),
(183, 15, 2, 'Safety systems (fire suppression, crowd control, surveillance)', 177, 0, '2025-11-26 05:00:29', NULL, '2025-11-26 05:00:29'),
(184, 15, 2, 'Landscaping and green infrastructure (gardens, walking paths, stormwater systems)', 177, 0, '2025-11-26 05:00:29', NULL, '2025-11-26 05:00:29'),

(185, 15, 3, 'Operationalize the facility and transfer to service teams', 0, 0, '2025-11-26 05:00:29', NULL, '2025-11-26 05:00:29'),
(186, 15, 3, 'Final inspections and compliance testing', 185, 0, '2025-11-26 05:00:29', NULL, '2025-11-26 05:00:29'),
(187, 15, 3, 'Defect resolution and quality assurance', 185, 0, '2025-11-26 05:00:29', NULL, '2025-11-26 05:00:29'),
(188, 15, 3, 'Handover documentation (as-built drawings, O&M manuals)', 185, 0, '2025-11-26 05:00:29', NULL, '2025-11-26 05:00:29'),
(189, 15, 3, 'Staff training and induction', 185, 0, '2025-11-26 05:00:29', NULL, '2025-11-26 05:00:29'),
(190, 15, 3, 'Community orientation and program launch', 185, 0, '2025-11-26 05:00:29', NULL, '2025-11-26 05:00:29'),
(191, 15, 3, 'Monitoring and evaluation framework setup', 185, 0, '2025-11-26 05:00:29', NULL, '2025-11-26 05:00:29'),
(192, 15, 3, 'Official handover and cultural/sporting launch event', 185, 0, '2025-11-26 05:00:29', NULL, '2025-11-26 05:00:29'),

(193, 1, 1, 'Prepare the site for construction and ensure regulatory compliance', 0, 0, '2025-11-26 05:00:29', NULL, '2025-11-26 05:00:29'),
(194, 1, 1, 'Land acquisition and zoning verification', 193, 0, '2025-11-26 05:00:29', NULL, '2025-11-26 05:00:29'),
(195, 1, 1, 'Environmental impact assessments', 193, 0, '2025-11-26 05:00:29', NULL, '2025-11-26 05:00:29'),
(196, 1, 1, 'Soil and water testing', 193, 0, '2025-11-26 05:00:29', NULL, '2025-11-26 05:00:29'),
(197, 1, 1, 'Community engagement and stakeholder consultations', 193, 0, '2025-11-26 05:00:29', NULL, '2025-11-26 05:00:29'),
(198, 1, 1, 'Site clearance and grading', 193, 0, '2025-11-26 05:00:29', NULL, '2025-11-26 05:00:29'),
(199, 1, 1, 'Temporary access roads and fencing', 193, 0, '2025-11-26 05:00:29', NULL, '2025-11-26 05:00:29'),
(200, 1, 1, 'Utility connections (water, electricity, ICT)', 193, 0, '2025-11-26 05:00:29', NULL, '2025-11-26 05:00:29'),

(201, 1, 2, 'Build core infrastructure to support agricultural operations', 0, 0, '2025-11-26 05:00:29', NULL, '2025-11-26 05:00:29'),
(202, 1, 2, 'Foundation and structural works (storage, processing units, admin buildings)', 201, 0, '2025-11-26 05:00:29', NULL, '2025-11-26 05:00:29'),
(203, 1, 2, 'Irrigation systems and water storage facilities', 201, 0, '2025-11-26 05:00:29', NULL, '2025-11-26 05:00:29'),
(204, 1, 2, 'Renewable energy installations (solar, biogas)', 201, 0, '2025-11-26 05:00:29', NULL, '2025-11-26 05:00:29'),
(205, 1, 2, 'Cold chain and logistics infrastructure', 201, 0, '2025-11-26 05:00:29', NULL, '2025-11-26 05:00:29'),
(206, 1, 2, 'ICT infrastructure for smart farming', 201, 0, '2025-11-26 05:00:29', NULL, '2025-11-26 05:00:29'),
(207, 1, 2, 'Safety systems and compliance inspections', 201, 0, '2025-11-26 05:00:29', NULL, '2025-11-26 05:00:29'),
(208, 1, 2, 'Landscaping and erosion control', 201, 0, '2025-11-26 05:00:29', NULL, '2025-11-26 05:00:29'),

(209, 1, 3, 'Operationalize the infrastructure and transfer to managing entities', 0, 0, '2025-11-26 05:00:29', NULL, '2025-11-26 05:00:29'),
(210, 1, 3, 'Final inspections and performance testing', 209, 0, '2025-11-26 05:00:29', NULL, '2025-11-26 05:00:29'),
(211, 1, 3, 'Defect resolution and quality assurance', 209, 0, '2025-11-26 05:00:29', NULL, '2025-11-26 05:00:29'),
(212, 1, 3, 'Handover documentation (as-built drawings, manuals)', 209, 0, '2025-11-26 05:00:29', NULL, '2025-11-26 05:00:29'),
(213, 1, 3, 'Training for facility operators and farmers', 209, 0, '2025-11-26 05:00:29', NULL, '2025-11-26 05:00:29'),
(214, 1, 3, 'Community induction and support programs', 209, 0, '2025-11-26 05:00:29', NULL, '2025-11-26 05:00:29'),
(215, 1, 3, 'Monitoring and evaluation framework setup', 209, 0, '2025-11-26 05:00:29', NULL, '2025-11-26 05:00:29'),
(216, 1, 3, 'Official handover ceremony', 209, 0, '2025-11-26 05:00:29', NULL, '2025-11-26 05:00:29'),

(217, 11, 1, 'Prepare the site for construction with community and environmental considerations', 0, 0, '2025-11-26 05:00:29', NULL, '2025-11-26 05:00:29'),
(218, 11, 1, 'Site selection based on community needs and accessibility', 217, 0, '2025-11-26 05:00:29', NULL, '2025-11-26 05:00:29'),
(219, 11, 1, 'Environmental and social impact assessments', 217, 0, '2025-11-26 05:00:29', NULL, '2025-11-26 05:00:29'),
(220, 11, 1, 'Stakeholder engagement (NGOs, community leaders, service users)', 217, 0, '2025-11-26 05:00:29', NULL, '2025-11-26 05:00:29'),
(221, 11, 1, 'Site clearance and grading', 217, 0, '2025-11-26 05:00:29', NULL, '2025-11-26 05:00:29'),
(222, 11, 1, 'Temporary access roads, fencing, and security', 217, 0, '2025-11-26 05:00:29', NULL, '2025-11-26 05:00:29'),
(223, 11, 1, 'Utility connections (water, electricity, sanitation, ICT)', 217, 0, '2025-11-26 05:00:29', NULL, '2025-11-26 05:00:29'),
(224, 11, 1, 'Planning for service continuity (temporary facilities or mobile units)', 217, 0, '2025-11-26 05:00:29', NULL, '2025-11-26 05:00:29'),

(225, 11, 2, 'Build infrastructure that supports social development services', 0, 0, '2025-11-26 05:00:29', NULL, '2025-11-26 05:00:29'),
(226, 11, 2, 'Foundation and structural works (ECD centres, shelters, youth care centres, service offices)', 225, 0, '2025-11-26 05:00:29', NULL, '2025-11-26 05:00:29'),
(227, 11, 2, 'Construction of multipurpose spaces (training rooms, counselling areas, kitchens)', 225, 0, '2025-11-26 05:00:29', NULL, '2025-11-26 05:00:29'),
(228, 11, 2, 'Accessibility features (universal design, ramps, signage, inclusive toilets)', 225, 0, '2025-11-26 05:00:29', NULL, '2025-11-26 05:00:29'),
(229, 11, 2, 'ICT infrastructure for case management, digital learning, and remote services', 225, 0, '2025-11-26 05:00:29', NULL, '2025-11-26 05:00:29'),
(230, 11, 2, 'Renewable energy systems (solar panels, energy-efficient lighting)', 225, 0, '2025-11-26 05:00:29', NULL, '2025-11-26 05:00:29'),
(231, 11, 2, 'Safety systems (fire suppression, secure access, child protection features)', 225, 0, '2025-11-26 05:00:29', NULL, '2025-11-26 05:00:29'),
(232, 11, 2, 'Landscaping and community integration (playgrounds, gardens, safe outdoor areas)', 225, 0, '2025-11-26 05:00:29', NULL, '2025-11-26 05:00:29'),

(233, 11, 3, 'Operationalize the facility and transfer to service providers or departmental teams', 0, 0, '2025-11-26 05:00:29', NULL, '2025-11-26 05:00:29'),
(234, 11, 3, 'Final inspections and compliance testing', 233, 0, '2025-11-26 05:00:29', NULL, '2025-11-26 05:00:29'),
(235, 11, 3, 'Defect resolution and quality assurance', 233, 0, '2025-11-26 05:00:29', NULL, '2025-11-26 05:00:29'),
(236, 11, 3, 'Handover documentation (as-built drawings, O&M manuals, service protocols)', 233, 0, '2025-11-26 05:00:29', NULL, '2025-11-26 05:00:29'),
(237, 11, 3, 'Staff training and induction (social workers, caregivers, admin staff)', 233, 0, '2025-11-26 05:00:29', NULL, '2025-11-26 05:00:29'),
(238, 11, 3, 'Community orientation and awareness campaigns', 233, 0, '2025-11-26 05:00:29', NULL, '2025-11-26 05:00:29'),
(239, 11, 3, 'Monitoring and evaluation framework setup', 233, 0, '2025-11-26 05:00:29', NULL, '2025-11-26 05:00:29'),
(240, 11, 3, 'Official handover and community launch event', 233, 0, '2025-11-26 05:00:29', NULL, '2025-11-26 05:00:29'),

(241, 4, 1, 'Prepare the site for construction and ensure regulatory readiness', 0, 0, '2025-11-26 05:00:29', NULL, '2025-11-26 05:00:29'),
(242, 4, 1, 'Site selection and zoning verification', 241, 0, '2025-11-26 05:00:29', NULL, '2025-11-26 05:00:29'),
(243, 4, 1, 'Environmental and geotechnical assessments', 241, 0, '2025-11-26 05:00:29', NULL, '2025-11-26 05:00:29'),
(244, 4, 1, 'Stakeholder consultations (municipalities, engineers, communities)', 241, 0, '2025-11-26 05:00:29', NULL, '2025-11-26 05:00:29'),
(245, 4, 1, 'Site clearance and grading', 241, 0, '2025-11-26 05:00:29', NULL, '2025-11-26 05:00:29'),
(246, 4, 1, 'Temporary access roads, fencing, and security', 241, 0, '2025-11-26 05:00:29', NULL, '2025-11-26 05:00:29'),
(247, 4, 1, 'Utility connections (water, electricity, ICT)', 241, 0, '2025-11-26 05:00:29', NULL, '2025-11-26 05:00:29'),
(248, 4, 1, 'Planning for service continuity and traffic management', 241, 0, '2025-11-26 05:00:29', NULL, '2025-11-26 05:00:29'),

(249, 4, 2, 'Build core infrastructure assets', 0, 0, '2025-11-26 05:00:29', NULL, '2025-11-26 05:00:29'),
(250, 4, 2, 'Foundation and structural works (roads, bridges, public buildings)', 249, 0, '2025-11-26 05:00:29', NULL, '2025-11-26 05:00:29'),
(251, 4, 2, 'Installation of utility systems (stormwater, sewerage, electrical)', 249, 0, '2025-11-26 05:00:29', NULL, '2025-11-26 05:00:29'),
(252, 4, 2, 'Construction of transport links and logistics corridors', 249, 0, '2025-11-26 05:00:29', NULL, '2025-11-26 05:00:29'),
(253, 4, 2, 'ICT infrastructure for smart systems and asset monitoring', 249, 0, '2025-11-26 05:00:29', NULL, '2025-11-26 05:00:29'),
(254, 4, 2, 'Accessibility features (universal design, signage, transport integration)', 249, 0, '2025-11-26 05:00:29', NULL, '2025-11-26 05:00:29'),
(255, 4, 2, 'Renewable energy systems (solar, energy-efficient lighting)', 249, 0, '2025-11-26 05:00:29', NULL, '2025-11-26 05:00:29'),
(256, 4, 2, 'Safety systems (fire suppression, structural integrity, surveillance)', 249, 0, '2025-11-26 05:00:29', NULL, '2025-11-26 05:00:29'),
(257, 4, 2, 'Landscaping and urban integration (green buffers, pedestrian zones)', 249, 0, '2025-11-26 05:00:29', NULL, '2025-11-26 05:00:29'),

(258, 4, 3, 'Operationalize the infrastructure and transfer to managing entities', 0, 0, '2025-11-26 05:00:29', NULL, '2025-11-26 05:00:29'),
(259, 4, 3, 'Final inspections and compliance testing', 258, 0, '2025-11-26 05:00:29', NULL, '2025-11-26 05:00:29'),
(260, 4, 3, 'Defect resolution and quality assurance', 258, 0, '2025-11-26 05:00:29', NULL, '2025-11-26 05:00:29'),
(261, 4, 3, 'Handover documentation (as-built drawings, O&M manuals)', 258, 0, '2025-11-26 05:00:29', NULL, '2025-11-26 05:00:29'),
(262, 4, 3, 'Staff training and induction (municipal teams, operators)', 258, 0, '2025-11-26 05:00:29', NULL, '2025-11-26 05:00:29'),
(263, 4, 3, 'Community orientation and public awareness campaigns', 258, 0, '2025-11-26 05:00:29', NULL, '2025-11-26 05:00:29'),
(264, 4, 3, 'Monitoring and evaluation framework setup', 258, 0, '2025-11-26 05:00:29', NULL, '2025-11-26 05:00:29'),
(265, 4, 3, 'Official launch and stakeholder engagement event', 258, 0, '2025-11-26 05:00:29', NULL, '2025-11-26 05:00:29');


-- DATE 31-12-2025 Insert Proof of Evidence records
INSERT INTO `tbl_proof_of_evidence`
(`poe_name`, `is_active`, `created_by`, `updated_by`, `creation_date`, `updation_date`)
VALUES
('Site Selection Report', '1', 110, NULL, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP),
('Zoning Compliance Certificates', '1', 110, NULL, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP),
('GIS maps', '1', 110, NULL, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP),
('EIA Report', '1', 110, NULL, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP),
('Environmental Authorisation', '1', 110, NULL, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP),
('Geotechnical Investigation Report', '1', 110, NULL, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP),
('Mitigation Plan', '1', 110, NULL, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP),
('Engagement Plan', '1', 110, NULL, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP),
('Minutes & Attendance', '1', 110, NULL, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP),
('Issues–Response Log', '1', 110, NULL, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP),
('Site Clearance Completion Certificates', '1', 110, NULL, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP),
('Grading and Earthworks Report', '1', 110, NULL, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP),
('Health and Safety Compliance Documentation', '1', 110, NULL, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP),
('Photographic Evidence of Cleared Site', '1', 110, NULL, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP),
('Temporary Works Plan', '1', 110, NULL, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP),
('Security and Access Control Plan', '1', 110, NULL, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP),
('Traffic Diversion and Signage Layout', '1', 110, NULL, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP),
('Completion Certificates for Temporary Infrastructure', '1', 110, NULL, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP),
('Utility Connection Applications and Approvals', '1', 110, NULL, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP),
('Service Connection Certificates', '1', 110, NULL, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP),
('Utility Layout Drawings', '1', 110, NULL, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP),
('Testing and Commissioning Reports', '1', 110, NULL, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP),
('Service Continuity Strategy Document', '1', 110, NULL, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP),
('Traffic Management Plan', '1', 110, NULL, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP),
('Risk and Contingency Plan', '1', 110, NULL, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP),
('Approval from Relevant Authorities (Transport, Municipal)', '1', 110, NULL, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP),
('Structural Design', '1', 110, NULL, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP),
('QA/Compliance', '1', 110, NULL, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP),
('As-Builts', '1', 110, NULL, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP),
('Completion Certificates', '1', 110, NULL, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP),
('Installation Plans', '1', 110, NULL, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP),
('Connection Certificates', '1', 110, NULL, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP),
('O&M Manuals', '1', 110, NULL, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP),
('Corridor Design Docs', '1', 110, NULL, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP),
('Progress Reports', '1', 110, NULL, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP),
('Road Safety Certificates', '1', 110, NULL, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP),
('Traffic Flow Analysis', '1', 110, NULL, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP),
('ICT Network Design', '1', 110, NULL, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP),
('Integration & Testing', '1', 110, NULL, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP),
('Cybersecurity Compliance', '1', 110, NULL, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP),
('Asset Monitoring Config', '1', 110, NULL, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP),
('Universal Design Compliance', '1', 110, NULL, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP),
('Accessibility Audit Certificates', '1', 110, NULL, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP),
('Signage Layout', '1', 110, NULL, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP),
('RE Design Specs', '1', 110, NULL, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP),
('Commissioning Reports', '1', 110, NULL, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP),
('Energy Compliance', '1', 110, NULL, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP),
('Performance Monitoring', '1', 110, NULL, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP),
('Fire System Certificates', '1', 110, NULL, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP),
('Structural Integrity Tests', '1', 110, NULL, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP),
('H&S Compliance', '1', 110, NULL, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP),
('Surveillance Install Docs', '1', 110, NULL, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP),
('Landscape Plans', '1', 110, NULL, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP),
('Environmental Compliance', '1', 110, NULL, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP),
('Integration Strategy', '1', 110, NULL, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP),
('Handover Report', '1', 110, NULL, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP),
('Final Inspection Reports', '1', 110, NULL, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP),
('Compliance Certificates', '1', 110, NULL, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP),
('T&C Records', '1', 110, NULL, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP),
('Regulator Sign-offs', '1', 110, NULL, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP),
('Snag List', '1', 110, NULL, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP),
('Defect Resolution Log', '1', 110, NULL, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP),
('QA Certification', '1', 110, NULL, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP),
('Rectification Certificates', '1', 110, NULL, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP),
('Asset Register', '1', 110, NULL, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP),
('Warranties', '1', 110, NULL, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP),
('Training Plan', '1', 110, NULL, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP),
('Materials', '1', 110, NULL, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP),
('Attendance', '1', 110, NULL, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP),
('Competency Certificates', '1', 110, NULL, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP),
('Awareness Materials', '1', 110, NULL, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP),
('Impact Report', '1', 110, NULL, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP),
('M&E Framework', '1', 110, NULL, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP),
('KPIs & Baseline', '1', 110, NULL, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP),
('Reporting Templates', '1', 110, NULL, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP),
('Oversight Plan', '1', 110, NULL, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP),
('Event Program', '1', 110, NULL, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP),
('Invitation List', '1', 110, NULL, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP),
('Media Pack', '1', 110, NULL, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP),
('Post-Event Report', '1', 110, NULL, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP);

-- DATE 31-12-2025 Link Proof of Evidence to Project Tasks
INSERT INTO tbl_poe_task (poe_id, dept_task_id, created_by, updated_by, creation_date, updation_date) VALUES
-- Task 2
(1, 242, 110, NULL, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP),
(2, 242, 110, NULL, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP),
(3, 242, 110, NULL, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP),

-- Task 3
(4, 243, 110, NULL, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP),
(5, 243, 110, NULL, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP),
(6, 243, 110, NULL, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP),
(7, 243, 110, NULL, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP),

-- Task 4
(8, 244, 110, NULL, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP),
(9, 244, 110, NULL, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP),
(10, 244, 110, NULL, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP),

-- Task 5
(11, 245, 110, NULL, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP),
(12, 245, 110, NULL, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP),
(13, 245, 110, NULL, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP),
(14, 245, 110, NULL, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP),

-- Task 6
(15, 246, 110, NULL, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP),
(16, 246, 110, NULL, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP),
(17, 246, 110, NULL, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP),
(18, 246, 110, NULL, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP),

-- Task 7
(19, 247, 110, NULL, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP),
(20, 247, 110, NULL, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP),
(21, 247, 110, NULL, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP),
(22, 247, 110, NULL, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP),

-- Task 8
(23, 248, 110, NULL, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP),
(24, 248, 110, NULL, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP),
(25, 248, 110, NULL, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP),
(26, 248, 110, NULL, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP),

-- Task 10
(27, 250, 110, NULL, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP),
(28, 250, 110, NULL, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP),
(29, 250, 110, NULL, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP),
(30, 250, 110, NULL, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP),

-- Task 11
(34, 251, 110, NULL, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP),
(35, 251, 110, NULL, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP),
(36, 251, 110, NULL, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP),
(37, 251, 110, NULL, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP),

-- Task 12
(31, 252, 110, NULL, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP),
(22, 252, 110, NULL, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP),
(32, 252, 110, NULL, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP),
(33, 252, 110, NULL, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP),

-- Task 13
(38, 253, 110, NULL, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP),
(39, 253, 110, NULL, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP),
(40, 253, 110, NULL, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP),
(41, 253, 110, NULL, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP),

-- Task 14
(42, 254, 110, NULL, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP),
(43, 254, 110, NULL, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP),
(44, 254, 110, NULL, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP),

-- Task 15
(45, 255, 110, NULL, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP),
(46, 255, 110, NULL, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP),
(47, 255, 110, NULL, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP),
(48, 255, 110, NULL, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP),

-- Task 16
(49, 256, 110, NULL, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP),
(50, 256, 110, NULL, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP),
(51, 256, 110, NULL, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP),
(52, 256, 110, NULL, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP),

-- Task 26
(53, 257, 110, NULL, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP),
(54, 257, 110, NULL, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP),
(55, 257, 110, NULL, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP),
(56, 257, 110, NULL, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP),

-- Task 18
(57, 259, 110, NULL, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP),
(58, 259, 110, NULL, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP),
(59, 259, 110, NULL, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP),
(60, 259, 110, NULL, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP),

-- Task 19
(61, 260, 110, NULL, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP),
(62, 260, 110, NULL, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP),
(63, 260, 110, NULL, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP),
(64, 260, 110, NULL, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP),

-- Task 20
(29, 261, 110, NULL, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP),
(33, 261, 110, NULL, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP),
(65, 261, 110, NULL, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP),
(66, 261, 110, NULL, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP),

-- Task 21
(67, 262, 110, NULL, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP),
(68, 262, 110, NULL, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP),
(69, 262, 110, NULL, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP),
(70, 262, 110, NULL, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP),

-- Task 22
(8, 263, 110, NULL, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP),
(71, 263, 110, NULL, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP),
(69, 263, 110, NULL, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP),
(72, 263, 110, NULL, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP),

-- Task 23
(73, 264, 110, NULL, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP),
(74, 264, 110, NULL, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP),
(75, 264, 110, NULL, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP),
(76, 264, 110, NULL, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP),

-- Task 24
(77, 265, 110, NULL, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP),
(78, 265, 110, NULL, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP),
(79, 265, 110, NULL, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP),
(80, 265, 110, NULL, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP);

-- Date 30-12-2025 create trigger for role right association
DROP TRIGGER IF EXISTS `tr_role_right_association_insert`;
DELIMITER $$
CREATE TRIGGER `tr_role_right_association_insert` AFTER INSERT ON `tbl_role_master` FOR EACH ROW BEGIN

  DELETE FROM tbl_role_right_association where role_id=new.role_id;

  INSERT INTO tbl_role_right_association(role_id, right_id, value)  

   SELECT new.role_id, b.right_id,-1 FROM tbl_right_master as b;

END
$$
DELIMITER ;

-- DATE 30-12-2025 Insert Responsible Party Roles
INSERT IGNORE INTO tbl_role_master
(role_id, app_id, role_type, role_name, role_short_name, isAdmin, isActive, creation_date, created_by)
VALUES
(25, 1, 'responsible_party', 'Clerk of Works', 'Clerk of Works', 0, 1, NOW(), 1),
(26, 1, 'responsible_party', 'Communications', 'Communications', 0, 1, NOW(), 1),
(27, 1, 'responsible_party', 'Consultants', 'Consultants', 0, 1, NOW(), 1),
(28, 1, 'responsible_party', 'Contractors', 'Contractors', 0, 1, NOW(), 1),
(29, 1, 'responsible_party', 'DOI', 'DOI', 0, 1, NOW(), 1),
(30, 1, 'responsible_party', 'DOI Engineering', 'DOI Engineering', 0, 1, NOW(), 1),
(31, 1, 'responsible_party', 'DOI Env/Geotech', 'DOI Env/Geotech', 0, 1, NOW(), 1),
(32, 1, 'responsible_party', 'DOI ICT', 'DOI ICT', 0, 1, NOW(), 1),
(33, 1, 'responsible_party', 'DOI Planning', 'DOI Planning', 0, 1, NOW(), 1),
(34, 1, 'responsible_party', 'DoM', 'DoM', 0, 1, NOW(), 1),
(35, 1, 'responsible_party', 'DoM Planning', 'DoM Planning', 0, 1, NOW(), 1),
(36, 1, 'responsible_party', 'Energy EPC', 'Energy EPC', 0, 1, NOW(), 1),
(37, 1, 'responsible_party', 'Landscape Architect', 'Landscape Architect', 0, 1, NOW(), 1),
(38, 1, 'responsible_party', 'Municipal Planning', 'Municipal Planning', 0, 1, NOW(), 1),
(39, 1, 'responsible_party', 'Municipal Transport', 'Municipal Transport', 0, 1, NOW(), 1),
(40, 1, 'responsible_party', 'Occupational Access Specialist', 'Occupational Access Specialist', 0, 1, NOW(), 1),
(41, 1, 'responsible_party', 'OEMs', 'OEMs', 0, 1, NOW(), 1),
(42, 1, 'responsible_party', 'OHS', 'OHS', 0, 1, NOW(), 1),
(43, 1, 'responsible_party', 'SITA/Service Providers', 'SITA/Service Providers', 0, 1, NOW(), 1),
(44, 1, 'responsible_party', 'Treasury', 'Treasury', 0, 1, NOW(), 1),
(45, 1, 'responsible_party', 'Utilities', 'Utilities', 0, 1, NOW(), 1);

-- DATE 30-12-2025 delete Department Roles
DELETE FROM `tbl_department_roles` WHERE `department_id` = 4;

-- DATE 30-12-2025 Insert Department Roles
INSERT INTO `tbl_department_roles` (`department_role_id`, `department_id`, `role_id`, `role_speciality`, `is_active`) 
VALUES 
(NULL, '4', '33', 'Municipal Planning', '1'),
(NULL, '4', '31', 'Consultants', '1'),
(NULL, '4', '30', 'Contractors', '1'),
(NULL, '4', '30', 'Utilities', '1'),
(NULL, '4', '30', 'DoM', '1'),
(NULL, '4', '32', 'SITA/Service Providers', '1'),
(NULL, '4', '29', 'Occupational Access Specialist', '1'),
(NULL, '4', '29', 'Energy EPC', '1'),
(NULL, '4', '29', 'Contractors OHS', '1'),
(NULL, '4', '29', 'Landscape Architect', '1'),
(NULL, '4', '29', 'Clerk of Works', '1'),
(NULL, '4', '29', 'Contractors', '1'),
(NULL, '4', '29', 'Consultants', '1'),
(NULL, '4', '29', 'OEMs', '1'),
(NULL, '4', '29', 'Communications', '1'),
(NULL, '4', '29', 'Treasury', '1'),
(NULL, '4', '25', ' Municipal Transport', '1');

-- DATE 31-12-2025 Insert Project Cost Breakdown Table
CREATE TABLE `tbl_budget_cost_items` (
    `cost_item_id` INT NOT NULL AUTO_INCREMENT,
    `name` VARCHAR(200) NOT NULL,
    `description` VARCHAR(200) DEFAULT NULL,
    `parent_id` INT NOT NULL DEFAULT 0,
    `created_by` INT DEFAULT NULL,
    `updated_by` INT DEFAULT NULL,
    `creation_date` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
    `updation_date` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP 
        ON UPDATE CURRENT_TIMESTAMP,
    PRIMARY KEY (`cost_item_id`)
) ENGINE=InnoDB
  DEFAULT CHARSET=utf8mb4
  COLLATE=utf8mb4_unicode_ci;

-- DATE 31-12-2025 Insert Project Cost Breakdown Parent Data
INSERT INTO tbl_budget_cost_items (name, description, parent_id, created_by, creation_date, updation_date) VALUES
('DIRECT CONSTRUCTION COSTS', NULL, 0, 110, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP),
('INDIRECT CONSTRUCTION COSTS', NULL, 0, 110, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP),
('CONTINGENCY & RISK ALLOWANCE', NULL, 0, 110, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP),
('DESIGN & PLANNING', NULL, 0, 110, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP),
('MONITORING & EVALUATION', NULL, 0, 110, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP),
('COMMUNITY & STAKEHOLDER ENGAGEMENT', NULL, 0, 110, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP),
('SUSTAINABILITY & COMPLIANCE', NULL, 0, 110, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP);

-- DATE 31-12-2025 Insert Project Cost Breakdown Child Data
INSERT INTO tbl_budget_cost_items (name, description, parent_id, created_by, creation_date, updation_date) VALUES
-- DIRECT CONSTRUCTION COSTS (1)
('Labour Costs', 'Wages, benefits, and allowances for workers and site staff', 1, 110, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP),
('Materials', 'Concrete, steel, piping, asphalt, etc.', 1, 110, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP),
('Equipment & Machinery', 'Rental or purchase of construction equipment', 1, 110, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP),
('Subcontractor Fees', 'Payments to third-party service providers', 1, 110, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP),

-- INDIRECT CONSTRUCTION COSTS (2)
('Site Overheads', 'Temporary facilities, utilities, security, and site management', 2, 110, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP),
('Project Management', 'Salaries of project managers, engineers, and consultants', 2, 110, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP),
('Insurance & Bonds', 'Construction insurance, performance guarantees', 2, 110, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP),
('Permits & Regulatory Fees', 'Environmental approvals, municipal permits', 2, 110, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP),

-- CONTINGENCY & RISK ALLOWANCE (3)
('Contingency Reserve', 'Typically 5–10% of total budget for unforeseen costs', 3, 110, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP),
('Risk Mitigation Costs', 'Budgeted actions to reduce identified risks', 3, 110, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP),

-- DESIGN & PLANNING (4)
('Architectural & Engineering Fees', 'Design, drawings, and technical specs', 4, 110, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP),
('Feasibility Studies', 'Pre-construction assessments', 4, 110, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP),
('Environmental Impact Assessments (EIA)', 'Environmental approvals and impact studies', 4, 110, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP),

-- MONITORING & EVALUATION (5)
('Quality Assurance', 'Testing, inspections, and certifications', 5, 110, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP),
('Progress Monitoring Tools', 'Software, reporting systems, dashboards', 5, 110, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP),

-- COMMUNITY & STAKEHOLDER ENGAGEMENT (6)
('Public Consultation Costs', 'Meetings, surveys, communication materials', 6, 110, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP),
('Social Impact Mitigation', 'Compensation, relocation, or support programs', 6, 110, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP),   

-- SUSTAINABILITY & COMPLIANCE (7)
('Green Building Features', 'Solar panels, water-saving systems', 7, 110, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP),
('Compliance Upgrades', 'Adjustments to meet new regulations or standards', 7, 110, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP);

-- DATE 31-12-2025 Add Cost item id to Project Tasks
ALTER TABLE `tbl_project_tasks` ADD `cost_item_id` INT NULL DEFAULT NULL AFTER `progress`;
ALTER TABLE `tbl_project_task_resources` DROP PRIMARY KEY;

-- Date 1-1-2026 add max_id for tbl_project_tasks
INSERT INTO `tbl_maxids` (`id`, `tbl_name`, `max_id`) VALUES ('22', 'tbl_project_tasks', '0');

-- DATE 01-01-2026 Insert 'Proof Of Evidence' in tbl_categories
ALTER TABLE `tbl_categories` ADD `dev_name` VARCHAR(200) NULL DEFAULT NULL AFTER `cat_name`;
INSERT INTO `tbl_categories` (`cat_id`, `cat_name`, `dev_name`, `type`, `creation_date`, `created_by`, `updation_date`, `updated_by`) VALUES (NULL, 'Proof Of Evidence', 'proof-of-evidence', 'project', CURRENT_TIMESTAMP, NULL, NULL, NULL);

-- DATE 01-01-2026 Add parent_id to existing tbl_project_tasks
ALTER TABLE `tbl_project_tasks` ADD `parent_id` INT NOT NULL DEFAULT '0' AFTER `dept_task_id`;

-- DATE 01-01-2026 drop sector_priority_term from tbl_project_plan_data
ALTER TABLE `tbl_project_plan_data` DROP `sector_priority_term`;

-- DATE 01-01-2026 change datatypes in tbl_project_plan_data
ALTER TABLE `tbl_project_plan_data` CHANGE `start_date_target` `start_date_target` VARCHAR(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT 'acceptance_criteria_risk_for_budget_1', CHANGE `end_date_target` `end_date_target` VARCHAR(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT 'acceptance_criteria_risk_for_budget_1', CHANGE `progress_target` `progress_target` VARCHAR(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT 'acceptance_criteria_risk_for_budget_1', CHANGE `target` `target` VARCHAR(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT 'acceptance_criteria_risk_for_budget_1';

-- DATE 01-01-2026 add actual_duration, actual_start_date, actual_end_date to tbl_project_tasks
ALTER TABLE `tbl_project_tasks` ADD `actual_duration` BIGINT NULL DEFAULT NULL AFTER `end_date`, ADD `actual_start_date` DATE NULL DEFAULT NULL AFTER `actual_duration`, ADD `actual_end_date` DATE NULL DEFAULT NULL AFTER `actual_start_date`;

-- DATE 01-01-2026 change datatypes in tbl_project_plan_data
ALTER TABLE `tbl_project_plan_data` CHANGE `created_at` `creation_date` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, CHANGE `updated_at` `updation_date` DATETIME on update CURRENT_TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP;

-- DATE 01-01-2026 add created_by and updated_by to tbl_project_plan_data
ALTER TABLE `tbl_project_plan_data` ADD `created_by` INT NULL DEFAULT NULL AFTER `total_adjusted`, ADD `updated_by` INT NULL DEFAULT NULL AFTER `created_by`;

-- DATE 01-01-2026 Insert Lookup for Impact On
INSERT INTO `tbl_lookup` (`keyid`, `dev_name`, `display_name`, `display_name_ml`, `description`, `is_active`, `translate`, `creation_date`, `created_by`, `updation_date`, `updated_by`) VALUES ('92', 'impact_on', 'Impact On', 'impact-on-ml', '', '1', 'No', '2025-12-11 11:30:00', '1', '2025-12-11 11:30:00', '1');
 
INSERT INTO tbl_lookup_detail (optionid, keyid, data_value, data_key, display_name, display_name_ml, sequence, item_data, parent_datakey, is_active, creation_date, created_by, updation_date, updated_by)
SELECT 
    COALESCE(MAX(optionid), 0) + 1,
    92,
    '1',
    'impact_on_1',
    'Resources',
    'resources-ml',
    1,
    '',
    '',
    'active',
    '2025-11-19 10:30:00',
    1,
    '2025-11-19 10:30:00',
    1
FROM tbl_lookup_detail;

INSERT INTO tbl_lookup_detail (
    optionid, keyid, data_value, data_key, display_name, display_name_ml,
    sequence, item_data, parent_datakey, is_active,
    creation_date, created_by, updation_date, updated_by
)
SELECT 
    COALESCE(MAX(optionid), 0) + 1,
    92,
    '2',
    'impact_on_2',
    'Budget',
    'budget-ml',
    2,
    '',
    '',
    'active',
    '2025-11-19 10:30:00',
    1,
    '2025-11-19 10:30:00',
    1
FROM tbl_lookup_detail;

INSERT INTO tbl_lookup_detail (
    optionid, keyid, data_value, data_key, display_name, display_name_ml,
    sequence, item_data, parent_datakey, is_active,
    creation_date, created_by, updation_date, updated_by
)
SELECT 
    COALESCE(MAX(optionid), 0) + 1,
    92,
    '3',
    'impact_on_3',
    'Duration',
    'duration-ml',
    3,
    '',
    '',
    'active',
    '2025-11-19 10:30:00',
    1,
    '2025-11-19 10:30:00',
    1
FROM tbl_lookup_detail;

-- DATE 01-01-2026 add impact_on and project_task_id to tbl_project_stg5_risk_management
ALTER TABLE `tbl_project_stg5_risk_management` ADD `impact_on` VARCHAR(500) NULL DEFAULT NULL AFTER `risk_id`;

-- DATE 01-01-2026 create table tbl_project_risk_tasks
CREATE TABLE `tbl_project_risk_tasks` (
    `risk_management_id` INT DEFAULT NULL,
    `project_task_id` INT DEFAULT NULL
) ENGINE=InnoDB
  DEFAULT CHARSET=utf8mb4
  COLLATE=utf8mb4_unicode_ci;

-- DATE 22-12-2025 create trigger for reset tbl_frontend_active_stage if project stage gate active status on
DELIMITER $$

CREATE TRIGGER trg_delete_frontend_stage
AFTER UPDATE ON tbl_project_stages
FOR EACH ROW
BEGIN
    -- Check if active_gate changed from 0 to 1
    IF OLD.active_gate = 0 AND NEW.active_gate = 1 THEN
        DELETE FROM tbl_frontend_active_stage
        WHERE project_id = NEW.project_id
          AND stage_id = NEW.stage_id;
    END IF;
END$$

-- DATE 29-12-2025  Update Trigger on tbl_project_users, Fix required as there can be two records with same project_id for project manager and owner.
-- DEV(DONE) QA(DONE)
DROP PROCEDURE IF EXISTS sp_insert_elevator_pitch;

DELIMITER $$
CREATE PROCEDURE `sp_insert_elevator_pitch`(IN `p_user_id` INT, IN `p_project_id` INT)
proc_block: BEGIN
    -- Declare variables for stage0/3 data
    DECLARE v_row_id INT;
    DECLARE v_background_justification TEXT;
    DECLARE v_estimated_years VARCHAR(50);
    DECLARE v_estimated_months VARCHAR(50);
    DECLARE v_estimated_start_date DATE;
    DECLARE v_project_type VARCHAR(100);
    DECLARE v_project_size VARCHAR(100);
    DECLARE v_estimated_cost FLOAT;
    DECLARE v_exists INT DEFAULT 0;
 
 	 -- Check if elevator pitch already exists for this project
    SELECT COUNT(*) 
    INTO v_exists
    FROM tbl_elevator_pitch
    WHERE project_id = p_project_id;

    -- If record exists, skip process
    IF v_exists > 0 THEN
    	  SELECT CONCAT(
            'Data already exists for given User ID : ', p_user_id,
            ', Project ID = ', p_project_id
        ) AS status_message;
        LEAVE proc_block;
    END IF;
    
    -- Get next row_id
    SELECT IFNULL(MAX(row_id), 0) + 1
    INTO v_row_id
    FROM tbl_elevator_pitch;
 
    -- Fetch data for elevator pitch (stage0 + stage3)
    SELECT
        tps3.background_justification,
        tps0.estimated_project_duration_years,
        tps0.estimated_project_duration_months,
        tps0.estimated_project_start_date,
        tps3.project_type,
        tps3.project_size,
        tps0.ballpark_project_cost
    INTO
        v_background_justification,
        v_estimated_years,
        v_estimated_months,
        v_estimated_start_date,
        v_project_type,
        v_project_size,
        v_estimated_cost
    FROM tbl_projects tp
    LEFT JOIN tbl_project_stg0 tps0
        ON tp.project_id = tps0.project_id
    LEFT JOIN tbl_project_stg3 tps3
        ON tp.project_id = tps3.project_id
    LEFT JOIN tbl_project_users tpu
        ON tps0.project_id = tpu.project_id
    WHERE tpu.user_id = p_user_id
      AND tp.project_id = p_project_id
      AND tps0.is_active = 1
      ORDER BY
            CASE
                WHEN tpu.role_id = 'project_team_roles_3' THEN 1
                WHEN tpu.role_id = 'project_team_roles_4' THEN 2
                ELSE 3
            END
        LIMIT 1;
 
    -- Insert main elevator pitch row
    INSERT INTO tbl_elevator_pitch (
        row_id,
        project_id,
        background_justification,
        project_size,
        project_type,
        estimated_cost,
        estimated_years,
        estimated_months,
        estimated_project_start_date,
        creation_date,
        created_by
    ) VALUES (
        v_row_id,
        p_project_id,
        v_background_justification,
        v_project_size,
        v_project_type,
        v_estimated_cost,
        v_estimated_years,
        v_estimated_months,
        v_estimated_start_date,
        NOW(),
        p_user_id
    );
 
    -- Insert stage1 keys directly (all rows at once)
    INSERT INTO tbl_elevator_pitch_key_parties (
        project_id,
        key_name,
        key_value,
        free_text,
        creation_date,
        created_by
    )
    SELECT
        p_project_id,
        psk.key_name,
        psk.key_value,
        psk.free_text,
        NOW(),
        p_user_id
    FROM tbl_project_stg1_keys psk
    LEFT JOIN tbl_lookup l ON psk.key_name = l.dev_name
    WHERE psk.project_id = p_project_id
    and l.keyid IN (17,18,19,20);
	
	-- Insert tbl_elevator_pitch_departments
	INSERT INTO tbl_elevator_pitch_departments (
		project_id,
		department_id,
		other_department,        
		creation_date,
		created_by
	)
	SELECT
		p_project_id,
		pd.department_id,
		COALESCE(pd.other_department, ''),   -- replace NULL with ''
		NOW(),
		p_user_id
	FROM tbl_project_departments pd    
	WHERE pd.project_id = p_project_id
	ON DUPLICATE KEY UPDATE
		other_department = VALUES(other_department),   -- update if already exists
		creation_date = VALUES(creation_date),
		created_by = VALUES(created_by);

    
    INSERT INTO tbl_elevator_pitch_key_objective (
          row_id,
        project_id,
        objective_datakey,
        focusarea_datakey,
        objective_name,
        creation_date,
        created_by
    )
    SELECT
          v_row_id,
        p_project_id,
        pso.objective_datakey,
        pso.focusarea_datakey,
        pso.objective_name,
        NOW(),
        p_user_id
    FROM tbl_project_stg0_objective pso
    WHERE pso.project_id = p_project_id;
    
    SELECT 'Data Inserted Successfully' AS status_message;
 
END proc_block$$
DELIMITER ;

-- DATE 30-12-2025 
-- Updated trigger in QA for separate project owner and manager.
-- DEV(DONE) QA(DONE)
DROP TRIGGER IF EXISTS tr_tbl_projects_insert;
DELIMITER $$
CREATE TRIGGER tr_tbl_projects_insert
AFTER INSERT ON tbl_projects
BEGIN

  /* Insert into tbl_project_stg0 */
  INSERT INTO tbl_project_stg0
  (
    project_id,
    background_justification,
    scope_of_work,
    ballpark_project_cost,
    estimated_project_duration_years,
    estimated_project_duration_months,
    estimated_project_start_date,
    is_active,
    creation_date,
    created_by,
    updation_date,
    updated_by
  )
  VALUES
  (
    NEW.project_id,
    '',
    '',
    NULL,
    NULL,
    NULL,
    NULL,
    1,
    NOW(),
    NEW.created_by,
    NULL,
    NULL
  );

  /* Insert project owner (ALWAYS when present) */
  IF NEW.project_owner IS NOT NULL AND NEW.project_owner <> 0 THEN
    INSERT INTO tbl_project_users
    (
      project_id,
      user_id,
      role_id,
      total_questions,
      attempted_questions,
      eval_status,
      project_rights,
      creation_date,
      created_by
    )
    VALUES
    (
      NEW.project_id,
      NEW.project_owner,
      'project_team_roles_3',
      0,
      0,
      'pending',
      'edit',
      NOW(),
      NEW.created_by
    );
  END IF;

  /* Insert project manager (OPTIONAL) */
  IF NEW.project_manager IS NOT NULL AND NEW.project_manager <> 0 THEN
    INSERT INTO tbl_project_users
    (
      project_id,
      user_id,
      role_id,
      total_questions,
      attempted_questions,
      eval_status,
      project_rights,
      creation_date,
      created_by
    )
    VALUES
    (
      NEW.project_id,
      NEW.project_manager,
      'project_team_roles_4',
      0,
      0,
      'pending',
      'edit',
      NOW(),
      NEW.created_by
    );
  END IF;

  /* Additional stage checks */
  INSERT INTO tbl_project_additonal_stages (
    additional_check_datakey,
    project_id,
    stage_id,
    user_id
  )
  VALUES
  ('project_additional_stages_1', NEW.project_id, 'project_stage_1', 0),
  ('project_additional_stages_2', NEW.project_id, 'project_stage_2', 0);

  /* Stage 0 */
  INSERT INTO tbl_project_stages (
    project_stage_id,
    project_id,
    stage_id,
    stage_status,
    active_gate,
    created_by,
    prerequisites_stages,
    creation_date
  )
  SELECT
    IFNULL(MAX(project_stage_id), 0) + 1,
    NEW.project_id,
    'project_stage_0',
    'stage_status_1',
    1,
    NEW.created_by,
    '',
    NOW()
  FROM tbl_project_stages;

  /* Stage 1 */
  INSERT INTO tbl_project_stages
  (project_stage_id, project_id, stage_id, stage_status, active_gate, additional_check, created_by, prerequisites_stages, creation_date)
  SELECT IFNULL(MAX(project_stage_id), 0) + 1, NEW.project_id, 'project_stage_1', 'stage_status_1', 0, 'na', NEW.created_by, 'project_stage_0', NOW() FROM tbl_project_stages;

  /* Stage 2 */
  INSERT INTO tbl_project_stages
  (project_stage_id, project_id, stage_id, stage_status, active_gate, created_by, prerequisites_stages, creation_date)
  SELECT IFNULL(MAX(project_stage_id), 0) + 1, NEW.project_id, 'project_stage_2', 'stage_status_1', 0, NEW.created_by, 'project_stage_1', NOW() FROM tbl_project_stages;

  /* Stage 3 */
  INSERT INTO tbl_project_stages
  (project_stage_id, project_id, stage_id, stage_status, active_gate, additional_check, created_by, prerequisites_stages, creation_date)
  SELECT IFNULL(MAX(project_stage_id), 0) + 1, NEW.project_id, 'project_stage_3', 'stage_status_1', 0, 'na', NEW.created_by, 'project_stage_2', NOW() FROM tbl_project_stages;

  /* Stage 4 */
  INSERT INTO tbl_project_stages
  (project_stage_id, project_id, stage_id, stage_status, active_gate, created_by, prerequisites_stages, creation_date)
  SELECT IFNULL(MAX(project_stage_id), 0) + 1, NEW.project_id, 'project_stage_4', 'stage_status_1', 0, NEW.created_by, 'project_stage_3', NOW() FROM tbl_project_stages;

  /* Stage 5 */
  INSERT INTO tbl_project_stages
  (project_stage_id, project_id, stage_id, stage_status, active_gate, created_by, prerequisites_stages, creation_date)
  SELECT IFNULL(MAX(project_stage_id), 0) + 1, NEW.project_id, 'project_stage_5', 'stage_status_1', 0, NEW.created_by, 'project_stage_4', NOW() FROM tbl_project_stages;

  /* Stage 6 */
  INSERT INTO tbl_project_stages
  (project_stage_id, project_id, stage_id, stage_status, active_gate, created_by, prerequisites_stages, creation_date)
  SELECT IFNULL(MAX(project_stage_id), 0) + 1, NEW.project_id, 'project_stage_6', 'stage_status_1', 0, NEW.created_by, 'project_stage_5', NOW() FROM tbl_project_stages;

  /* Stage 7 */
  INSERT INTO tbl_project_stages
  (project_stage_id, project_id, stage_id, stage_status, active_gate, created_by, prerequisites_stages, creation_date)
  SELECT IFNULL(MAX(project_stage_id), 0) + 1, NEW.project_id, 'project_stage_7', 'stage_status_1', 0, NEW.created_by, 'project_stage_6', NOW() FROM tbl_project_stages;

  /* Stage 8 */
  INSERT INTO tbl_project_stages
  (project_stage_id, project_id, stage_id, stage_status, active_gate, created_by, prerequisites_stages, creation_date)
  SELECT IFNULL(MAX(project_stage_id), 0) + 1, NEW.project_id, 'project_stage_8', 'stage_status_1', 0, NEW.created_by, 'project_stage_7', NOW() FROM tbl_project_stages;

  /* Stage 9 */
  INSERT INTO tbl_project_stages
  (project_stage_id, project_id, stage_id, stage_status, active_gate, created_by, prerequisites_stages, creation_date)
  SELECT IFNULL(MAX(project_stage_id), 0) + 1, NEW.project_id, 'project_stage_9', 'stage_status_1', 0, NEW.created_by, 'project_stage_8', NOW() FROM tbl_project_stages;

END
DELIMITER ;

-- DATE 12-01-2026 
-- add tips column in tbl_panoptics 
-- DEV(DONE) QA(DONE)
ALTER TABLE `tbl_panoptics` ADD `tip` TEXT NULL DEFAULT NULL AFTER `pp_desc`;

-- DATE 13-01-2026 
-- add report_generation_date column in tbl_project_stages
-- DEV[DONE] QA[DONE]
ALTER TABLE `tbl_project_stages` ADD `report_generation_date` DATETIME NULL DEFAULT NULL AFTER `stage_enddate`;

-- 19-01-2026 
-- update doc_desc column in tbl_documents DEV[DONE] QA[DONE]
ALTER TABLE `tbl_documents`
	CHANGE COLUMN `doc_desc` `doc_desc` TEXT NULL COLLATE 'utf8_general_ci' AFTER `doc_category`;

-- update estimated_cost column in tbl_elevator_pitch DEV[DONE] QA[DONE]
ALTER TABLE `tbl_elevator_pitch` 
CHANGE COLUMN `estimated_cost` `estimated_cost` DECIMAL(20,3) NULL DEFAULT NULL AFTER `project_type`;

-- STAGE-6 Production report related updates in buget_cost_items table DEV(DONE) QA(PENDING)
ALTER TABLE `tbl_budget_cost_items`
	ADD COLUMN `tolerance_lower` DECIMAL(15,2) NOT NULL DEFAULT 0.00 AFTER `parent_id`,
	ADD COLUMN `tolerance_upper` DECIMAL(15,2) NOT NULL DEFAULT 0.00 AFTER `tolerance_lower`;

-- STAGE-6 Production report tables DEV[DONE] QA[DONE]

CREATE TABLE IF NOT EXISTS `tbl_project_stg6_budget_items` (
  `budget_item_id` bigint(20) unsigned NOT NULL,
  `production_report_id` bigint(20) unsigned NOT NULL,
  `project_id` bigint(20) unsigned NOT NULL,
  `name` varchar(255) NOT NULL,
  `approved_budget_per_item` bigint(20) DEFAULT 0,
  `expenditure_till_prev_month` decimal(15,2) DEFAULT 0.00,
  `current_month_exp` decimal(15,2) DEFAULT 0.00,
  `tot_exp` decimal(15,2) GENERATED ALWAYS AS (`expenditure_till_prev_month` + `current_month_exp`) VIRTUAL,
  `variance` decimal(15,2) DEFAULT NULL,
  `tolerance_lower` decimal(15,2) DEFAULT NULL,
  `tolerance_upper` decimal(15,2) DEFAULT NULL,
  `comments` text DEFAULT NULL,
  `created_by` bigint(20) unsigned NOT NULL,
  `creation_date` timestamp NOT NULL DEFAULT current_timestamp(),
  `updated_by` bigint(20) unsigned DEFAULT NULL,
  `updation_date` timestamp NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(),
  PRIMARY KEY (`budget_item_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

-- Dumping structure for table tbl_project_stg6_kpis DEV[DONE] QA[DONE]
CREATE TABLE IF NOT EXISTS `tbl_project_stg6_kpis` (
  `project_kpis_id` bigint(20) unsigned NOT NULL,
  `production_report_id` bigint(20) unsigned NOT NULL,
  `project_id` bigint(20) unsigned NOT NULL,
  `kpi_master_id` bigint(20) unsigned NOT NULL,
  `planned_target_this_month` decimal(15,2) DEFAULT NULL,
  `actual` decimal(15,2) DEFAULT NULL,
  `variance` decimal(15,2) DEFAULT NULL,
  `tolerance_lower` decimal(15,2) DEFAULT NULL,
  `tolerance_upper` decimal(15,2) DEFAULT NULL,
  `comments` text DEFAULT NULL,
  `created_by` bigint(20) unsigned NOT NULL,
  `creation_date` timestamp NOT NULL DEFAULT current_timestamp(),
  `updated_by` bigint(20) unsigned DEFAULT NULL,
  `updation_date` timestamp NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(),
  PRIMARY KEY (`project_kpis_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

-- Dumping structure for table tbl_project_stg6_production_report  DEV[DONE] QA[DONE]
CREATE TABLE IF NOT EXISTS `tbl_project_stg6_production_report` (
  `production_report_id` bigint(20) unsigned NOT NULL,
  `project_id` bigint(20) unsigned NOT NULL,
  `from_date` date NOT NULL,
  `to_date` date NOT NULL,
  `reporting_month` varchar(50) NOT NULL DEFAULT '0' COMMENT 'Format: YYYY-MM',
  `prepared_by` bigint(20) unsigned DEFAULT NULL,
  `prepared_on` date DEFAULT NULL,
  `report_stage` varchar(50) DEFAULT NULL,
  `created_by` bigint(20) unsigned NOT NULL,
  `creation_date` timestamp NOT NULL DEFAULT current_timestamp(),
  `updated_by` bigint(20) unsigned DEFAULT NULL,
  `updation_date` timestamp NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(),
  PRIMARY KEY (`production_report_id`),
  CONSTRAINT `chk_date_range` CHECK (`to_date` >= `from_date`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;


-- Dumping structure for table tbl_stg6_kpis_master  DEV[DONE] QA[DONE]
CREATE TABLE IF NOT EXISTS `tbl_stg6_kpis_master` (
  `kpi_master_id` bigint(20) unsigned NOT NULL,
  `parent_id` bigint(20) unsigned NOT NULL DEFAULT 0,
  `is_default` tinyint(1) unsigned NOT NULL DEFAULT 0,
  `project_id` bigint(20) unsigned NOT NULL DEFAULT 0,
  `name` varchar(255) NOT NULL,
  `description` text DEFAULT NULL,
  `tolerance_lower` decimal(15,2) NOT NULL DEFAULT 0.00,
  `tolerance_upper` decimal(15,2) NOT NULL DEFAULT 0.00,
  `is_active` tinyint(1) DEFAULT 1,
  `created_by` bigint(20) unsigned NOT NULL,
  `creation_date` timestamp NOT NULL DEFAULT current_timestamp(),
  `updated_by` bigint(20) unsigned DEFAULT NULL,
  `updation_date` timestamp NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(),
  PRIMARY KEY (`kpi_master_id`) USING BTREE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

-- DEV[DONE] QA[DONE]
INSERT INTO `tbl_stg6_kpis_master` (`kpi_master_id`, `parent_id`, `is_default`, `project_id`, `name`, `description`, `tolerance_lower`, `tolerance_upper`, `is_active`, `created_by`, `creation_date`, `updated_by`, `updation_date`) VALUES
	(1, 0, 1, 0, 'PROGRESS & OUTPUT', NULL, 0.00, 0.00, 1, 0, '2026-01-06 06:00:26', NULL, '2026-01-06 10:27:37'),
	(2, 0, 1, 0, 'RESOURCE UTILISATION', NULL, 0.00, 0.00, 1, 0, '2026-01-06 06:01:49', NULL, '2026-01-06 10:27:37'),
	(3, 0, 1, 0, 'COST & BUDGET', NULL, 0.00, 0.00, 1, 0, '2026-01-06 06:02:10', NULL, '2026-01-06 10:27:37'),
	(4, 0, 1, 0, 'QUALITY & COMPLIANCE', NULL, 0.00, 0.00, 1, 0, '2026-01-06 06:02:33', NULL, '2026-01-06 10:27:37'),
	(5, 0, 1, 0, 'SAFETY & RISK', NULL, 0.00, 0.00, 1, 0, '2026-01-06 06:02:43', NULL, '2026-01-06 10:27:37'),
	(6, 0, 1, 0, 'ENVIRONMENTAL & SOCIAL IMPACT', NULL, 0.00, 0.00, 1, 0, '2026-01-06 06:02:51', NULL, '2026-01-06 10:27:37'),
	(7, 1, 1, 0, '% of Planned Work Completed', 'Measures actual vs scheduled progress (e.g., 65% of road paving completed)', 0.00, 0.00, 1, 0, '2026-01-06 06:03:17', NULL, '2026-01-06 10:27:37'),
	(8, 1, 1, 0, 'Milestone Achievement Rate', '% of key milestones met on time', 0.00, 0.00, 1, 0, '2026-01-06 06:03:39', NULL, '2026-01-06 10:27:37'),
	(9, 1, 1, 0, 'Daily/Weekly Production Rate', 'Quantity of work completed per time unit (e.g., meters of pipeline laid per day)', 0.00, 0.00, 1, 0, '2026-01-06 06:03:51', NULL, '2026-01-06 10:27:37'),
	(10, 2, 1, 0, 'Labour Productivity', 'Output per worker per day/week', 0.00, 0.00, 1, 0, '2026-01-06 06:04:11', NULL, '2026-01-06 10:27:37'),
	(11, 2, 1, 0, 'Equipment Utilization Rate', '% of time equipment is actively used vs idle', 0.00, 0.00, 1, 0, '2026-01-06 06:04:32', NULL, '2026-01-06 10:27:37'),
	(12, 2, 1, 0, 'Material Usage Efficiency', 'Actual material used vs planned (helps track waste or overuse)', 0.00, 0.00, 1, 0, '2026-01-06 06:04:49', NULL, '2026-01-06 10:27:37'),
	(13, 3, 1, 0, 'Cost Performance Index (CPI)', 'Ratio of budgeted cost of work performed to actual cost', 0.00, 0.00, 1, 0, '2026-01-06 06:05:01', NULL, '2026-01-06 10:27:37'),
	(14, 3, 1, 0, 'Budget Variance', 'Difference between planned and actual expenditure', 0.00, 0.00, 1, 0, '2026-01-06 06:05:36', NULL, '2026-01-06 10:27:37'),
	(15, 3, 1, 0, 'Forecast at Completion (FAC)', 'Updated estimate of total project cost based on current trends', 0.00, 0.00, 1, 0, '2026-01-06 06:05:51', NULL, '2026-01-06 10:27:37'),
	(16, 4, 1, 0, 'Defect Rate', 'Number of defects per unit of work (e.g., cracks per 100m of road)', 0.00, 0.00, 1, 0, '2026-01-06 06:06:09', NULL, '2026-01-06 10:27:37'),
	(17, 4, 1, 0, 'Inspection Pass Rate', '% of work passing quality inspections on first attempt', 0.00, 0.00, 1, 0, '2026-01-06 06:06:45', NULL, '2026-01-06 10:27:37'),
	(18, 4, 1, 0, 'Compliance Score', 'Adherence to contract specs, safety standards, and environmental regulations', 0.00, 0.00, 1, 0, '2026-01-06 06:07:06', NULL, '2026-01-06 10:27:37'),
	(19, 5, 1, 0, 'Incident Frequency Rate', 'Number of safety incidents per 1,000 work hours', 0.00, 0.00, 1, 0, '2026-01-06 06:07:39', NULL, '2026-01-06 10:27:37'),
	(20, 5, 1, 0, 'Lost Time Injury Rate (LTIR)', 'Number of injuries causing time off work', 0.00, 0.00, 1, 0, '2026-01-06 06:08:02', NULL, '2026-01-06 10:27:37'),
	(21, 5, 1, 0, 'Risk Mitigation Actions Completed', '% of identified risks with mitigation plans in place', 0.00, 0.00, 1, 0, '2026-01-06 06:08:27', NULL, '2026-01-06 10:27:37'),
	(22, 6, 1, 0, 'Waste Management Efficiency', '% of waste recycled or properly disposed', 0.00, 0.00, 1, 0, '2026-01-06 06:08:48', NULL, '2026-01-06 10:27:37'),
	(23, 6, 1, 0, 'Community Disruption Index', 'Number of complaints or disruptions reported', 0.00, 0.00, 1, 0, '2026-01-06 06:09:12', NULL, '2026-01-06 10:27:37'),
	(24, 6, 1, 0, 'Local Employment Ratio', '% of workforce hired from local communities', 0.00, 0.00, 1, 0, '2026-01-06 06:09:57', NULL, '2026-01-06 10:27:37');


-- DATE 21-01-2026 

-- Dumping structure for table tbl_project_stg6_construction_report DEV[DONE] QA[DONE]
CREATE TABLE IF NOT EXISTS `tbl_project_stg6_construction_report` (
  `construction_report_id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `project_id` bigint(20) unsigned NOT NULL,
  `from_date` date NOT NULL,
  `to_date` date NOT NULL,
  `reporting_month` varchar(50) NOT NULL,
  `prepared_by` bigint(20) unsigned NOT NULL,
  `prepared_on` date NOT NULL,
  `report_stage` varchar(50) NOT NULL DEFAULT 'Construction',
  `created_by` bigint(20) unsigned NOT NULL,
  `creation_date` datetime NOT NULL DEFAULT current_timestamp(),
  `updated_by` bigint(20) unsigned DEFAULT NULL,
  `updation_date` datetime DEFAULT NULL ON UPDATE current_timestamp(),
  PRIMARY KEY (`construction_report_id`)
) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

-- Data exporting was unselected.

-- Dumping structure for table tbl_project_stg6_site_progress_report_data DEV[DONE] QA[DONE]
CREATE TABLE IF NOT EXISTS `tbl_project_stg6_site_progress_report_data` (
  `site_progress_id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `project_id` bigint(20) unsigned NOT NULL,
  `activity_id` bigint(20) unsigned NOT NULL,
  `planned_completion` bigint(20) NOT NULL,
  `actual_completion` bigint(20) NOT NULL,
  `variance` bigint(20) NOT NULL,
  `comments` text DEFAULT NULL,
  `created_by` bigint(20) unsigned NOT NULL,
  `creation_date` timestamp NOT NULL DEFAULT current_timestamp(),
  `updated_by` bigint(20) unsigned DEFAULT NULL,
  `updation_date` timestamp NULL DEFAULT NULL ON UPDATE current_timestamp(),
  PRIMARY KEY (`site_progress_id`)
) ENGINE=InnoDB AUTO_INCREMENT=6 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

-- Data exporting was unselected.

-- Dumping structure for table tbl_project_stg6_workforce_and_equipement DEV[DONE] QA[DONE]
CREATE TABLE IF NOT EXISTS `tbl_project_stg6_workforce_and_equipement` (
  `workforce_and_equipement_id` bigint(20) unsigned NOT NULL,
  `project_id` bigint(20) NOT NULL,
  `category_id` bigint(20) NOT NULL COMMENT 'FK = tbl_project_stg6_activities_and_categories - type: category',
  `planned_no_of_assets` bigint(20) NOT NULL,
  `actual_no_of_assets` bigint(20) NOT NULL,
  `no_of_assets_variance` bigint(20) NOT NULL,
  `budget_item_id` bigint(20) NOT NULL COMMENT 'FK = tbl_budget_cost_items',
  `approved_budget_per_item` bigint(20) NOT NULL,
  `expenditure_till_previous_month` bigint(20) NOT NULL,
  `current_month_expenditure` bigint(20) NOT NULL,
  `total_expenditure` bigint(20) NOT NULL,
  `budget_variance` bigint(20) NOT NULL,
  `tolerance_lower` decimal(15,2) NOT NULL DEFAULT 0.00,
  `tolerance_upper` decimal(15,2) NOT NULL DEFAULT 0.00,
  `comments` text DEFAULT NULL,
  `created_by` bigint(20) NOT NULL,
  `creation_date` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(),
  `updated_by` bigint(20) DEFAULT NULL,
  `updation_date` timestamp NULL DEFAULT NULL,
  PRIMARY KEY (`workforce_and_equipement_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Data exporting was unselected.

-- Dumping structure for table tbl_stg6_activities_and_categories DEV[DONE] QA[DONE]
CREATE TABLE IF NOT EXISTS `tbl_stg6_activities_and_categories` (
  `row_id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `name` varchar(250) NOT NULL,
  `type` enum('activity','category') NOT NULL,
  `created_by` bigint(20) unsigned NOT NULL,
  `creation_date` timestamp NOT NULL DEFAULT current_timestamp(),
  `updated_by` bigint(20) unsigned DEFAULT NULL,
  `updation_date` timestamp NULL DEFAULT NULL ON UPDATE current_timestamp(),
  PRIMARY KEY (`row_id`)
) ENGINE=InnoDB AUTO_INCREMENT=11 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

-- Add table entries in tbl_maxid table with initial values DEV[DONE] QA[DONE]

INSERT INTO `tbl_maxids` (`id`, `tbl_name`, `max_id`) VALUES ('23', 'tbl_project_stg6_production_report', '0');
INSERT INTO `tbl_maxids` (`id`, `tbl_name`, `max_id`) VALUES ('24', 'tbl_stg6_kpis_master', '24');
INSERT INTO `tbl_maxids` (`id`, `tbl_name`, `max_id`) VALUES ('25', 'tbl_project_stg6_kpis', '0');
INSERT INTO `tbl_maxids` (`id`, `tbl_name`, `max_id`) VALUES ('26', 'tbl_project_stg6_construction_report', '0');
INSERT INTO `tbl_maxids` (`id`, `tbl_name`, `max_id`) VALUES ('27', 'tbl_project_stg6_site_progress_report_data', '0');
INSERT INTO `tbl_maxids` (`id`, `tbl_name`, `max_id`) VALUES ('28', 'tbl_project_stg6_workforce_and_equipement', '0');

-- DATE 26-01-2026 DEV[DONE] QA[DONE]
ALTER TABLE `tbl_project_stg5_risk_management` CHANGE `impact_on` `impact_on` JSON NULL DEFAULT NULL;


-- DATE 29-01-2026 Missing data for the table DEV[DONE] QA[DONE] 
INSERT INTO `tbl_stg6_activities_and_categories` (`row_id`, `name`, `type`, `created_by`, `creation_date`, `updated_by`, `updation_date`) VALUES
(1, 'Earthworks', 'activity', 0, '2026-01-22 06:45:46', NULL, NULL),
(2, 'Foundations', 'activity', 0, '2026-01-22 06:46:01', NULL, NULL),
(3, 'Superstructure', 'activity', 0, '2026-01-22 06:46:13', NULL, NULL),
(4, 'Finishes', 'activity', 0, '2026-01-22 06:46:26', NULL, NULL),
(5, 'Immovable', 'category', 0, '2026-01-22 06:46:42', NULL, NULL),
(6, 'Movable', 'category', 0, '2026-01-22 06:47:00', NULL, NULL),
(7, 'Heritage', 'category', 0, '2026-01-22 06:47:12', NULL, NULL),
(8, 'Financial', 'category', 0, '2026-01-22 06:47:25', NULL, NULL),
(9, 'Infrastructure', 'category', 0, '2026-01-22 06:47:39', NULL, NULL),
(10, 'Intangible', 'category', 0, '2026-01-22 06:48:33', NULL, NULL);

-- DATE 30-01-2026 DEV[DONE] QA[DONE]
ALTER TABLE `tbl_project_stg6_site_progress_report_data`
  ADD `construction_report_id` BIGINT UNSIGNED NULL AFTER `site_progress_id`;
ALTER TABLE `tbl_project_stg6_workforce_and_equipement`
  ADD `construction_report_id` BIGINT UNSIGNED NULL AFTER `workforce_and_equipement_id`;
-- backfill construction_report_id here
-- then enforce NOT NULL + FK in a follow-up migration


-- DATE 02-02-2026 

-- Update categories table. DEV[DONE] QA[DONE]
INSERT INTO `tbl_categories` (`cat_name`, `dev_name`, `type`, `creation_date`, `created_by`, `updation_date`, `updated_by`) 
VALUES ('Production report', 'production-report', 'project', '2026-01-08 15:38:38', NULL, NULL, NULL);
INSERT INTO `tbl_categories` (`cat_name`, `dev_name`, `type`, `creation_date`, `created_by`, `updation_date`, `updated_by`) 
VALUES ('Construction report', 'construction-report', 'project', '2026-01-08 15:38:38', NULL, NULL, NULL);

--Update tbl_project_stg6_production_report to add status column DEV[DONE] QA[DONE]
ALTER TABLE tbl_project_stg6_production_report
ADD COLUMN status ENUM('In Progress', 'Submitted')
NOT NULL
DEFAULT 'In Progress'
AFTER report_stage;

--Update tbl_project_stg6_production_report to add doc_id column DEV[DONE] QA[DONE]
ALTER TABLE `tbl_project_stg6_production_report` ADD `doc_id` INT NULL AFTER `status`;

--Update tbl_project_stg6_construction_report to add status and doc_id columns DEV[DONE] QA[DONE]
ALTER TABLE `tbl_project_stg6_construction_report` ADD `status` ENUM('In Progress', 'Submitted') NOT NULL DEFAULT 'In Progress' AFTER `report_stage`, ADD `doc_id` INT NULL AFTER `status`;

-- update tbl_project_stg6_site_progress_report_data to add construction_report_id column DEV[DONE] QA[DONE]
ALTER TABLE tbl_project_stg6_site_progress_report_data
ADD COLUMN construction_report_id BIGINT UNSIGNED NOT NULL
AFTER site_progress_id;

-- update tbl_project_stg6_workforce_and_equipement to add construction_report_id column DEV[DONE] QA[DONE]
ALTER TABLE tbl_project_stg6_workforce_and_equipement
ADD COLUMN construction_report_id BIGINT UNSIGNED NOT NULL
AFTER workforce_and_equipement_id;

-- 03-02-2026Add project_plan_report_generate and risk_management_report_generate columns to tbl_project_stg5 DEV[DONE] QA[DONE]
ALTER TABLE `tbl_project_stg5` ADD `project_plan_report_generate` INT NOT NULL DEFAULT '0' AFTER `conclusion`, ADD `risk_management_report_generate` INT NOT NULL DEFAULT '0' AFTER `project_plan_report_generate`;

-- 03-02-2026Add new categories for project plan and risk management report DEV[DONE] QA[DONE]
INSERT INTO `tbl_categories` (`cat_id`, `cat_name`, `dev_name`, `type`, `creation_date`, `created_by`, `updation_date`, `updated_by`) VALUES (NULL, 'Project Plan Report', 'project-plan-report', 'project', CURRENT_TIMESTAMP, NULL, NULL, NULL), (NULL, 'Project Risk Management Report', 'project-risk-management-report', 'project', CURRENT_TIMESTAMP, NULL, NULL, NULL);
-- DATE 03-02-2026

-- Update tbl_project_stg6_budget_items table DEV[DONE] QA[DONE]
ALTER TABLE `tbl_project_stg6_budget_items`
  MODIFY `expenditure_till_prev_month` DECIMAL(15,3) NULL DEFAULT 0.00,
  MODIFY `current_month_exp`          DECIMAL(15,3) NULL DEFAULT 0.00,
  MODIFY `variance`                  DECIMAL(15,3) NULL DEFAULT NULL,
  MODIFY `tolerance_lower`           DECIMAL(15,3) NULL DEFAULT NULL,
  MODIFY `tolerance_upper`           DECIMAL(15,3) NULL DEFAULT NULL;

-- DATE 05-02-2026 add platform config table DEV[Done] QA[DONE]
CREATE TABLE `tbl_platform_config` (
    `key` VARCHAR(255) NOT NULL,
    `value` VARCHAR(1000) NOT NULL,
    `created_by` INT DEFAULT NULL,
    `updated_by` INT DEFAULT NULL,
    `creation_date` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
    `updation_date` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP
        ON UPDATE CURRENT_TIMESTAMP,
    PRIMARY KEY (`key`),
    UNIQUE KEY `uq_tbl_platform_config_key` (`key`)
) ENGINE=InnoDB
  DEFAULT CHARSET=utf8mb4
  COLLATE=utf8mb4_unicode_ci;

-- DEV[DONE] QA[DONE]
INSERT INTO `tbl_platform_config` (`key`, `value`, `created_by`, `updated_by`, `creation_date`, `updation_date`) VALUES ('date_format', 'dd-MM-yyyy', NULL, NULL, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP), ('currency', 'amt', NULL, NULL, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP);


-- DATE 06-02-2026 add stage master values table DEV[DONE] QA[DONE]
CREATE TABLE `tbl_contractor` (
    `contractor_id` INT NOT NULL,
    `name` VARCHAR(100) NOT NULL,
    `email` VARCHAR(100) NOT NULL,
    `phone_no` VARCHAR(20) DEFAULT NULL,
    `created_by` INT DEFAULT NULL,
    `updated_by` INT DEFAULT NULL,
    `creation_date` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
    `updation_date` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP 
        ON UPDATE CURRENT_TIMESTAMP,
    PRIMARY KEY (`contractor_id`),
    UNIQUE KEY `uq_tbl_contractor_email` (`email`)
) ENGINE=InnoDB
  DEFAULT CHARSET=utf8mb4
  COLLATE=utf8mb4_unicode_ci;
-- DEV[DONE] QA[DONE]
INSERT INTO `tbl_lookup` (`keyid`, `dev_name`, `display_name`, `display_name_ml`, `description`, `is_active`, `translate`, `creation_date`, `created_by`) 
VALUES ('93', 'stage7_closeout_stages', 'Close Out Stages', 'stage7_closeout_stages-ml', '', '1', 'No', CURRENT_TIMESTAMP, '1'),
('94', 'stage7_kpi_alignments', 'KPI Alignment', 'stage7_kpi_alignments-ml', '', '1', 'No', CURRENT_TIMESTAMP, '1');
-- DEV[DONE] QA[DONE]
INSERT INTO tbl_lookup_detail
(optionid, keyid, data_value, data_key, display_name, display_name_ml, sequence, is_active, creation_date, created_by)
SELECT optionid, keyid, data_value, data_key, display_name, display_name_ml, sequence, is_active, creation_date, created_by
FROM (
    SELECT max_id + 1 AS optionid, 93 AS keyid, '1' AS data_value,
           'stage7_closeout_stages_1' AS data_key, 'Initiation' AS display_name,
           'initiation-ml' AS display_name_ml, 1 AS sequence, 'active' AS is_active,
           CURRENT_TIMESTAMP AS creation_date, 1 AS created_by
    FROM (SELECT COALESCE(MAX(optionid), 0) AS max_id FROM tbl_lookup_detail) t

    UNION ALL

    SELECT max_id + 2, 93, '2',
           'stage7_closeout_stages_2', 'Planning',
           'planning-ml', 2, 'active',
           CURRENT_TIMESTAMP, 1
    FROM (SELECT COALESCE(MAX(optionid), 0) AS max_id FROM tbl_lookup_detail) t

    UNION ALL

    SELECT max_id + 3, 93, '3',
           'stage7_closeout_stages_3', 'Design',
           'design-ml', 3, 'active',
           CURRENT_TIMESTAMP, 1
    FROM (SELECT COALESCE(MAX(optionid), 0) AS max_id FROM tbl_lookup_detail) t

    UNION ALL

    SELECT max_id + 4, 93, '4',
           'stage7_closeout_stages_4', 'Tender',
           'tender-ml', 4, 'active',
           CURRENT_TIMESTAMP, 1
    FROM (SELECT COALESCE(MAX(optionid), 0) AS max_id FROM tbl_lookup_detail) t

    UNION ALL

    SELECT max_id + 5, 93, '5',
           'stage7_closeout_stages_5', 'Construction',
           'construction-ml', 5, 'active',
           CURRENT_TIMESTAMP, 1
    FROM (SELECT COALESCE(MAX(optionid), 0) AS max_id FROM tbl_lookup_detail) t

    UNION ALL

    SELECT max_id + 6, 93, '6',
           'stage7_closeout_stages_6', 'Close-out',
           'close-out-ml', 6, 'active',
           CURRENT_TIMESTAMP, 1
    FROM (SELECT COALESCE(MAX(optionid), 0) AS max_id FROM tbl_lookup_detail) t
) x;
-- DEV[DONE] QA[DONE]
INSERT INTO tbl_lookup_detail
(optionid, keyid, data_value, data_key, display_name, display_name_ml, sequence, item_data, is_active, creation_date, created_by)
SELECT optionid, keyid, data_value, data_key, display_name, display_name_ml, sequence, item_data, is_active, creation_date, created_by
FROM (
    SELECT max_id + 1 AS optionid, 94 AS keyid, '1' AS data_value,
           'stage7_kpi_alignments_1' AS data_key, 'Delivery' AS display_name,
           'delivery_ml' AS display_name_ml, 1 AS sequence,
           JSON_OBJECT('indicator','% On-Time Completion') AS item_data,
           'active' AS is_active, CURRENT_TIMESTAMP AS creation_date, 1 AS created_by
    FROM (SELECT COALESCE(MAX(optionid), 0) AS max_id FROM tbl_lookup_detail) t

    UNION ALL

    SELECT max_id + 2, 94, '2',
           'stage7_kpi_alignments_2', 'Budget Efficiency',
           'budget_efficiency_ml', 2,
           JSON_OBJECT('indicator','Final Cost Within Budget'),
           'active', CURRENT_TIMESTAMP, 1
    FROM (SELECT COALESCE(MAX(optionid), 0) AS max_id FROM tbl_lookup_detail) t

    UNION ALL

    SELECT max_id + 3, 94, '3',
           'stage7_kpi_alignments_3', 'Local Economic Impact',
           'local_economic_impact_ml', 3,
           JSON_OBJECT('indicator','Local Procurement Compliance'),
           'active', CURRENT_TIMESTAMP, 1
    FROM (SELECT COALESCE(MAX(optionid), 0) AS max_id FROM tbl_lookup_detail) t

    UNION ALL

    SELECT max_id + 4, 94, '4',
           'stage7_kpi_alignments_4', 'Job Creation',
           'job_creation_ml', 4,
           JSON_OBJECT('indicator','Target Met'),
           'active', CURRENT_TIMESTAMP, 1
    FROM (SELECT COALESCE(MAX(optionid), 0) AS max_id FROM tbl_lookup_detail) t

    UNION ALL

    SELECT max_id + 5, 94, '5',
           'stage7_kpi_alignments_5', 'Sustainability',
           'sustainability_ml', 5,
           JSON_OBJECT('indicator','Green Building Compliance'),
           'active', CURRENT_TIMESTAMP, 1
    FROM (SELECT COALESCE(MAX(optionid), 0) AS max_id FROM tbl_lookup_detail) t
) x;

-- DEV[DONE] QA[DONE]
INSERT INTO `tbl_platform_config` (`key`, `value`, `created_by`, `updated_by`, `creation_date`, `updation_date`) VALUES  ('stage7_project_detail_declaration', 'This is to certify that the above-mentioned project has been completed in accordance with the approved scope, specifications, and contract terms. All required inspections, tests, and compliance checks have been conducted and passed.', NULL, NULL, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP);
-- DEV[DONE] QA[DONE]
CREATE TABLE `tbl_project_stg7_closeout_summary` (
    `closeout_summary_id` INT NOT NULL,
    `project_id` INT NOT NULL,
    `data_key` VARCHAR(100) NOT NULL,
    `is_completed` SMALLINT DEFAULT 0,
    `completed_date` DATE DEFAULT NULL,
    `notes` VARCHAR(1000) DEFAULT NULL,
    `created_by` INT DEFAULT NULL,
    `updated_by` INT DEFAULT NULL,
    `creation_date` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,  
    `updation_date` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP
        ON UPDATE CURRENT_TIMESTAMP,
    PRIMARY KEY (`closeout_summary_id`)
) ENGINE=InnoDB
  DEFAULT CHARSET=utf8mb4
  COLLATE=utf8mb4_unicode_ci;
-- DEV[DONE] QA[DONE]
CREATE TABLE `tbl_project_stg7_kpi_alignment` (
    `kpi_alignment_id` INT NOT NULL,
    `project_id` INT NOT NULL,
    `data_key` VARCHAR(100) NOT NULL,
    `achieved` ENUM('Yes', 'No') DEFAULT NULL,
    `notes` VARCHAR(1000) DEFAULT NULL,
    `created_by` INT DEFAULT NULL,
    `updated_by` INT DEFAULT NULL,
    `creation_date` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
    `updation_date` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP
        ON UPDATE CURRENT_TIMESTAMP,
    PRIMARY KEY (`kpi_alignment_id`)
) ENGINE=InnoDB
  DEFAULT CHARSET=utf8mb4
  COLLATE=utf8mb4_unicode_ci;

-- DEV[DONE] QA[DONE]
CREATE TABLE `tbl_project_stg7_contractors` (
    `project_contractor_id` INT NOT NULL,
    `project_id` INT NOT NULL,
    `contractor_id` INT NOT NULL,
    `contract_no` VARCHAR(20) DEFAULT NULL,
    `created_by` INT DEFAULT NULL,
    `updated_by` INT DEFAULT NULL,
    `creation_date` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
    `updation_date` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP
        ON UPDATE CURRENT_TIMESTAMP,
    PRIMARY KEY (`project_contractor_id`)
) ENGINE=InnoDB
  DEFAULT CHARSET=utf8mb4
  COLLATE=utf8mb4_unicode_ci;

-- DEV[DONE] QA[DONE]
CREATE TABLE `tbl_project_stg7` (
    `project_id` INT NOT NULL,
    `certificate_no` VARCHAR(50) DEFAULT NULL,
    `start_date` DATE DEFAULT NULL,
    `completion_date` DATE DEFAULT NULL,
    `final_contract_value_zar` DECIMAL(10,2) DEFAULT 0.00,
    `project_manager_id` INT DEFAULT NULL,
    `department_representative_id` INT DEFAULT NULL,
    `project_manager_sign_off_date` DATE DEFAULT NULL,
    `department_representative_sign_off_date` DATE DEFAULT NULL,
    `project_manager_approval_status` VARCHAR(50) NOT NULL DEFAULT 'stage_status_1',
    `dept_rep_approval_status` VARCHAR(50) NOT NULL DEFAULT 'stage_status_1',
    `is_declaration_checked` TINYINT NOT NULL DEFAULT 0,
    `created_by` INT DEFAULT NULL,
    `updated_by` INT DEFAULT NULL,
    `creation_date` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
    `updation_date` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP
        ON UPDATE CURRENT_TIMESTAMP,
    PRIMARY KEY (`project_id`)
) ENGINE=InnoDB
  DEFAULT CHARSET=utf8mb4
  COLLATE=utf8mb4_unicode_ci;
-- DEV[DONE] QA[DONE]
INSERT INTO `tbl_maxids` (`id`, `tbl_name`, `max_id`) VALUES ('29', 'tbl_contractor', '0'),
('30', 'tbl_project_stg7_closeout_summary', '0'),
('31', 'tbl_project_stg7_kpi_alignment', '0'),
('32', 'tbl_project_stg7_contractors', '0');
-- 05-02-2026 Update tolerance_lower and tolerance_upper DEV[DONE] QA[DONE]
UPDATE `tbl_stg6_kpis_master` SET `tolerance_lower` = 10, `tolerance_upper` = 10;
UPDATE `tbl_budget_cost_items` SET `tolerance_lower` = 10, `tolerance_upper` = 10;

-- DATE 09-02-2026 Add new table DEV[DONE] QA[DONE]

CREATE TABLE `tbl_stg6_prod_cons_report_calender` (
  `report_calender_id` int UNSIGNED NOT NULL,
  `department_id` int NOT NULL,
  `year` year NOT NULL,
  `month` varchar(9) COLLATE utf8mb4_unicode_ci NOT NULL COMMENT 'January .. December',
  `from_date` date NOT NULL,
  `to_date` date NOT NULL,
  `type` enum('prod','cons') COLLATE utf8mb4_unicode_ci NOT NULL,
  `created_by` int NOT NULL,
  `creation_date` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_by` int DEFAULT NULL,
  `updation_date` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

ALTER TABLE `tbl_stg6_prod_cons_report_calender`
  ADD PRIMARY KEY (`report_calender_id`),
  ADD UNIQUE KEY `uq_report_calender_period` (`department_id`, `year`, `month`, `type`, `from_date`);

INSERT INTO `tbl_stg6_prod_cons_report_calender` (`report_calender_id`, `department_id`, `year`, `month`, `from_date`, `to_date`, `type`, `created_by`, `creation_date`, `updated_by`, `updation_date`) VALUES
(1, 1, '2026', 'january', '2026-01-01', '2026-01-31', 'prod', 151, '2026-02-09 11:09:55', NULL, '2026-02-09 11:09:55'),
(2, 1, '2026', 'february', '2026-02-01', '2026-02-28', 'prod', 151, '2026-02-09 11:09:55', NULL, '2026-02-09 11:09:55'),
(3, 1, '2026', 'march', '2026-03-01', '2026-03-31', 'prod', 151, '2026-02-09 11:09:55', NULL, '2026-02-09 11:09:55'),
(4, 1, '2026', 'april', '2026-04-01', '2026-04-30', 'prod', 151, '2026-02-09 11:09:55', NULL, '2026-02-09 11:09:55'),
(5, 1, '2026', 'may', '2026-05-01', '2026-05-31', 'prod', 151, '2026-02-09 11:09:55', NULL, '2026-02-09 11:09:55'),
(6, 1, '2026', 'june', '2026-06-01', '2026-06-30', 'prod', 151, '2026-02-09 11:09:55', NULL, '2026-02-09 11:09:55'),
(7, 1, '2026', 'july', '2026-07-01', '2026-07-31', 'prod', 151, '2026-02-09 11:09:55', NULL, '2026-02-09 11:09:55'),
(8, 1, '2026', 'august', '2026-08-01', '2026-08-31', 'prod', 151, '2026-02-09 11:09:55', NULL, '2026-02-09 11:09:55'),
(9, 1, '2026', 'september', '2026-09-01', '2026-09-30', 'prod', 151, '2026-02-09 11:09:55', NULL, '2026-02-09 11:09:55'),
(10, 1, '2026', 'october', '2026-10-01', '2026-10-31', 'prod', 151, '2026-02-09 11:09:55', NULL, '2026-02-09 11:09:55'),
(11, 1, '2026', 'november', '2026-11-01', '2026-11-30', 'prod', 151, '2026-02-09 11:09:55', NULL, '2026-02-09 11:09:55'),
(12, 1, '2026', 'december', '2026-12-01', '2026-12-31', 'prod', 151, '2026-02-09 11:09:55', NULL, '2026-02-09 11:09:55'),
(13, 1, '2026', 'january', '2026-01-01', '2026-01-31', 'cons', 151, '2026-02-09 11:09:55', NULL, '2026-02-09 11:09:55'),
(14, 1, '2026', 'february', '2026-02-01', '2026-02-28', 'cons', 151, '2026-02-09 11:09:55', NULL, '2026-02-09 11:09:55'),
(15, 1, '2026', 'march', '2026-03-01', '2026-03-31', 'cons', 151, '2026-02-09 11:09:55', NULL, '2026-02-09 11:09:55'),
(16, 1, '2026', 'april', '2026-04-01', '2026-04-30', 'cons', 151, '2026-02-09 11:09:55', NULL, '2026-02-09 11:09:55'),
(17, 1, '2026', 'may', '2026-05-01', '2026-05-31', 'cons', 151, '2026-02-09 11:09:55', NULL, '2026-02-09 11:09:55'),
(18, 1, '2026', 'june', '2026-06-01', '2026-06-30', 'cons', 151, '2026-02-09 11:09:55', NULL, '2026-02-09 11:09:55'),
(19, 1, '2026', 'july', '2026-07-01', '2026-07-31', 'cons', 151, '2026-02-09 11:09:55', NULL, '2026-02-09 11:09:55'),
(20, 1, '2026', 'august', '2026-08-01', '2026-08-31', 'cons', 151, '2026-02-09 11:09:55', NULL, '2026-02-09 11:09:55'),
(21, 1, '2026', 'september', '2026-09-01', '2026-09-30', 'cons', 151, '2026-02-09 11:09:55', NULL, '2026-02-09 11:09:55'),
(22, 1, '2026', 'october', '2026-10-01', '2026-10-31', 'cons', 151, '2026-02-09 11:09:55', NULL, '2026-02-09 11:09:55'),
(23, 1, '2026', 'november', '2026-11-01', '2026-11-30', 'cons', 151, '2026-02-09 11:09:55', NULL, '2026-02-09 11:09:55'),
(24, 1, '2026', 'december', '2026-12-01', '2026-12-31', 'cons', 151, '2026-02-09 11:09:55', NULL, '2026-02-09 11:09:55');

-- 12-02-2026 Backfill data for tbl_stg6_prod_cons_report_calender with all department_ids DEV[DONE] QA[DONE]
SET @rownum := (
    SELECT IFNULL(MAX(report_calender_id),0) 
    FROM tbl_stg6_prod_cons_report_calender
);

INSERT INTO tbl_stg6_prod_cons_report_calender
(report_calender_id, department_id, year, month, from_date, to_date, type, created_by)
SELECT 
    @rownum := @rownum + 1 AS report_calender_id,
    d.department_id,
    2026,
    m.month_name,
    m.start_date,
    m.end_date,
    t.type,
    1
FROM 
(
    SELECT 2 AS department_id UNION ALL
    SELECT 3 UNION ALL
    SELECT 4 UNION ALL
    SELECT 5 UNION ALL
    SELECT 6 UNION ALL
    SELECT 7 UNION ALL
    SELECT 8 UNION ALL
    SELECT 9 UNION ALL
    SELECT 10 UNION ALL
    SELECT 11 UNION ALL
    SELECT 12 UNION ALL
    SELECT 13 UNION ALL
    SELECT 14 UNION ALL
    SELECT 15 UNION ALL
    SELECT 16 UNION ALL
    SELECT 17 UNION ALL
    SELECT 18 UNION ALL
    SELECT 19 UNION ALL
    SELECT 20 UNION ALL
    SELECT 21
) d
CROSS JOIN
(
    SELECT 'january' AS month_name, '2026-01-01' AS start_date, '2026-01-31' AS end_date UNION ALL
    SELECT 'february','2026-02-01','2026-02-28' UNION ALL
    SELECT 'march','2026-03-01','2026-03-31' UNION ALL
    SELECT 'april','2026-04-01','2026-04-30' UNION ALL
    SELECT 'may','2026-05-01','2026-05-31' UNION ALL
    SELECT 'june','2026-06-01','2026-06-30' UNION ALL
    SELECT 'july','2026-07-01','2026-07-31' UNION ALL
    SELECT 'august','2026-08-01','2026-08-31' UNION ALL
    SELECT 'september','2026-09-01','2026-09-30' UNION ALL
    SELECT 'october','2026-10-01','2026-10-31' UNION ALL
    SELECT 'november','2026-11-01','2026-11-30' UNION ALL
    SELECT 'december','2026-12-01','2026-12-31'
) m
CROSS JOIN
(
    SELECT 'prod' AS type UNION ALL
    SELECT 'cons'
) t;


-- 10-02-2026 Add applicable column to tbl_project_tasks DEV[DONE] QA[DONE]
ALTER TABLE `tbl_project_tasks` ADD `applicable` ENUM('Yes', 'No') NOT NULL DEFAULT 'Yes' AFTER `at_risk`;

-- 12-02-2026 Add is_residual_risk column to tbl_project_stg5_risk_management DEV[DONE] QA[DONE]
ALTER TABLE `tbl_project_stg5_risk_management` ADD `is_residual_risk` ENUM('Yes', 'No') NULL DEFAULT 'No' AFTER `mitigate_risk_id`;
ALTER TABLE `tbl_project_stg5_risk_management` ADD `risk_residual_description` TEXT NULL DEFAULT NULL AFTER `description`;
-- 12-02-2026 Change residual_likelihood_key, residual_likelihood_value, residual_severity_key, residual_severity_value columns to VARCHAR(50) and INT DEV[DONE] QA[DONE]
ALTER TABLE `tbl_project_stg5_risk_management` CHANGE `residual_likelihood_key` `residual_likelihood_key` VARCHAR(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT NULL, CHANGE `residual_likelihood_value` `residual_likelihood_value` INT NULL DEFAULT NULL, CHANGE `residual_severity_key` `residual_severity_key` VARCHAR(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT NULL, CHANGE `residual_severity_value` `residual_severity_value` INT NULL DEFAULT NULL, CHANGE `mitigate_risk_level_id` `mitigate_risk_level_id` INT NULL DEFAULT NULL;

-- 12-02-2026 Add risk_score and residual_risk_score config DEV[DONE] QA[DONE]
INSERT INTO `tbl_platform_config` (`key`, `value`, `created_by`, `updated_by`, `creation_date`, `updation_date`) VALUES
('risk_config', '{\"risk_score\":{\"operator\":\">=\",\"value\":10},\"residual_risk_score\":{\"operator\":\">=\",\"value\":10}}', NULL, NULL, '2026-02-12 15:42:24', '2026-02-12 16:19:16');


-- 12-02-2026 Add risk_score and residual_risk_score config DEV[DONE] QA[DONE]
INSERT INTO `tbl_role_master` (`role_id`, `app_id`, `role_type`, `role_name`, `role_short_name`, `isAdmin`, `isActive`, `creation_date`, `created_by`, `updation_date`, `updated_by`) VALUES ('25', '1', 'responsible_party', 'DOI', 'DOI', '0', '1', TIMESTAMP('2025-12-03 17:21:48'), '1', NULL, NULL);
Delete FROM `tbl_department_roles` WHERE `department_id` = 4;

INSERT INTO `tbl_department_roles` (`department_role_id`, `department_id`, `role_id`, `role_speciality`, `is_active`)
VALUES
(NULL, 4, 25, 'Clerk of Works', 1),
(NULL, 4, 25, 'Communications', 1),
(NULL, 4, 25, 'Consultants', 1),
(NULL, 4, 25, 'Contractors', 1),
(NULL, 4, 25, 'DOI', 1),
(NULL, 4, 25, 'DOI Engineering', 1),
(NULL, 4, 25, 'DOI Env/Geotech', 1),
(NULL, 4, 25, 'DOI ICT', 1),
(NULL, 4, 25, 'DOI Planning', 1),
(NULL, 4, 25, 'DoM', 1),
(NULL, 4, 25, 'DoM Planning', 1),
(NULL, 4, 25, 'Energy EPC', 1),
(NULL, 4, 25, 'Landscape Architect', 1),
(NULL, 4, 25, 'Municipal Planning', 1),
(NULL, 4, 25, 'Municipal Transport', 1),
(NULL, 4, 25, 'Occupational Access Specialist', 1),
(NULL, 4, 25, 'OEMs', 1),
(NULL, 4, 25, 'OHS', 1),
(NULL, 4, 25, 'SITA/Service Providers', 1),
(NULL, 4, 25, 'Treasury', 1),
(NULL, 4, 25, 'Utilities', 1);
-- 16-02-2026 Add project completion certificate category DEV[DONE] QA[PENDING]
INSERT INTO `tbl_categories` (`cat_id`, `cat_name`, `dev_name`, `type`, `creation_date`, `created_by`, `updation_date`, `updated_by`) VALUES (NULL, 'Project Completion Certificate Report', 'project-completion-certificate-report', 'project', CURRENT_TIMESTAMP, NULL, NULL, NULL);

-- 24-02-2026 Add require_type column to tbl_project_task_poe_documents DEV[DONE] QA[PENDING]
ALTER TABLE `tbl_project_task_poe_documents` ADD `require_type` ENUM('optional','required', 'global') NOT NULL DEFAULT 'required' AFTER `document_id`;
ALTER TABLE `tbl_project_task_poe_documents` CHANGE `document_id` `document_id` VARCHAR(1000) NULL DEFAULT NULL;


-- DATE 02-03-2026 
-- Email queue table for DB-based email sending with retry support. DEV[PENDING] QA[PENDING]

CREATE TABLE IF NOT EXISTS `tbl_email_queue` (
  `id` INT(11) NOT NULL AUTO_INCREMENT,
  `status` VARCHAR(20) NOT NULL DEFAULT 'pending' COMMENT 'pending, processing, sent, failed, dead_letter',
  `send_to` VARCHAR(500) NOT NULL,
  `subject` VARCHAR(500) NOT NULL,
  `body` LONGTEXT NOT NULL,
  `address_cc` VARCHAR(500) DEFAULT NULL,
  `address_bcc` VARCHAR(500) DEFAULT NULL,
  `is_html` TINYINT(1) NOT NULL DEFAULT 1,
  `attachment_path` VARCHAR(1000) DEFAULT NULL COMMENT 'Comma-separated paths',
  `attempts` INT(11) NOT NULL DEFAULT 0,
  `max_attempts` INT(11) NOT NULL DEFAULT 3,
  `last_error` TEXT DEFAULT NULL,
  `locked_at` DATETIME DEFAULT NULL COMMENT 'When this row was claimed by a worker run',
  `locked_by` VARCHAR(64) DEFAULT NULL COMMENT 'Unique run id of the worker that claimed this row',
  `email_type` VARCHAR(50) DEFAULT NULL COMMENT 'e.g. evaluation_reminder; copied to history on send',
  `scheduled_at` DATETIME NOT NULL,
  `created_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
  `sent_at` DATETIME DEFAULT NULL,
  `updated_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  PRIMARY KEY (`id`),
  KEY `idx_status_scheduled` (`status`, `scheduled_at`),
  KEY `idx_created_at` (`created_at`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Add email queue config keys to tbl_platform_config. DEV[PENDING] QA[PENDING]

INSERT IGNORE INTO tbl_platform_config (`key`, `value`, `created_by`, `updated_by`, `creation_date`, `updation_date`)
VALUES
('email_queue_max_attempts', '3', NULL, NULL, NOW(), NOW()),
('email_queue_retry_backoff_minutes', '5', NULL, NULL, NOW(), NOW()),
('email_queue_throttle_seconds', '5', NULL, NULL, NOW(), NOW()),
('email_queue_processing_timeout_minutes', '15', NULL, NULL, NOW(), NOW());


-- Email history table. DEV[PENDING] QA[PENDING]
CREATE TABLE IF NOT EXISTS tbl_email_history (
  id INT(11) NOT NULL AUTO_INCREMENT,
  sent_at DATETIME NOT NULL COMMENT 'When the email was sent',
  email_type VARCHAR(50) NOT NULL DEFAULT 'general' COMMENT 'e.g. evaluation_reminder, stakeholder_report',
  subject VARCHAR(500) NOT NULL,
  body LONGTEXT NOT NULL,
  send_to VARCHAR(500) NOT NULL COMMENT 'To address(es), comma-separated',
  address_cc VARCHAR(500) DEFAULT NULL,
  address_bcc VARCHAR(500) DEFAULT NULL,
  created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
  PRIMARY KEY (id),
  KEY idx_sent_at (sent_at),
  KEY idx_email_type (email_type)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;


-- Email templates table: store subject, body and common email fields with variable placeholders ({{variable_name}} or {{variable_name:raw}} for HTML). DEV[PENDING] QA[PENDING]

CREATE TABLE IF NOT EXISTS tbl_email_templates (
  id INT(11) NOT NULL AUTO_INCREMENT,
  template_key VARCHAR(80) NOT NULL,
  name VARCHAR(255) DEFAULT NULL COMMENT 'Human-readable name',
  subject VARCHAR(500) NOT NULL,
  body LONGTEXT NOT NULL,
  is_html TINYINT(1) NOT NULL DEFAULT 1,
  use_common_layout TINYINT(1) NOT NULL DEFAULT 1 COMMENT '1 = wrap body with common_layout.html via renderCommonEmailBody',
  created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
  updated_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  PRIMARY KEY (id),
  UNIQUE KEY uk_template_key (template_key)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Seed evaluation_reminder template. Variables: {{evaluator_name}}, {{project_summary}}, {{project_list_html:raw}}, {{email_title}} DEV[PENDING] QA[PENDING]
INSERT INTO tbl_email_templates (template_key, name, subject, body, is_html, use_common_layout, created_at, updated_at)
VALUES (
  'evaluation_reminder',
  'Project evaluation reminder to evaluator',
  'Reminder: Project(s) evaluation pending - {{project_summary}}',
  '<p>Dear <strong>{{evaluator_name}}</strong>,</p><p>This is a reminder that the following project(s) are pending your evaluation:</p>{{project_list_html:raw}}<p>Thank you,<br>DOI Platform</p>',
  1,
  1,
  NOW(),
  NOW()
) ON DUPLICATE KEY UPDATE updated_at = NOW();

-- Add header/footer columns to tbl_email_templates for configurable common layout. DEV[PENDING] QA[PENDING]
ALTER TABLE tbl_email_templates ADD COLUMN header_html LONGTEXT NULL COMMENT 'Override common layout header; used when template_key=common_layout';
ALTER TABLE tbl_email_templates ADD COLUMN footer_html LONGTEXT NULL COMMENT 'Override common layout footer; used when template_key=common_layout';

-- Seed common_layout row for configurable header/footer. Header/footer can use {{logo_url}} placeholder.
INSERT INTO tbl_email_templates (template_key, name, subject, body, is_html, use_common_layout, header_html, footer_html, created_at, updated_at)
VALUES (
  'common_layout',
  'Common email layout header and footer (configurable)',
  '',
  '',
  1,
  0,
  '<tr><td style="background: rgb(8, 20, 65); padding:30px; text-align:center;"><table cellpadding="0" cellspacing="0" border="0" align="center"><tr><td style="vertical-align:middle; padding-right:12px;"><img src="{{logo_url}}" width="60" height="60" alt="WCG Logo" style="display:block;"></td><td style="vertical-align:middle;"><span style="color:#ffffff; font-size:26px; font-weight:bold;">DOI Platform</span></td></tr></table></td></tr>',
  '<tr><td style="padding:16px 40px; font-size:12px; color:#666666; border-top:1px solid #dddddd; background:#fafafa;"><p style="margin:0;">This is an automated message from the DOI Platform. Please do not reply directly to this email.</p></td></tr>',
  NOW(),
  NOW()
) ON DUPLICATE KEY UPDATE updated_at = NOW();


-- Date 03-03-2026  Add overdue project status DEV[PENDING] QA[PENDING]
INSERT INTO `tbl_lookup_detail` (`optionid`, `keyid`, `data_value`, `data_key`, `display_name`, `display_name_ml`, `sequence`, `item_data`, `parent_datakey`, `is_active`, `creation_date`, `created_by`, `updation_date`, `updated_by`) 
VALUES ('1068', '2', '4', 'project_status_4', 'Overdue', 'overdue-ml', '4', '', NULL, 'active', '2026-02-09 15:00:05', '1', NULL, NULL);

-- Date 06-03-2026  Add overdue project status DEV[PENDING] QA[PENDING]
ALTER TABLE `tbl_project_evaluators` CHANGE `eval_status` `eval_status` ENUM('pending','in Progress','completed', 'overdue') CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci NOT NULL DEFAULT 'pending';

-- Date 06-03-2026  Add notifications table DEV[PENDING] QA[PENDING]
CREATE TABLE tbl_notifications (
    id BIGINT AUTO_INCREMENT PRIMARY KEY,
    user_id INT NULL,
    project_id INT NULL,
    type VARCHAR(50),
    title VARCHAR(255),
    message TEXT,
    action_url VARCHAR(255),
    reference_id INT NULL,
    is_global ENUM('Yes','No') DEFAULT 'No',
    is_read TINYINT(1) DEFAULT 0,
    is_important TINYINT(1) DEFAULT 0,
    priority ENUM('low','medium','high') DEFAULT 'medium',
    created_by INT NULL,
    updated_by INT NULL,
    creation_date DATETIME DEFAULT CURRENT_TIMESTAMP,
    updation_date DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,

    INDEX(user_id, is_read),
    INDEX(user_id, is_important),
    INDEX(priority),
    INDEX(is_global)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- DEV[DONE] QA[PENDING]
ALTER TABLE `tbl_project_stg6_site_progress_report_data` CHANGE `planned_completion` `planned_completion` BIGINT UNSIGNED NULL, 
CHANGE `actual_completion` `actual_completion` BIGINT UNSIGNED NULL, 
CHANGE `variance` `variance` BIGINT NULL;

-- DEV[DONE] QA[PENDING]
ALTER TABLE `tbl_project_stg6_workforce_and_equipement` CHANGE `planned_no_of_assets` `planned_no_of_assets` BIGINT NULL, 
CHANGE `actual_no_of_assets` `actual_no_of_assets` BIGINT NULL, 
CHANGE `no_of_assets_variance` `no_of_assets_variance` BIGINT NULL, 
CHANGE `expenditure_till_previous_month` `expenditure_till_previous_month` BIGINT NULL, 
CHANGE `current_month_expenditure` `current_month_expenditure` BIGINT NULL, 
CHANGE `total_expenditure` `total_expenditure` BIGINT NULL, 
CHANGE `budget_variance` `budget_variance` BIGINT NULL;

-- DATE 11-02-2026 
-- Stage-8 tables

-- TABLE: tbl_lookup DEV[DONE] QA[PENDING]
INSERT INTO `tbl_lookup` (`keyid`, `dev_name`, `display_name`, `display_name_ml`, `description`, `is_active`, `translate`, `creation_date`, `created_by`, `updation_date`, `updated_by`) VALUES ('95', 'stage8_sector_specific', 'Sector Specific', 'stage8_sector_specific-ml', '', '1', 'No', '2026-02-09 15:00:05', '1', NULL, NULL);

-- TABLE: tbl_lookup_detail DEV[DONE] QA[PENDING]
INSERT INTO `tbl_lookup_detail`
(`optionid`, `keyid`, `data_value`, `data_key`, `display_name`, `display_name_ml`, `sequence`, `item_data`, `parent_datakey`, `is_active`, `creation_date`, `created_by`, `updation_date`, `updated_by`)
VALUES
('1039', '95', '1', 'stage8_sector_specific_1', 'Transport (Provincial Roads)', 'transport-provincial-roads-ml', '1', '', NULL, 'active', '2026-02-09 15:00:05', '1', NULL, NULL),

('1040', '95', '2', 'stage8_sector_specific_2', 'Human Settlements', 'human_settlements-ml', '2', '', NULL, 'active', '2026-02-09 15:00:05', '1', NULL, NULL),

('1041', '95', '3', 'stage8_sector_specific_3', 'Health Facilities', 'health_facilities-ml', '3', '', NULL, 'active', '2026-02-09 15:00:05', '1', NULL, NULL),

('1042', '95', '4', 'stage8_sector_specific_4', 'Education Facilities', 'education_facilities-ml', '4', '', NULL, 'active', '2026-02-09 15:00:05', '1', NULL, NULL),

('1043', '95', '5', 'stage8_sector_specific_5', 'Water & Sanitation', 'water_sanitation-ml', '5', '', NULL, 'active', '2026-02-09 15:00:05', '1', NULL, NULL),

('1044', '95', '6', 'stage8_sector_specific_6', 'Energy (Resilience)', 'energy_resilience-ml', '6', '', NULL, 'active', '2026-02-09 15:00:05', '1', NULL, NULL),

('1045', '95', '7', 'stage8_sector_specific_7', 'Digital Infrastructure', 'digital_infrastructure-ml', '7', '', NULL, 'active', '2026-02-09 15:00:05', '1', NULL, NULL),

('1046', '95', '8', 'stage8_sector_specific_8', 'Public Works / Facilities', 'public_works_facilities-ml', '8', '', NULL, 'active', '2026-02-09 15:00:05', '1', NULL, NULL),

('1047', '95', '9', 'stage8_sector_specific_9', 'Climate Resilience & Environment', 'climate_resilience_environment-ml', '9', '', NULL, 'active', '2026-02-09 15:00:05', '1', NULL, NULL),

('1048', '95', '10', 'stage8_sector_specific_10', 'Economic Infrastructure / Precincts', 'economic_infrastructure_precincts-ml', '10', '', NULL, 'active', '2026-02-09 15:00:05', '1', NULL, NULL);


-- TABLE: tbl_stg8_department_sector_specific DEV[DONE] QA[PENDING]
CREATE TABLE `tbl_stg8_department_sector_specific` (
  `department_sector_id` int UNSIGNED NOT NULL,
  `department_id` int UNSIGNED NOT NULL,
  `sector_specific_id` int UNSIGNED NOT NULL COMMENT 'FK: tbl_lookup_details',
  `created_by` int NOT NULL,
  `creation_date` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_by` int DEFAULT NULL,
  `updation_date` timestamp NULL DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

 --DEV[DONE] QA[PENDING]
ALTER TABLE `tbl_stg8_department_sector_specific`
  ADD PRIMARY KEY (`department_sector_id`),
  ADD UNIQUE KEY `uniq_department_sector` (`department_id`,`sector_specific_id`);
COMMIT;


-- DEV[DONE] QA[PENDING]
INSERT INTO `tbl_stg8_department_sector_specific` (`department_sector_id`, `department_id`, `sector_specific_id`, `created_by`, `creation_date`, `updated_by`, `updation_date`) VALUES
(1, 4, 1039, 1, '2026-02-11 09:57:02', NULL, NULL),
(2, 4, 1047, 1, '2026-02-11 09:57:02', NULL, NULL),
(3, 4, 1048, 1, '2026-02-11 09:57:02', NULL, NULL),
(4, 12, 1040, 1, '2026-02-11 09:57:02', NULL, NULL),
(5, 12, 1047, 1, '2026-02-11 09:57:02', NULL, NULL),
(6, 12, 1048, 1, '2026-02-11 09:57:02', NULL, NULL),
(7, 2, 1041, 1, '2026-02-11 09:57:02', NULL, NULL),
(8, 2, 1047, 1, '2026-02-11 09:57:02', NULL, NULL),
(9, 2, 1048, 1, '2026-02-11 09:57:02', NULL, NULL),
(10, 3, 1042, 1, '2026-02-11 09:57:02', NULL, NULL),
(11, 3, 1047, 1, '2026-02-11 09:57:02', NULL, NULL),
(12, 3, 1048, 1, '2026-02-11 09:57:02', NULL, NULL),
(13, 6, 1043, 1, '2026-02-11 09:57:02', NULL, NULL),
(14, 6, 1047, 1, '2026-02-11 09:57:02', NULL, NULL),
(15, 6, 1048, 1, '2026-02-11 09:57:02', NULL, NULL),
(16, 9, 1044, 1, '2026-02-11 09:57:02', NULL, NULL),
(17, 9, 1047, 1, '2026-02-11 09:57:02', NULL, NULL),
(18, 9, 1048, 1, '2026-02-11 09:57:02', NULL, NULL),
(19, 21, 1045, 1, '2026-02-11 09:57:02', NULL, NULL),
(20, 21, 1047, 1, '2026-02-11 09:57:02', NULL, NULL),
(21, 21, 1048, 1, '2026-02-11 09:57:02', NULL, NULL),
(22, 5, 1046, 1, '2026-02-11 09:57:02', NULL, NULL),
(23, 5, 1047, 1, '2026-02-11 09:57:02', NULL, NULL),
(24, 5, 1048, 1, '2026-02-11 09:57:02', NULL, NULL);

-- DEV[DONE] QA[PENDING]
CREATE TABLE IF NOT EXISTS `tbl_stg8_kpi_master`(
  `kpi_id` int UNSIGNED NOT NULL,
  `sector_specific_data_key` varchar(100) COLLATE utf8mb4_unicode_ci NOT NULL,
  `kpi_code` varchar(100) COLLATE utf8mb4_unicode_ci NOT NULL,
  `kpi_name` text COLLATE utf8mb4_unicode_ci NOT NULL,
  `defination` text COLLATE utf8mb4_unicode_ci NOT NULL,
  `unit` enum('%','days','hours','kWp','km','number','index') COLLATE utf8mb4_unicode_ci NOT NULL,
  `default_target` decimal(10,2) DEFAULT NULL,
  `direction` enum('>=','<=') COLLATE utf8mb4_unicode_ci NOT NULL,
  `frequency` enum('Monthly','Quarterly','Annual','Seasonal') COLLATE utf8mb4_unicode_ci NOT NULL,
  `data_source` text COLLATE utf8mb4_unicode_ci,
  `owner` varchar(150) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `wcif_outcome_alignment` text COLLATE utf8mb4_unicode_ci,
  `created_by` int NOT NULL,
  `creation_date` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_by` int DEFAULT NULL,
  `updation_date` timestamp NULL DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;


ALTER TABLE `tbl_stg8_kpi_master` ADD PRIMARY KEY (`kpi_id`);

-- DEV[DONE] QA[PENDING]

INSERT INTO `tbl_stg8_kpi_master` (`kpi_id`, `sector_specific_data_key`, `kpi_code`, `kpi_name`, `defination`, `unit`, `default_target`, `direction`, `frequency`, `data_source`, `owner`, `wcif_outcome_alignment`, `created_by`, `creation_date`, `updated_by`, `updation_date`) VALUES
(1, 'stage8_sector_specific_1', 'TR_VCI_GOOD', '% paved provincial roads in fair/good condition (VCI)', 'Share of paved provincial road length with Visual Condition Index rated fair or better.', '%', 80.00, '>=', 'Annual', 'RNIS / Provincial Roads Condition Surveys', 'DoI Roads Infrastructure', 'Mobility systems provide safe and efficient connectivity', 1, '2026-02-11 12:52:18', NULL, NULL),
(2, 'stage8_sector_specific_1', 'TR_POTHOLE_RT', 'Average time to repair potholes', 'Average calendar days from defect report to permanent repair for potholes on provincial roads.', 'days', 7.00, '<=', 'Monthly', 'Maintenance CMMS / RNIS', 'DoI Roads Infrastructure', 'Mobility systems provide safe and efficient connectivity', 1, '2026-02-11 12:52:18', NULL, NULL),
(3, 'stage8_sector_specific_1', 'TR_BRIDGE_INSP', '% bridges inspected to standard', 'Proportion of provincial bridges inspected in accordance with the bridge management system schedules.', '%', 95.00, '>=', 'Quarterly', 'Bridge Management System', 'DoI Roads Infrastructure', 'Mobility systems provide safe and efficient connectivity', 1, '2026-02-11 12:52:18', NULL, NULL),
(4, 'stage8_sector_specific_2', 'HS_PM_ADH', '% preventative maintenance tasks completed on-time (rental stock)', 'On-time completion rate of scheduled preventative maintenance on provincial/community rental units.', '%', 95.00, '>=', 'Monthly', 'Housing Maintenance System', 'WCG Human Settlements', 'Households have increased access to basic services and improved shelter', 1, '2026-02-11 12:52:18', NULL, NULL),
(5, 'stage8_sector_specific_2', 'HS_EMERG_TAT', 'Emergency repair turnaround time', 'Median hours to restore habitability for emergency housing repairs (e.g., leaks, electrical faults).', 'hours', 24.00, '<=', 'Monthly', 'Call centre / ticketing', 'WCG Human Settlements', 'Households have increased access to basic services and improved shelter', 1, '2026-02-11 12:52:18', NULL, NULL),
(6, 'stage8_sector_specific_3', 'HL_IDEAL_MNT', '% facilities compliant with ICRM maintenance elements', 'Share of clinics/hospitals meeting Ideal Clinic/CHC maintenance-related elements.', '%', 85.00, '>=', 'Quarterly', 'ICRM assessments / OHSC', 'Dept. Health & Wellness', 'Investment in social infrastructure improves access to health', 1, '2026-02-11 12:52:18', NULL, NULL),
(7, 'stage8_sector_specific_3', 'HL_CRIT_SYS_UP', 'Critical systems uptime at hospitals', 'Percentage uptime of critical hospital systems (power, HVAC, oxygen) during maintenance period.', '%', 99.00, '>=', 'Monthly', 'BMS/SCADA logs', 'Dept. Health & Wellness', 'Investment in social infrastructure improves access to health', 1, '2026-02-11 12:52:18', NULL, NULL),
(8, 'stage8_sector_specific_4', 'ED_SANI_FUNC', '% schools with functional sanitation & water', 'Proportion of schools meeting Norms & Standards for sanitation and water functionality.', '%', 98.00, '>=', 'Quarterly', 'WCED Facilities Assessments', 'WCED', 'Investment in social infrastructure improves access to education', 1, '2026-02-11 12:52:18', NULL, NULL),
(9, 'stage8_sector_specific_4', 'ED_WO_SLA', '% maintenance work orders closed within SLA', 'Share of education facility maintenance work orders closed within agreed SLA windows.', '%', 90.00, '>=', 'Monthly', 'CMMS / Helpdesk', 'WCED', 'Investment in social infrastructure improves access to education', 1, '2026-02-11 12:52:18', NULL, NULL),
(10, 'stage8_sector_specific_5', 'WS_INT_RES', '% water supply interruptions resolved within SLA', 'Proportion of water supply interruptions at WCG facilities resolved within SLA.', '%', 95.00, '>=', 'Monthly', 'Facilities helpdesk / municipal reports', 'DoI / Local Govt interface', 'Households have increased access to basic services', 1, '2026-02-11 12:52:18', NULL, NULL),
(11, 'stage8_sector_specific_5', 'WS_GREEN_DROP', '% WWTWs serving WCG sites with Green Drop >80%', 'Share of municipal WWTWs servicing WCG priority sites with Green Drop score ≥80%.', '%', 70.00, '>=', 'Annual', 'DWS Green Drop', 'Local Government / DWS', 'Resource resilience & ecological infrastructure', 1, '2026-02-11 12:52:18', NULL, NULL),
(12, 'stage8_sector_specific_6', 'EN_FAC_UP', '% critical facilities with backup power uptime ≥ 99%', 'Proportion of designated critical WCG facilities maintaining ≥99% electrical uptime (grid + backup).', '%', 95.00, '>=', 'Monthly', 'Energy dashboard / facility logs', 'DotP / DoI / Health / WCED', 'Secure, decarbonised, affordable energy', 1, '2026-02-11 12:52:18', NULL, NULL),
(13, 'stage8_sector_specific_6', 'EN_SSEG_KWP', 'Solar PV capacity installed at WCG sites (kWp)', 'Cumulative small-scale embedded generation capacity commissioned at WCG facilities.', 'kWp', 1000.00, '>=', 'Quarterly', 'WCG Energy Dashboard', 'DotP / DoI', 'Secure, decarbonised, affordable energy', 1, '2026-02-11 12:52:18', NULL, NULL),
(14, 'stage8_sector_specific_7', 'DG_UPTIME', 'Network uptime at WCG sites', 'Percentage WAN/LAN uptime at WCG connected facilities.', '%', 99.50, '>=', 'Monthly', 'Network monitoring (NOC)', 'DotP / SITA / Vendor', 'Connecting through infrastructure and digitalisation', 1, '2026-02-11 12:52:18', NULL, NULL),
(15, 'stage8_sector_specific_7', 'DG_MTRS', 'Mean time to restore (MTTR) WAN incidents', 'Average hours to restore critical WAN incidents at WCG sites.', 'hours', 4.00, '<=', 'Monthly', 'NOC incident system', 'DotP / SITA / Vendor', 'Connecting through infrastructure and digitalisation', 1, '2026-02-11 12:52:18', NULL, NULL),
(16, 'stage8_sector_specific_8', 'PW_FCI', 'Facility Condition Index (FCI) <= 0.15', 'Share of buildings with FCI at or below 0.15 after planned maintenance.', '%', 80.00, '>=', 'Annual', 'Condition assessments / U-AMP', 'DoI Immovable Assets', 'Protecting the existing infrastructure portfolio', 1, '2026-02-11 12:52:18', NULL, NULL),
(17, 'stage8_sector_specific_8', 'PW_PM_ADH', '% planned maintenance tasks completed on time', 'On-time completion rate for planned preventative maintenance across WCG facilities.', '%', 95.00, '>=', 'Monthly', 'CMMS', 'DoI Facilities Management', 'Protecting the existing infrastructure portfolio', 1, '2026-02-11 12:52:18', NULL, NULL),
(18, 'stage8_sector_specific_9', 'CR_STORM_PREP', '% stormwater & flood mitigation maintenance completed pre-rainy season', 'Share of identified stormwater and flood mitigation assets at risk locations maintained before rainy season.', '%', 95.00, '>=', 'Seasonal', 'Maintenance plans / Disaster risk', 'DoI / Local Govt / DEADP', 'Infrastructure investment improves spatial resilience', 1, '2026-02-11 12:52:18', NULL, NULL),
(19, 'stage8_sector_specific_9', 'CR_ENERGY_EFF', '% facilities achieving annual energy intensity reduction', 'Share of facilities achieving ≥5% year-on-year energy intensity reduction through O&M actions.', '%', 60.00, '>=', 'Annual', 'Utility bills / Energy M&V', 'DotP / DoI', 'Resource resilience & decarbonisation', 1, '2026-02-11 12:52:18', NULL, NULL),
(20, 'stage8_sector_specific_10', 'EC_PUBLIC_REALM_PM', '% public realm assets in priority precincts maintained to standard', 'Proportion of lighting, CCTV, sidewalks and landscaping in designated precincts meeting maintenance standards.', '%', 90.00, '>=', 'Quarterly', 'Precinct O&M audits', 'DoI / Municipal partners', 'Mobility, public space and economic opportunity', 1, '2026-02-11 12:52:18', NULL, NULL),
(21, 'stage8_sector_specific_10', 'EC_TAT_PERMITS', 'Average turnaround time for wayleave/permits (days)', 'Average days to process maintenance-related wayleaves/permits for infrastructure works in precincts.', 'days', 10.00, '<=', 'Monthly', 'Municipal permitting systems', 'Municipal partners / DoI', 'Coordinated planning & delivery', 1, '2026-02-11 12:52:18', NULL, NULL);

-- DEV[DONE] QA[PENDING]
CREATE TABLE tbl_project_stg8_data (
    stg8_data_id INT UNSIGNED NOT NULL,
    project_id INT UNSIGNED NOT NULL,
    maintenance_start DATE NOT NULL,
    maintenance_end DATE NOT NULL,
    created_by INT UNSIGNED NOT NULL,
    creation_date TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
    updated_by INT UNSIGNED NULL,
    updation_date TIMESTAMP NULL,
    PRIMARY KEY (stg8_data_id),
    UNIQUE KEY uniq_project_period 
    (project_id, maintenance_start, maintenance_end)
);

-- DEV[PENDING] QA[PENDING]
INSERT INTO `tbl_maxids` (`id`, `tbl_name`, `max_id`) VALUES ('33', 'tbl_project_stg8_data', '0');


-- DEV[DONE] QA[PENDING]
START TRANSACTION;

CREATE TABLE `tbl_project_stg8_kpi_data` (
  `stg8_kpi_data_id` int UNSIGNED NOT NULL,
  `stg8_data_id` int NOT NULL,
  `project_id` int NOT NULL,
  `kpi_master_id` int NOT NULL,
  `actual` decimal(15,4) NOT NULL,
  `notes` text COLLATE utf8mb4_unicode_ci NOT NULL,
  `created_by` int NOT NULL,
  `creation_date` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_by` int DEFAULT NULL,
  `updation_date` datetime DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

ALTER TABLE `tbl_project_stg8_kpi_data`
  ADD PRIMARY KEY (`stg8_kpi_data_id`);

-- DEV[DONE] QA[PENDING]
INSERT INTO `tbl_maxids` (`id`, `tbl_name`, `max_id`) VALUES ('34', 'tbl_project_stg8_kpi_data', '0');

COMMIT;

-- DATE 13-03-2026  DEV[DONE] QA[PENDING]
UPDATE `tbl_email_templates` SET `header_html` = '<tr>\n  <td style=\"background: rgb(8, 20, 65); padding:24px 30px; text-align:left;\">\n    <table cellpadding=\"0\" cellspacing=\"0\" border=\"0\" align=\"left\" style=\"width:100%;\">\n      <tr>\n        <!-- Left: visible logo + platform name -->\n        <td style=\"vertical-align:middle; padding-right:12px; white-space:nowrap;\">\n          <table cellpadding=\"0\" cellspacing=\"0\" border=\"0\">\n            <tr>\n              <td style=\"vertical-align:middle; padding-right:12px;\">\n                <img src=\"{{logo_url}}\" width=\"60\" height=\"60\" alt=\"WCG Logo\" style=\"display:block;\">\n              </td>\n              <td style=\"vertical-align:middle;\">\n                <span style=\"color:#ffffff; font-size:26px; font-weight:bold;\">DOI Platform</span>\n              </td>\n            </tr>\n          </table>\n        </td>\n\n        <!-- Center: dynamic email title block -->\n        <td style=\"vertical-align:middle;\">\n          {{email_title_block}}\n        </td>\n      </tr>\n    </table>\n  </td>\n</tr>' WHERE `tbl_email_templates`.`template_key` = 'common_layout';

-- DATE 17-03-2026  DEV[DONE] QA[PENDING]
INSERT INTO `tbl_platform_config` (`key`, `value`, `created_by`, `updated_by`, `creation_date`, `updation_date`) 
VALUES ('email_queue_batch_size', '25', NULL, NULL, '2026-03-17 15:01:21', '2026-03-17 15:01:21'),
('email_queue_throttle_max_seconds', '300', NULL, NULL, '2026-03-17 15:01:21', '2026-03-17 15:01:21');

-- DATE 18-03-2026  DEV[PENDING] QA[PENDING]
INSERT INTO `tbl_platform_config` (`key`, `value`, `created_by`, `updated_by`, `creation_date`, `updation_date`) VALUES ('default_session_timeout', '60', '1', NULL, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP);

-- DATE 20-03-2026  DEV[DONE] QA[PENDING]
ALTER TABLE `tbl_categories` ADD `parent_id` INT NOT NULL DEFAULT '0' AFTER `type`, ADD `extra_data` TEXT NULL DEFAULT NULL AFTER `parent_id`;

-- Start Housing Insert Data
INSERT INTO `tbl_categories` (`cat_id`, `cat_name`, `dev_name`, `type`, `parent_id`, `extra_data`, `creation_date`, `created_by`, `updation_date`, `updated_by`) VALUES (NULL, 'Housing', 'housing', 'eve', '0', '{"icon":"faHouse","color":"#ffd258"}', current_timestamp(), NULL, NULL, NULL);

SET @parent_id = (SELECT cat_id FROM tbl_categories WHERE dev_name = 'housing' LIMIT 1);
INSERT INTO `tbl_categories`
(`cat_name`, `dev_name`, `type`, `parent_id`, `extra_data`, `creation_date`)
VALUES
('Guidelines / Manuals', 'guidelines-manuals', 'eve', @parent_id, '{"icon":"faFolder","color":"#ffd258"}', CURRENT_TIMESTAMP()),
('Legislation', 'legislation', 'eve', @parent_id, '{"icon":"faFolder","color":"#ffd258"}', CURRENT_TIMESTAMP()),
('Policy / Programme Documents', 'policy-programme-documents', 'eve', @parent_id, '{"icon":"faFolder","color":"#ffd258"}', CURRENT_TIMESTAMP()),
('Reports & Evaluations', 'reports-evaluations', 'eve', @parent_id, '{"icon":"faFolder","color":"#ffd258"}', CURRENT_TIMESTAMP());
-- End Housing Insert  Data

-- Start Prescripts Insert Data
INSERT INTO `tbl_categories`(`cat_name`,`dev_name`,`type`,`parent_id`,`extra_data`,`creation_date`) VALUES('Prescripts','prescripts','eve',0,'{"icon":"faBook","color":"#9fc5e8"}',CURRENT_TIMESTAMP());

SET @parent_id = (SELECT cat_id FROM tbl_categories WHERE dev_name='prescripts' LIMIT 1);

INSERT INTO `tbl_categories`(`cat_name`,`dev_name`,`type`,`parent_id`,`extra_data`,`creation_date`) VALUES
('Prescripts, Delegation & Case Law','prescripts-delegation-case-law','eve',@parent_id,'{"icon":"faFolder","color":"#ffd258"}',CURRENT_TIMESTAMP()),
('Climate, Environment & Sustainability','climate-environment-sustainability','eve',@parent_id,'{"icon":"faFolder","color":"#ffd258"}',CURRENT_TIMESTAMP()),
('Economic, growth development & Employment','economic-growth-development-employment','eve',@parent_id,'{"icon":"faFolder","color":"#ffd258"}',CURRENT_TIMESTAMP()),
('Governance & Oversight','governance-oversight','eve',@parent_id,'{"icon":"faFolder","color":"#ffd258"}',CURRENT_TIMESTAMP()),
('National Strategic Planning & Development','national-strategic-planning-development','eve',@parent_id,'{"icon":"faFolder","color":"#ffd258"}',CURRENT_TIMESTAMP()),
('Spatial Planning & Infrastructure','spatial-planning-infrastructure','eve',@parent_id,'{"icon":"faFolder","color":"#ffd258"}',CURRENT_TIMESTAMP());
-- End Prescripts Insert Data

-- Start Agriculture Insert Data
INSERT INTO `tbl_categories`(`cat_name`,`dev_name`,`type`,`parent_id`,`extra_data`,`creation_date`) VALUES('Agriculture','agriculture','eve',0,'{"icon":"faSeedling","color":"#8fce00"}',CURRENT_TIMESTAMP());

SET @parent_id = (SELECT cat_id FROM tbl_categories WHERE dev_name='agriculture' LIMIT 1);

INSERT INTO `tbl_categories`(`cat_name`,`dev_name`,`type`,`parent_id`,`extra_data`,`creation_date`) VALUES
('Annual Report','annual-report-agree','eve',@parent_id,'{"icon":"faFolder","color":"#ffd258"}',CURRENT_TIMESTAMP()),
('Policy Framework','policy-framework-agree','eve',@parent_id,'{"icon":"faFolder","color":"#ffd258"}',CURRENT_TIMESTAMP());
-- End Agriculture Insert Data

-- Start Dep of Cultural Affairs and Sport Insert Data
INSERT INTO `tbl_categories`(`cat_name`,`dev_name`,`type`,`parent_id`,`extra_data`,`creation_date`) VALUES('Dep of Cultural Affairs and Sport','dep-cultural-affairs-sport','eve',0,'{"icon":"faShieldHalved","color":"#3d85c6"}',CURRENT_TIMESTAMP());
SET @parent_id = (SELECT cat_id FROM tbl_categories WHERE dev_name='dep-cultural-affairs-sport' LIMIT 1);
INSERT INTO `tbl_categories`(`cat_name`,`dev_name`,`type`,`parent_id`,`extra_data`,`creation_date`) VALUES('Legislation','legislation-cas','eve',@parent_id,'{"icon":"faFolder","color":"#ffd258"}',CURRENT_TIMESTAMP());
-- End Dep of Cultural Affairs and Sport Insert Data

-- Start Dep of Economic Development and Tourism Insert Data
INSERT INTO `tbl_categories`(`cat_name`,`dev_name`,`type`,`parent_id`,`extra_data`,`creation_date`) VALUES('Dep of Economic Development and Tourism','dep-economic-development-tourism','eve',0,'{"icon":"faBuilding","color":"#C9A227"}',CURRENT_TIMESTAMP());
SET @parent_id = (SELECT cat_id FROM tbl_categories WHERE dev_name='dep-economic-development-tourism' LIMIT 1);
INSERT INTO `tbl_categories`(`cat_name`,`dev_name`,`type`,`parent_id`,`extra_data`,`creation_date`) VALUES('Annual Report','annual-report-edt','eve',@parent_id,'{"icon":"faFolder","color":"#ffd258"}',CURRENT_TIMESTAMP());
-- End Dep of Economic Development and Tourism Insert Data

-- Start Department of Infrastructure Insert Data
INSERT INTO `tbl_categories`(`cat_name`,`dev_name`,`type`,`parent_id`,`extra_data`,`creation_date`) VALUES('Department of Infrastructure','department-infrastructure','eve',0,'{"icon":"faRoad","color":"#E6E8EB"}',CURRENT_TIMESTAMP());
SET @parent_id = (SELECT cat_id FROM tbl_categories WHERE dev_name='department-infrastructure' LIMIT 1);
INSERT INTO `tbl_categories`(`cat_name`,`dev_name`,`type`,`parent_id`,`extra_data`,`creation_date`) VALUES
('Annual Report','annual-report-infra','eve',@parent_id,'{"icon":"faFolder","color":"#ffd258"}',CURRENT_TIMESTAMP()),
('Policy Framework','policy-framework-infra','eve',@parent_id,'{"icon":"faFolder","color":"#ffd258"}',CURRENT_TIMESTAMP());
-- End Department of Infrastructure Insert Data

-- Start Department of Local Government Insert Data
INSERT INTO `tbl_categories`(`cat_name`,`dev_name`,`type`,`parent_id`,`extra_data`,`creation_date`) VALUES('Department of Local Government','department-local-government','eve',0,'{"icon":"faCity","color":"#E9E5DC"}',CURRENT_TIMESTAMP());
SET @parent_id = (SELECT cat_id FROM tbl_categories WHERE dev_name='department-local-government' LIMIT 1);
INSERT INTO `tbl_categories`(`cat_name`,`dev_name`,`type`,`parent_id`,`extra_data`,`creation_date`) VALUES('Annual Report','annual-report-loc-gov','eve',@parent_id,'{"icon":"faFolder","color":"#ffd258"}',CURRENT_TIMESTAMP());
-- End Department of Local Government Insert Data

-- Start Department of Premier Insert Data
INSERT INTO `tbl_categories`(`cat_name`,`dev_name`,`type`,`parent_id`,`extra_data`,`creation_date`) VALUES('Department of Premier','department-premier','eve',0,'{"icon":"faStar","color":"#B89B5E"}',CURRENT_TIMESTAMP());
SET @parent_id = (SELECT cat_id FROM tbl_categories WHERE dev_name='department-premier' LIMIT 1);
INSERT INTO `tbl_categories`(`cat_name`,`dev_name`,`type`,`parent_id`,`extra_data`,`creation_date`) VALUES
('Annual Report','annual-report-premier','eve',@parent_id,'{"icon":"faFolder","color":"#ffd258"}',CURRENT_TIMESTAMP()),
('Legislation','legislation-premier','eve',@parent_id,'{"icon":"faFolder","color":"#ffd258"}',CURRENT_TIMESTAMP()),
('Policy Framework','policy-framework-premier','eve',@parent_id,'{"icon":"faFolder","color":"#ffd258"}',CURRENT_TIMESTAMP());
-- End Department of Premier Insert Data

-- Start Department of Social Development Insert Data
INSERT INTO `tbl_categories`(`cat_name`,`dev_name`,`type`,`parent_id`,`extra_data`,`creation_date`) VALUES('Department of Social Development','department-social-development','eve',0,'{"icon":"faHandshake","color":"#3FA7A0"}',CURRENT_TIMESTAMP());
SET @parent_id = (SELECT cat_id FROM tbl_categories WHERE dev_name='department-social-development' LIMIT 1);
INSERT INTO `tbl_categories`(`cat_name`,`dev_name`,`type`,`parent_id`,`extra_data`,`creation_date`) VALUES('Policy Framework','policy-framework-sd','eve',@parent_id,'{"icon":"faFolder","color":"#ffd258"}',CURRENT_TIMESTAMP());
-- End Department of Social Development Insert Data

-- Start Treasury Insert Data
INSERT INTO `tbl_categories`(`cat_name`,`dev_name`,`type`,`parent_id`,`extra_data`,`creation_date`) VALUES('Treasury','treasury','eve',0,'{"icon":"faCoins","color":"#B5A36A"}',CURRENT_TIMESTAMP());
SET @parent_id = (SELECT cat_id FROM tbl_categories WHERE dev_name='treasury' LIMIT 1);
INSERT INTO `tbl_categories`(`cat_name`,`dev_name`,`type`,`parent_id`,`extra_data`,`creation_date`) VALUES
('Annual Report','annual-report-treasury','eve',@parent_id,'{"icon":"faFolder","color":"#ffd258"}',CURRENT_TIMESTAMP()),
('Legislation','legislation-treasury','eve',@parent_id,'{"icon":"faFolder","color":"#ffd258"}',CURRENT_TIMESTAMP()),
('Policy Framework','policy-framework-treasury','eve',@parent_id,'{"icon":"faFolder","color":"#ffd258"}',CURRENT_TIMESTAMP());
-- End Treasury Insert Data

-- Start DEADP Insert Data
INSERT INTO `tbl_categories`(`cat_name`,`dev_name`,`type`,`parent_id`,`extra_data`,`creation_date`) VALUES('Department of Environmental Affairs and Development Planning (DEADP)','department-environmental-affairs-development-planning','eve',0,'{"icon":"faTree","color":"#E7ECE9"}',CURRENT_TIMESTAMP());
SET @parent_id = (SELECT cat_id FROM tbl_categories WHERE dev_name='department-environmental-affairs-development-planning' LIMIT 1);
INSERT INTO `tbl_categories`(`cat_name`,`dev_name`,`type`,`parent_id`,`extra_data`,`creation_date`) VALUES
('Annual Report','annual-report-eadp','eve',@parent_id,'{"icon":"faFolder","color":"#ffd258"}',CURRENT_TIMESTAMP()),
('Legislation','legislation-eadp','eve',@parent_id,'{"icon":"faFolder","color":"#ffd258"}',CURRENT_TIMESTAMP());
-- End DEADP Insert Data

-- Start WCED Insert Data
INSERT INTO `tbl_categories`(`cat_name`,`dev_name`,`type`,`parent_id`,`extra_data`,`creation_date`) VALUES('Western Cape Education Department','western-cape-education-department','eve',0,'{"icon":"faGraduationCap","color":"#5880f0"}',CURRENT_TIMESTAMP());
SET @parent_id = (SELECT cat_id FROM tbl_categories WHERE dev_name='western-cape-education-department' LIMIT 1);
INSERT INTO `tbl_categories`(`cat_name`,`dev_name`,`type`,`parent_id`,`extra_data`,`creation_date`) VALUES
('Annual Report','annual-report-wced','eve',@parent_id,'{"icon":"faFolder","color":"#ffd258"}',CURRENT_TIMESTAMP()),
('Policy Framework','policy-framework-wced','eve',@parent_id,'{"icon":"faFolder","color":"#ffd258"}',CURRENT_TIMESTAMP());
-- End WCED Insert Data

-- Start Health and Wellness Insert Data
INSERT INTO `tbl_categories`(`cat_name`,`dev_name`,`type`,`parent_id`,`extra_data`,`creation_date`) VALUES('Western Cape Government Health and Wellness','western-cape-health-wellness','eve',0,'{"icon":"faStethoscope","color":"#28dae2"}',CURRENT_TIMESTAMP());
SET @parent_id = (SELECT cat_id FROM tbl_categories WHERE dev_name='western-cape-health-wellness' LIMIT 1);
INSERT INTO `tbl_categories`(`cat_name`,`dev_name`,`type`,`parent_id`,`extra_data`,`creation_date`) VALUES
('Annual Report','annual-report-wchw','eve',@parent_id,'{"icon":"faFolder","color":"#ffd258"}',CURRENT_TIMESTAMP()),
('Policy Framework','policy-framework-wchw','eve',@parent_id,'{"icon":"faFolder","color":"#ffd258"}',CURRENT_TIMESTAMP());
-- End Health and Wellness Insert Data

-- Start Mobility Insert Data
INSERT INTO `tbl_categories`(`cat_name`,`dev_name`,`type`,`parent_id`,`extra_data`,`creation_date`) VALUES('Western Cape Mobility Department','western-cape-mobility-department','eve',0,'{"icon":"faCar","color":"#B0B7BD"}',CURRENT_TIMESTAMP());
SET @parent_id = (SELECT cat_id FROM tbl_categories WHERE dev_name='western-cape-mobility-department' LIMIT 1);
INSERT INTO `tbl_categories`(`cat_name`,`dev_name`,`type`,`parent_id`,`extra_data`,`creation_date`) VALUES
('Annual Report','annual-report-wcmd','eve',@parent_id,'{"icon":"faFolder","color":"#ffd258"}',CURRENT_TIMESTAMP()),
('Legislation','legislation-wcmd','eve',@parent_id,'{"icon":"faFolder","color":"#ffd258"}',CURRENT_TIMESTAMP()),
('Policy Framework','policy-framework-wcmd','eve',@parent_id,'{"icon":"faFolder","color":"#ffd258"}',CURRENT_TIMESTAMP());
-- End Mobility Insert Data


ALTER TABLE `tbl_documents` ADD `extra_data` TEXT NULL DEFAULT NULL AFTER `doc_level`;
ALTER TABLE `tbl_documents` CHANGE `doc_level` `doc_level` ENUM('project','panoptic','eve') CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL;

-- DATE 19-03-2026 change item_data field type DEV[DONE] QA[PENDING]
ALTER TABLE `tbl_lookup_detail` CHANGE `item_data` `item_data` MEDIUMTEXT CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci NULL DEFAULT NULL COMMENT 'Any additional details related to options in JSON format';

-- DATE 23-03-2026 create faqs table DEV[DONE] QA[PENDING]
CREATE TABLE tbl_faqs (
    faq_id INT AUTO_INCREMENT PRIMARY KEY,
    question TEXT NOT NULL,
    answer LONGTEXT NOT NULL,
    sort_order INT DEFAULT 0,
    status TINYINT(1) DEFAULT 1,   -- 1 = active, 0 = inactive

    created_by INT NULL,
    updated_by INT NULL,

    creation_date DATETIME DEFAULT CURRENT_TIMESTAMP,
    updation_date DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
);

INSERT INTO `tbl_maxids` (`id`, `tbl_name`, `max_id`) VALUES ('35', 'tbl_faqs', '0');

-- DATE 24-03-2026 create application table DEV[DONE] QA[PENDING]
CREATE TABLE IF NOT EXISTS tbl_wizard_applications (
  application_id INT UNSIGNED NOT NULL,
  application_number VARCHAR(13) NOT NULL,
  user_id VARCHAR(64) NOT NULL,
  form_type VARCHAR(64) NOT NULL,
  current_step VARCHAR(8) NOT NULL DEFAULT '',
  status VARCHAR(32) NOT NULL DEFAULT 'draft',
  creation_date TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
  updation_date TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  form_generated_pdf varchar(255) NULL,
  created_by INT NULL,
  updated_by INT NULL,
  PRIMARY KEY (application_id),
  UNIQUE KEY idx_application_number (application_number),
  KEY idx_user_form (user_id, form_type)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

INSERT INTO `tbl_maxids` (`id`, `tbl_name`, `max_id`) 
VALUES ('36', 'tbl_wizard_applications', '0');

CREATE TABLE IF NOT EXISTS tbl_wizard_application_data (
  application_id INT(13) NOT NULL,
  key_name VARCHAR(64) NOT NULL,
  value_data LONGTEXT NULL,
  creation_date TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
  updation_date TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  created_by INT NULL,
  updated_by INT NULL,
  UNIQUE KEY uniq_application_key (application_id, key_name)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
-- DATE 26-03-2026 add is_test_project column to tbl_projects table DEV[DONE] QA[PENDING]
ALTER TABLE `tbl_projects` ADD `is_test_project` TINYINT NOT NULL DEFAULT '0' COMMENT '1 = test project' AFTER `inc_desc`;

-- DATE 25-03-2026 DEV[DONE] QA[PENDING]
CREATE TABLE IF NOT EXISTS `user_activities` (
    id BIGINT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
    user_id INT UNSIGNED NULL,
    action VARCHAR(255) NOT NULL,
    entity_type VARCHAR(255) NULL,
    entity_id BIGINT UNSIGNED NULL,
    details JSON NULL,
    ip_address VARCHAR(45) NULL,
    user_agent TEXT NULL,
    creation_date TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
    INDEX (user_id),
    INDEX (action),
    INDEX (creation_date)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;


-- Date 31-03-2026  Per-user read status for global notifications DEV[DONE] QA[PENDING]
CREATE TABLE tbl_notification_read_status (
    id BIGINT AUTO_INCREMENT PRIMARY KEY,
    notification_id BIGINT NOT NULL,
    user_id INT NOT NULL,
    is_read TINYINT(1) NOT NULL DEFAULT 1,
    created_by INT NULL,
    updated_by INT NULL,
    creation_date TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
    updation_date TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
    UNIQUE KEY uq_notification_user (notification_id, user_id),
    INDEX idx_user_read (user_id, is_read),
    CONSTRAINT fk_notification_read_status_notification
      FOREIGN KEY (notification_id) REFERENCES tbl_notifications(id)
      ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;


-- DATE 09-04-2026  DEV[DONE] QA[PENDING]
ALTER TABLE `tbl_elevator_pitch` CHANGE `project_summary_editor` `key_objectives_summary_editor` TEXT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT NULL;

ALTER TABLE `tbl_elevator_pitch`
  DROP `objectives_focus_areas`
  DROP `project_size`,
  DROP `project_type`,
  DROP `estimated_cost`,
  DROP `estimated_years`,
  DROP `estimated_months`,
  DROP `estimated_project_start_date`;


DROP TABLE tbl_elevator_pitch_departments;
DROP TABLE `tbl_elevator_pitch_key_parties`;

TRUNCATE TABLE `tbl_elevator_pitch_timeline`;

ALTER TABLE `tbl_elevator_pitch_timeline` CHANGE `row_id` `project_id` INT(11) NULL DEFAULT NULL;

ALTER TABLE `tbl_elevator_pitch_key_objective` DROP `row_id`;
ALTER TABLE `tbl_elevator_pitch_timeline` DROP `ept_id`;


DROP PROCEDURE IF EXISTS sp_insert_elevator_pitch;

DELIMITER $$
CREATE PROCEDURE `sp_insert_elevator_pitch`(IN `p_user_id` INT, IN `p_project_id` INT)
proc_block: BEGIN
    -- Declare variables for stage0/3 data
    DECLARE v_row_id INT;
    DECLARE v_exists INT DEFAULT 0;
 
 	 -- Check if elevator pitch already exists for this project
    SELECT COUNT(*) 
    INTO v_exists
    FROM tbl_elevator_pitch
    WHERE project_id = p_project_id;

    -- If record exists, skip process
    IF v_exists > 0 THEN
    	  SELECT CONCAT(
            'Data already exists for given User ID : ', p_user_id,
            ', Project ID = ', p_project_id
        ) AS status_message;
        LEAVE proc_block;
    END IF;
    
    -- Get next row_id
    SELECT IFNULL(MAX(row_id), 0) + 1
    INTO v_row_id
    FROM tbl_elevator_pitch;
 
    -- Insert main elevator pitch row
    INSERT INTO tbl_elevator_pitch (
        row_id,
        project_id,
        creation_date,
        created_by
    ) VALUES (
        v_row_id,
		project_id,
        NOW(),
        p_user_id
    );
	
    
    INSERT INTO tbl_elevator_pitch_key_objective (
        project_id,
        objective_datakey,
        focusarea_datakey,
        objective_name,
        creation_date,
        created_by
    )
    SELECT
        p_project_id,
        pso.objective_datakey,
        pso.focusarea_datakey,
        pso.objective_name,
        NOW(),
        p_user_id
    FROM tbl_project_stg0_objective pso
    WHERE pso.project_id = p_project_id;
    
    SELECT 'Data Inserted Successfully' AS status_message;
 
END proc_block$$
DELIMITER ;

-- Date 06-04-2026  DEV[DONE] QA[PENDING]
UPDATE `tbl_categories` SET `cat_name` = 'Final Prospectus Report' WHERE `tbl_categories`.`cat_name` = 'Feasibility Executive Report';

-- Date 09-04-2026  DP-900 Per-user acknowledgment for important notifications DEV[DONE] QA[PENDING]
CREATE TABLE tbl_notification_acknowledgment (
    acknowledge_id BIGINT NOT NULL ,
    notification_id BIGINT NOT NULL,
    acknowledged_by INT NOT NULL,
    acknowledged_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
    created_by INT NULL,
    updated_by INT NULL,
    creation_date TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
    updation_date TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
    PRIMARY KEY (acknowledge_id),
    UNIQUE KEY uk_notification_acknowledged_by (notification_id, acknowledged_by),
    INDEX idx_ack_acknowledged_by (acknowledged_by),
    CONSTRAINT fk_notification_ack_notification
        FOREIGN KEY (notification_id) REFERENCES tbl_notifications(id)
        ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Date 09-04-2026  DP-900 Add is_starred flag (separate from is_important) DEV[DONE] QA[PENDING]
ALTER TABLE tbl_notifications
    ADD COLUMN is_starred TINYINT(1) NOT NULL DEFAULT 0 AFTER is_read;

-- Global notifications: store per-user starred state alongside per-user read state DEV[DONE] QA[PENDING]
ALTER TABLE tbl_notification_read_status
    ADD COLUMN is_starred TINYINT(1) NOT NULL DEFAULT 0 AFTER is_read;


-- Date 09-04-2026  DEV[DONE] QA[PENDING]
UPDATE `tbl_email_templates` 
SET `body` = '<p>Dear <strong>{{evaluator_name}}</strong>,</p><p>{{evaluation_intro}}</p>{{project_list_html:raw}}<p>Thank you,<br>DOI Platform</p>' 
WHERE `tbl_email_templates`.`template_key` = 'evaluation_reminder';

-- Date 09-04-2026  DP-900 Soft delete for notifications DEV[DONE] QA[PENDING]
ALTER TABLE tbl_notifications
    ADD COLUMN is_deleted TINYINT(1) NOT NULL DEFAULT 0 AFTER is_important,
    ADD COLUMN deleted_by INT NULL AFTER updated_by,
    ADD COLUMN deleted_at DATETIME NULL AFTER updation_date;
-- DEV[DONE] QA[PENDING]
ALTER TABLE tbl_notifications
    ADD INDEX idx_user_deleted_read (user_id, is_deleted, is_read),
    ADD INDEX idx_user_deleted_starred (user_id, is_deleted, is_starred),
    ADD INDEX idx_global_deleted (is_global, is_deleted);
-- DEV[DONE] QA[PENDING]
ALTER TABLE tbl_notification_read_status
    ADD COLUMN is_deleted TINYINT(1) NOT NULL DEFAULT 0 AFTER is_starred,
    ADD COLUMN deleted_by INT NULL AFTER updation_date,
    ADD COLUMN deleted_at DATETIME NULL AFTER deleted_by;

ALTER TABLE tbl_notification_read_status
    ADD INDEX idx_user_deleted (user_id, is_deleted),
    ADD INDEX idx_notification_user_deleted (notification_id, user_id, is_deleted);

-- Date: 10-04-2026  test user flag DEV[DONE] QA[PENDING]
ALTER TABLE `tbl_user_master` ADD `is_test_user` TINYINT NOT NULL DEFAULT '0' AFTER `reg_id`;

-- Date 13-04-2026  Informative email when evaluator evaluation is complete (same placeholders as evaluation_reminder) DEV[PENDING] QA[PENDING]
INSERT INTO tbl_email_templates (template_key, name, subject, body, is_html, use_common_layout, created_at, updated_at)
VALUES (
  'evaluation_completed',
  'Project evaluation completed (evaluator)',
  'Project evaluation completed - {{project_summary}}',
  '<p>Dear <strong>{{evaluator_name}}</strong>,</p><p>{{evaluation_intro}}</p>{{project_list_html:raw}}<p>Thank you,<br>DOI Platform</p>',
  1,
  1,
  NOW(),
  NOW()
) ON DUPLICATE KEY UPDATE
  name = VALUES(name),
  subject = VALUES(subject),
  body = VALUES(body),
  is_html = VALUES(is_html),
  use_common_layout = VALUES(use_common_layout),
  updated_at = NOW();

  -- Date 22-04-2026  DEV[DONE] QA[PENDING] create tbl_wcg_question_answer table

  CREATE TABLE `tbl_wcg_question_answer` (
  `qa_id` int(11) NOT NULL,
  `question` text NOT NULL,
  `answer` longtext NOT NULL,
  `sort_order` int(11) NOT NULL,
  `status` tinyint(1) NOT NULL,
  `stage` varchar(16) NOT NULL,
  `created_by` int(11) NOT NULL,
  `updated_by` int(11) NOT NULL,
  `creation_date` datetime NOT NULL DEFAULT current_timestamp(),
  `updation_date` datetime DEFAULT NULL ON UPDATE current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

ALTER TABLE `tbl_wcg_question_answer`
  ADD PRIMARY KEY (`qa_id`);
COMMIT;

-- Date 13-04-2026  Add eval_completed_date column to tbl_projects table DEV[DONE] QA[PENDING]
ALTER TABLE `tbl_projects` ADD `eval_completed_date` DATETIME NULL AFTER `eval_end_date`;

-- Date 01-05-2026  DEV[Done] QA[PENDING]
CREATE TABLE tbl_events (
    event_id                  BIGINT PRIMARY KEY,
    user_id             INT NULL,
    title               VARCHAR(255) NOT NULL,
    category            VARCHAR(100),
    sub_category        VARCHAR(100),
    description         TEXT,
    mode                ENUM('in_person', 'online', 'hybrid') DEFAULT 'in_person',
    place_or_link       VARCHAR(500),
    start_datetime      DATETIME,
    end_datetime        DATETIME,
    occurrence_type     ENUM('custom', 'monthly', 'quarterly', 'bi_yearly', 'yearly') NOT NULL,
    occurrence_config   JSON, 
    reminders           JSON,
    event_type          VARCHAR(100),
    status              ENUM('active', 'inactive') NOT NULL DEFAULT 'active',
    created_by          INT NULL,
    updated_by          INT NULL,
    creation_date       DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
    updation_date       DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
    updated_at          TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
);

INSERT INTO tbl_events
(event_id, title, category, sub_category, description, mode, place_or_link, start_datetime, end_datetime, user_id, occurrence_type, occurrence_config, reminders, event_type, status, created_by, updated_by, creation_date, updation_date)

VALUES

(1, 'Strategic Pan Report', 'Statutory Report', 'Strategic Pan',
'Mid term review 30 Sep 2027, End Term Report 31 Mar 2030',
'in_person', NULL, '2027-09-30 08:00:00', '2027-09-30 17:00:00',
NULL, 'custom', NULL, NULL, 'Government','active', NULL, NULL, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP),

(2, 'Strategic Pan Report', 'Statutory Report', 'Strategic Pan',
'Mid term review 30 Sep 2027, End Term Report 31 Mar 2030',
'in_person', NULL, '2030-03-31 08:00:00', '2030-03-31 17:00:00',
NULL, 'custom', NULL, NULL, 'Government','active', NULL, NULL, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP),

(3, 'Annual Performance Plan Report', 'Statutory Report', 'Annual Performance Plan',
'Annual due 31 Mar every year for the duration of the SP 5 year plan.',
'in_person', NULL, '2025-04-01 08:00:00', '2030-03-31 17:00:00',
NULL, 'yearly', '{"month":3,"day":31}', NULL, 'Government','active', NULL, NULL, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP),

(4, 'Annual Operating Plan Report', 'Internal', 'Annual Operating Plan',
'(Non statutory doc - internal document covering operational plan)',
'in_person', NULL, '2025-04-01 08:00:00', '2030-03-31 17:00:00',
NULL, 'yearly', '{"month":3,"day":31}', NULL, 'Gov-Internal','active', NULL, NULL, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP),

(5, 'Annual Report', 'Statutory Report', 'Annual Report',
'due 30 Sep.',
'in_person', NULL, '2025-04-01 08:00:00', '2030-03-31 17:00:00',
NULL, 'yearly', '{"month":9,"day":30}', NULL, 'Government','active', NULL, NULL, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP),

(6, 'eQPRS Report', 'Online Updates', 'eQPRS',
'every 3 months : Jun,Sep,Dec,Mar',
'in_person', NULL, '2025-04-01 08:00:00', '2030-03-31 17:00:00',
NULL, 'quarterly',
NULL,
NULL, 'Application','active', NULL, NULL, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP),

(7, 'Service Delivery Improvement Plan Report', 'Internal', 'Service Delivery Improvement Plan',
'updated every 3 years - Mar 2028',
'in_person', NULL, '2028-03-01 08:00:00', '2028-03-01 17:00:00',
NULL, 'custom', NULL, NULL, 'Gov-Internal','active', NULL, NULL, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP);


-- DATE 24-04-2026  DEV[DONE] QA[PENDING]
INSERT INTO `tbl_platform_config` (`key`, `value`, `created_by`, `updated_by`, `creation_date`, `updation_date`) VALUES ('project_overdue_after_days', '7', NULL, NULL, '2026-02-09 15:01:21', '2026-02-09 15:01:21');

-- DATE 27-04-2026  DEV[DONE] QA[PENDING] 
INSERT INTO `tbl_lookup` (`keyid`, `dev_name`, `display_name`, `display_name_ml`, `description`, `is_active`, `translate`, `creation_date`, `created_by`, `updation_date`, `updated_by`) VALUES ('117', 'project_eval_summary_recommendation', 'Evaluation Summary Recommendation', 'project_eval_summary_recommendation_ml', NULL, '1', 'No', '2026-04-02 07:13:38', NULL, '2026-04-02 07:13:38', NULL);

-- DATE 27-04-2026  DEV[DONE] QA[PENDING] 
INSERT INTO `tbl_lookup_detail` (`optionid`, `keyid`, `data_value`, `data_key`, `display_name`, `display_name_ml`, `sequence`, `item_data`, `parent_datakey`, `is_active`, `creation_date`, `created_by`, `updation_date`, `updated_by`) VALUES ('1949', '117', '1', 'project_eval_summary_recommendation', 'Evaluation Summary Recommendation', 'project_eval_summary_recommendation-ml', '1', '{"80-100":"Project advances to the bankable portfolio and should be packaged into a standard investor-ready summary as the final step.","50-79":"Project returns to Step-2 of the 4-step prioritisation process to refine identified metrics before resubmission.","0-49":"Project needs complete rework."}', NULL, 'active', '2026-04-02 07:14:19', '110', '2026-04-02 07:14:19', '110')
ON DUPLICATE KEY UPDATE
  `item_data` = VALUES(`item_data`),
  `display_name` = VALUES(`display_name`),
  `display_name_ml` = VALUES(`display_name_ml`),
  `parent_datakey` = VALUES(`parent_datakey`),
  `updation_date` = VALUES(`updation_date`),
  `updated_by` = VALUES(`updated_by`);

-- DATE 27-04-2026  DEV[DONE] QA[PENDING] PET requiurement table updates.
ALTER TABLE `tbl_projects` ADD `eval_additional_notes` TEXT NULL DEFAULT NULL AFTER `eval_status`;

------- Date 28 Apr 2026 enforce unique stakeholder mapping (prevents duplicates) DEV[DONE] QA[PENDING]
ALTER TABLE `tbl_project_stg5_stakeholders`
  ADD UNIQUE KEY `uq_stg5_stakeholder_mapping` (`project_id`, `user_id`, `type_datakey`, `stakeholder_datakey`);

  -- DATE 28 Apr 2026  DEV[DONE] QA[PENDING]
  ALTER TABLE `tbl_events` CHANGE `occurrence_type` `occurrence_type` ENUM('once','custom','monthly','quarterly','bi_yearly','yearly') CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL;

-- DATE 07 May 2026  DEV[PENDING] QA[PENDING] calendar all-day + split date/time support.
ALTER TABLE `tbl_events`
  ADD COLUMN `start_date` DATE NULL AFTER `end_datetime`,
  ADD COLUMN `end_date` DATE NULL AFTER `start_date`,
  ADD COLUMN `start_time` TIME NULL AFTER `end_date`,
  ADD COLUMN `end_time` TIME NULL AFTER `start_time`,
  ADD COLUMN `is_all_day` TINYINT(1) NOT NULL DEFAULT 0 AFTER `end_time`;

UPDATE `tbl_events`
SET
  `start_date` = IFNULL(`start_date`, DATE(`start_datetime`)),
  `end_date` = IFNULL(`end_date`, DATE(`end_datetime`)),
  `start_time` = IFNULL(`start_time`, TIME(`start_datetime`)),
  `end_time` = IFNULL(`end_time`, TIME(`end_datetime`))
WHERE `start_datetime` IS NOT NULL AND `end_datetime` IS NOT NULL;

-- DATE 07 May 2026  DEV[PENDING] QA[PENDING] calendar reminder channel policy + dedupe log.
CREATE TABLE IF NOT EXISTS `tbl_event_reminder_dispatch_log` (
  `id` BIGINT NOT NULL AUTO_INCREMENT,
  `event_id` BIGINT NOT NULL,
  `user_id` INT NOT NULL,
  `occurrence_start` DATETIME NOT NULL,
  `reminder_offset_minutes` INT NOT NULL,
  `channel` ENUM('email','in_app') NOT NULL,
  `created_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
  PRIMARY KEY (`id`),
  UNIQUE KEY `uq_event_user_occurrence_offset_channel` (`event_id`,`user_id`,`occurrence_start`,`reminder_offset_minutes`,`channel`),
  KEY `idx_event_reminder_lookup` (`event_id`,`occurrence_start`,`channel`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

INSERT INTO `tbl_platform_config` (`key`, `value`, `created_by`, `updated_by`, `creation_date`, `updation_date`)
VALUES
  ('calendar_reminder_lookback_minutes', '10', NULL, NULL, NOW(), NOW()),
  ('calendar_global_event_target_role_ids', '[2,3]', NULL, NULL, NOW(), NOW()),
  ('notification_scope_calendar_global_event_reminder_email_enabled', '0', NULL, NULL, NOW(), NOW()),
  ('notification_scope_calendar_global_event_reminder_in_app_enabled', '1', NULL, NULL, NOW(), NOW()),
  ('notification_scope_calendar_personal_event_reminder_email_enabled', '1', NULL, NULL, NOW(), NOW()),
  ('notification_scope_calendar_personal_event_reminder_in_app_enabled', '1', NULL, NULL, NOW(), NOW())
ON DUPLICATE KEY UPDATE
  `value` = VALUES(`value`),
  `updation_date` = VALUES(`updation_date`),
  `updated_by` = VALUES(`updated_by`);

-- Calendar event category and color DEV[PENDING] QA[PENDING]
INSERT INTO `tbl_lookup` (`keyid`, `dev_name`, `display_name`, `display_name_ml`, `description`, `is_active`, `translate`, `creation_date`, `created_by`, `updation_date`, `updated_by`)
 VALUES 
('119', 'calender_event_categories_and_colors', 'Calender event categories and colors', 'calender-event-categories-and-colors', NULL, '1', 'No', '2026-04-02 07:13:38', NULL, '2026-04-02 07:13:38', NULL);

INSERT INTO `tbl_lookup_detail` (`optionid`, `keyid`, `data_value`, `data_key`, `display_name`, `display_name_ml`, `sequence`, `item_data`, `parent_datakey`, `is_active`, `creation_date`, `created_by`, `updation_date`, `updated_by`)
VALUES (
  '2016', '119', '1', 'Calendar_event_categories_and_color_1',
  'Calendar event categories and color', 'calendar-event-category-and-color', '1',
  '{\n \"Statutory Report\": {\n \"color\": \"#D93025\",\n \"is_global\": true\n },\n \"Online Updates\": {\n \"color\": \"#34A853\",\n \"is_global\": true\n },\n \"Internal\": {\n \"color\": \"#8E44AD\",\n \"is_global\": false\n },\n \"Meeting\": {\n \"color\": \"#1E3A5F\",\n \"is_global\": false\n },\n \"Briefing Sessions\": {\n \"color\": \"#2C3E50\",\n \"is_global\": false\n },\n \"Seminars\": {\n \"color\": \"#4A2C2A\",\n \"is_global\": false\n },\n \"Workshops\": {\n \"color\": \"#0F4C5C\",\n \"is_global\": false\n }\n}',
  NULL, 'active', '2026-05-06 13:14:07', NULL, NULL, NULL
);

UPDATE `tbl_maxids`
SET `max_id` = GREATEST(`max_id`, 2016)
WHERE `tbl_name` = 'tbl_lookup_detail';

UPDATE `tbl_maxids`
SET `max_id` = GREATEST(`max_id`, 119)
WHERE `tbl_name` = 'tbl_lookup';

-- DATE 11 May 2026  DEV[DONE] QA[PENDING] add description column to tbl_categories table
ALTER TABLE `tbl_categories` ADD `description` TEXT NULL DEFAULT NULL AFTER `dev_name`;


-- DATE 13 May 2026  DEV[PENDING] QA[PENDING] calendar event UTC instants for reminder scheduling
ALTER TABLE `tbl_events`
  ADD COLUMN `start_at_utc` DATETIME NULL AFTER `end_time`,
  ADD COLUMN `end_at_utc` DATETIME NULL AFTER `start_at_utc`;

-- DATE 12 May 2026  DEV[PENDING] QA[PENDING] add send_event_reminder_notifications_to_respective_emails and event_reminders_notifications_emails_tobe_sent to tbl_platform_config table
INSERT INTO `tbl_platform_config` (`key`, `value`, `created_by`, `updated_by`, `creation_date`, `updation_date`) VALUES 
('send_event_reminder_notifications_to_respective_emails', 'false', NULL, NULL, NOW(), NOW()),
('event_reminders_notifications_emails_tobe_sent', '[]', NULL, NULL, NOW(), NOW());

--- DATE 06-05-2026 User-Registration flow. DEV[DONE] QA[PENDING]

ALTER TABLE `tbl_role_master` CHANGE `role_type` `role_type` ENUM('global','project','responsible_party', 'platform') CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci NOT NULL DEFAULT 'project';

-- =========================================================
-- tbl_role_right_association DEV[DONE] QA[PENDING]
-- =========================================================

-- Remove legacy value column DEV[DONE] QA[PENDING]
ALTER TABLE `tbl_role_right_association`
DROP COLUMN `value`;

-- add operation level permissions
ALTER TABLE `tbl_role_right_association`
ADD COLUMN `view` TINYINT(1) NOT NULL DEFAULT 0 AFTER `right_id`,
ADD COLUMN `create` TINYINT(1) NOT NULL DEFAULT 0 AFTER `view`,
ADD COLUMN `edit` TINYINT(1) NOT NULL DEFAULT 0 AFTER `create`,
ADD COLUMN `delete` TINYINT(1) NOT NULL DEFAULT 0 AFTER `edit`,
ADD COLUMN `submit` TINYINT(1) NOT NULL DEFAULT 0 AFTER `delete`,
ADD COLUMN `review` TINYINT(1) NOT NULL DEFAULT 0 AFTER `submit`,
ADD COLUMN `approve` TINYINT(1) NOT NULL DEFAULT 0 AFTER `review`;

-- prevent duplicate user-right mappings
ALTER TABLE `tbl_role_right_association`
ADD CONSTRAINT `uk_role_right`
UNIQUE (`role_id`, `right_id`);



-- =========================================================
-- tbl_user_right_association DEV[DONE] QA[PENDING]
-- =========================================================

-- Remove legacy value column DEV[DONE] QA[PENDING]
ALTER TABLE `tbl_user_right_association`
DROP COLUMN `value`;

-- add operation level permissions
ALTER TABLE `tbl_user_right_association`
ADD COLUMN `view` TINYINT(1) NOT NULL DEFAULT 0 AFTER `right_id`,
ADD COLUMN `create` TINYINT(1) NOT NULL DEFAULT 0 AFTER `view`,
ADD COLUMN `edit` TINYINT(1) NOT NULL DEFAULT 0 AFTER `create`,
ADD COLUMN `delete` TINYINT(1) NOT NULL DEFAULT 0 AFTER `edit`,
ADD COLUMN `submit` TINYINT(1) NOT NULL DEFAULT 0 AFTER `delete`,
ADD COLUMN `review` TINYINT(1) NOT NULL DEFAULT 0 AFTER `submit`,
ADD COLUMN `approve` TINYINT(1) NOT NULL DEFAULT 0 AFTER `review`;

-- prevent duplicate user-right mappings
ALTER TABLE `tbl_user_right_association`
ADD CONSTRAINT `uk_user_right`
UNIQUE (`user_id`, `right_id`);

-- =========================================================
-- tbl_right_master DEV[DONE] QA[PENDING]
-- =========================================================

-- classify right types
ALTER TABLE `tbl_right_master`
ADD COLUMN `right_type`
ENUM(
    'menu',
    'page',
    'workflow',
    'dashboard',
    'report',
    'feature'
)
DEFAULT 'feature'
AFTER `right_name`;

-- Clear role-right mappings DEV[DONE] QA[PENDING]
DELETE FROM `tbl_role_right_association`;

-- Clear user-right overrides DEV[DONE] QA[PENDING]
DELETE FROM `tbl_user_right_association`;

-- Clear Right-master DEV[DONE] QA[PENDING]
DELETE FROM `tbl_right_master`;


-- =========================================================
-- tbl_user_right_association triggers DEV[DONE] QA[PENDING]
-- =========================================================

DROP TRIGGER IF EXISTS tr_user_right_association_insert;

DELIMITER $$

CREATE TRIGGER tr_user_right_association_insert
AFTER INSERT ON tbl_user_master
FOR EACH ROW
BEGIN
    IF NEW.role_id IS NOT NULL AND NEW.role_id > 0 THEN
        INSERT INTO tbl_user_right_association
            (user_id, right_id, `view`, `create`, `edit`, `delete`, `submit`, `review`, `approve`)
        SELECT
            NEW.user_id,
            rra.right_id,
            rra.`view`,
            rra.`create`,
            rra.`edit`,
            rra.`delete`,
            rra.`submit`,
            rra.`review`,
            rra.`approve`
        FROM tbl_role_right_association rra
        WHERE rra.role_id = NEW.role_id
        ON DUPLICATE KEY UPDATE
            `view` = VALUES(`view`),
            `create` = VALUES(`create`),
            `edit` = VALUES(`edit`),
            `delete` = VALUES(`delete`),
            `submit` = VALUES(`submit`),
            `review` = VALUES(`review`),
            `approve` = VALUES(`approve`);
    END IF;
END$$

DELIMITER ;


DROP TRIGGER IF EXISTS tr_right_role_right_association_insert;

DELIMITER $$

CREATE TRIGGER tr_right_role_right_association_insert
AFTER INSERT ON tbl_right_master
FOR EACH ROW
BEGIN

    INSERT INTO tbl_role_right_association
    (
        role_id,
        right_id,
        view,
        `create`,
        edit,
        `delete`,
        submit,
        review,
        approve
    )
    SELECT
        r.role_id,
        NEW.right_id,
        0,
        0,
        0,
        0,
        0,
        0,
        0
    FROM tbl_role_master AS r;



    INSERT INTO tbl_user_right_association
    (
        user_id,
        right_id,
        view,
        `create`,
        edit,
        `delete`,
        submit,
        review,
        approve
    )
    SELECT
        u.user_id,
        NEW.right_id,
        0,
        0,
        0,
        0,
        0,
        0,
        0
    FROM tbl_user_master u;

END$$

DELIMITER ;

DROP TRIGGER IF EXISTS tr_right_role_right_association_delete;

DELIMITER $$

CREATE TRIGGER tr_right_role_right_association_delete
AFTER DELETE ON tbl_right_master
FOR EACH ROW
BEGIN

    DELETE FROM tbl_role_right_association
    WHERE right_id = OLD.right_id;


    DELETE FROM tbl_user_right_association
    WHERE right_id = OLD.right_id;

END$$

DELIMITER ;



 -- Date 06-05-2026  DEV[DONE] QA[PENDING]
DROP TRIGGER IF EXISTS tr_role_right_association_insert;

DELIMITER $$

CREATE TRIGGER tr_role_right_association_insert
AFTER INSERT ON tbl_role_master
FOR EACH ROW
BEGIN

    DELETE FROM tbl_role_right_association
    WHERE role_id = NEW.role_id;


    INSERT INTO tbl_role_right_association
    (
        role_id,
        right_id,
        view,
        `create`,
        edit,
        `delete`,
        submit,
        review,
        approve
    )
    SELECT
        NEW.role_id,
        b.right_id,
        0,
        0,
        0,
        0,
        0,
        0,
        0
    FROM tbl_right_master AS b;

END$$

DELIMITER ;


-- New platform roles entries. DEV[DONE] QA[PENDING]
INSERT INTO `tbl_role_master` (`role_id`, `app_id`, `role_type`, `role_name`, `role_short_name`, `isAdmin`, `isActive`, `creation_date`, `created_by`, `updation_date`, `updated_by`, `deleted_at`) 
VALUES 
('26', '1', 'platform', 'Stage Gate Data Entry', 'Stage Gate Data Entry', '0', '1', CURRENT_TIMESTAMP, NULL, NULL, NULL, NULL), 
('27', '1', 'platform', 'Stage Gate Submissions', 'Stage Gate Submissions', '0', '1', CURRENT_TIMESTAMP, NULL, NULL, NULL, NULL), 
('28', '1', 'platform', 'Review', 'Review', '0', '1', CURRENT_TIMESTAMP, NULL, NULL, NULL, NULL), 
('29', '1', 'platform', 'Approver', 'Approver', '0', '1', CURRENT_TIMESTAMP, NULL, NULL, NULL, NULL), 
('30', '1', 'platform', 'Infrastructure Planner', 'Infrastructure Planner', '0', '1', CURRENT_TIMESTAMP, NULL, NULL, NULL, NULL), 
('31', '1', 'platform', 'Systems Support', 'Systems Support', '0', '1', CURRENT_TIMESTAMP, NULL, NULL, NULL, NULL), 
('32', '1', 'platform', 'Monitor & Evaluate', 'Monitor & Evaluate', '0', '1', CURRENT_TIMESTAMP, NULL, NULL, NULL, NULL), 
('33', '1', 'platform', 'Client Liaison', 'Client Liaison', '0', '1', CURRENT_TIMESTAMP, NULL, NULL, NULL, NULL), 
('34', '1', 'platform', 'Project Governance', 'Project Governance', '0', '1', CURRENT_TIMESTAMP, NULL, NULL, NULL, NULL), 
('35', '1', 'platform', 'Infrastructure Planner Engineer', 'Infrastructure Planner Engineer', '0', '1', CURRENT_TIMESTAMP, NULL, NULL, NULL, NULL),
('36', '1', 'platform', 'Project Manager', 'Project Manager', '0', '1', CURRENT_TIMESTAMP, NULL, NULL, NULL, NULL),
('37', '1', 'platform', 'Project Coordinator', 'Project Coordinator', '0', '1', CURRENT_TIMESTAMP, NULL, NULL, NULL, NULL),
('38', '1', 'platform', 'Project Analyst', 'Project Analyst', '0', '1', CURRENT_TIMESTAMP, NULL, NULL, NULL, NULL),
('39', '1', 'platform', 'Project Specialist', 'Project Specialist', '0', '1', CURRENT_TIMESTAMP, NULL, NULL, NULL, NULL),
('40', '1', 'platform', 'Project Lead', 'Project Lead', '0', '1', CURRENT_TIMESTAMP, NULL, NULL, NULL, NULL),
('41', '1', 'platform', 'Project Planner', 'Project Planner', '0', '1', CURRENT_TIMESTAMP, NULL, NULL, NULL, NULL);


-- Remove existing designations from tbl_lookup_detail DEV[DONE] QA[PENDING]
DELETE  FROM `tbl_lookup_detail` WHERE data_key LIKE 'user_designation_%';

-- tbl_lookup_details: Designations entries DEV[DONE] QA[PENDING]

INSERT INTO `tbl_lookup_detail`
(
    `optionid`,
    `keyid`,
    `data_value`,
    `data_key`,
    `display_name`,
    `display_name_ml`,
    `sequence`,
    `item_data`,
    `parent_datakey`,
    `is_active`,
    `creation_date`
)
VALUES
(1917, 8, '1',  'user_designation_1',  'Acting Deputy Director-General', 'acting-deputy-director-general-ml', 1,  NULL, NULL, 'active', NOW()),
(1918, 8, '2',  'user_designation_2',  'Acting Director', 'acting-director-ml', 2,  NULL, NULL, 'active', NOW()),
(1919, 8, '3',  'user_designation_3',  'Architect Chief Grade B', 'architect-chief-grade-b-ml', 3,  NULL, NULL, 'active', NOW()),
(1920, 8, '4',  'user_designation_4',  'Assistant Director', 'assistant-director-ml', 4,  NULL, NULL, 'active', NOW()),
(1921, 8, '5',  'user_designation_5',  'Chief Director', 'chief-director-ml', 5,  NULL, NULL, 'active', NOW()),
(1922, 8, '6',  'user_designation_6',  'Chief Engineer', 'chief-engineer-ml', 6,  NULL, NULL, 'active', NOW()),
(1923, 8, '7',  'user_designation_7',  'Chief Executive Officer', 'chief-executive-officer-ml', 7,  NULL, NULL, 'active', NOW()),
(1924, 8, '8',  'user_designation_8',  'Project Manager', 'project-manager-ml', 8,  NULL, NULL, 'active', NOW()),
(1925, 8, '9',  'user_designation_9',  'Contract Manager', 'contract-manager-ml', 9,  NULL, NULL, 'active', NOW()),
(1926, 8, '10', 'user_designation_10', 'Deputy Director - Infrastructure Governance And Service Delivery', 'deputy-director-infrastructure-governance-and-service-delivery-ml', 10, NULL, NULL, 'active', NOW()),
(1927, 8, '11', 'user_designation_11', 'Deputy Director General', 'deputy-director-general-ml', 11, NULL, NULL, 'active', NOW()),
(1928, 8, '12', 'user_designation_12', 'Deputy Director', 'deputy-director-ml', 12, NULL, NULL, 'active', NOW()),
(1929, 8, '13', 'user_designation_13', 'Director', 'director-ml', 13, NULL, NULL, 'active', NOW()),
(1930, 8, '14', 'user_designation_14', 'Director-General', 'director-general-ml', 14, NULL, NULL, 'active', NOW()),
(1931, 8, '15', 'user_designation_15', 'Engineer Chief Grade A', 'engineer-chief-grade-a-ml', 15, NULL, NULL, 'active', NOW()),
(1932, 8, '16', 'user_designation_16', 'Engineer Chief Grade B', 'engineer-chief-grade-b-ml', 16, NULL, NULL, 'active', NOW()),
(1933, 8, '17', 'user_designation_17', 'Engineering Technologist', 'engineering-technologist-ml', 17, NULL, NULL, 'active', NOW()),
(1934, 8, '18', 'user_designation_18', 'Head of Department', 'head-of-department-ml', 18, NULL, NULL, 'active', NOW()),
(1935, 8, '19', 'user_designation_19', 'Head official', 'head-official-ml', 19, NULL, NULL, 'active', NOW()),
(1936, 8, '20', 'user_designation_20', 'Land Transport Safety Operations', 'land-transport-safety-operations-ml', 20, NULL, NULL, 'active', NOW()),
(1937, 8, '21', 'user_designation_21', 'Minister of Department', 'minister-of-department-ml', 21, NULL, NULL, 'active', NOW()),
(1938, 8, '22', 'user_designation_22', 'Municipal Manager', 'municipal-manager-ml', 22, NULL, NULL, 'active', NOW()),
(1939, 8, '23', 'user_designation_23', 'Operational Lead', 'operational-lead-ml', 23, NULL, NULL, 'active', NOW()),
(1940, 8, '24', 'user_designation_24', 'Premier of the Western Cape', 'premier-of-the-western-cape-ml', 24, NULL, NULL, 'active', NOW()),
(1941, 8, '25', 'user_designation_25', 'Provincial Minister of Finance', 'provincial-minister-of-finance-ml', 25, NULL, NULL, 'active', NOW()),
(1942, 8, '26', 'user_designation_26', 'Senior Project Leader', 'senior-project-leader-ml', 26, NULL, NULL, 'active', NOW()),
(1943, 8, '27', 'user_designation_27', 'Specialist Engineer', 'specialist-engineer-ml', 27, NULL, NULL, 'active', NOW()),
(1944, 8, '28', 'user_designation_28', 'Strategic Lead', 'strategic-lead-ml', 28, NULL, NULL, 'active', NOW());

-- tbl_lookup User Designations specific. DEV[DONE] QA[PENDING]
INSERT INTO `tbl_lookup` (`keyid`, `dev_name`, `display_name`, `display_name_ml`, `description`, `is_active`, `translate`, `creation_date`, `created_by`, `updation_date`, `updated_by`)
 VALUES 
('114', 'user_designation_specific', 'Designation Specific', 'user-designation-specific-ml', NULL, '1', 'No', '2026-04-02 07:13:38', NULL, '2026-04-02 07:13:38', NULL);

-- tbl_lookup_details User Designations specific. DEV[DONE] QA[PENDING]

INSERT INTO `tbl_lookup_detail`
(
    `optionid`,
    `keyid`,
    `data_value`,
    `data_key`,
    `display_name`,
    `display_name_ml`,
    `sequence`,
    `item_data`,
    `parent_datakey`,
    `is_active`,
    `creation_date`
)
VALUES
(1945, 114, '1',  'user_designation_specific_1',  'Finance', 'finance-ml', 1, NULL, NULL, 'active', NOW()),
(1946, 114, '2',  'user_designation_specific_2',  'Provincial Public Works', 'provincial-public-works-ml', 2, NULL, NULL, 'active', NOW()),
(1947, 114, '3',  'user_designation_specific_3',  'Roads', 'roads-ml', 3, NULL, NULL, 'active', NOW()),
(1948, 114, '4',  'user_designation_specific_4',  'Strategy & Policy', 'strategy-policy-ml', 4, NULL, NULL, 'active', NOW()),
(1949, 114, '5',  'user_designation_specific_5',  'Professional and Project Management', 'professional-and-project-management-ml', 5, NULL, NULL, 'active', NOW()),
(1950, 114, '6',  'user_designation_specific_6',  'Capacity Building & Inspections', 'capacity-building-inspections-ml', 6, NULL, NULL, 'active', NOW()),
(1951, 114, '7',  'user_designation_specific_7',  'Land Transp Integration & Oversight', 'land-transp-integration-oversight-ml', 7, NULL, NULL, 'active', NOW()),
(1952, 114, '8',  'user_designation_specific_8',  'Agricultural Education And Training', 'agricultural-education-and-training-ml', 8, NULL, NULL, 'active', NOW()),
(1953, 114, '9',  'user_designation_specific_9',  'Digital Economy', 'digital-economy-ml', 9, NULL, NULL, 'active', NOW()),
(1954, 114, '10', 'user_designation_specific_10', 'Economic Sector Support', 'economic-sector-support-ml', 10, NULL, NULL, 'active', NOW()),
(1955, 114, '11', 'user_designation_specific_11', 'Environmental Sustainability', 'environmental-sustainability-ml', 11, NULL, NULL, 'active', NOW()),
(1956, 114, '12', 'user_designation_specific_12', 'Human Settlement Planning', 'human-settlement-planning-ml', 12, NULL, NULL, 'active', NOW()),
(1957, 114, '13', 'user_designation_specific_13', 'Municipal Performance Monitoring And Support', 'municipal-performance-monitoring-and-support-ml', 13, NULL, NULL, 'active', NOW()),
(1958, 114, '14', 'user_designation_specific_14', 'Sport And Recreation', 'sport-and-recreation-ml', 14, NULL, NULL, 'active', NOW()),
(1959, 114, '15', 'user_designation_specific_15', 'Transport Operations', 'transport-operations-ml', 15, NULL, NULL, 'active', NOW()),
(1960, 114, '16', 'user_designation_specific_16', 'Contract Management PPP', 'contract-management-ppp-ml', 16, NULL, NULL, 'active', NOW()),
(1961, 114, '17', 'user_designation_specific_17', 'Centre For E-Innovation', 'centre-for-e-innovation-ml', 17, NULL, NULL, 'active', NOW()),
(1962, 114, '18', 'user_designation_specific_18', 'Cape Catalyst', 'cape-catalyst-ml', 18, NULL, NULL, 'active', NOW()),
(1963, 114, '19', 'user_designation_specific_19', 'Connected Business', 'connected-business-ml', 19, NULL, NULL, 'active', NOW()),
(1964, 114, '20', 'user_designation_specific_20', 'Contract Development', 'contract-development-ml', 20, NULL, NULL, 'active', NOW()),
(1965, 114, '21', 'user_designation_specific_21', 'Coordination Of Industrial Development', 'coordination-of-industrial-development-ml', 21, NULL, NULL, 'active', NOW()),
(1966, 114, '22', 'user_designation_specific_22', 'Economic Development Integration', 'economic-development-integration-ml', 22, NULL, NULL, 'active', NOW()),
(1967, 114, '23', 'user_designation_specific_23', 'Freight', 'freight-ml', 23, NULL, NULL, 'active', NOW()),
(1968, 114, '24', 'user_designation_specific_24', 'Land Trans Integration & Oversight', 'land-trans-integration-oversight-ml', 24, NULL, NULL, 'active', NOW()),
(1969, 114, '25', 'user_designation_specific_25', 'Public Private Partnerships', 'public-private-partnerships-ml', 25, NULL, NULL, 'active', NOW()),
(1970, 114, '26', 'user_designation_specific_26', 'General', 'general-ml', 26, NULL, NULL, 'active', NOW()),
(1971, 114, '27', 'user_designation_specific_27', 'Biodiversity And Coastal Management', 'biodiversity-and-coastal-management-ml', 27, NULL, NULL, 'active', NOW()),
(1972, 114, '28', 'user_designation_specific_28', 'Director-General Support', 'director-general-support-ml', 28, NULL, NULL, 'active', NOW()),
(1973, 114, '29', 'user_designation_specific_29', 'Human Settlement Project, Contract and Subsidy Admin', 'human-settlement-project-contract-and-subsidy-admin-ml', 29, NULL, NULL, 'active', NOW()),
(1974, 114, '30', 'user_designation_specific_30', 'Human Settlement Support Region', 'human-settlement-support-region-ml', 30, NULL, NULL, 'active', NOW()),
(1975, 114, '31', 'user_designation_specific_31', 'Infrastructure', 'infrastructure-ml', 31, NULL, NULL, 'active', NOW()),
(1976, 114, '32', 'user_designation_specific_32', 'Infrastructure Planning', 'infrastructure-planning-ml', 32, NULL, NULL, 'active', NOW()),
(1977, 114, '33', 'user_designation_specific_33', 'Land Transport Development Systems And Freight', 'land-transport-development-systems-and-freight-ml', 33, NULL, NULL, 'active', NOW()),
(1978, 114, '34', 'user_designation_specific_34', 'Municipal Infrastructure Management', 'municipal-infrastructure-management-ml', 34, NULL, NULL, 'active', NOW()),
(1979, 114, '35', 'user_designation_specific_35', 'Provincial Archive Services', 'provincial-archive-services-ml', 35, NULL, NULL, 'active', NOW()),
(1980, 114, '36', 'user_designation_specific_36', 'Secretariat Services And Protocol', 'secretariat-services-and-protocol-ml', 36, NULL, NULL, 'active', NOW()),
(1981, 114, '37', 'user_designation_specific_37', 'Special Programs', 'special-programs-ml', 37, NULL, NULL, 'active', NOW()),
(1982, 114, '38', 'user_designation_specific_38', 'Transport Policies And Strategies', 'transport-policies-and-strategies-ml', 38, NULL, NULL, 'active', NOW());


-- Triggers updates" tr_right_role_right_association_insert DEV[DONE] QA[PENDING]



-- Table tbl_right_master DEV[DONE] QA[PENDING]

INSERT INTO `tbl_right_master`
(
    `right_id`,
    `right_key`,
    `app_id`,
    `right_name`,
    `right_type`,
    `file_name`,
    `right_description`,
    `right_default`,
    `right_admin`,
    `right_group`,
    `right_is_menu`,
    `right_parent`,
    `right_sequence`
)
VALUES

-- =====================================================
-- ROOT MENUS
-- =====================================================

(1, 'workflow', 1, 'Workflow', 'menu', NULL,
'Workflow root menu',
0, 0, 0, 1, 0, 1),

(2, 'dashboard', 1, 'Dashboard', 'menu', NULL,
'Dashboard root menu',
0, 0, 0, 1, 0, 2),

(3, 'reports', 1, 'Reports', 'menu', NULL,
'Reports root menu',
0, 0, 0, 1, 0, 3),


-- =====================================================
-- WORKFLOW RIGHTS
-- =====================================================

(4, 'stage_gate_0', 1, 'Stage Gate 0', 'workflow', 'stage_gate_0.php',
'Stage Gate 0',
0, 0, 0, 1, 1, 1),

(5, 'stage_gate_1', 1, 'Stage Gate 1', 'workflow', 'stage_gate_1.php',
'Stage Gate 1',
0, 0, 0, 1, 1, 2),

(6, 'stage_gate_2', 1, 'Stage Gate 2', 'workflow', 'stage_gate_2.php',
'Stage Gate 2',
0, 0, 0, 1, 1, 3),

(7, 'stage_gate_3', 1, 'Stage Gate 3', 'workflow', 'stage_gate_3.php',
'Stage Gate 3',
0, 0, 0, 1, 1, 4),

(8, 'stage_gate_4', 1, 'Stage Gate 4', 'workflow', 'stage_gate_4.php',
'Stage Gate 4',
0, 0, 0, 1, 1, 5),

(9, 'stage_gate_5', 1, 'Stage Gate 5', 'workflow', 'stage_gate_5.php',
'Stage Gate 5',
0, 0, 0, 1, 1, 6),

(10, 'stage_gate_5_ddr', 1, 'DDR', 'workflow', 'stage_gate_5_ddr.php',
'Stage Gate 5 DDR',
0, 0, 0, 1, 9, 1),

(11, 'stage_gate_5_project_plan', 1, 'Project Plan', 'workflow', 'stage_gate_5_project_plan.php',
'Stage Gate 5 Project Plan',
0, 0, 0, 1, 9, 2),

(12, 'stage_gate_5_risk_management_plan', 1, 'Risk Management Plan', 'workflow', 'stage_gate_5_risk_management_plan.php',
'Stage Gate 5 Risk Management Plan',
0, 0, 0, 1, 9, 3),

(13, 'stage_gate_6', 1, 'Stage Gate 6', 'workflow', 'stage_gate_6.php',
'Stage Gate 6',
0, 0, 0, 1, 1, 7),

(14, 'stage_gate_6_production_report', 1, 'Production Report', 'workflow', 'stage_gate_6_production_report.php',
'Stage Gate 6 Production Report',
0, 0, 0, 1, 13, 1),

(15, 'stage_gate_6_construction_report', 1, 'Construction Report', 'workflow', 'stage_gate_6_construction_report.php',
'Stage Gate 6 Construction Report',
0, 0, 0, 1, 13, 2),

(16, 'stage_gate_7', 1, 'Stage Gate 7', 'workflow', 'stage_gate_7.php',
'Stage Gate 7',
0, 0, 0, 1, 1, 8),

(17, 'stage_gate_8', 1, 'Stage Gate 8', 'workflow', 'stage_gate_8.php',
'Stage Gate 8',
0, 0, 0, 1, 1, 9),

(18, 'stage_gate_9', 1, 'Stage Gate 9', 'workflow', 'stage_gate_9.php',
'Stage Gate 9',
0, 0, 0, 1, 1, 10),

(19, 'create_project', 1, 'Create Project', 'feature', 'create_project.php',
'Create Project',
0, 0, 0, 1, 1, 11),


-- =====================================================
-- DASHBOARD RIGHTS
-- =====================================================

(20, 'pipeline_status_dashboard', 1, 'Pipeline Status Dashboard', 'dashboard', 'pipeline_status_dashboard.php',
'Pipeline Status Dashboard',
0, 0, 0, 1, 2, 1),

(21, 'stage_gate_dashboard', 1, 'Stage Gate Dashboard', 'dashboard', 'stage_gate_dashboard.php',
'Stage Gate Dashboard',
0, 0, 0, 1, 2, 2),

(22, 'panoptic_evaluation_dashboard', 1, 'Panoptic Evaluation Dashboard', 'dashboard', 'panoptic_evaluation_dashboard.php',
'Panoptic Evaluation Dashboard',
0, 0, 0, 1, 2, 3),

(23, 'investor_prospectus_dashboard', 1, 'Investor Prospectus Dashboard', 'dashboard', 'investor_prospectus_dashboard.php',
'Investor Prospectus Dashboard',
0, 0, 0, 1, 2, 4),


-- =====================================================
-- REPORT RIGHTS
-- =====================================================

(24, 'panoptic_evaluation_summary_report', 1, 'Panoptic Evaluation Summary Report', 'report', 'panoptic_evaluation_summary_report.php',
'Panoptic Evaluation Summary Report',
0, 0, 0, 1, 3, 1);


-- DATE 18-05-2026 User management updates DEV[PENDING] QA[PENDING]

-- User-master: add designation-specific-data-key column.
ALTER TABLE `tbl_user_master` ADD `designation_specific_data_key` VARCHAR(255) NULL AFTER `designation_datakey`;

-- lookup entry for user types
INSERT INTO `tbl_lookup` (`keyid`, `dev_name`, `display_name`, `display_name_ml`, `description`, `is_active`, `translate`, `creation_date`, `created_by`, `updation_date`, `updated_by`) 
VALUES ('115', 'user_types', 'User Types', 'user-types-ml', 'Types of Users', '1', 'No', '2026-05-14 17:07:42', '1', NULL, NULL);

-- lookup_detail entry for user types
INSERT INTO `tbl_lookup_detail` (`optionid`, `keyid`, `data_value`, `data_key`, `display_name`, `display_name_ml`, `sequence`, `item_data`, `parent_datakey`, `is_active`, `creation_date`, `created_by`, `updation_date`, `updated_by`) VALUES ('1983', '115', '1', 'user_type_1', 'WCG Officials', 'wcg-officials-ml', '1', '', NULL, 'active', '2026-05-06 13:14:07', NULL, NULL, NULL);
INSERT INTO `tbl_lookup_detail` (`optionid`, `keyid`, `data_value`, `data_key`, `display_name`, `display_name_ml`, `sequence`, `item_data`, `parent_datakey`, `is_active`, `creation_date`, `created_by`, `updation_date`, `updated_by`) VALUES ('1984', '115', '2', 'user_types_2', 'WCG ICT Committees', 'wcg-ict-committees-ml', '2', '', NULL, 'active', '2026-05-06 13:14:07', NULL, NULL, NULL);
INSERT INTO `tbl_lookup_detail` (`optionid`, `keyid`, `data_value`, `data_key`, `display_name`, `display_name_ml`, `sequence`, `item_data`, `parent_datakey`, `is_active`, `creation_date`, `created_by`, `updation_date`, `updated_by`) VALUES ('1985', '115', '3', 'user_types_3', 'WCG Approval Committees', 'wcg-approval-committees-ml', '3', '', NULL, 'active', '2026-05-06 13:14:07', NULL, NULL, NULL);
INSERT INTO `tbl_lookup_detail` (`optionid`, `keyid`, `data_value`, `data_key`, `display_name`, `display_name_ml`, `sequence`, `item_data`, `parent_datakey`, `is_active`, `creation_date`, `created_by`, `updation_date`, `updated_by`) VALUES ('1986', '115', '4', 'user_types_4', 'Regulatory & Approval', 'regulatory-and-approval-ml', '4', '', NULL, 'active', '2026-05-06 13:14:07', NULL, NULL, NULL);
INSERT INTO `tbl_lookup_detail` (`optionid`, `keyid`, `data_value`, `data_key`, `display_name`, `display_name_ml`, `sequence`, `item_data`, `parent_datakey`, `is_active`, `creation_date`, `created_by`, `updation_date`, `updated_by`) VALUES ('1987', '115', '5', 'user_types_5', 'Public Entities', 'public-entities-ml', '5', '', NULL, 'active', '2026-05-06 13:14:07', NULL, NULL, NULL);
INSERT INTO `tbl_lookup_detail` (`optionid`, `keyid`, `data_value`, `data_key`, `display_name`, `display_name_ml`, `sequence`, `item_data`, `parent_datakey`, `is_active`, `creation_date`, `created_by`, `updation_date`, `updated_by`) VALUES ('1988', '115', '6', 'user_types_6', 'DISTRICTS & MUNICIPALITIES: Key Stakeholders', 'districts-and-municipalities-ml', '6', '', NULL, 'active', '2026-05-06 13:14:07', NULL, NULL, NULL);
INSERT INTO `tbl_lookup_detail` (`optionid`, `keyid`, `data_value`, `data_key`, `display_name`, `display_name_ml`, `sequence`, `item_data`, `parent_datakey`, `is_active`, `creation_date`, `created_by`, `updation_date`, `updated_by`) VALUES ('1989', '115', '7', 'user_types_7', 'COMMUNITIES: Key Stakeholders', 'communities-key-stakeholders-ml', '7', '', NULL, 'active', '2026-05-06 13:14:07', NULL, NULL, NULL);

-- # Update tbl_maxid for tbl_lookup_detail
UPDATE `tbl_maxids`
SET `max_id` = GREATEST(`max_id`, 2023)
WHERE `tbl_name` = 'tbl_lookup_detail';

-- DATE 16 May 2026  DEV[DONE] QA[PENDING] per-user personal reminders on global calendar events.
CREATE TABLE IF NOT EXISTS `tbl_global_event_personal_reminders` (
  `id` BIGINT NOT NULL AUTO_INCREMENT,
  `event_id` BIGINT NOT NULL,
  `user_id` INT NOT NULL,
  `reminders` JSON NOT NULL,
  `created_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
  `created_by` INT NOT NULL,
  `updated_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  `updated_by` INT NOT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `uq_global_event_personal_reminders` (`event_id`, `user_id`),
  KEY `idx_global_event_personal_reminders_user` (`user_id`),
  KEY `idx_global_event_personal_reminders_event` (`event_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

-- DATE 20-05-2026 User registration: allowed email domains (tbl_platform_config). DEV[PENDING] QA[PENDING]
INSERT IGNORE INTO `tbl_platform_config` (`key`, `value`, `created_by`, `updated_by`, `creation_date`, `updation_date`)
VALUES (
    'registration_allowed_email_domains',
    '["cioinfotech.com","cyberia.com","pet.com","cyberia.org.za"]',
    NULL, NULL, NOW(), NOW()
);

-- 21-05-2026 : Removed uniq_first_last_name index from tbl_user_master table. DEV[PENDING] QA[PENDING]
ALTER TABLE `tbl_user_master` DROP INDEX `uniq_first_last_name`;

-- 22-05-2026 : Registration OTP stored on tbl_register (not tbl_user_master.password). DEV[PENDING] QA[PENDING]
ALTER TABLE `tbl_register`
  ADD COLUMN `otp_encrypted` VARCHAR(512) NULL DEFAULT NULL
  COMMENT 'Encrypted registration OTP; cleared after verification'
  AFTER `reg_code`;

-- 28-05-2026 : updated prefix event discription as per the provided sheet. DEV[Done] QA[PENDING]
UPDATE `tbl_events` SET `occurrence_config` = '{"q1_day": 1, "q2_day": 1, "q3_day": 1, "q4_day": 1, "q1_month": 6, "q2_month": 9, "q3_month": 12, "q4_month": 3}' WHERE `event_id` = '6';
UPDATE `tbl_events` SET `description` = 'Strategic Plan to be submitted for mid term review on 30-09-2027.' WHERE `event_id` = '1';
UPDATE `tbl_events` SET `description` = 'Strategic Plan End Term Report to be submitted on 31-03-2030.' WHERE `event_id` = '2';
UPDATE `tbl_events` SET `description` = 'Annual Performance Plan to be submitted on 31st March of  every year for the  duration of the Strategic Planning of 5 years.' WHERE `event_id` = '3';
UPDATE `tbl_events` SET `description` = 'Annual Operating Plan to be submitted on 31st March of  every year for the  duration of the Strategic Planning 5 year.' WHERE `event_id` = '4';
UPDATE `tbl_events` SET `description` = 'Annual Report to be submitted on 30th September of  every year for the  duration of the Strategic Planning of 5 years.' WHERE `event_id` = '5';
UPDATE `tbl_events` SET `description` = 'eQPRS (Electronic Quarterly Performance Reporting System) - Updating indicators online on a Quarterly basis .                                                                                                                                                Online updates is due on 30-06-2026 ; 30-09-2026; 31-12-2026; 31-03-2027' WHERE `event_id` = '6';
UPDATE `tbl_events` SET `description` = 'Service Delivery Improvement Plan updated every 3 years. Update is due on 31-03-2028' WHERE `event_id` = '7';

-- 28-05-2026 : update calendar event category and color data key. DEV[DONE] QA[PENDING]
UPDATE `tbl_lookup_detail` SET
`data_key` = 'calendar_event_categories_and_color_1',
WHERE `optionid` = '2016';

-- 28-05-2026 : updaet calendar event category and color. DEV[DONE] QA[PENDING]
UPDATE `tbl_lookup_detail`
SET `item_data`='{"Statutory Report":{"color":"#D93025","is_global":true},"Online Updates":{"color":"#34A853","is_global":true},"Internal":{"color":"#8E44AD","is_global":true},"Meeting":{"color":"#076ef5","is_global":false},"Briefing Sessions":{"color":"#2C3E50","is_global":false},"Seminars":{"color":"#4A2C2A","is_global":false},"Workshops":{"color":"#0F4C5C","is_global":false}}'
WHERE `tbl_lookup_detail`.`data_key`= 'calender_event_categories_and_colors_1';




-- 04-06-2026: EVE Project Table Incremental Changes Only the table structure changes need to be applied through incremental scripts. We will import all data directly into the QA database, as some tables contain a large volume of records (approximately 37,000). Additionally, some tables were created directly on the Dev database, so please run only those incremental scripts that have not yet been applied to the database. DEV[Done] QA[PENDING]

CREATE TABLE `tbl_query_templates` (
	`template_id` INT(11) NOT NULL AUTO_INCREMENT,
	`intent_name` VARCHAR(100) NULL DEFAULT NULL COLLATE 'utf8mb4_unicode_ci',
	`sql_template` TEXT NULL DEFAULT NULL COLLATE 'utf8mb4_unicode_ci',
	`usage_count` INT(11) NULL DEFAULT '1',
	`creation_date` DATETIME NULL DEFAULT current_timestamp(),
	`created_by` VARCHAR(50) NULL DEFAULT 'system' COLLATE 'utf8mb4_unicode_ci',
	`updation_date` DATETIME NULL DEFAULT current_timestamp(),
	`updated_by` VARCHAR(50) NULL DEFAULT 'system' COLLATE 'utf8mb4_unicode_ci',
	PRIMARY KEY (`template_id`) USING BTREE
)
COLLATE='utf8mb4_unicode_ci'
ENGINE=InnoDB;

CREATE TABLE `tbl_hss` (
	`id` INT(11) NOT NULL AUTO_INCREMENT,
	`id_no` VARCHAR(20) NULL DEFAULT NULL COLLATE 'utf8mb4_general_ci',
	`database_name` VARCHAR(100) NULL DEFAULT 'Western Cape' COLLATE 'utf8mb4_general_ci',
	`name` VARCHAR(150) NULL DEFAULT NULL COLLATE 'utf8mb4_general_ci',
	`id_number` VARCHAR(20) NULL DEFAULT NULL COLLATE 'utf8mb4_general_ci',
	`status` VARCHAR(50) NULL DEFAULT NULL COLLATE 'utf8mb4_general_ci',
	`application_type` VARCHAR(200) NULL DEFAULT NULL COLLATE 'utf8mb4_general_ci',
	`area` VARCHAR(100) NULL DEFAULT NULL COLLATE 'utf8mb4_general_ci',
	`site_number` VARCHAR(50) NULL DEFAULT NULL COMMENT 'Not required' COLLATE 'utf8mb4_general_ci',
	`project_name` TEXT NULL DEFAULT NULL COLLATE 'utf8mb4_general_ci',
	`construction_status` VARCHAR(100) NULL DEFAULT NULL COMMENT 'Not required' COLLATE 'utf8mb4_general_ci',
	`happy_letter` VARCHAR(100) NULL DEFAULT NULL COMMENT 'Not required' COLLATE 'utf8mb4_general_ci',
	`creation_date` DATETIME NULL DEFAULT current_timestamp(),
	`created_by` INT(11) NULL DEFAULT NULL,
	`updation_date` DATETIME NULL DEFAULT NULL,
	`updated_by` INT(11) NULL DEFAULT NULL,
	PRIMARY KEY (`id`) USING BTREE
)
COLLATE='utf8mb4_general_ci'
ENGINE=InnoDB;