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
This commit is contained in:
parent
21ad4110e7
commit
4004f1acc5
@ -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
|
||||
// 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");
|
||||
|
||||
Loading…
Reference in New Issue
Block a user