Skip to content

Commit 1cdfd4e

Browse files
committed
Remplacement de constantes par un enum
1 parent 4615274 commit 1cdfd4e

File tree

18 files changed

+63
-63
lines changed

18 files changed

+63
-63
lines changed

db/seeds/Users.php

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
declare(strict_types=1);
44

5+
use AppBundle\Association\MemberType;
56
use AppBundle\Association\Model\User;
67
use Phinx\Seed\AbstractSeed;
78

@@ -179,78 +180,78 @@ public function run(): void
179180
$data = [
180181
[
181182
'date_debut' => $now - $oneMonthInSeconds,
182-
'type_personne' => AFUP_PERSONNES_PHYSIQUES,
183+
'type_personne' => MemberType::MemberPhysical->value,
183184
'id_personne' => self::ID_USER_ADMIN,
184185
'montant' => 25,
185186
'date_fin' => $now + $oneMonthInSeconds * 12,
186187
],
187188
[
188189
'date_debut' => $dateDebutUserExpire,
189-
'type_personne' => AFUP_PERSONNES_PHYSIQUES,
190+
'type_personne' => MemberType::MemberPhysical->value,
190191
'id_personne' => self::ID_USER_EXPIRIE,
191192
'montant' => 25,
192193
'date_fin' => $dateDebutUserExpire + $oneMonthInSeconds * 12,
193194
'numero_facture' => 'COTIS-2018-198',
194195
],
195196
[
196197
'date_debut' => $dateDebutUserExpire,
197-
'type_personne' => AFUP_PERSONNES_MORALES,
198+
'type_personne' => MemberType::MemberCompany->value,
198199
'id_personne' => self::ID_PERSONNE_MORALE_MY_CORP,
199200
'montant' => 150,
200201
'date_fin' => $now + $oneMonthInSeconds * 12,
201202
'numero_facture' => 'COTIS-' . date('Y') . '-200',
202203
],
203204
[
204205
'date_debut' => $dateDebutUserExpire,
205-
'type_personne' => AFUP_PERSONNES_PHYSIQUES,
206+
'type_personne' => MemberType::MemberPhysical->value,
206207
'id_personne' => self::ID_USER_PERSONNE_PHYSIQUE,
207208
'montant' => 25,
208209
'date_fin' => $now + $oneMonthInSeconds * 12,
209210
'numero_facture' => 'COTIS-' . date('Y') . '-' . (date('Hi') + 200),
210211
],
211212
[
212213
'date_debut' => mktime(16, 10, 10, 1, 1, 2023),
213-
'type_personne' => AFUP_PERSONNES_PHYSIQUES,
214+
'type_personne' => MemberType::MemberPhysical->value,
214215
'id_personne' => self::ID_USER_PERSONNE_PHYSIQUE_FIXED_COTISATIONS,
215216
'montant' => 30,
216217
'date_fin' => mktime(16, 10, 10, 1, 1, 2024),
217218
'numero_facture' => 'COTIS-2023-1',
218219
],
219220
[
220221
'date_debut' => mktime(16, 10, 10, 1, 1, 2024),
221-
'type_personne' => AFUP_PERSONNES_PHYSIQUES,
222+
'type_personne' => MemberType::MemberPhysical->value,
222223
'id_personne' => self::ID_USER_PERSONNE_PHYSIQUE_FIXED_COTISATIONS,
223224
'montant' => 30,
224225
'date_fin' => mktime(16, 10, 10, 1, 1, 2025),
225226
'numero_facture' => 'COTIS-2024-245',
226227
],
227228
[
228229
'date_debut' => mktime(16, 10, 10, 1, 1, $year),
229-
'type_personne' => AFUP_PERSONNES_PHYSIQUES,
230+
'type_personne' => MemberType::MemberPhysical->value,
230231
'id_personne' => self::ID_USER_PERSONNE_PHYSIQUE_FIXED_COTISATIONS,
231232
'montant' => 30,
232233
'date_fin' => mktime(16, 10, 10, 1, 1, $year + 1),
233234
'numero_facture' => "COTIS-$year-245",
234235
],
235236
[
236237
'date_debut' => mktime(16, 10, 10, 1, 2, 2023),
237-
'type_personne' => AFUP_PERSONNES_MORALES,
238+
'type_personne' => MemberType::MemberCompany->value,
238239
'id_personne' => self::ID_PERSONNE_MORALE_HELIOS_AEROSPACE,
239240
'montant' => 150,
240241
'date_fin' => mktime(16, 10, 10, 1, 2, 2024),
241242
'numero_facture' => 'COTIS-2023-2',
242243
],
243244
[
244245
'date_debut' => mktime(16, 10, 10, 1, 2, 2024),
245-
'type_personne' => AFUP_PERSONNES_MORALES,
246+
'type_personne' => MemberType::MemberCompany->value,
246247
'id_personne' => self::ID_PERSONNE_MORALE_HELIOS_AEROSPACE,
247248
'montant' => 180,
248249
'date_fin' => mktime(16, 10, 10, 1, 2, 2025),
249250
'numero_facture' => 'COTIS-2024-249',
250251
],
251252
[
252253
'date_debut' => mktime(16, 10, 10, 1, 2, $year),
253-
'type_personne' => AFUP_PERSONNES_MORALES,
254+
'type_personne' => MemberType::MemberCompany->value,
254255
'id_personne' => self::ID_PERSONNE_MORALE_HELIOS_AEROSPACE,
255256
'montant' => 180,
256257
'date_fin' => mktime(16, 10, 10, 1, 2, $year + 1),

sources/Afup/Association/Cotisations.php

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -50,21 +50,20 @@ public function __construct(
5050
/**
5151
* Renvoit la liste des cotisations concernant une personne
5252
*
53-
* @param int $type_personne Type de la personne (morale ou physique)
5453
* @param int $id_personne Identifiant de la personne
5554
* @param string $champs Champs à renvoyer
5655
* @param string $ordre Tri des enregistrements
5756
* @param bool $associatif Renvoyer un tableau associatif ?
5857
* @return array|false
5958
*/
60-
public function obtenirListe($type_personne, $id_personne, string $champs = '*', string $ordre = 'date_fin DESC', bool $associatif = false)
59+
public function obtenirListe(MemberType $type_personne, $id_personne, string $champs = '*', string $ordre = 'date_fin DESC', bool $associatif = false)
6160
{
6261
$requete = 'SELECT';
6362
$requete .= ' ' . $champs . ' ';
6463
$requete .= 'FROM';
6564
$requete .= ' afup_cotisations ';
6665
$requete .= 'WHERE';
67-
$requete .= ' type_personne=' . $type_personne;
66+
$requete .= ' type_personne=' . $type_personne->value;
6867
$requete .= ' AND id_personne=' . $id_personne . ' ';
6968
$requete .= 'ORDER BY ' . $ordre;
7069
if ($associatif) {
@@ -112,7 +111,6 @@ public function _genererNumeroFacture(): string
112111
/**
113112
* Ajoute une cotisation
114113
*
115-
* @param int $type_personne Type de la personne (morale ou physique)
116114
* @param int $id_personne Identifiant de la personne
117115
* @param float $montant Adresse de la personne
118116
* @param int $type_reglement Type de règlement (espèces, chèque, virement)
@@ -124,14 +122,14 @@ public function _genererNumeroFacture(): string
124122
* @param string $referenceClient Reference client à mentionner sur la facture
125123
* @return bool Succès de l'ajout
126124
*/
127-
public function ajouter($type_personne, $id_personne, $montant, $type_reglement,
125+
public function ajouter(MemberType $type_personne, $id_personne, $montant, $type_reglement,
128126
$informations_reglement, $date_debut, $date_fin, $commentaires, $referenceClient = null): bool
129127
{
130128
$requete = 'INSERT INTO ';
131129
$requete .= ' afup_cotisations (type_personne, id_personne, montant, type_reglement , informations_reglement,';
132130
$requete .= ' date_debut, date_fin, numero_facture, token, commentaires, reference_client) ';
133131
$requete .= 'VALUES (';
134-
$requete .= $type_personne . ',';
132+
$requete .= $type_personne->value . ',';
135133
$requete .= $id_personne . ',';
136134
$requete .= $montant . ',';
137135
$requete .= $this->_bdd->echapper($type_reglement) . ',';
@@ -214,7 +212,7 @@ public function notifierReglementEnLigneAuTresorier(string $cmd, float $total, s
214212
'email' => 'N.C.',
215213
];
216214

217-
if ($type_personne == AFUP_PERSONNES_MORALES) {
215+
if ($type_personne == MemberType::MemberCompany->value) {
218216
if ($company = $this->companyMemberRepository?->get($id_personne)) {
219217
$infos['nom'] = $company->getLastName();
220218
$infos['prenom'] = $company->getFirstName();
@@ -268,15 +266,16 @@ public function validerReglementEnLigne($cmd, $total, string $autorisation, stri
268266
[$ref, $date, $type_personne, $id_personne, $reste] = explode('-', (string) $cmd, 5);
269267
$date_debut = mktime(0, 0, 0, (int) substr($date, 2, 2), (int) substr($date, 0, 2), (int) substr($date, 4, 4));
270268

271-
$cotisation = $this->obtenirDerniere($type_personne, $id_personne);
269+
$cotisation = $this->obtenirDerniere(MemberType::from((int) $type_personne), $id_personne);
272270
$date_fin_precedente = $cotisation === false ? 0 : $cotisation['date_fin'];
273271

274272
if ($date_fin_precedente > 0) {
275273
$date_debut = strtotime('+1day', (int) $date_fin_precedente);
276274
}
277275

278276
$date_fin = $this->finProchaineCotisation($cotisation)->format('U');
279-
$result = $this->ajouter($type_personne,
277+
$result = $this->ajouter(
278+
MemberType::from((int) $type_personne),
280279
$id_personne,
281280
$total,
282281
AFUP_COTISATIONS_REGLEMENT_ENLIGNE,
@@ -330,7 +329,7 @@ public function genererFacture($id_cotisation, $chemin = null)
330329
$requete = 'SELECT * FROM afup_cotisations WHERE id=' . $id_cotisation;
331330
$cotisation = $this->_bdd->obtenirEnregistrement($requete);
332331

333-
$table = $cotisation['type_personne'] == AFUP_PERSONNES_MORALES ? 'afup_personnes_morales' : 'afup_personnes_physiques';
332+
$table = $cotisation['type_personne'] == MemberType::MemberCompany->value ? 'afup_personnes_morales' : 'afup_personnes_physiques';
334333
$requete = 'SELECT * FROM ' . $table . ' WHERE id=' . $cotisation['id_personne'];
335334
$personne = $this->_bdd->obtenirEnregistrement($requete);
336335

@@ -353,7 +352,7 @@ public function genererFacture($id_cotisation, $chemin = null)
353352
$pdf->Cell(130, 5, 'Objet : Facture n°' . $cotisation['numero_facture']);
354353
$pdf->SetFont('Arial', '', 10);
355354

356-
if ($cotisation['type_personne'] == AFUP_PERSONNES_MORALES) {
355+
if ($cotisation['type_personne'] == MemberType::MemberCompany->value) {
357356
$nom = $personne['raison_sociale'];
358357
$patternPrefix = $personne['raison_sociale'];
359358
} else {
@@ -394,7 +393,7 @@ public function genererFacture($id_cotisation, $chemin = null)
394393
} else {
395394
// On stocke le montant de la cotisation TTC, pour les personnes physiques c'est le même, par contre pour les personnes morales
396395
// ce n'est pas le même, afin d'éviter d'appliquer deux fois la TVA, on applique ce hotfix
397-
if ($cotisation['type_personne'] == AFUP_PERSONNES_MORALES) {
396+
if ($cotisation['type_personne'] == MemberType::MemberCompany->value) {
398397
$cotisation['montant'] = Vat::getRoundedWithoutVatPriceFromPriceWithVat($cotisation['montant'], Utils::MEMBERSHIP_FEE_VAT_RATE);
399398
}
400399

@@ -408,7 +407,7 @@ public function genererFacture($id_cotisation, $chemin = null)
408407
$pdf->Cell(25, 5, 'Taux TVA', 1, 0, 'R', 1);
409408
$pdf->Cell(25, 5, 'Prix TTC', 1, 0, 'R', 1);
410409

411-
if ($cotisation['type_personne'] == AFUP_PERSONNES_MORALES) {
410+
if ($cotisation['type_personne'] == MemberType::MemberCompany->value) {
412411
[$totalHt, $total] = $this->buildDetailsPersonneMorale($pdf, $cotisation['montant'], $cotisation['date_fin']);
413412
} else {
414413
[$totalHt, $total] = $this->buildDetailsPersonnePhysique($pdf, $cotisation['montant'], $cotisation['date_fin']);
@@ -503,7 +502,7 @@ public function envoyerFacture($id_cotisation, Mailer $mailer, UserRepository $u
503502
{
504503
$personne = $this->obtenir($id_cotisation, 'type_personne, id_personne');
505504

506-
if ($personne['type_personne'] == AFUP_PERSONNES_MORALES) {
505+
if ($personne['type_personne'] == MemberType::MemberCompany->value) {
507506
$company = $this->companyMemberRepository ? $this->companyMemberRepository->get($personne['id_personne']) : null;
508507
Assertion::notNull($company);
509508
$contactPhysique = [
@@ -532,7 +531,7 @@ public function envoyerFacture($id_cotisation, Mailer $mailer, UserRepository $u
532531

533532
$cheminFacture = AFUP_CHEMIN_RACINE . 'cache/fact' . $id_cotisation . '.pdf';
534533
$numeroFacture = $this->genererFacture($id_cotisation, $cheminFacture);
535-
$cotisation = $this->obtenirDerniere($personne['type_personne'], $personne['id_personne']);
534+
$cotisation = $this->obtenirDerniere(MemberType::from((int) $personne['type_personne']), $personne['id_personne']);
536535
$pattern = str_replace(' ', '', $patternPrefix) . '_' . $numeroFacture . '_' . date('dmY', (int) $cotisation['date_debut']) . '.pdf';
537536

538537
$message = new Message('Facture AFUP', null, new MailUser(
@@ -553,18 +552,17 @@ public function envoyerFacture($id_cotisation, Mailer $mailer, UserRepository $u
553552

554553
/**
555554
* Retourne la dernière cotisation d'une personne morale
556-
* @param int|string $type_personne
557555
* @param int $id_personne Identifiant de la personne
558556
* @return array|false
559557
*/
560-
public function obtenirDerniere($type_personne, $id_personne)
558+
public function obtenirDerniere(MemberType $type_personne, $id_personne)
561559
{
562560
$requete = 'SELECT';
563561
$requete .= ' * ';
564562
$requete .= 'FROM';
565563
$requete .= ' afup_cotisations ';
566564
$requete .= 'WHERE';
567-
$requete .= ' type_personne=' . $type_personne . ' ';
565+
$requete .= ' type_personne=' . $type_personne->value . ' ';
568566
$requete .= ' AND id_personne=' . $id_personne . ' ';
569567
$requete .= 'ORDER BY';
570568
$requete .= ' date_fin DESC ';
@@ -688,7 +686,7 @@ public function isCurrentUserAllowedToReadInvoice(string $invoiceId)
688686
* si type_personne = 1, alors personne morale: id_personne doit être égale à compagnyId de l'utilisateur connecté
689687
* qui doit aussi avoir le droit "ROLE_COMPAGNY_MANAGER"
690688
*/
691-
if ($result['type_personne'] == AFUP_PERSONNES_MORALES) {
689+
if ($result['type_personne'] == MemberType::MemberCompany->value) {
692690
return $this->_droits->verifierDroitManagerPersonneMorale($result['id_personne']);
693691
}
694692

sources/Afup/Bootstrap/_Common.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,6 @@
3030
// définitions des constantes
3131
if (!defined('AFUP_CHEMIN_RACINE')) {
3232
define('AFUP_CHEMIN_RACINE', $root . '/htdocs/');
33-
34-
// Voir la classe Afup\Site\Association\Personnes_Morales
35-
define('AFUP_PERSONNES_PHYSIQUES', 0);
36-
define('AFUP_COTISATION_PERSONNE_PHYSIQUE', 30);
3733
}
3834
date_default_timezone_set('Europe/Paris');
3935

sources/Afup/Bootstrap/commonStart.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,7 @@
8484
define('AFUP_FORUM_REGLEMENT_AUCUN', 3);
8585
define('AFUP_FORUM_REGLEMENT_A_POSTERIORI', 4);
8686

87-
88-
define('AFUP_PERSONNES_MORALES', 1);
87+
define('AFUP_COTISATION_PERSONNE_PHYSIQUE', 30);
8988
define('AFUP_COTISATION_PERSONNE_MORALE', 150);
9089
define('AFUP_PERSONNE_MORALE_SEUIL', 3);
9190

sources/AppBundle/Association/CompanyMembership/SubscriptionManagement.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
use Afup\Site\Association\Cotisations;
88
use Afup\Site\Utils\Utils;
9+
use AppBundle\Association\MemberType;
910
use AppBundle\Association\Model\CompanyMember;
1011

1112
final readonly class SubscriptionManagement
@@ -18,7 +19,7 @@ public function createInvoiceForInscription(CompanyMember $company, $numberOfMem
1819

1920
// Create the invoice
2021
$this->cotisations->ajouter(
21-
AFUP_PERSONNES_MORALES,
22+
MemberType::MemberCompany,
2223
$company->getId(),
2324
ceil($numberOfMembers / AFUP_PERSONNE_MORALE_SEUIL) * AFUP_COTISATION_PERSONNE_MORALE * (1 + Utils::MEMBERSHIP_FEE_VAT_RATE),
2425
null,
@@ -27,7 +28,7 @@ public function createInvoiceForInscription(CompanyMember $company, $numberOfMem
2728
$endSubscription->format('U'),
2829
'',
2930
);
30-
$subscriptionArray = $this->cotisations->obtenirDerniere(AFUP_PERSONNES_MORALES, $company->getId());
31+
$subscriptionArray = $this->cotisations->obtenirDerniere(MemberType::MemberCompany, $company->getId());
3132

3233
if ($subscriptionArray === false) {
3334
throw new \RuntimeException('An error occured');

sources/AppBundle/Association/MembershipFeeReferenceGenerator.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,14 @@
99
class MembershipFeeReferenceGenerator
1010
{
1111
/**
12-
* @param string|int $typePersonne
1312
* @param string|int $idPersonne
1413
* @param string $nomPersonne
1514
*
1615
* @return mixed|string
1716
*/
18-
public function generate(\DateTimeImmutable $currentDate, $typePersonne, $idPersonne, $nomPersonne)
17+
public function generate(\DateTimeImmutable $currentDate, MemberType $typePersonne, $idPersonne, $nomPersonne)
1918
{
20-
$reference = strtoupper('C' . $currentDate->format('Y') . '-' . $currentDate->format('dmYHi') . '-' . $typePersonne . '-' . $idPersonne . '-' . substr((string) supprimerAccents($nomPersonne), 0, 5));
19+
$reference = strtoupper('C' . $currentDate->format('Y') . '-' . $currentDate->format('dmYHi') . '-' . $typePersonne->value . '-' . $idPersonne . '-' . substr((string) supprimerAccents($nomPersonne), 0, 5));
2120
$reference = supprimerAccents($reference);
2221
$reference = preg_replace('/[^A-Z0-9_\-\:\.;]/', '', (string) $reference);
2322

sources/AppBundle/Association/Model/Repository/CompanyMemberRepository.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
namespace AppBundle\Association\Model\Repository;
66

7+
use AppBundle\Association\MemberType;
78
use AppBundle\Association\Model\CompanyMember;
89
use Assert\Assertion;
910
use Aura\SqlQuery\Common\SelectInterface;
@@ -121,7 +122,7 @@ public function countActiveByCompany(): array
121122
public function remove(CompanyMember $companyMember): void
122123
{
123124
$nbCotisations = (int) $this->getQuery('SELECT COUNT(*) nb FROM afup_cotisations WHERE type_personne = :memberType AND id_personne = :id')
124-
->setParams(['memberType' => AFUP_PERSONNES_MORALES, 'id' => $companyMember->getId()])
125+
->setParams(['memberType' => MemberType::MemberCompany->value, 'id' => $companyMember->getId()])
125126
->query()->first()[0]->nb;
126127
if (0 < $nbCotisations) {
127128
throw new InvalidArgumentException('Impossible de supprimer une personne morale qui a des cotisations');

sources/AppBundle/Association/UserMembership/SeniorityComputer.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
namespace AppBundle\Association\UserMembership;
66

77
use Afup\Site\Association\Cotisations;
8+
use AppBundle\Association\MemberType;
89
use AppBundle\Association\Model\CompanyMember;
910
use AppBundle\Association\Model\User;
1011

@@ -14,7 +15,7 @@ public function __construct(private readonly Cotisations $cotisations) {}
1415

1516
public function computeCompany(CompanyMember $companyMember)
1617
{
17-
$cotis = $this->cotisations->obtenirListe(AFUP_PERSONNES_MORALES, $companyMember->getId());
18+
$cotis = $this->cotisations->obtenirListe(MemberType::MemberCompany, $companyMember->getId());
1819

1920
$infos = $this->computeFromCotisationsAndReturnInfos($cotis);
2021

@@ -23,7 +24,7 @@ public function computeCompany(CompanyMember $companyMember)
2324

2425
public function computeCompanyAndReturnInfos(CompanyMember $companyMember): array
2526
{
26-
$cotis = $this->cotisations->obtenirListe(AFUP_PERSONNES_MORALES, $companyMember->getId());
27+
$cotis = $this->cotisations->obtenirListe(MemberType::MemberCompany, $companyMember->getId());
2728

2829
return $this->computeFromCotisationsAndReturnInfos($cotis);
2930
}
@@ -37,7 +38,7 @@ public function compute(User $user)
3738

3839
public function computeAndReturnInfos(User $user): array
3940
{
40-
$cotis = $this->cotisations->obtenirListe(AFUP_PERSONNES_PHYSIQUES, $user->getId());
41+
$cotis = $this->cotisations->obtenirListe(MemberType::MemberPhysical, $user->getId());
4142

4243
return $this->computeFromCotisationsAndReturnInfos($cotis);
4344
}

sources/AppBundle/Association/UserMembership/UserService.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
namespace AppBundle\Association\UserMembership;
66

77
use Afup\Site\Association\Cotisations;
8+
use AppBundle\Association\MemberType;
89
use AppBundle\Association\Model\Repository\UserRepository;
910
use AppBundle\Association\Model\User;
1011
use AppBundle\Email\Mailer\Mailer;
@@ -91,10 +92,10 @@ public function getLastSubscription(User $user)
9192
{
9293
if ($user->getCompanyId()) {
9394
$id = $user->getCompanyId();
94-
$personType = AFUP_PERSONNES_MORALES;
95+
$personType = MemberType::MemberCompany;
9596
} else {
9697
$id = $user->getId();
97-
$personType = AFUP_PERSONNES_PHYSIQUES;
98+
$personType = MemberType::MemberPhysical;
9899
}
99100

100101
return $this->cotisations->obtenirDerniere($personType, $id);

0 commit comments

Comments
 (0)