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
|
|
|
/** |
107
|
|
|
* @return string |
108
|
|
|
*/ |
109
|
|
|
public function getAccount() |
110
|
|
|
{ |
111
|
|
|
return $this->account; |
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
/** |
115
|
|
|
* @return string |
116
|
|
|
*/ |
117
|
|
|
public function getAccountName() |
118
|
|
|
{ |
119
|
|
|
return $this->accountName; |
120
|
|
|
} |
121
|
|
|
|
122
|
|
|
/** |
123
|
|
|
* @return float |
124
|
|
|
*/ |
125
|
|
|
public function getPrice() |
126
|
|
|
{ |
127
|
|
|
return $this->price; |
128
|
|
|
} |
129
|
|
|
|
130
|
|
|
/** |
131
|
|
|
* @return float |
132
|
|
|
*/ |
133
|
|
|
public function getRelativePrice() |
134
|
|
|
{ |
135
|
|
|
if ($this->isDebit()) { |
136
|
|
|
return -$this->price; |
137
|
|
|
} |
138
|
|
|
return $this->price; |
139
|
|
|
} |
140
|
|
|
|
141
|
|
|
/** |
142
|
|
|
* @return string |
143
|
|
|
*/ |
144
|
|
|
public function getDebitCredit() |
145
|
|
|
{ |
146
|
|
|
return $this->debitcredit; |
147
|
|
|
} |
148
|
|
|
|
149
|
|
|
/** |
150
|
|
|
* @return string |
151
|
|
|
*/ |
152
|
|
|
public function getDescription() |
153
|
|
|
{ |
154
|
|
|
return $this->description; |
155
|
|
|
} |
156
|
|
|
|
157
|
|
|
/** |
158
|
|
|
* @param string $format |
159
|
|
|
* |
160
|
|
|
* @return string |
161
|
|
|
*/ |
162
|
|
|
public function getValueTimestamp($format = 'U') |
163
|
|
|
{ |
164
|
|
|
return date($format, $this->valueTimestamp); |
165
|
|
|
} |
166
|
|
|
|
167
|
|
|
/** |
168
|
|
|
* @param string $format |
169
|
|
|
* |
170
|
|
|
* @return string |
171
|
|
|
*/ |
172
|
|
|
public function getEntryTimestamp($format = 'U') |
173
|
|
|
{ |
174
|
|
|
return date($format, $this->entryTimestamp); |
175
|
|
|
} |
176
|
|
|
|
177
|
|
|
/** |
178
|
|
|
* @return string |
179
|
|
|
*/ |
180
|
|
|
public function getTransactionCode() |
181
|
|
|
{ |
182
|
|
|
return $this->transactionCode; |
183
|
|
|
} |
184
|
|
|
|
185
|
|
|
/** |
186
|
|
|
* @return bool |
187
|
|
|
*/ |
188
|
|
|
public function isDebit() |
189
|
|
|
{ |
190
|
|
|
return $this->getDebitCredit() === self::DEBIT; |
191
|
|
|
} |
192
|
|
|
|
193
|
|
|
/** |
194
|
|
|
* @return bool |
195
|
|
|
*/ |
196
|
|
|
public function isCredit() |
197
|
|
|
{ |
198
|
|
|
return $this->getDebitCredit() === self::CREDIT; |
199
|
|
|
} |
200
|
|
|
|
201
|
|
|
/** |
202
|
|
|
* @return bool |
203
|
|
|
*/ |
204
|
|
|
public function isCancellation() |
205
|
|
|
{ |
206
|
|
|
return $this->cancellation; |
207
|
|
|
} |
208
|
|
|
} |
209
|
|
|
|