Improve CA-3 line details display with proper account grouping

Fixed:
- Grouped BASE and VAT accounts separately for lines 08, 09, 9B
- Added clear section headers: 'Base Accounts (Sales)' and 'VAT Accounts'
- Improved visual organization of account breakdown
- Removed debugging code
- Added translations for new section headers

This ensures users can clearly see which accounts contribute to base amounts vs VAT amounts for the special lines.
This commit is contained in:
Frank Cools 2025-10-02 23:28:07 +02:00
parent 24890aae71
commit 84017f33ce
4 changed files with 65 additions and 13 deletions

View File

@ -882,29 +882,21 @@ 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) {
// 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;

View File

@ -49,17 +49,13 @@ if (!$declarationtva->fetch($declaration_id)) {
// Get detailed breakdown
$line_details = $declarationtva->getCA3LineDetails($declaration_id, $ca3_line);
// Debug information
if (empty($line_details)) {
echo '<div class="error">' . $langs->trans("NoDataFoundForLine") . '</div>';
echo '<div class="info">Debug: CA-3 line: ' . $ca3_line . ', Declaration ID: ' . $declaration_id . '</div>';
exit;
}
// Debug: Show account count
if (empty($line_details['account_details'])) {
echo '<div class="info">' . $langs->trans("NoDataFoundForLine") . '</div>';
echo '<div class="info">Debug: No account details found for line ' . $ca3_line . '</div>';
exit;
}
@ -67,6 +63,21 @@ if (empty($line_details['account_details'])) {
$ca3_definitions = $config->getCA3LineDefinitions();
$line_definition = isset($ca3_definitions[$ca3_line]) ? $ca3_definitions[$ca3_line] : null;
// Group accounts by type for lines 08, 09, 9B
$base_accounts = array();
$vat_accounts = array();
$other_accounts = array();
foreach ($line_details['account_details'] as $account) {
if (strpos($account['mapping_type'], '_BASE') !== false) {
$base_accounts[] = $account;
} elseif (strpos($account['mapping_type'], '_VAT') !== false) {
$vat_accounts[] = $account;
} else {
$other_accounts[] = $account;
}
}
// Display account details table
echo '<table class="noborder centpercent">';
echo '<tr class="liste_titre">';
@ -82,7 +93,52 @@ $total_base = 0;
$total_vat = 0;
$total_amount = 0;
foreach ($line_details['account_details'] as $account) {
// Display BASE accounts first (if any)
if (!empty($base_accounts)) {
echo '<tr class="liste_titre">';
echo '<td colspan="6"><strong>' . $langs->trans("BaseAccounts") . '</strong></td>';
echo '</tr>';
foreach ($base_accounts as $account) {
$total_base += $account['base_amount'];
$total_vat += $account['vat_amount'];
$total_amount += $account['total_amount'];
echo '<tr class="oddeven">';
echo '<td><strong>' . $account['account_code'] . '</strong></td>';
echo '<td>' . $account['account_label'] . '</td>';
echo '<td class="right">' . price($account['base_amount']) . '</td>';
echo '<td class="right">' . price($account['vat_amount']) . '</td>';
echo '<td class="right">' . price($account['total_amount']) . '</td>';
echo '<td>' . $account['mapping_type'] . '</td>';
echo '</tr>';
}
}
// Display VAT accounts second (if any)
if (!empty($vat_accounts)) {
echo '<tr class="liste_titre">';
echo '<td colspan="6"><strong>' . $langs->trans("VATAccounts") . '</strong></td>';
echo '</tr>';
foreach ($vat_accounts as $account) {
$total_base += $account['base_amount'];
$total_vat += $account['vat_amount'];
$total_amount += $account['total_amount'];
echo '<tr class="oddeven">';
echo '<td><strong>' . $account['account_code'] . '</strong></td>';
echo '<td>' . $account['account_label'] . '</td>';
echo '<td class="right">' . price($account['base_amount']) . '</td>';
echo '<td class="right">' . price($account['vat_amount']) . '</td>';
echo '<td class="right">' . price($account['total_amount']) . '</td>';
echo '<td>' . $account['mapping_type'] . '</td>';
echo '</tr>';
}
}
// Display other accounts (normal lines)
foreach ($other_accounts as $account) {
$total_base += $account['base_amount'];
$total_vat += $account['vat_amount'];
$total_amount += $account['total_amount'];

View File

@ -461,3 +461,5 @@ AccountBreakdown = Account Breakdown
Loading = Loading...
ErrorLoadingDetails = Error loading details
Summary = Summary
BaseAccounts = Base Accounts (Sales)
VATAccounts = VAT Accounts

View File

@ -450,3 +450,5 @@ AccountBreakdown = Détail des comptes
Loading = Chargement...
ErrorLoadingDetails = Erreur lors du chargement des détails
Summary = Résumé
BaseAccounts = Comptes de base (ventes)
VATAccounts = Comptes de TVA