From 28b21ea4d33808a7738888c30421fe97ce7ea6bf Mon Sep 17 00:00:00 2001 From: Frank Cools Date: Thu, 2 Oct 2025 21:24:24 +0200 Subject: [PATCH] Fix negative VAT amounts by using absolute value Fixed: - Use abs() for VAT account calculations - VAT accounts typically have credit side amounts - Now shows positive values: -1957.57 -> 1957.57 - Enhanced logging to show debit/credit breakdown --- core/class/declarationtva.class.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/core/class/declarationtva.class.php b/core/class/declarationtva.class.php index 41d96dc..e33f887 100644 --- a/core/class/declarationtva.class.php +++ b/core/class/declarationtva.class.php @@ -287,10 +287,12 @@ class DeclarationTVA $result = $this->db->query($sql); if ($result && $this->db->num_rows($result) > 0) { $obj = $this->db->fetch_object($result); - $total_amount = $obj->total_debit - $obj->total_credit; + + // For VAT accounts, we need the absolute value since credit side contains VAT amounts + $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) . "... Amount: $total_amount"); + error_log("DeclarationTVA: Found data with query: " . substr($sql, 0, 100) . "... Debit: " . $obj->total_debit . ", Credit: " . $obj->total_credit . ", Amount: $total_amount"); return array( 'base_amount' => $total_amount,