Skip to content
Snippets Groups Projects
Commit c9973f3e authored by COULIBALY Aichatou's avatar COULIBALY Aichatou
Browse files

Gestion de comptabilité - coté patient

parent 82d7e8c5
No related branches found
No related tags found
No related merge requests found
......@@ -89,6 +89,16 @@ public class DatabaseSeeder implements CommandLineRunner {
Invoice invoice2 = new Invoice(appointment2, 200.00);
invoiceRepository.saveAll(List.of(invoice1, invoice2));
// Création de deux factures pour le patient1
Invoice invoice3 = new Invoice(appointment1, 120.00);
invoice3.setStatus(PaymentStatus.PAID);
Invoice invoice4 = new Invoice(appointment1, 80.00);
invoice4.setStatus(PaymentStatus.PAID);
invoiceRepository.saveAll(List.of(invoice3, invoice4));
System.out.println("Données insérées :");
System.out.println("Médecins : " + doctorRepository.count());
System.out.println("Patients : " + patientRepository.count());
......
......@@ -3,6 +3,7 @@ package com.projet.projetIndu.controllers;
import com.projet.projetIndu.entities.Invoice;
import com.projet.projetIndu.entities.PaymentStatus;
import com.projet.projetIndu.services.InvoiceService;
import com.projet.projetIndu.services.PatientService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
......@@ -19,6 +20,9 @@ public class InvoiceController {
@Autowired
private InvoiceService invoiceService;
@Autowired
private PatientService patientService;
@GetMapping("/invoices/{id}")
public String listInvoices(Model model) {
model.addAttribute("invoices", invoiceService.getAllInvoices());
......
package com.projet.projetIndu.controllers;
import com.projet.projetIndu.entities.Doctor;
import com.projet.projetIndu.entities.Invoice;
import com.projet.projetIndu.entities.Patient;
import com.projet.projetIndu.services.DoctorService;
import com.projet.projetIndu.services.InvoiceService;
import com.projet.projetIndu.services.PatientService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
......@@ -16,8 +18,10 @@ import java.util.Optional;
public class PatientController {
private final PatientService patientService;
private final DoctorService doctorService;
private final InvoiceService invoiceService;
public PatientController(PatientService patientService, DoctorService doctorService) {
public PatientController(InvoiceService invoiceService, PatientService patientService, DoctorService doctorService) {
this.invoiceService = invoiceService;
this.patientService = patientService;
this.doctorService = doctorService;
}
......@@ -69,4 +73,31 @@ public class PatientController {
model.addAttribute("doctors", doctors);
return "doctors";
}
// ✅ Correction : Changement du mapping pour éviter le conflit
@GetMapping("/{id}/invoices")
public String listPatientInvoices(@PathVariable Long id, Model model) {
List<Invoice> invoices = invoiceService.getInvoicesByPatientId(id);
model.addAttribute("invoices", invoices);
return "patient-invoices"; // Page HTML affichant les factures
}
@PostMapping("/{id}/pay")
public String payInvoice(@PathVariable Long id) {
invoiceService.markAsPaid(id);
return "redirect:/patients/" + id + "/invoices";
}
@GetMapping("/invoices")
public String listAuthenticatedPatientInvoices(Model model) {
Patient patient = patientService.getAuthenticatedPatient();
if (patient == null) {
return "redirect:/login";
}
List<Invoice> invoices = invoiceService.getInvoicesByPatientId(patient.getId());
model.addAttribute("invoices", invoices);
return "patient-invoices"; // Page HTML affichant les factures
}
}
......@@ -13,6 +13,7 @@ import java.util.List;
@Repository
public interface InvoiceRepository extends JpaRepository<Invoice, Long> {
List<Invoice> findByStatus(PaymentStatus status);
List<Invoice> findByAppointmentPatientId(Long patientId);
List<Invoice> findByAppointment_Doctor_Id(Long doctorId);
List<Invoice> findByIssueDateBetween(LocalDate startDate, LocalDate endDate);
}
......
......@@ -56,6 +56,9 @@ public class InvoiceService {
.orElseThrow(() -> new RuntimeException("Médecin introuvable"));
return invoiceRepository.findByAppointment_Doctor_Id(doctor.getId());
}
public List<Invoice> getInvoicesByPatientId(Long patientId) {
return invoiceRepository.findByAppointmentPatientId(patientId);
}
public List<Invoice> getInvoicesByPeriod(LocalDate startDate, LocalDate endDate) {
......
......@@ -73,4 +73,22 @@ public class PatientService {
}
return null;
}
public Patient getAuthenticatedPatient() {
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
if (authentication != null && authentication.isAuthenticated()) {
String username = authentication.getName(); // Cela pourrait être l'email ou un autre identifiant
Optional<Patient> patientOpt = patientRepository.findByEmail(username);
if (patientOpt.isPresent()) {
return patientOpt.get(); // Retourne le Patient trouvé
} else {
throw new RuntimeException("Patient non trouvé");
}
}
return null;
}
}
......@@ -46,6 +46,13 @@
<h3 class="text-xl font-semibold text-blue-800">📅 Mes Rendez-vous</h3>
<p class="mt-2 text-gray-600">Voir et gérer vos rendez-vous.</p>
</a>
<a href="/patients/invoices" class="p-6 bg-white shadow-md rounded-lg hover:shadow-lg transition border border-blue-300">
<h3 class="text-xl font-semibold text-blue-800">💳 Mes Factures</h3>
<p class="mt-2 text-gray-600">Voir et gérer vos factures.</p>
</a>
</div>
</div>
......
<!DOCTYPE html>
<html lang="fr" xmlns:th="http://www.w3.org/1999/xhtml">
<head>
<meta charset="UTF-8">
<title>Factures</title>
<script src="https://cdn.tailwindcss.com"></script>
</head>
<body class="bg-gray-100 font-sans leading-normal tracking-normal">
<header class="bg-white shadow-md">
<div class="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8">
<div class="flex justify-between items-center py-6">
<h1 class="text-2xl font-semibold text-gray-900">📜 Mes Factures</h1>
<a href="/patients/dashboard" class="text-blue-500 hover:text-blue-700">Retour au tableau de bord</a>
</div>
</div>
</header>
<main class="mt-12">
<div class="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8">
<table class="table-auto w-full border-collapse border border-gray-300">
<thead>
<tr class="bg-gray-200">
<th class="border border-gray-300 px-4 py-2">ID</th>
<th class="border border-gray-300 px-4 py-2">Montant</th>
<th class="border border-gray-300 px-4 py-2">Statut</th>
</tr>
</thead>
<tbody>
<tr th:each="invoice : ${invoices}">
<td class="border border-gray-300 px-4 py-2" th:text="${invoice.id}"></td>
<td class="border border-gray-300 px-4 py-2" th:text="${invoice.amount} + ' €'"></td>
<td class="border border-gray-300 px-4 py-2">
<span th:text="${invoice.status}"
th:classappend="${invoice.status == 'PAID' ? 'text-yellow-500' :
invoice.status == 'PAID' ? 'text-green-500' : 'text-red-500'}">
</span>
</td>
<td class="border border-gray-300 px-4 py-2">
<form th:if="${invoice.status == 'PENDING'}"
th:action="@{/patients/invoices/{id}/pay(id=${invoice.id})}" method="post">
<button type="submit" class="bg-green-500 hover:bg-green-700 text-white font-bold py-1 px-4 rounded">
Payer
</button>
</form>
</td>
</tr>
</tbody>
</table>
</div>
</main>
</body>
</html>
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment