Clean up debug logging statements

- Removed all error_log debug statements from PDF generation
- Removed debug logging from CA-3 data processing
- Removed debug logging from account amount calculations
- Cleaned up merge methods debug output
- Production-ready code without debug noise
This commit is contained in:
Frank Cools 2025-10-06 16:50:46 +02:00
parent 9255a39d42
commit 91ebf73866
2 changed files with 2 additions and 68 deletions

View File

@ -238,9 +238,7 @@ class DeclarationTVA
} else { } else {
// Normal processing for other lines // Normal processing for other lines
if (isset($grouped_mappings[$ca3_line])) { if (isset($grouped_mappings[$ca3_line])) {
error_log("DeclarationTVA: Processing CA-3 line $ca3_line with " . count($grouped_mappings[$ca3_line]) . " mapped accounts");
foreach ($grouped_mappings[$ca3_line] as $mapping) { foreach ($grouped_mappings[$ca3_line] as $mapping) {
error_log("DeclarationTVA: Processing account " . $mapping['account_code'] . " for line $ca3_line");
$amounts = $this->getAccountAmounts($mapping['account_code'], $period['start_date'], $period['end_date']); $amounts = $this->getAccountAmounts($mapping['account_code'], $period['start_date'], $period['end_date']);
$line_total_base += $amounts['base_amount']; $line_total_base += $amounts['base_amount'];
@ -248,10 +246,7 @@ class DeclarationTVA
$line_total_amount += $amounts['total_amount']; $line_total_amount += $amounts['total_amount'];
$account_labels[] = $mapping['account_label']; $account_labels[] = $mapping['account_label'];
error_log("DeclarationTVA: Account " . $mapping['account_code'] . " amounts: base=" . $amounts['base_amount'] . ", vat=" . $amounts['vat_amount']);
} }
} else {
error_log("DeclarationTVA: No mappings found for CA-3 line $ca3_line");
} }
} }
@ -271,8 +266,6 @@ class DeclarationTVA
$this->createCA3Line($declaration_id, $ca3_line, $combined_label, $combined_amounts); $this->createCA3Line($declaration_id, $ca3_line, $combined_label, $combined_amounts);
// Log the final amounts for debugging
error_log("DeclarationTVA: Final amounts for line $ca3_line: base=$line_total_base, vat=$line_total_vat, total=$line_total_amount");
// Update totals - only VAT amounts from sections B and C // Update totals - only VAT amounts from sections B and C
if (in_array($ca3_line, ['08', '09', '9B'])) { if (in_array($ca3_line, ['08', '09', '9B'])) {
@ -284,8 +277,6 @@ class DeclarationTVA
} }
} }
// Debug totals
error_log("DeclarationTVA: Total VAT collected: $total_vat_collected, Total VAT deductible: $total_vat_deductible");
// Calculate line 16: Subtotal of lines 08, 09, 9B (for user reference) // Calculate line 16: Subtotal of lines 08, 09, 9B (for user reference)
$this->calculateLine16($declaration_id); $this->calculateLine16($declaration_id);
@ -577,8 +568,6 @@ class DeclarationTVA
$total_amount = abs($obj->total_debit - $obj->total_credit); $total_amount = abs($obj->total_debit - $obj->total_credit);
} }
// Log successful query for debugging
error_log("DeclarationTVA: Found data with query: " . substr($sql, 0, 100) . "... Debit: " . $obj->total_debit . ", Credit: " . $obj->total_credit . ", Amount: $total_amount");
return array( return array(
'base_amount' => $total_amount, 'base_amount' => $total_amount,
@ -588,8 +577,6 @@ class DeclarationTVA
} }
} }
// If no data found, log the account code for debugging
error_log("DeclarationTVA: No data found for account $account_code in any accounting table");
return array('base_amount' => 0, 'vat_amount' => 0, 'total_amount' => 0); return array('base_amount' => 0, 'vat_amount' => 0, 'total_amount' => 0);
} }

View File

