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; }