fix(licence): corriger l'évaluation SpEL Thymeleaf et finaliser la réduction éducateur
This commit is contained in:
@@ -50,15 +50,21 @@ public class Licence {
|
||||
@Column(name = "sport_easy_email_sent_at")
|
||||
private java.time.LocalDateTime sportEasyEmailSentAt;
|
||||
|
||||
@Column(name = "reduction_educateur", nullable = false)
|
||||
private Boolean reductionEducateur = false;
|
||||
|
||||
@Column(name = "pourcentage_reduction_educateur")
|
||||
private Integer pourcentageReductionEducateur = 100;
|
||||
|
||||
@OneToMany(mappedBy = "licence", cascade = CascadeType.ALL, orphanRemoval = true)
|
||||
private List<Paiement> paiements = new ArrayList<>();
|
||||
|
||||
@OneToMany(mappedBy = "licence", cascade = CascadeType.ALL, orphanRemoval = true)
|
||||
private List<Dotation> dotations = new ArrayList<>();
|
||||
|
||||
// Logic for Global Total Price
|
||||
// Logic for Raw Price (before reduction)
|
||||
@Transient
|
||||
public BigDecimal getPrixTotal() {
|
||||
public BigDecimal getPrixBrut() {
|
||||
if (categorie == null) return BigDecimal.ZERO;
|
||||
|
||||
BigDecimal prixTotal = (adherent != null && adherent.isResidentTalange())
|
||||
@@ -69,7 +75,7 @@ public class Licence {
|
||||
|
||||
if (dotations != null) {
|
||||
for (Dotation dot : dotations) {
|
||||
if (dot.getChoisi() && dot.getEquipement() != null) {
|
||||
if (dot != null && Boolean.TRUE.equals(dot.getChoisi()) && dot.getEquipement() != null) {
|
||||
BigDecimal price = categorie.getEquipementPrix(dot.getEquipement().getId());
|
||||
if (price != null) {
|
||||
prixTotal = prixTotal.add(price);
|
||||
@@ -81,6 +87,50 @@ public class Licence {
|
||||
return prixTotal;
|
||||
}
|
||||
|
||||
@Transient
|
||||
public BigDecimal getEquipementsContrib() {
|
||||
if (categorie == null) return BigDecimal.ZERO;
|
||||
BigDecimal tarifCategorie = (adherent != null && adherent.isResidentTalange())
|
||||
? categorie.getTarifBase()
|
||||
: categorie.getTarifExterieur();
|
||||
if (tarifCategorie == null) tarifCategorie = BigDecimal.ZERO;
|
||||
BigDecimal prixBrut = getPrixBrut();
|
||||
BigDecimal contrib = prixBrut.subtract(tarifCategorie);
|
||||
return contrib.compareTo(BigDecimal.ZERO) < 0 ? BigDecimal.ZERO : contrib;
|
||||
}
|
||||
|
||||
// Logic for Global Total Price (after discount if applicable)
|
||||
@Transient
|
||||
public BigDecimal getPrixTotal() {
|
||||
BigDecimal prixBrut = getPrixBrut();
|
||||
|
||||
if (Boolean.TRUE.equals(reductionEducateur)) {
|
||||
int pct = (pourcentageReductionEducateur != null && pourcentageReductionEducateur >= 1 && pourcentageReductionEducateur <= 100)
|
||||
? pourcentageReductionEducateur
|
||||
: 100;
|
||||
|
||||
if (pct >= 100) {
|
||||
return BigDecimal.ZERO.setScale(2, java.math.RoundingMode.HALF_UP);
|
||||
} else {
|
||||
BigDecimal multiplier = BigDecimal.valueOf(100 - pct)
|
||||
.divide(BigDecimal.valueOf(100), 4, java.math.RoundingMode.HALF_UP);
|
||||
return prixBrut.multiply(multiplier).setScale(2, java.math.RoundingMode.HALF_UP);
|
||||
}
|
||||
}
|
||||
|
||||
return prixBrut.setScale(2, java.math.RoundingMode.HALF_UP);
|
||||
}
|
||||
|
||||
@Transient
|
||||
public BigDecimal getMontantReduction() {
|
||||
if (!Boolean.TRUE.equals(reductionEducateur)) {
|
||||
return BigDecimal.ZERO.setScale(2, java.math.RoundingMode.HALF_UP);
|
||||
}
|
||||
BigDecimal prixBrut = getPrixBrut();
|
||||
BigDecimal prixTotal = getPrixTotal();
|
||||
return prixBrut.subtract(prixTotal).setScale(2, java.math.RoundingMode.HALF_UP);
|
||||
}
|
||||
|
||||
// Logic for Reste A Payer
|
||||
@Transient
|
||||
public BigDecimal getResteAPayer() {
|
||||
@@ -146,6 +196,12 @@ public class Licence {
|
||||
public java.time.LocalDateTime getSportEasyEmailSentAt() { return sportEasyEmailSentAt; }
|
||||
public void setSportEasyEmailSentAt(java.time.LocalDateTime sportEasyEmailSentAt) { this.sportEasyEmailSentAt = sportEasyEmailSentAt; }
|
||||
|
||||
public Boolean getReductionEducateur() { return reductionEducateur != null ? reductionEducateur : false; }
|
||||
public void setReductionEducateur(Boolean reductionEducateur) { this.reductionEducateur = reductionEducateur; }
|
||||
|
||||
public Integer getPourcentageReductionEducateur() { return pourcentageReductionEducateur != null ? pourcentageReductionEducateur : 100; }
|
||||
public void setPourcentageReductionEducateur(Integer pourcentageReductionEducateur) { this.pourcentageReductionEducateur = pourcentageReductionEducateur; }
|
||||
|
||||
@Transient
|
||||
public boolean isRenouvellement() {
|
||||
return typeDemande != null && (
|
||||
|
||||
+2
@@ -0,0 +1,2 @@
|
||||
ALTER TABLE licence ADD COLUMN reduction_educateur BOOLEAN NOT NULL DEFAULT FALSE;
|
||||
ALTER TABLE licence ADD COLUMN pourcentage_reduction_educateur INT DEFAULT 100;
|
||||
@@ -0,0 +1,98 @@
|
||||
package com.astalange.core;
|
||||
|
||||
import com.astalange.core.entity.Adherent;
|
||||
import com.astalange.core.entity.Categorie;
|
||||
import com.astalange.core.entity.Licence;
|
||||
import org.junit.jupiter.api.DisplayName;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
class LicenceReductionTest {
|
||||
|
||||
@Test
|
||||
@DisplayName("Devrait calculer le prix normal sans réduction")
|
||||
void testPrixSansReduction() {
|
||||
Categorie cat = new Categorie();
|
||||
cat.setTarifBase(new BigDecimal("100.00"));
|
||||
cat.setTarifExterieur(new BigDecimal("120.00"));
|
||||
|
||||
Adherent adh = new Adherent();
|
||||
adh.setResidentTalange(true);
|
||||
|
||||
Licence licence = new Licence();
|
||||
licence.setCategorie(cat);
|
||||
licence.setAdherent(adh);
|
||||
licence.setReductionEducateur(false);
|
||||
|
||||
assertEquals(new BigDecimal("100.00"), licence.getPrixBrut());
|
||||
assertEquals(new BigDecimal("100.00"), licence.getPrixTotal());
|
||||
assertEquals(new BigDecimal("0.00"), licence.getMontantReduction());
|
||||
assertEquals(new BigDecimal("100.00"), licence.getResteAPayer());
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("Devrait calculer une réduction de 100% (gratuit)")
|
||||
void testReduction100Pourcent() {
|
||||
Categorie cat = new Categorie();
|
||||
cat.setTarifBase(new BigDecimal("140.00"));
|
||||
|
||||
Adherent adh = new Adherent();
|
||||
adh.setResidentTalange(true);
|
||||
|
||||
Licence licence = new Licence();
|
||||
licence.setCategorie(cat);
|
||||
licence.setAdherent(adh);
|
||||
licence.setReductionEducateur(true);
|
||||
licence.setPourcentageReductionEducateur(100);
|
||||
|
||||
assertEquals(new BigDecimal("140.00"), licence.getPrixBrut());
|
||||
assertEquals(new BigDecimal("0.00"), licence.getPrixTotal());
|
||||
assertEquals(new BigDecimal("140.00"), licence.getMontantReduction());
|
||||
assertEquals(new BigDecimal("0.00"), licence.getResteAPayer());
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("Devrait calculer une réduction partielle (ex: 50%)")
|
||||
void testReductionPartielle50Pourcent() {
|
||||
Categorie cat = new Categorie();
|
||||
cat.setTarifBase(new BigDecimal("150.00"));
|
||||
|
||||
Adherent adh = new Adherent();
|
||||
adh.setResidentTalange(true);
|
||||
|
||||
Licence licence = new Licence();
|
||||
licence.setCategorie(cat);
|
||||
licence.setAdherent(adh);
|
||||
licence.setReductionEducateur(true);
|
||||
licence.setPourcentageReductionEducateur(50);
|
||||
|
||||
assertEquals(new BigDecimal("150.00"), licence.getPrixBrut());
|
||||
assertEquals(new BigDecimal("75.00"), licence.getPrixTotal());
|
||||
assertEquals(new BigDecimal("75.00"), licence.getMontantReduction());
|
||||
assertEquals(new BigDecimal("75.00"), licence.getResteAPayer());
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("Devrait calculer une réduction partielle de 20%")
|
||||
void testReductionPartielle20Pourcent() {
|
||||
Categorie cat = new Categorie();
|
||||
cat.setTarifBase(new BigDecimal("200.00"));
|
||||
|
||||
Adherent adh = new Adherent();
|
||||
adh.setResidentTalange(true);
|
||||
|
||||
Licence licence = new Licence();
|
||||
licence.setCategorie(cat);
|
||||
licence.setAdherent(adh);
|
||||
licence.setReductionEducateur(true);
|
||||
licence.setPourcentageReductionEducateur(20);
|
||||
|
||||
assertEquals(new BigDecimal("200.00"), licence.getPrixBrut());
|
||||
assertEquals(new BigDecimal("160.00"), licence.getPrixTotal());
|
||||
assertEquals(new BigDecimal("40.00"), licence.getMontantReduction());
|
||||
assertEquals(new BigDecimal("160.00"), licence.getResteAPayer());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user