Fix export to use improved detailed pages instead of old method

This commit is contained in:
Frank Cools 2025-10-08 14:36:08 +02:00
parent 5a8be79dc8
commit b8583aacf4

View File

@ -1173,6 +1173,75 @@ class DeclarationTVA_PDF
$this->addAccountDetailsTable($pdf, $line_details['account_details'], $line_code); $this->addAccountDetailsTable($pdf, $line_details['account_details'], $line_code);
} }
/**
* Generate improved detailed PDF with new layout
*
* @param string $output_path Output file path
* @param DeclarationTVA $declaration Declaration object
* @param array $ca3_data CA-3 line data
* @param Societe $mysoc Company object
* @return bool Success
*/
private function generateImprovedDetailedPDF($output_path, $declaration, $ca3_data, $mysoc)
{
try {
// Create a new PDF document
$pdf = new DeclarationTVA_CustomPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
// Set company name and declaration period for footer
$pdf->setCompanyName($mysoc->name);
$pdf->setDeclarationPeriod(dol_print_date($declaration->start_date, 'day') . ' - ' . dol_print_date($declaration->end_date, 'day'));
// Set document information
$pdf->SetCreator('DeclarationTVA Module');
$pdf->SetAuthor($mysoc->name);
$pdf->SetTitle('CA-3 Declaration Details ' . $declaration->declaration_number);
$pdf->SetSubject('French VAT Declaration Details');
// Set margins
$pdf->SetMargins(15, 15, 15);
$pdf->SetHeaderMargin(5);
$pdf->SetFooterMargin(10);
// Set thin borders for all elements
$pdf->SetLineWidth(0.1);
// Add title page
$pdf->AddPage();
$pdf->SetFont('helvetica', 'B', 16);
$pdf->SetFillColor(240, 240, 240); // Light gray background
$pdf->Cell(0, 10, 'Détails de la Déclaration TVA CA-3', 1, 1, 'C', true);
$pdf->Ln(10);
$pdf->SetFont('helvetica', '', 12);
$pdf->Cell(0, 8, 'Numéro de déclaration: ' . $declaration->declaration_number, 0, 1);
$pdf->Cell(0, 8, 'Période: ' . dol_print_date($declaration->start_date, 'day') . ' - ' . dol_print_date($declaration->end_date, 'day'), 0, 1);
$pdf->Cell(0, 8, 'Statut: ' . $this->translateStatus($declaration->status), 0, 1);
$pdf->Ln(10);
// Add journal entry table on page 1
$this->addJournalEntryTable($pdf, $declaration, $ca3_data);
// Add bank journal entry table on page 1
$this->addBankJournalEntryTable($pdf, $declaration, $ca3_data);
// Add detailed breakdown pages starting on page 2
$this->addDetailedPagesContent($pdf, $declaration, $ca3_data);
// Set total pages for footer after all pages are generated
$pdf->setTotalPages($pdf->getNumPages());
// Output PDF
$pdf->Output($output_path, 'F');
return true;
} catch (Exception $e) {
$this->error = 'Improved detailed PDF generation failed: ' . $e->getMessage();
return false;
}
}
/** /**
* Add account details table to PDF * Add account details table to PDF
* *
@ -1336,7 +1405,7 @@ class DeclarationTVA_PDF
// 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, $mysoc); $result = $this->generateImprovedDetailedPDF($temp_detailed_path, $declaration, $ca3_data, $mysoc);
if (!$result) { if (!$result) {
return false; return false;