From 39a2414d633de58d41ae384e336f454f75501273 Mon Sep 17 00:00:00 2001 From: Frank Cools Date: Thu, 2 Oct 2025 22:35:58 +0200 Subject: [PATCH] Add line 23 subtotal for Section C MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Added: - Line 23: Subtotal of lines 20, 21, 22 (for user reference) - calculateLine23() method that sums VAT amounts from lines 20, 21, 22 - Line 23 display in Section C between lines 22 and Section D - Line 23 shows as 'Sous-total TVA déductible (20 + 21 + 22)' with bold formatting - Provides subtotal for Section C just like line 16 for Section B --- core/class/declarationtva.class.php | 37 +++++++++++++++++++++++++++++ declarationtva_view.php | 8 +++++++ 2 files changed, 45 insertions(+) diff --git a/core/class/declarationtva.class.php b/core/class/declarationtva.class.php index ebe2513..0e3983e 100644 --- a/core/class/declarationtva.class.php +++ b/core/class/declarationtva.class.php @@ -284,6 +284,9 @@ class DeclarationTVA // Calculate line 16: Subtotal of lines 08, 09, 9B (for user reference) $this->calculateLine16($declaration_id); + // Calculate line 23: Subtotal of lines 20, 21, 22 (for user reference) + $this->calculateLine23($declaration_id); + // Calculate D-section result lines (25, 26, 28, 29) $this->calculateDSectionLines($declaration_id, $total_vat_collected, $total_vat_deductible); @@ -332,6 +335,40 @@ class DeclarationTVA return true; } + /** + * Calculate line 23: Subtotal of lines 20, 21, 22 (for user reference) + * + * @param int $declaration_id Declaration ID + * @return bool Success + */ + private function calculateLine23($declaration_id) + { + // Get the amounts from lines 20, 21, 22 + $sql = "SELECT ca3_line, vat_amount FROM " . MAIN_DB_PREFIX . "declarationtva_ca3_lines + WHERE declaration_id = " . (int)$declaration_id . " + AND ca3_line IN ('20', '21', '22')"; + + $result = $this->db->query($sql); + $line_23_total = 0; + $account_labels = array(); + + if ($result) { + while ($obj = $this->db->fetch_object($result)) { + $line_23_total += $obj->vat_amount; + $account_labels[] = "Line " . $obj->ca3_line . ": " . number_format($obj->vat_amount, 2); + } + } + + // Create line 23 record + $this->createCA3Line($declaration_id, '23', 'Subtotal: ' . implode(', ', $account_labels), array( + 'base_amount' => 0, + 'vat_amount' => $line_23_total, + 'total_amount' => $line_23_total + )); + + return true; + } + /** * Calculate D-section result lines (25, 26, 28, 29) * diff --git a/declarationtva_view.php b/declarationtva_view.php index 9e0b538..0a92a83 100644 --- a/declarationtva_view.php +++ b/declarationtva_view.php @@ -243,6 +243,14 @@ foreach ($section_c_lines as $line) { print ''; } +// Line 23: Subtotal (calculated automatically) +$data = isset($ca3_data['23']) ? $ca3_data['23'] : array('line_label' => '', 'vat_amount' => 0); +print ''; +print '23'; +print 'Sous-total TVA déductible (20 + 21 + 22)'; +print '' . price($data['vat_amount']) . ''; +print ''; + // Section D: Résultat print ''; print 'D. ' . $langs->trans("CA3SectionD") . '';