Add special SIRET formatting with spaces
- Added formatSiret() method for special SIRET formatting - Spaces between every character in main part - Extra space before last 5 characters - Example: 48941746900033 → 4 8 9 4 1 7 4 6 9 0 0 0 3 3 - Handles edge cases like SIRET_NOT_CONFIGURED - Cleans input by removing non-numeric characters
This commit is contained in:
parent
3155ec7078
commit
83cc9016ea
@ -300,7 +300,7 @@ class DeclarationTVA_PDF
|
||||
error_log("DeclarationTVA: No SIRET found in company configuration. Please configure SIRET in Dolibarr company settings.");
|
||||
}
|
||||
|
||||
$field_data['company_siret'] = $siret_value;
|
||||
$field_data['company_siret'] = $this->formatSiret($siret_value);
|
||||
|
||||
$field_data['company_vat_number'] = $mysoc->tva_intra; // VAT number
|
||||
$field_data['declaration_period_start'] = dol_print_date($declaration->start_date, 'day');
|
||||
@ -1077,4 +1077,34 @@ class DeclarationTVA_PDF
|
||||
|
||||
return '0,00';
|
||||
}
|
||||
|
||||
/**
|
||||
* Format SIRET number with special spacing
|
||||
* Adds space between every character, with extra space before last 5 characters
|
||||
*
|
||||
* @param string $siret SIRET number
|
||||
* @return string Formatted SIRET
|
||||
*/
|
||||
private function formatSiret($siret)
|
||||
{
|
||||
// Remove any existing spaces or special characters
|
||||
$siret = preg_replace('/[^0-9]/', '', $siret);
|
||||
|
||||
// If SIRET is not configured or too short, return as is
|
||||
if (empty($siret) || $siret === 'SIRET_NOT_CONFIGURED' || strlen($siret) < 5) {
|
||||
return $siret;
|
||||
}
|
||||
|
||||
// Split into parts: main part and last 5 characters
|
||||
$main_part = substr($siret, 0, -5);
|
||||
$last_5 = substr($siret, -5);
|
||||
|
||||
// Add space between every character in main part
|
||||
$formatted_main = implode(' ', str_split($main_part));
|
||||
|
||||
// Add space between every character in last 5, with extra space before
|
||||
$formatted_last = ' ' . implode(' ', str_split($last_5));
|
||||
|
||||
return $formatted_main . $formatted_last;
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user