Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 11 additions & 10 deletions db/seeds/Users.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

declare(strict_types=1);

use AppBundle\Association\MemberType;
use AppBundle\Association\Model\User;
use Phinx\Seed\AbstractSeed;

Expand Down Expand Up @@ -179,78 +180,78 @@ public function run(): void
$data = [
[
'date_debut' => $now - $oneMonthInSeconds,
'type_personne' => AFUP_PERSONNES_PHYSIQUES,
'type_personne' => MemberType::MemberPhysical->value,
'id_personne' => self::ID_USER_ADMIN,
'montant' => 25,
'date_fin' => $now + $oneMonthInSeconds * 12,
],
[
'date_debut' => $dateDebutUserExpire,
'type_personne' => AFUP_PERSONNES_PHYSIQUES,
'type_personne' => MemberType::MemberPhysical->value,
'id_personne' => self::ID_USER_EXPIRIE,
'montant' => 25,
'date_fin' => $dateDebutUserExpire + $oneMonthInSeconds * 12,
'numero_facture' => 'COTIS-2018-198',
],
[
'date_debut' => $dateDebutUserExpire,
'type_personne' => AFUP_PERSONNES_MORALES,
'type_personne' => MemberType::MemberCompany->value,
'id_personne' => self::ID_PERSONNE_MORALE_MY_CORP,
'montant' => 150,
'date_fin' => $now + $oneMonthInSeconds * 12,
'numero_facture' => 'COTIS-' . date('Y') . '-200',
],
[
'date_debut' => $dateDebutUserExpire,
'type_personne' => AFUP_PERSONNES_PHYSIQUES,
'type_personne' => MemberType::MemberPhysical->value,
'id_personne' => self::ID_USER_PERSONNE_PHYSIQUE,
'montant' => 25,
'date_fin' => $now + $oneMonthInSeconds * 12,
'numero_facture' => 'COTIS-' . date('Y') . '-' . (date('Hi') + 200),
],
[
'date_debut' => mktime(16, 10, 10, 1, 1, 2023),
'type_personne' => AFUP_PERSONNES_PHYSIQUES,
'type_personne' => MemberType::MemberPhysical->value,
'id_personne' => self::ID_USER_PERSONNE_PHYSIQUE_FIXED_COTISATIONS,
'montant' => 30,
'date_fin' => mktime(16, 10, 10, 1, 1, 2024),
'numero_facture' => 'COTIS-2023-1',
],
[
'date_debut' => mktime(16, 10, 10, 1, 1, 2024),
'type_personne' => AFUP_PERSONNES_PHYSIQUES,
'type_personne' => MemberType::MemberPhysical->value,
'id_personne' => self::ID_USER_PERSONNE_PHYSIQUE_FIXED_COTISATIONS,
'montant' => 30,
'date_fin' => mktime(16, 10, 10, 1, 1, 2025),
'numero_facture' => 'COTIS-2024-245',
],
[
'date_debut' => mktime(16, 10, 10, 1, 1, $year),
'type_personne' => AFUP_PERSONNES_PHYSIQUES,
'type_personne' => MemberType::MemberPhysical->value,
'id_personne' => self::ID_USER_PERSONNE_PHYSIQUE_FIXED_COTISATIONS,
'montant' => 30,
'date_fin' => mktime(16, 10, 10, 1, 1, $year + 1),
'numero_facture' => "COTIS-$year-245",
],
[
'date_debut' => mktime(16, 10, 10, 1, 2, 2023),
'type_personne' => AFUP_PERSONNES_MORALES,
'type_personne' => MemberType::MemberCompany->value,
'id_personne' => self::ID_PERSONNE_MORALE_HELIOS_AEROSPACE,
'montant' => 150,
'date_fin' => mktime(16, 10, 10, 1, 2, 2024),
'numero_facture' => 'COTIS-2023-2',
],
[
'date_debut' => mktime(16, 10, 10, 1, 2, 2024),
'type_personne' => AFUP_PERSONNES_MORALES,
'type_personne' => MemberType::MemberCompany->value,
'id_personne' => self::ID_PERSONNE_MORALE_HELIOS_AEROSPACE,
'montant' => 180,
'date_fin' => mktime(16, 10, 10, 1, 2, 2025),
'numero_facture' => 'COTIS-2024-249',
],
[
'date_debut' => mktime(16, 10, 10, 1, 2, $year),
'type_personne' => AFUP_PERSONNES_MORALES,
'type_personne' => MemberType::MemberCompany->value,
'id_personne' => self::ID_PERSONNE_MORALE_HELIOS_AEROSPACE,
'montant' => 180,
'date_fin' => mktime(16, 10, 10, 1, 2, $year + 1),
Expand Down
36 changes: 17 additions & 19 deletions sources/Afup/Association/Cotisations.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,21 +50,20 @@ public function __construct(
/**
* Renvoit la liste des cotisations concernant une personne
*
* @param int $type_personne Type de la personne (morale ou physique)
* @param int $id_personne Identifiant de la personne
* @param string $champs Champs à renvoyer
* @param string $ordre Tri des enregistrements
* @param bool $associatif Renvoyer un tableau associatif ?
* @return array|false
*/
public function obtenirListe($type_personne, $id_personne, string $champs = '*', string $ordre = 'date_fin DESC', bool $associatif = false)
public function obtenirListe(MemberType $type_personne, $id_personne, string $champs = '*', string $ordre = 'date_fin DESC', bool $associatif = false)
{
$requete = 'SELECT';
$requete .= ' ' . $champs . ' ';
$requete .= 'FROM';
$requete .= ' afup_cotisations ';
$requete .= 'WHERE';
$requete .= ' type_personne=' . $type_personne;
$requete .= ' type_personne=' . $type_personne->value;
$requete .= ' AND id_personne=' . $id_personne . ' ';
$requete .= 'ORDER BY ' . $ordre;
if ($associatif) {
Expand Down Expand Up @@ -112,7 +111,6 @@ public function _genererNumeroFacture(): string
/**
* Ajoute une cotisation
*
* @param int $type_personne Type de la personne (morale ou physique)
* @param int $id_personne Identifiant de la personne
* @param float $montant Adresse de la personne
* @param int $type_reglement Type de règlement (espèces, chèque, virement)
Expand All @@ -124,14 +122,14 @@ public function _genererNumeroFacture(): string
* @param string $referenceClient Reference client à mentionner sur la facture
* @return bool Succès de l'ajout
*/
public function ajouter($type_personne, $id_personne, $montant, $type_reglement,
public function ajouter(MemberType $type_personne, $id_personne, $montant, $type_reglement,
$informations_reglement, $date_debut, $date_fin, $commentaires, $referenceClient = null): bool
{
$requete = 'INSERT INTO ';
$requete .= ' afup_cotisations (type_personne, id_personne, montant, type_reglement , informations_reglement,';
$requete .= ' date_debut, date_fin, numero_facture, token, commentaires, reference_client) ';
$requete .= 'VALUES (';
$requete .= $type_personne . ',';
$requete .= $type_personne->value . ',';
$requete .= $id_personne . ',';
$requete .= $montant . ',';
$requete .= $this->_bdd->echapper($type_reglement) . ',';
Expand Down Expand Up @@ -214,7 +212,7 @@ public function notifierReglementEnLigneAuTresorier(string $cmd, float $total, s
'email' => 'N.C.',
];

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

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

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

$date_fin = $this->finProchaineCotisation($cotisation)->format('U');
$result = $this->ajouter($type_personne,
$result = $this->ajouter(
MemberType::from((int) $type_personne),
$id_personne,
$total,
AFUP_COTISATIONS_REGLEMENT_ENLIGNE,
Expand Down Expand Up @@ -330,7 +329,7 @@ public function genererFacture($id_cotisation, $chemin = null)
$requete = 'SELECT * FROM afup_cotisations WHERE id=' . $id_cotisation;
$cotisation = $this->_bdd->obtenirEnregistrement($requete);

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

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

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

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

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

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

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

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

/**
* Retourne la dernière cotisation d'une personne morale
* @param int|string $type_personne
* @param int $id_personne Identifiant de la personne
* @return array|false
*/
public function obtenirDerniere($type_personne, $id_personne)
public function obtenirDerniere(MemberType $type_personne, $id_personne)
{
$requete = 'SELECT';
$requete .= ' * ';
$requete .= 'FROM';
$requete .= ' afup_cotisations ';
$requete .= 'WHERE';
$requete .= ' type_personne=' . $type_personne . ' ';
$requete .= ' type_personne=' . $type_personne->value . ' ';
$requete .= ' AND id_personne=' . $id_personne . ' ';
$requete .= 'ORDER BY';
$requete .= ' date_fin DESC ';
Expand Down Expand Up @@ -688,7 +686,7 @@ public function isCurrentUserAllowedToReadInvoice(string $invoiceId)
* si type_personne = 1, alors personne morale: id_personne doit être égale à compagnyId de l'utilisateur connecté
* qui doit aussi avoir le droit "ROLE_COMPAGNY_MANAGER"
*/
if ($result['type_personne'] == AFUP_PERSONNES_MORALES) {
if ($result['type_personne'] == MemberType::MemberCompany->value) {
return $this->_droits->verifierDroitManagerPersonneMorale($result['id_personne']);
}

Expand Down
4 changes: 0 additions & 4 deletions sources/Afup/Bootstrap/_Common.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,6 @@
// définitions des constantes
if (!defined('AFUP_CHEMIN_RACINE')) {
define('AFUP_CHEMIN_RACINE', $root . '/htdocs/');

// Voir la classe Afup\Site\Association\Personnes_Morales
define('AFUP_PERSONNES_PHYSIQUES', 0);
define('AFUP_COTISATION_PERSONNE_PHYSIQUE', 30);
}
date_default_timezone_set('Europe/Paris');

Expand Down
3 changes: 1 addition & 2 deletions sources/Afup/Bootstrap/commonStart.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,7 @@
define('AFUP_FORUM_REGLEMENT_AUCUN', 3);
define('AFUP_FORUM_REGLEMENT_A_POSTERIORI', 4);


define('AFUP_PERSONNES_MORALES', 1);
define('AFUP_COTISATION_PERSONNE_PHYSIQUE', 30);
define('AFUP_COTISATION_PERSONNE_MORALE', 150);
define('AFUP_PERSONNE_MORALE_SEUIL', 3);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use Afup\Site\Association\Cotisations;
use Afup\Site\Utils\Utils;
use AppBundle\Association\MemberType;
use AppBundle\Association\Model\CompanyMember;

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

// Create the invoice
$this->cotisations->ajouter(
AFUP_PERSONNES_MORALES,
MemberType::MemberCompany,
$company->getId(),
ceil($numberOfMembers / AFUP_PERSONNE_MORALE_SEUIL) * AFUP_COTISATION_PERSONNE_MORALE * (1 + Utils::MEMBERSHIP_FEE_VAT_RATE),
null,
Expand All @@ -27,7 +28,7 @@ public function createInvoiceForInscription(CompanyMember $company, $numberOfMem
$endSubscription->format('U'),
'',
);
$subscriptionArray = $this->cotisations->obtenirDerniere(AFUP_PERSONNES_MORALES, $company->getId());
$subscriptionArray = $this->cotisations->obtenirDerniere(MemberType::MemberCompany, $company->getId());

if ($subscriptionArray === false) {
throw new \RuntimeException('An error occured');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,14 @@
class MembershipFeeReferenceGenerator
{
/**
* @param string|int $typePersonne
* @param string|int $idPersonne
* @param string $nomPersonne
*
* @return mixed|string
*/
public function generate(\DateTimeImmutable $currentDate, $typePersonne, $idPersonne, $nomPersonne)
public function generate(\DateTimeImmutable $currentDate, MemberType $typePersonne, $idPersonne, $nomPersonne)
{
$reference = strtoupper('C' . $currentDate->format('Y') . '-' . $currentDate->format('dmYHi') . '-' . $typePersonne . '-' . $idPersonne . '-' . substr((string) supprimerAccents($nomPersonne), 0, 5));
$reference = strtoupper('C' . $currentDate->format('Y') . '-' . $currentDate->format('dmYHi') . '-' . $typePersonne->value . '-' . $idPersonne . '-' . substr((string) supprimerAccents($nomPersonne), 0, 5));
$reference = supprimerAccents($reference);
$reference = preg_replace('/[^A-Z0-9_\-\:\.;]/', '', (string) $reference);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace AppBundle\Association\Model\Repository;

use AppBundle\Association\MemberType;
use AppBundle\Association\Model\CompanyMember;
use Assert\Assertion;
use Aura\SqlQuery\Common\SelectInterface;
Expand Down Expand Up @@ -121,7 +122,7 @@ public function countActiveByCompany(): array
public function remove(CompanyMember $companyMember): void
{
$nbCotisations = (int) $this->getQuery('SELECT COUNT(*) nb FROM afup_cotisations WHERE type_personne = :memberType AND id_personne = :id')
->setParams(['memberType' => AFUP_PERSONNES_MORALES, 'id' => $companyMember->getId()])
->setParams(['memberType' => MemberType::MemberCompany->value, 'id' => $companyMember->getId()])
->query()->first()[0]->nb;
if (0 < $nbCotisations) {
throw new InvalidArgumentException('Impossible de supprimer une personne morale qui a des cotisations');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace AppBundle\Association\UserMembership;

use Afup\Site\Association\Cotisations;
use AppBundle\Association\MemberType;
use AppBundle\Association\Model\CompanyMember;
use AppBundle\Association\Model\User;

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

public function computeCompany(CompanyMember $companyMember)
{
$cotis = $this->cotisations->obtenirListe(AFUP_PERSONNES_MORALES, $companyMember->getId());
$cotis = $this->cotisations->obtenirListe(MemberType::MemberCompany, $companyMember->getId());

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

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

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

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

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

return $this->computeFromCotisationsAndReturnInfos($cotis);
}
Expand Down
5 changes: 3 additions & 2 deletions sources/AppBundle/Association/UserMembership/UserService.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace AppBundle\Association\UserMembership;

use Afup\Site\Association\Cotisations;
use AppBundle\Association\MemberType;
use AppBundle\Association\Model\Repository\UserRepository;
use AppBundle\Association\Model\User;
use AppBundle\Email\Mailer\Mailer;
Expand Down Expand Up @@ -91,10 +92,10 @@ public function getLastSubscription(User $user)
{
if ($user->getCompanyId()) {
$id = $user->getCompanyId();
$personType = AFUP_PERSONNES_MORALES;
$personType = MemberType::MemberCompany;
} else {
$id = $user->getId();
$personType = AFUP_PERSONNES_PHYSIQUES;
$personType = MemberType::MemberPhysical;
}

return $this->cotisations->obtenirDerniere($personType, $id);
Expand Down
Loading