diff --git a/core/class/declarationtva_pdf.class.php b/core/class/declarationtva_pdf.class.php index ba51c56..11c6d3c 100644 --- a/core/class/declarationtva_pdf.class.php +++ b/core/class/declarationtva_pdf.class.php @@ -2124,15 +2124,18 @@ class DeclarationTVA_PDF } } } else { - // 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) { + // Fallback to original logic if no TD line found + error_log("DeclarationTVA: No TD line found, using fallback logic"); + + // Use rounded amount for main balancing entry + $rounded_difference = round($difference); + if ($rounded_difference != 0) { + if ($rounded_difference < 0) { $balancing_entries[] = array( 'account_code' => '4456700', 'account_label' => $this->getAccountLabel('4456700'), 'entry_label' => $declaration->declaration_name, - 'debit' => $this->formatAmountReal(abs($difference)), + 'debit' => $this->formatAmount(abs($rounded_difference)), 'credit' => '' ); } else { @@ -2141,9 +2144,31 @@ class DeclarationTVA_PDF 'account_label' => $this->getAccountLabel('4455100'), 'entry_label' => $declaration->declaration_name, 'debit' => '', - 'credit' => $this->formatAmountReal($difference) + 'credit' => $this->formatAmount($rounded_difference) ); } + + // Add rounding entry for the difference between real and rounded + $rounding_diff = $difference - $rounded_difference; + if (abs($rounding_diff) >= 0.01) { + if ($rounding_diff < 0) { + $balancing_entries[] = array( + 'account_code' => '658000', + 'account_label' => $this->getAccountLabel('658000'), + 'entry_label' => $declaration->declaration_name, + 'debit' => $this->formatAmountReal(abs($rounding_diff)), + 'credit' => '' + ); + } else { + $balancing_entries[] = array( + 'account_code' => '758000', + 'account_label' => $this->getAccountLabel('758000'), + 'entry_label' => $declaration->declaration_name, + 'debit' => '', + 'credit' => $this->formatAmountReal($rounding_diff) + ); + } + } } }