feat(mail): ajout du service de relances par e-mail et intégration HTMX dans l'admin
This commit is contained in:
@@ -25,8 +25,9 @@ public class AdherentController {
|
||||
private final SaisonRepository saisonRepository;
|
||||
private final com.astalange.core.service.CategorieService categorieService;
|
||||
private final com.astalange.core.service.SportEasyEmailService sportEasyEmailService;
|
||||
private final com.astalange.core.service.RelanceEmailService relanceEmailService;
|
||||
|
||||
public AdherentController(AdherentRepository adherentRepository, CategorieRepository categorieRepository, com.astalange.core.repository.LicenceRepository licenceRepository, com.astalange.core.repository.ModePaiementRepository modePaiementRepository, SaisonRepository saisonRepository, com.astalange.core.service.CategorieService categorieService, com.astalange.core.service.SportEasyEmailService sportEasyEmailService) {
|
||||
public AdherentController(AdherentRepository adherentRepository, CategorieRepository categorieRepository, com.astalange.core.repository.LicenceRepository licenceRepository, com.astalange.core.repository.ModePaiementRepository modePaiementRepository, SaisonRepository saisonRepository, com.astalange.core.service.CategorieService categorieService, com.astalange.core.service.SportEasyEmailService sportEasyEmailService, com.astalange.core.service.RelanceEmailService relanceEmailService) {
|
||||
this.adherentRepository = adherentRepository;
|
||||
this.categorieRepository = categorieRepository;
|
||||
this.licenceRepository = licenceRepository;
|
||||
@@ -34,6 +35,7 @@ public class AdherentController {
|
||||
this.saisonRepository = saisonRepository;
|
||||
this.categorieService = categorieService;
|
||||
this.sportEasyEmailService = sportEasyEmailService;
|
||||
this.relanceEmailService = relanceEmailService;
|
||||
}
|
||||
|
||||
@org.springframework.web.bind.annotation.ModelAttribute("equipes")
|
||||
@@ -382,4 +384,54 @@ public class AdherentController {
|
||||
|
||||
return "redirect:/adherents";
|
||||
}
|
||||
|
||||
@org.springframework.web.bind.annotation.PostMapping("/{id}/relancer-paiement")
|
||||
public String relancerPaiement(
|
||||
@org.springframework.web.bind.annotation.PathVariable Long id,
|
||||
org.springframework.web.servlet.mvc.support.RedirectAttributes redirectAttributes) {
|
||||
|
||||
Adherent adherent = adherentRepository.findById(id)
|
||||
.orElseThrow(() -> new IllegalArgumentException("Adhérent invalide : " + id));
|
||||
|
||||
Licence licence = adherent.getLicenceActuelle();
|
||||
if (licence == null) {
|
||||
redirectAttributes.addFlashAttribute("errorMessage", "Cet adhérent n'a pas de licence enregistrée.");
|
||||
return "redirect:/adherents";
|
||||
}
|
||||
|
||||
if (licence.getResteAPayer().compareTo(java.math.BigDecimal.ZERO) <= 0) {
|
||||
redirectAttributes.addFlashAttribute("infoMessage", "Cet adhérent est déjà à jour de sa cotisation.");
|
||||
return "redirect:/adherents";
|
||||
}
|
||||
|
||||
boolean sent = relanceEmailService.sendRelancePaiementCotisation(licence);
|
||||
if (sent) {
|
||||
redirectAttributes.addFlashAttribute("successMessage", "L'e-mail de relance de paiement pour " + adherent.getPrenom() + " " + adherent.getNom() + " a été envoyé avec succès.");
|
||||
} else {
|
||||
redirectAttributes.addFlashAttribute("errorMessage", "Impossible d'envoyer l'e-mail de relance (adresse e-mail manquante).");
|
||||
}
|
||||
|
||||
return "redirect:/adherents";
|
||||
}
|
||||
|
||||
@org.springframework.web.bind.annotation.PostMapping("/{id}/relancer-paiement-htmx")
|
||||
@org.springframework.web.bind.annotation.ResponseBody
|
||||
public String relancerPaiementHtmx(@org.springframework.web.bind.annotation.PathVariable Long id) {
|
||||
Adherent adherent = adherentRepository.findById(id).orElse(null);
|
||||
if (adherent == null || adherent.getLicenceActuelle() == null) {
|
||||
return "<span class=\"text-xs text-red-600 font-medium bg-red-50 px-2.5 py-1 rounded-full border border-red-200\">Introuvable</span>";
|
||||
}
|
||||
|
||||
Licence licence = adherent.getLicenceActuelle();
|
||||
if (licence.getResteAPayer().compareTo(java.math.BigDecimal.ZERO) <= 0) {
|
||||
return "<span class=\"text-xs text-green-700 font-medium bg-green-50 px-2.5 py-1 rounded-full border border-green-200\">Déjà réglé</span>";
|
||||
}
|
||||
|
||||
boolean sent = relanceEmailService.sendRelancePaiementCotisation(licence);
|
||||
if (sent) {
|
||||
return "<span class=\"text-xs text-amber-700 font-medium bg-amber-50 px-2 py-0.5 rounded-full border border-amber-200 inline-flex items-center gap-1\"><svg class=\"w-3 h-3\" fill=\"none\" stroke=\"currentColor\" viewBox=\"0 0 24 24\"><path stroke-linecap=\"round\" stroke-linejoin=\"round\" stroke-width=\"2\" d=\"M3 8l7.89 5.26a2 2 0 002.22 0L21 8M5 19h14a2 2 0 002-2V7a2 2 0 002-2H5a2 2 0 00-2 2v10a2 2 0 002 2z\"/></svg> Relance envoyée</span>";
|
||||
} else {
|
||||
return "<span class=\"text-xs text-red-600 font-medium bg-red-50 px-2 py-0.5 rounded-full border border-red-200\">Email manquant</span>";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+21
-1
@@ -8,17 +8,23 @@ import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.Model;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import com.astalange.core.entity.PreInscription;
|
||||
import com.astalange.core.service.RelanceEmailService;
|
||||
|
||||
@Controller
|
||||
@RequestMapping("/admin/pre-inscriptions")
|
||||
public class AdminPreInscriptionController {
|
||||
|
||||
private final PreInscriptionRepository preInscriptionRepository;
|
||||
private final PreInscriptionService preInscriptionService;
|
||||
private final RelanceEmailService relanceEmailService;
|
||||
|
||||
public AdminPreInscriptionController(PreInscriptionRepository preInscriptionRepository,
|
||||
PreInscriptionService preInscriptionService) {
|
||||
PreInscriptionService preInscriptionService,
|
||||
RelanceEmailService relanceEmailService) {
|
||||
this.preInscriptionRepository = preInscriptionRepository;
|
||||
this.preInscriptionService = preInscriptionService;
|
||||
this.relanceEmailService = relanceEmailService;
|
||||
}
|
||||
|
||||
@GetMapping
|
||||
@@ -46,6 +52,20 @@ public class AdminPreInscriptionController {
|
||||
return ""; // HTMX target la ligne avec outerHTML -> supprime la ligne
|
||||
}
|
||||
|
||||
@PostMapping("/{id}/relancer")
|
||||
@ResponseBody
|
||||
public String relancer(@PathVariable Long id) {
|
||||
PreInscription pre = preInscriptionRepository.findById(id)
|
||||
.orElseThrow(() -> new IllegalArgumentException("Pré-inscription introuvable : " + id));
|
||||
|
||||
boolean sent = relanceEmailService.sendRelancePreInscription(pre);
|
||||
if (sent) {
|
||||
return "<span class=\"text-xs text-amber-700 font-medium bg-amber-50 px-2.5 py-1 rounded-full border border-amber-200 inline-flex items-center gap-1\"><svg class=\"w-3.5 h-3.5\" fill=\"none\" stroke=\"currentColor\" viewBox=\"0 0 24 24\"><path stroke-linecap=\"round\" stroke-linejoin=\"round\" stroke-width=\"2\" d=\"M3 8l7.89 5.26a2 2 0 002.22 0L21 8M5 19h14a2 2 0 002-2V7a2 2 0 002-2H5a2 2 0 00-2 2v10a2 2 0 002 2z\"/></svg> Relance envoyée</span>";
|
||||
} else {
|
||||
return "<span class=\"text-xs text-red-600 font-medium bg-red-50 px-2.5 py-1 rounded-full border border-red-200\">Erreur (sans email)</span>";
|
||||
}
|
||||
}
|
||||
|
||||
@GetMapping("/count")
|
||||
@ResponseBody
|
||||
public String countBadge() {
|
||||
|
||||
@@ -10,6 +10,8 @@
|
||||
body { font-family: 'Inter', sans-serif; }
|
||||
.hidden-block { display: none; }
|
||||
</style>
|
||||
<meta name="_csrf" th:content="${_csrf.token}"/>
|
||||
<meta name="_csrf_header" th:content="${_csrf.headerName}"/>
|
||||
</head>
|
||||
<body class="bg-gray-50 text-gray-900 flex h-screen overflow-hidden">
|
||||
|
||||
@@ -306,6 +308,15 @@
|
||||
th:data-reste-a-payer="${lic.getResteAPayer()}"
|
||||
onclick="openPaiementModal(this.getAttribute('data-licence-id'), this.getAttribute('data-reste-a-payer'))"
|
||||
class="text-green-600 hover:text-green-800 font-medium bg-green-50 px-3 py-1 rounded-lg btn-payer">Payer</button>
|
||||
<span th:if="${lic.getResteAPayer().compareTo(T(java.math.BigDecimal).ZERO) > 0}" th:id="'relance-licence-container-' + ${lic.id}">
|
||||
<button type="button"
|
||||
th:attr="hx-post=@{/adherents/{id}/relancer-paiement-htmx(id=${adherent.id})}, hx-target=|#relance-licence-container-${lic.id}|"
|
||||
hx-swap="innerHTML"
|
||||
class="text-amber-700 hover:text-amber-900 font-medium bg-amber-50 hover:bg-amber-100 border border-amber-200 px-3 py-1 rounded-lg inline-flex items-center gap-1.5 transition-colors cursor-pointer" title="Envoyer un e-mail de relance pour la cotisation impayée">
|
||||
<svg class="w-3.5 h-3.5" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M3 8l7.89 5.26a2 2 0 002.22 0L21 8M5 19h14a2 2 0 002-2V7a2 2 0 002-2H5a2 2 0 00-2 2v10a2 2 0 002 2z"/></svg>
|
||||
Relancer
|
||||
</button>
|
||||
</span>
|
||||
</td>
|
||||
</tr>
|
||||
<tr th:if="${!#lists.isEmpty(lic.paiements)}" class="bg-gray-50/50">
|
||||
@@ -1081,6 +1092,14 @@
|
||||
if (typeMaillotSelect) {
|
||||
typeMaillotSelect.addEventListener('change', updateEquipmentStyleLabels);
|
||||
}
|
||||
|
||||
document.body.addEventListener('htmx:configRequest', function(evt) {
|
||||
var csrfHeader = document.querySelector('meta[name="_csrf_header"]');
|
||||
var csrfToken = document.querySelector('meta[name="_csrf"]');
|
||||
if (csrfHeader && csrfToken) {
|
||||
evt.detail.headers[csrfHeader.content] = csrfToken.content;
|
||||
}
|
||||
});
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
|
||||
@@ -9,6 +9,8 @@
|
||||
<style>
|
||||
body { font-family: 'Inter', sans-serif; }
|
||||
</style>
|
||||
<meta name="_csrf" th:content="${_csrf.token}"/>
|
||||
<meta name="_csrf_header" th:content="${_csrf.headerName}"/>
|
||||
</head>
|
||||
<body class="bg-gray-50 text-gray-900 flex h-screen overflow-hidden">
|
||||
|
||||
@@ -279,6 +281,16 @@
|
||||
<span class="font-bold" th:classappend="${adherent.getLicenceActuelle().getResteAPayer().compareTo(T(java.math.BigDecimal).ZERO) == 0 ? 'text-gray-800' : 'text-red-600'}" th:text="|${adherent.getLicenceActuelle().getResteAPayer()} €|">50 €</span>
|
||||
</div>
|
||||
</div>
|
||||
<!-- Bouton Relancer Solde -->
|
||||
<div th:if="${adherent.getLicenceActuelle().getResteAPayer().compareTo(T(java.math.BigDecimal).ZERO) > 0}" class="mt-1 text-center" th:id="'relance-paiement-container-' + ${adherent.id}">
|
||||
<button type="button"
|
||||
th:attr="hx-post=@{/adherents/{id}/relancer-paiement-htmx(id=${adherent.id})}, hx-target=|#relance-paiement-container-${adherent.id}|"
|
||||
hx-swap="innerHTML"
|
||||
class="text-[10px] text-amber-700 hover:text-amber-900 bg-amber-50 hover:bg-amber-100 border border-amber-200 px-2 py-0.5 rounded transition-colors inline-flex items-center gap-1 font-medium">
|
||||
<svg class="w-3 h-3" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M3 8l7.89 5.26a2 2 0 002.22 0L21 8M5 19h14a2 2 0 002-2V7a2 2 0 002-2H5a2 2 0 00-2 2v10a2 2 0 002 2z"/></svg>
|
||||
Relancer
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</td>
|
||||
<!-- SportEasy Status Column -->
|
||||
@@ -415,6 +427,14 @@
|
||||
closeAllEquipementPopovers();
|
||||
}
|
||||
});
|
||||
|
||||
document.body.addEventListener('htmx:configRequest', function(evt) {
|
||||
var csrfHeader = document.querySelector('meta[name="_csrf_header"]');
|
||||
var csrfToken = document.querySelector('meta[name="_csrf"]');
|
||||
if (csrfHeader && csrfToken) {
|
||||
evt.detail.headers[csrfHeader.content] = csrfToken.content;
|
||||
}
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
@@ -45,15 +45,25 @@
|
||||
<td class="py-4 px-6">
|
||||
<div class="text-xs text-gray-500" th:text="${pre.email}"></div>
|
||||
</td>
|
||||
<td class="py-4 px-6 text-right space-x-2">
|
||||
<td class="py-4 px-6 text-right flex items-center justify-end space-x-2">
|
||||
<span th:id="'relance-container-' + ${pre.id}">
|
||||
<button th:attr="hx-post=@{/admin/pre-inscriptions/{id}/relancer(id=${pre.id})}, hx-target=|#relance-container-${pre.id}|"
|
||||
hx-swap="innerHTML"
|
||||
class="bg-amber-50 text-amber-700 border border-amber-200 px-3 py-1.5 rounded hover:bg-amber-100 transition-colors inline-flex items-center gap-1.5 font-medium">
|
||||
<svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M3 8l7.89 5.26a2 2 0 002.22 0L21 8M5 19h14a2 2 0 002-2V7a2 2 0 002-2H5a2 2 0 00-2 2v10a2 2 0 002 2z"/>
|
||||
</svg>
|
||||
Relancer
|
||||
</button>
|
||||
</span>
|
||||
<button th:attr="hx-post=@{/admin/pre-inscriptions/{id}/valider(id=${pre.id})}"
|
||||
class="bg-blue-600 text-white px-3 py-1.5 rounded hover:bg-blue-700 transition-colors">
|
||||
class="bg-blue-600 text-white px-3 py-1.5 rounded hover:bg-blue-700 transition-colors font-medium">
|
||||
Créer la fiche
|
||||
</button>
|
||||
<button th:attr="hx-post=@{/admin/pre-inscriptions/{id}/rejeter(id=${pre.id})}, hx-target=|#pre-${pre.id}|"
|
||||
hx-swap="outerHTML"
|
||||
hx-confirm="Confirmer le rejet du dossier ?"
|
||||
class="bg-red-50 text-red-600 border border-red-200 px-3 py-1.5 rounded hover:bg-red-100 transition-colors">
|
||||
class="bg-red-50 text-red-600 border border-red-200 px-3 py-1.5 rounded hover:bg-red-100 transition-colors font-medium">
|
||||
Rejeter
|
||||
</button>
|
||||
</td>
|
||||
|
||||
Reference in New Issue
Block a user