Implement proper VAT declarations document organization

- Create dedicated VAT declarations folder structure under Dolibarr documents
- Organize by year and month: /documents/declarationtva/YYYY/MM/
- Updated PDF saving to use proper directory structure
- Enhanced ECM file records with proper filepath and descriptions
- Added helper methods for directory management
- Better document organization following Dolibarr conventions
- VAT declarations now have their own dedicated space
This commit is contained in:
Frank Cools 2025-10-06 17:22:24 +02:00
parent 8cb8f9e588
commit 4074c4fabd

View File

@ -1091,18 +1091,36 @@ class DeclarationTVA
global $conf, $user;
try {
// Create documents directory if it doesn't exist
$doc_dir = DOL_DATA_ROOT . '/declarationtva/validated/';
if (!is_dir($doc_dir)) {
if (!dol_mkdir($doc_dir)) {
$this->error = "Failed to create documents directory: " . $doc_dir;
// 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)) {
if (!dol_mkdir($vat_declarations_dir)) {
$this->error = "Failed to create VAT declarations directory: " . $vat_declarations_dir;
return false;
}
}
// Generate filename
$filename = 'CA3_Validated_' . $this->declaration_number . '_' . date('Y-m-d') . '.pdf';
$dest_path = $doc_dir . $filename;
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;
}
}
// 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)) {
@ -1133,10 +1151,10 @@ class DeclarationTVA
require_once $ecmfiles_path;
$ecmfile = new EcmFiles($this->db);
$ecmfile->filepath = 'declarationtva/validated/';
$ecmfile->filepath = 'declarationtva/' . date('Y') . '/' . date('m') . '/';
$ecmfile->filename = $filename;
$ecmfile->label = 'CA-3 Validated Declaration - ' . $this->declaration_number;
$ecmfile->description = 'Validated CA-3 declaration with detailed breakdown';
$ecmfile->label = 'CA-3 Déclaration TVA - ' . $this->declaration_number;
$ecmfile->description = 'Déclaration TVA CA-3 validée avec détail des comptes pour la période ' . date('Y-m');
$ecmfile->entity = $this->entity;
$ecmfile->fk_user_author = $user->id;
$ecmfile->fk_user_modif = $user->id;
@ -1237,4 +1255,42 @@ class DeclarationTVA
return false;
}
/**
* Get the VAT declarations documents directory path
*
* @param string $year Year (optional, defaults to current year)
* @param string $month Month (optional, defaults to current month)
* @return string Directory path
*/
public function getVATDeclarationsDirectory($year = null, $month = null)
{
if ($year === null) {
$year = date('Y');
}
if ($month === null) {
$month = date('m');
}
return DOL_DATA_ROOT . '/documents/declarationtva/' . $year . '/' . $month . '/';
}
/**
* Get the relative path for ECM files
*
* @param string $year Year (optional, defaults to current year)
* @param string $month Month (optional, defaults to current month)
* @return string Relative path
*/
public function getVATDeclarationsRelativePath($year = null, $month = null)
{
if ($year === null) {
$year = date('Y');
}
if ($month === null) {
$month = date('m');
}
return 'declarationtva/' . $year . '/' . $month . '/';
}
}