From 23aa6cccb831b99d648c48eb013aefb109ec881c Mon Sep 17 00:00:00 2001 From: Frank Cools Date: Tue, 7 Oct 2025 14:48:42 +0200 Subject: [PATCH] Fix rounding logic for small differences - Added handling for cases where rounded difference is 0 but real difference is not 0 - Now creates rounding-only entry when difference is small (like -0.90) - Should show 758000 with 0.90 instead of 1.00 - Handles edge cases where difference rounds to 0 but real value is significant --- core/class/declarationtva_pdf.class.php | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/core/class/declarationtva_pdf.class.php b/core/class/declarationtva_pdf.class.php index 8c5a557..1d3840e 100644 --- a/core/class/declarationtva_pdf.class.php +++ b/core/class/declarationtva_pdf.class.php @@ -2129,6 +2129,30 @@ class DeclarationTVA_PDF ); } } + } else { + // If rounded difference is 0, but real difference is not 0, create rounding entry only + if (abs($difference) >= 0.01) { + error_log("DeclarationTVA: Creating rounding-only entry for " . $difference); + 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)) + ); + } + } } return $balancing_entries;