Để phát triển chức năng gửi tiền dịch vụ của phòng cho đại diện phòng, chúng ta cần thực hiện các bước sau:
Bước 1: Tạo API để lấy thông tin đại diện phòng
Trong file TenantsController.java, thêm một phương thức để lấy thông tin đại diện phòng dựa trên ID phòng:
[Redacted
@GetMapping("/representative/{roomId}")
public ResponseEntity<Tenants> getRepresentative(@PathVariable int roomId) {
Tenants representative = _tenantsService.getRepresentative(roomId);
if (representative != null) {
return ResponseEntity.ok(representative);
}
return ResponseEntity.notFound().build();
}
Bước 2: Tạo API để gửi tiền dịch vụ
Trong file InvoicesController.java, thêm một phương thức để gửi tiền dịch vụ cho đại diện phòng:
[Redacted
@PostMapping("/send-service-fee")
public ResponseEntity<String> sendServiceFee(@RequestBody InvoiceRequest request) {
// Lấy thông tin đại diện phòng
Tenants representative = _tenantsService.getRepresentative(request.getRoomId());
if (representative == null) {
return ResponseEntity.badRequest().body("Không tìm thấy đại diện phòng");
}
// Tạo hóa đơn mới
Invoices invoice = _invoicesService.createInvoice(request.getTotal(), representative.getRoom());
// Gửi email cho đại diện phòng
String email = representative.getEmail();
String message = "Hóa đơn tiền dịch vụ cho phòng " + representative.getRoom().getRoomNumber();
emailService.sendEmail(email, "Hóa Đơn Tiền Dịch Vụ", message);
return ResponseEntity.ok("Hóa đơn đã được gửi đến đại diện phòng");
}
Bước 3: Tạo giao diện để chọn nhà và phòng
Trong file RoomManager.js, thêm một nút để chọn nhà và phòng:
Chúng ta đã phát triển chức năng gửi tiền dịch vụ của phòng cho đại diện phòng. Khi chọn nhà và phòng, hệ thống sẽ hiển thị email của đại diện phòng. Khi bấm gửi, hệ thống sẽ tạo hóa đơn mới và gửi email cho đại diện phòng.