Display original amounts in brackets next to rounded amounts
Fixed: - Store original amounts in line_label with special format - Parse original amounts in view page helper function - Display original amounts in brackets: 124 (123.67) - Handle both base and VAT amounts separately - Original amounts now visible in amount columns - Clear transparency for rounding decisions
This commit is contained in:
parent
b54a54b38c
commit
b3f2ac492f
@ -553,19 +553,28 @@ class DeclarationTVA
|
|||||||
$rounded_vat = round($amounts['vat_amount']);
|
$rounded_vat = round($amounts['vat_amount']);
|
||||||
$rounded_total = round($amounts['total_amount']);
|
$rounded_total = round($amounts['total_amount']);
|
||||||
|
|
||||||
// Create formatted label with original amounts in brackets if different
|
// Store original amounts in the line_label for now (we'll need to modify the database schema later)
|
||||||
$formatted_label = $line_label;
|
$original_base = $amounts['base_amount'];
|
||||||
if ($rounded_vat != $amounts['vat_amount']) {
|
$original_vat = $amounts['vat_amount'];
|
||||||
$formatted_label .= ' [Original: ' . number_format($amounts['vat_amount'], 2) . ']';
|
$original_total = $amounts['total_amount'];
|
||||||
}
|
|
||||||
|
|
||||||
$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($formatted_label) . "', " . $rounded_base . ",
|
'" . $this->db->escape($line_label) . "', " . $rounded_base . ",
|
||||||
" . $rounded_vat . ", " . $rounded_total . ", NOW())";
|
" . $rounded_vat . ", " . $rounded_total . ", NOW())";
|
||||||
|
|
||||||
$result = $this->db->query($sql);
|
$result = $this->db->query($sql);
|
||||||
|
|
||||||
|
// Store original amounts in a separate way - we'll use the line_label to store them temporarily
|
||||||
|
if ($result && ($rounded_vat != $original_vat || $rounded_base != $original_base)) {
|
||||||
|
$original_info = "ORIGINAL_BASE:" . $original_base . "_ORIGINAL_VAT:" . $original_vat . "_ORIGINAL_TOTAL:" . $original_total;
|
||||||
|
$update_sql = "UPDATE " . MAIN_DB_PREFIX . "declarationtva_ca3_lines
|
||||||
|
SET line_label = CONCAT(line_label, '|', '" . $this->db->escape($original_info) . "')
|
||||||
|
WHERE declaration_id = " . $declaration_id . " AND ca3_line = '" . $this->db->escape($ca3_line) . "'";
|
||||||
|
$this->db->query($update_sql);
|
||||||
|
}
|
||||||
|
|
||||||
return $result !== false;
|
return $result !== false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -119,6 +119,24 @@ $ca3_lines = $declarationtva->getCA3Lines($id);
|
|||||||
// Get CA-3 line definitions for proper descriptions
|
// Get CA-3 line definitions for proper descriptions
|
||||||
$ca3_definitions = $config->getCA3LineDefinitions();
|
$ca3_definitions = $config->getCA3LineDefinitions();
|
||||||
|
|
||||||
|
// Helper function to format amounts with original values in brackets
|
||||||
|
function formatAmountWithOriginal($amount, $line_label, $amount_type = 'vat') {
|
||||||
|
// Parse original amounts from line_label if they exist
|
||||||
|
if (strpos($line_label, '|ORIGINAL_') !== false) {
|
||||||
|
$parts = explode('|', $line_label);
|
||||||
|
$original_info = $parts[1] ?? '';
|
||||||
|
|
||||||
|
$pattern = $amount_type == 'base' ? '/ORIGINAL_BASE:([0-9.]+)/' : '/ORIGINAL_VAT:([0-9.]+)/';
|
||||||
|
if (preg_match($pattern, $original_info, $matches)) {
|
||||||
|
$original_amount = floatval($matches[1]);
|
||||||
|
if ($original_amount != $amount) {
|
||||||
|
return price($amount) . ' (' . number_format($original_amount, 2) . ')';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return price($amount);
|
||||||
|
}
|
||||||
|
|
||||||
// Create a lookup array for quick access
|
// Create a lookup array for quick access
|
||||||
$ca3_data = array();
|
$ca3_data = array();
|
||||||
foreach ($ca3_lines as $line) {
|
foreach ($ca3_lines as $line) {
|
||||||
@ -143,7 +161,7 @@ foreach ($section_a_lines as $line) {
|
|||||||
print '<tr>';
|
print '<tr>';
|
||||||
print '<td>' . $line . '</td>';
|
print '<td>' . $line . '</td>';
|
||||||
print '<td colspan="2">' . $description . '</td>';
|
print '<td colspan="2">' . $description . '</td>';
|
||||||
print '<td class="right">' . price($data['vat_amount']) . '</td>';
|
print '<td class="right">' . formatAmountWithOriginal($data['vat_amount'], $data['line_label']) . '</td>';
|
||||||
print '</tr>';
|
print '</tr>';
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -171,8 +189,8 @@ foreach ($base_vat_lines as $line) {
|
|||||||
print '<tr>';
|
print '<tr>';
|
||||||
print '<td>' . $line . '</td>';
|
print '<td>' . $line . '</td>';
|
||||||
print '<td>' . $description . '</td>';
|
print '<td>' . $description . '</td>';
|
||||||
print '<td class="right">' . price($data['base_amount']) . '</td>';
|
print '<td class="right">' . formatAmountWithOriginal($data['base_amount'], $data['line_label'], 'base') . '</td>';
|
||||||
print '<td class="right">' . price($data['vat_amount']) . '</td>';
|
print '<td class="right">' . formatAmountWithOriginal($data['vat_amount'], $data['line_label']) . '</td>';
|
||||||
print '</tr>';
|
print '</tr>';
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -217,7 +235,7 @@ foreach ($section_c_lines as $line) {
|
|||||||
print '<tr>';
|
print '<tr>';
|
||||||
print '<td>' . $line . '</td>';
|
print '<td>' . $line . '</td>';
|
||||||
print '<td colspan="2">' . $description . '</td>';
|
print '<td colspan="2">' . $description . '</td>';
|
||||||
print '<td class="right">' . price($data['vat_amount']) . '</td>';
|
print '<td class="right">' . formatAmountWithOriginal($data['vat_amount'], $data['line_label']) . '</td>';
|
||||||
print '</tr>';
|
print '</tr>';
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -254,7 +272,7 @@ foreach ($section_d_lines as $line) {
|
|||||||
print '<tr>';
|
print '<tr>';
|
||||||
print '<td>' . $line . '</td>';
|
print '<td>' . $line . '</td>';
|
||||||
print '<td colspan="2">' . $description . '</td>';
|
print '<td colspan="2">' . $description . '</td>';
|
||||||
print '<td class="right">' . price($data['vat_amount']) . '</td>';
|
print '<td class="right">' . formatAmountWithOriginal($data['vat_amount'], $data['line_label']) . '</td>';
|
||||||
print '</tr>';
|
print '</tr>';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user