From ff314d043e42ad9811268aa725c622db8eff5354 Mon Sep 17 00:00:00 2001 From: Frank Cools Date: Tue, 7 Oct 2025 12:35:19 +0200 Subject: [PATCH] Fix rounding calculation to use real values instead of rounded - Added debugging to TD line query to see why VAT amount is 0 - Fixed fallback logic to use formatAmountReal() instead of formatAmount() - When TD line has 0 VAT amount, now uses real difference (0.90) instead of rounded (1.00) - Added logging to track TD line query and results - Should now show 0.90 instead of 1.00 in rounding entry --- core/class/declarationtva_pdf.class.php | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/core/class/declarationtva_pdf.class.php b/core/class/declarationtva_pdf.class.php index c06f171..ba51c56 100644 --- a/core/class/declarationtva_pdf.class.php +++ b/core/class/declarationtva_pdf.class.php @@ -2124,15 +2124,15 @@ class DeclarationTVA_PDF } } } else { - // Fallback to original logic if no TD line found - $rounded_difference = round($difference); - if ($rounded_difference != 0) { - if ($rounded_difference < 0) { + // Fallback to original logic if no TD line found - use real value, not rounded + error_log("DeclarationTVA: No TD line found, using fallback logic with real value"); + if (abs($difference) >= 0.01) { + if ($difference < 0) { $balancing_entries[] = array( 'account_code' => '4456700', 'account_label' => $this->getAccountLabel('4456700'), 'entry_label' => $declaration->declaration_name, - 'debit' => $this->formatAmount(abs($rounded_difference)), + 'debit' => $this->formatAmountReal(abs($difference)), 'credit' => '' ); } else { @@ -2141,7 +2141,7 @@ class DeclarationTVA_PDF 'account_label' => $this->getAccountLabel('4455100'), 'entry_label' => $declaration->declaration_name, 'debit' => '', - 'credit' => $this->formatAmount($rounded_difference) + 'credit' => $this->formatAmountReal($difference) ); } } @@ -2163,12 +2163,16 @@ class DeclarationTVA_PDF AND ca3_line = 'TD' AND entity = " . $this->entity; + error_log("DeclarationTVA: TD line query: " . $sql); + $result = $this->db->query($sql); if ($result && $this->db->num_rows($result) > 0) { $obj = $this->db->fetch_object($result); + error_log("DeclarationTVA: TD line found with vat_amount: " . $obj->vat_amount); return (float)$obj->vat_amount; } + error_log("DeclarationTVA: TD line not found or has no rows"); return 0; }