diff --git a/core/class/declarationtva.class.php b/core/class/declarationtva.class.php index 90a29b8..347ab84 100644 --- a/core/class/declarationtva.class.php +++ b/core/class/declarationtva.class.php @@ -1273,16 +1273,24 @@ class DeclarationTVA return false; } - // Check if PDF file exists in the VAT declarations directory - $vat_declarations_dir = DOL_DATA_ROOT . '/declarationtva/validated/'; + // Check if PDF file exists in the VAT declarations documents directory + $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 - $pattern = $vat_declarations_dir . 'CA3_' . $obj->declaration_number . '_*.pdf'; + // Look for PDF files with the declaration number in the current month directory + $pattern = $month_dir . 'CA3_' . $obj->declaration_number . '_*.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 = $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); } @@ -1313,16 +1321,24 @@ class DeclarationTVA return false; } - // Check if PDF file exists in the VAT declarations directory - $vat_declarations_dir = DOL_DATA_ROOT . '/declarationtva/validated/'; + // Check if PDF file exists in the VAT declarations documents directory + $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 - $pattern = $vat_declarations_dir . 'CA3_' . $obj->declaration_number . '_*.pdf'; + // Look for PDF files with the declaration number in the current month directory + $pattern = $month_dir . 'CA3_' . $obj->declaration_number . '_*.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 = $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); }