From c6984d8527509076897e2e77bb6d85620d1ed456 Mon Sep 17 00:00:00 2001 From: Frank Cools Date: Wed, 8 Oct 2025 22:21:05 +0200 Subject: [PATCH] Add account validation and existing entry comparison - Check if account number exists in accounting_account table - Compare with existing accounting entries to see field differences - Help identify if account validation is causing the -1 return - Debug the exact validation requirements --- 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 a8f1ef3..985ce51 100644 --- a/core/class/declarationtva.class.php +++ b/core/class/declarationtva.class.php @@ -1269,6 +1269,25 @@ class DeclarationTVA error_log("DEBUG: Journal code 'OD' NOT FOUND in system - this might be the issue"); } + // Check if account number exists + $account_check_sql = "SELECT account_number FROM " . MAIN_DB_PREFIX . "accounting_account WHERE account_number = '" . $this->db->escape($entry['account_code']) . "' AND entity = " . $this->entity; + $account_check_result = $this->db->query($account_check_sql); + if ($account_check_result && $this->db->num_rows($account_check_result) > 0) { + error_log("DEBUG: Account number '" . $entry['account_code'] . "' exists in system"); + } else { + error_log("DEBUG: Account number '" . $entry['account_code'] . "' NOT FOUND in system - this might be the issue"); + } + + // Check existing accounting entries to see what fields they have + $existing_sql = "SELECT * FROM " . MAIN_DB_PREFIX . "accounting_bookkeeping WHERE entity = " . $this->entity . " LIMIT 1"; + $existing_result = $this->db->query($existing_sql); + if ($existing_result && $this->db->num_rows($existing_result) > 0) { + $existing_obj = $this->db->fetch_object($existing_result); + error_log("DEBUG: Existing entry fields - doc_date: " . $existing_obj->doc_date . ", doc_ref: " . $existing_obj->doc_ref . ", code_journal: " . $existing_obj->code_journal . ", numero_compte: " . $existing_obj->numero_compte . ", montant: " . $existing_obj->montant . ", sens: " . $existing_obj->sens); + } else { + error_log("DEBUG: No existing accounting entries found in system"); + } + $result = $debit->create($user); error_log("DEBUG: Debit entry create result: " . $result . " (type: " . gettype($result) . ")");