From 673a2e4fdafcc5382a82d555dc3102c042fb457a Mon Sep 17 00:00:00 2001 From: Frank Cools Date: Tue, 7 Oct 2025 14:51:31 +0200 Subject: [PATCH] Remove ALL rounding from difference calculation - Completely removed rounding logic - Now uses real difference values only (formatAmountReal) - No more rounded amounts or complex rounding logic - Simple: real difference goes to 4455100/4456700 with real value - Should show 4455100 with 0.90 instead of 1.00 --- core/class/declarationtva_pdf.class.php | 88 ++----------------------- 1 file changed, 5 insertions(+), 83 deletions(-) diff --git a/core/class/declarationtva_pdf.class.php b/core/class/declarationtva_pdf.class.php index 32b5f19..b8119fa 100644 --- a/core/class/declarationtva_pdf.class.php +++ b/core/class/declarationtva_pdf.class.php @@ -2077,106 +2077,28 @@ class DeclarationTVA_PDF error_log("DeclarationTVA: Total difference: " . $difference); error_log("DeclarationTVA: Difference > 0: " . ($difference > 0 ? 'true' : 'false')); - // Calculate rounded difference for main entry - $rounded_difference = round($difference); - - // 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 + // Use real difference, no rounding + if (abs($difference) >= 0.01) { + error_log("DeclarationTVA: Creating balancing entry for real difference: " . $difference); if ($difference > 0) { // More credits than debits - need debit entry (4456700) - error_log("DeclarationTVA: Creating 4456700 debit entry for " . $rounded_difference); $balancing_entries[] = array( 'account_code' => '4456700', 'account_label' => $this->getAccountLabel('4456700'), 'entry_label' => $declaration->declaration_name, - 'debit' => $this->formatAmount($rounded_difference), + 'debit' => $this->formatAmountReal($difference), 'credit' => '' ); } else { // More debits than credits - need credit entry (4455100) - error_log("DeclarationTVA: Creating 4455100 credit entry for " . abs($rounded_difference)); $balancing_entries[] = array( 'account_code' => '4455100', 'account_label' => $this->getAccountLabel('4455100'), 'entry_label' => $declaration->declaration_name, 'debit' => '', - 'credit' => $this->formatAmount(abs($rounded_difference)) + 'credit' => $this->formatAmountReal(abs($difference)) ); } - - // Rounding entry for the difference between real and rounded - $rounding_diff = $difference - $rounded_difference; - error_log("DeclarationTVA: Rounding difference: " . $rounding_diff); - - if (abs($rounding_diff) >= 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(abs($rounding_diff)), - '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($rounding_diff)) - ); - } - } - } 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;