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