1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Swiss Payment Slip |
4
|
|
|
* |
5
|
|
|
* @license http://www.opensource.org/licenses/mit-license.php MIT License |
6
|
|
|
* @copyright 2012-2016 Some nice Swiss guys |
7
|
|
|
* @author Marc Würth [email protected] |
8
|
|
|
* @author Manuel Reinhard <[email protected]> |
9
|
|
|
* @author Peter Siska <[email protected]> |
10
|
|
|
* @link https://github.com/ravage84/SwissPaymentSlip/ |
11
|
|
|
*/ |
12
|
|
|
|
13
|
|
|
namespace SwissPaymentSlip\SwissPaymentSlip; |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* Red Swiss Payment Slip |
17
|
|
|
* |
18
|
|
|
* Describes how a red Swiss payment slip looks like and |
19
|
|
|
* how the various data fields of a red payment slip are |
20
|
|
|
* placed or displayed respectively. |
21
|
|
|
* |
22
|
|
|
* The data of the fields is organized by its sister class RedPaymentSlipData. |
23
|
|
|
* |
24
|
|
|
* @uses RedPaymentSlipData To store the slip data. |
25
|
|
|
*/ |
26
|
|
|
class RedPaymentSlip extends PaymentSlip |
27
|
|
|
{ |
28
|
|
|
/** |
29
|
|
|
* The red payment slip value object, which contains the payment slip data |
30
|
|
|
* |
31
|
|
|
* @var RedPaymentSlipData |
32
|
|
|
*/ |
33
|
|
|
protected $paymentSlipData = null; |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* The height of the slip |
37
|
|
|
* |
38
|
|
|
* @var int|float |
39
|
|
|
*/ |
40
|
|
|
protected $slipHeight = 106; // TODO default height of an red slip |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* The width of the slip |
44
|
|
|
* |
45
|
|
|
* @var int|float |
46
|
|
|
*/ |
47
|
|
|
protected $slipWidth = 210; // TODO default width of an red slip |
48
|
|
|
/** |
49
|
|
|
* Determines whether the IBAN should be displayed |
50
|
|
|
* |
51
|
|
|
* @var bool |
52
|
|
|
*/ |
53
|
|
|
protected $displayIban = true; |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* Determines whether the payment reason should be displayed |
57
|
|
|
* |
58
|
|
|
* @var bool |
59
|
|
|
*/ |
60
|
|
|
protected $displayPaymentReason = true; |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* Attributes of the left IBAN element |
64
|
|
|
* |
65
|
|
|
* @var array |
66
|
|
|
*/ |
67
|
|
|
protected $ibanLeftAttr = []; |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* Attributes of the rightIBAN element |
71
|
|
|
* |
72
|
|
|
* @var array |
73
|
|
|
*/ |
74
|
|
|
protected $ibanRightAttr = []; |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* Attributes of the payment reason element |
78
|
|
|
* |
79
|
|
|
* @var array |
80
|
|
|
*/ |
81
|
|
|
protected $paymentReasonAttr = []; |
82
|
|
|
|
83
|
|
|
/** |
84
|
|
|
* Create a new red payment slip |
85
|
|
|
* |
86
|
|
|
* @param RedPaymentSlipData $paymentSlipData The red payment slip data. |
87
|
|
|
* @param float|null $slipPosX The optional X position of the slip. |
88
|
|
|
* @param float|null $slipPosY The optional Y position of the slip. |
89
|
|
|
*/ |
90
|
|
|
public function __construct(RedPaymentSlipData $paymentSlipData, $slipPosX = null, $slipPosY = null) |
91
|
|
|
{ |
92
|
|
|
parent::__construct($paymentSlipData, $slipPosX, $slipPosY); |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
/** |
96
|
|
|
* Sets the default attributes of the elements for a red slip |
97
|
|
|
* |
98
|
|
|
* @return $this The current instance for a fluent interface. |
99
|
|
|
* @todo Set default attributes for $ibanLeftAttr, $ibanRightAttr & $paymentReasonAttr |
100
|
|
|
*/ |
101
|
1 |
|
protected function setDefaults() |
102
|
|
|
{ |
103
|
1 |
|
parent::setDefaults(); |
104
|
|
|
|
105
|
1 |
|
$this->setIbanLeftAttr(); |
106
|
1 |
|
$this->setIbanRightAttr(); |
107
|
1 |
|
$this->setPaymentReasonAttr(); |
108
|
|
|
|
109
|
1 |
|
$this->setSlipBackground(__DIR__.'/Resources/img/ezs_red.gif'); |
110
|
|
|
|
111
|
1 |
|
return $this; |
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
/** |
115
|
|
|
* Get the slip data object of the slip |
116
|
|
|
* |
117
|
|
|
* @return RedPaymentSlipData The data object of the slip. |
118
|
|
|
*/ |
119
|
1 |
|
public function getPaymentSlipData() |
120
|
|
|
{ |
121
|
1 |
|
return parent::getPaymentSlipData(); |
122
|
|
|
} |
123
|
|
|
|
124
|
|
|
/** |
125
|
|
|
* Set the left IBAN attributes |
126
|
|
|
* |
127
|
|
|
* @param float|null $posX The X position. |
128
|
|
|
* @param float|null $posY The Y Position. |
129
|
|
|
* @param float|null $width The width. |
130
|
|
|
* @param float|null $height The height. |
131
|
|
|
* @param string|null $background The background. |
132
|
|
|
* @param string|null $fontFamily The font family. |
133
|
|
|
* @param float|null $fontSize The font size. |
134
|
|
|
* @param string|null $fontColor The font color. |
135
|
|
|
* @param float|null $lineHeight The line height. |
136
|
|
|
* @param string|null $textAlign The text alignment. |
137
|
|
|
* @return $this The current instance for a fluent interface. |
138
|
|
|
*/ |
139
|
1 |
View Code Duplication |
public function setIbanLeftAttr( |
|
|
|
|
140
|
|
|
$posX = null, |
141
|
|
|
$posY = null, |
142
|
|
|
$width = null, |
143
|
|
|
$height = null, |
144
|
|
|
$background = null, |
145
|
|
|
$fontFamily = null, |
146
|
|
|
$fontSize = null, |
147
|
|
|
$fontColor = null, |
148
|
|
|
$lineHeight = null, |
149
|
|
|
$textAlign = null |
150
|
|
|
) { |
151
|
1 |
|
$this->setAttributes( |
152
|
1 |
|
$this->ibanLeftAttr, |
153
|
1 |
|
$posX, |
154
|
1 |
|
$posY, |
155
|
1 |
|
$width, |
156
|
1 |
|
$height, |
157
|
1 |
|
$background, |
158
|
1 |
|
$fontFamily, |
159
|
1 |
|
$fontSize, |
160
|
1 |
|
$fontColor, |
161
|
1 |
|
$lineHeight, |
162
|
|
|
$textAlign |
163
|
1 |
|
); |
164
|
|
|
|
165
|
1 |
|
return $this; |
166
|
|
|
} |
167
|
|
|
|
168
|
|
|
/** |
169
|
|
|
* Set the right IBAN attributes |
170
|
|
|
* |
171
|
|
|
* @param float|null $posX The X position. |
172
|
|
|
* @param float|null $posY The Y Position. |
173
|
|
|
* @param float|null $width The width. |
174
|
|
|
* @param float|null $height The height. |
175
|
|
|
* @param string|null $background The background. |
176
|
|
|
* @param string|null $fontFamily The font family. |
177
|
|
|
* @param float|null $fontSize The font size. |
178
|
|
|
* @param string|null $fontColor The font color. |
179
|
|
|
* @param float|null $lineHeight The line height. |
180
|
|
|
* @param string|null $textAlign The text alignment. |
181
|
|
|
* @return $this The current instance for a fluent interface. |
182
|
|
|
*/ |
183
|
1 |
View Code Duplication |
public function setIbanRightAttr( |
|
|
|
|
184
|
|
|
$posX = null, |
185
|
|
|
$posY = null, |
186
|
|
|
$width = null, |
187
|
|
|
$height = null, |
188
|
|
|
$background = null, |
189
|
|
|
$fontFamily = null, |
190
|
|
|
$fontSize = null, |
191
|
|
|
$fontColor = null, |
192
|
|
|
$lineHeight = null, |
193
|
|
|
$textAlign = null |
194
|
|
|
) { |
195
|
1 |
|
$this->setAttributes( |
196
|
1 |
|
$this->ibanRightAttr, |
197
|
1 |
|
$posX, |
198
|
1 |
|
$posY, |
199
|
1 |
|
$width, |
200
|
1 |
|
$height, |
201
|
1 |
|
$background, |
202
|
1 |
|
$fontFamily, |
203
|
1 |
|
$fontSize, |
204
|
1 |
|
$fontColor, |
205
|
1 |
|
$lineHeight, |
206
|
|
|
$textAlign |
207
|
1 |
|
); |
208
|
|
|
|
209
|
1 |
|
return $this; |
210
|
|
|
} |
211
|
|
|
|
212
|
|
|
/** |
213
|
|
|
* Get the attributes of the left IBAN element |
214
|
|
|
* |
215
|
|
|
* @return array The attributes of the left IBAN element. |
216
|
|
|
*/ |
217
|
1 |
|
public function getIbanLeftAttr() |
218
|
|
|
{ |
219
|
1 |
|
return $this->ibanLeftAttr; |
220
|
|
|
} |
221
|
|
|
|
222
|
|
|
/** |
223
|
|
|
* Get the attributes of the right IBAN element |
224
|
|
|
* |
225
|
|
|
* @return array The attributes of the right IBAN element. |
226
|
|
|
*/ |
227
|
1 |
|
public function getIbanRightAttr() |
228
|
|
|
{ |
229
|
1 |
|
return $this->ibanRightAttr; |
230
|
|
|
} |
231
|
|
|
|
232
|
|
|
/** |
233
|
|
|
* Set the payment reason attributes |
234
|
|
|
* |
235
|
|
|
* @param float|null $posX The X position. |
236
|
|
|
* @param float|null $posY The Y Position. |
237
|
|
|
* @param float|null $width The width. |
238
|
|
|
* @param float|null $height The height. |
239
|
|
|
* @param string|null $background The background. |
240
|
|
|
* @param string|null $fontFamily The font family. |
241
|
|
|
* @param float|null $fontSize The font size. |
242
|
|
|
* @param string|null $fontColor The font color. |
243
|
|
|
* @param float|null $lineHeight The line height. |
244
|
|
|
* @param string|null $textAlign The text alignment. |
245
|
|
|
* @return $this The current instance for a fluent interface. |
246
|
|
|
*/ |
247
|
1 |
View Code Duplication |
public function setPaymentReasonAttr( |
|
|
|
|
248
|
|
|
$posX = null, |
249
|
|
|
$posY = null, |
250
|
|
|
$width = null, |
251
|
|
|
$height = null, |
252
|
|
|
$background = null, |
253
|
|
|
$fontFamily = null, |
254
|
|
|
$fontSize = null, |
255
|
|
|
$fontColor = null, |
256
|
|
|
$lineHeight = null, |
257
|
|
|
$textAlign = null |
258
|
|
|
) { |
259
|
1 |
|
$this->setAttributes( |
260
|
1 |
|
$this->paymentReasonAttr, |
261
|
1 |
|
$posX, |
262
|
1 |
|
$posY, |
263
|
1 |
|
$width, |
264
|
1 |
|
$height, |
265
|
1 |
|
$background, |
266
|
1 |
|
$fontFamily, |
267
|
1 |
|
$fontSize, |
268
|
1 |
|
$fontColor, |
269
|
1 |
|
$lineHeight, |
270
|
|
|
$textAlign |
271
|
1 |
|
); |
272
|
|
|
|
273
|
1 |
|
return $this; |
274
|
|
|
} |
275
|
|
|
|
276
|
|
|
/** |
277
|
|
|
* Get the attributes of the payment reason element |
278
|
|
|
* |
279
|
|
|
* @return array The attributes of the payment reason element. |
280
|
|
|
*/ |
281
|
1 |
|
public function getPaymentReasonAttr() |
282
|
|
|
{ |
283
|
1 |
|
return $this->paymentReasonAttr; |
284
|
|
|
} |
285
|
|
|
|
286
|
|
|
/** |
287
|
|
|
* Set whether or not to display the IBAN |
288
|
|
|
* |
289
|
|
|
* @param bool $displayIban True if yes, false if no |
290
|
|
|
* @return $this The current instance for a fluent interface. |
291
|
|
|
*/ |
292
|
2 |
|
public function setDisplayIban($displayIban = true) |
293
|
|
|
{ |
294
|
2 |
|
$this->isBool($displayIban, 'displayIban'); |
295
|
1 |
|
$this->displayIban = $displayIban; |
296
|
|
|
|
297
|
1 |
|
return $this; |
298
|
|
|
} |
299
|
|
|
|
300
|
|
|
/** |
301
|
|
|
* Get whether or not to display the IBAN |
302
|
|
|
* |
303
|
|
|
* @return bool True if yes, false if no. |
304
|
|
|
*/ |
305
|
1 |
|
public function getDisplayIban() |
306
|
|
|
{ |
307
|
1 |
|
if ($this->getPaymentSlipData()->getWithIban() !== true) { |
308
|
1 |
|
return false; |
309
|
|
|
} |
310
|
1 |
|
return $this->displayIban; |
311
|
|
|
} |
312
|
|
|
|
313
|
|
|
/** |
314
|
|
|
* Set whether or not to display the payment reason lines |
315
|
|
|
* |
316
|
|
|
* @param bool $displayPaymentReason True if yes, false if no |
317
|
|
|
* @return $this The current instance for a fluent interface. |
318
|
|
|
*/ |
319
|
2 |
|
public function setDisplayPaymentReason($displayPaymentReason = true) |
320
|
|
|
{ |
321
|
2 |
|
$this->isBool($displayPaymentReason, 'displayPaymentReason'); |
322
|
1 |
|
$this->displayPaymentReason = $displayPaymentReason; |
323
|
|
|
|
324
|
1 |
|
return $this; |
325
|
|
|
} |
326
|
|
|
|
327
|
|
|
/** |
328
|
|
|
* Get whether or not to display the payment reason lines |
329
|
|
|
* |
330
|
|
|
* @return bool True if yes, false if no. |
331
|
|
|
*/ |
332
|
1 |
|
public function getDisplayPaymentReason() |
333
|
|
|
{ |
334
|
1 |
|
if ($this->getPaymentSlipData()->getWithPaymentReason() !== true) { |
335
|
1 |
|
return false; |
336
|
|
|
} |
337
|
1 |
|
return $this->displayPaymentReason; |
338
|
|
|
} |
339
|
|
|
|
340
|
|
|
/** |
341
|
|
|
* Get all elements of the slip |
342
|
|
|
* |
343
|
|
|
* @return array All elements with their lines and attributes. |
344
|
|
|
*/ |
345
|
3 |
|
public function getAllElements() |
346
|
|
|
{ |
347
|
3 |
|
$paymentSlipData = $this->paymentSlipData; |
348
|
|
|
|
349
|
3 |
|
$elements = parent::getAllElements(); |
350
|
|
|
|
351
|
|
|
// Place left IBAN |
352
|
3 |
|
if ($this->getDisplayIban()) { |
353
|
|
|
$lines = [ |
354
|
1 |
|
$paymentSlipData->getFormattedIban() |
355
|
1 |
|
]; |
356
|
1 |
|
$elements['IbanLeft'] = ['lines' => $lines, |
357
|
1 |
|
'attributes' => $this->getIbanLeftAttr() |
358
|
1 |
|
]; |
359
|
|
|
|
360
|
|
|
// Place right IBAN |
361
|
|
|
// Reuse lines from above |
362
|
1 |
|
$elements['IbanRight'] = [ |
363
|
1 |
|
'lines' => $lines, |
364
|
1 |
|
'attributes' => $this->getIbanRightAttr() |
365
|
1 |
|
]; |
366
|
1 |
|
} |
367
|
|
|
|
368
|
3 |
|
if ($this->getDisplayPaymentReason()) { |
369
|
|
|
// Place payment reason lines |
370
|
|
|
$lines = [ |
371
|
1 |
|
$paymentSlipData->getPaymentReasonLine1(), |
372
|
1 |
|
$paymentSlipData->getPaymentReasonLine2(), |
373
|
1 |
|
$paymentSlipData->getPaymentReasonLine3(), |
374
|
1 |
|
$paymentSlipData->getPaymentReasonLine4() |
375
|
1 |
|
]; |
376
|
1 |
|
$elements['paymentReason'] = [ |
377
|
1 |
|
'lines' => $lines, |
378
|
1 |
|
'attributes' => $this->getPaymentReasonAttr() |
379
|
1 |
|
]; |
380
|
1 |
|
} |
381
|
|
|
|
382
|
3 |
|
return $elements; |
383
|
|
|
} |
384
|
|
|
} |
385
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.