1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace App\Entity; |
4
|
|
|
|
5
|
|
|
use Doctrine\Common\Collections\ArrayCollection; |
6
|
|
|
use Doctrine\Common\Collections\Collection; |
7
|
|
|
use Doctrine\ORM\Mapping as ORM; |
8
|
|
|
|
9
|
|
|
/** |
10
|
|
|
* @ORM\Entity |
11
|
|
|
*/ |
12
|
|
|
class Transaction |
13
|
|
|
{ |
14
|
|
|
/** |
15
|
|
|
* @ORM\Id() |
16
|
|
|
* @ORM\GeneratedValue() |
17
|
|
|
* @ORM\Column(type="integer") |
18
|
|
|
*/ |
19
|
|
|
private $id; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* @ORM\Column(type="datetime") |
23
|
|
|
*/ |
24
|
|
|
private $date; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* @ORM\Column(type="string", length=25) |
28
|
|
|
*/ |
29
|
|
|
private $invoice_number; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* @ORM\Column(type="string", length=25) |
33
|
|
|
*/ |
34
|
|
|
private $user_id; |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* @ORM\Column(type="decimal", precision=7, scale=2) |
38
|
|
|
*/ |
39
|
|
|
private $total_balance; |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* @ORM\OneToMany(targetEntity="App\Entity\Fee", mappedBy="transaction", orphanRemoval=true) |
43
|
|
|
*/ |
44
|
|
|
private $fees; |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* @ORM\Column(type="boolean", nullable=true) |
48
|
|
|
*/ |
49
|
|
|
private $notified; |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* @ORM\Column(type="string", length=20) |
53
|
|
|
*/ |
54
|
|
|
private $status; |
55
|
|
|
|
56
|
|
|
const STATUS_PENDING = 'PENDING'; |
57
|
|
|
const STATUS_PAID = 'PAID'; |
58
|
|
|
const STATUS_COMPLETED = 'COMPLETED'; |
59
|
|
|
const STATUS_FAILED = 'FAILED'; |
60
|
|
|
const STATUS_DECLINED = 'DECLINED'; |
61
|
|
|
const STATUS_ERROR = 'ERROR'; |
62
|
|
|
|
63
|
|
|
public function __construct($user_id, $invoice_number = null, $status = self::STATUS_PENDING, $date = null, $notified = false) |
64
|
|
|
{ |
65
|
|
|
$this->fees = new ArrayCollection(); |
66
|
|
|
$this->user_id = $user_id; |
67
|
|
|
$this->status = $status; |
68
|
|
|
$this->invoice_number = $invoice_number ?: uniqid(); |
69
|
|
|
$this->date = $date ?: new \DateTime(); |
70
|
|
|
$this->notified = $notified; |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
public function getId() |
74
|
|
|
{ |
75
|
|
|
return $this->id; |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
public function getDate(): ?\DateTimeInterface |
79
|
|
|
{ |
80
|
|
|
return $this->date; |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
public function setDate(\DateTimeInterface $date): self |
84
|
|
|
{ |
85
|
|
|
$this->date = $date; |
86
|
|
|
|
87
|
|
|
return $this; |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
public function getInvoiceNumber(): ?string |
91
|
|
|
{ |
92
|
|
|
return $this->invoice_number; |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
public function setInvoiceNumber(string $invoice_number): self |
96
|
|
|
{ |
97
|
|
|
$this->invoice_number = $invoice_number; |
98
|
|
|
|
99
|
|
|
return $this; |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
public function getUserId(): ?string |
103
|
|
|
{ |
104
|
|
|
return $this->user_id; |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
public function setUserId(string $user_id): self |
108
|
|
|
{ |
109
|
|
|
$this->user_id = $user_id; |
110
|
|
|
|
111
|
|
|
return $this; |
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
public function getTotalBalance() |
115
|
|
|
{ |
116
|
|
|
return $this->total_balance; |
117
|
|
|
} |
118
|
|
|
|
119
|
|
|
public function setTotalBalance($total_balance): self |
120
|
|
|
{ |
121
|
|
|
$this->total_balance = $total_balance; |
122
|
|
|
|
123
|
|
|
return $this; |
124
|
|
|
} |
125
|
|
|
|
126
|
|
|
/** |
127
|
|
|
* @return Collection|Fee[] |
128
|
|
|
*/ |
129
|
|
|
public function getFees(): Collection |
130
|
|
|
{ |
131
|
|
|
return $this->fees; |
132
|
|
|
} |
133
|
|
|
|
134
|
|
|
public function addFee(Fee $fee): self |
135
|
|
|
{ |
136
|
|
|
if (!$this->fees->contains($fee)) { |
137
|
|
|
$this->fees[] = $fee; |
138
|
|
|
$fee->setTransaction($this); |
139
|
|
|
} |
140
|
|
|
|
141
|
|
|
return $this; |
142
|
|
|
} |
143
|
|
|
|
144
|
|
|
public function removeFee(Fee $fee): self |
145
|
|
|
{ |
146
|
|
|
if ($this->fees->contains($fee)) { |
147
|
|
|
$this->fees->removeElement($fee); |
148
|
|
|
// set the owning side to null (unless already changed) |
149
|
|
|
if ($fee->getTransaction() === $this) { |
150
|
|
|
$fee->setTransaction(null); |
151
|
|
|
} |
152
|
|
|
} |
153
|
|
|
|
154
|
|
|
return $this; |
155
|
|
|
} |
156
|
|
|
|
157
|
|
|
public function getNotified(): ?bool |
158
|
|
|
{ |
159
|
|
|
return $this->notified; |
160
|
|
|
} |
161
|
|
|
|
162
|
|
|
public function setNotified(?bool $notified): self |
163
|
|
|
{ |
164
|
|
|
$this->notified = $notified; |
165
|
|
|
|
166
|
|
|
return $this; |
167
|
|
|
} |
168
|
|
|
|
169
|
|
|
public function getStatus(): ?string |
170
|
|
|
{ |
171
|
|
|
return $this->status; |
172
|
|
|
} |
173
|
|
|
|
174
|
|
|
/** |
175
|
|
|
* Set the status of this Transaction to one of the defined available statuses. |
176
|
|
|
* |
177
|
|
|
* @param string $status -- A string containing one of the available statuses. |
178
|
|
|
* @throws InvalidArgumentException |
179
|
|
|
* @return $this |
180
|
|
|
*/ |
181
|
|
|
public function setStatus(string $status): self |
182
|
|
|
{ |
183
|
|
|
if (!in_array($status, array(self::STATUS_PENDING, self::STATUS_PAID, self::STATUS_COMPLETED, self::STATUS_FAILED, self::STATUS_DECLINED, self::STATUS_ERROR))) { |
184
|
|
|
throw new \InvalidArgumentException("Invalid status"); |
185
|
|
|
} |
186
|
|
|
$this->status = $status; |
187
|
|
|
|
188
|
|
|
return $this; |
189
|
|
|
} |
190
|
|
|
} |
191
|
|
|
|