1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Application\Model; |
6
|
|
|
|
7
|
|
|
use Application\Traits\HasIban; |
8
|
|
|
use Application\Traits\HasName; |
9
|
|
|
use Doctrine\Common\Collections\ArrayCollection; |
10
|
|
|
use Doctrine\Common\Collections\Collection; |
11
|
|
|
use Doctrine\ORM\Mapping as ORM; |
12
|
|
|
use GraphQL\Doctrine\Annotation as API; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* Financial account |
16
|
|
|
* |
17
|
|
|
* @ORM\Entity(repositoryClass="Application\Repository\AccountRepository") |
18
|
|
|
* @ORM\AssociationOverrides({ |
19
|
|
|
* @ORM\AssociationOverride( |
20
|
|
|
* name="owner", |
21
|
|
|
* inversedBy="accounts", |
22
|
|
|
* joinColumns=@ORM\JoinColumn(unique=true) |
23
|
|
|
* ) |
24
|
|
|
* }) |
25
|
|
|
*/ |
26
|
|
|
class Account extends AbstractModel |
27
|
|
|
{ |
28
|
|
|
use HasName; |
29
|
|
|
use HasIban; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* @var string |
33
|
|
|
* |
34
|
|
|
* @ORM\Column(type="decimal", precision=7, scale=2, options={"default" = "0.00"}) |
35
|
|
|
*/ |
36
|
|
|
private $balance = '0.00'; |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* @var Account |
40
|
|
|
* @ORM\ManyToOne(targetEntity="Account", inversedBy="children") |
41
|
|
|
* @ORM\JoinColumns({ |
42
|
|
|
* @ORM\JoinColumn(onDelete="CASCADE") |
43
|
|
|
* }) |
44
|
|
|
*/ |
45
|
|
|
private $parent; |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* @var Collection |
49
|
|
|
* @ORM\OneToMany(targetEntity="Account", mappedBy="parent") |
50
|
|
|
* @ORM\OrderBy({"code" = "ASC"}) |
51
|
|
|
*/ |
52
|
|
|
private $children; |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* @var string |
56
|
|
|
* |
57
|
|
|
* @ORM\Column(type="AccountType", length=10) |
58
|
|
|
*/ |
59
|
|
|
private $type; |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* @var string |
63
|
|
|
* |
64
|
|
|
* @ORM\Column(type="string", length=10, nullable=false, unique=true) |
65
|
|
|
*/ |
66
|
|
|
private $code; |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* Constructor |
70
|
|
|
*/ |
71
|
6 |
|
public function __construct() |
72
|
|
|
{ |
73
|
6 |
|
$this->children = new ArrayCollection(); |
74
|
6 |
|
} |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* Assign the account to an user |
78
|
|
|
* |
79
|
|
|
* @param null|User $owner |
80
|
|
|
*/ |
81
|
1 |
|
public function setOwner(User $owner = null): void |
82
|
|
|
{ |
83
|
1 |
|
if ($this->getOwner()) { |
84
|
1 |
|
$this->getOwner()->accountRemoved(); |
85
|
|
|
} |
86
|
|
|
|
87
|
1 |
|
parent::setOwner($owner); |
88
|
|
|
|
89
|
1 |
|
if ($this->getOwner()) { |
90
|
1 |
|
$owner->accountAdded($this); |
|
|
|
|
91
|
|
|
} |
92
|
1 |
|
} |
93
|
|
|
|
94
|
|
|
/** |
95
|
|
|
* Set balance |
96
|
|
|
* |
97
|
|
|
* @param string $balance |
98
|
|
|
* |
99
|
|
|
* @API\Exclude |
100
|
|
|
*/ |
101
|
|
|
public function setBalance(string $balance): void |
102
|
|
|
{ |
103
|
|
|
$this->balance = $balance; |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
/** |
107
|
|
|
* @return string |
108
|
|
|
*/ |
109
|
1 |
|
public function getBalance(): string |
110
|
|
|
{ |
111
|
1 |
|
return $this->balance; |
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
/** |
115
|
|
|
* Notify that an user was added |
116
|
|
|
* |
117
|
|
|
* @param null|User $user |
118
|
|
|
*/ |
119
|
|
|
public function userAdded(?User $user): void |
120
|
|
|
{ |
121
|
|
|
$this->user = $user; |
|
|
|
|
122
|
|
|
} |
123
|
|
|
|
124
|
|
|
/** |
125
|
|
|
* Set parent |
126
|
|
|
* |
127
|
|
|
* @param null|Account $parent |
128
|
|
|
*/ |
129
|
1 |
|
public function setParent(?self $parent): void |
130
|
|
|
{ |
131
|
1 |
|
if ($this->getParent()) { |
132
|
1 |
|
$this->getParent()->getChildren()->removeElement($this); |
133
|
|
|
} |
134
|
|
|
|
135
|
1 |
|
$this->parent = $parent; |
136
|
|
|
|
137
|
1 |
|
if ($this->getParent()) { |
138
|
1 |
|
$this->getParent()->getChildren()->add($this); |
139
|
|
|
} |
140
|
1 |
|
} |
141
|
|
|
|
142
|
|
|
/** |
143
|
|
|
* @return null|Account |
144
|
|
|
*/ |
145
|
1 |
|
public function getParent(): ?self |
146
|
|
|
{ |
147
|
1 |
|
return $this->parent; |
148
|
|
|
} |
149
|
|
|
|
150
|
|
|
/** |
151
|
|
|
* @return Collection |
152
|
|
|
*/ |
153
|
1 |
|
public function getChildren(): Collection |
154
|
|
|
{ |
155
|
1 |
|
return $this->children; |
156
|
|
|
} |
157
|
|
|
|
158
|
|
|
/** |
159
|
|
|
* Set type |
160
|
|
|
* |
161
|
|
|
* @API\Input(type="AccountType") |
162
|
|
|
* |
163
|
|
|
* @param string $type |
164
|
|
|
*/ |
165
|
|
|
public function setType(string $type): void |
166
|
|
|
{ |
167
|
|
|
$this->type = $type; |
168
|
|
|
} |
169
|
|
|
|
170
|
|
|
/** |
171
|
|
|
* Get type |
172
|
|
|
* |
173
|
|
|
* @API\Field(type="AccountType") |
174
|
|
|
* |
175
|
|
|
* @return string |
176
|
|
|
*/ |
177
|
|
|
public function getType(): string |
178
|
|
|
{ |
179
|
|
|
return $this->type; |
180
|
|
|
} |
181
|
|
|
|
182
|
|
|
/** |
183
|
|
|
* Set code |
184
|
|
|
* |
185
|
|
|
* @param string $code |
186
|
|
|
*/ |
187
|
|
|
public function setCode(string $code): void |
188
|
|
|
{ |
189
|
|
|
$this->code = $code; |
190
|
|
|
} |
191
|
|
|
|
192
|
|
|
/** |
193
|
|
|
* Get code |
194
|
|
|
* |
195
|
|
|
* @return string |
196
|
|
|
*/ |
197
|
|
|
public function getCode(): string |
198
|
|
|
{ |
199
|
|
|
return $this->code; |
200
|
|
|
} |
201
|
|
|
|
202
|
|
|
/** |
203
|
|
|
* Get lines of transactions |
204
|
|
|
* |
205
|
|
|
* @return TransactionLine[] |
206
|
|
|
*/ |
207
|
1 |
|
public function getTransactionLines(): array |
208
|
|
|
{ |
209
|
1 |
|
return _em()->getRepository(TransactionLine::class)->findByDebitOrCredit($this); |
210
|
|
|
} |
211
|
|
|
} |
212
|
|
|
|
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.