1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Kingsquare\Banking; |
4
|
|
|
|
5
|
|
|
/** |
6
|
|
|
* @property string rawData A container after parsing a statement containing 'rawdata' if debug was true on the engine |
7
|
|
|
* |
8
|
|
|
* @author Kingsquare ([email protected]) |
9
|
|
|
* @license http://opensource.org/licenses/MIT MIT |
10
|
|
|
*/ |
11
|
|
|
class Transaction implements \JsonSerializable |
12
|
|
|
{ |
13
|
|
|
const DEBIT = 'D'; |
14
|
|
|
const CREDIT = 'C'; |
15
|
|
|
|
16
|
|
|
private $account = ''; |
17
|
|
|
private $accountName = ''; |
18
|
|
|
private $price = 0.0; |
19
|
|
|
private $debitcredit = ''; |
20
|
|
|
private $cancellation = false; |
21
|
|
|
private $description = ''; |
22
|
|
|
private $valueTimestamp = 0; |
23
|
|
|
private $entryTimestamp = 0; |
24
|
|
|
private $transactionCode = ''; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* @return array |
28
|
|
|
*/ |
29
|
|
|
public function jsonSerialize() |
30
|
|
|
{ |
31
|
|
|
return get_object_vars($this); |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* @param string $var |
36
|
|
|
*/ |
37
|
|
|
public function setAccount($var) |
38
|
|
|
{ |
39
|
|
|
$this->account = (string) $var; |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* @param string $var |
44
|
|
|
*/ |
45
|
|
|
public function setAccountName($var) |
46
|
|
|
{ |
47
|
|
|
$this->accountName = (string) $var; |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* @param float $var |
52
|
|
|
*/ |
53
|
|
|
public function setPrice($var) |
54
|
|
|
{ |
55
|
|
|
$this->price = (float) $var; |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* @param string $var |
60
|
|
|
*/ |
61
|
|
|
public function setDebitCredit($var) |
62
|
|
|
{ |
63
|
|
|
$this->debitcredit = (string) $var; |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* @param bool $var |
68
|
|
|
*/ |
69
|
|
|
public function setCancellation($var) |
70
|
|
|
{ |
71
|
|
|
$this->cancellation = (bool) $var; |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* @param string $var |
76
|
|
|
*/ |
77
|
|
|
public function setDescription($var) |
78
|
|
|
{ |
79
|
|
|
$this->description = (string) $var; |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
* @param int $var |
84
|
|
|
*/ |
85
|
|
|
public function setValueTimestamp($var) |
86
|
|
|
{ |
87
|
|
|
$this->valueTimestamp = (int) $var; |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
/** |
91
|
|
|
* @param int $var |
92
|
|
|
*/ |
93
|
|
|
public function setEntryTimestamp($var) |
94
|
|
|
{ |
95
|
|
|
$this->entryTimestamp = (int) $var; |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
/** |
99
|
|
|
* @param string $var |
100
|
|
|
*/ |
101
|
|
|
public function setTransactionCode($var) |
102
|
|
|
{ |
103
|
|
|
$this->transactionCode = (string) $var; |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
// getters |
107
|
|
|
/** |
108
|
|
|
* @return string |
109
|
|
|
*/ |
110
|
|
|
public function getAccount() |
111
|
|
|
{ |
112
|
|
|
return $this->account; |
113
|
|
|
} |
114
|
|
|
|
115
|
|
|
/** |
116
|
|
|
* @return string |
117
|
|
|
*/ |
118
|
|
|
public function getAccountName() |
119
|
|
|
{ |
120
|
|
|
return $this->accountName; |
121
|
|
|
} |
122
|
|
|
|
123
|
|
|
/** |
124
|
|
|
* @return float |
125
|
|
|
*/ |
126
|
|
|
public function getPrice() |
127
|
|
|
{ |
128
|
|
|
return $this->price; |
129
|
|
|
} |
130
|
|
|
|
131
|
|
|
/** |
132
|
|
|
* @return float |
133
|
|
|
*/ |
134
|
|
|
public function getRelativePrice() |
135
|
|
|
{ |
136
|
|
|
if ($this->isDebit()) { |
137
|
|
|
return -$this->price; |
138
|
|
|
} |
139
|
|
|
return $this->price; |
140
|
|
|
} |
141
|
|
|
|
142
|
|
|
/** |
143
|
|
|
* @return string |
144
|
|
|
*/ |
145
|
|
|
public function getDebitCredit() |
146
|
|
|
{ |
147
|
|
|
return $this->debitcredit; |
148
|
|
|
} |
149
|
|
|
|
150
|
|
|
/** |
151
|
|
|
* @return string |
152
|
|
|
*/ |
153
|
|
|
public function getDescription() |
154
|
|
|
{ |
155
|
|
|
return $this->description; |
156
|
|
|
} |
157
|
|
|
|
158
|
|
|
/** |
159
|
|
|
* @param string $format |
160
|
|
|
* |
161
|
|
|
* @return string |
162
|
|
|
*/ |
163
|
|
|
public function getValueTimestamp($format = 'U') |
164
|
|
|
{ |
165
|
|
|
return date($format, $this->valueTimestamp); |
166
|
|
|
} |
167
|
|
|
|
168
|
|
|
/** |
169
|
|
|
* @param string $format |
170
|
|
|
* |
171
|
|
|
* @return string |
172
|
|
|
*/ |
173
|
|
|
public function getEntryTimestamp($format = 'U') |
174
|
|
|
{ |
175
|
|
|
return date($format, $this->entryTimestamp); |
176
|
|
|
} |
177
|
|
|
|
178
|
|
|
/** |
179
|
|
|
* @return string |
180
|
|
|
*/ |
181
|
|
|
public function getTransactionCode() |
182
|
|
|
{ |
183
|
|
|
return $this->transactionCode; |
184
|
|
|
} |
185
|
|
|
|
186
|
|
|
/** |
187
|
|
|
* @return bool |
188
|
|
|
*/ |
189
|
|
|
public function isDebit() |
190
|
|
|
{ |
191
|
|
|
return $this->getDebitCredit() === self::DEBIT; |
192
|
|
|
} |
193
|
|
|
|
194
|
|
|
/** |
195
|
|
|
* @return bool |
196
|
|
|
*/ |
197
|
|
|
public function isCredit() |
198
|
|
|
{ |
199
|
|
|
return $this->getDebitCredit() === self::CREDIT; |
200
|
|
|
} |
201
|
|
|
|
202
|
|
|
/** |
203
|
|
|
* @return bool |
204
|
|
|
*/ |
205
|
|
|
public function isCancellation() |
206
|
|
|
{ |
207
|
|
|
return $this->cancellation; |
208
|
|
|
} |
209
|
|
|
} |
210
|
|
|
|