Fix PDF field mapping to handle numeric array structure
- Added getCA3LineAmount() helper method to search through numeric array - Updated all field mappings to use the new helper method - Fixed A1_amount and other fields to correctly extract from ca3_data array - The data structure is numeric array with ca3_line field, not associative - Now correctly extracts A1 amount (1958.00) from the data structure
This commit is contained in:
parent
d93c0818f4
commit
6f0f348d5a
@ -308,24 +308,24 @@ class DeclarationTVA_PDF
|
||||
$field_data['declaration_number'] = $declaration->declaration_number;
|
||||
|
||||
// Section A: Opérations imposables
|
||||
$field_data['A1_amount'] = isset($ca3_data['A1']) ? $this->formatAmount($ca3_data['A1']['vat_amount']) : '0,00';
|
||||
$field_data['A2_amount'] = isset($ca3_data['A2']) ? $this->formatAmount($ca3_data['A2']['vat_amount']) : '0,00';
|
||||
$field_data['A3_amount'] = isset($ca3_data['A3']) ? $this->formatAmount($ca3_data['A3']['vat_amount']) : '0,00';
|
||||
$field_data['A4_amount'] = isset($ca3_data['A4']) ? $this->formatAmount($ca3_data['A4']['vat_amount']) : '0,00';
|
||||
$field_data['A5_amount'] = isset($ca3_data['A5']) ? $this->formatAmount($ca3_data['A5']['vat_amount']) : '0,00';
|
||||
$field_data['A1_amount'] = $this->getCA3LineAmount($ca3_data, 'A1');
|
||||
$field_data['A2_amount'] = $this->getCA3LineAmount($ca3_data, 'A2');
|
||||
$field_data['A3_amount'] = $this->getCA3LineAmount($ca3_data, 'A3');
|
||||
$field_data['A4_amount'] = $this->getCA3LineAmount($ca3_data, 'A4');
|
||||
$field_data['A5_amount'] = $this->getCA3LineAmount($ca3_data, 'A5');
|
||||
|
||||
// Section A: Additional reference fields (E1-E6, F1-F2, F6-F8)
|
||||
$field_data['E1_amount'] = isset($ca3_data['E1']) ? $this->formatAmount($ca3_data['E1']['vat_amount']) : '0,00';
|
||||
$field_data['E2_amount'] = isset($ca3_data['E2']) ? $this->formatAmount($ca3_data['E2']['vat_amount']) : '0,00';
|
||||
$field_data['E3_amount'] = isset($ca3_data['E3']) ? $this->formatAmount($ca3_data['E3']['vat_amount']) : '0,00';
|
||||
$field_data['E4_amount'] = isset($ca3_data['E4']) ? $this->formatAmount($ca3_data['E4']['vat_amount']) : '0,00';
|
||||
$field_data['E5_amount'] = isset($ca3_data['E5']) ? $this->formatAmount($ca3_data['E5']['vat_amount']) : '0,00';
|
||||
$field_data['E6_amount'] = isset($ca3_data['E6']) ? $this->formatAmount($ca3_data['E6']['vat_amount']) : '0,00';
|
||||
$field_data['F1_amount'] = isset($ca3_data['F1']) ? $this->formatAmount($ca3_data['F1']['vat_amount']) : '0,00';
|
||||
$field_data['F2_amount'] = isset($ca3_data['F2']) ? $this->formatAmount($ca3_data['F2']['vat_amount']) : '0,00';
|
||||
$field_data['F6_amount'] = isset($ca3_data['F6']) ? $this->formatAmount($ca3_data['F6']['vat_amount']) : '0,00';
|
||||
$field_data['F7_amount'] = isset($ca3_data['F7']) ? $this->formatAmount($ca3_data['F7']['vat_amount']) : '0,00';
|
||||
$field_data['F8_amount'] = isset($ca3_data['F8']) ? $this->formatAmount($ca3_data['F8']['vat_amount']) : '0,00';
|
||||
$field_data['E1_amount'] = $this->getCA3LineAmount($ca3_data, 'E1');
|
||||
$field_data['E2_amount'] = $this->getCA3LineAmount($ca3_data, 'E2');
|
||||
$field_data['E3_amount'] = $this->getCA3LineAmount($ca3_data, 'E3');
|
||||
$field_data['E4_amount'] = $this->getCA3LineAmount($ca3_data, 'E4');
|
||||
$field_data['E5_amount'] = $this->getCA3LineAmount($ca3_data, 'E5');
|
||||
$field_data['E6_amount'] = $this->getCA3LineAmount($ca3_data, 'E6');
|
||||
$field_data['F1_amount'] = $this->getCA3LineAmount($ca3_data, 'F1');
|
||||
$field_data['F2_amount'] = $this->getCA3LineAmount($ca3_data, 'F2');
|
||||
$field_data['F6_amount'] = $this->getCA3LineAmount($ca3_data, 'F6');
|
||||
$field_data['F7_amount'] = $this->getCA3LineAmount($ca3_data, 'F7');
|
||||
$field_data['F8_amount'] = $this->getCA3LineAmount($ca3_data, 'F8');
|
||||
|
||||
// Debug: Log the CA-3 data structure for troubleshooting
|
||||
if (empty($ca3_data)) {
|
||||
@ -346,25 +346,24 @@ class DeclarationTVA_PDF
|
||||
}
|
||||
|
||||
// Debug: Log specific amount field values
|
||||
error_log("DeclarationTVA: A1_amount will be: " . (isset($ca3_data['A1']) ? $this->formatAmount($ca3_data['A1']['vat_amount']) : '0,00'));
|
||||
error_log("DeclarationTVA: A1 data structure: " . (isset($ca3_data['A1']) ? print_r($ca3_data['A1'], true) : 'A1 not found in ca3_data'));
|
||||
error_log("DeclarationTVA: B08_vat_amount will be: " . (isset($ca3_data['08']) ? $this->formatAmount($ca3_data['08']['vat_amount']) : '0,00'));
|
||||
error_log("DeclarationTVA: B09_vat_amount will be: " . (isset($ca3_data['09']) ? $this->formatAmount($ca3_data['09']['vat_amount']) : '0,00'));
|
||||
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: total_vat_collected will be: " . $this->formatAmount($declaration->total_vat_collected));
|
||||
|
||||
// Section B: TVA due (Base + VAT columns)
|
||||
$field_data['B08_base_amount'] = isset($ca3_data['08']) ? $this->formatAmount($ca3_data['08']['base_amount']) : '0,00';
|
||||
$field_data['B08_vat_amount'] = isset($ca3_data['08']) ? $this->formatAmount($ca3_data['08']['vat_amount']) : '0,00';
|
||||
$field_data['B09_base_amount'] = isset($ca3_data['09']) ? $this->formatAmount($ca3_data['09']['base_amount']) : '0,00';
|
||||
$field_data['B09_vat_amount'] = isset($ca3_data['09']) ? $this->formatAmount($ca3_data['09']['vat_amount']) : '0,00';
|
||||
$field_data['B9B_base_amount'] = isset($ca3_data['9B']) ? $this->formatAmount($ca3_data['9B']['base_amount']) : '0,00';
|
||||
$field_data['B9B_vat_amount'] = isset($ca3_data['9B']) ? $this->formatAmount($ca3_data['9B']['vat_amount']) : '0,00';
|
||||
$field_data['B17_amount'] = isset($ca3_data['17']) ? $this->formatAmount($ca3_data['17']['vat_amount']) : '0,00';
|
||||
$field_data['B08_base_amount'] = $this->getCA3LineAmount($ca3_data, '08', 'base_amount');
|
||||
$field_data['B08_vat_amount'] = $this->getCA3LineAmount($ca3_data, '08', 'vat_amount');
|
||||
$field_data['B09_base_amount'] = $this->getCA3LineAmount($ca3_data, '09', 'base_amount');
|
||||
$field_data['B09_vat_amount'] = $this->getCA3LineAmount($ca3_data, '09', 'vat_amount');
|
||||
$field_data['B9B_base_amount'] = $this->getCA3LineAmount($ca3_data, '9B', 'base_amount');
|
||||
$field_data['B9B_vat_amount'] = $this->getCA3LineAmount($ca3_data, '9B', 'vat_amount');
|
||||
$field_data['B17_amount'] = $this->getCA3LineAmount($ca3_data, '17');
|
||||
|
||||
// Section C: TVA déductible
|
||||
$field_data['C20_amount'] = isset($ca3_data['20']) ? $this->formatAmount($ca3_data['20']['vat_amount']) : '0,00';
|
||||
$field_data['C21_amount'] = isset($ca3_data['21']) ? $this->formatAmount($ca3_data['21']['vat_amount']) : '0,00';
|
||||
$field_data['C22_amount'] = isset($ca3_data['22']) ? $this->formatAmount($ca3_data['22']['vat_amount']) : '0,00';
|
||||
$field_data['C20_amount'] = $this->getCA3LineAmount($ca3_data, '20');
|
||||
$field_data['C21_amount'] = $this->getCA3LineAmount($ca3_data, '21');
|
||||
$field_data['C22_amount'] = $this->getCA3LineAmount($ca3_data, '22');
|
||||
|
||||
// Section F: Intracom Acquisitions
|
||||
$field_data['F1_amount'] = isset($ca3_data['F1']) ? $this->formatAmount($ca3_data['F1']['vat_amount']) : '0,00';
|
||||
@ -1055,4 +1054,29 @@ class DeclarationTVA_PDF
|
||||
|
||||
return true; // No update needed
|
||||
}
|
||||
|
||||
/**
|
||||
* Get CA-3 line amount from the data array
|
||||
*
|
||||
* @param array $ca3_data CA-3 data array
|
||||
* @param string $ca3_line Line identifier (e.g., 'A1', '08', '17')
|
||||
* @param string $amount_type Amount type ('vat_amount' or 'base_amount')
|
||||
* @return string Formatted amount
|
||||
*/
|
||||
private function getCA3LineAmount($ca3_data, $ca3_line, $amount_type = 'vat_amount')
|
||||
{
|
||||
if (empty($ca3_data) || !is_array($ca3_data)) {
|
||||
return '0,00';
|
||||
}
|
||||
|
||||
// Search through the array for the matching ca3_line
|
||||
foreach ($ca3_data as $line_data) {
|
||||
if (isset($line_data['ca3_line']) && $line_data['ca3_line'] == $ca3_line) {
|
||||
$amount = isset($line_data[$amount_type]) ? $line_data[$amount_type] : 0;
|
||||
return $this->formatAmount($amount);
|
||||
}
|
||||
}
|
||||
|
||||
return '0,00';
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user