Fix PDF generation and saving path issues
- Modified generateDetailedCA3PDF to save PDFs directly to /documents/declarationtva/YYYY/MM/ - Updated saveValidatedPDF to handle PDFs already in correct location - Added debugging messages to show PDF generation success/failure - Fixed path mismatch between PDF generation and document detection - PDFs should now be properly generated and detected in declaration list
This commit is contained in:
parent
efa8f676fa
commit
7a3cfd1237
@ -1118,14 +1118,20 @@ class DeclarationTVA
|
||||
}
|
||||
}
|
||||
|
||||
// Generate filename with proper structure
|
||||
$filename = 'CA3_' . $this->declaration_number . '_' . date('Y-m-d') . '.pdf';
|
||||
$dest_path = $month_dir . $filename;
|
||||
// Check if PDF is already in the correct location
|
||||
if (strpos($pdf_path, $month_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;
|
||||
|
||||
// Copy PDF to documents directory
|
||||
if (!copy($pdf_path, $dest_path)) {
|
||||
$this->error = "Failed to copy PDF to documents directory";
|
||||
return false;
|
||||
// Copy PDF to documents directory
|
||||
if (!copy($pdf_path, $dest_path)) {
|
||||
$this->error = "Failed to copy PDF to documents directory";
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// Try to add document record to Dolibarr (optional feature)
|
||||
|
||||
@ -181,13 +181,25 @@ class DeclarationTVA_PDF
|
||||
$company->fetch($conf->entity);
|
||||
|
||||
// Generate PDF filename
|
||||
$filename = 'CA3_Detailed_' . $declaration->declaration_number . '_' . date('Y-m-d') . '.pdf';
|
||||
$filepath = DOL_DATA_ROOT . '/declarationtva/' . $filename;
|
||||
$filename = 'CA3_' . $declaration->declaration_number . '_' . date('Y-m-d') . '.pdf';
|
||||
|
||||
// Ensure directory exists
|
||||
if (!is_dir(DOL_DATA_ROOT . '/declarationtva/')) {
|
||||
dol_mkdir(DOL_DATA_ROOT . '/declarationtva/');
|
||||
// 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 directories if they don'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;
|
||||
|
||||
// Generate detailed PDF with breakdown pages
|
||||
$result = $this->generateDetailedPDF($filepath, $declaration, $ca3_data, $company);
|
||||
|
||||
@ -113,6 +113,8 @@ if ($action == 'validate' && $token) {
|
||||
$save_result = $declarationtva->saveValidatedPDF($id, $pdf_path);
|
||||
if (!$save_result) {
|
||||
setEventMessages("Warning: Declaration validated but PDF save failed: " . $declarationtva->error, null, 'warnings');
|
||||
} else {
|
||||
setEventMessages("PDF generated and saved successfully: " . $pdf_path, null, 'mesgs');
|
||||
}
|
||||
} else {
|
||||
setEventMessages("Warning: Declaration validated but PDF generation failed: " . $pdf_generator->error, null, 'warnings');
|
||||
|
||||
Loading…
Reference in New Issue
Block a user