diff --git a/core/class/declarationtva.class.php b/core/class/declarationtva.class.php index 347ab84..1dd14f1 100644 --- a/core/class/declarationtva.class.php +++ b/core/class/declarationtva.class.php @@ -1103,12 +1103,10 @@ class DeclarationTVA global $conf, $user; try { - // Create VAT declarations documents directory structure - $vat_declarations_dir = DOL_DATA_ROOT . '/documents/declarationtva/'; - $year_dir = $vat_declarations_dir . date('Y') . '/'; - $month_dir = $year_dir . date('m') . '/'; + // Create VAT declarations validated directory structure + $vat_declarations_dir = DOL_DATA_ROOT . '/declarationtva/validated/'; - // Create directories if they don't exist + // Create directory if it doesn't exist if (!is_dir($vat_declarations_dir)) { if (!dol_mkdir($vat_declarations_dir)) { $this->error = "Failed to create VAT declarations directory: " . $vat_declarations_dir; @@ -1116,32 +1114,18 @@ class DeclarationTVA } } - if (!is_dir($year_dir)) { - if (!dol_mkdir($year_dir)) { - $this->error = "Failed to create year directory: " . $year_dir; - return false; - } - } - - if (!is_dir($month_dir)) { - if (!dol_mkdir($month_dir)) { - $this->error = "Failed to create month directory: " . $month_dir; - return false; - } - } - // Check if PDF is already in the correct location - if (strpos($pdf_path, $month_dir) === 0) { + if (strpos($pdf_path, $vat_declarations_dir) === 0) { // PDF is already in the correct location, no need to copy $dest_path = $pdf_path; } else { // Generate filename with proper structure $filename = 'CA3_' . $this->declaration_number . '_' . date('Y-m-d') . '.pdf'; - $dest_path = $month_dir . $filename; + $dest_path = $vat_declarations_dir . $filename; - // Copy PDF to documents directory + // Copy PDF to validated directory if (!copy($pdf_path, $dest_path)) { - $this->error = "Failed to copy PDF to documents directory"; + $this->error = "Failed to copy PDF to validated directory"; return false; } } @@ -1273,24 +1257,16 @@ class DeclarationTVA return false; } - // 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') . '/'; + // 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 in the current month directory - $pattern = $month_dir . 'CA3_' . $obj->declaration_number . '_*.pdf'; + // Look for PDF files with the declaration number + $pattern = $vat_declarations_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 = $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'; + $pattern = $vat_declarations_dir . 'CA3_*' . $obj->declaration_number . '*.pdf'; $files = glob($pattern); } @@ -1321,24 +1297,16 @@ class DeclarationTVA return false; } - // 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') . '/'; + // 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 in the current month directory - $pattern = $month_dir . 'CA3_' . $obj->declaration_number . '_*.pdf'; + // Look for PDF files with the declaration number + $pattern = $vat_declarations_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 = $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'; + $pattern = $vat_declarations_dir . 'CA3_*' . $obj->declaration_number . '*.pdf'; $files = glob($pattern); } diff --git a/core/class/declarationtva_pdf.class.php b/core/class/declarationtva_pdf.class.php index 4ce97f6..7a1cd7c 100644 --- a/core/class/declarationtva_pdf.class.php +++ b/core/class/declarationtva_pdf.class.php @@ -322,23 +322,15 @@ class DeclarationTVA_PDF // Generate PDF filename $filename = 'CA3_' . $declaration_id . '_' . date('Y-m-d') . '.pdf'; - // Create VAT declarations documents directory structure (same as saveValidatedPDF expects) - $vat_declarations_dir = DOL_DATA_ROOT . '/documents/declarationtva/'; - $year_dir = $vat_declarations_dir . date('Y') . '/'; - $month_dir = $year_dir . date('m') . '/'; + // Create VAT declarations validated directory structure + $vat_declarations_dir = DOL_DATA_ROOT . '/declarationtva/validated/'; - // Create directories if they don't exist + // Create directory if it doesn't exist if (!is_dir($vat_declarations_dir)) { dol_mkdir($vat_declarations_dir); } - if (!is_dir($year_dir)) { - dol_mkdir($year_dir); - } - if (!is_dir($month_dir)) { - dol_mkdir($month_dir); - } - $filepath = $month_dir . $filename; + $filepath = $vat_declarations_dir . $filename; // Use the exact same method as export but with the correct output path // First generate the PDF using the same method as export