From f2b8cbfef0d396903e0a2d7d33e72c71e03c546f Mon Sep 17 00:00:00 2001 From: Frank Cools Date: Wed, 8 Oct 2025 22:07:52 +0200 Subject: [PATCH] Fix Bookkeeping instantiation - create new instance for each entry - Move Bookkeeping instantiation inside the loop - Create fresh instance for each accounting entry - Prevents field contamination between entries - Ensures each entry is processed independently --- core/class/declarationtva.class.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/core/class/declarationtva.class.php b/core/class/declarationtva.class.php index 7807548..d848de6 100644 --- a/core/class/declarationtva.class.php +++ b/core/class/declarationtva.class.php @@ -1225,11 +1225,12 @@ class DeclarationTVA // Use Dolibarr's bookkeeping class with correct field mapping require_once DOL_DOCUMENT_ROOT . '/accountancy/class/bookkeeping.class.php'; - $bookkeeping = new Bookkeeping($this->db); - foreach ($entries as $entry) { error_log("DEBUG: Creating accounting entry for account: " . $entry['account_code'] . ", debit: " . $entry['debit'] . ", credit: " . $entry['credit']); + // Create new instance for each entry + $bookkeeping = new Bookkeeping($this->db); + // Prepare amounts and determine debit/credit $debit_amount = !empty($entry['debit']) ? (float)$entry['debit'] : 0; $credit_amount = !empty($entry['credit']) ? (float)$entry['credit'] : 0;