|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace Application\Model; |
|
6
|
|
|
|
|
7
|
|
|
use Application\Traits\HasName; |
|
8
|
|
|
use Doctrine\Common\Collections\ArrayCollection; |
|
9
|
|
|
use Doctrine\Common\Collections\Collection; |
|
10
|
|
|
use Doctrine\ORM\Mapping as ORM; |
|
11
|
|
|
use GraphQL\Doctrine\Annotation as API; |
|
12
|
|
|
|
|
13
|
|
|
/** |
|
14
|
|
|
* A transaction account held for a member, or club's bank account |
|
15
|
|
|
* |
|
16
|
|
|
* @ORM\Entity(repositoryClass="Application\Repository\AccountRepository") |
|
17
|
|
|
* @ORM\AssociationOverrides({ |
|
18
|
|
|
* @ORM\AssociationOverride(name="owner", inversedBy="accounts", |
|
19
|
|
|
* joinColumns=@ORM\JoinColumn(unique=true) |
|
20
|
|
|
* ) |
|
21
|
|
|
* }) |
|
22
|
|
|
*/ |
|
23
|
|
|
class Account extends AbstractModel |
|
24
|
|
|
{ |
|
25
|
|
|
use HasName; |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* @var string |
|
29
|
|
|
* |
|
30
|
|
|
* @ORM\Column(type="decimal", precision=7, scale=2, options={"default" = "0.00"}) |
|
31
|
|
|
*/ |
|
32
|
|
|
private $balance = '0.00'; |
|
33
|
|
|
|
|
34
|
|
|
/** |
|
35
|
|
|
* @var string |
|
36
|
|
|
* |
|
37
|
|
|
* @ORM\Column(type="string", length=32, unique=true) |
|
38
|
|
|
*/ |
|
39
|
|
|
private $iban; |
|
40
|
|
|
|
|
41
|
|
|
/** |
|
42
|
|
|
* @var Collection |
|
43
|
|
|
* @ORM\OneToMany(targetEntity="Transaction", mappedBy="account") |
|
44
|
|
|
*/ |
|
45
|
|
|
private $transactions; |
|
46
|
|
|
|
|
47
|
5 |
|
public function __construct() |
|
48
|
|
|
{ |
|
49
|
5 |
|
$this->transactions = new ArrayCollection(); |
|
50
|
5 |
|
} |
|
51
|
|
|
|
|
52
|
|
|
/** |
|
53
|
|
|
* Assign the transaction account to a user |
|
54
|
|
|
* |
|
55
|
|
|
* @param null|User $owner |
|
56
|
|
|
*/ |
|
57
|
1 |
|
public function setOwner(User $owner = null): void |
|
58
|
|
|
{ |
|
59
|
1 |
|
if ($this->getOwner()) { |
|
60
|
1 |
|
$this->getOwner()->accountRemoved(); |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
1 |
|
parent::setOwner($owner); |
|
64
|
|
|
|
|
65
|
1 |
|
if ($this->getOwner()) { |
|
66
|
1 |
|
$owner->accountAdded($this); |
|
|
|
|
|
|
67
|
|
|
} |
|
68
|
1 |
|
} |
|
69
|
|
|
|
|
70
|
|
|
/** |
|
71
|
|
|
* Set balance |
|
72
|
|
|
* |
|
73
|
|
|
* @param string $balance |
|
74
|
|
|
* |
|
75
|
|
|
* @API\Exclude |
|
76
|
|
|
*/ |
|
77
|
|
|
public function setBalance(string $balance): void |
|
78
|
|
|
{ |
|
79
|
|
|
$this->balance = $balance; |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
/** |
|
83
|
|
|
* @return string |
|
84
|
|
|
*/ |
|
85
|
|
|
public function getBalance(): string |
|
86
|
|
|
{ |
|
87
|
|
|
return $this->balance; |
|
88
|
|
|
} |
|
89
|
|
|
|
|
90
|
|
|
/** |
|
91
|
|
|
* Set the IBAN (international bank account number) |
|
92
|
|
|
* |
|
93
|
|
|
* @param string $iban |
|
94
|
|
|
*/ |
|
95
|
|
|
public function setIban(string $iban): void |
|
96
|
|
|
{ |
|
97
|
|
|
$this->iban = $iban; |
|
98
|
|
|
} |
|
99
|
|
|
|
|
100
|
|
|
/** |
|
101
|
|
|
* Get the IBAN (international bank account number) |
|
102
|
|
|
* |
|
103
|
|
|
* @return string |
|
104
|
|
|
*/ |
|
105
|
|
|
public function getIban(): string |
|
106
|
|
|
{ |
|
107
|
|
|
return $this->iban; |
|
108
|
|
|
} |
|
109
|
|
|
|
|
110
|
|
|
/** |
|
111
|
|
|
* Get all transactions |
|
112
|
|
|
* |
|
113
|
|
|
* @return Collection |
|
114
|
|
|
*/ |
|
115
|
1 |
|
public function getTransactions(): Collection |
|
116
|
|
|
{ |
|
117
|
1 |
|
return $this->transactions; |
|
118
|
|
|
} |
|
119
|
|
|
|
|
120
|
|
|
/** |
|
121
|
|
|
* Notify the account that it has a new transaction |
|
122
|
|
|
* This should only be called by Transaction::setAccount() |
|
123
|
|
|
* |
|
124
|
|
|
* @param Transaction $transaction |
|
125
|
|
|
*/ |
|
126
|
1 |
|
public function transactionAdded(Transaction $transaction): void |
|
127
|
|
|
{ |
|
128
|
1 |
|
$this->transactions->add($transaction); |
|
129
|
1 |
|
} |
|
130
|
|
|
|
|
131
|
|
|
/** |
|
132
|
|
|
* Notify the account that a transaction was removed |
|
133
|
|
|
* This should only be called by Transaction::setAccount() |
|
134
|
|
|
* |
|
135
|
|
|
* @param Transaction $transaction |
|
136
|
|
|
*/ |
|
137
|
1 |
|
public function transactionRemoved(Transaction $transaction): void |
|
138
|
|
|
{ |
|
139
|
1 |
|
$this->transactions->removeElement($transaction); |
|
140
|
1 |
|
} |
|
141
|
|
|
|
|
142
|
|
|
/** |
|
143
|
|
|
* Notify that an user was added |
|
144
|
|
|
* |
|
145
|
|
|
* @param null|User $user |
|
146
|
|
|
*/ |
|
147
|
|
|
public function userAdded(?User $user): void |
|
148
|
|
|
{ |
|
149
|
|
|
$this->user = $user; |
|
|
|
|
|
|
150
|
|
|
} |
|
151
|
|
|
} |
|
152
|
|
|
|
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.