Completed
Pull Request — master (#95)
by
unknown
02:54
created

Transaction::getSignedAmount()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 10
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 3

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 10
ccs 8
cts 8
cp 1
rs 9.4285
cc 3
eloc 7
nc 3
nop 0
crap 3
1
<?php
2
3
namespace Fhp\Model\StatementOfAccount;
4
5
/**
6
 * Class Transaction
7
 * @package Fhp\Model\StatementOfAccount
8
 */
9
class Transaction
10
{
11
    const CD_CREDIT = 'credit';
12
    const CD_DEBIT = 'debit';
13
    const CD_CREDIT_CANCELLATION = 'credit_cancellation';
14
    const CD_DEBIT_CANCELLATION = 'debit_cancellation';
15
16
    /**
17
     * @var \DateTime|null
18
     */
19
    protected $bookingDate;
20
21
    /**
22
     * @var \DateTime|null
23
     */
24
    protected $valutaDate;
25
26
    /**
27
     * @var float
28
     */
29
    protected $amount;
30
31
    /**
32
     * @var string
33
     */
34
    protected $creditDebit;
35
36
    /**
37
     * @var string
38
     */
39
    protected $bookingText;
40
41
    /**
42
     * @var string
43
     */
44
    protected $description1;
45
46
    /**
47
     * @var string
48
     */
49
    protected $description2;
50
51
    /**
52
     * Array keys are identifiers like "SVWZ" for the main description.
53
     * @var string[]
54
     */
55
    protected $structuredDescription;
56
57
    /**
58
     * @var string
59
     */
60
    protected $bankCode;
61
62
    /**
63
     * @var string
64
     */
65
    protected $accountNumber;
66
67
    /**
68
     * @var string
69
     */
70
    protected $name;
71
72
    /**
73
     * See https://www.bayernlb.de/internet/media/de/ir/downloads_1/zahlungsverkehr/formate_1/MT940_942.pdf page 451 / 8.2.6 Geschäftsvorfallcodes 
74
     * @var string
75
     */
76
    protected $transactionCode;
77
78
    /**
79
     * Get booking date.
80
     *
81
     * @deprecated Use getBookingDate() instead
82
     * @codeCoverageIgnore
83
     * @return \DateTime|null
84
     */
85
    public function getDate()
86
    {
87
        return $this->getBookingDate();
88
    }
89
90
    /**
91
     * Get booking date
92
     *
93
     * @return \DateTime|null
94
     */
95 1
    public function getBookingDate()
96
    {
97 1
        return $this->bookingDate;
98
    }
99
100
    /**
101
     * Get date
102
     *
103
     * @return \DateTime|null
104
     */
105 1
    public function getValutaDate()
106
    {
107 1
        return $this->valutaDate;
108
    }
109
110
    /**
111
     * Set booking date
112
     *
113
     * @param \DateTime|null $date
114
     *
115
     * @return $this
116
     */
117 1
    public function setBookingDate(\DateTime $date = null)
118
    {
119 1
        $this->bookingDate = $date;
120
121 1
        return $this;
122
    }
123
124
    /**
125
     * Set valuta date
126
     *
127
     * @param \DateTime|null $date
128
     *
129
     * @return $this
130
     */
131 1
    public function setValutaDate(\DateTime $date = null)
132
    {
133 1
        $this->valutaDate = $date;
134
135 1
        return $this;
136
    }
137
138
    /**
139
     * Get the signed amount based on credit/debit setting.
140
     * Debits and canceled credits have a negative sign.
141
     * @return float
142
     */
143 1
    public function getSignedAmount()
144
    {
145 1
        switch ($this->creditDebit) {
146 1
            case Transaction::CD_DEBIT:
147 1
            case Transaction::CD_CREDIT_CANCELLATION:
148 1
                return -1 * $this->amount;
149 1
            default:
150 1
                return $this->amount;
151 1
        }
152
    }
153
154
    /**
155
     * Get amount
156
     *
157
     * @return float
158
     */
159 1
    public function getAmount()
160
    {
161 1
        return $this->amount;
162
    }
163
164
    /**
165
     * Set amount
166
     *
167
     * @param float $amount
168
     *
169
     * @return $this
170
     */
171 2
    public function setAmount($amount)
172
    {
173 2
        $this->amount = (float) $amount;
174
175 2
        return $this;
176
    }
177
178
    /**
179
     * Get creditDebit
180
     *
181
     * @return string
182
     */
183 1
    public function getCreditDebit()
184
    {
185 1
        return $this->creditDebit;
186
    }
187
188
    /**
189
     * Set creditDebit
190
     *
191
     * @param string $creditDebit
192
     *
193
     * @return $this
194
     */
195 2
    public function setCreditDebit($creditDebit)
196
    {
197 2
        $this->creditDebit = $creditDebit;
198
199 2
        return $this;
200
    }
201
202
    /**
203
     * Get bookingText
204
     *
205
     * @return string
206
     */
207 1
    public function getBookingText()
208
    {
209 1
        return $this->bookingText;
210
    }
211
212
    /**
213
     * Set bookingText
214
     *
215
     * @param string $bookingText
216
     *
217
     * @return $this
218
     */
219 1
    public function setBookingText($bookingText)
220
    {
221 1
        $this->bookingText = (string) $bookingText;
222
223 1
        return $this;
224
    }
225
226
    /**
227
     * Get description1
228
     *
229
     * @return string
230
     */
231 1
    public function getDescription1()
232
    {
233 1
        return $this->description1;
234
    }
235
236
    /**
237
     * Set description1
238
     *
239
     * @param string $description1
240
     *
241
     * @return $this
242
     */
243 1
    public function setDescription1($description1)
244
    {
245 1
        $this->description1 = (string) $description1;
246
247 1
        return $this;
248
    }
249
250
    /**
251
     * Get description2
252
     *
253
     * @return string
254
     */
255 1
    public function getDescription2()
256
    {
257 1
        return $this->description2;
258
    }
259
260
    /**
261
     * Set description2
262
     *
263
     * @param string $description2
264
     *
265
     * @return $this
266
     */
267 1
    public function setDescription2($description2)
268
    {
269 1
        $this->description2 = (string) $description2;
270
271 1
        return $this;
272
    }
273
274
    /**
275
     * Get structuredDescription
276
     *
277
     * @return string[]
278
     */
279
    public function getStructuredDescription()
280
    {
281
        return $this->structuredDescription;
282
    }
283
284
    /**
285
     * Set structuredDescription
286
     *
287
     * @param string[] $structuredDescription
288
     *
289
     * @return $this
290
     */
291
    public function setStructuredDescription($structuredDescription)
292
    {
293
        $this->structuredDescription = $structuredDescription;
294
295
        return $this;
296
    }
297
298
    /**
299
     * Get the main description (SVWZ)
300
     *
301
     * @return string
302
     */
303
    public function getMainDescription()
304
    {
305
        if (array_key_exists('SVWZ', $this->structuredDescription)) {
306
            return $this->structuredDescription['SVWZ'];
307
        } else {
308
            return '';
309
        }
310
    }
311
312
    /**
313
     * Get bankCode
314
     *
315
     * @return string
316
     */
317 1
    public function getBankCode()
318
    {
319 1
        return $this->bankCode;
320
    }
321
322
    /**
323
     * Set bankCode
324
     *
325
     * @param string $bankCode
326
     *
327
     * @return $this
328
     */
329 1
    public function setBankCode($bankCode)
330
    {
331 1
        $this->bankCode = (string) $bankCode;
332
333 1
        return $this;
334
    }
335
336
    /**
337
     * Get accountNumber
338
     *
339
     * @return string
340
     */
341 1
    public function getAccountNumber()
342
    {
343 1
        return $this->accountNumber;
344
    }
345
346
    /**
347
     * Set accountNumber
348
     *
349
     * @param string $accountNumber
350
     *
351
     * @return $this
352
     */
353 1
    public function setAccountNumber($accountNumber)
354
    {
355 1
        $this->accountNumber = (string) $accountNumber;
356
357 1
        return $this;
358
    }
359
360
    /**
361
     * Get name
362
     *
363
     * @return string
364
     */
365 1
    public function getName()
366
    {
367 1
        return $this->name;
368
    }
369
370
    /**
371
     * Set name
372
     *
373
     * @param string $name
374
     *
375
     * @return $this
376
     */
377 1
    public function setName($name)
378
    {
379 1
        $this->name = (string) $name;
380
381 1
        return $this;
382
    }
383
384
    /**
385
     * Get see https://www.bayernlb.de/internet/media/de/ir/downloads_1/zahlungsverkehr/formate_1/MT940_942.pdf page 451 / 8.2.6 Geschäftsvorfallcodes
386
     *
387
     * @return  string
388
     */ 
389
    public function getTransactionCode()
390
    {
391
        return $this->transactionCode;
392
    }
393
394
    /**
395
     * Set see https://www.bayernlb.de/internet/media/de/ir/downloads_1/zahlungsverkehr/formate_1/MT940_942.pdf page 451 / 8.2.6 Geschäftsvorfallcodes
396
     *
397
     * @param  string  $transactionCode  See https://www.bayernlb.de/internet/media/de/ir/downloads_1/zahlungsverkehr/formate_1/MT940_942.pdf page 451 / 8.2.6 Geschäftsvorfallcodes
398
     *
399
     * @return  self
400
     */ 
401
    public function setTransactionCode(string $transactionCode)
402
    {
403
        $this->transactionCode = $transactionCode;
404
405
        return $this;
406
    }
407
}
408