feat(ansible/cron): Ajoute une tâche cron pour la commande cota

 feat(src/Command): Crée la commande ecosplay:cota

🐛 fix(src/Repository): Corrige une erreur dans le repository MembersCotisations
This commit is contained in:
Serreau Jovann
2025-11-22 23:56:25 +01:00
parent 57cc319927
commit de43b9e1c1
3 changed files with 90 additions and 0 deletions

View File

@@ -230,3 +230,11 @@
become: false
args:
chdir: "{{ path }}"
- name: "Cota - Auto"
ansible.builtin.cron:
name: "E-Cosplay - Cota Auto"
minute: "0"
hour: "7,14,17"
user: "root"
job: "php {{ path }}/bin/console ecosplay:cota"
state: present

View File

@@ -0,0 +1,80 @@
<?php
namespace App\Command;
use App\Entity\Account;
use App\Entity\MembersCotisations;
use App\Repository\MembersCotisationsRepository;
use App\Repository\MembersRepository;
use App\Service\Generator\TempPasswordGenerator;
use App\Service\Mailer\Event\CreatedAdminEvent;
use App\Service\Mailer\Mailer;
use App\Service\Payments\PaymentClient;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Question\Question;
use Symfony\Component\Console\Style\SymfonyStyle;
use Symfony\Component\PasswordHasher\Hasher\UserPasswordHasherInterface;
use Symfony\Component\Uid\Uuid;
use Symfony\Contracts\EventDispatcher\EventDispatcherInterface;
#[AsCommand(name: 'ecosplay:cota')]
class CotaCommand extends Command
{
public function __construct(
private readonly MembersRepository $membersRepository,
private readonly MembersCotisationsRepository $membersCotisationsRepository,
private readonly EntityManagerInterface $entityManager,
private readonly Mailer $mailer,
private readonly PaymentClient $paymentClient,
?string $name = null
) {
parent::__construct($name);
}
protected function execute(InputInterface $input, OutputInterface $output): int
{
$io = new SymfonyStyle($input, $output);
$io->title("Création cota");
foreach ($this->membersRepository->findAll() as $member) {
if($member->getRole() =="Membre") {
$t = new \DateTimeImmutable();
$tNext = new \DateTimeImmutable();
$tNext = $tNext->modify("+1 year");
$cota = $member->getMembersCotisations()->filter(function (MembersCotisations $membersCotisations) use ($t, $tNext) {
return ($membersCotisations->getStartdATE()->format('Y') == $t->format('Y')) && ($membersCotisations->getEndDate()->format('Y') == $tNext->format('Y'));
})->first();
if (!$cota instanceof MembersCotisations) {
$cota = new MembersCotisations();
$cota->setIsPaid(false);
$cota->setAmount(15);
$cota->setStartdATE($t);
$cota->setEndDate($tNext);
$cota->setMembers($member);
$this->entityManager->persist($cota);
$this->entityManager->flush();
$link = $this->paymentClient->paymentCota($cota);
$cota->setPaymentId($link->id);
$paymentLink = $link->url;
$this->mailer->send($member->getEmail(), $member->getPseudo(), "[E-Cosplay] - Lien de paiement de votre cotisation", "mails/coti_payment.twig", [
'pseudo' => $member->getPseudo(),
'link' => $paymentLink,
'amount' => $cota->getAmount(),
'start_at' => $cota->getStartdATE(),
'end_at' => $cota->getEndDate(),
]);
$this->entityManager->persist($cota);
$this->entityManager->flush();
}
}
}
$this->entityManager->flush();
return Command::SUCCESS;
}
}

View File

@@ -2,6 +2,7 @@
namespace App\Repository;
use App\Entity\Members;
use App\Entity\MembersCotisations;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\Persistence\ManagerRegistry;
@@ -40,4 +41,5 @@ class MembersCotisationsRepository extends ServiceEntityRepository
// ->getOneOrNullResult()
// ;
// }
}