1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-10 13:12:50 +01:00

Add filters for swiss QR Codes

This commit is contained in:
David Bomba 2022-06-30 20:12:23 +10:00
parent ebf88ab693
commit 716561e22b
3 changed files with 40 additions and 23 deletions

View File

@ -24,11 +24,11 @@ class SwissQrGenerator
protected Company $company;
protected Invoice $invoice;
protected $invoice;
protected Client $client;
public function __construct(Invoice $invoice, Company $company)
public function __construct($invoice, Company $company)
{
$this->company = $company;
@ -86,11 +86,11 @@ class SwissQrGenerator
// They are interchangeable for creditor as well as debtor.
$qrBill->setUltimateDebtor(
QrBill\DataGroup\Element\StructuredAddress::createWithStreet(
$this->client->present()->name(),
$this->client->address1 ?: '',
$this->client->address2 ?: '',
$this->client->postal_code ?: '',
$this->client->city ?: '',
substr($this->client->present()->name(), 0 , 70),
$this->client->address1 ? substr($this->client->address1, 0 , 70) : '',
$this->client->address2 ? substr($this->client->address2, 0 , 16) : '',
$this->client->postal_code ? substr($this->client->postal_code, 0, 16) : '',
$this->client->city ? substr($this->client->postal_code, 0, 35) : '',
'CH'
));
@ -106,7 +106,7 @@ class SwissQrGenerator
// This is what you will need to identify incoming payments.
$referenceNumber = QrBill\Reference\QrPaymentReferenceGenerator::generate(
$this->company->present()->besr_id() ?: '', // You receive this number from your bank (BESR-ID). Unless your bank is PostFinance, in that case use NULL.
$this->invoice->number // A number to match the payment with your internal data, e.g. an invoice number
$this->invoice->number// A number to match the payment with your internal data, e.g. an invoice number
);
$qrBill->setPaymentReference(
@ -124,23 +124,28 @@ class SwissQrGenerator
// Now get the QR code image and save it as a file.
try {
// $qrBill->getQrCode()->writeFile(__DIR__ . '/qr.png');
// $qrBill->getQrCode()->writeFile(__DIR__ . '/qr.svg');
} catch (\Exception $e) {
foreach($qrBill->getViolations() as $key => $violation) {
}
try {
// return $e->getMessage();
}
$output = new QrBill\PaymentPart\Output\HtmlOutput\HtmlOutput($qrBill, 'en');
$output = new QrBill\PaymentPart\Output\HtmlOutput\HtmlOutput($qrBill, 'en');
$html = $output
->setPrintable(false)
->getPaymentPart();
return $html;
} catch (\Exception $e) {
foreach($qrBill->getViolations() as $key => $violation) {
nlog("qr");
nlog($violation);
}
return '';
// return $e->getMessage();
}
$html = $output
->setPrintable(false)
->getPaymentPart();
return $html;
}
}

View File

@ -284,12 +284,11 @@ class PreviewController extends BaseController
}
catch(\Exception $e){
nlog($e->getMessage());
DB::connection(config('database.default'))->rollBack();
return;
}
//if phantom js...... inject here..
if (config('ninja.phantomjs_pdf_generation') || config('ninja.pdf_generator') == 'phantom') {
return (new Phantom)->convertHtmlToPdf($maker->getCompiledHTML(true));

View File

@ -12,6 +12,7 @@
namespace App\Utils;
use App\Helpers\SwissQr\SwissQrGenerator;
use App\Models\Country;
use App\Models\CreditInvitation;
use App\Models\GatewayType;
@ -162,6 +163,17 @@ class HtmlEngine
if($this->entity->vendor) {
$data['$invoice.vendor'] = ['value' => $this->entity->vendor->present()->name(), 'label' => ctrans('texts.vendor_name')];
}
if(strlen($this->company->getSetting('qr_iban')) > 5 && strlen($this->company->getSetting('besr_id')) > 1)
{
try{
$data['$swiss_qr'] = ['value' => (new SwissQrGenerator($this->entity, $this->company))->run(), 'label' => ''];
}
catch(\Exception $e){
$data['$swiss_qr'] = ['value' => '', 'label' => ''];
}
}
}
if ($this->entity_string == 'quote') {
@ -281,6 +293,7 @@ class HtmlEngine
$data['$assigned_to_user'] = ['value' => $this->entity->assigned_user ? $this->entity->assigned_user->present()->name() : '', 'label' => ctrans('texts.name')];
$data['$user_iban'] = ['value' => $this->helpers->formatCustomFieldValue($this->company->custom_fields, 'company1', $this->settings->custom_value1, $this->client) ?: ' ', 'label' => $this->helpers->makeCustomField($this->company->custom_fields, 'company1')];
$data['$invoice.custom1'] = ['value' => $this->helpers->formatCustomFieldValue($this->company->custom_fields, 'invoice1', $this->entity->custom_value1, $this->client) ?: ' ', 'label' => $this->helpers->makeCustomField($this->company->custom_fields, 'invoice1')];
$data['$invoice.custom2'] = ['value' => $this->helpers->formatCustomFieldValue($this->company->custom_fields, 'invoice2', $this->entity->custom_value2, $this->client) ?: ' ', 'label' => $this->helpers->makeCustomField($this->company->custom_fields, 'invoice2')];
$data['$invoice.custom3'] = ['value' => $this->helpers->formatCustomFieldValue($this->company->custom_fields, 'invoice3', $this->entity->custom_value3, $this->client) ?: ' ', 'label' => $this->helpers->makeCustomField($this->company->custom_fields, 'invoice3')];