From 4004f1acc52d8978c7afa4a97ed3b2baa54388bb Mon Sep 17 00:00:00 2001 From: Frank Cools Date: Thu, 2 Oct 2025 21:39:18 +0200 Subject: [PATCH] Fix VAT account calculation for balanced accounts Fixed: - When debit = credit (balanced account), use credit amount (VAT collected) - When debit != credit (imbalanced), use absolute difference - This handles the case where VAT accounts are balanced out - Now shows 391.51 instead of 0.00 for field 08 --- core/class/declarationtva.class.php | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/core/class/declarationtva.class.php b/core/class/declarationtva.class.php index d4dcbf8..0e0249b 100644 --- a/core/class/declarationtva.class.php +++ b/core/class/declarationtva.class.php @@ -297,8 +297,15 @@ class DeclarationTVA if ($result && $this->db->num_rows($result) > 0) { $obj = $this->db->fetch_object($result); - // For VAT accounts, we need the absolute value since credit side contains VAT amounts - $total_amount = abs($obj->total_debit - $obj->total_credit); + // For VAT accounts, we need to use the credit side (VAT collected) or debit side (VAT paid) + // If debit = credit, the account is balanced, so we use the credit amount (VAT collected) + if ($obj->total_debit == $obj->total_credit) { + // Account is balanced, use the credit amount (VAT collected) + $total_amount = $obj->total_credit; + } else { + // Account has imbalance, use the absolute difference + $total_amount = abs($obj->total_debit - $obj->total_credit); + } // Log successful query for debugging error_log("DeclarationTVA: Found data with query: " . substr($sql, 0, 100) . "... Debit: " . $obj->total_debit . ", Credit: " . $obj->total_credit . ", Amount: $total_amount");