From b5da8910ee23ffb1f3ce5f195f6a450fafbe6305 Mon Sep 17 00:00:00 2001 From: Frank Cools Date: Thu, 9 Oct 2025 00:48:03 +0200 Subject: [PATCH] Fix getBankAccountDetails to match PDF version exactly - Use ba.account_number directly instead of LEFT JOIN - Get account label separately using getAccountLabel method - Match the exact logic from PDF generation that works - Add debug logging to see account_number and account_label values --- core/class/declarationtva.class.php | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/core/class/declarationtva.class.php b/core/class/declarationtva.class.php index 735063a..147cf40 100644 --- a/core/class/declarationtva.class.php +++ b/core/class/declarationtva.class.php @@ -1414,17 +1414,30 @@ class DeclarationTVA */ private function getBankAccountDetails($bank_account_id) { - $sql = "SELECT ba.rowid, ba.label, ba.number, a.account_number as account_code, a.label as account_label + // Get bank account info and its linked accounting account + $sql = "SELECT ba.rowid, ba.label, ba.number, ba.bank, ba.account_number FROM " . MAIN_DB_PREFIX . "bank_account ba - LEFT JOIN " . MAIN_DB_PREFIX . "accounting_account a ON a.rowid = ba.account_number - WHERE ba.rowid = " . (int)$bank_account_id . " AND ba.entity = " . $this->entity; + WHERE ba.rowid = " . (int)$bank_account_id . " + AND ba.entity = " . $this->entity; error_log("DEBUG: Bank account query: " . $sql); $result = $this->db->query($sql); if ($result && $this->db->num_rows($result) > 0) { - $bank_data = $this->db->fetch_array($result); - error_log("DEBUG: Bank account data: " . print_r($bank_data, true)); - return $bank_data; + $obj = $this->db->fetch_object($result); + + // Get the accounting account label for the account code + $account_label = $this->getAccountLabel($obj->account_number); + + error_log("DEBUG: Bank account data - account_number: " . $obj->account_number . ", account_label: " . $account_label); + + return array( + 'rowid' => $obj->rowid, + 'label' => $obj->label, + 'number' => $obj->number, + 'bank' => $obj->bank, + 'account_code' => $obj->account_number, // Use the linked accounting account code + 'account_label' => $account_label + ); } error_log("DEBUG: No bank account found for ID: " . $bank_account_id);