diff --git a/as-talange-core/src/main/java/com/astalange/core/entity/Licence.java b/as-talange-core/src/main/java/com/astalange/core/entity/Licence.java
index 32a2e34..9e5e8c7 100644
--- a/as-talange-core/src/main/java/com/astalange/core/entity/Licence.java
+++ b/as-talange-core/src/main/java/com/astalange/core/entity/Licence.java
@@ -160,6 +160,22 @@ public class Licence {
.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
public Long getId() { return id; }
diff --git a/as-talange-core/src/test/java/com/astalange/core/LicenceReductionTest.java b/as-talange-core/src/test/java/com/astalange/core/LicenceReductionTest.java
index 0ce4252..8b9615c 100644
--- a/as-talange-core/src/test/java/com/astalange/core/LicenceReductionTest.java
+++ b/as-talange-core/src/test/java/com/astalange/core/LicenceReductionTest.java
@@ -114,15 +114,18 @@ class LicenceReductionTest {
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 => reste à payer = 100.00 €
+ // 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 => reste à payer = 60.00 €
+ // 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()));
}
}
diff --git a/as-talange-web/src/main/java/com/astalange/web/controller/PaiementController.java b/as-talange-web/src/main/java/com/astalange/web/controller/PaiementController.java
index b6c8fd9..c8de189 100644
--- a/as-talange-web/src/main/java/com/astalange/web/controller/PaiementController.java
+++ b/as-talange-web/src/main/java/com/astalange/web/controller/PaiementController.java
@@ -63,9 +63,10 @@ public class PaiementController {
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
- if (montant.compareTo(licence.getResteAPayer()) > 0) {
- montant = licence.getResteAPayer();
+ // Validation pour ne pas dépasser le tarif global (tous paiements remis ou non inclus)
+ BigDecimal maxAutorise = licence.getSoldeRestantEngage();
+ if (montant.compareTo(maxAutorise) > 0) {
+ montant = maxAutorise;
}
if (montant.compareTo(BigDecimal.ZERO) > 0) {
@@ -128,9 +129,8 @@ public class PaiementController {
Licence licence = paiement.getLicence();
- // Validation basique pour ne pas dépasser le montant total de la licence
- BigDecimal currentContribution = Boolean.TRUE.equals(paiement.getRemis()) ? paiement.getMontant() : BigDecimal.ZERO;
- BigDecimal maxAmount = licence.getResteAPayer().add(currentContribution);
+ // Validation pour ne pas dépasser le tarif global (tous paiements remis ou non inclus)
+ BigDecimal maxAmount = licence.getSoldeRestantEngage().add(paiement.getMontant());
if (montant.compareTo(maxAmount) > 0) {
montant = maxAmount;
}
diff --git a/as-talange-web/src/main/resources/templates/adherents/form.html b/as-talange-web/src/main/resources/templates/adherents/form.html
index e95bcba..5726e90 100644
--- a/as-talange-web/src/main/resources/templates/adherents/form.html
+++ b/as-talange-web/src/main/resources/templates/adherents/form.html
@@ -307,11 +307,11 @@
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'))"
class="text-blue-600 hover:text-blue-800 font-medium bg-blue-50 px-3 py-1 rounded-lg">Modifier
-