Skip to content

Commit

Permalink
Merge branch 'master' into symfony-7
Browse files Browse the repository at this point in the history
  • Loading branch information
sprain committed Nov 23, 2023
2 parents a9de53f + eb68c11 commit 83abba1
Show file tree
Hide file tree
Showing 39 changed files with 1,848 additions and 1,789 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

[![Build Status](https://github.com/sprain/php-swiss-qr-bill/actions/workflows/ci.yml/badge.svg)](https://github.com/sprain/php-swiss-qr-bill/actions)

A PHP library to create Swiss QR Bill payment parts (_QR-Rechnung_) which fully replaced the red and orange payment slips by September 30, 2022.
A PHP library to create Swiss QR Bill payment parts (_QR-Rechnung_).

![Image of Swiss QR Bill example](docs/assets/example-payment-part.png)

Expand All @@ -20,7 +20,7 @@ Then have a look at [example/example.php](example/example.php).
A typical QR bill ([example](https://github.com/sprain/php-swiss-qr-bill/blob/master/example/example.php)) requires a special QR IBAN. You can get yours from your bank. A classic IBAN can be used for QR bills with a SCOR reference ([example](https://github.com/sprain/php-swiss-qr-bill/blob/master/example/example_scor.php)) or no reference number at all ([example](https://github.com/sprain/php-swiss-qr-bill/blob/master/example/example_minimal.php)).

* **How do I recognize a QR IBAN?**<br>
In a QR IBAN, the *institute id*, which is defined in the 5th to 9th character, is a number in the range of 30000 to 31999. (Example: CH44 **3199 9**123 0008 8901 2). For how detect it in code, see https://github.com/sprain/php-swiss-qr-bill/issues/182#issuecomment-1229539977
In a QR IBAN, the *institute id*, which is defined in the 5th to 9th character, is a number in the range of 30000 to 31999. (Example: CH44 **3199 9**123 0008 8901 2). For how to detect it in code, see https://github.com/sprain/php-swiss-qr-bill/issues/182#issuecomment-1229539977

* **How do I create QR bills for international IBANs?**<br>
You can't. The QR bill by specification only supports IBANs from Switzerland and Liechtenstein.
Expand Down
2 changes: 1 addition & 1 deletion example/example.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
// Add debtor information
// Who has to pay the invoice? This part is optional.
//
// Notice how you can use two different styles of addresses: CombinedAddress or StructuredAddress.
// Note how you can use two different styles of addresses: CombinedAddress or StructuredAddress.
// They are interchangeable for creditor as well as debtor.
$qrBill->setUltimateDebtor(
QrBill\DataGroup\Element\StructuredAddress::createWithStreet(
Expand Down
18 changes: 18 additions & 0 deletions src/DataGroup/EmptyElement/EmptyLine.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php declare(strict_types=1);

namespace Sprain\SwissQrBill\DataGroup\EmptyElement;

use Sprain\SwissQrBill\DataGroup\QrCodeableInterface;

/**
* @internal
*/
final class EmptyLine implements QrCodeableInterface
{
public function getQrCodeData(): array
{
return [
null
];
}
}
133 changes: 67 additions & 66 deletions src/PaymentPart/Output/HtmlOutput/Template/PaymentPartTemplate.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ class PaymentPartTemplate
public const TEMPLATE = <<<EOT
<style>
#qr-bill {
box-sizing: border-box;
border-collapse: collapse;
color: #000 !important;
box-sizing: border-box;
border-collapse: collapse;
color: #000 !important;
}
#qr-bill * {
font-family: Arial, Frutiger, Helvetica, "Liberation Sans" !important;
font-family: Arial, Frutiger, Helvetica, "Liberation Sans" !important;
}
#qr-bill img.qr-bill-placeholder {
Expand All @@ -24,92 +24,93 @@ class PaymentPartTemplate
text-align: center;
font-size: 8pt !important;
line-height: 9pt;
border-bottom: 0.75pt solid black;
height: 5mm;
vertical-align: middle;
border-bottom: 0.75pt solid black;
height: 5mm;
vertical-align: middle;
}
/* h1 / h2 */
#qr-bill h1 {
font-size: 11pt !important;
font-weight: bold !important;
margin: 0;
padding: 0;
height: 7mm;
color: #000 !important;
font-size: 11pt !important;
line-height: 13pt !important;
font-weight: bold !important;
margin: 0 !important;
padding: 0 !important;
height: 7mm !important;
color: #000 !important;
}
#qr-bill h2 {
font-weight: bold !important;
margin: 0;
padding: 0;
color: #000 !important;
font-weight: bold !important;
margin: 0 !important;
padding: 0 !important;
color: #000 !important;
}
#qr-bill-payment-part h2 {
font-size: 8pt !important;
line-height: 11pt !important;
margin-top: 11pt;
color: #000 !important;
font-size: 8pt !important;
line-height: 11pt !important;
margin-top: 11pt !important;
color: #000 !important;
}
#qr-bill-receipt h2 {
font-size: 6pt !important;
line-height: 8pt !important;
margin-top: 8pt;
color: #000 !important;
font-size: 6pt !important;
line-height: 8pt !important;
margin-top: 8pt !important;
color: #000 !important;
}
#qr-bill-payment-part h2:first-child,
#qr-bill-receipt h2:first-child {
margin-top: 0;
color: #000 !important;
margin-top: 0 !important;
color: #000 !important;
}
/* p */
#qr-bill p {
font-weight: normal !important;
margin: 0;
padding: 0;
color: #000 !important;
font-weight: normal !important;
margin: 0 !important;
padding: 0 !important;
color: #000 !important;
}
#qr-bill-receipt p {
font-size: 8pt !important;
line-height: 9pt !important;
color: #000 !important;
font-size: 8pt !important;
line-height: 9pt !important;
color: #000 !important;
}
#qr-bill-payment-part p {
font-size: 10pt !important;
line-height: 11pt !important;
color: #000 !important;
font-size: 10pt !important;
line-height: 11pt !important;
color: #000 !important;
}
#qr-bill-amount-area-receipt p{
line-height: 11pt !important;
color: #000 !important;
color: #000 !important;
}
#qr-bill-amount-area p{
line-height: 13pt !important;
color: #000 !important;
color: #000 !important;
}
#qr-bill-payment-further-information p {
font-size: 7pt !important;
line-height: 9pt !important;
color: #000 !important;
color: #000 !important;
}
/* Receipt */
#qr-bill-receipt {
box-sizing: border-box;
width: 62mm;
border-right: 0.2mm solid black;
padding-left: 5mm;
padding-top: 5mm;
vertical-align: top;
border-right: 0.2mm solid black;
padding-left: 5mm;
padding-top: 5mm;
vertical-align: top;
}
#qr-bill-information-receipt {
Expand All @@ -121,8 +122,8 @@ class PaymentPartTemplate
}
#qr-bill-currency-receipt {
float: left;
margin-right: 2mm;
float: left;
margin-right: 2mm;
}
#qr-bill-acceptance-point {
Expand All @@ -141,10 +142,10 @@ class PaymentPartTemplate
#qr-bill-payment-part {
box-sizing: border-box;
width: 148mm;
padding-left: 5mm;
padding-top: 5mm;
padding-right: 5mm;
vertical-align: top;
padding-left: 5mm;
padding-top: 5mm;
padding-right: 5mm;
vertical-align: top;
}
#qr-bill-payment-part-left {
Expand All @@ -154,19 +155,19 @@ class PaymentPartTemplate
}
#qr-bill-swiss-qr-image {
width: 46mm;
height: 46mm;
margin: 5mm;
margin-left: 0;
width: 46mm;
height: 46mm;
margin: 5mm;
margin-left: 0;
}
#qr-bill-amount-area {
height: 22mm;
}
#qr-bill-currency {
float: left;
margin-right: 2mm;
float: left;
margin-right: 2mm;
}
#qr-bill-payment-further-information {
Expand All @@ -185,10 +186,10 @@ class PaymentPartTemplate
<tr id="qr-bill-separate-info">
<td colspan="99"><span id="qr-bill-separate-info-text">{{ text.separate }}</span></td>
</tr>
<tr>
<td id="qr-bill-receipt">
<h1>{{ text.receipt }}</h1>
<div id="qr-bill-information-receipt">
<tr>
<td id="qr-bill-receipt">
<h1>{{ text.receipt }}</h1>
<div id="qr-bill-information-receipt">
{{ information-content-receipt }}
</div>
<div id="qr-bill-amount-area-receipt">
Expand Down Expand Up @@ -216,17 +217,17 @@ class PaymentPartTemplate
{{ amount-content }}
</div>
</div>
</div>
<div id="qr-bill-payment-part-right">
</div>
<div id="qr-bill-payment-part-right">
<div id="qr-bill-information">
{{ information-content }}
</div>
</div>
<div id="qr-bill-payment-further-information">
{{ further-information-content }}
</div>
<div id="qr-bill-payment-further-information">
{{ further-information-content }}
</div>
</td>
</tr>
</tr>
</table>
EOT;
}
13 changes: 13 additions & 0 deletions src/QrBill.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use Sprain\SwissQrBill\DataGroup\Element\PaymentReference;
use Sprain\SwissQrBill\DataGroup\EmptyElement\EmptyAdditionalInformation;
use Sprain\SwissQrBill\DataGroup\EmptyElement\EmptyAddress;
use Sprain\SwissQrBill\DataGroup\EmptyElement\EmptyLine;
use Sprain\SwissQrBill\DataGroup\QrCodeableInterface;
use Sprain\SwissQrBill\Exception\InvalidQrBillDataException;
use Sprain\SwissQrBill\QrCode\QrCode;
Expand Down Expand Up @@ -189,6 +190,7 @@ private function getQrCodeContent(): string
$this->getUltimateDebtor() ?: new EmptyAddress(),
$this->getPaymentReference(),
$this->getAdditionalInformation() ?: new EmptyAdditionalInformation(),
$this->getPossibleEmptyLine(),
$this->getAlternativeSchemes()
];

Expand All @@ -197,6 +199,17 @@ private function getQrCodeContent(): string
return implode("\n", $qrCodeStringElements);
}

private function getPossibleEmptyLine(): ?EmptyLine
{
if ($this->getAlternativeSchemes()) {
if (null === $this->getAdditionalInformation()?->getBillInformation()) {
return new EmptyLine();
}
}

return null;
}

/**
* @param list<QrCodeableInterface|AddressInterface|list<AddressInterface|QrCodeableInterface>> $elements
* @return list<string|int|null>
Expand Down
Binary file modified tests/TestData/FpdfOutput/qr-alternative-schemes.pdf
Binary file not shown.
Binary file modified tests/TestData/FpdfOutput/qr-alternative-schemes.print.pdf
Binary file not shown.
Loading

0 comments on commit 83abba1

Please sign in to comment.