From c8fc300c4c2d4aae718576f871dd39543916fa6d Mon Sep 17 00:00:00 2001 From: AJITHKUMAR12 <48044092+AJITHKUMAR12@users.noreply.github.com> Date: Wed, 30 Sep 2026 17:56:38 +0530 Subject: [PATCH] implemented few more modules under sm login --- .../controller/SmController.java | 946 ++++++++- .../resources/templates/fragments/smMenu.html | 72 +- .../templates/sm/approval-history.html | 445 ++++ .../resources/templates/sm/booking-list.html | 725 +++++++ .../templates/sm/bookingwaiting.html | 817 +++++++ .../templates/sm/collection-pending.html | 741 +++++++ .../templates/sm/gccblocking-new.html | 1054 +++++++++ .../resources/templates/sm/gccblocking.html | 1412 ++++++++++++ .../templates/sm/halldetailslist.html | 1888 +++++++++++++++++ .../templates/sm/headquarterspage.html | 552 +++++ .../templates/sm/login-creation.html | 1543 ++++++++++++++ .../resources/templates/sm/ongoingevents.html | 1065 ++++++++++ .../templates/sm/refund-failedlist.html | 1781 ++++++++++++++++ .../resources/templates/sm/rejected-list.html | 569 +++++ .../templates/sm/settlement-approved.html | 1456 +++++++++++++ .../templates/sm/settlement-completed.html | 1283 +++++++++++ .../templates/sm/settlement-initiate.html | 1395 ++++++++++++ .../templates/sm/settlement-list.html | 1780 ++++++++++++++++ .../templates/sm/settlement-reject.html | 764 +++++++ .../templates/sm/settlementlist.html | 740 +++++++ .../sm/sixmonthold-transactions.html | 1732 +++++++++++++++ .../resources/templates/sm/user-approved.html | 295 +++ .../resources/templates/sm/user-reject.html | 349 +++ .../resources/templates/sm/viewUploadNoc.html | 856 ++++++++ 24 files changed, 24218 insertions(+), 42 deletions(-) create mode 100644 src/main/resources/templates/sm/approval-history.html create mode 100644 src/main/resources/templates/sm/booking-list.html create mode 100644 src/main/resources/templates/sm/bookingwaiting.html create mode 100644 src/main/resources/templates/sm/collection-pending.html create mode 100644 src/main/resources/templates/sm/gccblocking-new.html create mode 100644 src/main/resources/templates/sm/gccblocking.html create mode 100644 src/main/resources/templates/sm/halldetailslist.html create mode 100644 src/main/resources/templates/sm/headquarterspage.html create mode 100644 src/main/resources/templates/sm/login-creation.html create mode 100644 src/main/resources/templates/sm/ongoingevents.html create mode 100644 src/main/resources/templates/sm/refund-failedlist.html create mode 100644 src/main/resources/templates/sm/rejected-list.html create mode 100644 src/main/resources/templates/sm/settlement-approved.html create mode 100644 src/main/resources/templates/sm/settlement-completed.html create mode 100644 src/main/resources/templates/sm/settlement-initiate.html create mode 100644 src/main/resources/templates/sm/settlement-list.html create mode 100644 src/main/resources/templates/sm/settlement-reject.html create mode 100644 src/main/resources/templates/sm/settlementlist.html create mode 100644 src/main/resources/templates/sm/sixmonthold-transactions.html create mode 100644 src/main/resources/templates/sm/user-approved.html create mode 100644 src/main/resources/templates/sm/user-reject.html create mode 100644 src/main/resources/templates/sm/viewUploadNoc.html diff --git a/src/main/java/com/gcc/communityHall/controller/SmController.java b/src/main/java/com/gcc/communityHall/controller/SmController.java index 28751f79..a5ce859f 100644 --- a/src/main/java/com/gcc/communityHall/controller/SmController.java +++ b/src/main/java/com/gcc/communityHall/controller/SmController.java @@ -305,6 +305,7 @@ public class SmController { return "redirect:/communityhall/login"; } } + private List handleBookingHallDetailsReportRequest(String request, String fromDate, String toDate, String filterby, String zone, String division, Integer hallid) { if (!request.equals("5")) { @@ -326,7 +327,8 @@ public class SmController { return new ArrayList<>(); } - private List handleUserRequest(String request, String fromDate, String toDate, String userstatus, + + private List handleUserRequest(String request, String fromDate, String toDate, String userstatus, String usertype) { if (!request.equals("1")) { return new ArrayList<>(); @@ -424,8 +426,6 @@ public class SmController { return new ArrayList<>(); } - - @GetMapping("/logout") public String viewLogout(Model model, HttpSession session) { session.invalidate(); @@ -433,14 +433,948 @@ public class SmController { return "redirect:/communityhall/login"; } - + @GetMapping("/approval-history") + public String viewApproval(Model model, HttpSession session) { + String headquartersname = (String) session.getAttribute("usertype"); + if (headquartersname != null && "sm".equals(headquartersname)) { + long mobileno = (long) session.getAttribute("mobileno"); + model.addAttribute("mobileno", mobileno); + model.addAttribute("headquartersname", headquartersname); + model.addAttribute("title", "approvalcontrol"); + List Pending = usersRepository.getPendingList(); + String zone = (String) session.getAttribute("zone"); + model.addAttribute("zone", zone); + model.addAttribute("pendinglist", Pending); + return "sm/approval-history"; + } else { + session.invalidate(); // Invalidate the session to clear all session attributes + return "redirect:/communityhall/login"; + } + } + + @GetMapping("/user-approved") + public String viewUserApproved(Model model, HttpSession session) { + String headquartersname = (String) session.getAttribute("usertype"); + if (headquartersname != null && "sm".equals(headquartersname)) { + long mobileno = (long) session.getAttribute("mobileno"); + model.addAttribute("mobileno", mobileno); + model.addAttribute("headquartersname", headquartersname); + model.addAttribute("title", "reasondetails"); + List approved = usersRepository.getUserApproved(); + String zone = (String) session.getAttribute("zone"); + model.addAttribute("zone", zone); + model.addAttribute("approvedlist", approved); + return "sm/user-approved"; + } else { + session.invalidate(); // Invalidate the session to clear all session attributes + return "redirect:/communityhall/login"; + } + } + + @GetMapping("/user-reject") + public String viewUserReject(Model model, HttpSession session) { + String headquartersname = (String) session.getAttribute("usertype"); + if (headquartersname != null && "sm".equals(headquartersname)) { + long mobileno = (long) session.getAttribute("mobileno"); + model.addAttribute("mobileno", mobileno); + model.addAttribute("headquartersname", headquartersname); + model.addAttribute("title", "reasondetails"); + List reject = usersRepository.getUserReject(); + String zone = (String) session.getAttribute("zone"); + model.addAttribute("zone", zone); + model.addAttribute("rejectedlist", reject); + return "sm/user-reject"; + } else { + session.invalidate(); // Invalidate the session to clear all session attributes + return "redirect:/communityhall/login"; + } + } + + @GetMapping("/ongoingevents") + public String viewRecentevents(Model model, HttpSession session) { + String headquartersname = (String) session.getAttribute("usertype"); + if (headquartersname != null && "sm".equals(headquartersname)) { + long mobileno = (long) session.getAttribute("mobileno"); + model.addAttribute("mobileno", mobileno); + List presenteventslist = bookingDetailsRepository.findPresentBookingList(); + List pasteventslist = bookingDetailsRepository.findPastEventsList(); + List futureeventslist = bookingDetailsRepository.findFutureEventsList(); + model.addAttribute("title", "settlement initiate"); + model.addAttribute("headquartersname", headquartersname); + model.addAttribute("presenteventslist", presenteventslist); + model.addAttribute("pasteventslist", pasteventslist); + model.addAttribute("futureeventslist", futureeventslist); + return "sm/ongoingevents"; + } else { + session.invalidate(); // Invalidate the session to clear all session attributes + return "redirect:/communityhall/login"; + } + } + + @GetMapping("/booking-list") + public String viewBookingList(Model model, HttpSession session) { + String headquartersname = (String) session.getAttribute("usertype"); + if (headquartersname != null && "sm".equals(headquartersname)) { + long mobileno = (long) session.getAttribute("mobileno"); + model.addAttribute("mobileno", mobileno); + model.addAttribute("headquartersname", headquartersname); + List bookingList = bookingDetailsRepository.getAllApprovedList(); + model.addAttribute("bookingList", bookingList); + return "sm/booking-list"; // Assuming "officer/rejected-booking-list" is the name of your HTML + // template + } else { + session.invalidate(); // Invalidate the session to clear all session attributes + return "redirect:/communityhall/login"; + } + } + @GetMapping("/rejected-list") + public String viewRejectedBookings(Model model, HttpSession session) { + String headquartersname = (String) session.getAttribute("usertype"); + if (headquartersname != null && "sm".equals(headquartersname)) { + long mobileno = (long) session.getAttribute("mobileno"); + model.addAttribute("mobileno", mobileno); + model.addAttribute("headquartersname", headquartersname); + List rejectedBookings = bookingDetailsRepository.getAllRejectingList(); + model.addAttribute("rejectedBookings", rejectedBookings); + return "sm/rejected-list"; + } else { + session.invalidate(); // Invalidate the session to clear all session attributes + return "redirect:/communityhall/login"; + } + } + @GetMapping("/bookingwaitinglist") + public String viewWaitingBookings(Model model, HttpSession session) { + String headquartersname = (String) session.getAttribute("usertype"); + if (headquartersname != null && "sm".equals(headquartersname)) { + long mobileno = (long) session.getAttribute("mobileno"); + model.addAttribute("mobileno", mobileno); + model.addAttribute("headquartersname", headquartersname); + List waitingBookings = bookingDetailsRepository.getAllwaitingList(); + model.addAttribute("waitingBookings", waitingBookings); + return "sm/bookingwaiting"; + } else { + session.invalidate(); // Invalidate the session to clear all session attributes + return "redirect:/communityhall/login"; + } + } + @GetMapping("/settlement-approved") + public String viewSettlementMaster(Model model, HttpSession session) { + String headquartersname = (String) session.getAttribute("usertype"); + if (headquartersname != null && "sm".equals(headquartersname)) { + long mobileno = (long) session.getAttribute("mobileno"); + model.addAttribute("mobileno", mobileno); + List approvedSettlements = bookingDetailsRepository.findAllWithApprovedRefundStatus(); + List settlements = new ArrayList<>(); + settlements.addAll(approvedSettlements); + List approvedcancelledbookings = bookingDetailsRepository.findCancelledList(); + List approvedrejectedbookings = bookingDetailsRepository.findRejectedList(); + model.addAttribute("headquartersname", headquartersname); + model.addAttribute("settlementlist", settlements); + model.addAttribute("approvedcancelledbookings", approvedcancelledbookings); + model.addAttribute("approvedrejectedbookings", approvedrejectedbookings); + return "sm/settlement-approved"; + } else { + session.invalidate(); // Invalidate the session to clear all session attributes + return "redirect:/communityhall/login"; + } + } + + @GetMapping("/settlement-initiatedlist") + public String viewSettlementInitiatedMaster(Model model, HttpSession session) { + String headquartersname = (String) session.getAttribute("usertype"); + if (headquartersname != null && "sm".equals(headquartersname)) { + long mobileno = (long) session.getAttribute("mobileno"); + model.addAttribute("mobileno", mobileno); + List settlement = bookingDetailsRepository.findByBookingDetailsRefundStatus(); + List Initiatedcancelledbookings = bookingDetailsRepository.findInitiatedCancelledList(); + List Initiatedrejectedbookings = bookingDetailsRepository.findInitiatedRejectedList(); + model.addAttribute("title", "settlement initiate"); + model.addAttribute("headquartersname", headquartersname); + model.addAttribute("settlementlist", settlement); + model.addAttribute("Initiatedcancelledbookings", Initiatedcancelledbookings); + model.addAttribute("Initiatedrejectedbookings", Initiatedrejectedbookings); + return "sm/settlement-initiate"; + } else { + session.invalidate(); // Invalidate the session to clear all session attributes + return "redirect:/communityhall/login"; + } + } + + @GetMapping("/settlement-list") + public String settlementPendingList(Model model, HttpSession session) { + String headquartersname = (String) session.getAttribute("usertype"); + if (headquartersname != null && "sm".equals(headquartersname)) { + model.addAttribute("headquartersname", headquartersname); + long mobileno = (long) session.getAttribute("mobileno"); + model.addAttribute("mobileno", mobileno); + model.addAttribute("title", "settlement Pending"); + String zone = (String) session.getAttribute("zone"); + model.addAttribute("zone", zone); + // ak + List settlementIntiated = bookingDetailsRepository.findSettlementInitiatedPending(); + List settlement = bookingDetailsRepository.findAllSettlementPending(); + List cancelledbookings = bookingDetailsRepository.findAllSettlementCancelledList(); + List rejectedbookings = bookingDetailsRepository.findAllSettlementRejectedList(); + model.addAttribute("settlementlist", settlement); + // AK + model.addAttribute("settlementIntiated", settlementIntiated); + model.addAttribute("cancelledbookings", cancelledbookings); + model.addAttribute("rejectedbookings", rejectedbookings); + return "sm/settlement-list"; + } else { + session.invalidate(); + return "redirect:/communityhall/login"; + } + } + + @GetMapping("/refundfailed-list") + public String RefundFailedList(Model model, HttpSession session) { + String headquartersname = (String) session.getAttribute("usertype"); + if (headquartersname != null && "sm".equals(headquartersname)) { + model.addAttribute("headquartersname", headquartersname); + long mobileno = (long) session.getAttribute("mobileno"); + model.addAttribute("mobileno", mobileno); + model.addAttribute("title", "settlementapproved"); + String zone = (String) session.getAttribute("zone"); + model.addAttribute("zone", zone); + List settlementrefundfailed = bookingDetailsRepository.findAllSettlementRefundFailed(); + List refundfailedcancelledbookings = bookingDetailsRepository + .findAllRefundFaileCancelledList(); + List refundfailedrejectedbookings = bookingDetailsRepository + .findAllRefundFaileRejectedList(); + model.addAttribute("settlementrefundfailed", settlementrefundfailed); + model.addAttribute("refundfailedcancelledbookings", refundfailedcancelledbookings); + model.addAttribute("refundfailedrejectedbookings", refundfailedrejectedbookings); + return "sm/refund-failedlist"; + } else { + session.invalidate(); + return "redirect:/communityhall/login"; + } + } + + @GetMapping("/settlement-completedlist") + public String viewSettlementcompletedMaster(Model model, HttpSession session) { + String headquartersname = (String) session.getAttribute("usertype"); + if (headquartersname != null && "sm".equals(headquartersname)) { + long mobileno = (long) session.getAttribute("mobileno"); + model.addAttribute("mobileno", mobileno); + List completedlist = bookingDetailsRepository.findSettlementCompletedList(); + List cancelledcompletedlist = bookingDetailsRepository.findCancelledCompletedList(); + List rejectedcompletedlist = bookingDetailsRepository.findRejectedSettlementCompletedList(); + model.addAttribute("title", "settlement initiate"); + model.addAttribute("headquartersname", headquartersname); + model.addAttribute("completedlist", completedlist); + model.addAttribute("cancelledcompletedlist", cancelledcompletedlist); + model.addAttribute("rejectedcompletedlist", rejectedcompletedlist); + return "sm/settlement-completed"; + } else { + session.invalidate(); // Invalidate the session to clear all session attributes + return "redirect:/communityhall/login"; + } + } + + @GetMapping("/settlementlist") + public String viewSettlementList(Model model, HttpSession session) { + String headquartersname = (String) session.getAttribute("usertype"); + if (headquartersname != null && "sm".equals(headquartersname)) { + List settlemetList = bookingDetailsRepository.getAllSettlementList(); + model.addAttribute("headquartersname", headquartersname); + model.addAttribute("settlemetList", settlemetList); + return "sm/settlementlist"; + } else { + session.invalidate(); + return "redirect:/communityhall/login"; + } + } + + @GetMapping("/headquarterspage") + public String viewcaretaker(Model model, HttpSession session, @RequestParam("bookingId") int bookingId) { + String caretakerName = (String) session.getAttribute("usertype"); + if (caretakerName != null && "sm".equals(caretakerName)) { + long mobileno = (long) session.getAttribute("mobileno"); + model.addAttribute("mobileno", mobileno); + model.addAttribute("caretakerName", caretakerName); + model.addAttribute("title", "caretaker"); + model.addAttribute("baseURL", appConfig.getBaseUrl()); + BookingDetails booking = bookingService.getBookingsById(bookingId); + model.addAttribute("booking", booking); + return "sm/headquarterspage"; + } else { + session.invalidate(); + return "redirect:/communityhall/login"; + } + } + + @GetMapping("/settlement-reject") + public String settlementRejectedList(Model model, HttpSession session) { + String headquartersname = (String) session.getAttribute("usertype"); + if (headquartersname != null && "sm".equals(headquartersname)) { + List settlement = bookingDetailsRepository.findAllSettlementRejected(); + model.addAttribute("headquartersname", headquartersname); + model.addAttribute("title", "Settlement Rejected"); + model.addAttribute("rejectSettlementlist", settlement); + return "sm/settlement-reject"; + } else { + session.invalidate(); + return "redirect:/communityhall/login"; + } + } + + @GetMapping("/Gccblocking") + public String viewGccBlocking(Model model, HttpSession session) { + String headquartersname = (String) session.getAttribute("usertype"); + if (headquartersname != null && "sm".equals(headquartersname)) { + long mobileno = (long) session.getAttribute("mobileno"); + model.addAttribute("mobileno", mobileno); + model.addAttribute("headquartersname", headquartersname); + // Fetch all blocked GCC dates + List gccBlocked = blockingDateRepository.findAllBlocked(); + + // Ensure distinct by hallId, blockingReason, startDate, and endDate + List uniqueGccBlockingDates = gccBlocked.stream() + .filter(distinctByKey(g -> Arrays.asList( + g.getHallId(), + g.getBlockingReason(), + g.getStartDate(), + g.getEndDate()))) + .collect(Collectors.toList()); + + // Map to store the count of blocked halls for each GccBlockingDate + Map hallCountMap = new HashMap<>(); + for (GccBlockingDate blockedDate : uniqueGccBlockingDates) { + // Parse and count unique hall IDs + String hallIds = blockedDate.getHallId(); + if (hallIds != null && !hallIds.isEmpty()) { + Set uniqueHallIds = new HashSet<>(Arrays.asList(hallIds.split(","))); + int hallCount = uniqueHallIds.size(); + hallCountMap.put(blockedDate.getBlockingId(), hallCount); + } else { + hallCountMap.put(blockedDate.getBlockingId(), 0); // No halls blocked + } + } + + // Add attributes to the model for the view + model.addAttribute("gccblocked", uniqueGccBlockingDates); + model.addAttribute("hallCountMap", hallCountMap); + + return "sm/gccblocking"; + } else { + session.invalidate(); // Invalidate the session to clear all session attributes + return "redirect:/communityhall/login"; + } + } + + // ── New enhanced GCC Blocking page (does NOT affect the existing page) ── + @GetMapping("/GccblockingNew") + public String viewGccBlockingNew(Model model, HttpSession session) { + String headquartersname = (String) session.getAttribute("usertype"); + if (headquartersname != null && "sm".equals(headquartersname)) { + long mobileno = (long) session.getAttribute("mobileno"); + model.addAttribute("mobileno", mobileno); + model.addAttribute("headquartersname", headquartersname); + return "sm/gccblocking-new"; + } else { + session.invalidate(); + return "redirect:/communityhall/login"; + } + } + + // Utility method to ensure distinct by a key + private static Predicate distinctByKey(Function keyExtractor) { + Set seen = new HashSet<>(); + return t -> seen.add(keyExtractor.apply(t)); + } + + @GetMapping("/viewUploadNoc") + public String viewUploadNoc(Model model, HttpSession session) { + String headquartersname = (String) session.getAttribute("usertype"); + if (headquartersname != null && "sm".equals(headquartersname)) { + long mobileno = (long) session.getAttribute("mobileno"); + model.addAttribute("mobileno", mobileno); + model.addAttribute("headquartersname", headquartersname); + + // Fetch waiting bookings + List waitingBookings = bookingDetailsRepository.getAllwaitingNOC(); + // System.out.println("Waiting Bookings: " + waitingBookings.size()); + model.addAttribute("waitingBookings", waitingBookings); + + return "sm/viewUploadNoc"; + } else { + session.invalidate(); // Invalidate the session to clear all session attributes + return "redirect:/communityhall/login"; + } + } + + // Newly added by kani for care-take and officer login creation 11/06/2026 + + @GetMapping("/login-creation") + public String viewLoginCreation(Model model, HttpSession session) { + String headquartersname = (String) session.getAttribute("usertype"); + if (headquartersname != null && "sm".equals(headquartersname)) { + long mobileno = (long) session.getAttribute("mobileno"); + model.addAttribute("mobileno", mobileno); + model.addAttribute("headquartersname", headquartersname); + + // Fetch existing active non-admin logins (returns projection, not full entity) + List> loginList = loginRepository.findActiveLogins(); + model.addAttribute("loginList", loginList); + + // Fetch hall details for the modal dropdown + List> hallList = hallDetailsRepository.getAllHalls(); + model.addAttribute("hallList", hallList); + + return "sm/login-creation"; + } else { + session.invalidate(); + return "redirect:/communityhall/login"; + } + } + + @PostMapping("/login-creation/save") + @ResponseBody + @Transactional + public Map saveLoginCreation( + @RequestParam("mobileNumber") long mobileNumber, + @RequestParam("name") String name, + @RequestParam("password") String password, + @RequestParam("userType") String userType, + @RequestParam("zone") String zone, + @RequestParam(value = "hallIds", required = false) List hallIds, + HttpSession session) { + + Map response = new HashMap<>(); + String headquartersname = (String) session.getAttribute("usertype"); + if (headquartersname == null && "sm".equals(headquartersname)) { + response.put("status", "error"); + response.put("message", "Session expired. Please log in again."); + return response; + } + try { + /* -------- Duplicate hall check for counter / caretaker -------- */ + boolean isSingleMode = "counter".equals(userType) || "caretaker".equals(userType); + boolean isMulitpleMode = "officer".equals(userType); + if (isSingleMode && hallIds != null && !hallIds.isEmpty()) { + int hallId = hallIds.get(0); + int existingCount = loginRepository.countActiveLoginsByHallId(hallId, userType); + if (existingCount > 0) { + // Fetch hall name for a clear message + String hallName = hallId + ""; + try { + String fetched = hallDetailsRepository.findHallNameById(hallId); + if (fetched != null && !fetched.isBlank()) + hallName = fetched; + } catch (Exception ignored) { + } + response.put("status", "error"); + response.put("message", "A login already exists for hall \"" + hallName + + "\". Only one counter/caretaker login is allowed per hall."); + return response; + } + } + + /* -------- Duplicate hall check for officer -------- */ + if (isMulitpleMode && hallIds != null && !hallIds.isEmpty()) { + int existingCount = loginRepository.getActiveLoginsByHallIds(hallIds, userType); + if (existingCount > 0) { + response.put("status", "error"); + response.put("message", + "A login already exists for the selected hall(s). Only one officer login is allowed per hall."); + return response; + } + } + + Login login = new Login(); + login.setMobileNumber(mobileNumber); + login.setName(name); + login.setPassword(password); + login.setUserType(userType); + login.setZone(zone); + login.setActive(true); + login.setDelete(false); + + if (hallIds == null || hallIds.isEmpty()) { + // HQ may have no hall assigned + loginRepository.save(login); + } else if (hallIds.size() == 1) { + // Single hall: store directly in login.hallId + login.setHallId(hallIds.get(0)); + loginRepository.save(login); + } else { + // Multiple halls: store first in hallId, rest in login_hall_ids + login.setHallId(hallIds.get(0)); + Login savedLogin = loginRepository.save(login); + for (int hallId : hallIds) { + LoginHallId loginHallId = new LoginHallId(savedLogin, hallId); + loginHallIdRepository.save(loginHallId); + } + } + + response.put("status", "success"); + response.put("message", "Login created successfully."); + } catch (Exception e) { + response.put("status", "error"); + response.put("message", "Error creating login: " + e.getMessage()); + } + return response; + } + + @PostMapping("/login-creation/delete/{id}") + @ResponseBody + @Transactional + public Map deleteLogin(@PathVariable("id") int id, HttpSession session) { + Map response = new HashMap<>(); + String headquartersname = (String) session.getAttribute("usertype"); + if (headquartersname == null && "headquarters".equals(headquartersname)) { + response.put("status", "error"); + response.put("message", "Session expired. Please log in again."); + return response; + } + try { + Login login = loginRepository.findLoginById(id); + if (login == null) { + response.put("status", "error"); + response.put("message", "Login not found."); + return response; + } + // Soft delete: set is_active = 0, is_delete = 1 + login.setActive(false); + login.setDelete(true); + loginRepository.save(login); + + // Also soft-delete any related login_hall_ids + loginHallIdRepository.softDeleteByLoginId(id); + + response.put("status", "success"); + response.put("message", "Login deleted successfully."); + } catch (Exception e) { + response.put("status", "error"); + response.put("message", "Error deleting login: " + e.getMessage()); + } + return response; + } + + @GetMapping("/login-creation/check-mobile") + @ResponseBody + public Map checkMobileExists(@RequestParam("mobileNumber") long mobileNumber, HttpSession session) { + Map response = new HashMap<>(); + try { + int count = loginRepository.countByMobileNumber(mobileNumber); + response.put("exists", count > 0); + } catch (Exception e) { + response.put("exists", false); + response.put("error", e.getMessage()); + } + return response; + } + + @GetMapping("/login-creation/halls-by-zone") + @ResponseBody + public List> getHallsByZone(@RequestParam("zone") String zone, HttpSession session) { + try { + return hallDetailsRepository.getHallsByZone(zone); + } catch (Exception e) { + return new java.util.ArrayList<>(); + } + } + + @GetMapping("/login-creation/get-login-halls") + @ResponseBody + public Map getLoginHalls(@RequestParam("loginId") int loginId, HttpSession session) { + Map response = new HashMap<>(); + try { + Login login = loginRepository.findLoginById(loginId); + if (login == null) { + response.put("status", "error"); + response.put("message", "Login not found."); + return response; + } + // Collect all assigned hall IDs + java.util.List assignedHallIds = new java.util.ArrayList<>(); + if (login.getHallId() != 0) { + assignedHallIds.add(login.getHallId()); + } + loginHallIdRepository.findActiveByLoginId(loginId).forEach(lh -> assignedHallIds.add(lh.getHallId())); + + response.put("status", "success"); + response.put("loginId", loginId); + response.put("name", login.getName()); + response.put("zone", login.getZone()); + response.put("userType", login.getUserType()); + response.put("assignedHallIds", assignedHallIds); + // Also return all halls for the zone + response.put("hallsForZone", hallDetailsRepository.getHallsByZone(login.getZone())); + } catch (Exception e) { + response.put("status", "error"); + response.put("message", "Error fetching login halls: " + e.getMessage()); + } + return response; + } + + @PostMapping("/login-creation/update-halls") + @ResponseBody + @Transactional + public Map updateLoginHalls( + @RequestParam("loginId") int loginId, + @RequestParam("hallIds") java.util.List hallIds, + HttpSession session) { + Map response = new HashMap<>(); + try { + Login login = loginRepository.findLoginById(loginId); + if (login == null) { + response.put("status", "error"); + response.put("message", "Login not found."); + return response; + } + if (hallIds == null || hallIds.isEmpty()) { + response.put("status", "error"); + response.put("message", "At least one hall must be selected."); + return response; + } + + // Clear all existing login_hall_ids rows for this login + loginHallIdRepository.softDeleteByLoginId(loginId); + + if (hallIds.size() == 1) { + // Single hall: store in login.hall_id only + login.setHallId(hallIds.get(0)); + loginRepository.save(login); + } else { + // Multiple halls: first goes to login.hall_id, rest to login_hall_ids + login.setHallId(hallIds.get(0)); + loginRepository.save(login); + for (int i = 1; i < hallIds.size(); i++) { + LoginHallId lh = new LoginHallId(login, hallIds.get(i)); + loginHallIdRepository.save(lh); + } + } + response.put("status", "success"); + response.put("message", "Hall assignment updated successfully."); + } catch (Exception e) { + response.put("status", "error"); + response.put("message", "Error updating halls: " + e.getMessage()); + } + return response; + } + + // hall creation newly added by kanimozhi 15062026 + @PostMapping("/saveHallDetails") + public String saveHall( + @RequestParam String hallName, + @RequestParam float depositAmount, + @RequestParam float halfdepositAmt, + @RequestParam float halfDayAmt, + @RequestParam float fullDayAmt, + @RequestParam float gst, + @RequestParam float hallArea, + @RequestParam String ebNumber, + @RequestParam float ebCostPerUnit, + @RequestParam String parkingCapacity, + @RequestParam int seatingCapacity, + @RequestParam String doorNo, + @RequestParam String street, + @RequestParam String area, + @RequestParam String zone, + @RequestParam String division, + @RequestParam(required = false) String landMark, + @RequestParam String city, + @RequestParam int pinCode, + @RequestParam(required = false) String latitude, + @RequestParam(required = false) String longitude, + @RequestParam String hallInchargeName, + @RequestParam long hallInchargeNo, + @RequestParam("hallImages") MultipartFile[] hallImages, + @RequestParam(value = "floorName", required = false) List floorNames, + @RequestParam(value = "floorCapacity", required = false) List floorCapacities, + @RequestParam(value = "mfDtUnit", defaultValue = "1") int mfDtUnit, + HttpSession session) { + + String updatedId = (String) session.getAttribute("employeeId"); + hallDetailService.saveHallByHQ(hallName, depositAmount, halfDayAmt, fullDayAmt, gst, hallArea, ebNumber, + ebCostPerUnit, parkingCapacity, seatingCapacity, doorNo, + street, area, zone, division, landMark, city, pinCode, latitude, longitude, hallInchargeName, + hallInchargeNo, updatedId, hallImages, halfdepositAmt, floorNames, floorCapacities, mfDtUnit); + + return "redirect:/communityhall/sm/halldetailslist"; + } + + @GetMapping("/halldetailslist") + public String viewhalldetailsList(Model model, HttpSession session) { + List list = hallDetailsRepository.findAll(); + String headquartersname = (String) session.getAttribute("usertype"); + if (headquartersname != null) { + long mobileno = (long) session.getAttribute("mobileno"); + model.addAttribute("mobileno", mobileno); + model.addAttribute("adminname", headquartersname); + model.addAttribute("halllist", list); + return "sm/halldetailslist"; + } else { + session.invalidate(); // Invalidate the session to clear all session attributes + return "redirect:/communityhall/login"; + } + + } + + // Six months old transaction details – redesigned with 4 tabs + @GetMapping("/sixmonthold-transactions") + public String SixMonthOldTransactions(Model model, HttpSession session) { + String headquartersname = (String) session.getAttribute("usertype"); + if (headquartersname != null && "sm".equals(headquartersname)) { + model.addAttribute("headquartersname", headquartersname); + long mobileno = (long) session.getAttribute("mobileno"); + model.addAttribute("mobileno", mobileno); + model.addAttribute("title", "sixmonthold-transactions"); + String zone = (String) session.getAttribute("zone"); + model.addAttribute("zone", zone); + + List> sixMonthOldBookings = normalizeMapKeys( + bookingDetailsRepository.findSixMonthOldNonCancelledRejectedBookings()); + List> cancelledBookings = normalizeMapKeys( + bookingDetailsRepository.findSixMonthOldCancelledBookings()); + List> rejectedBookings = normalizeMapKeys( + bookingDetailsRepository.findSixMonthOldRejectedBookings()); + List> mailSentBookings = normalizeMapKeys( + bookingDetailsRepository.findMailSentBookings()); + + model.addAttribute("sixMonthOldBookings", sixMonthOldBookings); + model.addAttribute("cancelledBookings", cancelledBookings); + model.addAttribute("rejectedBookings", rejectedBookings); + model.addAttribute("mailSentBookings", mailSentBookings); + return "sm/sixmonthold-transactions"; + } else { + session.invalidate(); + return "redirect:/communityhall/login"; + } + } + + private List> normalizeMapKeys(List> list) { + if (list == null) + return new ArrayList<>(); + List> result = new ArrayList<>(); + for (Map map : list) { + Map newMap = new HashMap<>(); + for (Map.Entry entry : map.entrySet()) { + if (entry.getKey() != null) { + newMap.put(entry.getKey().toLowerCase(), entry.getValue()); + } + } + result.add(newMap); + } + return result; + } + + @PostMapping("/sixmonthold-transactions/markMailSent") + @ResponseBody + @Transactional + public Map markMailSent( + @RequestParam("bookingId") int bookingId, + @RequestParam("bookingStatus") String bookingStatus, + @RequestParam(value = "transactionId", required = false) String transactionId, + @RequestParam(value = "tpslId", required = false) String tpslId, + @RequestParam(value = "transactionDate", required = false) String transactionDate, + @RequestParam(value = "refundAmount", required = false) Double refundAmount, + HttpSession session) { + + Map response = new HashMap<>(); + String headquartersname = (String) session.getAttribute("usertype"); + if (headquartersname == null || !"sm".equals(headquartersname)) { + response.put("status", "error"); + response.put("message", "Unauthorized"); + return response; + } + try { + // 1. Send the actual SMTP email via JavaMailSender + String mailBody = mailService.sendRefundFollowupMail( + bookingId, bookingStatus, transactionId, tpslId, transactionDate, refundAmount); + + // 2. Update booking_details: mail_sent = 1, mail_sent_date = NOW() + bookingDetailsRepository.markMailSent(bookingId); + + // 3. Write audit log entry + SixMonthMailLog log = new SixMonthMailLog( + bookingId, bookingStatus, transactionId, tpslId, refundAmount, headquartersname, mailBody); + sixMonthMailLogRepository.save(log); + + response.put("status", "success"); + response.put("message", "Mail sent and recorded successfully for booking " + bookingId); + } catch (Exception e) { + response.put("status", "error"); + response.put("message", "Error sending mail: " + e.getMessage()); + } + return response; + } + + @PostMapping("/sixmonthold-transactions/updateRefundDetails") + @ResponseBody + @Transactional + public Map updateRefundDetails( + @RequestParam("bookingId") int bookingId, + @RequestParam(value = "settlementId", required = false) Integer settlementId, + @RequestParam("bookingStatus") String bookingStatus, + @RequestParam("refundStatus") String refundStatus, + @RequestParam("refundDate") String refundDate, + @RequestParam("comments") String comments, + @RequestParam(value = "arnNumber", required = false) String arnNumber, + HttpSession session) { + + Map response = new HashMap<>(); + String headquartersname = (String) session.getAttribute("usertype"); + if (headquartersname == null || !"headquarters".equals(headquartersname)) { + response.put("status", "error"); + response.put("message", "Unauthorized"); + return response; + } + + try { + // Step 1: Fetch BookingDetails + BookingDetails booking = bookingDetailsRepository.findById(bookingId).orElse(null); + if (booking == null) { + response.put("status", "error"); + response.put("message", "Booking not found for ID: " + bookingId); + return response; + } + + // Get refundAmount and transactionId from latest SixMonthMailLog + List mailLogs = sixMonthMailLogRepository.findByBookingIdOrderBySentAtDesc(bookingId); + SixMonthMailLog latestLog = (mailLogs != null && !mailLogs.isEmpty()) ? mailLogs.get(0) : null; + double refundedAmount = (latestLog != null && latestLog.getRefundAmount() != null) + ? latestLog.getRefundAmount() + : 0.0; + String transactionIdFromLog = (latestLog != null) ? latestLog.getTransactionId() : null; + + // Step 2: Archive BookingDetails → booking_history + BookingHistory bookingHistory = new BookingHistory(); + bookingHistory.setBookingStatus(booking.getBookingStatus()); + bookingHistory.setRefundStatus(booking.getRefundStatus()); + bookingHistory.setComments("Archived before updateRefundDetails. " + comments); + bookingHistory.setUpdatedBy("HQ"); + bookingHistory.setCdate(new Date()); + bookingHistory.setStartDate(booking.getStartDate()); + bookingHistory.setEndDate(booking.getEndDate()); + bookingHistory.setStartingSlot(booking.getStartingSlot()); + bookingHistory.setEndingSlot(booking.getEndingSlot()); + bookingHistory.setBookingDetails(booking); + bookingHistoryRepository.save(bookingHistory); + + // Step 3: Update BookingDetails + booking.setBookingStatus(BookingDetails.BookingStatus.COMPLETED); + booking.setRefundStatus(BookingDetails.RefundStatus.COMPLETED); + booking.setComments(comments); + booking.setUpdatedDate(new java.text.SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date())); + bookingDetailsRepository.save(booking); + + // Steps 4 & 5: Settlement (APPROVED bookings only) + boolean isApproved = "APPROVED".equalsIgnoreCase(bookingStatus); + if (isApproved && booking.getSettlement() != null) { + Settlement settlement = booking.getSettlement(); + + // Step 4: Archive Settlement → settlement_history + SettlementHistory settlementHistory = new SettlementHistory(); + settlementHistory.setSettlementId(settlement.getSettlementId()); + settlementHistory.setComments(settlement.getComments()); + settlementHistory.setCdate(settlement.getCdate()); + settlementHistory.setDamageAmount(settlement.getDamageAmount()); + settlementHistory.setEbAmount(settlement.getEbAmount()); + settlementHistory.setDepositAmount(settlement.getDepositAmount()); + settlementHistory.setRefundedAmount(settlement.getRefundedAmount()); + settlementHistory.setUpdatedDate(settlement.getUpdatedDate()); + settlementHistory.setUpdatedId(settlement.getUpdatedId()); + settlementHistory.setChallon(settlement.getChallon()); + settlementHistory.setDddate(settlement.getDddate()); + settlementHistory.setDdnumber(settlement.getDdnumber()); + settlementHistory.setBookingDetails(booking); + settlementHistory.setCollectionPending(settlement.getCollectionPending()); + settlementHistory.setDdamount(settlement.getDdamount()); + settlementHistory.setChallonnumber(settlement.getChallonnumber()); + settlementHistory.setCollectionStatus(settlement.getCollectionStatus()); + settlementHistory.setShDate(new Date()); + settlementHistoryRepository.save(settlementHistory); + + // Step 5: Update Settlement + settlement.setComments(comments); + settlement.setUpdatedDate(new Date()); + settlement.setUpdatedId("HQ"); + settlementRepository.save(settlement); + } + + // Step 6: Upsert RefundTransaction + RefundTransaction refundTransaction = refundTransactionRepository.findByBookingId(bookingId); + if (refundTransaction == null) { + refundTransaction = new RefundTransaction(); + refundTransaction.setBookingDetails(booking); + } + refundTransaction.setTransactionId(transactionIdFromLog); + refundTransaction.setAmountRefunded(refundedAmount); + refundTransaction.setCdate(new Date()); + refundTransaction.setRefundStatus("0400"); + refundTransactionRepository.save(refundTransaction); + + // Step 7: Upsert RefundResponse + RefundResponse refundResponse = transRefundResRepository.findByBookingId(bookingId); + if (refundResponse == null) { + refundResponse = new RefundResponse(); + } + refundResponse.setAmount(String.valueOf(booking.getAmountReceived())); + refundResponse.setBalaceAmount(String.valueOf(refundedAmount)); + refundResponse.setBookingId(bookingId); + refundResponse.setDate(LocalDate.now()); + refundResponse.setStatusCode("0400"); + refundResponse.setTxansactionId(transactionIdFromLog); + refundResponse.setUserId("HQ"); + refundResponse.setCdate(LocalDateTime.now()); + refundResponse.setArnNumber(arnNumber); + refundResponse.setRefundedDate(LocalDate.parse(refundDate)); + transRefundResRepository.save(refundResponse); + + // Step 8: Application Log + ApplicationLogs appLog = new ApplicationLogs(); + appLog.setBookingId(bookingId); + appLog.setLogType("UPDATE_REFUND_DETAILS"); + appLog.setComments("RefundStatus set to " + refundStatus + + " by HQ. ARN: " + arnNumber + ". Comments: " + comments); + Integer loginId = (Integer) session.getAttribute("id"); + if (loginId != null) + appLog.setLoginId(loginId); + try { + InetAddress inetAddress = InetAddress.getLocalHost(); + appLog.setIpaddress(inetAddress.getHostAddress()); + appLog.setSystemName(InetAddress.getLocalHost().getHostName()); + } catch (UnknownHostException uhe) { + // non-fatal + } + applicationLogsRepository.save(appLog); + + response.put("status", "success"); + response.put("message", "Refund details updated successfully for Booking ID " + bookingId); + response.put("bookingId", bookingId); + + } catch (Exception e) { + response.put("status", "error"); + response.put("message", "Error updating refund details: " + e.getMessage()); + } + return response; + } + + // Newly added for collection pending by kani + + @GetMapping("/collectionpending") + public String viewCollectionPending(Model model, HttpSession session) { + String headquartersname = (String) session.getAttribute("usertype"); + if (headquartersname != null && "sm".equals(headquartersname)) { + List collectionPendingList = bookingDetailsRepository.getAllCollectionPendingList(); + model.addAttribute("headquartersname", headquartersname); + model.addAttribute("collectionPendingList", collectionPendingList); + return "sm/collection-pending"; + } else { + session.invalidate(); + return "redirect:/communityhall/login"; + } + } - //sm - + // sm } diff --git a/src/main/resources/templates/fragments/smMenu.html b/src/main/resources/templates/fragments/smMenu.html index be395dac..216a74ce 100644 --- a/src/main/resources/templates/fragments/smMenu.html +++ b/src/main/resources/templates/fragments/smMenu.html @@ -7,86 +7,86 @@ - - + + + Settlement Approved List + + + - -->