1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Application\Model; |
6
|
|
|
|
7
|
|
|
use Application\Traits\HasInternalRemarks; |
8
|
|
|
use Application\Traits\HasName; |
9
|
|
|
use Application\Traits\HasRemarks; |
10
|
|
|
use Cake\Chronos\Date; |
11
|
|
|
use Doctrine\Common\Collections\ArrayCollection; |
12
|
|
|
use Doctrine\Common\Collections\Collection; |
13
|
|
|
use Doctrine\ORM\Mapping as ORM; |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* An accounting journal entry (simple or compound) |
17
|
|
|
* |
18
|
|
|
* @ORM\Entity(repositoryClass="Application\Repository\TransactionRepository") |
19
|
|
|
*/ |
20
|
|
|
class Transaction extends AbstractModel |
21
|
|
|
{ |
22
|
|
|
use HasName; |
23
|
|
|
use HasRemarks; |
24
|
|
|
use HasInternalRemarks; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* @var Date |
28
|
|
|
* @ORM\Column(name="transactionDate", type="date") |
29
|
|
|
*/ |
30
|
|
|
private $transactionDate; |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* @var Collection |
34
|
|
|
* @ORM\OneToMany(targetEntity="TransactionLine", mappedBy="transaction") |
35
|
|
|
*/ |
36
|
|
|
private $transactionLines; |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* @var Collection |
40
|
|
|
* @ORM\OneToMany(targetEntity="AccountingDocument", mappedBy="transaction") |
41
|
|
|
*/ |
42
|
|
|
private $accountingDocuments; |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* @var ExpenseClaim |
46
|
|
|
* |
47
|
|
|
* @ORM\ManyToOne(targetEntity="ExpenseClaim", inversedBy="transactions") |
48
|
|
|
* @ORM\JoinColumns({ |
49
|
|
|
* @ORM\JoinColumn(nullable=true, onDelete="SET NULL") |
50
|
|
|
* }) |
51
|
|
|
*/ |
52
|
|
|
private $expenseClaim; |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* Constructor |
56
|
|
|
*/ |
57
|
13 |
|
public function __construct() |
58
|
|
|
{ |
59
|
13 |
|
$this->transactionLines = new ArrayCollection(); |
60
|
13 |
|
$this->accountingDocuments = new ArrayCollection(); |
61
|
13 |
|
} |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* Set date of transaction |
65
|
|
|
* |
66
|
|
|
* @param Date $transactionDate |
67
|
|
|
*/ |
68
|
6 |
|
public function setTransactionDate(Date $transactionDate): void |
69
|
|
|
{ |
70
|
6 |
|
$this->transactionDate = $transactionDate; |
71
|
6 |
|
} |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* Get date of transaction |
75
|
|
|
* |
76
|
|
|
* @return Date |
77
|
|
|
*/ |
78
|
|
|
public function getTransactionDate(): Date |
79
|
|
|
{ |
80
|
|
|
return $this->transactionDate; |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
/** |
84
|
|
|
* Notify when a transaction line is added |
85
|
|
|
* This should only be called by TransactionLine::setTransaction() |
86
|
|
|
* |
87
|
|
|
* @param TransactionLine $transactionLine |
88
|
|
|
*/ |
89
|
6 |
|
public function transactionLineAdded(TransactionLine $transactionLine): void |
90
|
|
|
{ |
91
|
6 |
|
$this->transactionLines->add($transactionLine); |
92
|
6 |
|
} |
93
|
|
|
|
94
|
|
|
/** |
95
|
|
|
* Notify when a transaction line is removed |
96
|
|
|
* This should only be called by TransactionLine::setTransaction() |
97
|
|
|
* |
98
|
|
|
* @param TransactionLine $transactionLine |
99
|
|
|
*/ |
100
|
|
|
public function transactionLineRemoved(TransactionLine $transactionLine): void |
101
|
|
|
{ |
102
|
|
|
$this->transactionLines->removeElement($transactionLine); |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
/** |
106
|
|
|
* @return Collection |
107
|
|
|
*/ |
108
|
6 |
|
public function getTransactionLines(): Collection |
109
|
|
|
{ |
110
|
6 |
|
return $this->transactionLines; |
111
|
|
|
} |
112
|
|
|
|
113
|
|
|
/** |
114
|
|
|
* Notify the transaction that an accounting document was added |
115
|
|
|
* This should only be called by AccountingDocument::setTransaction() |
116
|
|
|
* |
117
|
|
|
* @param AccountingDocument $document |
118
|
|
|
*/ |
119
|
1 |
|
public function accountingDocumentAdded(AccountingDocument $document): void |
120
|
|
|
{ |
121
|
1 |
|
$this->accountingDocuments->add($document); |
122
|
1 |
|
} |
123
|
|
|
|
124
|
|
|
/** |
125
|
|
|
* Notify the transaction that an accounting document was removed |
126
|
|
|
* This should only be called by AccountingDocument::setTransaction() |
127
|
|
|
* |
128
|
|
|
* @param AccountingDocument $document |
129
|
|
|
*/ |
130
|
1 |
|
public function accountingDocumentRemoved(AccountingDocument $document): void |
131
|
|
|
{ |
132
|
1 |
|
$this->accountingDocuments->removeElement($document); |
133
|
1 |
|
} |
134
|
|
|
|
135
|
|
|
/** |
136
|
|
|
* Get accounting documents |
137
|
|
|
* |
138
|
|
|
* @return Collection |
139
|
|
|
*/ |
140
|
1 |
|
public function getAccountingDocuments(): Collection |
141
|
|
|
{ |
142
|
1 |
|
return $this->accountingDocuments; |
143
|
|
|
} |
144
|
|
|
|
145
|
|
|
/** |
146
|
|
|
* Set expense claim |
147
|
|
|
* |
148
|
|
|
* @param null|ExpenseClaim $expenseClaim |
149
|
|
|
*/ |
150
|
1 |
|
public function setExpenseClaim(?ExpenseClaim $expenseClaim): void |
151
|
|
|
{ |
152
|
1 |
|
if ($this->expenseClaim && $expenseClaim !== $this->expenseClaim) { |
153
|
1 |
|
$this->expenseClaim->transactionRemoved($this); |
154
|
|
|
} |
155
|
|
|
|
156
|
1 |
|
$this->expenseClaim = $expenseClaim; |
157
|
1 |
|
$this->expenseClaim && $this->expenseClaim->transactionAdded($this); |
158
|
1 |
|
} |
159
|
|
|
|
160
|
|
|
/** |
161
|
|
|
* Get expense claim |
162
|
|
|
* |
163
|
|
|
* @return null|ExpenseClaim |
164
|
|
|
*/ |
165
|
|
|
public function getExpenseClaim(): ?ExpenseClaim |
166
|
|
|
{ |
167
|
|
|
return $this->expenseClaim; |
168
|
|
|
} |
169
|
|
|
} |
170
|
|
|
|