Add automatic calculation for D-section result lines (25, 26, 28, 29)

Enhanced:
- D-section lines are now calculated automatically from other sections
- Line 25: TVA brute due (sum of sections A and B)
- Line 26: TVA déductible totale (sum of section C)
- Line 28: TVA nette due (25 - 26, if positive)
- Line 29: Crédit de TVA (26 - 25, if negative)
- Configuration page skips D-section as it's calculated
- Added explanatory note in configuration
- Result lines show 'Calculated from...' labels
This commit is contained in:
Frank Cools 2025-10-02 22:18:20 +02:00
parent b9c3c74c16
commit bb6f5a3724
2 changed files with 72 additions and 0 deletions

View File

@ -154,6 +154,12 @@ foreach ($lines_by_section as $section_code => $lines) {
print '<div class="info"><strong>Référence:</strong> ' . $section_info['notice'] . '</div>';
}
// Skip D-section lines (25, 26, 28, 29) as they are calculated
if ($section_code == 'D') {
print '<div class="info"><strong>Note:</strong> Les lignes de la section D sont calculées automatiquement à partir des autres sections.</div>';
continue;
}
print '<table class="noborder centpercent">';
print '<tr class="liste_titre">';
print '<th>' . $langs->trans("CA3Line") . '</th>';

View File

@ -276,6 +276,9 @@ class DeclarationTVA
}
}
// Calculate D-section result lines (25, 26, 28, 29)
$this->calculateDSectionLines($declaration_id, $total_vat_collected, $total_vat_deductible);
// Calculate net amounts
$net_vat_due = $total_vat_collected - $total_vat_deductible;
$vat_credit = $net_vat_due < 0 ? abs($net_vat_due) : 0;
@ -287,6 +290,69 @@ class DeclarationTVA
return true;
}
/**
* Calculate D-section result lines (25, 26, 28, 29)
*
* @param int $declaration_id Declaration ID
* @param float $total_vat_collected Total VAT collected
* @param float $total_vat_deductible Total VAT deductible
* @return bool Success
*/
private function calculateDSectionLines($declaration_id, $total_vat_collected, $total_vat_deductible)
{
// Line 25: TVA brute due (Total VAT due)
$line_25_amount = $total_vat_collected;
$this->createCA3Line($declaration_id, '25', 'Calculated from sections A and B', array(
'base_amount' => 0,
'vat_amount' => $line_25_amount,
'total_amount' => $line_25_amount
));
// Line 26: TVA déductible totale (Total deductible VAT)
$line_26_amount = $total_vat_deductible;
$this->createCA3Line($declaration_id, '26', 'Calculated from section C', array(
'base_amount' => 0,
'vat_amount' => $line_26_amount,
'total_amount' => $line_26_amount
));
// Calculate net VAT due
$net_vat_due = $total_vat_collected - $total_vat_deductible;
// Line 28: TVA nette due (Net VAT due) - if positive
if ($net_vat_due > 0) {
$this->createCA3Line($declaration_id, '28', 'Calculated: 25 - 26', array(
'base_amount' => 0,
'vat_amount' => $net_vat_due,
'total_amount' => $net_vat_due
));
} else {
$this->createCA3Line($declaration_id, '28', 'Calculated: 25 - 26', array(
'base_amount' => 0,
'vat_amount' => 0,
'total_amount' => 0
));
}
// Line 29: Crédit de TVA (VAT Credit) - if negative
if ($net_vat_due < 0) {
$vat_credit = abs($net_vat_due);
$this->createCA3Line($declaration_id, '29', 'Calculated: 26 - 25', array(
'base_amount' => 0,
'vat_amount' => $vat_credit,
'total_amount' => $vat_credit
));
} else {
$this->createCA3Line($declaration_id, '29', 'Calculated: 26 - 25', array(
'base_amount' => 0,
'vat_amount' => 0,
'total_amount' => 0
));
}
return true;
}
/**
* Get account amounts for a period
*