feat: gestion type de demande, calcul dynamique du tarif et pre-selection equipement (maillot) pour inscription
This commit is contained in:
+69
-1
@@ -6,6 +6,8 @@ import com.astalange.core.entity.Saison;
|
||||
import com.astalange.core.repository.PreInscriptionRepository;
|
||||
import com.astalange.core.repository.TokenPreInscriptionRepository;
|
||||
import com.astalange.core.repository.SaisonRepository;
|
||||
import com.astalange.core.repository.CategorieRepository;
|
||||
import com.astalange.core.entity.Categorie;
|
||||
import com.astalange.core.service.CaptchaValidationService;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.Model;
|
||||
@@ -14,7 +16,10 @@ import org.springframework.web.servlet.mvc.support.RedirectAttributes;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.LocalDate;
|
||||
import java.util.UUID;
|
||||
import java.util.List;
|
||||
import java.math.BigDecimal;
|
||||
|
||||
@Controller
|
||||
@RequestMapping("/inscription-public")
|
||||
@@ -24,15 +29,18 @@ public class PublicInscriptionController {
|
||||
private final TokenPreInscriptionRepository tokenRepository;
|
||||
private final PreInscriptionRepository preInscriptionRepository;
|
||||
private final SaisonRepository saisonRepository;
|
||||
private final CategorieRepository categorieRepository;
|
||||
|
||||
public PublicInscriptionController(CaptchaValidationService captchaValidationService,
|
||||
TokenPreInscriptionRepository tokenRepository,
|
||||
PreInscriptionRepository preInscriptionRepository,
|
||||
SaisonRepository saisonRepository) {
|
||||
SaisonRepository saisonRepository,
|
||||
CategorieRepository categorieRepository) {
|
||||
this.captchaValidationService = captchaValidationService;
|
||||
this.tokenRepository = tokenRepository;
|
||||
this.preInscriptionRepository = preInscriptionRepository;
|
||||
this.saisonRepository = saisonRepository;
|
||||
this.categorieRepository = categorieRepository;
|
||||
}
|
||||
|
||||
@Value("${captcha.sitekey:1x00000000000000000000AA}")
|
||||
@@ -117,9 +125,69 @@ public class PublicInscriptionController {
|
||||
token.setEstUtilise(true);
|
||||
tokenRepository.save(token);
|
||||
|
||||
if ("NOUVELLE".equals(preInscription.getTypeDemande())) {
|
||||
String tarifStr = "210 €"; // Default
|
||||
if (preInscription.getDateNaissance() != null) {
|
||||
int annee = preInscription.getDateNaissance().getYear();
|
||||
List<Categorie> categories = categorieRepository.findBySaisonAndAnnee(activeSaison, annee);
|
||||
if (!categories.isEmpty()) {
|
||||
Categorie cat = categories.get(0);
|
||||
if (cat.getTarifBase() != null) {
|
||||
BigDecimal prixMaillot = BigDecimal.ZERO;
|
||||
if (cat.isU11OrBelow()) {
|
||||
prixMaillot = cat.getEquipementPrixByNom("Maillot");
|
||||
}
|
||||
BigDecimal tarifTotal = cat.getTarifBase().add(prixMaillot);
|
||||
tarifStr = tarifTotal.intValue() + " €";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
redirectAttributes.addFlashAttribute("prenom", preInscription.getPrenom());
|
||||
redirectAttributes.addFlashAttribute("tarif", tarifStr);
|
||||
redirectAttributes.addFlashAttribute("documents", java.util.Arrays.asList(
|
||||
"Photo d’identité",
|
||||
"Carte d’identité ou passeport de l’enfant",
|
||||
"Livret de famille (si pas de pièce d’identité)",
|
||||
"Adresse e-mail du représentant légal",
|
||||
"Pour les enfants nés à l’étranger : passeport + justificatif de domicile des parents"
|
||||
));
|
||||
redirectAttributes.addFlashAttribute("isNouvelle", true);
|
||||
}
|
||||
|
||||
return "redirect:/inscription-public/succes";
|
||||
}
|
||||
|
||||
@GetMapping("/api/tarif")
|
||||
@ResponseBody
|
||||
public String getTarif(@RequestParam(value = "dateNaissance", required = false) String dateNaissanceStr) {
|
||||
if (dateNaissanceStr == null || dateNaissanceStr.isEmpty()) {
|
||||
return "210 €";
|
||||
}
|
||||
try {
|
||||
LocalDate dateNaissance = LocalDate.parse(dateNaissanceStr);
|
||||
int annee = dateNaissance.getYear();
|
||||
Saison activeSaison = saisonRepository.findByEstActiveTrue().orElse(null);
|
||||
if (activeSaison == null) return "210 €";
|
||||
|
||||
List<Categorie> categories = categorieRepository.findBySaisonAndAnnee(activeSaison, annee);
|
||||
if (categories.isEmpty()) return "210 €";
|
||||
|
||||
Categorie cat = categories.get(0);
|
||||
if (cat.getTarifBase() != null) {
|
||||
BigDecimal prixMaillot = BigDecimal.ZERO;
|
||||
if (cat.isU11OrBelow()) {
|
||||
prixMaillot = cat.getEquipementPrixByNom("Maillot");
|
||||
}
|
||||
BigDecimal tarifTotal = cat.getTarifBase().add(prixMaillot);
|
||||
return tarifTotal.intValue() + " €";
|
||||
}
|
||||
} catch (Exception e) {
|
||||
// Return default on error
|
||||
}
|
||||
return "210 €";
|
||||
}
|
||||
|
||||
@GetMapping("/succes")
|
||||
public String showSucces() {
|
||||
return "public/succes";
|
||||
|
||||
Reference in New Issue
Block a user