✨ feat(Command/MailCommand): Ajoute nettoyage des contrats expirés et relance.
This commit is contained in:
@@ -13,12 +13,11 @@ use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
use Symfony\Component\Console\Style\SymfonyStyle;
|
||||
use Symfony\Component\HttpKernel\KernelInterface;
|
||||
use Symfony\Component\Mime\Part\DataPart;
|
||||
use Vich\UploaderBundle\Templating\Helper\UploaderHelper;
|
||||
|
||||
#[AsCommand(
|
||||
name: 'app:mail',
|
||||
description: 'Envoi automatisé des emails de suivi (devis, contrats, relances)',
|
||||
description: 'Envoi automatisé des emails de suivi et nettoyage des contrats expirés',
|
||||
)]
|
||||
class MailCommand extends Command
|
||||
{
|
||||
@@ -36,13 +35,14 @@ class MailCommand extends Command
|
||||
{
|
||||
$io = new SymfonyStyle($input, $output);
|
||||
$now = new \DateTime();
|
||||
$today = (new \DateTime())->setTime(0, 0);
|
||||
|
||||
// --- 1 & 2. DEVIS ET CONTRATS NON SIGNÉS (DÉJÀ IMPLÉMENTÉS) ---
|
||||
// --- 1. DEVIS NON SIGNÉS ---
|
||||
$this->processUnsignedDevis($io, $now);
|
||||
|
||||
// --- 2. CONTRATS NON SIGNÉS (RELANCE & SUPPRESSION) ---
|
||||
$this->processUnsignedContrats($io, $now);
|
||||
|
||||
// --- 3. CONTRAT EN ATTENTE D'ACOMPTE (Signé mais non payé) ---
|
||||
// --- 3. CONTRAT EN ATTENTE D'ACOMPTE ---
|
||||
$io->title('Traitement des contrats en attente d\'acompte');
|
||||
$contratsNoAccompte = $this->entityManager->getRepository(Contrats::class)->findBy(['isSigned' => true]);
|
||||
foreach ($contratsNoAccompte as $contrat) {
|
||||
@@ -61,7 +61,7 @@ class MailCommand extends Command
|
||||
}
|
||||
}
|
||||
|
||||
// --- 4. CONTRAT EN ATTENTE DE CAUTION (J-7 avant l'événement) ---
|
||||
// --- 4. CONTRAT EN ATTENTE DE CAUTION (J-7) ---
|
||||
$io->title('Traitement des cautions manquantes');
|
||||
$contratsNoCaution = $this->entityManager->getRepository(Contrats::class)->findBy(['isSigned' => true]);
|
||||
foreach ($contratsNoCaution as $contrat) {
|
||||
@@ -90,22 +90,23 @@ class MailCommand extends Command
|
||||
->setParameter('end', (clone $targetFeedback)->modify('+23 hours 59 mins'))
|
||||
->getQuery()->getResult();
|
||||
|
||||
/** @var Contrats $contrat */
|
||||
foreach ($finishedContrats as $contrat) {
|
||||
if($contrat->isSolde() && $contrat->isAccompte()){
|
||||
$customer = $contrat->getCustomer();
|
||||
$this->mailer->send(
|
||||
$customer->getEmail(),
|
||||
$customer->getName(),
|
||||
"[Ludikevent] Votre avis nous intéresse !",
|
||||
"mails/task/feedback.twig",
|
||||
['contrat' => $contrat, 'customer' => $customer]
|
||||
);
|
||||
$io->text("Email de satisfaction envoyé à " . $customer->getEmail());
|
||||
$customer = $contrat->getCustomer();
|
||||
$this->mailer->send(
|
||||
$customer->getEmail(),
|
||||
$customer->getName(),
|
||||
"[Ludikevent] Votre avis nous intéresse !",
|
||||
"mails/task/feedback.twig",
|
||||
['contrat' => $contrat, 'customer' => $customer]
|
||||
);
|
||||
$io->text("Email de satisfaction envoyé à " . $customer->getEmail());
|
||||
}
|
||||
}
|
||||
|
||||
$io->success('Toutes les tâches d\'envoi d\'emails ont été traitées.');
|
||||
$this->entityManager->flush();
|
||||
$io->success('Toutes les tâches d\'envoi d\'emails et de nettoyage ont été traitées.');
|
||||
|
||||
return Command::SUCCESS;
|
||||
}
|
||||
|
||||
@@ -114,33 +115,72 @@ class MailCommand extends Command
|
||||
$io->title('Analyse des devis non signés');
|
||||
$devisWaiting = $this->entityManager->getRepository(Devis::class)->findBy(['state' => 'wait-sign']);
|
||||
foreach ($devisWaiting as $devis) {
|
||||
if ($devis->getCreateA() && $devis->getCreateA()->diff($now)->days >= 3) {
|
||||
if (!$devis->getCreateA()) continue;
|
||||
|
||||
$diff = $devis->getCreateA()->diff($now)->days;
|
||||
|
||||
// Suppression si plus de 3 jours
|
||||
if ($diff >= 3) {
|
||||
foreach ($devis->getDevisLines() as $line) {
|
||||
$this->entityManager->persist($line);
|
||||
}
|
||||
foreach ($devis->getDevisOptions() as $line) {
|
||||
$this->entityManager->persist($line);
|
||||
}
|
||||
$io->warning("Suppression du devis N°" . $devis->getNum() . " (Non signé après 3 jours)");
|
||||
$this->entityManager->remove($devis);
|
||||
}
|
||||
// Relance si 1 jour révolu (email initial déjà envoyé à 0j)
|
||||
elseif ($diff >= 1) {
|
||||
$customer = $devis->getCustomer();
|
||||
$this->mailer->send(
|
||||
$customer->getEmail(),
|
||||
$customer->getName(),
|
||||
"[Ludikevent] Devis N°" . $devis->getNum() . " en attente de signature",
|
||||
"mails/task/task-nosigned.twig",
|
||||
['devis' => $devis, 'customer' => $customer, 'sign' => $this->client->getLinkSign($devis->getSignatureId())]
|
||||
);
|
||||
if ($customer) {
|
||||
$this->mailer->send(
|
||||
$customer->getEmail(),
|
||||
$customer->getName(),
|
||||
"[Ludikevent] Devis N°" . $devis->getNum() . " en attente de signature",
|
||||
"mails/task/task-nosigned.twig",
|
||||
['devis' => $devis, 'customer' => $customer, 'sign' => $this->client->getLinkSign($devis->getSignatureId())]
|
||||
);
|
||||
$io->text("Relance envoyée pour le devis : " . $devis->getNum());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private function processUnsignedContrats(SymfonyStyle $io, \DateTime $now): void
|
||||
{
|
||||
$io->title('Analyse des contrats non signés');
|
||||
$io->title('Analyse des contrats non signés (Relance & Nettoyage)');
|
||||
$contratWaiting = $this->entityManager->getRepository(Contrats::class)->findBy(['isSigned' => false]);
|
||||
|
||||
foreach ($contratWaiting as $contrat) {
|
||||
if ($contrat->getCreateAt() && $contrat->getCreateAt()->diff($now)->days >= 1) {
|
||||
if (!$contrat->getCreateAt()) continue;
|
||||
|
||||
$diff = $contrat->getCreateAt()->diff($now)->days;
|
||||
|
||||
// Suppression si plus de 3 jours
|
||||
if ($diff >= 3) {
|
||||
foreach ($contrat->getContratsLines() as $contratLine) {
|
||||
$this->entityManager->remove($contratLine);
|
||||
}
|
||||
foreach ($contrat->getContratsOptions() as $contratOption) {
|
||||
$this->entityManager->remove($contratOption);
|
||||
}
|
||||
$io->warning("Suppression du contrat N°" . $contrat->getNumReservation() . " (Non signé après 3 jours)");
|
||||
$this->entityManager->remove($contrat);
|
||||
}
|
||||
// Relance si 1 jour révolu (mais moins de 3)
|
||||
elseif ($diff >= 1) {
|
||||
$customer = $contrat->getCustomer();
|
||||
$this->mailer->send(
|
||||
$customer->getEmail(),
|
||||
$customer->getName(),
|
||||
"[Ludikevent] Signature urgente : Contrat N°" . $contrat->getNumReservation(),
|
||||
"mails/task/contrat-nosigned.twig",
|
||||
['contrat' => $contrat, 'customer' => $customer, 'sign' => $this->client->getLinkSign($contrat->getSignID())]
|
||||
);
|
||||
if ($customer) {
|
||||
$this->mailer->send(
|
||||
$customer->getEmail(),
|
||||
$customer->getName(),
|
||||
"[Ludikevent] Signature urgente : Contrat N°" . $contrat->getNumReservation(),
|
||||
"mails/task/contrat-nosigned.twig",
|
||||
['contrat' => $contrat, 'customer' => $customer, 'sign' => $this->client->getLinkSign($contrat->getSignID())]
|
||||
);
|
||||
$io->text("Relance envoyée pour le contrat : " . $contrat->getNumReservation());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -150,7 +190,6 @@ class MailCommand extends Command
|
||||
$io->title("Envoi des rappels J-$daysBefore");
|
||||
$targetDate = (new \DateTime())->modify("+$daysBefore days")->setTime(0, 0);
|
||||
|
||||
/** @var Contrats[] $contrats */
|
||||
$contrats = $this->entityManager->getRepository(Contrats::class)->createQueryBuilder('c')
|
||||
->where('c.dateStart >= :start AND c.dateStart <= :end')
|
||||
->andWhere('c.isSigned = true')
|
||||
|
||||
Reference in New Issue
Block a user