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.

1595 lines
74 KiB

​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. package com.gcc.communityHall.controller;
  2. import java.io.IOException;
  3. import java.net.InetAddress;
  4. import java.net.UnknownHostException;
  5. import java.text.ParseException;
  6. import java.text.SimpleDateFormat;
  7. import java.time.LocalDate;
  8. import java.time.ZoneId;
  9. import java.time.format.DateTimeFormatter;
  10. import java.util.ArrayList;
  11. import java.util.Arrays;
  12. import java.util.Collections;
  13. import java.util.Date;
  14. import java.util.HashMap;
  15. import java.util.HashSet;
  16. import java.util.List;
  17. import java.util.Map;
  18. import java.util.Optional;
  19. import java.util.Set;
  20. import java.util.function.Function;
  21. import java.util.function.Predicate;
  22. import java.util.stream.Collectors;
  23. import org.springframework.beans.factory.annotation.Autowired;
  24. import org.springframework.beans.factory.annotation.Value;
  25. import org.springframework.format.annotation.DateTimeFormat;
  26. import org.springframework.http.HttpStatus;
  27. import org.springframework.http.ResponseEntity;
  28. import org.springframework.ui.Model;
  29. import org.springframework.validation.annotation.Validated;
  30. import org.springframework.web.bind.annotation.DeleteMapping;
  31. import org.springframework.web.bind.annotation.ExceptionHandler;
  32. import org.springframework.web.bind.annotation.GetMapping;
  33. import org.springframework.web.bind.annotation.PathVariable;
  34. import org.springframework.web.bind.annotation.PostMapping;
  35. import org.springframework.web.bind.annotation.PutMapping;
  36. import org.springframework.web.bind.annotation.RequestBody;
  37. import org.springframework.web.bind.annotation.RequestMapping;
  38. import org.springframework.web.bind.annotation.RequestParam;
  39. import org.springframework.web.bind.annotation.ResponseBody;
  40. import org.springframework.web.bind.annotation.RestController;
  41. import org.springframework.web.method.annotation.MethodArgumentTypeMismatchException;
  42. import org.springframework.web.multipart.MultipartFile;
  43. import com.gcc.communityHall.component.JwtUtil;
  44. import com.gcc.communityHall.dto.BookingResponseDTO;
  45. import com.gcc.communityHall.dto.ErrorResponseDto;
  46. import com.gcc.communityHall.entity.ApplicationLogs;
  47. import com.gcc.communityHall.entity.BookingCalendar;
  48. import com.gcc.communityHall.entity.BookingDetails;
  49. import com.gcc.communityHall.entity.BookingDetails.BookingStatus;
  50. import com.gcc.communityHall.entity.BookingDetails.RefundStatus;
  51. import com.gcc.communityHall.entity.DiscountRange;
  52. import com.gcc.communityHall.entity.FloorDetails;
  53. import com.gcc.communityHall.entity.GccBlockingDate;
  54. import com.gcc.communityHall.entity.GccBlockingHistory;
  55. import com.gcc.communityHall.entity.HallDetails;
  56. import com.gcc.communityHall.entity.HallImages;
  57. import com.gcc.communityHall.entity.Notification;
  58. import com.gcc.communityHall.entity.ReasonDocumentMaster;
  59. import com.gcc.communityHall.entity.ReasonMaster;
  60. import com.gcc.communityHall.entity.Settlement;
  61. import com.gcc.communityHall.entity.Users;
  62. import com.gcc.communityHall.others.AppConfig;
  63. import com.gcc.communityHall.others.UserSession;
  64. import com.gcc.communityHall.paymentService.service.PaymentGatewayServiceImpl;
  65. import com.gcc.communityHall.repository.ApplicationLogsRepository;
  66. import com.gcc.communityHall.repository.BookingCalendarRepository;
  67. import com.gcc.communityHall.repository.BookingDetailsRepository;
  68. import com.gcc.communityHall.repository.DiscountRangeRepository;
  69. import com.gcc.communityHall.repository.GccBlockingDateRepository;
  70. import com.gcc.communityHall.repository.GccBlockingHistoryRepository;
  71. import com.gcc.communityHall.repository.HallDetailsRepository;
  72. import com.gcc.communityHall.repository.HallReasonRestrictionRepository;
  73. import com.gcc.communityHall.repository.HallImagesRepository;
  74. import com.gcc.communityHall.repository.NotificationRepository;
  75. import com.gcc.communityHall.repository.ReasonMasterRepository;
  76. import com.gcc.communityHall.repository.SettlementRepository;
  77. import com.gcc.communityHall.repository.UsersRepository;
  78. import com.gcc.communityHall.service.BookingService;
  79. import com.gcc.communityHall.service.HallDetailService;
  80. import com.gcc.communityHall.service.ReasonMasterService;
  81. import com.gcc.communityHall.service.SettlementService;
  82. import com.gcc.communityHall.service.UserService;
  83. import com.gcc.communityHall.service.Impl.BookingServiceImpl;
  84. import io.swagger.v3.oas.annotations.Operation;
  85. import io.swagger.v3.oas.annotations.responses.ApiResponse;
  86. import io.swagger.v3.oas.annotations.responses.ApiResponses;
  87. import io.swagger.v3.oas.annotations.tags.Tag;
  88. import io.swagger.v3.oas.annotations.media.Content;
  89. import io.swagger.v3.oas.annotations.media.Schema;
  90. import io.swagger.v3.oas.annotations.media.ExampleObject;
  91. import jakarta.servlet.http.HttpServletRequest;
  92. import jakarta.servlet.http.HttpServletResponse;
  93. import jakarta.servlet.http.HttpSession;
  94. import lombok.AllArgsConstructor;
  95. //@RestController
  96. //@RequestMapping("/admin/api")
  97. @Tag(name = "CRUD REST APIs for HQ's in CommunityHall", description = "CRUD REST APIs in CommunityHall to CREATE, UPDATE, FETCH AND DELETE Booking details")
  98. @RestController
  99. @RequestMapping("/communityhall/headquarters/api")
  100. @AllArgsConstructor
  101. @Validated
  102. public class HQAPIController {
  103. @Autowired
  104. private HallDetailsRepository hallDetailsRepository;
  105. @Autowired
  106. private HallDetailService hallDetailService;
  107. @Autowired
  108. private BookingDetailsRepository bookingDetailsRepository;
  109. @Autowired
  110. private SettlementService settlementService;
  111. @Autowired
  112. private SettlementRepository settlementRepository;
  113. @Autowired
  114. private BookingServiceImpl bookingService;
  115. @Autowired
  116. private BookingDetailsRepository bookingDetailsRepo;
  117. @Autowired
  118. private DiscountRangeRepository discountRangeRepo;
  119. @Autowired
  120. private GccBlockingDateRepository blockingDateRepository;
  121. @Autowired
  122. private ReasonMasterService reasonMasterService;
  123. @Autowired
  124. private HallDetailService hallService;
  125. @Autowired
  126. private UserService userService;
  127. @Autowired
  128. private BookingCalendarRepository bookingCalendarRepository;
  129. @Autowired
  130. private UsersRepository userRepository;
  131. @Autowired
  132. private HallImagesRepository hallImagesRepository;
  133. @Autowired
  134. private JwtUtil jwtUtil;
  135. @Autowired
  136. private AppConfig appConfig;
  137. @Autowired
  138. private PaymentGatewayServiceImpl paymentGatewayServiceImpl;
  139. @Autowired
  140. private NotificationRepository notificationRepo;
  141. @Autowired
  142. private HttpSession session;
  143. @Autowired
  144. private ApplicationLogsRepository applicationLogsRepository;
  145. @Autowired
  146. private HallReasonRestrictionRepository hallReasonRestrictionRepository;
  147. @Autowired
  148. private BookingServiceImpl bookingServiceImpl;
  149. @Operation(summary = "Update HallDetails REST API", description = "REST API to update the Hall Details")
  150. @ApiResponses({
  151. @ApiResponse(responseCode = "200", description = "HTTP Status UPDATED", content = @Content(mediaType = "text/plain", schema = @Schema(implementation = HallDetails.class), examples = @ExampleObject(value = "Hall details updated successfully"))),
  152. @ApiResponse(responseCode = "500", description = "HTTP Status Internal Server Error", content = @Content(mediaType = "application/json", schema = @Schema(implementation = ErrorResponseDto.class), examples = @ExampleObject(name = "Internal Server Error Example", value = "{ \"path\": \"/updateHallDetails\", \"status\": 500, \"error\": \"Internal Server Error\", \"timestamp\": \"2024-06-22T05:47:04.347+00:00\" }")))
  153. })
  154. @PostMapping("/updateHallDetails")
  155. public ResponseEntity<String> updateHallInfo(
  156. @RequestParam("hallId") String hallId,
  157. @RequestParam("zone") String zone,
  158. @RequestParam("division") String division,
  159. @RequestParam("hallName") String hallName,
  160. @RequestParam("hallArea") String hallArea,
  161. @RequestParam("doorNo") String doorNo,
  162. @RequestParam("street") String street,
  163. @RequestParam("area") String area,
  164. @RequestParam("pinCode") int pinCode,
  165. @RequestParam("landMark") String landMark,
  166. @RequestParam("latitude") String latitude,
  167. @RequestParam("longitude") String longitude,
  168. @RequestParam("hallInchargeMobno") long hallInchargeMobno,
  169. @RequestParam("hallInchargeName") String hallInchargeName,
  170. @RequestParam("depositAmount") float depositAmount,
  171. @RequestParam("halfDepositAmount") float halfDepositAmount,
  172. @RequestParam("fullDayRent") float fullDayRent,
  173. @RequestParam("halfDayRent") float halfDayRent,
  174. @RequestParam("parkingCapacity") String parkingCapacity,
  175. @RequestParam("seatingCapacity") int seatingCapacity,
  176. @RequestParam(value = "images", required = false) List<MultipartFile> images,
  177. @RequestParam("ebNumber") String ebNumber,
  178. @RequestParam("ebCostPerUnit") float ebCostPerUnit,
  179. @RequestParam("gst") float gst,
  180. @RequestParam("city") String city,
  181. @RequestParam("isActive") boolean isActive,
  182. @RequestParam(value = "floorName", required = false) List<String> floorNames,
  183. @RequestParam(value = "floorCapacity", required = false) List<Double> floorCapacities) {
  184. HallDetails hallDetails = new HallDetails();
  185. hallDetails.setHallId(Integer.parseInt(hallId));
  186. hallDetails.setZone(zone);
  187. hallDetails.setDivision(division);
  188. hallDetails.setHallName(hallName);
  189. hallDetails.setHallArea(Float.parseFloat(hallArea));
  190. hallDetails.setDoorNo(doorNo);
  191. hallDetails.setStreet(street);
  192. hallDetails.setArea(area);
  193. hallDetails.setPinCode(pinCode);
  194. hallDetails.setLandMark(landMark);
  195. hallDetails.setLatitude(latitude);
  196. hallDetails.setLongitude(longitude);
  197. hallDetails.setHallInchargeMobno(hallInchargeMobno);
  198. hallDetails.setHallInchargeName(hallInchargeName);
  199. hallDetails.setDepositAmount(depositAmount);
  200. hallDetails.setHalfDepositAmount(halfDepositAmount);
  201. hallDetails.setFullDayRent(fullDayRent);
  202. hallDetails.setHalfDayRent(halfDayRent);
  203. hallDetails.setParkingCapacity(parkingCapacity);
  204. hallDetails.setSeatingCapacity(seatingCapacity);
  205. hallDetails.setEbNumber(ebNumber);
  206. hallDetails.setEbCostPerUnit(ebCostPerUnit);
  207. hallDetails.setGst(gst);
  208. hallDetails.setCity(city);
  209. hallDetails.setActive(isActive);
  210. hallDetailService.updateHallDetail(hallDetails, images);
  211. // Update floor details for this hall (HQ only addition)
  212. hallDetailService.updateFloorDetails(Integer.parseInt(hallId), floorNames, floorCapacities);
  213. String adminname = (String) session.getAttribute("usertype");
  214. Integer loginid = (Integer) session.getAttribute("id");
  215. ApplicationLogs logs = new ApplicationLogs();
  216. logs.setComments("Action by " + adminname);
  217. logs.setLoginId(loginid);
  218. logs.setLogType("Hall Details edit:-" + hallName);
  219. InetAddress inetAddress;
  220. try {
  221. inetAddress = InetAddress.getLocalHost();
  222. String hostname = InetAddress.getLocalHost().getHostName();
  223. logs.setIpaddress(inetAddress.getHostAddress());
  224. logs.setSystemName(hostname);
  225. } catch (UnknownHostException e) {
  226. e.printStackTrace();
  227. }
  228. applicationLogsRepository.save(logs);
  229. return ResponseEntity.ok("Success");
  230. }
  231. @Operation(summary = "Update Settlement Status REST API", description = "REST API to update the Settlement Status to INITIATED")
  232. @ApiResponses({
  233. @ApiResponse(responseCode = "200", description = "HTTP Status UPDATED", content = @Content(mediaType = "application/json", schema = @Schema(implementation = Settlement.class), examples = @ExampleObject(name = "Settlement Example", value = "{\"settlementId\": Id, \"Refundstatus\": \"INITIATED\", \"comments\": \"Settlement initiated successfully\"}"))),
  234. @ApiResponse(responseCode = "500", description = "HTTP Status Internal Server Error", content = @Content(mediaType = "application/json", schema = @Schema(implementation = ErrorResponseDto.class), examples = @ExampleObject(name = "Internal Server Error Example", value = "{ \"path\": \"/updateInitiatedSettlementStatus/{settlementId}\", \"status\": 500, \"error\": \"Internal Server Error\", \"timestamp\": \"2024-06-22T05:47:04.347+00:00\" }")))
  235. })
  236. @PostMapping("/updateInitiatedSettlementStatus/{settlementId}")
  237. public ResponseEntity<Settlement> updateInitiatedSettlementStatus(
  238. @PathVariable("settlementId") int settlementId,
  239. @RequestParam("status") BookingDetails.RefundStatus status,
  240. @RequestParam("comments") String comments) {
  241. Settlement updateInitialiseSettlement = settlementService.updateSettlementStatus(settlementId, status,
  242. comments);
  243. String adminname = (String) session.getAttribute("usertype");
  244. Integer loginid = (Integer) session.getAttribute("id");
  245. ApplicationLogs logs = new ApplicationLogs();
  246. logs.setComments("Action by " + adminname);
  247. logs.setLoginId(loginid);
  248. logs.setLogType("Settlement Initiation:-" + status);
  249. InetAddress inetAddress;
  250. try {
  251. inetAddress = InetAddress.getLocalHost();
  252. String hostname = InetAddress.getLocalHost().getHostName();
  253. logs.setIpaddress(inetAddress.getHostAddress());
  254. logs.setSystemName(hostname);
  255. } catch (UnknownHostException e) {
  256. e.printStackTrace();
  257. }
  258. applicationLogsRepository.save(logs);
  259. if (updateInitialiseSettlement != null) {
  260. return new ResponseEntity<>(updateInitialiseSettlement, HttpStatus.OK);
  261. } else {
  262. return new ResponseEntity<>(HttpStatus.NOT_FOUND);
  263. }
  264. }
  265. @Operation(summary = "HallDetails by HallId REST API", description = "REST API to Retrieving the Hall Details by hallId")
  266. @ApiResponses({
  267. @ApiResponse(responseCode = "200", description = "HTTP Status OK", content = @Content(mediaType = "application/json", schema = @Schema(implementation = HallDetails.class))),
  268. @ApiResponse(responseCode = "400", description = "Bad Request"),
  269. @ApiResponse(responseCode = "404", description = "Not Found")
  270. })
  271. @GetMapping("/getHallDetails/{hallId}")
  272. public ResponseEntity<HallDetails> getHallDetails(@PathVariable String hallId) {
  273. int id;
  274. try {
  275. id = Integer.parseInt(hallId);
  276. } catch (NumberFormatException e) {
  277. return ResponseEntity.badRequest().build();
  278. }
  279. HallDetails hallDetails = hallDetailsRepository.findHallDetailsById(id);
  280. // System.out.println(hallDetails.isActive());
  281. if (hallDetails != null) {
  282. return ResponseEntity.ok(hallDetails);
  283. } else {
  284. return ResponseEntity.notFound().build();
  285. }
  286. }
  287. @Operation(summary = "Saving the DiscountRange REST API", description = "REST API to Saving the Discount Range for usertypes")
  288. @PostMapping("/savediscountrange")
  289. public String saveDiscountrange(
  290. @RequestParam String userType,
  291. @RequestParam float discountRange, HttpSession session) {
  292. Optional<DiscountRange> existingDiscountRanges = discountRangeRepo.findByUsertype(userType);
  293. if (!existingDiscountRanges.isEmpty()) {
  294. return "waiting";
  295. }
  296. String adminname = (String) session.getAttribute("usertype");
  297. DiscountRange discount = new DiscountRange();
  298. discount.setUsertype(userType);
  299. discount.setDiscountRange(discountRange);
  300. discount.setcDate(LocalDate.now());
  301. discount.setUpdtedBy(adminname);
  302. discount.setIs_active(true);
  303. discount.setIs_delete(false);
  304. discountRangeRepo.save(discount);
  305. return "success";
  306. }
  307. @PostMapping("/savenotification")
  308. public String saveNotification(
  309. @RequestParam String notification, HttpSession session) {
  310. String adminname = (String) session.getAttribute("usertype");
  311. Notification newnotification = new Notification();
  312. newnotification.setNotification_description(notification);
  313. newnotification.setCdate(LocalDate.now());
  314. newnotification.setCreatedBY(adminname);
  315. newnotification.setActive(true);
  316. newnotification.setDelete(false);
  317. notificationRepo.save(newnotification);
  318. Integer loginid = (Integer) session.getAttribute("id");
  319. ApplicationLogs logs = new ApplicationLogs();
  320. logs.setComments("Action by " + adminname);
  321. logs.setLoginId(loginid);
  322. logs.setLogType("Added New Notification:-" + newnotification.getNotification_description());
  323. InetAddress inetAddress;
  324. try {
  325. inetAddress = InetAddress.getLocalHost();
  326. String hostname = InetAddress.getLocalHost().getHostName();
  327. logs.setIpaddress(inetAddress.getHostAddress());
  328. logs.setSystemName(hostname);
  329. } catch (UnknownHostException e) {
  330. e.printStackTrace();
  331. }
  332. applicationLogsRepository.save(logs);
  333. return "success";
  334. }
  335. @Operation(summary = " Update the DiscountRange REST API", description = "REST API to Updating the Discount Range for usertypes")
  336. @PutMapping("/updateById/{id}")
  337. public String updateDiscountRangeById(@PathVariable int id, @RequestParam float discountRange,
  338. HttpSession session) {
  339. String adminname = (String) session.getAttribute("usertype");
  340. Optional<DiscountRange> existingDiscount = discountRangeRepo.findById(id);
  341. if (existingDiscount.isPresent()) {
  342. DiscountRange updatediscount = existingDiscount.get();
  343. updatediscount.setDiscountRange(discountRange);
  344. updatediscount.setUpdtedBy(adminname);
  345. updatediscount.setcDate(LocalDate.now());
  346. discountRangeRepo.save(updatediscount);
  347. Integer loginid = (Integer) session.getAttribute("id");
  348. ApplicationLogs logs = new ApplicationLogs();
  349. logs.setComments("Action by " + adminname);
  350. logs.setLoginId(loginid);
  351. logs.setLogType("Discount Details Update:-" + updatediscount.getUsertype());
  352. InetAddress inetAddress;
  353. try {
  354. inetAddress = InetAddress.getLocalHost();
  355. String hostname = InetAddress.getLocalHost().getHostName();
  356. logs.setIpaddress(inetAddress.getHostAddress());
  357. logs.setSystemName(hostname);
  358. } catch (UnknownHostException e) {
  359. e.printStackTrace();
  360. }
  361. applicationLogsRepository.save(logs);
  362. return "success";
  363. } else {
  364. return "error: Entry with ID " + id + " not found";
  365. }
  366. }
  367. @Operation(summary = " Delete the DiscountRange REST API", description = "REST API to Deleting the Discount for usertypes")
  368. @DeleteMapping("/deleteById/{id}")
  369. public ResponseEntity<String> deleteDiscountRangeById(@PathVariable int id) {
  370. if (discountRangeRepo.existsById(id)) {
  371. discountRangeRepo.deleteById(id);
  372. String adminname = (String) session.getAttribute("usertype");
  373. Integer loginid = (Integer) session.getAttribute("id");
  374. ApplicationLogs logs = new ApplicationLogs();
  375. logs.setComments("Action by " + adminname);
  376. logs.setLoginId(loginid);
  377. logs.setLogType("Discount Details Delete:-" + id);
  378. InetAddress inetAddress;
  379. try {
  380. inetAddress = InetAddress.getLocalHost();
  381. String hostname = InetAddress.getLocalHost().getHostName();
  382. logs.setIpaddress(inetAddress.getHostAddress());
  383. logs.setSystemName(hostname);
  384. } catch (UnknownHostException e) {
  385. e.printStackTrace();
  386. }
  387. applicationLogsRepository.save(logs);
  388. return ResponseEntity.ok("DiscountRange with ID " + id + " deleted successfully.");
  389. } else {
  390. return ResponseEntity.notFound().build(); // Return 404 if the entry does not exist
  391. }
  392. }
  393. @PostMapping("/deletenotificationById/{id}")
  394. public ResponseEntity<String> deleteNotificationById(@PathVariable int id, HttpSession session) {
  395. Optional<Notification> notification = notificationRepo.findById(id);
  396. Notification newnotification = notification.get();
  397. newnotification.setActive(false);
  398. newnotification.setDelete(true);
  399. String adminname = (String) session.getAttribute("usertype");
  400. newnotification.setUpdatedBy(adminname);
  401. String date = LocalDate.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd"));
  402. newnotification.setUpdatedDate(date);
  403. notificationRepo.save(newnotification);
  404. Integer loginid = (Integer) session.getAttribute("id");
  405. ApplicationLogs logs = new ApplicationLogs();
  406. logs.setComments("Action by " + adminname);
  407. logs.setLoginId(loginid);
  408. logs.setLogType("Detele Notification:-" + newnotification.getNotification_description());
  409. InetAddress inetAddress;
  410. try {
  411. inetAddress = InetAddress.getLocalHost();
  412. String hostname = InetAddress.getLocalHost().getHostName();
  413. logs.setIpaddress(inetAddress.getHostAddress());
  414. logs.setSystemName(hostname);
  415. } catch (UnknownHostException e) {
  416. e.printStackTrace();
  417. }
  418. applicationLogsRepository.save(logs);
  419. return ResponseEntity.ok("Notification with ID " + id + " deleted successfully.");
  420. }
  421. @Operation(summary = "Retrieving the Discount Details REST API", description = "REST API to Retrieve the Discount Details for usertypes")
  422. // Retrieving the Discount Details
  423. @GetMapping("/getDiscountDetails")
  424. public Optional<DiscountRange> getDIscountDetails(@RequestParam("id") int id) {
  425. Optional<DiscountRange> discountdetails = discountRangeRepo.findById(id);
  426. return discountdetails;
  427. }
  428. @Operation(summary = "Save Reasons REST API", description = "REST API to save the reasons")
  429. // saving the Reason
  430. @PostMapping("/saveReason")
  431. public ResponseEntity<?> saveReason(@RequestBody ReasonMaster reasaon) {
  432. return ResponseEntity.ok(reasonMasterService.saveTheReason(reasaon));
  433. }
  434. @Operation(summary = "All Reasons REST API", description = "REST API to retrie the allreasons")
  435. // retrieving the allreasons
  436. @GetMapping("/getReasons")
  437. @ResponseBody
  438. public List<ReasonMaster> getAllReasons() {
  439. return reasonMasterService.getAllReasons();
  440. }
  441. // retrieving allowed reasons for a specific hall (filtered by restriction)
  442. @GetMapping("/getAllowedReasons")
  443. @ResponseBody
  444. public List<ReasonMaster> getAllowedReasons(@RequestParam int hallId) {
  445. HallDetails hallDetails = hallDetailsRepository.findHallDetailsById(hallId);
  446. if (hallDetails != null && hallDetails.isReasonRestricted()) {
  447. List<Integer> allowedReasonIds = hallReasonRestrictionRepository.findReasonIdsByHallId(hallId);
  448. if (!allowedReasonIds.isEmpty()) {
  449. List<ReasonMaster> allReasons = reasonMasterService.getAllReasons();
  450. return allReasons.stream()
  451. .filter(r -> allowedReasonIds.contains(r.getReasonId()))
  452. .collect(java.util.stream.Collectors.toList());
  453. }
  454. }
  455. return reasonMasterService.getAllReasons();
  456. }
  457. @Operation(summary = "Reason Documents by reasonId REST API", description = "REST API to Get the ReasonDocuments By reasonId")
  458. // Getting ReasonDocuments By reasonId
  459. @GetMapping("/getReasonDocumentDetails")
  460. public List<ReasonDocumentMaster> getReasonDocumentDetails(@RequestParam int reasonId) {
  461. return reasonMasterService.getReasonDocumentDetailsByReasonId(reasonId);
  462. }
  463. @Operation(summary = "Booking Details by Fromdate,toDate and HallId REST API", description = "REST API to get the Booking Details by Fromdate,toDate and HallId for GccBlokcing")
  464. // @GetMapping("/filter")
  465. // public ResponseEntity<List<BookingResponseDTO>> getFilteredBookings(
  466. // @RequestParam("fromDate") @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate
  467. // fromDate,
  468. // @RequestParam("toDate") @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate
  469. // toDate,
  470. // @RequestParam("hallIds") List<Long> hallIds) {
  471. //
  472. // List<BookingDetails> bookings = bookingService.getFilteredBookings(fromDate,
  473. // toDate, hallIds);
  474. //
  475. // List<BookingResponseDTO> responses = new ArrayList<>();
  476. // for (BookingDetails bookingDetails : bookings) {
  477. // // Fetch GccBlockingDate records for each bookingId
  478. // List<GccBlockingDate> gccBlockedList =
  479. // blockingDateRepository.getByBookingId(bookingDetails.getBookingId());
  480. // Integer blockingId = gccBlockedList.isEmpty() ? null :
  481. // gccBlockedList.get(0).getBlockingId();
  482. // responses.add(new BookingResponseDTO(bookingDetails, blockingId));
  483. // }
  484. //
  485. // return ResponseEntity.ok(responses);
  486. // }
  487. @GetMapping("/filter")
  488. public ResponseEntity<Map<String, Object>> getFilteredBookings(
  489. @RequestParam("fromDate") @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate fromDate,
  490. @RequestParam("toDate") @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate toDate,
  491. @RequestParam("hallIds") List<Long> hallIds) {
  492. List<BookingDetails> bookings = bookingService.getFilteredBookings(fromDate, toDate, hallIds);
  493. List<GccBlockingDate> gccBlockedList = blockingDateRepository
  494. .findByFromDateAndToDateBetweenAndHallIdIn(fromDate, toDate, hallIds);
  495. Map<String, Object> response = new HashMap<>();
  496. response.put("bookings", bookings);
  497. response.put("blockedEvents", gccBlockedList);
  498. return ResponseEntity.ok(response);
  499. }
  500. @Operation(summary = " GCC Blocked Booking Details REST API", description = "REST API to get the GCC Blocked BookingDetails")
  501. // retrieving the GCC Blocked BookingDetails
  502. @GetMapping("/blockedevents")
  503. public ResponseEntity<List<GccBlockingDate>> getBlockedEvents() {
  504. List<GccBlockingDate> blockedBookings = bookingService.getBlockedEvents();
  505. if (blockedBookings.isEmpty()) {
  506. return ResponseEntity.ok(blockedBookings);
  507. }
  508. for (GccBlockingDate blockedBooking : blockedBookings) {
  509. // System.out.println("Blocked Event: " + blockedBooking);
  510. }
  511. return ResponseEntity.ok(blockedBookings);
  512. }
  513. @Operation(summary = "UNBLOCK the gcc Blocked Event REST API", description = "REST API to unblocking the Gcc blocked Events for blocking")
  514. @GetMapping("/cancelByid")
  515. public ResponseEntity<String> cancellationById(@RequestParam int blockingId,
  516. @RequestParam("fromDate") @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate fromDate,
  517. @RequestParam("endDate") @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate endDate) {
  518. // Fetch the blocking date entity
  519. GccBlockingDate blockingDate = blockingDateRepository.findById(blockingId).orElse(null);
  520. if (blockingDate == null) {
  521. return ResponseEntity.status(HttpStatus.NOT_FOUND).body("Blocking ID not found.");
  522. }
  523. // Get the booking IDs from the blocking date entity
  524. String bookingIds = blockingDate.getBookingIds();
  525. String hallIds = blockingDate.getHallId();
  526. // Convert the booking IDs to a list of integers
  527. List<Integer> bookingIdList = Arrays.stream(bookingIds.split(","))
  528. .map(Integer::parseInt)
  529. .collect(Collectors.toList());
  530. // Convert the hall IDs to a list of longs if provided
  531. List<Long> hallIdList = hallIds != null ? Arrays.stream(hallIds.split(","))
  532. .map(Long::parseLong)
  533. .collect(Collectors.toList())
  534. : Collections.emptyList();
  535. // Fetch the booking calendar entries within the date range
  536. List<BookingCalendar> bookingCalendars = bookingService.getBookedslots(fromDate, endDate, hallIdList);
  537. // ── Smart unblock: per-slot decision ──────────────────────────────────
  538. // If morning+evening+is_blocked are all true AND an APPROVED user booking
  539. // exists for that hall/date → only clear is_blocked (leave slots intact).
  540. // Otherwise (GCC-owned slot) → clear everything.
  541. for (BookingCalendar bookingslots : bookingCalendars) {
  542. if (bookingslots.isMorningSlot() && bookingslots.isEveningSlot() && bookingslots.getIs_blocked()) {
  543. List<BookingDetails> approvedBookings = bookingDetailsRepository.findByHallIdAndDate(
  544. bookingslots.getBdate(), bookingslots.getHallId());
  545. if (!approvedBookings.isEmpty()) {
  546. // Approved user booking owns the slots — only remove gcc flag
  547. bookingslots.setIs_blocked(false);
  548. } else {
  549. // GCC owned this slot fully — release everything
  550. bookingslots.setBookingId_1(null);
  551. bookingslots.setBookingId_2(null);
  552. bookingslots.setMorningSlot(false);
  553. bookingslots.setEveningSlot(false);
  554. bookingslots.setIs_blocked(false);
  555. }
  556. } else {
  557. // Partial slot scenario — only clear the gcc overlay flag
  558. bookingslots.setIs_blocked(false);
  559. }
  560. bookingCalendarRepository.save(bookingslots);
  561. }
  562. blockingDate.setBlockedStatus(GccBlockingDate.BlockedStatus.UNBLOCKED);
  563. blockingDateRepository.save(blockingDate);
  564. // Update GCC_BLOCKED booking_details entries back to GCC_UNBLOCKED
  565. for (int bookingId : bookingIdList) {
  566. Optional<BookingDetails> bookingDetails = bookingDetailsRepo.findById(bookingId);
  567. if (bookingDetails.isPresent()) {
  568. BookingDetails bookings = bookingDetails.get();
  569. if (bookings.getBookingStatus() == BookingDetails.BookingStatus.GCC_BLOCKED) {
  570. bookings.setBookingStatus(BookingDetails.BookingStatus.GCC_UNBLOCKED);
  571. bookings.setRefundStatus(BookingDetails.RefundStatus.NA);
  572. bookingDetailsRepo.save(bookings);
  573. }
  574. }
  575. }
  576. String adminname = (String) session.getAttribute("usertype");
  577. Integer loginid = (Integer) session.getAttribute("id");
  578. ApplicationLogs logs = new ApplicationLogs();
  579. logs.setComments("Action by " + adminname);
  580. logs.setLoginId(loginid);
  581. logs.setLogType("Gcc UnBlocking for the Id:-" + blockingDate.getBlockingId());
  582. InetAddress inetAddress;
  583. try {
  584. inetAddress = InetAddress.getLocalHost();
  585. String hostname = InetAddress.getLocalHost().getHostName();
  586. logs.setIpaddress(inetAddress.getHostAddress());
  587. logs.setSystemName(hostname);
  588. } catch (UnknownHostException e) {
  589. e.printStackTrace();
  590. }
  591. applicationLogsRepository.save(logs);
  592. return ResponseEntity.ok("Success");
  593. }
  594. // @GetMapping("/cancelByid")
  595. // public ResponseEntity<String> cancellationById(@RequestParam int blockingId,
  596. // @RequestParam("fromDate") @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate
  597. // fromDate,
  598. // @RequestParam("endDate") @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate
  599. // endDate) {
  600. // // Fetch the blocking date entity
  601. // GccBlockingDate blockingDate =
  602. // blockingDateRepository.findById(blockingId).orElse(null);
  603. // if (blockingDate == null) {
  604. // return ResponseEntity.status(HttpStatus.NOT_FOUND).body("Blocking ID not
  605. // found.");
  606. // }
  607. // // Get the booking IDs from the blocking date entity (may be null/empty for
  608. // // block-only entries)
  609. // String bookingIds = blockingDate.getBookingIds();
  610. // String hallIds = blockingDate.getHallId();
  611. // // Parse booking IDs only if present
  612. // List<Integer> bookingIdList = (bookingIds != null &&
  613. // !bookingIds.trim().isEmpty())
  614. // ? Arrays.stream(bookingIds.split(","))
  615. // .map(String::trim)
  616. // .filter(s -> !s.isEmpty())
  617. // .map(Integer::parseInt)
  618. // .collect(Collectors.toList())
  619. // : Collections.emptyList();
  620. // // Convert the hall IDs to a list of longs if provided
  621. // List<Long> hallIdList = (hallIds != null && !hallIds.trim().isEmpty())
  622. // ? Arrays.stream(hallIds.split(","))
  623. // .map(Long::parseLong)
  624. // .collect(Collectors.toList())
  625. // : Collections.emptyList();
  626. // // Fetch the booking calendar entries within the date range
  627. // List<BookingCalendar> bookingCalendars =
  628. // bookingService.getBookedslots(fromDate, endDate, hallIdList);
  629. // // Release the GCC block flag ONLY.
  630. // // Do NOT touch bookingId_1, bookingId_2, morningSlot, or eveningSlot –
  631. // // those belong to real user bookings that must remain intact.
  632. // for (BookingCalendar bookingslots : bookingCalendars) {
  633. // bookingslots.setIs_blocked(false);
  634. // bookingCalendarRepository.save(bookingslots);
  635. // }
  636. // blockingDate.setBlockedStatus(GccBlockingDate.BlockedStatus.UNBLOCKED);
  637. // blockingDateRepository.save(blockingDate);
  638. // // Restore status of any bookings that were cancelled as part of this GCC
  639. // block
  640. // for (int bookingId : bookingIdList) {
  641. // Optional<BookingDetails> bookingDetails =
  642. // bookingDetailsRepo.findById(bookingId);
  643. // if (bookingDetails.isPresent()) {
  644. // BookingDetails bookings = bookingDetails.get();
  645. // bookings.setBookingStatus(BookingDetails.BookingStatus.GCC_UNBLOCKED);
  646. // bookings.setRefundStatus(BookingDetails.RefundStatus.NA);
  647. // bookingDetailsRepo.save(bookings);
  648. // }
  649. // }
  650. // String adminname = (String) session.getAttribute("usertype");
  651. // Integer loginid = (Integer) session.getAttribute("id");
  652. // ApplicationLogs logs = new ApplicationLogs();
  653. // logs.setComments("Action by " + adminname);
  654. // logs.setLoginId(loginid);
  655. // logs.setLogType("Gcc UnBlocking for the Id:-" +
  656. // blockingDate.getBlockingId());
  657. // InetAddress inetAddress;
  658. // try {
  659. // inetAddress = InetAddress.getLocalHost();
  660. // String hostname = InetAddress.getLocalHost().getHostName();
  661. // logs.setIpaddress(inetAddress.getHostAddress());
  662. // logs.setSystemName(hostname);
  663. // } catch (UnknownHostException e) {
  664. // e.printStackTrace();
  665. // }
  666. // applicationLogsRepository.save(logs);
  667. // return ResponseEntity.ok("Success");
  668. // }
  669. @Operation(summary = "HAll IMAGES by HallId REST API", description = "REST API to get the hall Images by Hall Id")
  670. // retrieving Hall Images by Hallid
  671. @GetMapping("/getImageById")
  672. public List<HallImages> getImageDetails(@RequestParam int hallId) {
  673. return hallService.getHallImages(hallId);
  674. }
  675. @Operation(summary = "GCC Block Without Cancelling REST API", description = "REST API to Block halls without cancelling existing bookings (smart slot logic)")
  676. @PostMapping("/blockWithoutCancel")
  677. public ResponseEntity<String> blockWithoutCancel(
  678. @RequestParam("fromDate") String fromDate,
  679. @RequestParam("toDate") String toDate,
  680. @RequestParam("hallID") String hallID,
  681. @RequestParam("reasonforblocking") String reasonforblocking,
  682. @RequestParam(value = "description", required = false) String[] descriptions,
  683. @RequestParam(value = "document", required = false) MultipartFile[] documents,
  684. HttpSession session) {
  685. String updatedBy = (String) session.getAttribute("employeeId");
  686. List<Long> hallIdsList = Arrays.stream(hallID.split(","))
  687. .map(Long::parseLong)
  688. .collect(Collectors.toList());
  689. bookingService.blockWithoutCancellingBookings(fromDate, toDate, hallIdsList, reasonforblocking,
  690. updatedBy, descriptions, documents);
  691. String adminname = (String) session.getAttribute("usertype");
  692. Integer loginid = (Integer) session.getAttribute("id");
  693. ApplicationLogs logs = new ApplicationLogs();
  694. logs.setComments("Action by " + adminname);
  695. logs.setLoginId(loginid);
  696. logs.setLogType("Gcc Block Without Cancel for the Reason:-" + reasonforblocking);
  697. InetAddress inetAddress;
  698. try {
  699. inetAddress = InetAddress.getLocalHost();
  700. String hostname = InetAddress.getLocalHost().getHostName();
  701. logs.setIpaddress(inetAddress.getHostAddress());
  702. logs.setSystemName(hostname);
  703. } catch (UnknownHostException e) {
  704. e.printStackTrace();
  705. }
  706. applicationLogsRepository.save(logs);
  707. return ResponseEntity.ok("Success");
  708. }
  709. @Operation(summary = "GCC Blocking REST API", description = "REST API to Block the Halls by Admin")
  710. // GccBlocking Api
  711. @PostMapping("/cancelAll")
  712. public ResponseEntity<String> cancelAllBookings(
  713. @RequestParam("fromDate") String fromDate,
  714. @RequestParam("toDate") String toDate,
  715. @RequestParam("hallID") String hallID,
  716. @RequestParam("reasonforblocking") String reasonforblocking,
  717. @RequestParam(value = "selectedBookings", required = false) List<String> selectedBookings,
  718. @RequestParam(value = "description", required = false) String[] descriptions, // Handle descriptions
  719. @RequestParam(value = "document", required = false) MultipartFile[] documents, // Handle documents
  720. HttpSession session) {
  721. // Your existing logic
  722. String updatedBy = (String) session.getAttribute("employeeId");
  723. // Split and convert hall IDs
  724. List<Long> hallIdsList = Arrays.stream(hallID.split(","))
  725. .map(Long::parseLong)
  726. .collect(Collectors.toList());
  727. System.out.println("fromDate " + fromDate + "\n toDate " + toDate + "\n hallID " + hallID
  728. + "\n reasonforblocking " + reasonforblocking + "\n selectedBookings " + selectedBookings
  729. + "\n descriptions " + descriptions + "\n documents " + documents + "\n updatedBy " + updatedBy);
  730. // Call the service with descriptions and documents
  731. bookingService.cancelAllBookings(fromDate, toDate, hallIdsList, reasonforblocking, selectedBookings, updatedBy,
  732. descriptions, documents);
  733. String adminname = (String) session.getAttribute("usertype");
  734. Integer loginid = (Integer) session.getAttribute("id");
  735. ApplicationLogs logs = new ApplicationLogs();
  736. logs.setComments("Action by " + adminname);
  737. logs.setLoginId(loginid);
  738. logs.setLogType("Gcc Blocking for the Reason:-" + reasonforblocking);
  739. InetAddress inetAddress;
  740. try {
  741. inetAddress = InetAddress.getLocalHost();
  742. String hostname = InetAddress.getLocalHost().getHostName();
  743. logs.setIpaddress(inetAddress.getHostAddress());
  744. logs.setSystemName(hostname);
  745. } catch (UnknownHostException e) {
  746. e.printStackTrace();
  747. }
  748. applicationLogsRepository.save(logs);
  749. return ResponseEntity.ok("Success");
  750. }
  751. // @PostMapping("/blockhall")
  752. // public ResponseEntity<String> blockHall(
  753. // @RequestParam("blockingId") Integer blockingId,
  754. // @RequestParam("hallID") String hallID, // Ensure this matches the parameter
  755. // name used in AJAX
  756. // @RequestParam(value = "selectedBookings", required = false) List<String>
  757. // selectedBookings,
  758. // HttpSession session) {
  759. //
  760. // String updatedBy = (String) session.getAttribute("employeeId");
  761. // Optional<GccBlockingDate> gccblocking =
  762. // blockingDateRepository.findById(blockingId);
  763. // GccBlockingDate gccblockingdata = gccblocking.get();
  764. //
  765. // // Convert startDate and endDate to String
  766. // SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
  767. // String startDateString = sdf.format(gccblockingdata.getStartDate());
  768. // String endDateString = sdf.format(gccblockingdata.getEndDate());
  769. //
  770. // // Split and convert hall IDs
  771. // List<Long> hallIdsList = Arrays.stream(hallID.split(","))
  772. // .map(Long::parseLong)
  773. // .collect(Collectors.toList());
  774. //
  775. // System.out.println("selected BookingIds: " + selectedBookings);
  776. //
  777. // // Pass the formatted date strings
  778. // bookingService.cancelAllBookings(startDateString, endDateString, hallIdsList,
  779. // gccblockingdata.getDepartment(), gccblockingdata.getBlockingReason(),
  780. // selectedBookings, updatedBy);
  781. //
  782. // return ResponseEntity.ok("Success");
  783. // }
  784. @GetMapping("/bookingdetailsByuserId")
  785. public List<BookingDetails> getuserDetails(@RequestParam Integer userId) {
  786. return bookingService.getAllBookingsByUserId(userId);
  787. }
  788. @GetMapping("/settlement-approved")
  789. public ResponseEntity<List<Settlement>> getApprovedSettlements(HttpSession session) {
  790. List<Settlement> approvedSettlements = settlementRepository
  791. .findByBookingDetailsRefundStatus(RefundStatus.APPROVED);
  792. return ResponseEntity.ok(approvedSettlements);
  793. }
  794. // @PostMapping("/complete-refund")
  795. // public ResponseEntity<String> completeRefund(@RequestBody List<String>
  796. // bookingIds, HttpSession session, HttpServletResponse response) throws
  797. // IOException {
  798. // String token = (String) session.getAttribute("jwtToken");
  799. // //System.out.println("tokensssssssss" + token);
  800. //
  801. // // Validate JWT token
  802. // if (token != null && jwtUtil.validateToken(token)) {
  803. // // System.out.println("tokennnnnnnnnnnnnnns" + token);
  804. // try {
  805. // // System.out.println("Received booking IDs for refund: " + bookingIds);
  806. //
  807. // List<String> bookids = bookingService.processRefundRequests(bookingIds);
  808. //
  809. // if (!bookids.isEmpty()) {
  810. // // Prepare and return error response if there are errors
  811. // StringBuilder errorResponse = new StringBuilder("Errors processing refund for
  812. // IDs: ");
  813. // for (String bookId : bookids) {
  814. // errorResponse.append(bookId).append(", ");
  815. // }
  816. // return
  817. // ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(errorResponse.toString());
  818. // }
  819. //
  820. // return ResponseEntity.ok("Refund completed successfully");
  821. // } catch (Exception e) {
  822. // e.printStackTrace();
  823. // return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("Error
  824. // processing refund: " + e.getMessage());
  825. // }
  826. // } else {
  827. // // Token is invalid or not present, redirect to login
  828. // session.invalidate(); // Invalidate the session to clear all session
  829. // attributes
  830. // response.sendRedirect("/login"); // Redirect to the login page
  831. // return ResponseEntity.status(HttpStatus.UNAUTHORIZED).build(); // Return HTTP
  832. // 401 Unauthorized
  833. // }
  834. // }
  835. // @GetMapping("/Gccblocking")
  836. // public ResponseEntity<List<Object>>
  837. // getGccBlockingEvents(@RequestParam("hallId") int hallId) {
  838. // System.out.println("Received hallId: " + hallId);
  839. //
  840. // List<Object> results = bookingService.getGccBlockingEvents(hallId);
  841. //
  842. // return ResponseEntity.ok(results);
  843. // }
  844. @GetMapping("/Gccblocking")
  845. public ResponseEntity<List<Object>> getGccBlockingEvents(@RequestParam("hallId") String hallId) {
  846. // System.out.println("Received hallId: " + hallId);
  847. List<Object> results = bookingService.getGccBlockingEvents(hallId);
  848. return ResponseEntity.ok(results);
  849. }
  850. @GetMapping("/getblockedbookingdetails")
  851. public ResponseEntity<List<Map<String, Object>>> viewBlockedHallsByHallIdAndReason(
  852. @RequestParam String hallIds,
  853. @RequestParam int blockingId) {
  854. // System.out.println("Received hallIds: " + hallIds);
  855. // System.out.println("Received blockingId: " + blockingId);
  856. List<Integer> hallIdList;
  857. try {
  858. hallIdList = Arrays.stream(hallIds.split("\\s*,\\s*"))
  859. .map(Integer::parseInt)
  860. .collect(Collectors.toList());
  861. } catch (NumberFormatException e) {
  862. System.err.println("Invalid hall ID format: " + e.getMessage());
  863. return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(Collections.emptyList());
  864. }
  865. Optional<GccBlockingDate> gccOpt = blockingDateRepository.findById(blockingId);
  866. if (!gccOpt.isPresent()) {
  867. return ResponseEntity.status(HttpStatus.NOT_FOUND).body(Collections.emptyList());
  868. }
  869. GccBlockingDate savedGcc = gccOpt.get();
  870. LocalDate startDate = LocalDate.ofInstant(savedGcc.getStartDate().toInstant(), ZoneId.systemDefault());
  871. LocalDate endDate = LocalDate.ofInstant(savedGcc.getEndDate().toInstant(), ZoneId.systemDefault());
  872. List<Map<String, Object>> result = new ArrayList<>();
  873. for (int hallId : hallIdList) {
  874. int bookingCount = bookingDetailsRepository.countByHallIdAndBookingDateBetween(hallId, startDate, endDate);
  875. // System.out.println("bookingCount==="+bookingCount);
  876. Optional<HallDetails> hallDetailsOpt = hallDetailsRepository.findById(hallId);
  877. if (hallDetailsOpt.isPresent()) {
  878. HallDetails hallDetails = hallDetailsOpt.get();
  879. List<Integer> bookingIds = bookingDetailsRepository.findBookingIdsByHallIdAndBookingDateBetween(hallId,
  880. startDate, endDate);
  881. // System.out.println("Booking IDs for hallId " + hallId + ": " + bookingIds);
  882. // // Add this line
  883. Map<String, Object> hallInfo = new HashMap<>();
  884. hallInfo.put("hallName", hallDetails.getHallName());
  885. hallInfo.put("zone", hallDetails.getZone());
  886. hallInfo.put("division", hallDetails.getDivision());
  887. hallInfo.put("bookingCount", bookingCount);
  888. hallInfo.put("bookingIds", bookingIds);
  889. hallInfo.put("hallId", hallId);
  890. result.add(hallInfo);
  891. }
  892. }
  893. return ResponseEntity.ok(result);
  894. }
  895. @GetMapping("/getbookingdetails")
  896. public ResponseEntity<List<BookingDetails>> getBookingDetails(@RequestParam("bookingId") Long bookingId) {
  897. // System.out.println("Received bookingId: " + bookingId);
  898. try {
  899. List<BookingDetails> details = bookingService.findBookingDetailsByBookingId(bookingId);
  900. // System.out.println("bookingdetails==="+details);
  901. return ResponseEntity.ok(details);
  902. } catch (Exception e) {
  903. e.printStackTrace();
  904. return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build();
  905. }
  906. }
  907. @GetMapping("/blockedHallsByHallIdAndReason")
  908. @ResponseBody
  909. public Map<String, Object> viewBlockedHallsByHallIdAndReason(
  910. @RequestParam String department,
  911. @RequestParam String blockingReason,
  912. @RequestParam @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) Date startDate,
  913. @RequestParam @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) Date endDate) {
  914. List<GccBlockingDate> blockedHalls = blockingDateRepository.findByBlockingReasonAndDateRange(blockingReason,
  915. startDate, endDate);
  916. // Ensure distinct by hallId and other keys
  917. List<GccBlockingDate> uniqueGccBlockingDates = blockedHalls.stream()
  918. .filter(distinctByKey(
  919. g -> Arrays.asList(g.getHallId(), g.getBlockingReason(), g.getStartDate(), g.getEndDate())))
  920. .collect(Collectors.toList());
  921. // Prepare response data
  922. Map<String, Object> response = new HashMap<>();
  923. if (!uniqueGccBlockingDates.isEmpty()) {
  924. GccBlockingDate firstBlockedHall = uniqueGccBlockingDates.get(0); // Adjust as necessary
  925. response.put("blockingReason", firstBlockedHall.getBlockingReason());
  926. response.put("cdate", firstBlockedHall.getCdate());
  927. response.put("startDate", firstBlockedHall.getStartDate());
  928. response.put("endDate", firstBlockedHall.getEndDate());
  929. List<Map<String, Object>> hallDetailsList = new ArrayList<>();
  930. for (GccBlockingDate blockedHall : uniqueGccBlockingDates) {
  931. // Split the hallId string into individual hall IDs
  932. String[] hallIds = blockedHall.getHallId().split(",");
  933. for (String hallIdStr : hallIds) {
  934. try {
  935. int hallId = Integer.parseInt(hallIdStr.trim());
  936. HallDetails hall = hallService.getHallById(hallId);
  937. if (hall != null) {
  938. Map<String, Object> hallDetails = new HashMap<>();
  939. hallDetails.put("hallName", hall.getHallName());
  940. hallDetails.put("zone", hall.getZone());
  941. hallDetails.put("division", hall.getDivision());
  942. hallDetails.put("numOfBookings", calculateBookings(hall, blockedHall));
  943. hallDetails.put("refundedAmount", calculateRefund(hall, blockedHall));
  944. hallDetailsList.add(hallDetails);
  945. }
  946. } catch (NumberFormatException e) {
  947. // Handle the case where hallId is not a valid integer
  948. e.printStackTrace();
  949. }
  950. }
  951. }
  952. response.put("halls", hallDetailsList);
  953. } else {
  954. response.put("blockingReason", "N/A");
  955. response.put("cdate", "N/A");
  956. response.put("startDate", "N/A");
  957. response.put("endDate", "N/A");
  958. response.put("halls", Collections.emptyList());
  959. }
  960. return response;
  961. }
  962. // Utility method to ensure distinct by a key
  963. private static <T> Predicate<T> distinctByKey(Function<? super T, ?> keyExtractor) {
  964. Set<Object> seen = new HashSet<>();
  965. return t -> seen.add(keyExtractor.apply(t));
  966. }
  967. // Method to calculate number of bookings
  968. private int calculateBookings(HallDetails hall, GccBlockingDate blockedHall) {
  969. return blockingDateRepository.countBlockedBookings(hall.getHallId(), blockedHall.getStartDate(),
  970. blockedHall.getEndDate());
  971. }
  972. private double calculateRefund(HallDetails hall, GccBlockingDate blockedHall) {
  973. // Implement logic to calculate refund
  974. return 0.0;
  975. }
  976. // admin dashboard
  977. @GetMapping("/bookingstatistics")
  978. public ResponseEntity<Map<String, Map<String, Integer>>> getBookingStatistics(
  979. @RequestParam(required = false) @DateTimeFormat(iso = DateTimeFormat.ISO.DATE) LocalDate fromDate,
  980. @RequestParam(required = false) @DateTimeFormat(iso = DateTimeFormat.ISO.DATE) LocalDate toDate,
  981. @RequestParam(required = false, defaultValue = "ALL") String zone,
  982. @RequestParam(required = false, defaultValue = "ALL") String division,
  983. @RequestParam(required = false, defaultValue = "1000") Integer hallid,
  984. @RequestParam(required = false, defaultValue = "ALL") String userType) {
  985. try {
  986. Map<String, Map<String, Integer>> statistics = bookingService.getBookingStatistics(fromDate, toDate, zone,
  987. division, hallid, userType);
  988. return ResponseEntity.ok(statistics);
  989. } catch (Exception e) {
  990. // Log the exception and return an appropriate error response
  991. return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(Collections.emptyMap());
  992. }
  993. }
  994. @GetMapping("/getHallsDetailsByZone")
  995. public ResponseEntity<Map<String, Object>> getHallsDetailsByZone(@RequestParam String zone) {
  996. Map<String, Object> hallzones = hallDetailService.getHallsDetailsByZone(zone);
  997. // Debug log to verify the response before sending it to the client
  998. // System.out.println("Response from getHallsDetailsByZone: " + hallzones);
  999. return ResponseEntity.ok(hallzones);
  1000. }
  1001. @GetMapping("/byhallid")
  1002. public ResponseEntity<List<Map<String, Object>>> getBookingDetailsByHallId(@RequestParam int hallId) {
  1003. List<Map<String, Object>> bookingDetails = bookingService.getBookingDetailsByHallId(hallId);
  1004. return ResponseEntity.ok(bookingDetails);
  1005. }
  1006. @PostMapping("/savenewHallImages")
  1007. public ResponseEntity<?> updateHallImages(@RequestParam("hallId") Integer hallId,
  1008. @RequestParam("newHallImages") MultipartFile[] newHallImages) {
  1009. // Call the service method to update the hall images
  1010. hallService.updatenewHallImages(hallId, newHallImages);
  1011. return ResponseEntity.ok().build();
  1012. }
  1013. // @DeleteMapping("/deleteHallImage/{hallImageId}")
  1014. // public ResponseEntity<?> deleteHallImage(@PathVariable Long hallImageId) {
  1015. // // Call the service method to delete the hall image
  1016. // hallService.deleteHallImage(hallImageId);
  1017. // return ResponseEntity.ok().build();
  1018. // }
  1019. @PutMapping("/updateHallImage/{hallImageId}")
  1020. public ResponseEntity<Map<String, String>> updateHallImage(
  1021. @PathVariable Integer hallImageId,
  1022. @RequestParam("hallImage") MultipartFile hallImage) throws IOException {
  1023. try {
  1024. String newImageUrl = hallService.updateHallImage(hallImageId, hallImage);
  1025. Map<String, String> response = new HashMap<>();
  1026. response.put("newImageUrl", newImageUrl);
  1027. return ResponseEntity.ok(response);
  1028. } catch (IllegalArgumentException e) {
  1029. return ResponseEntity.status(HttpStatus.NOT_FOUND).body(Collections.singletonMap("error", e.getMessage()));
  1030. } catch (IOException e) {
  1031. return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR)
  1032. .body(Collections.singletonMap("error", "Failed to update image"));
  1033. }
  1034. }
  1035. @DeleteMapping("/deleteHallImage/{hallImageId}")
  1036. public ResponseEntity<String> deleteHallImage(@PathVariable Integer hallImageId) {
  1037. try {
  1038. // Find the image by ID and delete it
  1039. hallImagesRepository.deleteById(hallImageId);
  1040. return ResponseEntity.ok("Image deleted successfully.");
  1041. } catch (Exception e) {
  1042. return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("Error deleting image.");
  1043. }
  1044. }
  1045. @GetMapping("/bookingdetailsByzone")
  1046. public ResponseEntity<List<BookingDetails>> getBookingDetailsByZone(@RequestParam String zone) {
  1047. List<BookingDetails> bookingDetails = bookingDetailsRepository.findByZone(zone);
  1048. return ResponseEntity.ok(bookingDetails);
  1049. }
  1050. @GetMapping("/divisionsByZone")
  1051. public List<String> getDivisionsByZone(@RequestParam("zoneId") String zoneId) {
  1052. // Use zoneId instead of zone
  1053. return hallDetailsRepository.findDistinctDivisionsByZone(zoneId);
  1054. }
  1055. // Fetch hall names by division
  1056. @GetMapping("/hallsByDivision")
  1057. public ResponseEntity<List<String>> getHallsByDivision(@RequestParam String division) {
  1058. List<String> halls = hallDetailsRepository.findHallsByDivision(division);
  1059. if (halls.isEmpty()) {
  1060. return new ResponseEntity<>(HttpStatus.NO_CONTENT);
  1061. }
  1062. return new ResponseEntity<>(halls, HttpStatus.OK);
  1063. }
  1064. @PostMapping("/manualrefund")
  1065. public ResponseEntity<?> manualRefund(
  1066. @RequestParam int bookingId,
  1067. @RequestParam String txansactionId,
  1068. @RequestParam int userId,
  1069. @RequestParam String code,
  1070. @RequestParam String amount) throws Exception {
  1071. // Check if the code matches the value from AppConfig
  1072. if (code.equals(appConfig.getManualRefundCode())) {
  1073. // Call the refund method from PaymentService
  1074. String response = paymentGatewayServiceImpl.manualrefundTheAmount(bookingId, userId, txansactionId, amount);
  1075. // Check the response from the payment service
  1076. if ("Refunded".equals(response)) {
  1077. return ResponseEntity.ok("Refund processed successfully");
  1078. } else {
  1079. // If there was an error in processing the refund
  1080. return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("Error processing refund.");
  1081. }
  1082. } else {
  1083. // Return error message if the code doesn't match
  1084. return ResponseEntity.status(HttpStatus.BAD_REQUEST).body("Code is wrong");
  1085. }
  1086. }
  1087. // gccapps
  1088. @GetMapping("/viewsettlement-pending")
  1089. public ResponseEntity<Map<String, Object>> viewSettlementPendingMaster(HttpSession session) {
  1090. List<BookingDetails> settlement = bookingDetailsRepository.findAllWithPendingRefundStatus();
  1091. List<BookingDetails> cancelledbookings = bookingDetailsRepository.findPendingCancelledList();
  1092. List<BookingDetails> rejectedbookings = bookingDetailsRepository.findPendingRejectedList();
  1093. Map<String, Object> response = new HashMap<>();
  1094. response.put("settlementlist", settlement);
  1095. response.put("cancelledbookings", cancelledbookings);
  1096. response.put("rejectedbookings", rejectedbookings);
  1097. return ResponseEntity.ok(response);
  1098. }
  1099. @GetMapping("/viewsettlement-complete")
  1100. public ResponseEntity<Map<String, Object>> viewSettlementcompleteMaster(HttpSession session) {
  1101. List<BookingDetails> completedlist = bookingDetailsRepository.findAllwithCompletedRefundStatus();
  1102. List<BookingDetails> Completedcancelledbookings = bookingDetailsRepository.findCompletedCancelledList();
  1103. List<BookingDetails> Completedrejectedbookings = bookingDetailsRepository.findCompletedRejectedList();
  1104. Map<String, Object> response = new HashMap<>();
  1105. response.put("completedlist", completedlist);
  1106. response.put("Completedcancelledbookings", Completedcancelledbookings);
  1107. response.put("Completedrejectedbookings", Completedrejectedbookings);
  1108. return ResponseEntity.ok(response);
  1109. }
  1110. @GetMapping("/viewsettlement-approved")
  1111. public ResponseEntity<Map<String, Object>> viewSettlementApprovedMaster(HttpSession session) {
  1112. List<BookingDetails> approvedSettlements = bookingDetailsRepository.findAllWithApprovedRefundStatus();
  1113. List<BookingDetails> settlements = new ArrayList<>(approvedSettlements);
  1114. List<BookingDetails> approvedCancelledBookings = bookingDetailsRepository.findCancelledList();
  1115. List<BookingDetails> approvedRejectedBookings = bookingDetailsRepository.findRejectedList();
  1116. Map<String, Object> response = new HashMap<>();
  1117. response.put("settlementList", settlements);
  1118. response.put("approvedCancelledBookings", approvedCancelledBookings);
  1119. response.put("approvedRejectedBookings", approvedRejectedBookings);
  1120. return ResponseEntity.ok(response);
  1121. }
  1122. @GetMapping("/viewsettlement-reject")
  1123. public ResponseEntity<Map<String, Object>> viewSettlementRejectedMaster(HttpSession session) {
  1124. List<BookingDetails> settlementReject = bookingDetailsRepository.findSettlementRejected();
  1125. Map<String, Object> response = new HashMap<>();
  1126. response.put("settlementlist", settlementReject);
  1127. return ResponseEntity.ok(response);
  1128. }
  1129. @GetMapping("/viewsettlement-initiated")
  1130. public ResponseEntity<Map<String, Object>> viewSettlementInitiateMaster(HttpSession session) {
  1131. List<BookingDetails> settlement = bookingDetailsRepository.findByBookingDetailsRefundStatus();
  1132. List<BookingDetails> Initiatedcancelledbookings = bookingDetailsRepository.findInitiatedCancelledList();
  1133. List<BookingDetails> Initiatedrejectedbookings = bookingDetailsRepository.findInitiatedRejectedList();
  1134. Map<String, Object> response = new HashMap<>();
  1135. response.put("settlementlist", settlement);
  1136. response.put("Initiatedcancelledbookings", Initiatedcancelledbookings);
  1137. response.put("Initiatedrejectedbookings", Initiatedrejectedbookings);
  1138. return ResponseEntity.ok(response);
  1139. }
  1140. @GetMapping("/user-pending")
  1141. public ResponseEntity<List<Users>> viewApproval() {
  1142. List<Users> pendingList = userRepository.getPendingList();
  1143. return new ResponseEntity<>(pendingList, HttpStatus.OK);
  1144. }
  1145. @GetMapping("/user-approved")
  1146. public ResponseEntity<List<Users>> viewUserApproved() {
  1147. List<Users> approved = userRepository.getUserApproved();
  1148. return new ResponseEntity<>(approved, HttpStatus.OK);
  1149. }
  1150. @GetMapping("/user-reject")
  1151. public ResponseEntity<List<Users>> viewUserReject() {
  1152. List<Users> rejected = userRepository.getUserReject();
  1153. return new ResponseEntity<>(rejected, HttpStatus.OK);
  1154. }
  1155. @GetMapping("/halldetailslist")
  1156. public ResponseEntity<List<HallDetails>> getHallDetailsList() {
  1157. List<HallDetails> list = hallDetailsRepository.findAll();
  1158. return ResponseEntity.ok(list);
  1159. }
  1160. @GetMapping("/discountRange")
  1161. public ResponseEntity<List<DiscountRange>> getAllDiscountRanges() {
  1162. List<DiscountRange> discount = discountRangeRepo.findAll();
  1163. return ResponseEntity.ok(discount);
  1164. }
  1165. @PostMapping("/getReport")
  1166. public ResponseEntity<Map<String, Object>> generateReport(
  1167. @RequestParam(name = "FromDate") @DateTimeFormat(iso = DateTimeFormat.ISO.DATE) String fromDate,
  1168. @RequestParam(name = "ToDate") @DateTimeFormat(iso = DateTimeFormat.ISO.DATE) String toDate,
  1169. @RequestParam(name = "request") String request,
  1170. @RequestParam(name = "userstatus", required = false) String userstatus,
  1171. @RequestParam(name = "usertype", required = false) String usertype,
  1172. @RequestParam(name = "bookingStatus", required = false) String bookingStatus,
  1173. @RequestParam(name = "refundStatus", required = false) String refundStatus,
  1174. @RequestParam(name = "bookingId", required = false) Long bookingId) {
  1175. Map<String, Object> response = new HashMap<>();
  1176. List<Users> userList = handleUserRequest(request, fromDate, toDate, userstatus, usertype);
  1177. List<Object[]> bookingList = handleBookingRequest(request, fromDate, toDate, bookingStatus, bookingId);
  1178. List<BookingDetails> bookingSettlementList = handleBookingSettlementRequest(request, fromDate, toDate,
  1179. refundStatus);
  1180. List<Object[]> paymentList = request.equals("3") ? bookingService.getAllPaymentsDetails(fromDate, toDate)
  1181. : new ArrayList<>();
  1182. List<Object[]> userbookingList = request.equals("4")
  1183. ? bookingService.getBookingUserDetailsReport(fromDate, toDate)
  1184. : new ArrayList<>();
  1185. List<Object[]> hallbookingList = request.equals("5")
  1186. ? bookingService.getBookingHallDetailsReport(fromDate, toDate)
  1187. : new ArrayList<>();
  1188. response.put("users", userList);
  1189. response.put("bookings", bookingList);
  1190. response.put("fromdate", fromDate);
  1191. response.put("todate", toDate);
  1192. response.put("userstatus", userstatus);
  1193. response.put("bookingSettlementList", bookingSettlementList);
  1194. response.put("usertype", usertype);
  1195. response.put("bookingStatus", bookingStatus);
  1196. response.put("refundStatus", refundStatus);
  1197. response.put("request", request);
  1198. response.put("paymentLists", paymentList);
  1199. response.put("userbookingLists", userbookingList);
  1200. response.put("hallbookingLists", hallbookingList);
  1201. response.put("bookingId", bookingId);
  1202. return new ResponseEntity<>(response, HttpStatus.OK);
  1203. }
  1204. private List<Users> handleUserRequest(String request, String fromDate, String toDate, String userstatus,
  1205. String usertype) {
  1206. if (!request.equals("1")) {
  1207. return new ArrayList<>();
  1208. }
  1209. if ((userstatus != null && !userstatus.isEmpty()) && (usertype != null && !usertype.isEmpty())) {
  1210. return userService.getAllUsersWithFilters(fromDate, toDate, userstatus, usertype);
  1211. }
  1212. if (userstatus.isEmpty() && (usertype != null && !usertype.isEmpty())) {
  1213. return userService.getAllUsersWithTypeFilters(fromDate, toDate, usertype);
  1214. }
  1215. if (usertype.isEmpty() && (userstatus != null && !userstatus.isEmpty())) {
  1216. return userService.getAllUsersWithStatusFilters(fromDate, toDate, userstatus);
  1217. }
  1218. return userService.getAllUsers(fromDate, toDate);
  1219. }
  1220. private List<Object[]> handleBookingRequest(String request, String fromDate, String toDate, String bookingStatus,
  1221. Long bookingId) {
  1222. if (!request.equals("2")) {
  1223. return new ArrayList<>();
  1224. }
  1225. if (bookingStatus != null && !bookingStatus.isEmpty()) {
  1226. return bookingDetailsRepo.getAllBookingDetailsWithStatus(fromDate, toDate, bookingStatus);
  1227. } else if (bookingId != null) {
  1228. return bookingDetailsRepo.getAllBookingDetailsWithBookingId(fromDate, toDate, bookingId);
  1229. } else {
  1230. return bookingDetailsRepo.getAllBookingDetails(fromDate, toDate);
  1231. }
  1232. }
  1233. private List<BookingDetails> handleBookingSettlementRequest(String request, String fromDate, String toDate,
  1234. String refundStatus) {
  1235. if (!request.equals("6")) {
  1236. return new ArrayList<>();
  1237. }
  1238. if (refundStatus != null && !refundStatus.isEmpty()) {
  1239. return bookingDetailsRepository.getAllBookingsettlementDetailsWithStatus(fromDate, toDate, refundStatus);
  1240. }
  1241. return bookingDetailsRepository.getAllBookingsettlementDetails(fromDate, toDate);
  1242. }
  1243. @GetMapping("/getHallDetailsById")
  1244. public ResponseEntity<List<Map<String, Object>>> getHallDetailsById(@RequestParam Integer hall_id) {
  1245. List<Map<String, Object>> halldetails = bookingService.getHallDetailsForOfficer(hall_id);
  1246. return ResponseEntity.ok(halldetails);
  1247. }
  1248. @GetMapping("/listgccblocking")
  1249. public ResponseEntity<Map<String, Object>> getGccBlocking() {
  1250. // Fetch all blocked GCC dates
  1251. List<GccBlockingDate> gccBlocked = blockingDateRepository.findAllBlocked();
  1252. // Ensure distinct by hallId, blockingReason, startDate, and endDate
  1253. List<GccBlockingDate> uniqueGccBlockingDates = gccBlocked.stream()
  1254. .filter(distinctByKey(g -> Arrays.asList(
  1255. g.getHallId(),
  1256. g.getBlockingReason(),
  1257. g.getStartDate(),
  1258. g.getEndDate())))
  1259. .collect(Collectors.toList());
  1260. // Map to store the count of blocked halls for each GccBlockingDate
  1261. Map<Integer, Integer> hallCountMap = new HashMap<>();
  1262. for (GccBlockingDate blockedDate : uniqueGccBlockingDates) {
  1263. // Parse and count unique hall IDs
  1264. String hallIds = blockedDate.getHallId();
  1265. if (hallIds != null && !hallIds.isEmpty()) {
  1266. Set<String> uniqueHallIds = new HashSet<>(Arrays.asList(hallIds.split(",")));
  1267. int hallCount = uniqueHallIds.size();
  1268. hallCountMap.put(blockedDate.getBlockingId(), hallCount);
  1269. } else {
  1270. hallCountMap.put(blockedDate.getBlockingId(), 0); // No halls blocked
  1271. }
  1272. }
  1273. // Prepare the response data
  1274. Map<String, Object> response = new HashMap<>();
  1275. response.put("gccblocked", uniqueGccBlockingDates);
  1276. response.put("hallCountMap", hallCountMap);
  1277. return ResponseEntity.ok(response);
  1278. }
  1279. @GetMapping("/details")
  1280. public ResponseEntity<List<Object[]>> getUserDetails(
  1281. @RequestParam("fromDate") String fromDate,
  1282. @RequestParam("toDate") String toDate) {
  1283. List<Object[]> userDetails = userRepository.findUserDetailsByBookingDate(fromDate, toDate);
  1284. return ResponseEntity.ok(userDetails);
  1285. }
  1286. @GetMapping("/getPaymentswithRefunds")
  1287. public List<Object[]> getPaymentsWithRefunds(@RequestParam String startDate, @RequestParam String endDate) {
  1288. return userRepository.findPaymentsWithRefunds(startDate, endDate);
  1289. }
  1290. @GetMapping("/getpaymentswithoutRefunds")
  1291. public List<Object[]> getPaymentsWithoutRefunds(@RequestParam String startDate, @RequestParam String endDate) {
  1292. return userRepository.findPaymentsWithoutRefunds(startDate, endDate);
  1293. }
  1294. @GetMapping("/getRefundDetails")
  1295. public List<Object[]> getPaymentsWithRefundsOnly(@RequestParam String startDate, @RequestParam String endDate) {
  1296. return userRepository.findPaymentsWithRefundsOnly(startDate, endDate);
  1297. }
  1298. @PostMapping("/send")
  1299. public ResponseEntity<Map<String, String>> sendMessage(@RequestBody Map<String, String> messagePayload) {
  1300. String userMessage = messagePayload.get("message");
  1301. // Process the user message and prepare a response
  1302. String response = processMessage(userMessage);
  1303. Map<String, String> responseBody = new HashMap<>();
  1304. responseBody.put("response", response);
  1305. return ResponseEntity.ok(responseBody);
  1306. }
  1307. private String processMessage(String userMessage) {
  1308. // Simple logic to return a response, could be more advanced (AI, NLP, etc.)
  1309. if (userMessage.toLowerCase().contains("hello")) {
  1310. return "Hello! How can I assist you today?";
  1311. } else {
  1312. return "Thanks for your message! We will get back to you shortly.";
  1313. }
  1314. }
  1315. @PostMapping("/uploadnoc")
  1316. public ResponseEntity<String> uploadnoc(@RequestParam("nocFile") MultipartFile file,
  1317. @RequestParam("bookingid") int bookingId) {
  1318. try {
  1319. System.out.println("Received file: " + file.getOriginalFilename());
  1320. System.out.println("Booking ID: " + bookingId);
  1321. bookingService.uploadNOCFile(file, bookingId);
  1322. return ResponseEntity.ok("File uploaded and saved successfully");
  1323. } catch (Exception e) {
  1324. System.err.println("Error during file upload: " + e.getMessage());
  1325. return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR)
  1326. .body("File upload failed: " + e.getMessage());
  1327. }
  1328. }
  1329. @Operation(summary = "Settlement APPROVED REST API", description = "REST API for Updating the Refund Status to Approved by Settlement Id If the settlement is Approved")
  1330. // Updating the Refund Status to Approved by Settlement Id If the settlement is
  1331. // Approved
  1332. @PostMapping("/updateApprovedSettlementStatus/{bookingId}") // need to check this API for settlement approval
  1333. public ResponseEntity<Object> updateApprovedSettlementStatus(
  1334. @PathVariable("bookingId") int bookingId,
  1335. @RequestParam("status") BookingDetails.RefundStatus status,
  1336. @RequestParam("comments") String comments) {
  1337. Map<String, Object> response = new HashMap<>();
  1338. try {
  1339. System.out.println("settlementId1: " + bookingId);
  1340. System.out.println("status" + status);
  1341. System.out.println("comments" + comments);
  1342. // Update settlement status
  1343. Settlement updateSettlement = settlementService.updateSettlementStatus(bookingId, status, comments);
  1344. if (updateSettlement == null) {
  1345. return new ResponseEntity<>(HttpStatus.NOT_FOUND);
  1346. }
  1347. System.out.println("updateSettlement12" + updateSettlement);
  1348. // ak
  1349. // Set approvedFlag and approvedFlagDate
  1350. updateSettlement.setApprovedFlag(1);
  1351. updateSettlement.setApprovedFlagDate(new Date());
  1352. settlementRepository.save(updateSettlement);
  1353. // ak
  1354. // Log the action
  1355. String adminname = (String) session.getAttribute("usertype");
  1356. Integer loginid = (Integer) session.getAttribute("id");
  1357. ApplicationLogs logs = new ApplicationLogs();
  1358. logs.setComments("Action by " + adminname);
  1359. logs.setLoginId(loginid);
  1360. logs.setBookingId(updateSettlement.getBookingDetails().getBookingId());
  1361. logs.setLogType("Booking Status: " + status.toString());
  1362. try {
  1363. InetAddress inetAddress = InetAddress.getLocalHost();
  1364. String hostname = InetAddress.getLocalHost().getHostName();
  1365. logs.setIpaddress(inetAddress.getHostAddress());
  1366. logs.setSystemName(hostname);
  1367. } catch (UnknownHostException e) {
  1368. e.printStackTrace();
  1369. }
  1370. applicationLogsRepository.save(logs);
  1371. // Process refund request
  1372. String refundResponse = bookingServiceImpl
  1373. .processRefundRequest(updateSettlement.getBookingDetails().getBookingId());
  1374. // ak
  1375. // Prepare response map
  1376. response.put("settlement", updateSettlement);
  1377. response.put("approvedFlag", updateSettlement.getApprovedFlag());
  1378. response.put("approvedFlagDate", updateSettlement.getApprovedFlagDate());
  1379. if (refundResponse.contains("successful")) {
  1380. // Refund success, return updated settlement and status
  1381. // return new ResponseEntity<>(updateSettlement, HttpStatus.OK);
  1382. return new ResponseEntity<>(response, HttpStatus.OK);
  1383. } else {
  1384. // Refund failure, update refund status to FAILURE
  1385. bookingService.updateRefundStatus(updateSettlement.getBookingDetails().getBookingId(),
  1386. BookingDetails.RefundStatus.FAILURE);
  1387. Map<String, Object> responses = new HashMap<>();
  1388. responses.put("approvedFlag", 1);
  1389. responses.put("message", "Refund processing failed: " + refundResponse);
  1390. responses.put("status", "FAILURE");
  1391. return new ResponseEntity<>(responses, HttpStatus.INTERNAL_SERVER_ERROR);
  1392. // return new ResponseEntity<>("Refund processing failed: " + refundResponse,
  1393. // HttpStatus.INTERNAL_SERVER_ERROR);
  1394. }
  1395. } catch (Exception e) {
  1396. response.put("approvedFlag", 1);
  1397. response.put("message", "Exception while approving settlement: " + e.getMessage());
  1398. return new ResponseEntity<>(response, HttpStatus.INTERNAL_SERVER_ERROR);
  1399. // return new ResponseEntity<>("An error occurred while processing the
  1400. // settlement for Settlement ID: " + settlementId,
  1401. // HttpStatus.INTERNAL_SERVER_ERROR);
  1402. }
  1403. }
  1404. }