feat: implement global pricing model, optional equipment contribution, and bulk save for dotations
This commit is contained in:
@@ -3,10 +3,14 @@ package com.astalange.web.controller;
|
||||
import com.astalange.core.entity.Dotation;
|
||||
import com.astalange.core.repository.DotationRepository;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
|
||||
import java.util.List;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
|
||||
@Controller
|
||||
public class DotationController {
|
||||
|
||||
@@ -22,17 +26,61 @@ public class DotationController {
|
||||
@RequestParam Long adherentId,
|
||||
@RequestParam(required = false, defaultValue = "") String taille,
|
||||
@RequestParam(required = false, defaultValue = "") String flocage,
|
||||
@RequestParam(required = false) Boolean fourni) {
|
||||
@RequestParam(required = false, defaultValue = "") String numero,
|
||||
@RequestParam(required = false) Boolean fourni,
|
||||
@RequestParam(required = false) Boolean choisi) {
|
||||
|
||||
Dotation dotation = dotationRepository.findById(id)
|
||||
.orElseThrow(() -> new IllegalArgumentException("Invalid Dotation ID: " + id));
|
||||
|
||||
dotation.setTaille(taille);
|
||||
dotation.setFlocage(flocage);
|
||||
dotation.setNumero(numero);
|
||||
dotation.setFourni(fourni != null && fourni);
|
||||
|
||||
if (dotation.getEquipement().getObligatoire()) {
|
||||
dotation.setChoisi(true);
|
||||
} else {
|
||||
dotation.setChoisi(choisi != null && choisi);
|
||||
}
|
||||
|
||||
dotationRepository.save(dotation);
|
||||
|
||||
return "redirect:/adherents/" + adherentId + "/edit";
|
||||
}
|
||||
|
||||
@Transactional
|
||||
@PostMapping("/dotations/bulk")
|
||||
public String bulkUpdateDotations(
|
||||
@RequestParam Long adherentId,
|
||||
@RequestParam("dotationIds") List<Long> dotationIds,
|
||||
HttpServletRequest request) {
|
||||
|
||||
for (Long id : dotationIds) {
|
||||
Dotation dotation = dotationRepository.findById(id)
|
||||
.orElseThrow(() -> new IllegalArgumentException("Invalid Dotation ID: " + id));
|
||||
|
||||
String taille = request.getParameter("taille_" + id);
|
||||
String numero = request.getParameter("numero_" + id);
|
||||
String flocage = request.getParameter("flocage_" + id);
|
||||
String choisiParam = request.getParameter("choisi_" + id);
|
||||
String fourniParam = request.getParameter("fourni_" + id);
|
||||
|
||||
if (taille != null) dotation.setTaille(taille);
|
||||
if (numero != null) dotation.setNumero(numero);
|
||||
if (flocage != null) dotation.setFlocage(flocage);
|
||||
|
||||
if (dotation.getEquipement().getObligatoire()) {
|
||||
dotation.setChoisi(true);
|
||||
} else {
|
||||
dotation.setChoisi(choisiParam != null);
|
||||
}
|
||||
|
||||
dotation.setFourni(fourniParam != null);
|
||||
|
||||
dotationRepository.save(dotation);
|
||||
}
|
||||
|
||||
return "redirect:/adherents/" + adherentId + "/edit";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -41,12 +41,7 @@ public class HomeController {
|
||||
|
||||
List<com.astalange.core.entity.Licence> allLicences = licenceRepository.findAll();
|
||||
BigDecimal totalAttendu = allLicences.stream()
|
||||
.map(lic -> {
|
||||
if (lic.getCategorie() == null) return BigDecimal.ZERO;
|
||||
return (lic.getAdherent() != null && lic.getAdherent().isResidentTalange())
|
||||
? lic.getCategorie().getTarifBase()
|
||||
: lic.getCategorie().getTarifExterieur();
|
||||
})
|
||||
.map(com.astalange.core.entity.Licence::getPrixTotal)
|
||||
.reduce(BigDecimal.ZERO, BigDecimal::add);
|
||||
|
||||
BigDecimal resteARecouvrer = totalAttendu.subtract(totalEncaisse);
|
||||
|
||||
@@ -73,8 +73,10 @@ public class LicenceController {
|
||||
dotation.setLicence(licence);
|
||||
dotation.setEquipement(eq);
|
||||
dotation.setTaille("");
|
||||
dotation.setFlocage("");
|
||||
dotation.setFlocage(adherent.getNom().toUpperCase() + " " + adherent.getPrenom());
|
||||
dotation.setNumero("");
|
||||
dotation.setFourni(false);
|
||||
dotation.setChoisi(eq.getObligatoire());
|
||||
dotationRepository.save(dotation);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user