Fixes for peppol

This commit is contained in:
David Bomba
2026-01-24 12:06:28 +11:00
parent b5622df85b
commit b74e24382c
3 changed files with 407 additions and 3 deletions

View File

@@ -1407,11 +1407,13 @@ class Peppol extends AbstractService
$party->PartyIdentification[] = $pi;
$pts = new \InvoiceNinja\EInvoice\Models\Peppol\PartyTaxSchemeType\PartyTaxScheme();
//// If this is intracommunity supply, ensure that the country prefix is on the party tax scheme
$pts = new \InvoiceNinja\EInvoice\Models\Peppol\PartyTaxSchemeType\PartyTaxScheme();
$companyID = new \InvoiceNinja\EInvoice\Models\Peppol\IdentifierType\CompanyID();
$companyID->value = preg_replace("/[^a-zA-Z0-9]/", "", $this->invoice->client->vat_number);
$companyID->value = $this->ensureVatNumberPrefix($this->invoice->client->vat_number, $this->invoice->client->country->iso_3166_2);
$pts->CompanyID = $companyID;
//// If this is intracommunity supply, ensure that the country prefix is on the party tax scheme
$ts = new TaxScheme();
$id = new ID();
@@ -1920,6 +1922,30 @@ class Peppol extends AbstractService
return '0037';
}
/**
* Ensures the VAT number has the correct country code prefix.
*
* @param string $vatNumber The raw VAT number.
* @param string $countryCode The 2-letter ISO country code.
* @return string The formatted VAT number with prefix.
*/
private function ensureVatNumberPrefix(string $vatNumber, string $countryCode): string
{
// Clean the VAT number by removing non-alphanumeric characters
$cleanedVat = preg_replace("/[^a-zA-Z0-9]/", "", $vatNumber);
// Handle Greece special case
$prefix = ($countryCode === 'GR') ? 'EL' : $countryCode;
// Check if the VAT number already starts with the correct prefix
if (str_starts_with(strtoupper($cleanedVat), $prefix)) {
return $cleanedVat;
}
// Prepend the prefix if it's missing
return $prefix . $cleanedVat;
}
public function getErrors(): array
{
return $this->errors;

View File

@@ -161,7 +161,7 @@ class TemplateService
$this->twig->addFilter($filter);
$allowedTags = ['if', 'for', 'set', 'filter'];
$allowedFilters = ['default', 'groupBy','capitalize', 'abs', 'date_modify', 'keys', 'join', 'reduce', 'format_date','json_decode','date_modify','trim','round','format_spellout_number','split', 'reduce','replace', 'escape', 'e', 'reverse', 'shuffle', 'slice', 'batch', 'title', 'sort', 'split', 'upper', 'lower', 'capitalize', 'filter', 'length', 'merge','format_currency', 'format_number','format_percent_number','map', 'join', 'first', 'date', 'sum', 'number_format','nl2br','striptags','markdown_to_html'];
$allowedFilters = ['url_encode','default', 'groupBy','capitalize', 'abs', 'date_modify', 'keys', 'join', 'reduce', 'format_date','json_decode','date_modify','trim','round','format_spellout_number','split', 'reduce','replace', 'escape', 'e', 'reverse', 'shuffle', 'slice', 'batch', 'title', 'sort', 'split', 'upper', 'lower', 'capitalize', 'filter', 'length', 'merge','format_currency', 'format_number','format_percent_number','map', 'join', 'first', 'date', 'sum', 'number_format','nl2br','striptags','markdown_to_html'];
$allowedFunctions = ['range', 'cycle', 'constant', 'date','img','t'];
$allowedProperties = ['type_id'];
// $allowedMethods = ['img','t'];