Add VAT amount rounding to whole numbers

Added:
- Round all VAT amounts to whole numbers using round() function
- Store original amounts in line_label with brackets [Original: X.XX]
- Round totals in updateDeclarationTotals() method
- Round amounts in createCA3Line() method
- This ensures VAT declarations only show whole numbers as required
- Original amounts are visible for transparency
This commit is contained in:
Frank Cools 2025-10-02 22:51:25 +02:00
parent 03e6bafa53
commit b54a54b38c

View File

@ -335,6 +335,26 @@ class DeclarationTVA
return true; 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) * 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) 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 $sql = "INSERT INTO " . MAIN_DB_PREFIX . "declarationtva_ca3_lines
(declaration_id, ca3_line, line_label, base_amount, vat_amount, total_amount, created_date) (declaration_id, ca3_line, line_label, base_amount, vat_amount, total_amount, created_date)
VALUES (" . $declaration_id . ", '" . $this->db->escape($ca3_line) . "', VALUES (" . $declaration_id . ", '" . $this->db->escape($ca3_line) . "',
'" . $this->db->escape($line_label) . "', " . $amounts['base_amount'] . ", '" . $this->db->escape($formatted_label) . "', " . $rounded_base . ",
" . $amounts['vat_amount'] . ", " . $amounts['total_amount'] . ", NOW())"; " . $rounded_vat . ", " . $rounded_total . ", NOW())";
$result = $this->db->query($sql); $result = $this->db->query($sql);
return $result !== false; 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) 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 $sql = "UPDATE " . MAIN_DB_PREFIX . "declarationtva_declarations
SET total_vat_collected = " . $total_vat_collected . ", SET total_vat_collected = " . $rounded_collected . ",
total_vat_deductible = " . $total_vat_deductible . ", total_vat_deductible = " . $rounded_deductible . ",
net_vat_due = " . $net_vat_due . ", net_vat_due = " . $rounded_net_due . ",
vat_credit = " . $vat_credit . " vat_credit = " . $rounded_credit . "
WHERE rowid = " . $declaration_id; WHERE rowid = " . $declaration_id;
$result = $this->db->query($sql); $result = $this->db->query($sql);