1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Application\Model; |
6
|
|
|
|
7
|
|
|
use Application\Traits\HasName; |
8
|
|
|
use Application\Traits\HasRemarks; |
9
|
|
|
use Cake\Chronos\Date; |
10
|
|
|
use Doctrine\ORM\Mapping as ORM; |
11
|
|
|
use GraphQL\Doctrine\Annotation as API; |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* A single line of accounting transaction |
15
|
|
|
* |
16
|
|
|
* @ORM\Entity(repositoryClass="Application\Repository\TransactionLineRepository") |
17
|
|
|
*/ |
18
|
|
|
class TransactionLine extends AbstractModel |
19
|
|
|
{ |
20
|
|
|
use HasName; |
21
|
|
|
use HasRemarks; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* @var Transaction |
25
|
|
|
* |
26
|
|
|
* @ORM\ManyToOne(targetEntity="Transaction", inversedBy="transactionLines") |
27
|
|
|
* @ORM\JoinColumns({ |
28
|
|
|
* @ORM\JoinColumn(nullable=false, onDelete="CASCADE") |
29
|
|
|
* }) |
30
|
|
|
*/ |
31
|
|
|
private $transaction; |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* @var null|Account |
35
|
|
|
* |
36
|
|
|
* @ORM\ManyToOne(targetEntity="Account", inversedBy="debitTransactionLines") |
37
|
|
|
* @ORM\JoinColumns({ |
38
|
|
|
* @ORM\JoinColumn(nullable=true, onDelete="RESTRICT") |
39
|
|
|
* }) |
40
|
|
|
*/ |
41
|
|
|
private $debit; |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* @var null|Account |
45
|
|
|
* |
46
|
|
|
* @ORM\ManyToOne(targetEntity="Account", inversedBy="creditTransactionLines") |
47
|
|
|
* @ORM\JoinColumns({ |
48
|
|
|
* @ORM\JoinColumn(nullable=true, onDelete="RESTRICT") |
49
|
|
|
* }) |
50
|
|
|
*/ |
51
|
|
|
private $credit; |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* @var null|Bookable |
55
|
|
|
* |
56
|
|
|
* @ORM\ManyToOne(targetEntity="Bookable") |
57
|
|
|
* @ORM\JoinColumns({ |
58
|
|
|
* @ORM\JoinColumn(nullable=true, onDelete="SET NULL") |
59
|
|
|
* }) |
60
|
|
|
*/ |
61
|
|
|
private $bookable; |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* @var string |
65
|
|
|
* |
66
|
|
|
* @ORM\Column(type="decimal", precision=7, scale=2) |
67
|
|
|
*/ |
68
|
|
|
private $balance; |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* @var Date |
72
|
|
|
* @ORM\Column(name="transactionDate", type="date") |
73
|
|
|
*/ |
74
|
|
|
private $transactionDate; |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* @var null|TransactionTag |
78
|
|
|
* |
79
|
|
|
* @ORM\ManyToOne(targetEntity="TransactionTag") |
80
|
|
|
* @ORM\JoinColumns({ |
81
|
|
|
* @ORM\JoinColumn(nullable=true, onDelete="SET NULL") |
82
|
|
|
* }) |
83
|
|
|
*/ |
84
|
|
|
private $transactionTag; |
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* @var bool |
88
|
|
|
* |
89
|
|
|
* @ORM\Column(type="boolean", options={"default" = 0}) |
90
|
|
|
*/ |
91
|
|
|
private $isReconciled = false; |
92
|
|
|
|
93
|
|
|
/** |
94
|
|
|
* @API\Exclude |
95
|
|
|
* |
96
|
|
|
* @param Transaction $transaction |
97
|
|
|
*/ |
98
|
12 |
|
public function setTransaction(Transaction $transaction): void |
99
|
|
|
{ |
100
|
12 |
|
if ($this->transaction) { |
101
|
1 |
|
$this->transaction->transactionLineRemoved($this); |
102
|
|
|
} |
103
|
|
|
|
104
|
12 |
|
$this->transaction = $transaction; |
105
|
12 |
|
$transaction->transactionLineAdded($this); |
106
|
12 |
|
} |
107
|
|
|
|
108
|
|
|
/** |
109
|
|
|
* @return Transaction |
110
|
|
|
*/ |
111
|
4 |
|
public function getTransaction(): Transaction |
112
|
|
|
{ |
113
|
4 |
|
return $this->transaction; |
114
|
|
|
} |
115
|
|
|
|
116
|
|
|
/** |
117
|
|
|
* Set debit account |
118
|
|
|
* |
119
|
|
|
* @param null|Account $account |
120
|
|
|
*/ |
121
|
11 |
|
public function setDebit(?Account $account): void |
122
|
|
|
{ |
123
|
11 |
|
if ($this->debit) { |
124
|
1 |
|
$this->debit->debitTransactionLineRemoved($this); |
125
|
|
|
} |
126
|
|
|
|
127
|
11 |
|
$this->debit = $account; |
128
|
|
|
|
129
|
11 |
|
if ($this->debit) { |
130
|
9 |
|
$this->debit->debitTransactionLineAdded($this); |
131
|
|
|
} |
132
|
11 |
|
} |
133
|
|
|
|
134
|
|
|
/** |
135
|
|
|
* Get debit account |
136
|
|
|
* |
137
|
|
|
* @return null|Account |
138
|
|
|
*/ |
139
|
10 |
|
public function getDebit(): ?Account |
140
|
|
|
{ |
141
|
10 |
|
return $this->debit; |
142
|
|
|
} |
143
|
|
|
|
144
|
|
|
/** |
145
|
|
|
* Set credit account |
146
|
|
|
* |
147
|
|
|
* @param null|Account $account |
148
|
|
|
*/ |
149
|
12 |
|
public function setCredit(?Account $account): void |
150
|
|
|
{ |
151
|
12 |
|
if ($this->credit) { |
152
|
1 |
|
$this->credit->creditTransactionLineRemoved($this); |
153
|
|
|
} |
154
|
|
|
|
155
|
12 |
|
$this->credit = $account; |
156
|
|
|
|
157
|
12 |
|
if ($this->credit) { |
158
|
12 |
|
$this->credit->creditTransactionLineAdded($this); |
159
|
|
|
} |
160
|
12 |
|
} |
161
|
|
|
|
162
|
|
|
/** |
163
|
|
|
* Get credit account |
164
|
|
|
* |
165
|
|
|
* @return null|Account |
166
|
|
|
*/ |
167
|
10 |
|
public function getCredit(): ?Account |
168
|
|
|
{ |
169
|
10 |
|
return $this->credit; |
170
|
|
|
} |
171
|
|
|
|
172
|
|
|
/** |
173
|
|
|
* Get related equipment or service |
174
|
|
|
* |
175
|
|
|
* @return null|Bookable |
176
|
|
|
*/ |
177
|
4 |
|
public function getBookable(): ?Bookable |
178
|
|
|
{ |
179
|
4 |
|
return $this->bookable; |
180
|
|
|
} |
181
|
|
|
|
182
|
|
|
/** |
183
|
|
|
* Set related equipment or service |
184
|
|
|
* |
185
|
|
|
* @param null|Bookable $bookable |
186
|
|
|
*/ |
187
|
6 |
|
public function setBookable(?Bookable $bookable): void |
188
|
|
|
{ |
189
|
6 |
|
$this->bookable = $bookable; |
190
|
6 |
|
} |
191
|
|
|
|
192
|
|
|
/** |
193
|
|
|
* Set balance |
194
|
|
|
* |
195
|
|
|
* @param string $balance |
196
|
|
|
*/ |
197
|
12 |
|
public function setBalance(string $balance): void |
198
|
|
|
{ |
199
|
12 |
|
$this->balance = $balance; |
200
|
12 |
|
} |
201
|
|
|
|
202
|
|
|
/** |
203
|
|
|
* @return string |
204
|
|
|
*/ |
205
|
8 |
|
public function getBalance(): string |
206
|
|
|
{ |
207
|
8 |
|
return $this->balance; |
208
|
|
|
} |
209
|
|
|
|
210
|
|
|
/** |
211
|
|
|
* Set date of transaction |
212
|
|
|
* |
213
|
|
|
* @param Date $transactionDate |
214
|
|
|
*/ |
215
|
12 |
|
public function setTransactionDate(Date $transactionDate): void |
216
|
|
|
{ |
217
|
12 |
|
$this->transactionDate = $transactionDate; |
218
|
12 |
|
} |
219
|
|
|
|
220
|
|
|
/** |
221
|
|
|
* Get date of transaction |
222
|
|
|
* |
223
|
|
|
* @return Date |
224
|
|
|
*/ |
225
|
|
|
public function getTransactionDate(): Date |
226
|
|
|
{ |
227
|
|
|
return $this->transactionDate; |
228
|
|
|
} |
229
|
|
|
|
230
|
|
|
/** |
231
|
|
|
* Set transaction tag |
232
|
|
|
* |
233
|
|
|
* @param null|TransactionTag $transactionTag |
234
|
|
|
*/ |
235
|
|
|
public function setTransactionTag(?TransactionTag $transactionTag): void |
236
|
|
|
{ |
237
|
|
|
$this->transactionTag = $transactionTag; |
238
|
|
|
} |
239
|
|
|
|
240
|
|
|
/** |
241
|
|
|
* Get transaction tag |
242
|
|
|
* |
243
|
|
|
* @return null|TransactionTag |
244
|
|
|
*/ |
245
|
|
|
public function getTransactionTag(): ?TransactionTag |
246
|
|
|
{ |
247
|
|
|
return $this->transactionTag; |
248
|
|
|
} |
249
|
|
|
|
250
|
|
|
/** |
251
|
|
|
* Whether this line of transaction was reconciled (e.g. from a bank statement) |
252
|
|
|
* |
253
|
|
|
* @return bool |
254
|
|
|
*/ |
255
|
|
|
public function isReconciled(): bool |
256
|
|
|
{ |
257
|
|
|
return $this->isReconciled; |
258
|
|
|
} |
259
|
|
|
|
260
|
|
|
/** |
261
|
|
|
* Whether this line of transaction was reconciled (e.g. from a bank statement) |
262
|
|
|
* |
263
|
|
|
* @param bool $isReconciled |
264
|
|
|
*/ |
265
|
3 |
|
public function setIsReconciled(bool $isReconciled): void |
266
|
|
|
{ |
267
|
3 |
|
$this->isReconciled = $isReconciled; |
268
|
3 |
|
} |
269
|
|
|
} |
270
|
|
|
|