From 1cd82b94e63808632e887b36fefe037a3aceb2d7 Mon Sep 17 00:00:00 2001
From: Yvon <yvon.kerdoncuff@gmail.com>
Date: Mon, 22 Apr 2024 14:13:48 +0200
Subject: [PATCH] 6213 : send mail on ceiling cut

---
 src/Entity/CotisationTavApplication.php                    |  1 +
 src/Entity/CotisationTavPrelevementDepassementPlafond.php  | 29 +++++++++++++++++++++++++++++
 src/Entity/Flux.php                                        |  8 +++++---
 src/Utils/TAVCotisationUtils.php                           |  3 ++-
 templates/themes/kohinos/email/notification_flux.html.twig |  2 ++
 translations/flux.fr.yml                                   |  1 +
 6 files changed, 40 insertions(+), 4 deletions(-)
 create mode 100644 src/Entity/CotisationTavPrelevementDepassementPlafond.php

diff --git a/src/Entity/CotisationTavApplication.php b/src/Entity/CotisationTavApplication.php
index 8b09c56..c71c751 100644
--- a/src/Entity/CotisationTavApplication.php
+++ b/src/Entity/CotisationTavApplication.php
@@ -23,6 +23,7 @@ class CotisationTavApplication extends Flux
 {
     const TYPE_REVERSEMENT_COTISATION_ADHERENT = 'reversement_cotisation_adherent';
     const TYPE_PRELEVEMENT_COTISATION_ADHERENT = 'prelevement_cotisation_adherent';
+    const TYPE_PRELEVEMENT_COTISATION_ADHERENT_DEPASSEMENT_PLAFOND = 'prelevement_cotisation_adherent_depassement_plafond';
 
     /**
      * @return string
diff --git a/src/Entity/CotisationTavPrelevementDepassementPlafond.php b/src/Entity/CotisationTavPrelevementDepassementPlafond.php
new file mode 100644
index 0000000..754c8f2
--- /dev/null
+++ b/src/Entity/CotisationTavPrelevementDepassementPlafond.php
@@ -0,0 +1,29 @@
+<?php
+
+namespace App\Entity;
+use Doctrine\ORM\Mapping as ORM;
+
+/**
+ * Child class used to notify adherents by email.
+ *
+ * - [Allocation selon foyer] Un administrateur effectue une opération manuelle de prélèvement de l'adhérent
+ *   pour ramener son solde au niveau de son plafond.
+ * @ORM\Entity
+ */
+class CotisationTavPrelevementDepassementPlafond extends CotisationTavPrelevement
+{
+    /**
+     * @return string
+     */
+    public function getType(): string
+    {
+        return parent::TYPE_PRELEVEMENT_COTISATION_ADHERENT_DEPASSEMENT_PLAFOND;
+    }
+
+    public function getUsersToNotify()
+    {
+        return [
+            'expediteurs' => [$this->getExpediteur()->getUser()],
+        ];
+    }
+}
diff --git a/src/Entity/Flux.php b/src/Entity/Flux.php
index b48ea76..85cfa61 100644
--- a/src/Entity/Flux.php
+++ b/src/Entity/Flux.php
@@ -57,6 +57,7 @@ use Symfony\Component\Validator\Constraints as Assert;
  *     "application_cotisation_tav" = "CotisationTavApplication",
  *     "reversement_cotisation_adherent" = "CotisationTavReversement",
  *     "prelevement_cotisation_adherent" = "CotisationTavPrelevement",
+ *     "prelevement_cotisation_adherent_depassement_plafond" = "CotisationTavPrelevementDepassementPlafond",
  * })
  */
 abstract class Flux implements FluxInterface
@@ -658,13 +659,14 @@ abstract class Flux implements FluxInterface
             : $this->type;
     }
 
