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
|
// Check if PDF is already in the correct location
|
||||||
$filename = 'CA3_' . $this->declaration_number . '_' . date('Y-m-d') . '.pdf';
|
if (strpos($pdf_path, $month_dir) === 0) {
|
||||||
$dest_path = $month_dir . $filename;
|
// PDF is already in the correct location, no need to copy
|
||||||
|
$dest_path = $pdf_path;
|
||||||
// Copy PDF to documents directory
|
} else {
|
||||||
if (!copy($pdf_path, $dest_path)) {
|
// Generate filename with proper structure
|
||||||
$this->error = "Failed to copy PDF to documents directory";
|
$filename = 'CA3_' . $this->declaration_number . '_' . date('Y-m-d') . '.pdf';
|
||||||
return false;
|
$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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Try to add document record to Dolibarr (optional feature)
|
// Try to add document record to Dolibarr (optional feature)
|
||||||
|
|||||||
@ -181,13 +181,25 @@ class DeclarationTVA_PDF
|
|||||||
$company->fetch($conf->entity);
|
$company->fetch($conf->entity);
|
||||||
|
|
||||||
// Generate PDF filename
|
// Generate PDF filename
|
||||||
$filename = 'CA3_Detailed_' . $declaration->declaration_number . '_' . date('Y-m-d') . '.pdf';
|
$filename = 'CA3_' . $declaration->declaration_number . '_' . date('Y-m-d') . '.pdf';
|
||||||
$filepath = DOL_DATA_ROOT . '/declarationtva/' . $filename;
|
|
||||||
|
// Create VAT declarations documents directory structure
|
||||||
// Ensure directory exists
|
$vat_declarations_dir = DOL_DATA_ROOT . '/documents/declarationtva/';
|
||||||
if (!is_dir(DOL_DATA_ROOT . '/declarationtva/')) {
|
$year_dir = $vat_declarations_dir . date('Y') . '/';
|
||||||
dol_mkdir(DOL_DATA_ROOT . '/declarationtva/');
|
$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
|
// Generate detailed PDF with breakdown pages
|
||||||
$result = $this->generateDetailedPDF($filepath, $declaration, $ca3_data, $company);
|
$result = $this->generateDetailedPDF($filepath, $declaration, $ca3_data, $company);
|
||||||
|
|||||||
@ -113,6 +113,8 @@ if ($action == 'validate' && $token) {
|
|||||||
$save_result = $declarationtva->saveValidatedPDF($id, $pdf_path);
|
$save_result = $declarationtva->saveValidatedPDF($id, $pdf_path);
|
||||||
if (!$save_result) {
|
if (!$save_result) {
|
||||||
setEventMessages("Warning: Declaration validated but PDF save failed: " . $declarationtva->error, null, 'warnings');
|
setEventMessages("Warning: Declaration validated but PDF save failed: " . $declarationtva->error, null, 'warnings');
|
||||||
|
} else {
|
||||||
|
setEventMessages("PDF generated and saved successfully: " . $pdf_path, null, 'mesgs');
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
setEventMessages("Warning: Declaration validated but PDF generation failed: " . $pdf_generator->error, null, 'warnings');
|
setEventMessages("Warning: Declaration validated but PDF generation failed: " . $pdf_generator->error, null, 'warnings');
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user