$swiss_qr translation & preview

Heya

Thank you so much for implementing a native swiss qr solution!
Two questions:

  • although the configured languages in Ninja is german, the SPC slip is always shown in english?
    (my browser and os is set to be english, but this should have any implications, should it?)
  • in the preview of an invoice (invoice → edit) the SPC is not shown; once downloaded it is included

Any hints?
Best

Hi,

@david any thoughts?

@3tlam

We use this library to generate the full slip

I wasn’t able to find any information on how to localize it, it may be that it is hard coded to en?

yep, but there are translations here
/vendor/sprain/swiss-qr-bill/src/PaymentPart/Translation/Translation.php
thats why I am asking

//edit: any idea why the SPC is not shown in the invoice preview?

sorry for double posting, but maybe my edit was not seen in time?

mh. feels weird to have to keep asking for any comment?
the first one came ultra quickly, but now nothing?

Sorry for the delay, @david can you please advise?

@3tlam

We’ll look into the translations, i can see there is an option to pass the locale in.

Sometimes, if not enough data is present in the invoice preview, the SPC will not display

I believe the preview doesn’t display the SPC because at that point the invoice is not SPC conform? According to the php-swiss-qr-bill code reference generator:

$metadata->addPropertyConstraints('referenceNumber', [
            // Only numbers are allowed (including leading zeros)
            new Assert\Regex([
                'pattern' => '/^\d*$/',
                'match' => true
            ]),
            new Assert\NotBlank()
        ]);

My dirty workaround in app/Helpers/SwissQr/SwissQrGenerator.php now always displays it:

   if(stripos($this->invoice->number, "Live-") === 0)                                                                                                                                                                            
    {                                                                                                                                                                                                                             
       // we're currently in preview status. Let's give a dummy reference for now                                                                                                                                                 
       $invoicenumber = "123456789";                                                                                                                                                                                              
    }                                                                                                                                                                                                                             
    else                                                                                                                                                                                                                          
    {                                                                                                                                                                                                                             
       $invoicenumber = $this->invoice->number;                                                                                                                                                                                   
    }                                                                                                                                                                                                                             
                                                                                                                                                                                                                                  
    if(strlen($this->company->present()->besr_id()) > 1)                                                                                                                                                                          
    {                                                                                                                                                                                                                             
        $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.                                                             
            $invoicenumber // A number to match the payment with your internal data, e.g. an invoice number                                                                                                                        
        );  

Also, if your standard reference number includes anything else but numbers, SPC generation will fail.

I’m not sure if that’s standard conform, since Creditor Reference should also be possible (alphanumeric starting with RF (ISO 11649)). Will check with sprain/php-swiss-qr-bill author.

@aegidel

Thanks for this, I’ve ported your change into the repository for this and it will be available in the next release.

   if(stripos($this->invoice->number, "Live-") === 0)                                                                                                                                                                            
    {                                                                                                                                                                                                                             
       // we're currently in preview status. Let's give a dummy reference for now                                                                                                                                                 
       $invoice_number = "123456789";                                                                                                                                                                                              
    }                                                                                                                                                                                                                             
    else                                                                                                                                                                                                                          
    {                                                                                                                                                                                                                             
       $invoice_number = $this->invoice->number;                                                                                                                                                                                   
    }       

Also:

    // Localize QrBill output according to customer language.                     
    // FIXME: anon array should match potential future translations of sprain/php-swiss-qr-bill
    if (in_array($this->client->locale(), array('en','fr','de','it'))) 
    {                                                                 
         $language = $this->client->locale();                                 
    }                                                                 
    else                                                              
    {                                                                 
         // language not supported, fall back to 'en'                 
         $language = 'en';                                            
    }                                                
                                                                                     
    // Now get the QR code image and save it as a file.
        try {                                          
                                                                                              
            $output = new QrBill\PaymentPart\Output\HtmlOutput\HtmlOutput($qrBill, $language);
                                                                                         

This works for me in order to localize qr bill text data for now.