@@ -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
0 commit comments