Display rounded values without decimals and empty fields for zero

Improved:
- All amounts now display as whole numbers without decimals (e.g., 124 instead of 124.00)
- Zero values show as empty fields to avoid confusion
- Original amounts in brackets still show with 2 decimals for precision
- Cleaner display: 124 (123.67) or just 124 or empty field
- Added formatAmount() helper for simple amounts
- Updated formatAmountWithOriginal() to handle zero values
- Much cleaner and less confusing for users
This commit is contained in:
Frank Cools 2025-10-02 22:59:36 +02:00
parent ce88aa69c1
commit c73ca2ca48

View File

@ -121,6 +121,11 @@ $ca3_definitions = $config->getCA3LineDefinitions();
// Helper function to format amounts with original values in brackets // Helper function to format amounts with original values in brackets
function formatAmountWithOriginal($amount, $line_label, $amount_type = 'vat') { function formatAmountWithOriginal($amount, $line_label, $amount_type = 'vat') {
// If amount is zero, show empty field
if ($amount == 0) {
return '';
}
// Parse original amounts from line_label if they exist // Parse original amounts from line_label if they exist
if (strpos($line_label, '|ORIGINAL_') !== false) { if (strpos($line_label, '|ORIGINAL_') !== false) {
$parts = explode('|', $line_label); $parts = explode('|', $line_label);
@ -130,11 +135,20 @@ function formatAmountWithOriginal($amount, $line_label, $amount_type = 'vat') {
if (preg_match($pattern, $original_info, $matches)) { if (preg_match($pattern, $original_info, $matches)) {
$original_amount = floatval($matches[1]); $original_amount = floatval($matches[1]);
if ($original_amount != $amount) { if ($original_amount != $amount) {
return price($amount) . ' (' . number_format($original_amount, 2) . ')'; return number_format($amount, 0) . ' (' . number_format($original_amount, 2) . ')';
} }
} }
} }
return price($amount); return number_format($amount, 0);
}
// Helper function to format simple amounts (no original values)
function formatAmount($amount) {
// If amount is zero, show empty field
if ($amount == 0) {
return '';
}
return number_format($amount, 0);
} }
// Create a lookup array for quick access // Create a lookup array for quick access
@ -199,7 +213,7 @@ $data = isset($ca3_data['16']) ? $ca3_data['16'] : array('line_label' => '', 'va
print '<tr class="pair">'; print '<tr class="pair">';
print '<td><strong>16</strong></td>'; print '<td><strong>16</strong></td>';
print '<td colspan="2"><strong>Sous-total TVA due (08 + 09 + 9B)</strong></td>'; print '<td colspan="2"><strong>Sous-total TVA due (08 + 09 + 9B)</strong></td>';
print '<td class="right"><strong>' . price($data['vat_amount']) . '</strong></td>'; print '<td class="right"><strong>' . formatAmount($data['vat_amount']) . '</strong></td>';
print '</tr>'; print '</tr>';
// Reset to normal layout for line 17 // Reset to normal layout for line 17
@ -244,7 +258,7 @@ $data = isset($ca3_data['23']) ? $ca3_data['23'] : array('line_label' => '', 'va
print '<tr class="pair">'; print '<tr class="pair">';
print '<td><strong>23</strong></td>'; print '<td><strong>23</strong></td>';
print '<td colspan="2"><strong>Sous-total TVA déductible (20 + 21 + 22)</strong></td>'; print '<td colspan="2"><strong>Sous-total TVA déductible (20 + 21 + 22)</strong></td>';
print '<td class="right"><strong>' . price($data['vat_amount']) . '</strong></td>'; print '<td class="right"><strong>' . formatAmount($data['vat_amount']) . '</strong></td>';
print '</tr>'; print '</tr>';
// Section D: Résultat // Section D: Résultat
@ -272,7 +286,7 @@ foreach ($section_d_lines as $line) {
print '<tr>'; print '<tr>';
print '<td>' . $line . '</td>'; print '<td>' . $line . '</td>';
print '<td colspan="2">' . $description . '</td>'; print '<td colspan="2">' . $description . '</td>';
print '<td class="right">' . price($data['vat_amount']) . '</td>'; print '<td class="right">' . formatAmount($data['vat_amount']) . '</td>';
print '</tr>'; print '</tr>';
} }