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