diff --git a/core/class/declarationtva.class.php b/core/class/declarationtva.class.php index 3548678..66c5d2d 100644 --- a/core/class/declarationtva.class.php +++ b/core/class/declarationtva.class.php @@ -335,6 +335,26 @@ class DeclarationTVA return true; } + /** + * Round VAT amount to whole number and format with original amount in brackets + * + * @param float $amount Original amount + * @return array Array with 'rounded' and 'formatted' values + */ + private function roundVATAmount($amount) + { + $rounded = round($amount); + $formatted = $rounded; + if ($rounded != $amount) { + $formatted = $rounded . ' (' . number_format($amount, 2) . ')'; + } + + return array( + 'rounded' => $rounded, + 'formatted' => $formatted + ); + } + /** * Calculate line 23: Subtotal of lines 20, 21, 22 (for user reference) * @@ -528,11 +548,22 @@ class DeclarationTVA */ public function createCA3Line($declaration_id, $ca3_line, $line_label, $amounts) { + // Round amounts to whole numbers + $rounded_base = round($amounts['base_amount']); + $rounded_vat = round($amounts['vat_amount']); + $rounded_total = round($amounts['total_amount']); + + // Create formatted label with original amounts in brackets if different + $formatted_label = $line_label; + if ($rounded_vat != $amounts['vat_amount']) { + $formatted_label .= ' [Original: ' . number_format($amounts['vat_amount'], 2) . ']'; + } + $sql = "INSERT INTO " . MAIN_DB_PREFIX . "declarationtva_ca3_lines (declaration_id, ca3_line, line_label, base_amount, vat_amount, total_amount, created_date) VALUES (" . $declaration_id . ", '" . $this->db->escape($ca3_line) . "', - '" . $this->db->escape($line_label) . "', " . $amounts['base_amount'] . ", - " . $amounts['vat_amount'] . ", " . $amounts['total_amount'] . ", NOW())"; + '" . $this->db->escape($formatted_label) . "', " . $rounded_base . ", + " . $rounded_vat . ", " . $rounded_total . ", NOW())"; $result = $this->db->query($sql); return $result !== false; @@ -550,11 +581,17 @@ class DeclarationTVA */ public function updateDeclarationTotals($declaration_id, $total_vat_collected, $total_vat_deductible, $net_vat_due, $vat_credit) { + // Round totals to whole numbers + $rounded_collected = round($total_vat_collected); + $rounded_deductible = round($total_vat_deductible); + $rounded_net_due = round($net_vat_due); + $rounded_credit = round($vat_credit); + $sql = "UPDATE " . MAIN_DB_PREFIX . "declarationtva_declarations - SET total_vat_collected = " . $total_vat_collected . ", - total_vat_deductible = " . $total_vat_deductible . ", - net_vat_due = " . $net_vat_due . ", - vat_credit = " . $vat_credit . " + SET total_vat_collected = " . $rounded_collected . ", + total_vat_deductible = " . $rounded_deductible . ", + net_vat_due = " . $rounded_net_due . ", + vat_credit = " . $rounded_credit . " WHERE rowid = " . $declaration_id; $result = $this->db->query($sql);