From 175a4bdc902657c6281ba5cd8fae9bda7c513493 Mon Sep 17 00:00:00 2001 From: Frank Cools Date: Thu, 9 Oct 2025 00:44:03 +0200 Subject: [PATCH] Add getBankAccountDetails method for bank journal entries - Add getBankAccountDetails method copied from PDF class - This method gets bank account details and returns the linked accounting account code - Fixes the issue where bank account code is not found for bank journal entries - Uses the same logic that works in PDF generation --- core/class/declarationtva.class.php | 34 +++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/core/class/declarationtva.class.php b/core/class/declarationtva.class.php index 02169a4..9c5af20 100644 --- a/core/class/declarationtva.class.php +++ b/core/class/declarationtva.class.php @@ -1451,6 +1451,40 @@ class DeclarationTVA return $account_code; // Fallback to account code } + + /** + * Get bank account details + * + * @param int $bank_account_id Bank account ID + * @return array|false Bank account details or false if not found + */ + private function getBankAccountDetails($bank_account_id) + { + // 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 + WHERE ba.rowid = " . (int)$bank_account_id . " + AND ba.entity = " . $this->entity; + + $result = $this->db->query($sql); + if ($result && $this->db->num_rows($result) > 0) { + $obj = $this->db->fetch_object($result); + + // Get the accounting account label for the account code + $account_label = $this->getAccountLabel($obj->account_number); + + 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 + ); + } + + return false; + } /** * Submit declaration (create accounting entries and update status)