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.

2450 lines
138 KiB

2 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
2 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
2 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
2 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
2 years ago
​
​
​
​
​
​
​
2 years ago
​
​
​
​
​
​
​
​
​
​
​
​
2 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
2 years ago
​
2 years ago
​
2 years ago
​
2 years ago
​
2 years ago
​
2 years ago
​
2 years ago
​
2 years ago
​
2 years ago
​
2 years ago
​
2 years ago
​
​
​
2 years ago
​
​
​
​
​
​
​
2 years ago
​
​
​
​
2 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
2 years ago
2 years ago
​
​
​
2 years ago
​
​
2 years ago
​
​
​
2 years ago
​
​
2 years ago
2 years ago
​
​
​
2 years ago
​
​
2 years ago
​
​
2 years ago
​
​
​
​
​
2 years ago
​
​
2 years ago
​
2 years ago
2 years ago
2 years ago
​
​
​
​
​
2 years ago
​
​
​
​
2 years ago
​
​
​
​
2 years ago
​
​
​
​
​
​
​
​
​
2 years ago
​
​
2 years ago
​
2 years ago
​
​
​
​
2 years ago
​
​
​
​
2 years ago
​
​
​
2 years ago
​
2 years ago
​
​
​
​
​
​
​
2 years ago
2 years ago
​
​
​
​
​
​
​
​
2 years ago
​
​
​
​
​
​
2 years ago
​
​
​
​
​
​
2 years ago
​
​
2 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
2 years ago
​
​
2 years ago
​
​
​
2 years ago
​
​
2 years ago
2 years ago
​
​
​
2 years ago
​
​
​
​
​
2 years ago
​
​
​
​
​
​
​
​
​
2 years ago
2 years ago
2 years ago
​
​
​
​
​
2 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
2 years ago
​
​
2 years ago
​
2 years ago
​
​
​
​
2 years ago
​
​
​
​
2 years ago
​
​
​
2 years ago
​
2 years ago
​
​
​
​
​
​
​
2 years ago
​
2 years ago
​
​
​
​
​
​
​
​
​
​
2 years ago
​
​
​
​
​
2 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
2 years ago
​
​
​
​
2 years ago
​
​
​
​
​
2 years ago
​
​
​
​
​
​
​
​
​
​
2 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
2 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
2 years ago
2 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
2 years ago
2 years ago
​
​
​
​
​
2 years ago
​
​
2 years ago
​
​
​
​
​
​
2 years ago
​
​
​
​
​
2 years ago
​
​
2 years ago
​
​
​
​
​
2 years ago
​
2 years ago
​
​
​
​
​
​
​
​
2 years ago
​
​
​
​
​
​
​
2 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
2 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
2 years ago
​
​
​
​
​
​
​
​
​
​
​
2 years ago
​
​
​
​
​
​
2 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
2 years ago
​
​
2 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
2 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
2 years ago
​
​
​
​
2 years ago
​
​
​
2 years ago
​
​
​
​
​
​
​
​
2 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
2 years ago
​
​
​
​
​
​
​
​
​
​
​
2 years ago
​
​
2 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
2 years ago
​
​
​
2 years ago
​
​
​
​
​
2 years ago
​
​
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.service.Impl;
  2. import java.io.File;
  3. import java.io.FileOutputStream;
  4. import java.io.IOException;
  5. import java.text.ParseException;
  6. import java.text.SimpleDateFormat;
  7. import java.time.LocalDate;
  8. import java.time.LocalDateTime;
  9. import java.time.ZoneId;
  10. import java.time.format.DateTimeFormatter;
  11. import java.util.ArrayList;
  12. import java.util.Collections;
  13. import java.util.Date;
  14. import java.util.HashMap;
  15. import java.util.List;
  16. import java.util.Map;
  17. import java.util.Optional;
  18. import java.util.stream.Collectors;
  19. import jakarta.servlet.http.HttpSession;
  20. import org.springframework.beans.factory.annotation.Autowired;
  21. import org.springframework.beans.factory.annotation.Value;
  22. import org.springframework.stereotype.Service;
  23. import org.springframework.transaction.PlatformTransactionManager;
  24. import org.springframework.transaction.annotation.Propagation;
  25. import org.springframework.transaction.annotation.Transactional;
  26. import org.springframework.web.multipart.MultipartFile;
  27. import com.gcc.communityHall.entity.ApplicationLogs;
  28. import com.gcc.communityHall.entity.BookingCalendar;
  29. import com.gcc.communityHall.entity.BookingDetails;
  30. import com.gcc.communityHall.entity.BookingDetails.BookingStatus;
  31. import com.gcc.communityHall.entity.BookingDetails.RefundStatus;
  32. import com.gcc.communityHall.entity.BookingDocuments;
  33. import com.gcc.communityHall.entity.BookingHistory;
  34. import com.gcc.communityHall.entity.Damage;
  35. import com.gcc.communityHall.entity.DiscountRange;
  36. import com.gcc.communityHall.entity.EbDetails;
  37. import com.gcc.communityHall.entity.GccBlockingDate;
  38. import com.gcc.communityHall.entity.GccBlockingHistory;
  39. import com.gcc.communityHall.entity.GccblockingDocuments;
  40. import com.gcc.communityHall.entity.HallDetails;
  41. import com.gcc.communityHall.entity.HallDetailsConcession;
  42. import com.gcc.communityHall.entity.ReasonDocumentMaster;
  43. import com.gcc.communityHall.entity.ReasonMaster;
  44. import com.gcc.communityHall.entity.Settlement;
  45. import com.gcc.communityHall.entity.Users;
  46. import com.gcc.communityHall.exception.SlotOccupiedException;
  47. import com.gcc.communityHall.others.UserSession;
  48. import com.gcc.communityHall.paymentService.repository.TransRefundResRepository;
  49. import com.gcc.communityHall.paymentService.repository.TransactionResponseRepository;
  50. import com.gcc.communityHall.paymentService.service.PaymentGatewayService;
  51. import com.gcc.communityHall.repository.ApplicationLogsRepository;
  52. import com.gcc.communityHall.repository.BookingCalendarRepository;
  53. import com.gcc.communityHall.repository.BookingDetailsRepository;
  54. import com.gcc.communityHall.repository.BookingDocumentsRepository;
  55. import com.gcc.communityHall.repository.BookingHistoryRepository;
  56. import com.gcc.communityHall.repository.DamageRepository;
  57. import com.gcc.communityHall.repository.EbDetailsRepository;
  58. import com.gcc.communityHall.repository.GccBlockingDateRepository;
  59. import com.gcc.communityHall.repository.GccBlockingHistoryRepository;
  60. import com.gcc.communityHall.repository.GccblockingDocumentsRepo;
  61. import com.gcc.communityHall.repository.HallDetailsConcessionRepo;
  62. import com.gcc.communityHall.repository.HallDetailsRepository;
  63. import com.gcc.communityHall.repository.ReasonMasterRepository;
  64. import com.gcc.communityHall.repository.SettlementRepository;
  65. import com.gcc.communityHall.repository.UsersRepository;
  66. import com.gcc.communityHall.service.ApplicationLogService;
  67. import com.gcc.communityHall.service.BookingService;
  68. import com.gcc.communityHall.service.DiscountRangeService;
  69. import com.gcc.communityHall.service.HallDetailService;
  70. import com.gcc.communityHall.service.ReasonMasterService;
  71. import com.gcc.communityHall.service.UserService;
  72. @Service
  73. public class BookingServiceImpl implements BookingService {
  74. @Autowired
  75. private BookingDetailsRepository bookingDetailsRepository;
  76. @Autowired
  77. private BookingDocumentsRepository bookingDocumentsRepository;
  78. @Autowired
  79. private ReasonMasterService reasonMasterService;
  80. @Autowired
  81. private HallDetailService hallDetailService;
  82. @Autowired
  83. private UserService userService;
  84. @Autowired
  85. private UsersRepository userRepository;
  86. @Autowired
  87. private UserSession userSession;
  88. @Autowired
  89. private GccBlockingDateRepository gccBlockingDateRepository;
  90. @Autowired
  91. private BookingCalendarRepository bookingCalendarRepository;
  92. @Autowired
  93. private BookingHistoryRepository bookingHistoryRepository;
  94. @Autowired
  95. private EbDetailsRepository ebDetailsRepository;
  96. @Autowired
  97. private DamageRepository damageRepository;
  98. @Autowired
  99. private SettlementRepository settlementRepository;
  100. @Autowired
  101. private ApplicationLogService applicationLogService;
  102. @Autowired
  103. private PaymentGatewayService paymentGatewayService;
  104. @Autowired
  105. private GccBlockingDateRepository blockingDateRepository;
  106. @Autowired
  107. private DiscountRangeService discountRangeService;
  108. @Autowired
  109. private HallDetailsRepository hallDetailsRepository;
  110. @Autowired
  111. private GccBlockingHistoryRepository blockingHistoryRepository;
  112. @Autowired
  113. private WhatsappMsgServiceImpl whatsappMsgServiceImpl;
  114. @Autowired
  115. private GccblockingDocumentsRepo gccblockingDocumentsRepo;
  116. @Autowired
  117. private HttpSession session;
  118. @Autowired
  119. private HallDetailsConcessionRepo hallDetailsConcessionRepo;
  120. @Autowired
  121. private ReasonMasterRepository reasonMasterRepository;
  122. @Autowired
  123. private ApplicationLogsRepository applicationLogsRepository;
  124. @Autowired
  125. private TransactionResponseRepository transactionResponseRepository;
  126. @Autowired
  127. private TransRefundResRepository transRefundResRepository;
  128. @Value("${file.upload.directory}")
  129. private String uploadDirectory;
  130. @Value("${file.fullpath}")
  131. private String serverPath;
  132. private final PlatformTransactionManager transactionManager;
  133. public BookingServiceImpl(PlatformTransactionManager transactionManager) {
  134. this.transactionManager = transactionManager;
  135. }
  136. @Override
  137. public BookingDetails getBookingsById(int BookingId) {
  138. Optional<BookingDetails> OPBookingDetails = bookingDetailsRepository.findById(BookingId);
  139. if (OPBookingDetails.isPresent()) {
  140. return OPBookingDetails.get();
  141. }
  142. return null;
  143. }
  144. @Override
  145. public BookingDetails updateBookingDetails(BookingDetails bd) {
  146. return bookingDetailsRepository.save(bd);
  147. }
  148. @Override
  149. public BookingDetails updateBookingStatus(int bookingId, BookingDetails.BookingStatus status, String comments) {
  150. Optional<BookingDetails> booking = bookingDetailsRepository.findById(bookingId);
  151. if (booking.isPresent()) {
  152. BookingDetails book = booking.get();
  153. /*BookingHistory bookingHistory = new BookingHistory();
  154. bookingHistory.setBookingDetails(book);
  155. bookingHistory.setStartDate(book.getStartDate());
  156. bookingHistory.setEndDate(book.getEndDate());
  157. bookingHistory.setBookingStatus(book.getBookingStatus());
  158. bookingHistory.setComments(book.getComments());
  159. bookingHistory.setCdate(new Date());
  160. bookingHistory.setRefundStatus(book.getRefundStatus());
  161. System.out.println("bookingHistory.."+bookingHistory);
  162. bookingHistoryRepository.save(bookingHistory);*/
  163. book.setBookingStatus(status);
  164. book.setComments(comments);
  165. BookingDetails bookings = bookingDetailsRepository.save(book);
  166. return bookings;
  167. }
  168. return null;
  169. }
  170. @Override
  171. public String confirmTheDateAndSlot(String fromDate, String toDate, int days, int fromStartingSlot, int fromEndingSlot, int toStartingSlot, int toEndingSlot, int bookingId, int userId) {
  172. return null;
  173. }
  174. @Override
  175. @Transactional
  176. public String confirmBooking(int bookingId) {
  177. String exMsg = "Slot occupied";
  178. BookingDetails bookingDetails = null;
  179. try {
  180. Optional<BookingDetails> bookingDet = bookingDetailsRepository.findById(bookingId);
  181. if (!bookingDet.isPresent()) {
  182. // Handle invalid booking ID
  183. return "Invalid booking ID";
  184. }
  185. bookingDetails = bookingDet.get();
  186. // Validate booking details
  187. int hallId = bookingDetails.getHallDetails().getHallId();
  188. LocalDate startDate = LocalDate.parse(bookingDetails.getStartDate());
  189. LocalDate endDate = LocalDate.parse(bookingDetails.getEndDate());
  190. // Iterate through each date of the booking
  191. int i = 0;
  192. for (LocalDate date = startDate; !date.isAfter(endDate); date = date.plusDays(1)) {
  193. BookingCalendar bookingCalendar = bookingCalendarRepository.findByBdateAndHallId(date, hallId);
  194. if (bookingCalendar != null) {
  195. // System.out.println(bookingCalendar.toString());
  196. // System.out.println("date:-"+date );
  197. // System.out.println("bookingDetails.getEndingSlot() :- "+bookingDetails.getEndingSlot());
  198. //System.out.println("bookingCalendar.isMorningSlot():-"+bookingCalendar.isMorningSlot());
  199. //System.out.println(date.equals(endDate) && bookingDetails.getEndingSlot() == 1 && bookingCalendar.isMorningSlot());
  200. //System.out.println();
  201. // Check if the slot is already occupied
  202. if (bookingCalendar.getIs_blocked()) {
  203. throw new RuntimeException("GCC Blocked Date");
  204. } else if ((date.equals(startDate) && bookingDetails.getStartingSlot() == 1 && bookingCalendar.isMorningSlot()) ||
  205. (date.equals(startDate) && bookingDetails.getStartingSlot() == 2 && bookingCalendar.isEveningSlot()) ||
  206. (date.equals(endDate) && bookingDetails.getEndingSlot() == 1 && bookingCalendar.isMorningSlot()) ||
  207. (date.equals(endDate) && bookingDetails.getEndingSlot() == 2 && bookingCalendar.isEveningSlot())) {
  208. //System.out.println("booking slot occupied:- 218");
  209. throw new RuntimeException(exMsg);
  210. } else if (bookingCalendar.isMorningSlot() && bookingCalendar.isEveningSlot()) {
  211. //System.out.println("booking slot occupied:- 221");
  212. throw new RuntimeException(exMsg);
  213. } else if (!date.equals(endDate) && i != 0 && i != Math.round(bookingDetails.getNoOfDays() - 1)
  214. && (bookingCalendar.isMorningSlot() || bookingCalendar.isEveningSlot())) {
  215. //System.out.println("booking slot occupied:- 227 :-"+Math.round(bookingDetails.getNoOfDays()-1) );
  216. throw new RuntimeException(exMsg);
  217. } else if (date.equals(endDate) && bookingDetails.getEndingSlot() == 2 && bookingCalendar.isMorningSlot()
  218. && i != 0 && i == Math.round(bookingDetails.getNoOfDays() - 1)) {
  219. // System.out.println("booking slot occupied:- 240 :-"+Math.round(bookingDetails.getNoOfDays()-1) );
  220. throw new RuntimeException(exMsg);
  221. }
  222. } else {
  223. String uniqueId = date.format(DateTimeFormatter.ofPattern("yyyyMMdd")) + hallId;
  224. System.out.println("uniqueId....." + uniqueId);
  225. bookingCalendar = new BookingCalendar();
  226. bookingCalendar.setBdate(date);
  227. bookingCalendar.setHallId(hallId);
  228. bookingCalendar.setIs_booked(0);
  229. bookingCalendar.setIs_active(true);
  230. bookingCalendar.setUnique_id(uniqueId);
  231. }
  232. // Mark the appropriate slot as booked based on starting and ending slots
  233. if (date.equals(startDate)) {
  234. //System.out.println(i + "start :-"+bookingCalendar.toString());
  235. if (bookingDetails.getStartingSlot() == 1) {
  236. bookingCalendar.setMorningSlot(true);
  237. bookingCalendar.setBookingId_1(String.valueOf(bookingId));
  238. bookingCalendar.setIs_booked(bookingCalendar.getIs_booked() + 1);
  239. if (!date.equals(endDate)) {
  240. bookingCalendar.setEveningSlot(true);
  241. bookingCalendar.setBookingId_2(String.valueOf(bookingId));
  242. bookingCalendar.setIs_booked(bookingCalendar.getIs_booked() + 1);
  243. } else if (startDate.equals(endDate) && bookingDetails.getStartingSlot() == 1 && bookingDetails.getEndingSlot() == 2) {
  244. bookingCalendar.setEveningSlot(true);
  245. bookingCalendar.setBookingId_2(String.valueOf(bookingId));
  246. bookingCalendar.setIs_booked(bookingCalendar.getIs_booked() + 1);
  247. }
  248. } else {
  249. bookingCalendar.setEveningSlot(true);
  250. bookingCalendar.setBookingId_2(String.valueOf(bookingId));
  251. bookingCalendar.setIs_booked(bookingCalendar.getIs_booked() + 1);
  252. }
  253. } else if (date.equals(endDate)) {
  254. if (bookingDetails.getEndingSlot() == 1) {
  255. bookingCalendar.setMorningSlot(true);
  256. bookingCalendar.setBookingId_1(String.valueOf(bookingId));
  257. bookingCalendar.setIs_booked(bookingCalendar.getIs_booked() + 1);
  258. } else {
  259. bookingCalendar.setEveningSlot(true);
  260. bookingCalendar.setBookingId_2(String.valueOf(bookingId));
  261. bookingCalendar.setIs_booked(bookingCalendar.getIs_booked() + 1);
  262. if (bookingDetails.getEndingSlot() == 2) {
  263. bookingCalendar.setMorningSlot(true);
  264. bookingCalendar.setBookingId_1(String.valueOf(bookingId));
  265. bookingCalendar.setIs_booked(bookingCalendar.getIs_booked() + 1);
  266. }
  267. }
  268. } else {
  269. // For dates between start and end date, mark both slots as booked
  270. bookingCalendar.setMorningSlot(true);
  271. bookingCalendar.setEveningSlot(true);
  272. bookingCalendar.setBookingId_1(String.valueOf(bookingId));
  273. bookingCalendar.setBookingId_2(String.valueOf(bookingId));
  274. bookingCalendar.setIs_booked(bookingCalendar.getIs_booked() + 2);
  275. }
  276. // System.out.println(i + "end:-"+bookingCalendar.toString());
  277. bookingCalendarRepository.save(bookingCalendar);
  278. i++;
  279. }
  280. String statusMessage = processBookingStatusAndSendMessages(bookingDetails);
  281. return statusMessage;
  282. /*String reason = bookingDetails.getReason();
  283. ReasonMaster reasondetails = reasonMasterRepository.findByReason(reason);
  284. String reasoncode = reasondetails.getReasoncode();
  285. if (reasoncode == null) {
  286. reasoncode = ""; // or any default value
  287. }
  288. if (reasoncode.equals("CGE") || reasoncode.equals("CAO") || reasoncode.equals("SGE")) {
  289. updateBookingStatusById(bookingDetails.getBookingId(), BookingDetails.BookingStatus.WAITING_FOR_NOC, "Waiting For NOC Documents");
  290. String bookingconfirmationmsg = "Your booking ID " + bookingDetails.getBookingId() + " on " + bookingDetails.getBookingDate() + " has been confirmed successfully. Thanks for using GCC Community Hall Booking System.";
  291. String urlString = "https://tmegov.onex-aura.com/api/sms?key=pfTEYN6H&to=" + bookingDetails.getUsers().getMobileNo() + "&from=GCCCRP&body=" + bookingconfirmationmsg + "&entityid=1401572690000011081&templateid=1407172346459428987";
  292. String whatsupmsg = "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+" + bookingDetails.getBookingId() + "+on+" + bookingDetails.getBookingDate() + "+has+been+successfully+confirmed.+%0AThanks+for+using+GCC+Community+Hall+Booking+System.";
  293. whatsappMsgServiceImpl.sendMsg(whatsupmsg);
  294. whatsappMsgServiceImpl.sendSMS(urlString);
  295. return "Waiting For NOC Documents";
  296. } else {
  297. updateBookingStatusById(bookingDetails.getBookingId(), BookingDetails.BookingStatus.APPROVED, "Booking Confirmed Successfully");
  298. String bookingconfirmationmsg = "Your booking ID " + bookingDetails.getBookingId() + " on " + bookingDetails.getStartDate() + " has been confirmed successfully. Thanks for using GCC Community Hall Booking System.";
  299. String urlString = "https://tmegov.onex-aura.com/api/sms?key=pfTEYN6H&to=" + bookingDetails.getUsers().getMobileNo() + "&from=GCCCRP&body=" + bookingconfirmationmsg + "&entityid=1401572690000011081&templateid=1407172346459428987";
  300. String whatsupmsg = "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+" + bookingDetails.getBookingId() + "+on+" + bookingDetails.getStartDate() + "+has+been+successfully+confirmed.+%0AThanks+for+using+GCC+Community+Hall+Booking+System.";
  301. whatsappMsgServiceImpl.sendMsg(whatsupmsg);
  302. whatsappMsgServiceImpl.sendSMS(urlString);
  303. return "Booking confirmed successfully";
  304. }*/
  305. } catch (Exception e) {
  306. e.printStackTrace();
  307. bookingFailure(bookingDetails, 2);
  308. // System.out.println(bookingDetails.getBookingStatus()+","+bookingDetails.getRefundStatus()+","+bookingDetails.getComments());
  309. return "redirect:/communityhall/user/acknowledgement?bookingId=" + bookingDetails.getBookingId();
  310. }
  311. }
  312. @Transactional
  313. public String processBookingStatusAndSendMessages(BookingDetails bookingDetails) {
  314. try {
  315. String reason = bookingDetails.getReason();
  316. ReasonMaster reasonDetails = reasonMasterRepository.findByReason(reason);
  317. String reasonCode = (reasonDetails != null && reasonDetails.getReasoncode() != null) ? reasonDetails.getReasoncode() : "";
  318. String bookingconfirmationmsg, urlString, whatsupmsg;
  319. if (reasonCode.equals("CGE") || reasonCode.equals("CAO") || reasonCode.equals("SGE")) {
  320. updateBookingStatusById(bookingDetails.getBookingId(), BookingDetails.BookingStatus.WAITING_FOR_NOC, "Waiting For NOC Documents");
  321. bookingconfirmationmsg = "Your booking ID " + bookingDetails.getBookingId() + " on " + bookingDetails.getBookingDate() + " has been confirmed successfully. Thanks for using GCC Community Hall Booking System.";
  322. urlString = "https://tmegov.onex-aura.com/api/sms?key=pfTEYN6H&to=" + bookingDetails.getUsers().getMobileNo() +
  323. "&from=GCCCRP&body=" + bookingconfirmationmsg + "&entityid=1401572690000011081&templateid=1407172346459428987";
  324. whatsupmsg = "https://media.smsgupshup.com/GatewayAPI/rest?userid=2000233507&password=h2YjFNcJ&send_to=" +
  325. bookingDetails.getUsers().getMobileNo() +
  326. "&v=1.1&format=json&msg_type=TEXT&method=SENDMESSAGE&msg=Your+booking+with+ID+" +
  327. bookingDetails.getBookingId() + "+on+" + bookingDetails.getBookingDate() +
  328. "+has+been+successfully+confirmed.+%0AThanks+for+using+GCC+Community+Hall+Booking+System.";
  329. whatsappMsgServiceImpl.sendMsg(whatsupmsg);
  330. whatsappMsgServiceImpl.sendSMS(urlString);
  331. return "Waiting For NOC Documents";
  332. } else {
  333. updateBookingStatusById(bookingDetails.getBookingId(), BookingDetails.BookingStatus.APPROVED, "Booking Confirmed Successfully");
  334. bookingconfirmationmsg = "Your booking ID " + bookingDetails.getBookingId() + " on " + bookingDetails.getStartDate() + " has been confirmed successfully. Thanks for using GCC Community Hall Booking System.";
  335. urlString = "https://tmegov.onex-aura.com/api/sms?key=pfTEYN6H&to=" + bookingDetails.getUsers().getMobileNo() +
  336. "&from=GCCCRP&body=" + bookingconfirmationmsg + "&entityid=1401572690000011081&templateid=1407172346459428987";
  337. whatsupmsg = "https://media.smsgupshup.com/GatewayAPI/rest?userid=2000233507&password=h2YjFNcJ&send_to=" +
  338. bookingDetails.getUsers().getMobileNo() +
  339. "&v=1.1&format=json&msg_type=TEXT&method=SENDMESSAGE&msg=Your+booking+with+ID+" +
  340. bookingDetails.getBookingId() + "+on+" + bookingDetails.getStartDate() +
  341. "+has+been+successfully+confirmed.+%0AThanks+for+using+GCC+Community+Hall+Booking+System.";
  342. whatsappMsgServiceImpl.sendMsg(whatsupmsg);
  343. whatsappMsgServiceImpl.sendSMS(urlString);
  344. return "Booking confirmed successfully";
  345. }
  346. } catch (Exception e) {
  347. e.printStackTrace();
  348. return "error";
  349. }
  350. }
  351. @Override
  352. @Transactional
  353. public String confirmStateBooking(int bookingId) {
  354. String exMsg = "Slot occupied";
  355. BookingDetails bookingDetails = null;
  356. try {
  357. Optional<BookingDetails> bookingDet = bookingDetailsRepository.findById(bookingId);
  358. if (!bookingDet.isPresent()) {
  359. // Handle invalid booking ID
  360. return "Invalid booking ID";
  361. }
  362. bookingDetails = bookingDet.get();
  363. // Validate booking details
  364. int hallId = bookingDetails.getHallDetails().getHallId();
  365. LocalDate startDate = LocalDate.parse(bookingDetails.getStartDate());
  366. LocalDate endDate = LocalDate.parse(bookingDetails.getEndDate());
  367. // Iterate through each date of the booking
  368. int i = 0;
  369. for (LocalDate date = startDate; !date.isAfter(endDate); date = date.plusDays(1)) {
  370. BookingCalendar bookingCalendar = bookingCalendarRepository.findByBdateAndHallId(date, hallId);
  371. if (bookingCalendar != null) {
  372. // System.out.println(bookingCalendar.toString());
  373. // System.out.println("date:-"+date );
  374. // System.out.println("bookingDetails.getEndingSlot() :- "+bookingDetails.getEndingSlot());
  375. //System.out.println("bookingCalendar.isMorningSlot():-"+bookingCalendar.isMorningSlot());
  376. //System.out.println(date.equals(endDate) && bookingDetails.getEndingSlot() == 1 && bookingCalendar.isMorningSlot());
  377. //System.out.println();
  378. // Check if the slot is already occupied
  379. if ((date.equals(startDate) && bookingDetails.getStartingSlot() == 1 && bookingCalendar.isMorningSlot()) ||
  380. (date.equals(startDate) && bookingDetails.getStartingSlot() == 2 && bookingCalendar.isEveningSlot()) ||
  381. (date.equals(endDate) && bookingDetails.getEndingSlot() == 1 && bookingCalendar.isMorningSlot()) ||
  382. (date.equals(endDate) && bookingDetails.getEndingSlot() == 2 && bookingCalendar.isEveningSlot())) {
  383. //System.out.println("booking slot occupied:- 218");
  384. throw new RuntimeException(exMsg);
  385. } else if (bookingCalendar.isMorningSlot() && bookingCalendar.isEveningSlot()) {
  386. //System.out.println("booking slot occupied:- 221");
  387. throw new RuntimeException(exMsg);
  388. } else if (!date.equals(endDate) && i != 0 && i != Math.round(bookingDetails.getNoOfDays() - 1)
  389. && (bookingCalendar.isMorningSlot() || bookingCalendar.isEveningSlot())) {
  390. //System.out.println("booking slot occupied:- 227 :-"+Math.round(bookingDetails.getNoOfDays()-1) );
  391. throw new RuntimeException(exMsg);
  392. } else if (date.equals(endDate) && bookingDetails.getEndingSlot() == 2 && bookingCalendar.isMorningSlot()
  393. && i != 0 && i == Math.round(bookingDetails.getNoOfDays() - 1)) {
  394. // System.out.println("booking slot occupied:- 240 :-"+Math.round(bookingDetails.getNoOfDays()-1) );
  395. throw new RuntimeException(exMsg);
  396. }
  397. } else {
  398. bookingCalendar = new BookingCalendar();
  399. bookingCalendar.setBdate(date);
  400. bookingCalendar.setHallId(hallId);
  401. bookingCalendar.setIs_booked(0);
  402. bookingCalendar.setIs_active(true);
  403. }
  404. // Mark the appropriate slot as booked based on starting and ending slots
  405. if (date.equals(startDate)) {
  406. //System.out.println(i + "start :-"+bookingCalendar.toString());
  407. if (bookingDetails.getStartingSlot() == 1) {
  408. bookingCalendar.setMorningSlot(true);
  409. bookingCalendar.setBookingId_1(String.valueOf(bookingId));
  410. bookingCalendar.setIs_booked(bookingCalendar.getIs_booked() + 1);
  411. if (!date.equals(endDate)) {
  412. bookingCalendar.setEveningSlot(true);
  413. bookingCalendar.setBookingId_2(String.valueOf(bookingId));
  414. bookingCalendar.setIs_booked(bookingCalendar.getIs_booked() + 1);
  415. } else if (startDate.equals(endDate) && bookingDetails.getStartingSlot() == 1 && bookingDetails.getEndingSlot() == 2) {
  416. bookingCalendar.setEveningSlot(true);
  417. bookingCalendar.setBookingId_2(String.valueOf(bookingId));
  418. bookingCalendar.setIs_booked(bookingCalendar.getIs_booked() + 1);
  419. }
  420. } else {
  421. bookingCalendar.setEveningSlot(true);
  422. bookingCalendar.setBookingId_2(String.valueOf(bookingId));
  423. bookingCalendar.setIs_booked(bookingCalendar.getIs_booked() + 1);
  424. }
  425. } else if (date.equals(endDate)) {
  426. if (bookingDetails.getEndingSlot() == 1) {
  427. bookingCalendar.setMorningSlot(true);
  428. bookingCalendar.setBookingId_1(String.valueOf(bookingId));
  429. bookingCalendar.setIs_booked(bookingCalendar.getIs_booked() + 1);
  430. } else {
  431. bookingCalendar.setEveningSlot(true);
  432. bookingCalendar.setBookingId_2(String.valueOf(bookingId));
  433. bookingCalendar.setIs_booked(bookingCalendar.getIs_booked() + 1);
  434. if (bookingDetails.getEndingSlot() == 2) {
  435. bookingCalendar.setMorningSlot(true);
  436. bookingCalendar.setBookingId_1(String.valueOf(bookingId));
  437. bookingCalendar.setIs_booked(bookingCalendar.getIs_booked() + 1);
  438. }
  439. }
  440. } else {
  441. // For dates between start and end date, mark both slots as booked
  442. bookingCalendar.setMorningSlot(true);
  443. bookingCalendar.setEveningSlot(true);
  444. bookingCalendar.setBookingId_1(String.valueOf(bookingId));
  445. bookingCalendar.setBookingId_2(String.valueOf(bookingId));
  446. bookingCalendar.setIs_booked(bookingCalendar.getIs_booked() + 2);
  447. }
  448. // System.out.println(i + "end:-"+bookingCalendar.toString());
  449. bookingCalendarRepository.save(bookingCalendar);
  450. i++;
  451. }
  452. updateBookingStatusById(bookingDetails.getBookingId(), BookingDetails.BookingStatus.WAITING_FOR_NOC, "Waiting for NOC Documents");
  453. String bookingconfirmationmsg = "Your booking ID " + bookingDetails.getBookingId() + " on " + bookingDetails.getBookingDate() + " has been confirmed successfully. Thanks for using GCC Community Hall Booking System.";
  454. String urlString = "https://tmegov.onex-aura.com/api/sms?key=pfTEYN6H&to=" + bookingDetails.getUsers().getMobileNo() + "&from=GCCCRP&body=" + bookingconfirmationmsg + "&entityid=1401572690000011081&templateid=1407172346459428987";
  455. String whatsupmsg = "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+" + bookingDetails.getBookingId() + "+on+" + bookingDetails.getBookingDate() + "+has+been+successfully+confirmed.+%0AThanks+for+using+GCC+Community+Hall+Booking+System.";
  456. whatsappMsgServiceImpl.sendMsg(whatsupmsg);
  457. whatsappMsgServiceImpl.sendSMS(urlString);
  458. return "redirect:/communityhall/user/acknowledgement?bookingId=" + bookingDetails.getBookingId();
  459. } catch (Exception e) {
  460. bookingFailure(bookingDetails, 2);
  461. // System.out.println(bookingDetails.getBookingStatus()+","+bookingDetails.getRefundStatus()+","+bookingDetails.getComments());
  462. return "redirect:/communityhall/user/acknowledgement?bookingId=" + bookingDetails.getBookingId();
  463. }
  464. }
  465. /*@Transactional(propagation = Propagation.REQUIRES_NEW)
  466. public String bookingFailure(BookingDetails bookingDetails) {
  467. // System.out.println("Booking Failure:-"+bookingDetails.getBookingId());
  468. bookingDetails.setBookingStatus(BookingStatus.REFUNDED);
  469. bookingDetails.setComments("Slot occupied by other user,Amount paid will be refunded.");
  470. bookingDetailsRepository.save(bookingDetails);
  471. if (!(bookingDetails.getRefundStatus() == RefundStatus.COMPLETED) && !(bookingDetails.getRefundStatus() == RefundStatus.CLOSED)) {
  472. // BookingDetails bd =updateBookingStatusById(bookingDetails.getBookingId(), BookingDetails.BookingStatus.REFUNDED, "slot occupied Refund will happen shortly");
  473. applicationLogService.saveLog(bookingDetails.getBookingId(), ApplicationLogs.logsOfMsg.REFUNDED.toString(), "Refund will happen shortly");
  474. try {
  475. String refundedMsg = paymentGatewayService.refundTheAmount(bookingDetails.getBookingId(), bookingDetails.getUsers().getUserId());
  476. //System.out.println("refundedMsg=="+refundedMsg);
  477. if (refundedMsg.equals("Refunded")) {
  478. //System.out.println("Refund completed........");
  479. bookingDetails.setRefundStatus(BookingDetails.RefundStatus.COMPLETED);
  480. bookingDetailsRepository.save(bookingDetails);
  481. //System.out.println("refundStatus===="+bookingDetails.getRefundStatus());
  482. long mobile = bookingDetails.getUsers().getMobileNo();
  483. int bookingId = bookingDetails.getBookingId();
  484. double refundAmt = bookingDetails.getAmountReceived();
  485. // Thread thread = new Thread(() -> {
  486. String settlementrefundsms = "Your refund amount of Rs. " + refundAmt + " for Booking ID " + bookingId + " has been initiated. The amount will be credited to your account within 3 to 15 days. Thanks for using the GCC Community Hall Booking System.";
  487. String settlementrefundurlString = "https://tmegov.onex-aura.com/api/sms?key=pfTEYN6H&to=" + mobile + "&from=GCCCRP&body=" + settlementrefundsms + "&entityid=1401572690000011081&templateid=1407172346804951524";
  488. String settlementrefundwhatsupmsg = "https://media.smsgupshup.com/GatewayAPI/rest?userid=2000233507&password=h2YjFNcJ&send_to=" + mobile + "&v=1.1&format=json&msg_type=TEXT&method=SENDMESSAGE&msg=Your+refund+of+Rs.+" + refundAmt + "+for+Booking+ID+" + bookingId + "+has+been+initiated.+%0AThe+amount+will+be+credited+to+your+account+within+3+to+15+days.";
  489. whatsappMsgServiceImpl.sendMsg(settlementrefundwhatsupmsg);
  490. whatsappMsgServiceImpl.sendSMS(settlementrefundurlString);
  491. // });
  492. // thread.start();
  493. return "Success";
  494. }
  495. } catch (Exception e) {
  496. applicationLogService.saveLog(bookingDetails.getBookingId(), ApplicationLogs.logsOfMsg.ERROR.toString(), "Refund Error");
  497. return "error";
  498. }
  499. }
  500. return "error";
  501. }*/
  502. @Transactional(propagation = Propagation.REQUIRES_NEW)
  503. public String bookingFailure(BookingDetails bookingDetails, int flag) {
  504. // System.out.println("Booking Failure:-"+bookingDetails.getBookingId());
  505. bookingDetails.setBookingStatus(BookingStatus.REFUNDED);
  506. if (flag == 1) {
  507. bookingDetails.setComments("Booking Not Confirmed");
  508. } else {
  509. bookingDetails.setComments("Slot occupied by other user,Amount paid will be refunded.");
  510. }
  511. bookingDetailsRepository.save(bookingDetails);
  512. if (!(bookingDetails.getRefundStatus() == RefundStatus.COMPLETED) && !(bookingDetails.getRefundStatus() == RefundStatus.CLOSED)) {
  513. // BookingDetails bd =updateBookingStatusById(bookingDetails.getBookingId(), BookingDetails.BookingStatus.REFUNDED, "slot occupied Refund will happen shortly");
  514. applicationLogService.saveLog(bookingDetails.getBookingId(), ApplicationLogs.logsOfMsg.REFUNDED.toString(), "Refund will happen shortly");
  515. try {
  516. String refundedMsg = paymentGatewayService.refundTheAmount(bookingDetails.getBookingId(), bookingDetails.getUsers().getUserId());
  517. //System.out.println("refundedMsg=="+refundedMsg);
  518. if (refundedMsg.equals("Refunded")) {
  519. //System.out.println("Refund completed........");
  520. bookingDetails.setRefundStatus(BookingDetails.RefundStatus.COMPLETED);
  521. bookingDetailsRepository.save(bookingDetails);
  522. //System.out.println("refundStatus===="+bookingDetails.getRefundStatus());
  523. long mobile = bookingDetails.getUsers().getMobileNo();
  524. int bookingId = bookingDetails.getBookingId();
  525. double refundAmt = bookingDetails.getAmountReceived();
  526. // Thread thread = new Thread(() -> {
  527. String settlementrefundsms = "Your refund amount of Rs. " + refundAmt + " for Booking ID " + bookingId + " has been initiated. The amount will be credited to your account within 3 to 15 days. Thanks for using the GCC Community Hall Booking System.";
  528. String settlementrefundurlString = "https://tmegov.onex-aura.com/api/sms?key=pfTEYN6H&to=" + mobile + "&from=GCCCRP&body=" + settlementrefundsms + "&entityid=1401572690000011081&templateid=1407172346804951524";
  529. String settlementrefundwhatsupmsg = "https://media.smsgupshup.com/GatewayAPI/rest?userid=2000233507&password=h2YjFNcJ&send_to=" + mobile + "&v=1.1&format=json&msg_type=TEXT&method=SENDMESSAGE&msg=Your+refund+of+Rs.+" + refundAmt + "+for+Booking+ID+" + bookingId + "+has+been+initiated.+%0AThe+amount+will+be+credited+to+your+account+within+3+to+15+days.";
  530. whatsappMsgServiceImpl.sendMsg(settlementrefundwhatsupmsg);
  531. whatsappMsgServiceImpl.sendSMS(settlementrefundurlString);
  532. // });
  533. // thread.start();
  534. return "Success";
  535. }
  536. } catch (Exception e) {
  537. applicationLogService.saveLog(bookingDetails.getBookingId(), ApplicationLogs.logsOfMsg.ERROR.toString(), "Refund Error");
  538. return "error";
  539. }
  540. }
  541. return "error";
  542. }
  543. @Override
  544. public Map<String, Object> saveBookingDetails(Map<String, Object> formData) {
  545. Map<String, Object> hs = new HashMap<>();
  546. BookingDetails bookingDetails = null;
  547. Integer userId = userSession.getUserId();
  548. String counterId = userSession.getCounter();
  549. ReasonMaster reasonMaster = reasonMasterService.getReasonById(Integer.parseInt(formData.get("reasonId").toString()));
  550. HallDetails hallDetails = hallDetailService.getHallById(Integer.parseInt(formData.get("hallId").toString()));
  551. Users user = userService.getUserById(userId);
  552. String bookingId = formData.get("bookingId").toString();
  553. if (bookingId != null && bookingId.equals("0")) {
  554. bookingDetails = new BookingDetails();
  555. } else {
  556. BookingDetails book = getBookingsById(Integer.parseInt(formData.get("bookingId").toString()));
  557. if (book != null) {
  558. bookingDetails = book;
  559. bookingDocumentsRepository.deleteByBookingId(book.getBookingId());
  560. } else {
  561. bookingDetails = new BookingDetails();
  562. }
  563. }
  564. if (user != null) {
  565. bookingDetails.setUsers(user);
  566. if (counterId != null) {
  567. bookingDetails.setCounterId(counterId);
  568. }
  569. if (hallDetails != null) {
  570. bookingDetails.setHallDetails(hallDetails);
  571. String startDate = formData.get("startDate").toString();
  572. String endDate = formData.get("endDate").toString();
  573. String relation = formData.get("relation").toString();
  574. double days = Double.parseDouble(formData.get("days").toString());
  575. int daysrange = Integer.parseInt(formData.get("daysrange").toString());
  576. Optional<DiscountRange> discountOpt = discountRangeService.getDiscountByUserType(user.getUsertype());
  577. DiscountRange discountrange = discountOpt.get();
  578. float discount = discountrange.getDiscountRange();
  579. int startingSlot = Integer.parseInt(formData.get("startingSlot").toString());
  580. int endingSlot = Integer.parseInt(formData.get("endingSlot").toString());
  581. double hallAmount = calcHallAmount(hallDetails, daysrange, startingSlot, endingSlot);
  582. hs.put("actualhallamount", hallAmount);
  583. double discountAmount = 0;
  584. String usertype = user.getUsertype().toString();
  585. String reason = reasonMaster.getReason();
  586. //double depositeamount = hallDetails.getDepositAmount() * daysrange;
  587. double depositeamount = hallDetails.getDepositAmount() * Math.ceil(days);
  588. // Calculate discount based on user type
  589. if (usertype.equals("COUNCILLOR") || usertype.equals("PENSIONER") || usertype.equals("GCC_EMPLOYEE") || usertype.equals("PUBLIC")) {
  590. discountAmount = (hallAmount * discount) / 100;
  591. hallAmount = hallAmount - discountAmount;
  592. double gstAmount = Math.round(hallAmount * hallDetails.getGst()) / 100.0;
  593. double totalAmount = hallAmount + gstAmount + depositeamount;
  594. // Truncate the total amount to two decimal places
  595. double truncatedTotalAmount = Math.round(totalAmount * 100.0) / 100.0;
  596. // Set the calculated amounts to bookingDetails
  597. bookingDetails.setDepositAmount(depositeamount);
  598. bookingDetails.setHallAmount(hallAmount);
  599. bookingDetails.setGst(gstAmount);
  600. bookingDetails.setAmountReceived(truncatedTotalAmount);
  601. bookingDetails.setAmountReceived(truncatedTotalAmount);
  602. hs.put("totalAmount", truncatedTotalAmount);
  603. }
  604. // Calculate final hall amount after applying the discount
  605. hs.put("discount", discountrange.getDiscountRange());
  606. // Handle discount or hall amount adjustments based on the event reason
  607. String reasoncode = reasonMaster.getReasoncode();
  608. if (reasoncode == null) {
  609. reasoncode = ""; // or any default value
  610. }
  611. hs.put("reasoncode", reasoncode);
  612. HallDetailsConcession governmentevents = hallDetailsConcessionRepo.findbyhallId(hallDetails.getHallId());
  613. if (reasoncode.equals("SGE")) {
  614. if (startingSlot == 1 && endingSlot == 2) {
  615. discountAmount = (governmentevents.getFulldayhallamount() * hallDetails.getSGEdiscount()) / 100;
  616. hallAmount = governmentevents.getFulldayhallamount();
  617. hs.put("discount", hallDetails.getSGEdiscount()); // No discount for State Govt Event
  618. double cleaningCharges = governmentevents.getFullDayCleaningcharges();
  619. double PASystem = governmentevents.getFulldayPAsystem();
  620. double EB = governmentevents.getFulldayEBcharges();
  621. double additionalcharges = cleaningCharges + PASystem + EB;
  622. double gstAmount = Math.round(additionalcharges * hallDetails.getGst()) / 100.0;
  623. double depositAmount = hallDetails.getDepositAmount() * daysrange;
  624. double totalAmount = additionalcharges + gstAmount + depositAmount;
  625. double truncatedTotalAmount = Math.round(totalAmount * 100.0) / 100.0;
  626. hs.put("actualhallamount", hallAmount);
  627. bookingDetails.setDepositAmount(depositeamount);
  628. bookingDetails.setHallAmount(additionalcharges);
  629. bookingDetails.setGst(gstAmount);
  630. bookingDetails.setAmountReceived(truncatedTotalAmount);
  631. hs.put("additionalcharges", additionalcharges);
  632. hs.put("totalAmount", truncatedTotalAmount);
  633. } else {
  634. hallAmount = governmentevents.getHalfdayhallamount();
  635. discountAmount = (hallAmount * hallDetails.getSGEdiscount()) / 100;
  636. hs.put("discount", hallDetails.getSGEdiscount()); // No discount for State Govt Event
  637. double cleaningCharges = governmentevents.getHalfDayCleaningcharges();
  638. double PASystem = governmentevents.getHalfdayPAsystem();
  639. double EB = governmentevents.getHalfdayEBcharges();
  640. double additionalcharges = cleaningCharges + PASystem + EB;
  641. double gstAmount = Math.round(additionalcharges * hallDetails.getGst()) / 100.0;
  642. double depositAmount = hallDetails.getDepositAmount() * daysrange;
  643. double totalAmount = additionalcharges + gstAmount + depositAmount;
  644. double truncatedTotalAmount = Math.round(totalAmount * 100.0) / 100.0;
  645. hs.put("actualhallamount", hallAmount);
  646. bookingDetails.setDepositAmount(depositeamount);
  647. bookingDetails.setHallAmount(additionalcharges);
  648. bookingDetails.setGst(gstAmount);
  649. bookingDetails.setAmountReceived(truncatedTotalAmount);
  650. hs.put("additionalcharges", additionalcharges);
  651. hs.put("totalAmount", truncatedTotalAmount);
  652. }
  653. } /*else if (reasoncode.equals("CGE")) {
  654. double hallAmountforcentral = calcHallAmount(hallDetails, daysrange, startingSlot, endingSlot);
  655. double discountAmounts = (hallAmountforcentral * hallDetails.getCGEdiscount()) / 100;
  656. hs.put("discount", hallDetails.getCGEdiscount()); // 50% discount for Central Govt Event
  657. hallAmountforcentral = hallAmountforcentral - discountAmounts;
  658. // Calculate GST and total amount
  659. double gstAmount = Math.round(hallAmountforcentral * hallDetails.getGst()) / 100.0;
  660. double totalAmount = hallAmountforcentral + gstAmount + depositeamount;
  661. // Truncate the total amount to two decimal places
  662. //double truncatedTotalAmount = Math.floor(totalAmount * 100) / 100;
  663. // Round the total amount to two decimal places
  664. double truncatedTotalAmount = Math.round(totalAmount * 100.0) / 100.0;
  665. // Set the calculated amounts to bookingDetails
  666. bookingDetails.setDepositAmount(depositeamount);
  667. bookingDetails.setHallAmount(hallAmountforcentral);
  668. bookingDetails.setGst(gstAmount);
  669. bookingDetails.setAmountReceived(truncatedTotalAmount);
  670. hs.put("totalAmount", truncatedTotalAmount);
  671. }*/ else if (reasoncode.equals("CGE")) {
  672. if (startingSlot == 1 && endingSlot == 2) {
  673. discountAmount = (hallDetails.getFullDayRent() * hallDetails.getCGEdiscount()) / 100;
  674. hallAmount = hallDetails.getFullDayRent();
  675. hs.put("discount", hallDetails.getCGEdiscount()); // No discount for State Govt Event
  676. double cleaningCharges = governmentevents.getFullDayCleaningcharges();
  677. double PASystem = governmentevents.getFulldayPAsystem();
  678. double EB = governmentevents.getFulldayEBcharges();
  679. double additionalcharges = cleaningCharges + PASystem + EB;
  680. double rentAmount = discountAmount;
  681. double netAmount = rentAmount + additionalcharges;
  682. double gstAmount = Math.round(netAmount * hallDetails.getGst()) / 100.0;
  683. double depositAmount = hallDetails.getDepositAmount() * daysrange;
  684. double totalAmount = netAmount + gstAmount + depositAmount;
  685. double truncatedTotalAmount = Math.round(totalAmount * 100.0) / 100.0;
  686. hs.put("actualhallamount", hallAmount);
  687. bookingDetails.setDepositAmount(depositeamount);
  688. //bookingDetails.setHallAmount(additionalcharges);
  689. bookingDetails.setHallAmount(netAmount);
  690. bookingDetails.setGst(gstAmount);
  691. bookingDetails.setAmountReceived(truncatedTotalAmount);
  692. hs.put("rentAmount", rentAmount);
  693. hs.put("gstAmount", gstAmount);
  694. hs.put("netAmount", netAmount);
  695. hs.put("additionalcharges", additionalcharges);
  696. hs.put("totalAmount", truncatedTotalAmount);
  697. } else {
  698. discountAmount = (hallDetails.getHalfDayRent() * hallDetails.getCGEdiscount()) / 100;
  699. hallAmount = hallDetails.getHalfDayRent();
  700. hs.put("discount", hallDetails.getCGEdiscount()); // No discount for State Govt Event
  701. double cleaningCharges = governmentevents.getHalfDayCleaningcharges();
  702. double PASystem = governmentevents.getHalfdayPAsystem();
  703. double EB = governmentevents.getHalfdayEBcharges();
  704. double additionalcharges = cleaningCharges + PASystem + EB;
  705. double rentAmount = discountAmount;
  706. double netAmount = rentAmount + additionalcharges;
  707. double gstAmount = Math.round(netAmount * hallDetails.getGst()) / 100.0;
  708. double depositAmount = hallDetails.getDepositAmount() * daysrange;
  709. double totalAmount = netAmount + gstAmount + depositAmount;
  710. double truncatedTotalAmount = Math.round(totalAmount * 100.0) / 100.0;
  711. hs.put("actualhallamount", hallAmount);
  712. bookingDetails.setDepositAmount(depositeamount);
  713. //bookingDetails.setHallAmount(additionalcharges);
  714. bookingDetails.setHallAmount(netAmount);
  715. bookingDetails.setGst(gstAmount);
  716. bookingDetails.setAmountReceived(truncatedTotalAmount);
  717. hs.put("rentAmount", rentAmount);
  718. hs.put("gstAmount", gstAmount);
  719. hs.put("netAmount", netAmount);
  720. hs.put("additionalcharges", additionalcharges);
  721. hs.put("totalAmount", truncatedTotalAmount);
  722. }
  723. }
  724. bookingDetails.setNoOfDays(days);
  725. bookingDetails.setStartingSlot(startingSlot);
  726. bookingDetails.setEndingSlot(endingSlot);
  727. bookingDetails.setStartDate(startDate);
  728. bookingDetails.setEndDate(endDate);
  729. bookingDetails.setBookingDate(LocalDate.now());
  730. bookingDetails.setReason(reasonMaster.getReason());
  731. bookingDetails.setRefundStatus(BookingDetails.RefundStatus.WAITING);
  732. bookingDetails.setComments("Booking Slot not Confirmed.");
  733. bookingDetails.setBookingtype(BookingDetails.BookingType.ONLINE);
  734. bookingDetails.setRelationship(relation);
  735. int i = 0;
  736. String startDateStr = bookingDetails.getStartDate();
  737. String endDateStr = bookingDetails.getEndDate();
  738. DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
  739. LocalDate start = LocalDate.parse(startDateStr, formatter);
  740. LocalDate end = LocalDate.parse(endDateStr, formatter);
  741. int hallId = bookingDetails.getHallDetails().getHallId();
  742. for (LocalDate date = start; !date.isAfter(end); date = date.plusDays(1)) {
  743. BookingCalendar bookingCalendar = bookingCalendarRepository.findByBdateAndHallId(date, hallId);
  744. if (bookingCalendar != null) {
  745. if ((date.equals(start) && bookingDetails.getStartingSlot() == 1 && bookingCalendar.isMorningSlot()) ||
  746. (date.equals(start) && bookingDetails.getStartingSlot() == 2 && bookingCalendar.isEveningSlot()) ||
  747. (date.equals(end) && bookingDetails.getEndingSlot() == 1 && bookingCalendar.isMorningSlot()) ||
  748. (date.equals(end) && bookingDetails.getEndingSlot() == 2 && bookingCalendar.isEveningSlot())) {
  749. return Collections.singletonMap("status", "slotOccupied");
  750. } else if (bookingCalendar.isMorningSlot() && bookingCalendar.isEveningSlot()) {
  751. return Collections.singletonMap("status", "slotOccupied");
  752. } else if (!date.equals(end) && i != 0 && i != Math.round(bookingDetails.getNoOfDays() - 1)
  753. && (bookingCalendar.isMorningSlot() || bookingCalendar.isEveningSlot())) {
  754. return Collections.singletonMap("status", "slotOccupied");
  755. } else if (date.equals(end) && bookingDetails.getEndingSlot() == 2 && bookingCalendar.isMorningSlot()
  756. && i != 0 && i == Math.round(bookingDetails.getNoOfDays() - 1)) {
  757. return Collections.singletonMap("status", "slotOccupied");
  758. }
  759. }
  760. i++;
  761. }
  762. // Save the booking details after the loop
  763. bookingDetails = bookingDetailsRepository.save(bookingDetails);
  764. // confirmation of amount
  765. hs.put("bookingId", bookingDetails.getBookingId());
  766. hs.put("hallName", bookingDetails.getHallDetails().getHallName());
  767. hs.put("NoOfDay", bookingDetails.getNoOfDays());
  768. hs.put("startDate", bookingDetails.getStartDate());
  769. hs.put("endDate", bookingDetails.getEndDate());
  770. hs.put("startingSlot", bookingDetails.getStartingSlot());
  771. hs.put("endingSlot", bookingDetails.getEndingSlot());
  772. hs.put("hallAmount", bookingDetails.getHallAmount());
  773. hs.put("gst", bookingDetails.getGst());
  774. hs.put("depositAmount", depositeamount);
  775. hs.put("username", bookingDetails.getUsers().getName());
  776. hs.put("userId", bookingDetails.getUsers().getUserId());
  777. hs.put("mobileNo", bookingDetails.getUsers().getMobileNo());
  778. hs.put("userType", bookingDetails.getUsers().getUsertype());
  779. hs.put("reason", bookingDetails.getReason());
  780. }
  781. if (reasonMaster != null) {
  782. List<ReasonDocumentMaster> reasonDocMaster = reasonMaster.getReasonDocumentMasterList();
  783. List<BookingDocuments> uploadedDocs = new ArrayList<>();
  784. for (ReasonDocumentMaster rm : reasonDocMaster) {
  785. BookingDocuments bd = new BookingDocuments();
  786. bd.setBookingDetails(bookingDetails);
  787. if (rm.isAddTextField()) {
  788. bd.setName(formData.get(rm.getFieldName()).toString());
  789. bd.setBooking_label(rm.getFieldName());
  790. }
  791. if (rm.isAddDocumentField()) {
  792. MultipartFile file = (MultipartFile) formData.get(rm.getDocFieldName());
  793. bd.setBookingDocUrl(serverPath + "images/" + reasonMaster.getReason() + "/" + bookingDetails.getBookingId() + "_" + file.getOriginalFilename());
  794. String filePath = uploadDirectory + "/" + reasonMaster.getReason() + "/" + bookingDetails.getBookingId() + "_" + file.getOriginalFilename();
  795. bd.setDocumentName(file.getOriginalFilename());
  796. bd.setDocumentType(file.getContentType());
  797. try (FileOutputStream fos = new FileOutputStream(filePath)) {
  798. byte[] bytes = file.getBytes();
  799. fos.write(bytes);
  800. } catch (Exception e) {
  801. throw new RuntimeException(e);
  802. }
  803. bookingDocumentsRepository.save(bd);
  804. uploadedDocs.add(bd);
  805. }
  806. }
  807. hs.put("uploadedDocs", uploadedDocs);
  808. }
  809. }
  810. return hs;
  811. }
  812. private double calcHallAmount(HallDetails hallDetails, int daysrange, int startPeriod, int endPeriod) {
  813. double hallAmount = 0;
  814. if (daysrange == 1) {
  815. if (startPeriod == 1 && endPeriod == 2) {
  816. hallAmount = hallDetails.getFullDayRent();
  817. } else if (startPeriod == 1 && endPeriod == 1) {
  818. hallAmount = hallDetails.getHalfDayRent();
  819. } else if (startPeriod == 2 && endPeriod == 2) {
  820. hallAmount = hallDetails.getHalfDayRent();
  821. } else if (startPeriod == 2 && endPeriod == 1) {
  822. hallAmount = hallDetails.getFullDayRent();
  823. }
  824. } else {
  825. // For multiple days
  826. if (startPeriod == 1 && endPeriod == 2) {
  827. hallAmount = hallDetails.getFullDayRent() * daysrange;
  828. } else if (startPeriod == 1 && endPeriod == 1) {
  829. hallAmount = hallDetails.getFullDayRent() * (daysrange - 1) + hallDetails.getHalfDayRent();
  830. } else if (startPeriod == 2 && endPeriod == 2) {
  831. hallAmount = hallDetails.getFullDayRent() * (daysrange - 1) + hallDetails.getHalfDayRent();
  832. } else if (startPeriod == 2 && endPeriod == 1) {
  833. hallAmount = hallDetails.getFullDayRent() * (daysrange - 2) + hallDetails.getHalfDayRent() * 2;
  834. }
  835. }
  836. return hallAmount;
  837. }
  838. public String uploadNOCFile(MultipartFile file, int bookingId) {
  839. // Retrieve booking details, throw an exception if not found
  840. BookingDetails bookingDetails = bookingDetailsRepository.findById(bookingId)
  841. .orElseThrow(() -> new IllegalArgumentException("Invalid booking ID: " + bookingId));
  842. String reason = "NOC";
  843. String fileName = bookingId + "_" + file.getOriginalFilename();
  844. String fileUrl = serverPath + "images/" + reason + "/" + fileName;
  845. String filePath = uploadDirectory + File.separator + reason + File.separator + fileName;
  846. // Ensure the directory exists
  847. File directory = new File(uploadDirectory + File.separator + reason);
  848. if (!directory.exists()) {
  849. directory.mkdirs(); // Create the directory if it doesn't exist
  850. }
  851. BookingHistory bookinghistory = new BookingHistory();
  852. bookinghistory.setBookingStatus(bookingDetails.getBookingStatus());
  853. bookinghistory.setBookingDetails(bookingDetails);
  854. bookinghistory.setStartDate(bookingDetails.getStartDate());
  855. bookinghistory.setEndDate(bookingDetails.getEndDate());
  856. bookinghistory.setComments(bookingDetails.getComments());
  857. bookinghistory.setCdate(new Date());
  858. bookinghistory.setRefundStatus(bookingDetails.getRefundStatus());
  859. bookingHistoryRepository.save(bookinghistory);
  860. BookingDocuments bd = new BookingDocuments();
  861. bd.setBookingDocUrl(fileUrl);
  862. bd.setDocumentName(file.getOriginalFilename());
  863. bd.setDocumentType(file.getContentType());
  864. bd.setBookingDetails(bookingDetails); // Set the associated booking details
  865. bookingDetails.setBookingStatus(BookingStatus.WAITING_FOR_NOC_APPROVAL);
  866. bookingDetails.setComments("Waiting for Admin Approval");
  867. DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
  868. String formattedDate = LocalDateTime.now().format(formatter);
  869. bookingDetails.setUpdatedDate(formattedDate);
  870. // Save the file to the server
  871. try (FileOutputStream fos = new FileOutputStream(filePath)) {
  872. byte[] bytes = file.getBytes();
  873. fos.write(bytes);
  874. } catch (Exception e) {
  875. throw new RuntimeException("Error saving file", e);
  876. }
  877. // Save the document details in the repository
  878. bookingDetailsRepository.save(bookingDetails);
  879. bookingDocumentsRepository.save(bd);
  880. return "File uploaded and saved successfully";
  881. }
  882. @Transactional
  883. public List<Integer> saveGCCBlockingDate(GccBlockingDate gcc) {
  884. // Save the GccBlockingDate first
  885. GccBlockingDate savedGcc = gccBlockingDateRepository.save(gcc);
  886. // Extract hall IDs and initialize list for booking IDs
  887. String[] hallIds = savedGcc.getHallId().split(",");
  888. List<Integer> bookingIds = new ArrayList<>();
  889. for (String hallId : hallIds) {
  890. HallDetails hallDetails = hallDetailsRepository.findById(Integer.parseInt(hallId))
  891. .orElseThrow(() -> new RuntimeException("HallDetails not found for id: " + hallId));
  892. DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
  893. // Get GCC User
  894. Users user = userRepository.findByUsername("gccuser");
  895. if (user == null) {
  896. throw new RuntimeException("User not found for username: gccuser");
  897. }
  898. // Create and save BookingDetails
  899. BookingDetails bookingDetails = new BookingDetails();
  900. bookingDetails.setBookingStatus(BookingDetails.BookingStatus.GCC_BLOCKED);
  901. bookingDetails.setReason(gcc.getBlockingReason());
  902. bookingDetails.setNoOfDays(0);
  903. bookingDetails.setAmountReceived(0);
  904. bookingDetails.setDepositAmount(0);
  905. bookingDetails.setRefundStatus(BookingDetails.RefundStatus.NA);
  906. bookingDetails.setBookingDate(LocalDate.now());
  907. bookingDetails.setStartDate(LocalDate.ofInstant(savedGcc.getStartDate().toInstant(), ZoneId.systemDefault()).format(formatter));
  908. bookingDetails.setEndDate(LocalDate.ofInstant(savedGcc.getEndDate().toInstant(), ZoneId.systemDefault()).format(formatter));
  909. bookingDetails.setHallAmount(0);
  910. bookingDetails.setHallDetails(hallDetails);
  911. bookingDetails.setUsers(user);
  912. bookingDetails = bookingDetailsRepository.save(bookingDetails);
  913. bookingIds.add(bookingDetails.getBookingId());
  914. System.out.println("BookingDetails saved with ID: " + bookingDetails.getBookingId());
  915. }
  916. // Save the list of booking IDs in the GccBlockingDate entity
  917. String bookingIdsStr = bookingIds.stream()
  918. .map(String::valueOf)
  919. .collect(Collectors.joining(","));
  920. savedGcc.setBookingIds(bookingIdsStr);
  921. gccBlockingDateRepository.save(savedGcc);
  922. // Return the list of booking IDs
  923. return bookingIds;
  924. }
  925. public List<String> getCancelling(String fromDate, String toDate, String hallID) {
  926. List<String> data = bookingCalendarRepository.getCancelling(fromDate, toDate, hallID);
  927. return data;
  928. }
  929. public BookingCalendar getbyDates(LocalDate aa, String hallID) {
  930. BookingCalendar data = bookingCalendarRepository.getbyDates(aa, hallID);
  931. return data;
  932. }
  933. public void updateBookingStatus(BookingCalendar book) {
  934. bookingCalendarRepository.save(book);
  935. }
  936. public List<BookingCalendar> getCancellingdata1(String bookID) {
  937. List<BookingCalendar> data = bookingCalendarRepository.getCancellingdata1(bookID);
  938. return data;
  939. }
  940. //caretaker
  941. @Override
  942. public List<BookingDetails> getPresentsEventsByUserId(Integer hallId) {
  943. // TODO Auto-generated method stub
  944. return bookingDetailsRepository.findPresentsEventsByUserId(hallId);
  945. }
  946. public List<BookingDetails> getSettlementList(Integer hallId) {
  947. // TODO Auto-generated method stub
  948. return bookingDetailsRepository.getSettlementList(hallId);
  949. }
  950. @Override
  951. public List<BookingDetails> getPastsEventsByUserId(Integer hallId) {
  952. // TODO Auto-generated method stub
  953. return bookingDetailsRepository.findPastEventsByHallId(hallId);
  954. }
  955. @Override
  956. public List<BookingDetails> getFuturesEventsByUserId(Integer hallId) {
  957. // TODO Auto-generated method stub
  958. return bookingDetailsRepository.findFutureEventsByHallId(hallId);
  959. }
  960. @Override
  961. public List<BookingDetails> getFilteredBookings(LocalDate fromDate, LocalDate toDate, List<Long> hallIds) {
  962. return bookingDetailsRepository.findByFromDateBetweenAndToDateBetweenAndHallIdIn(fromDate, toDate, hallIds);
  963. }
  964. @Override
  965. public List<GccBlockingDate> getBlockedEvents(LocalDate fromDate, LocalDate toDate, List<Long> hallIds) {
  966. return blockingDateRepository.findByFromDateAndToDateBetweenAndHallIdIn(fromDate, toDate, hallIds);
  967. }
  968. @Override
  969. public BookingDetails updateBookingStatustoGCCBlocked(BookingDetails bookingDetails) {
  970. BookingDetails save = bookingDetailsRepository.save(bookingDetails);
  971. return save;
  972. }
  973. //carearetakerend
  974. @Override
  975. public BookingDetails updateBookingStatusById(int bookingId, BookingDetails.BookingStatus status, String comments) {
  976. Optional<BookingDetails> bookingDetails = bookingDetailsRepository.findById(bookingId);
  977. if (bookingDetails.isPresent()) {
  978. BookingDetails bookDet = bookingDetails.get();
  979. // Update Booking Status
  980. bookDet.setBookingStatus(status);
  981. bookDet.setComments(comments);
  982. BookingDetails updatedBookingDetails = bookingDetailsRepository.save(bookDet);
  983. return updatedBookingDetails;
  984. }
  985. return null;
  986. }
  987. @Override
  988. public BookingDetails updateCancelledBookingStatus(int bookingId, BookingDetails.BookingStatus status, String comments) {
  989. Optional<BookingDetails> bookingDetails = bookingDetailsRepository.findById(bookingId);
  990. if (bookingDetails.isPresent()) {
  991. BookingDetails bookDet = bookingDetails.get();
  992. // System.out.println("Current booking status: " + bookDet.getBookingStatus());
  993. // Create Booking History Entry
  994. BookingHistory bookHistory = new BookingHistory();
  995. bookHistory.setBookingDetails(bookDet);
  996. bookHistory.setBookingStatus(bookDet.getBookingStatus());
  997. bookHistory.setStartDate(bookDet.getStartDate());
  998. bookHistory.setEndDate(bookDet.getEndDate());
  999. bookHistory.setComments(bookDet.getComments());
  1000. bookHistory.setCdate(new Date());
  1001. bookHistory.setRefundStatus(bookDet.getRefundStatus());
  1002. bookingHistoryRepository.save(bookHistory);
  1003. // Update Booking Status
  1004. bookDet.setBookingStatus(status);
  1005. bookDet.setComments(comments);
  1006. DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
  1007. String formattedDate = LocalDateTime.now().format(formatter);
  1008. bookDet.setUpdatedDate(formattedDate);
  1009. BookingDetails updatedBookingDetails = bookingDetailsRepository.save(bookDet);
  1010. List<BookingCalendar> bookingCalendarList = bookingCalendarRepository.getCancellingdata1(String.valueOf(bookDet.getBookingId()));
  1011. for (BookingCalendar calendar : bookingCalendarList) {
  1012. if (String.valueOf(bookDet.getBookingId()).equals(calendar.getBookingId_1())) {
  1013. calendar.setBookingId_1(null);
  1014. calendar.setMorningSlot(false);
  1015. }
  1016. if (String.valueOf(bookDet.getBookingId()).equals(calendar.getBookingId_2())) {
  1017. calendar.setBookingId_2(null);
  1018. calendar.setEveningSlot(false);
  1019. }
  1020. bookingCalendarRepository.save(calendar);
  1021. }
  1022. return updatedBookingDetails;
  1023. }
  1024. //System.out.println("Booking details not found for ID: " + bookingId);
  1025. return null;
  1026. }
  1027. @Override
  1028. public EbDetails updateEbDetails(int bookingId, double startUnit, double endUnit, char status) {
  1029. Optional<BookingDetails> bookingDetails = bookingDetailsRepository.findById(bookingId);
  1030. if (bookingDetails.isPresent()) {
  1031. BookingDetails bd = bookingDetails.get();
  1032. EbDetails ed = bd.getEbDetails();
  1033. if (ed == null) {
  1034. ed = new EbDetails();
  1035. ed.setBookingDetails(bd);
  1036. }
  1037. if (status == 'S') {
  1038. ed.setCdate(new Date());
  1039. ed.setStartingReading(startUnit);
  1040. return ebDetailsRepository.save(ed);
  1041. } else if (status == 'E') {
  1042. double startReading = ed.getStartingReading();
  1043. if (endUnit != 0) {
  1044. ed.setEndingReading(endUnit);
  1045. double usedUnit = Math.floor((endUnit - startReading) * 100) / 100.0;
  1046. ed.setUsedUnit(Float.parseFloat(usedUnit + ""));
  1047. float costPerUnit = bd.getHallDetails().getEbCostPerUnit();
  1048. double ebAmount = Math.floor((usedUnit * costPerUnit) * 100) / 100.0;
  1049. ed.setEbAmount(ebAmount);
  1050. ed.setUpdatedDate(new Date());
  1051. return ebDetailsRepository.save(ed);
  1052. }
  1053. }
  1054. }
  1055. return null;
  1056. }
  1057. @Override
  1058. public String cancelBooking(int bookingId, BookingDetails.BookingStatus currentStatus, String comments) {
  1059. Optional<BookingDetails> bd = bookingDetailsRepository.findById(bookingId);
  1060. if (bd.isPresent()) {
  1061. BookingDetails bookingDetails = bd.get();
  1062. //System.out.println("currentStatus:-"+currentStatus);
  1063. if (bookingDetails.getBookingStatus().equals(BookingDetails.BookingStatus.APPROVED)) {
  1064. //System.err.println("test"+currentStatus);
  1065. if (currentStatus.equals(BookingDetails.BookingStatus.CANCELED)) {
  1066. //System.err.println("test11"+currentStatus);
  1067. try {
  1068. //System.err.println("test13331==="+currentStatus);
  1069. applicationLogService.saveLog(bookingDetails.getBookingId(), ApplicationLogs.logsOfMsg.USER_CANCELLED_BOOKING.toString(), comments);
  1070. String refundTheDepositAmount = paymentGatewayService.refundTheDepositAmount(bookingDetails.getBookingId(), bookingDetails.getUsers().getUserId(), bookingDetails.getDepositAmount());
  1071. //System.out.println("refundTheDepositAmount==="+refundTheDepositAmount);
  1072. if (refundTheDepositAmount.equals("Refunded")) {
  1073. updateBookingStatusById(bookingDetails.getBookingId(), BookingDetails.BookingStatus.CANCELED, "user cancelled Date:-" + new Date());
  1074. List<BookingCalendar> bookingCalendarList = bookingCalendarRepository.getCancellingdata1(String.valueOf(bookingDetails.getBookingId()));
  1075. for (BookingCalendar calendar : bookingCalendarList) {
  1076. boolean isUpdated = false;
  1077. if (String.valueOf(bookingDetails.getBookingId()).equals(calendar.getBookingId_1())) {
  1078. calendar.setBookingId_1(null);
  1079. isUpdated = true;
  1080. }
  1081. if (String.valueOf(bookingDetails.getBookingId()).equals(calendar.getBookingId_2())) {
  1082. calendar.setBookingId_2(null);
  1083. isUpdated = true;
  1084. }
  1085. if (calendar.isMorningSlot()) {
  1086. calendar.setMorningSlot(false);
  1087. isUpdated = true;
  1088. }
  1089. if (calendar.isEveningSlot()) {
  1090. calendar.setEveningSlot(false);
  1091. isUpdated = true;
  1092. }
  1093. if (isUpdated) {
  1094. calendar.setIs_delete(true);
  1095. bookingCalendarRepository.save(calendar);
  1096. }
  1097. }
  1098. return "success";
  1099. }
  1100. return "error";
  1101. } catch (Exception e) {
  1102. e.printStackTrace();
  1103. }
  1104. } else if (currentStatus.equals(BookingDetails.BookingStatus.REJECTED)) {
  1105. try {
  1106. applicationLogService.saveLog(bookingDetails.getBookingId(), ApplicationLogs.logsOfMsg.GCC_REJECTED.toString(), comments);
  1107. String refundtheAmount = paymentGatewayService.refundTheAmount(bookingDetails.getBookingId(), bookingDetails.getUsers().getUserId());
  1108. //System.out.println("refundtheAmount==="+refundtheAmount);
  1109. if (refundtheAmount.equals("Refunded")) {
  1110. updateBookingStatusById(bookingDetails.getBookingId(), BookingDetails.BookingStatus.REJECTED, comments);
  1111. List<BookingCalendar> bookingCalendarList = bookingCalendarRepository.getCancellingdata1(String.valueOf(bookingDetails.getBookingId()));
  1112. for (BookingCalendar calendar : bookingCalendarList) {
  1113. boolean isUpdated = false;
  1114. if (String.valueOf(bookingDetails.getBookingId()).equals(calendar.getBookingId_1())) {
  1115. calendar.setBookingId_1(null);
  1116. isUpdated = true;
  1117. }
  1118. if (String.valueOf(bookingDetails.getBookingId()).equals(calendar.getBookingId_2())) {
  1119. calendar.setBookingId_2(null);
  1120. isUpdated = true;
  1121. }
  1122. if (calendar.isMorningSlot()) {
  1123. calendar.setMorningSlot(false);
  1124. isUpdated = true;
  1125. }
  1126. if (calendar.isEveningSlot()) {
  1127. calendar.setEveningSlot(false);
  1128. isUpdated = true;
  1129. }
  1130. if (isUpdated) {
  1131. calendar.setIs_delete(true);
  1132. bookingCalendarRepository.save(calendar);
  1133. }
  1134. }
  1135. return "success";
  1136. }
  1137. return "error";
  1138. } catch (Exception e) {
  1139. e.printStackTrace();
  1140. }
  1141. } else if (currentStatus.equals(BookingDetails.BookingStatus.GCC_BLOCKED)) {
  1142. try {
  1143. applicationLogService.saveLog(bookingDetails.getBookingId(), ApplicationLogs.logsOfMsg.GCC_BLOCKED_DATE.toString(), comments);
  1144. paymentGatewayService.refundTheAmount(bookingDetails.getBookingId(), bookingDetails.getUsers().getUserId());
  1145. updateBookingStatusById(bookingDetails.getBookingId(), BookingDetails.BookingStatus.GCC_BLOCKED, "total amount will refund shortly");
  1146. } catch (Exception e) {
  1147. e.printStackTrace();
  1148. }
  1149. }
  1150. }
  1151. }
  1152. return null;
  1153. }
  1154. @Override
  1155. public BookingDetails getBookingDetailsWithSettlement(int settlementId) {
  1156. Optional<BookingDetails> SettleBookingDetails = Optional.of(bookingDetailsRepository.findBySettlementIdWithBookingDetails(settlementId));
  1157. if (SettleBookingDetails.isPresent()) {
  1158. return SettleBookingDetails.get();
  1159. }
  1160. return null;
  1161. }
  1162. @Override
  1163. public BookingDetails saveebdetails(int bookingId, double startingReading,
  1164. MultipartFile startingReadingimage) {
  1165. BookingDetails bd = getBookingsById(bookingId);
  1166. if (bd != null) {
  1167. if (bd.getEbDetails() == null) {
  1168. EbDetails eb = new EbDetails();
  1169. eb.setCdate(new Date());
  1170. eb.setStartingReading(startingReading);
  1171. if (startingReadingimage != null) {
  1172. eb.setEbImageUrl((serverPath + "images/eb/" + bookingId + "_" + startingReadingimage.getOriginalFilename()));
  1173. String filePath = uploadDirectory + "/eb/" + bookingId + "_" + startingReadingimage.getOriginalFilename();
  1174. try (FileOutputStream fos = new FileOutputStream(filePath)) {
  1175. byte[] bytes = startingReadingimage.getBytes();
  1176. fos.write(bytes);
  1177. } catch (Exception e) {
  1178. throw new RuntimeException(e);
  1179. }
  1180. }
  1181. eb.setBookingDetails(bd);
  1182. bd.setEbDetails(eb);
  1183. return bd;
  1184. }
  1185. }
  1186. return null;
  1187. }
  1188. @Override
  1189. public String processEbDetailsAndDamage(int bookingId, int ebId, double startingReading, double endingReading,
  1190. float usedUnit, double ebAmount, String[] assetNames, String[] comments, int[] quantities,
  1191. Double[] assetAmounts, MultipartFile[] assetImages) {
  1192. Optional<BookingDetails> findById = bookingDetailsRepository.findById(bookingId);
  1193. if (findById.isPresent()) {
  1194. BookingDetails book = findById.get();
  1195. book.setRefundStatus(RefundStatus.WAITING);
  1196. EbDetails updateEbDetails = updateEbDetails(bookingId, startingReading, endingReading, 'E');
  1197. double damageAmount = 0;
  1198. String adminname = (String) session.getAttribute("usertype");
  1199. if (assetNames != null && assetNames.length > 0) {
  1200. for (int i = 0; i < assetNames.length; i++) {
  1201. Damage damage = new Damage();
  1202. damage.setAssetName(assetNames[i]);
  1203. damage.setComments(comments[i]);
  1204. damage.setQuantity(quantities[i]);
  1205. damage.setAssetAmount(assetAmounts[i]);
  1206. damage.setUpdatedBy(adminname);
  1207. damage.setHallDetails(book.getHallDetails());
  1208. damageAmount = damageAmount + assetAmounts[i];
  1209. if (assetImages != null && !assetImages[i].isEmpty()) {
  1210. damage.setDamageImageUrl(serverPath + "images/damage/" + bookingId + "_" + assetImages[i].getOriginalFilename());
  1211. String filePath = uploadDirectory + "/damage/" + bookingId + "_" + assetImages[i].getOriginalFilename();
  1212. try (FileOutputStream fos = new FileOutputStream(filePath)) {
  1213. byte[] bytes = assetImages[i].getBytes();
  1214. fos.write(bytes);
  1215. } catch (Exception e) {
  1216. throw new RuntimeException(e);
  1217. }
  1218. }
  1219. damage.setBookingDetails(book);
  1220. damageRepository.save(damage);
  1221. }
  1222. }
  1223. Settlement settlement;
  1224. if (book.getSettlement() != null) {
  1225. settlement = book.getSettlement(); // Update existing settlement
  1226. } else {
  1227. settlement = new Settlement(); // Create new settlement
  1228. }
  1229. settlement.setCdate(LocalDate.now());
  1230. settlement.setBookingDetails(book);
  1231. settlement.setDepositAmount(book.getDepositAmount());
  1232. settlement.setEbAmount(updateEbDetails.getEbAmount());
  1233. settlement.setDamageAmount(damageAmount);
  1234. settlement.setUpdatedId(adminname);
  1235. double refundamount = book.getDepositAmount() - (updateEbDetails.getEbAmount() + damageAmount);
  1236. if (refundamount < 0) {
  1237. settlement.setRefundedAmount(0);
  1238. settlement.setCollectionPending(Math.abs(refundamount));
  1239. settlement.setCollectionStatus("waiting");
  1240. } else {
  1241. settlement.setRefundedAmount(refundamount);
  1242. settlement.setCollectionPending(0);
  1243. }
  1244. settlementRepository.save(settlement);
  1245. return "Success";
  1246. }
  1247. return "Error";
  1248. }
  1249. //sreeja
  1250. @Override
  1251. public List<BookingCalendar> getPastData(int hall_id) {
  1252. List<BookingCalendar> data = bookingCalendarRepository.getPastData(hall_id);
  1253. return data;
  1254. }
  1255. @Override
  1256. public int checkUserBookinglimitation(int userId) {
  1257. // TODO Auto-generated method stub
  1258. return bookingDetailsRepository.checkUserBookinglimitation(userId);
  1259. }
  1260. @Override
  1261. public List<BookingDetails> getAllBookingsByUserId(Integer userId) {
  1262. // TODO Auto-generated method stub
  1263. return bookingDetailsRepository.getAllBookingsByUserId(userId);
  1264. }
  1265. public BookingDetails getByBookingId(String bookID) {
  1266. return bookingDetailsRepository.getByBookingId(bookID);
  1267. }
  1268. public void updateBookingDetailsStatus(BookingDetails bookingDetails) {
  1269. bookingDetailsRepository.save(bookingDetails);
  1270. }
  1271. @Override
  1272. public List<Object[]> getBookingUserDetailsReport(String fromDate, String toDate) {
  1273. // TODO Auto-generated method stub
  1274. return bookingDetailsRepository.getBookingUserDetailsReport(fromDate, toDate);
  1275. }
  1276. @Override
  1277. public List<Object[]> getBookingHallDetailsReport(String fromDate, String toDate) {
  1278. // TODO Auto-generated method stub
  1279. return bookingDetailsRepository.getBookingHallDetailsReport(fromDate, toDate);
  1280. }
  1281. public List<Map<String, Object>> getAllBookingEventsByUserId(Integer userId) {
  1282. return bookingDetailsRepository.getAllBookingEventsByUserId(userId);
  1283. }
  1284. //counter
  1285. public List<Map<String, Object>> getOfflineBookings() {
  1286. return bookingDetailsRepository.findAllByBookingType();
  1287. }
  1288. @Override
  1289. public List<BookingCalendar> getBookedslots(LocalDate fromDate, LocalDate endDate, List<Long> hallIdList) {
  1290. return bookingCalendarRepository.findByHallIdAndDateRange(fromDate, endDate, hallIdList);
  1291. }
  1292. // public List<String> processRefundRequests(List<String> bookingIds) {
  1293. // List<String> bookIds = new ArrayList<>();
  1294. //
  1295. // for (String bookingIdStr : bookingIds) {
  1296. // try {
  1297. // int bookingId = Integer.parseInt(bookingIdStr);
  1298. // Optional<BookingDetails> bookings = bookingDetailsRepository.findById(bookingId);
  1299. // if (bookings.isPresent()) {
  1300. // BookingDetails bookingDetails = bookings.get();
  1301. // boolean refundSuccess = SettlementAmountRefund(bookingDetails);
  1302. // if (!refundSuccess) {
  1303. // bookIds.add(bookingIdStr); // Add ID to error list if refund fails
  1304. // }
  1305. // } else {
  1306. // bookIds.add(bookingIdStr); // Add ID to error list if booking not found
  1307. // }
  1308. // } catch (NumberFormatException e) {
  1309. // bookIds.add(bookingIdStr); // Add ID to error list if invalid format
  1310. // } catch (Exception e) {
  1311. // e.printStackTrace();
  1312. // bookIds.add(bookingIdStr); // Add ID to error list for any other exception
  1313. // }
  1314. // }
  1315. //
  1316. // return bookIds;
  1317. // }
  1318. // private final ConcurrentHashMap<Integer, Boolean> processingMap = new ConcurrentHashMap<>();
  1319. //
  1320. // @Synchronized
  1321. public String processRefundRequest(int bookingId) {
  1322. try {
  1323. Optional<BookingDetails> bookingOptional = bookingDetailsRepository.findById(bookingId);
  1324. if (bookingOptional.isPresent()) {
  1325. BookingDetails bookingDetails = bookingOptional.get();
  1326. boolean refundSuccess = SettlementAmountRefund(bookingDetails);
  1327. if (refundSuccess) {
  1328. return "Refund successful for Booking ID: " + bookingId;
  1329. } else {
  1330. return "Refund failed for Booking ID: " + bookingId;
  1331. }
  1332. } else {
  1333. return "Booking not found for Booking ID: " + bookingId;
  1334. }
  1335. } catch (Exception e) {
  1336. e.printStackTrace();
  1337. return "An error occurred while processing Booking ID: " + bookingId + ": " + e.getMessage();
  1338. }
  1339. }
  1340. public boolean SettlementAmountRefund(BookingDetails bookingDetails) throws Exception {
  1341. BookingStatus bookingStatus = bookingDetails.getBookingStatus();
  1342. RefundStatus refunStatus = bookingDetails.getRefundStatus();
  1343. String adminname = (String) session.getAttribute("usertype");
  1344. if (bookingStatus == BookingStatus.APPROVED && !(refunStatus == RefundStatus.COMPLETED) && !(refunStatus == RefundStatus.CLOSED)) {
  1345. applicationLogService.saveLog(bookingDetails.getBookingId(), ApplicationLogs.logsOfMsg.SETTLEMENT_COMPLETED.toString(), "Refund will happen shortly");
  1346. String refundThesettlementAmount = paymentGatewayService.refundTheDepositAmount(bookingDetails.getBookingId(), bookingDetails.getUsers().getUserId(), bookingDetails.getSettlement().getRefundedAmount());
  1347. //System.out.println("refundThesettlementAmount === " + refundThesettlementAmount);
  1348. if (refundThesettlementAmount.equals("Refunded")) {
  1349. Optional<BookingDetails> book = bookingDetailsRepository.findById(bookingDetails.getBookingId());
  1350. BookingDetails bookings = book.get();
  1351. //bookinghistoty update
  1352. BookingHistory bookingHistory = new BookingHistory();
  1353. bookingHistory.setStartDate(bookingDetails.getStartDate());
  1354. bookingHistory.setEndDate(bookingDetails.getEndDate());
  1355. bookingHistory.setComments(bookingDetails.getComments());
  1356. bookingHistory.setBookingDetails(bookingDetails);
  1357. bookingHistory.setBookingStatus(bookingDetails.getBookingStatus());
  1358. bookingHistory.setUpdatedBy(adminname);
  1359. bookingHistory.setCdate(new Date());
  1360. bookingHistory.setRefundStatus(bookingDetails.getRefundStatus());
  1361. bookingDetails.setComments("Completed the Refund");
  1362. bookingHistoryRepository.save(bookingHistory);
  1363. bookings.setBookingStatus(bookingStatus.COMPLETED);
  1364. bookings.setRefundStatus(RefundStatus.COMPLETED);
  1365. DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
  1366. String formattedDate = LocalDateTime.now().format(formatter);
  1367. bookings.setUpdatedDate(formattedDate);
  1368. bookings.setApprovedBy(adminname);
  1369. bookingDetailsRepository.save(bookings);
  1370. String settlementrefundsms = "Your refund amount of Rs. " + bookings.getSettlement().getRefundedAmount() + " for Booking ID " + bookings.getBookingId() + " has been initiated. The amount will be credited to your account within 3 to 15 days. Thanks for using the GCC Community Hall Booking System.";
  1371. String settlementrefundurlString = "https://tmegov.onex-aura.com/api/sms?key=pfTEYN6H&to=" + bookings.getUsers().getMobileNo() + "&from=GCCCRP&body=" + settlementrefundsms + "&entityid=1401572690000011081&templateid=1407172346804951524";
  1372. String settlementrefundwhatsupmsg = "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+refund+of+Rs.+" + bookingDetails.getSettlement().getRefundedAmount() + "+for+Booking+ID+" + bookingDetails.getBookingId() + "+has+been+initiated.+%0AThe+amount+will+be+credited+to+your+account+within+3+to+15+days.";
  1373. whatsappMsgServiceImpl.sendMsg(settlementrefundwhatsupmsg);
  1374. whatsappMsgServiceImpl.sendSMS(settlementrefundurlString);
  1375. return true;
  1376. } else {
  1377. return false;
  1378. }
  1379. } else if (bookingStatus == BookingStatus.REJECTED || bookingStatus == BookingStatus.GCC_BLOCKED && !(refunStatus == RefundStatus.COMPLETED) && !(refunStatus == RefundStatus.CLOSED)) {
  1380. applicationLogService.saveLog(bookingDetails.getBookingId(), ApplicationLogs.logsOfMsg.GCC_BLOCKED_DATE.toString(), "Refund will happen shortly");
  1381. String refundFullAmount = paymentGatewayService.refundTheAmount(bookingDetails.getBookingId(), bookingDetails.getUsers().getUserId());
  1382. //System.out.println("refundTheDepositAmount === " + refundFullAmount);
  1383. if (refundFullAmount.equals("Refunded")) {
  1384. Optional<BookingDetails> book = bookingDetailsRepository.findById(bookingDetails.getBookingId());
  1385. BookingDetails rejectedbookings = book.get();
  1386. rejectedbookings.setRefundStatus(RefundStatus.COMPLETED);
  1387. bookingDetailsRepository.save(rejectedbookings);
  1388. String rejectedsms = "Your refund amount of Rs. " + rejectedbookings.getAmountReceived() + " for Booking ID " + rejectedbookings.getBookingId() + " has been initiated. The amount will be credited to your account within 3 to 15 days. Thanks for using the GCC Community Hall Booking System.";
  1389. String rejectedrefundurlString = "https://tmegov.onex-aura.com/api/sms?key=pfTEYN6H&to=" + rejectedbookings.getUsers().getMobileNo() + "&from=GCCCRP&body=" + rejectedsms + "&entityid=1401572690000011081&templateid=1407172346804951524";
  1390. String settlementrefundwhatsupmsg = "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+refund+of+Rs.+" + bookingDetails.getAmountReceived() + "+for+Booking+ID+" + bookingDetails.getBookingId() + "+has+been+initiated.+%0AThe+amount+will+be+credited+to+your+account+within+3+to+15+days.";
  1391. whatsappMsgServiceImpl.sendMsg(settlementrefundwhatsupmsg);
  1392. whatsappMsgServiceImpl.sendSMS(rejectedrefundurlString);
  1393. return true;
  1394. } else {
  1395. return false;
  1396. }
  1397. } else if (bookingStatus == BookingStatus.CANCELED && !(refunStatus == RefundStatus.COMPLETED) && !(refunStatus == RefundStatus.CLOSED)) {
  1398. // System.out.println("Booking status is Cancelled. Booking ID: " + bookingDetails.getBookingId());
  1399. applicationLogService.saveLog(bookingDetails.getBookingId(), ApplicationLogs.logsOfMsg.USER_CANCELLED_BOOKING.toString(), "Refund will happen shortly");
  1400. String refundTheDepositAmount = paymentGatewayService.refundTheDepositAmount(bookingDetails.getBookingId(), bookingDetails.getUsers().getUserId(), bookingDetails.getDepositAmount());
  1401. //System.out.println("refundTheDepositAmount === " + refundTheDepositAmount);
  1402. if (refundTheDepositAmount.equals("Refunded")) {
  1403. Optional<BookingDetails> book = bookingDetailsRepository.findById(bookingDetails.getBookingId());
  1404. BookingDetails cancelledbookings = book.get();
  1405. cancelledbookings.setRefundStatus(RefundStatus.COMPLETED);
  1406. bookingDetailsRepository.save(cancelledbookings);
  1407. String cancelledsms = "Your refund amount of Rs. " + cancelledbookings.getDepositAmount() + " for Booking ID " + cancelledbookings.getBookingId() + " has been initiated. The amount will be credited to your account within 3 to 15 days. Thanks for using the GCC Community Hall Booking System.";
  1408. String cancelledrefundurlString = "https://tmegov.onex-aura.com/api/sms?key=pfTEYN6H&to=" + cancelledbookings.getUsers().getMobileNo() + "&from=GCCCRP&body=" + cancelledsms + "&entityid=1401572690000011081&templateid=1407172346804951524";
  1409. String settlementrefundwhatsupmsg = "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+refund+of+Rs.+" + bookingDetails.getDepositAmount() + "+for+Booking+ID+" + bookingDetails.getBookingId() + "+has+been+initiated.+%0AThe+amount+will+be+credited+to+your+account+within+3+to+15+days.";
  1410. whatsappMsgServiceImpl.sendMsg(settlementrefundwhatsupmsg);
  1411. whatsappMsgServiceImpl.sendSMS(cancelledrefundurlString);
  1412. return true;
  1413. } else {
  1414. return false;
  1415. }
  1416. } else {
  1417. return false;
  1418. }
  1419. }
  1420. @Override
  1421. public BookingDetails updateRefundStatus(int bookingId, RefundStatus status) {
  1422. Optional<BookingDetails> booking = bookingDetailsRepository.findById(bookingId);
  1423. if (booking.isPresent()) {
  1424. String adminname = (String) session.getAttribute("usertype");
  1425. BookingDetails book = booking.get();
  1426. book.setRefundStatus(status);
  1427. BookingHistory bookingHistory = new BookingHistory();
  1428. bookingHistory.setStartDate(book.getStartDate());
  1429. bookingHistory.setEndDate(book.getEndDate());
  1430. bookingHistory.setComments(book.getComments());
  1431. bookingHistory.setBookingDetails(book);
  1432. bookingHistory.setBookingStatus(book.getBookingStatus());
  1433. bookingHistory.setUpdatedBy(adminname);
  1434. bookingHistory.setCdate(new Date());
  1435. bookingHistory.setRefundStatus(book.getRefundStatus());
  1436. bookingHistoryRepository.save(bookingHistory);
  1437. book.setComments("Refund status Updated to:-" + status);
  1438. BookingDetails bookings = bookingDetailsRepository.save(book);
  1439. return bookings;
  1440. }
  1441. return null;
  1442. }
  1443. //officer reports
  1444. @Override
  1445. public List<BookingDetails> getAllBookingDetailsByZone(String fromDate, String toDate, String zone) {
  1446. return bookingDetailsRepository.getAllBookingDetailsByZone(fromDate, toDate, zone);
  1447. }
  1448. @Override
  1449. public List<BookingDetails> getAllBookingDetailsByZoneWithStatus(String fromDate, String toDate, String zone, String bookingStatus) {
  1450. return bookingDetailsRepository.getAllBookingDetailsByZoneWithStatus(fromDate, toDate, zone, bookingStatus);
  1451. }
  1452. @Override
  1453. public List<Object[]> getAllPaymentsDetailsByZone(String fromDate, String toDate, String zone) {
  1454. return bookingDetailsRepository.getAllPaymentsDetailsByZone(fromDate, toDate, zone);
  1455. }
  1456. @Override
  1457. public List<Object[]> getBookingHallDetailsReportByZone(String fromDate, String toDate, String zone) {
  1458. return bookingDetailsRepository.getBookingHallDetailsReportByZone(fromDate, toDate, zone);
  1459. }
  1460. //R
  1461. @Transactional
  1462. public Optional<String> updateBookingDatesAndCalendar(int bookingId, String startDat, String endDat) {
  1463. Optional<BookingDetails> optionalBookingDetails = bookingDetailsRepository.findById(bookingId);
  1464. //TransactionStatus status = transactionManager.getTransaction(new DefaultTransactionDefinition());
  1465. if (optionalBookingDetails.isPresent()) {
  1466. BookingDetails bookingDetails = optionalBookingDetails.get();
  1467. String starting = bookingDetails.getStartDate();
  1468. int hallId = bookingDetails.getHallDetails().getHallId();
  1469. DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
  1470. LocalDate startDate = LocalDate.parse(startDat, formatter);
  1471. LocalDate endDate = LocalDate.parse(endDat, formatter);
  1472. // Retrieve existing calendar entries where bookingId matches booking_id1 or booking_id2
  1473. List<BookingCalendar> existingCalendars = bookingCalendarRepository.getCancellingdata1(String.valueOf(bookingId));
  1474. // Empty the existing date in calendar
  1475. for (BookingCalendar calendar : existingCalendars) {
  1476. if (calendar.getBookingId_1() != null && calendar.getBookingId_1().equals(String.valueOf(bookingId))) {
  1477. calendar.setMorningSlot(false);
  1478. calendar.setBookingId_1(null);
  1479. }
  1480. if (calendar.getBookingId_2() != null && calendar.getBookingId_2().equals(String.valueOf(bookingId))) {
  1481. calendar.setEveningSlot(false);
  1482. calendar.setBookingId_2(null);
  1483. }
  1484. bookingCalendarRepository.save(calendar);
  1485. }
  1486. // Check if the dates exist and update or create new entries accordingly
  1487. String slotOccExpMsg = "Dates are already occupied. Please select another date.";
  1488. int i = 0;
  1489. for (LocalDate date = startDate; !date.isAfter(endDate); date = date.plusDays(1)) {
  1490. BookingCalendar bookingCalendar = bookingCalendarRepository.findByBdateAndHallId(date, hallId);
  1491. if (bookingCalendar != null) {
  1492. // Check if the slot is already occupied
  1493. if ((date.equals(startDate) && bookingDetails.getStartingSlot() == 1 && bookingCalendar.isMorningSlot()) ||
  1494. (date.equals(startDate) && bookingDetails.getStartingSlot() == 2 && bookingCalendar.isEveningSlot()) ||
  1495. (date.equals(endDate) && bookingDetails.getEndingSlot() == 1 && bookingCalendar.isMorningSlot()) ||
  1496. (date.equals(endDate) && bookingDetails.getEndingSlot() == 2 && bookingCalendar.isEveningSlot())) {
  1497. // return "Slot occupied";
  1498. throw new SlotOccupiedException(slotOccExpMsg);
  1499. } else if (bookingCalendar.isMorningSlot() && bookingCalendar.isEveningSlot()) {
  1500. // return "Slot occupied";
  1501. throw new SlotOccupiedException(slotOccExpMsg);
  1502. } else if (!date.equals(endDate) && i != 0 && i != Math.round(bookingDetails.getNoOfDays() - 1)
  1503. && (bookingCalendar.isMorningSlot() || bookingCalendar.isEveningSlot())) {
  1504. //System.out.println("booking slot occupied:- 227 :-"+Math.round(bookingDetails.getNoOfDays()-1) );
  1505. throw new SlotOccupiedException(slotOccExpMsg);
  1506. } else if (date.equals(endDate) && bookingDetails.getEndingSlot() == 2 && bookingCalendar.isMorningSlot()
  1507. && i != 0 && i == Math.round(bookingDetails.getNoOfDays() - 1)) {
  1508. // System.out.println("booking slot occupied:- 240 :-"+Math.round(bookingDetails.getNoOfDays()-1) );
  1509. throw new SlotOccupiedException(slotOccExpMsg);
  1510. }
  1511. } else {
  1512. String uniqueId = date.format(DateTimeFormatter.ofPattern("yyyyMMdd")) + hallId;
  1513. bookingCalendar = new BookingCalendar();
  1514. bookingCalendar.setBdate(date);
  1515. bookingCalendar.setHallId(hallId);
  1516. bookingCalendar.setIs_booked(0);
  1517. bookingCalendar.setIs_active(true);
  1518. bookingCalendar.setUnique_id(uniqueId);
  1519. }
  1520. // Mark the appropriate slot as booked based on starting and ending slots
  1521. if (date.equals(startDate)) {
  1522. if (bookingDetails.getStartingSlot() == 1) {
  1523. bookingCalendar.setMorningSlot(true);
  1524. bookingCalendar.setBookingId_1(String.valueOf(bookingId));
  1525. bookingCalendar.setIs_booked(bookingCalendar.getIs_booked() + 1);
  1526. if (!date.equals(endDate)) {
  1527. bookingCalendar.setEveningSlot(true);
  1528. bookingCalendar.setBookingId_2(String.valueOf(bookingId));
  1529. bookingCalendar.setIs_booked(bookingCalendar.getIs_booked() + 1);
  1530. } else if (startDate.equals(endDate) && bookingDetails.getStartingSlot() == 1 && bookingDetails.getEndingSlot() == 2) {
  1531. bookingCalendar.setEveningSlot(true);
  1532. bookingCalendar.setBookingId_2(String.valueOf(bookingId));
  1533. bookingCalendar.setIs_booked(bookingCalendar.getIs_booked() + 1);
  1534. }
  1535. } else {
  1536. bookingCalendar.setEveningSlot(true);
  1537. bookingCalendar.setBookingId_2(String.valueOf(bookingId));
  1538. bookingCalendar.setIs_booked(bookingCalendar.getIs_booked() + 1);
  1539. }
  1540. } else if (date.equals(endDate)) {
  1541. if (bookingDetails.getEndingSlot() == 1) {
  1542. bookingCalendar.setMorningSlot(true);
  1543. bookingCalendar.setBookingId_1(String.valueOf(bookingId));
  1544. bookingCalendar.setIs_booked(bookingCalendar.getIs_booked() + 1);
  1545. } else {
  1546. bookingCalendar.setEveningSlot(true);
  1547. bookingCalendar.setBookingId_2(String.valueOf(bookingId));
  1548. bookingCalendar.setIs_booked(bookingCalendar.getIs_booked() + 1);
  1549. if (bookingDetails.getEndingSlot() == 2) {
  1550. bookingCalendar.setMorningSlot(true);
  1551. bookingCalendar.setBookingId_1(String.valueOf(bookingId));
  1552. bookingCalendar.setIs_booked(bookingCalendar.getIs_booked() + 1);
  1553. }
  1554. }
  1555. } else {
  1556. // For dates between start and end date, mark both slots as booked
  1557. bookingCalendar.setMorningSlot(true);
  1558. bookingCalendar.setEveningSlot(true);
  1559. bookingCalendar.setBookingId_1(String.valueOf(bookingId));
  1560. bookingCalendar.setBookingId_2(String.valueOf(bookingId));
  1561. bookingCalendar.setIs_booked(bookingCalendar.getIs_booked() + 2);
  1562. }
  1563. bookingCalendarRepository.save(bookingCalendar);
  1564. i++;
  1565. }
  1566. //transactionManager.rollback(status);
  1567. updateResheduledBookingDetails(bookingId, startDat, endDat);
  1568. String rescheduledmsg = "Your booking ID " + bookingId + " on " + starting + " has been successfully rescheduled to " + startDate + ". Thanks for using the GCC Community Hall Booking System.";
  1569. String urlString = "https://tmegov.onex-aura.com/api/sms?key=pfTEYN6H&to=" + bookingDetails.getUsers().getMobileNo() + "&from=GCCCRP&body=" + rescheduledmsg + "&entityid=1401572690000011081&templateid=1407172346565044999";
  1570. String rescheduleMsg = "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+" + starting + "+has+been+successfully+rescheduled+to+" + startDate + "+.+%0AThank+you+for+using+the+GCC+Community+Hall+Booking+System.";
  1571. whatsappMsgServiceImpl.sendMsg(rescheduleMsg);
  1572. whatsappMsgServiceImpl.sendSMS(urlString);
  1573. return Optional.of("Booking dates updated successfully.");
  1574. }
  1575. return Optional.of("Booking not found.");
  1576. }
  1577. private void updateResheduledBookingDetails(int bookingId, String startDate, String endDate) {
  1578. Optional<BookingDetails> book = bookingDetailsRepository.findById(bookingId);
  1579. BookingDetails bookingDetails = book.get();
  1580. bookingDetails.setScheduleCount(bookingDetails.getScheduleCount() + 1);
  1581. if (bookingDetails.getReason().equals("Commercial")) {
  1582. bookingDetails.setBookingStatus(BookingStatus.WAITING_FOR_NOC);
  1583. }
  1584. //Updating Bookinghistory startDate and End Date
  1585. BookingHistory bookingHistory = new BookingHistory();
  1586. bookingHistory.setStartDate(bookingDetails.getStartDate());
  1587. bookingHistory.setEndDate(bookingDetails.getEndDate());
  1588. bookingHistory.setComments(bookingDetails.getComments());
  1589. bookingHistory.setBookingDetails(bookingDetails);
  1590. bookingHistory.setBookingStatus(BookingStatus.APPROVED);
  1591. bookingHistory.setUpdatedBy(userSession.getDispayName());
  1592. bookingHistory.setCdate(new Date());
  1593. bookingDetails.setStartDate(startDate);
  1594. bookingDetails.setEndDate(endDate);
  1595. bookingHistory.setRefundStatus(bookingDetails.getRefundStatus());
  1596. bookingDetails.setComments("slots Resheduled the Dates");
  1597. DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
  1598. String formattedDate = LocalDateTime.now().format(formatter);
  1599. bookingDetails.setUpdatedDate(formattedDate);
  1600. bookingDetailsRepository.save(bookingDetails);
  1601. bookingHistoryRepository.save(bookingHistory);
  1602. }
  1603. @Override
  1604. public List<Object[]> getBookingHallDetailsReportByZone1(String fromDate, String toDate, String zone, Integer hallId) {
  1605. // TODO Auto-generated method stub
  1606. return bookingDetailsRepository.getBookingHallDetailsReportByZone1(fromDate, toDate, zone, hallId);
  1607. }
  1608. public List<Object> getGccBlockingEvents(String hallId) {
  1609. HallDetails hallDetails = hallDetailsRepository.findById(Integer.parseInt(hallId))
  1610. .orElseThrow(() -> new RuntimeException("Hall not found"));
  1611. // Fetch BookingDetails with GCC_BLOCKED status
  1612. List<BookingDetails> bookingDetails = bookingDetailsRepository.findByHallDetailsAndBookingStatus(hallDetails, BookingDetails.BookingStatus.GCC_BLOCKED);
  1613. // Fetch GccBlockingDate with BLOCKED status
  1614. List<GccBlockingDate> gccBlockingDates = gccBlockingDateRepository.findAllByHallIdAndBlockedStatus(hallId, GccBlockingDate.BlockedStatus.BLOCKED);
  1615. // Combine results into a list of Object (can be more specific if needed)
  1616. List<Object> results = new ArrayList<>();
  1617. results.addAll(bookingDetails);
  1618. results.addAll(gccBlockingDates);
  1619. return results;
  1620. }
  1621. @Override
  1622. public int getBlockedHallCount(String blockingReason, Date startDate, Date endDate) {
  1623. return gccBlockingDateRepository.countBlockedHallsInDateRange(blockingReason, startDate, endDate);
  1624. }
  1625. public boolean isBlockingRecordExists(String fromDate, String toDate, List<Long> hallIdsList) {
  1626. LocalDate fromdate = LocalDate.parse(fromDate);
  1627. LocalDate todate = LocalDate.parse(toDate);
  1628. List<GccBlockingDate> existingRecords = gccBlockingDateRepository.findByFromDateAndToDateBetweenAndHallIdIn(fromdate, todate, hallIdsList);
  1629. return !existingRecords.isEmpty();
  1630. }
  1631. @Override
  1632. public void cancelAllBookings(String fromDate, String toDate, List<Long> hallIdsList,
  1633. String reasonforblocking, List<String> selectedBookings, String updatedBy, String[] descriptions, MultipartFile[] documents) {
  1634. if (selectedBookings != null && !selectedBookings.isEmpty()) {
  1635. for (String bookingIdStr : selectedBookings) {
  1636. Integer bookingId = Integer.parseInt(bookingIdStr);
  1637. Optional<BookingDetails> optionalBooking = bookingDetailsRepository.findById(bookingId);
  1638. if (optionalBooking.isPresent()) {
  1639. BookingDetails booking = optionalBooking.get();
  1640. BookingStatus currentStatus = booking.getBookingStatus();
  1641. if (currentStatus == BookingStatus.APPROVED || currentStatus == BookingStatus.WAITING_FOR_NOC ||
  1642. currentStatus == BookingStatus.WAITING_FOR_NOC_APPROVAL) {
  1643. booking.setBookingStatus(BookingStatus.GCC_BLOCKED);
  1644. List<BookingCalendar> calendardata = getCancellingdata1(bookingId.toString());
  1645. for (BookingCalendar bb : calendardata) {
  1646. if (bookingId != 0 && bb.getBookingId_1() != null &&
  1647. bookingId.equals(Integer.valueOf(bb.getBookingId_1()))) {
  1648. bb.setBookingId_1(null);
  1649. bb.setMorningSlot(false);
  1650. }
  1651. if (bookingId != 0 && bb.getBookingId_2() != null &&
  1652. bookingId.equals(Integer.valueOf(bb.getBookingId_2()))) {
  1653. bb.setBookingId_2(null);
  1654. bb.setEveningSlot(false);
  1655. }
  1656. //bb.setIs_blocked(true);
  1657. updateBookingStatus(bb);
  1658. }
  1659. // GCC blocking entry
  1660. GccBlockingDate gcc = new GccBlockingDate();
  1661. gcc.setStartDate(convertStringToDate(fromDate));
  1662. gcc.setEndDate(convertStringToDate(toDate));
  1663. gcc.setHallId(String.join(",", hallIdsList.stream().map(String::valueOf).collect(Collectors.toList())));
  1664. gcc.setUpdatedBy(updatedBy);
  1665. gcc.setCdate(new Date());
  1666. gcc.setBlockingReason(reasonforblocking);
  1667. if (documents != null && documents.length > 0 && descriptions != null && descriptions.length > 0) {
  1668. int i = 0;
  1669. for (MultipartFile document : documents) {
  1670. String filePath = uploadDirectory + "/" + gcc.getBlockingId() + "_" + i + "_" + document.getOriginalFilename();
  1671. String documentUrl = serverPath + "gccblockingdocs/" + gcc.getBlockingId() + "_" + i + "_" + document.getOriginalFilename();
  1672. try (FileOutputStream fos = new FileOutputStream(filePath)) {
  1673. // Save document to the file system
  1674. byte[] bytes = document.getBytes();
  1675. fos.write(bytes);
  1676. // Save document details along with description in the database
  1677. GccblockingDocuments documentDetails = new GccblockingDocuments(); // Assuming you have a DocumentDetails entity
  1678. documentDetails.setBlockingDate(gcc); // Assuming hallDetails is associated with the document
  1679. documentDetails.setBlockingDocument(documentUrl); // Save the URL of the uploaded document
  1680. documentDetails.setDescription(descriptions[i]); // Save corresponding description
  1681. gccblockingDocumentsRepo.save(documentDetails); // Save the document and description in the database
  1682. } catch (IOException e) {
  1683. throw new RuntimeException("Failed to save document", e);
  1684. }
  1685. i++;
  1686. }
  1687. }
  1688. // GCC blocking History
  1689. GccBlockingHistory gccblockinghistory = new GccBlockingHistory();
  1690. gccblockinghistory.setStartDate(convertStringToDate(fromDate));
  1691. gccblockinghistory.setEndDate(convertStringToDate(toDate));
  1692. gccblockinghistory.setHallId(String.join(",", hallIdsList.stream().map(String::valueOf).collect(Collectors.toList())));
  1693. gccblockinghistory.setUpdatedBy(updatedBy);
  1694. gccblockinghistory.setCdate(new Date());
  1695. gccblockinghistory.setBlockingReason(reasonforblocking);
  1696. List<Integer> bookingIds = saveGCCBlockingDate(gcc);
  1697. gccblockinghistory.setBookingIds(bookingIds.toString());
  1698. blockingHistoryRepository.save(gccblockinghistory);
  1699. // GCC calendar
  1700. for (Long hallId : hallIdsList) {
  1701. LocalDate fDate = LocalDate.parse(fromDate);
  1702. LocalDate tDate = LocalDate.parse(toDate);
  1703. List<LocalDate> dates = getDateRange(fDate, tDate);
  1704. for (LocalDate aa : dates) {
  1705. String uniqueId = aa.format(DateTimeFormatter.ofPattern("yyyyMMdd")) + hallId;
  1706. BookingCalendar data = getbyDates(aa, hallId.toString());
  1707. int userbookingbookingId = bookingIds.get(hallIdsList.indexOf(hallId));
  1708. if (data != null) {
  1709. System.out.println("uniqueId...1"+uniqueId);
  1710. data.setBookingId_1(String.valueOf(userbookingbookingId));
  1711. data.setBookingId_2(String.valueOf(userbookingbookingId));
  1712. data.setMorningSlot(true);
  1713. data.setEveningSlot(true);
  1714. data.setIs_blocked(true);
  1715. data.setUnique_id(uniqueId);
  1716. updateBookingStatus(data);
  1717. } else {
  1718. System.out.println("uniqueId...2"+uniqueId);
  1719. BookingCalendar book = new BookingCalendar();
  1720. book.setBdate(aa);
  1721. book.setBookingId_1(String.valueOf(userbookingbookingId));
  1722. book.setBookingId_2(String.valueOf(userbookingbookingId));
  1723. book.setMorningSlot(true);
  1724. book.setEveningSlot(true);
  1725. book.setHallId(hallId.intValue());
  1726. book.setIs_active(true);
  1727. book.setIs_booked(2);
  1728. book.setIs_delete(false);
  1729. book.setIs_blocked(true);
  1730. book.setUnique_id(uniqueId);
  1731. updateBookingStatus(book);
  1732. }
  1733. }
  1734. }
  1735. updateBookingStatusById(booking.getBookingId(), booking.getBookingStatus().GCC_BLOCKED, reasonforblocking);
  1736. //whatsup msg and SMS
  1737. String gccblockedsms = "Your booking ID " + bookingId + " on " + booking.getStartDate() + " has been blocked by GCC due to " + reasonforblocking + ". The entire amount paid will be refunded to your account with in 3 to 15 days.";
  1738. String gccblockedurlString = "https://tmegov.onex-aura.com/api/sms?key=pfTEYN6H&to=" + booking.getUsers().getMobileNo() + "&from=GCCCRP&body=" + gccblockedsms + "&entityid=1401572690000011081&templateid=1407172346521513227";
  1739. //String gccblockedwhatsupmsg="https://media.smsgupshup.com/GatewayAPI/rest?userid=2000233507&password=h2YjFNcJ&send_to="+booking.getUsers().getMobileNo()+"&v=1.1&format=json&msg_type=TEXT&method=SENDMESSAGE&msg=Your+booking+with+ID+"+booking.getBookingId()+"+on+"+booking.getBookingDate()+"+has+been+blocked+by+GCC+due+to+"+reasonforblocking+".+%0AThanks+for+using+GCC+Community+Hall+Booking+System.";
  1740. String gccblockedwhatsupmsg = "https://media.smsgupshup.com/GatewayAPI/rest?userid=2000233507&password=h2YjFNcJ&send_to=" + booking.getUsers().getMobileNo() + "&v=1.1&format=json&msg_type=TEXT&method=SENDMESSAGE&msg=Your+booking+with+ID+" + booking.getBookingId() + "+on+" + booking.getStartDate() + "+has+been+blocked+by+the+GCC+due+to+Goverment+event++.+%0AThe+entire+amount+paid+will+be+refunded+to+your+account+within+3+to+15+days.";
  1741. whatsappMsgServiceImpl.sendMsg(gccblockedwhatsupmsg);
  1742. whatsappMsgServiceImpl.sendSMS(gccblockedurlString);
  1743. bookingDetailsRepository.save(booking);
  1744. }
  1745. }
  1746. }
  1747. } else {
  1748. // Create and save a new GCC blocking date record
  1749. GccBlockingDate gcc = new GccBlockingDate();
  1750. gcc.setStartDate(convertStringToDate(fromDate));
  1751. gcc.setEndDate(convertStringToDate(toDate));
  1752. gcc.setHallId(String.join(",", hallIdsList.stream().map(String::valueOf).collect(Collectors.toList())));
  1753. gcc.setUpdatedBy(updatedBy);
  1754. gcc.setCdate(new Date());
  1755. gcc.setBlockingReason(reasonforblocking);
  1756. GccBlockingHistory gccblockinghistory = new GccBlockingHistory();
  1757. gccblockinghistory.setStartDate(convertStringToDate(fromDate));
  1758. gccblockinghistory.setEndDate(convertStringToDate(toDate));
  1759. gccblockinghistory.setHallId(String.join(",", hallIdsList.stream().map(String::valueOf).collect(Collectors.toList())));
  1760. gccblockinghistory.setUpdatedBy(updatedBy);
  1761. gccblockinghistory.setCdate(new Date());
  1762. gccblockinghistory.setBlockingReason(reasonforblocking);
  1763. List<Integer> bookingIds = saveGCCBlockingDate(gcc);
  1764. String bookingIdsString = bookingIds.stream()
  1765. .map(String::valueOf)
  1766. .collect(Collectors.joining(","));
  1767. gccblockinghistory.setBookingIds(bookingIdsString);
  1768. blockingHistoryRepository.save(gccblockinghistory);
  1769. if (documents != null && documents.length > 0) {
  1770. if (descriptions != null && descriptions.length == documents.length) {
  1771. int i = 0;
  1772. for (MultipartFile document : documents) {
  1773. String filePath = uploadDirectory + "/" + gcc.getBlockingId() + "_" + i + "_" + document.getOriginalFilename();
  1774. String documentUrl = serverPath + "gccblockingdocs/" + gcc.getBlockingId() + "_" + i + "_" + document.getOriginalFilename();
  1775. try (FileOutputStream fos = new FileOutputStream(filePath)) {
  1776. byte[] bytes = document.getBytes();
  1777. fos.write(bytes);
  1778. GccblockingDocuments documentDetails = new GccblockingDocuments();
  1779. documentDetails.setBlockingDate(gcc);
  1780. documentDetails.setBlockingDocument(documentUrl);
  1781. documentDetails.setDescription(descriptions[i]);
  1782. gccblockingDocumentsRepo.save(documentDetails);
  1783. } catch (IOException e) {
  1784. throw new RuntimeException("Failed to save document", e);
  1785. }
  1786. i++;
  1787. }
  1788. } else {
  1789. // Handle case where descriptions array length does not match documents length
  1790. }
  1791. }
  1792. // Iterate through hall IDs and corresponding dates to update BookingCalendar
  1793. for (Long hallId : hallIdsList) {
  1794. LocalDate fDate = LocalDate.parse(fromDate);
  1795. LocalDate tDate = LocalDate.parse(toDate);
  1796. List<LocalDate> dates = getDateRange(fDate, tDate);
  1797. for (LocalDate date : dates) {
  1798. BookingCalendar data = getbyDates(date, hallId.toString());
  1799. String uniqueId = date.format(DateTimeFormatter.ofPattern("yyyyMMdd")) + hallId;
  1800. int userbookingbookingId = bookingIds.get(hallIdsList.indexOf(hallId));
  1801. if (data != null) {
  1802. System.out.println("uniqueId...11"+uniqueId);
  1803. data.setBookingId_1(String.valueOf(userbookingbookingId));
  1804. data.setBookingId_2(String.valueOf(userbookingbookingId));
  1805. data.setMorningSlot(true);
  1806. data.setEveningSlot(true);
  1807. data.setIs_blocked(true);
  1808. data.setUnique_id(uniqueId);
  1809. updateBookingStatus(data);
  1810. } else {
  1811. System.out.println("uniqueId...21"+uniqueId);
  1812. BookingCalendar book = new BookingCalendar();
  1813. book.setBdate(date);
  1814. book.setBookingId_1(String.valueOf(userbookingbookingId));
  1815. book.setBookingId_2(String.valueOf(userbookingbookingId));
  1816. book.setMorningSlot(true);
  1817. book.setEveningSlot(true);
  1818. book.setHallId(hallId.intValue());
  1819. book.setIs_active(true);
  1820. book.setIs_booked(2);
  1821. book.setIs_delete(false);
  1822. book.setIs_blocked(true);
  1823. book.setUnique_id(uniqueId);
  1824. updateBookingStatus(book);
  1825. }
  1826. }
  1827. }
  1828. }
  1829. }
  1830. // Helper methods for date conversion and range calculation
  1831. public Date convertStringToDate(String dateString) {
  1832. SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
  1833. try {
  1834. return dateFormat.parse(dateString);
  1835. } catch (ParseException e) {
  1836. e.printStackTrace();
  1837. return null;
  1838. }
  1839. }
  1840. public static List<LocalDate> getDateRange(LocalDate fDate, LocalDate tDate) {
  1841. List<LocalDate> dateRange = new ArrayList<>();
  1842. LocalDate currentDate = fDate;
  1843. while (!currentDate.isAfter(tDate)) {
  1844. dateRange.add(currentDate);
  1845. currentDate = currentDate.plusDays(1);
  1846. }
  1847. return dateRange;
  1848. }
  1849. @Override
  1850. public List<BookingDetails> findBookingDetailsByBookingId(Long bookingId) {
  1851. return bookingDetailsRepository.findBookingDetailsByBookingId(bookingId);
  1852. }
  1853. //admin dashboard
  1854. @Override
  1855. public Map<String, Map<String, Integer>> getBookingStatistics(LocalDate fromDate, LocalDate toDate, String zone, String division, Integer hallid, String userType) {
  1856. List<Map<String, Object>> rawStatistics = bookingDetailsRepository.getBookingStatistics(fromDate, toDate, zone, division, hallid, userType);
  1857. return transformData(rawStatistics);
  1858. }
  1859. private Map<String, Map<String, Integer>> transformData(List<Map<String, Object>> rawStatistics) {
  1860. Map<String, Map<String, Integer>> transformedData = new HashMap<>();
  1861. for (Map<String, Object> entry : rawStatistics) {
  1862. if (entry.isEmpty()) continue; // Skip empty entries
  1863. String category = (String) entry.get("category");
  1864. String key = entry.get("key") != null ? (String) entry.get("key") : "total";
  1865. Integer totalCount = entry.get("totalCount") != null ? ((Number) entry.get("totalCount")).intValue() : 0;
  1866. transformedData.putIfAbsent(category, new HashMap<>());
  1867. transformedData.get(category).put(key, totalCount);
  1868. if (category.equals("main")) {
  1869. Integer mainTotalAmount = entry.get("main_total_amount") != null ? ((Number) entry.get("main_total_amount")).intValue() : 0;
  1870. Integer mainRefundedAmount = entry.get("main_refunded_amount") != null ? ((Number) entry.get("main_refunded_amount")).intValue() : 0;
  1871. Integer mainNetAmount = entry.get("main_net_amount") != null ? ((Number) entry.get("main_net_amount")).intValue() : 0;
  1872. Integer mainGstAmount = entry.get("main_gst_amount") != null ? ((Number) entry.get("main_gst_amount")).intValue() : 0;
  1873. transformedData.get(category).put("main_total_amount", mainTotalAmount);
  1874. transformedData.get(category).put("main_net_amount", mainNetAmount);
  1875. transformedData.get(category).put("main_refunded_amount", mainRefundedAmount);
  1876. transformedData.get(category).put("main_gst_amount", mainGstAmount);
  1877. }
  1878. if (category.equals("past_future")) {
  1879. Integer pastbooking = entry.get("PAST_Events") != null ? ((Number) entry.get("PAST_Events")).intValue() : 0;
  1880. Integer futurebooking = entry.get("FUTURE_Events") != null ? ((Number) entry.get("FUTURE_Events")).intValue() : 0;
  1881. transformedData.get(category).put("PAST_Events", pastbooking);
  1882. transformedData.get(category).put("FUTURE_Events", futurebooking);
  1883. }
  1884. }
  1885. return transformedData;
  1886. }
  1887. public List<Map<String, Object>> getBookingDetailsByHallId(int hallId) {
  1888. return bookingDetailsRepository.getBookingDetailsByHallId(hallId);
  1889. }
  1890. //officer Dashboard
  1891. @Override
  1892. public Map<String, Map<String, Integer>> getOfficerDashboard(LocalDate fromDate, LocalDate toDate, String zone, String division, Integer hallid, String userType) {
  1893. List<Map<String, Object>> rawStatistics = bookingDetailsRepository.getOfficerDashboard(fromDate, toDate, zone, division, hallid, userType);
  1894. return transformedData(rawStatistics);
  1895. }
  1896. private Map<String, Map<String, Integer>> transformedData(List<Map<String, Object>> rawStatistics) {
  1897. Map<String, Map<String, Integer>> transformedData = new HashMap<>();
  1898. for (Map<String, Object> entry : rawStatistics) {
  1899. if (entry.isEmpty()) continue; // Skip empty entries
  1900. String category = (String) entry.get("category");
  1901. String key = entry.get("key") != null ? (String) entry.get("key") : "total";
  1902. Integer totalCount = entry.get("totalCount") != null ? ((Number) entry.get("totalCount")).intValue() : 0;
  1903. transformedData.putIfAbsent(category, new HashMap<>());
  1904. transformedData.get(category).put(key, totalCount);
  1905. if (category.equals("main")) {
  1906. Integer mainTotalAmount = entry.get("main_total_amount") != null ? ((Number) entry.get("main_total_amount")).intValue() : 0;
  1907. Integer mainNetAmount = entry.get("main_net_amount") != null ? ((Number) entry.get("main_net_amount")).intValue() : 0;
  1908. Integer mainRefundedAmount = entry.get("main_refunded_amount") != null ? ((Number) entry.get("main_refunded_amount")).intValue() : 0;
  1909. transformedData.get(category).put("main_total_amount", mainTotalAmount);
  1910. transformedData.get(category).put("main_net_amount", mainNetAmount);
  1911. transformedData.get(category).put("main_refunded_amount", mainRefundedAmount);
  1912. }
  1913. if (category.equals("past_future")) {
  1914. Integer pastbooking = entry.get("PAST_Events") != null ? ((Number) entry.get("PAST_Events")).intValue() : 0;
  1915. Integer futurebooking = entry.get("FUTURE_Events") != null ? ((Number) entry.get("FUTURE_Events")).intValue() : 0;
  1916. transformedData.get(category).put("PAST_Events", pastbooking);
  1917. transformedData.get(category).put("FUTURE_Events", futurebooking);
  1918. }
  1919. }
  1920. return transformedData;
  1921. }
  1922. @Override
  1923. public List<Map<String, Object>> getHallDetailsForOfficer(Integer hallIid) {
  1924. // TODO Auto-generated method stub
  1925. return bookingDetailsRepository.getHallDetailsForOfficer(hallIid);
  1926. }
  1927. // @Override
  1928. // public List<Object[]> getAllPaymentsDetails(String fromDate, String toDate, String paymentStatus) {
  1929. // // TODO Auto-generated method stub
  1930. // return bookingDetailsRepository.getAllPaymentsDetails(fromDate, toDate,paymentStatus);
  1931. // }
  1932. //
  1933. //admin reports
  1934. @Override
  1935. public List<Object[]> getBookingDetailsByBookingDate(String fromDate, String toDate, String zone, String division, Integer hallid) {
  1936. // TODO Auto-generated method stub
  1937. return bookingDetailsRepository.getBookingDetailsByBookingDate(fromDate, toDate, zone, division, hallid);
  1938. }
  1939. @Override
  1940. public List<Object[]> getBookingDetailsByEventDate(String fromDate, String toDate, String zone, String division, Integer hallid) {
  1941. // TODO Auto-generated method stub
  1942. return bookingDetailsRepository.getBookingDetailsByEventDate(fromDate, toDate, zone, division, hallid);
  1943. }
  1944. @Override
  1945. public List<Object[]> getBookingDetailsByBookingDateWithStatus(String fromDate, String toDate,
  1946. String bookingStatus, String zone, String division, Integer hallid) {
  1947. // TODO Auto-generated method stub
  1948. return bookingDetailsRepository.getBookingDetailsByBookingDateWithStatus(fromDate, toDate, bookingStatus, zone, division, hallid);
  1949. }
  1950. @Override
  1951. public List<Object[]> getBookingDetailsByEventDateWithStatus(String fromDate, String toDate,
  1952. String bookingStatus, String zone, String division, Integer hallid) {
  1953. // TODO Auto-generated method stub
  1954. return bookingDetailsRepository.getBookingDetailsByEventDateWithStatus(fromDate, toDate, bookingStatus, zone, division, hallid);
  1955. }
  1956. @Override
  1957. public List<Object[]> getAllPaymentsDetails(String fromDate, String toDate, String paymentStatus, String zone, String division, Integer hallid) {
  1958. // TODO Auto-generated method stub
  1959. return bookingDetailsRepository.getAllPaymentsDetails(fromDate, toDate, paymentStatus, zone, division, hallid);
  1960. }
  1961. @Override
  1962. public List<Object[]> getAllExtraPaymentsDetails(String fromDate, String toDate, String paymentStatus, String zone, String division, Integer hallid) {
  1963. // TODO Auto-generated method stub
  1964. return bookingDetailsRepository.getAllExtraPaymentsDetails(fromDate, toDate, paymentStatus, zone, division, hallid);
  1965. }
  1966. @Override
  1967. public List<Object[]> getBookingHallDetailsReportByBookingDate(String fromDate, String toDate, String zone, String division, Integer hallid) {
  1968. // TODO Auto-generated method stub
  1969. return bookingDetailsRepository.getBookingHallDetailsReportByBookingDate(fromDate, toDate, zone, division, hallid);
  1970. }
  1971. @Override
  1972. public List<Object[]> getBookingHallDetailsReportByEventDate(String fromDate, String toDate, String zone, String division, Integer hallid) {
  1973. // TODO Auto-generated method stub
  1974. return bookingDetailsRepository.getBookingHallDetailsReportByEventDate(fromDate, toDate, zone, division, hallid);
  1975. }
  1976. @Override
  1977. public List<BookingDetails> getAllBookingsettlementDetailsByBookingDate(String fromDate, String toDate) {
  1978. // TODO Auto-generated method stub
  1979. return bookingDetailsRepository.getAllBookingsettlementDetailsByBookingDate(fromDate, toDate);
  1980. }
  1981. @Override
  1982. public List<BookingDetails> getAllBookingsettlementDetailsByBookingDateWithStatus(String fromDate,
  1983. String toDate, String refundStatus) {
  1984. // TODO Auto-generated method stub
  1985. return bookingDetailsRepository.getAllBookingsettlementDetailsByBookingDateWithStatus(fromDate, toDate, refundStatus);
  1986. }
  1987. @Override
  1988. public List<BookingDetails> getAllBookingsettlementDetailsByEventDate(String fromDate, String toDate) {
  1989. // TODO Auto-generated method stub
  1990. return bookingDetailsRepository.getAllBookingsettlementDetailsByEventDate(fromDate, toDate);
  1991. }
  1992. @Override
  1993. public List<BookingDetails> getAllBookingsettlementDetailsByEventDateWithStatus(String fromDate,
  1994. String toDate, String refundStatus) {
  1995. // TODO Auto-generated method stub
  1996. return bookingDetailsRepository.getAllBookingsettlementDetailsByEventDateWithStatus(fromDate, toDate, refundStatus);
  1997. }
  1998. @Override
  1999. public List<BookingDetails> getAllBookingDetailsBookingDateByZone(String fromDate, String toDate,
  2000. String zone) {
  2001. // TODO Auto-generated method stub
  2002. return bookingDetailsRepository.getAllBookingDetailsBookingDateByZone(fromDate, toDate, zone);
  2003. }
  2004. @Override
  2005. public List<BookingDetails> getAllBookingDetailsEventDateByZone(String fromDate, String toDate,
  2006. String zone) {
  2007. // TODO Auto-generated method stub
  2008. return bookingDetailsRepository.getAllBookingDetailsEventDateByZone(fromDate, toDate, zone);
  2009. }
  2010. @Override
  2011. public List<BookingDetails> getAllBookingDetailsBookingDateByZoneWithStatus(String fromDate, String toDate,
  2012. String zone, String bookingStatus) {
  2013. // TODO Auto-generated method stub
  2014. return bookingDetailsRepository.getAllBookingDetailsBookingDateByZoneWithStatus(fromDate, toDate, zone, bookingStatus);
  2015. }
  2016. @Override
  2017. public List<BookingDetails> getAllBookingDetailsEventDateByZoneWithStatus(String fromDate, String toDate,
  2018. String zone, String bookingStatus) {
  2019. // TODO Auto-generated method stub
  2020. return bookingDetailsRepository.getAllBookingDetailsEventDateByZoneWithStatus(fromDate, toDate, zone, bookingStatus);
  2021. }
  2022. @Override
  2023. public List<BookingDetails> getAllBookingsettlementDetailsByZoneByBookingDate(String fromDate,
  2024. String toDate, String zone) {
  2025. // TODO Auto-generated method stub
  2026. return bookingDetailsRepository.getAllBookingsettlementDetailsByZoneByBookingDate(fromDate, toDate, zone);
  2027. }
  2028. @Override
  2029. public List<BookingDetails> getAllBookingsettlementDetailsByZoneByEventDate(String fromDate, String toDate,
  2030. String zone) {
  2031. // TODO Auto-generated method stub
  2032. return bookingDetailsRepository.getAllBookingsettlementDetailsByZoneByEventDate(fromDate, toDate, zone);
  2033. }
  2034. @Override
  2035. public List<BookingDetails> getAllBookingsettlementDetailsByZoneByBookingDateWithStatus(String fromDate,
  2036. String toDate, String zone, String refundStatus) {
  2037. // TODO Auto-generated method stub
  2038. return bookingDetailsRepository.getAllBookingsettlementDetailsByZoneByBookingDateWithStatus(fromDate, toDate, zone, refundStatus);
  2039. }
  2040. @Override
  2041. public List<BookingDetails> getAllBookingsettlementDetailsByZoneByEventDateWithStatus(String fromDate,
  2042. String toDate, String zone, String refundStatus) {
  2043. // TODO Auto-generated method stub
  2044. return bookingDetailsRepository.getAllBookingsettlementDetailsByZoneByEventDateWithStatus(fromDate, toDate, zone, refundStatus);
  2045. }
  2046. @Override
  2047. public List<Object[]> getBookingHallDetailsReportByZoneByBookingDate(String fromDate, String toDate,
  2048. String zone) {
  2049. // TODO Auto-generated method stub
  2050. return bookingDetailsRepository.getBookingHallDetailsReportByZoneByBookingDate(fromDate, toDate, zone);
  2051. }
  2052. @Override
  2053. public List<Object[]> getBookingHallDetailsReportByZoneByEventDate(String fromDate, String toDate,
  2054. String zone) {
  2055. // TODO Auto-generated method stub
  2056. return bookingDetailsRepository.getBookingHallDetailsReportByZoneByEventDate(fromDate, toDate, zone);
  2057. }
  2058. @Override
  2059. public List<Object[]> getBookingHallDetailsReportByZoneByBookingDateHallname(String fromDate, String toDate,
  2060. String zone, Integer hallId) {
  2061. // TODO Auto-generated method stub
  2062. return bookingDetailsRepository.getBookingHallDetailsReportByZoneByBookingDateHallname(fromDate, toDate, zone, hallId);
  2063. }
  2064. @Override
  2065. public List<Object[]> getBookingHallDetailsReportByZoneByEventDateHallname(String fromDate, String toDate,
  2066. String zone, Integer hallId) {
  2067. // TODO Auto-generated method stub
  2068. return bookingDetailsRepository.getBookingHallDetailsReportByZoneByEventDateHallname(fromDate, toDate, zone, hallId);
  2069. }
  2070. //gccapps
  2071. @Override
  2072. public List<BookingDetails> getApprovedBookingDetails() {
  2073. return bookingDetailsRepository.findByBookingStatus(BookingDetails.BookingStatus.APPROVED);
  2074. }
  2075. @Override
  2076. public List<BookingDetails> getRejectedBookingDetails() {
  2077. return bookingDetailsRepository.findByBookingStatus(BookingDetails.BookingStatus.REJECTED);
  2078. }
  2079. @Override
  2080. public List<BookingDetails> getWaitingforNOCapproval() {
  2081. return bookingDetailsRepository.findByBookingStatus(BookingDetails.BookingStatus.WAITING_FOR_NOC_APPROVAL);
  2082. }
  2083. @Override
  2084. public List<Object[]> getAllPaymentsDetails(String fromDate, String toDate) {
  2085. // TODO Auto-generated method stub
  2086. //return bookingDetailsRepository.getAllPaymentsDetails(fromDate, toDate);
  2087. return null;
  2088. }
  2089. @Override
  2090. public List<BookingDetails> getPastsEvents() {
  2091. return bookingDetailsRepository.findPastsEvents();
  2092. }
  2093. @Override
  2094. public List<BookingDetails> getPresentsEvents() {
  2095. return bookingDetailsRepository.findPresentsEvents();
  2096. }
  2097. @Override
  2098. public List<BookingDetails> getFuturesEvents() {
  2099. return bookingDetailsRepository.findFuturesEvents();
  2100. }
  2101. @Override
  2102. public List<BookingDetails> getSettlementApprovedList() {
  2103. return bookingDetailsRepository.getSettlementApprovedList();
  2104. }
  2105. @Override
  2106. public List<Map<String, Object>> getHallDetails(Integer hall_id) {
  2107. // TODO Auto-generated method stub
  2108. //return bookingDetailsRepository.getHallDetails(hall_id);
  2109. return null;
  2110. }
  2111. public List<Object[]> getUserDetailsByBookingDate(String fromDate, String toDate) {
  2112. return userRepository.findUserDetailsByBookingDate(fromDate, toDate);
  2113. }
  2114. //developer
  2115. @Override
  2116. public List<Object[]> getTransactionresponse(String fromDate, String toDate, Long bookingId, Long hallId) {
  2117. return transactionResponseRepository.getTransactionResponseByBookingId(fromDate, toDate, bookingId, hallId);
  2118. }
  2119. @Override
  2120. public List<Object[]> getRefundResponse(String fromDate, String toDate, Long bookingId) {
  2121. return transRefundResRepository.getRefundResponseByBookingId(fromDate, toDate, bookingId);
  2122. }
  2123. @Override
  2124. public List<Object[]> getBookingCalendarDetails(String fromDate, String toDate, Long bookingId, String hallName) {
  2125. return bookingCalendarRepository.findBookingCalendarDetails(fromDate, toDate, bookingId, hallName);
  2126. }
  2127. @Override
  2128. public List<BookingDetails> getBookingsByDateAndHall(String bookingDate, Long hallId) {
  2129. LocalDate date = LocalDate.parse(bookingDate); // Ensure format matches yyyy-MM-dd
  2130. return bookingDetailsRepository.findByBookingDateAndHallId(date, hallId);
  2131. }
  2132. @Override
  2133. @Transactional
  2134. public BookingDetails updateRefundStatusScheduler(int bookingId, RefundStatus status) {
  2135. Optional<BookingDetails> booking = bookingDetailsRepository.findById(bookingId);
  2136. if (booking.isPresent()) {
  2137. String adminname = "Refund Scheduler";
  2138. BookingDetails book = booking.get();
  2139. book.setRefundStatus(status);
  2140. book.setComments("Refund status Updated to:-" + status);
  2141. BookingDetails bookings = bookingDetailsRepository.save(book);
  2142. BookingHistory bookingHistory = new BookingHistory();
  2143. bookingHistory.setStartDate(book.getStartDate());
  2144. bookingHistory.setEndDate(book.getEndDate());
  2145. bookingHistory.setComments(book.getComments());
  2146. bookingHistory.setBookingDetails(book);
  2147. bookingHistory.setBookingStatus(book.getBookingStatus());
  2148. bookingHistory.setUpdatedBy(adminname);
  2149. bookingHistory.setCdate(new Date());
  2150. bookingHistory.setRefundStatus(book.getRefundStatus());
  2151. bookingHistoryRepository.save(bookingHistory);
  2152. return bookings;
  2153. }
  2154. return null;
  2155. }
  2156. }