diff --git a/core/class/declarationtva_pdf.class.php b/core/class/declarationtva_pdf.class.php index 1961208..6ebd070 100644 --- a/core/class/declarationtva_pdf.class.php +++ b/core/class/declarationtva_pdf.class.php @@ -1073,15 +1073,33 @@ class DeclarationTVA_PDF return '0,00'; } + $calculated_amount = null; + $mapped_amount = null; + // Search through the array for the matching ca3_line foreach ($ca3_data as $line_data) { if (isset($line_data['ca3_line']) && $line_data['ca3_line'] == $ca3_line) { $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); } /**