From 5cbffd799add0482c2f0bc817c16b5bc242952b0 Mon Sep 17 00:00:00 2001 From: Frank Cools Date: Thu, 2 Oct 2025 23:33:21 +0200 Subject: [PATCH] Add getAccountMappings() method to retrieve account labels Fixed: - Added missing getAccountMappings() method to DeclarationTVA class - Joins with Dolibarr's accounting_account table to get labels - Retrieves account labels from chart of accounts (llx_accounting_account) - Falls back to stored label if chart of accounts label not available - Returns array with rowid, ca3_line, account_code, account_label, vat_rate, is_active This fixes the issue where account labels were not showing in dropdown panels. --- core/class/declarationtva.class.php | 36 +++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/core/class/declarationtva.class.php b/core/class/declarationtva.class.php index bbda54a..61abc7c 100644 --- a/core/class/declarationtva.class.php +++ b/core/class/declarationtva.class.php @@ -856,6 +856,42 @@ class DeclarationTVA return $this->calculateCA3Amounts($declaration_id, $period); } + /** + * Get account mappings with labels from chart of accounts + * + * @return array Array of account mappings with labels + */ + public function getAccountMappings() + { + $sql = "SELECT m.rowid, m.ca3_line, m.account_code, m.account_label, m.vat_rate, m.is_active, + a.label as account_label_pcg + FROM " . MAIN_DB_PREFIX . "declarationtva_account_mappings m + LEFT JOIN " . MAIN_DB_PREFIX . "accounting_account a ON a.account_number = m.account_code AND a.entity = m.entity + WHERE m.entity = " . $this->entity . " AND m.is_active = 1 + ORDER BY m.ca3_line, m.account_code"; + + $result = $this->db->query($sql); + $mappings = array(); + + if ($result) { + while ($obj = $this->db->fetch_object($result)) { + // Use the label from chart of accounts if available, otherwise use the stored label + $account_label = !empty($obj->account_label_pcg) ? $obj->account_label_pcg : $obj->account_label; + + $mappings[] = array( + 'rowid' => $obj->rowid, + 'ca3_line' => $obj->ca3_line, + 'account_code' => $obj->account_code, + 'account_label' => $account_label, + 'vat_rate' => $obj->vat_rate, + 'is_active' => $obj->is_active + ); + } + } + + return $mappings; + } + /** * Get detailed account breakdown for a specific CA-3 line *