SEPA EPC codes

This commit is contained in:
David Bomba 2022-11-13 11:13:27 +11:00
parent f54f4b9200
commit acb6b8e579
2 changed files with 23 additions and 2 deletions

View File

@ -45,8 +45,12 @@ class EpcQrGenerator
);
$writer = new Writer($renderer);
$this->validateFields();
$qr = $writer->writeString($this->encodeMessage());
nlog($qr);
return "<svg viewBox='0 0 200 200' width='200' height='200' x='0' y='0' xmlns='http://www.w3.org/2000/svg'>
<rect x='0' y='0' width='100%'' height='100%' />{$qr}</svg>";
@ -60,9 +64,9 @@ class EpcQrGenerator
sprintf('%03d', $this->sepa['version']),
$this->sepa['characterSet'],
$this->sepa['identification'],
$this->sepa['bic'],
isset($this->company?->custom_fields?->company2) ? $this->company->settings->custom_value2 : '',
$this->company->present()->name(),
$this->company?->custom_fields?->company1 ?: '',
isset($this->company?->custom_fields?->company1) ? $this->company->settings->custom_value1 : '',
$this->formatMoney($this->amount),
$this->sepa['purpose'],
substr($this->invoice->number,0,34),
@ -72,6 +76,17 @@ class EpcQrGenerator
}
private function validateFields()
{
if(isset($this->company?->custom_fields?->company2))
nlog('The BIC field is not present and _may_ be a required fields for EPC QR codes');
if(isset($this->company?->custom_fields?->company1))
nlog('The IBAN field is required');
}
private function formatMoney($value) {
return sprintf('EUR%s', number_format($value, 2, '.', ''));
}

View File

@ -12,6 +12,7 @@
namespace App\Utils;
use App\Helpers\Epc\EpcQrGenerator;
use App\Helpers\SwissQr\SwissQrGenerator;
use App\Models\Country;
use App\Models\CreditInvitation;
@ -581,6 +582,11 @@ class HtmlEngine
$data['$payments'] = ['value' => $payment_list, 'label' => ctrans('texts.payments')];
}
if($this->entity_string == 'invoice' && isset($this->company?->custom_fields?->company1))
{
$data['$sepa_qr_code'] = ['value' => (new EpcQrGenerator($this->company, $this->entity,$data['$amount_raw']['value']))->getQrCode(), 'label' => ''];
}
$arrKeysLength = array_map('strlen', array_keys($data));
array_multisort($arrKeysLength, SORT_DESC, $data);