feat: pré-sélection de la catégorie par âge et sexe lors de la création d'une licence
This commit is contained in:
@@ -431,6 +431,7 @@
|
|||||||
th:data-nom="${cat.nom}"
|
th:data-nom="${cat.nom}"
|
||||||
th:data-annee-min="${cat.anneeMin}"
|
th:data-annee-min="${cat.anneeMin}"
|
||||||
th:data-annee-max="${cat.anneeMax}"
|
th:data-annee-max="${cat.anneeMax}"
|
||||||
|
th:data-sexe="${cat.sexe}"
|
||||||
th:data-tarif-base="${cat.tarifBase}"
|
th:data-tarif-base="${cat.tarifBase}"
|
||||||
th:data-tarif-exterieur="${cat.tarifExterieur}"
|
th:data-tarif-exterieur="${cat.tarifExterieur}"
|
||||||
th:text="${cat.nom} + ' (Talange: ' + ${cat.tarifBase} + ' € / Ext: ' + ${cat.tarifExterieur} + ' €)'"></option>
|
th:text="${cat.nom} + ' (Talange: ' + ${cat.tarifBase} + ' € / Ext: ' + ${cat.tarifExterieur} + ' €)'"></option>
|
||||||
@@ -604,25 +605,41 @@
|
|||||||
|
|
||||||
document.getElementById('typeLicenceSelect').value = '';
|
document.getElementById('typeLicenceSelect').value = '';
|
||||||
|
|
||||||
// Pré-sélection de la catégorie selon l'année de naissance
|
// Pré-sélection de la catégorie selon l'année de naissance et le sexe
|
||||||
const dateNaissanceStr = document.getElementById('dateNaissance').value;
|
const dateNaissanceStr = document.getElementById('dateNaissance').value;
|
||||||
|
const adherentSexe = document.getElementById('sexe') ? document.getElementById('sexe').value : 'MASCULIN';
|
||||||
let foundCat = false;
|
let foundCat = false;
|
||||||
|
let fallbackCatId = '';
|
||||||
let preSelectedCatId = '';
|
let preSelectedCatId = '';
|
||||||
|
|
||||||
if (dateNaissanceStr) {
|
if (dateNaissanceStr) {
|
||||||
const birthYear = new Date(dateNaissanceStr).getFullYear();
|
const birthYear = new Date(dateNaissanceStr).getFullYear();
|
||||||
|
|
||||||
Array.from(catSelect.options).forEach(opt => {
|
Array.from(catSelect.options).forEach(opt => {
|
||||||
|
if (!opt.value) return;
|
||||||
const min = parseInt(opt.getAttribute('data-annee-min'));
|
const min = parseInt(opt.getAttribute('data-annee-min'));
|
||||||
const max = parseInt(opt.getAttribute('data-annee-max'));
|
const max = parseInt(opt.getAttribute('data-annee-max'));
|
||||||
|
const catSexe = opt.getAttribute('data-sexe') || 'MASCULIN';
|
||||||
|
|
||||||
if (!isNaN(min) && !isNaN(max) && birthYear >= min && birthYear <= max) {
|
if (!isNaN(min) && !isNaN(max) && birthYear >= min && birthYear <= max) {
|
||||||
catSelect.value = opt.value;
|
if (catSexe === adherentSexe) {
|
||||||
preSelectedCatId = opt.value;
|
catSelect.value = opt.value;
|
||||||
foundCat = true;
|
preSelectedCatId = opt.value;
|
||||||
|
foundCat = true;
|
||||||
|
}
|
||||||
|
if (catSexe === 'MASCULIN') {
|
||||||
|
fallbackCatId = opt.value;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!foundCat && fallbackCatId) {
|
||||||
|
catSelect.value = fallbackCatId;
|
||||||
|
preSelectedCatId = fallbackCatId;
|
||||||
|
foundCat = true;
|
||||||
|
}
|
||||||
|
|
||||||
if (!foundCat) {
|
if (!foundCat) {
|
||||||
catSelect.value = '';
|
catSelect.value = '';
|
||||||
}
|
}
|
||||||
@@ -730,6 +747,7 @@
|
|||||||
const dob = new Date(dateInput.value);
|
const dob = new Date(dateInput.value);
|
||||||
const birthYear = dob.getFullYear();
|
const birthYear = dob.getFullYear();
|
||||||
const isResident = residentCheckbox ? residentCheckbox.checked : true;
|
const isResident = residentCheckbox ? residentCheckbox.checked : true;
|
||||||
|
const adherentSexe = document.getElementById('sexe') ? document.getElementById('sexe').value : 'MASCULIN';
|
||||||
|
|
||||||
const categories = [];
|
const categories = [];
|
||||||
const catSelect = document.getElementById('categorieSelect');
|
const catSelect = document.getElementById('categorieSelect');
|
||||||
@@ -739,17 +757,21 @@
|
|||||||
const nom = opt.getAttribute('data-nom');
|
const nom = opt.getAttribute('data-nom');
|
||||||
const min = parseInt(opt.getAttribute('data-annee-min'));
|
const min = parseInt(opt.getAttribute('data-annee-min'));
|
||||||
const max = parseInt(opt.getAttribute('data-annee-max'));
|
const max = parseInt(opt.getAttribute('data-annee-max'));
|
||||||
|
const sexe = opt.getAttribute('data-sexe') || 'MASCULIN';
|
||||||
const tarifBase = parseFloat(opt.getAttribute('data-tarif-base') || '0');
|
const tarifBase = parseFloat(opt.getAttribute('data-tarif-base') || '0');
|
||||||
const tarifExterieur = parseFloat(opt.getAttribute('data-tarif-exterieur') || '0');
|
const tarifExterieur = parseFloat(opt.getAttribute('data-tarif-exterieur') || '0');
|
||||||
if (id) {
|
if (id) {
|
||||||
categories.push({ id, nom, min, max, tarifBase, tarifExterieur });
|
categories.push({ id, nom, min, max, sexe, tarifBase, tarifExterieur });
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
if (categories.length === 0) return;
|
if (categories.length === 0) return;
|
||||||
|
|
||||||
const matchingCat = categories.find(c => birthYear >= c.min && birthYear <= c.max);
|
let matchingCat = categories.find(c => birthYear >= c.min && birthYear <= c.max && c.sexe === adherentSexe);
|
||||||
|
if (!matchingCat) {
|
||||||
|
matchingCat = categories.find(c => birthYear >= c.min && birthYear <= c.max && c.sexe === 'MASCULIN');
|
||||||
|
}
|
||||||
if (!matchingCat) return;
|
if (!matchingCat) return;
|
||||||
|
|
||||||
document.querySelectorAll('.licence-row').forEach(row => {
|
document.querySelectorAll('.licence-row').forEach(row => {
|
||||||
@@ -897,7 +919,10 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (sexeSelect) {
|
if (sexeSelect) {
|
||||||
sexeSelect.addEventListener('change', updateEquipmentStyleLabels);
|
sexeSelect.addEventListener('change', function() {
|
||||||
|
updateEquipmentStyleLabels();
|
||||||
|
updateLicencesCategoryAndPrices();
|
||||||
|
});
|
||||||
}
|
}
|
||||||
if (typeMaillotSelect) {
|
if (typeMaillotSelect) {
|
||||||
typeMaillotSelect.addEventListener('change', updateEquipmentStyleLabels);
|
typeMaillotSelect.addEventListener('change', updateEquipmentStyleLabels);
|
||||||
|
|||||||
Reference in New Issue
Block a user