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