Fix declaration list to use CA-3 line values (line 32 for VAT due, lines 26/27 for refund) instead of main table values

This commit is contained in:
Frank Cools 2025-10-08 15:16:03 +02:00
parent 5cae470880
commit fea225dc3d

View File

@ -141,14 +141,33 @@ if (empty($declarations)) {
}
print '<td class="center">' . $langs->trans("Status" . ucfirst($d['status'])) . $status_icon . '</td>';
// Show VAT amount with proper label
// Check if there's a VAT credit (refund) or net VAT due
if ($d['vat_credit'] > 0) {
// VAT refund case
print '<td class="center"><strong style="color: #28a745;">' . price($d['vat_credit']) . '</strong><br><small>' . $langs->trans("VATToReceive") . '</small></td>';
} elseif ($d['net_vat_due'] > 0) {
// VAT due case - DEBUG: Show raw value
print '<td class="center"><strong style="color: #dc3545;">' . price($d['net_vat_due']) . '</strong><br><small>' . $langs->trans("NetVATDue") . ' (DB: ' . $d['net_vat_due'] . ')</small></td>';
// Show VAT amount with proper label - use CA-3 line values instead of main table
$declarationtva = new DeclarationTVA($db, $conf->entity);
$ca3_lines = $declarationtva->getCA3Lines($d['rowid']);
// Get line 32 (net VAT due) and lines 26/27 (VAT credit)
$line_32_amount = 0;
$line_26_amount = 0;
$line_27_amount = 0;
foreach ($ca3_lines as $line) {
if ($line['ca3_line'] == '32') {
$line_32_amount = $line['vat_amount'];
} elseif ($line['ca3_line'] == '26') {
$line_26_amount = $line['vat_amount'];
} elseif ($line['ca3_line'] == '27') {
$line_27_amount = $line['vat_amount'];
}
}
// Determine which value to show based on CA-3 lines
if ($line_32_amount > 0) {
// VAT due case - use line 32
print '<td class="center"><strong style="color: #dc3545;">' . price($line_32_amount) . '</strong><br><small>' . $langs->trans("NetVATDue") . '</small></td>';
} elseif ($line_26_amount > 0 || $line_27_amount > 0) {
// VAT refund case - use line 26 or 27 (whichever is not 0)
$refund_amount = $line_26_amount > 0 ? $line_26_amount : $line_27_amount;
print '<td class="center"><strong style="color: #28a745;">' . price($refund_amount) . '</strong><br><small>' . $langs->trans("VATToReceive") . '</small></td>';
} else {
// Balanced case
print '<td class="center"><strong>' . price(0) . '</strong><br><small>' . $langs->trans("VATBalanced") . '</small></td>';