Process Invoice Numbers which includes letters

-Using custom Invoice Number Patterns like R-ABC-P224301 breaks the QR Bill Generation
-This solution loops through the Invoice Number and translates letter into ASCII
-Makes sure that the field Additional Information not shows the wrong content
This commit is contained in:
checkitsedo 2022-10-30 23:27:16 +01:00 committed by GitHub
parent 577f2a4809
commit b2e3ea53d0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -112,7 +112,34 @@ class SwissQrGenerator
}
else
{
$invoice_number = $this->invoice->number;
$tempInvoiceNumber = $this->invoice->number;
$tempInvoiceNumber = preg_replace('/[^A-Za-z0-9]/', '', $tempInvoiceNumber);
$tempInvoiceNumber = substr($tempInvoiceNumber, 1);
$calcInvoiceNumber = "";
$array = str_split($tempInvoiceNumber);
foreach($array as $char)
{
if (is_numeric($char))
{
//
}
else
{
if ($char)
{
$char = strtolower($char);
$char = ord($char) - 96;
}
else
{
return 0;
}
}
$calcInvoiceNumber .= $char;
}
$invoice_number = $calcInvoiceNumber;
}
if(strlen($this->company->present()->besr_id()) > 1)
@ -141,7 +168,7 @@ class SwissQrGenerator
// Optionally, add some human-readable information about what the bill is for.
$qrBill->setAdditionalInformation(
QrBill\DataGroup\Element\AdditionalInformation::create(
$this->invoice->public_notes ? substr($this->invoice->public_notes, 0, 139) : ctrans('texts.invoice_number_placeholder', ['invoice' => $invoice_number])
$this->invoice->public_notes ? substr($this->invoice->public_notes, 0, 139) : ctrans('texts.invoice_number_placeholder', ['invoice' => $this->invoice->number])
)
);