From 9aeb09cc5cb6bd11292a8363d50acab1390a1bc3 Mon Sep 17 00:00:00 2001 From: Frank Cools Date: Wed, 8 Oct 2025 14:56:38 +0200 Subject: [PATCH] Fix PDF search to use declaration ID instead of declaration number --- core/class/declarationtva.class.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/core/class/declarationtva.class.php b/core/class/declarationtva.class.php index 4d5aea5..c4ed6f5 100644 --- a/core/class/declarationtva.class.php +++ b/core/class/declarationtva.class.php @@ -1263,8 +1263,8 @@ class DeclarationTVA // Debug: Log the search error_log("hasValidatedDocument: Searching in " . $vat_declarations_dir . " for declaration " . $obj->declaration_number); - // Look for PDF files with the declaration number - $pattern = $vat_declarations_dir . 'CA3_' . $obj->declaration_number . '_*.pdf'; + // Look for PDF files with the declaration ID (not declaration number) + $pattern = $vat_declarations_dir . 'CA3_' . $declaration_id . '_*.pdf'; $files = glob($pattern); // Debug: Log the pattern and results @@ -1273,7 +1273,7 @@ class DeclarationTVA // If no files found with the exact pattern, try a more flexible search if (empty($files)) { - $pattern = $vat_declarations_dir . 'CA3_*' . $obj->declaration_number . '*.pdf'; + $pattern = $vat_declarations_dir . 'CA3_*' . $declaration_id . '*.pdf'; $files = glob($pattern); error_log("hasValidatedDocument: Flexible pattern: " . $pattern); error_log("hasValidatedDocument: Flexible files found: " . print_r($files, true)); @@ -1311,13 +1311,13 @@ class DeclarationTVA // Check if PDF file exists in the VAT declarations validated directory $vat_declarations_dir = DOL_DATA_ROOT . '/declarationtva/validated/'; - // Look for PDF files with the declaration number - $pattern = $vat_declarations_dir . 'CA3_' . $obj->declaration_number . '_*.pdf'; + // Look for PDF files with the declaration ID (not declaration number) + $pattern = $vat_declarations_dir . 'CA3_' . $declaration_id . '_*.pdf'; $files = glob($pattern); // If no files found with the exact pattern, try a more flexible search if (empty($files)) { - $pattern = $vat_declarations_dir . 'CA3_*' . $obj->declaration_number . '*.pdf'; + $pattern = $vat_declarations_dir . 'CA3_*' . $declaration_id . '*.pdf'; $files = glob($pattern); }