feat: implement server-side pagination, eager query loading, and dynamic column filtering via HTMX for Payment History
This commit is contained in:
@@ -11,4 +11,12 @@ public interface PaiementRepository extends JpaRepository<Paiement, Long> {
|
|||||||
|
|
||||||
@Query("SELECT SUM(p.montant) FROM Paiement p")
|
@Query("SELECT SUM(p.montant) FROM Paiement p")
|
||||||
BigDecimal sumMontant();
|
BigDecimal sumMontant();
|
||||||
|
|
||||||
|
@Query("SELECT p FROM Paiement p " +
|
||||||
|
"LEFT JOIN FETCH p.licence l " +
|
||||||
|
"LEFT JOIN FETCH l.adherent a " +
|
||||||
|
"LEFT JOIN FETCH l.categorie c " +
|
||||||
|
"LEFT JOIN FETCH p.modePaiement m " +
|
||||||
|
"ORDER BY p.datePaiement DESC, p.id DESC")
|
||||||
|
java.util.List<Paiement> findAllWithAssociations();
|
||||||
}
|
}
|
||||||
|
|||||||
+106
-4
@@ -1,23 +1,125 @@
|
|||||||
package com.astalange.web.controller;
|
package com.astalange.web.controller;
|
||||||
|
|
||||||
|
import com.astalange.core.entity.Paiement;
|
||||||
|
import com.astalange.core.repository.CategorieRepository;
|
||||||
|
import com.astalange.core.repository.ModePaiementRepository;
|
||||||
import com.astalange.core.repository.PaiementRepository;
|
import com.astalange.core.repository.PaiementRepository;
|
||||||
import org.springframework.data.domain.Sort;
|
|
||||||
import org.springframework.stereotype.Controller;
|
import org.springframework.stereotype.Controller;
|
||||||
import org.springframework.ui.Model;
|
import org.springframework.ui.Model;
|
||||||
import org.springframework.web.bind.annotation.GetMapping;
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestParam;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
@Controller
|
@Controller
|
||||||
public class PaiementsController {
|
public class PaiementsController {
|
||||||
|
|
||||||
private final PaiementRepository paiementRepository;
|
private final PaiementRepository paiementRepository;
|
||||||
|
private final CategorieRepository categorieRepository;
|
||||||
|
private final ModePaiementRepository modePaiementRepository;
|
||||||
|
|
||||||
public PaiementsController(PaiementRepository paiementRepository) {
|
public PaiementsController(PaiementRepository paiementRepository,
|
||||||
|
CategorieRepository categorieRepository,
|
||||||
|
ModePaiementRepository modePaiementRepository) {
|
||||||
this.paiementRepository = paiementRepository;
|
this.paiementRepository = paiementRepository;
|
||||||
|
this.categorieRepository = categorieRepository;
|
||||||
|
this.modePaiementRepository = modePaiementRepository;
|
||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping("/paiements")
|
@GetMapping("/paiements")
|
||||||
public String listPaiements(Model model) {
|
public String listPaiements(
|
||||||
model.addAttribute("paiements", paiementRepository.findAll(Sort.by(Sort.Direction.DESC, "datePaiement", "id")));
|
@RequestParam(required = false) String query,
|
||||||
|
@RequestParam(required = false) String adherent,
|
||||||
|
@RequestParam(required = false) String categorie,
|
||||||
|
@RequestParam(required = false) String saison,
|
||||||
|
@RequestParam(required = false) String modePaiement,
|
||||||
|
@RequestParam(required = false) String montant,
|
||||||
|
@RequestParam(defaultValue = "0") int page,
|
||||||
|
@RequestParam(defaultValue = "20") int size,
|
||||||
|
Model model) {
|
||||||
|
|
||||||
|
List<Paiement> allPaiements = paiementRepository.findAllWithAssociations();
|
||||||
|
|
||||||
|
List<Paiement> filtered = allPaiements.stream()
|
||||||
|
.filter(p -> {
|
||||||
|
// Global query
|
||||||
|
if (query != null && !query.trim().isEmpty()) {
|
||||||
|
String q = query.toLowerCase().trim();
|
||||||
|
String fullName = (p.getLicence().getAdherent().getPrenom() + " " + p.getLicence().getAdherent().getNom()).toLowerCase();
|
||||||
|
String catName = p.getLicence().getCategorie().getNom().toLowerCase();
|
||||||
|
String modeName = p.getModePaiement().getNom().toLowerCase();
|
||||||
|
String seasonName = p.getLicence().getSaison().getNom().toLowerCase();
|
||||||
|
if (!fullName.contains(q) && !catName.contains(q) && !modeName.contains(q) && !seasonName.contains(q)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Column filters
|
||||||
|
if (adherent != null && !adherent.trim().isEmpty()) {
|
||||||
|
String af = adherent.toLowerCase().trim();
|
||||||
|
String fullName = (p.getLicence().getAdherent().getPrenom() + " " + p.getLicence().getAdherent().getNom()).toLowerCase();
|
||||||
|
if (!fullName.contains(af)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (categorie != null && !categorie.trim().isEmpty()) {
|
||||||
|
if (!p.getLicence().getCategorie().getNom().equalsIgnoreCase(categorie.trim())) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (saison != null && !saison.trim().isEmpty()) {
|
||||||
|
String sf = saison.toLowerCase().trim();
|
||||||
|
if (!p.getLicence().getSaison().getNom().toLowerCase().contains(sf)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (modePaiement != null && !modePaiement.trim().isEmpty()) {
|
||||||
|
if (!p.getModePaiement().getNom().equalsIgnoreCase(modePaiement.trim())) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (montant != null && !montant.trim().isEmpty()) {
|
||||||
|
String mf = montant.trim();
|
||||||
|
if (!p.getMontant().toString().contains(mf)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
})
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
|
||||||
|
int totalElements = filtered.size();
|
||||||
|
int totalPages = (int) Math.ceil((double) totalElements / size);
|
||||||
|
int fromIndex = page * size;
|
||||||
|
int toIndex = Math.min(fromIndex + size, totalElements);
|
||||||
|
|
||||||
|
List<Paiement> paginated = List.of();
|
||||||
|
if (fromIndex < totalElements) {
|
||||||
|
paginated = filtered.subList(fromIndex, toIndex);
|
||||||
|
}
|
||||||
|
|
||||||
|
model.addAttribute("paiements", paginated);
|
||||||
|
model.addAttribute("categories", categorieRepository.findAll());
|
||||||
|
model.addAttribute("modesPaiement", modePaiementRepository.findAll());
|
||||||
|
model.addAttribute("currentPage", page);
|
||||||
|
model.addAttribute("pageSize", size);
|
||||||
|
model.addAttribute("totalPages", totalPages);
|
||||||
|
model.addAttribute("totalElements", totalElements);
|
||||||
|
|
||||||
|
// Keep filter values in model to restore inputs after swap
|
||||||
|
model.addAttribute("searchQuery", query);
|
||||||
|
model.addAttribute("adherentFilter", adherent);
|
||||||
|
model.addAttribute("categorieFilter", categorie);
|
||||||
|
model.addAttribute("saisonFilter", saison);
|
||||||
|
model.addAttribute("modePaiementFilter", modePaiement);
|
||||||
|
model.addAttribute("montantFilter", montant);
|
||||||
|
|
||||||
return "paiements/list";
|
return "paiements/list";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,6 +4,7 @@
|
|||||||
<meta charset="UTF-8">
|
<meta charset="UTF-8">
|
||||||
<title>Paiements - AS Talange</title>
|
<title>Paiements - AS Talange</title>
|
||||||
<script src="https://cdn.tailwindcss.com"></script>
|
<script src="https://cdn.tailwindcss.com"></script>
|
||||||
|
<script src="https://unpkg.com/htmx.org@1.9.11"></script>
|
||||||
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap" rel="stylesheet">
|
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap" rel="stylesheet">
|
||||||
<style> body { font-family: 'Inter', sans-serif; } </style>
|
<style> body { font-family: 'Inter', sans-serif; } </style>
|
||||||
</head>
|
</head>
|
||||||
@@ -21,39 +22,135 @@
|
|||||||
<h3 class="text-xl font-bold text-gray-900">Transactions Récentes</h3>
|
<h3 class="text-xl font-bold text-gray-900">Transactions Récentes</h3>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="bg-white rounded-xl shadow-sm border border-gray-100 overflow-hidden">
|
<div id="paiements-table-container" class="bg-white rounded-xl shadow-sm border border-gray-100 overflow-hidden">
|
||||||
<table class="w-full text-left border-collapse">
|
<div class="p-4 border-b border-gray-200 flex justify-between items-center">
|
||||||
<thead>
|
<form hx-get="/paiements" hx-target="#paiements-table-container" hx-select="#paiements-table-container" class="flex items-center space-x-2">
|
||||||
<tr class="bg-gray-50 text-gray-500 text-sm uppercase tracking-wider border-b border-gray-200">
|
<input type="text" name="query" th:value="${searchQuery}" placeholder="Nom, prénom, catégorie..."
|
||||||
<th class="py-3 px-6 font-medium text-left">Date</th>
|
class="border border-gray-300 rounded-lg px-4 py-2 text-sm w-64 focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-blue-500">
|
||||||
<th class="py-3 px-6 font-medium text-left">Adhérent</th>
|
<button type="submit" class="bg-gray-100 text-gray-700 px-4 py-2 rounded-lg text-sm font-medium hover:bg-gray-200 border border-gray-300 transition-colors">Chercher</button>
|
||||||
<th class="py-3 px-6 font-medium text-left">Catégorie</th>
|
<a th:if="${searchQuery != null and !searchQuery.isEmpty()}" th:href="@{/paiements}" class="text-sm text-gray-500 hover:text-gray-700 underline underline-offset-2 ml-2">Effacer</a>
|
||||||
<th class="py-3 px-6 font-medium text-center">Saison</th>
|
</form>
|
||||||
<th class="py-3 px-6 font-medium text-left">Mode de paiement</th>
|
</div>
|
||||||
<th class="py-3 px-6 font-medium text-right">Montant</th>
|
|
||||||
</tr>
|
<form id="filter-form" hx-get="/paiements" hx-target="#paiements-table-container" hx-select="#paiements-table-container" hx-trigger="change, keyup changed delay:300ms" hx-sync="this:replace" hx-on::config-request="if (event.detail.trigger.tagName !== 'BUTTON') { event.detail.parameters['page'] = 0; }" class="m-0">
|
||||||
</thead>
|
<input type="hidden" name="query" th:value="${searchQuery}">
|
||||||
<tbody class="divide-y divide-gray-200 text-sm">
|
|
||||||
<tr th:if="${#lists.isEmpty(paiements)}">
|
<table class="w-full text-left border-collapse">
|
||||||
<td colspan="6" class="py-8 text-center text-gray-500">Aucun paiement enregistré pour le moment.</td>
|
<thead>
|
||||||
</tr>
|
<tr class="bg-gray-50 text-gray-500 text-sm uppercase tracking-wider border-b border-gray-200">
|
||||||
<tr th:each="p : ${paiements}" class="hover:bg-gray-50 transition-colors">
|
<th class="py-3 px-6 font-medium text-left">Date</th>
|
||||||
<td class="py-4 px-6 text-gray-600" th:text="${#temporals.format(p.datePaiement, 'dd/MM/yyyy')}">15/05/2026</td>
|
<th class="py-3 px-6 font-medium text-left">Adhérent</th>
|
||||||
<td class="py-4 px-6 font-medium text-gray-900">
|
<th class="py-3 px-6 font-medium text-left">Catégorie</th>
|
||||||
<a th:href="@{/adherents/{id}/edit(id=${p.licence.adherent.id})}"
|
<th class="py-3 px-6 font-medium text-center">Saison</th>
|
||||||
class="text-blue-600 hover:text-blue-800 hover:underline"
|
<th class="py-3 px-6 font-medium text-left">Mode de paiement</th>
|
||||||
th:text="${p.licence.adherent.prenom + ' ' + p.licence.adherent.nom}">Jean Dupont</a>
|
<th class="py-3 px-6 font-medium text-right">Montant</th>
|
||||||
</td>
|
</tr>
|
||||||
<td class="py-4 px-6 text-gray-600" th:text="${p.licence.categorie.nom}">U13</td>
|
<!-- Filter Row -->
|
||||||
<td class="py-4 px-6 text-center text-gray-600" th:text="${p.licence.saison}">2024-2025</td>
|
<tr class="bg-gray-100 border-b border-gray-200 text-xs">
|
||||||
<td class="py-4 px-6 text-gray-600">
|
<td class="py-2 px-3"></td>
|
||||||
<span class="px-2 py-0.5 rounded border border-gray-200 bg-gray-50 text-gray-700 text-xs"
|
<td class="py-2 px-3">
|
||||||
th:text="${p.modePaiement.nom}">Chèque</span>
|
<input type="text" id="filterAdherent" name="adherent" th:value="${adherentFilter}" placeholder="Filtrer Adhérent..." class="w-full border border-gray-300 rounded px-2 py-1 text-xs focus:ring-1 focus:ring-blue-500 focus:outline-none">
|
||||||
</td>
|
</td>
|
||||||
<td class="py-4 px-6 text-right font-semibold text-green-600" th:text="${p.montant + ' €'}">50.00 €</td>
|
<td class="py-2 px-3">
|
||||||
</tr>
|
<select id="filterCategorie" name="categorie" class="w-full border border-gray-300 rounded px-2 py-1 text-xs focus:ring-1 focus:ring-blue-500 focus:outline-none">
|
||||||
</tbody>
|
<option value="">Toutes</option>
|
||||||
</table>
|
<option th:each="cat : ${categories}" th:value="${cat.nom}" th:text="${cat.nom}" th:selected="${categorieFilter == cat.nom}"></option>
|
||||||
|
</select>
|
||||||
|
</td>
|
||||||
|
<td class="py-2 px-3">
|
||||||
|
<input type="text" id="filterSaison" name="saison" th:value="${saisonFilter}" placeholder="Filtrer Saison..." class="w-full border border-gray-300 rounded px-2 py-1 text-xs focus:ring-1 focus:ring-blue-500 focus:outline-none">
|
||||||
|
</td>
|
||||||
|
<td class="py-2 px-3">
|
||||||
|
<select id="filterModePaiement" name="modePaiement" class="w-full border border-gray-300 rounded px-2 py-1 text-xs focus:ring-1 focus:ring-blue-500 focus:outline-none">
|
||||||
|
<option value="">Tous</option>
|
||||||
|
<option th:each="mode : ${modesPaiement}" th:value="${mode.nom}" th:text="${mode.nom}" th:selected="${modePaiementFilter == mode.nom}"></option>
|
||||||
|
</select>
|
||||||
|
</td>
|
||||||
|
<td class="py-2 px-3">
|
||||||
|
<input type="text" id="filterMontant" name="montant" th:value="${montantFilter}" placeholder="Filtrer Montant..." class="w-full border border-gray-300 rounded px-2 py-1 text-xs focus:ring-1 focus:ring-blue-500 focus:outline-none text-right">
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody class="divide-y divide-gray-200 text-sm">
|
||||||
|
<tr th:if="${#lists.isEmpty(paiements)}">
|
||||||
|
<td colspan="6" class="py-8 text-center text-gray-500">Aucun paiement trouvé.</td>
|
||||||
|
</tr>
|
||||||
|
<tr th:each="p : ${paiements}" class="hover:bg-gray-50 transition-colors">
|
||||||
|
<td class="py-4 px-6 text-gray-600" th:text="${#temporals.format(p.datePaiement, 'dd/MM/yyyy')}">15/05/2026</td>
|
||||||
|
<td class="py-4 px-6 font-medium text-gray-900">
|
||||||
|
<a th:href="@{/adherents/{id}/edit(id=${p.licence.adherent.id})}"
|
||||||
|
class="text-blue-600 hover:text-blue-800 hover:underline"
|
||||||
|
th:text="${p.licence.adherent.prenom + ' ' + p.licence.adherent.nom}">Jean Dupont</a>
|
||||||
|
</td>
|
||||||
|
<td class="py-4 px-6 text-gray-600" th:text="${p.licence.categorie.nom}">U13</td>
|
||||||
|
<td class="py-4 px-6 text-center text-gray-600" th:text="${p.licence.saison.nom}">2024-2025</td>
|
||||||
|
<td class="py-4 px-6 text-gray-600">
|
||||||
|
<span class="px-2 py-0.5 rounded border border-gray-200 bg-gray-50 text-gray-700 text-xs"
|
||||||
|
th:text="${p.modePaiement.nom}">Chèque</span>
|
||||||
|
</td>
|
||||||
|
<td class="py-4 px-6 text-right font-semibold text-green-600" th:text="${p.montant + ' €'}">50.00 €</td>
|
||||||
|
</tr>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</form>
|
||||||
|
|
||||||
|
<!-- Pagination Footer -->
|
||||||
|
<div class="px-6 py-4 border-t border-gray-200 flex items-center justify-between bg-gray-50 text-sm text-gray-700">
|
||||||
|
<div th:if="${totalElements > 0}">
|
||||||
|
Affichage de <span class="font-semibold" th:text="${currentPage * pageSize + 1}">1</span> à
|
||||||
|
<span class="font-semibold" th:text="${T(java.lang.Math).min((currentPage + 1) * pageSize, totalElements)}">20</span> sur
|
||||||
|
<span class="font-semibold" th:text="${totalElements}">100</span> paiements
|
||||||
|
</div>
|
||||||
|
<div th:if="${totalElements == 0}">
|
||||||
|
Aucun paiement à afficher
|
||||||
|
</div>
|
||||||
|
<div class="flex items-center space-x-2" th:if="${totalPages > 1}">
|
||||||
|
<!-- Page Précédente -->
|
||||||
|
<button type="button"
|
||||||
|
th:if="${currentPage > 0}"
|
||||||
|
hx-get="/paiements"
|
||||||
|
hx-target="#paiements-table-container"
|
||||||
|
hx-select="#paiements-table-container"
|
||||||
|
hx-include="#filter-form"
|
||||||
|
th:attr="hx-vals=|{'page': ${currentPage - 1}}|"
|
||||||
|
class="px-3 py-1 border border-gray-300 rounded hover:bg-gray-100 transition-colors">
|
||||||
|
Précédent
|
||||||
|
</button>
|
||||||
|
<span th:if="${currentPage == 0}" class="px-3 py-1 border border-gray-200 rounded text-gray-400 bg-gray-50 cursor-not-allowed">
|
||||||
|
Précédent
|
||||||
|
</span>
|
||||||
|
|
||||||
|
<!-- Numéros de pages -->
|
||||||
|
<th:block th:each="pageNum : ${#numbers.sequence(0, totalPages - 1)}" th:if="${totalPages > 0}">
|
||||||
|
<button type="button"
|
||||||
|
hx-get="/paiements"
|
||||||
|
hx-target="#paiements-table-container"
|
||||||
|
hx-select="#paiements-table-container"
|
||||||
|
hx-include="#filter-form"
|
||||||
|
th:attr="hx-vals=|{'page': ${pageNum}}|"
|
||||||
|
th:text="${pageNum + 1}"
|
||||||
|
class="px-3 py-1 rounded transition-colors"
|
||||||
|
th:classappend="${currentPage == pageNum ? 'bg-blue-600 text-white' : 'border border-gray-300 hover:bg-gray-100'}">
|
||||||
|
1
|
||||||
|
</button>
|
||||||
|
</th:block>
|
||||||
|
|
||||||
|
<!-- Page Suivante -->
|
||||||
|
<button type="button"
|
||||||
|
th:if="${currentPage < totalPages - 1}"
|
||||||
|
hx-get="/paiements"
|
||||||
|
hx-target="#paiements-table-container"
|
||||||
|
hx-select="#paiements-table-container"
|
||||||
|
hx-include="#filter-form"
|
||||||
|
th:attr="hx-vals=|{'page': ${currentPage + 1}}|"
|
||||||
|
class="px-3 py-1 border border-gray-300 rounded hover:bg-gray-100 transition-colors">
|
||||||
|
Suivant
|
||||||
|
</button>
|
||||||
|
<span th:if="${currentPage == totalPages - 1}" class="px-3 py-1 border border-gray-200 rounded text-gray-400 bg-gray-50 cursor-not-allowed">
|
||||||
|
Suivant
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</main>
|
</main>
|
||||||
|
|||||||
Reference in New Issue
Block a user