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
|
|
|
* @ORM\JoinColumn(nullable=true, onDelete="SET NULL") |
78
|
|
|
* }) |
79
|
|
|
*/ |
80
|
|
|
private $category; |
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
* Set account |
84
|
|
|
* |
85
|
|
|
* @param Account $account |
86
|
|
|
*/ |
87
|
1 |
|
public function setAccount(Account $account): void |
88
|
|
|
{ |
89
|
1 |
|
if ($this->account) { |
90
|
1 |
|
$this->account->transactionRemoved($this); |
91
|
|
|
} |
92
|
1 |
|
$this->account = $account; |
93
|
1 |
|
$this->account && $this->account->transactionAdded($this); |
94
|
1 |
|
} |
95
|
|
|
|
96
|
|
|
/** |
97
|
|
|
* Get account |
98
|
|
|
* |
99
|
|
|
* @return Account |
100
|
|
|
*/ |
101
|
1 |
|
public function getAccount(): Account |
102
|
|
|
{ |
103
|
1 |
|
return $this->account; |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
/** |
107
|
|
|
* Set bookable |
108
|
|
|
* |
109
|
|
|
* @param null|Bookable $bookable |
110
|
|
|
*/ |
111
|
1 |
|
public function setBookable(?Bookable $bookable): void |
112
|
|
|
{ |
113
|
1 |
|
if ($this->bookable) { |
114
|
1 |
|
$this->bookable->transactionRemoved($this); |
115
|
|
|
} |
116
|
1 |
|
$this->bookable = $bookable; |
117
|
1 |
|
$this->bookable && $this->bookable->transactionAdded($this); |
118
|
1 |
|
} |
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
|
|
|
* Set remarks for internal use |
160
|
|
|
* |
161
|
|
|
* @param string $internalRemarks |
162
|
|
|
*/ |
163
|
|
|
public function setInternalRemarks(string $internalRemarks): void |
164
|
|
|
{ |
165
|
|
|
$this->internalRemarks = $internalRemarks; |
166
|
|
|
} |
167
|
|
|
|
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
|
1 |
|
public function setExpenseClaim(?ExpenseClaim $expenseClaim): void |
184
|
|
|
{ |
185
|
1 |
|
if ($this->expenseClaim && $expenseClaim !== $this->expenseClaim) { |
186
|
1 |
|
$this->expenseClaim->transactionRemoved($this); |
187
|
|
|
} |
188
|
|
|
|
189
|
1 |
|
$this->expenseClaim = $expenseClaim; |
190
|
1 |
|
$this->expenseClaim && $this->expenseClaim->transactionAdded($this); |
191
|
1 |
|
} |
192
|
|
|
|
193
|
|
|
/** |
194
|
|
|
* Get expense claim |
195
|
|
|
* |
196
|
|
|
* @return null|ExpenseClaim |
197
|
|
|
*/ |
198
|
|
|
public function getExpenseClaim(): ?ExpenseClaim |
199
|
|
|
{ |
200
|
|
|
return $this->expenseClaim; |
201
|
|
|
} |
202
|
|
|
|
203
|
|
|
/** |
204
|
|
|
* Set category |
205
|
|
|
* |
206
|
|
|
* @param null|Category $category |
207
|
|
|
*/ |
208
|
1 |
|
public function setCategory(?Category $category): void |
209
|
|
|
{ |
210
|
1 |
|
if ($this->category && $category !== $this->category) { |
211
|
1 |
|
$this->category->transactionRemoved($this); |
212
|
|
|
} |
213
|
|
|
|
214
|
1 |
|
$this->category = $category; |
215
|
1 |
|
$this->category && $this->category->transactionAdded($this); |
216
|
1 |
|
} |
217
|
|
|
|
218
|
|
|
/** |
219
|
|
|
* Get category |
220
|
|
|
* |
221
|
|
|
* @return null|Category |
222
|
|
|
*/ |
223
|
1 |
|
public function getCategory(): ?Category |
224
|
|
|
{ |
225
|
1 |
|
return $this->category; |
226
|
|
|
} |
227
|
|
|
} |
228
|
|
|
|