diff --git a/app/Helpers/Epc/EpcQrGenerator.php b/app/Helpers/Epc/EpcQrGenerator.php index adf36dc83887..457fb24550d3 100644 --- a/app/Helpers/Epc/EpcQrGenerator.php +++ b/app/Helpers/Epc/EpcQrGenerator.php @@ -45,8 +45,12 @@ class EpcQrGenerator ); $writer = new Writer($renderer); + $this->validateFields(); + $qr = $writer->writeString($this->encodeMessage()); + nlog($qr); + return " {$qr}"; @@ -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, '.', '')); } diff --git a/app/Utils/HtmlEngine.php b/app/Utils/HtmlEngine.php index f800b6db41a5..a022d5e1642e 100644 --- a/app/Utils/HtmlEngine.php +++ b/app/Utils/HtmlEngine.php @@ -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);