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