From c00894db2d1d410dd17700df4b86733cc6d88108 Mon Sep 17 00:00:00 2001 From: Frank Cools Date: Tue, 7 Oct 2025 14:50:59 +0200 Subject: [PATCH] Fix small difference handling for proper rounding - Added special handling for differences < 1.0 (like -0.90) - Small differences now create rounding-only entries (758000/658000) - No main balancing entry (4455100/4456700) for small differences - Should show 758000 with 0.90 instead of 4455100 with 1.00 --- core/class/declarationtva_pdf.class.php | 26 ++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/core/class/declarationtva_pdf.class.php b/core/class/declarationtva_pdf.class.php index 1d3840e..32b5f19 100644 --- a/core/class/declarationtva_pdf.class.php +++ b/core/class/declarationtva_pdf.class.php @@ -2080,7 +2080,31 @@ class DeclarationTVA_PDF // Calculate rounded difference for main entry $rounded_difference = round($difference); - if ($rounded_difference != 0) { + // For very small differences, don't create main balancing entry + if (abs($difference) < 1.0) { + error_log("DeclarationTVA: Small difference detected: " . $difference . ", creating rounding-only entry"); + if (abs($difference) >= 0.01) { + if ($difference > 0) { + // Credit difference - rounding goes to 658000 debit + $balancing_entries[] = array( + 'account_code' => '658000', + 'account_label' => $this->getAccountLabel('658000'), + 'entry_label' => $declaration->declaration_name, + 'debit' => $this->formatAmountReal($difference), + 'credit' => '' + ); + } else { + // Debit difference - rounding goes to 758000 credit + $balancing_entries[] = array( + 'account_code' => '758000', + 'account_label' => $this->getAccountLabel('758000'), + 'entry_label' => $declaration->declaration_name, + 'debit' => '', + 'credit' => $this->formatAmountReal(abs($difference)) + ); + } + } + } elseif ($rounded_difference != 0) { // Main balancing entry with rounded amount if ($difference > 0) { // More credits than debits - need debit entry (4456700)