Fix getCA3LineAmount to prioritize calculated entries over 'No accounts mapped'

- Updated getCA3LineAmount method to handle duplicate CA-3 line entries
- Prioritizes 'Calculated' entries over 'No accounts mapped' entries
- This fixes lines 28 and 29 not displaying in PDF (they were showing 0 instead of calculated values)
- The method now correctly extracts calculated values: D28=357, D29=0
This commit is contained in:
Frank Cools 2025-10-03 15:12:10 +02:00
parent 2ee7e67a43
commit c896cfab7f

View File

@ -1073,15 +1073,33 @@ class DeclarationTVA_PDF
return '0,00'; return '0,00';
} }
$calculated_amount = null;
$mapped_amount = null;
// Search through the array for the matching ca3_line // Search through the array for the matching ca3_line
foreach ($ca3_data as $line_data) { foreach ($ca3_data as $line_data) {
if (isset($line_data['ca3_line']) && $line_data['ca3_line'] == $ca3_line) { if (isset($line_data['ca3_line']) && $line_data['ca3_line'] == $ca3_line) {
$amount = isset($line_data[$amount_type]) ? $line_data[$amount_type] : 0; $amount = isset($line_data[$amount_type]) ? $line_data[$amount_type] : 0;
return $this->formatAmount($amount);
// Prioritize calculated entries over "No accounts mapped" entries
if (isset($line_data['line_label']) && strpos($line_data['line_label'], 'Calculated') !== false) {
$calculated_amount = $amount;
} elseif (isset($line_data['line_label']) && strpos($line_data['line_label'], 'No accounts mapped') === false) {
$mapped_amount = $amount;
} else {
// This is a "No accounts mapped" entry, only use if no other option
if ($calculated_amount === null && $mapped_amount === null) {
$mapped_amount = $amount;
}
}
} }
} }
return '0,00'; // Return calculated amount if available, otherwise mapped amount, otherwise 0
$final_amount = $calculated_amount !== null ? $calculated_amount :
($mapped_amount !== null ? $mapped_amount : 0);
return $this->formatAmount($final_amount);
} }
/** /**