From ea11f50de2314109f97dbf891ef897987766549b Mon Sep 17 00:00:00 2001 From: Frank Cools Date: Thu, 30 Oct 2025 16:51:46 +0100 Subject: [PATCH] fix: populate line 22 from prior credit and correct query - Create line 22 from carry-forward before computing line 23 - Use numero_compte and entity filter to read 44567 balance - Ensures prior period VAT credit appears in current declaration --- core/class/declarationtva.class.php | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/core/class/declarationtva.class.php b/core/class/declarationtva.class.php index dcd39df..c70dd2a 100644 --- a/core/class/declarationtva.class.php +++ b/core/class/declarationtva.class.php @@ -277,7 +277,17 @@ class DeclarationTVA } } - + // Inject carry-forward into line 22 BEFORE computing line 23 + // Line 22 should represent the carry-forward credit from previous periods + $carry_forward = $this->getVATCreditCarryForward($period['start_date']); + // Remove existing line 22 (created above) and recreate with carry-forward amount + $this->db->query("DELETE FROM " . MAIN_DB_PREFIX . "declarationtva_ca3_lines WHERE declaration_id = " . (int)$declaration_id . " AND ca3_line = '22'"); + $this->createCA3Line($declaration_id, '22', 'Report du crédit apparaissant ligne 27 de la précédente déclaration', array( + 'base_amount' => 0, + 'vat_amount' => $carry_forward, + 'total_amount' => $carry_forward + )); + // Calculate line 16: Subtotal of lines 08, 09, 9B (for user reference) $this->calculateLine16($declaration_id); @@ -905,10 +915,12 @@ class DeclarationTVA $vat_to_receive_account = $journal_config['vat_to_receive']; // Check VAT credit account balance at declaration start date + // Use bookkeeping table columns: numero_compte, debit, credit, doc_date, entity $sql = "SELECT SUM(debit - credit) as balance FROM " . MAIN_DB_PREFIX . "accounting_bookkeeping - WHERE account_number = '" . $this->db->escape($vat_to_receive_account) . "' - AND doc_date < '" . $declaration_start_date . "'"; + WHERE numero_compte = '" . $this->db->escape($vat_to_receive_account) . "' + AND doc_date < '" . $this->db->escape($declaration_start_date) . "' + AND entity = " . $this->entity; $result = $this->db->query($sql); if ($result && $this->db->num_rows($result) > 0) {