From 12a14e6dd2ee5117c71336c77d43c6bb50aa30d1 Mon Sep 17 00:00:00 2001 From: Frank Cools Date: Thu, 2 Oct 2025 17:39:14 +0200 Subject: [PATCH] Add automatic table creation to setup page Setup Page Enhancement: - Added automatic table creation when table doesn't exist - Creates table with correct structure and constraints - Provides immediate feedback on creation success/failure - No need to deactivate/reactivate module This should resolve the table creation issue immediately! --- admin/setup_mvp.php | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/admin/setup_mvp.php b/admin/setup_mvp.php index 34f3114..0f77e32 100644 --- a/admin/setup_mvp.php +++ b/admin/setup_mvp.php @@ -71,7 +71,7 @@ $mappings_by_line = $config->getAccountMappingsByLine(); $accounts = $config->getAccountingAccounts(); $ca3_definitions = $config->getCA3LineDefinitions(); -// Debug: Check if table exists and show structure (simplified) +// Debug: Check if table exists and create if missing $table_name = MAIN_DB_PREFIX . "declarationtva_account_mappings"; $check_table_sql = "SHOW TABLES LIKE '" . $table_name . "'"; $table_exists = $db->query($check_table_sql); @@ -85,7 +85,30 @@ if ($table_exists && $db->num_rows($table_exists) > 0) { setEventMessages("Debug: Table exists but needs migration - please deactivate and reactivate the module", null, 'warnings'); } } else { - setEventMessages("Debug: Table $table_name does NOT exist - please activate the module first", null, 'errors'); + setEventMessages("Debug: Table $table_name does NOT exist - creating it now", null, 'warnings'); + + // Create the table manually + $create_table_sql = "CREATE TABLE IF NOT EXISTS `" . $table_name . "` ( + `rowid` int(11) NOT NULL AUTO_INCREMENT, + `entity` int(11) NOT NULL DEFAULT 1, + `ca3_line` varchar(8) NOT NULL COMMENT 'A1, A2, A3, A4, A5, 08, 09, 9B, 17, 20, 21, 22, 25, 26, 28, 29', + `account_code` varchar(32) NOT NULL COMMENT 'PCG account code', + `account_label` varchar(255) DEFAULT NULL, + `vat_rate` decimal(5,2) DEFAULT NULL, + `is_active` tinyint(1) DEFAULT 1, + `created_date` datetime DEFAULT NULL, + PRIMARY KEY (`rowid`), + UNIQUE KEY `uk_mapping_entity_line_account` (`entity`, `ca3_line`, `account_code`), + KEY `idx_ca3_line` (`ca3_line`), + KEY `idx_account_code` (`account_code`) + ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci"; + + $create_result = $db->query($create_table_sql); + if ($create_result) { + setEventMessages("Debug: Table created successfully!", null, 'mesgs'); + } else { + setEventMessages("Debug: Failed to create table: " . $db->lasterror(), null, 'errors'); + } } $section_headers = $config->getCA3SectionHeaders();