1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
<?php
namespace App\Entity;
use App\Enum\CurrencyEnum;
use App\Enum\MoyenEnum;
use App\Utils\OperationFactory;
use Doctrine\ORM\Mapping as ORM;
/**
* Don d'un utilisateur.
*
* @ORM\Entity
*/
class Don extends Flux
{
const TYPE_DON_ADHERENT = 'don_adherent';
const TYPE_DON_PRESTATAIRE = 'don_prestataire';
/**
* @ORM\OneToOne(targetEntity="Prestataire")
* @ORM\JoinColumn(name="prestataire_dest_id", referencedColumnName="id", nullable=true)
*/
protected $destinataire;
/**
* Constructeur.
*/
public function __construct()
{
parent::__construct();
}
public static function getAvailableTypes(): array
{
return [
self::TYPE_DON_ADHERENT => self::TYPE_DON_ADHERENT,
self::TYPE_DON_PRESTATAIRE => self::TYPE_DON_PRESTATAIRE,
];
}
public function getAllOperations($em)
{
if (MoyenEnum::MOYEN_EMLC == $this->getMoyen()) {
return [
OperationFactory::getOperation($this, $this->getExpediteur(), CurrencyEnum::CURRENCY_EMLC, -$this->getMontant()),
OperationFactory::getOperation($this, $this->getDestinataire(), CurrencyEnum::CURRENCY_EMLC, $this->getMontant()),
];
} elseif (MoyenEnum::MOYEN_CB == $this->getMoyen()) {
return [
OperationFactory::getOperation($this, $this->getDestinataire(), CurrencyEnum::CURRENCY_EURO, $this->getMontant()),
];
}
return [];
}
public function operate($em)
{
if (MoyenEnum::MOYEN_MLC == $this->getMoyen()) {
$compteExp = $this->getExpediteur()->getEcompte() - $this->getMontant();
if ($compteExp < 0) {
throw new \Exception('[FLUX] Opération impossible ! Montant supérieur au solde de monnaie éléctronique !');
} else {
$this->getExpediteur()->removeEcompte($this->getMontant());
$this->getDestinataire()->addEcompte($this->getMontant());
return [$this->getExpediteur(), $this->getDestinataire()];
}
}
// Pas d'opération si la cotisation se fait par CB
return [];
}
public function getUsersToNotify()
{
return [];
}
/**
* @return string
*/
public function getParenttype(): string
{
return parent::TYPE_DON;
}
/**
* @return string
*/
public function getType(): string
{
return '';
}
public function __toString(): string
{
if (empty($this->getDestinataire()) || empty($this->getExpediteur()) || null === $this->getMontant()) {
return '[FLUX] Visualisation impossible ! Destinataire / Expéditeur et/ou montant manquant(s) !';
}
return ucwords(str_replace('_', ' ', $this->getType())) . ' : ' . $this->getExpediteur() . ' : ' . $this->getMontant() . '€' . ($this->getCreatedAt() ? ' (le ' . $this->getCreatedAt()->format('d/m/Y H:i') . ')' : '');
}
}