-
Notifications
You must be signed in to change notification settings - Fork 61
/
Spk.php
139 lines (124 loc) · 3.32 KB
/
Spk.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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
<?php
namespace Kingsquare\Parser\Banking\Mt940\Engine;
use Kingsquare\Parser\Banking\Mt940\Engine;
/**
* @author Timotheus Pokorra ([email protected])
* @license http://opensource.org/licenses/MIT MIT
*
* This is for german banks, for example Sparkasse
*/
class Spk extends Engine
{
/**
* returns the name of the bank.
*
* @return string
*/
protected function parseStatementBank()
{
return 'Spk';
}
/**
* Overloaded: Sparkasse uses 60M and 60F.
*
* @inheritdoc
*/
protected function parseStatementStartPrice()
{
return $this->parseStatementPrice('60[FM]');
}
/**
* Overloaded: Sparkasse uses 60M and 60F.
*
* @inheritdoc
*/
protected function parseStatementStartTimestamp()
{
return $this->parseTimestampFromStatement('60[FM]');
}
/**
* Overloaded: Sparkasse uses 60M and 60F.
*
* @inheritdoc
*/
protected function parseStatementEndTimestamp()
{
return $this->parseTimestampFromStatement('60[FM]');
}
/**
* Overloaded: Sparkasse uses 62M and 62F.
*
* @inheritdoc
*/
protected function parseStatementEndPrice()
{
return $this->parseStatementPrice('62[FM]');
}
/**
* Overloaded: Sparkasse can have the 3rd character of the currencyname after the C/D
* currency codes last letter is always a letter http://www.xe.com/iso4217.php.
*
* @inheritdoc
*/
protected function parseTransactionPrice()
{
$results = [];
if (preg_match('/^:61:.*?[CD][a-zA-Z]?([\d,\.]+)N/i', $this->getCurrentTransactionData(), $results)
&& !empty($results[1])
) {
return $this->sanitizePrice($results[1]);
}
return 0;
}
/**
* Overloaded: Sparkasse can have the 3rd character of the currencyname after the C/D and an "R" for cancellation befor the C/D.
*
* @inheritdoc
*/
protected function parseTransactionDebitCredit()
{
$results = [];
if (preg_match('/^:61:\d+R?([CD]).?\d+/', $this->getCurrentTransactionData(), $results)
&& !empty($results[1])
) {
return $this->sanitizeDebitCredit($results[1]);
}
return '';
}
/**
* Overloaded: Sparkasse use the Field 61 for cancellations
*
* @inheritdoc
*/
protected function parseTransactionCancellation()
{
$results = [];
return preg_match('/^:61:\d+(R)?[CD].?\d+/', $this->getCurrentTransactionData(), $results)
&& !empty($results[1]);
}
/**
* Overloaded: Sparkasse does not have a header line.
*
* @inheritdoc
*/
protected function parseStatementData()
{
return preg_split(
'/(^:20:|^-X{,3}$|\Z)/m',
$this->getRawData(),
-1,
PREG_SPLIT_NO_EMPTY
);
}
/**
* Overloaded: Is applicable if first or second line has :20:STARTUMS or first line has -.
*
* @inheritdoc
*/
public static function isApplicable($string)
{
$firstline = strtok($string, "\r\n\t");
$secondline = strtok("\r\n\t");
return strpos($firstline, ':20:STARTUMS') !== false || ($firstline === '-' && $secondline === ':20:STARTUMS');
}
}