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 Rabo extends Engine |
12
|
|
|
{ |
13
|
|
|
/** |
14
|
|
|
* returns the name of the bank. |
15
|
|
|
* |
16
|
|
|
* @return string |
17
|
|
|
*/ |
18
|
|
|
protected function parseStatementBank() |
19
|
|
|
{ |
20
|
|
|
return 'Rabo'; |
21
|
|
|
} |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* Overloaded: Rabo has different way of storing account info. |
25
|
|
|
* |
26
|
|
|
* {@inheritdoc} |
27
|
|
|
*/ |
28
|
|
View Code Duplication |
protected function parseTransactionAccount() |
|
|
|
|
29
|
|
|
{ |
30
|
|
|
$results = []; |
31
|
|
|
// SEPA MT940 Structured |
32
|
|
|
if (preg_match('/^:61:.*\n(.*?)(\n|\:8)/im', $this->getCurrentTransactionData(), $results) |
33
|
|
|
&& !empty($results[1]) |
34
|
|
|
) { |
35
|
|
|
return $this->sanitizeAccount($results[1]); |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
if (preg_match('/^:61:.{26}(.{16})/m', $this->getCurrentTransactionData(), $results) |
39
|
|
|
&& !empty($results[1]) |
40
|
|
|
) { |
41
|
|
|
return $this->sanitizeAccount($results[1]); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
return ''; |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* Overloaded: Rabo has different way of storing account name. |
49
|
|
|
* |
50
|
|
|
* {@inheritdoc} |
51
|
|
|
*/ |
52
|
|
|
protected function parseTransactionAccountName() |
53
|
|
|
{ |
54
|
|
|
$results = []; |
55
|
|
|
// SEPA MT940 Structured |
56
|
|
|
if (preg_match('#/NAME/(.+?)\n?/(REMI|ADDR|ISDT|CSID)/#ms', $this->getCurrentTransactionData(), $results)) { |
57
|
|
|
$accountName = trim($results[1]); |
58
|
|
|
if (!empty($accountName)) { |
59
|
|
|
return $this->sanitizeAccountName($accountName); |
60
|
|
|
} |
61
|
|
|
} |
62
|
|
|
|
63
|
|
View Code Duplication |
if (preg_match('/^:61:.*? (.+)/m', $this->getCurrentTransactionData(), $results)) { |
|
|
|
|
64
|
|
|
$accountName = trim($results[1]); |
65
|
|
|
if (!empty($accountName)) { |
66
|
|
|
return $this->sanitizeAccountName($accountName); |
67
|
|
|
} |
68
|
|
|
} |
69
|
|
|
|
70
|
|
View Code Duplication |
if (preg_match('/(.*) Betaalautomaat/', $this->parseTransactionDescription(), $results)) { |
|
|
|
|
71
|
|
|
$accountName = trim($results[1]); |
72
|
|
|
if (!empty($accountName)) { |
73
|
|
|
return $this->sanitizeAccountName($accountName); |
74
|
|
|
} |
75
|
|
|
} |
76
|
|
|
return ''; |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* Overloaded: Rabo has different way of storing transaction value timestamps (ymd). |
81
|
|
|
* |
82
|
|
|
* {@inheritdoc} |
83
|
|
|
*/ |
84
|
|
|
protected function parseTransactionEntryTimestamp() |
85
|
|
|
{ |
86
|
|
|
$results = []; |
87
|
|
|
if (preg_match('/^:60F:[C|D]([\d]{6})/m', $this->getCurrentStatementData(), $results) && !empty($results[1])) { |
88
|
|
|
return $this->sanitizeTimestamp($results[1], 'ymd'); |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
return 0; |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
/** |
95
|
|
|
* Overloaded: Rabo has different way of storing transaction value timestamps (ymd). |
96
|
|
|
* |
97
|
|
|
* {@inheritdoc} |
98
|
|
|
*/ |
99
|
|
View Code Duplication |
protected function parseTransactionValueTimestamp() |
|
|
|
|
100
|
|
|
{ |
101
|
|
|
$results = []; |
102
|
|
|
if (preg_match('/^:61:([\d]{6})[C|D]/', $this->getCurrentTransactionData(), $results) && !empty($results[1])) { |
103
|
|
|
return $this->sanitizeTimestamp($results[1], 'ymd'); |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
return 0; |
107
|
|
|
} |
108
|
|
|
|
109
|
|
|
/** |
110
|
|
|
* Overloaded: Rabo uses longer strings for accountnumbers. |
111
|
|
|
* |
112
|
|
|
* {@inheritdoc} |
113
|
|
|
*/ |
114
|
|
|
protected function sanitizeAccount($string) |
115
|
|
|
{ |
116
|
|
|
$account = parent::sanitizeAccount($string); |
117
|
|
|
if (strlen($account) > 20 && strpos($account, '80000') === 0) { |
118
|
|
|
$account = substr($account, 5); |
119
|
|
|
} |
120
|
|
|
|
121
|
|
|
return $account; |
122
|
|
|
} |
123
|
|
|
|
124
|
|
|
/** |
125
|
|
|
* Overloaded: Rabo encapsulates the description with /REMI/ for SEPA. |
126
|
|
|
* |
127
|
|
|
* {@inheritdoc} |
128
|
|
|
*/ |
129
|
|
View Code Duplication |
protected function sanitizeDescription($string) |
|
|
|
|
130
|
|
|
{ |
131
|
|
|
$description = parent::sanitizeDescription($string); |
132
|
|
|
if (strpos($description, '/REMI/') !== false |
133
|
|
|
&& preg_match('#/REMI/(.*?)(/((PURP|ISDT|CSID|RTRN)/)|$)#s', $description, $results) && !empty($results[1]) |
134
|
|
|
) { |
135
|
|
|
return $results[1]; |
136
|
|
|
} |
137
|
|
|
if (strpos($description, '/EREF/') !== false |
138
|
|
|
&& preg_match('#/EREF/(.*?)/(ORDP)/#s', $description, $results) && !empty($results[1]) |
139
|
|
|
) { |
140
|
|
|
return $results[1]; |
141
|
|
|
} |
142
|
|
|
|
143
|
|
|
return $description; |
144
|
|
|
} |
145
|
|
|
|
146
|
|
|
/** |
147
|
|
|
* Overloaded: Is applicable if first line has :940:. |
148
|
|
|
* |
149
|
|
|
* {@inheritdoc} |
150
|
|
|
*/ |
151
|
|
|
public static function isApplicable($string) |
152
|
|
|
{ |
153
|
|
|
return strpos(strtok($string, "\r\n\t"), ':940:') !== false; |
154
|
|
|
} |
155
|
|
|
|
156
|
|
|
protected function parseTransactionType() |
157
|
|
|
{ |
158
|
|
|
$code = $this->parseTransactionCode(); |
159
|
|
|
switch ($code) { |
160
|
|
|
case 541: |
161
|
|
|
case 544: |
162
|
|
|
case 102: // "Betaalopdracht IDEAL" |
163
|
|
|
case 547: |
164
|
|
|
$result = TransactionType::get(TransactionType::SEPA_TRANSFER); |
165
|
|
|
break; |
166
|
|
|
|
167
|
|
|
case 504: |
168
|
|
|
case 691: |
169
|
|
|
$result = TransactionType::get(TransactionType::SAVINGS_TRANSFER); |
170
|
|
|
break; |
171
|
|
|
case 64: |
172
|
|
|
$result = TransactionType::get(TransactionType::SEPA_DIRECTDEBIT); |
173
|
|
|
break; |
174
|
|
|
case 93: |
175
|
|
|
$result = TransactionType::get(TransactionType::BANK_COSTS); |
176
|
|
|
break; |
177
|
|
|
case 13: |
178
|
|
|
case 12: |
179
|
|
|
case 30: |
180
|
|
|
$result = TransactionType::get(TransactionType::PAYMENT_TERMINAL); |
181
|
|
|
break; |
182
|
|
|
case 29: |
183
|
|
|
case 31: |
184
|
|
|
$result = TransactionType::get(TransactionType::ATM_WITHDRAWAL); |
185
|
|
|
break; |
186
|
|
|
case "MSC": |
187
|
|
|
$result = TransactionType::get(TransactionType::BANK_INTEREST); |
188
|
|
|
break; |
189
|
|
|
case 404: // "Buitenland transactie credit" |
190
|
|
|
if (stripos($this->getCurrentTransactionData(), 'eurobetaling') !== false) { |
191
|
|
|
$result = TransactionType::get(TransactionType::SEPA_TRANSFER); |
192
|
|
|
} else { |
193
|
|
|
$result = TransactionType::get(TransactionType::TRANSFER); |
194
|
|
|
} |
195
|
|
|
|
196
|
|
|
break; |
197
|
|
|
case 79: // "Acceptgiro Mobiel Bankieren" |
198
|
|
|
$result = TransactionType::get(TransactionType::UNKNOWN); |
199
|
|
|
break; |
200
|
|
|
|
201
|
|
|
default: |
202
|
|
|
var_dump($code); |
|
|
|
|
203
|
|
|
var_dump($this->getCurrentTransactionData()); die(); |
204
|
|
|
throw new \RuntimeException("Don't know code $code for RABOBANK"); |
|
|
|
|
205
|
|
|
} |
206
|
|
|
|
207
|
|
|
return $result; |
208
|
|
|
} |
209
|
|
|
|
210
|
|
|
} |
211
|
|
|
|
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.