You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

596 lines
28 KiB

2 years ago
​
​
​
​
2 years ago
​
​
​
​
2 years ago
​
​
​
​
​
​
​
​
​
​
​
​
2 years ago
​
​
​
​
​
​
2 years ago
​
​
​
​
​
​
​
​
​
​
​
2 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
2 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
2 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
2 years ago
2 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
2 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
2 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
2 years ago
2 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
2 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
2 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
2 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
2 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
2 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
2 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
2 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
2 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
2 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
2 years ago
​
​
​
​
​
​
​
​
2 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
2 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
2 years ago
​
​
2 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
2 years ago
  1. package com.gcc.communityHall.controller;
  2. import java.util.ArrayList;
  3. import java.util.Arrays;
  4. import java.util.HashMap;
  5. import java.util.HashSet;
  6. import java.util.List;
  7. import java.util.Map;
  8. import java.util.Set;
  9. import java.util.function.Function;
  10. import java.util.function.Predicate;
  11. import java.util.stream.Collectors;
  12. import org.springframework.beans.factory.annotation.Autowired;
  13. import org.springframework.format.annotation.DateTimeFormat;
  14. import org.springframework.stereotype.Controller;
  15. import org.springframework.ui.Model;
  16. import org.springframework.web.bind.annotation.GetMapping;
  17. import org.springframework.web.bind.annotation.PostMapping;
  18. import org.springframework.web.bind.annotation.RequestMapping;
  19. import org.springframework.web.bind.annotation.RequestParam;
  20. import com.gcc.communityHall.entity.BookingDetails;
  21. import com.gcc.communityHall.entity.BookingDetails.RefundStatus;
  22. import com.gcc.communityHall.entity.CounterRefundList;
  23. import com.gcc.communityHall.entity.GccBlockingDate;
  24. import com.gcc.communityHall.entity.HallDetails;
  25. import com.gcc.communityHall.entity.Payments;
  26. import com.gcc.communityHall.entity.Settlement;
  27. import com.gcc.communityHall.entity.Users;
  28. import com.gcc.communityHall.others.AppConfig;
  29. import com.gcc.communityHall.repository.BookingDetailsRepository;
  30. import com.gcc.communityHall.repository.CounterRefundListRepository;
  31. import com.gcc.communityHall.repository.GccBlockingDateRepository;
  32. import com.gcc.communityHall.repository.HallDetailsRepository;
  33. import com.gcc.communityHall.repository.PaymentsRepository;
  34. import com.gcc.communityHall.repository.SettlementRepository;
  35. import com.gcc.communityHall.repository.UsersRepository;
  36. import com.gcc.communityHall.service.BookingService;
  37. import com.gcc.communityHall.service.HallDetailService;
  38. import jakarta.servlet.http.HttpSession;
  39. @Controller
  40. @RequestMapping("/communityhall/officer")
  41. public class OfficerController {
  42. @Autowired
  43. private AppConfig appConfig;
  44. @Autowired
  45. private BookingDetailsRepository bookingDetailsRepository;
  46. @Autowired
  47. private PaymentsRepository paymentsRepository;
  48. @Autowired
  49. private UsersRepository usersRepository;
  50. @Autowired
  51. private SettlementRepository settlementRepository;
  52. @Autowired
  53. private CounterRefundListRepository counterRefundListRepository;
  54. @Autowired
  55. private BookingService bookingService;
  56. @Autowired
  57. private HallDetailsRepository hallDetailsRepository;
  58. @Autowired
  59. private HallDetailService hallDetailsService;
  60. @Autowired
  61. private GccBlockingDateRepository blockingDateRepository;
  62. @GetMapping("/login")
  63. public String viewLoginPage(Model model) {
  64. String msg = "Login to Your Account";
  65. model.addAttribute("errortxt", msg);
  66. return "officiallogin";
  67. }
  68. @GetMapping("/officer-dashboard")
  69. public String viewDashboard(Model model, HttpSession session) {
  70. String officername = (String) session.getAttribute("usertype");
  71. if (officername != null) {
  72. String zone = (String) session.getAttribute("zone");
  73. model.addAttribute("officername", officername);
  74. long mobileno = (long) session.getAttribute("mobileno");
  75. model.addAttribute("mobileno", mobileno);
  76. model.addAttribute("zone", zone);
  77. return "officer/officer-dashboard";
  78. } else {
  79. session.invalidate();
  80. return "redirect:/communityhall/login";
  81. }
  82. }
  83. @GetMapping("/booking-pending")
  84. public String viewhall(Model model, HttpSession session) {
  85. String officername = (String) session.getAttribute("usertype");
  86. if (officername != null) {
  87. model.addAttribute("officername", officername);
  88. long mobileno = (long) session.getAttribute("mobileno");
  89. model.addAttribute("mobileno", mobileno);
  90. model.addAttribute("title", "pending bookings");
  91. model.addAttribute("baseURL", appConfig.getBaseUrl());
  92. String zone = (String) session.getAttribute("zone");
  93. model.addAttribute("zone", zone);
  94. List<BookingDetails> pendingbooking = bookingDetailsRepository.getPendingOrPaymentFailureBookings(zone);
  95. model.addAttribute("pendingbooking", pendingbooking);
  96. return "officer/booking-pending";
  97. } else {
  98. session.invalidate();
  99. return "redirect:/communityhall/login";
  100. }
  101. }
  102. @GetMapping("/payment-list")
  103. public String viewPayment(Model model, HttpSession session) {
  104. String officername = (String) session.getAttribute("usertype");
  105. if (officername != null) {
  106. model.addAttribute("officername", officername);
  107. long mobileno = (long) session.getAttribute("mobileno");
  108. model.addAttribute("mobileno", mobileno);
  109. model.addAttribute("title", "paymentlist");
  110. model.addAttribute("baseURL", appConfig.getBaseUrl());
  111. String zone = (String) session.getAttribute("zone");
  112. model.addAttribute("zone", zone);
  113. // System.out.println(zone);
  114. List<Payments> pay = paymentsRepository.getPaymentListByzone(zone);
  115. model.addAttribute("paymentlist", pay);
  116. return "officer/payment-list";
  117. } else {
  118. session.invalidate();
  119. return "redirect:/communityhall/login";
  120. }
  121. }
  122. @GetMapping("/bookingwaitinglist")
  123. public String viewWaitingBookings(Model model, HttpSession session) {
  124. String officername = (String) session.getAttribute("usertype");
  125. if (officername != null) {
  126. model.addAttribute("officername", officername);
  127. long mobileno = (long) session.getAttribute("mobileno");
  128. model.addAttribute("mobileno", mobileno);
  129. model.addAttribute("title", "bookinglist");
  130. model.addAttribute("baseURL", appConfig.getBaseUrl());
  131. String zone = (String) session.getAttribute("zone");
  132. model.addAttribute("zone", zone);
  133. List<BookingDetails> bookingList = bookingDetailsRepository.getWaitinglist(zone);
  134. model.addAttribute("bookingList", bookingList);
  135. return "officer/booking-list"; // Assuming "officer/rejected-booking-list" is the name of your HTML template
  136. } else {
  137. session.invalidate();
  138. return "redirect:/communityhall/login";
  139. }
  140. }
  141. @GetMapping("/booking-list")
  142. public String viewBookingList(Model model, HttpSession session) {
  143. String officername = (String) session.getAttribute("usertype");
  144. if (officername != null) {
  145. model.addAttribute("officername", officername);
  146. long mobileno = (long) session.getAttribute("mobileno");
  147. model.addAttribute("mobileno", mobileno);
  148. model.addAttribute("title", "bookinglist");
  149. model.addAttribute("baseURL", appConfig.getBaseUrl());
  150. String zone = (String) session.getAttribute("zone");
  151. model.addAttribute("zone", zone);
  152. List<BookingDetails> bookingList = bookingDetailsRepository.getApprovedlist(zone);
  153. model.addAttribute("bookingList", bookingList);
  154. return "officer/booking-list"; // Assuming "officer/rejected-booking-list" is the name of your HTML template
  155. } else {
  156. session.invalidate();
  157. return "redirect:/communityhall/login";
  158. }
  159. }
  160. @GetMapping("/rejected-list")
  161. public String viewRejectedBookings(Model model, HttpSession session) {
  162. String officername = (String) session.getAttribute("usertype");
  163. if (officername != null) {
  164. model.addAttribute("officername", officername);
  165. long mobileno = (long) session.getAttribute("mobileno");
  166. model.addAttribute("mobileno", mobileno);
  167. model.addAttribute("title", "rejectedlist");
  168. model.addAttribute("baseURL", appConfig.getBaseUrl());
  169. String zone = (String) session.getAttribute("zone");
  170. model.addAttribute("zone", zone);
  171. List<BookingDetails> rejectedBookings = bookingDetailsRepository.getrejectedlist(zone);
  172. model.addAttribute("rejectedBookings", rejectedBookings);
  173. return "officer/rejected-list";
  174. } else {
  175. session.invalidate();
  176. return "redirect:/communityhall/login";
  177. }
  178. }
  179. @GetMapping("/settlement-list")
  180. public String settlementPendingList(Model model, HttpSession session) {
  181. String officername = (String) session.getAttribute("usertype");
  182. if (officername != null) {
  183. model.addAttribute("officername", officername);
  184. long mobileno = (long) session.getAttribute("mobileno");
  185. model.addAttribute("mobileno", mobileno);
  186. model.addAttribute("title", "settlement Pending");
  187. model.addAttribute("baseURL", appConfig.getBaseUrl());
  188. String zone = (String) session.getAttribute("zone");
  189. model.addAttribute("zone", zone);
  190. System.out.println("Zone: " + zone);
  191. List<BookingDetails> settlement = bookingDetailsRepository.findSettlementPendingByZone(zone);
  192. // ak
  193. List<BookingDetails> settlementIntiated = bookingDetailsRepository
  194. .findSettlementInitiatedPendingByZone(zone);
  195. List<BookingDetails> cancelledbookings = bookingDetailsRepository.findCancelledListByZone(zone);
  196. List<BookingDetails> rejectedbookings = bookingDetailsRepository.findRejectedListByZone(zone);
  197. model.addAttribute("settlementlist", settlement);
  198. // AK
  199. model.addAttribute("settlementIntiated", settlementIntiated);
  200. model.addAttribute("cancelledbookings", cancelledbookings);
  201. model.addAttribute("rejectedbookings", rejectedbookings);
  202. System.out.println("settlementIntiated" + settlementIntiated);
  203. return "officer/settlement-list";
  204. } else {
  205. session.invalidate();
  206. return "redirect:/communityhall/login";
  207. }
  208. }
  209. @GetMapping("/refundfailed-list")
  210. public String RefundFailedList(Model model, HttpSession session) {
  211. String officername = (String) session.getAttribute("usertype");
  212. if (officername != null) {
  213. model.addAttribute("officername", officername);
  214. long mobileno = (long) session.getAttribute("mobileno");
  215. model.addAttribute("mobileno", mobileno);
  216. model.addAttribute("title", "settlementapproved");
  217. model.addAttribute("baseURL", appConfig.getBaseUrl());
  218. String zone = (String) session.getAttribute("zone");
  219. model.addAttribute("zone", zone);
  220. List<BookingDetails> settlementrefundfailed = bookingDetailsRepository
  221. .findSettlementRefundFailedByZone(zone);
  222. List<BookingDetails> refundfailedcancelledbookings = bookingDetailsRepository
  223. .findRefundFaileCancelledListByZone(zone);
  224. List<BookingDetails> refundfailedrejectedbookings = bookingDetailsRepository
  225. .findRefundFaileRejectedListByZone(zone);
  226. model.addAttribute("settlementrefundfailed", settlementrefundfailed);
  227. model.addAttribute("refundfailedcancelledbookings", refundfailedcancelledbookings);
  228. model.addAttribute("refundfailedrejectedbookings", refundfailedrejectedbookings);
  229. return "officer/refund-failedlist";
  230. } else {
  231. session.invalidate();
  232. return "redirect:/communityhall/login";
  233. }
  234. }
  235. @GetMapping("/settlement-approved")
  236. public String settlementApprovedList(Model model, HttpSession session) {
  237. String officername = (String) session.getAttribute("usertype");
  238. if (officername != null) {
  239. model.addAttribute("officername", officername);
  240. long mobileno = (long) session.getAttribute("mobileno");
  241. model.addAttribute("mobileno", mobileno);
  242. model.addAttribute("title", "settlementapproved");
  243. model.addAttribute("baseURL", appConfig.getBaseUrl());
  244. String zone = (String) session.getAttribute("zone");
  245. model.addAttribute("zone", zone);
  246. List<BookingDetails> settlement = bookingDetailsRepository.findSettlementApprovedByZone(zone);
  247. List<BookingDetails> approvedcancelledbookings = bookingDetailsRepository
  248. .findapprovedCancelledListByZone(zone);
  249. List<BookingDetails> approvedrejectedbookings = bookingDetailsRepository
  250. .findapprovedRejectedListByZone(zone);
  251. model.addAttribute("approvedSettlementlist", settlement);
  252. model.addAttribute("approvedcancelledbookings", approvedcancelledbookings);
  253. model.addAttribute("approvedrejectedbookings", approvedrejectedbookings);
  254. return "officer/settlement-approved";
  255. } else {
  256. session.invalidate();
  257. return "redirect:/communityhall/login";
  258. }
  259. }
  260. @GetMapping("/settlement-reject")
  261. public String settlementRejectedList(Model model, HttpSession session) {
  262. String officername = (String) session.getAttribute("usertype");
  263. if (officername != null) {
  264. model.addAttribute("officername", officername);
  265. long mobileno = (long) session.getAttribute("mobileno");
  266. model.addAttribute("mobileno", mobileno);
  267. model.addAttribute("title", "settlement rejected");
  268. model.addAttribute("baseURL", appConfig.getBaseUrl());
  269. String zone = (String) session.getAttribute("zone");
  270. model.addAttribute("zone", zone);
  271. List<BookingDetails> settlement = bookingDetailsRepository.findSettlementRejectedByZone(zone);
  272. model.addAttribute("rejectSettlementlist", settlement);
  273. return "officer/settlement-reject";
  274. } else {
  275. session.invalidate();
  276. return "redirect:/communityhall/login";
  277. }
  278. }
  279. @GetMapping("/settlement-completedlist")
  280. public String viewSettlementcompletedMaster(Model model, HttpSession session) {
  281. String officername = (String) session.getAttribute("usertype");
  282. if (officername != null) {
  283. long mobileno = (long) session.getAttribute("mobileno");
  284. model.addAttribute("mobileno", mobileno);
  285. String zone = (String) session.getAttribute("zone");
  286. model.addAttribute("zone", zone);
  287. List<BookingDetails> completedlist = bookingDetailsRepository.findSettlementCompletedListbyzone(zone);
  288. List<BookingDetails> cancelledcompletedlist = bookingDetailsRepository
  289. .findCancelledCompletedListbyzone(zone);
  290. List<BookingDetails> rejectedcompletedlist = bookingDetailsRepository
  291. .findRejectedSettlementCompletedListbyzone(zone);
  292. model.addAttribute("title", "settlement initiate");
  293. model.addAttribute("officername", officername);
  294. model.addAttribute("completedlist", completedlist);
  295. model.addAttribute("cancelledcompletedlist", cancelledcompletedlist);
  296. model.addAttribute("rejectedcompletedlist", rejectedcompletedlist);
  297. return "officer/settlement-completed";
  298. } else {
  299. session.invalidate(); // Invalidate the session to clear all session attributes
  300. return "redirect:/communityhall/login";
  301. }
  302. }
  303. @GetMapping("/reports")
  304. public String viewReports(Model model, HttpSession session) {
  305. String officername = (String) session.getAttribute("usertype");
  306. if (officername != null) {
  307. String zone = (String) session.getAttribute("zone");
  308. model.addAttribute("officername", officername);
  309. long mobileno = (long) session.getAttribute("mobileno");
  310. model.addAttribute("mobileno", mobileno);
  311. model.addAttribute("zone", zone);
  312. List<HallDetails> hallnames = hallDetailsService.getHallNames();
  313. model.addAttribute("hallnames", hallnames);
  314. return "officer/report";
  315. } else {
  316. session.invalidate();
  317. return "redirect:/communityhall/login";
  318. }
  319. }
  320. @GetMapping("/getReport")
  321. public String viewgetReports(Model model, HttpSession session) {
  322. String officername = (String) session.getAttribute("usertype");
  323. if (officername != null) {
  324. String zone = (String) session.getAttribute("zone");
  325. model.addAttribute("officername", officername);
  326. long mobileno = (long) session.getAttribute("mobileno");
  327. model.addAttribute("mobileno", mobileno);
  328. model.addAttribute("zone", zone);
  329. List<HallDetails> hallnames = hallDetailsService.getHallNames();
  330. model.addAttribute("hallnames", hallnames);
  331. return "officer/report";
  332. } else {
  333. session.invalidate();
  334. return "redirect:/communityhall/login";
  335. }
  336. }
  337. @PostMapping("/getReport")
  338. public String generateReport(Model model, HttpSession session,
  339. @RequestParam(name = "FromDate") @DateTimeFormat(iso = DateTimeFormat.ISO.DATE) String fromDate,
  340. @RequestParam(name = "ToDate") @DateTimeFormat(iso = DateTimeFormat.ISO.DATE) String toDate,
  341. @RequestParam(name = "request") String request,
  342. @RequestParam(name = "bookingStatus", required = false) String bookingStatus,
  343. @RequestParam(name = "filterby", required = false) String filterby,
  344. @RequestParam(name = "refundStatus", required = false) String refundStatus,
  345. @RequestParam(name = "hallname", required = false, defaultValue = "0") Integer hallId) {
  346. String officername = (String) session.getAttribute("usertype");
  347. if (officername != null) {
  348. String zone = (String) session.getAttribute("zone");
  349. model.addAttribute("zone", zone);
  350. model.addAttribute("officername", officername);
  351. long mobileno = (long) session.getAttribute("mobileno");
  352. model.addAttribute("mobileno", mobileno);
  353. List<HallDetails> hallnames = hallDetailsService.getHallNamesbyzone(zone);
  354. model.addAttribute("hallnames", hallnames);
  355. List<BookingDetails> bookingList = handleBookingRequest(request, fromDate, toDate, bookingStatus, zone,
  356. filterby);
  357. List<BookingDetails> bookingSettlementList = handleBookingSettlementRequest(request, fromDate, toDate,
  358. refundStatus, zone, filterby);
  359. List<Object[]> paymentList = request.equals("3")
  360. ? bookingService.getAllPaymentsDetailsByZone(fromDate, toDate, zone)
  361. : new ArrayList<>();
  362. List<Object[]> hallbookingList = handleHallBookingRequest(request, fromDate, toDate, zone, hallId,
  363. filterby);
  364. model.addAttribute("bookings", bookingList);
  365. model.addAttribute("bookingSettlementList", bookingSettlementList);
  366. model.addAttribute("bookingStatus", bookingStatus);
  367. model.addAttribute("refundStatus", refundStatus);
  368. model.addAttribute("fromdate", fromDate);
  369. model.addAttribute("todate", toDate);
  370. model.addAttribute("request", request);
  371. model.addAttribute("filterby", filterby);
  372. model.addAttribute("paymentLists", paymentList);
  373. model.addAttribute("hallbookingLists", hallbookingList);
  374. return "officer/report";
  375. } else {
  376. session.invalidate();
  377. return "redirect:/communityhall/login";
  378. }
  379. }
  380. private List<BookingDetails> handleBookingRequest(String request, String fromDate, String toDate,
  381. String bookingStatus, String zone, String filterby) {
  382. if (!request.equals("1")) {
  383. return new ArrayList<>();
  384. }
  385. if (bookingStatus.isEmpty() && filterby.isEmpty()) {
  386. return bookingService.getAllBookingDetailsBookingDateByZone(fromDate, toDate, zone);
  387. }
  388. if (filterby.isEmpty() && !bookingStatus.isEmpty()) {
  389. return bookingService.getAllBookingDetailsBookingDateByZoneWithStatus(fromDate, toDate, zone,
  390. bookingStatus);
  391. }
  392. if (!filterby.isEmpty()) {
  393. if ("1".equals(filterby)) {
  394. if (bookingStatus.isEmpty()) {
  395. return bookingService.getAllBookingDetailsBookingDateByZone(fromDate, toDate, zone);
  396. } else {
  397. return bookingService.getAllBookingDetailsBookingDateByZoneWithStatus(fromDate, toDate, zone,
  398. bookingStatus);
  399. }
  400. }
  401. if ("2".equals(filterby)) {
  402. if (bookingStatus.isEmpty()) {
  403. return bookingService.getAllBookingDetailsEventDateByZone(fromDate, toDate, zone);
  404. } else {
  405. return bookingService.getAllBookingDetailsEventDateByZoneWithStatus(fromDate, toDate, zone,
  406. bookingStatus);
  407. }
  408. }
  409. }
  410. return new ArrayList<>();
  411. }
  412. private List<BookingDetails> handleBookingSettlementRequest(String request, String fromDate, String toDate,
  413. String refundStatus, String zone, String filterby) {
  414. if (!request.equals("2")) {
  415. return new ArrayList<>();
  416. }
  417. if ((refundStatus == null || refundStatus.isEmpty()) && filterby.isEmpty()) {
  418. return bookingService.getAllBookingsettlementDetailsByZoneByBookingDate(fromDate, toDate, zone);
  419. }
  420. if ((refundStatus != null && !refundStatus.isEmpty()) && filterby.isEmpty()) {
  421. return bookingService.getAllBookingsettlementDetailsByZoneByBookingDateWithStatus(fromDate, toDate, zone,
  422. refundStatus);
  423. }
  424. if (!filterby.isEmpty()) {
  425. if ("1".equals(filterby)) {
  426. if (refundStatus.isEmpty() || refundStatus == null) {
  427. return bookingService.getAllBookingsettlementDetailsByZoneByBookingDate(fromDate, toDate, zone);
  428. } else {
  429. return bookingService.getAllBookingsettlementDetailsByZoneByBookingDateWithStatus(fromDate, toDate,
  430. zone, refundStatus);
  431. }
  432. }
  433. if ("2".equals(filterby)) {
  434. if (refundStatus.isEmpty() || refundStatus == null) {
  435. return bookingService.getAllBookingsettlementDetailsByZoneByEventDate(fromDate, toDate, zone);
  436. } else {
  437. return bookingService.getAllBookingsettlementDetailsByZoneByEventDateWithStatus(fromDate, toDate,
  438. zone, refundStatus);
  439. }
  440. }
  441. }
  442. return new ArrayList<>();
  443. }
  444. private List<Object[]> handleHallBookingRequest(String request, String fromDate, String toDate, String zone,
  445. Integer hallId, String filterby) {
  446. if (!request.equals("4")) {
  447. return new ArrayList<>();
  448. }
  449. if (filterby.isEmpty() && hallId == 0) {
  450. return bookingService.getBookingHallDetailsReportByZoneByBookingDate(fromDate, toDate, zone);
  451. }
  452. if (filterby.isEmpty() && hallId != 0) {
  453. return bookingService.getBookingHallDetailsReportByZoneByBookingDateHallname(fromDate, toDate, zone,
  454. hallId);
  455. }
  456. if (!filterby.isEmpty()) {
  457. if ("1".equals(filterby)) {
  458. if (hallId != 0) {
  459. return bookingService.getBookingHallDetailsReportByZoneByBookingDateHallname(fromDate, toDate, zone,
  460. hallId);
  461. } else {
  462. return bookingService.getBookingHallDetailsReportByZoneByBookingDate(fromDate, toDate, zone);
  463. }
  464. }
  465. if ("2".equals(filterby)) {
  466. if (hallId != 0) {
  467. return bookingService.getBookingHallDetailsReportByZoneByEventDateHallname(fromDate, toDate, zone,
  468. hallId);
  469. } else {
  470. return bookingService.getBookingHallDetailsReportByZoneByEventDate(fromDate, toDate, zone);
  471. }
  472. }
  473. }
  474. return new ArrayList<>();
  475. }
  476. @GetMapping("/counter-refund")
  477. public String counterRefundList(Model model, HttpSession session) {
  478. String officername = (String) session.getAttribute("usertype");
  479. if (officername != null) {
  480. model.addAttribute("officername", officername);
  481. long mobileno = (long) session.getAttribute("mobileno");
  482. model.addAttribute("mobileno", mobileno);
  483. model.addAttribute("title", "settlement rejected");
  484. model.addAttribute("baseURL", appConfig.getBaseUrl());
  485. String zone = (String) session.getAttribute("zone");
  486. model.addAttribute("zone", zone);
  487. List<CounterRefundList> counterRefund = counterRefundListRepository.findCounterRefundList(zone);
  488. model.addAttribute("counterRefund", counterRefund);
  489. return "officer/counter-refund";
  490. } else {
  491. session.invalidate();
  492. return "redirect:/communityhall/login";
  493. }
  494. }
  495. @GetMapping("/logout")
  496. public String viewLogout(Model model, HttpSession session) {
  497. session.invalidate();
  498. return "redirect:/communityhall/login";
  499. }
  500. // Newly added for zone level block
  501. @GetMapping("/Gccblocking")
  502. public String viewGccBlocking(Model model, HttpSession session) {
  503. String officername = (String) session.getAttribute("usertype");
  504. if (officername != null) {
  505. long mobileno = (long) session.getAttribute("mobileno");
  506. model.addAttribute("mobileno", mobileno);
  507. model.addAttribute("officername", officername);
  508. // Fetch all blocked GCC dates
  509. List<GccBlockingDate> gccBlocked = blockingDateRepository.findAllBlocked();
  510. // Ensure distinct by hallId, blockingReason, startDate, and endDate
  511. List<GccBlockingDate> uniqueGccBlockingDates = gccBlocked.stream()
  512. .filter(distinctByKey(g -> Arrays.asList(
  513. g.getHallId(),
  514. g.getBlockingReason(),
  515. g.getStartDate(),
  516. g.getEndDate())))
  517. .collect(Collectors.toList());
  518. // Map to store the count of blocked halls for each GccBlockingDate
  519. Map<Integer, Integer> hallCountMap = new HashMap<>();
  520. for (GccBlockingDate blockedDate : uniqueGccBlockingDates) {
  521. // Parse and count unique hall IDs
  522. String hallIds = blockedDate.getHallId();
  523. if (hallIds != null && !hallIds.isEmpty()) {
  524. Set<String> uniqueHallIds = new HashSet<>(Arrays.asList(hallIds.split(",")));
  525. int hallCount = uniqueHallIds.size();
  526. hallCountMap.put(blockedDate.getBlockingId(), hallCount);
  527. } else {
  528. hallCountMap.put(blockedDate.getBlockingId(), 0); // No halls blocked
  529. }
  530. }
  531. // Add attributes to the model for the view
  532. model.addAttribute("gccblocked", uniqueGccBlockingDates);
  533. model.addAttribute("hallCountMap", hallCountMap);
  534. return "officer/gccblocking";
  535. } else {
  536. session.invalidate(); // Invalidate the session to clear all session attributes
  537. return "redirect:/communityhall/login";
  538. }
  539. }
  540. // Utility method to ensure distinct by a key
  541. private static <T> Predicate<T> distinctByKey(Function<? super T, ?> keyExtractor) {
  542. Set<Object> seen = new HashSet<>();
  543. return t -> seen.add(keyExtractor.apply(t));
  544. }
  545. }