From c73ca2ca480a29a7c06747d80fb12b437ae9a2c4 Mon Sep 17 00:00:00 2001 From: Frank Cools Date: Thu, 2 Oct 2025 22:59:36 +0200 Subject: [PATCH] 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 --- declarationtva_view.php | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/declarationtva_view.php b/declarationtva_view.php index 40b2272..19c6340 100644 --- a/declarationtva_view.php +++ b/declarationtva_view.php @@ -121,6 +121,11 @@ $ca3_definitions = $config->getCA3LineDefinitions(); // Helper function to format amounts with original values in brackets 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 if (strpos($line_label, '|ORIGINAL_') !== false) { $parts = explode('|', $line_label); @@ -130,11 +135,20 @@ function formatAmountWithOriginal($amount, $line_label, $amount_type = 'vat') { if (preg_match($pattern, $original_info, $matches)) { $original_amount = floatval($matches[1]); 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 @@ -199,7 +213,7 @@ $data = isset($ca3_data['16']) ? $ca3_data['16'] : array('line_label' => '', 'va print ''; print '16'; print 'Sous-total TVA due (08 + 09 + 9B)'; -print '' . price($data['vat_amount']) . ''; +print '' . formatAmount($data['vat_amount']) . ''; print ''; // Reset to normal layout for line 17 @@ -244,7 +258,7 @@ $data = isset($ca3_data['23']) ? $ca3_data['23'] : array('line_label' => '', 'va print ''; print '23'; print 'Sous-total TVA déductible (20 + 21 + 22)'; -print '' . price($data['vat_amount']) . ''; +print '' . formatAmount($data['vat_amount']) . ''; print ''; // Section D: Résultat @@ -272,7 +286,7 @@ foreach ($section_d_lines as $line) { print ''; print '' . $line . ''; print '' . $description . ''; - print '' . price($data['vat_amount']) . ''; + print '' . formatAmount($data['vat_amount']) . ''; print ''; }