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
|
|
|
* A transaction account held for a member, or club's bank 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 Collection |
40
|
|
|
* @ORM\OneToMany(targetEntity="Transaction", mappedBy="account") |
41
|
|
|
*/ |
42
|
|
|
private $transactions; |
43
|
|
|
|
44
|
6 |
|
public function __construct() |
45
|
|
|
{ |
46
|
6 |
|
$this->transactions = new ArrayCollection(); |
47
|
6 |
|
} |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* Assign the transaction account to a user |
51
|
|
|
* |
52
|
|
|
* @param null|User $owner |
53
|
|
|
*/ |
54
|
1 |
|
public function setOwner(User $owner = null): void |
55
|
|
|
{ |
56
|
1 |
|
if ($this->getOwner()) { |
57
|
1 |
|
$this->getOwner()->accountRemoved(); |
58
|
|
|
} |
59
|
|
|
|
60
|
1 |
|
parent::setOwner($owner); |
61
|
|
|
|
62
|
1 |
|
if ($this->getOwner()) { |
63
|
1 |
|
$owner->accountAdded($this); |
|
|
|
|
64
|
|
|
} |
65
|
1 |
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* Set balance |
69
|
|
|
* |
70
|
|
|
* @param string $balance |
71
|
|
|
* |
72
|
|
|
* @API\Exclude |
73
|
|
|
*/ |
74
|
|
|
public function setBalance(string $balance): void |
75
|
|
|
{ |
76
|
|
|
$this->balance = $balance; |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* @return string |
81
|
|
|
*/ |
82
|
|
|
public function getBalance(): string |
83
|
|
|
{ |
84
|
|
|
return $this->balance; |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
/** |
88
|
|
|
* Get all transactions |
89
|
|
|
* |
90
|
|
|
* @return Collection |
91
|
|
|
*/ |
92
|
1 |
|
public function getTransactions(): Collection |
93
|
|
|
{ |
94
|
1 |
|
return $this->transactions; |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
/** |
98
|
|
|
* Notify the account that it has a new transaction |
99
|
|
|
* This should only be called by Transaction::setAccount() |
100
|
|
|
* |
101
|
|
|
* @param Transaction $transaction |
102
|
|
|
*/ |
103
|
1 |
|
public function transactionAdded(Transaction $transaction): void |
104
|
|
|
{ |
105
|
1 |
|
$this->transactions->add($transaction); |
106
|
1 |
|
} |
107
|
|
|
|
108
|
|
|
/** |
109
|
|
|
* Notify the account that a transaction was removed |
110
|
|
|
* This should only be called by Transaction::setAccount() |
111
|
|
|
* |
112
|
|
|
* @param Transaction $transaction |
113
|
|
|
*/ |
114
|
1 |
|
public function transactionRemoved(Transaction $transaction): void |
115
|
|
|
{ |
116
|
1 |
|
$this->transactions->removeElement($transaction); |
117
|
1 |
|
} |
118
|
|
|
|
119
|
|
|
/** |
120
|
|
|
* Notify that an user was added |
121
|
|
|
* |
122
|
|
|
* @param null|User $user |
123
|
|
|
*/ |
124
|
|
|
public function userAdded(?User $user): void |
125
|
|
|
{ |
126
|
|
|
$this->user = $user; |
|
|
|
|
127
|
|
|
} |
128
|
|
|
} |
129
|
|
|
|
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.