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
This commit is contained in:
Frank Cools 2025-10-02 21:24:24 +02:00
parent bbecae15f0
commit 28b21ea4d3

View File

@ -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,