From cac229486add6424cf0c5f81ff2a67ac875c6ded Mon Sep 17 00:00:00 2001 From: Youssef Date: Wed, 20 May 2026 19:12:56 +0200 Subject: [PATCH] feat: recalculate license and remaining prices dynamically on residency checkbox change --- .../resources/templates/adherents/form.html | 69 +++++++++++++++++-- 1 file changed, 64 insertions(+), 5 deletions(-) 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 eaf36ca..f339477 100644 --- a/as-talange-web/src/main/resources/templates/adherents/form.html +++ b/as-talange-web/src/main/resources/templates/adherents/form.html @@ -186,11 +186,15 @@ Aucune licence enregistrée. - + 2024-2025 U15 - 100.00 € (Catégorie) + 100.00 € (Catégorie) - @@ -198,13 +202,13 @@ th:classappend="${lic.etat == 'Validée' ? 'bg-blue-100 text-blue-800' : (lic.etat == 'Payée' ? 'bg-green-100 text-green-800' : 'bg-yellow-100 text-yellow-800')}" th:text="${lic.etat}">Brouillon - 130.00 € - 130.00 € + 30.00 € + th:data-licence-id="${lic.id}" class="text-green-600 hover:text-green-800 font-medium bg-green-50 px-3 py-1 rounded-lg btn-payer">Payer @@ -428,6 +432,61 @@ if (hasRepError || document.getElementById('representantLegal').classList.contains('border-red-500')) { repBlock.classList.remove('hidden-block'); } + + // Recalculate price dynamically when residentTalange checkbox changes + const residentCheckbox = document.getElementById('residentTalange'); + if (residentCheckbox) { + residentCheckbox.addEventListener('change', function() { + const isResident = this.checked; + document.querySelectorAll('.licence-row').forEach(row => { + const tarifBase = parseFloat(row.getAttribute('data-tarif-base') || '0'); + const tarifExterieur = parseFloat(row.getAttribute('data-tarif-exterieur') || '0'); + const equipContrib = parseFloat(row.getAttribute('data-equipements-contrib') || '0'); + const totalPaye = parseFloat(row.getAttribute('data-total-paye') || '0'); + + const baseTarif = isResident ? tarifBase : tarifExterieur; + const newTotal = baseTarif + equipContrib; + const newReste = Math.max(0, newTotal - totalPaye); + + // Update Category price cell + const catCell = row.querySelector('.cell-tarif-categorie'); + if (catCell) { + catCell.textContent = baseTarif.toFixed(2) + ' € (Catégorie)'; + } + + // Update Tarif Global cell + const globalCell = row.querySelector('.cell-tarif-global'); + if (globalCell) { + globalCell.textContent = newTotal.toFixed(2) + ' €'; + } + + // Update Reste à Payer cell + const resteCell = row.querySelector('.cell-reste-payer'); + if (resteCell) { + resteCell.textContent = newReste.toFixed(2) + ' €'; + if (newReste === 0) { + resteCell.classList.remove('text-red-600'); + resteCell.classList.add('text-green-600'); + } else { + resteCell.classList.remove('text-green-600'); + resteCell.classList.add('text-red-600'); + } + } + + // Update Payer button + const payerBtn = row.querySelector('.btn-payer'); + if (payerBtn) { + if (newReste > 0) { + payerBtn.classList.remove('hidden'); + const licId = payerBtn.getAttribute('data-licence-id'); + payerBtn.setAttribute('onclick', `openPaiementModal(${licId}, ${newReste})`); + } else { + payerBtn.classList.add('hidden'); + } + } + }); + }); + } });