diff --git a/src/main/java/com/gcc/communityHall/controller/SmController.java b/src/main/java/com/gcc/communityHall/controller/SmController.java new file mode 100644 index 00000000..28751f79 --- /dev/null +++ b/src/main/java/com/gcc/communityHall/controller/SmController.java @@ -0,0 +1,446 @@ +package com.gcc.communityHall.controller; + +import java.net.InetAddress; +import java.net.UnknownHostException; +import java.time.LocalDate; +import java.time.LocalDateTime; +import java.util.*; +import java.util.function.Function; +import java.util.function.Predicate; +import java.util.stream.Collectors; + +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.gcc.communityHall.entity.ApplicationLogs; +import com.gcc.communityHall.entity.BookingHistory; +import com.gcc.communityHall.entity.GccBlockingDate; +import com.gcc.communityHall.entity.Login; +import com.gcc.communityHall.entity.LoginHallId; +import com.gcc.communityHall.entity.RefundTransaction; +import com.gcc.communityHall.entity.Settlement; +import com.gcc.communityHall.entity.SettlementHistory; +import com.gcc.communityHall.entity.SixMonthMailLog; +import com.gcc.communityHall.others.AppConfig; +import com.gcc.communityHall.paymentService.entity.RefundResponse; +import com.gcc.communityHall.paymentService.repository.TransRefundResRepository; +import com.gcc.communityHall.repository.ApplicationLogsRepository; +import com.gcc.communityHall.repository.BookingHistoryRepository; +import com.gcc.communityHall.repository.GccBlockingDateRepository; +import com.gcc.communityHall.repository.LoginHallIdRepository; +import com.gcc.communityHall.repository.LoginRepository; +import com.gcc.communityHall.repository.RefundTransactionRepository; +import com.gcc.communityHall.repository.SettlementHistoryRepository; +import com.gcc.communityHall.repository.SettlementRepository; +import com.gcc.communityHall.repository.SixMonthMailLogRepository; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.format.annotation.DateTimeFormat; +import org.springframework.stereotype.Controller; +import org.springframework.ui.Model; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.ResponseBody; +import org.springframework.web.multipart.MultipartFile; + +import com.gcc.communityHall.entity.BookingDetails; +import com.gcc.communityHall.entity.HallDetails; +import com.gcc.communityHall.entity.Users; +import com.gcc.communityHall.repository.BookingDetailsRepository; +import com.gcc.communityHall.repository.HallDetailsRepository; +import com.gcc.communityHall.repository.UsersRepository; +import com.gcc.communityHall.service.BookingService; +import com.gcc.communityHall.service.HallDetailService; +import com.gcc.communityHall.service.MailService; +import com.gcc.communityHall.service.ReasonMasterService; +import com.gcc.communityHall.service.UserService; + +import jakarta.servlet.http.HttpSession; +import jakarta.transaction.Transactional; + +@Controller +@RequestMapping("/communityhall/sm") +public class SmController { + @Autowired + HallDetailService hallDetailService; + @Autowired + ReasonMasterService reasonMasterService; + @Autowired + private BookingDetailsRepository bookingDetailsRepo; + + @Autowired + private UsersRepository usersRepository; + + @Autowired + private BookingService bookingService; + + @Autowired + private UserService userService; + @Autowired + private BookingDetailsRepository bookingDetailsRepository; + + @Autowired + private GccBlockingDateRepository blockingDateRepository; + + @Autowired + private AppConfig appConfig; + + @Autowired + private LoginRepository loginRepository; + + @Autowired + private LoginHallIdRepository loginHallIdRepository; + + @Autowired + private HallDetailsRepository hallDetailsRepository; + + @Autowired + private SixMonthMailLogRepository sixMonthMailLogRepository; + + @Autowired + private MailService mailService; + + @Autowired + private BookingHistoryRepository bookingHistoryRepository; + + @Autowired + private SettlementHistoryRepository settlementHistoryRepository; + + @Autowired + private SettlementRepository settlementRepository; + + @Autowired + private RefundTransactionRepository refundTransactionRepository; + + @Autowired + private TransRefundResRepository transRefundResRepository; + + @Autowired + private ApplicationLogsRepository applicationLogsRepository; + + @GetMapping("/dashboard") + public String viewDashboard( + @RequestParam(required = false, defaultValue = "all zones") String zone, + Model model, HttpSession session) { + + System.out.println("sm dashboard before condition"); + String headquartersname = (String) session.getAttribute("usertype"); + if (headquartersname != null && "sm".equals(headquartersname)) { + System.out.println("sm dashboard"); + long mobileno = (long) session.getAttribute("mobileno"); + model.addAttribute("mobileno", mobileno); + List> getMonthCount = bookingDetailsRepository.getAllAdminmonthcount(zone); + List> count = bookingDetailsRepository.getAdmincount(zone); + Map map = count.get(0); + + model.addAttribute("mounthcount", getMonthCount); + model.addAttribute("APPROVED", map.get("approved_count")); + model.addAttribute("REJECTED", map.get("rejected_count")); + model.addAttribute("PENDING", map.get("pending_count")); + model.addAttribute("CANCELED", map.get("CANCELED")); + model.addAttribute("PAYMENT_FAILURE", map.get("PAYMENT_FAILURE")); + model.addAttribute("GCC_BLOCKED", map.get("GCC_BLOCKED")); + model.addAttribute("headquartersname", headquartersname); + model.addAttribute("zone", zone); + + return "sm/dashboard"; + } else { + // Token is invalid or not present, redirect to logout + session.invalidate(); // Invalidate the session to clear all session attributes + return "redirect:/communityhall/login"; + } + } + + @GetMapping("/Reports") + public String viewReports(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/reports"; + } else { + session.invalidate(); // Invalidate the session to clear all session attributes + return "redirect:/communityhall/login"; + } + } + + @PostMapping("/getReport") + public String generateReport(Model model, + @RequestParam(name = "FromDate") @DateTimeFormat(iso = DateTimeFormat.ISO.DATE) String fromDate, + @RequestParam(name = "ToDate") @DateTimeFormat(iso = DateTimeFormat.ISO.DATE) String toDate, + @RequestParam(name = "request") String request, + @RequestParam(name = "userstatus", required = false) String userstatus, + @RequestParam(name = "usertype", required = false) String usertype, + @RequestParam(name = "bookingStatus", required = false) String bookingStatus, + @RequestParam(name = "refundStatus", required = false) String refundStatus, + @RequestParam(name = "paymentStatus", required = false) String paymentStatus, + @RequestParam(name = "filterby", required = false) String filterby, + @RequestParam(name = "zone1", required = false, defaultValue = "ALL") String zone, + @RequestParam(name = "division1", required = false, defaultValue = "ALL") String division, + @RequestParam(name = "hall1", required = false) Integer hallid, + @RequestParam(name = "basedon", required = false) String basedon, + @RequestParam(name = "bookingId", required = false) Long bookingId, + @RequestParam(name = "reporttype", required = false) String reporttype, + @RequestParam(name = "counterId", required = false) String counterId, HttpSession session) + throws JsonProcessingException { + String headquartersname = (String) session.getAttribute("usertype"); + if (headquartersname != null && "sm".equals(headquartersname)) { + long mobileno = (long) session.getAttribute("mobileno"); + model.addAttribute("mobileno", mobileno); + List userList = handleUserRequest(request, fromDate, toDate, userstatus, usertype); + List bookingList = handleBookingRequest(request, fromDate, toDate, bookingStatus, filterby, + bookingId, zone, division, hallid); + List bookingSettlementList = handleBookingSettlementRequest(request, fromDate, toDate, + refundStatus, filterby); + // List paymentList = request.equals("3") ? + // bookingService.getAllPaymentsDetails(fromDate, toDate,zone,division,hallid) : + // new ArrayList<>(); + List paymentList = new ArrayList<>(); + List extrapaymentList = new ArrayList<>(); + if (request.equals("3")) { + if (paymentStatus == null || paymentStatus.isEmpty()) { + paymentList = bookingService.getAllPaymentsDetails(fromDate, toDate, null, zone, division, hallid); + } else { + paymentList = bookingService.getAllPaymentsDetails(fromDate, toDate, paymentStatus, zone, division, + hallid); + } + } + if (request.equals("8")) { + if (paymentStatus == null || paymentStatus.isEmpty()) { + extrapaymentList = bookingService.getAllExtraPaymentsDetails(fromDate, toDate, null, zone, division, + hallid); + } else { + extrapaymentList = bookingService.getAllExtraPaymentsDetails(fromDate, toDate, paymentStatus, zone, + division, hallid); + } + } + List userbookingList = request.equals("4") + ? bookingService.getBookingUserDetailsReport(fromDate, toDate) + : new ArrayList<>(); + // List hallbookingList = request.equals("5") ? + // bookingService.getBookingHallDetailsReport(fromDate, toDate) : new + // ArrayList<>(); + // In your controller method + // Fetch booking count by zone + List totalcount = new ArrayList<>(); + int totalBookings = 0; + if ("7".equals(request)) { + if ("zone".equals(basedon)) { + totalcount = bookingDetailsRepository.countBookingsByZone(); + // Format zone data + totalcount = totalcount.stream() + .map(data -> new Object[] { "Zone-" + data[0], data[1] }) + .collect(Collectors.toList()); + } else if ("division".equals(basedon)) { + totalcount = bookingDetailsRepository.countBookingsByDivisions(); + // Format division data + totalcount = totalcount.stream() + .map(data -> new Object[] { "Division-" + data[0], data[1] }) + .collect(Collectors.toList()); + } + + totalBookings = totalcount.stream() + .mapToInt(data -> ((Number) data[1]).intValue()) + .sum(); + } + model.addAttribute("basedon", basedon); + model.addAttribute("totalcount", totalcount); + model.addAttribute("totalBookings", totalBookings); + List hallbookingList = handleBookingHallDetailsReportRequest(request, fromDate, toDate, filterby, + zone, division, hallid); + + if ("9".equals(request)) { + if ("abstract".equals(reporttype)) { + List counterBookingList = new ArrayList<>(); + counterBookingList = bookingService.getCounterWiseBookingCount(fromDate, toDate); + model.addAttribute("counterBookingList", counterBookingList); + // System.out.println("counterBookingList.." + counterBookingList); + + List hallBookingByCounter = bookingService.getHallWiseBookingDetails(fromDate, toDate, + counterId); + // Convert to JSON for JS usage + String hallBookingJson = new ObjectMapper().writeValueAsString(hallBookingByCounter); + model.addAttribute("hallBookingJson", hallBookingJson); + + List hallBookingDetails = bookingService.getBookingDetailsForAllHalls(fromDate, toDate, + counterId, hallid); + String hallBookingDetailsJson = new ObjectMapper().writeValueAsString(hallBookingDetails); + model.addAttribute("hallBookingDetailsJson", hallBookingDetailsJson); + + } else { + List counterBookingList = new ArrayList<>(); + counterBookingList = bookingService.getCounterWiseBookingDetails(fromDate, toDate); + model.addAttribute("counterBookingList", counterBookingList); + } + model.addAttribute("reporttype", reporttype); + } + + model.addAttribute("filterby", filterby); + model.addAttribute("users", userList); + model.addAttribute("bookings", bookingList); + model.addAttribute("fromdate", fromDate); + model.addAttribute("todate", toDate); + model.addAttribute("userstatus", userstatus); + model.addAttribute("bookingSettlementList", bookingSettlementList); + model.addAttribute("usertype", usertype); + model.addAttribute("bookingStatus", bookingStatus); + model.addAttribute("refundStatus", refundStatus); + model.addAttribute("paymentStatus", paymentStatus); + model.addAttribute("request", request); + model.addAttribute("paymentLists", paymentList); + model.addAttribute("extrapaymentLists", extrapaymentList); + model.addAttribute("userbookingLists", userbookingList); + model.addAttribute("hallbookingLists", hallbookingList); + model.addAttribute("bookingId", bookingId); + model.addAttribute("zone1", zone); + model.addAttribute("division1", division); + model.addAttribute("hall1", hallid); + model.addAttribute("headquartersname", headquartersname); + + return "sm/reports"; + } else { + session.invalidate(); // Invalidate the session to clear all session attributes + 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")) { + return new ArrayList<>(); + } + if (filterby.isEmpty()) { + return bookingService.getBookingHallDetailsReportByBookingDate(fromDate, toDate, zone, division, hallid); + } + if ("1".equals(filterby)) { + + return bookingService.getBookingHallDetailsReportByBookingDate(fromDate, toDate, zone, division, hallid); + + } + if ("2".equals(filterby)) { + + return bookingService.getBookingHallDetailsReportByEventDate(fromDate, toDate, zone, division, hallid); + + } + + return new ArrayList<>(); + } + private List handleUserRequest(String request, String fromDate, String toDate, String userstatus, + String usertype) { + if (!request.equals("1")) { + return new ArrayList<>(); + } + if ((userstatus != null && !userstatus.isEmpty()) && (usertype != null && !usertype.isEmpty())) { + return userService.getAllUsersWithFilters(fromDate, toDate, userstatus, usertype); + } + if (userstatus.isEmpty() && (usertype != null && !usertype.isEmpty())) { + return userService.getAllUsersWithTypeFilters(fromDate, toDate, usertype); + } + if (usertype.isEmpty() && (userstatus != null && !userstatus.isEmpty())) { + return userService.getAllUsersWithStatusFilters(fromDate, toDate, userstatus); + } + return userService.getAllUsers(fromDate, toDate); + } + + private List handleBookingRequest(String request, String fromDate, String toDate, String bookingStatus, + String filterby, Long bookingId, String zone, String division, Integer hallid) { + if (!request.equals("2")) { + return new ArrayList<>(); + } + if (filterby.isEmpty() && bookingStatus.isEmpty() && bookingId == null) { + return bookingService.getBookingDetailsByBookingDate(fromDate, toDate, zone, division, hallid); + } + if (bookingId != null && bookingStatus.isEmpty()) { + return bookingDetailsRepo.getAllBookingDetailsWithBookingId(fromDate, toDate, bookingId); + } + if (bookingId != null && !bookingStatus.isEmpty()) { + return bookingDetailsRepo.getAllBookingDetailsWithBookingIdwithbookingStatus(fromDate, toDate, bookingId, + bookingStatus); + } + if (bookingId == null && filterby.isEmpty() && !bookingStatus.isEmpty()) { + return bookingService.getBookingDetailsByBookingDateWithStatus(fromDate, toDate, bookingStatus, zone, + division, hallid); + } + if (!filterby.isEmpty()) { + + if ("1".equals(filterby)) { + if (bookingStatus.isEmpty()) { + return bookingService.getBookingDetailsByBookingDate(fromDate, toDate, zone, division, hallid); + } else { + return bookingService.getBookingDetailsByBookingDateWithStatus(fromDate, toDate, bookingStatus, + zone, division, hallid); + } + + } + if ("2".equals(filterby)) { + if (bookingStatus.isEmpty()) { + return bookingService.getBookingDetailsByEventDate(fromDate, toDate, zone, division, hallid); + } else { + return bookingService.getBookingDetailsByEventDateWithStatus(fromDate, toDate, bookingStatus, zone, + division, hallid); + } + + } + } + // Handle default or error case + return new ArrayList<>(); + } + + private List handleBookingSettlementRequest(String request, String fromDate, String toDate, + String refundStatus, String filterby) { + if (!request.equals("6")) { + return new ArrayList<>(); + } + if (filterby.isEmpty() && refundStatus.isEmpty()) { + return bookingService.getAllBookingsettlementDetailsByBookingDate(fromDate, toDate); + } + if (filterby.isEmpty() && !refundStatus.isEmpty()) { + return bookingService.getAllBookingsettlementDetailsByBookingDateWithStatus(fromDate, toDate, refundStatus); + } + if (!filterby.isEmpty()) { + + if ("1".equals(filterby)) { + if (refundStatus.isEmpty()) { + return bookingService.getAllBookingsettlementDetailsByBookingDate(fromDate, toDate); + } else { + return bookingService.getAllBookingsettlementDetailsByBookingDateWithStatus(fromDate, toDate, + refundStatus); + } + + } + if ("2".equals(filterby)) { + if (refundStatus.isEmpty()) { + return bookingService.getAllBookingsettlementDetailsByEventDate(fromDate, toDate); + } else { + return bookingService.getAllBookingsettlementDetailsByEventDateWithStatus(fromDate, toDate, + refundStatus); + } + + } + } + + // Handle default or error case + return new ArrayList<>(); + } + + + + @GetMapping("/logout") + public String viewLogout(Model model, HttpSession session) { + session.invalidate(); + System.out.println("Logged out successfully"); + return "redirect:/communityhall/login"; + } + + + + + + + + + //sm + + +} diff --git a/src/main/resources/templates/fragments/head-sm.html b/src/main/resources/templates/fragments/head-sm.html new file mode 100644 index 00000000..2ff433eb --- /dev/null +++ b/src/main/resources/templates/fragments/head-sm.html @@ -0,0 +1,44 @@ + + + + + GCC + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/main/resources/templates/fragments/header-sm.html b/src/main/resources/templates/fragments/header-sm.html new file mode 100644 index 00000000..6189af07 --- /dev/null +++ b/src/main/resources/templates/fragments/header-sm.html @@ -0,0 +1,98 @@ + \ No newline at end of file diff --git a/src/main/resources/templates/fragments/nav-sm.html b/src/main/resources/templates/fragments/nav-sm.html new file mode 100644 index 00000000..44b4022a --- /dev/null +++ b/src/main/resources/templates/fragments/nav-sm.html @@ -0,0 +1,13 @@ + \ No newline at end of file diff --git a/src/main/resources/templates/fragments/smMenu.html b/src/main/resources/templates/fragments/smMenu.html new file mode 100644 index 00000000..be395dac --- /dev/null +++ b/src/main/resources/templates/fragments/smMenu.html @@ -0,0 +1,152 @@ + \ No newline at end of file diff --git a/src/main/resources/templates/officiallogin.html b/src/main/resources/templates/officiallogin.html index 740fd20b..cb462e40 100644 --- a/src/main/resources/templates/officiallogin.html +++ b/src/main/resources/templates/officiallogin.html @@ -488,6 +488,9 @@ case "cro": window.location.href = "/communityhall/cro/booking-list"; break; + case "sm": + window.location.href = "/communityhall/sm/dashboard"; + break; default: console.error("Invalid user type:", userType); } diff --git a/src/main/resources/templates/sm/dashboard.html b/src/main/resources/templates/sm/dashboard.html new file mode 100644 index 00000000..8cb59300 --- /dev/null +++ b/src/main/resources/templates/sm/dashboard.html @@ -0,0 +1,1570 @@ + + + + + + Title + + + + + + + +

You are using an outdated browser. Please upgrade your browser to improve your experience.

+ + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/main/resources/templates/sm/reports.html b/src/main/resources/templates/sm/reports.html new file mode 100644 index 00000000..2639cb9e --- /dev/null +++ b/src/main/resources/templates/sm/reports.html @@ -0,0 +1,2417 @@ + + + + + + + + + + + + + + +
+ + + + + + + \ No newline at end of file