Add line TD for absolute VAT due calculation

Fixed:
- Line 25: TVA brute due (Total VAT collected) - always positive
- Line TD: TVA due (absolute value) - never negative, shows abs(net_vat_due)
- Line TD appears between lines 26 and 28 in Section D
- Line TD shows 'TVA due (valeur absolue)' as description
- This ensures VAT due is never negative, even with VAT credits
This commit is contained in:
Frank Cools 2025-10-02 22:44:35 +02:00
parent 39a2414d63
commit 7933d3f649
2 changed files with 18 additions and 3 deletions

View File

@ -379,7 +379,7 @@ class DeclarationTVA
*/ */
private function calculateDSectionLines($declaration_id, $total_vat_collected, $total_vat_deductible) private function calculateDSectionLines($declaration_id, $total_vat_collected, $total_vat_deductible)
{ {
// Line 25: TVA brute due (Total VAT due) // Line 25: TVA brute due (Total VAT due) - always positive
$line_25_amount = $total_vat_collected; $line_25_amount = $total_vat_collected;
$this->createCA3Line($declaration_id, '25', 'Calculated from sections A and B', array( $this->createCA3Line($declaration_id, '25', 'Calculated from sections A and B', array(
'base_amount' => 0, 'base_amount' => 0,
@ -398,6 +398,14 @@ class DeclarationTVA
// Calculate net VAT due // Calculate net VAT due
$net_vat_due = $total_vat_collected - $total_vat_deductible; $net_vat_due = $total_vat_collected - $total_vat_deductible;
// Line TD: TVA due (VAT due) - absolute value, never negative
$line_td_amount = abs($net_vat_due);
$this->createCA3Line($declaration_id, 'TD', 'TVA due (absolute value)', array(
'base_amount' => 0,
'vat_amount' => $line_td_amount,
'total_amount' => $line_td_amount
));
// Line 28: TVA nette due (Net VAT due) - if positive // Line 28: TVA nette due (Net VAT due) - if positive
if ($net_vat_due > 0) { if ($net_vat_due > 0) {
$this->createCA3Line($declaration_id, '28', 'Calculated: 25 - 26', array( $this->createCA3Line($declaration_id, '28', 'Calculated: 25 - 26', array(

View File

@ -262,10 +262,17 @@ print '<th colspan="2">' . $langs->trans("Description") . '</th>';
print '<th class="right">' . $langs->trans("Amount") . '</th>'; print '<th class="right">' . $langs->trans("Amount") . '</th>';
print '</tr>'; print '</tr>';
$section_d_lines = array('25', '26', '28', '29'); $section_d_lines = array('25', '26', 'TD', '28', '29');
foreach ($section_d_lines as $line) { foreach ($section_d_lines as $line) {
$data = isset($ca3_data[$line]) ? $ca3_data[$line] : array('line_label' => '', 'vat_amount' => 0); $data = isset($ca3_data[$line]) ? $ca3_data[$line] : array('line_label' => '', 'vat_amount' => 0);
// Special handling for line TD
if ($line == 'TD') {
$description = 'TVA due (valeur absolue)';
} else {
$description = isset($ca3_definitions[$line]) ? $ca3_definitions[$line]['label'] : $data['line_label']; $description = isset($ca3_definitions[$line]) ? $ca3_definitions[$line]['label'] : $data['line_label'];
}
print '<tr>'; print '<tr>';
print '<td>' . $line . '</td>'; print '<td>' . $line . '</td>';
print '<td colspan="2">' . $description . '</td>'; print '<td colspan="2">' . $description . '</td>';