From c638ce5233be3017adc5f54b4f7290c3dfbc0a2b Mon Sep 17 00:00:00 2001 From: Frank Cools Date: Thu, 2 Oct 2025 22:32:28 +0200 Subject: [PATCH] Add line 16 subtotal calculation Added: - Line 16: Subtotal of lines 08, 09, 9B (for user reference) - calculateLine16() method that sums VAT amounts from lines 08, 09, 9B - Line 16 definition in CA-3 line definitions - Line 16 will appear automatically in the view page - This provides a subtotal for the user before line 17 (manual entry) --- core/class/declarationtva.class.php | 37 ++++++++++++++++++++++ core/class/declarationtva_config.class.php | 7 ++++ 2 files changed, 44 insertions(+) diff --git a/core/class/declarationtva.class.php b/core/class/declarationtva.class.php index a3da5f4..ebe2513 100644 --- a/core/class/declarationtva.class.php +++ b/core/class/declarationtva.class.php @@ -281,6 +281,9 @@ class DeclarationTVA // Debug totals error_log("DeclarationTVA: Total VAT collected: $total_vat_collected, Total VAT deductible: $total_vat_deductible"); + // Calculate line 16: Subtotal of lines 08, 09, 9B (for user reference) + $this->calculateLine16($declaration_id); + // Calculate D-section result lines (25, 26, 28, 29) $this->calculateDSectionLines($declaration_id, $total_vat_collected, $total_vat_deductible); @@ -295,6 +298,40 @@ class DeclarationTVA return true; } + /** + * Calculate line 16: Subtotal of lines 08, 09, 9B (for user reference) + * + * @param int $declaration_id Declaration ID + * @return bool Success + */ + private function calculateLine16($declaration_id) + { + // Get the amounts from lines 08, 09, 9B + $sql = "SELECT ca3_line, vat_amount FROM " . MAIN_DB_PREFIX . "declarationtva_ca3_lines + WHERE declaration_id = " . (int)$declaration_id . " + AND ca3_line IN ('08', '09', '9B')"; + + $result = $this->db->query($sql); + $line_16_total = 0; + $account_labels = array(); + + if ($result) { + while ($obj = $this->db->fetch_object($result)) { + $line_16_total += $obj->vat_amount; + $account_labels[] = "Line " . $obj->ca3_line . ": " . number_format($obj->vat_amount, 2); + } + } + + // Create line 16 record + $this->createCA3Line($declaration_id, '16', 'Subtotal: ' . implode(', ', $account_labels), array( + 'base_amount' => 0, + 'vat_amount' => $line_16_total, + 'total_amount' => $line_16_total + )); + + return true; + } + /** * Calculate D-section result lines (25, 26, 28, 29) * diff --git a/core/class/declarationtva_config.class.php b/core/class/declarationtva_config.class.php index b451d8a..9a9e398 100644 --- a/core/class/declarationtva_config.class.php +++ b/core/class/declarationtva_config.class.php @@ -291,6 +291,13 @@ class DeclarationTVA_Config 'description' => 'Base HT and VAT amounts due at reduced rates (5,5% and 2,1%)', 'pcg_accounts' => 'Base: 7xxxx (Sales); VAT: 44573x (5,5%) / 44574x (2,1%)' ), + '16' => array( + 'label' => 'Sous-total TVA due (08 + 09 + 9B)', + 'type' => 'calculated', + 'section' => 'B', + 'description' => 'Subtotal of VAT due (calculated from lines 08, 09, 9B)', + 'pcg_accounts' => 'Calculated automatically' + ), '17' => array( 'label' => 'TVA due au titre des acquisitions intracommunautaires (autoliquidation)', 'type' => 'vat',