@ -331,13 +331,6 @@ class DeclarationTVA_PDF
$field_data['company_city'] = $mysoc->town; $field_data['company_city'] = $mysoc->town;
$field_data['company_postal_code'] = $mysoc->zip; $field_data['company_postal_code'] = $mysoc->zip;
// Debug: Log company information to see what's available
error_log("DeclarationTVA: Company data - name: " . $mysoc->name);
error_log("DeclarationTVA: Company data - idprof1: " . $mysoc->idprof1);
error_log("DeclarationTVA: Company data - idprof2: " . $mysoc->idprof2);
error_log("DeclarationTVA: Company data - idprof3: " . $mysoc->idprof3);
error_log("DeclarationTVA: Company data - idprof4: " . $mysoc->idprof4);
error_log("DeclarationTVA: Company data - tva_intra: " . $mysoc->tva_intra);
// Try different fields for SIRET - it could be in different idprof fields // Try different fields for SIRET - it could be in different idprof fields
$siret_value = !empty($mysoc->idprof2) ? $mysoc->idprof2 : $siret_value = !empty($mysoc->idprof2) ? $mysoc->idprof2 :
@ -345,10 +338,9 @@ class DeclarationTVA_PDF
(!empty($mysoc->idprof3) ? $mysoc->idprof3 : (!empty($mysoc->idprof3) ? $mysoc->idprof3 :
(!empty($mysoc->idprof4) ? $mysoc->idprof4 : ''))); (!empty($mysoc->idprof4) ? $mysoc->idprof4 : '')));
// If no SIRET found, use a placeholder for testing // If no SIRET found, use a placeholder
if (empty($siret_value)) { if (empty($siret_value)) {
$siret_value = 'SIRET_NOT_CONFIGURED'; $siret_value = 'SIRET_NOT_CONFIGURED';
error_log("DeclarationTVA: No SIRET found in company configuration. Please configure SIRET in Dolibarr company settings.");
} }
$field_data['company_siret'] = $this->formatSiret($siret_value); $field_data['company_siret'] = $this->formatSiret($siret_value);
@ -380,7 +372,6 @@ class DeclarationTVA_PDF
// Debug: Log the CA-3 data structure for troubleshooting // Debug: Log the CA-3 data structure for troubleshooting
if (empty($ca3_data)) { if (empty($ca3_data)) {
error_log("DeclarationTVA: CA-3 data is empty");
// Use test data for debugging // Use test data for debugging
$ca3_data = array( $ca3_data = array(
'A1' => array('vat_amount' => 1000.00), 'A1' => array('vat_amount' => 1000.00),
@ -391,19 +382,8 @@ class DeclarationTVA_PDF
'F1' => array('vat_amount' => 300.00), 'F1' => array('vat_amount' => 300.00),
'F2' => array('vat_amount' => 400.00) 'F2' => array('vat_amount' => 400.00)
); );
error_log("DeclarationTVA: Using test data for debugging");
} else {
error_log("DeclarationTVA: CA-3 data structure: " . print_r($ca3_data, true));
} }
// Debug: Log specific amount field values
error_log("DeclarationTVA: A1_amount will be: " . $this->getCA3LineAmount($ca3_data, 'A1'));
error_log("DeclarationTVA: B08_vat_amount will be: " . $this->getCA3LineAmount($ca3_data, '08', 'vat_amount'));
error_log("DeclarationTVA: B09_vat_amount will be: " . $this->getCA3LineAmount($ca3_data, '09', 'vat_amount'));
error_log("DeclarationTVA: DTD_amount will be: " . $this->getCA3LineAmount($ca3_data, 'TD'));
error_log("DeclarationTVA: D28_amount will be: " . $this->getCA3LineAmount($ca3_data, '28'));
error_log("DeclarationTVA: D29_amount will be: " . $this->getCA3LineAmount($ca3_data, '29'));
error_log("DeclarationTVA: total_vat_collected will be: " . $this->formatAmount($declaration->total_vat_collected));
// Section B: TVA due (Base + VAT columns) // Section B: TVA due (Base + VAT columns)
$field_data['B08_base_amount'] = $this->getCA3LineAmount($ca3_data, '08', 'base_amount'); $field_data['B08_base_amount'] = $this->getCA3LineAmount($ca3_data, '08', 'base_amount');
@ -439,8 +419,6 @@ class DeclarationTVA_PDF
$field_data['net_vat_due'] = $this->formatAmount($declaration->net_vat_due); $field_data['net_vat_due'] = $this->formatAmount($declaration->net_vat_due);
$field_data['vat_credit'] = $this->formatAmount($declaration->vat_credit); $field_data['vat_credit'] = $this->formatAmount($declaration->vat_credit);
// Debug: Log specific D-section fields
error_log("DeclarationTVA: D-section fields - D25: " . $field_data['D25_amount'] . ", D26: " . $field_data['D26_amount'] . ", D27: " . $field_data['D27_amount'] . ", DTD: " . $field_data['DTD_amount'] . ", D28: " . $field_data['D28_amount'] . ", D32: " . $field_data['D32_amount']);
return $field_data; return $field_data;
} }
@ -1154,47 +1132,31 @@ class DeclarationTVA_PDF
private function addDetailedPagesToPDF($pdf_path, $declaration, $ca3_data, $company) private function addDetailedPagesToPDF($pdf_path, $declaration, $ca3_data, $company)
{ {
try { try {
error_log("DeclarationTVA: Starting addDetailedPagesToPDF process");
// 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';
error_log("DeclarationTVA: Temporary detailed PDF path: " . $temp_detailed_path);
$result = $this->generateDetailedPDF($temp_detailed_path, $declaration, $ca3_data, $company); $result = $this->generateDetailedPDF($temp_detailed_path, $declaration, $ca3_data, $company);
if (!$result) { if (!$result) {
error_log("DeclarationTVA: Failed to generate detailed PDF: " . $this->error);
return false; return false;
} }
// Check if detailed PDF was created and has content // Check if detailed PDF was created and has content
if (!file_exists($temp_detailed_path)) { if (!file_exists($temp_detailed_path) || filesize($temp_detailed_path) == 0) {
error_log("DeclarationTVA: Detailed PDF file does not exist at: " . $temp_detailed_path);
return false; return false;
} }
if (filesize($temp_detailed_path) == 0) {
error_log("DeclarationTVA: Detailed PDF file is empty");
return false;
}
error_log("DeclarationTVA: Detailed PDF created successfully, size: " . filesize($temp_detailed_path) . " bytes");
// Use a different approach: use pdftk to merge PDFs (preserves form fields) // Use a different approach: use pdftk to merge PDFs (preserves form fields)
$merge_result = $this->mergePDFsWithPdftk($pdf_path, $temp_detailed_path, $pdf_path); $merge_result = $this->mergePDFsWithPdftk($pdf_path, $temp_detailed_path, $pdf_path);
if (!$merge_result) { if (!$merge_result) {
error_log("DeclarationTVA: Failed to merge PDFs with pdftk: " . $this->error);
// Fallback: try FPDI merge // Fallback: try FPDI merge
$merge_result = $this->mergePDFs($pdf_path, $temp_detailed_path, $pdf_path); $merge_result = $this->mergePDFs($pdf_path, $temp_detailed_path, $pdf_path);
if (!$merge_result) { if (!$merge_result) {
error_log("DeclarationTVA: Failed to merge PDFs with FPDI: " . $this->error);
return false; return false;
} }
} }
error_log("DeclarationTVA: PDFs merged successfully");
// Clean up temporary file // Clean up temporary file
if (file_exists($temp_detailed_path)) { if (file_exists($temp_detailed_path)) {
unlink($temp_detailed_path); unlink($temp_detailed_path);
@ -1204,7 +1166,6 @@ class DeclarationTVA_PDF
} catch (Exception $e) { } catch (Exception $e) {
$this->error = 'Failed to add detailed pages: ' . $e->getMessage(); $this->error = 'Failed to add detailed pages: ' . $e->getMessage();
error_log("DeclarationTVA: Exception in addDetailedPagesToPDF: " . $e->getMessage());
return false; return false;
} }
} }
@ -1226,17 +1187,13 @@ class DeclarationTVA_PDF
return false; return false;
} }
error_log("DeclarationTVA: Starting PDF merge with pdftk - PDF1: " . $pdf1_path . " (size: " . filesize($pdf1_path) . "), PDF2: " . $pdf2_path . " (size: " . filesize($pdf2_path) . ")");
// Use pdftk to merge PDFs (preserves form fields) // Use pdftk to merge PDFs (preserves form fields)
// Create a temporary output file to avoid pdftk input/output filename conflict // Create a temporary output file to avoid pdftk input/output filename conflict
$temp_output_path = tempnam(sys_get_temp_dir(), 'ca3_merged_') . '.pdf'; $temp_output_path = tempnam(sys_get_temp_dir(), 'ca3_merged_') . '.pdf';
$pdftk_path = $this->getPdftkPath(); $pdftk_path = $this->getPdftkPath();
$command = "\"$pdftk_path\" \"$pdf1_path\" \"$pdf2_path\" cat output \"$temp_output_path\""; $command = "\"$pdftk_path\" \"$pdf1_path\" \"$pdf2_path\" cat output \"$temp_output_path\"";
error_log("DeclarationTVA: pdftk command: " . $command);
$result = shell_exec($command . ' 2>&1'); $result = shell_exec($command . ' 2>&1');
error_log("DeclarationTVA: pdftk result: " . $result);
// If pdftk succeeded, copy the merged file to the final output path // If pdftk succeeded, copy the merged file to the final output path
if (file_exists($temp_output_path) && filesize($temp_output_path) > 0) { if (file_exists($temp_output_path) && filesize($temp_output_path) > 0) {
@ -1246,17 +1203,14 @@ 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) {
error_log("DeclarationTVA: PDFs merged successfully with pdftk, size: " . filesize($output_path) . " bytes");
return true; return true;
} else { } else {
$this->error = 'pdftk failed to merge PDFs: ' . $result; $this->error = 'pdftk failed to merge PDFs: ' . $result;
error_log("DeclarationTVA: pdftk merge failed: " . $result);
return false; return false;
} }
} catch (Exception $e) { } catch (Exception $e) {
$this->error = 'Failed to merge PDFs with pdftk: ' . $e->getMessage(); $this->error = 'Failed to merge PDFs with pdftk: ' . $e->getMessage();
error_log("DeclarationTVA: Exception in mergePDFsWithPdftk: " . $e->getMessage());
return false; return false;
} }
} }
@ -1272,14 +1226,11 @@ class DeclarationTVA_PDF
private function mergePDFs($pdf1_path, $pdf2_path, $output_path) private function mergePDFs($pdf1_path, $pdf2_path, $output_path)
{ {
try { try {
error_log("DeclarationTVA: Starting PDF merge - PDF1: " . $pdf1_path . " (size: " . filesize($pdf1_path) . "), PDF2: " . $pdf2_path . " (size: " . filesize($pdf2_path) . ")");
// Use TCPDF-based FPDI // Use TCPDF-based FPDI
$pdf = new \setasign\Fpdi\Tcpdf\Fpdi(); $pdf = new \setasign\Fpdi\Tcpdf\Fpdi();
// Import pages from first PDF // Import pages from first PDF
$page_count1 = $pdf->setSourceFile($pdf1_path); $page_count1 = $pdf->setSourceFile($pdf1_path);
error_log("DeclarationTVA: PDF1 has " . $page_count1 . " pages");
for ($i = 1; $i <= $page_count1; $i++) { for ($i = 1; $i <= $page_count1; $i++) {
$pdf->AddPage(); $pdf->AddPage();
$pdf->useTemplate($pdf->importPage($i)); $pdf->useTemplate($pdf->importPage($i));
@ -1287,7 +1238,6 @@ class DeclarationTVA_PDF
// Import pages from second PDF // Import pages from second PDF
$page_count2 = $pdf->setSourceFile($pdf2_path); $page_count2 = $pdf->setSourceFile($pdf2_path);
error_log("DeclarationTVA: PDF2 has " . $page_count2 . " pages");
for ($i = 1; $i <= $page_count2; $i++) { for ($i = 1; $i <= $page_count2; $i++) {
$pdf->AddPage(); $pdf->AddPage();
$pdf->useTemplate($pdf->importPage($i)); $pdf->useTemplate($pdf->importPage($i));
@ -1296,13 +1246,10 @@ class DeclarationTVA_PDF
// Output merged PDF // Output merged PDF
$pdf->Output($output_path, 'F'); $pdf->Output($output_path, 'F');
error_log("DeclarationTVA: Merged PDF created successfully, size: " . filesize($output_path) . " bytes");
return true; return true;
} catch (Exception $e) { } catch (Exception $e) {
$this->error = 'Failed to merge PDFs: ' . $e->getMessage(); $this->error = 'Failed to merge PDFs: ' . $e->getMessage();
error_log("DeclarationTVA: Exception in mergePDFs: " . $e->getMessage());
return false; return false;
} }
} }