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