diff --git a/.vscode/settings.json b/.vscode/settings.json index 7b016a89..e0120650 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,3 +1,4 @@ { - "java.compile.nullAnalysis.mode": "automatic" + "java.compile.nullAnalysis.mode": "automatic", + "java.configuration.updateBuildConfiguration": "interactive" } \ No newline at end of file diff --git a/jwtToken.txt b/jwtToken.txt index 9014d974..65bcc2e5 100644 --- a/jwtToken.txt +++ b/jwtToken.txt @@ -1 +1 @@ -eyJhbGciOiJIUzUxMiJ9.eyJ1c2VyVHlwZSI6ImhlYWRxdWFydGVycyIsImhhbGxJZCI6MCwiaGFsbElkcyI6IiIsIm1vYmlsZU51bWJlciI6OTUxNzUzODUyNCwiem9uZSI6IjAwIiwiZXhwIjoxNzgzOTI4NDY4fQ.JDuWljfRXzemAjgmLj4MFq3DgmL9Z1hbE8_LoLpQQ0jLZp4wBbyvmEopk9BHmWtzh8SlDN6dxQHEJDsxTRt0_Q \ No newline at end of file +eyJhbGciOiJIUzUxMiJ9.eyJ1c2VyVHlwZSI6ImhlYWRxdWFydGVycyIsImhhbGxJZCI6MCwiaGFsbElkcyI6IiIsIm1vYmlsZU51bWJlciI6OTUxNzUzODUyNCwiem9uZSI6IjAwIiwiZXhwIjoxNzg1MzI4MDYwfQ.aXxOu_OHvSMRSKZFqyQzzi9rFw8KCuC5m-Hv4QNSk36_lWZCcZJSvbPHDyQKyELJkbZdURa9p0dd6sPmDoZsLg \ No newline at end of file diff --git a/src/main/java/com/gcc/communityHall/controller/HeadquartersController.java b/src/main/java/com/gcc/communityHall/controller/HeadquartersController.java index 153ac4b4..f792789e 100644 --- a/src/main/java/com/gcc/communityHall/controller/HeadquartersController.java +++ b/src/main/java/com/gcc/communityHall/controller/HeadquartersController.java @@ -1177,11 +1177,6 @@ public class HeadquartersController { return result; } - /** - * Marks a booking as "mail sent": - * 1. Stamps mail_sent = 1, mail_sent_date = NOW() on booking_details. - * 2. Inserts a row into six_month_mail_log for audit history. - */ @PostMapping("/sixmonthold-transactions/markMailSent") @ResponseBody @Transactional @@ -1206,7 +1201,7 @@ public class HeadquartersController { String mailBody = mailService.sendRefundFollowupMail( bookingId, bookingStatus, transactionId, tpslId, transactionDate, refundAmount); - // 2. Stamp booking_details: mail_sent = 1, mail_sent_date = NOW() + // 2. Update booking_details: mail_sent = 1, mail_sent_date = NOW() bookingDetailsRepository.markMailSent(bookingId); // 3. Write audit log entry @@ -1223,24 +1218,6 @@ public class HeadquartersController { return response; } - /** - * Update Refund Details for Mail Sent Bookings (new method – does NOT touch - * existing endpoints). - * - * ID logic: - * - Cancelled / Rejected → bookingId is the primary reference. - * - Approved → settlementId is the primary reference; - * bookingId used to fetch BookingDetails. - * - * Tables updated (in order): - * 1. booking_history – archive current BookingDetails snapshot. - * 2. booking_details – bookingStatus=COMPLETED, refundStatus=COMPLETED. - * 3. settlement_history – archive Settlement snapshot (APPROVED only). - * 4. settlement – update comments + updatedDate (APPROVED only). - * 5. refund_transaction – upsert. - * 6. refund_response – upsert with arn_number. - * 7. application_logs – audit entry. - */ @PostMapping("/sixmonthold-transactions/updateRefundDetails") @ResponseBody @Transactional diff --git a/src/main/java/com/gcc/communityHall/controller/UserAPIController.java b/src/main/java/com/gcc/communityHall/controller/UserAPIController.java index 70e59481..18bfc3d4 100644 --- a/src/main/java/com/gcc/communityHall/controller/UserAPIController.java +++ b/src/main/java/com/gcc/communityHall/controller/UserAPIController.java @@ -1329,9 +1329,12 @@ public class UserAPIController { public ResponseEntity updateBookingDates( @RequestParam int bookingId, @RequestParam String startDate, - @RequestParam String endDate) { + @RequestParam String endDate, + @RequestParam(required = false, defaultValue = "0") int startingSlot, + @RequestParam(required = false, defaultValue = "0") int endingSlot) { try { - Optional updateResult = bookingService.updateBookingDatesAndCalendar(bookingId, startDate, endDate); + Optional updateResult = bookingService.updateBookingDatesAndCalendar( + bookingId, startDate, endDate, startingSlot, endingSlot); if (updateResult.isPresent()) { if (updateResult.get().equals("Booking dates updated successfully.")) { return new ResponseEntity<>(updateResult.get(), HttpStatus.OK); diff --git a/src/main/java/com/gcc/communityHall/entity/BookingDetails.java b/src/main/java/com/gcc/communityHall/entity/BookingDetails.java index 7f42a4af..9f79582f 100644 --- a/src/main/java/com/gcc/communityHall/entity/BookingDetails.java +++ b/src/main/java/com/gcc/communityHall/entity/BookingDetails.java @@ -5,6 +5,8 @@ import java.time.LocalDateTime; import java.util.List; import com.fasterxml.jackson.annotation.JsonIgnore; +import com.gcc.communityHall.paymentService.entity.RefundResponse; + import jakarta.persistence.*; @Entity diff --git a/src/main/java/com/gcc/communityHall/paymentService/controller/PaymentAPIController.java b/src/main/java/com/gcc/communityHall/paymentService/controller/PaymentAPIController.java index 24d70a96..79bb291a 100644 --- a/src/main/java/com/gcc/communityHall/paymentService/controller/PaymentAPIController.java +++ b/src/main/java/com/gcc/communityHall/paymentService/controller/PaymentAPIController.java @@ -1,7 +1,8 @@ package com.gcc.communityHall.paymentService.controller; - import java.security.NoSuchAlgorithmException; +import java.time.LocalDate; +import java.time.format.DateTimeFormatter; import java.util.HashMap; import java.util.Optional; @@ -17,6 +18,7 @@ import org.springframework.web.bind.annotation.RestController; import org.springframework.web.client.RestTemplate; import com.fasterxml.jackson.databind.ObjectMapper; +import com.gcc.communityHall.entity.BookingCalendar; import com.gcc.communityHall.entity.BookingDetails; import com.gcc.communityHall.entity.Users; import com.gcc.communityHall.paymentService.DTO.Merchant; @@ -28,6 +30,7 @@ import com.gcc.communityHall.paymentService.entity.TransactionResponse; import com.gcc.communityHall.paymentService.refund.DTO.TransactionRefundResponse; import com.gcc.communityHall.paymentService.service.PaymentGatewayService; import com.gcc.communityHall.paymentService.service.TransactionNumberGenerator; +import com.gcc.communityHall.repository.BookingCalendarRepository; import com.gcc.communityHall.repository.BookingDetailsRepository; import com.google.gson.Gson; @@ -35,12 +38,7 @@ import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.tags.Tag; import lombok.AllArgsConstructor; - - -@Tag( - name = "CRUD REST APIs for Payment in CommunityHall", - description = "CRUD REST APIs in CommunityHall to CREATE, UPDATE, FETCH AND DELETE Booking details" -) +@Tag(name = "CRUD REST APIs for Payment in CommunityHall", description = "CRUD REST APIs in CommunityHall to CREATE, UPDATE, FETCH AND DELETE Booking details") @RestController @RequestMapping("/communityhall/payment/api") @AllArgsConstructor @@ -56,176 +54,275 @@ public class PaymentAPIController { @Autowired private BookingDetailsRepository bookRepo; + @Autowired + private BookingCalendarRepository bookingCalendarRepository; + @Autowired private TransactionNumberGenerator transactionNumber; + // @Operation( + // summary = "Refund the Total Amount REST API", + // description = "REST API to refunding the Total Amount if the admin will + // cancel and block the hall" + // ) + // @GetMapping(value="/refund") + // public ResponseEntity refundAmount(Model model,@RequestParam int + // bookingId) throws Exception { + // //System.out.println("Refund Api call.......working on it"); + // TransactionResponse transactionRes = + // this.paymentService.getTransactionResponseByBookingIdAndStatusCode(bookingId,this.paymentConfig.getTransactionSuccessCode()); + // RefundResponse recordRefundResponse = new RefundResponse(); + // + // Merchant merchant = new Merchant(); + // merchant.setIdentifier(this.paymentConfig.getMerchantId()); + // + // Transaction transaction = new Transaction(); + // transaction.setAmount(transactionRes.getAmount());//Amount given here + // transaction.setIdentifier(""); + // String[] datestime = transactionRes.getDate().split(" "); + // transaction.setDateTime(datestime[0]); //At what date transaction happens + // transaction.setRequestType("R"); + // transaction.setToken(""); + // transaction.setReference(transactionRes.getTpslTxnId()); //tpsl refer number + // + // TransactionData transactionData = new TransactionData(); + // transactionData.setMerchant(merchant); + // transactionData.setTransaction(transaction); + // + // // Serialize TransactionData object to JSON string + // Gson gson = new Gson(); + // String json = gson.toJson(transactionData); + // //System.out.println(json); + // + // String encryptHxRefund = this.paymentService.encryptHxRefund(json); + // RestTemplate resttemplate = new RestTemplate(); + // String Url + // ="https://www.tpsl-india.in/PaymentGateway/merchant2.pg/"+this.paymentConfig.getMerchantId(); + // ResponseEntity postForEntity = resttemplate.postForEntity(Url, + // encryptHxRefund, String.class); + // + // String decryptHxTRefund = + // this.paymentService.decryptHxTRefund(postForEntity.getBody()); + // recordRefundResponse.setResponse(decryptHxTRefund); + // //recordRefundResponse.setUserId("2");//make it dynamic + // recordRefundResponse.setBookingId(bookingId); + // try { + // ObjectMapper objectMapper = new ObjectMapper(); + // + // TransactionRefundResponse myObject = objectMapper.readValue(decryptHxTRefund, + // TransactionRefundResponse.class); + // //System.out.println(myObject.toString()); + // + // if(myObject.getPaymentMethod().getPaymentTransaction().getStatusCode().equals(this.paymentConfig.getRefundSuccessCode())) + // { + // //System.out.println("Refund Process complete........"+bookingId); + // recordRefundResponse.setAmount(myObject.getPaymentMethod().getPaymentTransaction().getAmount()); + // recordRefundResponse.setBalaceAmount(myObject.getPaymentMethod().getPaymentTransaction().getBalanceAmount()); + // } + // recordRefundResponse.setStatusCode(myObject.getPaymentMethod().getPaymentTransaction().getStatusCode()); + // recordRefundResponse.setTxansactionId(myObject.getMerchantTransactionIdentifier()); + // + // this.paymentService.recordRefund(recordRefundResponse); + // return ResponseEntity.ok(myObject); + // + // } catch (Exception e) { + // e.printStackTrace(); + // } + // return ResponseEntity.ok(decryptHxTRefund); + // + // } + + @Operation(summary = "payment-request REST API", description = "REST API payment-request") + @PostMapping(value = { "/payment-request" }) + public HashMap startPayment(int userId, int bookingId) throws NoSuchAlgorithmException { + + // System.out.println("I entered payment Service......"+bookingId+ "User Id :- + // "+userId); + HashMap hs = new HashMap<>(); + Optional findById = bookRepo.findById(bookingId); + + if (findById.isPresent()) { + // System.out.println("Success in finding booking Id"); + BookingDetails booking = findById.get(); + + // --- Slot Availability Check --- + String startDateStr = booking.getStartDate(); + String endDateStr = booking.getEndDate(); + int startingSlot = booking.getStartingSlot(); + int endingSlot = booking.getEndingSlot(); + int hallId = booking.getHallDetails().getHallId(); + String currentBookingIdStr = String.valueOf(bookingId); + + if (startDateStr != null && endDateStr != null) { + LocalDate startDate = LocalDate.parse(startDateStr, DateTimeFormatter.ofPattern("yyyy-MM-dd")); + LocalDate endDate = LocalDate.parse(endDateStr, DateTimeFormatter.ofPattern("yyyy-MM-dd")); + + int dayIndex = 0; + for (LocalDate date = startDate; !date.isAfter(endDate); date = date.plusDays(1)) { + BookingCalendar calEntry = bookingCalendarRepository.findByBdateAndHallId(date, hallId); + if (calEntry == null) { + dayIndex++; + continue; // No entry means this date is free + } + + // Determine which slots are occupied by OTHER bookings (exclude this booking) + boolean morningOccupied = calEntry.isMorningSlot() + && !currentBookingIdStr.equals(calEntry.getBookingId_1()); + boolean eveningOccupied = calEntry.isEveningSlot() + && !currentBookingIdStr.equals(calEntry.getBookingId_2()); + + boolean isConflict = false; + + if (date.equals(startDate) && date.equals(endDate)) { + // Single-day booking + if (startingSlot == 1 && endingSlot == 2) { + // Full day needed - conflict if morning or evening is taken + isConflict = morningOccupied || eveningOccupied; + } else if (startingSlot == 1) { + isConflict = morningOccupied; + } else if (startingSlot == 2 || endingSlot == 2) { + isConflict = eveningOccupied; + } + } else if (date.equals(startDate)) { + // Start day of a multi-day booking + if (startingSlot == 1) { + // Morning start: needs morning + evening on start day + isConflict = morningOccupied || eveningOccupied; + } else { + // Evening start: needs only evening on start day + isConflict = eveningOccupied; + } + } else if (date.equals(endDate)) { + // End day of a multi-day booking + if (endingSlot == 1) { + // Morning end: needs only morning on end day + isConflict = morningOccupied; + } else { + // Evening end: needs both morning and evening on end day + isConflict = morningOccupied || eveningOccupied; + } + } else { + // Middle day: entire day must be free + isConflict = morningOccupied || eveningOccupied; + } + + if (isConflict) { + hs.put("error", true); + hs.put("slotOccupied", true); + hs.put("occupiedDate", date.toString()); + hs.put("message", + "The selected date " + date + " is already occupied. Please Change your dates."); + hs.put("hallId", hallId); + return hs; + } + + dayIndex++; + } + } + // --- End Slot Availability Check --- + + Users user = booking.getUsers(); + int findUserId = user.getUserId(); + // System.out.println("Merchant ID:-"+this.paymentConfig.getMerchantId()); + + String txnId = "CHB" + transactionNumber.generateTransactionNumber() + String.format("%05d", findUserId); // create + // unique + // transaction + // Id + // from + // our + // side + + String totalAmt = String.valueOf(booking.getAmountReceived()); // Amount of Community Hall from our side + TransactionResponse response = new TransactionResponse(); + response.setTxansactionId(txnId); + response.setHallId(booking.getHallDetails().getHallId()); + response.setUserId(String.valueOf(findUserId));// make it dynamic + response.setStatusCode("temp"); + response.setBookingId(bookingId); + this.paymentService.recordResponse(response); + + String merchantId = this.paymentConfig.getMerchantId(); // This is Test Merchant ID from worldLine + String consumerId = String.format("%05d", findUserId); // Replace consumer ID in c964634 from our side + String consumerMobileNo = String.valueOf(user.getMobileNo()); // Replace consumer Mobile no in 9879879870 + // from our side + String consumerEmailId = user.getEmail(); // replace consumer email Id + + String encryptedtoken = this.paymentService.getToken(merchantId + "|", txnId + "|", totalAmt + "|", "|", + consumerId + "|", consumerMobileNo + "|", consumerEmailId + "|", "|", "|", "|", "|", "|", "|", "|", + "|", "|", this.paymentConfig.getEncryptionKey()); + + hs.put("txansactionId", txnId); + hs.put("token", encryptedtoken); + hs.put("amount", totalAmt); + hs.put("merchantId", merchantId); + hs.put("consumerMobileNo", consumerMobileNo); + hs.put("consumerEmailId", consumerEmailId); + hs.put("consumerId", consumerId); + hs.put("error", false); + } else { + hs.put("error", true); + } + + return hs; + } + + @Operation(summary = "Additional Damage payment-request REST API", description = "REST API Additional Damage payment-request") + @PostMapping(value = { "/additionaldamage-payment-request" }) + public HashMap startextraPayment(int userId, int bookingId) throws NoSuchAlgorithmException { + + // System.out.println("I entered payment Service......"+bookingId+ "User Id :- + // "+userId); + HashMap hs = new HashMap<>(); + Optional findById = bookRepo.findById(bookingId); + + if (findById.isPresent()) { + // System.out.println("Success in finding booking Id"); + BookingDetails booking = findById.get(); + Users user = booking.getUsers(); + int findUserId = user.getUserId(); + // System.out.println("Merchant ID:-"+this.paymentConfig.getMerchantId()); + + String txnId = "CHBED" + transactionNumber.generateTransactionNumber() + String.format("%05d", findUserId); // create + // transaction + // Id + // unique + // from + // our + // side + String totalAmt = String.valueOf(booking.getSettlement().getCollectionPending()); // Amount of Community + // Hall from our side + TransactionResponse response = new TransactionResponse(); + response.setTxansactionId(txnId); + response.setHallId(booking.getHallDetails().getHallId()); + response.setUserId(String.valueOf(findUserId));// make it dynamic + response.setStatusCode("temp"); + response.setBookingId(bookingId); + this.paymentService.recordResponse(response); + + String merchantId = this.paymentConfig.getMerchantId(); // This is Test Merchant ID from worldLine + String consumerId = String.format("%05d", findUserId); // Replace consumer ID in c964634 from our side + String consumerMobileNo = String.valueOf(user.getMobileNo()); // Replace consumer Mobile no in 9879879870 + // from our side + String consumerEmailId = user.getEmail(); // replace consumer email Id + + String encryptedtoken = this.paymentService.getToken(merchantId + "|", txnId + "|", totalAmt + "|", "|", + consumerId + "|", consumerMobileNo + "|", consumerEmailId + "|", "|", "|", "|", "|", "|", "|", "|", + "|", "|", this.paymentConfig.getEncryptionKey()); + System.out.println(totalAmt); + hs.put("txansactionId", txnId); + hs.put("token", encryptedtoken); + hs.put("amount", totalAmt); + hs.put("merchantId", merchantId); + hs.put("consumerMobileNo", consumerMobileNo); + hs.put("consumerEmailId", consumerEmailId); + hs.put("consumerId", consumerId); + hs.put("error", false); + } else { + hs.put("error", true); + } -// @Operation( -// summary = "Refund the Total Amount REST API", -// description = "REST API to refunding the Total Amount if the admin will cancel and block the hall" -// ) -// @GetMapping(value="/refund") -// public ResponseEntity refundAmount(Model model,@RequestParam int bookingId) throws Exception { -// //System.out.println("Refund Api call.......working on it"); -// TransactionResponse transactionRes = this.paymentService.getTransactionResponseByBookingIdAndStatusCode(bookingId,this.paymentConfig.getTransactionSuccessCode()); -// RefundResponse recordRefundResponse = new RefundResponse(); -// -// Merchant merchant = new Merchant(); -// merchant.setIdentifier(this.paymentConfig.getMerchantId()); -// -// Transaction transaction = new Transaction(); -// transaction.setAmount(transactionRes.getAmount());//Amount given here -// transaction.setIdentifier(""); -// String[] datestime = transactionRes.getDate().split(" "); -// transaction.setDateTime(datestime[0]); //At what date transaction happens -// transaction.setRequestType("R"); -// transaction.setToken(""); -// transaction.setReference(transactionRes.getTpslTxnId()); //tpsl refer number -// -// TransactionData transactionData = new TransactionData(); -// transactionData.setMerchant(merchant); -// transactionData.setTransaction(transaction); -// -// // Serialize TransactionData object to JSON string -// Gson gson = new Gson(); -// String json = gson.toJson(transactionData); -// //System.out.println(json); -// -// String encryptHxRefund = this.paymentService.encryptHxRefund(json); -// RestTemplate resttemplate = new RestTemplate(); -// String Url ="https://www.tpsl-india.in/PaymentGateway/merchant2.pg/"+this.paymentConfig.getMerchantId(); -// ResponseEntity postForEntity = resttemplate.postForEntity(Url, encryptHxRefund, String.class); -// -// String decryptHxTRefund = this.paymentService.decryptHxTRefund(postForEntity.getBody()); -// recordRefundResponse.setResponse(decryptHxTRefund); -// //recordRefundResponse.setUserId("2");//make it dynamic -// recordRefundResponse.setBookingId(bookingId); -// try { -// ObjectMapper objectMapper = new ObjectMapper(); -// -// TransactionRefundResponse myObject = objectMapper.readValue(decryptHxTRefund, TransactionRefundResponse.class); -// //System.out.println(myObject.toString()); -// -// if(myObject.getPaymentMethod().getPaymentTransaction().getStatusCode().equals(this.paymentConfig.getRefundSuccessCode())) { -// //System.out.println("Refund Process complete........"+bookingId); -// recordRefundResponse.setAmount(myObject.getPaymentMethod().getPaymentTransaction().getAmount()); -// recordRefundResponse.setBalaceAmount(myObject.getPaymentMethod().getPaymentTransaction().getBalanceAmount()); -// } -// recordRefundResponse.setStatusCode(myObject.getPaymentMethod().getPaymentTransaction().getStatusCode()); -// recordRefundResponse.setTxansactionId(myObject.getMerchantTransactionIdentifier()); -// -// this.paymentService.recordRefund(recordRefundResponse); -// return ResponseEntity.ok(myObject); -// -// } catch (Exception e) { -// e.printStackTrace(); -// } -// return ResponseEntity.ok(decryptHxTRefund); -// -// } - - @Operation( - summary = "payment-request REST API", - description = "REST API payment-request" - ) - @PostMapping(value = {"/payment-request"}) - public HashMap startPayment(int userId,int bookingId) throws NoSuchAlgorithmException { - - //System.out.println("I entered payment Service......"+bookingId+ "User Id :- "+userId); - HashMap hs = new HashMap<>(); - Optional findById = bookRepo.findById(bookingId); - - if(findById.isPresent()) { - //System.out.println("Success in finding booking Id"); - BookingDetails booking = findById.get(); - Users user = booking.getUsers(); - int findUserId=user.getUserId(); - //System.out.println("Merchant ID:-"+this.paymentConfig.getMerchantId()); - - String txnId="CHB"+transactionNumber.generateTransactionNumber()+String.format("%05d", findUserId); //create transaction Id unique from our side - String totalAmt = String.valueOf(booking.getAmountReceived()); //Amount of Community Hall from our side - TransactionResponse response = new TransactionResponse(); - response.setTxansactionId(txnId); - response.setHallId(booking.getHallDetails().getHallId()); - response.setUserId(String.valueOf(findUserId));//make it dynamic - response.setStatusCode("temp"); - response.setBookingId(bookingId); - this.paymentService.recordResponse(response); - - - String merchantId = this.paymentConfig.getMerchantId(); //This is Test Merchant ID from worldLine - String consumerId=String.format("%05d", findUserId); // Replace consumer ID in c964634 from our side - String consumerMobileNo=String.valueOf(user.getMobileNo()); //Replace consumer Mobile no in 9879879870 from our side - String consumerEmailId=user.getEmail(); //replace consumer email Id - - String encryptedtoken = this.paymentService.getToken(merchantId+"|", txnId+"|", totalAmt+"|", "|", consumerId+"|", consumerMobileNo+"|", consumerEmailId+"|", "|", "|", "|", "|", "|", "|", "|", "|", "|", this.paymentConfig.getEncryptionKey()); - - hs.put("txansactionId",txnId); - hs.put("token",encryptedtoken); - hs.put("amount",totalAmt); - hs.put("merchantId",merchantId); - hs.put("consumerMobileNo",consumerMobileNo); - hs.put("consumerEmailId",consumerEmailId); - hs.put("consumerId",consumerId); - hs.put("error", false); - } - else { - hs.put("error", true); - } - - return hs; - } - - @Operation( - summary = "Additional Damage payment-request REST API", - description = "REST API Additional Damage payment-request" - ) - @PostMapping(value = {"/additionaldamage-payment-request"}) - public HashMap startextraPayment(int userId,int bookingId) throws NoSuchAlgorithmException { - - //System.out.println("I entered payment Service......"+bookingId+ "User Id :- "+userId); - HashMap hs = new HashMap<>(); - Optional findById = bookRepo.findById(bookingId); - - if(findById.isPresent()) { - //System.out.println("Success in finding booking Id"); - BookingDetails booking = findById.get(); - Users user = booking.getUsers(); - int findUserId=user.getUserId(); - //System.out.println("Merchant ID:-"+this.paymentConfig.getMerchantId()); - - String txnId="CHBED"+transactionNumber.generateTransactionNumber()+String.format("%05d", findUserId); //create transaction Id unique from our side - String totalAmt = String.valueOf(booking.getSettlement().getCollectionPending()); //Amount of Community Hall from our side - TransactionResponse response = new TransactionResponse(); - response.setTxansactionId(txnId); - response.setHallId(booking.getHallDetails().getHallId()); - response.setUserId(String.valueOf(findUserId));//make it dynamic - response.setStatusCode("temp"); - response.setBookingId(bookingId); - this.paymentService.recordResponse(response); - - - String merchantId = this.paymentConfig.getMerchantId(); //This is Test Merchant ID from worldLine - String consumerId=String.format("%05d", findUserId); // Replace consumer ID in c964634 from our side - String consumerMobileNo=String.valueOf(user.getMobileNo()); //Replace consumer Mobile no in 9879879870 from our side - String consumerEmailId=user.getEmail(); //replace consumer email Id - - String encryptedtoken = this.paymentService.getToken(merchantId+"|", txnId+"|", totalAmt+"|", "|", consumerId+"|", consumerMobileNo+"|", consumerEmailId+"|", "|", "|", "|", "|", "|", "|", "|", "|", "|", this.paymentConfig.getEncryptionKey()); - System.out.println(totalAmt); - hs.put("txansactionId",txnId); - hs.put("token",encryptedtoken); - hs.put("amount",totalAmt); - hs.put("merchantId",merchantId); - hs.put("consumerMobileNo",consumerMobileNo); - hs.put("consumerEmailId",consumerEmailId); - hs.put("consumerId",consumerId); - hs.put("error", false); - } - else { - hs.put("error", true); - } - - return hs; - } + return hs; + } } diff --git a/src/main/java/com/gcc/communityHall/paymentService/scheduler/PaymentStatusScheduler.java b/src/main/java/com/gcc/communityHall/paymentService/scheduler/PaymentStatusScheduler.java index eca9e99e..a2d863a6 100644 --- a/src/main/java/com/gcc/communityHall/paymentService/scheduler/PaymentStatusScheduler.java +++ b/src/main/java/com/gcc/communityHall/paymentService/scheduler/PaymentStatusScheduler.java @@ -69,15 +69,19 @@ public class PaymentStatusScheduler { @Autowired private CalendarService calendarService; - // @Scheduled(cron = "0 0 0 * * ?", zone = "Asia/Kolkata") //executed at 12:00 AM - // @Scheduled(fixedRate = 900000) + // @Scheduled(cron = "0 0 0 * * ?", zone = "Asia/Kolkata") //executed at 12:00 + // AM + // @Scheduled(fixedRate = 900000) @Scheduled(fixedRate = 60000) public void fetchAndSavePaymentStatus() { - // System.out.println("Fetching Payment Status...At 12:00 AM IST"); + // System.out.println("Fetching Payment Status...At 12:00 AM IST"); System.out.println("Fetching Payment Status...At 15 min Testing"); try { - List> pendingTransactions = transactionResponseRepository.getTransResBycdateandStatus("temp"); + List> pendingTransactions = transactionResponseRepository + .getTransResBycdateandStatus("temp"); + System.out.println("pendingTransactions size " + pendingTransactions.size() + "\n pendingTransactions list:" + + pendingTransactions); for (Map transactionRecord : pendingTransactions) { try { @@ -94,7 +98,8 @@ public class PaymentStatusScheduler { transaction.put("token", ""); transaction.put("reference", ""); - System.out.println("=====================================" + transactionRecord.get("txansaction_id")); + System.out + .println("=====================================" + transactionRecord.get("txansaction_id")); System.out.println(merchant); System.out.println(transaction); System.out.println(status); @@ -113,15 +118,16 @@ public class PaymentStatusScheduler { transaction.put("dateTime", ""); } - Gson gson = new Gson(); String json = gson.toJson(status); System.out.println("Hello json " + json); String encryptHxRefund = paymentGatewayService.encryptHxRefund(json); RestTemplate restTemplate = new RestTemplate(); - String url = "https://www.tpsl-india.in/PaymentGateway/merchant2.pg/" + paymentConfig.getMerchantId(); - ResponseEntity postForEntity = restTemplate.postForEntity(url, encryptHxRefund, String.class); + String url = "https://www.tpsl-india.in/PaymentGateway/merchant2.pg/" + + paymentConfig.getMerchantId(); + ResponseEntity postForEntity = restTemplate.postForEntity(url, encryptHxRefund, + String.class); String decryptHxTRefund = paymentGatewayService.decryptHxTRefund(postForEntity.getBody()); Map myObj = new ObjectMapper().readValue(decryptHxTRefund, Map.class); @@ -137,7 +143,7 @@ public class PaymentStatusScheduler { log.setBookingId(transactionRecord.get("booking_id").toString()); log.setUserId(transactionRecord.get("user_id").toString()); log.setTransactionId(transactionRecord.get("txansaction_id").toString()); -// log.setStatus(response.get("status").toString()); + // log.setStatus(response.get("status").toString()); log.setErrorMessage(response.get("errorMessage").toString()); log.setStatusMessage(response.get("statusMessage").toString()); log.setStatusCode(response.get("statusCode").toString()); @@ -149,9 +155,9 @@ public class PaymentStatusScheduler { TransactionStatusLog saveLog = transactionStatusLogRepository.save(log); - - TransactionResponse transRes = transactionResponseRepository.findById(Integer.parseInt(transactionRecord.get("id").toString()) - ).orElseThrow(() -> new Exception("TransactionResponse not found")); + TransactionResponse transRes = transactionResponseRepository + .findById(Integer.parseInt(transactionRecord.get("id").toString())) + .orElseThrow(() -> new Exception("TransactionResponse not found")); transRes.setStatusCode(log.getStatusCode()); transRes.setAmount(log.getAmount()); @@ -159,31 +165,33 @@ public class PaymentStatusScheduler { transRes.setResponse(response.toString()); transRes.setDate(log.getReceivedDate()); transRes.setSchedulerUpdate(1); - //updated scheduler_update column to 1 + // updated scheduler_update column to 1 transactionResponseRepository.save(transRes); - - Payments payments = paymentsRepository.findByBookingId(Integer.valueOf(String.valueOf(transRes.getBookingId()))); + Payments payments = paymentsRepository + .findByBookingId(Integer.valueOf(String.valueOf(transRes.getBookingId()))); System.out.println("payments hello" + payments); if (payments != null && response.get("statusCode").toString().equals("0300")) { - payments.setBookingDetails(payments.getBookingDetails()); + payments.setBookingDetails(payments.getBookingDetails()); payments.setTransactionId(transRes.getTxansactionId()); payments.setAmountReceived(Double.parseDouble(response.get("amount").toString())); payments.setPaymentStatus("Success"); Date date = new Date(payments.getCdate().getTime()); - // paymentsRepository.updatePaymentInfo(payments.getPaymentId(),payments.getTransactionId(),payments.getAmountReceived(),payments.getPaymentStatus(),transRes.getBookingId()); + // paymentsRepository.updatePaymentInfo(payments.getPaymentId(),payments.getTransactionId(),payments.getAmountReceived(),payments.getPaymentStatus(),transRes.getBookingId()); - bookingService.updateBookingStatus(transRes.getBookingId(), BookingDetails.BookingStatus.REFUNDED, "Booking Not Confirmed. Amount will be refunded shortly."); - //intiateRefund(transRes.getBookingId(), Integer.parseInt(transRes.getUserId())); + bookingService.updateBookingStatus(transRes.getBookingId(), + BookingDetails.BookingStatus.REFUNDED, + "Booking Not Confirmed. Amount will be refunded shortly."); + // intiateRefund(transRes.getBookingId(), + // Integer.parseInt(transRes.getUserId())); } else if (response.get("statusCode").toString().equals("0300")) { payments = new Payments(); - BookingDetails bookingsById = bookingService.getBookingsById(transRes.getBookingId()); payments.setBookingDetails(bookingsById); payments.setTransactionId(transRes.getTxansactionId()); @@ -191,20 +199,26 @@ public class PaymentStatusScheduler { payments.setPaymentStatus("Success"); payments.setCdate(new Date()); - //paymentsRepository.insertPaymentinfo(payments.getPaymentId(),payments.getTransactionId(),payments.getAmountReceived(),payments.getPaymentStatus(),transRes.getBookingId(),payments.getCdate() ); + // paymentsRepository.insertPaymentinfo(payments.getPaymentId(),payments.getTransactionId(),payments.getAmountReceived(),payments.getPaymentStatus(),transRes.getBookingId(),payments.getCdate() + // ); - bookingService.updateBookingStatus(transRes.getBookingId(), BookingDetails.BookingStatus.REFUNDED, "Booking Not Confirmed. Amount will be refunded shortly."); - // intiateRefund(transRes.getBookingId(), Integer.parseInt(transRes.getUserId())); + bookingService.updateBookingStatus(transRes.getBookingId(), + BookingDetails.BookingStatus.REFUNDED, + "Booking Not Confirmed. Amount will be refunded shortly."); + // intiateRefund(transRes.getBookingId(), + // Integer.parseInt(transRes.getUserId())); } else { payments.setBookingDetails(payments.getBookingDetails()); payments.setTransactionId(transRes.getTxansactionId()); - payments.setAmountReceived(Double.parseDouble(response.get("amount") != null ? response.get("amount").toString() : "0")); + payments.setAmountReceived(Double + .parseDouble(response.get("amount") != null ? response.get("amount").toString() : "0")); payments.setPaymentStatus("Not Completed"); payments.setCdate(new Date()); paymentsRepository.save(payments); - bookingService.updateBookingStatus(transRes.getBookingId(), BookingDetails.BookingStatus.PAYMENT_FAILURE, "Booking Not Confirmed. Amount Not Received."); - + bookingService.updateBookingStatus(transRes.getBookingId(), + BookingDetails.BookingStatus.PAYMENT_FAILURE, + "Booking Not Confirmed. Amount Not Received."); } updateRefundInfo(response, log); @@ -219,10 +233,8 @@ public class PaymentStatusScheduler { e.printStackTrace(); } - } - public void updateRefundInfo(Map response, TransactionStatusLog log) { if (response.get("refundDdetails") != null) { @@ -233,7 +245,8 @@ public class PaymentStatusScheduler { if (refundDetails != null && !refundDetails.isEmpty()) { RefundResponse refundResponse = new RefundResponse(); refundResponse.setAmount(response.get("amount") != null ? response.get("amount").toString() : ""); - refundResponse.setBalaceAmount(response.get("balanceAmount") != null ? response.get("balanceAmount").toString() : ""); + refundResponse.setBalaceAmount( + response.get("balanceAmount") != null ? response.get("balanceAmount").toString() : ""); refundResponse.setTxansactionId(log.getTransactionId()); Map mapRef = refundDetails.get(refundDetails.size() - 1); @@ -258,7 +271,8 @@ public class PaymentStatusScheduler { Double amt = Double.parseDouble(response.get("amount").toString()); Double balAmt = Double.parseDouble(response.get("balanceAmount").toString()); if (amt != balAmt) { - RefundTransaction refundTrans = transactionService.getRefundTrans(saverRefundResponse.getBookingId()); + RefundTransaction refundTrans = transactionService + .getRefundTrans(saverRefundResponse.getBookingId()); if (refundTrans != null) { refundTrans.setAmountRefunded(amt - balAmt); @@ -266,57 +280,59 @@ public class PaymentStatusScheduler { refundTrans.setRefundIdentifier(response.get("refundIdentifier").toString()); refundTrans.setCdate(new Date()); - transactionService.saveRefundTransaction(refundTrans); } else { refundTrans = new RefundTransaction(); double refundAmt = amt - balAmt; - System.out.println("refundAmt.."+refundAmt); + System.out.println("refundAmt.." + refundAmt); refundTrans.setAmountRefunded(refundAmt); refundTrans.setRefundStatus("0400"); refundTrans.setRefundIdentifier(response.get("refundIdentifier").toString()); refundTrans.setCdate(new Date()); refundTrans.setTransactionId(log.getTransactionId()); BookingDetails bookings = new BookingDetails(); - BookingDetails bookingsById = bookingService.getBookingsById(Integer.parseInt(log.getBookingId())); - System.out.println("bookingsById"+bookingsById.getBookingId()); + BookingDetails bookingsById = bookingService + .getBookingsById(Integer.parseInt(log.getBookingId())); + System.out.println("bookingsById" + bookingsById.getBookingId()); bookings.setBookingId(bookingsById.getBookingId()); refundTrans.setBookingDetails(bookings); System.out.println(refundTrans.toString()); transactionService.saveRefundTransactionDetails(refundTrans); } -// bookingService.updateRefundStatus(saverRefundResponse.getBookingId(), BookingDetails.RefundStatus.COMPLETED); - bookingService.updateRefundStatusScheduler(saverRefundResponse.getBookingId(), BookingDetails.RefundStatus.COMPLETED); + // bookingService.updateRefundStatus(saverRefundResponse.getBookingId(), + // BookingDetails.RefundStatus.COMPLETED); + bookingService.updateRefundStatusScheduler(saverRefundResponse.getBookingId(), + BookingDetails.RefundStatus.COMPLETED); } saveRefundClientInfo(refundDetails, log.getUserId(), log.getBookingId(), log.getTransactionId()); } - } - } - public String saveRefundClientInfo(List> refundDetail, String userId, String bookingId, String transactionId) { - + public String saveRefundClientInfo(List> refundDetail, String userId, String bookingId, + String transactionId) { if (refundDetail == null || refundDetail.isEmpty()) { return "error"; } - for (Map refund : refundDetail) { RefundClientInfo refundClientInfo = new RefundClientInfo(); refundClientInfo.setUserId(Integer.parseInt(userId)); refundClientInfo.setBookingId(Integer.parseInt(bookingId)); refundClientInfo.setTransactionId(transactionId); - refundClientInfo.setClntRfndId(refund.get("clnt_rfnd_id") != null ? refund.get("clnt_rfnd_id").toString() : ""); + refundClientInfo + .setClntRfndId(refund.get("clnt_rfnd_id") != null ? refund.get("clnt_rfnd_id").toString() : ""); refundClientInfo.setArnNo(refund.get("ARN_Number") != null ? refund.get("ARN_Number").toString() : ""); - refundClientInfo.setGetRefTxnDate(refund.get("REF_TXN_DATE") != null ? refund.get("REF_TXN_DATE").toString() : ""); - refundClientInfo.setRefTxnAmt(refund.get("REF_TXN_AMT") != null ? refund.get("REF_TXN_AMT").toString() : ""); + refundClientInfo + .setGetRefTxnDate(refund.get("REF_TXN_DATE") != null ? refund.get("REF_TXN_DATE").toString() : ""); + refundClientInfo + .setRefTxnAmt(refund.get("REF_TXN_AMT") != null ? refund.get("REF_TXN_AMT").toString() : ""); refundClientInfo.setRefTxnId(refund.get("REF_TXN_ID") != null ? refund.get("REF_TXN_ID").toString() : ""); refundClientInfo.setStatus(refund.get("STATUS") != null ? refund.get("STATUS").toString() : ""); refundClientInfo.setSrno(refund.get("SR_NO") != null ? refund.get("SR_NO").toString() : ""); @@ -327,24 +343,22 @@ public class PaymentStatusScheduler { return "success"; } -//need to be commented + // need to be commented // @Transactional // public void intiateRefund(int bookingId, int userId) throws Exception { - // List bc = calendarService.getCalendarByBookingId(bookingId); - // if (bc != null && bc.isEmpty()) { - // String s = paymentGatewayServiceImpl.refundTheAmount(bookingId, userId); - // if (s.equals("Refunded")) { - // bookingService.updateRefundStatus(bookingId, BookingDetails.RefundStatus.COMPLETED); - // } - - // } else { - // bookingService.updateRefundStatus(bookingId, BookingDetails.RefundStatus.FAILURE); - // } + // List bc = calendarService.getCalendarByBookingId(bookingId); + // if (bc != null && bc.isEmpty()) { + // String s = paymentGatewayServiceImpl.refundTheAmount(bookingId, userId); + // if (s.equals("Refunded")) { + // bookingService.updateRefundStatus(bookingId, + // BookingDetails.RefundStatus.COMPLETED); + // } + // } else { + // bookingService.updateRefundStatus(bookingId, + // BookingDetails.RefundStatus.FAILURE); + // } // } } - - - diff --git a/src/main/java/com/gcc/communityHall/repository/BookingDetailsRepository.java b/src/main/java/com/gcc/communityHall/repository/BookingDetailsRepository.java index 57f12193..66dd6856 100644 --- a/src/main/java/com/gcc/communityHall/repository/BookingDetailsRepository.java +++ b/src/main/java/com/gcc/communityHall/repository/BookingDetailsRepository.java @@ -1766,7 +1766,7 @@ public interface BookingDetailsRepository extends JpaRepository 180 " + - "AND bd.booking_status NOT IN ('PENDING','CANCELED','REJECTED') " + + "AND bd.booking_status IN ('APPROVED') and bd.refund_status in ('WAITING','FAILURE') " + "AND (bd.mail_sent IS NULL OR bd.mail_sent = 0) " + "ORDER BY bd.booking_id ASC", nativeQuery = true) List> findSixMonthOldNonCancelledRejectedBookings(); @@ -1788,7 +1788,7 @@ public interface BookingDetailsRepository extends JpaRepository 180 " + - "AND bd.booking_status = 'CANCELED' " + + "AND bd.booking_status = 'CANCELED' and bd.refund_status != 'COMPLETED' " + "AND (bd.mail_sent IS NULL OR bd.mail_sent = 0) " + "ORDER BY bd.booking_id ASC", nativeQuery = true) List> findSixMonthOldCancelledBookings(); @@ -1810,7 +1810,7 @@ public interface BookingDetailsRepository extends JpaRepository 180 " + - "AND bd.booking_status = 'REJECTED' " + + "AND bd.booking_status in ('REJECTED','GCC_BLOCKED') and bd.refund_status != 'COMPLETED' " + "AND (bd.mail_sent IS NULL OR bd.mail_sent = 0) " + "ORDER BY bd.booking_id ASC", nativeQuery = true) List> findSixMonthOldRejectedBookings(); diff --git a/src/main/java/com/gcc/communityHall/repository/LoginRepository.java b/src/main/java/com/gcc/communityHall/repository/LoginRepository.java index 7c5046c6..a1540c00 100644 --- a/src/main/java/com/gcc/communityHall/repository/LoginRepository.java +++ b/src/main/java/com/gcc/communityHall/repository/LoginRepository.java @@ -13,13 +13,13 @@ import java.util.Map; @Repository public interface LoginRepository extends JpaRepository { - @Query(value = "SELECT * FROM login where mobile_number=:mobileNo and password=:pin", nativeQuery = true) + @Query(value = "SELECT * FROM login where mobile_number=:mobileNo and password=:pin and is_active = 1 and is_delete = 0", nativeQuery = true) Login findByMobileNoAndPin(long mobileNo, String pin); - @Query(value = "SELECT a FROM Login a WHERE a.mobileNumber = ?1") + @Query(value = "SELECT a FROM Login a WHERE a.mobileNumber = ?1 and a.isActive = true and a.isDelete = false") Login checkUserbyMobile(long mobileNo); - @Query(value = "SELECT * FROM login where name=:username and password=:pass LIMIT 1", nativeQuery = true) + @Query(value = "SELECT * FROM login where name=:username and password=:pass and is_active = 1 and is_delete = 0 LIMIT 1", nativeQuery = true) Login findByUsernameAndPass(String username, String pass); @Query(value = "SELECT " + @@ -53,7 +53,7 @@ public interface LoginRepository extends JpaRepository { "ORDER BY cast(l.zone as unsigned)", nativeQuery = true) List> findActiveLogins(); - @Query(value = "SELECT * FROM login WHERE id = :id", nativeQuery = true) + @Query(value = "SELECT * FROM login WHERE id = :id and is_active = 1 and is_delete = 0", nativeQuery = true) Login findLoginById(int id); @Query(value = "SELECT COUNT(*) FROM login WHERE mobile_number = :mobileNo AND is_delete = 0", nativeQuery = true) diff --git a/src/main/java/com/gcc/communityHall/service/BookingService.java b/src/main/java/com/gcc/communityHall/service/BookingService.java index 62760618..9e4ef465 100644 --- a/src/main/java/com/gcc/communityHall/service/BookingService.java +++ b/src/main/java/com/gcc/communityHall/service/BookingService.java @@ -17,242 +17,247 @@ import com.gcc.communityHall.entity.EbDetails; import com.gcc.communityHall.entity.GccBlockingDate; public interface BookingService { - BookingDetails getBookingsById(int BookingId); + BookingDetails getBookingsById(int BookingId); - // ak - BookingDetails getBookingByRefId(String refId); + // ak + BookingDetails getBookingByRefId(String refId); - // ak - void migrateOldBookingsToRefId(); + // ak + void migrateOldBookingsToRefId(); - BookingDetails updateBookingDetails(BookingDetails bd); + BookingDetails updateBookingDetails(BookingDetails bd); - public String confirmTheDateAndSlot(String fromDate, String toDate, int days, int fromStartingSlot, - int fromEndingSlot, int toStartingSlot, int toEndingSlot, int bookingId, int userId); + public String confirmTheDateAndSlot(String fromDate, String toDate, int days, int fromStartingSlot, + int fromEndingSlot, int toStartingSlot, int toEndingSlot, int bookingId, int userId); - public Map saveBookingDetails(Map formData); + public Map saveBookingDetails(Map formData); - public BookingDetails updateBookingStatustoGCCBlocked(BookingDetails bookingDetails); + public BookingDetails updateBookingStatustoGCCBlocked(BookingDetails bookingDetails); - public BookingDetails updateBookingStatus(int bookingId, BookingDetails.BookingStatus status, String comments); + public BookingDetails updateBookingStatus(int bookingId, BookingDetails.BookingStatus status, String comments); - public BookingDetails updateBookingStatusById(int bookingId, BookingDetails.BookingStatus status, String comments); + public BookingDetails updateBookingStatusById(int bookingId, BookingDetails.BookingStatus status, String comments); - public EbDetails updateEbDetails(int bookingId, double startUnit, double endUnit, char status); + public EbDetails updateEbDetails(int bookingId, double startUnit, double endUnit, char status); - // typeOfCancel depends { } - String cancelBooking(int bookingId, BookingDetails.BookingStatus currentStatus, String comments); + // typeOfCancel depends { } + String cancelBooking(int bookingId, BookingDetails.BookingStatus currentStatus, String comments); - public String confirmBooking(int bookingId); + public String confirmBooking(int bookingId); - public BookingDetails getBookingDetailsWithSettlement(int settlementId); + public BookingDetails getBookingDetailsWithSettlement(int settlementId); - // sreeja - List getPresentsEventsByUserId(Integer hallId); + // sreeja + List getPresentsEventsByUserId(Integer hallId); - List getPastsEventsByUserId(Integer hallId); + List getPastsEventsByUserId(Integer hallId); - List getFuturesEventsByUserId(Integer hallId); + List getFuturesEventsByUserId(Integer hallId); - List getSettlementList(Integer hallId); + List getSettlementList(Integer hallId); - public List getFilteredBookings(LocalDate fromDate, LocalDate toDate, List hallIds); + public List getFilteredBookings(LocalDate fromDate, LocalDate toDate, List hallIds); - public List> getPastData(int hall_id); + public List> getPastData(int hall_id); - public String processEbDetailsAndDamage( - int bookingId, int ebId, - double startingReading, double endingReading, - float usedUnit, double ebAmount, - String assetNames[], String comments[], int quantities[], Double assetAmounts[], MultipartFile assetImages[]); + public String processEbDetailsAndDamage( + int bookingId, int ebId, + double startingReading, double endingReading, + float usedUnit, double ebAmount, + String assetNames[], String comments[], int quantities[], Double assetAmounts[], + MultipartFile assetImages[]); - public int checkUserBookinglimitation(int userId); + public int checkUserBookinglimitation(int userId); - List getAllBookingsByUserId(Integer userId); + List getAllBookingsByUserId(Integer userId); - List> getAllBookingEventsByUserId(Integer userId); + List> getAllBookingEventsByUserId(Integer userId); - // List getAllBookingDetailsWithStatus(String fromDate, String - // toDate, String bookingStatus); + // List getAllBookingDetailsWithStatus(String fromDate, String + // toDate, String bookingStatus); - // List getAllPaymentsDetails( String fromDate, String toDate); + // List getAllPaymentsDetails( String fromDate, String toDate); - List getBookingUserDetailsReport(String fromDate, String toDate); + List getBookingUserDetailsReport(String fromDate, String toDate); - List getBookingHallDetailsReport(String fromDate, String toDate); + List getBookingHallDetailsReport(String fromDate, String toDate); - List getBlockedEvents(LocalDate fromDate, LocalDate toDate, List hallIds); + List getBlockedEvents(LocalDate fromDate, LocalDate toDate, List hallIds); - List> getOfflineBookings(); + List> getOfflineBookings(); - List getBookedslots(LocalDate fromDate, LocalDate endDate, List hallIdList); + List getBookedslots(LocalDate fromDate, LocalDate endDate, List hallIdList); - BookingDetails updateCancelledBookingStatus(int bookingId, BookingStatus status, String comments); + BookingDetails updateCancelledBookingStatus(int bookingId, BookingStatus status, String comments); - BookingDetails updateRefundStatus(int bookingId, RefundStatus status); + BookingDetails updateRefundStatus(int bookingId, RefundStatus status); - // officer service - List getAllBookingDetailsByZone(String fromDate, String toDate, String zone); + // officer service + List getAllBookingDetailsByZone(String fromDate, String toDate, String zone); - List getAllBookingDetailsByZoneWithStatus(String fromDate, String toDate, String zone, - String bookingStatus); + List getAllBookingDetailsByZoneWithStatus(String fromDate, String toDate, String zone, + String bookingStatus); - List getAllPaymentsDetailsByZone(String fromDate, String toDate, String zone); + List getAllPaymentsDetailsByZone(String fromDate, String toDate, String zone); - List getBookingHallDetailsReportByZone(String fromDate, String toDate, String zone); + List getBookingHallDetailsReportByZone(String fromDate, String toDate, String zone); - Optional updateBookingDatesAndCalendar(int bookingId, String startDate, String endDate); + Optional updateBookingDatesAndCalendar(int bookingId, String startDate, String endDate); - List getBookingHallDetailsReportByZone1(String fromDate, String toDate, String zone, Integer hallId); + Optional updateBookingDatesAndCalendar(int bookingId, String startDate, String endDate, + int startingSlot, int endingSlot); - List getGccBlockingEvents(String hallId); + List getBookingHallDetailsReportByZone1(String fromDate, String toDate, String zone, Integer hallId); - int getBlockedHallCount(String blockingReason, Date startDate, Date endDate); + List getGccBlockingEvents(String hallId); - @Transactional - void cancelAllBookings(String fromDate, String toDate, List hallIdsList, - String reasonforblocking, List selectedBookings, String updatedBy, String[] descriptions, - MultipartFile[] documents); + int getBlockedHallCount(String blockingReason, Date startDate, Date endDate); - @Transactional - void blockWithoutCancellingBookings(String fromDate, String toDate, List hallIdsList, - String reasonforblocking, String updatedBy, String[] descriptions, - MultipartFile[] documents); + @Transactional + void cancelAllBookings(String fromDate, String toDate, List hallIdsList, + String reasonforblocking, List selectedBookings, String updatedBy, String[] descriptions, + MultipartFile[] documents); - List findBookingDetailsByBookingId(Long bookingId); + @Transactional + void blockWithoutCancellingBookings(String fromDate, String toDate, List hallIdsList, + String reasonforblocking, String updatedBy, String[] descriptions, + MultipartFile[] documents); - // admin dashboard - Map> getBookingStatistics(LocalDate fromDate, LocalDate toDate, String zone, - String division, Integer hallid, String userType); + List findBookingDetailsByBookingId(Long bookingId); - public List> getBookingDetailsByHallId(int hallId); + // admin dashboard + Map> getBookingStatistics(LocalDate fromDate, LocalDate toDate, String zone, + String division, Integer hallid, String userType); - // officer dashboard - Map> getOfficerDashboard(LocalDate fromDate, LocalDate toDate, String zone, - String division, Integer hallid, String userType); + public List> getBookingDetailsByHallId(int hallId); - List> getHallDetailsForOfficer(Integer hallIid); - // List getAllPaymentsDetails(String fromDate, String toDate, String - // paymentStatus); - // admin reports + // officer dashboard + Map> getOfficerDashboard(LocalDate fromDate, LocalDate toDate, String zone, + String division, Integer hallid, String userType); - List getBookingDetailsByBookingDate(String fromDate, String toDate, String zone, String division, - Integer hallid); + List> getHallDetailsForOfficer(Integer hallIid); + // List getAllPaymentsDetails(String fromDate, String toDate, String + // paymentStatus); + // admin reports - List getBookingDetailsByEventDate(String fromDate, String toDate, String zone, String division, - Integer hallid); + List getBookingDetailsByBookingDate(String fromDate, String toDate, String zone, String division, + Integer hallid); - List getBookingDetailsByBookingDateWithStatus(String fromDate, String toDate, String bookingStatus, - String zone, String division, Integer hallid); + List getBookingDetailsByEventDate(String fromDate, String toDate, String zone, String division, + Integer hallid); - List getBookingDetailsByEventDateWithStatus(String fromDate, String toDate, String bookingStatus, - String zone, String division, Integer hallid); + List getBookingDetailsByBookingDateWithStatus(String fromDate, String toDate, String bookingStatus, + String zone, String division, Integer hallid); - List getAllPaymentsDetails(String fromDate, String toDate, String paymentStatus, String zone, - String division, Integer hallid); + List getBookingDetailsByEventDateWithStatus(String fromDate, String toDate, String bookingStatus, + String zone, String division, Integer hallid); - List getBookingHallDetailsReportByBookingDate(String fromDate, String toDate, String zone, String division, - Integer hallid); + List getAllPaymentsDetails(String fromDate, String toDate, String paymentStatus, String zone, + String division, Integer hallid); - List getBookingHallDetailsReportByEventDate(String fromDate, String toDate, String zone, String division, - Integer hallid); + List getBookingHallDetailsReportByBookingDate(String fromDate, String toDate, String zone, + String division, + Integer hallid); - List getAllBookingsettlementDetailsByBookingDate(String fromDate, String toDate); + List getBookingHallDetailsReportByEventDate(String fromDate, String toDate, String zone, String division, + Integer hallid); - List getAllBookingsettlementDetailsByBookingDateWithStatus(String fromDate, String toDate, - String refundStatus); + List getAllBookingsettlementDetailsByBookingDate(String fromDate, String toDate); - List getAllBookingsettlementDetailsByEventDate(String fromDate, String toDate); + List getAllBookingsettlementDetailsByBookingDateWithStatus(String fromDate, String toDate, + String refundStatus); - List getAllBookingsettlementDetailsByEventDateWithStatus(String fromDate, String toDate, - String refundStatus); + List getAllBookingsettlementDetailsByEventDate(String fromDate, String toDate); - List getAllBookingDetailsBookingDateByZone(String fromDate, String toDate, String zone); + List getAllBookingsettlementDetailsByEventDateWithStatus(String fromDate, String toDate, + String refundStatus); - List getAllBookingDetailsEventDateByZone(String fromDate, String toDate, String zone); + List getAllBookingDetailsBookingDateByZone(String fromDate, String toDate, String zone); - List getAllBookingDetailsBookingDateByZoneWithStatus(String fromDate, String toDate, String zone, - String bookingStatus); + List getAllBookingDetailsEventDateByZone(String fromDate, String toDate, String zone); - List getAllBookingDetailsEventDateByZoneWithStatus(String fromDate, String toDate, String zone, - String bookingStatus); + List getAllBookingDetailsBookingDateByZoneWithStatus(String fromDate, String toDate, String zone, + String bookingStatus); - List getAllBookingsettlementDetailsByZoneByBookingDate(String fromDate, String toDate, String zone); + List getAllBookingDetailsEventDateByZoneWithStatus(String fromDate, String toDate, String zone, + String bookingStatus); - List getAllBookingsettlementDetailsByZoneByEventDate(String fromDate, String toDate, String zone); + List getAllBookingsettlementDetailsByZoneByBookingDate(String fromDate, String toDate, String zone); - List getAllBookingsettlementDetailsByZoneByBookingDateWithStatus(String fromDate, String toDate, - String zone, String refundStatus); + List getAllBookingsettlementDetailsByZoneByEventDate(String fromDate, String toDate, String zone); - List getAllBookingsettlementDetailsByZoneByEventDateWithStatus(String fromDate, String toDate, - String zone, String refundStatus); + List getAllBookingsettlementDetailsByZoneByBookingDateWithStatus(String fromDate, String toDate, + String zone, String refundStatus); - List getBookingHallDetailsReportByZoneByBookingDate(String fromDate, String toDate, String zone); + List getAllBookingsettlementDetailsByZoneByEventDateWithStatus(String fromDate, String toDate, + String zone, String refundStatus); - List getBookingHallDetailsReportByZoneByEventDate(String fromDate, String toDate, String zone); + List getBookingHallDetailsReportByZoneByBookingDate(String fromDate, String toDate, String zone); - List getBookingHallDetailsReportByZoneByBookingDateHallname(String fromDate, String toDate, String zone, - Integer hallId); + List getBookingHallDetailsReportByZoneByEventDate(String fromDate, String toDate, String zone); - List getBookingHallDetailsReportByZoneByEventDateHallname(String fromDate, String toDate, String zone, - Integer hallId); + List getBookingHallDetailsReportByZoneByBookingDateHallname(String fromDate, String toDate, String zone, + Integer hallId); - BookingDetails saveebdetails(int bookingId, double startingReading, MultipartFile startingReadingimage); + List getBookingHallDetailsReportByZoneByEventDateHallname(String fromDate, String toDate, String zone, + Integer hallId); - String confirmStateBooking(int bookingId); + BookingDetails saveebdetails(int bookingId, double startingReading, MultipartFile startingReadingimage); - String uploadNOCFile(MultipartFile file, int bookingId); + String confirmStateBooking(int bookingId); - // gccapps - List getApprovedBookingDetails(); + String uploadNOCFile(MultipartFile file, int bookingId); - List getRejectedBookingDetails(); + // gccapps + List getApprovedBookingDetails(); - List getAllPaymentsDetails(String fromDate, String toDate); + List getRejectedBookingDetails(); - List getPastsEvents(); + List getAllPaymentsDetails(String fromDate, String toDate); - List getPresentsEvents(); + List getPastsEvents(); - List getFuturesEvents(); + List getPresentsEvents(); - List getSettlementApprovedList(); + List getFuturesEvents(); - List> getHallDetails(Integer hall_id); + List getSettlementApprovedList(); - List getWaitingforNOCapproval(); + List> getHallDetails(Integer hall_id); - List getAllExtraPaymentsDetails(String fromDate, String toDate, String paymentStatus, String zone, - String division, Integer hallid); + List getWaitingforNOCapproval(); - // developer - List getTransactionresponse(String fromDate, String toDate, Long bookingId, Long hallId); + List getAllExtraPaymentsDetails(String fromDate, String toDate, String paymentStatus, String zone, + String division, Integer hallid); - List getRefundResponse(String fromDate, String toDate, Long bookingId); + // developer + List getTransactionresponse(String fromDate, String toDate, Long bookingId, Long hallId); - List getBookingCalendarDetails(String fromDate, String toDate, Long bookingId, String hallName); + List getRefundResponse(String fromDate, String toDate, Long bookingId); - List getBookingsByDateAndHall(String bookingDate, Long hallId); + List getBookingCalendarDetails(String fromDate, String toDate, Long bookingId, String hallName); - BookingDetails updateRefundStatusScheduler(int bookingId, RefundStatus status); + List getBookingsByDateAndHall(String bookingDate, Long hallId); - List getCounterWiseBookingCount(String fromDate, String toDate); + BookingDetails updateRefundStatusScheduler(int bookingId, RefundStatus status); - List getHallWiseBookingDetails(String fromDate, String toDate, String CounterId); + List getCounterWiseBookingCount(String fromDate, String toDate); - List getBookingDetailsForAllHalls(String fromDate, String toDate, String CounterId, Integer hallid); + List getHallWiseBookingDetails(String fromDate, String toDate, String CounterId); - List getCounterWiseBookingDetails(String fromDate, String toDate); + List getBookingDetailsForAllHalls(String fromDate, String toDate, String CounterId, Integer hallid); - List getZoneWiseBookingList(String fromDate, String toDate); + List getCounterWiseBookingDetails(String fromDate, String toDate); - List getAllHallWiseBookingList(String fromDate, String toDate); + List getZoneWiseBookingList(String fromDate, String toDate); - List getAllCounterWiseBookingList(String fromDate, String toDate); + List getAllHallWiseBookingList(String fromDate, String toDate); - // ak - List getSettlementInitiatedReport(String fromDate, String toDate); + List getAllCounterWiseBookingList(String fromDate, String toDate); - List getBlockedEvents(); + // ak + List getSettlementInitiatedReport(String fromDate, String toDate); + + List getBlockedEvents(); } diff --git a/src/main/java/com/gcc/communityHall/service/Impl/BookingServiceImpl.java b/src/main/java/com/gcc/communityHall/service/Impl/BookingServiceImpl.java index a886454a..282e5cf6 100644 --- a/src/main/java/com/gcc/communityHall/service/Impl/BookingServiceImpl.java +++ b/src/main/java/com/gcc/communityHall/service/Impl/BookingServiceImpl.java @@ -2288,6 +2288,154 @@ public class BookingServiceImpl implements BookingService { return Optional.of("Booking not found."); } + /** + * Overloaded version that also updates startingSlot and endingSlot. + * Used by the /reschedule-dates endpoint when the user has changed the slot. + */ + @Override + public Optional updateBookingDatesAndCalendar(int bookingId, String startDat, String endDat, + int startingSlot, int endingSlot) { + // If slots are 0 (not provided by client), fall through to the existing method + if (startingSlot == 0 && endingSlot == 0) { + return updateBookingDatesAndCalendar(bookingId, startDat, endDat); + } + + Optional optionalBookingDetails = bookingDetailsRepository.findById(bookingId); + if (optionalBookingDetails.isPresent()) { + BookingDetails bookingDetails = optionalBookingDetails.get(); + String starting = bookingDetails.getStartDate(); + int hallId = bookingDetails.getHallDetails().getHallId(); + DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd"); + LocalDate startDate = LocalDate.parse(startDat, formatter); + LocalDate endDate = LocalDate.parse(endDat, formatter); + + // Temporarily apply new slots for calendar-check logic + int origStartSlot = bookingDetails.getStartingSlot(); + int origEndSlot = bookingDetails.getEndingSlot(); + bookingDetails.setStartingSlot(startingSlot); + bookingDetails.setEndingSlot(endingSlot); + + // Clear old calendar entries + List existingCalendars = bookingCalendarRepository + .getCancellingdata1(String.valueOf(bookingId)); + for (BookingCalendar calendar : existingCalendars) { + if (calendar.getBookingId_1() != null && calendar.getBookingId_1().equals(String.valueOf(bookingId))) { + calendar.setMorningSlot(false); + calendar.setBookingId_1(null); + } + if (calendar.getBookingId_2() != null && calendar.getBookingId_2().equals(String.valueOf(bookingId))) { + calendar.setEveningSlot(false); + calendar.setBookingId_2(null); + } + bookingCalendarRepository.save(calendar); + } + + String slotOccExpMsg = "Dates are already occupied. Please select another date."; + int i = 0; + for (LocalDate date = startDate; !date.isAfter(endDate); date = date.plusDays(1)) { + BookingCalendar bookingCalendar = bookingCalendarRepository.findByBdateAndHallId(date, hallId); + if (bookingCalendar != null) { + if ((date.equals(startDate) && startingSlot == 1 && bookingCalendar.isMorningSlot()) || + (date.equals(startDate) && startingSlot == 2 && bookingCalendar.isEveningSlot()) || + (date.equals(endDate) && endingSlot == 1 && bookingCalendar.isMorningSlot()) || + (date.equals(endDate) && endingSlot == 2 && bookingCalendar.isEveningSlot())) { + // Restore original slots before throwing + bookingDetails.setStartingSlot(origStartSlot); + bookingDetails.setEndingSlot(origEndSlot); + throw new SlotOccupiedException(slotOccExpMsg); + } else if (bookingCalendar.isMorningSlot() && bookingCalendar.isEveningSlot()) { + bookingDetails.setStartingSlot(origStartSlot); + bookingDetails.setEndingSlot(origEndSlot); + throw new SlotOccupiedException(slotOccExpMsg); + } else if (!date.equals(endDate) && i != 0 && i != Math.round(bookingDetails.getNoOfDays() - 1) + && (bookingCalendar.isMorningSlot() || bookingCalendar.isEveningSlot())) { + bookingDetails.setStartingSlot(origStartSlot); + bookingDetails.setEndingSlot(origEndSlot); + throw new SlotOccupiedException(slotOccExpMsg); + } else if (date.equals(endDate) && endingSlot == 2 && bookingCalendar.isMorningSlot() + && i != 0 && i == Math.round(bookingDetails.getNoOfDays() - 1)) { + bookingDetails.setStartingSlot(origStartSlot); + bookingDetails.setEndingSlot(origEndSlot); + throw new SlotOccupiedException(slotOccExpMsg); + } + } else { + String uniqueId = date.format(DateTimeFormatter.ofPattern("yyyyMMdd")) + hallId; + bookingCalendar = new BookingCalendar(); + bookingCalendar.setBdate(date); + bookingCalendar.setHallId(hallId); + bookingCalendar.setIs_booked(0); + bookingCalendar.setIs_active(true); + bookingCalendar.setUnique_id(uniqueId); + } + + // Mark slots + if (date.equals(startDate)) { + if (startingSlot == 1) { + bookingCalendar.setMorningSlot(true); + bookingCalendar.setBookingId_1(String.valueOf(bookingId)); + bookingCalendar.setIs_booked(bookingCalendar.getIs_booked() + 1); + if (!date.equals(endDate)) { + bookingCalendar.setEveningSlot(true); + bookingCalendar.setBookingId_2(String.valueOf(bookingId)); + bookingCalendar.setIs_booked(bookingCalendar.getIs_booked() + 1); + } else if (startDate.equals(endDate) && startingSlot == 1 && endingSlot == 2) { + bookingCalendar.setEveningSlot(true); + bookingCalendar.setBookingId_2(String.valueOf(bookingId)); + bookingCalendar.setIs_booked(bookingCalendar.getIs_booked() + 1); + } + } else { + bookingCalendar.setEveningSlot(true); + bookingCalendar.setBookingId_2(String.valueOf(bookingId)); + bookingCalendar.setIs_booked(bookingCalendar.getIs_booked() + 1); + } + } else if (date.equals(endDate)) { + if (endingSlot == 1) { + bookingCalendar.setMorningSlot(true); + bookingCalendar.setBookingId_1(String.valueOf(bookingId)); + bookingCalendar.setIs_booked(bookingCalendar.getIs_booked() + 1); + } else { + bookingCalendar.setEveningSlot(true); + bookingCalendar.setBookingId_2(String.valueOf(bookingId)); + bookingCalendar.setIs_booked(bookingCalendar.getIs_booked() + 1); + if (endingSlot == 2) { + bookingCalendar.setMorningSlot(true); + bookingCalendar.setBookingId_1(String.valueOf(bookingId)); + bookingCalendar.setIs_booked(bookingCalendar.getIs_booked() + 1); + } + } + } else { + bookingCalendar.setMorningSlot(true); + bookingCalendar.setEveningSlot(true); + bookingCalendar.setBookingId_1(String.valueOf(bookingId)); + bookingCalendar.setBookingId_2(String.valueOf(bookingId)); + bookingCalendar.setIs_booked(bookingCalendar.getIs_booked() + 2); + } + + bookingCalendarRepository.save(bookingCalendar); + i++; + } + + // Persist new dates and slots + updateResheduledBookingDetails(bookingId, startDat, endDat, startingSlot, endingSlot); + + String rescheduledmsg = "Your booking ID " + bookingId + " on " + starting + + " has been successfully rescheduled to " + startDate + + ". Thanks for using the GCC Community Hall Booking System."; + String urlString = "https://tmegov.onex-aura.com/api/sms?key=pfTEYN6H&to=" + + bookingDetails.getUsers().getMobileNo() + "&from=GCCCRP&body=" + rescheduledmsg + + "&entityid=1401572690000011081&templateid=1407172346565044999"; + 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."; + whatsappMsgServiceImpl.sendMsg(rescheduleMsg); + whatsappMsgServiceImpl.sendSMS(urlString); + return Optional.of("Booking dates updated successfully."); + } + return Optional.of("Booking not found."); + } + private void updateResheduledBookingDetails(int bookingId, String startDate, String endDate) { Optional book = bookingDetailsRepository.findById(bookingId); BookingDetails bookingDetails = book.get(); @@ -2316,6 +2464,37 @@ public class BookingServiceImpl implements BookingService { bookingHistoryRepository.save(bookingHistory); } + /** Overload – also persists updated starting/ending slot values. */ + private void updateResheduledBookingDetails(int bookingId, String startDate, String endDate, + int startingSlot, int endingSlot) { + Optional book = bookingDetailsRepository.findById(bookingId); + BookingDetails bookingDetails = book.get(); + bookingDetails.setScheduleCount(bookingDetails.getScheduleCount() + 1); + if (bookingDetails.getReason().equals("Commercial") || bookingDetails.getReason().equals("State Govt Event") + || bookingDetails.getReason().equals("Central Govt Event")) { + bookingDetails.setBookingStatus(BookingStatus.WAITING_FOR_NOC); + } + BookingHistory bookingHistory = new BookingHistory(); + bookingHistory.setStartDate(bookingDetails.getStartDate()); + bookingHistory.setEndDate(bookingDetails.getEndDate()); + bookingHistory.setComments(bookingDetails.getComments()); + bookingHistory.setBookingDetails(bookingDetails); + bookingHistory.setBookingStatus(BookingStatus.APPROVED); + bookingHistory.setUpdatedBy(userSession.getDispayName()); + bookingHistory.setCdate(new Date()); + bookingHistory.setRefundStatus(bookingDetails.getRefundStatus()); + bookingDetails.setStartDate(startDate); + bookingDetails.setEndDate(endDate); + // ── Persist the updated slots ────────────────────────────────────── + bookingDetails.setStartingSlot(startingSlot); + bookingDetails.setEndingSlot(endingSlot); + bookingDetails.setComments("slots Resheduled the Dates"); + DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); + bookingDetails.setUpdatedDate(LocalDateTime.now().format(formatter)); + bookingDetailsRepository.save(bookingDetails); + bookingHistoryRepository.save(bookingHistory); + } + @Override public List getBookingHallDetailsReportByZone1(String fromDate, String toDate, String zone, Integer hallId) { @@ -2361,15 +2540,8 @@ public class BookingServiceImpl implements BookingService { String reasonforblocking, List selectedBookings, String updatedBy, String[] descriptions, MultipartFile[] documents) { if (selectedBookings != null && !selectedBookings.isEmpty()) { - - // ── Collect cancelled user booking IDs (used later to build ONE GCC record) ── - List cancelledBookingIds = new ArrayList<>(); - - // ── Phase 1: Cancel each selected booking (BookingDetails + BookingCalendar - // slots) ── for (String bookingIdStr : selectedBookings) { Integer bookingId = Integer.parseInt(bookingIdStr); - System.out.println("bookingId..." + bookingId); Optional optionalBooking = bookingDetailsRepository.findById(bookingId); if (optionalBooking.isPresent()) { @@ -2395,10 +2567,102 @@ public class BookingServiceImpl implements BookingService { updateBookingStatus(bb); } - updateBookingStatusById(booking.getBookingId(), BookingStatus.GCC_BLOCKED, - reasonforblocking); + // GCC blocking entry + GccBlockingDate gcc = new GccBlockingDate(); + gcc.setStartDate(convertStringToDate(fromDate)); + gcc.setEndDate(convertStringToDate(toDate)); + gcc.setHallId(String.join(",", + hallIdsList.stream().map(String::valueOf).collect(Collectors.toList()))); + gcc.setUpdatedBy(updatedBy); + gcc.setCdate(new Date()); + gcc.setBlockingReason(reasonforblocking); + if (documents != null && documents.length > 0 && descriptions != null + && descriptions.length > 0) { + int i = 0; + for (MultipartFile document : documents) { + String filePath = uploadDirectory + "/" + gcc.getBlockingId() + "_" + i + "_" + + document.getOriginalFilename(); + String documentUrl = serverPath + "gccblockingdocs/" + gcc.getBlockingId() + "_" + i + + "_" + document.getOriginalFilename(); + + try (FileOutputStream fos = new FileOutputStream(filePath)) { + // Save document to the file system + byte[] bytes = document.getBytes(); + fos.write(bytes); + + // Save document details along with description in the database + GccblockingDocuments documentDetails = new GccblockingDocuments(); // Assuming you + // have a + // DocumentDetails + // entity + documentDetails.setBlockingDate(gcc); // Assuming hallDetails is associated with the + // document + documentDetails.setBlockingDocument(documentUrl); // Save the URL of the uploaded + // document + documentDetails.setDescription(descriptions[i]); // Save corresponding description + gccblockingDocumentsRepo.save(documentDetails); // Save the document and description + // in the database + } catch (IOException e) { + throw new RuntimeException("Failed to save document", e); + } + i++; + } + } + + // GCC blocking History + GccBlockingHistory gccblockinghistory = new GccBlockingHistory(); + gccblockinghistory.setStartDate(convertStringToDate(fromDate)); + gccblockinghistory.setEndDate(convertStringToDate(toDate)); + gccblockinghistory.setHallId(String.join(",", + hallIdsList.stream().map(String::valueOf).collect(Collectors.toList()))); + gccblockinghistory.setUpdatedBy(updatedBy); + gccblockinghistory.setCdate(new Date()); + gccblockinghistory.setBlockingReason(reasonforblocking); + List bookingIds = saveGCCBlockingDate(gcc); + gccblockinghistory.setBookingIds(bookingIds.toString()); + blockingHistoryRepository.save(gccblockinghistory); + // GCC calendar + for (Long hallId : hallIdsList) { + LocalDate fDate = LocalDate.parse(fromDate); + LocalDate tDate = LocalDate.parse(toDate); + + List dates = getDateRange(fDate, tDate); + + for (LocalDate aa : dates) { + String uniqueId = aa.format(DateTimeFormatter.ofPattern("yyyyMMdd")) + hallId; + BookingCalendar data = getbyDates(aa, hallId.toString()); + int userbookingbookingId = bookingIds.get(hallIdsList.indexOf(hallId)); + if (data != null) { + System.out.println("uniqueId...1" + uniqueId); + data.setBookingId_1(String.valueOf(userbookingbookingId)); + data.setBookingId_2(String.valueOf(userbookingbookingId)); + data.setMorningSlot(true); + data.setEveningSlot(true); + data.setIs_blocked(true); + data.setUnique_id(uniqueId); + updateBookingStatus(data); + } else { + System.out.println("uniqueId...2" + uniqueId); + BookingCalendar book = new BookingCalendar(); + book.setBdate(aa); + book.setBookingId_1(String.valueOf(userbookingbookingId)); + book.setBookingId_2(String.valueOf(userbookingbookingId)); + book.setMorningSlot(true); + book.setEveningSlot(true); + book.setHallId(hallId.intValue()); + book.setIs_active(true); + book.setIs_booked(2); + book.setIs_delete(false); + book.setIs_blocked(true); + book.setUnique_id(uniqueId); + updateBookingStatus(book); + } + } + } - // WhatsApp msg and SMS + updateBookingStatusById(booking.getBookingId(), booking.getBookingStatus().GCC_BLOCKED, + reasonforblocking); + // whatsup msg and SMS 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."; @@ -2415,103 +2679,6 @@ public class BookingServiceImpl implements BookingService { whatsappMsgServiceImpl.sendMsg(gccblockedwhatsupmsg); whatsappMsgServiceImpl.sendSMS(gccblockedurlString); bookingDetailsRepository.save(booking); - - cancelledBookingIds.add(bookingId); - } - } - } - - // ── Phase 2: Create ONE GccBlockingDate record for the entire operation ── - GccBlockingDate gcc = new GccBlockingDate(); - gcc.setStartDate(convertStringToDate(fromDate)); - gcc.setEndDate(convertStringToDate(toDate)); - gcc.setHallId(String.join(",", - hallIdsList.stream().map(String::valueOf).collect(Collectors.toList()))); - gcc.setUpdatedBy(updatedBy); - gcc.setCdate(new Date()); - gcc.setBlockingReason(reasonforblocking); - - // Save document(s) if present - if (documents != null && documents.length > 0 && descriptions != null - && descriptions.length > 0) { - int i = 0; - for (MultipartFile document : documents) { - String filePath = uploadDirectory + "/" + gcc.getBlockingId() + "_" + i + "_" - + document.getOriginalFilename(); - String documentUrl = serverPath + "gccblockingdocs/" + gcc.getBlockingId() + "_" + i - + "_" + document.getOriginalFilename(); - try (FileOutputStream fos = new FileOutputStream(filePath)) { - byte[] bytes = document.getBytes(); - fos.write(bytes); - GccblockingDocuments documentDetails = new GccblockingDocuments(); - documentDetails.setBlockingDate(gcc); - documentDetails.setBlockingDocument(documentUrl); - documentDetails.setDescription(descriptions[i]); - gccblockingDocumentsRepo.save(documentDetails); - } catch (IOException e) { - throw new RuntimeException("Failed to save document", e); - } - i++; - } - } - - // Save the single GCC blocking record - List gccBookingIds = saveGCCBlockingDate(gcc); - - // Store the actual cancelled user booking IDs on the gcc record - if (!cancelledBookingIds.isEmpty()) { - String cancelledIdsStr = cancelledBookingIds.stream() - .map(String::valueOf) - .collect(Collectors.joining(",")); - gcc.setBookingIds(cancelledIdsStr); - gccBlockingDateRepository.save(gcc); - } - - // GCC Blocking History — one entry for the whole operation - GccBlockingHistory gccblockinghistory = new GccBlockingHistory(); - gccblockinghistory.setStartDate(convertStringToDate(fromDate)); - gccblockinghistory.setEndDate(convertStringToDate(toDate)); - gccblockinghistory.setHallId(String.join(",", - hallIdsList.stream().map(String::valueOf).collect(Collectors.toList()))); - gccblockinghistory.setUpdatedBy(updatedBy); - gccblockinghistory.setCdate(new Date()); - gccblockinghistory.setBlockingReason(reasonforblocking); - gccblockinghistory.setBookingIds(cancelledBookingIds.stream() - .map(String::valueOf).collect(Collectors.joining(","))); - blockingHistoryRepository.save(gccblockinghistory); - - // ── Phase 3: Update BookingCalendar (mark dates as GCC-blocked) ── - for (Long hallId : hallIdsList) { - LocalDate fDate = LocalDate.parse(fromDate); - LocalDate tDate = LocalDate.parse(toDate); - List dates = getDateRange(fDate, tDate); - - for (LocalDate aa : dates) { - String uniqueId = aa.format(DateTimeFormatter.ofPattern("yyyyMMdd")) + hallId; - BookingCalendar data = getbyDates(aa, hallId.toString()); - int userbookingbookingId = gccBookingIds.get(hallIdsList.indexOf(hallId)); - if (data != null) { - // data.setBookingId_1(String.valueOf(userbookingbookingId)); - // data.setBookingId_2(String.valueOf(userbookingbookingId)); - // data.setMorningSlot(true); - // data.setEveningSlot(true); - data.setIs_blocked(true); - data.setUnique_id(uniqueId); - updateBookingStatus(data); - } else { - BookingCalendar book = new BookingCalendar(); - book.setBdate(aa); - book.setBookingId_1(String.valueOf(userbookingbookingId)); - book.setBookingId_2(String.valueOf(userbookingbookingId)); - book.setMorningSlot(true); - book.setEveningSlot(true); - book.setHallId(hallId.intValue()); - book.setIs_active(true); - book.setIs_booked(2); - book.setIs_delete(false); - book.setIs_blocked(true); - book.setUnique_id(uniqueId); - updateBookingStatus(book); } } } diff --git a/src/main/java/com/gcc/communityHall/service/MailService.java b/src/main/java/com/gcc/communityHall/service/MailService.java index 44851c4b..81e98ce8 100644 --- a/src/main/java/com/gcc/communityHall/service/MailService.java +++ b/src/main/java/com/gcc/communityHall/service/MailService.java @@ -46,7 +46,7 @@ public class MailService { } } - helper.setSubject("Test Mail Refund Status Update Request - Community Hall Booking"); + helper.setSubject("Refund Status Update Request - Community Hall Booking"); DecimalFormat df = new DecimalFormat("#,##0.00"); String amt = (refundAmount != null) ? "Rs. " + df.format(refundAmount) : "N/A"; diff --git a/src/main/resources/resources/templates/headquarters/sixmonthold-transactions.html b/src/main/resources/resources/templates/headquarters/sixmonthold-transactions.html deleted file mode 100644 index 62d79e72..00000000 --- a/src/main/resources/resources/templates/headquarters/sixmonthold-transactions.html +++ /dev/null @@ -1,843 +0,0 @@ - - - - - - - - - - - -
- - - - - - diff --git a/src/main/resources/templates/admin/bookingwaiting.html b/src/main/resources/templates/admin/bookingwaiting.html index 43385406..6ba4de11 100644 --- a/src/main/resources/templates/admin/bookingwaiting.html +++ b/src/main/resources/templates/admin/bookingwaiting.html @@ -24,6 +24,7 @@ width: 100% !important; } +
-
+
-
-

