Add special VAT number formatting with custom spacing
- Added formatVatNumber() method for special VAT number formatting - Space between every character - 3 extra spaces after first 2 characters - 43 extra spaces after first 4 characters - Example: FR85489417469 → F R 8 5 4 8 9 4 1 7 4 6 9 - Handles edge cases like empty or short VAT numbers - Cleans input by removing non-alphanumeric characters and converting to uppercase
This commit is contained in:
parent
7300aa7122
commit
1d709ca6f0
@ -302,7 +302,7 @@ class DeclarationTVA_PDF
|
|||||||
|
|
||||||
$field_data['company_siret'] = $this->formatSiret($siret_value);
|
$field_data['company_siret'] = $this->formatSiret($siret_value);
|
||||||
|
|
||||||
$field_data['company_vat_number'] = $mysoc->tva_intra; // VAT number
|
$field_data['company_vat_number'] = $this->formatVatNumber($mysoc->tva_intra); // VAT number
|
||||||
$field_data['declaration_period_start'] = dol_print_date($declaration->start_date, 'day');
|
$field_data['declaration_period_start'] = dol_print_date($declaration->start_date, 'day');
|
||||||
$field_data['declaration_period_end'] = dol_print_date($declaration->end_date, 'day');
|
$field_data['declaration_period_end'] = dol_print_date($declaration->end_date, 'day');
|
||||||
$field_data['declaration_number'] = $declaration->declaration_number;
|
$field_data['declaration_number'] = $declaration->declaration_number;
|
||||||
@ -1107,4 +1107,46 @@ class DeclarationTVA_PDF
|
|||||||
|
|
||||||
return $formatted_main . $formatted_last;
|
return $formatted_main . $formatted_last;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Format VAT number with special spacing
|
||||||
|
* Adds space between every character, with 3 spaces after first 2 chars and 43 spaces after first 4 chars
|
||||||
|
*
|
||||||
|
* @param string $vat_number VAT number
|
||||||
|
* @return string Formatted VAT number
|
||||||
|
*/
|
||||||
|
private function formatVatNumber($vat_number)
|
||||||
|
{
|
||||||
|
// Remove any existing spaces or special characters
|
||||||
|
$vat_number = preg_replace('/[^A-Z0-9]/', '', strtoupper($vat_number));
|
||||||
|
|
||||||
|
// If VAT number is not configured or too short, return as is
|
||||||
|
if (empty($vat_number) || strlen($vat_number) < 4) {
|
||||||
|
return $vat_number;
|
||||||
|
}
|
||||||
|
|
||||||
|
$result = '';
|
||||||
|
$length = strlen($vat_number);
|
||||||
|
|
||||||
|
for ($i = 0; $i < $length; $i++) {
|
||||||
|
$result .= $vat_number[$i];
|
||||||
|
|
||||||
|
// Add space between every character
|
||||||
|
if ($i < $length - 1) {
|
||||||
|
$result .= ' ';
|
||||||
|
}
|
||||||
|
|
||||||
|
// After first 2 characters, add 3 extra spaces
|
||||||
|
if ($i == 1) {
|
||||||
|
$result .= ' ';
|
||||||
|
}
|
||||||
|
|
||||||
|
// After first 4 characters, add 43 extra spaces
|
||||||
|
if ($i == 3) {
|
||||||
|
$result .= str_repeat(' ', 43);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user