diff --git a/src/Controller/Admin/EFlexController.php b/src/Controller/Admin/EFlexController.php index 35daab5..af0203f 100644 --- a/src/Controller/Admin/EFlexController.php +++ b/src/Controller/Admin/EFlexController.php @@ -39,6 +39,21 @@ class EFlexController extends AbstractController throw $this->createNotFoundException('Client introuvable'); } + // Bloquer si un E-Flex est en cours ou annule (defaut) + $existingEflex = $this->em->getRepository(EFlex::class)->findBy(['customer' => $customer]); + foreach ($existingEflex as $existing) { + if (\in_array($existing->getState(), [EFlex::STATE_ACTIVE, EFlex::STATE_PENDING_SETUP, EFlex::STATE_DRAFT], true)) { + $this->addFlash('error', 'Un E-Flex est deja en cours ('.$existing->getReference().'). Impossible d\'en creer un nouveau.'); + + return $this->redirectToRoute('app_admin_clients_show', ['id' => $customerId, 'tab' => 'esyflex']); + } + if (EFlex::STATE_CANCELLED === $existing->getState() && $existing->getNbFailed() > 0) { + $this->addFlash('error', 'Un E-Flex est en defaut ('.$existing->getReference().'). Le client doit regulariser avant de creer un nouveau E-Flex.'); + + return $this->redirectToRoute('app_admin_clients_show', ['id' => $customerId, 'tab' => 'esyflex']); + } + } + $description = trim($request->request->getString('description')); $totalAmount = $request->request->getString('totalAmount'); $nbEcheances = $request->request->getInt('nbEcheances'); diff --git a/src/Controller/WebhookStripeController.php b/src/Controller/WebhookStripeController.php index f46d989..6448f7b 100644 --- a/src/Controller/WebhookStripeController.php +++ b/src/Controller/WebhookStripeController.php @@ -761,12 +761,52 @@ class WebhookStripeController extends AbstractController $line->setStripePaymentIntentId($paymentIntent->id); $this->em->flush(); + $cancelled = false; if ($eflex->getNbFailed() >= 2) { $eflex->setState(\App\Entity\EFlex::STATE_CANCELLED); $this->em->flush(); + $cancelled = true; } $customer = $eflex->getCustomer(); + + // Si annule : envoyer mail d'annulation au client + admin + if ($cancelled) { + if (null !== $customer->getEmail()) { + try { + $this->mailer->sendEmail( + $customer->getEmail(), + 'E-Flex '.$eflex->getReference().' annule - Rejets de prelevement', + $this->twig->render('emails/eflex_cancelled.html.twig', [ + 'customer' => $customer, + 'eflex' => $eflex, + ]), + null, + null, + false, + ); + } catch (\Throwable) { + // silencieux + } + } + + try { + $this->mailer->sendEmail( + self::NOTIFICATION_EMAIL, + 'E-Flex '.$eflex->getReference().' annule (2 rejets) - '.$customer->getFullName(), + $this->twig->render('emails/eflex_cancelled.html.twig', [ + 'customer' => $customer, + 'eflex' => $eflex, + ]), + null, + null, + false, + ); + } catch (\Throwable) { + // silencieux + } + } + if (null !== $customer->getEmail()) { try { $payUrl = $this->urlGenerator->generate('app_eflex_pay', [ diff --git a/templates/admin/clients/show.html.twig b/templates/admin/clients/show.html.twig index 81a5f88..cdc4e13 100644 --- a/templates/admin/clients/show.html.twig +++ b/templates/admin/clients/show.html.twig @@ -1208,9 +1208,26 @@ {# Tab: E-Flex #} {% elseif tab == 'esyflex' %} + {% set hasActiveEflex = false %} + {% set hasDefaultEflex = false %} + {% for e in eflexList %} + {% if e.state in ['active', 'pending_setup', 'draft'] %} + {% set hasActiveEflex = true %} + {% endif %} + {% if e.state == 'cancelled' and e.nbFailed > 0 %} + {% set hasDefaultEflex = true %} + {% endif %} + {% endfor %} +
+ {% set greeting = customer.raisonSociale ? 'Chez ' ~ customer.raisonSociale : 'Bonjour ' ~ customer.firstName %}
+ {{ greeting }},+ +
+
+
+ + E-Flex {{ eflex.reference }} annule + ++ Votre contrat de financement E-Flex a ete automatiquement annule suite a des rejets repetes de prelevement. Le solde restant reste du. + + +
+ Veuillez contacter notre service pour regulariser votre situation dans les plus brefs delais. + + ++ Pour toute question : contact@e-cosplay.fr + + |
+