From fada7ba882c906bca86f8a2b52daa73c47558f17 Mon Sep 17 00:00:00 2001 From: Frank Cools Date: Thu, 2 Oct 2025 17:48:49 +0200 Subject: [PATCH] Fix database column name and duplicate entry issues Database Fixes: - Fixed 'Unknown column id' error by using 'rowid' instead of 'id' - Fixed duplicate entry constraint by properly handling existing records - Now checks for both active and inactive existing records - Reactivates existing inactive records instead of trying to insert duplicates This should resolve the account mapping save issues! --- core/class/declarationtva_config.class.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/core/class/declarationtva_config.class.php b/core/class/declarationtva_config.class.php index a8426c8..b45a400 100644 --- a/core/class/declarationtva_config.class.php +++ b/core/class/declarationtva_config.class.php @@ -116,8 +116,8 @@ class DeclarationTVA_Config if (!empty($account_codes)) { foreach ($account_codes as $account_code) { if (!empty($account_code)) { - // Check if mapping already exists - $check_sql = "SELECT id FROM " . MAIN_DB_PREFIX . "declarationtva_account_mappings + // Check if mapping already exists (active or inactive) + $check_sql = "SELECT rowid, is_active FROM " . MAIN_DB_PREFIX . "declarationtva_account_mappings WHERE entity = " . $this->entity . " AND ca3_line = '" . $this->db->escape($ca3_line) . "' AND account_code = '" . $this->db->escape($account_code) . "'"; @@ -125,7 +125,7 @@ class DeclarationTVA_Config error_log("DeclarationTVA: Check query result: " . ($check_result ? 'SUCCESS' : 'FAILED - ' . $this->db->lasterror())); if ($check_result && $this->db->num_rows($check_result) > 0) { - // Update existing mapping + // Update existing mapping (reactivate it) $sql = "UPDATE " . MAIN_DB_PREFIX . "declarationtva_account_mappings SET is_active = 1 WHERE entity = " . $this->entity . "