1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Kingsquare\Parser\Banking\Mt940\Engine; |
4
|
|
|
|
5
|
|
|
use Kingsquare\Parser\Banking\Mt940\Engine; |
6
|
|
|
|
7
|
|
|
/** |
8
|
|
|
* @author Kingsquare ([email protected]) |
9
|
|
|
* @license http://opensource.org/licenses/MIT MIT |
10
|
|
|
*/ |
11
|
|
|
class Abn extends Engine |
12
|
|
|
{ |
13
|
|
|
/** |
14
|
|
|
* returns the name of the bank. |
15
|
|
|
* |
16
|
|
|
* @return string |
17
|
|
|
*/ |
18
|
|
|
protected function parseStatementBank() |
19
|
|
|
{ |
20
|
|
|
return 'ABN'; |
21
|
|
|
} |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* Overloaded: ABN Amro shows the GIRO |
25
|
|
|
* includes fix for 'for GIRO 1234567 TEST 201009063689 CLIEOP 21-9' and translates that into 1234567. |
26
|
|
|
* |
27
|
|
|
* {@inheritdoc} |
28
|
|
|
*/ |
29
|
|
|
protected function parseTransactionAccount() |
30
|
|
|
{ |
31
|
|
|
$results = parent::parseTransactionAccount(); |
32
|
|
|
|
33
|
|
|
if (empty($results)) { |
34
|
|
|
$giroMatch = $ibanMatch = []; |
35
|
|
|
if (preg_match('/^:86:GIRO(.{9})/im', $this->getCurrentTransactionData(), $giroMatch) |
36
|
|
|
&& !empty($giroMatch[1]) |
37
|
|
|
) { |
38
|
|
|
$results = $giroMatch[1]; |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
if (preg_match('!^:86:/.*/IBAN/(.*?)/!m', $this->getCurrentTransactionData(), $ibanMatch) |
42
|
|
|
&& !empty($ibanMatch[1]) |
43
|
|
|
) { |
44
|
|
|
$results = $ibanMatch[1]; |
45
|
|
|
} |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
return $this->sanitizeAccount($results); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* Overloaded: ABN Amro shows the GIRO and fixes newlines etc. |
53
|
|
|
* |
54
|
|
|
* {@inheritdoc} |
55
|
|
|
*/ |
56
|
|
|
protected function parseTransactionAccountName() |
57
|
|
|
{ |
58
|
|
|
$results = parent::parseTransactionAccountName(); |
59
|
|
|
if ($results !== '') { |
60
|
|
|
return $results; |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
$results = []; |
64
|
|
|
if (preg_match('/:86:(GIRO|BGC\.)\s+[\d]+ (.+)/', $this->getCurrentTransactionData(), $results) |
65
|
|
|
&& !empty($results[2]) |
66
|
|
|
) { |
67
|
|
|
return $this->sanitizeAccountName($results[2]); |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
if (preg_match('/:86:.+\n(.*)\n/', $this->getCurrentTransactionData(), $results) |
71
|
|
|
&& !empty($results[1]) |
72
|
|
|
) { |
73
|
|
|
return $this->sanitizeAccountName($results[1]); |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
return ''; |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* Overloaded: ABNAMRO uses the :61: date-part of the field for two values: |
81
|
|
|
* Valuetimestamp (YYMMDD) and Entry date (book date) (MMDD). |
82
|
|
|
* |
83
|
|
|
* @return int |
84
|
|
|
*/ |
85
|
|
|
protected function parseTransactionEntryTimestamp() |
86
|
|
|
{ |
87
|
|
|
$results = []; |
88
|
|
|
if (preg_match('/^:61:(\d{2})((\d{2})\d{2})((\d{2})\d{2})[C|D]/', $this->getCurrentTransactionData(), $results) |
89
|
|
|
&& !empty($results[1]) |
90
|
|
|
) { |
91
|
|
|
|
92
|
|
|
list(, $valueDateY, $valueDateMD, $valueDateM, $entryDateMD, $entryDateM) = $results; |
93
|
|
|
$entryDate = $valueDateY.$entryDateMD; |
94
|
|
|
if ($valueDateMD !== $entryDateMD && $valueDateM > $entryDateM) { |
95
|
|
|
$entryDate = ($valueDateY+1).$entryDateMD; |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
return $this->sanitizeTimestamp($entryDate, 'ymd'); |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
return 0; |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
/** |
105
|
|
|
* Overloaded: Is applicable if first line has ABNA. |
106
|
|
|
* |
107
|
|
|
* {@inheritdoc} |
108
|
|
|
*/ |
109
|
|
|
public static function isApplicable($string) |
110
|
|
|
{ |
111
|
|
|
$firstline = strtok($string, "\r\n\t"); |
112
|
|
|
|
113
|
|
|
return strpos($firstline, 'ABNA') !== false; |
114
|
|
|
} |
115
|
|
|
} |
116
|
|
|
|