List of Bookings Waiting for NOC Approval

-
-
-
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
S.NoBooking IdZoneDivisionHall NameUser NameUser typeBooking DateNumber of daysReason for BookingCaretaker Name/MobileNumberAction
- -

- Approve -

-
+
+

List of Bookings Waiting for NOC Approval

+
+
+
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
S.NoBooking IdZoneDivisionHall NameUser NameUser typeBooking DateNumber of daysReason for BookingCaretaker Name/MobileNumberAction
+ +

+ Approve +

+
+
+
-
-
@@ -291,20 +293,23 @@
-
- - -
-
- - - -
+
+ + +
+
+ + + +
@@ -312,17 +317,18 @@ - - + th:onclick="accept()">Approve + + - @@ -310,17 +315,18 @@ - - + th:onclick="accept()">Approve + + - + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + +
+ + + + + +
+ + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/main/resources/templates/user/viewhistory_reschedulelogic.html b/src/main/resources/templates/user/viewhistory_reschedulelogic.html new file mode 100644 index 00000000..3b0acf68 --- /dev/null +++ b/src/main/resources/templates/user/viewhistory_reschedulelogic.html @@ -0,0 +1,3538 @@ + + + + + + + + + + + + +
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ + +
+
+ + + + +
+ +
+
+
+ + +
+
+ + + +
+
+
Hall Booking Details
+ +
+ +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
S.NoBooking IdBooking dateHall NameStarting DateEnding DateStarting PeriodEnding PeriodReason for bookingBooking StatusPayment StatusEvent StatusActionView
+ + + + + + + Current Event + Completed Event + Upcoming Event + Upcoming + Event + Govt Event + + + + Refund Completed Event + + + User Canceled Event + + + GCC Rejected Event + + + GCC Blocked Event + + + Waiting For NOC Document + + + Waiting For Admin Approval + + + +

+ + Cancel + Booking + +

+

+ + Upload + NOC + + + + Cancel + Booking + + + + Reschedule + Booking + +

+ +

+ + Cancel + Booking + + + Reschedule + Booking + +

+ + +

+ + + Cancel + Booking + + +

+

+ + --No Action-- + +

+

+ + Cancel + Booking + + + Reschedule + Booking + + + Reschedule + Booking + + +

+ +
+ + + + View + + + + +
+
+
+ +
+ + + + + + + + + +
+
+
+
+ +
+ + + + + + + + + + + + + + + +
+
+
+
+ + +
+ + + + + + + + + + +
+ + + + + \ No newline at end of file