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
This commit is contained in:
Frank Cools 2025-10-08 22:03:22 +02:00
parent 0dcab38b4a
commit b7d6f50d27

View File

@ -1247,6 +1247,25 @@ class DeclarationTVA
$this->error = 'Failed to create accounting entry: ' . $bookkeeping->error; $this->error = 'Failed to create accounting entry: ' . $bookkeeping->error;
return false; 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; return true;