From b7d6f50d2753e04663dd47d56bfc86de993d216d Mon Sep 17 00:00:00 2001 From: Frank Cools Date: Wed, 8 Oct 2025 22:03:22 +0200 Subject: [PATCH] Add database verification for accounting entries - Add verification query after each bookkeeping create call - Add final verification to count total entries created - Help identify if entries are actually being saved to database --- core/class/declarationtva.class.php | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/core/class/declarationtva.class.php b/core/class/declarationtva.class.php index f5733a2..e4551ae 100644 --- a/core/class/declarationtva.class.php +++ b/core/class/declarationtva.class.php @@ -1247,6 +1247,25 @@ class DeclarationTVA $this->error = 'Failed to create accounting entry: ' . $bookkeeping->error; return false; } + + // Check if entry was actually created by querying the database + $check_sql = "SELECT COUNT(*) as count FROM " . MAIN_DB_PREFIX . "accounting_bookkeeping + WHERE doc_type = 'declarationtva' AND doc_ref = '" . $this->db->escape($declaration->declaration_name) . "' + AND account_number = '" . $this->db->escape($entry['account_code']) . "'"; + $check_result = $this->db->query($check_sql); + if ($check_result && $this->db->num_rows($check_result) > 0) { + $check_obj = $this->db->fetch_object($check_result); + error_log("DEBUG: Entry verification - Found " . $check_obj->count . " entries in database for account " . $entry['account_code']); + } + } + + // Final verification - check all entries created for this declaration + $final_check_sql = "SELECT COUNT(*) as total_entries FROM " . MAIN_DB_PREFIX . "accounting_bookkeeping + WHERE doc_type = 'declarationtva' AND doc_ref = '" . $this->db->escape($declaration->declaration_name) . "'"; + $final_check_result = $this->db->query($final_check_sql); + if ($final_check_result && $this->db->num_rows($final_check_result) > 0) { + $final_check_obj = $this->db->fetch_object($final_check_result); + error_log("DEBUG: Final verification - Total entries in database for declaration " . $declaration->declaration_name . ": " . $final_check_obj->total_entries); } return true;