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.

1913 lines
85 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
​
  1. package com.gcc.communityHall.controller;
  2. import java.io.File;
  3. import java.io.FileOutputStream;
  4. import java.io.IOException;
  5. import java.time.LocalDate;
  6. import java.time.LocalDateTime;
  7. import java.time.format.DateTimeFormatter;
  8. import java.util.ArrayList;
  9. import java.util.Arrays;
  10. import java.util.Date;
  11. import java.util.Enumeration;
  12. import java.util.HashMap;
  13. import java.util.HashSet;
  14. import java.util.List;
  15. import java.util.Map;
  16. import java.util.Optional;
  17. import java.util.Random;
  18. import java.util.stream.Collector;
  19. import java.util.stream.Collectors;
  20. import org.springframework.beans.factory.annotation.Autowired;
  21. import org.springframework.beans.factory.annotation.Value;
  22. import org.springframework.http.HttpEntity;
  23. import org.springframework.http.HttpHeaders;
  24. import org.springframework.http.HttpMethod;
  25. import org.springframework.http.HttpStatus;
  26. import org.springframework.http.ResponseEntity;
  27. import org.springframework.ui.Model;
  28. import org.springframework.validation.annotation.Validated;
  29. import org.springframework.web.bind.annotation.GetMapping;
  30. import org.springframework.web.bind.annotation.ModelAttribute;
  31. import org.springframework.web.bind.annotation.PathVariable;
  32. import org.springframework.web.bind.annotation.PostMapping;
  33. import org.springframework.web.bind.annotation.RequestMapping;
  34. import org.springframework.web.bind.annotation.RequestParam;
  35. import org.springframework.web.bind.annotation.ResponseBody;
  36. import org.springframework.web.bind.annotation.RestController;
  37. import org.springframework.web.client.RestTemplate;
  38. import org.springframework.web.multipart.MultipartFile;
  39. import org.springframework.web.multipart.MultipartHttpServletRequest;
  40. import org.thymeleaf.context.Context;
  41. import com.fasterxml.jackson.databind.ObjectMapper;
  42. import com.gcc.communityHall.dto.BookingDetailsDTO;
  43. import com.gcc.communityHall.dto.EmployeeDetails;
  44. import com.gcc.communityHall.dto.EmployeeDetailsResponse;
  45. import com.gcc.communityHall.dto.ErrorResponseDto;
  46. import com.gcc.communityHall.dto.FamilyPensionerDetails;
  47. import com.gcc.communityHall.dto.FamilyPensionerDetailsResponse;
  48. import com.gcc.communityHall.dto.PensionerDetails;
  49. import com.gcc.communityHall.dto.PensionerDetailsResponse;
  50. import com.gcc.communityHall.entity.BookingCalendar;
  51. import com.gcc.communityHall.entity.BookingDetails;
  52. import com.gcc.communityHall.entity.Counsellordetails;
  53. import com.gcc.communityHall.entity.CounterDetails;
  54. import com.gcc.communityHall.entity.CounterRefundList;
  55. import com.gcc.communityHall.entity.FloorDetails;
  56. import com.gcc.communityHall.entity.HallDetails;
  57. import com.gcc.communityHall.entity.RefundTransaction;
  58. import com.gcc.communityHall.entity.SmsSender;
  59. import com.gcc.communityHall.entity.UserHistory;
  60. import com.gcc.communityHall.entity.Users;
  61. import com.gcc.communityHall.entity.BookingDetails.BookingStatus;
  62. import com.gcc.communityHall.entity.BookingDetails.RefundStatus;
  63. import com.gcc.communityHall.entity.BookingHistory;
  64. import com.gcc.communityHall.entity.Users.userStatus;
  65. import com.gcc.communityHall.entity.Users.userType;
  66. import com.gcc.communityHall.exception.SlotOccupiedException;
  67. import com.gcc.communityHall.others.AppConfig;
  68. import com.gcc.communityHall.others.UserSession;
  69. import com.gcc.communityHall.paymentService.entity.RefundResponse;
  70. import com.gcc.communityHall.paymentService.entity.TransactionResponse;
  71. import com.gcc.communityHall.paymentService.refund.DTO.TransactionRefundResponse;
  72. import com.gcc.communityHall.paymentService.repository.TransRefundResRepository;
  73. import com.gcc.communityHall.paymentService.service.PaymentGatewayServiceImpl;
  74. import com.gcc.communityHall.repository.BookingCalendarRepository;
  75. import com.gcc.communityHall.repository.BookingDetailsRepository;
  76. import com.gcc.communityHall.repository.BookingHistoryRepository;
  77. import com.gcc.communityHall.repository.CounsellorDetailsRepository;
  78. import com.gcc.communityHall.repository.FloorDetailsRepository;
  79. import com.gcc.communityHall.repository.HallDetailsRepository;
  80. import com.gcc.communityHall.repository.RefundTransactionRepository;
  81. import com.gcc.communityHall.repository.SmsSenderRepository;
  82. import com.gcc.communityHall.repository.UsersRepository;
  83. import com.gcc.communityHall.service.BookingService;
  84. import com.gcc.communityHall.service.CalendarService;
  85. import com.gcc.communityHall.service.CounterService;
  86. import com.gcc.communityHall.service.HallDetailService;
  87. import com.gcc.communityHall.service.UserService;
  88. import com.gcc.communityHall.service.Impl.WhatsappMsgServiceImpl;
  89. import io.swagger.v3.oas.annotations.Operation;
  90. import io.swagger.v3.oas.annotations.media.Content;
  91. import io.swagger.v3.oas.annotations.media.Schema;
  92. import io.swagger.v3.oas.annotations.responses.ApiResponse;
  93. import io.swagger.v3.oas.annotations.responses.ApiResponses;
  94. import io.swagger.v3.oas.annotations.tags.Tag;
  95. import jakarta.servlet.http.HttpServletRequest;
  96. import jakarta.servlet.http.HttpSession;
  97. import lombok.AllArgsConstructor;
  98. import static org.hibernate.query.sqm.tree.SqmNode.log;
  99. import org.springframework.web.bind.annotation.GetMapping;
  100. import org.springframework.web.bind.annotation.RequestParam;
  101. import org.springframework.web.bind.annotation.ResponseBody;
  102. import org.springframework.core.io.ClassPathResource;
  103. import org.springframework.util.StreamUtils;
  104. import java.io.IOException;
  105. import java.nio.charset.StandardCharsets;
  106. @Tag(
  107. name = "CRUD REST APIs for User in CommunityHall",
  108. description = "CRUD REST APIs in CommunityHall to CREATE, UPDATE, FETCH AND DELETE Booking details"
  109. )
  110. @RestController
  111. @RequestMapping("/communityhall/user/api")
  112. @AllArgsConstructor
  113. @Validated
  114. public class UserAPIController {
  115. @Autowired
  116. private HallDetailsRepository hallDetailsRepository;
  117. @Autowired
  118. private AppConfig appConfig;
  119. @Autowired
  120. private UserSession userSession;
  121. @Autowired
  122. private SmsSenderRepository smsSenderRepository;
  123. @Autowired
  124. private BookingCalendarRepository bookingCalendarRepository;
  125. @Autowired
  126. private UserService userservice;
  127. @Autowired
  128. private BookingService bookingService;
  129. @Autowired
  130. private UserService userService;
  131. @Autowired
  132. private CounterService counterservice;
  133. @Autowired
  134. private BookingDetailsRepository bookingDetailsRepository;
  135. @Autowired
  136. private BookingHistoryRepository bookingHistoryRepository;
  137. @Autowired
  138. private CounterService counterService;
  139. @Autowired
  140. private UserService userServices;
  141. @Autowired
  142. private HallDetailService hallDetailService;
  143. @Autowired
  144. private CalendarService calendarService;
  145. @Autowired
  146. private UsersRepository usersRepository;
  147. private final String uploadDirectory;
  148. @Autowired
  149. private WhatsappMsgServiceImpl whatsappMsgServiceImpl;
  150. @Autowired
  151. private PaymentGatewayServiceImpl PaymentGatewayServiceImpl;
  152. @Autowired
  153. private TransRefundResRepository transRefundResRepository;
  154. @Autowired
  155. public UserAPIController(@Value("${file.upload.directory}") String uploadDirectory) {
  156. this.uploadDirectory = uploadDirectory;
  157. }
  158. @Operation(
  159. summary = "Retrieving the HallDetails by HallId REST API",
  160. description = "REST API to Retrieving the HallDetails by HallId"
  161. )
  162. @ApiResponses({
  163. @ApiResponse(
  164. responseCode = "200",
  165. description = "HTTP Status UPDATED"
  166. ),
  167. @ApiResponse(
  168. responseCode = "500",
  169. description = "HTTP Status Internal Server Error",
  170. content = @Content(
  171. schema = @Schema(implementation = ErrorResponseDto.class)
  172. )
  173. )
  174. }
  175. )
  176. //retrieving Hall Details by HallId
  177. @GetMapping("/gethalldetails/{hallId}")
  178. public ResponseEntity<HallDetails> getHallDetails(@PathVariable int hallId) {
  179. Optional<HallDetails> hallDetails = hallDetailsRepository.findById(hallId);
  180. return hallDetails.map(ResponseEntity::ok)
  181. .orElseGet(() -> ResponseEntity.status(404).body(null));
  182. }
  183. @Operation(
  184. summary = "Retrieving the Hallnames only REST API",
  185. description = "REST API to Retrieving the Hallnames only"
  186. )
  187. @GetMapping("/gethallnames")
  188. public ResponseEntity<List<HallDetails>> getHallNames() {
  189. List<HallDetails> hallDetailsList = hallDetailsRepository.findActiveHalls();
  190. List<HallDetails> hallDataList = new ArrayList<>();
  191. for (HallDetails hallDetails : hallDetailsList) {
  192. HallDetails hallData = new HallDetails();
  193. hallData.setHallId(hallDetails.getHallId());
  194. hallData.setHallName(hallDetails.getHallName());
  195. hallDataList.add(hallData);
  196. }
  197. return ResponseEntity.ok(hallDataList); // Return ResponseEntity with list of HallData objects containing only id and hallname
  198. }
  199. @Operation(
  200. summary = "Send OTP REST API",
  201. description = "REST API For Sending OTP to user"
  202. )
  203. //SendOTP
  204. @GetMapping(value = "/sendOTP")
  205. public String sendOtp(HttpServletRequest request, @RequestParam Long mobileNo,@RequestParam String purpose) {
  206. Long MobileNo=mobileNo;
  207. //System.out.println(purpose);
  208. //System.out.print("\n MobileNo---:"+mobileNo);
  209. Random rand = new Random();
  210. // int otp = rand.nextInt(90000) + 10000;
  211. int otp = 11111;
  212. System.out.print("\n otp---:"+otp);
  213. DateTimeFormatter dtf = DateTimeFormatter.ofPattern("dd-MMM-yyyy%20HH:mm");
  214. LocalDateTime now = LocalDateTime.now();
  215. //System.out.println(dtf.format(now));
  216. String key="pfTEYN6H";
  217. String generatedToken = "Welcome to GCC! Your OTP for GCC Community Centre is "+otp;
  218. String urlString = "https://tmegov.onex-aura.com/api/sms?key=pfTEYN6H&to="+mobileNo+"&from=GCCCRP&body=Welcome to GCC! Your OTP for GCC Community Centre booking is "+otp+"&entityid=1401572690000011081&templateid=1407172346444550398";
  219. System.out.println(urlString);
  220. System.out.println("\n urlString---: "+urlString);
  221. String bodyMessage = ""+otp;
  222. /*try {
  223. RestTemplate restTemplate = new RestTemplate();
  224. String Response = restTemplate.getForObject(urlString, String.class);
  225. bodyMessage=Response;
  226. SmsSender sms = new SmsSender();
  227. sms.setPhone(MobileNo);
  228. sms.setCdate(new Date());
  229. sms.setBodyMsg(bodyMessage);
  230. sms.setPurpose(purpose);
  231. smsSenderRepository.save(sms);
  232. String whatsappMsg="https://media.smsgupshup.com/GatewayAPI/rest?userid=2000233507&password=h2YjFNcJ&send_to="+MobileNo+"&v=1.1&format=json&msg_type=TEXT&method=SENDMESSAGE&msg=Welcome+to+GCC%21+%0A%0AYour+OTP+for+GCC+Community+Centre+is+"+otp+"+.";
  233. String sendMsg = whatsappMsgServiceImpl.sendMsg(whatsappMsg);
  234. System.out.println("sendwhatsuprepsosne===="+sendMsg);
  235. } catch (Exception e) {
  236. // System.out.print("ERROR in Sending---: "+e);
  237. bodyMessage = "Error";
  238. }*/
  239. HttpSession session = request.getSession();
  240. session.setAttribute("otp", otp);
  241. return bodyMessage;
  242. }
  243. @Operation(
  244. summary = "Vetify OTP REST API",
  245. description = "REST API For verifying OTP"
  246. )
  247. //VerifyOTP
  248. @GetMapping(value = "/verifyOTP")
  249. public String verifyOtp(HttpServletRequest request, @RequestParam String otp,@RequestParam long mobileNo) {
  250. HttpSession session = request.getSession();
  251. try {
  252. Integer session_otp = (Integer) session.getAttribute("otp");
  253. System.out.println("session_otp---:" + session_otp);
  254. Integer entered_otp = Integer.parseInt(otp);
  255. if (session_otp != null && session_otp.equals(entered_otp)) {
  256. System.out.println("Entered OTP Correct user API");
  257. Users user = userservice.findByMobileno(mobileNo);
  258. if(user!=null) {
  259. userSession.setMobileno(user.getMobileNo());
  260. //userSession.setUserType(user.getUserType());
  261. userSession.setDispayName(user.getName());
  262. userSession.setUserId(user.getUserId());
  263. String userType = user.getUsertype().toString();
  264. userSession.setUserType(userType);
  265. }
  266. session.setAttribute("verifiedotp", "success");
  267. return "Success";
  268. } else {
  269. System.out.println("Incorrect OTP. Please enter correct OTPs.");
  270. session.setAttribute("user","");
  271. session.setAttribute("mobileNo", "");
  272. session.setAttribute("id","");
  273. session.setAttribute("verifiedotp", "error");
  274. return "Error";
  275. }
  276. } catch (NumberFormatException e) {
  277. //System.out.println("Invalid OTP format: " + otp);
  278. return "Error";
  279. } catch (Exception e) {
  280. // System.out.println("Error verifying OTP: " + e.getMessage());
  281. return "Error";
  282. }
  283. }
  284. @GetMapping(value = "/verifyofficialOTP")
  285. public String verifyOtp(HttpServletRequest request, @RequestParam String otp) {
  286. HttpSession session = request.getSession();
  287. try {
  288. Integer session_otp = (Integer) session.getAttribute("otp");
  289. // System.out.println("session_otp---:" + session_otp);
  290. Integer entered_otp = Integer.parseInt(otp);
  291. if (session_otp != null && session_otp.equals(entered_otp)) {
  292. //System.out.println("Entered OTP Correct");
  293. session.setAttribute("verifiedotp", "success");
  294. return "Success";
  295. } else {
  296. // System.out.println("Incorrect OTP. Please enter correct OTPs.");
  297. session.setAttribute("verifiedotp", "error");
  298. return "Error";
  299. }
  300. } catch (NumberFormatException e) {
  301. // System.out.println("Invalid OTP format: " + otp);
  302. return "Error";
  303. } catch (Exception e) {
  304. //System.out.println("Error verifying OTP: " + e.getMessage());
  305. return "Error";
  306. }
  307. }
  308. @Operation(
  309. summary = "User Mobileno Validation REST API",
  310. description = "REST API For Validating User with Mobileno"
  311. )
  312. //Validating User with the mobileno
  313. @GetMapping(value = "/checkMobileExits")
  314. public String checkMobileExits(@RequestParam long mobileno) {
  315. try {
  316. Users form = userservice.findByMobileno(mobileno);
  317. if (form != null) {
  318. return "success";
  319. } else {
  320. return "error";
  321. }
  322. } catch (NumberFormatException e) {
  323. // Handle the case where the phone number cannot be parsed as a Long
  324. return "error";
  325. } catch (Exception e) {
  326. // Handle any other unexpected exceptions
  327. return "error";
  328. }
  329. }
  330. @Operation(
  331. summary = "Cousellor Mobileno Validation REST API",
  332. description = "REST API For Validating the Counsellor Mobileno"
  333. )
  334. //Counsellor Mobile no Validation
  335. @GetMapping(value = "/checkCounsellorMobileExits")
  336. public ResponseEntity<String> checkCounsellorMobileExits(@RequestParam long mobileno) {
  337. // Find the counsellor by the provided mobile number
  338. Counsellordetails counsellor = userservice.findByMobile(mobileno); // This checks both mobileNo1 and mobileNo2 in the counsellor table
  339. if (counsellor == null) {
  340. return ResponseEntity.status(HttpStatus.NOT_FOUND).body("Counsellor Mobile Number Not Found");
  341. }
  342. // Check if mobileNo1 or mobileNo2 of the counsellor is already used in the Users table
  343. boolean isMobile1Used = usersRepository.existsByMobileNo(counsellor.getMobile1());
  344. boolean isMobile2Used = usersRepository.existsByMobileNo(counsellor.getMobile2());
  345. if (isMobile1Used || isMobile2Used) {
  346. return ResponseEntity.status(HttpStatus.CONFLICT).body("One of the counsellor's mobile numbers is already used.");
  347. }
  348. // If no conflict, return success with the counsellor's name
  349. return ResponseEntity.ok(counsellor.getName());
  350. }
  351. @GetMapping("/checkEmployee")
  352. public Map<String, Boolean> checkEmployee(@RequestParam String id) {
  353. boolean isRegistered = usersRepository.existsByGovernmentId(id);
  354. Map<String, Boolean> response = new HashMap<>();
  355. response.put("isRegistered", isRegistered);
  356. return response;
  357. }
  358. @Operation(
  359. summary = "Retriving the zone REST API",
  360. description = "REST API to Retriev the zone for displaying in Frontend"
  361. )
  362. //retrieving the zone
  363. @GetMapping(value = "/getZone")
  364. public List<Map<String, Object>> getZone() {
  365. return hallDetailsRepository.getZoneAndDivision();
  366. }
  367. @Operation(
  368. summary = "Zones by Hall REST API",
  369. description = "REST API to Retrieve the zone by Hall for displaying in GccBlocking page"
  370. )
  371. //retrieving the zones by hall
  372. @GetMapping(value = "/hallsbyzone")
  373. public List<Map<String, Object>> getHallsByZone(@RequestParam(required = false) String zones) {
  374. if (zones == null || zones.isEmpty()) {
  375. return hallDetailsRepository.getAllHalls();
  376. } else {
  377. List<String> zoneList = Arrays.asList(zones.split(","));
  378. return hallDetailsRepository.getHallsByZones(zoneList);
  379. }
  380. }
  381. @Operation(
  382. summary = "Past Data from the booking Calendar Hall REST API",
  383. description = "REST API to Retrieve the Pat Data from booking calendar"
  384. )
  385. //Getting the Past Data from the Calendar
  386. @GetMapping("/getPastData")
  387. public List<BookingCalendar> getPastData(@RequestParam("hall_id") int hall_id){
  388. List<BookingCalendar> data = new ArrayList();
  389. data = bookingService.getPastData(hall_id);
  390. if(data!=null) {
  391. return data;
  392. }
  393. return data;
  394. }
  395. @Operation(
  396. summary = "Pensioner Details ERP REST API",
  397. description = "REST API to retrieving the Pensioner Details From ERP"
  398. )
  399. //retrieving the Pensioner Details From ERP
  400. @GetMapping("/PensionerDetail")
  401. public PensionerDetailsResponse getPensionerDetails(@RequestParam("pensionerId") String pensionerId) {
  402. //System.out.println(pensionerId);
  403. RestTemplate restTemplate = new RestTemplate();
  404. String url = "https://erp.chennaicorporation.gov.in/pgr/external/mobileservice?serviceId=getPensionerDetailsList&pensionerId="+pensionerId;
  405. ResponseEntity<String> responseEntity = restTemplate.getForEntity(url, String.class);
  406. // Extract the JSON string from the response body
  407. String jsonString = responseEntity.getBody();
  408. // Extract the Java object from the response body
  409. ObjectMapper objectMapper = new ObjectMapper();
  410. try {
  411. PensionerDetailsResponse pensionerResponse = objectMapper.readValue(jsonString, PensionerDetailsResponse.class);
  412. // Now you can access the pensionerResponse object as usual
  413. // e.g., pensionerResponse.getPensioners() to get the list of pensioners
  414. return pensionerResponse;
  415. } catch (Exception e) {
  416. e.printStackTrace();
  417. return null;
  418. }
  419. //return null;
  420. }
  421. @Operation(
  422. summary = "Employee Details ERP REST API",
  423. description = "REST API to retrieving the Employee Details From ERP"
  424. )
  425. @GetMapping("/EmployeeDetails")
  426. public EmployeeDetailsResponse getEmployeeDetails(@RequestParam("employeeId") Long employeeId) {
  427. //System.out.println("Employee ID:"+employeeId);
  428. RestTemplate restTemplate = new RestTemplate();
  429. String url = "https://erp.chennaicorporation.gov.in/pgr/external/mobileservice?serviceId=getEmployeeDetail&EmployeeID="+employeeId;
  430. ResponseEntity<String> responseEntity = restTemplate.getForEntity(url, String.class);
  431. // Extract the JSON string from the response body
  432. String jsonString = responseEntity.getBody();
  433. // Extract the Java object from the response body
  434. ObjectMapper objectMapper = new ObjectMapper();
  435. try {
  436. EmployeeDetailsResponse employeeResponse = objectMapper.readValue(jsonString, EmployeeDetailsResponse.class);
  437. // Now you can access the pensionerResponse object as usual
  438. // e.g., pensionerResponse.getPensioners() to get the list of pensioners
  439. return employeeResponse;
  440. } catch (Exception e) {
  441. e.printStackTrace();
  442. return null;
  443. }
  444. //return null;
  445. }
  446. @Operation(
  447. summary = "FamilyPensioner Details ERP REST API",
  448. description = "REST API to retrieving the FamilyPensioner Details From ERP"
  449. )
  450. //retrieving the FamilyPensionerDetails Details From ERP
  451. @GetMapping("/FamilyPensionerDetail")
  452. public FamilyPensionerDetailsResponse getFamilyPensionerDetails(@RequestParam("id") Long id) {
  453. RestTemplate restTemplate = new RestTemplate();
  454. String url = "https://erp.chennaicorporation.gov.in/pgr/external/mobileservice?serviceId=getFamPensionerDetailsList&familPensionId="+id;
  455. ResponseEntity<String> responseEntity = restTemplate.getForEntity(url, String.class);
  456. // Extract the JSON string from the response body
  457. String jsonString = responseEntity.getBody();
  458. // Extract the Java object from the response body
  459. ObjectMapper objectMapper = new ObjectMapper();
  460. try {
  461. FamilyPensionerDetailsResponse familyPensionerDetailsResponse = objectMapper.readValue(jsonString, FamilyPensionerDetailsResponse.class);
  462. // Now you can access the pensionerResponse object as usual
  463. // e.g., pensionerResponse.getPensioners() to get the list of pensioners
  464. return familyPensionerDetailsResponse;
  465. } catch (Exception e) {
  466. e.printStackTrace();
  467. return null;
  468. }
  469. }
  470. @Operation(
  471. summary = "Hall Details coordinates REST API",
  472. description = "REST API to retrieving the Hall Details coordinates for Map"
  473. )
  474. //retrieving the All Hall Details coordinates
  475. @GetMapping("/getallhallcoordinates")
  476. public List<Map<String, Object>> getAllHallCoordinates() {
  477. List<HallDetails> allHallDetails = hallDetailsRepository.findActiveHalls();
  478. return allHallDetails.stream().map(this::extractRequiredDetails).collect(Collectors.toList());
  479. }
  480. private Map<String, Object> extractRequiredDetails(HallDetails hallDetails) {
  481. Map<String, Object> details = new HashMap<>();
  482. details.put("latitude", hallDetails.getLatitude());
  483. details.put("longitude", hallDetails.getLongitude());
  484. details.put("hallId", String.valueOf(hallDetails.getHallId()));
  485. details.put("hallName", hallDetails.getHallName());
  486. details.put("seatingCapacity",String.valueOf(hallDetails.getSeatingCapacity()) );
  487. details.put("parkingCapacity", hallDetails.getParkingCapacity());
  488. details.put("hallImage", hallDetails.getHallImagesList());
  489. details.put("fullDayRent", hallDetails.getFullDayRent());
  490. details.put("halfDayRent", hallDetails.getHalfDayRent());
  491. details.put("depositAmount", hallDetails.getDepositAmount());
  492. details.put("area", hallDetails.getArea());
  493. details.put("street", hallDetails.getStreet());
  494. details.put("landMark", hallDetails.getLandMark());
  495. details.put("doorNo", hallDetails.getDoorNo());
  496. details.put("hallArea", hallDetails.getHallArea());
  497. return details;
  498. }
  499. @Operation(
  500. summary = "Booking Limitation Details ERP REST API",
  501. description = "REST API to check the Booking Limitation & UserStatus pending"
  502. )
  503. //Booking Limitation & UserStatus pending
  504. @GetMapping("/bookingLimit")
  505. public String CheckbookingLimitation(Model model) {
  506. int userId = userSession.getUserId();
  507. Users userById = userService.getUserById(userId);
  508. if(userById!=null && userById.getUserstatus()==Users.userStatus.PENDING) {
  509. return "pending";
  510. }
  511. if (userById != null && userById.getUserstatus() == Users.userStatus.REJECTED) {
  512. return "rejected";
  513. }
  514. int checkUserBookingLimitation = bookingService.checkUserBookinglimitation(userId);
  515. // System.out.println("checkUserBookingLimitation="+checkUserBookingLimitation);
  516. if (checkUserBookingLimitation < 2) {
  517. // System.out.println("checkUserBookingLimitationss="+checkUserBookingLimitation);
  518. return "success";
  519. }
  520. return "failure";
  521. }
  522. @Operation(
  523. summary = "Counter Booikng Limit REST API",
  524. description = "REST API to check the Counter Booking Limitation"
  525. )
  526. @GetMapping("/counterbookinglimit")
  527. public String checkCounterBookingLimitation(@RequestParam long mobileNo) {
  528. Users user = userService.getUserDetailsByMobileNo(mobileNo);
  529. if (user == null) {
  530. // System.err.println("User not found for mobile number: " + mobileNo);
  531. return "checkmobilenoexists"; // You can return a different status or handle it accordingly
  532. }
  533. int userId = user.getUserId();
  534. int checkUserBookingLimitation = bookingService.checkUserBookinglimitation(userId);
  535. if (checkUserBookingLimitation >= 2) {
  536. // System.err.println("bookinglimitreached");
  537. return "bookinglimitreached";
  538. }
  539. if (user != null && !user.isActive()) {
  540. return "deactive";
  541. }
  542. return "checkmobilenoexists";
  543. }
  544. @Operation(
  545. summary = "User Status Pending REST API",
  546. description = "REST API to check User Status is Pending and not allow user to login"
  547. )
  548. //UserStatus pending
  549. @GetMapping("/checkuserstatus")
  550. public String checkUserStatus(@RequestParam long mobileNo) {
  551. Users user = userService.getUserDetailsByMobileNo(mobileNo); // Assuming you have a method to retrieve a user by mobile number
  552. if (user != null && user.getUserstatus() == Users.userStatus.PENDING) {
  553. return "pending";
  554. }
  555. if (user != null && !user.isActive()) {
  556. return "deactive";
  557. }
  558. return "checkmobileexist";
  559. }
  560. @Operation(
  561. summary = "Username and Mobileno from userSession REST API",
  562. description = "REST API to get the Username and Mobileno from userSession"
  563. )
  564. //Getting Username and Mobileno from userSession
  565. @GetMapping("/getUsername")
  566. public ResponseEntity<Map<String, Object>> checkUsername() {
  567. Map<String, Object> userDetails = new HashMap<>();
  568. userDetails.put("displayName", userSession.getDispayName());
  569. userDetails.put("mobileNo", userSession.getMobileno());
  570. userDetails.put("userType", userSession.getUserType());
  571. return ResponseEntity.ok(userDetails);
  572. }
  573. @GetMapping(value = "/getZonehalls")
  574. public List<Map<String, Object>> getZonehalls() {
  575. return hallDetailsRepository.getZonesAndDivisions();
  576. }
  577. @Operation(
  578. summary = "ZONES from ERP REST API",
  579. description = "REST API to get the zones from ERP"
  580. )
  581. // Rest Api From ERP for getting Zones
  582. @GetMapping(value = "/getZoneNo")
  583. public String getZoneNo() {
  584. String urlString = appConfig.getErpUrl()+"serviceId=getZones";
  585. ResponseEntity<String> response = null;
  586. RestTemplate restTemplate = new RestTemplate();
  587. String bodyMessage = "";
  588. HttpHeaders headers = new HttpHeaders();
  589. try {
  590. HttpEntity<String> postData = new HttpEntity<String>(headers);
  591. response = restTemplate.exchange(urlString, HttpMethod.POST, postData, String.class);
  592. bodyMessage = response.getBody();
  593. //System.out.println("BodyMessage" + bodyMessage);
  594. } catch (Exception e) {
  595. e.printStackTrace();
  596. //System.out.print("\n ERROR---: " + e);
  597. bodyMessage = "Error";
  598. }
  599. return bodyMessage;
  600. }
  601. @Operation(
  602. summary = "DIVISIONS from ERP REST API",
  603. description = "REST API to get the divisions from ERP"
  604. )
  605. // Rest Api From ERP for getting Divisions
  606. @GetMapping(value = "/getDiv")
  607. public String getDiv(@RequestParam String zoneId) {
  608. String urlString = appConfig.getErpUrl()+"serviceId=getWards&Zoneid="+zoneId+"";
  609. ResponseEntity<String> response = null;
  610. RestTemplate restTemplate = new RestTemplate();
  611. String bodyMessage = "";
  612. HttpHeaders headers = new HttpHeaders();
  613. try {
  614. HttpEntity<String> postData = new HttpEntity<String>(headers);
  615. response = restTemplate.exchange(urlString, HttpMethod.POST, postData, String.class);
  616. bodyMessage = response.getBody();
  617. //System.out.println("bodyMessage" + bodyMessage);
  618. } catch (Exception e) {
  619. e.printStackTrace();
  620. //System.out.print("\n ERROR---: " + e);
  621. bodyMessage = "Error";
  622. }
  623. return bodyMessage;
  624. }
  625. @Operation(
  626. summary = "HAlls By Division ERP REST API",
  627. description = "REST API to get the HAlls by Divisions"
  628. )
  629. //retrieving the Halls By Division
  630. @GetMapping("/hallsbydivision")
  631. public List<HallDetails> getHallsByDivision(@RequestParam("division") String division) {
  632. return hallDetailsRepository.findByDivision(division);
  633. }
  634. @Operation(
  635. summary = "HAlls By zone ERP REST API",
  636. description = "REST API to get the HAlls by zone"
  637. )
  638. @GetMapping("/findhallsbyzone")
  639. public List<HallDetails> getHallsByzone(@RequestParam("zone") String zone) {
  640. return hallDetailsRepository.findByZone(zone);
  641. }
  642. @Operation(
  643. summary = "Booking Details By bookingId ERP REST API",
  644. description = "REST API to get the Booking Details based on BookingId"
  645. )
  646. //retrieving the Booking Details based on BookingId
  647. @GetMapping("/viewAllBookingDetails")
  648. public ResponseEntity<?> getUserDetailsByBookingId(@RequestParam("bookingId") int bookingId) {
  649. BookingDetails bookingDetails = bookingService.getBookingsById(bookingId);
  650. if (bookingDetails != null) {
  651. return ResponseEntity.ok(bookingDetails);
  652. } else {
  653. return ResponseEntity.notFound().build();
  654. }
  655. }
  656. @Operation(
  657. summary = "New Registration in Counter REST API",
  658. description = "REST API for New Registration in Counter"
  659. )
  660. //New Registration in Counter
  661. @PostMapping("/newcounterregistrationform")
  662. public ResponseEntity<?> showRegistrationForm(
  663. @ModelAttribute Users counterform,
  664. @RequestParam(value = "userPhoto", required = false) MultipartFile userPhoto) {
  665. try {
  666. if (userPhoto != null && !userPhoto.isEmpty()) {
  667. counterform.setUserPhoto(userPhoto); // Set the photo if it exists
  668. }
  669. Users user = userService.user(counterform);
  670. userSession.setMobileno(user.getMobileNo());
  671. userSession.setDispayName(user.getName());
  672. userSession.setUserId(user.getUserId());
  673. userSession.setUserType(user.getUsertype().toString());
  674. // Return the userId in the response
  675. Map<String, Object> response = new HashMap<>();
  676. response.put("userId", user.getUserId());
  677. response.put("mobileNo", user.getMobileNo());
  678. response.put("name", user.getName());
  679. response.put("usertype", user.getUsertype());
  680. response.put("message", "Registration successful");
  681. return ResponseEntity.ok(response);
  682. } catch (Exception e) {
  683. // Log the exception and return an appropriate error response
  684. e.printStackTrace();
  685. return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("Error registering user");
  686. }
  687. }
  688. @Operation(
  689. summary = "Counter User Details REST API",
  690. description = "REST API to get the User Details by Mobileno for counter"
  691. )
  692. //retrieving the User Details by Mobileno for Counter
  693. @GetMapping("/getUserDetails")
  694. public ResponseEntity<?> getUserDetailsByMobileNo(@RequestParam("mobileNo") long mobileNo) {
  695. try {
  696. // Call service method to retrieve user details by mobile number
  697. Users userDetails = userService.getUserDetailsByMobileNo(mobileNo);
  698. if (userDetails != null) {
  699. return ResponseEntity.ok(userDetails);
  700. } else {
  701. return ResponseEntity.status(HttpStatus.NOT_FOUND).body("User not found");
  702. }
  703. } catch (Exception e) {
  704. // Log the exception and return an appropriate error response
  705. e.printStackTrace();
  706. return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("Error retrieving user details");
  707. }
  708. }
  709. @Operation(
  710. summary = "DD Image by CounterID REST API",
  711. description = "REST API to get the DD Image by counterId"
  712. )
  713. //retrieving the Dd Image by counterId
  714. @GetMapping("/getImageByDdId")
  715. public ResponseEntity<CounterDetails> getImageByDdId(@RequestParam int counterId) {
  716. CounterDetails counterDetails = counterservice.getDdImageById(counterId);
  717. if (counterDetails != null) {
  718. //System.out.println("CounterDetails found: " + counterDetails.getDdphoto());
  719. return ResponseEntity.ok(counterDetails);
  720. } else {
  721. //System.out.println("CounterDetails not found for ID: " + counterId);
  722. return ResponseEntity.status(HttpStatus.NOT_FOUND).body(null);
  723. }
  724. }
  725. @Operation(
  726. summary = "Counter Booking Cancellation by Letter and Reason REST API",
  727. description = "REST API save the counter Booking Cancellation Letter and reason"
  728. )
  729. //Saving the counter Booking Cancellation Letter and reason
  730. @PostMapping("/saveCancellation")
  731. public ResponseEntity<CounterRefundList> saveCancellation(
  732. @RequestParam("counterId") int counterId,
  733. @RequestParam("uploadLetter") MultipartFile uploadLetter,
  734. @RequestParam("reason") String reason) throws IOException {
  735. //System.out.println("Received counterId: " + counterId);
  736. //System.out.println("Received file: " + uploadLetter.getOriginalFilename());
  737. // Fetch booking details using counterId
  738. List<BookingDetails> bookingList = bookingDetailsRepository.findByCounterId(counterId);
  739. if (bookingList.isEmpty()) {
  740. //System.out.println("No bookings found for counterId: " + counterId);
  741. }
  742. for (BookingDetails booking : bookingList) {
  743. booking.setBookingStatus(BookingStatus.CANCELED);
  744. bookingDetailsRepository.save(booking);
  745. List<BookingCalendar> bookingCalendarList = bookingCalendarRepository.getCancellingdata1(String.valueOf(booking.getBookingId()));
  746. for (BookingCalendar calendar : bookingCalendarList) {
  747. boolean isUpdated = false;
  748. if (String.valueOf(booking.getBookingId()).equals(calendar.getBookingId_1())) {
  749. calendar.setBookingId_1(null);
  750. isUpdated = true;
  751. }
  752. if (String.valueOf(booking.getBookingId()).equals(calendar.getBookingId_2())) {
  753. calendar.setBookingId_2(null);
  754. isUpdated = true;
  755. }
  756. if (calendar.isMorningSlot()) {
  757. calendar.setMorningSlot(false);
  758. isUpdated = true;
  759. }
  760. if (calendar.isEveningSlot()) {
  761. calendar.setEveningSlot(false);
  762. isUpdated = true;
  763. }
  764. if (isUpdated) {
  765. calendar.setIs_delete(true);
  766. bookingCalendarRepository.save(calendar);
  767. }
  768. }
  769. }
  770. CounterRefundList counterRefundList = counterservice.saveCancellation(counterId, uploadLetter, reason);
  771. return ResponseEntity.ok(counterRefundList);
  772. }
  773. @Operation(
  774. summary = "Counter Booking Details by CounterId REST API",
  775. description = "REST API to get the Counter Details by CounterId"
  776. )
  777. //retrieving Counter Booking Details by counterId
  778. @GetMapping("/counterdetails")
  779. public List<BookingDetails> getUserDetailsbycounterId(@RequestParam("counterId") int counterId) {
  780. List<BookingDetails> counterRefundList = bookingDetailsRepository.getCounterDetailsbycounterId(counterId);
  781. return counterRefundList;
  782. }
  783. // @GetMapping("/getUser")
  784. // public ResponseEntity<?> getUserByID(@RequestParam int userId){
  785. // if(userId == 0) {
  786. // userId=userSession.getUserId();
  787. // }
  788. // return ResponseEntity.ok(userService.getUserById(userId));
  789. // }
  790. @Operation(
  791. summary = "Updating the User Details Mobileno Validation REST API",
  792. description = "REST API to Update the User Details if the User status is Rejected"
  793. )
  794. //Updating the Rejected user details
  795. @PostMapping("/updateUserDetails")
  796. public String updateUserDetails(
  797. @RequestParam("userId") int userId,
  798. @RequestParam(value = "name", required = false) String name,
  799. @RequestParam(value = "doorNo", required = false) String doorNo,
  800. @RequestParam(value = "area", required = false) String area,
  801. @RequestParam(value = "location", required = false) String location,
  802. @RequestParam(value = "usertype", required = false) String userType,
  803. @RequestParam(value="pinCode", required = false) int pinCode,
  804. @RequestParam(value="email", required = false) String email,
  805. @RequestParam(value = "profilephoto", required = false) MultipartFile profilephoto) {
  806. Users userDetails = new Users();
  807. userDetails.setUserId(userId);
  808. userDetails.setName(name);
  809. userDetails.setDoorNo(doorNo);
  810. userDetails.setArea(area);
  811. userDetails.setLocation(location);
  812. userDetails.setUserstatus(userStatus.PENDING);
  813. userDetails.setPinCode(pinCode);
  814. userDetails.setEmail(email);
  815. if (userType != null) {
  816. userDetails.setUsertype(Users.userType.valueOf(userType));
  817. }
  818. // Handle profile photo
  819. if (profilephoto != null && !profilephoto.isEmpty()) {
  820. //System.out.println("Profile photo uploaded: " + profilephoto.getOriginalFilename());
  821. String fileName = userId + "_" + profilephoto.getOriginalFilename();
  822. String filePath = "/images/userPhoto/" + fileName;
  823. File file = new File(uploadDirectory + "/userPhoto/" + fileName);
  824. try {
  825. try (FileOutputStream fos = new FileOutputStream(file)) {
  826. fos.write(profilephoto.getBytes());
  827. }
  828. userDetails.setProfilephoto(filePath);
  829. } catch (IOException e) {
  830. e.printStackTrace();
  831. return "failed";
  832. }
  833. } else {
  834. // If no new profile photo is uploaded, retain the existing one
  835. Users existingUser = usersRepository.findById(userId).orElse(null);
  836. if (existingUser != null) {
  837. userDetails.setProfilephoto(existingUser.getProfilephoto());
  838. }
  839. }
  840. return userServices.updateUserDetails(userDetails);
  841. }
  842. @Operation(
  843. summary = "Counter User Details REST API",
  844. description = "REST API to Get the User Details for Counter"
  845. )
  846. //Retrive user details for counter
  847. @GetMapping("/getuserforcounter")
  848. public ResponseEntity<?> getCounterUserById(@RequestParam int userId){
  849. if(userId == 0) {
  850. userId = userSession.getUserId();
  851. // System.out.println("User ID retrieved from session: " + userId);
  852. } else {
  853. //System.out.println("User ID provided as parameter: " + userId);
  854. }
  855. Users user = userService.getUserById(userId);
  856. if(user == null) {
  857. return ResponseEntity.status(HttpStatus.NOT_FOUND).body("User not found");
  858. }
  859. return ResponseEntity.ok(user);
  860. }
  861. @Operation(
  862. summary = "User Details REST API",
  863. description = "REST API to Get the User Details"
  864. )
  865. //retrieving User Details
  866. @GetMapping("/getUser")
  867. public ResponseEntity<?> getUserByID(@RequestParam int userId) {
  868. if (userId == 0) {
  869. userId = userSession.getUserId();
  870. }
  871. Users user = userService.getUserById(userId);
  872. Map<String, Object> response = new HashMap<>();
  873. response.put("userId",user.getUserId());
  874. response.put("name", user.getName());
  875. response.put("email", user.getEmail());
  876. response.put("mobileNo", user.getMobileNo());
  877. response.put("doorNo", user.getDoorNo());
  878. response.put("area", user.getArea());
  879. response.put("location", user.getLocation());
  880. response.put("pinCode", user.getPinCode());
  881. response.put("userstatus", user.getUserstatus());
  882. response.put("profilephoto", user.getProfilephoto());
  883. response.put("usertype", user.getUsertype());
  884. if ("REJECTED".equalsIgnoreCase(user.getUserstatus().name())) {
  885. List<UserHistory> histories = user.getUserHistories();
  886. String rejectionReason = histories.stream()
  887. .filter(history -> history.getComments() != null)
  888. .map(UserHistory::getComments)
  889. .findFirst()
  890. .orElse("No reason provided");
  891. response.put("rejectionReason", rejectionReason);
  892. }
  893. //System.out.println("Response: " + response); // Log the response
  894. return ResponseEntity.ok(response);
  895. }
  896. @Operation(
  897. summary = "Saving the Booking Details REST API",
  898. description = "REST API to Save the Booking Details"
  899. )
  900. //APi for Saving the Booking Details
  901. @PostMapping(path = "/saveTheRequest2", consumes = { "multipart/form-data" })
  902. public ResponseEntity<?> saveTheBookingDetails2(HttpServletRequest request) {
  903. MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
  904. Map<String,Object> bookingDetails = splitFormData(multipartRequest);
  905. Map<String, Object> saveBookingDetails = bookingService.saveBookingDetails(bookingDetails);
  906. return ResponseEntity.ok(saveBookingDetails);
  907. }
  908. public Map<String,Object> splitFormData(MultipartHttpServletRequest multipartRequest){
  909. Map<String, Object> formData = new HashMap<>();
  910. // Iterate through the request parameters
  911. Enumeration<String> parameterNames = multipartRequest.getParameterNames();
  912. while (parameterNames.hasMoreElements()) {
  913. String paramName = parameterNames.nextElement();
  914. String paramValues = multipartRequest.getParameter(paramName);
  915. formData.put(paramName, paramValues);
  916. }
  917. // Iterate through the request parts (files)
  918. try {
  919. Map<String, MultipartFile> fileMap = multipartRequest.getFileMap();
  920. for (Map.Entry<String, MultipartFile> entry : fileMap.entrySet()) {
  921. MultipartFile file = entry.getValue();
  922. if (!file.isEmpty()) {
  923. formData.put(entry.getKey(), file);
  924. }
  925. }
  926. } catch (Exception e) {
  927. e.printStackTrace(); // Handle the exception according to your needs
  928. }
  929. return formData;
  930. }
  931. @Operation(
  932. summary = "Retrieving the Booking Details by BookingId REST API",
  933. description = "REST API to get the Booking Details by Booking Id"
  934. )
  935. //retrieving the Booking Details BY Booking ID
  936. @GetMapping("/getBooking")
  937. public ResponseEntity<?> getBookingByID(@RequestParam int bookingId){
  938. return ResponseEntity.ok(bookingService.getBookingsById(bookingId));
  939. }
  940. @Operation(
  941. summary = "User Booking Cancelling by BookingId REST API",
  942. description = "REST API to Cancel the Booking by BookingId by User"
  943. )
  944. //Booking Cancelling by BookingId
  945. //Booking Cancelling by BookingId
  946. @GetMapping("/cancelBookingbyId")
  947. public ResponseEntity<?> cancelBooking(@RequestParam int bookingId,
  948. @RequestParam BookingDetails.BookingStatus status,
  949. @RequestParam String comments) {
  950. log.info("Received request to cancel booking with ID: {}");
  951. log.info("Status: {}, Comments: {}");
  952. Optional<BookingDetails> bookings=bookingDetailsRepository.findById(bookingId);
  953. BookingDetails bookingDetails=bookings.get();
  954. try {
  955. BookingDetails cancelledBooking = bookingService.updateCancelledBookingStatus(bookingId, status, comments);
  956. String cancelledbookingsms="Your booking ID "+bookingId+" on "+bookingDetails.getStartDate()+" has been cancelled successfully. The deposit amount will be refunded to your account within 3 to 15 days. Thanks for using the GCC Community Hall Booking System.";
  957. String cancelledurlString ="https://tmegov.onex-aura.com/api/sms?key=pfTEYN6H&to="+bookingDetails.getUsers().getMobileNo()+"&from=GCCCRP&body="+cancelledbookingsms+"&entityid=1401572690000011081&templateid=1407172346829376988";
  958. String cancelledwhatsupmsg = "https://media.smsgupshup.com/GatewayAPI/rest?userid=2000233507&password=h2YjFNcJ&send_to="+bookingDetails.getUsers().getMobileNo()+"&v=1.1&format=json&msg_type=TEXT&method=SENDMESSAGE&msg=Your+booking+with+ID+"+bookingId+"+on+"+bookingDetails.getStartDate()+"+has+been+cancelled+successfully.+%0AThe+deposit+amount+will+be+refunded+to+your+account+within+3+to+15+days.";
  959. whatsappMsgServiceImpl.sendMsg(cancelledwhatsupmsg);
  960. whatsappMsgServiceImpl.sendSMS(cancelledurlString);
  961. Optional<BookingDetails> book=bookingDetailsRepository.findById(bookingDetails.getBookingId());
  962. BookingDetails booking=book.get();
  963. DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
  964. String formattedDate = LocalDateTime.now().format(formatter);
  965. booking.setUpdatedDate(formattedDate);
  966. bookingDetailsRepository.save(booking);
  967. log.info("Booking cancelled successfully");
  968. return ResponseEntity.ok(cancelledBooking);
  969. } catch (Exception e) {
  970. log.error("Error cancelling booking", e);
  971. return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR)
  972. .body("Error cancelling booking: " + e.getMessage());
  973. }
  974. }
  975. @Operation(
  976. summary = "Family Pensioner Details from ERP REST API",
  977. description = "REST API to check the Family Pensioner Details From ERP"
  978. )
  979. //checking Family pensioner Details
  980. @GetMapping("/FamilyPensionerDetails")
  981. @ResponseBody // Ensure Spring treats the returned object as the response body
  982. public Map<String, Object> getFamilyPensionerDetails(HttpServletRequest request, @RequestParam("id") Long id) {
  983. String purpose = "Checking Pensioner";
  984. RestTemplate restTemplate = new RestTemplate();
  985. String url = "https://erp.chennaicorporation.gov.in/pgr/external/mobileservice?serviceId=getFamPensionerDetailsList&familPensionId="
  986. + id;
  987. ResponseEntity<String> responseEntity = restTemplate.getForEntity(url, String.class);
  988. // Extract the JSON string from the response body
  989. String jsonString = responseEntity.getBody();
  990. // Extract the Java object from the response body
  991. ObjectMapper objectMapper = new ObjectMapper();
  992. Map<String, Object> responseMap = new HashMap<>();
  993. try {
  994. FamilyPensionerDetailsResponse familyPensionerDetailsResponse = objectMapper.readValue(jsonString,
  995. FamilyPensionerDetailsResponse.class);
  996. if (familyPensionerDetailsResponse != null) {
  997. List<FamilyPensionerDetails> familyPensionerDetails = familyPensionerDetailsResponse
  998. .getFamilyPensionerDetails();
  999. if (familyPensionerDetails != null && !familyPensionerDetails.isEmpty()) {
  1000. //Long mobileNo = Long.parseLong(familyPensionerDetailsResponse.getFamilyPensionerDetails().get(0).getMobile_no());
  1001. Long mobileNo = 8220798937l;
  1002. //System.out.println("step 1");
  1003. responseMap.put("mobileNo", mobileNo);
  1004. }
  1005. }
  1006. } catch (IOException e) {
  1007. e.printStackTrace();
  1008. }
  1009. return responseMap;
  1010. }
  1011. @Operation(
  1012. summary = "GCC Employee Details ERP REST API",
  1013. description = "REST API to retrieving the GCC Employee Details From ERP"
  1014. )
  1015. @GetMapping("/gccemployee")
  1016. @ResponseBody // Ensure Spring treats the returned object as the response body
  1017. public Map<String, Object> getGccEmployee(HttpServletRequest request, @RequestParam("id") Long id) {
  1018. String purpose = "Checking GccEmployee";
  1019. RestTemplate restTemplate = new RestTemplate();
  1020. String url = "https://erp.chennaicorporation.gov.in/pgr/external/mobileservice?serviceId=getEmployeeDetail&EmployeeID="
  1021. + id;
  1022. ResponseEntity<String> responseEntity = restTemplate.getForEntity(url, String.class);
  1023. // Extract the JSON string from the response body
  1024. String jsonString = responseEntity.getBody();
  1025. // Extract the Java object from the response body
  1026. ObjectMapper objectMapper = new ObjectMapper();
  1027. Map<String, Object> responseMap = new HashMap<>();
  1028. try {
  1029. EmployeeDetailsResponse employeeDetailsResponse = objectMapper.readValue(jsonString,
  1030. EmployeeDetailsResponse.class);
  1031. if (employeeDetailsResponse != null) {
  1032. List<EmployeeDetails> employeeDetails = employeeDetailsResponse
  1033. .getEmployeeDetailsResult();
  1034. if (employeeDetails != null && !employeeDetails.isEmpty()) {
  1035. //Long mobileNo = Long.parseLong(familyPensionerDetailsResponse.getFamilyPensionerDetails().get(0).getMobile_no());
  1036. //Long mobileNo = 8220798933l;
  1037. //System.out.println("step 1");
  1038. responseMap.put("EmployeeDetailsResult", employeeDetails );
  1039. }else {
  1040. responseMap.put("EmployeeDetailsResult", null );
  1041. }
  1042. }
  1043. } catch (IOException e) {
  1044. e.printStackTrace();
  1045. }
  1046. return responseMap;
  1047. }
  1048. @Operation(
  1049. summary = "Pensioner Details ERP REST API",
  1050. description = "REST API to retrieving the Pensioner Details From ERP"
  1051. )
  1052. //checking pensioner Details
  1053. @GetMapping("/PensionerDetails")
  1054. @ResponseBody
  1055. public Map<String, Object> getPensionerDetails(HttpServletRequest request, @RequestParam("id") Long id) {
  1056. String purpose = "Checking Employee";
  1057. RestTemplate restTemplate = new RestTemplate();
  1058. String url = "https://erp.chennaicorporation.gov.in/pgr/external/mobileservice?serviceId=getPensionerDetailsList&pensionerId=" + id;
  1059. ResponseEntity<String> responseEntity = restTemplate.getForEntity(url, String.class);
  1060. // Extract the JSON string from the response body
  1061. String jsonString = responseEntity.getBody();
  1062. // Extract the Java object from the response body
  1063. ObjectMapper objectMapper = new ObjectMapper();
  1064. Map<String, Object> responseMap = new HashMap<>();
  1065. try {
  1066. PensionerDetailsResponse pensionerDetailsResponse = objectMapper.readValue(jsonString, PensionerDetailsResponse.class);
  1067. if (pensionerDetailsResponse != null) {
  1068. List<PensionerDetails> pensionerDetails = pensionerDetailsResponse.getEmployees();
  1069. if (pensionerDetails != null && !pensionerDetails.isEmpty()) {
  1070. Long mobileNo = Long.parseLong(pensionerDetailsResponse.getEmployees().get(0).getMobile_no());
  1071. // Long mobileNo = 9874561230l;
  1072. // System.out.println("step 2");
  1073. responseMap.put("mobileNo", mobileNo);
  1074. return responseMap;
  1075. } else {
  1076. responseMap.put("error", "No pensioner details found for the given ID");
  1077. return responseMap;
  1078. }
  1079. }
  1080. } catch (Exception e) {
  1081. e.printStackTrace();
  1082. responseMap.put("error", "An error occurred while processing the request");
  1083. }
  1084. return responseMap;
  1085. }
  1086. @Operation(
  1087. summary = "Saving Counter Details ERP REST API",
  1088. description = "REST API to save the Counter Details"
  1089. )
  1090. //Saving the Counter Details
  1091. @PostMapping(path = "/counter-booking", consumes = { "multipart/form-data" })
  1092. public ResponseEntity<?> saveCounterBookingDetails(HttpServletRequest request) {
  1093. MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
  1094. Map<String,Object> bookingDetails = splitFormData(multipartRequest);
  1095. Map<String, Object> saveCounterBooking = counterService.saveCounterBooking(bookingDetails);
  1096. return ResponseEntity.ok(saveCounterBooking);
  1097. }
  1098. @GetMapping("/checkAvail")
  1099. public List<HallDetails> checkAvail(@RequestParam("fromDate") String fromDate,
  1100. @RequestParam("toDate") String toDate,
  1101. @RequestParam("starting") String starting,
  1102. @RequestParam("ending") String ending,
  1103. @RequestParam(name = "hallId",required = false) String hallId){
  1104. List<BookingCalendar> data = new ArrayList<>();
  1105. HashSet<Integer> removeHallId = new HashSet<Integer>();
  1106. int hallIdd=0;
  1107. if(hallId != null && !hallId.equals("")){
  1108. hallIdd = Integer.parseInt(hallId);
  1109. }
  1110. if(!fromDate.equals(toDate) && (starting.equals(ending) || starting.equals("evening") && ending.equals("morning"))){
  1111. Map<String,String> mp =incrementAndDecrementAndDaysCount(fromDate,toDate);
  1112. long noOfDays= Long.parseLong(mp.get("NoOfDays").toString());
  1113. if(noOfDays>2){
  1114. data = calendarService.getCalendarByDateAndHallIdAndSlot(mp.get("fromDate"),mp.get("toDate"),starting,ending,hallIdd);
  1115. for(int i=0;i<data.size();i++){
  1116. removeHallId.add(data.get(i).getHallId());
  1117. }
  1118. }
  1119. }
  1120. data=calendarService.getCalendarByDateAndHallIdAndSlot(fromDate,toDate,starting,ending,hallIdd);
  1121. //System.out.println("data size :-"+data.size());
  1122. if(starting!=null && ending != null ) {
  1123. boolean checkAvail =false;
  1124. int checkHallId=0;
  1125. for(int i=0;i<data.size();i++) {
  1126. if((starting.equals("evening") || ending.equals("morning")) && fromDate.equals(data.get(i).getBdate().toString()) && toDate.equals(fromDate)) {
  1127. if(data.get(i).isEveningSlot()==false) {
  1128. continue;
  1129. }
  1130. else if(data.get(i).isMorningSlot()==false) {
  1131. continue;
  1132. }
  1133. } else if ((starting.equals(ending) || starting.equals("evening") && ending.equals("morning")) && !toDate.equals(fromDate)) {
  1134. if(checkHallId==0 || checkHallId != data.get(i).getHallId()){
  1135. checkHallId = data.get(i).getHallId();
  1136. checkAvail=false;
  1137. }
  1138. if(starting.equals("morning") && ending.equals("morning") ) {
  1139. if(fromDate.equals(data.get(i).getBdate().toString()) && data.get(i).isMorningSlot()==false){
  1140. if(checkHallId == data.get(i).getHallId()){
  1141. continue;
  1142. }
  1143. }
  1144. else if(toDate.equals(data.get(i).getBdate().toString()) && data.get(i).isMorningSlot()==false){
  1145. if(checkHallId == data.get(i).getHallId() && checkAvail==false){
  1146. checkHallId=data.get(i).getHallId();
  1147. continue;
  1148. }
  1149. }
  1150. }else if(starting.equals("evening") && ending.equals("morning") ) {
  1151. if(fromDate.equals(data.get(i).getBdate().toString()) && data.get(i).isEveningSlot()==false){
  1152. if(checkHallId == data.get(i).getHallId()){
  1153. continue;
  1154. }
  1155. }
  1156. else if(toDate.equals(data.get(i).getBdate().toString()) && data.get(i).isMorningSlot()==false){
  1157. if(checkHallId == data.get(i).getHallId() && checkAvail==false){
  1158. checkHallId=data.get(i).getHallId();
  1159. continue;
  1160. }
  1161. }
  1162. }else if(starting.equals("evening") && ending.equals("evening") ) {
  1163. if(fromDate.equals(data.get(i).getBdate().toString()) && data.get(i).isEveningSlot()==false){
  1164. if(checkHallId == data.get(i).getHallId()){
  1165. continue;
  1166. }
  1167. }
  1168. else if(toDate.equals(data.get(i).getBdate().toString()) && data.get(i).isEveningSlot()==false){
  1169. if(checkHallId == data.get(i).getHallId() && checkAvail==false){
  1170. checkHallId=data.get(i).getHallId();
  1171. continue;
  1172. }
  1173. }
  1174. }
  1175. else{
  1176. if(checkHallId == data.get(i).getHallId()) {
  1177. checkAvail = true;
  1178. }
  1179. }
  1180. }
  1181. //System.out.println(data.get(i).getHallId());
  1182. removeHallId.add(data.get(i).getHallId());
  1183. }
  1184. }
  1185. List<HallDetails> removeHallByid = new ArrayList<>();
  1186. if(hallIdd!=0){
  1187. if(hallIdd!=data.get(0).getHallId()){
  1188. HallDetails hallDetails = hallDetailService.getHallById(hallIdd);
  1189. removeHallByid.add(hallDetails);
  1190. }
  1191. }else {
  1192. removeHallByid = hallDetailService.removeHallById(removeHallId);
  1193. }
  1194. return removeHallByid;
  1195. }
  1196. Map<String,String> incrementAndDecrementAndDaysCount(String fromdate, String todate){
  1197. Map mp = new HashMap<>();
  1198. LocalDate increasement = LocalDate.parse(fromdate);
  1199. LocalDate decrement = LocalDate.parse(todate);
  1200. LocalDate outputDateFrom =increasement;
  1201. LocalDate outputDateToday = decrement;
  1202. long daysDifference = increasement.until(decrement).getDays();
  1203. daysDifference = Math.abs(daysDifference);
  1204. if(fromdate!=todate) {
  1205. outputDateFrom = increasement.plusDays(1);
  1206. outputDateToday = decrement.minusDays(1);
  1207. }
  1208. mp.put("fromDate", outputDateFrom.format(DateTimeFormatter.ofPattern("yyyy-MM-dd")));
  1209. mp.put("toDate",outputDateToday.format(DateTimeFormatter.ofPattern("yyyy-MM-dd")));
  1210. mp.put("NoOfDays",daysDifference+"");
  1211. return mp;
  1212. }
  1213. @GetMapping("/getuserDetailsbymobileno")
  1214. public Users getuserDetailsbymobileno(@RequestParam long mobileNo) {
  1215. return userservice.getUserDetailsByMobileNo(mobileNo);
  1216. }
  1217. //Reschedule
  1218. @PostMapping("/reschedule-dates")
  1219. public ResponseEntity<String> updateBookingDates(
  1220. @RequestParam int bookingId,
  1221. @RequestParam String startDate,
  1222. @RequestParam String endDate) {
  1223. try {
  1224. Optional<String> updateResult = bookingService.updateBookingDatesAndCalendar(bookingId, startDate, endDate);
  1225. if (updateResult.isPresent()) {
  1226. if (updateResult.get().equals("Booking dates updated successfully.")) {
  1227. return new ResponseEntity<>(updateResult.get(), HttpStatus.OK);
  1228. } else {
  1229. // Any other message is treated as an error
  1230. return new ResponseEntity<>(updateResult.get(), HttpStatus.BAD_REQUEST);
  1231. }
  1232. } else {
  1233. return new ResponseEntity<>("Booking not found", HttpStatus.NOT_FOUND);
  1234. }
  1235. } catch (SlotOccupiedException e) {
  1236. // Return a bad request status with the exception message
  1237. return new ResponseEntity<>(e.getMessage(), HttpStatus.BAD_REQUEST);
  1238. }
  1239. }
  1240. @GetMapping("/trackBooking")
  1241. public List<Map<String, Object>> getTrackingDetails(@RequestParam int bookingId) {
  1242. Optional<BookingDetails> booking = bookingDetailsRepository.findById(bookingId);
  1243. List<Map<String, Object>> trackingDetails = new ArrayList<>();
  1244. DateTimeFormatter dateFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
  1245. DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss");
  1246. if (booking.isPresent()) {
  1247. BookingDetails bookingDetails = booking.get();
  1248. // Payment Success
  1249. if (bookingDetails.getPayments() != null) {
  1250. Map<String, Object> paymentDetail = new HashMap<>();
  1251. paymentDetail.put("status", "PAYMENT_SUCCESS");
  1252. paymentDetail.put("description", "Payment Success");
  1253. paymentDetail.put("dateTime", bookingDetails.getPayments().getCdate()); // Assuming Cdate is the created date
  1254. trackingDetails.add(paymentDetail);
  1255. }
  1256. // Booking Approved
  1257. if (bookingDetails.getBookingStatus() == BookingStatus.APPROVED) {
  1258. Map<String, Object> bookingApprovedDetail = new HashMap<>();
  1259. bookingApprovedDetail.put("status", "APPROVED");
  1260. bookingApprovedDetail.put("description", "Booking Approved");
  1261. bookingApprovedDetail.put("dateTime", bookingDetails.getBookingDate()); // Assuming BookingDate is correct
  1262. trackingDetails.add(bookingApprovedDetail);
  1263. }
  1264. // Event Completed
  1265. LocalDateTime endDate = null;
  1266. try {
  1267. // Try parsing as LocalDateTime first
  1268. try {
  1269. endDate = LocalDateTime.parse(bookingDetails.getEndDate(), dateTimeFormatter);
  1270. } catch (Exception e) {
  1271. // If parsing fails, try parsing as LocalDate
  1272. LocalDate endDateOnly = LocalDate.parse(bookingDetails.getEndDate(), dateFormatter);
  1273. endDate = endDateOnly.atStartOfDay(); // Convert LocalDate to LocalDateTime at start of the day
  1274. }
  1275. } catch (Exception e) {
  1276. // Handle parsing exception
  1277. e.printStackTrace();
  1278. }
  1279. if (endDate != null && bookingDetails.getBookingStatus() == BookingStatus.APPROVED &&
  1280. endDate.isBefore(LocalDateTime.now().plusDays(1))) { // Compare endDate with current date
  1281. Map<String, Object> eventCompletedDetail = new HashMap<>();
  1282. eventCompletedDetail.put("status", "EVENT_COMPLETED");
  1283. eventCompletedDetail.put("description", "Event Completed");
  1284. eventCompletedDetail.put("dateTime", bookingDetails.getEndDate());
  1285. trackingDetails.add(eventCompletedDetail);
  1286. }
  1287. // Settlement Raising
  1288. if (bookingDetails.getSettlement() != null && bookingDetails.getRefundStatus() == RefundStatus.WAITING) {
  1289. Map<String, Object> settlementRaisingDetail = new HashMap<>();
  1290. settlementRaisingDetail.put("status", "SETTLEMENT_RAISING");
  1291. settlementRaisingDetail.put("description", "Settlement Raising");
  1292. settlementRaisingDetail.put("dateTime", bookingDetails.getSettlement().getUpdatedDate() );
  1293. trackingDetails.add(settlementRaisingDetail);
  1294. }
  1295. // Refund Completed
  1296. if (bookingDetails.getBookingStatus() == BookingStatus.COMPLETED
  1297. && bookingDetails.getRefundStatus() == BookingDetails.RefundStatus.COMPLETED) {
  1298. Map<String, Object> refundCompletedDetail = new HashMap<>();
  1299. refundCompletedDetail.put("status", "COMPLETED");
  1300. refundCompletedDetail.put("description", "Refund Completed");
  1301. refundCompletedDetail.put("dateTime", bookingDetails.getUpdatedDate());
  1302. trackingDetails.add(refundCompletedDetail);
  1303. }
  1304. if (bookingDetails.getBookingStatus() == BookingStatus.CANCELED){
  1305. Map<String ,Object> bookingCanceledDetail = new HashMap<>();
  1306. bookingCanceledDetail.put("status","CANCELED");
  1307. bookingCanceledDetail.put("description", "Booking Cancelled");
  1308. bookingCanceledDetail.put("dateTime", bookingDetails.getUpdatedDate()); // Assuming BookingDate is correct
  1309. trackingDetails.add(bookingCanceledDetail);
  1310. }
  1311. if (bookingDetails.getBookingStatus() == BookingStatus.CANCELED
  1312. && bookingDetails.getRefundStatus() == RefundStatus.WAITING){
  1313. Map<String ,Object> canceledRaisingDetail = new HashMap<>();
  1314. canceledRaisingDetail.put("status","SETTLEMENT_RAISING");
  1315. canceledRaisingDetail.put("description", "Settlement Raising");
  1316. canceledRaisingDetail.put("dateTime", bookingDetails.getUpdatedDate()); // Assuming BookingDate is correct
  1317. trackingDetails.add(canceledRaisingDetail);
  1318. }
  1319. if (bookingDetails.getBookingStatus() == BookingStatus.CANCELED
  1320. && bookingDetails.getRefundStatus() == BookingDetails.RefundStatus.COMPLETED){
  1321. Map<String, Object> cancelRefundCompletedDetail = new HashMap<>();
  1322. cancelRefundCompletedDetail.put("status", "COMPLETED");
  1323. cancelRefundCompletedDetail.put("description", "Refund Completed");
  1324. cancelRefundCompletedDetail.put("dateTime", bookingDetails.getUpdatedDate());
  1325. trackingDetails.add(cancelRefundCompletedDetail);
  1326. }
  1327. if (bookingDetails.getBookingStatus() == BookingStatus.REJECTED){
  1328. Map<String ,Object> bookingRejectedDetail = new HashMap<>();
  1329. bookingRejectedDetail.put("status","REJECTED");
  1330. bookingRejectedDetail.put("description", "Booking Rejected");
  1331. bookingRejectedDetail.put("dateTime", bookingDetails.getUpdatedDate()); // Assuming BookingDate is correct
  1332. trackingDetails.add(bookingRejectedDetail);
  1333. }
  1334. if (bookingDetails.getBookingStatus() == BookingStatus.REJECTED
  1335. && bookingDetails.getRefundStatus() == RefundStatus.WAITING){
  1336. Map<String ,Object> rejectedRaisingDetail = new HashMap<>();
  1337. rejectedRaisingDetail.put("status","SETTLEMENT_RAISING");
  1338. rejectedRaisingDetail.put("description", "Settlement Raising");
  1339. rejectedRaisingDetail.put("dateTime", bookingDetails.getUpdatedDate()); // Assuming BookingDate is correct
  1340. trackingDetails.add(rejectedRaisingDetail);
  1341. }
  1342. if (bookingDetails.getBookingStatus() == BookingStatus.REJECTED
  1343. && bookingDetails.getRefundStatus() == BookingDetails.RefundStatus.COMPLETED){
  1344. Map<String, Object> rejectedRefundCompletedDetail = new HashMap<>();
  1345. rejectedRefundCompletedDetail.put("status", "COMPLETED");
  1346. rejectedRefundCompletedDetail.put("description", "Refund Completed");
  1347. rejectedRefundCompletedDetail.put("dateTime", bookingDetails.getUpdatedDate());
  1348. trackingDetails.add(rejectedRefundCompletedDetail);
  1349. }
  1350. if (bookingDetails.getBookingStatus() == BookingStatus.GCC_BLOCKED){
  1351. Map<String ,Object> gccBlockedDetail = new HashMap<>();
  1352. gccBlockedDetail.put("status","GCC_BLOCKED");
  1353. gccBlockedDetail.put("description", "GCC Blocked");
  1354. gccBlockedDetail.put("dateTime", bookingDetails.getUpdatedDate());
  1355. trackingDetails.add(gccBlockedDetail);
  1356. }
  1357. }
  1358. return trackingDetails;
  1359. }
  1360. @GetMapping("/confirmstatebooking")
  1361. public String Confirmstatebookig(@RequestParam int bookingId ) {
  1362. String response=bookingService.confirmStateBooking(bookingId);
  1363. return response;
  1364. }
  1365. @PostMapping("/uploaddocs")
  1366. public ResponseEntity<String> uploadDocs(@RequestParam("nocFile") MultipartFile file,
  1367. @RequestParam("bookingssId") int bookingId) {
  1368. try {
  1369. bookingService.uploadNOCFile(file, bookingId);
  1370. return ResponseEntity.ok("File uploaded and saved successfully");
  1371. } catch (Exception e) {
  1372. return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("File upload failed: " + e.getMessage());
  1373. }
  1374. }
  1375. /*@GetMapping("/calculatehallamount")
  1376. public ResponseEntity<Map<String, Object>> getHallDetailsConcession(
  1377. @RequestParam int numDays,
  1378. @RequestParam(value = "startPeriod", required = false) String startPeriod,
  1379. @RequestParam(value = "endPeriod", required = false) String endPeriod,
  1380. @RequestParam(value = "reasonforBooking", required = false) String reasonforBooking,
  1381. @RequestParam int hallId) {
  1382. Optional<HallDetails> hallDetailsOpt = hallDetailsRepository.findById(hallId);
  1383. if (!hallDetailsOpt.isPresent()) {
  1384. return ResponseEntity.status(404).body(null); // Handle not found
  1385. }
  1386. HallDetails hallDetails = hallDetailsOpt.get();
  1387. boolean isSGE = hallDetails.isSGE();
  1388. boolean isCGE = hallDetails.isCGE();
  1389. double fullDayAmount = hallDetails.getFullDayRent();
  1390. double halfDayAmount = hallDetails.getHalfDayRent();
  1391. double depositAmount = hallDetails.getDepositAmount();
  1392. double gstRate = hallDetails.getGst();
  1393. Map<String, Object> response = new HashMap<>();
  1394. double amount = calculateAmount(numDays, startPeriod, endPeriod, fullDayAmount, halfDayAmount);
  1395. double totalDepositAmount = depositAmount * numDays;
  1396. double totalAmount;
  1397. double discountAmount = 0.0;
  1398. response.put("reasonforBooking", reasonforBooking);
  1399. if (!isSGE) {
  1400. totalAmount = amount + (amount * gstRate / 100) + totalDepositAmount;
  1401. response.put("discount", 0);
  1402. response.put("amount", amount);
  1403. response.put("totalAmount", totalAmount);
  1404. response.put("depositAmount", totalDepositAmount);
  1405. double gstValue =gstRate * amount / 100.0;
  1406. response.put("gst", gstValue);
  1407. response.put("discountAmount", amount);
  1408. } else {
  1409. if ("SGE".equals(reasonforBooking)) {
  1410. double cleaningCharges = hallDetails.getHallDetailsConcession().get(0).getFullDayCleaningcharges();
  1411. double pasystem=hallDetails.getHallDetailsConcession().get(0).getFulldayPAsystem();
  1412. double ebCharges=hallDetails.getHallDetailsConcession().get(0).getFulldayEBcharges();
  1413. double halfcleaningCharges = hallDetails.getHallDetailsConcession().get(0).getHalfDayCleaningcharges();
  1414. double halfpasystem=hallDetails.getHallDetailsConcession().get(0).getHalfdayPAsystem();
  1415. double halfebCharges=hallDetails.getHallDetailsConcession().get(0).getHalfdayEBcharges();
  1416. double fulladditionalCharges = cleaningCharges+pasystem+ebCharges;
  1417. double halfadditionalCharges = halfcleaningCharges+halfpasystem+halfebCharges;
  1418. double fulldayhallAmount=hallDetails.getHallDetailsConcession().get(0).getFulldayhallamount();
  1419. double halfdayhallAmount=hallDetails.getHallDetailsConcession().get(0).getHalfdayhallamount();
  1420. double additionalCharges=calculateAmount(numDays, startPeriod, endPeriod, fulladditionalCharges, halfadditionalCharges);
  1421. totalAmount = additionalCharges + totalDepositAmount + (additionalCharges * gstRate / 100.0);
  1422. discountAmount = (fulldayhallAmount * hallDetails.getSGEdiscount()) / 100.0;
  1423. response.put("startperiod", startPeriod);
  1424. response.put("endPeriod", endPeriod);
  1425. response.put("fulldayhallAmount", fulldayhallAmount);
  1426. response.put("halfdayhallAmount", halfdayhallAmount);
  1427. response.put("discount", hallDetails.getSGEdiscount());
  1428. response.put("rentAmount", 0);
  1429. response.put("additionalCharges", additionalCharges);
  1430. response.put("netAmount", additionalCharges);
  1431. response.put("gst", gstRate * additionalCharges / 100);
  1432. response.put("depositAmount", totalDepositAmount);
  1433. response.put("totalAmount", totalAmount);
  1434. response.put("discountAmount", discountAmount);
  1435. } else if ("CGE".equals(reasonforBooking)) {
  1436. response.put("discount", hallDetails.getCGEdiscount());
  1437. discountAmount = (amount * hallDetails.getCGEdiscount()) / 100.0;
  1438. totalAmount = discountAmount + totalDepositAmount + (discountAmount * gstRate / 100);
  1439. response.put("amount", amount);
  1440. response.put("totalAmount", totalAmount);
  1441. response.put("depositAmount", totalDepositAmount);
  1442. double gstValue = gstRate * discountAmount / 100;
  1443. response.put("gst", gstValue);
  1444. response.put("discountAmount", discountAmount);
  1445. } else {
  1446. totalAmount = amount + (amount * gstRate / 100) + totalDepositAmount;
  1447. response.put("discount", 0);
  1448. response.put("amount", amount);
  1449. response.put("totalAmount", totalAmount);
  1450. response.put("depositAmount", totalDepositAmount);
  1451. double gstValue =gstRate * amount / 100.0;
  1452. response.put("gst", gstValue);
  1453. response.put("discountAmount", amount);
  1454. }
  1455. }
  1456. return ResponseEntity.ok(response);
  1457. }
  1458. public double calculateAmount(double numDays, String startPeriod, String endPeriod, double fullDayAmount, double halfDayAmount) {
  1459. double amount = 0;
  1460. // If there is only one day
  1461. if (numDays == 1) {
  1462. if ("1".equals(startPeriod) && "2".equals(endPeriod)) {
  1463. amount = fullDayAmount;
  1464. } else if ("1".equals(startPeriod) && "1".equals(endPeriod)) {
  1465. amount = halfDayAmount;
  1466. } else if ("2".equals(startPeriod) && "2".equals(endPeriod)) {
  1467. amount = halfDayAmount;
  1468. }else {
  1469. amount=numDays;
  1470. }
  1471. } else {
  1472. // For multiple days
  1473. if ("1".equals(startPeriod) && "2".equals(endPeriod)) {
  1474. amount = fullDayAmount * numDays;
  1475. } else if ("1".equals(startPeriod) && "1".equals(endPeriod)) {
  1476. amount = fullDayAmount * (numDays - 1) + halfDayAmount;
  1477. } else if ("2".equals(startPeriod) && "2".equals(endPeriod)) {
  1478. amount = fullDayAmount * (numDays - 1) + halfDayAmount;
  1479. } else if ("2".equals(startPeriod) && "1".equals(endPeriod)) {
  1480. amount = fullDayAmount * (numDays - 2) + halfDayAmount * 2;
  1481. }else {
  1482. amount=numDays;
  1483. }
  1484. }
  1485. return amount;
  1486. }*/
  1487. @GetMapping("/calculatehallamount")
  1488. public ResponseEntity<Map<String, Object>> getHallDetailsConcession(
  1489. @RequestParam int numDays,
  1490. @RequestParam(value = "startPeriod", required = false) String startPeriod,
  1491. @RequestParam(value = "endPeriod", required = false) String endPeriod,
  1492. @RequestParam(value = "reasonforBooking", required = false) String reasonforBooking,
  1493. @RequestParam int hallId) {
  1494. Optional<HallDetails> hallDetailsOpt = hallDetailsRepository.findById(hallId);
  1495. if (!hallDetailsOpt.isPresent()) {
  1496. return ResponseEntity.status(404).body(null); // Handle not found
  1497. }
  1498. HallDetails hallDetails = hallDetailsOpt.get();
  1499. boolean isSGE = hallDetails.isSGE();
  1500. boolean isCGE = hallDetails.isCGE();
  1501. double fullDayAmount = hallDetails.getFullDayRent();
  1502. double halfDayAmount = hallDetails.getHalfDayRent();
  1503. double depositAmount = hallDetails.getDepositAmount();
  1504. double gstRate = hallDetails.getGst();
  1505. Map<String, Object> response = new HashMap<>();
  1506. double amount = calculateAmount(numDays, startPeriod, endPeriod, fullDayAmount, halfDayAmount);
  1507. double totalDepositAmount = calculateDepositAmount(numDays, startPeriod, endPeriod, depositAmount);
  1508. double totalAmount;
  1509. double discountAmount = 0.0;
  1510. response.put("reasonforBooking", reasonforBooking);
  1511. if (!isSGE) {
  1512. totalAmount = amount + (amount * gstRate / 100) + totalDepositAmount;
  1513. response.put("discount", 0);
  1514. response.put("amount", amount);
  1515. response.put("totalAmount", totalAmount);
  1516. response.put("depositAmount", totalDepositAmount);
  1517. double gstValue =gstRate * amount / 100.0;
  1518. response.put("gst", gstValue);
  1519. response.put("discountAmount", amount);
  1520. } else {
  1521. if ("SGE".equals(reasonforBooking)) {
  1522. double cleaningCharges = hallDetails.getHallDetailsConcession().get(0).getFullDayCleaningcharges();
  1523. double pasystem=hallDetails.getHallDetailsConcession().get(0).getFulldayPAsystem();
  1524. double ebCharges=hallDetails.getHallDetailsConcession().get(0).getFulldayEBcharges();
  1525. double halfcleaningCharges = hallDetails.getHallDetailsConcession().get(0).getHalfDayCleaningcharges();
  1526. double halfpasystem=hallDetails.getHallDetailsConcession().get(0).getHalfdayPAsystem();
  1527. double halfebCharges=hallDetails.getHallDetailsConcession().get(0).getHalfdayEBcharges();
  1528. double fulladditionalCharges = cleaningCharges+pasystem+ebCharges;
  1529. double halfadditionalCharges = halfcleaningCharges+halfpasystem+halfebCharges;
  1530. double fulldayhallAmount=hallDetails.getHallDetailsConcession().get(0).getFulldayhallamount();
  1531. double halfdayhallAmount=hallDetails.getHallDetailsConcession().get(0).getHalfdayhallamount();
  1532. double additionalCharges=calculateAmount(numDays, startPeriod, endPeriod, fulladditionalCharges, halfadditionalCharges);
  1533. totalAmount = additionalCharges + totalDepositAmount + (additionalCharges * gstRate / 100.0);
  1534. discountAmount = (fulldayhallAmount * hallDetails.getSGEdiscount()) / 100.0;
  1535. response.put("startperiod", startPeriod);
  1536. response.put("endPeriod", endPeriod);
  1537. response.put("fulldayhallAmount", fulldayhallAmount);
  1538. response.put("halfdayhallAmount", halfdayhallAmount);
  1539. response.put("discount", hallDetails.getSGEdiscount());
  1540. response.put("rentAmount", 0);
  1541. response.put("additionalCharges", additionalCharges);
  1542. response.put("netAmount", additionalCharges);
  1543. response.put("gst", gstRate * additionalCharges / 100);
  1544. response.put("depositAmount", totalDepositAmount);
  1545. response.put("totalAmount", totalAmount);
  1546. response.put("discountAmount", discountAmount);
  1547. } else if ("CGE".equals(reasonforBooking)) {
  1548. double cleaningCharges = hallDetails.getHallDetailsConcession().get(0).getFullDayCleaningcharges();
  1549. double pasystem=hallDetails.getHallDetailsConcession().get(0).getFulldayPAsystem();
  1550. double ebCharges=hallDetails.getHallDetailsConcession().get(0).getFulldayEBcharges();
  1551. double halfcleaningCharges = hallDetails.getHallDetailsConcession().get(0).getHalfDayCleaningcharges();
  1552. double halfpasystem=hallDetails.getHallDetailsConcession().get(0).getHalfdayPAsystem();
  1553. double halfebCharges=hallDetails.getHallDetailsConcession().get(0).getHalfdayEBcharges();
  1554. double fulladditionalCharges = cleaningCharges+pasystem+ebCharges;
  1555. double halfadditionalCharges = halfcleaningCharges+halfpasystem+halfebCharges;
  1556. double additionalCharges=calculateAmount(numDays, startPeriod, endPeriod, fulladditionalCharges, halfadditionalCharges);
  1557. double rentAmount = (amount * hallDetails.getCGEdiscount()) / 100.0;
  1558. double netAmount = rentAmount + additionalCharges;
  1559. double gst = ((additionalCharges+rentAmount) * gstRate / 100.0);
  1560. totalAmount = Math.floor((netAmount + gst + totalDepositAmount) * 100) / 100.0 ;
  1561. response.put("startperiod", startPeriod);
  1562. response.put("endPeriod", endPeriod);
  1563. response.put("fulldayhallAmount", fullDayAmount);
  1564. response.put("halfdayhallAmount", halfDayAmount);
  1565. response.put("discount", hallDetails.getCGEdiscount());
  1566. response.put("rentAmount", rentAmount);
  1567. response.put("additionalCharges", additionalCharges);
  1568. response.put("netAmount", netAmount);
  1569. response.put("gst", gst);
  1570. response.put("depositAmount", totalDepositAmount);
  1571. response.put("totalAmount", totalAmount);
  1572. response.put("discountAmount", discountAmount);
  1573. } else {
  1574. double gstValue =(gstRate * amount) / 100.0;
  1575. totalAmount = Math.ceil((amount + gstValue + totalDepositAmount) * 100) / 100;
  1576. response.put("discount", 0);
  1577. response.put("amount", amount);
  1578. response.put("totalAmount", totalAmount);
  1579. response.put("depositAmount", totalDepositAmount);
  1580. response.put("gst", gstValue);
  1581. response.put("discountAmount", amount);
  1582. }
  1583. }
  1584. return ResponseEntity.ok(response);
  1585. }
  1586. public double calculateAmount(double numDays, String startPeriod, String endPeriod, double fullDayAmount, double halfDayAmount) {
  1587. double amount = 0;
  1588. // If there is only one day
  1589. if (numDays == 1) {
  1590. if ("1".equals(startPeriod) && "2".equals(endPeriod)) {
  1591. amount = fullDayAmount;
  1592. } else if ("1".equals(startPeriod) && "1".equals(endPeriod)) {
  1593. amount = halfDayAmount;
  1594. } else if ("2".equals(startPeriod) && "2".equals(endPeriod)) {
  1595. amount = halfDayAmount;
  1596. }else {
  1597. amount=numDays;
  1598. }
  1599. } else {
  1600. // For multiple days
  1601. if ("1".equals(startPeriod) && "2".equals(endPeriod)) {
  1602. amount = fullDayAmount * numDays;
  1603. } else if ("1".equals(startPeriod) && "1".equals(endPeriod)) {
  1604. amount = fullDayAmount * (numDays - 1) + halfDayAmount;
  1605. } else if ("2".equals(startPeriod) && "2".equals(endPeriod)) {
  1606. amount = fullDayAmount * (numDays - 1) + halfDayAmount;
  1607. } else if ("2".equals(startPeriod) && "1".equals(endPeriod)) {
  1608. amount = fullDayAmount * (numDays - 2) + halfDayAmount * 2;
  1609. }else {
  1610. amount=numDays;
  1611. }
  1612. }
  1613. return amount;
  1614. }
  1615. @GetMapping("/getTransactionDetails")
  1616. public Map<String, Object> getTransactionDetails(@RequestParam String userId) {
  1617. // Fetch all transaction details for the user
  1618. List<TransactionResponse> transactions = PaymentGatewayServiceImpl.getTransactionResponseByuserId(userId);
  1619. Map<String, Object> response = new HashMap<>();
  1620. response.put("transactions", transactions);
  1621. // Fetch all refund details for the user in a single query
  1622. List<RefundResponse> refundDetails = transRefundResRepository.getRefundResponseByuserId(userId);
  1623. response.put("refundDetails", refundDetails);
  1624. System.out.println("Response: " + response);
  1625. return response;
  1626. }
  1627. @GetMapping("/collectionpendingacknowledgementsss")
  1628. public BookingDetails viewCollectionpendingAck(Model model,int bookingId){
  1629. BookingDetails bookingsDetails = bookingService.getBookingsById(bookingId);
  1630. model.addAttribute("bookingsDetails",bookingsDetails); // Add single BookingDetails object
  1631. model.addAttribute("userName",userSession.getDispayName());
  1632. return bookingsDetails;
  1633. }
  1634. @GetMapping("/checkQueue")
  1635. public ResponseEntity<List<BookingDetails>> checkQueue(
  1636. @RequestParam String bookingDate,
  1637. @RequestParam Long hallId) {
  1638. try {
  1639. List<BookingDetails> bookings = bookingService.getBookingsByDateAndHall(bookingDate, hallId);
  1640. return ResponseEntity.ok(bookings);
  1641. } catch (Exception e) {
  1642. return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build();
  1643. }
  1644. }
  1645. public double calculateDepositAmount(double numDays, String startPeriod, String endPeriod, double depositAmount) {
  1646. double damount = 0;
  1647. // If there is only one day
  1648. if (numDays == 1) {
  1649. if ("1".equals(startPeriod) && "2".equals(endPeriod)) {
  1650. damount = depositAmount;
  1651. } else if ("1".equals(startPeriod) && "1".equals(endPeriod)) {
  1652. damount = depositAmount;
  1653. } else if ("2".equals(startPeriod) && "2".equals(endPeriod)) {
  1654. damount = depositAmount;
  1655. } else {
  1656. damount = numDays;
  1657. }
  1658. } else {
  1659. // For multiple days
  1660. if ("1".equals(startPeriod) && "2".equals(endPeriod)) {
  1661. damount = depositAmount * numDays;
  1662. } else if ("1".equals(startPeriod) && "1".equals(endPeriod)) {
  1663. damount = depositAmount * (numDays - 1) + depositAmount;
  1664. } else if ("2".equals(startPeriod) && "2".equals(endPeriod)) {
  1665. damount = depositAmount * (numDays - 1) + depositAmount;
  1666. } else if ("2".equals(startPeriod) && "1".equals(endPeriod)) {
  1667. damount = depositAmount * (numDays - 2) + depositAmount;
  1668. } else {
  1669. damount = numDays;
  1670. }
  1671. }
  1672. return damount;
  1673. }
  1674. }