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
<?php
namespace App\Entity;
use App\Enum\CurrencyEnum;
use App\Utils\OperationFactory;
use Doctrine\ORM\Mapping as ORM;
/**
* TRANSFERT
* Les transferts dans la structure sont les flux de billets détenus par les opérateurs.
* Pour ajouter il faut un rôle spécifique :
* – Administrateur (Siège)
* – Gestionnaire (Groupe local)
* – Comptoir + Vente de monnaie locale
* – Prestataire (Reconversion).
*
* Types de transfert : (Les transferts dans la structure sont les flux de billets détenus par les opérateurs.)
*
* - SIEGE => GROUPES LOCAUX (Transfert du siège au groupe)
* - GROUPE => SIEGE (Transfert du groupe au siège)
* - GROUPES LOCAUX => COMPTOIRS (Transfert du groupe au comptoir)
* - COMPTOIRS => GROUPES LOCAUX (Transfert du comptoir au groupe)
* - COMPTOIRS => ADHERENTS (Diffusion de monnaie papier auprès des adhérents)
* - COMPTOIRS => PRESTATAIRES (Diffusion de monnaie papier auprès des prestataires)
*
* @ORM\Entity
*/
class Transfert extends Flux
{
const TYPE_TRANSFERT_COMPTOIR_GROUPE = 'comptoir_groupe';
const TYPE_TRANSFERT_GROUPE_COMPTOIR = 'groupe_comptoir';
const TYPE_TRANSFERT_GROUPE_SIEGE = 'groupe_siege';
const TYPE_TRANSFERT_SIEGE_GROUPE = 'siege_groupe';
public static function getAvailableTypes(): array
{
return [
self::TYPE_TRANSFERT_COMPTOIR_GROUPE => self::TYPE_TRANSFERT_COMPTOIR_GROUPE,
self::TYPE_TRANSFERT_GROUPE_COMPTOIR => self::TYPE_TRANSFERT_GROUPE_COMPTOIR,
self::TYPE_TRANSFERT_GROUPE_SIEGE => self::TYPE_TRANSFERT_GROUPE_SIEGE,
self::TYPE_TRANSFERT_SIEGE_GROUPE => self::TYPE_TRANSFERT_SIEGE_GROUPE,
];
}
/**
* @return string
*/
public function getParenttype(): string
{
return parent::TYPE_TRANSFERT;
}
public function getAllOperations($em)
{
return [
OperationFactory::getOperation($this, $this->getExpediteur(), CurrencyEnum::CURRENCY_MLC, -$this->getMontant()),
OperationFactory::getOperation($this, $this->getDestinataire(), CurrencyEnum::CURRENCY_MLC, $this->getMontant()),
];
}
public function operate($em)
{
$compteExp = $this->getExpediteur()->getCompte() - $this->getMontant();
if ($compteExp < 0) {
throw new \Exception("[FLUX] Transfert impossible ! Montant supérieur au solde de l'expéditeur !");
} else {
$this->getExpediteur()->removeCompte($this->getMontant());
$this->getDestinataire()->addCompte($this->getMontant());
return [$this->getExpediteur(), $this->getDestinataire()];
}
return [];
}
/**
* @return string
*/
public function getType(): string
{
return '';
}
public function getUsersToNotify()
{
return [];
}
}