-    public static function ssaUsefulFriendlyTypeNames($differentiateAchatsDeMonaPayzenOrComptoir = false)
+    public static function ssaUsefulFriendlyTypeNames($uniqueValues = false)
     {
         return [
-            VenteEmlc::TYPE_VENTE_EMLC_ADHERENT => "Achat de MonA via cotisation" . ($differentiateAchatsDeMonaPayzenOrComptoir ? " (au comptoir)" : ""),
-            AchatMonnaie::TYPE_ACHAT_ADHERENT => "Achat de MonA via cotisation" . ($differentiateAchatsDeMonaPayzenOrComptoir ? " (via Payzen)" : ""),
+            VenteEmlc::TYPE_VENTE_EMLC_ADHERENT => "Achat de MonA via cotisation" . ($uniqueValues ? " (au comptoir)" : ""),
+            AchatMonnaie::TYPE_ACHAT_ADHERENT => "Achat de MonA via cotisation" . ($uniqueValues ? " (via Payzen)" : ""),
             CotisationTavApplication::TYPE_REVERSEMENT_COTISATION_ADHERENT => "Allocation complémentaire de la caisse",
             CotisationTavApplication::TYPE_PRELEVEMENT_COTISATION_ADHERENT => "Réduction de l'allocation",
+            CotisationTavApplication::TYPE_PRELEVEMENT_COTISATION_ADHERENT_DEPASSEMENT_PLAFOND => "Réduction de l'allocation" . ($uniqueValues ? " (dépassement plafond)" : ""),
             Don::TYPE_DON_ADHERENT => Don::TYPE_DON_ADHERENT,
             Don::TYPE_DON_PRESTATAIRE => Don::TYPE_DON_PRESTATAIRE,
             Reconversion::TYPE_RECONVERSION_PRESTATAIRE => Reconversion::TYPE_RECONVERSION_PRESTATAIRE,
diff --git a/src/Utils/TAVCotisationUtils.php b/src/Utils/TAVCotisationUtils.php
index 3b6e54e..780db44 100644
--- a/src/Utils/TAVCotisationUtils.php
+++ b/src/Utils/TAVCotisationUtils.php
@@ -3,6 +3,7 @@
 namespace App\Utils;
 
 use App\Entity\Adherent;
+use App\Entity\CotisationTavPrelevementDepassementPlafond;
 use App\Entity\Payment;
 use App\Entity\Siege;
 use App\Entity\Flux;
@@ -223,7 +224,7 @@ class TAVCotisationUtils
             throw new \Exception("Impossible de prélèver : le solde de l'adhérent est inférieur ou égal au plafond.");
         }
 
-        $flux = new CotisationTavPrelevement();
+        $flux = new CotisationTavPrelevementDepassementPlafond();
         $flux->setExpediteur($adherent);
         $flux->setDestinataire($siege);
         $flux->setMontant(-$amountDiff);
diff --git a/templates/themes/kohinos/email/notification_flux.html.twig b/templates/themes/kohinos/email/notification_flux.html.twig
index c9559de..da07656 100644
--- a/templates/themes/kohinos/email/notification_flux.html.twig
+++ b/templates/themes/kohinos/email/notification_flux.html.twig
@@ -10,6 +10,8 @@
 	<h3>
 		{% if flux.type == 'reconversion' %}
 			{{ 'Demande de reconversion' }}
+		{% elseif flux.type == 'prelevement_cotisation_adherent_depassement_plafond' %}
+			{{ "Réduction de l'allocation après dépassement du plafond" }}
 		{% else %}
 			{{ flux.parenttype|capitalize }} : {{ flux.type|replace({'_' : ' => '}) }}
 		{% endif %}
diff --git a/translations/flux.fr.yml b/translations/flux.fr.yml
index 1dbfd41..12a3ca6 100644
--- a/translations/flux.fr.yml
+++ b/translations/flux.fr.yml
@@ -128,3 +128,4 @@ des_vente_emlc: 'Achat monnaie numérique'
 exp_vente_emlc: 'Vente monnaie numérique'
 exp_ticket_print: 'Impression de billets'
 exp_ticket_destroy: 'Destruction de billets'
+exp_prelevement_cotisation_adherent_depassement_plafond_email_subject: 'Réduction de l''allocation après dépassement du plafond'
\ No newline at end of file
--
libgit2 0.26.0