v2.5.15: Fixed company information source in PDF generation
- Now uses Dolibarr's $mysoc configuration instead of fetching separate company - PDF footer now uses the same company data as CA-3 form filling - Uses $mysoc (Dolibarr company config) for all company information - Company name in PDF footer now matches the company used in CA-3 form - Updated all method signatures and calls to use $mysoc consistently - Removed duplicate company fetching and use consistent data source
This commit is contained in:
parent
024bc785f3
commit
0b66cb4fd4
@ -1,5 +1,13 @@
|
|||||||
# CHANGELOG MODULE DECLARATIONTVA FOR [DOLIBARR ERP CRM](https://www.dolibarr.org)
|
# CHANGELOG MODULE DECLARATIONTVA FOR [DOLIBARR ERP CRM](https://www.dolibarr.org)
|
||||||
|
|
||||||
|
## 2.5.15
|
||||||
|
|
||||||
|
### Bug Fixes
|
||||||
|
- **Fixed Company Information Source**: Now uses Dolibarr's $mysoc configuration instead of fetching separate company
|
||||||
|
- **Consistent Company Data**: PDF footer now uses the same company data as CA-3 form filling
|
||||||
|
- **Proper Data Source**: Uses $mysoc (Dolibarr company config) for all company information
|
||||||
|
- **Accurate Footer**: Company name in PDF footer now matches the company used in CA-3 form
|
||||||
|
|
||||||
## 2.5.14
|
## 2.5.14
|
||||||
|
|
||||||
### Bug Fixes
|
### Bug Fixes
|
||||||
|
|||||||
@ -159,9 +159,8 @@ class DeclarationTVA_PDF
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get company information - use main company entity (1) instead of current entity
|
// Get company information from Dolibarr's company configuration (same as used in CA-3 form)
|
||||||
$company = new Societe($this->db);
|
global $mysoc;
|
||||||
$company->fetch(1); // Main company entity
|
|
||||||
|
|
||||||
// Generate PDF filename
|
// Generate PDF filename
|
||||||
$filename = 'CA3_' . $declaration->declaration_number . '_' . date('Y-m-d') . '.pdf';
|
$filename = 'CA3_' . $declaration->declaration_number . '_' . date('Y-m-d') . '.pdf';
|
||||||
@ -180,7 +179,7 @@ class DeclarationTVA_PDF
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Generate PDF using FPDI or similar library
|
// Generate PDF using FPDI or similar library
|
||||||
$result = $this->fillPDFTemplate($template_file, $filepath, $declaration, $ca3_data, $company);
|
$result = $this->fillPDFTemplate($template_file, $filepath, $declaration, $ca3_data, $mysoc);
|
||||||
|
|
||||||
if ($result) {
|
if ($result) {
|
||||||
return $filepath;
|
return $filepath;
|
||||||
@ -216,9 +215,8 @@ class DeclarationTVA_PDF
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get company information - use main company entity (1) instead of current entity
|
// Get company information from Dolibarr's company configuration (same as used in CA-3 form)
|
||||||
$company = new Societe($this->db);
|
global $mysoc;
|
||||||
$company->fetch(1); // Main company entity
|
|
||||||
|
|
||||||
// Generate PDF filename
|
// Generate PDF filename
|
||||||
$filename = 'CA3_' . $declaration->declaration_number . '_' . date('Y-m-d') . '.pdf';
|
$filename = 'CA3_' . $declaration->declaration_number . '_' . date('Y-m-d') . '.pdf';
|
||||||
@ -301,15 +299,15 @@ class DeclarationTVA_PDF
|
|||||||
* @param Societe $company Company object
|
* @param Societe $company Company object
|
||||||
* @return bool Success
|
* @return bool Success
|
||||||
*/
|
*/
|
||||||
private function fillPDFTemplate($template_path, $output_path, $declaration, $ca3_data, $company)
|
private function fillPDFTemplate($template_path, $output_path, $declaration, $ca3_data, $mysoc)
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
// Check if we have a custom fillable PDF template
|
// Check if we have a custom fillable PDF template
|
||||||
if (file_exists($template_path) && $this->isFillablePDF($template_path)) {
|
if (file_exists($template_path) && $this->isFillablePDF($template_path)) {
|
||||||
return $this->fillFillablePDF($template_path, $output_path, $declaration, $ca3_data, $company);
|
return $this->fillFillablePDF($template_path, $output_path, $declaration, $ca3_data, $mysoc);
|
||||||
} else {
|
} else {
|
||||||
// Fall back to basic PDF generation
|
// Fall back to basic PDF generation
|
||||||
return $this->generateBasicPDF($output_path, $declaration, $ca3_data, $company);
|
return $this->generateBasicPDF($output_path, $declaration, $ca3_data, $mysoc);
|
||||||
}
|
}
|
||||||
} catch (Exception $e) {
|
} catch (Exception $e) {
|
||||||
$this->error = 'PDF generation failed: ' . $e->getMessage();
|
$this->error = 'PDF generation failed: ' . $e->getMessage();
|
||||||
@ -340,17 +338,17 @@ class DeclarationTVA_PDF
|
|||||||
* @param Societe $company Company object
|
* @param Societe $company Company object
|
||||||
* @return bool Success
|
* @return bool Success
|
||||||
*/
|
*/
|
||||||
private function fillFillablePDF($template_path, $output_path, $declaration, $ca3_data, $company)
|
private function fillFillablePDF($template_path, $output_path, $declaration, $ca3_data, $mysoc)
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
// Check if pdftk is available
|
// Check if pdftk is available
|
||||||
if (!$this->isPdftkAvailable()) {
|
if (!$this->isPdftkAvailable()) {
|
||||||
// Fallback to manual approach if pdftk is not available
|
// Fallback to manual approach if pdftk is not available
|
||||||
return $this->fillFillablePDFManual($template_path, $output_path, $declaration, $ca3_data, $company);
|
return $this->fillFillablePDFManual($template_path, $output_path, $declaration, $ca3_data, $mysoc);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Prepare field data mapping
|
// Prepare field data mapping
|
||||||
$field_data = $this->prepareFieldData($declaration, $ca3_data, $company);
|
$field_data = $this->prepareFieldData($declaration, $ca3_data, $mysoc);
|
||||||
|
|
||||||
// Create FDF data file for pdftk
|
// Create FDF data file for pdftk
|
||||||
$fdf_file = $this->createFDFFile($field_data, $declaration);
|
$fdf_file = $this->createFDFFile($field_data, $declaration);
|
||||||
@ -368,7 +366,7 @@ class DeclarationTVA_PDF
|
|||||||
// Check if output file was created successfully
|
// Check if output file was created successfully
|
||||||
if (file_exists($output_path) && filesize($output_path) > 0) {
|
if (file_exists($output_path) && filesize($output_path) > 0) {
|
||||||
// Add detailed pages to the filled PDF
|
// Add detailed pages to the filled PDF
|
||||||
$this->addDetailedPagesToPDF($output_path, $declaration, $ca3_data, $company);
|
$this->addDetailedPagesToPDF($output_path, $declaration, $ca3_data, $mysoc);
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
$this->error = 'pdftk failed to generate output: ' . $result;
|
$this->error = 'pdftk failed to generate output: ' . $result;
|
||||||
@ -389,12 +387,12 @@ class DeclarationTVA_PDF
|
|||||||
* @param Societe $company Company object
|
* @param Societe $company Company object
|
||||||
* @return array Field data mapping
|
* @return array Field data mapping
|
||||||
*/
|
*/
|
||||||
private function prepareFieldData($declaration, $ca3_data, $company)
|
private function prepareFieldData($declaration, $ca3_data, $mysoc)
|
||||||
{
|
{
|
||||||
$field_data = array();
|
$field_data = array();
|
||||||
|
|
||||||
// Get the actual company information from Dolibarr configuration
|
// Get the actual company information from Dolibarr configuration
|
||||||
global $conf, $mysoc;
|
global $conf;
|
||||||
|
|
||||||
// Use Dolibarr's company configuration
|
// Use Dolibarr's company configuration
|
||||||
$field_data['company_name'] = $mysoc->name;
|
$field_data['company_name'] = $mysoc->name;
|
||||||
@ -734,14 +732,14 @@ class DeclarationTVA_PDF
|
|||||||
* @param Societe $company Company object
|
* @param Societe $company Company object
|
||||||
* @return bool Success
|
* @return bool Success
|
||||||
*/
|
*/
|
||||||
private function fillFillablePDFManual($template_path, $output_path, $declaration, $ca3_data, $company)
|
private function fillFillablePDFManual($template_path, $output_path, $declaration, $ca3_data, $mysoc)
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
// Simple approach: Just copy the template and create a data file
|
// Simple approach: Just copy the template and create a data file
|
||||||
if (copy($template_path, $output_path)) {
|
if (copy($template_path, $output_path)) {
|
||||||
// Create a data file with all the values for manual filling
|
// Create a data file with all the values for manual filling
|
||||||
$data_file = dirname($output_path) . '/ca3_data_' . $declaration->declaration_number . '.txt';
|
$data_file = dirname($output_path) . '/ca3_data_' . $declaration->declaration_number . '.txt';
|
||||||
$field_data = $this->prepareFieldData($declaration, $ca3_data, $company);
|
$field_data = $this->prepareFieldData($declaration, $ca3_data, $mysoc);
|
||||||
|
|
||||||
$data_content = "CA-3 Declaration Data (Manual Filling Required)\n";
|
$data_content = "CA-3 Declaration Data (Manual Filling Required)\n";
|
||||||
$data_content .= "============================================\n\n";
|
$data_content .= "============================================\n\n";
|
||||||
@ -818,7 +816,7 @@ class DeclarationTVA_PDF
|
|||||||
file_put_contents($data_file, $data_content);
|
file_put_contents($data_file, $data_content);
|
||||||
|
|
||||||
// Add detailed pages to the filled PDF
|
// Add detailed pages to the filled PDF
|
||||||
$this->addDetailedPagesToPDF($output_path, $declaration, $ca3_data, $company);
|
$this->addDetailedPagesToPDF($output_path, $declaration, $ca3_data, $mysoc);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
@ -842,18 +840,18 @@ class DeclarationTVA_PDF
|
|||||||
* @param Societe $company Company object
|
* @param Societe $company Company object
|
||||||
* @return bool Success
|
* @return bool Success
|
||||||
*/
|
*/
|
||||||
private function generateBasicPDF($output_path, $declaration, $ca3_data, $company)
|
private function generateBasicPDF($output_path, $declaration, $ca3_data, $mysoc)
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
// Create a new PDF document
|
// Create a new PDF document
|
||||||
$pdf = new DeclarationTVA_CustomPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
|
$pdf = new DeclarationTVA_CustomPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
|
||||||
|
|
||||||
// Set company name for footer
|
// Set company name for footer
|
||||||
$pdf->setCompanyName($company->name);
|
$pdf->setCompanyName($mysoc->name);
|
||||||
|
|
||||||
// Set document information
|
// Set document information
|
||||||
$pdf->SetCreator('DeclarationTVA Module');
|
$pdf->SetCreator('DeclarationTVA Module');
|
||||||
$pdf->SetAuthor($company->name);
|
$pdf->SetAuthor($mysoc->name);
|
||||||
$pdf->SetTitle('CA-3 Declaration ' . $declaration->declaration_number);
|
$pdf->SetTitle('CA-3 Declaration ' . $declaration->declaration_number);
|
||||||
$pdf->SetSubject('French VAT Declaration');
|
$pdf->SetSubject('French VAT Declaration');
|
||||||
|
|
||||||
@ -1231,13 +1229,13 @@ class DeclarationTVA_PDF
|
|||||||
* @param Societe $company Company object
|
* @param Societe $company Company object
|
||||||
* @return bool Success
|
* @return bool Success
|
||||||
*/
|
*/
|
||||||
private function addDetailedPagesToPDF($pdf_path, $declaration, $ca3_data, $company)
|
private function addDetailedPagesToPDF($pdf_path, $declaration, $ca3_data, $mysoc)
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
// Create a temporary detailed PDF
|
// Create a temporary detailed PDF
|
||||||
$temp_detailed_path = tempnam(sys_get_temp_dir(), 'ca3_detailed_') . '.pdf';
|
$temp_detailed_path = tempnam(sys_get_temp_dir(), 'ca3_detailed_') . '.pdf';
|
||||||
|
|
||||||
$result = $this->generateDetailedPDF($temp_detailed_path, $declaration, $ca3_data, $company);
|
$result = $this->generateDetailedPDF($temp_detailed_path, $declaration, $ca3_data, $mysoc);
|
||||||
|
|
||||||
if (!$result) {
|
if (!$result) {
|
||||||
return false;
|
return false;
|
||||||
@ -1429,18 +1427,18 @@ class DeclarationTVA_PDF
|
|||||||
* @param Societe $company Company object
|
* @param Societe $company Company object
|
||||||
* @return bool Success
|
* @return bool Success
|
||||||
*/
|
*/
|
||||||
private function generateDetailedPDF($output_path, $declaration, $ca3_data, $company)
|
private function generateDetailedPDF($output_path, $declaration, $ca3_data, $mysoc)
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
// Create a new PDF document
|
// Create a new PDF document
|
||||||
$pdf = new DeclarationTVA_CustomPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
|
$pdf = new DeclarationTVA_CustomPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
|
||||||
|
|
||||||
// Set company name for footer
|
// Set company name for footer
|
||||||
$pdf->setCompanyName($company->name);
|
$pdf->setCompanyName($mysoc->name);
|
||||||
|
|
||||||
// Set document information
|
// Set document information
|
||||||
$pdf->SetCreator('DeclarationTVA Module');
|
$pdf->SetCreator('DeclarationTVA Module');
|
||||||
$pdf->SetAuthor($company->name);
|
$pdf->SetAuthor($mysoc->name);
|
||||||
$pdf->SetTitle('CA-3 Declaration Details ' . $declaration->declaration_number);
|
$pdf->SetTitle('CA-3 Declaration Details ' . $declaration->declaration_number);
|
||||||
$pdf->SetSubject('French VAT Declaration - Detailed Breakdown');
|
$pdf->SetSubject('French VAT Declaration - Detailed Breakdown');
|
||||||
|
|
||||||
|
|||||||
@ -76,7 +76,7 @@ class modDeclarationTVA extends DolibarrModules
|
|||||||
$this->editor_squarred_logo = ''; // Must be image filename into the module/img directory followed with @modulename. Example: 'myimage.png@declarationtva'
|
$this->editor_squarred_logo = ''; // Must be image filename into the module/img directory followed with @modulename. Example: 'myimage.png@declarationtva'
|
||||||
|
|
||||||
// Possible values for version are: 'development', 'experimental', 'dolibarr', 'dolibarr_deprecated', 'experimental_deprecated' or a version string like 'x.y.z'
|
// Possible values for version are: 'development', 'experimental', 'dolibarr', 'dolibarr_deprecated', 'experimental_deprecated' or a version string like 'x.y.z'
|
||||||
$this->version = '2.5.14';
|
$this->version = '2.5.15';
|
||||||
// Url to the file with your last numberversion of this module
|
// Url to the file with your last numberversion of this module
|
||||||
//$this->url_last_version = 'http://www.example.com/versionmodule.txt';
|
//$this->url_last_version = 'http://www.example.com/versionmodule.txt';
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user