|
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
|
|
|
|
|
12
|
|
|
/** |
|
13
|
|
|
* A monetary transaction |
|
14
|
|
|
* |
|
15
|
|
|
* @ORM\Entity(repositoryClass="Application\Repository\TransactionRepository") |
|
16
|
|
|
*/ |
|
17
|
|
|
class Transaction extends AbstractModel |
|
18
|
|
|
{ |
|
19
|
|
|
use hasName; |
|
20
|
|
|
use hasRemarks; |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* @var Account |
|
24
|
|
|
* |
|
25
|
|
|
* @ORM\ManyToOne(targetEntity="Account", inversedBy="transactions") |
|
26
|
|
|
* @ORM\JoinColumns({ |
|
27
|
|
|
* @ORM\JoinColumn(nullable=false, onDelete="CASCADE") |
|
28
|
|
|
* }) |
|
29
|
|
|
*/ |
|
30
|
|
|
private $account; |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* @var Bookable |
|
34
|
|
|
* |
|
35
|
|
|
* @ORM\ManyToOne(targetEntity="Bookable", inversedBy="transactions") |
|
36
|
|
|
* @ORM\JoinColumns({ |
|
37
|
|
|
* @ORM\JoinColumn(nullable=true, onDelete="SET NULL") |
|
38
|
|
|
* }) |
|
39
|
|
|
*/ |
|
40
|
|
|
private $bookable; |
|
41
|
|
|
|
|
42
|
|
|
/** |
|
43
|
|
|
* @var float |
|
44
|
|
|
* |
|
45
|
|
|
* @ORM\Column(type="decimal", precision=7, scale=2) |
|
46
|
|
|
*/ |
|
47
|
|
|
private $amount; |
|
48
|
|
|
|
|
49
|
|
|
/** |
|
50
|
|
|
* @var Date |
|
51
|
|
|
* @ORM\Column(name="transactionDate", type="date") |
|
52
|
|
|
*/ |
|
53
|
|
|
private $transactionDate; |
|
54
|
|
|
|
|
55
|
|
|
/** |
|
56
|
|
|
* @var string |
|
57
|
|
|
* |
|
58
|
|
|
* @ORM\Column(type="text", length=65535) |
|
59
|
|
|
*/ |
|
60
|
|
|
private $internalRemarks = ''; |
|
61
|
|
|
|
|
62
|
|
|
/** |
|
63
|
|
|
* @var ExpenseClaim |
|
64
|
|
|
* |
|
65
|
|
|
* @ORM\ManyToOne(targetEntity="ExpenseClaim", inversedBy="transactions") |
|
66
|
|
|
* @ORM\JoinColumns({ |
|
67
|
|
|
* @ORM\JoinColumn(nullable=true, onDelete="SET NULL") |
|
68
|
|
|
* }) |
|
69
|
|
|
*/ |
|
70
|
|
|
private $expenseClaim; |
|
71
|
|
|
|
|
72
|
|
|
/** |
|
73
|
|
|
* @var Category |
|
74
|
|
|
* |
|
75
|
|
|
* @ORM\ManyToOne(targetEntity="Category", inversedBy="transactions") |
|
76
|
|
|
* @ORM\JoinColumns({ |
|
77
|
1 |
|
* @ORM\JoinColumn(nullable=true, onDelete="SET NULL") |
|
78
|
|
|
* }) |
|
79
|
1 |
|
*/ |
|
80
|
1 |
|
private $category; |
|
81
|
|
|
|
|
82
|
1 |
|
/** |
|
83
|
1 |
|
* Set account |
|
84
|
1 |
|
* |
|
85
|
|
|
* @param Account $account |
|
86
|
|
|
*/ |
|
87
|
|
|
public function setAccount(Account $account): void |
|
88
|
|
|
{ |
|
89
|
|
|
if ($this->account) { |
|
90
|
|
|
$this->account->transactionRemoved($this); |
|
91
|
1 |
|
} |
|
92
|
|
|
$this->account = $account; |
|
93
|
1 |
|
$this->account && $this->account->transactionAdded($this); |
|
94
|
|
|
} |
|
95
|
|
|
|
|
96
|
|
|
/** |
|
97
|
|
|
* Get account |
|
98
|
|
|
* |
|
99
|
|
|
* @return Account |
|
100
|
|
|
*/ |
|
101
|
|
|
public function getAccount(): Account |
|
102
|
|
|
{ |
|
103
|
|
|
return $this->account; |
|
104
|
|
|
} |
|
105
|
|
|
|
|
106
|
|
|
/** |
|
107
|
|
|
* Set bookable |
|
108
|
|
|
* |
|
109
|
|
|
* @param null|Bookable $bookable |
|
110
|
|
|
*/ |
|
111
|
|
|
public function setBookable(?Bookable $bookable): void |
|
112
|
|
|
{ |
|
113
|
|
|
if ($this->bookable) { |
|
114
|
|
|
$this->bookable->transactionRemoved($this); |
|
115
|
|
|
} |
|
116
|
|
|
$this->bookable = $bookable; |
|
117
|
|
|
$this->bookable && $this->bookable->transactionAdded($this); |
|
118
|
|
|
} |
|
119
|
|
|
|
|
120
|
|
|
/** |
|
121
|
|
|
* Set amount |
|
122
|
|
|
* |
|
123
|
|
|
* @param float $amount |
|
124
|
|
|
*/ |
|
125
|
|
|
public function setAmount(float $amount): void |
|
126
|
|
|
{ |
|
127
|
|
|
$this->amount = $amount; |
|
128
|
|
|
} |
|
129
|
|
|
|
|
130
|
|
|
/** |
|
131
|
|
|
* @return float |
|
132
|
|
|
*/ |
|
133
|
|
|
public function getAmount(): float |
|
134
|
|
|
{ |
|
135
|
|
|
return $this->amount; |
|
136
|
|
|
} |
|
137
|
|
|
|
|
138
|
|
|
/** |
|
139
|
|
|
* Set date of transaction |
|
140
|
|
|
* |
|
141
|
|
|
* @param Date $transactionDate |
|
142
|
|
|
*/ |
|
143
|
|
|
public function setTransactionDate(Date $transactionDate): void |
|
144
|
|
|
{ |
|
145
|
|
|
$this->transactionDate = $transactionDate; |
|
146
|
|
|
} |
|
147
|
|
|
|
|
148
|
|
|
/** |
|
149
|
|
|
* Get date of transaction |
|
150
|
|
|
* |
|
151
|
|
|
* @return Date |
|
152
|
|
|
*/ |
|
153
|
|
|
public function getTransactionDate(): Date |
|
154
|
|
|
{ |
|
155
|
|
|
return $this->transactionDate; |
|
156
|
|
|
} |
|
157
|
|
|
|
|
158
|
|
|
/** |
|
159
|
1 |
|
* Set remarks for internal use |
|
160
|
|
|
* |
|
161
|
1 |
|
* @param string $internalRemarks |
|
162
|
1 |
|
*/ |
|
163
|
|
|
public function setInternalRemarks(string $internalRemarks): void |
|
164
|
|
|
{ |
|
165
|
1 |
|
$this->internalRemarks = $internalRemarks; |
|
166
|
1 |
|
} |
|
167
|
1 |
|
|
|
168
|
|
|
/** |
|
169
|
|
|
* Get remarks for internal use |
|
170
|
|
|
* |
|
171
|
|
|
* @return string |
|
172
|
|
|
*/ |
|
173
|
|
|
public function getInternalRemarks(): string |
|
174
|
|
|
{ |
|
175
|
|
|
return $this->internalRemarks; |
|
176
|
|
|
} |
|
177
|
|
|
|
|
178
|
|
|
/** |
|
179
|
|
|
* Set expense claim |
|
180
|
|
|
* |
|
181
|
|
|
* @param null|ExpenseClaim $expenseClaim |
|
182
|
|
|
*/ |
|
183
|
|
|
public function setExpenseClaim(?ExpenseClaim $expenseClaim): void |
|
184
|
1 |
|
{ |
|
185
|
|
|
if ($this->expenseClaim && $expenseClaim !== $this->expenseClaim) { |
|
186
|
1 |
|
$this->expenseClaim->transactionRemoved($this); |
|
187
|
1 |
|
} |
|
188
|
|
|
|
|
189
|
|
|
$this->expenseClaim = $expenseClaim; |
|
190
|
1 |
|
$this->expenseClaim && $this->expenseClaim->transactionAdded($this); |
|
191
|
1 |
|
} |
|
192
|
1 |
|
|
|
193
|
|
|
/** |
|
194
|
|
|
* Get expense claim |
|
195
|
|
|
* |
|
196
|
|
|
* @return null|ExpenseClaim |
|
197
|
|
|
*/ |
|
198
|
|
|
public function getExpenseClaim(): ?ExpenseClaim |
|
199
|
1 |
|
{ |
|
200
|
|
|
return $this->expenseClaim; |
|
201
|
1 |
|
} |
|
202
|
|
|
|
|
203
|
|
|
/** |
|
204
|
|
|
* Set category |
|
205
|
|
|
* |
|
206
|
|
|
* @param null|Category $category |
|
207
|
|
|
*/ |
|
208
|
|
|
public function setCategory(?Category $category): void |
|
209
|
|
|
{ |
|
210
|
|
|
if ($this->category && $category !== $this->category) { |
|
211
|
|
|
$this->category->transactionRemoved($this); |
|
212
|
|
|
} |
|
213
|
|
|
|
|
214
|
|
|
$this->category = $category; |
|
215
|
|
|
$this->category && $this->category->transactionAdded($this); |
|
216
|
|
|
} |
|
217
|
|
|
|
|
218
|
|
|
/** |
|
219
|
|
|
* Get category |
|
220
|
|
|
* |
|
221
|
|
|
* @return null|Category |
|
222
|
|
|
*/ |
|
223
|
|
|
public function getCategory(): ?Category |
|
224
|
|
|
{ |
|
225
|
|
|
return $this->category; |
|
226
|
|
|
} |
|
227
|
|
|
} |
|
228
|
|
|
|