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.

1379 lines
64 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
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
​
​
​
​
​
​
​
​
​
​
​
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
​
​
​
​
​
​
​
​
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.net.InetAddress;
  3. import java.net.UnknownHostException;
  4. import java.util.ArrayList;
  5. import java.util.Arrays;
  6. import java.util.HashMap;
  7. import java.util.HashSet;
  8. import java.util.List;
  9. import java.util.Map;
  10. import java.util.Set;
  11. import java.util.function.Function;
  12. import java.util.function.Predicate;
  13. import java.util.stream.Collectors;
  14. import com.fasterxml.jackson.core.JsonProcessingException;
  15. import com.fasterxml.jackson.databind.ObjectMapper;
  16. import com.gcc.communityHall.others.AppConfig;
  17. import org.springframework.beans.factory.annotation.Autowired;
  18. import org.springframework.format.annotation.DateTimeFormat;
  19. import org.springframework.http.ResponseEntity;
  20. import org.springframework.stereotype.Controller;
  21. import org.springframework.ui.Model;
  22. import org.springframework.web.bind.annotation.DeleteMapping;
  23. import org.springframework.web.bind.annotation.ExceptionHandler;
  24. import org.springframework.web.bind.annotation.GetMapping;
  25. import org.springframework.web.bind.annotation.PathVariable;
  26. import org.springframework.web.bind.annotation.PostMapping;
  27. import org.springframework.web.bind.annotation.PutMapping;
  28. import org.springframework.web.bind.annotation.RequestBody;
  29. import org.springframework.web.bind.annotation.RequestMapping;
  30. import org.springframework.web.bind.annotation.RequestParam;
  31. import org.springframework.web.bind.annotation.ResponseBody;
  32. import org.springframework.web.method.annotation.MethodArgumentTypeMismatchException;
  33. import org.springframework.web.multipart.MultipartFile;
  34. import com.gcc.communityHall.component.JwtUtil;
  35. import com.gcc.communityHall.entity.ApplicationLogs;
  36. import com.gcc.communityHall.entity.BookingDetails;
  37. import com.gcc.communityHall.entity.BookingDetails.RefundStatus;
  38. import com.gcc.communityHall.entity.DiscountRange;
  39. import com.gcc.communityHall.entity.GccBlockingDate;
  40. import com.gcc.communityHall.entity.HallDetails;
  41. import com.gcc.communityHall.entity.Notification;
  42. import com.gcc.communityHall.entity.Settlement;
  43. import com.gcc.communityHall.entity.Users;
  44. import com.gcc.communityHall.entity.Login;
  45. import com.gcc.communityHall.entity.LoginHallId;
  46. import com.gcc.communityHall.others.UserSession;
  47. import com.gcc.communityHall.paymentService.entity.TransactionResponse;
  48. import com.gcc.communityHall.paymentService.repository.TransactionResponseRepository;
  49. import com.gcc.communityHall.repository.ApplicationLogsRepository;
  50. import com.gcc.communityHall.repository.BookingDetailsRepository;
  51. import com.gcc.communityHall.repository.DiscountRangeRepository;
  52. import com.gcc.communityHall.repository.GccBlockingDateRepository;
  53. import com.gcc.communityHall.repository.HallDetailsRepository;
  54. import com.gcc.communityHall.repository.NotificationRepository;
  55. import com.gcc.communityHall.repository.SettlementRepository;
  56. import com.gcc.communityHall.repository.UsersRepository;
  57. import com.gcc.communityHall.repository.LoginHallIdRepository;
  58. import com.gcc.communityHall.repository.LoginRepository;
  59. import com.gcc.communityHall.service.BookingService;
  60. import com.gcc.communityHall.service.HallDetailService;
  61. import com.gcc.communityHall.service.ReasonMasterService;
  62. import com.gcc.communityHall.service.UserService;
  63. import jakarta.servlet.http.HttpSession;
  64. import jakarta.transaction.Transactional;
  65. @Controller
  66. @RequestMapping("/communityhall/admin")
  67. public class Admincontroller {
  68. @Autowired
  69. HallDetailService hallDetailService;
  70. @Autowired
  71. ReasonMasterService reasonMasterService;
  72. @Autowired
  73. private BookingDetailsRepository bookingDetailsRepo;
  74. @Autowired
  75. private UsersRepository usersRepository;
  76. @Autowired
  77. private BookingService bookingService;
  78. @Autowired
  79. private UserService userService;
  80. @Autowired
  81. private BookingDetailsRepository bookingDetailsRepository;
  82. @Autowired
  83. private HallDetailsRepository hallDetailsRepo;
  84. @Autowired
  85. private DiscountRangeRepository discountRangeRepo;
  86. @Autowired
  87. private GccBlockingDateRepository blockingDateRepository;
  88. @Autowired
  89. private BookingDetailsRepository bookingRepository;
  90. @Autowired
  91. private AppConfig appConfig;
  92. @Autowired
  93. private JwtUtil jwtUtil;
  94. @Autowired
  95. private NotificationRepository notificationRepository;
  96. @Autowired
  97. private ApplicationLogsRepository applicationLogsRepository;
  98. @Autowired
  99. private TransactionResponseRepository transactionResponseRepository;
  100. @Autowired
  101. private LoginRepository loginRepository;
  102. @Autowired
  103. private LoginHallIdRepository loginHallIdRepository;
  104. @GetMapping("/dashboard")
  105. public String viewDashboard(
  106. @RequestParam(required = false, defaultValue = "all zones") String zone,
  107. Model model, HttpSession session) {
  108. String token = (String) session.getAttribute("jwtToken");
  109. // System.out.println("tokensssssssss"+token);
  110. // Validate JWT token
  111. if (token != null && jwtUtil.validateToken(token)) {
  112. // System.out.println("tokennnnnnnnnnnnnnns"+token);
  113. // Token is valid, proceed with dashboard logic
  114. String adminName = (String) session.getAttribute("usertype");
  115. long mobileno = (long) session.getAttribute("mobileno");
  116. model.addAttribute("mobileno", mobileno);
  117. List<Map<String, Object>> getMonthCount = bookingDetailsRepository.getAllAdminmonthcount(zone);
  118. List<Map<String, Object>> count = bookingDetailsRepository.getAdmincount(zone);
  119. Map<String, Object> map = count.get(0);
  120. model.addAttribute("mounthcount", getMonthCount);
  121. model.addAttribute("APPROVED", map.get("approved_count"));
  122. model.addAttribute("REJECTED", map.get("rejected_count"));
  123. model.addAttribute("PENDING", map.get("pending_count"));
  124. model.addAttribute("CANCELED", map.get("CANCELED"));
  125. model.addAttribute("PAYMENT_FAILURE", map.get("PAYMENT_FAILURE"));
  126. model.addAttribute("GCC_BLOCKED", map.get("GCC_BLOCKED"));
  127. model.addAttribute("adminname", adminName);
  128. model.addAttribute("zone", zone);
  129. return "admin/dashboard";
  130. } else {
  131. // Token is invalid or not present, redirect to logout
  132. session.invalidate(); // Invalidate the session to clear all session attributes
  133. return "redirect:/communityhall/login";
  134. }
  135. }
  136. @GetMapping("/Reports")
  137. public String viewReports(Model model, HttpSession session) {
  138. String adminname = (String) session.getAttribute("usertype");
  139. if (adminname != null) {
  140. long mobileno = (long) session.getAttribute("mobileno");
  141. model.addAttribute("mobileno", mobileno);
  142. return "admin/reports";
  143. } else {
  144. session.invalidate(); // Invalidate the session to clear all session attributes
  145. return "redirect:/communityhall/login";
  146. }
  147. }
  148. @GetMapping("/getReport")
  149. public String getReports(Model model, HttpSession session) {
  150. String adminname = (String) session.getAttribute("usertype");
  151. if (adminname != null) {
  152. long mobileno = (long) session.getAttribute("mobileno");
  153. model.addAttribute("mobileno", mobileno);
  154. return "admin/reports";
  155. } else {
  156. session.invalidate(); // Invalidate the session to clear all session attributes
  157. return "redirect:/communityhall/login";
  158. }
  159. }
  160. @GetMapping("/HallDetails")
  161. public String viewHallDetails(Model model, HttpSession session) {
  162. String adminname = (String) session.getAttribute("usertype");
  163. if (adminname != null) {
  164. long mobileno = (long) session.getAttribute("mobileno");
  165. model.addAttribute("mobileno", mobileno);
  166. return "admin/halldetailslist";
  167. } else {
  168. session.invalidate(); // Invalidate the session to clear all session attributes
  169. return "redirect:/communityhall/login";
  170. }
  171. }
  172. @GetMapping("/halldetailslist")
  173. public String viewhalldetailsList(Model model, HttpSession session) {
  174. List<HallDetails> list = hallDetailsRepo.findAll();
  175. String adminname = (String) session.getAttribute("usertype");
  176. if (adminname != null) {
  177. long mobileno = (long) session.getAttribute("mobileno");
  178. model.addAttribute("mobileno", mobileno);
  179. model.addAttribute("adminname", adminname);
  180. model.addAttribute("halllist", list);
  181. return "admin/halldetailslist";
  182. } else {
  183. session.invalidate(); // Invalidate the session to clear all session attributes
  184. return "redirect:/communityhall/login";
  185. }
  186. }
  187. @GetMapping("/settlement-approved")
  188. public String viewSettlementMaster(Model model, HttpSession session) {
  189. String adminname = (String) session.getAttribute("usertype");
  190. if (adminname != null) {
  191. long mobileno = (long) session.getAttribute("mobileno");
  192. model.addAttribute("mobileno", mobileno);
  193. List<BookingDetails> approvedSettlements = bookingDetailsRepository.findAllWithApprovedRefundStatus();
  194. List<BookingDetails> settlements = new ArrayList<>();
  195. settlements.addAll(approvedSettlements);
  196. List<BookingDetails> approvedcancelledbookings = bookingDetailsRepository.findCancelledList();
  197. List<BookingDetails> approvedrejectedbookings = bookingDetailsRepository.findRejectedList();
  198. model.addAttribute("adminname", adminname);
  199. model.addAttribute("settlementlist", settlements);
  200. model.addAttribute("approvedcancelledbookings", approvedcancelledbookings);
  201. model.addAttribute("approvedrejectedbookings", approvedrejectedbookings);
  202. return "admin/settlement-approved";
  203. } else {
  204. session.invalidate(); // Invalidate the session to clear all session attributes
  205. return "redirect:/communityhall/login";
  206. }
  207. }
  208. @GetMapping("/settlement-initiatedlist")
  209. public String viewSettlementInitiatedMaster(Model model, HttpSession session) {
  210. String adminname = (String) session.getAttribute("usertype");
  211. if (adminname != null) {
  212. long mobileno = (long) session.getAttribute("mobileno");
  213. model.addAttribute("mobileno", mobileno);
  214. List<BookingDetails> settlement = bookingDetailsRepository.findByBookingDetailsRefundStatus();
  215. List<BookingDetails> Initiatedcancelledbookings = bookingDetailsRepository.findInitiatedCancelledList();
  216. List<BookingDetails> Initiatedrejectedbookings = bookingDetailsRepository.findInitiatedRejectedList();
  217. model.addAttribute("title", "settlement initiate");
  218. model.addAttribute("adminname", adminname);
  219. model.addAttribute("settlementlist", settlement);
  220. model.addAttribute("Initiatedcancelledbookings", Initiatedcancelledbookings);
  221. model.addAttribute("Initiatedrejectedbookings", Initiatedrejectedbookings);
  222. return "admin/settlement-initiate";
  223. } else {
  224. session.invalidate(); // Invalidate the session to clear all session attributes
  225. return "redirect:/communityhall/login";
  226. }
  227. }
  228. @GetMapping("/settlement-list")
  229. public String settlementPendingList(Model model, HttpSession session) {
  230. String adminname = (String) session.getAttribute("usertype");
  231. if (adminname != null) {
  232. model.addAttribute("adminname", adminname);
  233. long mobileno = (long) session.getAttribute("mobileno");
  234. model.addAttribute("mobileno", mobileno);
  235. model.addAttribute("title", "settlement Pending");
  236. String zone = (String) session.getAttribute("zone");
  237. model.addAttribute("zone", zone);
  238. List<BookingDetails> settlement = bookingDetailsRepository.findAllSettlementPending();
  239. List<BookingDetails> cancelledbookings = bookingDetailsRepository.findAllSettlementCancelledList();
  240. List<BookingDetails> rejectedbookings = bookingDetailsRepository.findAllSettlementRejectedList();
  241. model.addAttribute("settlementlist", settlement);
  242. // AKI
  243. List<BookingDetails> settlementIntiated = bookingDetailsRepository.findSettlementInitiatedPending();
  244. model.addAttribute("settlementIntiated", settlementIntiated);
  245. model.addAttribute("cancelledbookings", cancelledbookings);
  246. model.addAttribute("rejectedbookings", rejectedbookings);
  247. // System.out.println("Settlement List: " + settlement);
  248. return "admin/settlement-list";
  249. } else {
  250. session.invalidate();
  251. return "redirect:/communityhall/login";
  252. }
  253. }
  254. @GetMapping("/refundfailed-list")
  255. public String RefundFailedList(Model model, HttpSession session) {
  256. String adminname = (String) session.getAttribute("usertype");
  257. if (adminname != null) {
  258. model.addAttribute("adminname", adminname);
  259. long mobileno = (long) session.getAttribute("mobileno");
  260. model.addAttribute("mobileno", mobileno);
  261. model.addAttribute("title", "settlementapproved");
  262. String zone = (String) session.getAttribute("zone");
  263. model.addAttribute("zone", zone);
  264. List<BookingDetails> settlementrefundfailed = bookingDetailsRepository.findAllSettlementRefundFailed();
  265. List<BookingDetails> refundfailedcancelledbookings = bookingDetailsRepository
  266. .findAllRefundFaileCancelledList();
  267. List<BookingDetails> refundfailedrejectedbookings = bookingDetailsRepository
  268. .findAllRefundFaileRejectedList();
  269. model.addAttribute("settlementrefundfailed", settlementrefundfailed);
  270. model.addAttribute("refundfailedcancelledbookings", refundfailedcancelledbookings);
  271. model.addAttribute("refundfailedrejectedbookings", refundfailedrejectedbookings);
  272. return "admin/refund-failedlist";
  273. } else {
  274. session.invalidate();
  275. return "redirect:/communityhall/login";
  276. }
  277. }
  278. @GetMapping("/settlement-completedlist")
  279. public String viewSettlementcompletedMaster(Model model, HttpSession session) {
  280. String adminname = (String) session.getAttribute("usertype");
  281. if (adminname != null) {
  282. long mobileno = (long) session.getAttribute("mobileno");
  283. model.addAttribute("mobileno", mobileno);
  284. List<BookingDetails> completedlist = bookingDetailsRepository.findSettlementCompletedList();
  285. List<BookingDetails> cancelledcompletedlist = bookingDetailsRepository.findCancelledCompletedList();
  286. List<BookingDetails> rejectedcompletedlist = bookingDetailsRepository.findRejectedSettlementCompletedList();
  287. model.addAttribute("title", "settlement initiate");
  288. model.addAttribute("adminname", adminname);
  289. model.addAttribute("completedlist", completedlist);
  290. model.addAttribute("cancelledcompletedlist", cancelledcompletedlist);
  291. model.addAttribute("rejectedcompletedlist", rejectedcompletedlist);
  292. return "admin/settlement-completed";
  293. } else {
  294. session.invalidate(); // Invalidate the session to clear all session attributes
  295. return "redirect:/communityhall/login";
  296. }
  297. }
  298. @GetMapping("/ReasonMaster")
  299. public String viewreasonMaster(Model model, HttpSession session) {
  300. String adminname = (String) session.getAttribute("usertype");
  301. if (adminname != null) {
  302. long mobileno = (long) session.getAttribute("mobileno");
  303. model.addAttribute("mobileno", mobileno);
  304. model.addAttribute("adminname", adminname);
  305. return "admin/reasonmaster";
  306. } else {
  307. session.invalidate(); // Invalidate the session to clear all session attributes
  308. return "redirect:/communityhall/login";
  309. }
  310. }
  311. @GetMapping("/userdeactive")
  312. public String viewuserDetails(Model model, HttpSession session) {
  313. String adminname = (String) session.getAttribute("usertype");
  314. if (adminname != null) {
  315. long mobileno = (long) session.getAttribute("mobileno");
  316. model.addAttribute("mobileno", mobileno);
  317. model.addAttribute("adminname", adminname);
  318. return "admin/userdetails";
  319. } else {
  320. session.invalidate(); // Invalidate the session to clear all session attributes
  321. return "redirect:/communityhall/login";
  322. }
  323. }
  324. @GetMapping("/Gccblocking")
  325. public String viewGccBlocking(Model model, HttpSession session) {
  326. String adminname = (String) session.getAttribute("usertype");
  327. if (adminname != null) {
  328. long mobileno = (long) session.getAttribute("mobileno");
  329. model.addAttribute("mobileno", mobileno);
  330. model.addAttribute("adminname", adminname);
  331. // Fetch all blocked GCC dates
  332. List<GccBlockingDate> gccBlocked = blockingDateRepository.findAllBlocked();
  333. // Ensure distinct by hallId, blockingReason, startDate, and endDate
  334. List<GccBlockingDate> uniqueGccBlockingDates = gccBlocked.stream()
  335. .filter(distinctByKey(g -> Arrays.asList(
  336. g.getHallId(),
  337. g.getBlockingReason(),
  338. g.getStartDate(),
  339. g.getEndDate())))
  340. .collect(Collectors.toList());
  341. // Map to store the count of blocked halls for each GccBlockingDate
  342. Map<Integer, Integer> hallCountMap = new HashMap<>();
  343. for (GccBlockingDate blockedDate : uniqueGccBlockingDates) {
  344. // Parse and count unique hall IDs
  345. String hallIds = blockedDate.getHallId();
  346. if (hallIds != null && !hallIds.isEmpty()) {
  347. Set<String> uniqueHallIds = new HashSet<>(Arrays.asList(hallIds.split(",")));
  348. int hallCount = uniqueHallIds.size();
  349. hallCountMap.put(blockedDate.getBlockingId(), hallCount);
  350. } else {
  351. hallCountMap.put(blockedDate.getBlockingId(), 0); // No halls blocked
  352. }
  353. }
  354. // Add attributes to the model for the view
  355. model.addAttribute("gccblocked", uniqueGccBlockingDates);
  356. model.addAttribute("hallCountMap", hallCountMap);
  357. return "admin/gccblocking";
  358. } else {
  359. session.invalidate(); // Invalidate the session to clear all session attributes
  360. return "redirect:/communityhall/login";
  361. }
  362. }
  363. // ── New enhanced GCC Blocking page (does NOT affect the existing page) ──
  364. @GetMapping("/GccblockingNew")
  365. public String viewGccBlockingNew(Model model, HttpSession session) {
  366. String adminname = (String) session.getAttribute("usertype");
  367. if (adminname != null) {
  368. long mobileno = (long) session.getAttribute("mobileno");
  369. model.addAttribute("mobileno", mobileno);
  370. model.addAttribute("adminname", adminname);
  371. return "admin/gccblocking-new";
  372. } else {
  373. session.invalidate();
  374. return "redirect:/communityhall/login";
  375. }
  376. }
  377. // Utility method to ensure distinct by a key
  378. private static <T> Predicate<T> distinctByKey(Function<? super T, ?> keyExtractor) {
  379. Set<Object> seen = new HashSet<>();
  380. return t -> seen.add(keyExtractor.apply(t));
  381. }
  382. @PostMapping("/saveHallDetails")
  383. public String saveHall(
  384. @RequestParam String hallName,
  385. @RequestParam float depositAmount,
  386. @RequestParam float halfdepositAmt,
  387. @RequestParam float halfDayAmt,
  388. @RequestParam float fullDayAmt,
  389. @RequestParam float gst,
  390. @RequestParam float hallArea,
  391. @RequestParam String ebNumber,
  392. @RequestParam float ebCostPerUnit,
  393. @RequestParam String parkingCapacity,
  394. @RequestParam int seatingCapacity,
  395. @RequestParam String doorNo,
  396. @RequestParam String street,
  397. @RequestParam String area,
  398. @RequestParam String zone,
  399. @RequestParam String division,
  400. @RequestParam(required = false) String landMark,
  401. @RequestParam String city,
  402. @RequestParam int pinCode,
  403. @RequestParam(required = false) String latitude,
  404. @RequestParam(required = false) String longitude,
  405. @RequestParam String hallInchargeName,
  406. @RequestParam long hallInchargeNo,
  407. @RequestParam("hallImages") MultipartFile[] hallImages,
  408. @RequestParam(value = "mfDtUnit", defaultValue = "1", required = false) int mfDtUnit,
  409. HttpSession session) {
  410. String updatedId = (String) session.getAttribute("employeeId");
  411. hallDetailService.saveHallByAdmin(hallName, depositAmount, halfDayAmt, fullDayAmt, gst, hallArea, ebNumber,
  412. ebCostPerUnit, parkingCapacity, seatingCapacity, doorNo,
  413. street, area, zone, division, landMark, city, pinCode, latitude, longitude, hallInchargeName,
  414. hallInchargeNo, updatedId, hallImages, halfdepositAmt, mfDtUnit);
  415. String adminname = (String) session.getAttribute("usertype");
  416. Integer loginid = (Integer) session.getAttribute("id");
  417. ApplicationLogs logs = new ApplicationLogs();
  418. logs.setComments("Action by " + adminname);
  419. logs.setLoginId(loginid);
  420. logs.setLogType("Adding New Hall:-" + hallName);
  421. InetAddress inetAddress;
  422. try {
  423. inetAddress = InetAddress.getLocalHost();
  424. String hostname = InetAddress.getLocalHost().getHostName();
  425. logs.setIpaddress(inetAddress.getHostAddress());
  426. logs.setSystemName(hostname);
  427. } catch (UnknownHostException e) {
  428. e.printStackTrace();
  429. }
  430. applicationLogsRepository.save(logs);
  431. // Redirect to a success page or return a ModelAndView as per your application
  432. // flow
  433. return "redirect:/communityhall/admin/halldetailslist";
  434. }
  435. @GetMapping("/approval-history")
  436. public String viewApproval(Model model, HttpSession session) {
  437. String adminname = (String) session.getAttribute("usertype");
  438. if (adminname != null) {
  439. long mobileno = (long) session.getAttribute("mobileno");
  440. model.addAttribute("mobileno", mobileno);
  441. model.addAttribute("adminname", adminname);
  442. model.addAttribute("adminname", adminname);
  443. model.addAttribute("title", "approvalcontrol");
  444. List<Users> Pending = usersRepository.getPendingList();
  445. String zone = (String) session.getAttribute("zone");
  446. model.addAttribute("zone", zone);
  447. model.addAttribute("pendinglist", Pending);
  448. return "admin/approval-history";
  449. } else {
  450. session.invalidate(); // Invalidate the session to clear all session attributes
  451. return "redirect:/communityhall/login";
  452. }
  453. }
  454. @GetMapping("/user-approved")
  455. public String viewUserApproved(Model model, HttpSession session) {
  456. String adminname = (String) session.getAttribute("usertype");
  457. if (adminname != null) {
  458. long mobileno = (long) session.getAttribute("mobileno");
  459. model.addAttribute("mobileno", mobileno);
  460. model.addAttribute("adminname", adminname);
  461. model.addAttribute("title", "reasondetails");
  462. List<Users> approved = usersRepository.getUserApproved();
  463. String zone = (String) session.getAttribute("zone");
  464. model.addAttribute("zone", zone);
  465. model.addAttribute("approvedlist", approved);
  466. return "admin/user-approved";
  467. } else {
  468. session.invalidate(); // Invalidate the session to clear all session attributes
  469. return "redirect:/communityhall/login";
  470. }
  471. }
  472. @GetMapping("/user-reject")
  473. public String viewUserReject(Model model, HttpSession session) {
  474. String adminname = (String) session.getAttribute("usertype");
  475. if (adminname != null) {
  476. long mobileno = (long) session.getAttribute("mobileno");
  477. model.addAttribute("mobileno", mobileno);
  478. model.addAttribute("adminname", adminname);
  479. model.addAttribute("title", "reasondetails");
  480. List<Users> reject = usersRepository.getUserReject();
  481. String zone = (String) session.getAttribute("zone");
  482. model.addAttribute("zone", zone);
  483. model.addAttribute("rejectedlist", reject);
  484. return "admin/user-reject";
  485. } else {
  486. session.invalidate(); // Invalidate the session to clear all session attributes
  487. return "redirect:/communityhall/login";
  488. }
  489. }
  490. @GetMapping("/booking-list")
  491. public String viewBookingList(Model model, HttpSession session) {
  492. String adminname = (String) session.getAttribute("usertype");
  493. if (adminname != null) {
  494. long mobileno = (long) session.getAttribute("mobileno");
  495. model.addAttribute("mobileno", mobileno);
  496. model.addAttribute("adminname", adminname);
  497. List<BookingDetails> bookingList = bookingDetailsRepository.getAllApprovedList();
  498. model.addAttribute("bookingList", bookingList);
  499. return "admin/booking-list"; // Assuming "officer/rejected-booking-list" is the name of your HTML template
  500. } else {
  501. session.invalidate(); // Invalidate the session to clear all session attributes
  502. return "redirect:/communityhall/login";
  503. }
  504. }
  505. @GetMapping("/rejected-list")
  506. public String viewRejectedBookings(Model model, HttpSession session) {
  507. String adminname = (String) session.getAttribute("usertype");
  508. if (adminname != null) {
  509. long mobileno = (long) session.getAttribute("mobileno");
  510. model.addAttribute("mobileno", mobileno);
  511. model.addAttribute("adminname", adminname);
  512. List<BookingDetails> rejectedBookings = bookingDetailsRepository.getAllRejectingList();
  513. model.addAttribute("rejectedBookings", rejectedBookings);
  514. return "admin/rejected-list";
  515. } else {
  516. session.invalidate(); // Invalidate the session to clear all session attributes
  517. return "redirect:/communityhall/login";
  518. }
  519. }
  520. @GetMapping("/bookingwaitinglist")
  521. public String viewWaitingBookings(Model model, HttpSession session) {
  522. String adminname = (String) session.getAttribute("usertype");
  523. if (adminname != null) {
  524. long mobileno = (long) session.getAttribute("mobileno");
  525. model.addAttribute("mobileno", mobileno);
  526. model.addAttribute("adminname", adminname);
  527. List<BookingDetails> waitingBookings = bookingDetailsRepository.getAllwaitingList();
  528. model.addAttribute("waitingBookings", waitingBookings);
  529. return "admin/bookingwaiting";
  530. } else {
  531. session.invalidate(); // Invalidate the session to clear all session attributes
  532. return "redirect:/communityhall/login";
  533. }
  534. }
  535. @PostMapping("/getReport")
  536. public String generateReport(Model model,
  537. @RequestParam(name = "FromDate") @DateTimeFormat(iso = DateTimeFormat.ISO.DATE) String fromDate,
  538. @RequestParam(name = "ToDate") @DateTimeFormat(iso = DateTimeFormat.ISO.DATE) String toDate,
  539. @RequestParam(name = "request") String request,
  540. @RequestParam(name = "userstatus", required = false) String userstatus,
  541. @RequestParam(name = "usertype", required = false) String usertype,
  542. @RequestParam(name = "bookingStatus", required = false) String bookingStatus,
  543. @RequestParam(name = "refundStatus", required = false) String refundStatus,
  544. @RequestParam(name = "paymentStatus", required = false) String paymentStatus,
  545. @RequestParam(name = "filterby", required = false) String filterby,
  546. @RequestParam(name = "zone1", required = false, defaultValue = "ALL") String zone,
  547. @RequestParam(name = "division1", required = false, defaultValue = "ALL") String division,
  548. @RequestParam(name = "hall1", required = false) Integer hallid,
  549. @RequestParam(name = "basedon", required = false) String basedon,
  550. @RequestParam(name = "bookingId", required = false) Long bookingId,
  551. @RequestParam(name = "reporttype", required = false) String reporttype,
  552. @RequestParam(name = "counterId", required = false) String counterId, HttpSession session)
  553. throws JsonProcessingException {
  554. String adminname = (String) session.getAttribute("usertype");
  555. if (adminname != null) {
  556. long mobileno = (long) session.getAttribute("mobileno");
  557. model.addAttribute("mobileno", mobileno);
  558. List<Users> userList = handleUserRequest(request, fromDate, toDate, userstatus, usertype);
  559. List<Object[]> bookingList = handleBookingRequest(request, fromDate, toDate, bookingStatus, filterby,
  560. bookingId, zone, division, hallid);
  561. List<BookingDetails> bookingSettlementList = handleBookingSettlementRequest(request, fromDate, toDate,
  562. refundStatus, filterby);
  563. // List<Object[]> paymentList = request.equals("3") ?
  564. // bookingService.getAllPaymentsDetails(fromDate, toDate,zone,division,hallid) :
  565. // new ArrayList<>();
  566. List<Object[]> paymentList = new ArrayList<>();
  567. List<Object[]> extrapaymentList = new ArrayList<>();
  568. if (request.equals("3")) {
  569. if (paymentStatus == null || paymentStatus.isEmpty()) {
  570. paymentList = bookingService.getAllPaymentsDetails(fromDate, toDate, null, zone, division, hallid);
  571. } else {
  572. paymentList = bookingService.getAllPaymentsDetails(fromDate, toDate, paymentStatus, zone, division,
  573. hallid);
  574. }
  575. }
  576. if (request.equals("8")) {
  577. if (paymentStatus == null || paymentStatus.isEmpty()) {
  578. extrapaymentList = bookingService.getAllExtraPaymentsDetails(fromDate, toDate, null, zone, division,
  579. hallid);
  580. } else {
  581. extrapaymentList = bookingService.getAllExtraPaymentsDetails(fromDate, toDate, paymentStatus, zone,
  582. division, hallid);
  583. }
  584. }
  585. List<Object[]> userbookingList = request.equals("4")
  586. ? bookingService.getBookingUserDetailsReport(fromDate, toDate)
  587. : new ArrayList<>();
  588. // List<Object[]> hallbookingList = request.equals("5") ?
  589. // bookingService.getBookingHallDetailsReport(fromDate, toDate) : new
  590. // ArrayList<>();
  591. // In your controller method
  592. // Fetch booking count by zone
  593. List<Object[]> totalcount = new ArrayList<>();
  594. int totalBookings = 0;
  595. if ("7".equals(request)) {
  596. if ("zone".equals(basedon)) {
  597. totalcount = bookingDetailsRepository.countBookingsByZone();
  598. // Format zone data
  599. totalcount = totalcount.stream()
  600. .map(data -> new Object[] { "Zone-" + data[0], data[1] })
  601. .collect(Collectors.toList());
  602. } else if ("division".equals(basedon)) {
  603. totalcount = bookingDetailsRepository.countBookingsByDivisions();
  604. // Format division data
  605. totalcount = totalcount.stream()
  606. .map(data -> new Object[] { "Division-" + data[0], data[1] })
  607. .collect(Collectors.toList());
  608. }
  609. totalBookings = totalcount.stream()
  610. .mapToInt(data -> ((Number) data[1]).intValue())
  611. .sum();
  612. }
  613. model.addAttribute("basedon", basedon);
  614. model.addAttribute("totalcount", totalcount);
  615. model.addAttribute("totalBookings", totalBookings);
  616. List<Object[]> hallbookingList = handleBookingHallDetailsReportRequest(request, fromDate, toDate, filterby,
  617. zone, division, hallid);
  618. if ("9".equals(request)) {
  619. if ("abstract".equals(reporttype)) {
  620. List<Object[]> counterBookingList = new ArrayList<>();
  621. counterBookingList = bookingService.getCounterWiseBookingCount(fromDate, toDate);
  622. model.addAttribute("counterBookingList", counterBookingList);
  623. // System.out.println("counterBookingList.." + counterBookingList);
  624. List<Object[]> hallBookingByCounter = bookingService.getHallWiseBookingDetails(fromDate, toDate,
  625. counterId);
  626. // Convert to JSON for JS usage
  627. String hallBookingJson = new ObjectMapper().writeValueAsString(hallBookingByCounter);
  628. model.addAttribute("hallBookingJson", hallBookingJson);
  629. List<Object[]> hallBookingDetails = bookingService.getBookingDetailsForAllHalls(fromDate, toDate,
  630. counterId, hallid);
  631. String hallBookingDetailsJson = new ObjectMapper().writeValueAsString(hallBookingDetails);
  632. model.addAttribute("hallBookingDetailsJson", hallBookingDetailsJson);
  633. } else {
  634. List<Object[]> counterBookingList = new ArrayList<>();
  635. counterBookingList = bookingService.getCounterWiseBookingDetails(fromDate, toDate);
  636. model.addAttribute("counterBookingList", counterBookingList);
  637. }
  638. model.addAttribute("reporttype", reporttype);
  639. }
  640. if ("10".equals(request)) {
  641. List<Object> zoneWiseBookingList = bookingService.getZoneWiseBookingList(fromDate, toDate);
  642. model.addAttribute("zoneWiseBookingList", zoneWiseBookingList);
  643. // Fetch all hall data (not dependent on zone dropdown yet)
  644. List<Object> hallWiseBookingList = bookingService.getAllHallWiseBookingList(fromDate, toDate);
  645. String hallWiseBookingJson = new ObjectMapper().writeValueAsString(hallWiseBookingList);
  646. model.addAttribute("hallWiseBookingList", hallWiseBookingJson);
  647. // Fetch all counter data
  648. List<Object> counterWiseBookingList = bookingService.getAllCounterWiseBookingList(fromDate, toDate);
  649. String counterWiseBookingJson = new ObjectMapper().writeValueAsString(counterWiseBookingList);
  650. model.addAttribute("counterWiseBookingList", counterWiseBookingJson);
  651. }
  652. // ak
  653. if ("11".equals(request)) {
  654. // Fetch Settlement Initiated Report details
  655. List<Object[]> settlementInitiatedList = bookingService.getSettlementInitiatedReport(fromDate, toDate);
  656. // System.out.println("settlementInitatedList" + settlementInitiatedList);
  657. // Add the list to the model
  658. model.addAttribute("settlementInitiatedList", settlementInitiatedList);
  659. }
  660. model.addAttribute("filterby", filterby);
  661. model.addAttribute("users", userList);
  662. model.addAttribute("bookings", bookingList);
  663. model.addAttribute("fromdate", fromDate);
  664. model.addAttribute("todate", toDate);
  665. model.addAttribute("userstatus", userstatus);
  666. model.addAttribute("bookingSettlementList", bookingSettlementList);
  667. model.addAttribute("usertype", usertype);
  668. model.addAttribute("bookingStatus", bookingStatus);
  669. model.addAttribute("refundStatus", refundStatus);
  670. model.addAttribute("paymentStatus", paymentStatus);
  671. model.addAttribute("request", request);
  672. model.addAttribute("paymentLists", paymentList);
  673. model.addAttribute("extrapaymentLists", extrapaymentList);
  674. model.addAttribute("userbookingLists", userbookingList);
  675. model.addAttribute("hallbookingLists", hallbookingList);
  676. model.addAttribute("bookingId", bookingId);
  677. model.addAttribute("zone1", zone);
  678. model.addAttribute("division1", division);
  679. model.addAttribute("hall1", hallid);
  680. model.addAttribute("adminname", adminname);
  681. // System.out.println("request" + request);
  682. return "admin/reports";
  683. } else {
  684. session.invalidate(); // Invalidate the session to clear all session attributes
  685. return "redirect:/communityhall/login";
  686. }
  687. }
  688. private List<Object[]> handleBookingHallDetailsReportRequest(String request, String fromDate, String toDate,
  689. String filterby, String zone, String division, Integer hallid) {
  690. if (!request.equals("5")) {
  691. return new ArrayList<>();
  692. }
  693. if (filterby.isEmpty()) {
  694. return bookingService.getBookingHallDetailsReportByBookingDate(fromDate, toDate, zone, division, hallid);
  695. }
  696. if ("1".equals(filterby)) {
  697. return bookingService.getBookingHallDetailsReportByBookingDate(fromDate, toDate, zone, division, hallid);
  698. }
  699. if ("2".equals(filterby)) {
  700. return bookingService.getBookingHallDetailsReportByEventDate(fromDate, toDate, zone, division, hallid);
  701. }
  702. return new ArrayList<>();
  703. }
  704. private List<Users> handleUserRequest(String request, String fromDate, String toDate, String userstatus,
  705. String usertype) {
  706. if (!request.equals("1")) {
  707. return new ArrayList<>();
  708. }
  709. if ((userstatus != null && !userstatus.isEmpty()) && (usertype != null && !usertype.isEmpty())) {
  710. return userService.getAllUsersWithFilters(fromDate, toDate, userstatus, usertype);
  711. }
  712. if (userstatus.isEmpty() && (usertype != null && !usertype.isEmpty())) {
  713. return userService.getAllUsersWithTypeFilters(fromDate, toDate, usertype);
  714. }
  715. if (usertype.isEmpty() && (userstatus != null && !userstatus.isEmpty())) {
  716. return userService.getAllUsersWithStatusFilters(fromDate, toDate, userstatus);
  717. }
  718. return userService.getAllUsers(fromDate, toDate);
  719. }
  720. private List<Object[]> handleBookingRequest(String request, String fromDate, String toDate, String bookingStatus,
  721. String filterby, Long bookingId, String zone, String division, Integer hallid) {
  722. if (!request.equals("2")) {
  723. return new ArrayList<>();
  724. }
  725. if (filterby.isEmpty() && bookingStatus.isEmpty() && bookingId == null) {
  726. return bookingService.getBookingDetailsByBookingDate(fromDate, toDate, zone, division, hallid);
  727. }
  728. if (bookingId != null && bookingStatus.isEmpty()) {
  729. return bookingDetailsRepo.getAllBookingDetailsWithBookingId(fromDate, toDate, bookingId);
  730. }
  731. if (bookingId != null && !bookingStatus.isEmpty()) {
  732. return bookingDetailsRepo.getAllBookingDetailsWithBookingIdwithbookingStatus(fromDate, toDate, bookingId,
  733. bookingStatus);
  734. }
  735. if (bookingId == null && filterby.isEmpty() && !bookingStatus.isEmpty()) {
  736. return bookingService.getBookingDetailsByBookingDateWithStatus(fromDate, toDate, bookingStatus, zone,
  737. division, hallid);
  738. }
  739. if (!filterby.isEmpty()) {
  740. if ("1".equals(filterby)) {
  741. if (bookingStatus.isEmpty()) {
  742. return bookingService.getBookingDetailsByBookingDate(fromDate, toDate, zone, division, hallid);
  743. } else {
  744. return bookingService.getBookingDetailsByBookingDateWithStatus(fromDate, toDate, bookingStatus,
  745. zone, division, hallid);
  746. }
  747. }
  748. if ("2".equals(filterby)) {
  749. if (bookingStatus.isEmpty()) {
  750. return bookingService.getBookingDetailsByEventDate(fromDate, toDate, zone, division, hallid);
  751. } else {
  752. return bookingService.getBookingDetailsByEventDateWithStatus(fromDate, toDate, bookingStatus, zone,
  753. division, hallid);
  754. }
  755. }
  756. }
  757. // Handle default or error case
  758. return new ArrayList<>();
  759. }
  760. private List<BookingDetails> handleBookingSettlementRequest(String request, String fromDate, String toDate,
  761. String refundStatus, String filterby) {
  762. if (!request.equals("6")) {
  763. return new ArrayList<>();
  764. }
  765. if (filterby.isEmpty() && refundStatus.isEmpty()) {
  766. return bookingService.getAllBookingsettlementDetailsByBookingDate(fromDate, toDate);
  767. }
  768. if (filterby.isEmpty() && !refundStatus.isEmpty()) {
  769. return bookingService.getAllBookingsettlementDetailsByBookingDateWithStatus(fromDate, toDate, refundStatus);
  770. }
  771. if (!filterby.isEmpty()) {
  772. if ("1".equals(filterby)) {
  773. if (refundStatus.isEmpty()) {
  774. return bookingService.getAllBookingsettlementDetailsByBookingDate(fromDate, toDate);
  775. } else {
  776. return bookingService.getAllBookingsettlementDetailsByBookingDateWithStatus(fromDate, toDate,
  777. refundStatus);
  778. }
  779. }
  780. if ("2".equals(filterby)) {
  781. if (refundStatus.isEmpty()) {
  782. return bookingService.getAllBookingsettlementDetailsByEventDate(fromDate, toDate);
  783. } else {
  784. return bookingService.getAllBookingsettlementDetailsByEventDateWithStatus(fromDate, toDate,
  785. refundStatus);
  786. }
  787. }
  788. }
  789. // Handle default or error case
  790. return new ArrayList<>();
  791. }
  792. @GetMapping("/DiscountRange")
  793. public String viewDiscountRange(Model model, HttpSession session) {
  794. String adminname = (String) session.getAttribute("usertype");
  795. if (adminname != null) {
  796. long mobileno = (long) session.getAttribute("mobileno");
  797. model.addAttribute("mobileno", mobileno);
  798. List<DiscountRange> discountRanges = discountRangeRepo.findAll();
  799. model.addAttribute("discountRanges", discountRanges);
  800. model.addAttribute("adminname", adminname);
  801. return "admin/discountrange";
  802. } else {
  803. session.invalidate(); // Invalidate the session to clear all session attributes
  804. return "redirect:/communityhall/login";
  805. }
  806. }
  807. @GetMapping("/ongoingevents")
  808. public String viewRecentevents(Model model, HttpSession session) {
  809. String adminname = (String) session.getAttribute("usertype");
  810. if (adminname != null) {
  811. long mobileno = (long) session.getAttribute("mobileno");
  812. model.addAttribute("mobileno", mobileno);
  813. List<BookingDetails> presenteventslist = bookingDetailsRepository.findPresentBookingList();
  814. List<BookingDetails> pasteventslist = bookingDetailsRepository.findPastEventsList();
  815. List<BookingDetails> futureeventslist = bookingDetailsRepository.findFutureEventsList();
  816. model.addAttribute("title", "settlement initiate");
  817. model.addAttribute("adminname", adminname);
  818. model.addAttribute("presenteventslist", presenteventslist);
  819. model.addAttribute("pasteventslist", pasteventslist);
  820. model.addAttribute("futureeventslist", futureeventslist);
  821. return "admin/ongoingevents";
  822. } else {
  823. session.invalidate(); // Invalidate the session to clear all session attributes
  824. return "redirect:/communityhall/login";
  825. }
  826. }
  827. @GetMapping("/manualrefund")
  828. public String viewManualRefund(Model model, HttpSession session) {
  829. String adminname = (String) session.getAttribute("usertype");
  830. if (adminname != null) {
  831. long mobileno = (long) session.getAttribute("mobileno");
  832. model.addAttribute("mobileno", mobileno);
  833. model.addAttribute("adminname", adminname);
  834. return "admin/manualrefund";
  835. } else {
  836. session.invalidate(); // Invalidate the session to clear all session attributes
  837. return "redirect:/communityhall/login";
  838. }
  839. }
  840. @GetMapping("/developer")
  841. public String viewDeveloper(Model model, HttpSession session) {
  842. String adminname = (String) session.getAttribute("usertype");
  843. if (adminname != null) {
  844. long mobileno = (long) session.getAttribute("mobileno");
  845. model.addAttribute("mobileno", mobileno);
  846. model.addAttribute("adminname", adminname);
  847. return "admin/developer";
  848. } else {
  849. session.invalidate(); // Invalidate the session to clear all session attributes
  850. return "redirect:/communityhall/login";
  851. }
  852. }
  853. // @GetMapping("/getDeveloperdetails")
  854. // public String getDetails(Model model,HttpSession session)
  855. // {
  856. // String adminname = (String) session.getAttribute("usertype");
  857. // if(adminname != null) {
  858. // long mobileno = (long) session.getAttribute("mobileno");
  859. // model.addAttribute("mobileno", mobileno);
  860. // return "admin/developer";
  861. // }else {
  862. // session.invalidate(); // Invalidate the session to clear all session
  863. // attributes
  864. // return "redirect:/communityhall/login";
  865. // }
  866. // }
  867. @PostMapping("/getDeveloperdetails")
  868. public String generatedetails(Model model,
  869. @RequestParam(name = "FromDate") @DateTimeFormat(iso = DateTimeFormat.ISO.DATE) String fromDate,
  870. @RequestParam(name = "ToDate") @DateTimeFormat(iso = DateTimeFormat.ISO.DATE) String toDate,
  871. @RequestParam(name = "request") String request,
  872. @RequestParam(name = "bookingId", required = false) Long bookingId,
  873. @RequestParam(name = "hallId", required = false) Long hallId,
  874. @RequestParam(name = "hallName", required = false) String hallName, HttpSession session) {
  875. String adminname = (String) session.getAttribute("usertype");
  876. if (adminname != null) {
  877. long mobileno = (long) session.getAttribute("mobileno");
  878. model.addAttribute("mobileno", mobileno);
  879. List<Object[]> TransactionResponse = new ArrayList<>();
  880. if (request.equals("1")) {
  881. if (bookingId == null && hallId == null) {
  882. TransactionResponse = bookingService.getTransactionresponse(fromDate, toDate, null, null);
  883. } else if (bookingId != null && hallId == null) {
  884. TransactionResponse = bookingService.getTransactionresponse(fromDate, toDate, bookingId, null);
  885. } else if (bookingId == null && hallId != null) {
  886. TransactionResponse = bookingService.getTransactionresponse(fromDate, toDate, null, hallId);
  887. } else {
  888. TransactionResponse = bookingService.getTransactionresponse(fromDate, toDate, bookingId, hallId);
  889. }
  890. }
  891. List<Object[]> RefundResponse = new ArrayList<>();
  892. if (request.equals("2")) {
  893. if (bookingId == null) {
  894. RefundResponse = bookingService.getRefundResponse(fromDate, toDate, null);
  895. } else {
  896. RefundResponse = bookingService.getRefundResponse(fromDate, toDate, bookingId);
  897. }
  898. }
  899. List<Object[]> BookingCalendar = new ArrayList<>();
  900. if (request.equals("3")) {
  901. // System.out.println("outside");
  902. // if (hallName.isEmpty()) {
  903. // System.out.println("check1");
  904. // // Fetch all details for the given date range
  905. // BookingCalendar = bookingService.getBookingCalendarDetails(fromDate,
  906. // toDate,hallName);
  907. // } else {
  908. // System.out.println("check2");
  909. // // Fetch filtered details based on hallName
  910. // BookingCalendar = bookingService.getBookingCalendarDetails(fromDate, toDate,
  911. // hallName);
  912. // }
  913. BookingCalendar = bookingService.getBookingCalendarDetails(fromDate, toDate, bookingId, hallName);
  914. }
  915. model.addAttribute("fromdate", fromDate);
  916. model.addAttribute("todate", toDate);
  917. model.addAttribute("request", request);
  918. model.addAttribute("TransactionResponse", TransactionResponse);
  919. model.addAttribute("RefundResponse", RefundResponse);
  920. model.addAttribute("BookingCalendar", BookingCalendar);
  921. model.addAttribute("bookingId", bookingId);
  922. model.addAttribute("hallId", hallId);
  923. model.addAttribute("hallName", hallName);
  924. model.addAttribute("adminname", adminname);
  925. return "admin/developer";
  926. } else {
  927. session.invalidate(); // Invalidate the session to clear all session attributes
  928. return "redirect:/communityhall/login";
  929. }
  930. }
  931. @GetMapping("/notification")
  932. public String viewNotificationPage(Model model, HttpSession session) {
  933. String adminname = (String) session.getAttribute("usertype");
  934. if (adminname != null) {
  935. long mobileno = (long) session.getAttribute("mobileno");
  936. List<Notification> newnotifications = notificationRepository.findActivenotifications();
  937. model.addAttribute("newnotifications", newnotifications);
  938. model.addAttribute("mobileno", mobileno);
  939. model.addAttribute("adminname", adminname);
  940. return "admin/notification";
  941. } else {
  942. session.invalidate(); // Invalidate the session to clear all session attributes
  943. return "redirect:/communityhall/login";
  944. }
  945. }
  946. @GetMapping("/raisesettlement")
  947. public String viewcaretakerpage(Model model, HttpSession session, @RequestParam("bookingId") int bookingId) {
  948. String adminname = (String) session.getAttribute("usertype");
  949. if (adminname != null) {
  950. long mobileno = (long) session.getAttribute("mobileno");
  951. model.addAttribute("mobileno", mobileno);
  952. model.addAttribute("adminname", adminname);
  953. BookingDetails booking = bookingService.getBookingsById(bookingId);
  954. model.addAttribute("booking", booking);
  955. return "admin/caretakerpage";
  956. } else {
  957. session.invalidate();
  958. return "redirect:/communityhall/login";
  959. }
  960. }
  961. @GetMapping("/settlementlist")
  962. public String viewSettlementList(Model model, HttpSession session) {
  963. String userType = (String) session.getAttribute("usertype");
  964. if (userType != null) {
  965. List<BookingDetails> settlemetList = bookingRepository.getAllSettlementList();
  966. model.addAttribute("settlemetList", settlemetList);
  967. return "admin/settlementlist";
  968. } else {
  969. session.invalidate();
  970. return "redirect:/communityhall/login";
  971. }
  972. }
  973. @GetMapping("/adminpage")
  974. public String viewcaretaker(Model model, HttpSession session, @RequestParam("bookingId") int bookingId) {
  975. String adminname = (String) session.getAttribute("usertype");
  976. if (adminname != null) {
  977. long mobileno = (long) session.getAttribute("mobileno");
  978. model.addAttribute("mobileno", mobileno);
  979. model.addAttribute("adminname", adminname);
  980. model.addAttribute("title", "Admin");
  981. model.addAttribute("baseURL", appConfig.getBaseUrl());
  982. BookingDetails booking = bookingService.getBookingsById(bookingId);
  983. model.addAttribute("booking", booking);
  984. return "admin/adminpage";
  985. } else {
  986. session.invalidate();
  987. return "redirect:/communityhall/login";
  988. }
  989. }
  990. @GetMapping("/settlement-reject")
  991. public String settlementRejectedList(Model model, HttpSession session) {
  992. String userType = (String) session.getAttribute("usertype");
  993. if (userType != null) {
  994. List<BookingDetails> settlement = bookingDetailsRepository.findAllSettlementRejected();
  995. model.addAttribute("title", "Settlement Rejected");
  996. model.addAttribute("rejectSettlementlist", settlement);
  997. return "admin/settlement-reject";
  998. } else {
  999. session.invalidate();
  1000. return "redirect:/communityhall/login";
  1001. }
  1002. }
  1003. @GetMapping("/logout")
  1004. public String viewLogout(Model model, HttpSession session) {
  1005. session.invalidate();
  1006. return "redirect:/communityhall/login";
  1007. }
  1008. @GetMapping("/viewUploadNoc")
  1009. public String viewUploadNoc(Model model, HttpSession session) {
  1010. String adminname = (String) session.getAttribute("usertype");
  1011. if (adminname != null) {
  1012. long mobileno = (long) session.getAttribute("mobileno");
  1013. model.addAttribute("mobileno", mobileno);
  1014. model.addAttribute("adminname", adminname);
  1015. // Fetch waiting bookings
  1016. List<BookingDetails> waitingBookings = bookingDetailsRepository.getAllwaitingNOC();
  1017. // System.out.println("Waiting Bookings: " + waitingBookings.size());
  1018. model.addAttribute("waitingBookings", waitingBookings);
  1019. return "admin/viewUploadNoc";
  1020. } else {
  1021. session.invalidate(); // Invalidate the session to clear all session attributes
  1022. return "redirect:/communityhall/login";
  1023. }
  1024. }
  1025. // care taker, counter and officer login creation added by kanimozhi 15062026
  1026. @GetMapping("/login-creation")
  1027. public String viewLoginCreation(Model model, HttpSession session) {
  1028. String adminname = (String) session.getAttribute("usertype");
  1029. if (adminname != null && "admin".equals(adminname)) {
  1030. long mobileno = (long) session.getAttribute("mobileno");
  1031. model.addAttribute("mobileno", mobileno);
  1032. model.addAttribute("adminname", adminname);
  1033. // Fetch existing active non-admin logins (returns projection, not full entity)
  1034. List<Map<String, Object>> loginList = loginRepository.findActiveLogins();
  1035. model.addAttribute("loginList", loginList);
  1036. // Fetch hall details for the modal dropdown
  1037. List<Map<String, Object>> hallList = hallDetailsRepo.getAllHalls();
  1038. model.addAttribute("hallList", hallList);
  1039. return "admin/login-creation";
  1040. } else {
  1041. session.invalidate();
  1042. return "redirect:/communityhall/login";
  1043. }
  1044. }
  1045. @PostMapping("/login-creation/save")
  1046. @ResponseBody
  1047. @Transactional
  1048. public Map<String, Object> saveLoginCreation(
  1049. @RequestParam("mobileNumber") long mobileNumber,
  1050. @RequestParam("name") String name,
  1051. @RequestParam("password") String password,
  1052. @RequestParam("userType") String userType,
  1053. @RequestParam("zone") String zone,
  1054. @RequestParam(value = "hallIds", required = false) List<Integer> hallIds,
  1055. HttpSession session) {
  1056. Map<String, Object> response = new HashMap<>();
  1057. String adminname = (String) session.getAttribute("usertype");
  1058. if (adminname == null && "admin".equals(adminname)) {
  1059. response.put("status", "error");
  1060. response.put("message", "Session expired. Please log in again.");
  1061. return response;
  1062. }
  1063. try {
  1064. /* -------- Duplicate hall check for counter / caretaker -------- */
  1065. boolean isSingleMode = "counter".equals(userType) || "caretaker".equals(userType);
  1066. boolean isMulitpleMode = "officer".equals(userType);
  1067. if (isSingleMode && hallIds != null && !hallIds.isEmpty()) {
  1068. int hallId = hallIds.get(0);
  1069. int existingCount = loginRepository.countActiveLoginsByHallId(hallId, userType);
  1070. if (existingCount > 0) {
  1071. // Fetch hall name for a clear message
  1072. String hallName = hallId + "";
  1073. try {
  1074. String fetched = hallDetailsRepo.findHallNameById(hallId);
  1075. if (fetched != null && !fetched.isBlank())
  1076. hallName = fetched;
  1077. } catch (Exception ignored) {
  1078. }
  1079. response.put("status", "error");
  1080. response.put("message", "A login already exists for hall \"" + hallName
  1081. + "\". Only one counter/caretaker login is allowed per hall.");
  1082. return response;
  1083. }
  1084. }
  1085. /* -------- Duplicate hall check for officer -------- */
  1086. if (isMulitpleMode && hallIds != null && !hallIds.isEmpty()) {
  1087. int existingCount = loginRepository.getActiveLoginsByHallIds(hallIds, userType);
  1088. if (existingCount > 0) {
  1089. response.put("status", "error");
  1090. response.put("message",
  1091. "A login already exists for the selected hall(s). Only one officer login is allowed per hall.");
  1092. return response;
  1093. }
  1094. }
  1095. Login login = new Login();
  1096. login.setMobileNumber(mobileNumber);
  1097. login.setName(name);
  1098. login.setPassword(password);
  1099. login.setUserType(userType);
  1100. login.setZone(zone);
  1101. login.setActive(true);
  1102. login.setDelete(false);
  1103. if (hallIds == null || hallIds.isEmpty()) {
  1104. // HQ may have no hall assigned
  1105. loginRepository.save(login);
  1106. } else if (hallIds.size() == 1) {
  1107. // Single hall: store directly in login.hallId
  1108. login.setHallId(hallIds.get(0));
  1109. loginRepository.save(login);
  1110. } else {
  1111. // Multiple halls: store first in hallId, rest in login_hall_ids
  1112. login.setHallId(hallIds.get(0));
  1113. Login savedLogin = loginRepository.save(login);
  1114. for (int hallId : hallIds) {
  1115. LoginHallId loginHallId = new LoginHallId(savedLogin, hallId);
  1116. loginHallIdRepository.save(loginHallId);
  1117. }
  1118. }
  1119. response.put("status", "success");
  1120. response.put("message", "Login created successfully.");
  1121. } catch (Exception e) {
  1122. response.put("status", "error");
  1123. response.put("message", "Error creating login: " + e.getMessage());
  1124. }
  1125. return response;
  1126. }
  1127. @PostMapping("/login-creation/delete/{id}")
  1128. @ResponseBody
  1129. @Transactional
  1130. public Map<String, Object> deleteLogin(@PathVariable("id") int id, HttpSession session) {
  1131. Map<String, Object> response = new HashMap<>();
  1132. String adminname = (String) session.getAttribute("usertype");
  1133. if (adminname == null && "admin".equals(adminname)) {
  1134. response.put("status", "error");
  1135. response.put("message", "Session expired. Please log in again.");
  1136. return response;
  1137. }
  1138. try {
  1139. Login login = loginRepository.findLoginById(id);
  1140. if (login == null) {
  1141. response.put("status", "error");
  1142. response.put("message", "Login not found.");
  1143. return response;
  1144. }
  1145. // Soft delete: set is_active = 0, is_delete = 1
  1146. login.setActive(false);
  1147. login.setDelete(true);
  1148. loginRepository.save(login);
  1149. // Also soft-delete any related login_hall_ids
  1150. loginHallIdRepository.softDeleteByLoginId(id);
  1151. response.put("status", "success");
  1152. response.put("message", "Login deleted successfully.");
  1153. } catch (Exception e) {
  1154. response.put("status", "error");
  1155. response.put("message", "Error deleting login: " + e.getMessage());
  1156. }
  1157. return response;
  1158. }
  1159. @GetMapping("/login-creation/check-mobile")
  1160. @ResponseBody
  1161. public Map<String, Object> checkMobileExists(@RequestParam("mobileNumber") long mobileNumber, HttpSession session) {
  1162. Map<String, Object> response = new HashMap<>();
  1163. try {
  1164. int count = loginRepository.countByMobileNumber(mobileNumber);
  1165. response.put("exists", count > 0);
  1166. } catch (Exception e) {
  1167. response.put("exists", false);
  1168. response.put("error", e.getMessage());
  1169. }
  1170. return response;
  1171. }
  1172. @GetMapping("/login-creation/halls-by-zone")
  1173. @ResponseBody
  1174. public List<Map<String, Object>> getHallsByZone(@RequestParam("zone") String zone, HttpSession session) {
  1175. try {
  1176. return hallDetailsRepo.getHallsByZone(zone);
  1177. } catch (Exception e) {
  1178. return new java.util.ArrayList<>();
  1179. }
  1180. }
  1181. @GetMapping("/login-creation/get-login-halls")
  1182. @ResponseBody
  1183. public Map<String, Object> getLoginHalls(@RequestParam("loginId") int loginId, HttpSession session) {
  1184. Map<String, Object> response = new HashMap<>();
  1185. try {
  1186. Login login = loginRepository.findLoginById(loginId);
  1187. if (login == null) {
  1188. response.put("status", "error");
  1189. response.put("message", "Login not found.");
  1190. return response;
  1191. }
  1192. // Collect all assigned hall IDs
  1193. java.util.List<Integer> assignedHallIds = new java.util.ArrayList<>();
  1194. if (login.getHallId() != 0) {
  1195. assignedHallIds.add(login.getHallId());
  1196. }
  1197. loginHallIdRepository.findActiveByLoginId(loginId).forEach(lh -> assignedHallIds.add(lh.getHallId()));
  1198. response.put("status", "success");
  1199. response.put("loginId", loginId);
  1200. response.put("name", login.getName());
  1201. response.put("zone", login.getZone());
  1202. response.put("userType", login.getUserType());
  1203. response.put("assignedHallIds", assignedHallIds);
  1204. // Also return all halls for the zone
  1205. response.put("hallsForZone", hallDetailsRepo.getHallsByZone(login.getZone()));
  1206. } catch (Exception e) {
  1207. response.put("status", "error");
  1208. response.put("message", "Error fetching login halls: " + e.getMessage());
  1209. }
  1210. return response;
  1211. }
  1212. @PostMapping("/login-creation/update-halls")
  1213. @ResponseBody
  1214. @Transactional
  1215. public Map<String, Object> updateLoginHalls(
  1216. @RequestParam("loginId") int loginId,
  1217. @RequestParam("hallIds") java.util.List<Integer> hallIds,
  1218. HttpSession session) {
  1219. Map<String, Object> response = new HashMap<>();
  1220. try {
  1221. Login login = loginRepository.findLoginById(loginId);
  1222. if (login == null) {
  1223. response.put("status", "error");
  1224. response.put("message", "Login not found.");
  1225. return response;
  1226. }
  1227. if (hallIds == null || hallIds.isEmpty()) {
  1228. response.put("status", "error");
  1229. response.put("message", "At least one hall must be selected.");
  1230. return response;
  1231. }
  1232. // Clear all existing login_hall_ids rows for this login
  1233. loginHallIdRepository.softDeleteByLoginId(loginId);
  1234. if (hallIds.size() == 1) {
  1235. // Single hall: store in login.hall_id only
  1236. login.setHallId(hallIds.get(0));
  1237. loginRepository.save(login);
  1238. } else {
  1239. // Multiple halls: first goes to login.hall_id, rest to login_hall_ids
  1240. login.setHallId(hallIds.get(0));
  1241. loginRepository.save(login);
  1242. for (int i = 1; i < hallIds.size(); i++) {
  1243. LoginHallId lh = new LoginHallId(login, hallIds.get(i));
  1244. loginHallIdRepository.save(lh);
  1245. }
  1246. }
  1247. response.put("status", "success");
  1248. response.put("message", "Hall assignment updated successfully.");
  1249. } catch (Exception e) {
  1250. response.put("status", "error");
  1251. response.put("message", "Error updating halls: " + e.getMessage());
  1252. }
  1253. return response;
  1254. }
  1255. }