Fix PDF document detection in declaration list
- Modified hasValidatedDocument() to check file system instead of database - Added getValidatedPDFPath() method to get PDF file path - Updated declaration list to show clickable PDF download links - Added DownloadPDF translation in French and English - PDF icons now link directly to downloadable PDF files - Fixed issue where validated declarations didn't show PDF availability
This commit is contained in:
parent
00157f2634
commit
efa8f676fa
@ -1239,25 +1239,69 @@ class DeclarationTVA
|
|||||||
*/
|
*/
|
||||||
public function hasValidatedDocument($declaration_id)
|
public function hasValidatedDocument($declaration_id)
|
||||||
{
|
{
|
||||||
// First check if the table exists
|
// Get declaration details
|
||||||
$sql_check = "SHOW TABLES LIKE '" . MAIN_DB_PREFIX . "declarationtva_documents'";
|
$sql = "SELECT declaration_number, status FROM " . MAIN_DB_PREFIX . "declarationtva_declarations
|
||||||
$result_check = $this->db->query($sql_check);
|
WHERE rowid = " . (int)$declaration_id . " AND entity = " . $this->entity;
|
||||||
|
|
||||||
if (!$result_check || $this->db->num_rows($result_check) == 0) {
|
$result = $this->db->query($sql);
|
||||||
// Table doesn't exist, so no documents
|
if (!$result || $this->db->num_rows($result) == 0) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
$sql = "SELECT COUNT(*) as count
|
$obj = $this->db->fetch_object($result);
|
||||||
FROM " . MAIN_DB_PREFIX . "declarationtva_documents dd
|
|
||||||
INNER JOIN " . MAIN_DB_PREFIX . "ecm_files ef ON dd.document_id = ef.rowid
|
// Only check for documents if declaration is validated
|
||||||
WHERE dd.declaration_id = " . (int)$declaration_id . "
|
if ($obj->status != 'validated') {
|
||||||
AND dd.entity = " . $this->entity;
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check if PDF file exists in the VAT declarations 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 = $month_dir . 'CA3_' . $obj->declaration_number . '_*.pdf';
|
||||||
|
$files = glob($pattern);
|
||||||
|
|
||||||
|
return !empty($files) && file_exists($files[0]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the PDF file path for a validated declaration
|
||||||
|
*
|
||||||
|
* @param int $declaration_id Declaration ID
|
||||||
|
* @return string|false PDF file path or false if not found
|
||||||
|
*/
|
||||||
|
public function getValidatedPDFPath($declaration_id)
|
||||||
|
{
|
||||||
|
// Get declaration details
|
||||||
|
$sql = "SELECT declaration_number, status FROM " . MAIN_DB_PREFIX . "declarationtva_declarations
|
||||||
|
WHERE rowid = " . (int)$declaration_id . " AND entity = " . $this->entity;
|
||||||
|
|
||||||
$result = $this->db->query($sql);
|
$result = $this->db->query($sql);
|
||||||
if ($result && $this->db->num_rows($result) > 0) {
|
if (!$result || $this->db->num_rows($result) == 0) {
|
||||||
$obj = $this->db->fetch_object($result);
|
return false;
|
||||||
return $obj->count > 0;
|
}
|
||||||
|
|
||||||
|
$obj = $this->db->fetch_object($result);
|
||||||
|
|
||||||
|
// Only return path if declaration is validated
|
||||||
|
if ($obj->status != 'validated') {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check if PDF file exists in the VAT declarations 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 = $month_dir . 'CA3_' . $obj->declaration_number . '_*.pdf';
|
||||||
|
$files = glob($pattern);
|
||||||
|
|
||||||
|
if (!empty($files) && file_exists($files[0])) {
|
||||||
|
return $files[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
@ -149,7 +149,17 @@ if (empty($declarations)) {
|
|||||||
// Check if document exists
|
// Check if document exists
|
||||||
$has_document = $declarationtva->hasValidatedDocument($d['rowid']);
|
$has_document = $declarationtva->hasValidatedDocument($d['rowid']);
|
||||||
if ($has_document) {
|
if ($has_document) {
|
||||||
print '<i class="fa fa-file-pdf-o text-success" title="' . $langs->trans("ValidatedPDFAvailable") . '"></i>';
|
$pdf_path = $declarationtva->getValidatedPDFPath($d['rowid']);
|
||||||
|
if ($pdf_path) {
|
||||||
|
// Create a download link
|
||||||
|
$relative_path = str_replace(DOL_DATA_ROOT, '', $pdf_path);
|
||||||
|
$download_url = DOL_URL_ROOT . '/documents' . $relative_path;
|
||||||
|
print '<a href="' . $download_url . '" target="_blank" title="' . $langs->trans("DownloadPDF") . '">';
|
||||||
|
print '<i class="fa fa-file-pdf-o text-success"></i>';
|
||||||
|
print '</a>';
|
||||||
|
} else {
|
||||||
|
print '<i class="fa fa-file-pdf-o text-success" title="' . $langs->trans("ValidatedPDFAvailable") . '"></i>';
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
print '<i class="fa fa-file-o text-muted" title="' . $langs->trans("NoDocument") . '"></i>';
|
print '<i class="fa fa-file-o text-muted" title="' . $langs->trans("NoDocument") . '"></i>';
|
||||||
}
|
}
|
||||||
|
|||||||
@ -512,3 +512,4 @@ ValidatedDeclaration = Validated Declaration
|
|||||||
DraftDeclaration = Draft Declaration
|
DraftDeclaration = Draft Declaration
|
||||||
ValidatedPDFAvailable = Validated PDF Available
|
ValidatedPDFAvailable = Validated PDF Available
|
||||||
NoDocument = No Document
|
NoDocument = No Document
|
||||||
|
DownloadPDF = Download PDF
|
||||||
|
|||||||
@ -484,3 +484,4 @@ ValidatedDeclaration = Déclaration validée
|
|||||||
DraftDeclaration = Déclaration brouillon
|
DraftDeclaration = Déclaration brouillon
|
||||||
ValidatedPDFAvailable = PDF validé disponible
|
ValidatedPDFAvailable = PDF validé disponible
|
||||||
NoDocument = Aucun document
|
NoDocument = Aucun document
|
||||||
|
DownloadPDF = Télécharger le PDF
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user