Fix balancing logic to create only one main entry

- Removed duplicate 4455100 entry creation
- Now creates either 4455100 (credit) OR 4456700 (debit), not both
- Added debug logging for total debits/credits to trace calculation
- Should eliminate the unwanted 4455100 line in journal table
This commit is contained in:
Frank Cools 2025-10-07 14:07:29 +02:00
parent 240360a393
commit 34b9864a4e

View File

@ -2072,6 +2072,8 @@ class DeclarationTVA_PDF
$balancing_entries = array();
// Debug logging
error_log("DeclarationTVA: Total debits: " . $total_debits);
error_log("DeclarationTVA: Total credits: " . $total_credits);
error_log("DeclarationTVA: Total difference: " . $difference);
// Calculate rounded difference for main entry
@ -2079,16 +2081,7 @@ class DeclarationTVA_PDF
if ($rounded_difference != 0) {
// Main balancing entry with rounded amount
if ($difference < 0) {
// More credits than debits - need debit entry (4456700)
$balancing_entries[] = array(
'account_code' => '4456700',
'account_label' => $this->getAccountLabel('4456700'),
'entry_label' => $declaration->declaration_name,
'debit' => $this->formatAmount(abs($rounded_difference)),
'credit' => ''
);
} else {
if ($difference > 0) {
// More debits than credits - need credit entry (4455100)
$balancing_entries[] = array(
'account_code' => '4455100',
@ -2097,6 +2090,15 @@ class DeclarationTVA_PDF
'debit' => '',
'credit' => $this->formatAmount($rounded_difference)
);
} else {
// More credits than debits - need debit entry (4456700)
$balancing_entries[] = array(
'account_code' => '4456700',
'account_label' => $this->getAccountLabel('4456700'),
'entry_label' => $declaration->declaration_name,
'debit' => $this->formatAmount(abs($rounded_difference)),
'credit' => ''
);
}
// Rounding entry for the difference between real and rounded