|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Sprain\SwissQrBill\PaymentPart\Output; |
|
4
|
|
|
|
|
5
|
|
|
use Sprain\SwissQrBill\DataGroup\Element\PaymentReference; |
|
6
|
|
|
use Sprain\SwissQrBill\PaymentPart\Output\Element\Placeholder; |
|
7
|
|
|
use Sprain\SwissQrBill\PaymentPart\Output\Element\Text; |
|
8
|
|
|
use Sprain\SwissQrBill\PaymentPart\Output\Element\Title; |
|
9
|
|
|
use Sprain\SwissQrBill\QrBill; |
|
10
|
|
|
use Sprain\SwissQrBill\QrCode\QrCode; |
|
11
|
|
|
|
|
12
|
|
|
abstract class AbstractOutput |
|
13
|
|
|
{ |
|
14
|
|
|
/** @var QrBill */ |
|
15
|
|
|
protected $qrBill; |
|
16
|
|
|
|
|
17
|
|
|
/** @var string */ |
|
18
|
|
|
protected $language; |
|
19
|
|
|
|
|
20
|
|
|
/** @var bool */ |
|
21
|
|
|
protected $printable; |
|
22
|
|
|
|
|
23
|
|
|
/** @var string */ |
|
24
|
|
|
private $qrCodeImageFormat; |
|
25
|
|
|
|
|
26
|
|
|
public function __construct(QrBill $qrBill, string $language) |
|
27
|
|
|
{ |
|
28
|
|
|
$this->qrBill = $qrBill; |
|
29
|
|
|
$this->language = $language; |
|
30
|
|
|
$this->printable = false; |
|
31
|
|
|
$this->qrCodeImageFormat = QrCode::FILE_FORMAT_SVG; |
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
|
|
public function getQrBill(): ?QrBill |
|
35
|
|
|
{ |
|
36
|
|
|
return $this->qrBill; |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
public function getLanguage(): ?string |
|
40
|
|
|
{ |
|
41
|
|
|
return $this->language; |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
public function setPrintable(bool $printable): self |
|
45
|
|
|
{ |
|
46
|
|
|
$this->printable = $printable; |
|
47
|
|
|
|
|
48
|
|
|
return $this; |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
public function isPrintable(): bool |
|
52
|
|
|
{ |
|
53
|
|
|
return $this->printable; |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
public function setQrCodeImageFormat(string $fileExtension): self |
|
57
|
|
|
{ |
|
58
|
|
|
$this->qrCodeImageFormat = $fileExtension; |
|
59
|
|
|
|
|
60
|
|
|
return $this; |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
public function getQrCodeImageFormat(): string |
|
64
|
|
|
{ |
|
65
|
|
|
return $this->qrCodeImageFormat; |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
protected function getInformationElements(): array |
|
69
|
|
|
{ |
|
70
|
|
|
$informationElements = []; |
|
71
|
|
|
|
|
72
|
|
|
$informationElements[] = Title::create('text.creditor'); |
|
73
|
|
|
$informationElements[] = Text::create($this->qrBill->getCreditorInformation()->getFormattedIban() . "\n" . $this->qrBill->getCreditor()->getFullAddress()); |
|
74
|
|
|
|
|
75
|
|
|
if ($this->qrBill->getPaymentReference()->getType() !== PaymentReference::TYPE_NON) { |
|
76
|
|
|
$informationElements[] = Title::create('text.reference'); |
|
77
|
|
|
$informationElements[] = Text::create($this->qrBill->getPaymentReference()->getFormattedReference()); |
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
|
|
if ($this->qrBill->getAdditionalInformation()) { |
|
81
|
|
|
$informationElements[] = Title::create('text.additionalInformation'); |
|
82
|
|
|
$informationElements[] = Text::create($this->qrBill->getAdditionalInformation()->getFormattedString()); |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
|
if ($this->qrBill->getUltimateDebtor()) { |
|
86
|
|
|
$informationElements[] = Title::create('text.payableBy'); |
|
87
|
|
|
$informationElements[] = Text::create($this->qrBill->getUltimateDebtor()->getFullAddress()); |
|
88
|
|
|
} else { |
|
89
|
|
|
$informationElements[] = Title::create('text.payableByName'); |
|
90
|
|
|
$informationElements[] = Placeholder::create(Placeholder::PLACEHOLDER_TYPE_PAYABLE_BY); |
|
91
|
|
|
} |
|
92
|
|
|
|
|
93
|
|
|
return $informationElements; |
|
94
|
|
|
} |
|
95
|
|
|
|
|
96
|
|
|
protected function getInformationElementsOfReceipt(): array |
|
97
|
|
|
{ |
|
98
|
|
|
$informationElements = []; |
|
99
|
|
|
|
|
100
|
|
|
$informationElements[] = Title::create('text.creditor'); |
|
101
|
|
|
$informationElements[] = Text::create($this->qrBill->getCreditorInformation()->getFormattedIban() . "\n" . $this->qrBill->getCreditor()->getFullAddress()); |
|
102
|
|
|
|
|
103
|
|
|
if ($this->qrBill->getPaymentReference()->getType() !== PaymentReference::TYPE_NON) { |
|
104
|
|
|
$informationElements[] = Title::create('text.reference'); |
|
105
|
|
|
$informationElements[] = Text::create($this->qrBill->getPaymentReference()->getFormattedReference()); |
|
106
|
|
|
} |
|
107
|
|
|
|
|
108
|
|
|
if ($this->qrBill->getUltimateDebtor()) { |
|
109
|
|
|
$informationElements[] = Title::create('text.payableBy'); |
|
110
|
|
|
$informationElements[] = Text::create($this->qrBill->getUltimateDebtor()->getFullAddress()); |
|
111
|
|
|
} else { |
|
112
|
|
|
$informationElements[] = Title::create('text.payableByName'); |
|
113
|
|
|
$informationElements[] = Placeholder::create(Placeholder::PLACEHOLDER_TYPE_PAYABLE_BY_RECEIPT); |
|
114
|
|
|
} |
|
115
|
|
|
|
|
116
|
|
|
return $informationElements; |
|
117
|
|
|
} |
|
118
|
|
|
|
|
119
|
|
|
protected function getCurrencyElements(): array |
|
120
|
|
|
{ |
|
121
|
|
|
$currencyElements = []; |
|
122
|
|
|
|
|
123
|
|
|
$currencyElements[] = Title::create('text.currency'); |
|
124
|
|
|
$currencyElements[] = Text::create($this->qrBill->getPaymentAmountInformation()->getCurrency()); |
|
125
|
|
|
|
|
126
|
|
|
return $currencyElements; |
|
127
|
|
|
} |
|
128
|
|
|
|
|
129
|
|
|
protected function getAmountElements(): array |
|
130
|
|
|
{ |
|
131
|
|
|
$amountElements = []; |
|
132
|
|
|
|
|
133
|
|
|
$amountElements[] = Title::create('text.amount'); |
|
134
|
|
|
|
|
135
|
|
|
if ($this->qrBill->getPaymentAmountInformation()->getAmount()) { |
|
136
|
|
|
$amountElements[] = Text::create($this->qrBill->getPaymentAmountInformation()->getFormattedAmount()); |
|
137
|
|
|
} else { |
|
138
|
|
|
$amountElements[] = Placeholder::create(Placeholder::PLACEHOLDER_TYPE_AMOUNT); |
|
139
|
|
|
} |
|
140
|
|
|
|
|
141
|
|
|
return $amountElements; |
|
142
|
|
|
} |
|
143
|
|
|
|
|
144
|
|
|
protected function getAmountElementsReceipt(): array |
|
145
|
|
|
{ |
|
146
|
|
|
$amountElements = []; |
|
147
|
|
|
|
|
148
|
|
|
$amountElements[] = Title::create('text.amount'); |
|
149
|
|
|
|
|
150
|
|
|
if ($this->qrBill->getPaymentAmountInformation()->getAmount()) { |
|
151
|
|
|
$amountElements[] = Text::create($this->qrBill->getPaymentAmountInformation()->getFormattedAmount()); |
|
152
|
|
|
} else { |
|
153
|
|
|
$amountElements[] = Placeholder::create(Placeholder::PLACEHOLDER_TYPE_AMOUNT_RECEIPT); |
|
154
|
|
|
} |
|
155
|
|
|
|
|
156
|
|
|
return $amountElements; |
|
157
|
|
|
} |
|
158
|
|
|
|
|
159
|
|
|
protected function getFurtherInformationElements(): array |
|
160
|
|
|
{ |
|
161
|
|
|
$furtherInformationElements = []; |
|
162
|
|
|
|
|
163
|
|
|
$furtherInformationLines= []; |
|
164
|
|
|
foreach($this->qrBill->getAlternativeSchemes() as $alternativeScheme) { |
|
165
|
|
|
$furtherInformationLines[] = $alternativeScheme->getParameter(); |
|
166
|
|
|
} |
|
167
|
|
|
$furtherInformationElements[] = Text::create(implode("\n", $furtherInformationLines)); |
|
168
|
|
|
|
|
169
|
|
|
return $furtherInformationElements; |
|
170
|
|
|
} |
|
171
|
|
|
|
|
172
|
|
|
protected function getQrCode(): QrCode |
|
173
|
|
|
{ |
|
174
|
|
|
$qrCode = $this->qrBill->getQrCode(); |
|
175
|
|
|
$qrCode->setWriterByExtension($this->getQrCodeImageFormat()); |
|
176
|
|
|
|
|
177
|
|
|
return $qrCode; |
|
178
|
|
|
} |
|
179
|
|
|
} |