8 Commits
23 changed files with 1052 additions and 90 deletions
@@ -141,6 +141,7 @@ public class Licence {
} }
BigDecimal totalPaye = paiements.stream() BigDecimal totalPaye = paiements.stream()
.filter(p -> p.getRemis() == null || Boolean.TRUE.equals(p.getRemis()))
.map(Paiement::getMontant) .map(Paiement::getMontant)
.reduce(BigDecimal.ZERO, BigDecimal::add); .reduce(BigDecimal.ZERO, BigDecimal::add);
@@ -154,10 +155,27 @@ public class Licence {
return BigDecimal.ZERO; return BigDecimal.ZERO;
} }
return paiements.stream() return paiements.stream()
.filter(p -> p.getRemis() == null || Boolean.TRUE.equals(p.getRemis()))
.map(Paiement::getMontant) .map(Paiement::getMontant)
.reduce(BigDecimal.ZERO, BigDecimal::add); .reduce(BigDecimal.ZERO, BigDecimal::add);
} }
@Transient
public BigDecimal getSoldeRestantEngage() {
BigDecimal prixTotal = getPrixTotal();
if (paiements == null || paiements.isEmpty()) {
return prixTotal;
}
BigDecimal totalTousPaiements = paiements.stream()
.map(Paiement::getMontant)
.reduce(BigDecimal.ZERO, BigDecimal::add);
BigDecimal reste = prixTotal.subtract(totalTousPaiements);
return reste.compareTo(BigDecimal.ZERO) < 0 ? BigDecimal.ZERO : reste;
}
// Getters and Setters // Getters and Setters
public Long getId() { return id; } public Long getId() { return id; }
@@ -35,6 +35,9 @@ public class Paiement {
@Column(name = "commentaire", columnDefinition = "TEXT") @Column(name = "commentaire", columnDefinition = "TEXT")
private String commentaire; private String commentaire;
@Column(name = "remis", nullable = false)
private Boolean remis = true;
// Getters and Setters // Getters and Setters
public Long getId() { return id; } public Long getId() { return id; }
@@ -60,4 +63,7 @@ public class Paiement {
public String getCommentaire() { return commentaire; } public String getCommentaire() { return commentaire; }
public void setCommentaire(String commentaire) { this.commentaire = commentaire; } public void setCommentaire(String commentaire) { this.commentaire = commentaire; }
public Boolean getRemis() { return remis != null ? remis : true; }
public void setRemis(Boolean remis) { this.remis = remis != null ? remis : true; }
} }
@@ -70,6 +70,11 @@ public class PaiementEmailService {
return false; return false;
} }
if (Boolean.FALSE.equals(paiement.getRemis())) {
log.info("Paiement non remis (remis=false) pour le paiement ID {}. L'e-mail de confirmation ne sera pas envoyé.", paiement.getId());
return false;
}
Licence licence = paiement.getLicence(); Licence licence = paiement.getLicence();
String recipientEmail = licence.getAdherent() != null ? licence.getAdherent().getEmail() : null; String recipientEmail = licence.getAdherent() != null ? licence.getAdherent().getEmail() : null;
log.info(">>> [PaiementEmailService] Adhérent: {} {}, Email: {}", log.info(">>> [PaiementEmailService] Adhérent: {} {}, Email: {}",
@@ -0,0 +1,309 @@
package com.astalange.core.service;
import com.astalange.core.entity.Adherent;
import com.astalange.core.entity.Licence;
import com.astalange.core.entity.PreInscription;
import jakarta.mail.internet.MimeMessage;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.mail.javamail.MimeMessageHelper;
import org.springframework.stereotype.Service;
import java.math.BigDecimal;
import java.time.LocalDate;
import java.time.Period;
import java.util.Locale;
import java.util.concurrent.CompletableFuture;
@Service
public class RelanceEmailService {
private static final Logger log = LoggerFactory.getLogger(RelanceEmailService.class);
private final JavaMailSender mailSender;
@Value("${app.mail.from:${spring.mail.username:astalange1933@gmail.com}}")
private String fromEmail = "astalange1933@gmail.com";
public RelanceEmailService(@Autowired(required = false) JavaMailSender mailSender) {
this.mailSender = mailSender;
}
private String getEffectiveFromEmail() {
if (fromEmail != null && !fromEmail.trim().isEmpty() && fromEmail.contains("@")) {
return fromEmail.trim();
}
return "astalange1933@gmail.com";
}
public boolean isMineur(LocalDate dateNaissance) {
if (dateNaissance == null) return false;
return Period.between(dateNaissance, LocalDate.now()).getYears() < 18;
}
/**
* Envoie une relance aux personnes pré-inscrites pour leur demander de se présenter au club.
*/
public boolean sendRelancePreInscription(PreInscription preInscription) {
if (preInscription == null) {
log.warn("Impossible d'envoyer l'e-mail de relance : la pré-inscription est nulle.");
return false;
}
String recipientEmail = preInscription.getEmail();
if (recipientEmail == null || recipientEmail.trim().isEmpty()) {
log.warn("Pré-inscription ID {}: aucun e-mail renseigné. Relance non envoyée.", preInscription.getId());
return false;
}
boolean estMineur = isMineur(preInscription.getDateNaissance());
String adherentNomComplet = preInscription.getPrenom() + " " + preInscription.getNom();
String greeting;
String subject;
if (estMineur) {
String rep = preInscription.getRepresentantLegal();
if (rep != null && !rep.trim().isEmpty()) {
greeting = "Bonjour " + rep.trim() + " (Représentant légal de " + adherentNomComplet + ")";
} else {
greeting = "Bonjour (Représentant légal de " + adherentNomComplet + ")";
}
subject = "AS Talange - Relance demande d'inscription pour " + adherentNomComplet;
} else {
greeting = "Bonjour " + adherentNomComplet;
subject = "AS Talange - Relance concernant votre demande d'inscription";
}
String htmlContent = buildRelancePreInscriptionHtml(preInscription, greeting, adherentNomComplet, estMineur);
CompletableFuture.runAsync(() -> {
if (mailSender != null) {
try {
MimeMessage message = mailSender.createMimeMessage();
MimeMessageHelper helper = new MimeMessageHelper(message, true, "UTF-8");
helper.setFrom(getEffectiveFromEmail());
helper.setTo(recipientEmail.trim());
helper.setSubject(subject);
helper.setText(htmlContent, true);
mailSender.send(message);
log.info("E-mail de relance pré-inscription envoyé avec succès à {} pour {}", recipientEmail, adherentNomComplet);
} catch (Exception e) {
log.warn("Erreur envoi SMTP relance pré-inscription à {}: {}. Log en mode simulation.", recipientEmail, e.getMessage());
logDevEmail(recipientEmail, subject, htmlContent);
}
} else {
log.info("Mode DEV (MailSender non configuré) : simulation relance pré-inscription.");
logDevEmail(recipientEmail, subject, htmlContent);
}
});
return true;
}
/**
* Envoie une relance pour les paiements de cotisation incomplets.
*/
public boolean sendRelancePaiementCotisation(Licence licence) {
if (licence == null || licence.getAdherent() == null) {
log.warn("Impossible d'envoyer l'e-mail de relance paiement : licence ou adhérent nul.");
return false;
}
Adherent adherent = licence.getAdherent();
String recipientEmail = adherent.getEmail();
if (recipientEmail == null || recipientEmail.trim().isEmpty()) {
log.warn("Adhérent ID {}: aucun e-mail renseigné. Relance paiement non envoyée.", adherent.getId());
return false;
}
BigDecimal resteAPayer = licence.getResteAPayer();
if (resteAPayer.compareTo(BigDecimal.ZERO) <= 0) {
log.info("Licence ID {}: aucun solde restant à payer (Reste = 0 €). Relance non nécessaire.", licence.getId());
return false;
}
boolean estMineur = isMineur(adherent.getDateNaissance());
String adherentNomComplet = adherent.getPrenom() + " " + adherent.getNom();
String greeting;
String subject;
if (estMineur) {
String rep = adherent.getRepresentantLegal();
if (rep != null && !rep.trim().isEmpty()) {
greeting = "Bonjour " + rep.trim() + " (Représentant légal de " + adherentNomComplet + ")";
} else {
greeting = "Bonjour (Représentant légal de " + adherentNomComplet + ")";
}
subject = "AS Talange - Rappel solde de cotisation pour " + adherentNomComplet;
} else {
greeting = "Bonjour " + adherentNomComplet;
subject = "AS Talange - Rappel important : Solde de cotisation impayé";
}
String htmlContent = buildRelancePaiementHtml(licence, greeting, adherentNomComplet, estMineur, resteAPayer);
CompletableFuture.runAsync(() -> {
if (mailSender != null) {
try {
MimeMessage message = mailSender.createMimeMessage();
MimeMessageHelper helper = new MimeMessageHelper(message, true, "UTF-8");
helper.setFrom(getEffectiveFromEmail());
helper.setTo(recipientEmail.trim());
helper.setSubject(subject);
helper.setText(htmlContent, true);
mailSender.send(message);
log.info("E-mail de relance paiement envoyé avec succès à {} (Reste: {} €)", recipientEmail, resteAPayer);
} catch (Exception e) {
log.warn("Erreur envoi SMTP relance paiement à {}: {}. Log en mode simulation.", recipientEmail, e.getMessage());
logDevEmail(recipientEmail, subject, htmlContent);
}
} else {
log.info("Mode DEV (MailSender non configuré) : simulation relance paiement.");
logDevEmail(recipientEmail, subject, htmlContent);
}
});
return true;
}
private void logDevEmail(String recipient, String subject, String body) {
log.info("==================== [SIMULATION E-MAIL RELANCE] ====================");
log.info("Destinataire: {}", recipient);
log.info("Sujet: {}", subject);
log.info("Contenu:\n{}", body);
log.info("======================================================================");
}
private String buildRelancePreInscriptionHtml(PreInscription pre, String greeting, String adherentNomComplet, boolean estMineur) {
String saisonNom = pre.getSaison() != null ? pre.getSaison().getNom() : "";
String termeSujet = estMineur ? "la demande d'inscription pour votre enfant <strong>" + adherentNomComplet + "</strong>" : "votre demande d'inscription";
return """
<!DOCTYPE html>
<html lang="fr">
<head>
<meta charset="UTF-8">
<style>
body { font-family: Arial, sans-serif; background-color: #f4f6f8; margin: 0; padding: 20px; color: #333; }
.container { max-width: 600px; margin: 0 auto; background: #ffffff; border-radius: 8px; overflow: hidden; box-shadow: 0 2px 8px rgba(0,0,0,0.1); }
.header { background-color: #1e3a8a; color: #ffffff; padding: 24px; text-align: center; }
.header h1 { margin: 0; font-size: 22px; }
.content { padding: 24px; line-height: 1.6; }
.alert-info { background-color: #e0f2fe; border-left: 4px solid #0284c7; color: #075985; padding: 16px; border-radius: 6px; margin: 20px 0; }
.info-box { background: #f9fafb; border: 1px solid #e5e7eb; border-radius: 6px; padding: 16px; margin-top: 20px; }
.info-box h3 { margin-top: 0; font-size: 16px; color: #1e3a8a; }
.btn { display: inline-block; background-color: #1e3a8a; color: #ffffff; padding: 12px 24px; text-decoration: none; border-radius: 6px; font-weight: bold; margin-top: 15px; }
.footer { background: #f9fafb; border-top: 1px solid #e5e7eb; padding: 16px; text-align: center; font-size: 12px; color: #6b7280; }
</style>
</head>
<body>
<div class="container">
<div class="header">
<h1>AS Talange - Finalisation de votre inscription</h1>
</div>
<div class="content">
<p>%s,</p>
<p>Sauf erreur de notre part, nous avons bien reçu %s pour la saison <strong>%s</strong>, mais celle-ci n'a pas encore été finalisée au sein de notre club.</p>
<div class="alert-info">
<strong>Pour finaliser l'inscription :</strong> Nous vous invitons à vous présenter directement au secrétariat de l'AS Talange lors de nos permanences pour valider l'inscription.
</div>
<p style="margin-top: 24px;">Nous restant à votre entière disposition pour tout renseignement complémentaire.<br><br>Sportivement,<br><strong>L'équipe de l'AS Talange</strong></p>
</div>
<div class="footer">
Cet e-mail automatique a été envoyé par le système de gestion de l'AS Talange.
</div>
</div>
</body>
</html>
""".formatted(greeting, termeSujet, saisonNom);
}
private String buildRelancePaiementHtml(Licence licence, String greeting, String adherentNomComplet, boolean estMineur, BigDecimal resteAPayer) {
String saisonNom = licence.getSaison() != null ? licence.getSaison().getNom() : "";
String categorieNom = licence.getCategorie() != null ? licence.getCategorie().getNom() : "";
String termeSujet = estMineur ? "la cotisation de votre enfant <strong>" + adherentNomComplet + "</strong>" : "votre cotisation";
String prixTotalStr = String.format(Locale.FRANCE, "%.2f €", licence.getPrixTotal());
String totalPayeStr = String.format(Locale.FRANCE, "%.2f €", licence.getSommePayee());
String resteStr = String.format(Locale.FRANCE, "%.2f €", resteAPayer);
return """
<!DOCTYPE html>
<html lang="fr">
<head>
<meta charset="UTF-8">
<style>
body { font-family: Arial, sans-serif; background-color: #f4f6f8; margin: 0; padding: 20px; color: #333; }
.container { max-width: 600px; margin: 0 auto; background: #ffffff; border-radius: 8px; overflow: hidden; box-shadow: 0 2px 8px rgba(0,0,0,0.1); }
.header { background-color: #1e3a8a; color: #ffffff; padding: 24px; text-align: center; }
.header h1 { margin: 0; font-size: 22px; }
.content { padding: 24px; line-height: 1.6; }
.alert-danger { background-color: #fef2f2; border-left: 4px solid #ef4444; color: #991b1b; padding: 16px; border-radius: 6px; margin: 20px 0; }
.receipt-box { background: #f9fafb; border: 1px solid #e5e7eb; border-radius: 6px; padding: 16px; margin-top: 20px; }
.receipt-box h3 { margin-top: 0; margin-bottom: 12px; font-size: 16px; color: #1e3a8a; border-bottom: 1px solid #e5e7eb; padding-bottom: 8px; }
.receipt-table { width: 100%%; border-collapse: collapse; font-size: 14px; }
.receipt-table td { padding: 6px 0; }
.receipt-table td.label { color: #6b7280; width: 50%%; }
.receipt-table td.value { font-weight: bold; text-align: right; }
.badge-danger { display: inline-block; padding: 4px 10px; border-radius: 12px; font-weight: bold; font-size: 14px; background-color: #fef2f2; color: #991b1b; border: 1px solid #fca5a5; }
.footer { background: #f9fafb; border-top: 1px solid #e5e7eb; padding: 16px; text-align: center; font-size: 12px; color: #6b7280; }
</style>
</head>
<body>
<div class="container">
<div class="header">
<h1>AS Talange - Rappel de solde de cotisation</h1>
</div>
<div class="content">
<p>%s,</p>
<p>Nous vous contactons concernant %s (saison <strong>%s</strong>, catégorie <strong>%s</strong>) pour laquelle un solde reste actuellement à régler.</p>
<div class="receipt-box">
<h3>Situation Financière</h3>
<table class="receipt-table">
<tr>
<td class="label">Adhérent :</td>
<td class="value">%s</td>
</tr>
<tr>
<td class="label">Montant total cotisation :</td>
<td class="value">%s</td>
</tr>
<tr>
<td class="label">Total versé à ce jour :</td>
<td class="value">%s</td>
</tr>
<tr>
<td class="label">Solde restant à régler :</td>
<td class="value"><span class="badge-danger">%s</span></td>
</tr>
</table>
</div>
<div class="alert-danger">
<strong>Important :</strong><br>
Conformément aux statuts et au règlement intérieur de l'AS Talange, <strong>tant que le paiement de la cotisation n'est pas intégralement finalisé, l'inscription et la licence ne seront pas valides</strong>. L'accès aux entraînements et aux rencontres officielles pourra être suspendu.
</div>
<p>Nous vous demandons de bien vouloir vous présenter au secrétariat du club lors des permanences afin d'effectuer le règlement du solde restant (%s).</p>
<p style="margin-top: 24px;">Comptant sur votre prompt réajustement,<br>Sportivement,<br><strong>Le Bureau de l'AS Talange</strong></p>
</div>
<div class="footer">
Cet e-mail automatique a été envoyé par le système de gestion de l'AS Talange.
</div>
</div>
</body>
</html>
""".formatted(greeting, termeSujet, saisonNom, categorieNom, adherentNomComplet, prixTotalStr, totalPayeStr, resteStr, resteStr);
}
}
@@ -0,0 +1,4 @@
ALTER TABLE paiement ADD COLUMN IF NOT EXISTS remis BOOLEAN NOT NULL DEFAULT TRUE;
INSERT INTO mode_paiement (nom) VALUES ('Chèque Sport mairie')
ON CONFLICT (nom) DO NOTHING;
@@ -95,4 +95,37 @@ class LicenceReductionTest {
assertEquals(new BigDecimal("40.00"), licence.getMontantReduction()); assertEquals(new BigDecimal("40.00"), licence.getMontantReduction());
assertEquals(new BigDecimal("160.00"), licence.getResteAPayer()); assertEquals(new BigDecimal("160.00"), licence.getResteAPayer());
} }
@Test
@DisplayName("Devrait inclure le paiement dans le total payé uniquement s'il est remis")
void testPaiementRemisVsNonRemis() {
Categorie cat = new Categorie();
cat.setTarifBase(new BigDecimal("100.00"));
Adherent adh = new Adherent();
adh.setResidentTalange(true);
Licence licence = new Licence();
licence.setCategorie(cat);
licence.setAdherent(adh);
com.astalange.core.entity.Paiement p1 = new com.astalange.core.entity.Paiement();
p1.setMontant(new BigDecimal("40.00"));
p1.setRemis(false); // Non remis (ex: Chèque Sport mairie en attente)
licence.addPaiement(p1);
// La somme de ce chèque non remis n'est PAS déduite du financier => reste à payer = 100.00 €
assertEquals(0, BigDecimal.ZERO.compareTo(licence.getSommePayee()));
assertEquals(0, new BigDecimal("100.00").compareTo(licence.getResteAPayer()));
// En revanche, le solde disponible engagé prend en compte TOUS les paiements => reste engagé = 60.00 €
assertEquals(0, new BigDecimal("60.00").compareTo(licence.getSoldeRestantEngage()));
// Passage à remis = true (remis/encaissé)
p1.setRemis(true);
// La somme est déduite du financier => reste à payer = 60.00 €
assertEquals(0, new BigDecimal("40.00").compareTo(licence.getSommePayee()));
assertEquals(0, new BigDecimal("60.00").compareTo(licence.getResteAPayer()));
assertEquals(0, new BigDecimal("60.00").compareTo(licence.getSoldeRestantEngage()));
}
} }
@@ -170,4 +170,23 @@ class PaiementEmailServiceTest {
assertTrue(result); assertTrue(result);
verify(mailSenderMock, timeout(2000).times(1)).send(any(MimeMessage.class)); verify(mailSenderMock, timeout(2000).times(1)).send(any(MimeMessage.class));
} }
@Test
void testSendPaiementConfirmation_NonRemis() {
Adherent adherent = new Adherent();
adherent.setNom("DUPONT");
adherent.setPrenom("Jean");
adherent.setEmail("jean.dupont@example.com");
Licence licence = new Licence();
licence.setAdherent(adherent);
Paiement paiement = new Paiement();
paiement.setLicence(licence);
paiement.setMontant(new BigDecimal("50.00"));
paiement.setRemis(false);
boolean result = paiementEmailService.sendPaiementConfirmation(paiement);
assertFalse(result, "Devrait retourner false et ne pas envoyer d'email si remis = false");
}
} }
@@ -0,0 +1,151 @@
package com.astalange.core.service;
import com.astalange.core.entity.Adherent;
import com.astalange.core.entity.Categorie;
import com.astalange.core.entity.Licence;
import com.astalange.core.entity.PreInscription;
import com.astalange.core.entity.Saison;
import jakarta.mail.internet.MimeMessage;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.mockito.ArgumentCaptor;
import org.springframework.mail.javamail.JavaMailSender;
import java.math.BigDecimal;
import java.time.LocalDate;
import static org.junit.jupiter.api.Assertions.*;
import static org.mockito.Mockito.*;
class RelanceEmailServiceTest {
private RelanceEmailService relanceEmailService;
private JavaMailSender mailSenderMock;
@BeforeEach
void setUp() {
mailSenderMock = mock(JavaMailSender.class);
MimeMessage mimeMessage = new MimeMessage((jakarta.mail.Session) null);
when(mailSenderMock.createMimeMessage()).thenReturn(mimeMessage);
relanceEmailService = new RelanceEmailService(mailSenderMock);
}
@Test
void testIsMineur() {
LocalDate minorDob = LocalDate.now().minusYears(10);
LocalDate adultDob = LocalDate.now().minusYears(20);
assertTrue(relanceEmailService.isMineur(minorDob));
assertFalse(relanceEmailService.isMineur(adultDob));
assertFalse(relanceEmailService.isMineur(null));
}
@Test
void testSendRelancePreInscription_Mineur() {
PreInscription pre = new PreInscription();
pre.setId(1L);
pre.setNom("MARTIN");
pre.setPrenom("Lucas");
pre.setEmail("parent.martin@example.com");
pre.setDateNaissance(LocalDate.now().minusYears(12));
pre.setRepresentantLegal("Marc MARTIN");
Saison saison = new Saison();
saison.setNom("2026/2027");
pre.setSaison(saison);
boolean sent = relanceEmailService.sendRelancePreInscription(pre);
assertTrue(sent);
verify(mailSenderMock, timeout(2000).times(1)).send(any(MimeMessage.class));
}
@Test
void testSendRelancePreInscription_Majeur() {
PreInscription pre = new PreInscription();
pre.setId(2L);
pre.setNom("DUBOIS");
pre.setPrenom("Alexandre");
pre.setEmail("alex.dubois@example.com");
pre.setDateNaissance(LocalDate.now().minusYears(25));
Saison saison = new Saison();
saison.setNom("2026/2027");
pre.setSaison(saison);
boolean sent = relanceEmailService.sendRelancePreInscription(pre);
assertTrue(sent);
verify(mailSenderMock, timeout(2000).times(1)).send(any(MimeMessage.class));
}
@Test
void testSendRelancePreInscription_SansEmail() {
PreInscription pre = new PreInscription();
pre.setId(3L);
pre.setEmail(null);
boolean sent = relanceEmailService.sendRelancePreInscription(pre);
assertFalse(sent);
verify(mailSenderMock, never()).send(any(MimeMessage.class));
}
@Test
void testSendRelancePaiementCotisation_MineurAvecReste() {
Adherent adherent = new Adherent();
adherent.setId(10L);
adherent.setNom("GARCIA");
adherent.setPrenom("Leo");
adherent.setEmail("parent.garcia@example.com");
adherent.setDateNaissance(LocalDate.now().minusYears(14));
adherent.setRepresentantLegal("Sophie GARCIA");
Categorie cat = new Categorie();
cat.setNom("U15");
cat.setTarifBase(new BigDecimal("180.00"));
cat.setTarifExterieur(new BigDecimal("180.00"));
Saison saison = new Saison();
saison.setNom("2026/2027");
Licence licence = new Licence();
licence.setId(100L);
licence.setAdherent(adherent);
licence.setCategorie(cat);
licence.setSaison(saison);
boolean sent = relanceEmailService.sendRelancePaiementCotisation(licence);
assertTrue(sent);
verify(mailSenderMock, timeout(2000).times(1)).send(any(MimeMessage.class));
}
@Test
void testSendRelancePaiementCotisation_SoldeZero() {
Adherent adherent = new Adherent();
adherent.setId(11L);
adherent.setNom("ROUX");
adherent.setPrenom("Thomas");
adherent.setEmail("thomas.roux@example.com");
adherent.setDateNaissance(LocalDate.now().minusYears(22));
Categorie cat = new Categorie();
cat.setNom("Senior");
cat.setTarifBase(new BigDecimal("200.00"));
cat.setTarifExterieur(new BigDecimal("200.00"));
Licence licence = new Licence();
licence.setId(101L);
licence.setAdherent(adherent);
licence.setCategorie(cat);
// Simulation d'un paiement intégral
com.astalange.core.entity.Paiement p = new com.astalange.core.entity.Paiement();
p.setMontant(new BigDecimal("200.00"));
licence.addPaiement(p);
boolean sent = relanceEmailService.sendRelancePaiementCotisation(licence);
assertFalse(sent, "Aucune relance ne doit être envoyée si le reste à payer est égal à 0");
verify(mailSenderMock, never()).send(any(MimeMessage.class));
}
}
@@ -25,8 +25,9 @@ public class AdherentController {
private final SaisonRepository saisonRepository; private final SaisonRepository saisonRepository;
private final com.astalange.core.service.CategorieService categorieService; private final com.astalange.core.service.CategorieService categorieService;
private final com.astalange.core.service.SportEasyEmailService sportEasyEmailService; 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.adherentRepository = adherentRepository;
this.categorieRepository = categorieRepository; this.categorieRepository = categorieRepository;
this.licenceRepository = licenceRepository; this.licenceRepository = licenceRepository;
@@ -34,6 +35,7 @@ public class AdherentController {
this.saisonRepository = saisonRepository; this.saisonRepository = saisonRepository;
this.categorieService = categorieService; this.categorieService = categorieService;
this.sportEasyEmailService = sportEasyEmailService; this.sportEasyEmailService = sportEasyEmailService;
this.relanceEmailService = relanceEmailService;
} }
@org.springframework.web.bind.annotation.ModelAttribute("equipes") @org.springframework.web.bind.annotation.ModelAttribute("equipes")
@@ -382,4 +384,54 @@ public class AdherentController {
return "redirect:/adherents"; 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>";
}
}
} }
@@ -8,17 +8,23 @@ import org.springframework.stereotype.Controller;
import org.springframework.ui.Model; import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import com.astalange.core.entity.PreInscription;
import com.astalange.core.service.RelanceEmailService;
@Controller @Controller
@RequestMapping("/admin/pre-inscriptions") @RequestMapping("/admin/pre-inscriptions")
public class AdminPreInscriptionController { public class AdminPreInscriptionController {
private final PreInscriptionRepository preInscriptionRepository; private final PreInscriptionRepository preInscriptionRepository;
private final PreInscriptionService preInscriptionService; private final PreInscriptionService preInscriptionService;
private final RelanceEmailService relanceEmailService;
public AdminPreInscriptionController(PreInscriptionRepository preInscriptionRepository, public AdminPreInscriptionController(PreInscriptionRepository preInscriptionRepository,
PreInscriptionService preInscriptionService) { PreInscriptionService preInscriptionService,
RelanceEmailService relanceEmailService) {
this.preInscriptionRepository = preInscriptionRepository; this.preInscriptionRepository = preInscriptionRepository;
this.preInscriptionService = preInscriptionService; this.preInscriptionService = preInscriptionService;
this.relanceEmailService = relanceEmailService;
} }
@GetMapping @GetMapping
@@ -46,6 +52,20 @@ public class AdminPreInscriptionController {
return ""; // HTMX target la ligne avec outerHTML -> supprime la ligne 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") @GetMapping("/count")
@ResponseBody @ResponseBody
public String countBadge() { public String countBadge() {
@@ -63,6 +63,17 @@ public class EquipeController {
return "redirect:/equipes"; return "redirect:/equipes";
} }
@PostMapping("/equipes/{id}/update")
public String updateEquipe(@PathVariable Long id, @RequestParam String nom) {
Equipe equipe = equipeRepository.findById(id)
.orElseThrow(() -> new IllegalArgumentException("Équipe invalide : " + id));
if (nom != null && !nom.trim().isEmpty()) {
equipe.setNom(nom.trim());
equipeRepository.save(equipe);
}
return "redirect:/equipes";
}
@PostMapping("/equipes/{id}/delete") @PostMapping("/equipes/{id}/delete")
public String deleteEquipe(@PathVariable Long id) { public String deleteEquipe(@PathVariable Long id) {
Equipe equipe = equipeRepository.findById(id) Equipe equipe = equipeRepository.findById(id)
@@ -77,8 +77,13 @@ public class LicenceController {
licence.setTypeDemande(typeDemande); licence.setTypeDemande(typeDemande);
licence.setTypeLicence(typeLicence); licence.setTypeLicence(typeLicence);
licence.setCommentaire(commentaire); licence.setCommentaire(commentaire);
licence.setReductionEducateur(Boolean.TRUE.equals(reductionEducateur)); if (isUserAdmin()) {
licence.setPourcentageReductionEducateur(pourcentageReductionEducateur != null ? pourcentageReductionEducateur : 100); licence.setReductionEducateur(Boolean.TRUE.equals(reductionEducateur));
licence.setPourcentageReductionEducateur(pourcentageReductionEducateur != null ? pourcentageReductionEducateur : 100);
} else {
licence.setReductionEducateur(false);
licence.setPourcentageReductionEducateur(100);
}
if (equipeId != null) { if (equipeId != null) {
Equipe equipe = equipeRepository.findById(equipeId) Equipe equipe = equipeRepository.findById(equipeId)
@@ -120,8 +125,10 @@ public class LicenceController {
licence.setTypeDemande(typeDemande); licence.setTypeDemande(typeDemande);
licence.setTypeLicence(typeLicence); licence.setTypeLicence(typeLicence);
licence.setCommentaire(commentaire); licence.setCommentaire(commentaire);
licence.setReductionEducateur(Boolean.TRUE.equals(reductionEducateur)); if (isUserAdmin()) {
licence.setPourcentageReductionEducateur(pourcentageReductionEducateur != null ? pourcentageReductionEducateur : 100); licence.setReductionEducateur(Boolean.TRUE.equals(reductionEducateur));
licence.setPourcentageReductionEducateur(pourcentageReductionEducateur != null ? pourcentageReductionEducateur : 100);
}
if (equipeId != null) { if (equipeId != null) {
Equipe equipe = equipeRepository.findById(equipeId) Equipe equipe = equipeRepository.findById(equipeId)
@@ -270,4 +277,10 @@ public class LicenceController {
return cb.and(predicates.toArray(new jakarta.persistence.criteria.Predicate[0])); return cb.and(predicates.toArray(new jakarta.persistence.criteria.Predicate[0]));
}; };
} }
private boolean isUserAdmin() {
org.springframework.security.core.Authentication auth = org.springframework.security.core.context.SecurityContextHolder.getContext().getAuthentication();
return auth != null && auth.getAuthorities().stream()
.anyMatch(a -> a.getAuthority().equals("ROLE_ADMIN") || a.getAuthority().equals("ADMIN"));
}
} }
@@ -52,6 +52,7 @@ public class PaiementController {
@RequestParam @DateTimeFormat(iso = DateTimeFormat.ISO.DATE) LocalDate datePaiement, @RequestParam @DateTimeFormat(iso = DateTimeFormat.ISO.DATE) LocalDate datePaiement,
@RequestParam Long modePaiementId, @RequestParam Long modePaiementId,
@RequestParam(required = false) String numeroCheque, @RequestParam(required = false) String numeroCheque,
@RequestParam(required = false, defaultValue = "true") Boolean remis,
@RequestParam(required = false) String commentaire, @RequestParam(required = false) String commentaire,
Principal principal) { Principal principal) {
@@ -60,11 +61,12 @@ public class PaiementController {
ModePaiement mode = modePaiementRepository.findById(modePaiementId) ModePaiement mode = modePaiementRepository.findById(modePaiementId)
.orElseThrow(() -> new IllegalArgumentException("Invalid ModePaiement ID")); .orElseThrow(() -> new IllegalArgumentException("Invalid ModePaiement ID"));
log.info(">>> [PaiementController] Demande de création de paiement reçue pour Licence ID: {}, Adhérent ID: {}, Montant: {} €", id, adherentId, montant); log.info(">>> [PaiementController] Demande de création de paiement reçue pour Licence ID: {}, Adhérent ID: {}, Montant: {} €, Remis: {}", id, adherentId, montant, remis);
// Validation basique pour ne pas payer plus que le reste à payer // Validation pour ne pas dépasser le tarif global (tous paiements remis ou non inclus)
if (montant.compareTo(licence.getResteAPayer()) > 0) { BigDecimal maxAutorise = licence.getSoldeRestantEngage();
montant = licence.getResteAPayer(); if (montant.compareTo(maxAutorise) > 0) {
montant = maxAutorise;
} }
if (montant.compareTo(BigDecimal.ZERO) > 0) { if (montant.compareTo(BigDecimal.ZERO) > 0) {
@@ -75,6 +77,7 @@ public class PaiementController {
paiement.setDatePaiement(datePaiement); paiement.setDatePaiement(datePaiement);
paiement.setNumeroCheque(numeroCheque); paiement.setNumeroCheque(numeroCheque);
paiement.setCommentaire(commentaire); paiement.setCommentaire(commentaire);
paiement.setRemis(Boolean.TRUE.equals(remis));
if (principal != null) { if (principal != null) {
paiement.setGestionnaire(principal.getName()); paiement.setGestionnaire(principal.getName());
} }
@@ -88,7 +91,7 @@ public class PaiementController {
auditLog.setPaiementId(paiement.getId()); auditLog.setPaiementId(paiement.getId());
auditLog.setMontant(montant); auditLog.setMontant(montant);
auditLog.setAdherentNomComplet(licence.getAdherent().getNom() + " " + licence.getAdherent().getPrenom()); auditLog.setAdherentNomComplet(licence.getAdherent().getNom() + " " + licence.getAdherent().getPrenom());
auditLog.setDetails("Création d'un paiement de " + montant + "€ via " + mode.getNom() + " pour la licence " + (licence.getNumeroLicence() != null ? licence.getNumeroLicence() : "sans numéro")); auditLog.setDetails("Création d'un paiement de " + montant + "€ via " + mode.getNom() + " (Remis: " + (Boolean.TRUE.equals(remis) ? "Oui" : "Non") + ") pour la licence " + (licence.getNumeroLicence() != null ? licence.getNumeroLicence() : "sans numéro"));
auditLogPaiementRepository.save(auditLog); auditLogPaiementRepository.save(auditLog);
try { try {
@@ -109,6 +112,7 @@ public class PaiementController {
@RequestParam @DateTimeFormat(iso = DateTimeFormat.ISO.DATE) LocalDate datePaiement, @RequestParam @DateTimeFormat(iso = DateTimeFormat.ISO.DATE) LocalDate datePaiement,
@RequestParam Long modePaiementId, @RequestParam Long modePaiementId,
@RequestParam(required = false) String numeroCheque, @RequestParam(required = false) String numeroCheque,
@RequestParam(required = false, defaultValue = "true") Boolean remis,
@RequestParam(required = false) String commentaire, @RequestParam(required = false) String commentaire,
@RequestParam(required = false) String redirect, @RequestParam(required = false) String redirect,
Principal principal) { Principal principal) {
@@ -121,11 +125,12 @@ public class PaiementController {
BigDecimal ancienMontant = paiement.getMontant(); BigDecimal ancienMontant = paiement.getMontant();
String ancienMode = paiement.getModePaiement().getNom(); String ancienMode = paiement.getModePaiement().getNom();
Boolean ancienRemis = paiement.getRemis();
Licence licence = paiement.getLicence(); Licence licence = paiement.getLicence();
// Validation basique pour ne pas dépasser le montant total de la licence // Validation pour ne pas dépasser le tarif global (tous paiements remis ou non inclus)
BigDecimal maxAmount = licence.getResteAPayer().add(paiement.getMontant()); BigDecimal maxAmount = licence.getSoldeRestantEngage().add(paiement.getMontant());
if (montant.compareTo(maxAmount) > 0) { if (montant.compareTo(maxAmount) > 0) {
montant = maxAmount; montant = maxAmount;
} }
@@ -136,6 +141,7 @@ public class PaiementController {
paiement.setDatePaiement(datePaiement); paiement.setDatePaiement(datePaiement);
paiement.setNumeroCheque(numeroCheque); paiement.setNumeroCheque(numeroCheque);
paiement.setCommentaire(commentaire); paiement.setCommentaire(commentaire);
paiement.setRemis(Boolean.TRUE.equals(remis));
if (principal != null) { if (principal != null) {
paiement.setGestionnaire(principal.getName()); paiement.setGestionnaire(principal.getName());
} }
@@ -147,8 +153,18 @@ public class PaiementController {
auditLog.setPaiementId(paiement.getId()); auditLog.setPaiementId(paiement.getId());
auditLog.setMontant(montant); auditLog.setMontant(montant);
auditLog.setAdherentNomComplet(licence.getAdherent().getNom() + " " + licence.getAdherent().getPrenom()); auditLog.setAdherentNomComplet(licence.getAdherent().getNom() + " " + licence.getAdherent().getPrenom());
auditLog.setDetails("Modification du paiement: montant " + ancienMontant + "€ -> " + montant + "€, mode " + ancienMode + " -> " + mode.getNom()); auditLog.setDetails("Modification du paiement: montant " + ancienMontant + "€ -> " + montant + "€, mode " + ancienMode + " -> " + mode.getNom() + ", remis -> " + (Boolean.TRUE.equals(remis) ? "Oui" : "Non"));
auditLogPaiementRepository.save(auditLog); auditLogPaiementRepository.save(auditLog);
// Si le paiement passe de non remis (ex: Chèque Sport mairie) à remis (Oui), envoyer l'email de confirmation
if (Boolean.FALSE.equals(ancienRemis) && Boolean.TRUE.equals(remis)) {
try {
log.info("Appel de sendPaiementConfirmation depuis updatePaiement (passage de remis=false à remis=true) pour le paiement ID: {}", paiement.getId());
paiementEmailService.sendPaiementConfirmation(paiement);
} catch (Exception e) {
log.error("Erreur lors de l'envoi de l'e-mail de confirmation après la remise du paiement ID {}: ", id, e);
}
}
} }
if (redirect != null && !redirect.isEmpty()) { if (redirect != null && !redirect.isEmpty()) {
@@ -135,6 +135,20 @@ public class PublicInscriptionController {
return "redirect:/inscription-public/demarrer"; return "redirect:/inscription-public/demarrer";
} }
// Nettoyage défensif des champs non applicables
if ("RENOUVELLEMENT".equals(preInscription.getTypeDemande())) {
preInscription.setAncienClub(null);
preInscription.setRaisonChangementClub(null);
preInscription.setAncienneCategorie(null);
preInscription.setCommentConnuClub(null);
}
if (preInscription.getDateNaissance() != null) {
int age = java.time.Period.between(preInscription.getDateNaissance(), java.time.LocalDate.now()).getYears();
if (age >= 18) {
preInscription.setRepresentantLegal(null);
}
}
// Sauvegarde de la pré-inscription // Sauvegarde de la pré-inscription
preInscription.setSaison(activeSaison); preInscription.setSaison(activeSaison);
preInscription.setStatutTraite(false); preInscription.setStatutTraite(false);
@@ -10,6 +10,8 @@
body { font-family: 'Inter', sans-serif; } body { font-family: 'Inter', sans-serif; }
.hidden-block { display: none; } .hidden-block { display: none; }
</style> </style>
<meta name="_csrf" th:content="${_csrf.token}"/>
<meta name="_csrf_header" th:content="${_csrf.headerName}"/>
</head> </head>
<body class="bg-gray-50 text-gray-900 flex h-screen overflow-hidden"> <body class="bg-gray-50 text-gray-900 flex h-screen overflow-hidden">
@@ -271,15 +273,20 @@
th:text="${lic.etat}">Brouillon</span> th:text="${lic.etat}">Brouillon</span>
</td> </td>
<td class="py-4 px-4 font-medium cell-tarif-global"> <td class="py-4 px-4 font-medium cell-tarif-global">
<div th:if="${lic.reductionEducateur}" class="flex flex-col"> <div sec:authorize="hasRole('ROLE_ADMIN')">
<span class="text-[10px] font-bold text-amber-700 bg-amber-50 border border-amber-200 px-2 py-0.5 rounded-full inline-block w-max mb-0.5" <div th:if="${lic.reductionEducateur}" class="flex flex-col">
th:text="'Éducateur (-' + ${lic.pourcentageReductionEducateur != null ? lic.pourcentageReductionEducateur : 100} + '%)'">Éducateur (-100%)</span> <span class="text-[10px] font-bold text-amber-700 bg-amber-50 border border-amber-200 px-2 py-0.5 rounded-full inline-block w-max mb-0.5"
<div class="flex items-center space-x-1 text-xs"> th:text="'Éducateur (-' + ${lic.pourcentageReductionEducateur != null ? lic.pourcentageReductionEducateur : 100} + '%)'">Éducateur (-100%)</span>
<span th:if="${lic.getPrixBrut().compareTo(lic.getPrixTotal()) != 0}" class="line-through text-gray-400" th:text="${lic.getPrixBrut() + ' €'}">150.00 €</span> <div class="flex items-center space-x-1 text-xs">
<span class="text-gray-900 font-bold" th:text="${lic.getPrixTotal() + ' €'}">0.00 €</span> <span th:if="${lic.getPrixBrut().compareTo(lic.getPrixTotal()) != 0}" class="line-through text-gray-400" th:text="${lic.getPrixBrut() + ' €'}">150.00 €</span>
<span class="text-gray-900 font-bold" th:text="${lic.getPrixTotal() + ' €'}">0.00 €</span>
</div>
</div>
<div th:if="${!lic.reductionEducateur}">
<span class="text-gray-900" th:text="${lic.getPrixTotal() + ' €'}">130.00 €</span>
</div> </div>
</div> </div>
<div th:if="${!lic.reductionEducateur}"> <div sec:authorize="!hasRole('ROLE_ADMIN')">
<span class="text-gray-900" th:text="${lic.getPrixTotal() + ' €'}">130.00 €</span> <span class="text-gray-900" th:text="${lic.getPrixTotal() + ' €'}">130.00 €</span>
</div> </div>
</td> </td>
@@ -300,12 +307,21 @@
th:data-pourcentage-reduction="${lic.pourcentageReductionEducateur != null ? lic.pourcentageReductionEducateur : 100}" th:data-pourcentage-reduction="${lic.pourcentageReductionEducateur != null ? lic.pourcentageReductionEducateur : 100}"
onclick="openLicenceModal(this.getAttribute('data-licence-id'), this.getAttribute('data-categorie-id'), this.getAttribute('data-numero-licence'), this.getAttribute('data-etat'), this.getAttribute('data-type-demande'), this.getAttribute('data-type-licence'), this.getAttribute('data-equipe-id'), this.getAttribute('data-commentaire'), this.getAttribute('data-reduction-educateur'), this.getAttribute('data-pourcentage-reduction'))" onclick="openLicenceModal(this.getAttribute('data-licence-id'), this.getAttribute('data-categorie-id'), this.getAttribute('data-numero-licence'), this.getAttribute('data-etat'), this.getAttribute('data-type-demande'), this.getAttribute('data-type-licence'), this.getAttribute('data-equipe-id'), this.getAttribute('data-commentaire'), this.getAttribute('data-reduction-educateur'), this.getAttribute('data-pourcentage-reduction'))"
class="text-blue-600 hover:text-blue-800 font-medium bg-blue-50 px-3 py-1 rounded-lg">Modifier</button> class="text-blue-600 hover:text-blue-800 font-medium bg-blue-50 px-3 py-1 rounded-lg">Modifier</button>
<button th:if="${lic.getResteAPayer().compareTo(T(java.math.BigDecimal).ZERO) > 0}" <button th:if="${lic.getSoldeRestantEngage().compareTo(T(java.math.BigDecimal).ZERO) > 0}"
type="button" type="button"
th:data-licence-id="${lic.id}" th:data-licence-id="${lic.id}"
th:data-reste-a-payer="${lic.getResteAPayer()}" th:data-solde-restant="${lic.getSoldeRestantEngage()}"
onclick="openPaiementModal(this.getAttribute('data-licence-id'), this.getAttribute('data-reste-a-payer'))" onclick="openPaiementModal(this.getAttribute('data-licence-id'), this.getAttribute('data-solde-restant'))"
class="text-green-600 hover:text-green-800 font-medium bg-green-50 px-3 py-1 rounded-lg btn-payer">Payer</button> 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> </td>
</tr> </tr>
<tr th:if="${!#lists.isEmpty(lic.paiements)}" class="bg-gray-50/50"> <tr th:if="${!#lists.isEmpty(lic.paiements)}" class="bg-gray-50/50">
@@ -328,6 +344,7 @@
<td class="py-2 px-3 text-gray-600 font-medium" th:text="${#temporals.format(paiement.datePaiement, 'dd/MM/yyyy')}">01/01/2026</td> <td class="py-2 px-3 text-gray-600 font-medium" th:text="${#temporals.format(paiement.datePaiement, 'dd/MM/yyyy')}">01/01/2026</td>
<td class="py-2 px-3 text-gray-600"> <td class="py-2 px-3 text-gray-600">
<span class="px-2 py-0.5 rounded bg-gray-100 text-gray-700 font-mono text-[10px]" th:text="${paiement.modePaiement.nom}">Chèque</span> <span class="px-2 py-0.5 rounded bg-gray-100 text-gray-700 font-mono text-[10px]" th:text="${paiement.modePaiement.nom}">Chèque</span>
<span th:if="${paiement.remis == false}" class="px-1.5 py-0.5 rounded bg-amber-100 text-amber-800 text-[10px] font-semibold ml-1" title="Montant non encore déduit du solde">Non remis</span>
</td> </td>
<td class="py-2 px-3 text-gray-500 text-xs"> <td class="py-2 px-3 text-gray-500 text-xs">
<div th:if="${paiement.numeroCheque != null and !paiement.numeroCheque.isEmpty()}" class="text-[10px]"> <div th:if="${paiement.numeroCheque != null and !paiement.numeroCheque.isEmpty()}" class="text-[10px]">
@@ -355,10 +372,11 @@
th:data-date="${paiement.datePaiement}" th:data-date="${paiement.datePaiement}"
th:data-mode-id="${paiement.modePaiement.id}" th:data-mode-id="${paiement.modePaiement.id}"
th:data-licence-id="${lic.id}" th:data-licence-id="${lic.id}"
th:data-max-amount="${lic.getResteAPayer().add(paiement.montant)}" th:data-max-amount="${lic.getSoldeRestantEngage().add(paiement.montant)}"
th:data-cheque="${paiement.numeroCheque}" th:data-cheque="${paiement.numeroCheque}"
th:data-commentaire="${paiement.commentaire}" th:data-commentaire="${paiement.commentaire}"
onclick="openEditPaiementModal(this.getAttribute('data-paiement-id'), this.getAttribute('data-montant'), this.getAttribute('data-date'), this.getAttribute('data-mode-id'), this.getAttribute('data-licence-id'), this.getAttribute('data-max-amount'), this.getAttribute('data-cheque'), this.getAttribute('data-commentaire'))" th:data-remis="${paiement.remis}"
onclick="openEditPaiementModal(this.getAttribute('data-paiement-id'), this.getAttribute('data-montant'), this.getAttribute('data-date'), this.getAttribute('data-mode-id'), this.getAttribute('data-licence-id'), this.getAttribute('data-max-amount'), this.getAttribute('data-cheque'), this.getAttribute('data-commentaire'), this.getAttribute('data-remis'))"
class="text-blue-600 hover:text-blue-900 bg-blue-50 hover:bg-blue-100 p-1.5 rounded transition-colors inline-flex items-center" class="text-blue-600 hover:text-blue-900 bg-blue-50 hover:bg-blue-100 p-1.5 rounded transition-colors inline-flex items-center"
title="Modifier"> title="Modifier">
<svg class="w-3.5 h-3.5" fill="none" stroke="currentColor" viewBox="0 0 24 24"> <svg class="w-3.5 h-3.5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
@@ -568,7 +586,7 @@
<label class="block text-sm font-medium text-gray-700 mb-1">Commentaire</label> <label class="block text-sm font-medium text-gray-700 mb-1">Commentaire</label>
<textarea id="licenceCommentaireInput" name="commentaire" rows="3" class="w-full border border-gray-300 rounded-lg px-4 py-2 text-sm focus:ring-2 focus:ring-blue-500 outline-none" placeholder="Commentaire optionnel..."></textarea> <textarea id="licenceCommentaireInput" name="commentaire" rows="3" class="w-full border border-gray-300 rounded-lg px-4 py-2 text-sm focus:ring-2 focus:ring-blue-500 outline-none" placeholder="Commentaire optionnel..."></textarea>
</div> </div>
<div class="bg-amber-50 p-3 rounded-lg border border-amber-200"> <div sec:authorize="hasRole('ROLE_ADMIN')" class="bg-amber-50 p-3 rounded-lg border border-amber-200">
<label class="flex items-center space-x-2 cursor-pointer select-none"> <label class="flex items-center space-x-2 cursor-pointer select-none">
<input type="checkbox" id="reductionEducateurInput" name="reductionEducateur" value="true" onchange="toggleReductionPourcentageVisibility()" class="w-4 h-4 text-amber-600 border-gray-300 rounded focus:ring-amber-500"> <input type="checkbox" id="reductionEducateurInput" name="reductionEducateur" value="true" onchange="toggleReductionPourcentageVisibility()" class="w-4 h-4 text-amber-600 border-gray-300 rounded focus:ring-amber-500">
<span class="text-sm font-semibold text-amber-900">Enfant d'éducateur / Réduction</span> <span class="text-sm font-semibold text-amber-900">Enfant d'éducateur / Réduction</span>
@@ -608,7 +626,7 @@
</div> </div>
<div> <div>
<label class="block text-sm font-medium text-gray-700 mb-1">Mode de paiement</label> <label class="block text-sm font-medium text-gray-700 mb-1">Mode de paiement</label>
<select id="addPaiementMode" name="modePaiementId" required class="w-full border border-gray-300 rounded-lg px-4 py-2 text-sm focus:ring-2 focus:ring-blue-500 outline-none" onchange="toggleChequeVisibility(this, 'addChequeBlock', 'addNumeroCheque')"> <select id="addPaiementMode" name="modePaiementId" required class="w-full border border-gray-300 rounded-lg px-4 py-2 text-sm focus:ring-2 focus:ring-blue-500 outline-none" onchange="toggleChequeVisibility(this, 'addChequeBlock', 'addNumeroCheque', 'addRemisBlock', 'addRemisOui', 'addRemisNon')">
<option value="">Sélectionnez un mode...</option> <option value="">Sélectionnez un mode...</option>
<option th:each="mode : ${modesPaiement}" th:value="${mode.id}" th:data-nom="${#strings.toLowerCase(mode.nom)}" th:text="${mode.nom}"></option> <option th:each="mode : ${modesPaiement}" th:value="${mode.id}" th:data-nom="${#strings.toLowerCase(mode.nom)}" th:text="${mode.nom}"></option>
</select> </select>
@@ -617,6 +635,20 @@
<label class="block text-sm font-medium text-gray-700 mb-1">Numéro du chèque <span class="text-red-500">*</span></label> <label class="block text-sm font-medium text-gray-700 mb-1">Numéro du chèque <span class="text-red-500">*</span></label>
<input type="text" id="addNumeroCheque" name="numeroCheque" class="w-full border border-gray-300 rounded-lg px-4 py-2 text-sm focus:ring-2 focus:ring-blue-500 outline-none"> <input type="text" id="addNumeroCheque" name="numeroCheque" class="w-full border border-gray-300 rounded-lg px-4 py-2 text-sm focus:ring-2 focus:ring-blue-500 outline-none">
</div> </div>
<div id="addRemisBlock" class="hidden bg-amber-50 p-3 rounded-lg border border-amber-200">
<label class="block text-xs font-semibold text-amber-900 mb-1.5">Remis / Encaissé ?</label>
<div class="flex items-center space-x-6">
<label class="flex items-center space-x-1.5 cursor-pointer text-sm text-gray-700">
<input type="radio" id="addRemisOui" name="remis" value="true" class="w-4 h-4 text-blue-600 border-gray-300 focus:ring-blue-500">
<span>Oui</span>
</label>
<label class="flex items-center space-x-1.5 cursor-pointer text-sm text-gray-700">
<input type="radio" id="addRemisNon" name="remis" value="false" checked class="w-4 h-4 text-blue-600 border-gray-300 focus:ring-blue-500">
<span>Non</span>
</label>
</div>
<p class="text-[11px] text-amber-700 mt-1">Si "Non", cette somme reste à payer.</p>
</div>
<div> <div>
<label class="block text-sm font-medium text-gray-700 mb-1">Commentaire (facultatif)</label> <label class="block text-sm font-medium text-gray-700 mb-1">Commentaire (facultatif)</label>
<textarea id="addCommentaire" name="commentaire" rows="2" class="w-full border border-gray-300 rounded-lg px-4 py-2 text-sm focus:ring-2 focus:ring-blue-500 outline-none"></textarea> <textarea id="addCommentaire" name="commentaire" rows="2" class="w-full border border-gray-300 rounded-lg px-4 py-2 text-sm focus:ring-2 focus:ring-blue-500 outline-none"></textarea>
@@ -648,7 +680,7 @@
</div> </div>
<div> <div>
<label class="block text-sm font-medium text-gray-700 mb-1">Mode de paiement</label> <label class="block text-sm font-medium text-gray-700 mb-1">Mode de paiement</label>
<select id="editPaiementMode" name="modePaiementId" required class="w-full border border-gray-300 rounded-lg px-4 py-2 text-sm focus:ring-2 focus:ring-blue-500 outline-none" onchange="toggleChequeVisibility(this, 'editChequeBlock', 'editNumeroCheque')"> <select id="editPaiementMode" name="modePaiementId" required class="w-full border border-gray-300 rounded-lg px-4 py-2 text-sm focus:ring-2 focus:ring-blue-500 outline-none" onchange="toggleChequeVisibility(this, 'editChequeBlock', 'editNumeroCheque', 'editRemisBlock', 'editRemisOui', 'editRemisNon', true)">
<option value="">Sélectionnez un mode...</option> <option value="">Sélectionnez un mode...</option>
<option th:each="mode : ${modesPaiement}" th:value="${mode.id}" th:data-nom="${#strings.toLowerCase(mode.nom)}" th:text="${mode.nom}"></option> <option th:each="mode : ${modesPaiement}" th:value="${mode.id}" th:data-nom="${#strings.toLowerCase(mode.nom)}" th:text="${mode.nom}"></option>
</select> </select>
@@ -657,6 +689,20 @@
<label class="block text-sm font-medium text-gray-700 mb-1">Numéro du chèque <span class="text-red-500">*</span></label> <label class="block text-sm font-medium text-gray-700 mb-1">Numéro du chèque <span class="text-red-500">*</span></label>
<input type="text" id="editNumeroCheque" name="numeroCheque" class="w-full border border-gray-300 rounded-lg px-4 py-2 text-sm focus:ring-2 focus:ring-blue-500 outline-none"> <input type="text" id="editNumeroCheque" name="numeroCheque" class="w-full border border-gray-300 rounded-lg px-4 py-2 text-sm focus:ring-2 focus:ring-blue-500 outline-none">
</div> </div>
<div id="editRemisBlock" class="hidden bg-amber-50 p-3 rounded-lg border border-amber-200">
<label class="block text-xs font-semibold text-amber-900 mb-1.5">Remis / Encaissé ?</label>
<div class="flex items-center space-x-6">
<label class="flex items-center space-x-1.5 cursor-pointer text-sm text-gray-700">
<input type="radio" id="editRemisOui" name="remis" value="true" class="w-4 h-4 text-blue-600 border-gray-300 focus:ring-blue-500">
<span>Oui</span>
</label>
<label class="flex items-center space-x-1.5 cursor-pointer text-sm text-gray-700">
<input type="radio" id="editRemisNon" name="remis" value="false" class="w-4 h-4 text-blue-600 border-gray-300 focus:ring-blue-500">
<span>Non</span>
</label>
</div>
<p class="text-[11px] text-amber-700 mt-1">Si "Non", cette somme reste à payer.</p>
</div>
<div> <div>
<label class="block text-sm font-medium text-gray-700 mb-1">Commentaire (facultatif)</label> <label class="block text-sm font-medium text-gray-700 mb-1">Commentaire (facultatif)</label>
<textarea id="editCommentaire" name="commentaire" rows="2" class="w-full border border-gray-300 rounded-lg px-4 py-2 text-sm focus:ring-2 focus:ring-blue-500 outline-none"></textarea> <textarea id="editCommentaire" name="commentaire" rows="2" class="w-full border border-gray-300 rounded-lg px-4 py-2 text-sm focus:ring-2 focus:ring-blue-500 outline-none"></textarea>
@@ -800,12 +846,15 @@
document.getElementById('paiementMontant').value = maxAmount; document.getElementById('paiementMontant').value = maxAmount;
document.getElementById('paiementMontant').max = maxAmount; document.getElementById('paiementMontant').max = maxAmount;
document.getElementById('paiementDate').valueAsDate = new Date(); document.getElementById('paiementDate').valueAsDate = new Date();
document.getElementById('addPaiementMode').value = '';
document.getElementById('addRemisNon').checked = true;
toggleChequeVisibility(document.getElementById('addPaiementMode'), 'addChequeBlock', 'addNumeroCheque', 'addRemisBlock', 'addRemisOui', 'addRemisNon');
} }
function closePaiementModal() { function closePaiementModal() {
document.getElementById('paiementModal').classList.add('hidden'); document.getElementById('paiementModal').classList.add('hidden');
} }
function openEditPaiementModal(paiementId, montant, date, modePaiementId, licenceId, maxAmount, numeroCheque, commentaire) { function openEditPaiementModal(paiementId, montant, date, modePaiementId, licenceId, maxAmount, numeroCheque, commentaire, remis) {
document.getElementById('editPaiementModal').classList.remove('hidden'); document.getElementById('editPaiementModal').classList.remove('hidden');
document.getElementById('editPaiementForm').action = '/paiements/' + paiementId + '/update'; document.getElementById('editPaiementForm').action = '/paiements/' + paiementId + '/update';
document.getElementById('editPaiementMontant').value = montant; document.getElementById('editPaiementMontant').value = montant;
@@ -814,18 +863,34 @@
document.getElementById('editPaiementMode').value = modePaiementId; document.getElementById('editPaiementMode').value = modePaiementId;
document.getElementById('editNumeroCheque').value = numeroCheque || ''; document.getElementById('editNumeroCheque').value = numeroCheque || '';
document.getElementById('editCommentaire').value = commentaire || ''; document.getElementById('editCommentaire').value = commentaire || '';
toggleChequeVisibility(document.getElementById('editPaiementMode'), 'editChequeBlock', 'editNumeroCheque');
const isRemis = (remis === true || remis === 'true' || remis === null || remis === '');
if (isRemis) {
document.getElementById('editRemisOui').checked = true;
} else {
document.getElementById('editRemisNon').checked = true;
}
toggleChequeVisibility(document.getElementById('editPaiementMode'), 'editChequeBlock', 'editNumeroCheque', 'editRemisBlock', 'editRemisOui', 'editRemisNon', true);
} }
function closeEditPaiementModal() { function closeEditPaiementModal() {
document.getElementById('editPaiementModal').classList.add('hidden'); document.getElementById('editPaiementModal').classList.add('hidden');
} }
function toggleChequeVisibility(selectElement, blockId, inputId) { function toggleChequeVisibility(selectElement, blockId, inputId, remisBlockId, remisOuiId, remisNonId, isEdit = false) {
const block = document.getElementById(blockId); const block = document.getElementById(blockId);
const input = document.getElementById(inputId); const input = document.getElementById(inputId);
const selectedOption = selectElement.options[selectElement.selectedIndex]; const remisBlock = remisBlockId ? document.getElementById(remisBlockId) : null;
const remisOui = remisOuiId ? document.getElementById(remisOuiId) : null;
const remisNon = remisNonId ? document.getElementById(remisNonId) : null;
if (selectedOption && selectedOption.getAttribute('data-nom') && selectedOption.getAttribute('data-nom').includes('chèque')) { const selectedOption = selectElement.options[selectElement.selectedIndex];
const dataNom = selectedOption ? (selectedOption.getAttribute('data-nom') || selectedOption.textContent || '').toLowerCase().trim() : '';
const isChequeSportMairie = dataNom.includes('mairie') || dataNom.includes('chèque sport') || dataNom.includes('cheque sport');
const isStandardCheque = dataNom.includes('chèque') && !isChequeSportMairie;
if (isStandardCheque) {
block.classList.remove('hidden'); block.classList.remove('hidden');
input.required = true; input.required = true;
} else { } else {
@@ -833,6 +898,14 @@
input.required = false; input.required = false;
input.value = ''; input.value = '';
} }
if (isChequeSportMairie) {
if (remisBlock) remisBlock.classList.remove('hidden');
if (!isEdit && remisNon) remisNon.checked = true;
} else {
if (remisBlock) remisBlock.classList.add('hidden');
if (remisOui) remisOui.checked = true;
}
} }
document.addEventListener("DOMContentLoaded", function() { document.addEventListener("DOMContentLoaded", function() {
const dateInput = document.getElementById('dateNaissance'); const dateInput = document.getElementById('dateNaissance');
@@ -1081,6 +1154,14 @@
if (typeMaillotSelect) { if (typeMaillotSelect) {
typeMaillotSelect.addEventListener('change', updateEquipmentStyleLabels); 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> </script>
</body> </body>
@@ -9,6 +9,8 @@
<style> <style>
body { font-family: 'Inter', sans-serif; } body { font-family: 'Inter', sans-serif; }
</style> </style>
<meta name="_csrf" th:content="${_csrf.token}"/>
<meta name="_csrf_header" th:content="${_csrf.headerName}"/>
</head> </head>
<body class="bg-gray-50 text-gray-900 flex h-screen overflow-hidden"> <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> <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>
</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> </div>
</td> </td>
<!-- SportEasy Status Column --> <!-- SportEasy Status Column -->
@@ -415,6 +427,14 @@
closeAllEquipementPopovers(); 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> </script>
</body> </body>
</html> </html>
@@ -89,6 +89,7 @@
<td class="py-4 px-6 text-gray-600"> <td class="py-4 px-6 text-gray-600">
<span class="px-2 py-0.5 rounded border border-gray-200 bg-gray-50 text-gray-700 text-xs" <span class="px-2 py-0.5 rounded border border-gray-200 bg-gray-50 text-gray-700 text-xs"
th:text="${p.modePaiement.nom}">Chèque</span> th:text="${p.modePaiement.nom}">Chèque</span>
<span th:if="${p.remis == false}" class="px-1.5 py-0.5 rounded bg-amber-100 text-amber-800 text-xs font-semibold ml-1">Non remis</span>
</td> </td>
<td class="py-4 px-6 text-right font-semibold text-green-600" th:text="${p.montant + ' €'}">50.00 €</td> <td class="py-4 px-6 text-right font-semibold text-green-600" th:text="${p.montant + ' €'}">50.00 €</td>
<td class="py-4 px-6 text-right pr-6"> <td class="py-4 px-6 text-right pr-6">
@@ -108,8 +109,10 @@
th:data-date="${p.datePaiement}" th:data-date="${p.datePaiement}"
th:data-mode-id="${p.modePaiement.id}" th:data-mode-id="${p.modePaiement.id}"
th:data-licence-id="${p.licence.id}" th:data-licence-id="${p.licence.id}"
th:data-max-amount="${p.licence.getResteAPayer().add(p.montant)}" th:data-max-amount="${p.licence.getSoldeRestantEngage().add(p.montant)}"
onclick="openEditPaiementModal(this.getAttribute('data-paiement-id'), this.getAttribute('data-montant'), this.getAttribute('data-date'), this.getAttribute('data-mode-id'), this.getAttribute('data-licence-id'), this.getAttribute('data-max-amount'))" th:data-cheque="${p.numeroCheque}"
th:data-remis="${p.remis}"
onclick="openEditPaiementModal(this.getAttribute('data-paiement-id'), this.getAttribute('data-montant'), this.getAttribute('data-date'), this.getAttribute('data-mode-id'), this.getAttribute('data-licence-id'), this.getAttribute('data-max-amount'), this.getAttribute('data-cheque'), this.getAttribute('data-remis'))"
class="text-blue-600 hover:text-blue-900 bg-blue-50 hover:bg-blue-100 p-1.5 rounded transition-colors inline-flex items-center" class="text-blue-600 hover:text-blue-900 bg-blue-50 hover:bg-blue-100 p-1.5 rounded transition-colors inline-flex items-center"
title="Modifier"> title="Modifier">
<svg class="w-3.5 h-3.5" fill="none" stroke="currentColor" viewBox="0 0 24 24"> <svg class="w-3.5 h-3.5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
@@ -212,11 +215,29 @@
</div> </div>
<div> <div>
<label class="block text-sm font-medium text-gray-700 mb-1">Mode de paiement</label> <label class="block text-sm font-medium text-gray-700 mb-1">Mode de paiement</label>
<select id="editPaiementMode" name="modePaiementId" required class="w-full border border-gray-300 rounded-lg px-4 py-2 text-sm focus:ring-2 focus:ring-blue-500 outline-none"> <select id="editPaiementMode" name="modePaiementId" required class="w-full border border-gray-300 rounded-lg px-4 py-2 text-sm focus:ring-2 focus:ring-blue-500 outline-none" onchange="toggleChequeVisibility(this, 'editChequeBlock', 'editNumeroCheque', 'editRemisBlock', 'editRemisOui', 'editRemisNon', true)">
<option value="">Sélectionnez un mode...</option> <option value="">Sélectionnez un mode...</option>
<option th:each="mode : ${modesPaiement}" th:value="${mode.id}" th:text="${mode.nom}"></option> <option th:each="mode : ${modesPaiement}" th:value="${mode.id}" th:data-nom="${#strings.toLowerCase(mode.nom)}" th:text="${mode.nom}"></option>
</select> </select>
</div> </div>
<div id="editChequeBlock" class="hidden">
<label class="block text-sm font-medium text-gray-700 mb-1">Numéro du chèque <span class="text-red-500">*</span></label>
<input type="text" id="editNumeroCheque" name="numeroCheque" class="w-full border border-gray-300 rounded-lg px-4 py-2 text-sm focus:ring-2 focus:ring-blue-500 outline-none">
</div>
<div id="editRemisBlock" class="hidden bg-amber-50 p-3 rounded-lg border border-amber-200">
<label class="block text-xs font-semibold text-amber-900 mb-1.5">Remis / Encaissé ?</label>
<div class="flex items-center space-x-6">
<label class="flex items-center space-x-1.5 cursor-pointer text-sm text-gray-700">
<input type="radio" id="editRemisOui" name="remis" value="true" class="w-4 h-4 text-blue-600 border-gray-300 focus:ring-blue-500">
<span>Oui</span>
</label>
<label class="flex items-center space-x-1.5 cursor-pointer text-sm text-gray-700">
<input type="radio" id="editRemisNon" name="remis" value="false" class="w-4 h-4 text-blue-600 border-gray-300 focus:ring-blue-500">
<span>Non</span>
</label>
</div>
<p class="text-[11px] text-amber-700 mt-1">Si "Non", cette somme reste à payer.</p>
</div>
<div class="items-center px-4 py-3 flex justify-end space-x-2"> <div class="items-center px-4 py-3 flex justify-end space-x-2">
<button type="button" onclick="closeEditPaiementModal()" class="px-4 py-2 text-sm font-medium text-gray-700 bg-white border border-gray-300 rounded-lg hover:bg-gray-50">Annuler</button> <button type="button" onclick="closeEditPaiementModal()" class="px-4 py-2 text-sm font-medium text-gray-700 bg-white border border-gray-300 rounded-lg hover:bg-gray-50">Annuler</button>
<button type="submit" class="px-4 py-2 text-sm font-medium text-white bg-blue-600 rounded-lg hover:bg-blue-700">Enregistrer</button> <button type="submit" class="px-4 py-2 text-sm font-medium text-white bg-blue-600 rounded-lg hover:bg-blue-700">Enregistrer</button>
@@ -227,17 +248,58 @@
</div> </div>
<script> <script>
function openEditPaiementModal(paiementId, montant, date, modePaiementId, licenceId, maxAmount) { function openEditPaiementModal(paiementId, montant, date, modePaiementId, licenceId, maxAmount, numeroCheque, remis) {
document.getElementById('editPaiementModal').classList.remove('hidden'); document.getElementById('editPaiementModal').classList.remove('hidden');
document.getElementById('editPaiementForm').action = '/paiements/' + paiementId + '/update'; document.getElementById('editPaiementForm').action = '/paiements/' + paiementId + '/update';
document.getElementById('editPaiementMontant').value = montant; document.getElementById('editPaiementMontant').value = montant;
document.getElementById('editPaiementMontant').max = maxAmount; document.getElementById('editPaiementMontant').max = maxAmount;
document.getElementById('editPaiementDate').value = date; document.getElementById('editPaiementDate').value = date;
document.getElementById('editPaiementMode').value = modePaiementId; document.getElementById('editPaiementMode').value = modePaiementId;
document.getElementById('editNumeroCheque').value = numeroCheque || '';
const isRemis = (remis === true || remis === 'true' || remis === null || remis === '');
if (isRemis) {
document.getElementById('editRemisOui').checked = true;
} else {
document.getElementById('editRemisNon').checked = true;
}
toggleChequeVisibility(document.getElementById('editPaiementMode'), 'editChequeBlock', 'editNumeroCheque', 'editRemisBlock', 'editRemisOui', 'editRemisNon', true);
} }
function closeEditPaiementModal() { function closeEditPaiementModal() {
document.getElementById('editPaiementModal').classList.add('hidden'); document.getElementById('editPaiementModal').classList.add('hidden');
} }
function toggleChequeVisibility(selectElement, blockId, inputId, remisBlockId, remisOuiId, remisNonId, isEdit = false) {
const block = document.getElementById(blockId);
const input = document.getElementById(inputId);
const remisBlock = remisBlockId ? document.getElementById(remisBlockId) : null;
const remisOui = remisOuiId ? document.getElementById(remisOuiId) : null;
const remisNon = remisNonId ? document.getElementById(remisNonId) : null;
const selectedOption = selectElement.options[selectElement.selectedIndex];
const dataNom = selectedOption ? (selectedOption.getAttribute('data-nom') || selectedOption.textContent || '').toLowerCase().trim() : '';
const isChequeSportMairie = dataNom.includes('mairie') || dataNom.includes('chèque sport') || dataNom.includes('cheque sport');
const isStandardCheque = dataNom.includes('chèque') && !isChequeSportMairie;
if (isStandardCheque) {
block.classList.remove('hidden');
input.required = true;
} else {
block.classList.add('hidden');
input.required = false;
input.value = '';
}
if (isChequeSportMairie) {
if (remisBlock) remisBlock.classList.remove('hidden');
if (!isEdit && remisNon) remisNon.checked = true;
} else {
if (remisBlock) remisBlock.classList.add('hidden');
if (remisOui) remisOui.checked = true;
}
}
</script> </script>
</body> </body>
</html> </html>
@@ -31,16 +31,27 @@
<thead> <thead>
<tr class="bg-gray-50 text-gray-500 text-sm uppercase tracking-wider border-b border-gray-200"> <tr class="bg-gray-50 text-gray-500 text-sm uppercase tracking-wider border-b border-gray-200">
<th class="py-3 px-6 font-medium text-left">Nom de l'équipement</th> <th class="py-3 px-6 font-medium text-left">Nom de l'équipement</th>
<th class="py-3 px-6 font-medium text-left">Référence</th>
<th class="py-3 px-6 font-medium text-left">Description</th> <th class="py-3 px-6 font-medium text-left">Description</th>
<th class="py-3 px-6 font-medium text-right">Actions</th> <th class="py-3 px-6 font-medium text-right">Actions</th>
</tr> </tr>
</thead> </thead>
<tbody class="divide-y divide-gray-200 text-sm"> <tbody class="divide-y divide-gray-200 text-sm">
<tr th:if="${#lists.isEmpty(equipements)}"> <tr th:if="${#lists.isEmpty(equipements)}">
<td colspan="3" class="py-8 text-center text-gray-500">Aucun équipement n'est paramétré.</td> <td colspan="4" class="py-8 text-center text-gray-500">Aucun équipement n'est paramétré.</td>
</tr> </tr>
<tr th:each="equip : ${equipements}" class="hover:bg-gray-50 transition-colors"> <tr th:each="equip : ${equipements}" class="hover:bg-gray-50 transition-colors">
<td class="py-4 px-6 font-medium text-gray-900" th:text="${equip.nom}">Maillot</td> <td class="py-4 px-6 font-medium text-gray-900" th:text="${equip.nom}">Maillot</td>
<td class="py-4 px-6">
<span th:if="${equip.reference != null and !equip.reference.trim().isEmpty()}"
class="font-mono text-xs text-gray-700 bg-gray-100 border border-gray-200 px-2.5 py-1 rounded-md font-semibold"
th:text="${equip.reference}">REF-001</span>
<span th:if="${equip.reference == null or equip.reference.trim().isEmpty()}"
class="inline-flex items-center gap-1.5 px-2.5 py-1 rounded-full text-xs font-semibold bg-amber-50 text-amber-700 border border-amber-200" title="Référence non renseignée - Cliquez sur Modifier pour l'ajouter">
<svg class="w-3.5 h-3.5 text-amber-500" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 9v2m0 4h.01m-6.938 4h13.856c1.54 0 2.502-1.667 1.732-3L13.732 4c-.77-1.333-2.694-1.333-3.464 0L3.34 16c-.77 1.333.192 3 1.732 3z"/></svg>
Non renseignée
</span>
</td>
<td class="py-4 px-6 text-gray-600" th:text="${equip.description != null ? equip.description : '-'}">Maillot de match officiel</td> <td class="py-4 px-6 text-gray-600" th:text="${equip.description != null ? equip.description : '-'}">Maillot de match officiel</td>
<td class="py-4 px-6 text-right flex justify-end space-x-3 items-center"> <td class="py-4 px-6 text-right flex justify-end space-x-3 items-center">
<a th:href="@{/equipements/{id}/edit(id=${equip.id})}" class="text-indigo-600 hover:text-indigo-900 font-medium bg-indigo-50 px-3 py-1 rounded-lg">Modifier</a> <a th:href="@{/equipements/{id}/edit(id=${equip.id})}" class="text-indigo-600 hover:text-indigo-900 font-medium bg-indigo-50 px-3 py-1 rounded-lg">Modifier</a>
@@ -98,7 +98,15 @@
</td> </td>
<td class="py-3 px-4 text-gray-600" th:text="${dotation.licence.categorie != null ? dotation.licence.categorie.nom : '-'}">Catégorie</td> <td class="py-3 px-4 text-gray-600" th:text="${dotation.licence.categorie != null ? dotation.licence.categorie.nom : '-'}">Catégorie</td>
<td class="py-3 px-4 text-gray-900 font-medium" th:text="${dotation.equipement != null ? dotation.equipement.nom : '-'}">Maillot</td> <td class="py-3 px-4 text-gray-900 font-medium" th:text="${dotation.equipement != null ? dotation.equipement.nom : '-'}">Maillot</td>
<td class="py-3 px-4 text-gray-600 font-mono text-xs" th:text="${dotation.equipement != null && dotation.equipement.reference != null ? dotation.equipement.reference : '-'}">REF-01</td> <td class="py-3 px-4">
<span th:if="${dotation.equipement != null && dotation.equipement.reference != null && !dotation.equipement.reference.trim().isEmpty()}"
class="font-mono text-xs text-gray-700 bg-gray-100 border border-gray-200 px-2 py-0.5 rounded font-semibold"
th:text="${dotation.equipement.reference}">REF-01</span>
<span th:unless="${dotation.equipement != null && dotation.equipement.reference != null && !dotation.equipement.reference.trim().isEmpty()}"
class="inline-flex items-center gap-1 px-2 py-0.5 rounded text-[10px] font-semibold bg-amber-50 text-amber-700 border border-amber-200" title="Référence non renseignée sur cet équipement">
⚠️ Non renseignée
</span>
</td>
<td class="py-3 px-4 text-gray-600"> <td class="py-3 px-4 text-gray-600">
<div th:text="'T: ' + (${dotation.taille != null && !dotation.taille.isEmpty() ? dotation.taille : '-'})">Taille</div> <div th:text="'T: ' + (${dotation.taille != null && !dotation.taille.isEmpty() ? dotation.taille : '-'})">Taille</div>
<div th:if="${dotation.flocage != null && !dotation.flocage.isEmpty()}" th:text="'F: ' + ${dotation.flocage}">Flocage</div> <div th:if="${dotation.flocage != null && !dotation.flocage.isEmpty()}" th:text="'F: ' + ${dotation.flocage}">Flocage</div>
@@ -67,13 +67,53 @@
<tr th:if="${#lists.isEmpty(equipes)}"> <tr th:if="${#lists.isEmpty(equipes)}">
<td colspan="4" class="py-8 text-center text-gray-500">Aucune équipe configurée pour le moment. Usez du formulaire à gauche pour en créer une.</td> <td colspan="4" class="py-8 text-center text-gray-500">Aucune équipe configurée pour le moment. Usez du formulaire à gauche pour en créer une.</td>
</tr> </tr>
<tr th:each="team : ${equipes}" class="hover:bg-gray-50 transition-colors"> <tr th:each="team : ${equipes}" class="hover:bg-gray-50 transition-colors" th:id="'team-row-' + ${team.id}">
<td class="py-4 px-6 font-medium text-gray-900" th:text="${team.nom}">Équipe 1</td> <td class="py-4 px-6 font-medium text-gray-900">
<!-- Affichage Normal -->
<div th:id="'team-name-display-' + ${team.id}" class="flex items-center gap-2">
<span th:text="${team.nom}" class="font-semibold text-gray-900">Équipe 1</span>
<button type="button"
th:onclick="|enableEditTeam('${team.id}')|"
class="text-gray-400 hover:text-indigo-600 p-1 rounded transition-colors"
title="Modifier le nom">
<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="M15.232 5.232l3.536 3.536m-2.036-5.036a2.5 2.5 0 113.536 3.536L6.5 21.036H3v-3.572L16.732 3.732z"/></svg>
</button>
</div>
<!-- Formulaire d'édition Inline (Masqué par défaut) -->
<form th:id="'team-name-form-' + ${team.id}"
th:action="@{/equipes/{id}/update(id=${team.id})}"
method="post"
class="hidden flex items-center gap-2 m-0">
<input type="text"
name="nom"
th:value="${team.nom}"
required
class="border border-indigo-300 rounded-lg px-3 py-1 text-sm font-medium focus:ring-2 focus:ring-indigo-500 focus:border-indigo-500 outline-none w-48 shadow-sm">
<button type="submit"
class="bg-indigo-600 hover:bg-indigo-700 text-white p-1.5 rounded-lg text-xs font-semibold transition-colors shadow-sm"
title="Enregistrer">
<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="M5 13l4 4L19 7"/></svg>
</button>
<button type="button"
th:onclick="|cancelEditTeam('${team.id}')|"
class="bg-gray-100 hover:bg-gray-200 text-gray-600 p-1.5 rounded-lg text-xs font-semibold transition-colors"
title="Annuler">
<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="M6 18L18 6M6 6l12 12"/></svg>
</button>
</form>
</td>
<td class="py-4 px-6 text-gray-600"> <td class="py-4 px-6 text-gray-600">
<span class="bg-blue-50 text-blue-700 px-2.5 py-1 rounded-full text-xs font-medium" th:text="${team.categorie.nom}">U15</span> <span class="bg-blue-50 text-blue-700 px-2.5 py-1 rounded-full text-xs font-medium" th:text="${team.categorie.nom}">U15</span>
</td> </td>
<td class="py-4 px-6 text-gray-500" th:text="${team.saison.nom}">2024-2025</td> <td class="py-4 px-6 text-gray-500" th:text="${team.saison.nom}">2024-2025</td>
<td class="py-4 px-6 text-right flex justify-end items-center"> <td class="py-4 px-6 text-right flex justify-end items-center space-x-2">
<button type="button"
th:onclick="|enableEditTeam('${team.id}')|"
class="text-indigo-600 hover:text-indigo-800 font-medium text-xs bg-indigo-50 hover:bg-indigo-100 px-2.5 py-1.5 rounded-lg transition-colors 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="M15.232 5.232l3.536 3.536m-2.036-5.036a2.5 2.5 0 113.536 3.536L6.5 21.036H3v-3.572L16.732 3.732z"/></svg>
Modifier
</button>
<form th:action="@{/equipes/{id}/delete(id=${team.id})}" method="post" onsubmit="return confirm('Supprimer cette équipe ? Elle sera dissociée de toutes ses licences.');"> <form th:action="@{/equipes/{id}/delete(id=${team.id})}" method="post" onsubmit="return confirm('Supprimer cette équipe ? Elle sera dissociée de toutes ses licences.');">
<button type="submit" class="text-red-500 hover:text-red-700 font-medium text-xs bg-red-50 hover:bg-red-100 px-2.5 py-1.5 rounded-lg transition-colors"> <button type="submit" class="text-red-500 hover:text-red-700 font-medium text-xs bg-red-50 hover:bg-red-100 px-2.5 py-1.5 rounded-lg transition-colors">
Supprimer Supprimer
@@ -89,5 +129,23 @@
</div> </div>
</div> </div>
</main> </main>
<script>
function enableEditTeam(teamId) {
document.getElementById('team-name-display-' + teamId).classList.add('hidden');
const form = document.getElementById('team-name-form-' + teamId);
form.classList.remove('hidden');
const input = form.querySelector('input[name="nom"]');
if (input) {
input.focus();
input.select();
}
}
function cancelEditTeam(teamId) {
document.getElementById('team-name-display-' + teamId).classList.remove('hidden');
document.getElementById('team-name-form-' + teamId).classList.add('hidden');
}
</script>
</body> </body>
</html> </html>
@@ -88,7 +88,7 @@
<td class="py-3 px-4 text-gray-600 font-mono" th:text="${licence.numeroLicence != null ? licence.numeroLicence : '-'}"></td> <td class="py-3 px-4 text-gray-600 font-mono" th:text="${licence.numeroLicence != null ? licence.numeroLicence : '-'}"></td>
<td class="py-3 px-4 text-gray-600"> <td class="py-3 px-4 text-gray-600">
<div th:text="${licence.typeDemande != null ? licence.typeDemande : '-'}">Type</div> <div th:text="${licence.typeDemande != null ? licence.typeDemande : '-'}">Type</div>
<span th:if="${licence.reductionEducateur}" class="text-[10px] font-bold text-amber-700 bg-amber-50 border border-amber-200 px-1.5 py-0.5 rounded-full inline-block mt-0.5" th:text="'Éducateur (-' + ${licence.pourcentageReductionEducateur} + '%)'">Éducateur (-100%)</span> <span sec:authorize="hasRole('ROLE_ADMIN')" th:if="${licence.reductionEducateur}" class="text-[10px] font-bold text-amber-700 bg-amber-50 border border-amber-200 px-1.5 py-0.5 rounded-full inline-block mt-0.5" th:text="'Éducateur (-' + ${licence.pourcentageReductionEducateur} + '%)'">Éducateur (-100%)</span>
</td> </td>
<td class="py-3 px-4 text-gray-600" th:text="${licence.adherent.email != null ? licence.adherent.email : '-'}">Email</td> <td class="py-3 px-4 text-gray-600" th:text="${licence.adherent.email != null ? licence.adherent.email : '-'}">Email</td>
<td class="py-3 px-4 text-gray-600" th:text="${licence.etat != null ? licence.etat : '-'}">Etat</td> <td class="py-3 px-4 text-gray-600" th:text="${licence.etat != null ? licence.etat : '-'}">Etat</td>
@@ -45,15 +45,25 @@
<td class="py-4 px-6"> <td class="py-4 px-6">
<div class="text-xs text-gray-500" th:text="${pre.email}"></div> <div class="text-xs text-gray-500" th:text="${pre.email}"></div>
</td> </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})}" <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 Créer la fiche
</button> </button>
<button th:attr="hx-post=@{/admin/pre-inscriptions/{id}/rejeter(id=${pre.id})}, hx-target=|#pre-${pre.id}|" <button th:attr="hx-post=@{/admin/pre-inscriptions/{id}/rejeter(id=${pre.id})}, hx-target=|#pre-${pre.id}|"
hx-swap="outerHTML" hx-swap="outerHTML"
hx-confirm="Confirmer le rejet du dossier ?" 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 Rejeter
</button> </button>
</td> </td>
@@ -206,6 +206,7 @@
<script> <script>
const form = document.querySelector('form'); const form = document.querySelector('form');
form.addEventListener('submit', function(event) { form.addEventListener('submit', function(event) {
if (!form.checkValidity()) { if (!form.checkValidity()) {
event.preventDefault(); event.preventDefault();
@@ -230,32 +231,71 @@
const typeDemandeRadios = document.querySelectorAll('input[name="typeDemande"]'); const typeDemandeRadios = document.querySelectorAll('input[name="typeDemande"]');
const nouvelleLicenceBlock = document.getElementById('nouvelleLicenceBlock'); const nouvelleLicenceBlock = document.getElementById('nouvelleLicenceBlock');
typeDemandeRadios.forEach(radio => {
radio.addEventListener('change', function() {
if (this.value === 'NOUVELLE') {
nouvelleLicenceBlock.classList.remove('hidden');
} else {
nouvelleLicenceBlock.classList.add('hidden');
}
});
});
// Trigger on load if already checked (e.g. going back or validation error)
const checkedRadio = document.querySelector('input[name="typeDemande"]:checked');
if (checkedRadio && checkedRadio.value === 'NOUVELLE') {
nouvelleLicenceBlock.classList.remove('hidden');
}
const ancienClubInput = document.getElementById('ancienClub'); const ancienClubInput = document.getElementById('ancienClub');
const ancienneCategorieBlock = document.getElementById('ancienneCategorieBlock'); const ancienneCategorieBlock = document.getElementById('ancienneCategorieBlock');
const ancienneCategorieSelect = document.getElementById('ancienneCategorie'); const ancienneCategorieSelect = document.getElementById('ancienneCategorie');
const raisonChangementClubBlock = document.getElementById('raisonChangementClubBlock'); const raisonChangementClubBlock = document.getElementById('raisonChangementClubBlock');
const raisonChangementClubInput = document.getElementById('raisonChangementClub'); const raisonChangementClubInput = document.getElementById('raisonChangementClub');
const commentConnuInput = document.querySelector('input[name="commentConnuClub"]');
function updateTypeDemandeState(typeValue) {
if (typeValue === 'NOUVELLE') {
nouvelleLicenceBlock.classList.remove('hidden');
// Synchroniser l'état de l'ancien club s'il contient du texte
if (ancienClubInput && ancienClubInput.value.trim().length > 0) {
ancienneCategorieBlock.classList.remove('hidden');
ancienneCategorieSelect.required = true;
raisonChangementClubBlock.classList.remove('hidden');
raisonChangementClubInput.required = true;
} else {
ancienneCategorieBlock.classList.add('hidden');
ancienneCategorieSelect.required = false;
raisonChangementClubBlock.classList.add('hidden');
raisonChangementClubInput.required = false;
}
} else {
// RENOUVELLEMENT
nouvelleLicenceBlock.classList.add('hidden');
// Réinitialisation complète des champs spécifiques aux nouvelles demandes
if (ancienClubInput) ancienClubInput.value = '';
if (raisonChangementClubInput) {
raisonChangementClubInput.value = '';
raisonChangementClubInput.required = false;
}
if (ancienneCategorieSelect) {
ancienneCategorieSelect.value = 'NA';
ancienneCategorieSelect.required = false;
}
if (commentConnuInput) commentConnuInput.value = '';
if (ancienneCategorieBlock) ancienneCategorieBlock.classList.add('hidden');
if (raisonChangementClubBlock) raisonChangementClubBlock.classList.add('hidden');
}
// Si le formulaire redevient valide, masquer le message d'erreur
const errorMsg = document.getElementById('form-error-msg');
if (errorMsg && form.checkValidity()) {
errorMsg.remove();
}
}
typeDemandeRadios.forEach(radio => {
radio.addEventListener('change', function() {
updateTypeDemandeState(this.value);
});
});
// Exécution initiale au chargement si un type est déjà coché
const checkedRadio = document.querySelector('input[name="typeDemande"]:checked');
if (checkedRadio) {
updateTypeDemandeState(checkedRadio.value);
}
if (ancienClubInput) { if (ancienClubInput) {
ancienClubInput.addEventListener('input', function() { ancienClubInput.addEventListener('input', function() {
if (this.value.trim().length > 0) { const isNouvelle = document.querySelector('input[name="typeDemande"]:checked')?.value === 'NOUVELLE';
if (isNouvelle && this.value.trim().length > 0) {
ancienneCategorieBlock.classList.remove('hidden'); ancienneCategorieBlock.classList.remove('hidden');
ancienneCategorieSelect.required = true; ancienneCategorieSelect.required = true;
raisonChangementClubBlock.classList.remove('hidden'); raisonChangementClubBlock.classList.remove('hidden');
@@ -267,35 +307,36 @@
raisonChangementClubInput.required = false; raisonChangementClubInput.required = false;
} }
}); });
// Initial check
if (ancienClubInput.value.trim().length > 0) {
ancienneCategorieBlock.classList.remove('hidden');
ancienneCategorieSelect.required = true;
raisonChangementClubBlock.classList.remove('hidden');
raisonChangementClubInput.required = true;
}
} }
document.getElementById('dateNaissance').addEventListener('change', function() { const dateNaissanceInput = document.getElementById('dateNaissance');
const dateInput = this.value; if (dateNaissanceInput) {
const repBlock = document.getElementById('representantBlock'); dateNaissanceInput.addEventListener('change', function() {
const repInput = document.getElementById('representantLegal'); const dateInput = this.value;
const repBlock = document.getElementById('representantBlock');
const repInput = document.getElementById('representantLegal');
if (dateInput) { if (dateInput) {
const dob = new Date(dateInput); const dob = new Date(dateInput);
const ageDifMs = Date.now() - dob.getTime(); const ageDifMs = Date.now() - dob.getTime();
const ageDate = new Date(ageDifMs); const ageDate = new Date(ageDifMs);
const age = Math.abs(ageDate.getUTCFullYear() - 1970); const age = Math.abs(ageDate.getUTCFullYear() - 1970);
if (age < 18) { if (age < 18) {
repBlock.classList.remove('hidden'); repBlock.classList.remove('hidden');
repInput.required = true; repInput.required = true;
} else { } else {
repBlock.classList.add('hidden'); repBlock.classList.add('hidden');
repInput.required = false; repInput.required = false;
repInput.value = '';
}
} }
});
// Vérification initiale si la date est pré-remplie
if (dateNaissanceInput.value) {
dateNaissanceInput.dispatchEvent(new Event('change'));
} }
}); }
</script> </script>
</body> </body>
</html> </html>