From 24890aae716c8ccbb6e7ae430b9b9663a9abb033 Mon Sep 17 00:00:00 2001 From: Frank Cools Date: Thu, 2 Oct 2025 23:24:46 +0200 Subject: [PATCH] Fix CA-3 line details mapping logic and add debugging Fixed: - Updated getCA3LineDetails() to handle special cases for lines 08, 09, 9B - These lines have _BASE and _VAT suffixes in the database - Added proper matching logic for both normal lines and special cases - Added debugging to AJAX endpoint and backend method - Added error logging to trace mapping issues This should fix the issue where only A1 works but other lines show no accounts. --- core/class/declarationtva.class.php | 20 ++++++++++++++++++-- declarationtva_line_details_ajax.php | 9 +++++++++ 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/core/class/declarationtva.class.php b/core/class/declarationtva.class.php index c1c95c8..b1b6fde 100644 --- a/core/class/declarationtva.class.php +++ b/core/class/declarationtva.class.php @@ -882,13 +882,29 @@ class DeclarationTVA $mappings = $this->getAccountMappings(); $line_mappings = array(); + // Debug: Log all mappings for this line + error_log("DeclarationTVA: Looking for mappings for CA-3 line: " . $ca3_line); + error_log("DeclarationTVA: Total mappings found: " . count($mappings)); + // Find mappings for this specific line foreach ($mappings as $mapping) { - if ($mapping['ca3_line'] == $ca3_line) { - $line_mappings[] = $mapping; + // Handle special cases for lines 08, 09, 9B which have _BASE and _VAT suffixes + if (in_array($ca3_line, array('08', '09', '9B'))) { + if ($mapping['ca3_line'] == $ca3_line . '_BASE' || $mapping['ca3_line'] == $ca3_line . '_VAT') { + $line_mappings[] = $mapping; + error_log("DeclarationTVA: Found mapping for " . $ca3_line . ": " . $mapping['ca3_line'] . " -> " . $mapping['account_code']); + } + } else { + // Normal matching for other lines + if ($mapping['ca3_line'] == $ca3_line) { + $line_mappings[] = $mapping; + error_log("DeclarationTVA: Found mapping for " . $ca3_line . ": " . $mapping['ca3_line'] . " -> " . $mapping['account_code']); + } } } + error_log("DeclarationTVA: Line mappings found for " . $ca3_line . ": " . count($line_mappings)); + $details = array(); $total_base = 0; $total_vat = 0; diff --git a/declarationtva_line_details_ajax.php b/declarationtva_line_details_ajax.php index 950369a..ed7f810 100644 --- a/declarationtva_line_details_ajax.php +++ b/declarationtva_line_details_ajax.php @@ -49,8 +49,17 @@ if (!$declarationtva->fetch($declaration_id)) { // Get detailed breakdown $line_details = $declarationtva->getCA3LineDetails($declaration_id, $ca3_line); +// Debug information if (empty($line_details)) { + echo '
' . $langs->trans("NoDataFoundForLine") . '
'; + echo '
Debug: CA-3 line: ' . $ca3_line . ', Declaration ID: ' . $declaration_id . '
'; + exit; +} + +// Debug: Show account count +if (empty($line_details['account_details'])) { echo '
' . $langs->trans("NoDataFoundForLine") . '
'; + echo '
Debug: No account details found for line ' . $ca3_line . '
'; exit; }