1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the vseth-musikzimmer-pay project. |
5
|
|
|
* |
6
|
|
|
* (c) Florian Moser <[email protected]> |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace App\Entity; |
13
|
|
|
|
14
|
|
|
use App\Entity\Base\BaseEntity; |
15
|
|
|
use App\Entity\Traits\IdTrait; |
16
|
|
|
use App\Enum\PaymentRemainderStatusType; |
17
|
|
|
use App\Enum\UserCategoryType; |
18
|
|
|
use App\Model\Bill\Recipient; |
19
|
|
|
use App\Model\PaymentInfo; |
20
|
|
|
use Doctrine\Common\Collections\ArrayCollection; |
21
|
|
|
use Doctrine\ORM\Mapping as ORM; |
22
|
|
|
use Ramsey\Uuid\Uuid; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* an event determines how the questionnaire looks like. |
26
|
|
|
* |
27
|
|
|
* @ORM\Entity(repositoryClass="App\Repository\UserRepository") |
28
|
|
|
* @ORM\HasLifecycleCallbacks |
29
|
|
|
*/ |
30
|
|
|
class User extends BaseEntity |
31
|
|
|
{ |
32
|
|
|
use IdTrait; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* @var string |
36
|
|
|
* |
37
|
|
|
* @ORM\Column(type="text") |
38
|
|
|
*/ |
39
|
|
|
private $authenticationCode; |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* @var string |
43
|
|
|
* |
44
|
|
|
* @ORM\Column(type="text") |
45
|
|
|
*/ |
46
|
|
|
private $email; |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* @var string |
50
|
|
|
* |
51
|
|
|
* @ORM\Column(type="text") |
52
|
|
|
*/ |
53
|
|
|
private $givenName; |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* @var string |
57
|
|
|
* |
58
|
|
|
* @ORM\Column(type="text") |
59
|
|
|
*/ |
60
|
|
|
private $familyName; |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* @var string |
64
|
|
|
* |
65
|
|
|
* @ORM\Column(type="text") |
66
|
|
|
*/ |
67
|
|
|
private $address; |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* @var string |
71
|
|
|
* |
72
|
|
|
* @ORM\Column(type="text") |
73
|
|
|
*/ |
74
|
|
|
private $phone; |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* @var int |
78
|
|
|
* |
79
|
|
|
* @ORM\Column(type="integer") |
80
|
|
|
*/ |
81
|
|
|
private $category = UserCategoryType::STUDENT; |
82
|
|
|
|
83
|
|
|
/** |
84
|
|
|
* @var int |
85
|
|
|
* |
86
|
|
|
* @ORM\Column(type="integer") |
87
|
|
|
*/ |
88
|
|
|
private $discount = 0; |
89
|
|
|
|
90
|
|
|
/** |
91
|
|
|
* @var string|null |
92
|
|
|
* |
93
|
|
|
* @ORM\Column(type="text", nullable=true) |
94
|
|
|
*/ |
95
|
|
|
private $discountDescription; |
96
|
|
|
|
97
|
|
|
/** |
98
|
|
|
* @var \DateTime|null |
99
|
|
|
* |
100
|
|
|
* @ORM\Column(type="datetime", nullable=true) |
101
|
|
|
*/ |
102
|
|
|
private $lastPayedPeriodicFeeEnd; |
103
|
|
|
|
104
|
|
|
/** |
105
|
|
|
* this is in francs. |
106
|
|
|
* |
107
|
|
|
* @var int |
108
|
|
|
* |
109
|
|
|
* @ORM\Column(type="integer") |
110
|
|
|
*/ |
111
|
|
|
private $amountOwed; |
112
|
|
|
|
113
|
|
|
/** |
114
|
|
|
* this is in cents. |
115
|
|
|
* |
116
|
|
|
* @var int|null |
117
|
|
|
* |
118
|
|
|
* @ORM\Column(type="integer", nullable=true) |
119
|
|
|
*/ |
120
|
|
|
private $amountPayed; |
121
|
|
|
|
122
|
|
|
/** |
123
|
|
|
* @var string|null |
124
|
|
|
* |
125
|
|
|
* @ORM\Column(type="text", nullable=true) |
126
|
|
|
*/ |
127
|
|
|
private $transactionId; |
128
|
|
|
|
129
|
|
|
/** |
130
|
|
|
* @var int|null |
131
|
|
|
* |
132
|
|
|
* @ORM\Column(type="integer", nullable=true) |
133
|
|
|
*/ |
134
|
|
|
private $invoiceId; |
135
|
|
|
|
136
|
|
|
/** |
137
|
|
|
* @var string|null |
138
|
|
|
* |
139
|
|
|
* @ORM\Column(type="text", nullable=true) |
140
|
|
|
*/ |
141
|
|
|
private $invoiceLink; |
142
|
|
|
|
143
|
|
|
/** |
144
|
|
|
* @var int |
145
|
|
|
* |
146
|
|
|
* @ORM\Column(type="integer") |
147
|
|
|
*/ |
148
|
|
|
private $paymentRemainderStatus = PaymentRemainderStatusType::NONE; |
149
|
|
|
|
150
|
|
|
/** |
151
|
|
|
* @var bool |
152
|
|
|
* |
153
|
|
|
* @ORM\Column(type="boolean", options={"default" : false}) |
154
|
|
|
*/ |
155
|
|
|
private $markedAsPayed; |
156
|
|
|
|
157
|
|
|
/** |
158
|
|
|
* @var \DateTime|null |
159
|
|
|
* |
160
|
|
|
* @ORM\Column(type="datetime",nullable=true) |
161
|
|
|
*/ |
162
|
|
|
private $paymentRemainderStatusAt; |
163
|
|
|
|
164
|
|
|
/** |
165
|
|
|
* @var PaymentRemainder|null |
166
|
|
|
* |
167
|
|
|
* @ORM\ManyToOne(targetEntity="App\Entity\PaymentRemainder", inversedBy="users") |
168
|
|
|
*/ |
169
|
|
|
private $paymentRemainder; |
170
|
|
|
|
171
|
|
|
/** |
172
|
|
|
* @var Reservation[]|ArrayCollection |
173
|
|
|
* |
174
|
|
|
* @ORM\OneToMany(targetEntity="App\Entity\Reservation", mappedBy="user") |
175
|
|
|
*/ |
176
|
|
|
private $reservations; |
177
|
|
|
|
178
|
|
|
public function __construct() |
179
|
|
|
{ |
180
|
|
|
$this->reservations = new ArrayCollection(); |
181
|
|
|
} |
182
|
|
|
|
183
|
|
|
public function generateAuthenticationCode(): void |
184
|
|
|
{ |
185
|
|
|
$this->authenticationCode = Uuid::uuid4()->toString(); |
186
|
|
|
} |
187
|
|
|
|
188
|
|
|
public function getEmail(): string |
189
|
|
|
{ |
190
|
|
|
return $this->email; |
191
|
|
|
} |
192
|
|
|
|
193
|
|
|
public function setEmail(string $email): void |
194
|
|
|
{ |
195
|
|
|
$this->email = $email; |
196
|
|
|
} |
197
|
|
|
|
198
|
|
|
public function getGivenName(): string |
199
|
|
|
{ |
200
|
|
|
return $this->givenName; |
201
|
|
|
} |
202
|
|
|
|
203
|
|
|
public function setGivenName(string $givenName): void |
204
|
|
|
{ |
205
|
|
|
$this->givenName = $givenName; |
206
|
|
|
} |
207
|
|
|
|
208
|
|
|
public function getFamilyName(): string |
209
|
|
|
{ |
210
|
|
|
return $this->familyName; |
211
|
|
|
} |
212
|
|
|
|
213
|
|
|
public function setFamilyName(string $familyName): void |
214
|
|
|
{ |
215
|
|
|
$this->familyName = $familyName; |
216
|
|
|
} |
217
|
|
|
|
218
|
|
|
public function getAddress(): string |
219
|
|
|
{ |
220
|
|
|
return $this->address; |
221
|
|
|
} |
222
|
|
|
|
223
|
|
|
public function setAddress(string $address): void |
224
|
|
|
{ |
225
|
|
|
$this->address = $address; |
226
|
|
|
} |
227
|
|
|
|
228
|
|
|
public function getPhone(): string |
229
|
|
|
{ |
230
|
|
|
return $this->phone; |
231
|
|
|
} |
232
|
|
|
|
233
|
|
|
public function setPhone(string $phone): void |
234
|
|
|
{ |
235
|
|
|
$this->phone = $phone; |
236
|
|
|
} |
237
|
|
|
|
238
|
|
|
public function getCategory(): int |
239
|
|
|
{ |
240
|
|
|
return $this->category; |
241
|
|
|
} |
242
|
|
|
|
243
|
|
|
public function setCategory(int $category): void |
244
|
|
|
{ |
245
|
|
|
$this->category = $category; |
246
|
|
|
} |
247
|
|
|
|
248
|
|
|
public function getDiscount(): int |
249
|
|
|
{ |
250
|
|
|
return $this->discount; |
251
|
|
|
} |
252
|
|
|
|
253
|
|
|
public function setDiscount(int $discount): void |
254
|
|
|
{ |
255
|
|
|
$this->discount = $discount; |
256
|
|
|
} |
257
|
|
|
|
258
|
|
|
public function getDiscountDescription(): ?string |
259
|
|
|
{ |
260
|
|
|
return $this->discountDescription; |
261
|
|
|
} |
262
|
|
|
|
263
|
|
|
public function setDiscountDescription(?string $discountDescription): void |
264
|
|
|
{ |
265
|
|
|
$this->discountDescription = $discountDescription; |
266
|
|
|
} |
267
|
|
|
|
268
|
|
|
public function getLastPayedPeriodicFeeEnd(): ?\DateTime |
269
|
|
|
{ |
270
|
|
|
return $this->lastPayedPeriodicFeeEnd; |
271
|
|
|
} |
272
|
|
|
|
273
|
|
|
public function setLastPayedPeriodicFeeEnd(?\DateTime $lastPayedPeriodicFeeEnd): void |
274
|
|
|
{ |
275
|
|
|
$this->lastPayedPeriodicFeeEnd = $lastPayedPeriodicFeeEnd; |
276
|
|
|
} |
277
|
|
|
|
278
|
|
|
public function getAmountOwed(): int |
279
|
|
|
{ |
280
|
|
|
return $this->amountOwed; |
281
|
|
|
} |
282
|
|
|
|
283
|
|
|
public function setAmountOwed(int $amountOwed): void |
284
|
|
|
{ |
285
|
|
|
$this->amountOwed = $amountOwed; |
286
|
|
|
} |
287
|
|
|
|
288
|
|
|
public function getInvoiceId(): ?int |
289
|
|
|
{ |
290
|
|
|
return $this->invoiceId; |
291
|
|
|
} |
292
|
|
|
|
293
|
|
|
public function setInvoiceId(?int $invoiceId): void |
294
|
|
|
{ |
295
|
|
|
$this->invoiceId = $invoiceId; |
296
|
|
|
} |
297
|
|
|
|
298
|
|
|
public function getInvoiceLink(): ?string |
299
|
|
|
{ |
300
|
|
|
return $this->invoiceLink; |
301
|
|
|
} |
302
|
|
|
|
303
|
|
|
public function setInvoiceLink(?string $invoiceLink): void |
304
|
|
|
{ |
305
|
|
|
$this->invoiceLink = $invoiceLink; |
306
|
|
|
} |
307
|
|
|
|
308
|
|
|
public function getPaymentRemainderStatus(): int |
309
|
|
|
{ |
310
|
|
|
return $this->paymentRemainderStatus; |
311
|
|
|
} |
312
|
|
|
|
313
|
|
|
public function setPaymentRemainderStatus(int $paymentRemainderStatus): void |
314
|
|
|
{ |
315
|
|
|
$this->paymentRemainderStatus = $paymentRemainderStatus; |
316
|
|
|
$this->paymentRemainderStatusAt = new \DateTime(); |
317
|
|
|
} |
318
|
|
|
|
319
|
|
|
public function getPaymentRemainderStatusAt(): ?\DateTime |
320
|
|
|
{ |
321
|
|
|
return $this->paymentRemainderStatusAt; |
322
|
|
|
} |
323
|
|
|
|
324
|
|
|
public function getPaymentRemainder(): ?PaymentRemainder |
325
|
|
|
{ |
326
|
|
|
return $this->paymentRemainder; |
327
|
|
|
} |
328
|
|
|
|
329
|
|
|
public function setPaymentRemainder(?PaymentRemainder $paymentRemainder): void |
330
|
|
|
{ |
331
|
|
|
$this->paymentRemainder = $paymentRemainder; |
332
|
|
|
} |
333
|
|
|
|
334
|
|
|
/** |
335
|
|
|
* @return Reservation[]|ArrayCollection |
336
|
|
|
*/ |
337
|
|
|
public function getReservations() |
338
|
|
|
{ |
339
|
|
|
return $this->reservations; |
340
|
|
|
} |
341
|
|
|
|
342
|
|
|
public function writePaymentInfo(PaymentInfo $paymentInfo) |
343
|
|
|
{ |
344
|
|
|
$this->invoiceId = $paymentInfo->getInvoiceId(); |
345
|
|
|
$this->invoiceLink = $paymentInfo->getInvoiceLink(); |
346
|
|
|
} |
347
|
|
|
|
348
|
|
|
/** |
349
|
|
|
* @return PaymentInfo |
350
|
|
|
*/ |
351
|
|
|
public function getPaymentInfo() |
352
|
|
|
{ |
353
|
|
|
if ($this->invoiceId === null || $this->invoiceLink === null) { |
354
|
|
|
throw new \Exception('no payment info available'); |
355
|
|
|
} |
356
|
|
|
|
357
|
|
|
$paymentInfo = new PaymentInfo(); |
358
|
|
|
|
359
|
|
|
$paymentInfo->setInvoiceId($this->invoiceId); |
360
|
|
|
$paymentInfo->setInvoiceLink($this->invoiceLink); |
361
|
|
|
|
362
|
|
|
return $paymentInfo; |
363
|
|
|
} |
364
|
|
|
|
365
|
|
|
public function clearPaymentInfo() |
366
|
|
|
{ |
367
|
|
|
$this->invoiceLink = null; |
368
|
|
|
$this->invoiceId = null; |
369
|
|
|
} |
370
|
|
|
|
371
|
|
|
/** |
372
|
|
|
* @return Recipient |
373
|
|
|
*/ |
374
|
|
|
public function createRecipient() |
375
|
|
|
{ |
376
|
|
|
$recipient = new Recipient(); |
377
|
|
|
$recipient->setEmail($this->email); |
378
|
|
|
|
379
|
|
|
$recipient->setGivenName($this->givenName); |
380
|
|
|
$recipient->setFamilyName($this->familyName); |
381
|
|
|
|
382
|
|
|
$addressLines = explode("\n", $this->address); |
383
|
|
|
if (\count($addressLines) > 0) { |
384
|
|
|
$recipient->setStreet($addressLines[0]); |
385
|
|
|
} |
386
|
|
|
|
387
|
|
|
if (\count($addressLines) > 1) { |
388
|
|
|
$cityLine = $addressLines[\count($addressLines) - 1]; |
389
|
|
|
$firstSpace = mb_strpos($cityLine, ' '); |
390
|
|
|
if ($firstSpace !== false) { |
391
|
|
|
$recipient->setPostcode(mb_substr($cityLine, 0, $firstSpace)); |
392
|
|
|
$recipient->setPlace(mb_substr($cityLine, $firstSpace + 1)); |
393
|
|
|
} else { |
394
|
|
|
$recipient->setPlace($cityLine); |
395
|
|
|
} |
396
|
|
|
} |
397
|
|
|
|
398
|
|
|
return $recipient; |
399
|
|
|
} |
400
|
|
|
|
401
|
|
|
public function getAuthenticationCode(): string |
402
|
|
|
{ |
403
|
|
|
return $this->authenticationCode; |
404
|
|
|
} |
405
|
|
|
|
406
|
|
|
public function getAmountPayed(): ?int |
407
|
|
|
{ |
408
|
|
|
return $this->amountPayed; |
409
|
|
|
} |
410
|
|
|
|
411
|
|
|
public function setAmountPayed(?int $amountPayed): void |
412
|
|
|
{ |
413
|
|
|
$this->amountPayed = $amountPayed; |
414
|
|
|
} |
415
|
|
|
|
416
|
|
|
public function getTransactionId(): ?string |
417
|
|
|
{ |
418
|
|
|
return $this->transactionId; |
419
|
|
|
} |
420
|
|
|
|
421
|
|
|
public function setTransactionId(?string $transactionId): void |
422
|
|
|
{ |
423
|
|
|
$this->transactionId = $transactionId; |
424
|
|
|
} |
425
|
|
|
|
426
|
|
|
public function getMarkedAsPayed(): bool |
427
|
|
|
{ |
428
|
|
|
return $this->markedAsPayed; |
429
|
|
|
} |
430
|
|
|
|
431
|
|
|
public function setMarkedAsPayed(bool $markedAsPayed): void |
432
|
|
|
{ |
433
|
|
|
$this->markedAsPayed = $markedAsPayed; |
434
|
|
|
} |
435
|
|
|
} |
436
|
|
|
|