Fix PDF path lookup to use correct documents directory

This commit is contained in:
Frank Cools 2025-10-08 14:51:05 +02:00
parent 1cb9837ae7
commit c1d1f122fa

View File

@ -1273,16 +1273,24 @@ class DeclarationTVA
return false; return false;
} }
// Check if PDF file exists in the VAT declarations directory // Check if PDF file exists in the VAT declarations documents directory
$vat_declarations_dir = DOL_DATA_ROOT . '/declarationtva/validated/'; $vat_declarations_dir = DOL_DATA_ROOT . '/documents/declarationtva/';
$year_dir = $vat_declarations_dir . date('Y') . '/';
$month_dir = $year_dir . date('m') . '/';
// Look for PDF files with the declaration number // Look for PDF files with the declaration number in the current month directory
$pattern = $vat_declarations_dir . 'CA3_' . $obj->declaration_number . '_*.pdf'; $pattern = $month_dir . 'CA3_' . $obj->declaration_number . '_*.pdf';
$files = glob($pattern); $files = glob($pattern);
// If no files found with the exact pattern, try a more flexible search // If no files found with the exact pattern, try a more flexible search
if (empty($files)) { if (empty($files)) {
$pattern = $vat_declarations_dir . 'CA3_*' . $obj->declaration_number . '*.pdf'; $pattern = $month_dir . 'CA3_*' . $obj->declaration_number . '*.pdf';
$files = glob($pattern);
}
// If still no files found, search in the year directory
if (empty($files)) {
$pattern = $year_dir . 'CA3_' . $obj->declaration_number . '_*.pdf';
$files = glob($pattern); $files = glob($pattern);
} }
@ -1313,16 +1321,24 @@ class DeclarationTVA
return false; return false;
} }
// Check if PDF file exists in the VAT declarations directory // Check if PDF file exists in the VAT declarations documents directory
$vat_declarations_dir = DOL_DATA_ROOT . '/declarationtva/validated/'; $vat_declarations_dir = DOL_DATA_ROOT . '/documents/declarationtva/';
$year_dir = $vat_declarations_dir . date('Y') . '/';
$month_dir = $year_dir . date('m') . '/';
// Look for PDF files with the declaration number // Look for PDF files with the declaration number in the current month directory
$pattern = $vat_declarations_dir . 'CA3_' . $obj->declaration_number . '_*.pdf'; $pattern = $month_dir . 'CA3_' . $obj->declaration_number . '_*.pdf';
$files = glob($pattern); $files = glob($pattern);
// If no files found with the exact pattern, try a more flexible search // If no files found with the exact pattern, try a more flexible search
if (empty($files)) { if (empty($files)) {
$pattern = $vat_declarations_dir . 'CA3_*' . $obj->declaration_number . '*.pdf'; $pattern = $month_dir . 'CA3_*' . $obj->declaration_number . '*.pdf';
$files = glob($pattern);
}
// If still no files found, search in the year directory
if (empty($files)) {
$pattern = $year_dir . 'CA3_' . $obj->declaration_number . '_*.pdf';
$files = glob($pattern); $files = glob($pattern);
} }