diff --git a/core/class/declarationtva_pdf.class.php b/core/class/declarationtva_pdf.class.php index 26c40d4..f2c4c5c 100644 --- a/core/class/declarationtva_pdf.class.php +++ b/core/class/declarationtva_pdf.class.php @@ -205,8 +205,15 @@ class DeclarationTVA_PDF $result = $this->generateDetailedPDF($filepath, $declaration, $ca3_data, $company); if ($result) { - return $filepath; + // Verify file was actually created + if (file_exists($filepath)) { + return $filepath; + } else { + $this->error = "PDF file was not created at expected path: " . $filepath; + return false; + } } else { + $this->error = "PDF generation failed: " . $this->error; return false; } } diff --git a/declarationtva_view.php b/declarationtva_view.php index 2568e33..72b4463 100644 --- a/declarationtva_view.php +++ b/declarationtva_view.php @@ -100,16 +100,24 @@ if ($action == 'export_pdf_detailed') { if ($action == 'validate' && $token) { // Validate the declaration + setEventMessages("Starting validation process...", null, 'mesgs'); + if ($declarationtva->validateDeclaration($id)) { setEventMessages($langs->trans("DeclarationValidated"), null, 'mesgs'); // Generate and save detailed PDF to Dolibarr documents + setEventMessages("Loading PDF generator...", null, 'mesgs'); require_once DOL_DOCUMENT_ROOT . '/custom/declarationtva/core/class/declarationtva_pdf.class.php'; $pdf_generator = new DeclarationTVA_PDF($db); + setEventMessages("Generating detailed PDF...", null, 'mesgs'); $pdf_path = $pdf_generator->generateDetailedCA3PDF($id); + if ($pdf_path && file_exists($pdf_path)) { + setEventMessages("PDF generated successfully: " . $pdf_path, null, 'mesgs'); + // Save PDF to Dolibarr documents + setEventMessages("Saving PDF to documents...", null, 'mesgs'); $save_result = $declarationtva->saveValidatedPDF($id, $pdf_path); if (!$save_result) { setEventMessages("Warning: Declaration validated but PDF save failed: " . $declarationtva->error, null, 'warnings'); @@ -118,6 +126,8 @@ if ($action == 'validate' && $token) { } } else { setEventMessages("Warning: Declaration validated but PDF generation failed: " . $pdf_generator->error, null, 'warnings'); + setEventMessages("PDF path returned: " . ($pdf_path ? $pdf_path : 'NULL'), null, 'warnings'); + setEventMessages("File exists: " . ($pdf_path && file_exists($pdf_path) ? 'YES' : 'NO'), null, 'warnings'); } } else { setEventMessages($langs->trans("ErrorValidatingDeclaration") . ": " . $declarationtva->error, null, 'errors');