diff --git a/jwtToken.txt b/jwtToken.txt index 7324af95..944441b6 100644 --- a/jwtToken.txt +++ b/jwtToken.txt @@ -1 +1 @@ -eyJhbGciOiJIUzUxMiJ9.eyJ1c2VyVHlwZSI6ImFkbWluIiwiaGFsbElkIjoxLCJtb2JpbGVOdW1iZXIiOjgzNDQ5NzkyOTIsImVtcGxveWVlSWQiOiIxIiwiem9uZSI6IjAwIiwiZXhwIjoxNzczMTIyNTkxfQ.6cTw68Q9NsMgdKLtP7D1k0I_6PJQ62mFIOItwtpYz7o7FNC_Kf0qRzulFguzgnPpdvSwXF2v2w_PqIXte7eIMg \ No newline at end of file +eyJhbGciOiJIUzUxMiJ9.eyJ1c2VyVHlwZSI6ImhlYWRxdWFydGVycyIsImhhbGxJZCI6MywiaGFsbElkcyI6IjMiLCJtb2JpbGVOdW1iZXIiOjEyMzQ1Njc4OTEsImVtcGxveWVlSWQiOiI2Iiwiem9uZSI6IjAwIiwiZXhwIjoxNzgxNTA2NDEwfQ.GsMmYYsPT_S2rsgB_q1hFaX-2uu3Z1HvKwijAbA1Ck5ruG9Q2JaV_ZGZGic-Jl0LLRUPHi5Xs_6jCvfg6UbiNA \ No newline at end of file diff --git a/src/main/java/com/gcc/communityHall/component/JwtUtil.java b/src/main/java/com/gcc/communityHall/component/JwtUtil.java index dcc9dba9..83db2ea5 100644 --- a/src/main/java/com/gcc/communityHall/component/JwtUtil.java +++ b/src/main/java/com/gcc/communityHall/component/JwtUtil.java @@ -11,6 +11,8 @@ import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Component; import java.util.Date; +import java.util.List; +import java.util.stream.Collectors; @Component public class JwtUtil { @@ -23,23 +25,32 @@ public class JwtUtil { @PostConstruct public void init() { - // System.out.println("jwtSecret: " + jwtSecret); - // System.out.println("jwtExpirationMs: " + jwtExpirationMs); + // System.out.println("jwtSecret: " + jwtSecret); + // System.out.println("jwtExpirationMs: " + jwtExpirationMs); } - public String generateToken(String userType, int hallId, long mobileNumber, String employeeId, String zone) { + public String generateToken(String userType, int hallId, List hallIds, long mobileNumber, + String employeeId, String zone) { try { - //System.out.println("generate token here"); - String token= Jwts.builder() + // Build effective hall IDs: prefer hallIds list if non-empty, otherwise fall + // back to single hallId + List effectiveHallIds = (hallIds != null && !hallIds.isEmpty()) + ? hallIds + : (hallId != 0 ? List.of(hallId) : List.of()); + String hallIdsStr = effectiveHallIds.stream() + .map(String::valueOf) + .collect(Collectors.joining(",")); + String token = Jwts.builder() .claim("userType", userType) .claim("hallId", hallId) + .claim("hallIds", hallIdsStr) .claim("mobileNumber", mobileNumber) .claim("employeeId", employeeId) .claim("zone", zone) .setExpiration(new Date(System.currentTimeMillis() + jwtExpirationMs)) .signWith(SignatureAlgorithm.HS512, jwtSecret) .compact(); - //System.out.println("Generated JWT Token: " + token); + // System.out.println("Generated JWT Token: " + token); return token; } catch (Exception e) { System.err.println("Failed to generate JWT token: " + e.getMessage()); @@ -49,9 +60,9 @@ public class JwtUtil { } public boolean validateToken(String token) { - //System.out.println("validation starts"); + // System.out.println("validation starts"); try { - //System.out.println("inside validation try"); + // System.out.println("inside validation try"); Claims claims = Jwts.parser().setSigningKey(jwtSecret).parseClaimsJws(token).getBody(); return !isTokenExpired(claims); } catch (ExpiredJwtException e) { @@ -67,5 +78,5 @@ public class JwtUtil { private boolean isTokenExpired(Claims claims) { return claims.getExpiration().before(new Date()); } - + } diff --git a/src/main/java/com/gcc/communityHall/controller/CareTakerAPIController.java b/src/main/java/com/gcc/communityHall/controller/CareTakerAPIController.java index cd394305..d0dcc472 100644 --- a/src/main/java/com/gcc/communityHall/controller/CareTakerAPIController.java +++ b/src/main/java/com/gcc/communityHall/controller/CareTakerAPIController.java @@ -48,156 +48,86 @@ import lombok.AllArgsConstructor; //@RestController //@RequestMapping("/careTaker/api") -@Tag( - name = "CRUD REST APIs for CareTaker in CommunityHall", - description = "CRUD REST APIs in CommunityHall to CREATE, UPDATE, FETCH AND DELETE Booking details" -) +@Tag(name = "CRUD REST APIs for CareTaker in CommunityHall", description = "CRUD REST APIs in CommunityHall to CREATE, UPDATE, FETCH AND DELETE Booking details") @RestController @RequestMapping("/communityhall/careTaker/api") @AllArgsConstructor @Validated public class CareTakerAPIController { - @Autowired - private UserSession userSession; - - @Autowired - private BookingService bookingService; - - @Autowired - private LoginRepository loginrepo; - - @Autowired - private JwtUtil jwtUtil; - - @Autowired - private BookingDetailsRepository bookingRepository; - - @Autowired - private ApplicationLogsRepository applicationLogsRepository; - - @Autowired - private HttpSession session; - - @Autowired - private AppConfig appConfig; - - @Operation( - summary = "Retrieving the User Details by bookingId REST API", - description = "REST API for Retrieving the User Details by bookingId" - ) - @ApiResponses({ - @ApiResponse( - responseCode = "200", - description = "HTTP Status OK", - content = @Content( - mediaType = "application/json", - schema = @Schema(implementation = Users.class) - - ) - ), - @ApiResponse( - responseCode = "500", - description = "Internal Server Error", - content = @Content( - mediaType = "application/json", - schema = @Schema(implementation = ErrorResponseDto.class), - examples = @ExampleObject(value = "{ \"path\": \"/viewuserDetails\", \"status\": 500, \"error\": \"Internal Server Error\", \"timestamp\": \"2024-06-22T05:47:04.347+00:00\" }") - ) - ) - }) - @GetMapping("/viewuserDetails") - public ResponseEntity getUserDetailsByBookingId(@RequestParam("bookingId") int bookingId) { - BookingDetails bookingDetails = bookingService.getBookingsById(bookingId); - Users user = bookingDetails.getUsers(); - return ResponseEntity.ok(bookingDetails); - } - - @Operation( - summary = "Saving the Eb Details REST API", - description = "REST API for Saving the EB Details" - ) - @ApiResponses({ - @ApiResponse( - responseCode = "200", - description = "HTTP Status OK", - content = @Content( - mediaType = "application/json", - examples = @ExampleObject(value = "{ \"message\": \"EB details saved successfully\" }") - ) - ), - @ApiResponse( - responseCode = "500", - description = "Internal Server Error", - content = @Content( - mediaType = "application/json", - schema = @Schema(implementation = ErrorResponseDto.class), - examples = @ExampleObject(value = "{ \"path\": \"/saveEbDetails\", \"status\": 500, \"error\": \"Internal Server Error\", \"timestamp\": \"2024-06-22T05:47:04.347+00:00\" }") - ) - ) - }) - @PostMapping(path = "/saveEbDetails") - public ResponseEntity saveEbDetails(@RequestParam int bookingId, @RequestParam double startingReading , @RequestParam(required = false) MultipartFile startingReadingimage) { - BookingDetails bd=bookingService.saveebdetails(bookingId,startingReading,startingReadingimage); - String adminname = (String) session.getAttribute("usertype"); - Integer loginid = (Integer) session.getAttribute("id"); - ApplicationLogs logs=new ApplicationLogs(); - logs.setComments("Action by " + adminname); - logs.setLoginId(loginid); - logs.setBookingId(bookingId); - logs.setLogType("saving EB StartingReading:-"+startingReading); - InetAddress inetAddress; - try { - inetAddress = InetAddress.getLocalHost(); - String hostname = InetAddress.getLocalHost().getHostName(); - logs.setIpaddress(inetAddress.getHostAddress()); - logs.setSystemName(hostname); - } catch (UnknownHostException e) { - e.printStackTrace(); - } - applicationLogsRepository.save(logs); - return ResponseEntity.ok(bookingService.updateBookingDetails(bd)); - } - - - @Operation( - summary = "Checking the MobileNo and PIN REST API", - description = "REST API for Checking the Mobile No and PIN" - ) + @Autowired + private UserSession userSession; + + @Autowired + private BookingService bookingService; + + @Autowired + private LoginRepository loginrepo; + + @Autowired + private JwtUtil jwtUtil; + + @Autowired + private BookingDetailsRepository bookingRepository; + + @Autowired + private ApplicationLogsRepository applicationLogsRepository; + + @Autowired + private HttpSession session; + + @Autowired + private AppConfig appConfig; + + @Operation(summary = "Retrieving the User Details by bookingId REST API", description = "REST API for Retrieving the User Details by bookingId") + @ApiResponses({ + @ApiResponse(responseCode = "200", description = "HTTP Status OK", content = @Content(mediaType = "application/json", schema = @Schema(implementation = Users.class) + + )), + @ApiResponse(responseCode = "500", description = "Internal Server Error", content = @Content(mediaType = "application/json", schema = @Schema(implementation = ErrorResponseDto.class), examples = @ExampleObject(value = "{ \"path\": \"/viewuserDetails\", \"status\": 500, \"error\": \"Internal Server Error\", \"timestamp\": \"2024-06-22T05:47:04.347+00:00\" }"))) + }) + @GetMapping("/viewuserDetails") + public ResponseEntity getUserDetailsByBookingId(@RequestParam("bookingId") int bookingId) { + BookingDetails bookingDetails = bookingService.getBookingsById(bookingId); + Users user = bookingDetails.getUsers(); + return ResponseEntity.ok(bookingDetails); + } + + @Operation(summary = "Saving the Eb Details REST API", description = "REST API for Saving the EB Details") @ApiResponses({ - @ApiResponse( - responseCode = "200", - description = "HTTP Status OK", - content = @Content( - mediaType = "text/plain", - examples = @ExampleObject(value = "{ \"usertype\" }") - ) - ), - @ApiResponse( - responseCode = "417", - description = "Expectation Failed", - content = @Content( - mediaType = "application/json", - examples = @ExampleObject(value = "{ \"error\": \"Invalid mobile number or PIN\" }") - ) - ), - @ApiResponse( - responseCode = "400", - description = "Bad Request", - content = @Content( - mediaType = "application/json", - examples = @ExampleObject(value = "{ \"mobileNo\": \"Mobile number must be 10 digits\" }") - ) - ), - @ApiResponse( - responseCode = "500", - description = "Internal Server Error", - content = @Content( - mediaType = "application/json", - schema = @Schema(implementation = ErrorResponseDto.class), - examples = @ExampleObject(value = "{ \"path\": \"/checkLogin\", \"status\": 500, \"error\": \"Internal Server Error\", \"timestamp\": \"2024-06-22T05:47:04.347+00:00\" }") - ) - ) + @ApiResponse(responseCode = "200", description = "HTTP Status OK", content = @Content(mediaType = "application/json", examples = @ExampleObject(value = "{ \"message\": \"EB details saved successfully\" }"))), + @ApiResponse(responseCode = "500", description = "Internal Server Error", content = @Content(mediaType = "application/json", schema = @Schema(implementation = ErrorResponseDto.class), examples = @ExampleObject(value = "{ \"path\": \"/saveEbDetails\", \"status\": 500, \"error\": \"Internal Server Error\", \"timestamp\": \"2024-06-22T05:47:04.347+00:00\" }"))) + }) + @PostMapping(path = "/saveEbDetails") + public ResponseEntity saveEbDetails(@RequestParam int bookingId, @RequestParam double startingReading, + @RequestParam(required = false) MultipartFile startingReadingimage) { + BookingDetails bd = bookingService.saveebdetails(bookingId, startingReading, startingReadingimage); + String adminname = (String) session.getAttribute("usertype"); + Integer loginid = (Integer) session.getAttribute("id"); + ApplicationLogs logs = new ApplicationLogs(); + logs.setComments("Action by " + adminname); + logs.setLoginId(loginid); + logs.setBookingId(bookingId); + logs.setLogType("saving EB StartingReading:-" + startingReading); + InetAddress inetAddress; + try { + inetAddress = InetAddress.getLocalHost(); + String hostname = InetAddress.getLocalHost().getHostName(); + logs.setIpaddress(inetAddress.getHostAddress()); + logs.setSystemName(hostname); + } catch (UnknownHostException e) { + e.printStackTrace(); + } + applicationLogsRepository.save(logs); + return ResponseEntity.ok(bookingService.updateBookingDetails(bd)); + } + + @Operation(summary = "Checking the MobileNo and PIN REST API", description = "REST API for Checking the Mobile No and PIN") + @ApiResponses({ + @ApiResponse(responseCode = "200", description = "HTTP Status OK", content = @Content(mediaType = "text/plain", examples = @ExampleObject(value = "{ \"usertype\" }"))), + @ApiResponse(responseCode = "417", description = "Expectation Failed", content = @Content(mediaType = "application/json", examples = @ExampleObject(value = "{ \"error\": \"Invalid mobile number or PIN\" }"))), + @ApiResponse(responseCode = "400", description = "Bad Request", content = @Content(mediaType = "application/json", examples = @ExampleObject(value = "{ \"mobileNo\": \"Mobile number must be 10 digits\" }"))), + @ApiResponse(responseCode = "500", description = "Internal Server Error", content = @Content(mediaType = "application/json", schema = @Schema(implementation = ErrorResponseDto.class), examples = @ExampleObject(value = "{ \"path\": \"/checkLogin\", \"status\": 500, \"error\": \"Internal Server Error\", \"timestamp\": \"2024-06-22T05:47:04.347+00:00\" }"))) }) @GetMapping("/checkLogin") public ResponseEntity checkLogin( @@ -205,26 +135,35 @@ public class CareTakerAPIController { @RequestParam String pin, HttpSession session) { try { -// System.out.println("careTaker API Controller\nCounter Id: "+userSession.getCounter()+"\nCounter Name: "+userSession.getCounterName()); + // System.out.println("careTaker API Controller\nCounter Id: + // "+userSession.getCounter()+"\nCounter Name: "+userSession.getCounterName()); // Fetch login details from the repository Login login = loginrepo.findByMobileNoAndPin(Long.parseLong(mobileNo), pin); if (login != null) { - // System.out.println("Login successful for mobile number: " + mobileNo); + // System.out.println("Login successful for mobile number: " + mobileNo); // Generate JWT token if login is successful String token = jwtUtil.generateToken( login.getUserType(), login.getHallId(), + login.getHallIds(), login.getMobileNumber(), login.getEmployeeId(), - login.getZone() - ); - //System.out.println("Generated JWT Token: " + token); + login.getZone()); + // System.out.println("Generated JWT Token: " + token); // Store JWT token and user information in session session.setAttribute("jwtToken", token); session.setAttribute("id", login.getId()); session.setAttribute("hall_id", login.getHallId()); + // Store multi-hall IDs: prefer hallIds list if assigned, else derive from + // single hallId + List effectiveHallIds = (login.getHallIds() != null && !login.getHallIds().isEmpty()) + ? login.getHallIds() + : (login.getHallId() != 0 ? java.util.Arrays.asList(login.getHallId()) + : new java.util.ArrayList<>()); + System.out.println("effectiveHallIds.." + effectiveHallIds); + session.setAttribute("hall_ids", effectiveHallIds); session.setAttribute("mobileno", login.getMobileNumber()); session.setAttribute("usertype", login.getUserType()); session.setAttribute("employeeId", login.getEmployeeId()); @@ -232,27 +171,28 @@ public class CareTakerAPIController { InetAddress inetAddress = InetAddress.getLocalHost(); String hostname = InetAddress.getLocalHost().getHostName(); System.out.println("Hostname: " + hostname); - ApplicationLogs logs=new ApplicationLogs(); - logs.setComments("login as "+login.getName()); + ApplicationLogs logs = new ApplicationLogs(); + logs.setComments("login as " + login.getName()); logs.setLoginId(login.getId()); logs.setIpaddress(inetAddress.getHostAddress()); logs.setSystemName(hostname); - applicationLogsRepository.save(logs); + applicationLogsRepository.save(logs); - userSession.setCounter(login.getEmployeeId()); - userSession.setCounterName(login.getName()); + userSession.setCounter(login.getEmployeeId()); + userSession.setCounterName(login.getName()); - Map response = new HashMap<>(); - response.put("userType", login.getUserType()); - response.put("counterName", login.getName()); // Send Counter Name - response.put("token", token); + Map response = new HashMap<>(); + response.put("userType", login.getUserType()); + response.put("counterName", login.getName()); // Send Counter Name + response.put("token", token); // Write the token to a file try (FileWriter fileWriter = new FileWriter("jwtToken.txt")) { fileWriter.write(token); } catch (IOException e) { e.printStackTrace(); - return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("Failed to store token in file"); + return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR) + .body("Failed to store token in file"); } // Return successful response with user type @@ -271,95 +211,89 @@ public class CareTakerAPIController { } } + @Operation(summary = "Process EB Details and Damage REST API", description = "REST API for saving the EB Details and Damage") + @ApiResponses({ + @ApiResponse(responseCode = "200", description = "HTTP Status OK", content = @Content(mediaType = "text/plain", examples = @ExampleObject(value = "EB details and damage processed successfully"))), + @ApiResponse(responseCode = "500", description = "Internal Server Error", content = @Content(mediaType = "application/json", schema = @Schema(implementation = ErrorResponseDto.class), examples = @ExampleObject(value = "{ \"path\": \"/processEbDetailsAndDamage\", \"status\": 500, \"error\": \"Internal Server Error\", \"timestamp\": \"2024-06-22T05:47:04.347+00:00\" }"))) + }) + @PostMapping(path = "/processEbDetailsAndDamage") + public ResponseEntity processEbDetailsAndDamage( + @RequestParam("bookingId") int bookingId, + @RequestParam("ebId") int ebId, + @RequestParam("startingReading") double startingReading, + @RequestParam("endingReading") double endingReading, + @RequestParam("usedUnit") float usedUnit, + @RequestParam("ebAmount") double ebAmount, + @RequestParam(name = "assetName", required = false) String assetNames[], + @RequestParam(name = "comments", required = false) String comments[], + @RequestParam(name = "quantity", required = false) int quantities[], + @RequestParam(name = "assetAmount", required = false) Double assetAmounts[], + @RequestParam(name = "assetImage", required = false) MultipartFile assetImages[]) { - - @Operation( - summary = "Process EB Details and Damage REST API", - description = "REST API for saving the EB Details and Damage" - ) - @ApiResponses({ - @ApiResponse( - responseCode = "200", - description = "HTTP Status OK", - content = @Content( - mediaType = "text/plain", - examples = @ExampleObject(value = "EB details and damage processed successfully") - ) - ), - @ApiResponse( - responseCode = "500", - description = "Internal Server Error", - content = @Content( - mediaType = "application/json", - schema = @Schema(implementation = ErrorResponseDto.class), - examples = @ExampleObject(value = "{ \"path\": \"/processEbDetailsAndDamage\", \"status\": 500, \"error\": \"Internal Server Error\", \"timestamp\": \"2024-06-22T05:47:04.347+00:00\" }") - ) - ) - }) - @PostMapping(path = "/processEbDetailsAndDamage") - public ResponseEntity processEbDetailsAndDamage( - @RequestParam("bookingId") int bookingId, - @RequestParam("ebId") int ebId, - @RequestParam("startingReading") double startingReading, - @RequestParam("endingReading") double endingReading, - @RequestParam("usedUnit") float usedUnit, - @RequestParam("ebAmount") double ebAmount, - @RequestParam(name ="assetName",required = false) String assetNames[], - @RequestParam(name ="comments",required = false) String comments[], - @RequestParam(name ="quantity",required = false) int quantities[], - @RequestParam(name ="assetAmount",required = false) Double assetAmounts[], - @RequestParam(name ="assetImage",required = false) MultipartFile assetImages[]) { - - String processEbDetailsAndDamage = bookingService.processEbDetailsAndDamage(bookingId, ebId, startingReading, endingReading, usedUnit, ebAmount, assetNames, comments, quantities, assetAmounts, assetImages); - String adminname = (String) session.getAttribute("usertype"); - Integer loginid = (Integer) session.getAttribute("id"); - ApplicationLogs logs=new ApplicationLogs(); - logs.setComments("Action by " + adminname); - logs.setLoginId(loginid); - logs.setBookingId(bookingId); - logs.setLogType("Saving the SettlementDetails"); - InetAddress inetAddress; - try { - inetAddress = InetAddress.getLocalHost(); - String hostname = InetAddress.getLocalHost().getHostName(); - logs.setIpaddress(inetAddress.getHostAddress()); - logs.setSystemName(hostname); - } catch (UnknownHostException e) { - e.printStackTrace(); - } - applicationLogsRepository.save(logs); - return ResponseEntity.ok(processEbDetailsAndDamage); - } + String processEbDetailsAndDamage = bookingService.processEbDetailsAndDamage(bookingId, ebId, startingReading, + endingReading, usedUnit, ebAmount, assetNames, comments, quantities, assetAmounts, assetImages); + String adminname = (String) session.getAttribute("usertype"); + Integer loginid = (Integer) session.getAttribute("id"); + ApplicationLogs logs = new ApplicationLogs(); + logs.setComments("Action by " + adminname); + logs.setLoginId(loginid); + logs.setBookingId(bookingId); + logs.setLogType("Saving the SettlementDetails"); + InetAddress inetAddress; + try { + inetAddress = InetAddress.getLocalHost(); + String hostname = InetAddress.getLocalHost().getHostName(); + logs.setIpaddress(inetAddress.getHostAddress()); + logs.setSystemName(hostname); + } catch (UnknownHostException e) { + e.printStackTrace(); + } + applicationLogsRepository.save(logs); + return ResponseEntity.ok(processEbDetailsAndDamage); + } @GetMapping("/settlementlist") - public List getApprovedBookingsWithSettlement(int hallId) { - return bookingRepository.getSettlementList(hallId); + public List getApprovedBookingsWithSettlement() { + // Use multi-hall IDs from session if available, else fall back to single + // hall_id + @SuppressWarnings("unchecked") + List hallIds = (List) session.getAttribute("hall_ids"); + if (hallIds != null && !hallIds.isEmpty()) { + return bookingRepository.getSettlementListByHallIds(hallIds); + } + // Fallback: single hall_id + Integer singleHallId = (Integer) session.getAttribute("hall_id"); + if (singleHallId != null && singleHallId != 0) { + return bookingRepository.getSettlementList(singleHallId); + } + return java.util.Collections.emptyList(); } - + @GetMapping(value = "/checkofficialMobileExits") public String checkMobileExits(HttpServletRequest request, @RequestParam String phone) { - //System.out.println("correction in pin"+phone); - Login mod= loginrepo.checkUserbyMobile(Long.parseLong(phone)); - //System.out.println(mod); - if(mod!=null){ - return "success"; - } - else { - return "error"; - } + // System.out.println("correction in pin"+phone); + Login mod = loginrepo.checkUserbyMobile(Long.parseLong(phone)); + // System.out.println(mod); + if (mod != null) { + return "success"; + } else { + return "error"; + } } - + @GetMapping(value = "/updatePIN") public String updatePIN(long phone, String pin) { - Login mod= loginrepo.checkUserbyMobile(phone); - mod.setPassword(pin); - loginrepo.save(mod); - return "Success"; + Login mod = loginrepo.checkUserbyMobile(phone); + mod.setPassword(pin); + loginrepo.save(mod); + return "Success"; } + @GetMapping(value = "/resetPIN") - public String resetPIN(@RequestParam long resetpinmobilenumber, @RequestParam String oldpin, @RequestParam String newpin) { + public String resetPIN(@RequestParam long resetpinmobilenumber, @RequestParam String oldpin, + @RequestParam String newpin) { Login mod = loginrepo.checkUserbyMobile(resetpinmobilenumber); - + if (mod != null && mod.getPassword().equals(oldpin)) { mod.setPassword(newpin); loginrepo.save(mod); @@ -368,39 +302,39 @@ public class CareTakerAPIController { return "error"; } } - + @GetMapping("/past-booking") public ResponseEntity> viewPast() { List pastBookings = bookingService.getPastsEvents(); return new ResponseEntity<>(pastBookings, HttpStatus.OK); } - + @GetMapping("/getPresentBooking") public List getpresentBooking() { return bookingService.getPresentsEvents(); } - + @GetMapping("/getFutureBooking") public List getfutureBooking() { return bookingService.getFuturesEvents(); } - + @GetMapping("/getsettlementList") public List getSettlementApprovedList() { return bookingService.getSettlementApprovedList(); } - - @GetMapping("/settlement-list") + + @GetMapping("/settlement-list") public ResponseEntity> getSettlementList() { List settlementList = bookingRepository.getSettlementsList(); - + if (settlementList != null && !settlementList.isEmpty()) { return ResponseEntity.ok(settlementList); } else { return ResponseEntity.status(HttpStatus.NO_CONTENT).body(null); } } - + @GetMapping("/getBookingDetails") public ResponseEntity getBookingsById(@RequestParam("bookingId") int bookingId) { BookingDetails bookingDetails = bookingService.getBookingsById(bookingId); @@ -410,19 +344,21 @@ public class CareTakerAPIController { return ResponseEntity.status(HttpStatus.NOT_FOUND).body(null); } } + @GetMapping("/generateQRCode") public ResponseEntity generateQRCodeForUser(@RequestParam("bookingId") Long bookingId) { try { // Base URL and full URL construction String baseUrl = appConfig.getFullUrl(); // Base URL - // String fullUrl = baseUrl + "/getuserbyid?registerId=" + registerId; // Full URL + // String fullUrl = baseUrl + "/getuserbyid?registerId=" + registerId; // Full + // URL // Log the generated full URL for debugging System.out.println("Generated Full URL for QR Code: " + baseUrl); // Generate the QR code with the full URL String qrCodeImage = QRCodeGenerator.generateQRCode(baseUrl, bookingId); - String dataUri = qrCodeImage; // Encode QR code image as Base64 + String dataUri = qrCodeImage; // Encode QR code image as Base64 // Return the QR code image as a Base64 string return ResponseEntity.ok(dataUri); diff --git a/src/main/java/com/gcc/communityHall/controller/CareTakerController.java b/src/main/java/com/gcc/communityHall/controller/CareTakerController.java index abde96db..3ea7cfbd 100644 --- a/src/main/java/com/gcc/communityHall/controller/CareTakerController.java +++ b/src/main/java/com/gcc/communityHall/controller/CareTakerController.java @@ -21,145 +21,151 @@ import jakarta.servlet.http.HttpSession; @Controller @RequestMapping("/communityhall/caretaker") public class CareTakerController { - @Autowired - private AppConfig appConfig; - - @Autowired - private BookingDetailsRepository bookingDetailsRepo; - - @Autowired - private BookingService bookingService; - - @Autowired - private BookingDetailsRepository bookingRepository; - @Autowired - private HallDetailsRepository hallDetailsRepository; - - @GetMapping("/dashboard") - public String viewdashboardPage(Model model,HttpSession session) { - // model.addAttribute("session", session); - - String caretakerName = (String) session.getAttribute("usertype"); - if(caretakerName!=null) { - long mobileno = (long) session.getAttribute("mobileno"); - model.addAttribute("mobileno", mobileno); - int hall_id = (int) session.getAttribute("hall_id"); - String hallName = hallDetailsRepository.findHallNameById(hall_id); - List> getmounthcount = bookingDetailsRepo.getCartakermounthcount(hall_id); - List> count = bookingDetailsRepo.getcartakecount(hall_id); - Map map = count.get(0); - - model.addAttribute("mounthcount",getmounthcount); - - //System.out.println( map.get("approved_count")!=null?map.get("approved_count"):1); - model.addAttribute("APPROVED", map.get("approved_count")); - model.addAttribute("REJECTED", map.get("rejected_count")); - model.addAttribute("COMPLETED", map.get("completed_count")); - model.addAttribute("CANCELED", map.get("CANCELED")); - model.addAttribute("PAYMENT_FAILURE", map.get("PAYMENT_FAILURE")); - model.addAttribute("GCC_BLOCKED", map.get("GCC_BLOCKED")); - model.addAttribute("caretakerName", caretakerName); - model.addAttribute("hallName", hallName); - return "caretaker/dashboard"; - }else { - session.invalidate(); - return "redirect:/communityhall/login"; - } - } - @GetMapping("/settlementlist") - public String viewSettlementList(Model model,HttpSession session) { - String caretakerName = (String) session.getAttribute("usertype"); - if(caretakerName!=null) { - long mobileno = (long) session.getAttribute("mobileno"); - model.addAttribute("mobileno", mobileno); - Integer hallid = (Integer) session.getAttribute("hall_id"); - List settlemetList = bookingRepository.getSettlementList(hallid); - model.addAttribute("caretakerName", caretakerName); - model.addAttribute("settlemetList", settlemetList); - return "caretaker/settlementlist"; - }else { - session.invalidate(); - return "redirect:/communityhall/login"; - } - } - @GetMapping("/present-booking") - public String viewPresent(Model model, HttpSession session) { - String caretakerName = (String) session.getAttribute("usertype"); - if(caretakerName!=null) { - long mobileno = (long) session.getAttribute("mobileno"); - model.addAttribute("mobileno", mobileno); - Integer hallid = (Integer) session.getAttribute("hall_id"); - List bookings = bookingService.getPresentsEventsByUserId(hallid); - model.addAttribute("caretakerName", caretakerName); - model.addAttribute("hallid", hallid); - model.addAttribute("bookings", bookings); - - return "caretaker/present-booking"; - }else { - session.invalidate(); - return "redirect:/communityhall/login"; - } - } - @GetMapping("/past-booking") - public String viewPast(Model model,HttpSession session) { - String caretakerName = (String) session.getAttribute("usertype"); - if(caretakerName!=null) { - long mobileno = (long) session.getAttribute("mobileno"); - model.addAttribute("mobileno", mobileno); - Integer hallid = (Integer) session.getAttribute("hall_id"); - // Assuming you have a service class to handle business logic - List pastBookings = bookingService.getPastsEventsByUserId(hallid); - - model.addAttribute("caretakerName", caretakerName); - model.addAttribute("hallid", hallid); - model.addAttribute("pastBookings", pastBookings); - return "caretaker/past-booking"; - }else { - session.invalidate(); - return "redirect:/communityhall/login"; - } - } - @GetMapping("/future-booking") - public String viewFuture(Model model,HttpSession session) { - String caretakerName = (String) session.getAttribute("usertype"); - if(caretakerName!=null) { - long mobileno = (long) session.getAttribute("mobileno"); - model.addAttribute("mobileno", mobileno); - Integer hallid = (Integer) session.getAttribute("hall_id"); - // Assuming you have a service class to handle business logic - List futureBookings = bookingService.getFuturesEventsByUserId(hallid); - - model.addAttribute("caretakerName", caretakerName); - model.addAttribute("hallid", hallid); - model.addAttribute("futureBookings", futureBookings); - return "caretaker/future-booking"; - }else { - session.invalidate(); - return "redirect:/communityhall/login"; - } - } - - @GetMapping("/caretakerpage") - public String viewcaretakerpage(Model model,HttpSession session,@RequestParam("bookingId") int bookingId) { - String caretakerName = (String) session.getAttribute("usertype"); - if(caretakerName!=null) { - long mobileno = (long) session.getAttribute("mobileno"); - model.addAttribute("mobileno", mobileno); - model.addAttribute("caretakerName", caretakerName); - model.addAttribute("title","caretaker"); - model.addAttribute("baseURL", appConfig.getBaseUrl()); - BookingDetails booking = bookingService.getBookingsById(bookingId); - model.addAttribute("booking",booking); - return "caretaker/caretakerpage"; - }else { - session.invalidate(); - return "redirect:/communityhall/login"; - } - } - @GetMapping("/logout") - public String viewLogout(Model model,HttpSession session) { - session.invalidate(); - return "redirect:/communityhall/login"; - } + @Autowired + private AppConfig appConfig; + + @Autowired + private BookingDetailsRepository bookingDetailsRepo; + + @Autowired + private BookingService bookingService; + + @Autowired + private BookingDetailsRepository bookingRepository; + @Autowired + private HallDetailsRepository hallDetailsRepository; + + @GetMapping("/dashboard") + public String viewdashboardPage(Model model, HttpSession session) { + // model.addAttribute("session", session); + + String caretakerName = (String) session.getAttribute("usertype"); + if (caretakerName != null && "caretaker".equals(caretakerName)) { + long mobileno = (long) session.getAttribute("mobileno"); + model.addAttribute("mobileno", mobileno); + int hall_id = (int) session.getAttribute("hall_id"); + String hallName = hallDetailsRepository.findHallNameById(hall_id); + List> getmounthcount = bookingDetailsRepo.getCartakermounthcount(hall_id); + List> count = bookingDetailsRepo.getcartakecount(hall_id); + Map map = count.get(0); + + model.addAttribute("mounthcount", getmounthcount); + + // System.out.println( + // map.get("approved_count")!=null?map.get("approved_count"):1); + model.addAttribute("APPROVED", map.get("approved_count")); + model.addAttribute("REJECTED", map.get("rejected_count")); + model.addAttribute("COMPLETED", map.get("completed_count")); + model.addAttribute("CANCELED", map.get("CANCELED")); + model.addAttribute("PAYMENT_FAILURE", map.get("PAYMENT_FAILURE")); + model.addAttribute("GCC_BLOCKED", map.get("GCC_BLOCKED")); + model.addAttribute("caretakerName", caretakerName); + model.addAttribute("hallName", hallName); + return "caretaker/dashboard"; + } else { + session.invalidate(); + return "redirect:/communityhall/login"; + } + } + + @GetMapping("/settlementlist") + public String viewSettlementList(Model model, HttpSession session) { + String caretakerName = (String) session.getAttribute("usertype"); + if (caretakerName != null && "caretaker".equals(caretakerName)) { + long mobileno = (long) session.getAttribute("mobileno"); + model.addAttribute("mobileno", mobileno); + Integer hallid = (Integer) session.getAttribute("hall_id"); + List settlemetList = bookingRepository.getSettlementList(hallid); + model.addAttribute("caretakerName", caretakerName); + model.addAttribute("settlemetList", settlemetList); + return "caretaker/settlementlist"; + } else { + session.invalidate(); + return "redirect:/communityhall/login"; + } + } + + @GetMapping("/present-booking") + public String viewPresent(Model model, HttpSession session) { + String caretakerName = (String) session.getAttribute("usertype"); + if (caretakerName != null && "caretaker".equals(caretakerName)) { + long mobileno = (long) session.getAttribute("mobileno"); + model.addAttribute("mobileno", mobileno); + Integer hallid = (Integer) session.getAttribute("hall_id"); + List bookings = bookingService.getPresentsEventsByUserId(hallid); + model.addAttribute("caretakerName", caretakerName); + model.addAttribute("hallid", hallid); + model.addAttribute("bookings", bookings); + + return "caretaker/present-booking"; + } else { + session.invalidate(); + return "redirect:/communityhall/login"; + } + } + + @GetMapping("/past-booking") + public String viewPast(Model model, HttpSession session) { + String caretakerName = (String) session.getAttribute("usertype"); + if (caretakerName != null && "caretaker".equals(caretakerName)) { + long mobileno = (long) session.getAttribute("mobileno"); + model.addAttribute("mobileno", mobileno); + Integer hallid = (Integer) session.getAttribute("hall_id"); + // Assuming you have a service class to handle business logic + List pastBookings = bookingService.getPastsEventsByUserId(hallid); + + model.addAttribute("caretakerName", caretakerName); + model.addAttribute("hallid", hallid); + model.addAttribute("pastBookings", pastBookings); + return "caretaker/past-booking"; + } else { + session.invalidate(); + return "redirect:/communityhall/login"; + } + } + + @GetMapping("/future-booking") + public String viewFuture(Model model, HttpSession session) { + String caretakerName = (String) session.getAttribute("usertype"); + if (caretakerName != null && "caretaker".equals(caretakerName)) { + long mobileno = (long) session.getAttribute("mobileno"); + model.addAttribute("mobileno", mobileno); + Integer hallid = (Integer) session.getAttribute("hall_id"); + // Assuming you have a service class to handle business logic + List futureBookings = bookingService.getFuturesEventsByUserId(hallid); + + model.addAttribute("caretakerName", caretakerName); + model.addAttribute("hallid", hallid); + model.addAttribute("futureBookings", futureBookings); + return "caretaker/future-booking"; + } else { + session.invalidate(); + return "redirect:/communityhall/login"; + } + } + + @GetMapping("/caretakerpage") + public String viewcaretakerpage(Model model, HttpSession session, @RequestParam("bookingId") int bookingId) { + String caretakerName = (String) session.getAttribute("usertype"); + if (caretakerName != null && "caretaker".equals(caretakerName)) { + long mobileno = (long) session.getAttribute("mobileno"); + model.addAttribute("mobileno", mobileno); + model.addAttribute("caretakerName", caretakerName); + model.addAttribute("title", "caretaker"); + model.addAttribute("baseURL", appConfig.getBaseUrl()); + BookingDetails booking = bookingService.getBookingsById(bookingId); + model.addAttribute("booking", booking); + return "caretaker/caretakerpage"; + } else { + session.invalidate(); + return "redirect:/communityhall/login"; + } + } + + @GetMapping("/logout") + public String viewLogout(Model model, HttpSession session) { + session.invalidate(); + return "redirect:/communityhall/login"; + } } diff --git a/src/main/java/com/gcc/communityHall/controller/CounterController.java b/src/main/java/com/gcc/communityHall/controller/CounterController.java index c67c4af5..7f5491cf 100644 --- a/src/main/java/com/gcc/communityHall/controller/CounterController.java +++ b/src/main/java/com/gcc/communityHall/controller/CounterController.java @@ -66,12 +66,12 @@ public class CounterController { @Autowired private ApplicationLogsRepository applicationLogsRepository; - @GetMapping(value = {"", "/", "/counterbooking"}) + @GetMapping(value = { "", "/", "/counterbooking" }) public String viewcounter(Model model, HttpSession session) { System.out.println("viewcounter"); String countername = (String) session.getAttribute("usertype"); - System.out.println("serverDate....."+ LocalDate.now().toString()); - model.addAttribute("serverDate", LocalDate.now().toString()); //for server date + System.out.println("serverDate....." + LocalDate.now().toString()); + model.addAttribute("serverDate", LocalDate.now().toString()); // for server date model.addAttribute("countername", countername); return "counter/counter-booking"; } @@ -139,34 +139,35 @@ public class CounterController { userSession.setDispayName(null); userSession.setCounter(null); userSession.setCounterName(null); -// return "redirect:/communityhall/login"; + // return "redirect:/communityhall/login"; return "redirect:/communityhall/user/dashboard"; } - // newly added for counter login + // newly added for counter login @GetMapping("/verifyLogin") public ResponseEntity verifyLogin( @RequestParam("username") String username, @RequestParam("password") String password, Model model, HttpSession session) { - System.out.println("username: "+username+"\n"+"password: "+password); + System.out.println("username: " + username + "\n" + "password: " + password); try { Login login = loginRepository.findByUsernameAndPass(username, password); - System.out.println("counter controller\nCounter Id: "+userSession.getCounter()+"\nCounter Name: "+userSession.getCounterName()); + System.out.println("counter controller\nCounter Id: " + userSession.getCounter() + "\nCounter Name: " + + userSession.getCounterName()); if (login != null) { - // System.out.println("Login successful for mobile number: " + mobileNo); + System.out.println("Login successful for mobile number: " + login.getMobileNumber()); // Generate JWT token if login is successful String token = jwtUtil.generateToken( login.getUserType(), login.getHallId(), + login.getHallIds(), login.getMobileNumber(), login.getEmployeeId(), - login.getZone() - ); - //System.out.println("Generated JWT Token: " + token); + login.getZone()); + // System.out.println("Generated JWT Token: " + token); // Store JWT token and user information in session session.setAttribute("jwtToken", token); @@ -205,7 +206,8 @@ public class CounterController { fileWriter.write(token); } catch (IOException e) { e.printStackTrace(); - return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("Failed to store token in file"); + return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR) + .body("Failed to store token in file"); } // Return successful response with user type @@ -225,4 +227,3 @@ public class CounterController { } } - diff --git a/src/main/java/com/gcc/communityHall/controller/HeadquartersController.java b/src/main/java/com/gcc/communityHall/controller/HeadquartersController.java index 29ff230c..e08047f1 100644 --- a/src/main/java/com/gcc/communityHall/controller/HeadquartersController.java +++ b/src/main/java/com/gcc/communityHall/controller/HeadquartersController.java @@ -8,20 +8,27 @@ import java.util.stream.Collectors; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; import com.gcc.communityHall.entity.GccBlockingDate; +import com.gcc.communityHall.entity.Login; +import com.gcc.communityHall.entity.LoginHallId; import com.gcc.communityHall.others.AppConfig; import com.gcc.communityHall.repository.GccBlockingDateRepository; +import com.gcc.communityHall.repository.LoginHallIdRepository; +import com.gcc.communityHall.repository.LoginRepository; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.format.annotation.DateTimeFormat; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.ResponseBody; import com.gcc.communityHall.entity.BookingDetails; import com.gcc.communityHall.entity.Users; import com.gcc.communityHall.repository.BookingDetailsRepository; +import com.gcc.communityHall.repository.HallDetailsRepository; import com.gcc.communityHall.repository.UsersRepository; import com.gcc.communityHall.service.BookingService; import com.gcc.communityHall.service.HallDetailService; @@ -29,6 +36,7 @@ import com.gcc.communityHall.service.ReasonMasterService; import com.gcc.communityHall.service.UserService; import jakarta.servlet.http.HttpSession; +import jakarta.transaction.Transactional; @Controller @RequestMapping("/communityhall/headquarters") @@ -57,13 +65,22 @@ public class HeadquartersController { @Autowired private AppConfig appConfig; + @Autowired + private LoginRepository loginRepository; + + @Autowired + private LoginHallIdRepository loginHallIdRepository; + + @Autowired + private HallDetailsRepository hallDetailsRepository; + @GetMapping("/dashboard") public String viewDashboard( @RequestParam(required = false, defaultValue = "all zones") String zone, Model model, HttpSession session) { String headquartersname = (String) session.getAttribute("usertype"); - if (headquartersname != null) { + if (headquartersname != null && "headquarters".equals(headquartersname)) { long mobileno = (long) session.getAttribute("mobileno"); model.addAttribute("mobileno", mobileno); List> getMonthCount = bookingDetailsRepository.getAllAdminmonthcount(zone); @@ -88,11 +105,10 @@ public class HeadquartersController { } } - @GetMapping("/Reports") public String viewReports(Model model, HttpSession session) { String headquartersname = (String) session.getAttribute("usertype"); - if (headquartersname != null) { + if (headquartersname != null && "headquarters".equals(headquartersname)) { long mobileno = (long) session.getAttribute("mobileno"); model.addAttribute("mobileno", mobileno); model.addAttribute("headquartersname", headquartersname); @@ -106,7 +122,7 @@ public class HeadquartersController { @GetMapping("/getReport") public String getReports(Model model, HttpSession session) { String headquartersname = (String) session.getAttribute("usertype"); - if (headquartersname != null) { + if (headquartersname != null && "headquarters".equals(headquartersname)) { long mobileno = (long) session.getAttribute("mobileno"); model.addAttribute("mobileno", mobileno); model.addAttribute("headquartersname", headquartersname); @@ -120,7 +136,7 @@ public class HeadquartersController { @GetMapping("/approval-history") public String viewApproval(Model model, HttpSession session) { String headquartersname = (String) session.getAttribute("usertype"); - if (headquartersname != null) { + if (headquartersname != null && "headquarters".equals(headquartersname)) { long mobileno = (long) session.getAttribute("mobileno"); model.addAttribute("mobileno", mobileno); model.addAttribute("headquartersname", headquartersname); @@ -139,7 +155,7 @@ public class HeadquartersController { @GetMapping("/user-approved") public String viewUserApproved(Model model, HttpSession session) { String headquartersname = (String) session.getAttribute("usertype"); - if (headquartersname != null) { + if (headquartersname != null && "headquarters".equals(headquartersname)) { long mobileno = (long) session.getAttribute("mobileno"); model.addAttribute("mobileno", mobileno); model.addAttribute("headquartersname", headquartersname); @@ -158,7 +174,7 @@ public class HeadquartersController { @GetMapping("/user-reject") public String viewUserReject(Model model, HttpSession session) { String headquartersname = (String) session.getAttribute("usertype"); - if (headquartersname != null) { + if (headquartersname != null && "headquarters".equals(headquartersname)) { long mobileno = (long) session.getAttribute("mobileno"); model.addAttribute("mobileno", mobileno); model.addAttribute("headquartersname", headquartersname); @@ -176,48 +192,60 @@ public class HeadquartersController { @PostMapping("/getReport") public String generateReport(Model model, - @RequestParam(name = "FromDate") @DateTimeFormat(iso = DateTimeFormat.ISO.DATE) String fromDate, - @RequestParam(name = "ToDate") @DateTimeFormat(iso = DateTimeFormat.ISO.DATE) String toDate, - @RequestParam(name = "request") String request, - @RequestParam(name = "userstatus", required = false) String userstatus, - @RequestParam(name = "usertype", required = false) String usertype, - @RequestParam(name = "bookingStatus", required = false) String bookingStatus, - @RequestParam(name = "refundStatus", required = false) String refundStatus, - @RequestParam(name = "paymentStatus", required = false) String paymentStatus, - @RequestParam(name = "filterby", required = false) String filterby, - @RequestParam(name = "zone1", required = false, defaultValue = "ALL") String zone, - @RequestParam(name = "division1", required = false, defaultValue = "ALL") String division, - @RequestParam(name = "hall1", required = false) Integer hallid, - @RequestParam(name = "basedon", required = false) String basedon, - @RequestParam(name = "bookingId", required = false) Long bookingId, - @RequestParam(name = "reporttype", required = false) String reporttype, - @RequestParam(name = "counterId", required = false) String counterId, HttpSession session) throws JsonProcessingException { + @RequestParam(name = "FromDate") @DateTimeFormat(iso = DateTimeFormat.ISO.DATE) String fromDate, + @RequestParam(name = "ToDate") @DateTimeFormat(iso = DateTimeFormat.ISO.DATE) String toDate, + @RequestParam(name = "request") String request, + @RequestParam(name = "userstatus", required = false) String userstatus, + @RequestParam(name = "usertype", required = false) String usertype, + @RequestParam(name = "bookingStatus", required = false) String bookingStatus, + @RequestParam(name = "refundStatus", required = false) String refundStatus, + @RequestParam(name = "paymentStatus", required = false) String paymentStatus, + @RequestParam(name = "filterby", required = false) String filterby, + @RequestParam(name = "zone1", required = false, defaultValue = "ALL") String zone, + @RequestParam(name = "division1", required = false, defaultValue = "ALL") String division, + @RequestParam(name = "hall1", required = false) Integer hallid, + @RequestParam(name = "basedon", required = false) String basedon, + @RequestParam(name = "bookingId", required = false) Long bookingId, + @RequestParam(name = "reporttype", required = false) String reporttype, + @RequestParam(name = "counterId", required = false) String counterId, HttpSession session) + throws JsonProcessingException { String headquartersname = (String) session.getAttribute("usertype"); - if (headquartersname != null) { + if (headquartersname != null && "headquarters".equals(headquartersname)) { long mobileno = (long) session.getAttribute("mobileno"); model.addAttribute("mobileno", mobileno); List userList = handleUserRequest(request, fromDate, toDate, userstatus, usertype); - List bookingList = handleBookingRequest(request, fromDate, toDate, bookingStatus, filterby, bookingId, zone, division, hallid); - List bookingSettlementList = handleBookingSettlementRequest(request, fromDate, toDate, refundStatus, filterby); - //List paymentList = request.equals("3") ? bookingService.getAllPaymentsDetails(fromDate, toDate,zone,division,hallid) : new ArrayList<>(); + List bookingList = handleBookingRequest(request, fromDate, toDate, bookingStatus, filterby, + bookingId, zone, division, hallid); + List bookingSettlementList = handleBookingSettlementRequest(request, fromDate, toDate, + refundStatus, filterby); + // List paymentList = request.equals("3") ? + // bookingService.getAllPaymentsDetails(fromDate, toDate,zone,division,hallid) : + // new ArrayList<>(); List paymentList = new ArrayList<>(); List extrapaymentList = new ArrayList<>(); if (request.equals("3")) { if (paymentStatus == null || paymentStatus.isEmpty()) { paymentList = bookingService.getAllPaymentsDetails(fromDate, toDate, null, zone, division, hallid); } else { - paymentList = bookingService.getAllPaymentsDetails(fromDate, toDate, paymentStatus, zone, division, hallid); + paymentList = bookingService.getAllPaymentsDetails(fromDate, toDate, paymentStatus, zone, division, + hallid); } } if (request.equals("8")) { if (paymentStatus == null || paymentStatus.isEmpty()) { - extrapaymentList = bookingService.getAllExtraPaymentsDetails(fromDate, toDate, null, zone, division, hallid); + extrapaymentList = bookingService.getAllExtraPaymentsDetails(fromDate, toDate, null, zone, division, + hallid); } else { - extrapaymentList = bookingService.getAllExtraPaymentsDetails(fromDate, toDate, paymentStatus, zone, division, hallid); + extrapaymentList = bookingService.getAllExtraPaymentsDetails(fromDate, toDate, paymentStatus, zone, + division, hallid); } } - List userbookingList = request.equals("4") ? bookingService.getBookingUserDetailsReport(fromDate, toDate) : new ArrayList<>(); - //List hallbookingList = request.equals("5") ? bookingService.getBookingHallDetailsReport(fromDate, toDate) : new ArrayList<>(); + List userbookingList = request.equals("4") + ? bookingService.getBookingUserDetailsReport(fromDate, toDate) + : new ArrayList<>(); + // List hallbookingList = request.equals("5") ? + // bookingService.getBookingHallDetailsReport(fromDate, toDate) : new + // ArrayList<>(); // In your controller method // Fetch booking count by zone List totalcount = new ArrayList<>(); @@ -227,13 +255,13 @@ public class HeadquartersController { totalcount = bookingDetailsRepository.countBookingsByZone(); // Format zone data totalcount = totalcount.stream() - .map(data -> new Object[]{"Zone-" + data[0], data[1]}) + .map(data -> new Object[] { "Zone-" + data[0], data[1] }) .collect(Collectors.toList()); } else if ("division".equals(basedon)) { totalcount = bookingDetailsRepository.countBookingsByDivisions(); // Format division data totalcount = totalcount.stream() - .map(data -> new Object[]{"Division-" + data[0], data[1]}) + .map(data -> new Object[] { "Division-" + data[0], data[1] }) .collect(Collectors.toList()); } @@ -244,22 +272,24 @@ public class HeadquartersController { model.addAttribute("basedon", basedon); model.addAttribute("totalcount", totalcount); model.addAttribute("totalBookings", totalBookings); - List hallbookingList = handleBookingHallDetailsReportRequest(request, fromDate, toDate, filterby, zone, division, hallid); + List hallbookingList = handleBookingHallDetailsReportRequest(request, fromDate, toDate, filterby, + zone, division, hallid); if ("9".equals(request)) { - if("abstract".equals(reporttype)){ + if ("abstract".equals(reporttype)) { List counterBookingList = new ArrayList<>(); counterBookingList = bookingService.getCounterWiseBookingCount(fromDate, toDate); model.addAttribute("counterBookingList", counterBookingList); System.out.println("counterBookingList.." + counterBookingList); - List hallBookingByCounter = bookingService.getHallWiseBookingDetails(fromDate, toDate, counterId); + List hallBookingByCounter = bookingService.getHallWiseBookingDetails(fromDate, toDate, + counterId); // Convert to JSON for JS usage String hallBookingJson = new ObjectMapper().writeValueAsString(hallBookingByCounter); model.addAttribute("hallBookingJson", hallBookingJson); - - List hallBookingDetails = bookingService.getBookingDetailsForAllHalls(fromDate, toDate, counterId, hallid); + List hallBookingDetails = bookingService.getBookingDetailsForAllHalls(fromDate, toDate, + counterId, hallid); String hallBookingDetailsJson = new ObjectMapper().writeValueAsString(hallBookingDetails); model.addAttribute("hallBookingDetailsJson", hallBookingDetailsJson); @@ -300,7 +330,8 @@ public class HeadquartersController { } } - private List handleBookingHallDetailsReportRequest(String request, String fromDate, String toDate, String filterby, String zone, String division, Integer hallid) { + private List handleBookingHallDetailsReportRequest(String request, String fromDate, String toDate, + String filterby, String zone, String division, Integer hallid) { if (!request.equals("5")) { return new ArrayList<>(); } @@ -321,7 +352,8 @@ public class HeadquartersController { return new ArrayList<>(); } - private List handleUserRequest(String request, String fromDate, String toDate, String userstatus, String usertype) { + private List handleUserRequest(String request, String fromDate, String toDate, String userstatus, + String usertype) { if (!request.equals("1")) { return new ArrayList<>(); } @@ -337,8 +369,8 @@ public class HeadquartersController { return userService.getAllUsers(fromDate, toDate); } - - private List handleBookingRequest(String request, String fromDate, String toDate, String bookingStatus, String filterby, Long bookingId, String zone, String division, Integer hallid) { + private List handleBookingRequest(String request, String fromDate, String toDate, String bookingStatus, + String filterby, Long bookingId, String zone, String division, Integer hallid) { if (!request.equals("2")) { return new ArrayList<>(); } @@ -349,10 +381,12 @@ public class HeadquartersController { return bookingDetailsRepo.getAllBookingDetailsWithBookingId(fromDate, toDate, bookingId); } if (bookingId != null && !bookingStatus.isEmpty()) { - return bookingDetailsRepo.getAllBookingDetailsWithBookingIdwithbookingStatus(fromDate, toDate, bookingId, bookingStatus); + return bookingDetailsRepo.getAllBookingDetailsWithBookingIdwithbookingStatus(fromDate, toDate, bookingId, + bookingStatus); } if (bookingId == null && filterby.isEmpty() && !bookingStatus.isEmpty()) { - return bookingService.getBookingDetailsByBookingDateWithStatus(fromDate, toDate, bookingStatus, zone, division, hallid); + return bookingService.getBookingDetailsByBookingDateWithStatus(fromDate, toDate, bookingStatus, zone, + division, hallid); } if (!filterby.isEmpty()) { @@ -360,7 +394,8 @@ public class HeadquartersController { if (bookingStatus.isEmpty()) { return bookingService.getBookingDetailsByBookingDate(fromDate, toDate, zone, division, hallid); } else { - return bookingService.getBookingDetailsByBookingDateWithStatus(fromDate, toDate, bookingStatus, zone, division, hallid); + return bookingService.getBookingDetailsByBookingDateWithStatus(fromDate, toDate, bookingStatus, + zone, division, hallid); } } @@ -368,7 +403,8 @@ public class HeadquartersController { if (bookingStatus.isEmpty()) { return bookingService.getBookingDetailsByEventDate(fromDate, toDate, zone, division, hallid); } else { - return bookingService.getBookingDetailsByEventDateWithStatus(fromDate, toDate, bookingStatus, zone, division, hallid); + return bookingService.getBookingDetailsByEventDateWithStatus(fromDate, toDate, bookingStatus, zone, + division, hallid); } } @@ -377,8 +413,8 @@ public class HeadquartersController { return new ArrayList<>(); } - - private List handleBookingSettlementRequest(String request, String fromDate, String toDate, String refundStatus, String filterby) { + private List handleBookingSettlementRequest(String request, String fromDate, String toDate, + String refundStatus, String filterby) { if (!request.equals("6")) { return new ArrayList<>(); } @@ -394,7 +430,8 @@ public class HeadquartersController { if (refundStatus.isEmpty()) { return bookingService.getAllBookingsettlementDetailsByBookingDate(fromDate, toDate); } else { - return bookingService.getAllBookingsettlementDetailsByBookingDateWithStatus(fromDate, toDate, refundStatus); + return bookingService.getAllBookingsettlementDetailsByBookingDateWithStatus(fromDate, toDate, + refundStatus); } } @@ -402,7 +439,8 @@ public class HeadquartersController { if (refundStatus.isEmpty()) { return bookingService.getAllBookingsettlementDetailsByEventDate(fromDate, toDate); } else { - return bookingService.getAllBookingsettlementDetailsByEventDateWithStatus(fromDate, toDate, refundStatus); + return bookingService.getAllBookingsettlementDetailsByEventDateWithStatus(fromDate, toDate, + refundStatus); } } @@ -415,7 +453,7 @@ public class HeadquartersController { @GetMapping("/ongoingevents") public String viewRecentevents(Model model, HttpSession session) { String headquartersname = (String) session.getAttribute("usertype"); - if (headquartersname != null) { + if (headquartersname != null && "headquarters".equals(headquartersname)) { long mobileno = (long) session.getAttribute("mobileno"); model.addAttribute("mobileno", mobileno); List presenteventslist = bookingDetailsRepository.findPresentBookingList(); @@ -436,13 +474,14 @@ public class HeadquartersController { @GetMapping("/booking-list") public String viewBookingList(Model model, HttpSession session) { String headquartersname = (String) session.getAttribute("usertype"); - if (headquartersname != null) { + if (headquartersname != null && "headquarters".equals(headquartersname)) { long mobileno = (long) session.getAttribute("mobileno"); model.addAttribute("mobileno", mobileno); model.addAttribute("headquartersname", headquartersname); List bookingList = bookingDetailsRepository.getAllApprovedList(); model.addAttribute("bookingList", bookingList); - return "headquarters/booking-list"; // Assuming "officer/rejected-booking-list" is the name of your HTML template + return "headquarters/booking-list"; // Assuming "officer/rejected-booking-list" is the name of your HTML + // template } else { session.invalidate(); // Invalidate the session to clear all session attributes return "redirect:/communityhall/login"; @@ -452,7 +491,7 @@ public class HeadquartersController { @GetMapping("/rejected-list") public String viewRejectedBookings(Model model, HttpSession session) { String headquartersname = (String) session.getAttribute("usertype"); - if (headquartersname != null) { + if (headquartersname != null && "headquarters".equals(headquartersname)) { long mobileno = (long) session.getAttribute("mobileno"); model.addAttribute("mobileno", mobileno); model.addAttribute("headquartersname", headquartersname); @@ -469,7 +508,7 @@ public class HeadquartersController { @GetMapping("/bookingwaitinglist") public String viewWaitingBookings(Model model, HttpSession session) { String headquartersname = (String) session.getAttribute("usertype"); - if (headquartersname != null) { + if (headquartersname != null && "headquarters".equals(headquartersname)) { long mobileno = (long) session.getAttribute("mobileno"); model.addAttribute("mobileno", mobileno); model.addAttribute("headquartersname", headquartersname); @@ -486,7 +525,7 @@ public class HeadquartersController { @GetMapping("/settlement-approved") public String viewSettlementMaster(Model model, HttpSession session) { String headquartersname = (String) session.getAttribute("usertype"); - if (headquartersname != null) { + if (headquartersname != null && "headquarters".equals(headquartersname)) { long mobileno = (long) session.getAttribute("mobileno"); model.addAttribute("mobileno", mobileno); List approvedSettlements = bookingDetailsRepository.findAllWithApprovedRefundStatus(); @@ -508,7 +547,7 @@ public class HeadquartersController { @GetMapping("/settlement-initiatedlist") public String viewSettlementInitiatedMaster(Model model, HttpSession session) { String headquartersname = (String) session.getAttribute("usertype"); - if (headquartersname != null) { + if (headquartersname != null && "headquarters".equals(headquartersname)) { long mobileno = (long) session.getAttribute("mobileno"); model.addAttribute("mobileno", mobileno); List settlement = bookingDetailsRepository.findByBookingDetailsRefundStatus(); @@ -529,21 +568,21 @@ public class HeadquartersController { @GetMapping("/settlement-list") public String settlementPendingList(Model model, HttpSession session) { String headquartersname = (String) session.getAttribute("usertype"); - if (headquartersname != null) { + if (headquartersname != null && "headquarters".equals(headquartersname)) { model.addAttribute("headquartersname", headquartersname); long mobileno = (long) session.getAttribute("mobileno"); model.addAttribute("mobileno", mobileno); model.addAttribute("title", "settlement Pending"); String zone = (String) session.getAttribute("zone"); model.addAttribute("zone", zone); - //ak - List settlementIntiated = bookingDetailsRepository.findSettlementInitiatedPending(); + // ak + List settlementIntiated = bookingDetailsRepository.findSettlementInitiatedPending(); List settlement = bookingDetailsRepository.findAllSettlementPending(); List cancelledbookings = bookingDetailsRepository.findAllSettlementCancelledList(); List rejectedbookings = bookingDetailsRepository.findAllSettlementRejectedList(); model.addAttribute("settlementlist", settlement); - //AK - model.addAttribute("settlementIntiated", settlementIntiated); + // AK + model.addAttribute("settlementIntiated", settlementIntiated); model.addAttribute("cancelledbookings", cancelledbookings); model.addAttribute("rejectedbookings", rejectedbookings); return "headquarters/settlement-list"; @@ -556,7 +595,7 @@ public class HeadquartersController { @GetMapping("/refundfailed-list") public String RefundFailedList(Model model, HttpSession session) { String headquartersname = (String) session.getAttribute("usertype"); - if (headquartersname != null) { + if (headquartersname != null && "headquarters".equals(headquartersname)) { model.addAttribute("headquartersname", headquartersname); long mobileno = (long) session.getAttribute("mobileno"); model.addAttribute("mobileno", mobileno); @@ -564,8 +603,10 @@ public class HeadquartersController { String zone = (String) session.getAttribute("zone"); model.addAttribute("zone", zone); List settlementrefundfailed = bookingDetailsRepository.findAllSettlementRefundFailed(); - List refundfailedcancelledbookings = bookingDetailsRepository.findAllRefundFaileCancelledList(); - List refundfailedrejectedbookings = bookingDetailsRepository.findAllRefundFaileRejectedList(); + List refundfailedcancelledbookings = bookingDetailsRepository + .findAllRefundFaileCancelledList(); + List refundfailedrejectedbookings = bookingDetailsRepository + .findAllRefundFaileRejectedList(); model.addAttribute("settlementrefundfailed", settlementrefundfailed); model.addAttribute("refundfailedcancelledbookings", refundfailedcancelledbookings); model.addAttribute("refundfailedrejectedbookings", refundfailedrejectedbookings); @@ -579,7 +620,7 @@ public class HeadquartersController { @GetMapping("/settlement-completedlist") public String viewSettlementcompletedMaster(Model model, HttpSession session) { String headquartersname = (String) session.getAttribute("usertype"); - if (headquartersname != null) { + if (headquartersname != null && "headquarters".equals(headquartersname)) { long mobileno = (long) session.getAttribute("mobileno"); model.addAttribute("mobileno", mobileno); List completedlist = bookingDetailsRepository.findSettlementCompletedList(); @@ -600,7 +641,7 @@ public class HeadquartersController { @GetMapping("/settlementlist") public String viewSettlementList(Model model, HttpSession session) { String headquartersname = (String) session.getAttribute("usertype"); - if (headquartersname != null) { + if (headquartersname != null && "headquarters".equals(headquartersname)) { List settlemetList = bookingDetailsRepository.getAllSettlementList(); model.addAttribute("headquartersname", headquartersname); model.addAttribute("settlemetList", settlemetList); @@ -614,7 +655,7 @@ public class HeadquartersController { @GetMapping("/headquarterspage") public String viewcaretaker(Model model, HttpSession session, @RequestParam("bookingId") int bookingId) { String caretakerName = (String) session.getAttribute("usertype"); - if (caretakerName != null) { + if (caretakerName != null && "headquarters".equals(caretakerName)) { long mobileno = (long) session.getAttribute("mobileno"); model.addAttribute("mobileno", mobileno); model.addAttribute("caretakerName", caretakerName); @@ -632,7 +673,7 @@ public class HeadquartersController { @GetMapping("/settlement-reject") public String settlementRejectedList(Model model, HttpSession session) { String headquartersname = (String) session.getAttribute("usertype"); - if (headquartersname != null) { + if (headquartersname != null && "headquarters".equals(headquartersname)) { List settlement = bookingDetailsRepository.findAllSettlementRejected(); model.addAttribute("headquartersname", headquartersname); model.addAttribute("title", "Settlement Rejected"); @@ -653,7 +694,7 @@ public class HeadquartersController { @GetMapping("/Gccblocking") public String viewGccBlocking(Model model, HttpSession session) { String headquartersname = (String) session.getAttribute("usertype"); - if (headquartersname != null) { + if (headquartersname != null && "headquarters".equals(headquartersname)) { long mobileno = (long) session.getAttribute("mobileno"); model.addAttribute("mobileno", mobileno); model.addAttribute("headquartersname", headquartersname); @@ -703,7 +744,7 @@ public class HeadquartersController { @GetMapping("/viewUploadNoc") public String viewUploadNoc(Model model, HttpSession session) { String headquartersname = (String) session.getAttribute("usertype"); - if (headquartersname != null) { + if (headquartersname != null && "headquarters".equals(headquartersname)) { long mobileno = (long) session.getAttribute("mobileno"); model.addAttribute("mobileno", mobileno); model.addAttribute("headquartersname", headquartersname); @@ -720,5 +761,255 @@ public class HeadquartersController { } } -} + // Newly added by kani for care-take and officer login creation 11/06/2026 + + @GetMapping("/login-creation") + public String viewLoginCreation(Model model, HttpSession session) { + String headquartersname = (String) session.getAttribute("usertype"); + if (headquartersname != null && "headquarters".equals(headquartersname)) { + long mobileno = (long) session.getAttribute("mobileno"); + model.addAttribute("mobileno", mobileno); + model.addAttribute("headquartersname", headquartersname); + + // Fetch existing active non-admin logins (returns projection, not full entity) + List> loginList = loginRepository.findActiveLogins(); + model.addAttribute("loginList", loginList); + + // Fetch hall details for the modal dropdown + List> hallList = hallDetailsRepository.getAllHalls(); + model.addAttribute("hallList", hallList); + + return "headquarters/login-creation"; + } else { + session.invalidate(); + return "redirect:/communityhall/login"; + } + } + + @PostMapping("/login-creation/save") + @ResponseBody + @Transactional + public Map saveLoginCreation( + @RequestParam("mobileNumber") long mobileNumber, + @RequestParam("name") String name, + @RequestParam("password") String password, + @RequestParam("userType") String userType, + @RequestParam("zone") String zone, + @RequestParam(value = "hallIds", required = false) List hallIds, + HttpSession session) { + + Map response = new HashMap<>(); + String headquartersname = (String) session.getAttribute("usertype"); + if (headquartersname == null && "headquarters".equals(headquartersname)) { + response.put("status", "error"); + response.put("message", "Session expired. Please log in again."); + return response; + } + try { + /* -------- Duplicate hall check for counter / caretaker -------- */ + boolean isSingleMode = "counter".equals(userType) || "caretaker".equals(userType); + boolean isMulitpleMode = "officer".equals(userType); + if (isSingleMode && hallIds != null && !hallIds.isEmpty()) { + int hallId = hallIds.get(0); + int existingCount = loginRepository.countActiveLoginsByHallId(hallId, userType); + if (existingCount > 0) { + // Fetch hall name for a clear message + String hallName = hallId + ""; + try { + String fetched = hallDetailsRepository.findHallNameById(hallId); + if (fetched != null && !fetched.isBlank()) + hallName = fetched; + } catch (Exception ignored) { + } + response.put("status", "error"); + response.put("message", "A login already exists for hall \"" + hallName + + "\". Only one counter/caretaker login is allowed per hall."); + return response; + } + } + + /* -------- Duplicate hall check for officer -------- */ + if (isMulitpleMode && hallIds != null && !hallIds.isEmpty()) { + int existingCount = loginRepository.getActiveLoginsByHallIds(hallIds, userType); + if (existingCount > 0) { + response.put("status", "error"); + response.put("message", + "A login already exists for the selected hall(s). Only one officer login is allowed per hall."); + return response; + } + } + Login login = new Login(); + login.setMobileNumber(mobileNumber); + login.setName(name); + login.setPassword(password); + login.setUserType(userType); + login.setZone(zone); + login.setActive(true); + login.setDelete(false); + + if (hallIds == null || hallIds.isEmpty()) { + // HQ may have no hall assigned + loginRepository.save(login); + } else if (hallIds.size() == 1) { + // Single hall: store directly in login.hallId + login.setHallId(hallIds.get(0)); + loginRepository.save(login); + } else { + // Multiple halls: store first in hallId, rest in login_hall_ids + login.setHallId(hallIds.get(0)); + Login savedLogin = loginRepository.save(login); + for (int hallId : hallIds) { + LoginHallId loginHallId = new LoginHallId(savedLogin, hallId); + loginHallIdRepository.save(loginHallId); + } + } + + response.put("status", "success"); + response.put("message", "Login created successfully."); + } catch (Exception e) { + response.put("status", "error"); + response.put("message", "Error creating login: " + e.getMessage()); + } + return response; + } + + @PostMapping("/login-creation/delete/{id}") + @ResponseBody + @Transactional + public Map deleteLogin(@PathVariable("id") int id, HttpSession session) { + Map response = new HashMap<>(); + String headquartersname = (String) session.getAttribute("usertype"); + if (headquartersname == null && "headquarters".equals(headquartersname)) { + response.put("status", "error"); + response.put("message", "Session expired. Please log in again."); + return response; + } + try { + Login login = loginRepository.findLoginById(id); + if (login == null) { + response.put("status", "error"); + response.put("message", "Login not found."); + return response; + } + // Soft delete: set is_active = 0, is_delete = 1 + login.setActive(false); + login.setDelete(true); + loginRepository.save(login); + + // Also soft-delete any related login_hall_ids + loginHallIdRepository.softDeleteByLoginId(id); + + response.put("status", "success"); + response.put("message", "Login deleted successfully."); + } catch (Exception e) { + response.put("status", "error"); + response.put("message", "Error deleting login: " + e.getMessage()); + } + return response; + } + + @GetMapping("/login-creation/check-mobile") + @ResponseBody + public Map checkMobileExists(@RequestParam("mobileNumber") long mobileNumber, HttpSession session) { + Map response = new HashMap<>(); + try { + int count = loginRepository.countByMobileNumber(mobileNumber); + response.put("exists", count > 0); + } catch (Exception e) { + response.put("exists", false); + response.put("error", e.getMessage()); + } + return response; + } + + @GetMapping("/login-creation/halls-by-zone") + @ResponseBody + public List> getHallsByZone(@RequestParam("zone") String zone, HttpSession session) { + try { + return hallDetailsRepository.getHallsByZone(zone); + } catch (Exception e) { + return new java.util.ArrayList<>(); + } + } + + @GetMapping("/login-creation/get-login-halls") + @ResponseBody + public Map getLoginHalls(@RequestParam("loginId") int loginId, HttpSession session) { + Map response = new HashMap<>(); + try { + Login login = loginRepository.findLoginById(loginId); + if (login == null) { + response.put("status", "error"); + response.put("message", "Login not found."); + return response; + } + // Collect all assigned hall IDs + java.util.List assignedHallIds = new java.util.ArrayList<>(); + if (login.getHallId() != 0) { + assignedHallIds.add(login.getHallId()); + } + loginHallIdRepository.findActiveByLoginId(loginId).forEach(lh -> assignedHallIds.add(lh.getHallId())); + + response.put("status", "success"); + response.put("loginId", loginId); + response.put("name", login.getName()); + response.put("zone", login.getZone()); + response.put("userType", login.getUserType()); + response.put("assignedHallIds", assignedHallIds); + // Also return all halls for the zone + response.put("hallsForZone", hallDetailsRepository.getHallsByZone(login.getZone())); + } catch (Exception e) { + response.put("status", "error"); + response.put("message", "Error fetching login halls: " + e.getMessage()); + } + return response; + } + + @PostMapping("/login-creation/update-halls") + @ResponseBody + @Transactional + public Map updateLoginHalls( + @RequestParam("loginId") int loginId, + @RequestParam("hallIds") java.util.List hallIds, + HttpSession session) { + Map response = new HashMap<>(); + try { + Login login = loginRepository.findLoginById(loginId); + if (login == null) { + response.put("status", "error"); + response.put("message", "Login not found."); + return response; + } + if (hallIds == null || hallIds.isEmpty()) { + response.put("status", "error"); + response.put("message", "At least one hall must be selected."); + return response; + } + + // Clear all existing login_hall_ids rows for this login + loginHallIdRepository.softDeleteByLoginId(loginId); + + if (hallIds.size() == 1) { + // Single hall: store in login.hall_id only + login.setHallId(hallIds.get(0)); + loginRepository.save(login); + } else { + // Multiple halls: first goes to login.hall_id, rest to login_hall_ids + login.setHallId(hallIds.get(0)); + loginRepository.save(login); + for (int i = 1; i < hallIds.size(); i++) { + LoginHallId lh = new LoginHallId(login, hallIds.get(i)); + loginHallIdRepository.save(lh); + } + } + response.put("status", "success"); + response.put("message", "Hall assignment updated successfully."); + } catch (Exception e) { + response.put("status", "error"); + response.put("message", "Error updating halls: " + e.getMessage()); + } + return response; + } + +} diff --git a/src/main/java/com/gcc/communityHall/controller/OfficerController.java b/src/main/java/com/gcc/communityHall/controller/OfficerController.java index 4e48263e..369bad13 100644 --- a/src/main/java/com/gcc/communityHall/controller/OfficerController.java +++ b/src/main/java/com/gcc/communityHall/controller/OfficerController.java @@ -80,13 +80,17 @@ public class OfficerController { @GetMapping("/officer-dashboard") public String viewDashboard(Model model, HttpSession session) { String officername = (String) session.getAttribute("usertype"); - if (officername != null) { + if (officername != null && "officer".equals(officername)) { String zone = (String) session.getAttribute("zone"); model.addAttribute("officername", officername); long mobileno = (long) session.getAttribute("mobileno"); - model.addAttribute("mobileno", mobileno); + List hallIds = (List) session.getAttribute("hall_ids"); + + System.out.println("HallIds in officer Dashboard: " + hallIds.toString()); + model.addAttribute("mobileno", mobileno); model.addAttribute("zone", zone); + model.addAttribute("hallIds", hallIds); return "officer/officer-dashboard"; } else { @@ -98,15 +102,18 @@ public class OfficerController { @GetMapping("/booking-pending") public String viewhall(Model model, HttpSession session) { String officername = (String) session.getAttribute("usertype"); - if (officername != null) { + if (officername != null && "officer".equals(officername)) { model.addAttribute("officername", officername); long mobileno = (long) session.getAttribute("mobileno"); model.addAttribute("mobileno", mobileno); model.addAttribute("title", "pending bookings"); model.addAttribute("baseURL", appConfig.getBaseUrl()); String zone = (String) session.getAttribute("zone"); + List hallIds = (List) session.getAttribute("hall_ids"); model.addAttribute("zone", zone); - List pendingbooking = bookingDetailsRepository.getPendingOrPaymentFailureBookings(zone); + model.addAttribute("hallIds", hallIds); + List pendingbooking = bookingDetailsRepository.getPendingOrPaymentFailureBookings(zone, + hallIds); model.addAttribute("pendingbooking", pendingbooking); return "officer/booking-pending"; } else { @@ -118,16 +125,18 @@ public class OfficerController { @GetMapping("/payment-list") public String viewPayment(Model model, HttpSession session) { String officername = (String) session.getAttribute("usertype"); - if (officername != null) { + if (officername != null && "officer".equals(officername)) { model.addAttribute("officername", officername); long mobileno = (long) session.getAttribute("mobileno"); model.addAttribute("mobileno", mobileno); model.addAttribute("title", "paymentlist"); model.addAttribute("baseURL", appConfig.getBaseUrl()); String zone = (String) session.getAttribute("zone"); + List hallIds = (List) session.getAttribute("hall_ids"); model.addAttribute("zone", zone); + model.addAttribute("hallIds", hallIds); // System.out.println(zone); - List pay = paymentsRepository.getPaymentListByzone(zone); + List pay = paymentsRepository.getPaymentListByzoneandHall(zone, hallIds); model.addAttribute("paymentlist", pay); return "officer/payment-list"; } else { @@ -139,15 +148,17 @@ public class OfficerController { @GetMapping("/bookingwaitinglist") public String viewWaitingBookings(Model model, HttpSession session) { String officername = (String) session.getAttribute("usertype"); - if (officername != null) { + if (officername != null && "officer".equals(officername)) { model.addAttribute("officername", officername); long mobileno = (long) session.getAttribute("mobileno"); model.addAttribute("mobileno", mobileno); model.addAttribute("title", "bookinglist"); model.addAttribute("baseURL", appConfig.getBaseUrl()); String zone = (String) session.getAttribute("zone"); + List hallIds = (List) session.getAttribute("hall_ids"); model.addAttribute("zone", zone); - List bookingList = bookingDetailsRepository.getWaitinglist(zone); + model.addAttribute("hallIds", hallIds); + List bookingList = bookingDetailsRepository.getWaitinglist(zone, hallIds); model.addAttribute("bookingList", bookingList); return "officer/booking-list"; // Assuming "officer/rejected-booking-list" is the name of your HTML template } else { @@ -159,15 +170,17 @@ public class OfficerController { @GetMapping("/booking-list") public String viewBookingList(Model model, HttpSession session) { String officername = (String) session.getAttribute("usertype"); - if (officername != null) { + if (officername != null && "officer".equals(officername)) { model.addAttribute("officername", officername); long mobileno = (long) session.getAttribute("mobileno"); model.addAttribute("mobileno", mobileno); model.addAttribute("title", "bookinglist"); model.addAttribute("baseURL", appConfig.getBaseUrl()); String zone = (String) session.getAttribute("zone"); + List hallIds = (List) session.getAttribute("hall_ids"); model.addAttribute("zone", zone); - List bookingList = bookingDetailsRepository.getApprovedlist(zone); + model.addAttribute("hallIds", hallIds); + List bookingList = bookingDetailsRepository.getApprovedlist(zone, hallIds); model.addAttribute("bookingList", bookingList); return "officer/booking-list"; // Assuming "officer/rejected-booking-list" is the name of your HTML template } else { @@ -179,15 +192,17 @@ public class OfficerController { @GetMapping("/rejected-list") public String viewRejectedBookings(Model model, HttpSession session) { String officername = (String) session.getAttribute("usertype"); - if (officername != null) { + if (officername != null && "officer".equals(officername)) { model.addAttribute("officername", officername); long mobileno = (long) session.getAttribute("mobileno"); model.addAttribute("mobileno", mobileno); model.addAttribute("title", "rejectedlist"); model.addAttribute("baseURL", appConfig.getBaseUrl()); String zone = (String) session.getAttribute("zone"); + List hallIds = (List) session.getAttribute("hall_ids"); model.addAttribute("zone", zone); - List rejectedBookings = bookingDetailsRepository.getrejectedlist(zone); + model.addAttribute("hallIds", hallIds); + List rejectedBookings = bookingDetailsRepository.getrejectedlist(zone, hallIds); model.addAttribute("rejectedBookings", rejectedBookings); return "officer/rejected-list"; @@ -200,21 +215,23 @@ public class OfficerController { @GetMapping("/settlement-list") public String settlementPendingList(Model model, HttpSession session) { String officername = (String) session.getAttribute("usertype"); - if (officername != null) { + if (officername != null && "officer".equals(officername)) { model.addAttribute("officername", officername); long mobileno = (long) session.getAttribute("mobileno"); model.addAttribute("mobileno", mobileno); model.addAttribute("title", "settlement Pending"); model.addAttribute("baseURL", appConfig.getBaseUrl()); String zone = (String) session.getAttribute("zone"); + List hallIds = (List) session.getAttribute("hall_ids"); model.addAttribute("zone", zone); + model.addAttribute("hallIds", hallIds); System.out.println("Zone: " + zone); - List settlement = bookingDetailsRepository.findSettlementPendingByZone(zone); + List settlement = bookingDetailsRepository.findSettlementPendingByZone(zone, hallIds); // ak List settlementIntiated = bookingDetailsRepository - .findSettlementInitiatedPendingByZone(zone); - List cancelledbookings = bookingDetailsRepository.findCancelledListByZone(zone); - List rejectedbookings = bookingDetailsRepository.findRejectedListByZone(zone); + .findSettlementInitiatedPendingByZone(zone, hallIds); + List cancelledbookings = bookingDetailsRepository.findCancelledListByZone(zone, hallIds); + List rejectedbookings = bookingDetailsRepository.findRejectedListByZone(zone, hallIds); model.addAttribute("settlementlist", settlement); // AK model.addAttribute("settlementIntiated", settlementIntiated); @@ -231,20 +248,22 @@ public class OfficerController { @GetMapping("/refundfailed-list") public String RefundFailedList(Model model, HttpSession session) { String officername = (String) session.getAttribute("usertype"); - if (officername != null) { + if (officername != null && "officer".equals(officername)) { model.addAttribute("officername", officername); long mobileno = (long) session.getAttribute("mobileno"); model.addAttribute("mobileno", mobileno); model.addAttribute("title", "settlementapproved"); model.addAttribute("baseURL", appConfig.getBaseUrl()); String zone = (String) session.getAttribute("zone"); + List hallIds = (List) session.getAttribute("hall_ids"); model.addAttribute("zone", zone); + model.addAttribute("hallIds", hallIds); List settlementrefundfailed = bookingDetailsRepository - .findSettlementRefundFailedByZone(zone); + .findSettlementRefundFailedByZone(zone, hallIds); List refundfailedcancelledbookings = bookingDetailsRepository - .findRefundFaileCancelledListByZone(zone); + .findRefundFaileCancelledListByZone(zone, hallIds); List refundfailedrejectedbookings = bookingDetailsRepository - .findRefundFaileRejectedListByZone(zone); + .findRefundFaileRejectedListByZone(zone, hallIds); model.addAttribute("settlementrefundfailed", settlementrefundfailed); model.addAttribute("refundfailedcancelledbookings", refundfailedcancelledbookings); model.addAttribute("refundfailedrejectedbookings", refundfailedrejectedbookings); @@ -258,19 +277,21 @@ public class OfficerController { @GetMapping("/settlement-approved") public String settlementApprovedList(Model model, HttpSession session) { String officername = (String) session.getAttribute("usertype"); - if (officername != null) { + if (officername != null && "officer".equals(officername)) { model.addAttribute("officername", officername); long mobileno = (long) session.getAttribute("mobileno"); model.addAttribute("mobileno", mobileno); model.addAttribute("title", "settlementapproved"); model.addAttribute("baseURL", appConfig.getBaseUrl()); String zone = (String) session.getAttribute("zone"); + List hallIds = (List) session.getAttribute("hall_ids"); model.addAttribute("zone", zone); - List settlement = bookingDetailsRepository.findSettlementApprovedByZone(zone); + model.addAttribute("hallIds", hallIds); + List settlement = bookingDetailsRepository.findSettlementApprovedByZone(zone, hallIds); List approvedcancelledbookings = bookingDetailsRepository - .findapprovedCancelledListByZone(zone); + .findapprovedCancelledListByZone(zone, hallIds); List approvedrejectedbookings = bookingDetailsRepository - .findapprovedRejectedListByZone(zone); + .findapprovedRejectedListByZone(zone, hallIds); model.addAttribute("approvedSettlementlist", settlement); model.addAttribute("approvedcancelledbookings", approvedcancelledbookings); model.addAttribute("approvedrejectedbookings", approvedrejectedbookings); @@ -284,15 +305,17 @@ public class OfficerController { @GetMapping("/settlement-reject") public String settlementRejectedList(Model model, HttpSession session) { String officername = (String) session.getAttribute("usertype"); - if (officername != null) { + if (officername != null && "officer".equals(officername)) { model.addAttribute("officername", officername); long mobileno = (long) session.getAttribute("mobileno"); model.addAttribute("mobileno", mobileno); model.addAttribute("title", "settlement rejected"); model.addAttribute("baseURL", appConfig.getBaseUrl()); String zone = (String) session.getAttribute("zone"); + List hallIds = (List) session.getAttribute("hall_ids"); model.addAttribute("zone", zone); - List settlement = bookingDetailsRepository.findSettlementRejectedByZone(zone); + model.addAttribute("hallIds", hallIds); + List settlement = bookingDetailsRepository.findSettlementRejectedByZone(zone, hallIds); model.addAttribute("rejectSettlementlist", settlement); return "officer/settlement-reject"; } else { @@ -304,16 +327,19 @@ public class OfficerController { @GetMapping("/settlement-completedlist") public String viewSettlementcompletedMaster(Model model, HttpSession session) { String officername = (String) session.getAttribute("usertype"); - if (officername != null) { + if (officername != null && "officer".equals(officername)) { long mobileno = (long) session.getAttribute("mobileno"); model.addAttribute("mobileno", mobileno); String zone = (String) session.getAttribute("zone"); + List hallIds = (List) session.getAttribute("hall_ids"); model.addAttribute("zone", zone); - List completedlist = bookingDetailsRepository.findSettlementCompletedListbyzone(zone); + model.addAttribute("hallIds", hallIds); + List completedlist = bookingDetailsRepository + .findSettlementCompletedListbyzone(zone, hallIds); List cancelledcompletedlist = bookingDetailsRepository - .findCancelledCompletedListbyzone(zone); + .findCancelledCompletedListbyzone(zone, hallIds); List rejectedcompletedlist = bookingDetailsRepository - .findRejectedSettlementCompletedListbyzone(zone); + .findRejectedSettlementCompletedListbyzone(zone, hallIds); model.addAttribute("title", "settlement initiate"); model.addAttribute("officername", officername); model.addAttribute("completedlist", completedlist); @@ -329,12 +355,14 @@ public class OfficerController { @GetMapping("/reports") public String viewReports(Model model, HttpSession session) { String officername = (String) session.getAttribute("usertype"); - if (officername != null) { + if (officername != null && "officer".equals(officername)) { String zone = (String) session.getAttribute("zone"); + List hallIds = (List) session.getAttribute("hall_ids"); model.addAttribute("officername", officername); long mobileno = (long) session.getAttribute("mobileno"); model.addAttribute("mobileno", mobileno); model.addAttribute("zone", zone); + model.addAttribute("hallIds", hallIds); List hallnames = hallDetailsService.getHallNames(); model.addAttribute("hallnames", hallnames); return "officer/report"; @@ -347,12 +375,14 @@ public class OfficerController { @GetMapping("/getReport") public String viewgetReports(Model model, HttpSession session) { String officername = (String) session.getAttribute("usertype"); - if (officername != null) { + if (officername != null && "officer".equals(officername)) { String zone = (String) session.getAttribute("zone"); + List hallIds = (List) session.getAttribute("hall_ids"); model.addAttribute("officername", officername); long mobileno = (long) session.getAttribute("mobileno"); model.addAttribute("mobileno", mobileno); model.addAttribute("zone", zone); + model.addAttribute("hallIds", hallIds); List hallnames = hallDetailsService.getHallNames(); model.addAttribute("hallnames", hallnames); return "officer/report"; @@ -372,9 +402,11 @@ public class OfficerController { @RequestParam(name = "refundStatus", required = false) String refundStatus, @RequestParam(name = "hallname", required = false, defaultValue = "0") Integer hallId) { String officername = (String) session.getAttribute("usertype"); - if (officername != null) { + if (officername != null && "officer".equals(officername)) { String zone = (String) session.getAttribute("zone"); + List hallIds = (List) session.getAttribute("hall_ids"); model.addAttribute("zone", zone); + model.addAttribute("hallIds", hallIds); model.addAttribute("officername", officername); long mobileno = (long) session.getAttribute("mobileno"); model.addAttribute("mobileno", mobileno); @@ -519,14 +551,16 @@ public class OfficerController { @GetMapping("/counter-refund") public String counterRefundList(Model model, HttpSession session) { String officername = (String) session.getAttribute("usertype"); - if (officername != null) { + if (officername != null && "officer".equals(officername)) { model.addAttribute("officername", officername); long mobileno = (long) session.getAttribute("mobileno"); model.addAttribute("mobileno", mobileno); model.addAttribute("title", "settlement rejected"); model.addAttribute("baseURL", appConfig.getBaseUrl()); String zone = (String) session.getAttribute("zone"); + List hallIds = (List) session.getAttribute("hall_ids"); model.addAttribute("zone", zone); + model.addAttribute("hallIds", hallIds); List counterRefund = counterRefundListRepository.findCounterRefundList(zone); model.addAttribute("counterRefund", counterRefund); return "officer/counter-refund"; @@ -547,10 +581,12 @@ public class OfficerController { @GetMapping("/Gccblocking") public String viewGccBlocking(Model model, HttpSession session) { String officername = (String) session.getAttribute("usertype"); - if (officername != null) { + if (officername != null && "officer".equals(officername)) { long mobileno = (long) session.getAttribute("mobileno"); + List accesshallIds = (List) session.getAttribute("hall_ids"); model.addAttribute("mobileno", mobileno); model.addAttribute("officername", officername); + model.addAttribute("hallIds", accesshallIds); // Fetch all blocked GCC dates List gccBlocked = blockingDateRepository.findAllBlocked(); diff --git a/src/main/java/com/gcc/communityHall/controller/UserAPIController.java b/src/main/java/com/gcc/communityHall/controller/UserAPIController.java index 63e7b010..6ea23a6c 100644 --- a/src/main/java/com/gcc/communityHall/controller/UserAPIController.java +++ b/src/main/java/com/gcc/communityHall/controller/UserAPIController.java @@ -224,8 +224,8 @@ public class UserAPIController { // System.out.println(purpose); // System.out.print("\n MobileNo---:"+mobileNo); Random rand = new Random(); - int otp = rand.nextInt(90000) + 10000; - // int otp = 11111; + // int otp = rand.nextInt(90000) + 10000; + int otp = 11111; System.out.print("\n otp---:" + otp); DateTimeFormatter dtf = DateTimeFormatter.ofPattern("dd-MMM-yyyy%20HH:mm"); LocalDateTime now = LocalDateTime.now(); @@ -238,29 +238,31 @@ public class UserAPIController { System.out.println(urlString); System.out.println("\n urlString---: " + urlString); String bodyMessage = "" + otp; - try { - RestTemplate restTemplate = new RestTemplate(); - String Response = restTemplate.getForObject(urlString, String.class); - bodyMessage = Response; - SmsSender sms = new SmsSender(); - sms.setPhone(MobileNo); - sms.setCdate(new Date()); - sms.setBodyMsg(bodyMessage); - sms.setPurpose(purpose); - smsSenderRepository.save(sms); - - String whatsappMsg = - "https://media.smsgupshup.com/GatewayAPI/rest?userid=2000233507&password=h2YjFNcJ&send_to=" - + MobileNo - + - "&v=1.1&format=json&msg_type=TEXT&method=SENDMESSAGE&msg=Welcome+to+GCC%21+%0A%0AYour+OTP+for+GCC+Community+Centre+is+" - + otp + "+."; - String sendMsg = whatsappMsgServiceImpl.sendMsg(whatsappMsg); - System.out.println("sendwhatsuprepsosne====" + sendMsg); - } catch (Exception e) { - // System.out.print("ERROR in Sending---: "+e); - bodyMessage = "Error"; - } + /* + * try { + * RestTemplate restTemplate = new RestTemplate(); + * String Response = restTemplate.getForObject(urlString, String.class); + * bodyMessage = Response; + * SmsSender sms = new SmsSender(); + * sms.setPhone(MobileNo); + * sms.setCdate(new Date()); + * sms.setBodyMsg(bodyMessage); + * sms.setPurpose(purpose); + * smsSenderRepository.save(sms); + * + * String whatsappMsg = + * "https://media.smsgupshup.com/GatewayAPI/rest?userid=2000233507&password=h2YjFNcJ&send_to=" + * + MobileNo + * + + * "&v=1.1&format=json&msg_type=TEXT&method=SENDMESSAGE&msg=Welcome+to+GCC%21+%0A%0AYour+OTP+for+GCC+Community+Centre+is+" + * + otp + "+."; + * String sendMsg = whatsappMsgServiceImpl.sendMsg(whatsappMsg); + * System.out.println("sendwhatsuprepsosne====" + sendMsg); + * } catch (Exception e) { + * // System.out.print("ERROR in Sending---: "+e); + * bodyMessage = "Error"; + * } + */ HttpSession session = request.getSession(); session.setAttribute("otp", otp); return bodyMessage; diff --git a/src/main/java/com/gcc/communityHall/entity/Login.java b/src/main/java/com/gcc/communityHall/entity/Login.java index c1099898..13a99ead 100644 --- a/src/main/java/com/gcc/communityHall/entity/Login.java +++ b/src/main/java/com/gcc/communityHall/entity/Login.java @@ -1,17 +1,29 @@ package com.gcc.communityHall.entity; - +import jakarta.persistence.CascadeType; +import jakarta.persistence.Column; import jakarta.persistence.Entity; +import jakarta.persistence.FetchType; import jakarta.persistence.GeneratedValue; import jakarta.persistence.GenerationType; import jakarta.persistence.Id; +import jakarta.persistence.OneToMany; + +import java.util.ArrayList; +import java.util.List; @Entity public class Login { + @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private int id; + private int hallId; + + @OneToMany(mappedBy = "login", cascade = CascadeType.ALL, fetch = FetchType.EAGER, orphanRemoval = true) + private List loginHallIds = new ArrayList<>(); + private String name; private long mobileNumber; private String password; @@ -19,6 +31,14 @@ public class Login { private String userType; private String zone; + @Column(name = "is_active", nullable = false, columnDefinition = "TINYINT(1) DEFAULT 1") + private boolean isActive = true; + + @Column(name = "is_delete", nullable = false, columnDefinition = "TINYINT(1) DEFAULT 0") + private boolean isDelete = false; + + // ---- Getters & Setters ---- + public int getId() { return id; } @@ -35,6 +55,27 @@ public class Login { this.hallId = hallId; } + public List getLoginHallIds() { + return loginHallIds; + } + + public void setLoginHallIds(List loginHallIds) { + this.loginHallIds = loginHallIds; + } + + /** + * Convenience method: returns only the active, non-deleted hall IDs. + */ + public List getHallIds() { + List ids = new ArrayList<>(); + for (LoginHallId lhid : loginHallIds) { + if (lhid.isActive() && !lhid.isDelete()) { + ids.add(lhid.getHallId()); + } + } + return ids; + } + public String getName() { return name; } @@ -75,12 +116,27 @@ public class Login { this.userType = userType; } - public String getZone() { - return zone; - } + public String getZone() { + return zone; + } + + public void setZone(String zone) { + this.zone = zone; + } + + public boolean isActive() { + return isActive; + } + + public void setActive(boolean isActive) { + this.isActive = isActive; + } - public void setZone(String zone) { - this.zone = zone; - } + public boolean isDelete() { + return isDelete; + } + public void setDelete(boolean isDelete) { + this.isDelete = isDelete; + } } diff --git a/src/main/java/com/gcc/communityHall/entity/LoginHallId.java b/src/main/java/com/gcc/communityHall/entity/LoginHallId.java new file mode 100644 index 00000000..b9e228c8 --- /dev/null +++ b/src/main/java/com/gcc/communityHall/entity/LoginHallId.java @@ -0,0 +1,103 @@ +package com.gcc.communityHall.entity; + +import jakarta.persistence.Column; +import jakarta.persistence.Entity; +import jakarta.persistence.FetchType; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.GenerationType; +import jakarta.persistence.Id; +import jakarta.persistence.JoinColumn; +import jakarta.persistence.ManyToOne; +import jakarta.persistence.Table; +import org.hibernate.annotations.CreationTimestamp; + +import java.time.LocalDateTime; + +@Entity +@Table(name = "login_hall_ids") +public class LoginHallId { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + @Column(name = "id") + private int id; + + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "login_id", nullable = false) + private Login login; + + @Column(name = "hall_id", nullable = false) + private int hallId; + + @Column(name = "is_active", nullable = false, columnDefinition = "TINYINT(1) DEFAULT 1") + private boolean isActive = true; + + @Column(name = "is_delete", nullable = false, columnDefinition = "TINYINT(1) DEFAULT 0") + private boolean isDelete = false; + + @CreationTimestamp + @Column(name = "cdate", updatable = false, columnDefinition = "DATETIME DEFAULT CURRENT_TIMESTAMP") + private LocalDateTime cdate; + + // ---- Constructors ---- + + public LoginHallId() { + } + + public LoginHallId(Login login, int hallId) { + this.login = login; + this.hallId = hallId; + this.isActive = true; + this.isDelete = false; + } + + // ---- Getters & Setters ---- + + public int getId() { + return id; + } + + public void setId(int id) { + this.id = id; + } + + public Login getLogin() { + return login; + } + + public void setLogin(Login login) { + this.login = login; + } + + public int getHallId() { + return hallId; + } + + public void setHallId(int hallId) { + this.hallId = hallId; + } + + public boolean isActive() { + return isActive; + } + + public void setActive(boolean isActive) { + this.isActive = isActive; + } + + public boolean isDelete() { + return isDelete; + } + + public void setDelete(boolean isDelete) { + this.isDelete = isDelete; + } + + public LocalDateTime getCdate() { + return cdate; + } + + public void setCdate(LocalDateTime cdate) { + this.cdate = cdate; + } +} diff --git a/src/main/java/com/gcc/communityHall/repository/BookingDetailsRepository.java b/src/main/java/com/gcc/communityHall/repository/BookingDetailsRepository.java index 4b074e2a..47439991 100644 --- a/src/main/java/com/gcc/communityHall/repository/BookingDetailsRepository.java +++ b/src/main/java/com/gcc/communityHall/repository/BookingDetailsRepository.java @@ -11,1615 +11,1711 @@ import org.springframework.data.jpa.repository.Query; import org.springframework.data.repository.query.Param; import org.springframework.stereotype.Repository; - import com.gcc.communityHall.entity.BookingDetails; import com.gcc.communityHall.entity.BookingDetails.BookingStatus; import com.gcc.communityHall.entity.HallDetails; @Repository public interface BookingDetailsRepository extends JpaRepository { - @Query(value = "SELECT * FROM booking_details where booking_status='GCC_BLOCKED'", nativeQuery = true) - List getGccBlockedList(); - - @Query(value = "SELECT * FROM booking_details where booking_status='APPROVED'", nativeQuery = true) - List getAllApprovedList(); - - @Query(value = "SELECT * FROM booking_details where booking_status='REJECTED'", nativeQuery = true) - List getAllRejectingList(); - - @Query(value = "SELECT * FROM booking_details where booking_status='WAITING_FOR_NOC_APPROVAL'", nativeQuery = true) - List getAllwaitingList(); - - @Query(value = "SELECT * FROM booking_details WHERE hall_details_hall_id IN (:hallIds) AND " + - "booking_status IN ('APPROVED','WAITING_FOR_NOC','WAITING_FOR_NOC_APPROVAL') AND " + - "((start_date BETWEEN :fromDate AND :toDate) or (end_date BETWEEN :fromDate AND :toDate))", nativeQuery = true) - List findByFromDateBetweenAndToDateBetweenAndHallIdIn(LocalDate fromDate, LocalDate toDate, List hallIds); - - - @Query("SELECT b FROM BookingDetails b JOIN FETCH b.settlement s WHERE s.settlementId = :settlementId") - BookingDetails findBySettlementIdWithBookingDetails(@Param("settlementId") int settlementId); - - //ak - @Query("SELECT b.bookingRefId FROM BookingDetails b WHERE b.bookingId = :bookingId") - String getRefIdByBookingId(@Param("bookingId") int bookingId); - - - -@Modifying - @Query("UPDATE BookingDetails b SET b.bookingRefId = :refId WHERE b.bookingId = :bookingId") - void updateRefId(@Param("refId") String refId, @Param("bookingId") int bookingId); - - //ak - @Query("SELECT b FROM BookingDetails b WHERE b.bookingRefId = :refId") -BookingDetails findByRefId(@Param("refId") String refId); - -//ak for migrate -@Query("SELECT b FROM BookingDetails b WHERE b.bookingRefId IS NULL OR b.bookingRefId = ''") -List findAllOldBookingsWithoutRefId(); - - - - - @Query("SELECT bd FROM BookingDetails bd JOIN bd.hallDetails hd WHERE hd.zone = :zone AND bd.bookingStatus IN ('WAITING_FOR_NOC')") - List getWaitinglist(@Param("zone") String zone); - - @Query("SELECT bd FROM BookingDetails bd JOIN bd.hallDetails hd WHERE hd.zone = :zone AND bd.bookingStatus IN ('APPROVED')") - List getApprovedlist(@Param("zone") String zone); - - @Query("SELECT bd FROM BookingDetails bd JOIN bd.hallDetails hd WHERE hd.zone = :zone AND bd.bookingStatus IN ('REJECTED')") - List getrejectedlist(@Param("zone") String zone); - - @Query("SELECT bd FROM BookingDetails bd JOIN bd.hallDetails hd WHERE hd.zone = :zone AND bd.bookingStatus IN ('PENDING', 'PAYMENT_FAILURE')") - List getPendingOrPaymentFailureBookings(@Param("zone") String zone); - - - @Query(value = "SELECT * FROM booking_details WHERE DATE(start_date) = CURRENT_DATE() AND hall_details_hall_id = :hallId and booking_status='APPROVED'", nativeQuery = true) - List findPresentsEventsByUserId(Integer hallId); - //List findpresentseventsByHallid(Integer hallId); - - // @Query(value = "SELECT * FROM booking_details WHERE DATE(start_date) < CURRENT_DATE() AND hall_details_hall_id = :hallId and booking_status='APPROVED'", nativeQuery = true) -// List findPastsEventsByUserId(Integer hallId); -// @Query(value = "SELECT * FROM booking_details WHERE DATE(start_date) < CURRENT_DATE() AND hall_details_hall_id = :hallId AND booking_status = 'APPROVED'", nativeQuery = true) -// List findPastEventsByHallId(Integer hallId); -/* @Query(value = "SELECT * FROM booking_details WHERE DATE(start_date) BETWEEN DATE_SUB(CURRENT_DATE(), INTERVAL 2 DAY) AND CURRENT_DATE() - INTERVAL 1 DAY AND hall_details_hall_id = :hallId AND booking_status = 'APPROVED'", nativeQuery = true) - List findPastEventsByHallId(@Param("hallId") Integer hallId);*/ - @Query(value = "SELECT * FROM booking_details WHERE DATE(start_date) < CURRENT_DATE() AND hall_details_hall_id = :hallId AND booking_status = 'APPROVED'", nativeQuery = true) - List findPastEventsByHallId(@Param("hallId") Integer hallId); - - - @Query(value = "SELECT * FROM booking_details " + - "WHERE DATE(start_date) BETWEEN DATE_ADD(CURRENT_DATE(), INTERVAL 1 DAY) AND DATE_ADD(CURRENT_DATE(), INTERVAL 2 DAY) " + - "AND hall_details_hall_id = :hallId " + - "AND booking_status = 'APPROVED'", nativeQuery = true) - List findFutureEventsByHallId(Integer hallId); -// @Query(value = "SELECT * FROM booking_details " + -// "WHERE DATE(start_date) > CURRENT_DATE() " + -// "AND hall_details_hall_id = :hallId " + -// "AND booking_status = 'APPROVED'", nativeQuery = true) -// List findFutureEventsByHallId(Integer hallId); - - - @Query(value = "select count(users_user_id), us.user_status from booking_details bd inner join users us on us.user_id = bd.users_user_id \r" - + "where users_user_id=:userId and booking_status in ('APPROVED','COMPLETED','WAITING_FOR_NOC','WAITING_FOR_NOC_APPROVAL') and DATE_SUB(CURDATE(), INTERVAL 1 YEAR) \r" - + "and us.user_status not in ('PENDING')", nativeQuery = true) - int checkUserBookinglimitation(int userId); - - @Query(value = "SELECT * FROM booking_details WHERE users_user_id = :userId AND booking_status NOT IN ('PENDING')", nativeQuery = true) - List getAllBookingsByUserId(Integer userId); - - @Query(value = "select * from booking_details WHERE booking_id =:bookID", nativeQuery = true) - BookingDetails getByBookingId(String bookID); - - // + " WHERE hall_details_hall_id =:hallId and booking_status= 'APPROVED' and start_date < curdate() ", nativeQuery = true) - @Query(value = "SELECT * FROM booking_details WHERE DATE(start_date) <= CURRENT_DATE() AND hall_details_hall_id = :hallId and booking_status='APPROVED' and refund_status IN ('WAITING','REJECTED','APPROVED')", nativeQuery = true) - public List getSettlementList(Integer hallId); - - @Query(value = "SELECT * FROM booking_details WHERE DATE(start_date) <= CURRENT_DATE() AND booking_status='APPROVED' AND refund_status IN ('WAITING','REJECTED','APPROVED')", nativeQuery = true) - public List getAllSettlementList(); - - - //yoga - @Query(value = "SELECT " + - "u.user_id AS userId, " + - "u.name AS UserName, " + - "u.mobile_no AS MobileNumber, " + - "CONCAT(u.doorno,',',u.street, ', ', u.area, ', ', u.location, ', ', u.pin_code) AS Address, " + - "COUNT(*) AS TotalBookings, " + - "SUM(CASE WHEN bd.booking_status = 'APPROVED' THEN 1 ELSE 0 END) AS Payment, " + - "SUM(CASE WHEN bd.booking_status = 'REJECTED' THEN 1 ELSE 0 END) AS Rejected, " + - "SUM(CASE WHEN bd.booking_status = 'CANCELED' THEN 1 ELSE 0 END) AS Canceled, " + - "SUM(CASE WHEN bd.booking_status = 'PAYMENT_FAILURE' THEN 1 ELSE 0 END) AS PaymentFailure " + - "FROM " + - "booking_details bd " + - "JOIN " + - "users u ON bd.users_user_id = u.user_id " + - "WHERE DATE(bd.booking_date) >= :fromDate " + - "AND DATE(bd.booking_date) <= :toDate " + - "AND bd.booking_status NOT IN ('PENDING')" + - "GROUP BY " + - "bd.users_user_id order by u.user_id asc", nativeQuery = true) - List getBookingUserDetailsReport(@Param("fromDate") String fromDate, @Param("toDate") String toDate); - - - @Query(value = "SELECT " + - "h.hall_name AS HallName, " + - "h.hall_Incharge_name AS InchargeName, " + - "h.hall_Incharge_no AS hallInchargeMobno, " + - "CONCAT(h.zone, '/', h.division) AS ZoneDivision, " + // Concatenate zone and division - "COUNT(*) AS HallTotalBookings, " + - "SUM(p.amount_received) AS AmountReceived, " + - "COALESCE(SUM(r.amount - r.balace_amount), 0) AS AmountRefund, " + - "COALESCE(SUM(CASE WHEN bd.booking_status IN ('COMPLETED', 'CANCELED') THEN r.balace_amount ELSE 0 END), 0) AS Difference " + - "FROM " + - "booking_details bd " + - "JOIN " + - "hall_details h ON bd.hall_details_hall_id = h.hall_id " + - "LEFT JOIN users u ON bd.users_user_id = u.user_id " + - "JOIN " + - "payments p ON bd.booking_id = p.booking_details_booking_id " + - "LEFT JOIN refund_response r ON bd.booking_id = r.booking_id " + - "WHERE DATE(bd.booking_date) >= :fromDate " + - "AND DATE(bd.booking_date) <= :toDate " + - "AND bd.booking_status NOT IN ('PENDING')" + - "GROUP BY " + - "bd.hall_details_hall_id", nativeQuery = true) - List getBookingHallDetailsReport(@Param("fromDate") String fromDate, @Param("toDate") String toDate); - //ak - /* @Query(value = "SELECT * \r" - - + "FROM \r" - + " settlement s\r" - + " JOIN booking_details b ON s.booking_details_booking_id = b.booking_id\r" - - + "WHERE \r" - + " DATE(b.booking_date) BETWEEN :fromDate AND :toDate\r" - - + "ORDER BY \r" - + " b.booking_date", nativeQuery = true) -List getSettlementInitiatedReport(@Param("fromDate") String fromDate, @Param("toDate") String toDate);*/ -@Query(value = "SELECT distinct(p.booking_id), " + - // "b.booking_id, " + - "b.booking_date, " + - "s.cdate, " + - "u.name, " + - "u.mobile_no, " + - "hd.hall_name, " + - "b.end_date, " + - "b.start_date, " + - "b.amount_received, " + - "s.refunded_amount, " + - "p.txansaction_id " + - "FROM booking_details b " + - "INNER JOIN settlement s ON b.booking_id = s.booking_details_booking_id " + - "INNER JOIN users u ON u.user_id = b.users_user_id " + - "INNER JOIN hall_details hd ON hd.hall_id = b.hall_details_hall_id " + - "inner join refund_response p on p.booking_id=b.booking_id " + - "WHERE DATE(b.booking_date) BETWEEN :fromDate AND :toDate " + - "ORDER BY b.booking_date DESC", - nativeQuery = true) -List getSettlementInitiatedReport(@Param("fromDate") String fromDate, - @Param("toDate") String toDate); - - - - - - @Query(value = "SELECT \r" - + " COALESCE( SUM(\r" - + " CASE \r" - + " WHEN start_date = CURDATE() THEN 1\r" - + " ELSE 0\r" - + " END\r" - + " ),0) AS currente,\r" - + " COALESCE( SUM(\r" - + " CASE \r" - + " \r" - + " WHEN start_date < CURDATE() THEN 1\r" - + " ELSE 0\r" - + " END\r" - + " ), 0) AS past,\r" - + " COALESCE( SUM(\r" - + " CASE \r" - + " \r" - + " WHEN start_date > CURDATE() THEN 1\r" - + " ELSE 0\r" - + " END\r" - + " ),0) AS FUTURE\r" - + "FROM \r" - + " booking_details hall\r" - + " where hall_details_hall_id= :hall_id and booking_status='APPROVED'", nativeQuery = true) - List> pieChartCount(int hall_id); - - //@Query(value = "SELECT * FROM booking_details WHERE DATE(booking_date) >= :fromDate AND DATE(booking_date) <= :toDate AND (:bookingStatus IS NULL OR booking_status = :bookingStatus)", nativeQuery = true) - @Query(value = "SELECT bd.booking_id, bd.booking_date, hd.hall_name, us.name, us.mobile_no, " + - "CONCAT(us.doorno, ', ', us.street, ', ', us.area, ', ', us.location, ', ', us.pin_code) AS address, " + - "us.usertype, bd.reason, bd.start_date, bd.end_date, " + - "(bd.deposit_amount + bd.hall_amount + bd.gst) AS amount_paid, bd.booking_status " + - "FROM booking_details bd " + - "JOIN hall_details hd ON bd.hall_details_hall_id = hd.hall_id " + - "JOIN users us ON bd.users_user_id = us.user_id " + - "WHERE DATE(bd.booking_date) >= :fromDate " + - "AND DATE(bd.booking_date) <= :toDate " + - "AND (:bookingStatus IS NULL OR bd.booking_status = :bookingStatus) order by bd.booking_id asc ", - nativeQuery = true) - List getAllBookingDetailsWithStatus(@Param("fromDate") String fromDate, - @Param("toDate") String toDate, - @Param("bookingStatus") String bookingStatus); - - @Query(value = "SELECT bd.booking_id, bd.booking_date, hd.hall_name, us.name, us.mobile_no, " + - "CONCAT(us.doorno, ', ', us.street, ', ', us.area, ', ', us.location, ', ', us.pin_code) AS address, " + - "us.usertype, bd.reason, bd.start_date, bd.end_date, " + - "bd.deposit_amount, bd.hall_amount, bd.gst, bd.amount_received, bd.booking_status " + - "FROM booking_details bd " + - "JOIN hall_details hd ON bd.hall_details_hall_id = hd.hall_id " + - "JOIN users us ON bd.users_user_id = us.user_id " + - "WHERE DATE(bd.booking_date) >= :fromDate " + - "AND DATE(bd.booking_date) <= :toDate " + - "AND (:bookingId IS NULL OR bd.booking_id = :bookingId) order by bd.booking_id asc", - nativeQuery = true) - List getAllBookingDetailsWithBookingId(@Param("fromDate") String fromDate, - @Param("toDate") String toDate, - @Param("bookingId") Long bookingId); - - @Query(value = "SELECT bd.booking_id, bd.booking_date, hd.hall_name, us.name, us.mobile_no, " + - "CONCAT(us.doorno, ', ', us.street, ', ', us.area, ', ', us.location, ', ', us.pin_code) AS address, " + - "us.usertype, bd.reason, bd.start_date, bd.end_date, " + - "bd.deposit_amount, bd.hall_amount, bd.gst, bd.amount_received, bd.booking_status " + - "FROM booking_details bd " + - "JOIN hall_details hd ON bd.hall_details_hall_id = hd.hall_id " + - "JOIN users us ON bd.users_user_id = us.user_id " + - "WHERE DATE(bd.booking_date) >= :fromDate " + - "AND DATE(bd.booking_date) <= :toDate " + - "AND (:bookingId IS NULL OR bd.booking_id = :bookingId)" + - "AND (:bookingStatus IS NULL OR bd.booking_status = :bookingStatus) order by bd.booking_id asc", - nativeQuery = true) - List getAllBookingDetailsWithBookingIdwithbookingStatus(@Param("fromDate") String fromDate, - @Param("toDate") String toDate, - @Param("bookingId") Long bookingId, @Param("bookingStatus") String bookingStatus); - - //@Query(value = "SELECT * FROM booking_details WHERE DATE(booking_date) >= :fromDate AND DATE(booking_date) <= :toDate", nativeQuery = true) - @Query(value = "SELECT bd.booking_id, bd.booking_date, hd.hall_name, us.name, us.mobile_no, " + - "CONCAT(us.doorno, ', ', us.street, ', ', us.area, ', ', us.location, ', ', us.pin_code) AS address, " + - "us.usertype, bd.reason, bd.start_date, bd.end_date, " + - "(bd.deposit_amount + bd.hall_amount + bd.gst) AS amount_paid, bd.booking_status " + - "FROM booking_details bd " + - "JOIN hall_details hd ON bd.hall_details_hall_id = hd.hall_id " + - "JOIN users us ON bd.users_user_id = us.user_id " + - "WHERE DATE(bd.booking_date) >= :fromDate " + - "AND DATE(bd.booking_date) <= :toDate order by bd.booking_id asc", - nativeQuery = true) - List getAllBookingDetails(@Param("fromDate") String fromDate, @Param("toDate") String toDate); - -// @Query(value = "SELECT bd.booking_id, bd.booking_date, hd.hall_name, us.name, us.usertype, p.transaction_id, p.payment_type, p.amount_received, bd.reason, bd.start_date, bd.end_date, p.payment_status " + -// "FROM payments p " + -// "JOIN booking_details bd ON p.booking_details_booking_id =bd.booking_id " + -// "JOIN hall_details hd ON bd.hall_details_hall_id = hd.hall_id " + -// "left JOIN users us ON bd.users_user_id = us.user_id " + -// "WHERE DATE(p.cdate) >= :fromDate " + -// "AND DATE(p.cdate) <= :toDate " + -// "AND (:paymentStatus IS NULL OR p.payment_status = :paymentStatus)", -// nativeQuery = true) -// List getAllPaymentsDetails(@Param("fromDate") String fromDate, -// @Param("toDate") String toDate, -// @Param("paymentStatus") String paymentStatus); - - @Query(value = "SELECT SUM(CASE WHEN bd.booking_status = 'APPROVED' THEN 1 ELSE 0 END) AS approved_booking_count,\r" - + "SUM(CASE WHEN bd.booking_status = 'REJECTED' THEN 1 ELSE 0 END) AS rejected_booking_count,\r" - + "SUM(CASE WHEN bd.refund_status = 'WAITING' THEN 1 ELSE 0 END) AS waiting_settlement_count,\r" - + "SUM(CASE WHEN bd.refund_status = 'APPROVED' THEN 1 ELSE 0 END) AS approved_settlement_count,\r" - + "SUM(CASE WHEN bd.refund_status = 'REJECTED' THEN 1 ELSE 0 END) AS reject_settlement_count\r" - + "FROM booking_details bd " - + "JOIN hall_details hd ON bd.hall_details_hall_id = hd.hall_id " - + "WHERE hd.zone = :zone", nativeQuery = true) - List> toatlBookingCount(String zone); - - @Query(value = " SELECT SUM(CASE WHEN booking_status = 'APPROVED' THEN 1 ELSE 0 END) AS approved_count,\r" - + " SUM(CASE WHEN bd.booking_status = 'REJECTED' THEN 1 ELSE 0 END) AS rejected_count,\r" - + " SUM(CASE WHEN bd.booking_status = 'PENDING' THEN 1 ELSE 0 END) AS pending_count,\r" - + " SUM(CASE WHEN bd.booking_status = 'CANCELED' THEN 1 ELSE 0 END) AS CANCELED,\r" - + " SUM(CASE WHEN bd.booking_status = 'PAYMENT_FAILURE' THEN 1 ELSE 0 END) AS PAYMENT_FAILURE,\r" - + " SUM(CASE WHEN bd.booking_status = 'GCC_BLOCKED' THEN 1 ELSE 0 END) AS GCC_BLOCKED\r" - + "FROM booking_details bd " - + "JOIN hall_details hd ON bd.hall_details_hall_id = hd.hall_id " - + "WHERE hd.zone = :zone", nativeQuery = true) - List> getCount(String zone); - - - @Query(value = "SELECT CONCAT(YEAR(bd.start_date), '-', LPAD(MONTH(bd.start_date), 2, '0')) AS months, SUM(CASE WHEN booking_status = 'APPROVED' THEN 1 ELSE 0 END) AS approved_count,\r" - + " SUM(CASE WHEN bd.booking_status = 'REJECTED' THEN 1 ELSE 0 END) AS rejected_count,\r" - + " SUM(CASE WHEN bd.booking_status = 'PENDING' THEN 1 ELSE 0 END) AS pending_count\r" - + "FROM booking_details bd JOIN hall_details hd ON bd.hall_details_hall_id = hd.hall_id \r" - + "WHERE bd.start_date >= DATE_SUB(CURDATE(), INTERVAL 6 MONTH)\r" - + " AND bd.start_date <= DATE_ADD(CURDATE(), INTERVAL 6 MONTH) AND hd.zone = :zone \r" - + " group by months order by months ASC", nativeQuery = true) - List> getmounthcount(String zone); - - - @Query(value = "SELECT CONCAT(YEAR(bd.start_date), '-', LPAD(MONTH(bd.start_date), 2, '0')) AS months, SUM(CASE WHEN booking_status = 'APPROVED' THEN 1 ELSE 0 END) AS approved_count,\r" - + " SUM(CASE WHEN bd.booking_status = 'REJECTED' THEN 1 ELSE 0 END) AS rejected_count,\r" - + " SUM(CASE WHEN bd.booking_status = 'PENDING' THEN 1 ELSE 0 END) AS pending_count\r" - + "FROM booking_details bd JOIN hall_details hd ON bd.hall_details_hall_id = hd.hall_id \r" - + "WHERE bd.start_date >= DATE_SUB(CURDATE(), INTERVAL 6 MONTH)\r" - + " AND bd.start_date <= DATE_ADD(CURDATE(), INTERVAL 6 MONTH) \r" - + "AND (:zone = 'all zones' OR hd.zone = :zone)\r " - + " group by months order by months ASC", nativeQuery = true) - List> getAllAdminmonthcount(@Param("zone") String zone); - - - @Query(value = " SELECT SUM(CASE WHEN booking_status = 'APPROVED' THEN 1 ELSE 0 END) AS approved_count,\r" - + " SUM(CASE WHEN bd.booking_status = 'REJECTED' THEN 1 ELSE 0 END) AS rejected_count,\r" - + " SUM(CASE WHEN bd.booking_status = 'PENDING' THEN 1 ELSE 0 END) AS pending_count,\r" - + " SUM(CASE WHEN bd.booking_status = 'CANCELED' THEN 1 ELSE 0 END) AS CANCELED,\r" - + " SUM(CASE WHEN bd.booking_status = 'PAYMENT_FAILURE' THEN 1 ELSE 0 END) AS PAYMENT_FAILURE,\r" - + " SUM(CASE WHEN bd.booking_status = 'GCC_BLOCKED' THEN 1 ELSE 0 END) AS GCC_BLOCKED\r" - + "FROM booking_details bd " - + "JOIN hall_details hd ON bd.hall_details_hall_id = hd.hall_id " - + "WHERE (:zone = 'all zones' OR hd.zone = :zone)", nativeQuery = true) - List> getAdmincount(@Param("zone") String zone); - - @Query(value = "SELECT CONCAT(YEAR(bd.start_date), '-', LPAD(MONTH(bd.start_date), 2, '0')) AS months, SUM(CASE WHEN booking_status = 'APPROVED' THEN 1 ELSE 0 END) AS approved_count,\r" - + " SUM(CASE WHEN bd.booking_status = 'REJECTED' THEN 1 ELSE 0 END) AS rejected_count,\r" - + " SUM(CASE WHEN bd.booking_status = 'COMPLETED' THEN 1 ELSE 0 END) AS completed_count\r" - + "FROM booking_details bd JOIN hall_details hd ON bd.hall_details_hall_id = hd.hall_id \r" - + "WHERE bd.start_date >= DATE_SUB(CURDATE(), INTERVAL 6 MONTH)\r" - + " AND bd.start_date <= DATE_ADD(CURDATE(), INTERVAL 6 MONTH) AND hd.hall_id=:hall_id \r" - + " group by months order by months ASC", nativeQuery = true) - List> getCartakermounthcount(int hall_id); - - - @Query(value = " SELECT SUM(CASE WHEN booking_status = 'APPROVED' THEN 1 ELSE 0 END) AS approved_count,\r" - + " SUM(CASE WHEN bd.booking_status = 'REJECTED' THEN 1 ELSE 0 END) AS rejected_count,\r" - + " SUM(CASE WHEN bd.booking_status = 'COMPLETED' THEN 1 ELSE 0 END) AS completed_count,\r" - + " SUM(CASE WHEN bd.booking_status = 'CANCELED' THEN 1 ELSE 0 END) AS CANCELED,\r" - + " SUM(CASE WHEN bd.booking_status = 'PAYMENT_FAILURE' THEN 1 ELSE 0 END) AS PAYMENT_FAILURE,\r" - + " SUM(CASE WHEN bd.booking_status = 'GCC_BLOCKED' THEN 1 ELSE 0 END) AS GCC_BLOCKED\r" - + "FROM booking_details bd " - + "JOIN hall_details hd ON bd.hall_details_hall_id = hd.hall_id where hd.hall_id=:hall_id", nativeQuery = true) - List> getcartakecount(int hall_id); - - @Query(value = "SELECT \r" - + " bd.*, \r" - + " CASE \r" - + " WHEN bd.start_date < CURDATE() THEN 'Past'\r" - + " WHEN bd.start_date = CURDATE() THEN 'Current'\r" - + " WHEN bd.booking_status = 'WAITING_FOR_NOC' THEN 'waitingfornoc'\r" - + " WHEN bd.booking_status = 'WAITING_FOR_NOC_APPROVAL' THEN 'waitingfornocapproval'\r" - + " WHEN bd.schedule_count = 0 AND bd.start_date > CURDATE() THEN 'Reschedule'\r" - + " WHEN bd.reason IN ('State Govt Event','Central Govt Event','Commericial & Others') AND bd.booking_status='APPROVED' THEN 'noaction'" - + " ELSE 'Future' \r" - + " END AS event_category,\r" - + " users.*, \r" - + " hd.*, \r" - + " cd.*, \r" - + " pd.* \r" - + "FROM booking_details bd \r" - + "INNER JOIN users users ON bd.users_user_id = users.user_id \r" - + "INNER JOIN hall_details hd ON hd.hall_id = bd.hall_details_hall_id \r" - + "LEFT JOIN counter_details cd ON cd.counter_id = bd.counterdetails_counter_id\r" - + "LEFT JOIN payments pd ON bd.booking_id = pd.booking_details_booking_id \r" - + "WHERE bd.users_user_id = :userId and booking_status IN ('GCC_BLOCKED', 'APPROVED','CANCELED','REJECTED','COMPLETED','WAITING_FOR_NOC','WAITING_FOR_NOC_APPROVAL') \r" - + "ORDER BY bd.booking_id DESC\r", nativeQuery = true) - List> getAllBookingEventsByUserId(Integer userId); - - //counter - @Query(value = "SELECT bd.*, " + - "hd.zone AS hall_zone, " + - "hd.division AS hall_division, " + - "users.mobile_no AS mobile_no, " + - "CASE " + - "WHEN bd.start_date < CURDATE() THEN 'Past' " + - "WHEN bd.start_date = CURDATE() THEN 'Current' " + - "ELSE 'Future' " + - "END AS event_category " + - "FROM booking_details bd " + - "INNER JOIN users users on bd.users_user_id = users.user_id " + - "INNER JOIN hall_details hd ON bd.hall_details_hall_id = hd.hall_id " + - "WHERE bd.booking_type = 'OFFLINE'", - nativeQuery = true) - List> findAllByBookingType(); - - - @Query(value = "select bdud.* from booking_details bdud inner Join counter_refund_list crl on bdud.counterdetails_counter_id = crl.counterdetails_counter_id where crl.counterdetails_counter_id = :counterId", nativeQuery = true) - List getCounterDetailsbycounterId(int counterId); - - @Query(value = "select *from booking_details where counterdetails_counter_id = :counterId", nativeQuery = true) - List findByCounterId(int counterId); - - @Query("SELECT b FROM BookingDetails b LEFT JOIN FETCH b.bookingHistories WHERE b.bookingId = :bookingId") - Optional findByIdWithHistories(@Param("bookingId") int bookingId); - - @Query("SELECT b FROM BookingDetails b JOIN FETCH b.settlement s WHERE b.refundStatus = 'APPROVED'") - List findAllWithApprovedRefundStatus(); - - @Query("SELECT b FROM BookingDetails b JOIN FETCH b.settlement s WHERE b.refundStatus = 'INITIATED'") - List findByBookingDetailsRefundStatus(); - - @Query("SELECT b FROM BookingDetails b JOIN FETCH b.settlement s WHERE b.refundStatus = 'COMPLETED' AND b.bookingStatus='COMPLETED'") - List findAllwithCompletedRefundStatus(); - - @Query("SELECT b FROM BookingDetails b JOIN FETCH b.settlement s WHERE b.refundStatus = 'WAITING' and b.hallDetails.zone=:zone") - List findSettlementPendingByZone(String zone); - //ak - @Query("SELECT b FROM BookingDetails b JOIN FETCH b.settlement s WHERE b.refundStatus = 'FAILURE' and b.hallDetails.zone=:zone") - List findSettlementInitiatedPendingByZone(String zone); - @Query("SELECT b FROM BookingDetails b JOIN FETCH b.settlement s WHERE b.refundStatus = 'FAILURE'") - List findSettlementInitiatedPending(); - - @Query("SELECT b FROM BookingDetails b JOIN FETCH b.settlement s WHERE b.refundStatus = 'APPROVED' and b.hallDetails.zone=:zone") - List findSettlementApprovedByZone(String zone); - - @Query("SELECT b FROM BookingDetails b JOIN FETCH b.settlement s WHERE b.refundStatus = 'REJECTED' and b.hallDetails.zone=:zone") - List findSettlementRejectedByZone(String zone); - - @Query("SELECT b FROM BookingDetails b JOIN FETCH b.settlement s WHERE b.refundStatus = 'REJECTED'") - List findAllSettlementRejected(); - - - @Query("SELECT b FROM BookingDetails b WHERE b.refundStatus = 'WAITING' AND b.bookingStatus = 'CANCELED' AND b.hallDetails.zone = :zone") - List findCancelledListByZone(@Param("zone") String zone); - - @Query("SELECT b FROM BookingDetails b WHERE b.refundStatus = 'APPROVED' AND b.bookingStatus = 'CANCELED' AND b.hallDetails.zone = :zone") - List findapprovedCancelledListByZone(String zone); - - @Query("SELECT b FROM BookingDetails b WHERE b.refundStatus = 'WAITING' AND b.bookingStatus IN ('GCC_BLOCKED', 'REJECTED') AND b.hallDetails.zone = :zone") - List findRejectedListByZone(@Param("zone") String zone); - - @Query("SELECT b FROM BookingDetails b WHERE b.refundStatus = 'APPROVED' AND b.bookingStatus IN ('GCC_BLOCKED', 'REJECTED') AND b.hallDetails.zone = :zone") - List findapprovedRejectedListByZone(@Param("zone") String zone); - - @Query("SELECT b FROM BookingDetails b WHERE b.refundStatus = 'APPROVED' AND b.bookingStatus = 'CANCELED'") - List findCancelledList(); - - - @Query(value = "SELECT * FROM booking_details WHERE refund_status = 'APPROVED' AND booking_status IN ('GCC_BLOCKED', 'REJECTED')", nativeQuery = true) - List findRejectedList(); - - @Query(value = "SELECT * FROM booking_details WHERE refund_status = 'INITIATED' AND booking_status = 'CANCELED'", nativeQuery = true) - List findInitiatedCancelledList(); - - @Query(value = "SELECT * FROM booking_details WHERE refund_status = 'INITIATED' AND booking_status IN ('GCC_BLOCKED', 'REJECTED')", nativeQuery = true) - List findInitiatedRejectedList(); - - @Query(value = "SELECT * FROM booking_details WHERE refund_status IN ('COMPLETED','CLOSED') AND booking_status = 'COMPLETED'", nativeQuery = true) - List findSettlementCompletedList(); - - @Query(value = "SELECT * FROM booking_details WHERE refund_status = 'COMPLETED' AND booking_status = 'CANCELED'", nativeQuery = true) - List findCancelledCompletedList(); - - @Query(value = "SELECT * FROM booking_details WHERE refund_status = 'COMPLETED' AND booking_status IN ('GCC_BLOCKED', 'REJECTED')", nativeQuery = true) - List findRejectedSettlementCompletedList(); - - //officer reports - @Query(value = "SELECT bd.*, hd.hall_name, us.name, us.usertype " + - "FROM booking_details bd " + - "JOIN hall_details hd ON bd.hall_details_hall_id = hd.hall_id " + - "JOIN users us ON bd.users_user_id = us.user_id " + - "WHERE DATE(bd.booking_date) >= :fromDate " + - "AND DATE(bd.booking_date) <= :toDate " + - "AND hd.zone = :zone ", nativeQuery = true) - List getAllBookingDetailsByZone(@Param("fromDate") String fromDate, @Param("toDate") String toDate, @Param("zone") String zone); - - @Query(value = "SELECT bd.*, hd.hall_name, us.name, us.usertype " + - "FROM booking_details bd " + - "JOIN hall_details hd ON bd.hall_details_hall_id = hd.hall_id " + - "JOIN users us ON bd.users_user_id = us.user_id " + - "WHERE DATE(bd.booking_date) >= :fromDate " + - "AND DATE(bd.booking_date) <= :toDate " + - "AND hd.zone = :zone " + - "AND (:bookingStatus IS NULL OR bd.booking_status = :bookingStatus)", nativeQuery = true) - List getAllBookingDetailsByZoneWithStatus(@Param("fromDate") String fromDate, @Param("toDate") String toDate, @Param("zone") String zone, @Param("bookingStatus") String bookingStatus); - - @Query(value = "SELECT " + - "h.hall_name AS HallName, " + - "h.zone AS Zone, " + - "h.division AS Division, " + - "CONCAT(h.door_no,',',h.street, ', ', h.area, ', ', h.city, ', ', h.pin_code) AS Address, " + - "COUNT(*) AS HallTotalBookings, " + - "SUM(p.amount_received) AS AmountReceived, " + - "COALESCE(SUM(r.amount_refunded), 0) AS AmountRefund, " + //Use COALESCE to handle NULL values - "(SUM(p.amount_received) - COALESCE(SUM(r.amount_refunded), 0)) AS Difference " + // Calculate the difference - "FROM " + - "booking_details bd " + - "JOIN " + - "hall_details h ON bd.hall_details_hall_id = h.hall_id " + - "JOIN " + - "payments p ON bd.booking_id = p.booking_details_booking_id " + - "LEFT JOIN " + - "refund_transaction r ON p.transaction_id = r.transaction_id " + - "WHERE DATE(bd.booking_date) >= :fromDate " + - "AND DATE(bd.booking_date) <= :toDate " + - "AND h.zone = :zone " + - "GROUP BY " + - "bd.hall_details_hall_id", nativeQuery = true) - List getBookingHallDetailsReportByZone(@Param("fromDate") String fromDate, @Param("toDate") String toDate, @Param("zone") String zone); - - @Query(value = "SELECT bd.*, hd.hall_name, us.name, us.usertype " + - "FROM booking_details bd " + - "JOIN hall_details hd ON bd.hall_details_hall_id = hd.hall_id " + - "LEFT JOIN users us ON bd.users_user_id = us.user_id " + - "LEFT JOIN settlement st ON bd.booking_id=st.booking_details_booking_id " + - "WHERE DATE(bd.booking_date) >= :fromDate " + - "AND DATE(bd.booking_date) <= :toDate " + - "AND bd.booking_status NOT IN ('PENDING')" + - "AND hd.zone = :zone ", nativeQuery = true) - List getAllBookingsettlementDetailsByZone(@Param("fromDate") String fromDate, @Param("toDate") String toDate, @Param("zone") String zone); - - @Query(value = "SELECT bd.*, hd.hall_name, us.name, us.usertype " + - "FROM booking_details bd " + - "JOIN hall_details hd ON bd.hall_details_hall_id = hd.hall_id " + - "LEFT JOIN users us ON bd.users_user_id = us.user_id " + - "LEFT JOIN settlement st ON bd.booking_id=st.booking_details_booking_id " + - "WHERE DATE(bd.booking_date) >= :fromDate " + - "AND DATE(bd.booking_date) <= :toDate " + - "AND bd.booking_status NOT IN ('PENDING')" + - "AND hd.zone = :zone " + - "AND (:refundStatus IS NULL OR bd.refund_status = :refundStatus) ", nativeQuery = true) - List getAllBookingsettlementDetailsByZoneWithStatus(@Param("fromDate") String fromDate, @Param("toDate") String toDate, @Param("zone") String zone, @Param("refundStatus") String refundStatus); - - - @Query(value = "SELECT " + - "h.hall_name AS HallName, " + - "h.hall_Incharge_name AS InchargeName, " + - "h.hall_Incharge_no AS hallInchargeMobno, " + - "CONCAT(h.zone, '/', h.division) AS ZoneDivision, " + // Concatenate zone and division - "COUNT(*) AS HallTotalBookings, " + - "SUM(p.amount_received) AS AmountReceived, " + - "COALESCE(SUM(r.amount - r.balace_amount), 0) AS AmountRefund, " + - "COALESCE(SUM(CASE WHEN bd.booking_status IN ('COMPLETED', 'CANCELED') THEN r.balace_amount ELSE 0 END), 0) AS Difference " + - "FROM " + - "booking_details bd " + - "JOIN " + - "hall_details h ON bd.hall_details_hall_id = h.hall_id " + - "LEFT JOIN users u ON bd.users_user_id = u.user_id " + - "JOIN " + - "payments p ON bd.booking_id = p.booking_details_booking_id " + - "LEFT JOIN refund_response r ON bd.booking_id = r.booking_id " + - "WHERE DATE(bd.booking_date) >= :fromDate " + - "AND DATE(bd.booking_date) <= :toDate " + - "AND bd.booking_status NOT IN ('PENDING')" + - "AND h.zone = :zone " + - "AND bd.hall_details_hall_id = :hall_id " + - "GROUP BY " + - "bd.hall_details_hall_id", nativeQuery = true) - List getBookingHallDetailsReportByZone1(@Param("fromDate") String fromDate, @Param("toDate") String toDate, @Param("zone") String zone, @Param("hall_id") Integer hallId); - - List findByHallDetailsAndBookingStatus(HallDetails hallDetails, BookingStatus gccBlocked); - - @Query(value = "SELECT COUNT(*) FROM booking_details WHERE hall_details_hall_id = :hallId AND start_date BETWEEN :startDate AND :endDate AND booking_status='GCC_BLOCKED'", nativeQuery = true) - int countByHallIdAndBookingDateBetween( - @Param("hallId") int hallId, - @Param("startDate") LocalDate startDate, - @Param("endDate") LocalDate endDate); - - @Query(value = "SELECT * FROM booking_details WHERE booking_id=:bookingId", nativeQuery = true) - List findBookingDetailsByBookingId(@Param("bookingId") Long bookingId); - - @Query(value = "SELECT booking_id FROM booking_details WHERE hall_details_hall_id = :hallId AND start_date BETWEEN :startDate AND :endDate AND booking_status='GCC_BLOCKED'", nativeQuery = true) - List findBookingIdsByHallIdAndBookingDateBetween(@Param("hallId") int hallId, @Param("startDate") LocalDate startDate, @Param("endDate") LocalDate endDate); - - @Query(value = "SELECT bd.*, hd.hall_name, us.name, us.usertype " + - "FROM booking_details bd " + - "JOIN hall_details hd ON bd.hall_details_hall_id = hd.hall_id " + - "LEFT JOIN users us ON bd.users_user_id = us.user_id " + - "LEFT JOIN settlement st ON bd.booking_id=st.booking_details_booking_id " + - "WHERE DATE(bd.booking_date) >= :fromDate " + - "AND DATE(bd.booking_date) <= :toDate " + - "AND bd.booking_status NOT IN ('PENDING')" + - "AND (:refundStatus IS NULL OR bd.refund_status = :refundStatus) ", nativeQuery = true) - List getAllBookingsettlementDetailsWithStatus(@Param("fromDate") String fromDate, @Param("toDate") String toDate, @Param("refundStatus") String refundStatus); - - @Query(value = "SELECT bd.*, hd.hall_name, us.name, us.usertype " + - "FROM booking_details bd " + - "JOIN hall_details hd ON bd.hall_details_hall_id = hd.hall_id " + - "LEFT JOIN users us ON bd.users_user_id = us.user_id " + - "LEFT JOIN settlement st ON bd.booking_id=st.booking_details_booking_id " + - "WHERE DATE(bd.booking_date) >= :fromDate " + - "AND bd.booking_status NOT IN ('PENDING')" + - "AND DATE(bd.booking_date) <= :toDate ", nativeQuery = true) - List getAllBookingsettlementDetails(@Param("fromDate") String fromDate, @Param("toDate") String toDate); - - - //admin dashboard - @Query(nativeQuery = true, value = - - "SELECT 'main' AS category, NULL AS `key` , " + - - "COUNT(DISTINCT CASE WHEN b.booking_status NOT IN ('GCC_BLOCKED', 'GCC_UNBLOCKED') THEN b.booking_id END) AS totalCount," + - - "COALESCE(SUM(CASE WHEN b.booking_status NOT IN ('PENDING') THEN b.amount_received ELSE 0 END), 0) AS main_total_amount, " + - - "COALESCE(SUM(r.amount - r.balace_amount), 0) AS main_refunded_amount," + - - "COALESCE(SUM(CASE WHEN b.booking_status NOT IN ('PENDING', 'REFUNDED', 'GCC_BLOCKED','REJECTED') THEN b.hall_amount ELSE 0 END), 0) AS main_net_amount, " + + @Query(value = "SELECT * FROM booking_details where booking_status='GCC_BLOCKED'", nativeQuery = true) + List getGccBlockedList(); + + @Query(value = "SELECT * FROM booking_details where booking_status='APPROVED'", nativeQuery = true) + List getAllApprovedList(); + + @Query(value = "SELECT * FROM booking_details where booking_status='REJECTED'", nativeQuery = true) + List getAllRejectingList(); + + @Query(value = "SELECT * FROM booking_details where booking_status='WAITING_FOR_NOC_APPROVAL'", nativeQuery = true) + List getAllwaitingList(); + + @Query(value = "SELECT * FROM booking_details WHERE hall_details_hall_id IN (:hallIds) AND " + + "booking_status IN ('APPROVED','WAITING_FOR_NOC','WAITING_FOR_NOC_APPROVAL') AND " + + "((start_date BETWEEN :fromDate AND :toDate) or (end_date BETWEEN :fromDate AND :toDate))", nativeQuery = true) + List findByFromDateBetweenAndToDateBetweenAndHallIdIn(LocalDate fromDate, LocalDate toDate, + List hallIds); + + @Query("SELECT b FROM BookingDetails b JOIN FETCH b.settlement s WHERE s.settlementId = :settlementId") + BookingDetails findBySettlementIdWithBookingDetails(@Param("settlementId") int settlementId); + + // ak + @Query("SELECT b.bookingRefId FROM BookingDetails b WHERE b.bookingId = :bookingId") + String getRefIdByBookingId(@Param("bookingId") int bookingId); + + @Modifying + @Query("UPDATE BookingDetails b SET b.bookingRefId = :refId WHERE b.bookingId = :bookingId") + void updateRefId(@Param("refId") String refId, @Param("bookingId") int bookingId); + + // ak + @Query("SELECT b FROM BookingDetails b WHERE b.bookingRefId = :refId") + BookingDetails findByRefId(@Param("refId") String refId); + + // ak for migrate + @Query("SELECT b FROM BookingDetails b WHERE b.bookingRefId IS NULL OR b.bookingRefId = ''") + List findAllOldBookingsWithoutRefId(); + + @Query("SELECT bd FROM BookingDetails bd JOIN bd.hallDetails hd WHERE hd.zone = :zone AND bd.bookingStatus IN ('WAITING_FOR_NOC') and hd.hallId in (:hallIds)") + List getWaitinglist(@Param("zone") String zone, @Param("hallIds") List hallIds); + + @Query("SELECT bd FROM BookingDetails bd JOIN bd.hallDetails hd WHERE hd.zone = :zone AND bd.bookingStatus IN ('APPROVED') and hd.hallId in (:hallIds)") + List getApprovedlist(@Param("zone") String zone, @Param("hallIds") List hallIds); + + @Query("SELECT bd FROM BookingDetails bd JOIN bd.hallDetails hd WHERE hd.zone = :zone AND bd.bookingStatus IN ('REJECTED') and hd.hallId in (:hallIds)") + List getrejectedlist(@Param("zone") String zone, @Param("hallIds") List hallIds); + + @Query("SELECT bd FROM BookingDetails bd JOIN bd.hallDetails hd WHERE hd.zone = :zone AND bd.bookingStatus IN ('PENDING', 'PAYMENT_FAILURE') and hd.hallId in (:hallIds)") + List getPendingOrPaymentFailureBookings(@Param("zone") String zone, + @Param("hallIds") List hallIds); + + @Query(value = "SELECT * FROM booking_details WHERE DATE(start_date) = CURRENT_DATE() AND hall_details_hall_id = :hallId and booking_status='APPROVED'", nativeQuery = true) + List findPresentsEventsByUserId(Integer hallId); + // List findpresentseventsByHallid(Integer hallId); + + // @Query(value = "SELECT * FROM booking_details WHERE DATE(start_date) < + // CURRENT_DATE() AND hall_details_hall_id = :hallId and + // booking_status='APPROVED'", nativeQuery = true) + // List findPastsEventsByUserId(Integer hallId); + // @Query(value = "SELECT * FROM booking_details WHERE DATE(start_date) < + // CURRENT_DATE() AND hall_details_hall_id = :hallId AND booking_status = + // 'APPROVED'", nativeQuery = true) + // List findPastEventsByHallId(Integer hallId); + /* + * @Query(value = + * "SELECT * FROM booking_details WHERE DATE(start_date) BETWEEN DATE_SUB(CURRENT_DATE(), INTERVAL 2 DAY) AND CURRENT_DATE() - INTERVAL 1 DAY AND hall_details_hall_id = :hallId AND booking_status = 'APPROVED'" + * , nativeQuery = true) + * List findPastEventsByHallId(@Param("hallId") Integer hallId); + */ + @Query(value = "SELECT * FROM booking_details WHERE DATE(start_date) < CURRENT_DATE() AND hall_details_hall_id = :hallId AND booking_status = 'APPROVED'", nativeQuery = true) + List findPastEventsByHallId(@Param("hallId") Integer hallId); + + @Query(value = "SELECT * FROM booking_details " + + "WHERE DATE(start_date) BETWEEN DATE_ADD(CURRENT_DATE(), INTERVAL 1 DAY) AND DATE_ADD(CURRENT_DATE(), INTERVAL 2 DAY) " + + + "AND hall_details_hall_id = :hallId " + + "AND booking_status = 'APPROVED'", nativeQuery = true) + List findFutureEventsByHallId(Integer hallId); + // @Query(value = "SELECT * FROM booking_details " + + // "WHERE DATE(start_date) > CURRENT_DATE() " + + // "AND hall_details_hall_id = :hallId " + + // "AND booking_status = 'APPROVED'", nativeQuery = true) + // List findFutureEventsByHallId(Integer hallId); + + @Query(value = "select count(users_user_id), us.user_status from booking_details bd inner join users us on us.user_id = bd.users_user_id \r" + + "where users_user_id=:userId and booking_status in ('APPROVED','COMPLETED','WAITING_FOR_NOC','WAITING_FOR_NOC_APPROVAL') and DATE_SUB(CURDATE(), INTERVAL 1 YEAR) \r" + + "and us.user_status not in ('PENDING')", nativeQuery = true) + int checkUserBookinglimitation(int userId); + + @Query(value = "SELECT * FROM booking_details WHERE users_user_id = :userId AND booking_status NOT IN ('PENDING')", nativeQuery = true) + List getAllBookingsByUserId(Integer userId); + + @Query(value = "select * from booking_details WHERE booking_id =:bookID", nativeQuery = true) + BookingDetails getByBookingId(String bookID); + + // + " WHERE hall_details_hall_id =:hallId and booking_status= 'APPROVED' and + // start_date < curdate() ", nativeQuery = true) + @Query(value = "SELECT * FROM booking_details WHERE DATE(start_date) <= CURRENT_DATE() AND hall_details_hall_id = :hallId and booking_status='APPROVED' and refund_status IN ('WAITING','REJECTED','APPROVED')", nativeQuery = true) + public List getSettlementList(Integer hallId); + + @Query(value = "SELECT * FROM booking_details WHERE DATE(start_date) <= CURRENT_DATE() AND hall_details_hall_id IN (:hallIds) AND booking_status='APPROVED' AND refund_status IN ('WAITING','REJECTED','APPROVED')", nativeQuery = true) + public List getSettlementListByHallIds(@Param("hallIds") List hallIds); + + @Query(value = "SELECT * FROM booking_details WHERE DATE(start_date) <= CURRENT_DATE() AND booking_status='APPROVED' AND refund_status IN ('WAITING','REJECTED','APPROVED')", nativeQuery = true) + public List getAllSettlementList(); + + // yoga + @Query(value = "SELECT " + + "u.user_id AS userId, " + + "u.name AS UserName, " + + "u.mobile_no AS MobileNumber, " + + "CONCAT(u.doorno,',',u.street, ', ', u.area, ', ', u.location, ', ', u.pin_code) AS Address, " + + "COUNT(*) AS TotalBookings, " + + "SUM(CASE WHEN bd.booking_status = 'APPROVED' THEN 1 ELSE 0 END) AS Payment, " + + "SUM(CASE WHEN bd.booking_status = 'REJECTED' THEN 1 ELSE 0 END) AS Rejected, " + + "SUM(CASE WHEN bd.booking_status = 'CANCELED' THEN 1 ELSE 0 END) AS Canceled, " + + "SUM(CASE WHEN bd.booking_status = 'PAYMENT_FAILURE' THEN 1 ELSE 0 END) AS PaymentFailure " + + "FROM " + + "booking_details bd " + + "JOIN " + + "users u ON bd.users_user_id = u.user_id " + + "WHERE DATE(bd.booking_date) >= :fromDate " + + "AND DATE(bd.booking_date) <= :toDate " + + "AND bd.booking_status NOT IN ('PENDING')" + + "GROUP BY " + + "bd.users_user_id order by u.user_id asc", nativeQuery = true) + List getBookingUserDetailsReport(@Param("fromDate") String fromDate, @Param("toDate") String toDate); + + @Query(value = "SELECT " + + "h.hall_name AS HallName, " + + "h.hall_Incharge_name AS InchargeName, " + + "h.hall_Incharge_no AS hallInchargeMobno, " + + "CONCAT(h.zone, '/', h.division) AS ZoneDivision, " + // Concatenate zone and division + "COUNT(*) AS HallTotalBookings, " + + "SUM(p.amount_received) AS AmountReceived, " + + "COALESCE(SUM(r.amount - r.balace_amount), 0) AS AmountRefund, " + + "COALESCE(SUM(CASE WHEN bd.booking_status IN ('COMPLETED', 'CANCELED') THEN r.balace_amount ELSE 0 END), 0) AS Difference " + + + "FROM " + + "booking_details bd " + + "JOIN " + + "hall_details h ON bd.hall_details_hall_id = h.hall_id " + + "LEFT JOIN users u ON bd.users_user_id = u.user_id " + + "JOIN " + + "payments p ON bd.booking_id = p.booking_details_booking_id " + + "LEFT JOIN refund_response r ON bd.booking_id = r.booking_id " + + "WHERE DATE(bd.booking_date) >= :fromDate " + + "AND DATE(bd.booking_date) <= :toDate " + + "AND bd.booking_status NOT IN ('PENDING')" + + "GROUP BY " + + "bd.hall_details_hall_id", nativeQuery = true) + List getBookingHallDetailsReport(@Param("fromDate") String fromDate, @Param("toDate") String toDate); + + // ak + /* + * @Query(value = "SELECT * \r" + * + * + "FROM \r" + * + " settlement s\r" + * + + * " JOIN booking_details b ON s.booking_details_booking_id = b.booking_id\r" + * + * + "WHERE \r" + * + " DATE(b.booking_date) BETWEEN :fromDate AND :toDate\r" + * + * + "ORDER BY \r" + * + " b.booking_date", nativeQuery = true) + * List getSettlementInitiatedReport(@Param("fromDate") String + * fromDate, @Param("toDate") String toDate); + */ + @Query(value = "SELECT distinct(p.booking_id), " + + // "b.booking_id, " + + "b.booking_date, " + + "s.cdate, " + + "u.name, " + + "u.mobile_no, " + + "hd.hall_name, " + + "b.end_date, " + + "b.start_date, " + + "b.amount_received, " + + "s.refunded_amount, " + + "p.txansaction_id " + + "FROM booking_details b " + + "INNER JOIN settlement s ON b.booking_id = s.booking_details_booking_id " + + "INNER JOIN users u ON u.user_id = b.users_user_id " + + "INNER JOIN hall_details hd ON hd.hall_id = b.hall_details_hall_id " + + "inner join refund_response p on p.booking_id=b.booking_id " + + "WHERE DATE(b.booking_date) BETWEEN :fromDate AND :toDate " + + "ORDER BY b.booking_date DESC", nativeQuery = true) + List getSettlementInitiatedReport(@Param("fromDate") String fromDate, + @Param("toDate") String toDate); + + @Query(value = "SELECT \r" + + " COALESCE( SUM(\r" + + " CASE \r" + + " WHEN start_date = CURDATE() THEN 1\r" + + " ELSE 0\r" + + " END\r" + + " ),0) AS currente,\r" + + " COALESCE( SUM(\r" + + " CASE \r" + + " \r" + + " WHEN start_date < CURDATE() THEN 1\r" + + " ELSE 0\r" + + " END\r" + + " ), 0) AS past,\r" + + " COALESCE( SUM(\r" + + " CASE \r" + + " \r" + + " WHEN start_date > CURDATE() THEN 1\r" + + " ELSE 0\r" + + " END\r" + + " ),0) AS FUTURE\r" + + "FROM \r" + + " booking_details hall\r" + + " where hall_details_hall_id= :hall_id and booking_status='APPROVED'", nativeQuery = true) + List> pieChartCount(int hall_id); + + // @Query(value = "SELECT * FROM booking_details WHERE DATE(booking_date) >= + // :fromDate AND DATE(booking_date) <= :toDate AND (:bookingStatus IS NULL OR + // booking_status = :bookingStatus)", nativeQuery = true) + @Query(value = "SELECT bd.booking_id, bd.booking_date, hd.hall_name, us.name, us.mobile_no, " + + "CONCAT(us.doorno, ', ', us.street, ', ', us.area, ', ', us.location, ', ', us.pin_code) AS address, " + + + "us.usertype, bd.reason, bd.start_date, bd.end_date, " + + "(bd.deposit_amount + bd.hall_amount + bd.gst) AS amount_paid, bd.booking_status " + + "FROM booking_details bd " + + "JOIN hall_details hd ON bd.hall_details_hall_id = hd.hall_id " + + "JOIN users us ON bd.users_user_id = us.user_id " + + "WHERE DATE(bd.booking_date) >= :fromDate " + + "AND DATE(bd.booking_date) <= :toDate " + + "AND (:bookingStatus IS NULL OR bd.booking_status = :bookingStatus) order by bd.booking_id asc ", nativeQuery = true) + List getAllBookingDetailsWithStatus(@Param("fromDate") String fromDate, + @Param("toDate") String toDate, + @Param("bookingStatus") String bookingStatus); + + @Query(value = "SELECT bd.booking_id, bd.booking_date, hd.hall_name, us.name, us.mobile_no, " + + "CONCAT(us.doorno, ', ', us.street, ', ', us.area, ', ', us.location, ', ', us.pin_code) AS address, " + + + "us.usertype, bd.reason, bd.start_date, bd.end_date, " + + "bd.deposit_amount, bd.hall_amount, bd.gst, bd.amount_received, bd.booking_status " + + "FROM booking_details bd " + + "JOIN hall_details hd ON bd.hall_details_hall_id = hd.hall_id " + + "JOIN users us ON bd.users_user_id = us.user_id " + + "WHERE DATE(bd.booking_date) >= :fromDate " + + "AND DATE(bd.booking_date) <= :toDate " + + "AND (:bookingId IS NULL OR bd.booking_id = :bookingId) order by bd.booking_id asc", nativeQuery = true) + List getAllBookingDetailsWithBookingId(@Param("fromDate") String fromDate, + @Param("toDate") String toDate, + @Param("bookingId") Long bookingId); + + @Query(value = "SELECT bd.booking_id, bd.booking_date, hd.hall_name, us.name, us.mobile_no, " + + "CONCAT(us.doorno, ', ', us.street, ', ', us.area, ', ', us.location, ', ', us.pin_code) AS address, " + + + "us.usertype, bd.reason, bd.start_date, bd.end_date, " + + "bd.deposit_amount, bd.hall_amount, bd.gst, bd.amount_received, bd.booking_status " + + "FROM booking_details bd " + + "JOIN hall_details hd ON bd.hall_details_hall_id = hd.hall_id " + + "JOIN users us ON bd.users_user_id = us.user_id " + + "WHERE DATE(bd.booking_date) >= :fromDate " + + "AND DATE(bd.booking_date) <= :toDate " + + "AND (:bookingId IS NULL OR bd.booking_id = :bookingId)" + + "AND (:bookingStatus IS NULL OR bd.booking_status = :bookingStatus) order by bd.booking_id asc", nativeQuery = true) + List getAllBookingDetailsWithBookingIdwithbookingStatus(@Param("fromDate") String fromDate, + @Param("toDate") String toDate, + @Param("bookingId") Long bookingId, @Param("bookingStatus") String bookingStatus); + + // @Query(value = "SELECT * FROM booking_details WHERE DATE(booking_date) >= + // :fromDate AND DATE(booking_date) <= :toDate", nativeQuery = true) + @Query(value = "SELECT bd.booking_id, bd.booking_date, hd.hall_name, us.name, us.mobile_no, " + + "CONCAT(us.doorno, ', ', us.street, ', ', us.area, ', ', us.location, ', ', us.pin_code) AS address, " + + + "us.usertype, bd.reason, bd.start_date, bd.end_date, " + + "(bd.deposit_amount + bd.hall_amount + bd.gst) AS amount_paid, bd.booking_status " + + "FROM booking_details bd " + + "JOIN hall_details hd ON bd.hall_details_hall_id = hd.hall_id " + + "JOIN users us ON bd.users_user_id = us.user_id " + + "WHERE DATE(bd.booking_date) >= :fromDate " + + "AND DATE(bd.booking_date) <= :toDate order by bd.booking_id asc", nativeQuery = true) + List getAllBookingDetails(@Param("fromDate") String fromDate, @Param("toDate") String toDate); + + // @Query(value = "SELECT bd.booking_id, bd.booking_date, hd.hall_name, us.name, + // us.usertype, p.transaction_id, p.payment_type, p.amount_received, bd.reason, + // bd.start_date, bd.end_date, p.payment_status " + + // "FROM payments p " + + // "JOIN booking_details bd ON p.booking_details_booking_id =bd.booking_id " + + // "JOIN hall_details hd ON bd.hall_details_hall_id = hd.hall_id " + + // "left JOIN users us ON bd.users_user_id = us.user_id " + + // "WHERE DATE(p.cdate) >= :fromDate " + + // "AND DATE(p.cdate) <= :toDate " + + // "AND (:paymentStatus IS NULL OR p.payment_status = :paymentStatus)", + // nativeQuery = true) + // List getAllPaymentsDetails(@Param("fromDate") String fromDate, + // @Param("toDate") String toDate, + // @Param("paymentStatus") String paymentStatus); + + @Query(value = "SELECT SUM(CASE WHEN bd.booking_status = 'APPROVED' THEN 1 ELSE 0 END) AS approved_booking_count,\r" + + "SUM(CASE WHEN bd.booking_status = 'REJECTED' THEN 1 ELSE 0 END) AS rejected_booking_count,\r" + + "SUM(CASE WHEN bd.refund_status = 'WAITING' THEN 1 ELSE 0 END) AS waiting_settlement_count,\r" + + "SUM(CASE WHEN bd.refund_status = 'APPROVED' THEN 1 ELSE 0 END) AS approved_settlement_count,\r" + + "SUM(CASE WHEN bd.refund_status = 'REJECTED' THEN 1 ELSE 0 END) AS reject_settlement_count\r" + + "FROM booking_details bd " + + "JOIN hall_details hd ON bd.hall_details_hall_id = hd.hall_id " + + "WHERE hd.zone = :zone", nativeQuery = true) + List> toatlBookingCount(String zone); + + @Query(value = " SELECT SUM(CASE WHEN booking_status = 'APPROVED' THEN 1 ELSE 0 END) AS approved_count,\r" + + " SUM(CASE WHEN bd.booking_status = 'REJECTED' THEN 1 ELSE 0 END) AS rejected_count,\r" + + " SUM(CASE WHEN bd.booking_status = 'PENDING' THEN 1 ELSE 0 END) AS pending_count,\r" + + " SUM(CASE WHEN bd.booking_status = 'CANCELED' THEN 1 ELSE 0 END) AS CANCELED,\r" + + " SUM(CASE WHEN bd.booking_status = 'PAYMENT_FAILURE' THEN 1 ELSE 0 END) AS PAYMENT_FAILURE,\r" + + " SUM(CASE WHEN bd.booking_status = 'GCC_BLOCKED' THEN 1 ELSE 0 END) AS GCC_BLOCKED\r" + + "FROM booking_details bd " + + "JOIN hall_details hd ON bd.hall_details_hall_id = hd.hall_id " + + "WHERE hd.zone = :zone", nativeQuery = true) + List> getCount(String zone); + + @Query(value = "SELECT CONCAT(YEAR(bd.start_date), '-', LPAD(MONTH(bd.start_date), 2, '0')) AS months, SUM(CASE WHEN booking_status = 'APPROVED' THEN 1 ELSE 0 END) AS approved_count,\r" + + " SUM(CASE WHEN bd.booking_status = 'REJECTED' THEN 1 ELSE 0 END) AS rejected_count,\r" + + " SUM(CASE WHEN bd.booking_status = 'PENDING' THEN 1 ELSE 0 END) AS pending_count\r" + + "FROM booking_details bd JOIN hall_details hd ON bd.hall_details_hall_id = hd.hall_id \r" + + "WHERE bd.start_date >= DATE_SUB(CURDATE(), INTERVAL 6 MONTH)\r" + + " AND bd.start_date <= DATE_ADD(CURDATE(), INTERVAL 6 MONTH) AND hd.zone = :zone \r" + + " group by months order by months ASC", nativeQuery = true) + List> getmounthcount(String zone); + + @Query(value = "SELECT CONCAT(YEAR(bd.start_date), '-', LPAD(MONTH(bd.start_date), 2, '0')) AS months, SUM(CASE WHEN booking_status = 'APPROVED' THEN 1 ELSE 0 END) AS approved_count,\r" + + " SUM(CASE WHEN bd.booking_status = 'REJECTED' THEN 1 ELSE 0 END) AS rejected_count,\r" + + " SUM(CASE WHEN bd.booking_status = 'PENDING' THEN 1 ELSE 0 END) AS pending_count\r" + + "FROM booking_details bd JOIN hall_details hd ON bd.hall_details_hall_id = hd.hall_id \r" + + "WHERE bd.start_date >= DATE_SUB(CURDATE(), INTERVAL 6 MONTH)\r" + + " AND bd.start_date <= DATE_ADD(CURDATE(), INTERVAL 6 MONTH) \r" + + "AND (:zone = 'all zones' OR hd.zone = :zone)\r " + + " group by months order by months ASC", nativeQuery = true) + List> getAllAdminmonthcount(@Param("zone") String zone); + + @Query(value = " SELECT SUM(CASE WHEN booking_status = 'APPROVED' THEN 1 ELSE 0 END) AS approved_count,\r" + + " SUM(CASE WHEN bd.booking_status = 'REJECTED' THEN 1 ELSE 0 END) AS rejected_count,\r" + + " SUM(CASE WHEN bd.booking_status = 'PENDING' THEN 1 ELSE 0 END) AS pending_count,\r" + + " SUM(CASE WHEN bd.booking_status = 'CANCELED' THEN 1 ELSE 0 END) AS CANCELED,\r" + + " SUM(CASE WHEN bd.booking_status = 'PAYMENT_FAILURE' THEN 1 ELSE 0 END) AS PAYMENT_FAILURE,\r" + + " SUM(CASE WHEN bd.booking_status = 'GCC_BLOCKED' THEN 1 ELSE 0 END) AS GCC_BLOCKED\r" + + "FROM booking_details bd " + + "JOIN hall_details hd ON bd.hall_details_hall_id = hd.hall_id " + + "WHERE (:zone = 'all zones' OR hd.zone = :zone)", nativeQuery = true) + List> getAdmincount(@Param("zone") String zone); + + @Query(value = "SELECT CONCAT(YEAR(bd.start_date), '-', LPAD(MONTH(bd.start_date), 2, '0')) AS months, SUM(CASE WHEN booking_status = 'APPROVED' THEN 1 ELSE 0 END) AS approved_count,\r" + + " SUM(CASE WHEN bd.booking_status = 'REJECTED' THEN 1 ELSE 0 END) AS rejected_count,\r" + + " SUM(CASE WHEN bd.booking_status = 'COMPLETED' THEN 1 ELSE 0 END) AS completed_count\r" + + "FROM booking_details bd JOIN hall_details hd ON bd.hall_details_hall_id = hd.hall_id \r" + + "WHERE bd.start_date >= DATE_SUB(CURDATE(), INTERVAL 6 MONTH)\r" + + " AND bd.start_date <= DATE_ADD(CURDATE(), INTERVAL 6 MONTH) AND hd.hall_id=:hall_id \r" + + " group by months order by months ASC", nativeQuery = true) + List> getCartakermounthcount(int hall_id); + + @Query(value = " SELECT SUM(CASE WHEN booking_status = 'APPROVED' THEN 1 ELSE 0 END) AS approved_count,\r" + + " SUM(CASE WHEN bd.booking_status = 'REJECTED' THEN 1 ELSE 0 END) AS rejected_count,\r" + + " SUM(CASE WHEN bd.booking_status = 'COMPLETED' THEN 1 ELSE 0 END) AS completed_count,\r" + + " SUM(CASE WHEN bd.booking_status = 'CANCELED' THEN 1 ELSE 0 END) AS CANCELED,\r" + + " SUM(CASE WHEN bd.booking_status = 'PAYMENT_FAILURE' THEN 1 ELSE 0 END) AS PAYMENT_FAILURE,\r" + + " SUM(CASE WHEN bd.booking_status = 'GCC_BLOCKED' THEN 1 ELSE 0 END) AS GCC_BLOCKED\r" + + "FROM booking_details bd " + + "JOIN hall_details hd ON bd.hall_details_hall_id = hd.hall_id where hd.hall_id=:hall_id", nativeQuery = true) + List> getcartakecount(int hall_id); + + @Query(value = "SELECT \r" + + " bd.*, \r" + + " CASE \r" + + " WHEN bd.start_date < CURDATE() THEN 'Past'\r" + + " WHEN bd.start_date = CURDATE() THEN 'Current'\r" + + " WHEN bd.booking_status = 'WAITING_FOR_NOC' THEN 'waitingfornoc'\r" + + " WHEN bd.booking_status = 'WAITING_FOR_NOC_APPROVAL' THEN 'waitingfornocapproval'\r" + + " WHEN bd.schedule_count = 0 AND bd.start_date > CURDATE() THEN 'Reschedule'\r" + + " WHEN bd.reason IN ('State Govt Event','Central Govt Event','Commericial & Others') AND bd.booking_status='APPROVED' THEN 'noaction'" + + " ELSE 'Future' \r" + + " END AS event_category,\r" + + " users.*, \r" + + " hd.*, \r" + + " cd.*, \r" + + " pd.* \r" + + "FROM booking_details bd \r" + + "INNER JOIN users users ON bd.users_user_id = users.user_id \r" + + "INNER JOIN hall_details hd ON hd.hall_id = bd.hall_details_hall_id \r" + + "LEFT JOIN counter_details cd ON cd.counter_id = bd.counterdetails_counter_id\r" + + "LEFT JOIN payments pd ON bd.booking_id = pd.booking_details_booking_id \r" + + "WHERE bd.users_user_id = :userId and booking_status IN ('GCC_BLOCKED', 'APPROVED','CANCELED','REJECTED','COMPLETED','WAITING_FOR_NOC','WAITING_FOR_NOC_APPROVAL') \r" + + "ORDER BY bd.booking_id DESC\r", nativeQuery = true) + List> getAllBookingEventsByUserId(Integer userId); + + // counter + @Query(value = "SELECT bd.*, " + + "hd.zone AS hall_zone, " + + "hd.division AS hall_division, " + + "users.mobile_no AS mobile_no, " + + "CASE " + + "WHEN bd.start_date < CURDATE() THEN 'Past' " + + "WHEN bd.start_date = CURDATE() THEN 'Current' " + + "ELSE 'Future' " + + "END AS event_category " + + "FROM booking_details bd " + + "INNER JOIN users users on bd.users_user_id = users.user_id " + + "INNER JOIN hall_details hd ON bd.hall_details_hall_id = hd.hall_id " + + "WHERE bd.booking_type = 'OFFLINE'", nativeQuery = true) + List> findAllByBookingType(); + + @Query(value = "select bdud.* from booking_details bdud inner Join counter_refund_list crl on bdud.counterdetails_counter_id = crl.counterdetails_counter_id where crl.counterdetails_counter_id = :counterId", nativeQuery = true) + List getCounterDetailsbycounterId(int counterId); + + @Query(value = "select *from booking_details where counterdetails_counter_id = :counterId", nativeQuery = true) + List findByCounterId(int counterId); + + @Query("SELECT b FROM BookingDetails b LEFT JOIN FETCH b.bookingHistories WHERE b.bookingId = :bookingId") + Optional findByIdWithHistories(@Param("bookingId") int bookingId); + + @Query("SELECT b FROM BookingDetails b JOIN FETCH b.settlement s WHERE b.refundStatus = 'APPROVED'") + List findAllWithApprovedRefundStatus(); + + @Query("SELECT b FROM BookingDetails b JOIN FETCH b.settlement s WHERE b.refundStatus = 'INITIATED'") + List findByBookingDetailsRefundStatus(); + + @Query("SELECT b FROM BookingDetails b JOIN FETCH b.settlement s WHERE b.refundStatus = 'COMPLETED' AND b.bookingStatus='COMPLETED'") + List findAllwithCompletedRefundStatus(); + + @Query("SELECT b FROM BookingDetails b JOIN FETCH b.settlement s WHERE b.refundStatus = 'WAITING' and b.hallDetails.zone=:zone and b.hallDetails.hallId in (:hallIds)") + List findSettlementPendingByZone(String zone, List hallIds); + + // ak + @Query("SELECT b FROM BookingDetails b JOIN FETCH b.settlement s WHERE b.refundStatus = 'FAILURE' and b.hallDetails.zone=:zone and b.hallDetails.hallId in (:hallIds)") + List findSettlementInitiatedPendingByZone(String zone, List hallIds); + + @Query("SELECT b FROM BookingDetails b JOIN FETCH b.settlement s WHERE b.refundStatus = 'FAILURE'") + List findSettlementInitiatedPending(); + + @Query("SELECT b FROM BookingDetails b JOIN FETCH b.settlement s WHERE b.refundStatus = 'APPROVED' and b.hallDetails.zone=:zone and b.hallDetails.hallId in (:hallIds)") + List findSettlementApprovedByZone(String zone, List hallIds); + + @Query("SELECT b FROM BookingDetails b JOIN FETCH b.settlement s WHERE b.refundStatus = 'REJECTED' and b.hallDetails.zone=:zone and b.hallDetails.hallId in (:hallIds)") + List findSettlementRejectedByZone(String zone, List hallIds); + + @Query("SELECT b FROM BookingDetails b JOIN FETCH b.settlement s WHERE b.refundStatus = 'REJECTED'") + List findAllSettlementRejected(); + + @Query("SELECT b FROM BookingDetails b WHERE b.refundStatus = 'WAITING' AND b.bookingStatus = 'CANCELED' AND b.hallDetails.zone = :zone and b.hallDetails.hallId in (:hallIds)") + List findCancelledListByZone(@Param("zone") String zone, + @Param("hallIds") List hallIds); + + @Query("SELECT b FROM BookingDetails b WHERE b.refundStatus = 'APPROVED' AND b.bookingStatus = 'CANCELED' AND b.hallDetails.zone = :zone and b.hallDetails.hallId in (:hallIds)") + List findapprovedCancelledListByZone(String zone, @Param("hallIds") List hallIds); + + @Query("SELECT b FROM BookingDetails b WHERE b.refundStatus = 'WAITING' AND b.bookingStatus IN ('GCC_BLOCKED', 'REJECTED') AND b.hallDetails.zone = :zone and b.hallDetails.hallId in (:hallIds)") + List findRejectedListByZone(@Param("zone") String zone, + @Param("hallIds") List hallIds); + + @Query("SELECT b FROM BookingDetails b WHERE b.refundStatus = 'APPROVED' AND b.bookingStatus IN ('GCC_BLOCKED', 'REJECTED') AND b.hallDetails.zone = :zone and b.hallDetails.hallId in (:hallIds)") + List findapprovedRejectedListByZone(String zone, @Param("hallIds") List hallIds); + + @Query("SELECT b FROM BookingDetails b WHERE b.refundStatus = 'APPROVED' AND b.bookingStatus = 'CANCELED'") + List findCancelledList(); + + @Query(value = "SELECT * FROM booking_details WHERE refund_status = 'APPROVED' AND booking_status IN ('GCC_BLOCKED', 'REJECTED')", nativeQuery = true) + List findRejectedList(); + + @Query(value = "SELECT * FROM booking_details WHERE refund_status = 'INITIATED' AND booking_status = 'CANCELED'", nativeQuery = true) + List findInitiatedCancelledList(); + + @Query(value = "SELECT * FROM booking_details WHERE refund_status = 'INITIATED' AND booking_status IN ('GCC_BLOCKED', 'REJECTED')", nativeQuery = true) + List findInitiatedRejectedList(); + + @Query(value = "SELECT * FROM booking_details WHERE refund_status IN ('COMPLETED','CLOSED') AND booking_status = 'COMPLETED'", nativeQuery = true) + List findSettlementCompletedList(); + + @Query(value = "SELECT * FROM booking_details WHERE refund_status = 'COMPLETED' AND booking_status = 'CANCELED'", nativeQuery = true) + List findCancelledCompletedList(); + + @Query(value = "SELECT * FROM booking_details WHERE refund_status = 'COMPLETED' AND booking_status IN ('GCC_BLOCKED', 'REJECTED')", nativeQuery = true) + List findRejectedSettlementCompletedList(); + + // officer reports + @Query(value = "SELECT bd.*, hd.hall_name, us.name, us.usertype " + + "FROM booking_details bd " + + "JOIN hall_details hd ON bd.hall_details_hall_id = hd.hall_id " + + "JOIN users us ON bd.users_user_id = us.user_id " + + "WHERE DATE(bd.booking_date) >= :fromDate " + + "AND DATE(bd.booking_date) <= :toDate " + + "AND hd.zone = :zone ", nativeQuery = true) + List getAllBookingDetailsByZone(@Param("fromDate") String fromDate, + @Param("toDate") String toDate, @Param("zone") String zone); + + @Query(value = "SELECT bd.*, hd.hall_name, us.name, us.usertype " + + "FROM booking_details bd " + + "JOIN hall_details hd ON bd.hall_details_hall_id = hd.hall_id " + + "JOIN users us ON bd.users_user_id = us.user_id " + + "WHERE DATE(bd.booking_date) >= :fromDate " + + "AND DATE(bd.booking_date) <= :toDate " + + "AND hd.zone = :zone " + + "AND (:bookingStatus IS NULL OR bd.booking_status = :bookingStatus)", nativeQuery = true) + List getAllBookingDetailsByZoneWithStatus(@Param("fromDate") String fromDate, + @Param("toDate") String toDate, @Param("zone") String zone, + @Param("bookingStatus") String bookingStatus); + + @Query(value = "SELECT " + + "h.hall_name AS HallName, " + + "h.zone AS Zone, " + + "h.division AS Division, " + + "CONCAT(h.door_no,',',h.street, ', ', h.area, ', ', h.city, ', ', h.pin_code) AS Address, " + + "COUNT(*) AS HallTotalBookings, " + + "SUM(p.amount_received) AS AmountReceived, " + + "COALESCE(SUM(r.amount_refunded), 0) AS AmountRefund, " + // Use COALESCE to handle NULL values + "(SUM(p.amount_received) - COALESCE(SUM(r.amount_refunded), 0)) AS Difference " + // Calculate + // the + // difference + "FROM " + + "booking_details bd " + + "JOIN " + + "hall_details h ON bd.hall_details_hall_id = h.hall_id " + + "JOIN " + + "payments p ON bd.booking_id = p.booking_details_booking_id " + + "LEFT JOIN " + + "refund_transaction r ON p.transaction_id = r.transaction_id " + + "WHERE DATE(bd.booking_date) >= :fromDate " + + "AND DATE(bd.booking_date) <= :toDate " + + "AND h.zone = :zone " + + "GROUP BY " + + "bd.hall_details_hall_id", nativeQuery = true) + List getBookingHallDetailsReportByZone(@Param("fromDate") String fromDate, + @Param("toDate") String toDate, @Param("zone") String zone); + + @Query(value = "SELECT bd.*, hd.hall_name, us.name, us.usertype " + + "FROM booking_details bd " + + "JOIN hall_details hd ON bd.hall_details_hall_id = hd.hall_id " + + "LEFT JOIN users us ON bd.users_user_id = us.user_id " + + "LEFT JOIN settlement st ON bd.booking_id=st.booking_details_booking_id " + + "WHERE DATE(bd.booking_date) >= :fromDate " + + "AND DATE(bd.booking_date) <= :toDate " + + "AND bd.booking_status NOT IN ('PENDING')" + + "AND hd.zone = :zone ", nativeQuery = true) + List getAllBookingsettlementDetailsByZone(@Param("fromDate") String fromDate, + @Param("toDate") String toDate, @Param("zone") String zone); + + @Query(value = "SELECT bd.*, hd.hall_name, us.name, us.usertype " + + "FROM booking_details bd " + + "JOIN hall_details hd ON bd.hall_details_hall_id = hd.hall_id " + + "LEFT JOIN users us ON bd.users_user_id = us.user_id " + + "LEFT JOIN settlement st ON bd.booking_id=st.booking_details_booking_id " + + "WHERE DATE(bd.booking_date) >= :fromDate " + + "AND DATE(bd.booking_date) <= :toDate " + + "AND bd.booking_status NOT IN ('PENDING')" + + "AND hd.zone = :zone " + + "AND (:refundStatus IS NULL OR bd.refund_status = :refundStatus) ", nativeQuery = true) + List getAllBookingsettlementDetailsByZoneWithStatus(@Param("fromDate") String fromDate, + @Param("toDate") String toDate, @Param("zone") String zone, + @Param("refundStatus") String refundStatus); + + @Query(value = "SELECT " + + "h.hall_name AS HallName, " + + "h.hall_Incharge_name AS InchargeName, " + + "h.hall_Incharge_no AS hallInchargeMobno, " + + "CONCAT(h.zone, '/', h.division) AS ZoneDivision, " + // Concatenate zone and division + "COUNT(*) AS HallTotalBookings, " + + "SUM(p.amount_received) AS AmountReceived, " + + "COALESCE(SUM(r.amount - r.balace_amount), 0) AS AmountRefund, " + + "COALESCE(SUM(CASE WHEN bd.booking_status IN ('COMPLETED', 'CANCELED') THEN r.balace_amount ELSE 0 END), 0) AS Difference " + + + "FROM " + + "booking_details bd " + + "JOIN " + + "hall_details h ON bd.hall_details_hall_id = h.hall_id " + + "LEFT JOIN users u ON bd.users_user_id = u.user_id " + + "JOIN " + + "payments p ON bd.booking_id = p.booking_details_booking_id " + + "LEFT JOIN refund_response r ON bd.booking_id = r.booking_id " + + "WHERE DATE(bd.booking_date) >= :fromDate " + + "AND DATE(bd.booking_date) <= :toDate " + + "AND bd.booking_status NOT IN ('PENDING')" + + "AND h.zone = :zone " + + "AND bd.hall_details_hall_id = :hall_id " + + "GROUP BY " + + "bd.hall_details_hall_id", nativeQuery = true) + List getBookingHallDetailsReportByZone1(@Param("fromDate") String fromDate, + @Param("toDate") String toDate, @Param("zone") String zone, @Param("hall_id") Integer hallId); + + List findByHallDetailsAndBookingStatus(HallDetails hallDetails, BookingStatus gccBlocked); + + @Query(value = "SELECT COUNT(*) FROM booking_details WHERE hall_details_hall_id = :hallId AND start_date BETWEEN :startDate AND :endDate AND booking_status='GCC_BLOCKED'", nativeQuery = true) + int countByHallIdAndBookingDateBetween( + @Param("hallId") int hallId, + @Param("startDate") LocalDate startDate, + @Param("endDate") LocalDate endDate); + + @Query(value = "SELECT * FROM booking_details WHERE booking_id=:bookingId", nativeQuery = true) + List findBookingDetailsByBookingId(@Param("bookingId") Long bookingId); + + @Query(value = "SELECT booking_id FROM booking_details WHERE hall_details_hall_id = :hallId AND start_date BETWEEN :startDate AND :endDate AND booking_status='GCC_BLOCKED'", nativeQuery = true) + List findBookingIdsByHallIdAndBookingDateBetween(@Param("hallId") int hallId, + @Param("startDate") LocalDate startDate, @Param("endDate") LocalDate endDate); + + @Query(value = "SELECT bd.*, hd.hall_name, us.name, us.usertype " + + "FROM booking_details bd " + + "JOIN hall_details hd ON bd.hall_details_hall_id = hd.hall_id " + + "LEFT JOIN users us ON bd.users_user_id = us.user_id " + + "LEFT JOIN settlement st ON bd.booking_id=st.booking_details_booking_id " + + "WHERE DATE(bd.booking_date) >= :fromDate " + + "AND DATE(bd.booking_date) <= :toDate " + + "AND bd.booking_status NOT IN ('PENDING')" + + "AND (:refundStatus IS NULL OR bd.refund_status = :refundStatus) ", nativeQuery = true) + List getAllBookingsettlementDetailsWithStatus(@Param("fromDate") String fromDate, + @Param("toDate") String toDate, @Param("refundStatus") String refundStatus); + + @Query(value = "SELECT bd.*, hd.hall_name, us.name, us.usertype " + + "FROM booking_details bd " + + "JOIN hall_details hd ON bd.hall_details_hall_id = hd.hall_id " + + "LEFT JOIN users us ON bd.users_user_id = us.user_id " + + "LEFT JOIN settlement st ON bd.booking_id=st.booking_details_booking_id " + + "WHERE DATE(bd.booking_date) >= :fromDate " + + "AND bd.booking_status NOT IN ('PENDING')" + + "AND DATE(bd.booking_date) <= :toDate ", nativeQuery = true) + List getAllBookingsettlementDetails(@Param("fromDate") String fromDate, + @Param("toDate") String toDate); - "COALESCE(SUM(CASE WHEN b.booking_status NOT IN ('PENDING', 'REFUNDED', 'GCC_BLOCKED','REJECTED') THEN b.gst ELSE 0 END), 0) AS main_gst_amount, NULL AS PAST_Events, NULL AS FUTURE_Events " + + // admin dashboard + @Query(nativeQuery = true, value = - "FROM booking_details b " + + "SELECT 'main' AS category, NULL AS `key` , " + - "JOIN hall_details h ON h.hall_id = b.hall_details_hall_id " + + "COUNT(DISTINCT CASE WHEN b.booking_status NOT IN ('GCC_BLOCKED', 'GCC_UNBLOCKED') THEN b.booking_id END) AS totalCount," + + - "LEFT JOIN refund_response r ON b.booking_id = r.booking_id " + + "COALESCE(SUM(CASE WHEN b.booking_status NOT IN ('PENDING') THEN b.amount_received ELSE 0 END), 0) AS main_total_amount, " + + - "LEFT JOIN users u ON b.users_user_id = u.user_id " + + "COALESCE(SUM(r.amount - r.balace_amount), 0) AS main_refunded_amount," + - "WHERE (b.start_date >= CASE WHEN :fromDate IS NOT NULL THEN :fromDate ELSE (SELECT MIN(start_date) FROM booking_details) END) " + + "COALESCE(SUM(CASE WHEN b.booking_status NOT IN ('PENDING', 'REFUNDED', 'GCC_BLOCKED','REJECTED') THEN b.hall_amount ELSE 0 END), 0) AS main_net_amount, " + + - "AND (b.start_date <= CASE WHEN :toDate IS NOT NULL THEN :toDate ELSE (SELECT MAX(end_date) FROM booking_details) END) " + + "COALESCE(SUM(CASE WHEN b.booking_status NOT IN ('PENDING', 'REFUNDED', 'GCC_BLOCKED','REJECTED') THEN b.gst ELSE 0 END), 0) AS main_gst_amount, NULL AS PAST_Events, NULL AS FUTURE_Events " + + - "AND (:zone IS NULL OR :zone = 'ALL' OR h.zone = :zone) " + + "FROM booking_details b " + - "AND (:division IS NULL OR :division = 'ALL' OR h.division = :division) " + + "JOIN hall_details h ON h.hall_id = b.hall_details_hall_id " + - "AND (:hall_id IS NULL OR :hall_id = '1000' OR h.hall_id = :hall_id) " + + "LEFT JOIN refund_response r ON b.booking_id = r.booking_id " + - "AND (:userType IS NULL OR :userType = 'ALL' OR u.usertype = :userType) " + + "LEFT JOIN users u ON b.users_user_id = u.user_id " + - "AND b.booking_status!='PENDING'" + + "WHERE (b.start_date >= CASE WHEN :fromDate IS NOT NULL THEN :fromDate ELSE (SELECT MIN(start_date) FROM booking_details) END) " + + - "UNION ALL " + + "AND (b.start_date <= CASE WHEN :toDate IS NOT NULL THEN :toDate ELSE (SELECT MAX(end_date) FROM booking_details) END) " + + + "AND (:zone IS NULL OR :zone = 'ALL' OR h.zone = :zone) " + - "SELECT 'bookingStatus' AS category, b.booking_status AS `key`, COUNT(*) AS totalCount, NULL AS main_total_amount, NULL AS main_refunded_amount, NULL AS main_net_amount,NULL AS main_gst_amount, NULL AS PAST_Events, NULL AS FUTURE_Events " + + "AND (:division IS NULL OR :division = 'ALL' OR h.division = :division) " + - "FROM booking_details b " + + "AND (:hall_id IS NULL OR :hall_id = '1000' OR h.hall_id = :hall_id) " + - "JOIN hall_details h ON b.hall_details_hall_id = h.hall_id " + + "AND (:userType IS NULL OR :userType = 'ALL' OR u.usertype = :userType) " + - "LEFT JOIN users u ON b.users_user_id = u.user_id " + + "AND b.booking_status!='PENDING'" + - "WHERE (b.start_date >= CASE WHEN :fromDate IS NOT NULL THEN :fromDate ELSE (SELECT MIN(start_date) FROM booking_details) END) " + + "UNION ALL " + - "AND (b.start_date <= CASE WHEN :toDate IS NOT NULL THEN :toDate ELSE (SELECT MAX(end_date) FROM booking_details) END) " + + "SELECT 'bookingStatus' AS category, b.booking_status AS `key`, COUNT(*) AS totalCount, NULL AS main_total_amount, NULL AS main_refunded_amount, NULL AS main_net_amount,NULL AS main_gst_amount, NULL AS PAST_Events, NULL AS FUTURE_Events " + + - "AND (:zone IS NULL OR :zone = 'ALL' OR h.zone = :zone) " + + "FROM booking_details b " + - "AND (:division IS NULL OR :division = 'ALL' OR h.division = :division) " + + "JOIN hall_details h ON b.hall_details_hall_id = h.hall_id " + - "AND (:hall_id IS NULL OR :hall_id = '1000' OR h.hall_id = :hall_id) " + + "LEFT JOIN users u ON b.users_user_id = u.user_id " + - "AND (:userType IS NULL OR :userType = 'ALL' OR u.usertype = :userType) " + + "WHERE (b.start_date >= CASE WHEN :fromDate IS NOT NULL THEN :fromDate ELSE (SELECT MIN(start_date) FROM booking_details) END) " + + - "AND b.booking_status != 'PENDING'" + + "AND (b.start_date <= CASE WHEN :toDate IS NOT NULL THEN :toDate ELSE (SELECT MAX(end_date) FROM booking_details) END) " + + - "GROUP BY b.booking_status " + + "AND (:zone IS NULL OR :zone = 'ALL' OR h.zone = :zone) " + - "UNION ALL " + + "AND (:division IS NULL OR :division = 'ALL' OR h.division = :division) " + + "AND (:hall_id IS NULL OR :hall_id = '1000' OR h.hall_id = :hall_id) " + - "SELECT 'refundStatus' AS category, b.refund_status AS `key`, COUNT(*) AS totalCount, NULL AS main_total_amount, NULL AS main_refunded_amount, NULL AS main_net_amount,NULL AS main_gst_amount, NULL AS PAST_Events, NULL AS FUTURE_Events " + + "AND (:userType IS NULL OR :userType = 'ALL' OR u.usertype = :userType) " + - "FROM booking_details b " + + "AND b.booking_status != 'PENDING'" + - "JOIN hall_details h ON b.hall_details_hall_id = h.hall_id " + + "GROUP BY b.booking_status " + - "LEFT JOIN users u ON b.users_user_id = u.user_id " + + "UNION ALL " + - "WHERE (b.start_date >= CASE WHEN :fromDate IS NOT NULL THEN :fromDate ELSE (SELECT MIN(start_date) FROM booking_details) END) " + + "SELECT 'refundStatus' AS category, b.refund_status AS `key`, COUNT(*) AS totalCount, NULL AS main_total_amount, NULL AS main_refunded_amount, NULL AS main_net_amount,NULL AS main_gst_amount, NULL AS PAST_Events, NULL AS FUTURE_Events " + + - "AND (b.start_date <= CASE WHEN :toDate IS NOT NULL THEN :toDate ELSE (SELECT MAX(end_date) FROM booking_details) END) " + + "FROM booking_details b " + - "AND (:zone IS NULL OR :zone = 'ALL' OR h.zone = :zone) " + + "JOIN hall_details h ON b.hall_details_hall_id = h.hall_id " + - "AND (:division IS NULL OR :division = 'ALL' OR h.division = :division) " + + "LEFT JOIN users u ON b.users_user_id = u.user_id " + - "AND (:hall_id IS NULL OR :hall_id = '1000' OR h.hall_id = :hall_id) " + + "WHERE (b.start_date >= CASE WHEN :fromDate IS NOT NULL THEN :fromDate ELSE (SELECT MIN(start_date) FROM booking_details) END) " + + - "AND (:userType IS NULL OR :userType = 'ALL' OR u.usertype = :userType) " + + "AND (b.start_date <= CASE WHEN :toDate IS NOT NULL THEN :toDate ELSE (SELECT MAX(end_date) FROM booking_details) END) " + + - "AND b.booking_status != 'PENDING'" + + "AND (:zone IS NULL OR :zone = 'ALL' OR h.zone = :zone) " + - "GROUP BY b.refund_status " + + "AND (:division IS NULL OR :division = 'ALL' OR h.division = :division) " + - "UNION ALL " + + "AND (:hall_id IS NULL OR :hall_id = '1000' OR h.hall_id = :hall_id) " + + "AND (:userType IS NULL OR :userType = 'ALL' OR u.usertype = :userType) " + - "SELECT 'reason' AS category, b.reason AS `key`, COUNT(*) AS totalCount, NULL AS main_total_amount, NULL AS main_net_amount, NULL AS main_refunded_amount,NULL AS main_gst_amount, NULL AS PAST_Events, NULL AS FUTURE_Events " + + "AND b.booking_status != 'PENDING'" + - "FROM booking_details b " + + "GROUP BY b.refund_status " + - "JOIN hall_details h ON b.hall_details_hall_id = h.hall_id " + + "UNION ALL " + - "LEFT JOIN users u ON b.users_user_id = u.user_id " + + "SELECT 'reason' AS category, b.reason AS `key`, COUNT(*) AS totalCount, NULL AS main_total_amount, NULL AS main_net_amount, NULL AS main_refunded_amount,NULL AS main_gst_amount, NULL AS PAST_Events, NULL AS FUTURE_Events " + + - "WHERE (b.start_date >= CASE WHEN :fromDate IS NOT NULL THEN :fromDate ELSE (SELECT MIN(start_date) FROM booking_details) END) " + + "FROM booking_details b " + - "AND (b.start_date <= CASE WHEN :toDate IS NOT NULL THEN :toDate ELSE (SELECT MAX(end_date) FROM booking_details) END) " + + "JOIN hall_details h ON b.hall_details_hall_id = h.hall_id " + - "AND (:zone IS NULL OR :zone = 'ALL' OR h.zone = :zone) " + + "LEFT JOIN users u ON b.users_user_id = u.user_id " + - "AND (:division IS NULL OR :division = 'ALL' OR h.division = :division) " + + "WHERE (b.start_date >= CASE WHEN :fromDate IS NOT NULL THEN :fromDate ELSE (SELECT MIN(start_date) FROM booking_details) END) " + + - "AND (:hall_id IS NULL OR :hall_id = '1000' OR h.hall_id = :hall_id) " + + "AND (b.start_date <= CASE WHEN :toDate IS NOT NULL THEN :toDate ELSE (SELECT MAX(end_date) FROM booking_details) END) " + + - "AND (:userType IS NULL OR :userType = 'ALL' OR u.usertype = :userType) " + + "AND (:zone IS NULL OR :zone = 'ALL' OR h.zone = :zone) " + - "AND b.booking_status != 'PENDING'" + + "AND (:division IS NULL OR :division = 'ALL' OR h.division = :division) " + - "GROUP BY b.reason " + + "AND (:hall_id IS NULL OR :hall_id = '1000' OR h.hall_id = :hall_id) " + - "UNION ALL " + + "AND (:userType IS NULL OR :userType = 'ALL' OR u.usertype = :userType) " + + "AND b.booking_status != 'PENDING'" + - "SELECT 'zonewise' AS category, h.zone AS `key`, SUM(CASE WHEN b.hall_details_hall_id IS NOT NULL AND b.booking_status != 'PENDING' THEN 1 ELSE 0 END) AS totalCount, " + + "GROUP BY b.reason " + - "NULL AS main_total_amount, NULL AS main_refunded_amount, NULL AS main_net_amount,NULL AS main_gst_amount, NULL AS PAST_Events, NULL AS FUTURE_Events " + + "UNION ALL " + - "FROM hall_details h " + + "SELECT 'zonewise' AS category, h.zone AS `key`, SUM(CASE WHEN b.hall_details_hall_id IS NOT NULL AND b.booking_status != 'PENDING' THEN 1 ELSE 0 END) AS totalCount, " + + - "LEFT JOIN booking_details b ON b.hall_details_hall_id = h.hall_id " + + "NULL AS main_total_amount, NULL AS main_refunded_amount, NULL AS main_net_amount,NULL AS main_gst_amount, NULL AS PAST_Events, NULL AS FUTURE_Events " + + - "LEFT JOIN users u ON b.users_user_id = u.user_id " + + "FROM hall_details h " + - "WHERE (b.start_date IS NULL OR b.start_date BETWEEN COALESCE(:fromDate, (SELECT MIN(start_date) FROM booking_details)) AND COALESCE(:toDate, (SELECT MAX(end_date) FROM booking_details))) " + + "LEFT JOIN booking_details b ON b.hall_details_hall_id = h.hall_id " + - "AND (:zone IS NULL OR :zone = 'ALL' OR h.zone = :zone) " + + "LEFT JOIN users u ON b.users_user_id = u.user_id " + - "AND (:division IS NULL OR :division = 'ALL' OR h.division = :division) " + + "WHERE (b.start_date IS NULL OR b.start_date BETWEEN COALESCE(:fromDate, (SELECT MIN(start_date) FROM booking_details)) AND COALESCE(:toDate, (SELECT MAX(end_date) FROM booking_details))) " + + - "AND (:hall_id IS NULL OR :hall_id = '1000' OR h.hall_id = :hall_id) " + + "AND (:zone IS NULL OR :zone = 'ALL' OR h.zone = :zone) " + - "AND (:userType IS NULL OR :userType = 'ALL' OR u.usertype = :userType) " + + "AND (:division IS NULL OR :division = 'ALL' OR h.division = :division) " + - "GROUP BY h.zone " + + "AND (:hall_id IS NULL OR :hall_id = '1000' OR h.hall_id = :hall_id) " + - "UNION ALL " + + "AND (:userType IS NULL OR :userType = 'ALL' OR u.usertype = :userType) " + + "GROUP BY h.zone " + - "SELECT 'paymentStatus' AS category, " + + "UNION ALL " + - " p.payment_status AS `key`, " + + "SELECT 'paymentStatus' AS category, " + - " COUNT(*) AS totalCount, " + + " p.payment_status AS `key`, " + - " NULL AS main_total_amount, " + + " COUNT(*) AS totalCount, " + - " NULL AS main_refunded_amount, " + + " NULL AS main_total_amount, " + - " NULL AS main_net_amount, " + + " NULL AS main_refunded_amount, " + - " NULL AS main_gst_amount," + + " NULL AS main_net_amount, " + - " NULL AS PAST_Events, " + + " NULL AS main_gst_amount," + - " NULL AS FUTURE_Events " + + " NULL AS PAST_Events, " + - "FROM payments p " + + " NULL AS FUTURE_Events " + - "JOIN booking_details b ON p.booking_details_booking_id = b.booking_id " + + "FROM payments p " + - "JOIN hall_details h ON b.hall_details_hall_id = h.hall_id " + + "JOIN booking_details b ON p.booking_details_booking_id = b.booking_id " + - "LEFT JOIN users u ON b.users_user_id = u.user_id " + + "JOIN hall_details h ON b.hall_details_hall_id = h.hall_id " + - "WHERE (b.start_date >= CASE WHEN :fromDate IS NOT NULL THEN :fromDate ELSE (SELECT MIN(start_date) FROM booking_details) END) " + + "LEFT JOIN users u ON b.users_user_id = u.user_id " + - "AND (b.start_date <= CASE WHEN :toDate IS NOT NULL THEN :toDate ELSE (SELECT MAX(end_date) FROM booking_details) END) " + + "WHERE (b.start_date >= CASE WHEN :fromDate IS NOT NULL THEN :fromDate ELSE (SELECT MIN(start_date) FROM booking_details) END) " + + - "AND (:zone IS NULL OR :zone = 'ALL' OR h.zone = :zone) " + + "AND (b.start_date <= CASE WHEN :toDate IS NOT NULL THEN :toDate ELSE (SELECT MAX(end_date) FROM booking_details) END) " + + - "AND (:division IS NULL OR :division = 'ALL' OR h.division = :division) " + + "AND (:zone IS NULL OR :zone = 'ALL' OR h.zone = :zone) " + - "AND (:hall_id IS NULL OR :hall_id = '1000' OR h.hall_id = :hall_id) " + + "AND (:division IS NULL OR :division = 'ALL' OR h.division = :division) " + - "AND (:userType IS NULL OR :userType = 'ALL' OR u.usertype = :userType) " + + "AND (:hall_id IS NULL OR :hall_id = '1000' OR h.hall_id = :hall_id) " + - "AND b.booking_status!='PENDING'" + + "AND (:userType IS NULL OR :userType = 'ALL' OR u.usertype = :userType) " + - "GROUP BY p.payment_status " + + "AND b.booking_status!='PENDING'" + - "UNION ALL " + + "GROUP BY p.payment_status " + + "UNION ALL " + - "SELECT 'past_future' AS category, NULL AS `key`, NULL AS totalCount, NULL AS main_total_amount, NULL AS main_refunded_amount, NULL AS main_net_amount, " + - "NULL AS main_gst_amount," + - "COALESCE(SUM(PAST_Booking), 0) AS PAST_Events, " + - "COALESCE(SUM(FUTURE_Booking), 0) AS FUTURE_Events " + - "FROM ( " + - "SELECT " + - "CASE WHEN DATE(b.start_date) < CURRENT_DATE() THEN 1 ELSE 0 END AS PAST_Booking, " + - "CASE WHEN DATE(b.start_date) BETWEEN CURRENT_DATE() AND DATE_ADD(CURRENT_DATE(), INTERVAL 3 MONTH) THEN 1 ELSE 0 END AS FUTURE_Booking " + - "FROM booking_details b " + - "JOIN hall_details h ON b.hall_details_hall_id = h.hall_id " + - "LEFT JOIN users u ON b.users_user_id = u.user_id " + - "WHERE " + - " b.booking_status!='PENDING'" + - "AND (b.start_date >= CASE WHEN :fromDate IS NOT NULL THEN :fromDate ELSE (SELECT MIN(start_date) FROM booking_details) END) AND " + - "(b.start_date <= CASE WHEN :toDate IS NOT NULL THEN :toDate ELSE (SELECT MAX(end_date) FROM booking_details) END) AND " + - "(:zone IS NULL OR :zone = 'ALL' OR h.zone = :zone) AND " + - "(:division IS NULL OR :division = 'ALL' OR h.division = :division) AND " + - "(:hall_id IS NULL OR :hall_id = '1000' OR h.hall_id = :hall_id) AND " + - "(:userType IS NULL OR :userType = 'ALL' OR u.usertype = :userType) " + - ") AS combined" - - ) - List> getBookingStatistics( - @Param("fromDate") LocalDate fromDate, - @Param("toDate") LocalDate toDate, - @Param("zone") String zone, - @Param("division") String division, - @Param("hall_id") Integer hallid, - @Param("userType") String userType - ); - - @Query(value = "SELECT \r" - + " b.booking_date as booking_date,\r" - + " u.name as name,\r" - + " u.usertype as usertype,\r" - + " b.reason as reason,\r" - + " b.start_date as start_date,\r" - + " b.end_date as end_date,\r" - + " b.no_of_days as no_of_days,\r" - + " b.booking_status as booking_status,\r" - + " b.amount_received as amount_received,\r" - + " COALESCE(rt.amount_refunded, 0) as amount_refunded,\r" - + " COALESCE(r.balace_amount, 0) as balance_amount\r" - + "FROM booking_details b\r" - + "JOIN hall_details h ON b.hall_details_hall_id = h.hall_id \r" - + "LEFT JOIN users u ON b.users_user_id = u.user_id\r" - + "LEFT JOIN refund_response r ON b.booking_id = r.booking_id\r" - + "LEFT JOIN refund_transaction rt ON b.booking_id = rt.booking_details_booking_id\r" - + "WHERE h.hall_id = :hallId AND b.booking_status != 'PENDING' ", nativeQuery = true) - List> getBookingDetailsByHallId(@Param("hallId") int hallId); - - //officer Dashboard - @Query(nativeQuery = true, value = - "SELECT 'main' AS category, NULL AS `key` , " + - "COUNT(DISTINCT b.booking_id) AS totalCount," + - "SUM(b.amount_received) AS main_total_amount, " + - "COALESCE(SUM(r.amount-r.balace_amount),0) AS main_refunded_amount, " + - "COALESCE(SUM(CASE WHEN b.booking_status IN ('COMPLETED', 'CANCELED') THEN r.balace_amount ELSE 0 END), 0) AS main_net_amount, NULL AS PAST_Events, NULL AS FUTURE_Events " + - "FROM booking_details b " + - "JOIN hall_details h ON h.hall_id = b.hall_details_hall_id " + - "LEFT JOIN refund_response r ON b.booking_id = r.booking_id " + - "LEFT JOIN users u ON b.users_user_id = u.user_id " + - "WHERE (b.start_date >= CASE WHEN :fromDate IS NOT NULL THEN :fromDate ELSE (SELECT MIN(start_date) FROM booking_details) END) " + - "AND (b.start_date <= CASE WHEN :toDate IS NOT NULL THEN :toDate ELSE (SELECT MAX(end_date) FROM booking_details) END) " + - "AND (:zone IS NULL OR :zone = 'ALL' OR h.zone = :zone) " + - "AND (:division IS NULL OR :division = 'ALL' OR h.division = :division) " + - "AND (:hall_id IS NULL OR :hall_id = '1000' OR h.hall_id = :hall_id) " + - "AND (:userType IS NULL OR :userType = 'ALL' OR u.usertype = :userType) " + - "AND b.booking_status!='PENDING'" + - "UNION ALL " + - - "SELECT 'bookingStatus' AS category, b.booking_status AS `key`, COUNT(*) AS totalCount, NULL AS main_total_amount, NULL AS main_refunded_amount, NULL AS main_net_amount, NULL AS PAST_Events, NULL AS FUTURE_Events " + - "FROM booking_details b " + - "JOIN hall_details h ON b.hall_details_hall_id = h.hall_id " + - "LEFT JOIN users u ON b.users_user_id = u.user_id " + - "WHERE (b.start_date >= CASE WHEN :fromDate IS NOT NULL THEN :fromDate ELSE (SELECT MIN(start_date) FROM booking_details) END) " + - "AND (b.start_date <= CASE WHEN :toDate IS NOT NULL THEN :toDate ELSE (SELECT MAX(end_date) FROM booking_details) END) " + - "AND (:zone IS NULL OR :zone = 'ALL' OR h.zone = :zone) " + - "AND (:division IS NULL OR :division = 'ALL' OR h.division = :division) " + - "AND (:hall_id IS NULL OR :hall_id = '1000' OR h.hall_id = :hall_id) " + - "AND (:userType IS NULL OR :userType = 'ALL' OR u.usertype = :userType) " + - "AND b.booking_status != 'PENDING'" + - "GROUP BY b.booking_status " + - "UNION ALL " + - - "SELECT 'refundStatus' AS category, b.refund_status AS `key`, COUNT(*) AS totalCount, NULL AS main_total_amount, NULL AS main_refunded_amount, NULL AS main_net_amount, NULL AS PAST_Events, NULL AS FUTURE_Events " + - "FROM booking_details b " + - "JOIN hall_details h ON b.hall_details_hall_id = h.hall_id " + - "LEFT JOIN users u ON b.users_user_id = u.user_id " + - "WHERE (b.start_date >= CASE WHEN :fromDate IS NOT NULL THEN :fromDate ELSE (SELECT MIN(start_date) FROM booking_details) END) " + - "AND (b.start_date <= CASE WHEN :toDate IS NOT NULL THEN :toDate ELSE (SELECT MAX(end_date) FROM booking_details) END) " + - "AND (:zone IS NULL OR :zone = 'ALL' OR h.zone = :zone) " + - "AND (:division IS NULL OR :division = 'ALL' OR h.division = :division) " + - "AND (:hall_id IS NULL OR :hall_id = '1000' OR h.hall_id = :hall_id) " + - "AND (:userType IS NULL OR :userType = 'ALL' OR u.usertype = :userType) " + - "AND b.booking_status != 'PENDING'" + - "GROUP BY b.refund_status " + - "UNION ALL " + - - "SELECT 'reason' AS category, b.reason AS `key`, COUNT(*) AS totalCount, NULL AS main_total_amount, NULL AS main_net_amount, NULL AS main_refunded_amount, NULL AS PAST_Events, NULL AS FUTURE_Events " + - "FROM booking_details b " + - "JOIN hall_details h ON b.hall_details_hall_id = h.hall_id " + - "LEFT JOIN users u ON b.users_user_id = u.user_id " + - "WHERE (b.start_date >= CASE WHEN :fromDate IS NOT NULL THEN :fromDate ELSE (SELECT MIN(start_date) FROM booking_details) END) " + - "AND (b.start_date <= CASE WHEN :toDate IS NOT NULL THEN :toDate ELSE (SELECT MAX(end_date) FROM booking_details) END) " + - "AND (:zone IS NULL OR :zone = 'ALL' OR h.zone = :zone) " + - "AND (:division IS NULL OR :division = 'ALL' OR h.division = :division) " + - "AND (:hall_id IS NULL OR :hall_id = '1000' OR h.hall_id = :hall_id) " + - "AND (:userType IS NULL OR :userType = 'ALL' OR u.usertype = :userType) " + - "AND b.booking_status != 'PENDING'" + - "GROUP BY b.reason " + - "UNION ALL " + - - "SELECT 'zonewise' AS category, h.zone AS `key`, SUM(CASE WHEN b.hall_details_hall_id IS NOT NULL AND b.booking_status != 'PENDING' THEN 1 ELSE 0 END) AS totalCount, " + - "NULL AS main_total_amount, NULL AS main_refunded_amount, NULL AS main_net_amount, NULL AS PAST_Events, NULL AS FUTURE_Events " + - "FROM hall_details h " + - "LEFT JOIN booking_details b ON b.hall_details_hall_id = h.hall_id " + - "LEFT JOIN users u ON b.users_user_id = u.user_id " + - "WHERE (b.start_date IS NULL OR b.start_date BETWEEN COALESCE(:fromDate, (SELECT MIN(start_date) FROM booking_details)) AND COALESCE(:toDate, (SELECT MAX(end_date) FROM booking_details))) " + - "AND (:zone IS NULL OR :zone = 'ALL' OR h.zone = :zone) " + - "AND (:division IS NULL OR :division = 'ALL' OR h.division = :division) " + - "AND (:hall_id IS NULL OR :hall_id = '1000' OR h.hall_id = :hall_id) " + - "AND (:userType IS NULL OR :userType = 'ALL' OR u.usertype = :userType) " + - "GROUP BY h.zone " + - "UNION ALL " + - - "SELECT 'paymentStatus' AS category, " + - " p.payment_status AS `key`, " + - " COUNT(*) AS totalCount, " + - " NULL AS main_total_amount, " + - " NULL AS main_refunded_amount, " + - " NULL AS main_net_amount, " + - " NULL AS PAST_Events, " + - " NULL AS FUTURE_Events " + - "FROM payments p " + - "JOIN booking_details b ON p.booking_details_booking_id = b.booking_id " + - "JOIN hall_details h ON b.hall_details_hall_id = h.hall_id " + - "LEFT JOIN users u ON b.users_user_id = u.user_id " + - "WHERE (b.start_date >= CASE WHEN :fromDate IS NOT NULL THEN :fromDate ELSE (SELECT MIN(start_date) FROM booking_details) END) " + - "AND (b.start_date <= CASE WHEN :toDate IS NOT NULL THEN :toDate ELSE (SELECT MAX(end_date) FROM booking_details) END) " + - "AND (:zone IS NULL OR :zone = 'ALL' OR h.zone = :zone) " + - "AND (:division IS NULL OR :division = 'ALL' OR h.division = :division) " + - "AND (:hall_id IS NULL OR :hall_id = '1000' OR h.hall_id = :hall_id) " + - "AND (:userType IS NULL OR :userType = 'ALL' OR u.usertype = :userType) " + - "AND b.booking_status!='PENDING'" + - "GROUP BY p.payment_status " + - "UNION ALL " + - - "SELECT 'past_future' AS category, NULL AS `key`, NULL AS totalCount, NULL AS main_total_amount, NULL AS main_refunded_amount, NULL AS main_net_amount, " + - "COALESCE(SUM(PAST_Booking), 0) AS PAST_Events, " + - "COALESCE(SUM(FUTURE_Booking), 0) AS FUTURE_Events " + - "FROM ( " + - "SELECT " + - "CASE WHEN DATE(b.start_date) < CURRENT_DATE() THEN 1 ELSE 0 END AS PAST_Booking, " + - "CASE WHEN DATE(b.start_date) BETWEEN CURRENT_DATE() AND DATE_ADD(CURRENT_DATE(), INTERVAL 3 MONTH) THEN 1 ELSE 0 END AS FUTURE_Booking " + - "FROM booking_details b " + - "JOIN hall_details h ON b.hall_details_hall_id = h.hall_id " + - "LEFT JOIN users u ON b.users_user_id = u.user_id " + - "WHERE " + - " b.booking_status!='PENDING'" + - "AND (b.start_date >= CASE WHEN :fromDate IS NOT NULL THEN :fromDate ELSE (SELECT MIN(start_date) FROM booking_details) END) AND " + - "(b.start_date <= CASE WHEN :toDate IS NOT NULL THEN :toDate ELSE (SELECT MAX(end_date) FROM booking_details) END) AND " + - "(:zone IS NULL OR :zone = 'ALL' OR h.zone = :zone) AND " + - "(:division IS NULL OR :division = 'ALL' OR h.division = :division) AND " + - "(:hall_id IS NULL OR :hall_id = '1000' OR h.hall_id = :hall_id) AND " + - "(:userType IS NULL OR :userType = 'ALL' OR u.usertype = :userType) " + - ") AS combined" - ) - List> getOfficerDashboard( - @Param("fromDate") LocalDate fromDate, - @Param("toDate") LocalDate toDate, - @Param("zone") String zone, - @Param("division") String division, - @Param("hall_id") Integer hallid, - @Param("userType") String userType - ); - - @Query(value = "SELECT \r" - + " b.booking_date as booking_date,\r" - + " u.name as name,\r" - + " u.usertype as usertype,\r" - + " b.reason as reason,\r" - + " b.start_date as start_date,\r" - + " b.end_date as end_date,\r" - + " b.no_of_days as no_of_days,\r" - + " b.booking_status as booking_status,\r" - + " b.amount_received as amount_received,\r" - + " COALESCE(rt.amount_refunded, 0) as amount_refunded,\r" - + " COALESCE(r.balace_amount, 0) as balance_amount\r" - + "FROM booking_details b\r" - + "JOIN hall_details h ON b.hall_details_hall_id = h.hall_id \r" - + "LEFT JOIN users u ON b.users_user_id = u.user_id\r" - + "LEFT JOIN refund_response r ON b.booking_id = r.booking_id\r" - + "LEFT JOIN refund_transaction rt ON b.booking_id = rt.booking_details_booking_id\r" - + "WHERE h.hall_id = :hallId AND b.booking_status != 'PENDING' ", nativeQuery = true) - List> getHallDetailsForOfficer(@Param("hallId") Integer hallIid); - - @Query(value = "SELECT bd.*, hd.hall_name, us.name, us.usertype " + - "FROM booking_details bd " + - "JOIN hall_details hd ON bd.hall_details_hall_id = hd.hall_id " + - "JOIN users us ON bd.users_user_id = us.user_id " + - "WHERE DATE(bd.booking_date) >= :fromDate " + - "AND DATE(bd.booking_date) <= :toDate " + - "AND hd.zone = :zone ", nativeQuery = true) - List getAllBookingDetailsBookingDateByZone(@Param("fromDate") String fromDate, @Param("toDate") String toDate, @Param("zone") String zone); - - @Query(value = "SELECT bd.*, hd.hall_name, us.name, us.usertype " + - "FROM booking_details bd " + - "JOIN hall_details hd ON bd.hall_details_hall_id = hd.hall_id " + - "JOIN users us ON bd.users_user_id = us.user_id " + - "WHERE DATE(bd.start_date) >= :fromDate " + - "AND DATE(bd.end_date) <= :toDate " + - "AND hd.zone = :zone ", nativeQuery = true) - List getAllBookingDetailsEventDateByZone(@Param("fromDate") String fromDate, @Param("toDate") String toDate, @Param("zone") String zone); - - @Query(value = "SELECT bd.*, hd.hall_name, us.name, us.usertype " + - "FROM booking_details bd " + - "JOIN hall_details hd ON bd.hall_details_hall_id = hd.hall_id " + - "JOIN users us ON bd.users_user_id = us.user_id " + - "WHERE DATE(bd.booking_date) >= :fromDate " + - "AND DATE(bd.booking_date) <= :toDate " + - "AND hd.zone = :zone " + - "AND (:bookingStatus IS NULL OR bd.booking_status = :bookingStatus)", nativeQuery = true) - List getAllBookingDetailsBookingDateByZoneWithStatus(@Param("fromDate") String fromDate, @Param("toDate") String toDate, @Param("zone") String zone, @Param("bookingStatus") String bookingStatus); - - @Query(value = "SELECT bd.*, hd.hall_name, us.name, us.usertype " + - "FROM booking_details bd " + - "JOIN hall_details hd ON bd.hall_details_hall_id = hd.hall_id " + - "JOIN users us ON bd.users_user_id = us.user_id " + - "WHERE DATE(bd.start_date) >= :fromDate " + - "AND DATE(bd.end_date) <= :toDate " + - "AND hd.zone = :zone " + - "AND (:bookingStatus IS NULL OR bd.booking_status = :bookingStatus)", nativeQuery = true) - List getAllBookingDetailsEventDateByZoneWithStatus(@Param("fromDate") String fromDate, @Param("toDate") String toDate, @Param("zone") String zone, @Param("bookingStatus") String bookingStatus); - - @Query(value = "SELECT bd.*, hd.hall_name, us.name, us.usertype " + - "FROM booking_details bd " + - "JOIN hall_details hd ON bd.hall_details_hall_id = hd.hall_id " + - "JOIN users us ON bd.users_user_id = us.user_id " + - "JOIN settlement st ON bd.booking_id=st.booking_details_booking_id " + - "WHERE DATE(bd.booking_date) >= :fromDate " + - "AND DATE(bd.booking_date) <= :toDate " + - "AND hd.zone = :zone ", nativeQuery = true) - List getAllBookingsettlementDetailsByZoneByBookingDate(@Param("fromDate") String fromDate, @Param("toDate") String toDate, @Param("zone") String zone); - - @Query(value = "SELECT bd.*, hd.hall_name, us.name, us.usertype " + - "FROM booking_details bd " + - "JOIN hall_details hd ON bd.hall_details_hall_id = hd.hall_id " + - "JOIN users us ON bd.users_user_id = us.user_id " + - "JOIN settlement st ON bd.booking_id=st.booking_details_booking_id " + - "WHERE DATE(bd.start_date) >= :fromDate " + - "AND DATE(bd.end_date) <= :toDate " + - "AND hd.zone = :zone ", nativeQuery = true) - List getAllBookingsettlementDetailsByZoneByEventDate(@Param("fromDate") String fromDate, @Param("toDate") String toDate, @Param("zone") String zone); - - @Query(value = "SELECT bd.*, hd.hall_name, us.name, us.usertype " + - "FROM booking_details bd " + - "JOIN hall_details hd ON bd.hall_details_hall_id = hd.hall_id " + - "JOIN users us ON bd.users_user_id = us.user_id " + - "JOIN settlement st ON bd.booking_id=st.booking_details_booking_id " + - "WHERE DATE(bd.booking_date) >= :fromDate " + - "AND DATE(bd.booking_date) <= :toDate " + - "AND hd.zone = :zone " + - "AND (:refundStatus IS NULL OR bd.refund_status = :refundStatus) ", nativeQuery = true) - List getAllBookingsettlementDetailsByZoneByBookingDateWithStatus(@Param("fromDate") String fromDate, @Param("toDate") String toDate, @Param("zone") String zone, @Param("refundStatus") String refundStatus); - - @Query(value = "SELECT bd.*, hd.hall_name, us.name, us.usertype " + - "FROM booking_details bd " + - "JOIN hall_details hd ON bd.hall_details_hall_id = hd.hall_id " + - "JOIN users us ON bd.users_user_id = us.user_id " + - "JOIN settlement st ON bd.booking_id=st.booking_details_booking_id " + - "WHERE DATE(bd.start_date) >= :fromDate " + - "AND DATE(bd.end_date) <= :toDate " + - "AND hd.zone = :zone " + - "AND (:refundStatus IS NULL OR bd.refund_status = :refundStatus) ", nativeQuery = true) - List getAllBookingsettlementDetailsByZoneByEventDateWithStatus(@Param("fromDate") String fromDate, @Param("toDate") String toDate, @Param("zone") String zone, @Param("refundStatus") String refundStatus); - - @Query(value = "SELECT bd.booking_id, bd.booking_date, hd.hall_name, us.name, us.usertype, p.transaction_id, p.payment_type, p.amount_received, bd.reason, bd.start_date, bd.end_date, p.payment_status " + - "FROM booking_details bd " + - "JOIN hall_details hd ON bd.hall_details_hall_id = hd.hall_id " + - "JOIN users us ON bd.users_user_id = us.user_id " + - "JOIN payments p ON bd.booking_id = p.booking_details_booking_id " + - "WHERE DATE(bd.booking_date) >= :fromDate " + - "AND DATE(bd.booking_date) <= :toDate " + - "AND hd.zone = :zone " + - "AND p.payment_status='Success' ", nativeQuery = true) - List getAllPaymentsDetailsByZone(@Param("fromDate") String fromDate, @Param("toDate") String toDate, @Param("zone") String zone); - - @Query(value = "SELECT " + - "h.hall_name AS HallName, " + - "h.zone AS Zone, " + - "h.division AS Division, " + - "CONCAT(h.door_no,',',h.street, ', ', h.area, ', ', h.city, ', ', h.pin_code) AS Address, " + - "COUNT(*) AS HallTotalBookings, " + - "SUM(p.amount_received) AS AmountReceived, " + - "COALESCE(SUM(r.amount_refunded), 0) AS AmountRefund, " + //Use COALESCE to handle NULL values - "(SUM(p.amount_received) - COALESCE(SUM(r.amount_refunded), 0)) AS Difference " + // Calculate the difference - "FROM " + - "booking_details bd " + - "JOIN " + - "hall_details h ON bd.hall_details_hall_id = h.hall_id " + - "JOIN " + - "payments p ON bd.booking_id = p.booking_details_booking_id " + - "LEFT JOIN " + - "refund_transaction r ON p.transaction_id = r.transaction_id " + - "WHERE DATE(bd.booking_date) >= :fromDate " + - "AND DATE(bd.booking_date) <= :toDate " + - "AND h.zone = :zone " + - "GROUP BY " + - "h.hall_id", nativeQuery = true) - List getBookingHallDetailsReportByZoneByBookingDate(@Param("fromDate") String fromDate, @Param("toDate") String toDate, @Param("zone") String zone); - - - @Query(value = "SELECT " + - "h.hall_name AS HallName, " + - "h.zone AS Zone, " + - "h.division AS Division, " + - "CONCAT(h.door_no,',',h.street, ', ', h.area, ', ', h.city, ', ', h.pin_code) AS Address, " + - "COUNT(*) AS HallTotalBookings, " + - "SUM(p.amount_received) AS AmountReceived, " + - "COALESCE(SUM(r.amount_refunded), 0) AS AmountRefund, " + //Use COALESCE to handle NULL values - "(SUM(p.amount_received) - COALESCE(SUM(r.amount_refunded), 0)) AS Difference " + // Calculate the difference - "FROM " + - "booking_details bd " + - "JOIN " + - "hall_details h ON bd.hall_details_hall_id = h.hall_id " + - "JOIN " + - "payments p ON bd.booking_id = p.booking_details_booking_id " + - "LEFT JOIN " + - "refund_transaction r ON p.transaction_id = r.transaction_id " + - "WHERE DATE(bd.start_date) >= :fromDate " + - "AND DATE(bd.end_date) <= :toDate " + - "AND h.zone = :zone " + - "GROUP BY " + - "h.hall_id", nativeQuery = true) - List getBookingHallDetailsReportByZoneByEventDate(@Param("fromDate") String fromDate, @Param("toDate") String toDate, @Param("zone") String zone); - - @Query(value = "SELECT " + - "h.hall_name AS HallName, " + - "h.zone AS Zone, " + - "h.division AS Division, " + - "CONCAT(h.door_no,',',h.street, ', ', h.area, ', ', h.city, ', ', h.pin_code) AS Address, " + - "COUNT(*) AS HallTotalBookings, " + - "SUM(p.amount_received) AS AmountReceived, " + - "COALESCE(SUM(r.amount_refunded), 0) AS AmountRefund, " + //Use COALESCE to handle NULL values - "(SUM(p.amount_received) - COALESCE(SUM(r.amount_refunded), 0)) AS Difference " + // Calculate the difference - "FROM " + - "booking_details bd " + - "JOIN " + - "hall_details h ON bd.hall_details_hall_id = h.hall_id " + - "JOIN " + - "payments p ON bd.booking_id = p.booking_details_booking_id " + - "LEFT JOIN " + - "refund_transaction r ON p.transaction_id = r.transaction_id " + - "WHERE DATE(bd.booking_date) >= :fromDate " + - "AND DATE(bd.booking_date) <= :toDate " + - "AND h.zone = :zone " + - "AND (:hall_id = '0' OR h.hall_id = :hall_id) " + - "GROUP BY " + - "h.hall_id", nativeQuery = true) - List getBookingHallDetailsReportByZoneByBookingDateHallname(@Param("fromDate") String fromDate, @Param("toDate") String toDate, @Param("zone") String zone, @Param("hall_id") Integer hallId); - - - @Query(value = "SELECT " + - "h.hall_name AS HallName, " + - "h.zone AS Zone, " + - "h.division AS Division, " + - "CONCAT(h.door_no,',',h.street, ', ', h.area, ', ', h.city, ', ', h.pin_code) AS Address, " + - "COUNT(*) AS HallTotalBookings, " + - "SUM(p.amount_received) AS AmountReceived, " + - "COALESCE(SUM(r.amount_refunded), 0) AS AmountRefund, " + //Use COALESCE to handle NULL values - "(SUM(p.amount_received) - COALESCE(SUM(r.amount_refunded), 0)) AS Difference " + // Calculate the difference - "FROM " + - "booking_details bd " + - "JOIN " + - "hall_details h ON bd.hall_details_hall_id = h.hall_id " + - "JOIN " + - "payments p ON bd.booking_id = p.booking_details_booking_id " + - "LEFT JOIN " + - "refund_transaction r ON p.transaction_id = r.transaction_id " + - "WHERE DATE(bd.start_date) >= :fromDate " + - "AND DATE(bd.end_date) <= :toDate " + - "AND h.zone = :zone " + - "AND (:hall_id = '0' OR h.hall_id = :hall_id) " + - "GROUP BY " + - "h.hall_id", nativeQuery = true) - List getBookingHallDetailsReportByZoneByEventDateHallname(@Param("fromDate") String fromDate, @Param("toDate") String toDate, @Param("zone") String zone, @Param("hall_id") Integer hallId); - - // Present Events: Fetch today's events - @Query(value = "SELECT * FROM booking_details WHERE DATE(start_date) = CURRENT_DATE() AND booking_status='APPROVED'", nativeQuery = true) - List findPresentBookingList(); - - // Past Events: Fetch events - @Query(value = "SELECT * FROM booking_details " + - "WHERE DATE(start_date) < CURRENT_DATE() " + - "AND booking_status='APPROVED'", nativeQuery = true) - List findPastEventsList(); - - // Future Events: Fetch events for the next two days (tomorrow and the day after) - @Query(value = "SELECT * FROM booking_details " + - "WHERE start_date BETWEEN CURDATE() + INTERVAL 1 DAY AND CURDATE() + INTERVAL 2 DAY " + - "AND booking_status = 'APPROVED'", nativeQuery = true) - List findFutureEventsList(); - - //admin reports - @Query(value = "SELECT bd.booking_id, bd.booking_date, hd.hall_name, us.name, us.mobile_no, " + - "CONCAT(us.doorno, ', ', us.street, ', ', us.area, ', ', us.location, ', ', us.pin_code) AS address, " + - "us.usertype, bd.reason, bd.start_date, bd.end_date, " + - "bd.deposit_amount, bd.hall_amount, bd.gst, bd.amount_received, bd.booking_status " + - "FROM booking_details bd " + - "JOIN hall_details hd ON bd.hall_details_hall_id = hd.hall_id " + - "JOIN users us ON bd.users_user_id = us.user_id " + - "WHERE DATE(bd.booking_date) >= :fromDate " + - "AND DATE(bd.booking_date) <= :toDate " + - "AND (:zone IS NULL OR :zone = 'ALL' OR hd.zone = :zone) " + - "AND (:division IS NULL OR :division = 'ALL' OR hd.division = :division) " + - "AND (:hallid IS NULL OR :hallid = '1000' OR hd.hall_id = :hallid) " + - "AND bd.booking_status!='PENDING' order by bd.booking_id asc", nativeQuery = true) - List getBookingDetailsByBookingDate(@Param("fromDate") String fromDate, - @Param("toDate") String toDate, @Param("zone") String zone, @Param("division") String division, @Param("hallid") Integer hallid); - - @Query(value = "SELECT bd.booking_id, bd.booking_date, hd.hall_name, us.name, us.mobile_no, " + - "CONCAT(us.doorno, ', ', us.street, ', ', us.area, ', ', us.location, ', ', us.pin_code) AS address, " + - "us.usertype, bd.reason, bd.start_date, bd.end_date, " + - "bd.deposit_amount, bd.hall_amount, bd.gst, bd.amount_received, bd.booking_status " + - "FROM booking_details bd " + - "JOIN hall_details hd ON bd.hall_details_hall_id = hd.hall_id " + - "JOIN users us ON bd.users_user_id = us.user_id " + - "WHERE DATE(bd.booking_date) >= :fromDate " + - "AND DATE(bd.booking_date) <= :toDate " + - "AND (:zone IS NULL OR :zone = 'ALL' OR hd.zone = :zone) " + - "AND (:division IS NULL OR :division = 'ALL' OR hd.division = :division) " + - "AND (:hallid IS NULL OR :hallid = '1000' OR hd.hall_id = :hallid) " + - "AND bd.booking_status = :bookingStatus order by bd.booking_id asc", nativeQuery = true) - List getBookingDetailsByBookingDateWithStatus(@Param("fromDate") String fromDate, - @Param("toDate") String toDate, - @Param("bookingStatus") String bookingStatus, @Param("zone") String zone, @Param("division") String division, @Param("hallid") Integer hallid); - - - @Query(value = "SELECT bd.booking_id, bd.booking_date, hd.hall_name, us.name, us.mobile_no, " + - "CONCAT(us.doorno, ', ', us.street, ', ', us.area, ', ', us.location, ', ', us.pin_code) AS address, " + - "us.usertype, bd.reason, bd.start_date, bd.end_date, " + - "bd.deposit_amount, bd.hall_amount, bd.gst, bd.amount_received, bd.booking_status " + - "FROM booking_details bd " + - "JOIN hall_details hd ON bd.hall_details_hall_id = hd.hall_id " + - "JOIN users us ON bd.users_user_id = us.user_id " + - "WHERE DATE(bd.start_date) >= :fromDate " + - "AND DATE(bd.end_date) <= :toDate " + - "AND (:zone IS NULL OR :zone = 'ALL' OR hd.zone = :zone) " + - "AND (:division IS NULL OR :division = 'ALL' OR hd.division = :division) " + - "AND (:hallid IS NULL OR :hallid = '1000' OR hd.hall_id = :hallid) " + - "AND bd.booking_status!='PENDING' order by bd.booking_id asc", nativeQuery = true) - List getBookingDetailsByEventDate(@Param("fromDate") String fromDate, - @Param("toDate") String toDate, @Param("zone") String zone, @Param("division") String division, @Param("hallid") Integer hallid); - - @Query(value = "SELECT bd.booking_id, bd.booking_date, hd.hall_name, us.name, us.mobile_no, " + - "CONCAT(us.doorno, ', ', us.street, ', ', us.area, ', ', us.location, ', ', us.pin_code) AS address, " + - "us.usertype, bd.reason, bd.start_date, bd.end_date, " + - "bd.deposit_amount, bd.hall_amount, bd.gst, bd.amount_received, bd.booking_status " + - "FROM booking_details bd " + - "JOIN hall_details hd ON bd.hall_details_hall_id = hd.hall_id " + - "JOIN users us ON bd.users_user_id = us.user_id " + - "WHERE DATE(bd.start_date) >= :fromDate " + - "AND DATE(bd.end_date) <= :toDate " + - "AND (:zone IS NULL OR :zone = 'ALL' OR hd.zone = :zone) " + - "AND (:division IS NULL OR :division = 'ALL' OR hd.division = :division) " + - "AND (:hallid IS NULL OR :hallid = '1000' OR hd.hall_id = :hallid) " + - "AND bd.booking_status = :bookingStatus order by bd.booking_id asc", nativeQuery = true) - List getBookingDetailsByEventDateWithStatus(@Param("fromDate") String fromDate, - @Param("toDate") String toDate, - @Param("bookingStatus") String bookingStatus, @Param("zone") String zone, @Param("division") String division, @Param("hallid") Integer hallid); - - @Query(value = "SELECT bd.booking_id, bd.booking_date, hd.hall_name, us.name, us.usertype, p.transaction_id, p.payment_type, bd.deposit_amount, bd.hall_amount, bd.gst, p.amount_received, bd.reason, bd.start_date, bd.end_date, p.payment_status " + - "FROM booking_details bd " + - "JOIN hall_details hd ON bd.hall_details_hall_id = hd.hall_id " + - "JOIN users us ON bd.users_user_id = us.user_id " + - "JOIN payments p ON bd.booking_id = p.booking_details_booking_id " + - "WHERE DATE(p.cdate) >= :fromDate " + - "AND DATE(p.cdate) <= :toDate " + - "AND (:paymentStatus IS NULL OR p.payment_status = :paymentStatus)" + - "AND (:zone IS NULL OR :zone = 'ALL' OR hd.zone = :zone) " + - "AND (:division IS NULL OR :division = 'ALL' OR hd.division = :division) " + - "AND (:hallid IS NULL OR :hallid = '1000' OR hd.hall_id = :hallid) order by bd.booking_id asc", - nativeQuery = true) - List getAllPaymentsDetails(@Param("fromDate") String fromDate, @Param("toDate") String toDate, @Param("paymentStatus") String paymentStatus, @Param("zone") String zone, @Param("division") String division, @Param("hallid") Integer hallid); - - @Query(value = "SELECT bd.booking_id, bd.booking_date, hd.hall_name, us.name, us.usertype, p.transaction_id, p.payment_type, bd.deposit_amount, bd.hall_amount, bd.gst, p.amount_received, bd.reason, bd.start_date, bd.end_date, p.payment_status " + - "FROM booking_details bd " + - "JOIN hall_details hd ON bd.hall_details_hall_id = hd.hall_id " + - "JOIN users us ON bd.users_user_id = us.user_id " + - "JOIN extra_payments p ON bd.booking_id = p.booking_details_booking_id " + - "WHERE DATE(p.cdate) >= :fromDate " + - "AND DATE(p.cdate) <= :toDate " + - "AND (:paymentStatus IS NULL OR p.payment_status = :paymentStatus)" + - "AND (:zone IS NULL OR :zone = 'ALL' OR hd.zone = :zone) " + - "AND (:division IS NULL OR :division = 'ALL' OR hd.division = :division) " + - "AND (:hallid IS NULL OR :hallid = '1000' OR hd.hall_id = :hallid) order by bd.booking_id asc ", - nativeQuery = true) - List getAllExtraPaymentsDetails(@Param("fromDate") String fromDate, @Param("toDate") String toDate, @Param("paymentStatus") String paymentStatus, @Param("zone") String zone, @Param("division") String division, @Param("hallid") Integer hallid); - - - @Query(value = "SELECT " + - "h.hall_name AS HallName, " + - "h.hall_Incharge_name AS InchargeName, " + - "h.hall_Incharge_no AS hallInchargeMobno, " + - "CONCAT(h.zone, '/', h.division) AS ZoneDivision, " + // Concatenate zone and division - "COUNT(*) AS HallTotalBookings, " + - "SUM(bd.deposit_amount) AS depositAmount, " + - "SUM(bd.hall_amount) AS hallAmount, " + - "SUM(bd.gst) AS gst, " + - "SUM(p.amount_received) AS AmountReceived, " + - "COALESCE(SUM(r.amount - r.balace_amount), 0) AS AmountRefund, " + - "COALESCE(SUM(CASE WHEN bd.booking_status IN ('COMPLETED', 'CANCELED') THEN r.balace_amount - bd.gst ELSE 0 END), 0) AS NetRevenue ," + - "h.hall_id " + - "FROM " + - "booking_details bd " + - "JOIN " + - "hall_details h ON bd.hall_details_hall_id = h.hall_id " + - "JOIN " + - "payments p ON bd.booking_id = p.booking_details_booking_id " + - "LEFT JOIN refund_response r ON bd.booking_id = r.booking_id " + - "WHERE DATE(bd.booking_date) >= :fromDate " + - "AND DATE(bd.booking_date) <= :toDate " + - "AND (:zone IS NULL OR :zone = 'ALL' OR h.zone = :zone) " + - "AND (:division IS NULL OR :division = 'ALL' OR h.division = :division) " + - "AND (:hallid IS NULL OR :hallid = '1000' OR h.hall_id = :hallid) " + - "GROUP BY " + - "bd.hall_details_hall_id order by COUNT(*) desc", nativeQuery = true) - List getBookingHallDetailsReportByBookingDate(@Param("fromDate") String fromDate, @Param("toDate") String toDate, @Param("zone") String zone, @Param("division") String division, @Param("hallid") Integer hallid); - - - @Query(value = "SELECT " + - "h.hall_name AS HallName, " + - "h.hall_Incharge_name AS InchargeName, " + - "h.hall_Incharge_no AS hallInchargeMobno, " + - "CONCAT(h.zone, '/', h.division) AS ZoneDivision, " + // Concatenate zone and division - "COUNT(*) AS HallTotalBookings, " + - "SUM(bd.deposit_amount) AS depositAmount, " + - "SUM(bd.hall_amount) AS hallAmount, " + - "SUM(bd.gst) AS gst, " + - "SUM(p.amount_received) AS AmountReceived, " + - "COALESCE(SUM(r.amount - r.balace_amount), 0) AS AmountRefund, " + - "COALESCE(SUM(CASE WHEN bd.booking_status IN ('COMPLETED', 'CANCELED') THEN r.balace_amount - bd.gst ELSE 0 END), 0) AS NetRevenue " + - "FROM " + - "booking_details bd " + - "JOIN " + - "hall_details h ON bd.hall_details_hall_id = h.hall_id " + - "JOIN " + - "payments p ON bd.booking_id = p.booking_details_booking_id " + - "LEFT JOIN refund_response r ON bd.booking_id = r.booking_id " + - "WHERE DATE(bd.start_date) >= :fromDate " + - "AND DATE(bd.end_date) <= :toDate " + - "AND (:zone IS NULL OR :zone = 'ALL' OR h.zone = :zone) " + - "AND (:division IS NULL OR :division = 'ALL' OR h.division = :division) " + - "AND (:hallid IS NULL OR :hallid = '1000' OR h.hall_id = :hallid) " + - "GROUP BY " + - "bd.hall_details_hall_id", nativeQuery = true) - List getBookingHallDetailsReportByEventDate(@Param("fromDate") String fromDate, @Param("toDate") String toDate, @Param("zone") String zone, @Param("division") String division, @Param("hallid") Integer hallid); - - - @Query(value = "SELECT bd.*, hd.hall_name, us.name, us.usertype " + - "FROM booking_details bd " + - "JOIN hall_details hd ON bd.hall_details_hall_id = hd.hall_id " + - "JOIN users us ON bd.users_user_id = us.user_id " + - "left JOIN settlement st ON bd.booking_id=st.booking_details_booking_id " + - "WHERE DATE(bd.booking_date) >= :fromDate " + - "AND DATE(bd.booking_date) <= :toDate order by bd.booking_id asc ", nativeQuery = true) - List getAllBookingsettlementDetailsByBookingDate(@Param("fromDate") String fromDate, @Param("toDate") String toDate); - - @Query(value = "SELECT bd.*, hd.hall_name, us.name, us.usertype " + - "FROM booking_details bd " + - "JOIN hall_details hd ON bd.hall_details_hall_id = hd.hall_id " + - "JOIN users us ON bd.users_user_id = us.user_id " + - "left JOIN settlement st ON bd.booking_id=st.booking_details_booking_id " + - "WHERE DATE(bd.booking_date) >= :fromDate " + - "AND DATE(bd.booking_date) <= :toDate " + - "AND (:refundStatus IS NULL OR bd.refund_status = :refundStatus) order by bd.booking_id asc", nativeQuery = true) - List getAllBookingsettlementDetailsByBookingDateWithStatus(@Param("fromDate") String fromDate, @Param("toDate") String toDate, @Param("refundStatus") String refundStatus); - - @Query(value = "SELECT bd.*, hd.hall_name, us.name, us.usertype " + - "FROM booking_details bd " + - "JOIN hall_details hd ON bd.hall_details_hall_id = hd.hall_id " + - "JOIN users us ON bd.users_user_id = us.user_id " + - "left JOIN settlement st ON bd.booking_id=st.booking_details_booking_id " + - "WHERE DATE(bd.start_date) >= :fromDate " + - "AND DATE(bd.end_date) <= :toDate order by bd.booking_id asc", nativeQuery = true) - List getAllBookingsettlementDetailsByEventDate(@Param("fromDate") String fromDate, @Param("toDate") String toDate); - - @Query(value = "SELECT bd.*, hd.hall_name, us.name, us.usertype " + - "FROM booking_details bd " + - "JOIN hall_details hd ON bd.hall_details_hall_id = hd.hall_id " + - "JOIN users us ON bd.users_user_id = us.user_id " + - "left JOIN settlement st ON bd.booking_id=st.booking_details_booking_id " + - "WHERE DATE(bd.start_date) >= :fromDate " + - "AND DATE(bd.end_date) <= :toDate " + - "AND (:refundStatus IS NULL OR bd.refund_status = :refundStatus) order by bd.booking_id asc", nativeQuery = true) - List getAllBookingsettlementDetailsByEventDateWithStatus(@Param("fromDate") String fromDate, @Param("toDate") String toDate, @Param("refundStatus") String refundStatus); - - // In BookingDetailsRepository.java - // In BookingDetailsRepository.java - @Query("SELECT h.zone, COUNT(b) FROM BookingDetails b JOIN b.hallDetails h WHERE b.bookingStatus = 'APPROVED' GROUP BY h.zone") - List countBookingsByZone(); - - @Query("SELECT h.division, COUNT(b) FROM BookingDetails b JOIN b.hallDetails h WHERE b.bookingStatus = 'APPROVED' GROUP BY h.division") - List countBookingsByDivisions(); - - @Query("SELECT b FROM BookingDetails b JOIN b.hallDetails h WHERE h.zone = :zone AND b.bookingStatus = 'APPROVED'") - List findByZone(@Param("zone") String zone); - - //gccapps - List findByBookingStatus(BookingDetails.BookingStatus bookingStatus); - - @Query("SELECT b FROM BookingDetails b JOIN FETCH b.settlement s WHERE b.refundStatus = 'WAITING'") - List findAllWithPendingRefundStatus(); - - @Query("SELECT b FROM BookingDetails b WHERE b.refundStatus = 'WAITING' AND b.bookingStatus = 'CANCELED'") - List findPendingCancelledList(); - - @Query(value = "SELECT * FROM booking_details WHERE refund_status = 'WAITING' AND booking_status IN ('GCC_BLOCKED', 'REJECTED')", nativeQuery = true) - List findPendingRejectedList(); - - @Query(value = "SELECT * FROM booking_details WHERE refund_status = 'COMPLETED' AND booking_status = 'CANCELED'", nativeQuery = true) - List findCompletedCancelledList(); - - @Query(value = "SELECT * FROM booking_details WHERE refund_status = 'COMPLETED' AND booking_status IN ('GCC_BLOCKED', 'REJECTED')", nativeQuery = true) - List findCompletedRejectedList(); - - @Query("SELECT b FROM BookingDetails b JOIN FETCH b.settlement s WHERE b.refundStatus = 'REJECTED'") - List findSettlementRejected(); - - @Query(value = "SELECT * FROM booking_details WHERE DATE(start_date) < CURRENT_DATE() AND booking_status='APPROVED'", nativeQuery = true) - List findPastsEvents(); - - @Query(value = "SELECT * FROM booking_details WHERE DATE(start_date) = CURRENT_DATE() AND booking_status='APPROVED'", nativeQuery = true) - List findPresentsEvents(); - - @Query(value = "SELECT * FROM booking_details WHERE DATE(start_date) BETWEEN CURRENT_DATE() AND DATE_ADD(CURRENT_DATE(), INTERVAL 2 DAY) AND booking_status = 'APPROVED'", nativeQuery = true) - List findFuturesEvents(); - - @Query(value = "SELECT * FROM booking_details WHERE DATE(start_date) < CURRENT_DATE() AND booking_status='APPROVED'", nativeQuery = true) - public List getSettlementApprovedList(); - - @Query(value = "SELECT * FROM booking_details WHERE DATE(start_date) <= CURRENT_DATE() AND booking_status='APPROVED'", nativeQuery = true) - public List getSettlementsList(); - - @Query("SELECT b FROM BookingDetails b WHERE b.refundStatus = 'FAILURE' AND b.bookingStatus = 'APPROVED' AND b.hallDetails.zone = :zone") - List findSettlementRefundFailedByZone(String zone); - - @Query("SELECT b FROM BookingDetails b WHERE b.refundStatus = 'FAILURE' AND b.bookingStatus = 'CANCELED' AND b.hallDetails.zone = :zone") - List findRefundFaileCancelledListByZone(String zone); - - @Query("SELECT b FROM BookingDetails b WHERE b.refundStatus = 'FAILURE' AND b.bookingStatus IN ('REJECTED','GCC_BLOCKED') AND b.hallDetails.zone = :zone") - List findRefundFaileRejectedListByZone(String zone); - - @Query("SELECT b FROM BookingDetails b WHERE b.bookingStatus = 'COMPLETED' AND b.refundStatus IN ('COMPLETED','CLOSED') AND b.hallDetails.zone = :zone") - List findSettlementCompletedListbyzone(String zone); - - @Query("SELECT b FROM BookingDetails b WHERE b.bookingStatus = 'CANCELED' AND b.refundStatus = 'COMPLETED' AND b.hallDetails.zone = :zone") - List findCancelledCompletedListbyzone(String zone); - - @Query("SELECT b FROM BookingDetails b WHERE b.bookingStatus IN ('REJECTED','GCC_BLOCKED') AND b.refundStatus = 'COMPLETED' AND b.hallDetails.zone = :zone") - List findRejectedSettlementCompletedListbyzone(String zone); - - @Query("SELECT b FROM BookingDetails b JOIN FETCH b.settlement s WHERE b.refundStatus = 'WAITING'") - List findAllSettlementPending(); - - @Query("SELECT b FROM BookingDetails b WHERE b.refundStatus = 'WAITING' AND b.bookingStatus = 'CANCELED'") - List findAllSettlementCancelledList(); - - @Query("SELECT b FROM BookingDetails b WHERE b.refundStatus = 'WAITING' AND b.bookingStatus IN ('REJECTED','GCC_BLOCKED')") - List findAllSettlementRejectedList(); - - @Query("SELECT b FROM BookingDetails b WHERE b.refundStatus = 'FAILURE' AND b.bookingStatus = 'APPROVED'") - List findAllSettlementRefundFailed(); - - @Query("SELECT b FROM BookingDetails b WHERE b.refundStatus = 'FAILURE' AND b.bookingStatus = 'CANCELED'") - List findAllRefundFaileCancelledList(); - - @Query("SELECT b FROM BookingDetails b WHERE b.refundStatus = 'FAILURE' AND b.bookingStatus IN ('REJECTED','GCC_BLOCKED')") - List findAllRefundFaileRejectedList(); - - - @Query(value = "SELECT * FROM booking_details WHERE booking_date = :bookingDate AND hall_details_hall_id = :hallId", nativeQuery = true) - List findByBookingDateAndHallId(@Param("bookingDate") LocalDate bookingDate, - @Param("hallId") Long hallId); - - @Query(value = "SELECT * FROM booking_details where booking_status='WAITING_FOR_NOC' order by booking_id", nativeQuery = true) - List getAllwaitingNOC(); - - - @Query(value = - "SELECT bd.counter_id, COUNT(*) AS total_count " + - "FROM booking_details bd " + - "WHERE DATE(bd.booking_date) BETWEEN :fromDate AND :toDate " + - "AND bd.booking_status <> 'PENDING' " + - "AND bd.counter_id IS NOT NULL " + - "GROUP BY bd.counter_id", - nativeQuery = true) - List getCounterWiseBookingCount( - @Param("fromDate") String fromDate, - @Param("toDate") String toDate - ); - - /*@Query(value = "SELECT bd.counter_id, h.zone, h. division, h.hall_name, COUNT(*) as total_bookings " + - "FROM booking_details bd " + - "JOIN hall_details h ON h.hall_id = bd.hall_details_hall_id " + - "WHERE DATE(bd.booking_date) BETWEEN :fromDate AND :toDate " + - "AND bd.counter_id IS NOT NULL " + - "GROUP BY bd.counter_id,h.zone, h. division, h.hall_name", nativeQuery = true) - List getHallWiseBookingDetails(@Param("fromDate") String fromDate, @Param("toDate") String toDate); - - @Query(value = "SELECT bd.booking_id,h.hall_name, bd.booking_date, bd.start_date, bd.end_date," + - "bd.starting_slot,bd.ending_slot,bd.no_of_days,bd.reason,bd.amount_received, " + - "bd.hall_amount,bd.deposit_amount,bd.gst, " + - "bd.booking_status,bd.booking_type " + - "FROM booking_details bd " + - "JOIN hall_details h ON h.hall_id = bd.hall_details_hall_id " + - "WHERE DATE(bd.booking_date) BETWEEN :fromDate AND :toDate " + - "AND bd.counter_id IS NOT NULL", nativeQuery = true) - List getBookingDetailsForAllHalls(@Param("fromDate") String fromDate, @Param("toDate") String toDate);*/ - - @Query(value = - "SELECT bd.counter_id, h.zone, h.division, h.hall_name, COUNT(*) AS total_bookings " + - "FROM booking_details bd " + - "JOIN hall_details h ON h.hall_id = bd.hall_details_hall_id " + - "WHERE DATE(bd.booking_date) BETWEEN :fromDate AND :toDate " + - "AND bd.counter_id IS NOT NULL " + - "AND bd.booking_status <> 'PENDING' " + - "AND (:counterId IS NULL OR bd.counter_id = :counterId) " + - "GROUP BY bd.counter_id, h.zone, h.division, h.hall_name", - nativeQuery = true) - List getHallWiseBookingDetails( - @Param("fromDate") String fromDate, - @Param("toDate") String toDate, - @Param("counterId") String counterId - ); - - @Query(value = " SELECT bd.booking_id, h.hall_name, bd.booking_date, bd.start_date, " + - "bd.end_date, bd.starting_slot, bd.ending_slot, bd.no_of_days, bd.reason, " + - "bd.amount_received, bd.hall_amount, bd.deposit_amount, bd.gst, bd.booking_status, " + - "bd.booking_type FROM booking_details bd " + - "JOIN hall_details h ON h.hall_id = bd.hall_details_hall_id " + - "WHERE DATE(bd.booking_date) BETWEEN :fromDate AND :toDate " + - "AND bd.counter_id IS NOT NULL " + - "AND ( :counterId IS NULL OR bd.counter_id = :counterId ) " + - "AND ( :hallid IS NULL OR bd.hall_details_hall_id = :hallid ) " + - "AND bd.booking_status <> 'PENDING' ", nativeQuery = true) - List getBookingDetailsForAllHalls( - @Param("fromDate") String fromDate, - @Param("toDate") String toDate, - @Param("counterId") String counterId, - @Param("hallid") Integer hallid - ); - - @Query(value = " SELECT bd.booking_id, h.hall_name, bd.booking_date, bd.start_date, " + - "bd.end_date, bd.starting_slot, bd.ending_slot, bd.no_of_days, bd.reason, " + - "bd.amount_received, bd.hall_amount, bd.deposit_amount, bd.gst, bd.booking_status, " + - "bd.booking_type, bd.counter_id FROM booking_details bd " + - "JOIN hall_details h ON h.hall_id = bd.hall_details_hall_id " + - "WHERE DATE(bd.booking_date) BETWEEN :fromDate AND :toDate " + - "AND bd.counter_id IS NOT NULL " + - "AND bd.booking_status <> 'PENDING' GROUP BY bd.counter_id, bd.booking_id ", nativeQuery = true) - List getCounterWiseBookingDetails(String fromDate, String toDate); - - @Query(value = " SELECT hd.zone, " + - " COUNT(DISTINCT hd.hall_id) AS hall_count, " + - " COUNT(bd.booking_id) AS total_count, " + - " SUM(CASE " + - " WHEN bd.booking_type = 'ONLINE' AND bd.counter_id IS NULL THEN 1 " + - " ELSE 0 " + - " END) AS online_count, " + - " SUM(CASE " + - " WHEN bd.booking_type = 'ONLINE' AND bd.counter_id IS NOT NULL THEN 1 " + - " ELSE 0 " + - " END) AS counter_count " + - "FROM hall_details hd " + - "LEFT JOIN booking_details bd " + - " ON hd.hall_id = bd.hall_details_hall_id " + - " AND DATE(bd.booking_date) BETWEEN :fromDate AND :toDate " + - " AND bd.booking_status NOT IN ('PENDING','GCC_UNBLOCKED','REFUNDED','GCC_BLOCKED') " + - " AND bd.booking_type IS NOT NULL " + - "GROUP BY hd.zone " + - "ORDER BY hd.zone", nativeQuery = true) - List getZoneWiseBookingList(String fromDate, String toDate); - - - @Query(value = " select hd.hall_id, hd.hall_name, " + - "COUNT(bd.booking_id) AS total_count, " + - " SUM(CASE " + - " WHEN bd.booking_type = 'ONLINE' AND bd.counter_id IS NULL THEN 1 " + - " ELSE 0 " + - " END) AS online_count, " + - " SUM(CASE " + - " WHEN bd.booking_type = 'ONLINE' AND bd.counter_id IS NOT NULL THEN 1 " + - " ELSE 0 " + - " END) AS counter_count, hd.zone from hall_details hd " + - "left join booking_details bd on hd.hall_id = bd.hall_details_hall_id " + - "where DATE(bd.booking_date) BETWEEN :fromDate AND :toDate and " + - "bd.booking_status not in ('PENDING','GCC_UNBLOCKED','REFUNDED','GCC_BLOCKED') and bd.booking_type is not null " + - "group by hd.hall_name, hd.hall_id ", nativeQuery = true) - List getHallWiseBookingList(String fromDate, String toDate); - - @Query(value = " SELECT " + - " bd.counter_id, bd.hall_details_hall_id, " + - " COUNT(bd.booking_id) AS booking_count " + - "FROM booking_details bd " + - "WHERE DATE(bd.booking_date) BETWEEN :fromDate AND :toDate " + - " AND bd.booking_status NOT IN ('PENDING','GCC_UNBLOCKED','REFUNDED','GCC_BLOCKED') " + - " AND bd.booking_type IS NOT NULL " + - " AND bd.counter_id IS NOT NULL " + - "GROUP BY bd.counter_id, bd.hall_details_hall_id " , nativeQuery = true) - List getCounterWiseBookingList( String fromDate, String toDate); + "SELECT 'past_future' AS category, NULL AS `key`, NULL AS totalCount, NULL AS main_total_amount, NULL AS main_refunded_amount, NULL AS main_net_amount, " + + + "NULL AS main_gst_amount," + + "COALESCE(SUM(PAST_Booking), 0) AS PAST_Events, " + + "COALESCE(SUM(FUTURE_Booking), 0) AS FUTURE_Events " + + "FROM ( " + + "SELECT " + + "CASE WHEN DATE(b.start_date) < CURRENT_DATE() THEN 1 ELSE 0 END AS PAST_Booking, " + + "CASE WHEN DATE(b.start_date) BETWEEN CURRENT_DATE() AND DATE_ADD(CURRENT_DATE(), INTERVAL 3 MONTH) THEN 1 ELSE 0 END AS FUTURE_Booking " + + + "FROM booking_details b " + + "JOIN hall_details h ON b.hall_details_hall_id = h.hall_id " + + "LEFT JOIN users u ON b.users_user_id = u.user_id " + + "WHERE " + + " b.booking_status!='PENDING'" + + "AND (b.start_date >= CASE WHEN :fromDate IS NOT NULL THEN :fromDate ELSE (SELECT MIN(start_date) FROM booking_details) END) AND " + + + "(b.start_date <= CASE WHEN :toDate IS NOT NULL THEN :toDate ELSE (SELECT MAX(end_date) FROM booking_details) END) AND " + + + "(:zone IS NULL OR :zone = 'ALL' OR h.zone = :zone) AND " + + "(:division IS NULL OR :division = 'ALL' OR h.division = :division) AND " + + "(:hall_id IS NULL OR :hall_id = '1000' OR h.hall_id = :hall_id) AND " + + "(:userType IS NULL OR :userType = 'ALL' OR u.usertype = :userType) " + + ") AS combined" + + ) + List> getBookingStatistics( + @Param("fromDate") LocalDate fromDate, + @Param("toDate") LocalDate toDate, + @Param("zone") String zone, + @Param("division") String division, + @Param("hall_id") Integer hallid, + @Param("userType") String userType); + + @Query(value = "SELECT \r" + + " b.booking_date as booking_date,\r" + + " u.name as name,\r" + + " u.usertype as usertype,\r" + + " b.reason as reason,\r" + + " b.start_date as start_date,\r" + + " b.end_date as end_date,\r" + + " b.no_of_days as no_of_days,\r" + + " b.booking_status as booking_status,\r" + + " b.amount_received as amount_received,\r" + + " COALESCE(rt.amount_refunded, 0) as amount_refunded,\r" + + " COALESCE(r.balace_amount, 0) as balance_amount\r" + + "FROM booking_details b\r" + + "JOIN hall_details h ON b.hall_details_hall_id = h.hall_id \r" + + "LEFT JOIN users u ON b.users_user_id = u.user_id\r" + + "LEFT JOIN refund_response r ON b.booking_id = r.booking_id\r" + + "LEFT JOIN refund_transaction rt ON b.booking_id = rt.booking_details_booking_id\r" + + "WHERE h.hall_id = :hallId AND b.booking_status != 'PENDING' ", nativeQuery = true) + List> getBookingDetailsByHallId(@Param("hallId") int hallId); + + // officer Dashboard + @Query(nativeQuery = true, value = "SELECT 'main' AS category, NULL AS `key` , " + + "COUNT(DISTINCT b.booking_id) AS totalCount," + + "SUM(b.amount_received) AS main_total_amount, " + + "COALESCE(SUM(r.amount-r.balace_amount),0) AS main_refunded_amount, " + + "COALESCE(SUM(CASE WHEN b.booking_status IN ('COMPLETED', 'CANCELED') THEN r.balace_amount ELSE 0 END), 0) AS main_net_amount, NULL AS PAST_Events, NULL AS FUTURE_Events " + + + "FROM booking_details b " + + "JOIN hall_details h ON h.hall_id = b.hall_details_hall_id " + + "LEFT JOIN refund_response r ON b.booking_id = r.booking_id " + + "LEFT JOIN users u ON b.users_user_id = u.user_id " + + "WHERE (b.start_date >= CASE WHEN :fromDate IS NOT NULL THEN :fromDate ELSE (SELECT MIN(start_date) FROM booking_details) END) " + + + "AND (b.start_date <= CASE WHEN :toDate IS NOT NULL THEN :toDate ELSE (SELECT MAX(end_date) FROM booking_details) END) " + + + "AND (:zone IS NULL OR :zone = 'ALL' OR h.zone = :zone) " + + "AND (:division IS NULL OR :division = 'ALL' OR h.division = :division) " + + "AND (:hall_id IS NULL OR :hall_id = '1000' OR h.hall_id = :hall_id) " + + "AND (:userType IS NULL OR :userType = 'ALL' OR u.usertype = :userType) " + + "AND b.booking_status!='PENDING'" + + "UNION ALL " + + + "SELECT 'bookingStatus' AS category, b.booking_status AS `key`, COUNT(*) AS totalCount, NULL AS main_total_amount, NULL AS main_refunded_amount, NULL AS main_net_amount, NULL AS PAST_Events, NULL AS FUTURE_Events " + + + "FROM booking_details b " + + "JOIN hall_details h ON b.hall_details_hall_id = h.hall_id " + + "LEFT JOIN users u ON b.users_user_id = u.user_id " + + "WHERE (b.start_date >= CASE WHEN :fromDate IS NOT NULL THEN :fromDate ELSE (SELECT MIN(start_date) FROM booking_details) END) " + + + "AND (b.start_date <= CASE WHEN :toDate IS NOT NULL THEN :toDate ELSE (SELECT MAX(end_date) FROM booking_details) END) " + + + "AND (:zone IS NULL OR :zone = 'ALL' OR h.zone = :zone) " + + "AND (:division IS NULL OR :division = 'ALL' OR h.division = :division) " + + "AND (:hall_id IS NULL OR :hall_id = '1000' OR h.hall_id = :hall_id) " + + "AND (:userType IS NULL OR :userType = 'ALL' OR u.usertype = :userType) " + + "AND b.booking_status != 'PENDING'" + + "GROUP BY b.booking_status " + + "UNION ALL " + + + "SELECT 'refundStatus' AS category, b.refund_status AS `key`, COUNT(*) AS totalCount, NULL AS main_total_amount, NULL AS main_refunded_amount, NULL AS main_net_amount, NULL AS PAST_Events, NULL AS FUTURE_Events " + + + "FROM booking_details b " + + "JOIN hall_details h ON b.hall_details_hall_id = h.hall_id " + + "LEFT JOIN users u ON b.users_user_id = u.user_id " + + "WHERE (b.start_date >= CASE WHEN :fromDate IS NOT NULL THEN :fromDate ELSE (SELECT MIN(start_date) FROM booking_details) END) " + + + "AND (b.start_date <= CASE WHEN :toDate IS NOT NULL THEN :toDate ELSE (SELECT MAX(end_date) FROM booking_details) END) " + + + "AND (:zone IS NULL OR :zone = 'ALL' OR h.zone = :zone) " + + "AND (:division IS NULL OR :division = 'ALL' OR h.division = :division) " + + "AND (:hall_id IS NULL OR :hall_id = '1000' OR h.hall_id = :hall_id) " + + "AND (:userType IS NULL OR :userType = 'ALL' OR u.usertype = :userType) " + + "AND b.booking_status != 'PENDING'" + + "GROUP BY b.refund_status " + + "UNION ALL " + + + "SELECT 'reason' AS category, b.reason AS `key`, COUNT(*) AS totalCount, NULL AS main_total_amount, NULL AS main_net_amount, NULL AS main_refunded_amount, NULL AS PAST_Events, NULL AS FUTURE_Events " + + + "FROM booking_details b " + + "JOIN hall_details h ON b.hall_details_hall_id = h.hall_id " + + "LEFT JOIN users u ON b.users_user_id = u.user_id " + + "WHERE (b.start_date >= CASE WHEN :fromDate IS NOT NULL THEN :fromDate ELSE (SELECT MIN(start_date) FROM booking_details) END) " + + + "AND (b.start_date <= CASE WHEN :toDate IS NOT NULL THEN :toDate ELSE (SELECT MAX(end_date) FROM booking_details) END) " + + + "AND (:zone IS NULL OR :zone = 'ALL' OR h.zone = :zone) " + + "AND (:division IS NULL OR :division = 'ALL' OR h.division = :division) " + + "AND (:hall_id IS NULL OR :hall_id = '1000' OR h.hall_id = :hall_id) " + + "AND (:userType IS NULL OR :userType = 'ALL' OR u.usertype = :userType) " + + "AND b.booking_status != 'PENDING'" + + "GROUP BY b.reason " + + "UNION ALL " + + + "SELECT 'zonewise' AS category, h.zone AS `key`, SUM(CASE WHEN b.hall_details_hall_id IS NOT NULL AND b.booking_status != 'PENDING' THEN 1 ELSE 0 END) AS totalCount, " + + + "NULL AS main_total_amount, NULL AS main_refunded_amount, NULL AS main_net_amount, NULL AS PAST_Events, NULL AS FUTURE_Events " + + + "FROM hall_details h " + + "LEFT JOIN booking_details b ON b.hall_details_hall_id = h.hall_id " + + "LEFT JOIN users u ON b.users_user_id = u.user_id " + + "WHERE (b.start_date IS NULL OR b.start_date BETWEEN COALESCE(:fromDate, (SELECT MIN(start_date) FROM booking_details)) AND COALESCE(:toDate, (SELECT MAX(end_date) FROM booking_details))) " + + + "AND (:zone IS NULL OR :zone = 'ALL' OR h.zone = :zone) " + + "AND (:division IS NULL OR :division = 'ALL' OR h.division = :division) " + + "AND (:hall_id IS NULL OR :hall_id = '1000' OR h.hall_id = :hall_id) " + + "AND (:userType IS NULL OR :userType = 'ALL' OR u.usertype = :userType) " + + "GROUP BY h.zone " + + "UNION ALL " + + + "SELECT 'paymentStatus' AS category, " + + " p.payment_status AS `key`, " + + " COUNT(*) AS totalCount, " + + " NULL AS main_total_amount, " + + " NULL AS main_refunded_amount, " + + " NULL AS main_net_amount, " + + " NULL AS PAST_Events, " + + " NULL AS FUTURE_Events " + + "FROM payments p " + + "JOIN booking_details b ON p.booking_details_booking_id = b.booking_id " + + "JOIN hall_details h ON b.hall_details_hall_id = h.hall_id " + + "LEFT JOIN users u ON b.users_user_id = u.user_id " + + "WHERE (b.start_date >= CASE WHEN :fromDate IS NOT NULL THEN :fromDate ELSE (SELECT MIN(start_date) FROM booking_details) END) " + + + "AND (b.start_date <= CASE WHEN :toDate IS NOT NULL THEN :toDate ELSE (SELECT MAX(end_date) FROM booking_details) END) " + + + "AND (:zone IS NULL OR :zone = 'ALL' OR h.zone = :zone) " + + "AND (:division IS NULL OR :division = 'ALL' OR h.division = :division) " + + "AND (:hall_id IS NULL OR :hall_id = '1000' OR h.hall_id = :hall_id) " + + "AND (:userType IS NULL OR :userType = 'ALL' OR u.usertype = :userType) " + + "AND b.booking_status!='PENDING'" + + "GROUP BY p.payment_status " + + "UNION ALL " + + + "SELECT 'past_future' AS category, NULL AS `key`, NULL AS totalCount, NULL AS main_total_amount, NULL AS main_refunded_amount, NULL AS main_net_amount, " + + + "COALESCE(SUM(PAST_Booking), 0) AS PAST_Events, " + + "COALESCE(SUM(FUTURE_Booking), 0) AS FUTURE_Events " + + "FROM ( " + + "SELECT " + + "CASE WHEN DATE(b.start_date) < CURRENT_DATE() THEN 1 ELSE 0 END AS PAST_Booking, " + + "CASE WHEN DATE(b.start_date) BETWEEN CURRENT_DATE() AND DATE_ADD(CURRENT_DATE(), INTERVAL 3 MONTH) THEN 1 ELSE 0 END AS FUTURE_Booking " + + + "FROM booking_details b " + + "JOIN hall_details h ON b.hall_details_hall_id = h.hall_id " + + "LEFT JOIN users u ON b.users_user_id = u.user_id " + + "WHERE " + + " b.booking_status!='PENDING'" + + "AND (b.start_date >= CASE WHEN :fromDate IS NOT NULL THEN :fromDate ELSE (SELECT MIN(start_date) FROM booking_details) END) AND " + + + "(b.start_date <= CASE WHEN :toDate IS NOT NULL THEN :toDate ELSE (SELECT MAX(end_date) FROM booking_details) END) AND " + + + "(:zone IS NULL OR :zone = 'ALL' OR h.zone = :zone) AND " + + "(:division IS NULL OR :division = 'ALL' OR h.division = :division) AND " + + "(:hall_id IS NULL OR :hall_id = '1000' OR h.hall_id = :hall_id) AND " + + "(:userType IS NULL OR :userType = 'ALL' OR u.usertype = :userType) " + + ") AS combined") + List> getOfficerDashboard( + @Param("fromDate") LocalDate fromDate, + @Param("toDate") LocalDate toDate, + @Param("zone") String zone, + @Param("division") String division, + @Param("hall_id") Integer hallid, + @Param("userType") String userType); + + @Query(value = "SELECT \r" + + " b.booking_date as booking_date,\r" + + " u.name as name,\r" + + " u.usertype as usertype,\r" + + " b.reason as reason,\r" + + " b.start_date as start_date,\r" + + " b.end_date as end_date,\r" + + " b.no_of_days as no_of_days,\r" + + " b.booking_status as booking_status,\r" + + " b.amount_received as amount_received,\r" + + " COALESCE(rt.amount_refunded, 0) as amount_refunded,\r" + + " COALESCE(r.balace_amount, 0) as balance_amount\r" + + "FROM booking_details b\r" + + "JOIN hall_details h ON b.hall_details_hall_id = h.hall_id \r" + + "LEFT JOIN users u ON b.users_user_id = u.user_id\r" + + "LEFT JOIN refund_response r ON b.booking_id = r.booking_id\r" + + "LEFT JOIN refund_transaction rt ON b.booking_id = rt.booking_details_booking_id\r" + + "WHERE h.hall_id = :hallId AND b.booking_status != 'PENDING' ", nativeQuery = true) + List> getHallDetailsForOfficer(@Param("hallId") Integer hallIid); + + @Query(value = "SELECT bd.*, hd.hall_name, us.name, us.usertype " + + "FROM booking_details bd " + + "JOIN hall_details hd ON bd.hall_details_hall_id = hd.hall_id " + + "JOIN users us ON bd.users_user_id = us.user_id " + + "WHERE DATE(bd.booking_date) >= :fromDate " + + "AND DATE(bd.booking_date) <= :toDate " + + "AND hd.zone = :zone ", nativeQuery = true) + List getAllBookingDetailsBookingDateByZone(@Param("fromDate") String fromDate, + @Param("toDate") String toDate, @Param("zone") String zone); + + @Query(value = "SELECT bd.*, hd.hall_name, us.name, us.usertype " + + "FROM booking_details bd " + + "JOIN hall_details hd ON bd.hall_details_hall_id = hd.hall_id " + + "JOIN users us ON bd.users_user_id = us.user_id " + + "WHERE DATE(bd.start_date) >= :fromDate " + + "AND DATE(bd.end_date) <= :toDate " + + "AND hd.zone = :zone ", nativeQuery = true) + List getAllBookingDetailsEventDateByZone(@Param("fromDate") String fromDate, + @Param("toDate") String toDate, @Param("zone") String zone); + + @Query(value = "SELECT bd.*, hd.hall_name, us.name, us.usertype " + + "FROM booking_details bd " + + "JOIN hall_details hd ON bd.hall_details_hall_id = hd.hall_id " + + "JOIN users us ON bd.users_user_id = us.user_id " + + "WHERE DATE(bd.booking_date) >= :fromDate " + + "AND DATE(bd.booking_date) <= :toDate " + + "AND hd.zone = :zone " + + "AND (:bookingStatus IS NULL OR bd.booking_status = :bookingStatus)", nativeQuery = true) + List getAllBookingDetailsBookingDateByZoneWithStatus(@Param("fromDate") String fromDate, + @Param("toDate") String toDate, @Param("zone") String zone, + @Param("bookingStatus") String bookingStatus); + + @Query(value = "SELECT bd.*, hd.hall_name, us.name, us.usertype " + + "FROM booking_details bd " + + "JOIN hall_details hd ON bd.hall_details_hall_id = hd.hall_id " + + "JOIN users us ON bd.users_user_id = us.user_id " + + "WHERE DATE(bd.start_date) >= :fromDate " + + "AND DATE(bd.end_date) <= :toDate " + + "AND hd.zone = :zone " + + "AND (:bookingStatus IS NULL OR bd.booking_status = :bookingStatus)", nativeQuery = true) + List getAllBookingDetailsEventDateByZoneWithStatus(@Param("fromDate") String fromDate, + @Param("toDate") String toDate, @Param("zone") String zone, + @Param("bookingStatus") String bookingStatus); + + @Query(value = "SELECT bd.*, hd.hall_name, us.name, us.usertype " + + "FROM booking_details bd " + + "JOIN hall_details hd ON bd.hall_details_hall_id = hd.hall_id " + + "JOIN users us ON bd.users_user_id = us.user_id " + + "JOIN settlement st ON bd.booking_id=st.booking_details_booking_id " + + "WHERE DATE(bd.booking_date) >= :fromDate " + + "AND DATE(bd.booking_date) <= :toDate " + + "AND hd.zone = :zone ", nativeQuery = true) + List getAllBookingsettlementDetailsByZoneByBookingDate(@Param("fromDate") String fromDate, + @Param("toDate") String toDate, @Param("zone") String zone); + + @Query(value = "SELECT bd.*, hd.hall_name, us.name, us.usertype " + + "FROM booking_details bd " + + "JOIN hall_details hd ON bd.hall_details_hall_id = hd.hall_id " + + "JOIN users us ON bd.users_user_id = us.user_id " + + "JOIN settlement st ON bd.booking_id=st.booking_details_booking_id " + + "WHERE DATE(bd.start_date) >= :fromDate " + + "AND DATE(bd.end_date) <= :toDate " + + "AND hd.zone = :zone ", nativeQuery = true) + List getAllBookingsettlementDetailsByZoneByEventDate(@Param("fromDate") String fromDate, + @Param("toDate") String toDate, @Param("zone") String zone); + + @Query(value = "SELECT bd.*, hd.hall_name, us.name, us.usertype " + + "FROM booking_details bd " + + "JOIN hall_details hd ON bd.hall_details_hall_id = hd.hall_id " + + "JOIN users us ON bd.users_user_id = us.user_id " + + "JOIN settlement st ON bd.booking_id=st.booking_details_booking_id " + + "WHERE DATE(bd.booking_date) >= :fromDate " + + "AND DATE(bd.booking_date) <= :toDate " + + "AND hd.zone = :zone " + + "AND (:refundStatus IS NULL OR bd.refund_status = :refundStatus) ", nativeQuery = true) + List getAllBookingsettlementDetailsByZoneByBookingDateWithStatus( + @Param("fromDate") String fromDate, @Param("toDate") String toDate, @Param("zone") String zone, + @Param("refundStatus") String refundStatus); + + @Query(value = "SELECT bd.*, hd.hall_name, us.name, us.usertype " + + "FROM booking_details bd " + + "JOIN hall_details hd ON bd.hall_details_hall_id = hd.hall_id " + + "JOIN users us ON bd.users_user_id = us.user_id " + + "JOIN settlement st ON bd.booking_id=st.booking_details_booking_id " + + "WHERE DATE(bd.start_date) >= :fromDate " + + "AND DATE(bd.end_date) <= :toDate " + + "AND hd.zone = :zone " + + "AND (:refundStatus IS NULL OR bd.refund_status = :refundStatus) ", nativeQuery = true) + List getAllBookingsettlementDetailsByZoneByEventDateWithStatus( + @Param("fromDate") String fromDate, @Param("toDate") String toDate, @Param("zone") String zone, + @Param("refundStatus") String refundStatus); + + @Query(value = "SELECT bd.booking_id, bd.booking_date, hd.hall_name, us.name, us.usertype, p.transaction_id, p.payment_type, p.amount_received, bd.reason, bd.start_date, bd.end_date, p.payment_status " + + + "FROM booking_details bd " + + "JOIN hall_details hd ON bd.hall_details_hall_id = hd.hall_id " + + "JOIN users us ON bd.users_user_id = us.user_id " + + "JOIN payments p ON bd.booking_id = p.booking_details_booking_id " + + "WHERE DATE(bd.booking_date) >= :fromDate " + + "AND DATE(bd.booking_date) <= :toDate " + + "AND hd.zone = :zone " + + "AND p.payment_status='Success' ", nativeQuery = true) + List getAllPaymentsDetailsByZone(@Param("fromDate") String fromDate, @Param("toDate") String toDate, + @Param("zone") String zone); + + @Query(value = "SELECT " + + "h.hall_name AS HallName, " + + "h.zone AS Zone, " + + "h.division AS Division, " + + "CONCAT(h.door_no,',',h.street, ', ', h.area, ', ', h.city, ', ', h.pin_code) AS Address, " + + "COUNT(*) AS HallTotalBookings, " + + "SUM(p.amount_received) AS AmountReceived, " + + "COALESCE(SUM(r.amount_refunded), 0) AS AmountRefund, " + // Use COALESCE to handle NULL values + "(SUM(p.amount_received) - COALESCE(SUM(r.amount_refunded), 0)) AS Difference " + // Calculate + // the + // difference + "FROM " + + "booking_details bd " + + "JOIN " + + "hall_details h ON bd.hall_details_hall_id = h.hall_id " + + "JOIN " + + "payments p ON bd.booking_id = p.booking_details_booking_id " + + "LEFT JOIN " + + "refund_transaction r ON p.transaction_id = r.transaction_id " + + "WHERE DATE(bd.booking_date) >= :fromDate " + + "AND DATE(bd.booking_date) <= :toDate " + + "AND h.zone = :zone " + + "GROUP BY " + + "h.hall_id", nativeQuery = true) + List getBookingHallDetailsReportByZoneByBookingDate(@Param("fromDate") String fromDate, + @Param("toDate") String toDate, @Param("zone") String zone); + + @Query(value = "SELECT " + + "h.hall_name AS HallName, " + + "h.zone AS Zone, " + + "h.division AS Division, " + + "CONCAT(h.door_no,',',h.street, ', ', h.area, ', ', h.city, ', ', h.pin_code) AS Address, " + + "COUNT(*) AS HallTotalBookings, " + + "SUM(p.amount_received) AS AmountReceived, " + + "COALESCE(SUM(r.amount_refunded), 0) AS AmountRefund, " + // Use COALESCE to handle NULL values + "(SUM(p.amount_received) - COALESCE(SUM(r.amount_refunded), 0)) AS Difference " + // Calculate + // the + // difference + "FROM " + + "booking_details bd " + + "JOIN " + + "hall_details h ON bd.hall_details_hall_id = h.hall_id " + + "JOIN " + + "payments p ON bd.booking_id = p.booking_details_booking_id " + + "LEFT JOIN " + + "refund_transaction r ON p.transaction_id = r.transaction_id " + + "WHERE DATE(bd.start_date) >= :fromDate " + + "AND DATE(bd.end_date) <= :toDate " + + "AND h.zone = :zone " + + "GROUP BY " + + "h.hall_id", nativeQuery = true) + List getBookingHallDetailsReportByZoneByEventDate(@Param("fromDate") String fromDate, + @Param("toDate") String toDate, @Param("zone") String zone); + + @Query(value = "SELECT " + + "h.hall_name AS HallName, " + + "h.zone AS Zone, " + + "h.division AS Division, " + + "CONCAT(h.door_no,',',h.street, ', ', h.area, ', ', h.city, ', ', h.pin_code) AS Address, " + + "COUNT(*) AS HallTotalBookings, " + + "SUM(p.amount_received) AS AmountReceived, " + + "COALESCE(SUM(r.amount_refunded), 0) AS AmountRefund, " + // Use COALESCE to handle NULL values + "(SUM(p.amount_received) - COALESCE(SUM(r.amount_refunded), 0)) AS Difference " + // Calculate + // the + // difference + "FROM " + + "booking_details bd " + + "JOIN " + + "hall_details h ON bd.hall_details_hall_id = h.hall_id " + + "JOIN " + + "payments p ON bd.booking_id = p.booking_details_booking_id " + + "LEFT JOIN " + + "refund_transaction r ON p.transaction_id = r.transaction_id " + + "WHERE DATE(bd.booking_date) >= :fromDate " + + "AND DATE(bd.booking_date) <= :toDate " + + "AND h.zone = :zone " + + "AND (:hall_id = '0' OR h.hall_id = :hall_id) " + + "GROUP BY " + + "h.hall_id", nativeQuery = true) + List getBookingHallDetailsReportByZoneByBookingDateHallname(@Param("fromDate") String fromDate, + @Param("toDate") String toDate, @Param("zone") String zone, @Param("hall_id") Integer hallId); + + @Query(value = "SELECT " + + "h.hall_name AS HallName, " + + "h.zone AS Zone, " + + "h.division AS Division, " + + "CONCAT(h.door_no,',',h.street, ', ', h.area, ', ', h.city, ', ', h.pin_code) AS Address, " + + "COUNT(*) AS HallTotalBookings, " + + "SUM(p.amount_received) AS AmountReceived, " + + "COALESCE(SUM(r.amount_refunded), 0) AS AmountRefund, " + // Use COALESCE to handle NULL values + "(SUM(p.amount_received) - COALESCE(SUM(r.amount_refunded), 0)) AS Difference " + // Calculate + // the + // difference + "FROM " + + "booking_details bd " + + "JOIN " + + "hall_details h ON bd.hall_details_hall_id = h.hall_id " + + "JOIN " + + "payments p ON bd.booking_id = p.booking_details_booking_id " + + "LEFT JOIN " + + "refund_transaction r ON p.transaction_id = r.transaction_id " + + "WHERE DATE(bd.start_date) >= :fromDate " + + "AND DATE(bd.end_date) <= :toDate " + + "AND h.zone = :zone " + + "AND (:hall_id = '0' OR h.hall_id = :hall_id) " + + "GROUP BY " + + "h.hall_id", nativeQuery = true) + List getBookingHallDetailsReportByZoneByEventDateHallname(@Param("fromDate") String fromDate, + @Param("toDate") String toDate, @Param("zone") String zone, @Param("hall_id") Integer hallId); + + // Present Events: Fetch today's events + @Query(value = "SELECT * FROM booking_details WHERE DATE(start_date) = CURRENT_DATE() AND booking_status='APPROVED'", nativeQuery = true) + List findPresentBookingList(); + + // Past Events: Fetch events + @Query(value = "SELECT * FROM booking_details " + + "WHERE DATE(start_date) < CURRENT_DATE() " + + "AND booking_status='APPROVED'", nativeQuery = true) + List findPastEventsList(); + + // Future Events: Fetch events for the next two days (tomorrow and the day + // after) + @Query(value = "SELECT * FROM booking_details " + + "WHERE start_date BETWEEN CURDATE() + INTERVAL 1 DAY AND CURDATE() + INTERVAL 2 DAY " + + "AND booking_status = 'APPROVED'", nativeQuery = true) + List findFutureEventsList(); + + // admin reports + @Query(value = "SELECT bd.booking_id, bd.booking_date, hd.hall_name, us.name, us.mobile_no, " + + "CONCAT(us.doorno, ', ', us.street, ', ', us.area, ', ', us.location, ', ', us.pin_code) AS address, " + + + "us.usertype, bd.reason, bd.start_date, bd.end_date, " + + "bd.deposit_amount, bd.hall_amount, bd.gst, bd.amount_received, bd.booking_status " + + "FROM booking_details bd " + + "JOIN hall_details hd ON bd.hall_details_hall_id = hd.hall_id " + + "JOIN users us ON bd.users_user_id = us.user_id " + + "WHERE DATE(bd.booking_date) >= :fromDate " + + "AND DATE(bd.booking_date) <= :toDate " + + "AND (:zone IS NULL OR :zone = 'ALL' OR hd.zone = :zone) " + + "AND (:division IS NULL OR :division = 'ALL' OR hd.division = :division) " + + "AND (:hallid IS NULL OR :hallid = '1000' OR hd.hall_id = :hallid) " + + "AND bd.booking_status!='PENDING' order by bd.booking_id asc", nativeQuery = true) + List getBookingDetailsByBookingDate(@Param("fromDate") String fromDate, + @Param("toDate") String toDate, @Param("zone") String zone, @Param("division") String division, + @Param("hallid") Integer hallid); + + @Query(value = "SELECT bd.booking_id, bd.booking_date, hd.hall_name, us.name, us.mobile_no, " + + "CONCAT(us.doorno, ', ', us.street, ', ', us.area, ', ', us.location, ', ', us.pin_code) AS address, " + + + "us.usertype, bd.reason, bd.start_date, bd.end_date, " + + "bd.deposit_amount, bd.hall_amount, bd.gst, bd.amount_received, bd.booking_status " + + "FROM booking_details bd " + + "JOIN hall_details hd ON bd.hall_details_hall_id = hd.hall_id " + + "JOIN users us ON bd.users_user_id = us.user_id " + + "WHERE DATE(bd.booking_date) >= :fromDate " + + "AND DATE(bd.booking_date) <= :toDate " + + "AND (:zone IS NULL OR :zone = 'ALL' OR hd.zone = :zone) " + + "AND (:division IS NULL OR :division = 'ALL' OR hd.division = :division) " + + "AND (:hallid IS NULL OR :hallid = '1000' OR hd.hall_id = :hallid) " + + "AND bd.booking_status = :bookingStatus order by bd.booking_id asc", nativeQuery = true) + List getBookingDetailsByBookingDateWithStatus(@Param("fromDate") String fromDate, + @Param("toDate") String toDate, + @Param("bookingStatus") String bookingStatus, @Param("zone") String zone, + @Param("division") String division, @Param("hallid") Integer hallid); + + @Query(value = "SELECT bd.booking_id, bd.booking_date, hd.hall_name, us.name, us.mobile_no, " + + "CONCAT(us.doorno, ', ', us.street, ', ', us.area, ', ', us.location, ', ', us.pin_code) AS address, " + + + "us.usertype, bd.reason, bd.start_date, bd.end_date, " + + "bd.deposit_amount, bd.hall_amount, bd.gst, bd.amount_received, bd.booking_status " + + "FROM booking_details bd " + + "JOIN hall_details hd ON bd.hall_details_hall_id = hd.hall_id " + + "JOIN users us ON bd.users_user_id = us.user_id " + + "WHERE DATE(bd.start_date) >= :fromDate " + + "AND DATE(bd.end_date) <= :toDate " + + "AND (:zone IS NULL OR :zone = 'ALL' OR hd.zone = :zone) " + + "AND (:division IS NULL OR :division = 'ALL' OR hd.division = :division) " + + "AND (:hallid IS NULL OR :hallid = '1000' OR hd.hall_id = :hallid) " + + "AND bd.booking_status!='PENDING' order by bd.booking_id asc", nativeQuery = true) + List getBookingDetailsByEventDate(@Param("fromDate") String fromDate, + @Param("toDate") String toDate, @Param("zone") String zone, @Param("division") String division, + @Param("hallid") Integer hallid); + + @Query(value = "SELECT bd.booking_id, bd.booking_date, hd.hall_name, us.name, us.mobile_no, " + + "CONCAT(us.doorno, ', ', us.street, ', ', us.area, ', ', us.location, ', ', us.pin_code) AS address, " + + + "us.usertype, bd.reason, bd.start_date, bd.end_date, " + + "bd.deposit_amount, bd.hall_amount, bd.gst, bd.amount_received, bd.booking_status " + + "FROM booking_details bd " + + "JOIN hall_details hd ON bd.hall_details_hall_id = hd.hall_id " + + "JOIN users us ON bd.users_user_id = us.user_id " + + "WHERE DATE(bd.start_date) >= :fromDate " + + "AND DATE(bd.end_date) <= :toDate " + + "AND (:zone IS NULL OR :zone = 'ALL' OR hd.zone = :zone) " + + "AND (:division IS NULL OR :division = 'ALL' OR hd.division = :division) " + + "AND (:hallid IS NULL OR :hallid = '1000' OR hd.hall_id = :hallid) " + + "AND bd.booking_status = :bookingStatus order by bd.booking_id asc", nativeQuery = true) + List getBookingDetailsByEventDateWithStatus(@Param("fromDate") String fromDate, + @Param("toDate") String toDate, + @Param("bookingStatus") String bookingStatus, @Param("zone") String zone, + @Param("division") String division, @Param("hallid") Integer hallid); + + @Query(value = "SELECT bd.booking_id, bd.booking_date, hd.hall_name, us.name, us.usertype, p.transaction_id, p.payment_type, bd.deposit_amount, bd.hall_amount, bd.gst, p.amount_received, bd.reason, bd.start_date, bd.end_date, p.payment_status " + + + "FROM booking_details bd " + + "JOIN hall_details hd ON bd.hall_details_hall_id = hd.hall_id " + + "JOIN users us ON bd.users_user_id = us.user_id " + + "JOIN payments p ON bd.booking_id = p.booking_details_booking_id " + + "WHERE DATE(p.cdate) >= :fromDate " + + "AND DATE(p.cdate) <= :toDate " + + "AND (:paymentStatus IS NULL OR p.payment_status = :paymentStatus)" + + "AND (:zone IS NULL OR :zone = 'ALL' OR hd.zone = :zone) " + + "AND (:division IS NULL OR :division = 'ALL' OR hd.division = :division) " + + "AND (:hallid IS NULL OR :hallid = '1000' OR hd.hall_id = :hallid) order by bd.booking_id asc", nativeQuery = true) + List getAllPaymentsDetails(@Param("fromDate") String fromDate, @Param("toDate") String toDate, + @Param("paymentStatus") String paymentStatus, @Param("zone") String zone, + @Param("division") String division, @Param("hallid") Integer hallid); + + @Query(value = "SELECT bd.booking_id, bd.booking_date, hd.hall_name, us.name, us.usertype, p.transaction_id, p.payment_type, bd.deposit_amount, bd.hall_amount, bd.gst, p.amount_received, bd.reason, bd.start_date, bd.end_date, p.payment_status " + + + "FROM booking_details bd " + + "JOIN hall_details hd ON bd.hall_details_hall_id = hd.hall_id " + + "JOIN users us ON bd.users_user_id = us.user_id " + + "JOIN extra_payments p ON bd.booking_id = p.booking_details_booking_id " + + "WHERE DATE(p.cdate) >= :fromDate " + + "AND DATE(p.cdate) <= :toDate " + + "AND (:paymentStatus IS NULL OR p.payment_status = :paymentStatus)" + + "AND (:zone IS NULL OR :zone = 'ALL' OR hd.zone = :zone) " + + "AND (:division IS NULL OR :division = 'ALL' OR hd.division = :division) " + + "AND (:hallid IS NULL OR :hallid = '1000' OR hd.hall_id = :hallid) order by bd.booking_id asc ", nativeQuery = true) + List getAllExtraPaymentsDetails(@Param("fromDate") String fromDate, @Param("toDate") String toDate, + @Param("paymentStatus") String paymentStatus, @Param("zone") String zone, + @Param("division") String division, @Param("hallid") Integer hallid); + + @Query(value = "SELECT " + + "h.hall_name AS HallName, " + + "h.hall_Incharge_name AS InchargeName, " + + "h.hall_Incharge_no AS hallInchargeMobno, " + + "CONCAT(h.zone, '/', h.division) AS ZoneDivision, " + // Concatenate zone and division + "COUNT(*) AS HallTotalBookings, " + + "SUM(bd.deposit_amount) AS depositAmount, " + + "SUM(bd.hall_amount) AS hallAmount, " + + "SUM(bd.gst) AS gst, " + + "SUM(p.amount_received) AS AmountReceived, " + + "COALESCE(SUM(r.amount - r.balace_amount), 0) AS AmountRefund, " + + "COALESCE(SUM(CASE WHEN bd.booking_status IN ('COMPLETED', 'CANCELED') THEN r.balace_amount - bd.gst ELSE 0 END), 0) AS NetRevenue ," + + + "h.hall_id " + + "FROM " + + "booking_details bd " + + "JOIN " + + "hall_details h ON bd.hall_details_hall_id = h.hall_id " + + "JOIN " + + "payments p ON bd.booking_id = p.booking_details_booking_id " + + "LEFT JOIN refund_response r ON bd.booking_id = r.booking_id " + + "WHERE DATE(bd.booking_date) >= :fromDate " + + "AND DATE(bd.booking_date) <= :toDate " + + "AND (:zone IS NULL OR :zone = 'ALL' OR h.zone = :zone) " + + "AND (:division IS NULL OR :division = 'ALL' OR h.division = :division) " + + "AND (:hallid IS NULL OR :hallid = '1000' OR h.hall_id = :hallid) " + + "GROUP BY " + + "bd.hall_details_hall_id order by COUNT(*) desc", nativeQuery = true) + List getBookingHallDetailsReportByBookingDate(@Param("fromDate") String fromDate, + @Param("toDate") String toDate, @Param("zone") String zone, @Param("division") String division, + @Param("hallid") Integer hallid); + + @Query(value = "SELECT " + + "h.hall_name AS HallName, " + + "h.hall_Incharge_name AS InchargeName, " + + "h.hall_Incharge_no AS hallInchargeMobno, " + + "CONCAT(h.zone, '/', h.division) AS ZoneDivision, " + // Concatenate zone and division + "COUNT(*) AS HallTotalBookings, " + + "SUM(bd.deposit_amount) AS depositAmount, " + + "SUM(bd.hall_amount) AS hallAmount, " + + "SUM(bd.gst) AS gst, " + + "SUM(p.amount_received) AS AmountReceived, " + + "COALESCE(SUM(r.amount - r.balace_amount), 0) AS AmountRefund, " + + "COALESCE(SUM(CASE WHEN bd.booking_status IN ('COMPLETED', 'CANCELED') THEN r.balace_amount - bd.gst ELSE 0 END), 0) AS NetRevenue " + + + "FROM " + + "booking_details bd " + + "JOIN " + + "hall_details h ON bd.hall_details_hall_id = h.hall_id " + + "JOIN " + + "payments p ON bd.booking_id = p.booking_details_booking_id " + + "LEFT JOIN refund_response r ON bd.booking_id = r.booking_id " + + "WHERE DATE(bd.start_date) >= :fromDate " + + "AND DATE(bd.end_date) <= :toDate " + + "AND (:zone IS NULL OR :zone = 'ALL' OR h.zone = :zone) " + + "AND (:division IS NULL OR :division = 'ALL' OR h.division = :division) " + + "AND (:hallid IS NULL OR :hallid = '1000' OR h.hall_id = :hallid) " + + "GROUP BY " + + "bd.hall_details_hall_id", nativeQuery = true) + List getBookingHallDetailsReportByEventDate(@Param("fromDate") String fromDate, + @Param("toDate") String toDate, @Param("zone") String zone, @Param("division") String division, + @Param("hallid") Integer hallid); + + @Query(value = "SELECT bd.*, hd.hall_name, us.name, us.usertype " + + "FROM booking_details bd " + + "JOIN hall_details hd ON bd.hall_details_hall_id = hd.hall_id " + + "JOIN users us ON bd.users_user_id = us.user_id " + + "left JOIN settlement st ON bd.booking_id=st.booking_details_booking_id " + + "WHERE DATE(bd.booking_date) >= :fromDate " + + "AND DATE(bd.booking_date) <= :toDate order by bd.booking_id asc ", nativeQuery = true) + List getAllBookingsettlementDetailsByBookingDate(@Param("fromDate") String fromDate, + @Param("toDate") String toDate); + + @Query(value = "SELECT bd.*, hd.hall_name, us.name, us.usertype " + + "FROM booking_details bd " + + "JOIN hall_details hd ON bd.hall_details_hall_id = hd.hall_id " + + "JOIN users us ON bd.users_user_id = us.user_id " + + "left JOIN settlement st ON bd.booking_id=st.booking_details_booking_id " + + "WHERE DATE(bd.booking_date) >= :fromDate " + + "AND DATE(bd.booking_date) <= :toDate " + + "AND (:refundStatus IS NULL OR bd.refund_status = :refundStatus) order by bd.booking_id asc", nativeQuery = true) + List getAllBookingsettlementDetailsByBookingDateWithStatus(@Param("fromDate") String fromDate, + @Param("toDate") String toDate, @Param("refundStatus") String refundStatus); + + @Query(value = "SELECT bd.*, hd.hall_name, us.name, us.usertype " + + "FROM booking_details bd " + + "JOIN hall_details hd ON bd.hall_details_hall_id = hd.hall_id " + + "JOIN users us ON bd.users_user_id = us.user_id " + + "left JOIN settlement st ON bd.booking_id=st.booking_details_booking_id " + + "WHERE DATE(bd.start_date) >= :fromDate " + + "AND DATE(bd.end_date) <= :toDate order by bd.booking_id asc", nativeQuery = true) + List getAllBookingsettlementDetailsByEventDate(@Param("fromDate") String fromDate, + @Param("toDate") String toDate); + + @Query(value = "SELECT bd.*, hd.hall_name, us.name, us.usertype " + + "FROM booking_details bd " + + "JOIN hall_details hd ON bd.hall_details_hall_id = hd.hall_id " + + "JOIN users us ON bd.users_user_id = us.user_id " + + "left JOIN settlement st ON bd.booking_id=st.booking_details_booking_id " + + "WHERE DATE(bd.start_date) >= :fromDate " + + "AND DATE(bd.end_date) <= :toDate " + + "AND (:refundStatus IS NULL OR bd.refund_status = :refundStatus) order by bd.booking_id asc", nativeQuery = true) + List getAllBookingsettlementDetailsByEventDateWithStatus(@Param("fromDate") String fromDate, + @Param("toDate") String toDate, @Param("refundStatus") String refundStatus); + + // In BookingDetailsRepository.java + // In BookingDetailsRepository.java + @Query("SELECT h.zone, COUNT(b) FROM BookingDetails b JOIN b.hallDetails h WHERE b.bookingStatus = 'APPROVED' GROUP BY h.zone") + List countBookingsByZone(); + + @Query("SELECT h.division, COUNT(b) FROM BookingDetails b JOIN b.hallDetails h WHERE b.bookingStatus = 'APPROVED' GROUP BY h.division") + List countBookingsByDivisions(); + + @Query("SELECT b FROM BookingDetails b JOIN b.hallDetails h WHERE h.zone = :zone AND b.bookingStatus = 'APPROVED'") + List findByZone(@Param("zone") String zone); + + // gccapps + List findByBookingStatus(BookingDetails.BookingStatus bookingStatus); + + @Query("SELECT b FROM BookingDetails b JOIN FETCH b.settlement s WHERE b.refundStatus = 'WAITING'") + List findAllWithPendingRefundStatus(); + + @Query("SELECT b FROM BookingDetails b WHERE b.refundStatus = 'WAITING' AND b.bookingStatus = 'CANCELED'") + List findPendingCancelledList(); + + @Query(value = "SELECT * FROM booking_details WHERE refund_status = 'WAITING' AND booking_status IN ('GCC_BLOCKED', 'REJECTED')", nativeQuery = true) + List findPendingRejectedList(); + + @Query(value = "SELECT * FROM booking_details WHERE refund_status = 'COMPLETED' AND booking_status = 'CANCELED'", nativeQuery = true) + List findCompletedCancelledList(); + + @Query(value = "SELECT * FROM booking_details WHERE refund_status = 'COMPLETED' AND booking_status IN ('GCC_BLOCKED', 'REJECTED')", nativeQuery = true) + List findCompletedRejectedList(); + + @Query("SELECT b FROM BookingDetails b JOIN FETCH b.settlement s WHERE b.refundStatus = 'REJECTED'") + List findSettlementRejected(); + + @Query(value = "SELECT * FROM booking_details WHERE DATE(start_date) < CURRENT_DATE() AND booking_status='APPROVED'", nativeQuery = true) + List findPastsEvents(); + + @Query(value = "SELECT * FROM booking_details WHERE DATE(start_date) = CURRENT_DATE() AND booking_status='APPROVED'", nativeQuery = true) + List findPresentsEvents(); + + @Query(value = "SELECT * FROM booking_details WHERE DATE(start_date) BETWEEN CURRENT_DATE() AND DATE_ADD(CURRENT_DATE(), INTERVAL 2 DAY) AND booking_status = 'APPROVED'", nativeQuery = true) + List findFuturesEvents(); + + @Query(value = "SELECT * FROM booking_details WHERE DATE(start_date) < CURRENT_DATE() AND booking_status='APPROVED'", nativeQuery = true) + public List getSettlementApprovedList(); + + @Query(value = "SELECT * FROM booking_details WHERE DATE(start_date) <= CURRENT_DATE() AND booking_status='APPROVED'", nativeQuery = true) + public List getSettlementsList(); + + @Query("SELECT b FROM BookingDetails b WHERE b.refundStatus = 'FAILURE' AND b.bookingStatus = 'APPROVED' AND b.hallDetails.zone = :zone AND b.hallDetails.hallId IN (:hallIds)") + List findSettlementRefundFailedByZone(String zone, List hallIds); + + @Query("SELECT b FROM BookingDetails b WHERE b.refundStatus = 'FAILURE' AND b.bookingStatus = 'CANCELED' AND b.hallDetails.zone = :zone AND b.hallDetails.hallId IN (:hallIds)") + List findRefundFaileCancelledListByZone(String zone, List hallIds); + + @Query("SELECT b FROM BookingDetails b WHERE b.refundStatus = 'FAILURE' AND b.bookingStatus IN ('REJECTED','GCC_BLOCKED') AND b.hallDetails.zone = :zone AND b.hallDetails.hallId IN (:hallIds)") + List findRefundFaileRejectedListByZone(String zone, List hallIds); + + @Query("SELECT b FROM BookingDetails b WHERE b.bookingStatus = 'COMPLETED' AND b.refundStatus IN ('COMPLETED','CLOSED') AND b.hallDetails.zone = :zone AND b.hallDetails.hallId IN (:hallIds)") + List findSettlementCompletedListbyzone(String zone, List hallIds); + + @Query("SELECT b FROM BookingDetails b WHERE b.bookingStatus = 'CANCELED' AND b.refundStatus = 'COMPLETED' AND b.hallDetails.zone = :zone AND b.hallDetails.hallId IN (:hallIds)") + List findCancelledCompletedListbyzone(String zone, List hallIds); + + @Query("SELECT b FROM BookingDetails b WHERE b.bookingStatus IN ('REJECTED','GCC_BLOCKED') AND b.refundStatus = 'COMPLETED' AND b.hallDetails.zone = :zone AND b.hallDetails.hallId IN (:hallIds)") + List findRejectedSettlementCompletedListbyzone(String zone, List hallIds); + + @Query("SELECT b FROM BookingDetails b JOIN FETCH b.settlement s WHERE b.refundStatus = 'WAITING'") + List findAllSettlementPending(); + + @Query("SELECT b FROM BookingDetails b WHERE b.refundStatus = 'WAITING' AND b.bookingStatus = 'CANCELED'") + List findAllSettlementCancelledList(); + + @Query("SELECT b FROM BookingDetails b WHERE b.refundStatus = 'WAITING' AND b.bookingStatus IN ('REJECTED','GCC_BLOCKED')") + List findAllSettlementRejectedList(); + + @Query("SELECT b FROM BookingDetails b WHERE b.refundStatus = 'FAILURE' AND b.bookingStatus = 'APPROVED'") + List findAllSettlementRefundFailed(); + + @Query("SELECT b FROM BookingDetails b WHERE b.refundStatus = 'FAILURE' AND b.bookingStatus = 'CANCELED'") + List findAllRefundFaileCancelledList(); + + @Query("SELECT b FROM BookingDetails b WHERE b.refundStatus = 'FAILURE' AND b.bookingStatus IN ('REJECTED','GCC_BLOCKED')") + List findAllRefundFaileRejectedList(); + + @Query(value = "SELECT * FROM booking_details WHERE booking_date = :bookingDate AND hall_details_hall_id = :hallId", nativeQuery = true) + List findByBookingDateAndHallId(@Param("bookingDate") LocalDate bookingDate, + @Param("hallId") Long hallId); + + @Query(value = "SELECT * FROM booking_details where booking_status='WAITING_FOR_NOC' order by booking_id", nativeQuery = true) + List getAllwaitingNOC(); + + @Query(value = "SELECT bd.counter_id, COUNT(*) AS total_count " + + "FROM booking_details bd " + + "WHERE DATE(bd.booking_date) BETWEEN :fromDate AND :toDate " + + "AND bd.booking_status <> 'PENDING' " + + "AND bd.counter_id IS NOT NULL " + + "GROUP BY bd.counter_id", nativeQuery = true) + List getCounterWiseBookingCount( + @Param("fromDate") String fromDate, + @Param("toDate") String toDate); + + /* + * @Query(value = + * "SELECT bd.counter_id, h.zone, h. division, h.hall_name, COUNT(*) as total_bookings " + * + + * "FROM booking_details bd " + + * "JOIN hall_details h ON h.hall_id = bd.hall_details_hall_id " + + * "WHERE DATE(bd.booking_date) BETWEEN :fromDate AND :toDate " + + * "AND bd.counter_id IS NOT NULL " + + * "GROUP BY bd.counter_id,h.zone, h. division, h.hall_name", nativeQuery = + * true) + * List getHallWiseBookingDetails(@Param("fromDate") String + * fromDate, @Param("toDate") String toDate); + * + * @Query(value = + * "SELECT bd.booking_id,h.hall_name, bd.booking_date, bd.start_date, bd.end_date," + * + + * "bd.starting_slot,bd.ending_slot,bd.no_of_days,bd.reason,bd.amount_received, " + * + + * "bd.hall_amount,bd.deposit_amount,bd.gst, " + + * "bd.booking_status,bd.booking_type " + + * "FROM booking_details bd " + + * "JOIN hall_details h ON h.hall_id = bd.hall_details_hall_id " + + * "WHERE DATE(bd.booking_date) BETWEEN :fromDate AND :toDate " + + * "AND bd.counter_id IS NOT NULL", nativeQuery = true) + * List getBookingDetailsForAllHalls(@Param("fromDate") String + * fromDate, @Param("toDate") String toDate); + */ + + @Query(value = "SELECT bd.counter_id, h.zone, h.division, h.hall_name, COUNT(*) AS total_bookings " + + "FROM booking_details bd " + + "JOIN hall_details h ON h.hall_id = bd.hall_details_hall_id " + + "WHERE DATE(bd.booking_date) BETWEEN :fromDate AND :toDate " + + "AND bd.counter_id IS NOT NULL " + + "AND bd.booking_status <> 'PENDING' " + + "AND (:counterId IS NULL OR bd.counter_id = :counterId) " + + "GROUP BY bd.counter_id, h.zone, h.division, h.hall_name", nativeQuery = true) + List getHallWiseBookingDetails( + @Param("fromDate") String fromDate, + @Param("toDate") String toDate, + @Param("counterId") String counterId); + + @Query(value = " SELECT bd.booking_id, h.hall_name, bd.booking_date, bd.start_date, " + + "bd.end_date, bd.starting_slot, bd.ending_slot, bd.no_of_days, bd.reason, " + + "bd.amount_received, bd.hall_amount, bd.deposit_amount, bd.gst, bd.booking_status, " + + "bd.booking_type FROM booking_details bd " + + "JOIN hall_details h ON h.hall_id = bd.hall_details_hall_id " + + "WHERE DATE(bd.booking_date) BETWEEN :fromDate AND :toDate " + + "AND bd.counter_id IS NOT NULL " + + "AND ( :counterId IS NULL OR bd.counter_id = :counterId ) " + + "AND ( :hallid IS NULL OR bd.hall_details_hall_id = :hallid ) " + + "AND bd.booking_status <> 'PENDING' ", nativeQuery = true) + List getBookingDetailsForAllHalls( + @Param("fromDate") String fromDate, + @Param("toDate") String toDate, + @Param("counterId") String counterId, + @Param("hallid") Integer hallid); + + @Query(value = " SELECT bd.booking_id, h.hall_name, bd.booking_date, bd.start_date, " + + "bd.end_date, bd.starting_slot, bd.ending_slot, bd.no_of_days, bd.reason, " + + "bd.amount_received, bd.hall_amount, bd.deposit_amount, bd.gst, bd.booking_status, " + + "bd.booking_type, bd.counter_id FROM booking_details bd " + + "JOIN hall_details h ON h.hall_id = bd.hall_details_hall_id " + + "WHERE DATE(bd.booking_date) BETWEEN :fromDate AND :toDate " + + "AND bd.counter_id IS NOT NULL " + + "AND bd.booking_status <> 'PENDING' GROUP BY bd.counter_id, bd.booking_id ", nativeQuery = true) + List getCounterWiseBookingDetails(String fromDate, String toDate); + + @Query(value = " SELECT hd.zone, " + + " COUNT(DISTINCT hd.hall_id) AS hall_count, " + + " COUNT(bd.booking_id) AS total_count, " + + " SUM(CASE " + + " WHEN bd.booking_type = 'ONLINE' AND bd.counter_id IS NULL THEN 1 " + + " ELSE 0 " + + " END) AS online_count, " + + " SUM(CASE " + + " WHEN bd.booking_type = 'ONLINE' AND bd.counter_id IS NOT NULL THEN 1 " + + " ELSE 0 " + + " END) AS counter_count " + + "FROM hall_details hd " + + "LEFT JOIN booking_details bd " + + " ON hd.hall_id = bd.hall_details_hall_id " + + " AND DATE(bd.booking_date) BETWEEN :fromDate AND :toDate " + + " AND bd.booking_status NOT IN ('PENDING','GCC_UNBLOCKED','REFUNDED','GCC_BLOCKED') " + + " AND bd.booking_type IS NOT NULL " + + "GROUP BY hd.zone " + + "ORDER BY hd.zone", nativeQuery = true) + List getZoneWiseBookingList(String fromDate, String toDate); + + @Query(value = " select hd.hall_id, hd.hall_name, " + + "COUNT(bd.booking_id) AS total_count, " + + " SUM(CASE " + + " WHEN bd.booking_type = 'ONLINE' AND bd.counter_id IS NULL THEN 1 " + + " ELSE 0 " + + " END) AS online_count, " + + " SUM(CASE " + + " WHEN bd.booking_type = 'ONLINE' AND bd.counter_id IS NOT NULL THEN 1 " + + " ELSE 0 " + + " END) AS counter_count, hd.zone from hall_details hd " + + "left join booking_details bd on hd.hall_id = bd.hall_details_hall_id " + + "where DATE(bd.booking_date) BETWEEN :fromDate AND :toDate and " + + "bd.booking_status not in ('PENDING','GCC_UNBLOCKED','REFUNDED','GCC_BLOCKED') and bd.booking_type is not null " + + + "group by hd.hall_name, hd.hall_id ", nativeQuery = true) + List getHallWiseBookingList(String fromDate, String toDate); + + @Query(value = " SELECT " + + " bd.counter_id, bd.hall_details_hall_id, " + + " COUNT(bd.booking_id) AS booking_count " + + "FROM booking_details bd " + + "WHERE DATE(bd.booking_date) BETWEEN :fromDate AND :toDate " + + " AND bd.booking_status NOT IN ('PENDING','GCC_UNBLOCKED','REFUNDED','GCC_BLOCKED') " + + " AND bd.booking_type IS NOT NULL " + + " AND bd.counter_id IS NOT NULL " + + "GROUP BY bd.counter_id, bd.hall_details_hall_id ", nativeQuery = true) + List getCounterWiseBookingList(String fromDate, String toDate); } diff --git a/src/main/java/com/gcc/communityHall/repository/HallDetailsRepository.java b/src/main/java/com/gcc/communityHall/repository/HallDetailsRepository.java index f67cc20f..6ac3f2fc 100644 --- a/src/main/java/com/gcc/communityHall/repository/HallDetailsRepository.java +++ b/src/main/java/com/gcc/communityHall/repository/HallDetailsRepository.java @@ -1,6 +1,5 @@ package com.gcc.communityHall.repository; - import java.util.List; import java.util.Map; import java.util.Set; @@ -13,43 +12,46 @@ import org.springframework.stereotype.Repository; import com.gcc.communityHall.entity.HallDetails; @Repository -public interface HallDetailsRepository extends JpaRepository { - @Query(value= "select id from halldetails", nativeQuery=true) +public interface HallDetailsRepository extends JpaRepository { + @Query(value = "select id from halldetails", nativeQuery = true) List getHallAvailablity(); - @Query(value = "SELECT * FROM hall_details where hall_id NOT IN (:groupByHallIdToRemov) ",nativeQuery = true) - List removeHallById(Set groupByHallIdToRemov); + + @Query(value = "SELECT * FROM hall_details where hall_id NOT IN (:groupByHallIdToRemov) ", nativeQuery = true) + List removeHallById(Set groupByHallIdToRemov); + @Query("SELECT h FROM HallDetails h WHERE h.division = :division ") List findByDivision(@Param("division") String division); + @Query("SELECT h FROM HallDetails h WHERE h.zone = :zone ") List findByZone(@Param("zone") String zone); + @Query("SELECT h FROM HallDetails h WHERE h.id = :hallId ") - HallDetails findHallDetailsById(@Param("hallId") int hallId); + HallDetails findHallDetailsById(@Param("hallId") int hallId); @Query("SELECT h FROM HallDetails h WHERE h.id = :hallId and h.isActive = true ") - HallDetails findHallActiveDetailsById(@Param("hallId") int hallId); - - @Query(value = "SELECT zone,division FROM hall_details ",nativeQuery = true ) + HallDetails findHallActiveDetailsById(@Param("hallId") int hallId); + + @Query(value = "SELECT zone,division FROM hall_details ", nativeQuery = true) List> getZoneAndDivision(); - - @Query(value = "SELECT DISTINCT division FROM hall_details where zone=:zone ",nativeQuery = true ) + + @Query(value = "SELECT DISTINCT division FROM hall_details where zone=:zone ", nativeQuery = true) List> getDivision(String zone); - + @Query(value = "SELECT hall_id, hall_name FROM hall_details where is_active = 1 ", nativeQuery = true) List> getAllHalls(); - @Query(value = "SELECT hall_id, hall_name FROM hall_details WHERE zone = :zone and is_active = 1 ", nativeQuery = true) + @Query(value = "SELECT division,hall_id, hall_name FROM hall_details WHERE zone = :zone and is_active = 1 ", nativeQuery = true) List> getHallsByZone(@Param("zone") String zone); - + @Query(value = "SELECT hall_id AS hallId, hall_name AS hallName FROM hall_details WHERE zone IN (:zones) and is_active = 1 ", nativeQuery = true) List> getHallsByZones(@Param("zones") List zones); @Query(value = "SELECT * FROM hall_details WHERE is_active = 1 order by hall_name asc", nativeQuery = true) List findActiveHalls(); + // admin dashboard - //admin dashboard - - @Query(nativeQuery = true, value ="SELECT SUM(CASE WHEN b.booking_status = 'APPROVED' THEN 1 ELSE 0 END) AS approvedCount,\r\n" + @Query(nativeQuery = true, value = "SELECT SUM(CASE WHEN b.booking_status = 'APPROVED' THEN 1 ELSE 0 END) AS approvedCount,\r\n" + "SUM(CASE WHEN b.booking_status = 'REJECTED' THEN 1 ELSE 0 END) AS rejectedCount,\r\n" + "SUM(CASE WHEN b.booking_status = 'COMPLETED' THEN 1 ELSE 0 END) AS completedCount, \r\n" + "SUM(CASE WHEN b.booking_status = 'CANCELED' THEN 1 ELSE 0 END) AS canceledCount, \r\n" @@ -59,57 +61,60 @@ public interface HallDetailsRepository extends JpaRepository getTotalBookingsAndAmountReceivedByZone(@Param("zone") String zone); - @Query(nativeQuery = true, value ="SELECT h.hall_id AS hall_id, h.zone AS zonename,h.division AS division, h.hall_name AS hallName, " + - "SUM(CASE WHEN b.booking_status = 'APPROVED' THEN 1 ELSE 0 END) AS approvedCount, " + - "SUM(CASE WHEN b.booking_status = 'REJECTED' THEN 1 ELSE 0 END) AS rejectedCount, " + - "SUM(CASE WHEN b.booking_status = 'COMPLETED' THEN 1 ELSE 0 END) AS completedCount, " + - "SUM(CASE WHEN b.booking_status = 'CANCELED' THEN 1 ELSE 0 END) AS canceledCount, " + - "SUM(CASE WHEN b.booking_status = 'PAYMENT_FAILURE' THEN 1 ELSE 0 END) AS paymentFailureCount, " + - "SUM(CASE WHEN b.booking_status = 'GCC_BLOCKED' THEN 1 ELSE 0 END) AS gccBlockedCount, " + - "COUNT(b.booking_status) AS totalBookings, " + - "SUM(CASE WHEN b.amount_received IS NULL THEN 0 ELSE b.amount_received END) AS totalAmount " + - "FROM hall_details h LEFT JOIN booking_details b ON b.hall_details_hall_id = h.hall_id WHERE h.zone = :zone AND b.booking_status!='PENDING' "+ - "GROUP BY h.hall_id,h.zone,h.division,h.hall_name") + @Query(nativeQuery = true, value = "SELECT h.hall_id AS hall_id, h.zone AS zonename,h.division AS division, h.hall_name AS hallName, " + + + "SUM(CASE WHEN b.booking_status = 'APPROVED' THEN 1 ELSE 0 END) AS approvedCount, " + + "SUM(CASE WHEN b.booking_status = 'REJECTED' THEN 1 ELSE 0 END) AS rejectedCount, " + + "SUM(CASE WHEN b.booking_status = 'COMPLETED' THEN 1 ELSE 0 END) AS completedCount, " + + "SUM(CASE WHEN b.booking_status = 'CANCELED' THEN 1 ELSE 0 END) AS canceledCount, " + + "SUM(CASE WHEN b.booking_status = 'PAYMENT_FAILURE' THEN 1 ELSE 0 END) AS paymentFailureCount, " + + "SUM(CASE WHEN b.booking_status = 'GCC_BLOCKED' THEN 1 ELSE 0 END) AS gccBlockedCount, " + + "COUNT(b.booking_status) AS totalBookings, " + + "SUM(CASE WHEN b.amount_received IS NULL THEN 0 ELSE b.amount_received END) AS totalAmount " + + "FROM hall_details h LEFT JOIN booking_details b ON b.hall_details_hall_id = h.hall_id WHERE h.zone = :zone AND b.booking_status!='PENDING' " + + + "GROUP BY h.hall_id,h.zone,h.division,h.hall_name") List> getHallDetailsByZone(@Param("zone") String zone); -@Query(value = "SELECT zone,division,hall_id,hall_name FROM hall_details where is_active = 1 ",nativeQuery = true ) + @Query(value = "SELECT zone,division,hall_id,hall_name FROM hall_details where is_active = 1 ", nativeQuery = true) List> getZonesAndDivisions(); + // officer dashboard -//officer dashboard - -@Query(nativeQuery = true, value ="SELECT SUM(CASE WHEN b.booking_status = 'APPROVED' THEN 1 ELSE 0 END) AS approvedCount,\r\n" - + "SUM(CASE WHEN b.booking_status = 'REJECTED' THEN 1 ELSE 0 END) AS rejectedCount,\r\n" - + "SUM(CASE WHEN b.booking_status = 'COMPLETED' THEN 1 ELSE 0 END) AS completedCount, \r\n" - + "SUM(CASE WHEN b.booking_status = 'CANCELED' THEN 1 ELSE 0 END) AS canceledCount, \r\n" - + "SUM(CASE WHEN b.booking_status = 'PAYMENT_FAILURE' THEN 1 ELSE 0 END) AS paymentFailureCount, \r\n" - + "SUM(CASE WHEN b.booking_status = 'GCC_BLOCKED' THEN 1 ELSE 0 END) AS gccBlockedCount,\r\n" - + "COUNT(b.booking_status) AS totalBooking, SUM( CASE WHEN b.amount_received IS NULL THEN 0 ELSE b.amount_received END ) AS amountReceived \r\n" - + "FROM hall_details h LEFT JOIN booking_details b ON b.hall_details_hall_id = h.hall_id WHERE h.zone = :zone AND b.booking_status!='PENDING'") - Map getTotalCountsForOfficer(@Param("zone") String zone); - -@Query(nativeQuery = true, value ="SELECT h.hall_id AS hall_id, h.zone AS zonename,h.division AS division, h.hall_name AS hallName, " + - "SUM(CASE WHEN b.booking_status = 'APPROVED' THEN 1 ELSE 0 END) AS approvedCount, " + - "SUM(CASE WHEN b.booking_status = 'REJECTED' THEN 1 ELSE 0 END) AS rejectedCount, " + - "SUM(CASE WHEN b.booking_status = 'COMPLETED' THEN 1 ELSE 0 END) AS completedCount, " + - "SUM(CASE WHEN b.booking_status = 'CANCELED' THEN 1 ELSE 0 END) AS canceledCount, " + - "SUM(CASE WHEN b.booking_status = 'PAYMENT_FAILURE' THEN 1 ELSE 0 END) AS paymentFailureCount, " + - "SUM(CASE WHEN b.booking_status = 'GCC_BLOCKED' THEN 1 ELSE 0 END) AS gccBlockedCount, " + - "COUNT(b.booking_status) AS totalBookings, " + - "SUM(CASE WHEN b.amount_received IS NULL THEN 0 ELSE b.amount_received END) AS totalAmount " + - "FROM hall_details h LEFT JOIN booking_details b ON b.hall_details_hall_id = h.hall_id WHERE h.zone = :zone AND b.booking_status!='PENDING' "+ - "GROUP BY h.hall_id,h.zone,h.division,h.hall_name") - List> getHallCountsForOfficer(@Param("zone") String zone); + @Query(nativeQuery = true, value = "SELECT SUM(CASE WHEN b.booking_status = 'APPROVED' THEN 1 ELSE 0 END) AS approvedCount,\r\n" + + "SUM(CASE WHEN b.booking_status = 'REJECTED' THEN 1 ELSE 0 END) AS rejectedCount,\r\n" + + "SUM(CASE WHEN b.booking_status = 'COMPLETED' THEN 1 ELSE 0 END) AS completedCount, \r\n" + + "SUM(CASE WHEN b.booking_status = 'CANCELED' THEN 1 ELSE 0 END) AS canceledCount, \r\n" + + "SUM(CASE WHEN b.booking_status = 'PAYMENT_FAILURE' THEN 1 ELSE 0 END) AS paymentFailureCount, \r\n" + + "SUM(CASE WHEN b.booking_status = 'GCC_BLOCKED' THEN 1 ELSE 0 END) AS gccBlockedCount,\r\n" + + "COUNT(b.booking_status) AS totalBooking, SUM( CASE WHEN b.amount_received IS NULL THEN 0 ELSE b.amount_received END ) AS amountReceived \r\n" + + "FROM hall_details h LEFT JOIN booking_details b ON b.hall_details_hall_id = h.hall_id WHERE h.zone = :zone AND b.booking_status!='PENDING'") + Map getTotalCountsForOfficer(@Param("zone") String zone); + + @Query(nativeQuery = true, value = "SELECT h.hall_id AS hall_id, h.zone AS zonename,h.division AS division, h.hall_name AS hallName, " + + + "SUM(CASE WHEN b.booking_status = 'APPROVED' THEN 1 ELSE 0 END) AS approvedCount, " + + "SUM(CASE WHEN b.booking_status = 'REJECTED' THEN 1 ELSE 0 END) AS rejectedCount, " + + "SUM(CASE WHEN b.booking_status = 'COMPLETED' THEN 1 ELSE 0 END) AS completedCount, " + + "SUM(CASE WHEN b.booking_status = 'CANCELED' THEN 1 ELSE 0 END) AS canceledCount, " + + "SUM(CASE WHEN b.booking_status = 'PAYMENT_FAILURE' THEN 1 ELSE 0 END) AS paymentFailureCount, " + + "SUM(CASE WHEN b.booking_status = 'GCC_BLOCKED' THEN 1 ELSE 0 END) AS gccBlockedCount, " + + "COUNT(b.booking_status) AS totalBookings, " + + "SUM(CASE WHEN b.amount_received IS NULL THEN 0 ELSE b.amount_received END) AS totalAmount " + + "FROM hall_details h LEFT JOIN booking_details b ON b.hall_details_hall_id = h.hall_id WHERE h.zone = :zone AND b.booking_status!='PENDING' " + + + "GROUP BY h.hall_id,h.zone,h.division,h.hall_name") + List> getHallCountsForOfficer(@Param("zone") String zone); @Query(value = "SELECT hall_name FROM hall_details WHERE hall_id = :hall_id and is_active = 1 ", nativeQuery = true) String findHallNameById(@Param("hall_id") int hallId); - - @Query("SELECT DISTINCT h.division FROM HallDetails h WHERE h.zone = :zone ") - List findDistinctDivisionsByZone(@Param("zone") String zone); - // Query to get hall names by division - @Query("SELECT h.hallName FROM HallDetails h WHERE h.division = :division and h.isActive = true ") - List findHallsByDivision(@Param("division") String division); + @Query("SELECT DISTINCT h.division FROM HallDetails h WHERE h.zone = :zone ") + List findDistinctDivisionsByZone(@Param("zone") String zone); + + // Query to get hall names by division + @Query("SELECT h.hallName FROM HallDetails h WHERE h.division = :division and h.isActive = true ") + List findHallsByDivision(@Param("division") String division); @Query("SELECT h FROM HallDetails h WHERE h.division = :division and h.isActive = true ") List findActiveHallsByDivision(@Param("division") String division); diff --git a/src/main/java/com/gcc/communityHall/repository/LoginHallIdRepository.java b/src/main/java/com/gcc/communityHall/repository/LoginHallIdRepository.java new file mode 100644 index 00000000..53977a9f --- /dev/null +++ b/src/main/java/com/gcc/communityHall/repository/LoginHallIdRepository.java @@ -0,0 +1,25 @@ +package com.gcc.communityHall.repository; + +import com.gcc.communityHall.entity.LoginHallId; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Modifying; +import org.springframework.data.jpa.repository.Query; +import org.springframework.data.repository.query.Param; +import org.springframework.stereotype.Repository; + +import java.util.List; + +@Repository +public interface LoginHallIdRepository extends JpaRepository { + + @Query(value = "SELECT * FROM login_hall_ids WHERE login_id = :loginId AND is_active = 1 AND is_delete = 0", nativeQuery = true) + List findActiveByLoginId(@Param("loginId") int loginId); + + @Modifying + @Query(value = "UPDATE login_hall_ids SET is_active = 0, is_delete = 1 WHERE login_id = :loginId", nativeQuery = true) + void softDeleteByLoginId(@Param("loginId") int loginId); + + @Modifying + @Query(value = "DELETE FROM login_hall_ids WHERE login_id = :loginId", nativeQuery = true) + void deleteAllByLoginId(@Param("loginId") int loginId); +} diff --git a/src/main/java/com/gcc/communityHall/repository/LoginRepository.java b/src/main/java/com/gcc/communityHall/repository/LoginRepository.java index 425b30b5..7c5046c6 100644 --- a/src/main/java/com/gcc/communityHall/repository/LoginRepository.java +++ b/src/main/java/com/gcc/communityHall/repository/LoginRepository.java @@ -1,21 +1,95 @@ package com.gcc.communityHall.repository; - import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.Query; +import org.springframework.data.repository.query.Param; import org.springframework.stereotype.Repository; import com.gcc.communityHall.entity.Login; +import java.util.List; +import java.util.Map; + @Repository public interface LoginRepository extends JpaRepository { - @Query(value = "SELECT * FROM login where mobile_number=:mobileNo and password=:pin",nativeQuery = true) - Login findByMobileNoAndPin(long mobileNo, String pin); + @Query(value = "SELECT * FROM login where mobile_number=:mobileNo and password=:pin", nativeQuery = true) + Login findByMobileNoAndPin(long mobileNo, String pin); @Query(value = "SELECT a FROM Login a WHERE a.mobileNumber = ?1") 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 LIMIT 1", nativeQuery = true) Login findByUsernameAndPass(String username, String pass); + + @Query(value = "SELECT " + + " l.id, " + + " l.name, " + + " l.mobile_number, " + + " l.user_type, " + + " l.zone, " + + " GROUP_CONCAT( " + + " DISTINCT concat(hd.division,'-',hd.hall_id,'-',hd.hall_name) " + + " ORDER BY hd.hall_name " + + " SEPARATOR ', ' " + + " ) AS hall_names " + + "FROM login l " + + "LEFT JOIN ( " + + " SELECT id AS login_id, hall_id " + + " FROM login " + + " WHERE hall_id IS NOT NULL " + + " UNION ALL " + + " SELECT login_id, hall_id " + + " FROM login_hall_ids " + + " WHERE is_active = 1 " + + " AND is_delete = 0 " + + ") halls ON l.id = halls.login_id " + + "LEFT JOIN hall_details hd " + + " ON halls.hall_id = hd.hall_id " + + "WHERE l.user_type != 'admin' " + + " AND l.is_active = 1 " + + " AND l.is_delete = 0 " + + "GROUP BY l.id, l.name, l.mobile_number, l.user_type, l.zone " + + "ORDER BY cast(l.zone as unsigned)", nativeQuery = true) + List> findActiveLogins(); + + @Query(value = "SELECT * FROM login WHERE id = :id", nativeQuery = true) + Login findLoginById(int id); + + @Query(value = "SELECT COUNT(*) FROM login WHERE mobile_number = :mobileNo AND is_delete = 0", nativeQuery = true) + int countByMobileNumber(@Param("mobileNo") long mobileNo); + + /** + * Returns how many active counter/caretaker logins already own the given hall. + * Checks both login.hall_id and the login_hall_ids join table. + */ + @Query(value = "SELECT COUNT(*) FROM (" + + " SELECT l.id FROM login l " + + " WHERE l.hall_id = :hallId " + + " AND l.user_type = :userType " + + " AND l.is_active = 1 AND l.is_delete = 0 " + + " UNION ALL " + + " SELECT lh.login_id FROM login_hall_ids lh " + + " JOIN login l ON l.id = lh.login_id " + + " WHERE lh.hall_id = :hallId " + + " AND l.user_type = :userType " + + " AND lh.is_active = 1 AND lh.is_delete = 0 " + + " AND l.is_active = 1 AND l.is_delete = 0 " + + ") AS dup", nativeQuery = true) + int countActiveLoginsByHallId(@Param("hallId") int hallId, @Param("userType") String userType); + + @Query(value = "SELECT COUNT(*) FROM (" + + " SELECT l.id FROM login l " + + " WHERE l.hall_id in (:hallId) " + + " AND l.user_type = :userType " + + " AND l.is_active = 1 AND l.is_delete = 0 " + + " UNION ALL " + + " SELECT lh.login_id FROM login_hall_ids lh " + + " JOIN login l ON l.id = lh.login_id " + + " WHERE lh.hall_id in (:hallId) " + + " AND l.user_type = :userType " + + " AND lh.is_active = 1 AND lh.is_delete = 0 " + + " AND l.is_active = 1 AND l.is_delete = 0 " + + ") AS dup", nativeQuery = true) + int getActiveLoginsByHallIds(@Param("hallId") List hallIds, @Param("userType") String userType); } diff --git a/src/main/java/com/gcc/communityHall/repository/PaymentsRepository.java b/src/main/java/com/gcc/communityHall/repository/PaymentsRepository.java index 11df3bd2..b9d99f37 100644 --- a/src/main/java/com/gcc/communityHall/repository/PaymentsRepository.java +++ b/src/main/java/com/gcc/communityHall/repository/PaymentsRepository.java @@ -1,6 +1,5 @@ package com.gcc.communityHall.repository; - import com.gcc.communityHall.entity.Payments; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.Query; @@ -12,17 +11,26 @@ import java.util.Optional; @Repository -public interface PaymentsRepository extends JpaRepository { +public interface PaymentsRepository extends JpaRepository { - @Query(value = "SELECT * FROM payments WHERE payment_status in ('paid') ",nativeQuery = true) + @Query(value = "SELECT * FROM payments WHERE payment_status in ('paid') ", nativeQuery = true) List getPaymentlist(); - @Query(value="SELECT p.* " - + "FROM payments p " - + "JOIN booking_details b ON p.booking_details_booking_id = b.booking_id " - + "JOIN hall_details h ON b.hall_details_hall_id = h.hall_id " - + "WHERE h.zone = :zone", nativeQuery = true) + + @Query(value = "SELECT p.* " + + "FROM payments p " + + "JOIN booking_details b ON p.booking_details_booking_id = b.booking_id " + + "JOIN hall_details h ON b.hall_details_hall_id = h.hall_id " + + "WHERE h.zone = :zone ", nativeQuery = true) List getPaymentListByzone(@Param("zone") String zone); - //List findAllWithBookingDetailsAndUsers(); - @Query(value = "select * from payments where booking_details_booking_id=?",nativeQuery = true) + + @Query(value = "SELECT p.* " + + "FROM payments p " + + "JOIN booking_details b ON p.booking_details_booking_id = b.booking_id " + + "JOIN hall_details h ON b.hall_details_hall_id = h.hall_id " + + "WHERE h.zone = :zone and h.hall_id in (:hallIds)", nativeQuery = true) + List getPaymentListByzoneandHall(@Param("zone") String zone, @Param("hallIds") List hallIds); + + // List findAllWithBookingDetailsAndUsers(); + @Query(value = "select * from payments where booking_details_booking_id=?", nativeQuery = true) Payments findByBookingId(int bookingId); } \ No newline at end of file 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 195e2551..861dd04e 100644 --- a/src/main/java/com/gcc/communityHall/service/Impl/BookingServiceImpl.java +++ b/src/main/java/com/gcc/communityHall/service/Impl/BookingServiceImpl.java @@ -3,6 +3,8 @@ package com.gcc.communityHall.service.Impl; import java.io.File; import java.io.FileOutputStream; import java.io.IOException; +import java.math.BigDecimal; +import java.math.RoundingMode; import java.text.ParseException; import java.text.SimpleDateFormat; import java.time.LocalDate; @@ -1847,6 +1849,9 @@ public class BookingServiceImpl implements BookingService { settlement.setDamageAmount(damageAmount); settlement.setUpdatedId(adminname); double refundamount = book.getDepositAmount() - (updateEbDetails.getEbAmount() + damageAmount); + BigDecimal roundedAmount = BigDecimal.valueOf(refundamount).setScale(2, RoundingMode.HALF_UP); + + refundamount = roundedAmount.doubleValue(); if (refundamount < 0) { settlement.setRefundedAmount(0); settlement.setCollectionPending(Math.abs(refundamount)); diff --git a/src/main/java/com/gcc/communityHall/service/Impl/PaymentsServiceImpl.java b/src/main/java/com/gcc/communityHall/service/Impl/PaymentsServiceImpl.java index efda0ec6..574fd2e8 100644 --- a/src/main/java/com/gcc/communityHall/service/Impl/PaymentsServiceImpl.java +++ b/src/main/java/com/gcc/communityHall/service/Impl/PaymentsServiceImpl.java @@ -15,77 +15,77 @@ import com.gcc.communityHall.entity.Users; import com.gcc.communityHall.repository.PaymentsRepository; import com.gcc.communityHall.service.PaymentsService; -@Service -public class PaymentsServiceImpl implements PaymentsService{ - - private PaymentsRepository paymentsRepository; +@Service +public class PaymentsServiceImpl implements PaymentsService { - @Autowired - public PaymentsServiceImpl(PaymentsRepository paymentsRepository) { - this.paymentsRepository = paymentsRepository; - } + private PaymentsRepository paymentsRepository; - @Override - public List getPaymentsByZone(String zone) { - return paymentsRepository.getPaymentListByzone(zone); - } + @Autowired + public PaymentsServiceImpl(PaymentsRepository paymentsRepository) { + this.paymentsRepository = paymentsRepository; + } - @Override - public List getAllPaymentDetails() { - // List payments = paymentsRepository.findAllWithBookingDetailsAndUsers(); - return null; - } + @Override + public List getPaymentsByZone(String zone) { + return paymentsRepository.getPaymentListByzone(zone); + } - private PaymentsDTO convertToDto(Payments payment) { - PaymentsDTO paymentsDTO = new PaymentsDTO(); - paymentsDTO.setPaymentId(payment.getPaymentId()); - paymentsDTO.setAmountReceived(payment.getAmountReceived()); - paymentsDTO.setTransactionId(payment.getTransactionId()); - paymentsDTO.setPaymentType(payment.getPaymentType()); - paymentsDTO.setPaymentStatus(payment.getPaymentStatus()); - paymentsDTO.setCdate(payment.getCdate()); + @Override + public List getAllPaymentDetails() { + // List payments = + // paymentsRepository.findAllWithBookingDetailsAndUsers(); + return null; + } - BookingDetails bookingDetails = payment.getBookingDetails(); - BookingDetailsDTO bookingDetailsDTO = new BookingDetailsDTO(); - bookingDetailsDTO.setBookingId(bookingDetails.getBookingId()); - bookingDetailsDTO.setNoOfDays(bookingDetails.getNoOfDays()); - bookingDetailsDTO.setStartDate(bookingDetails.getStartDate()); - bookingDetailsDTO.setEndDate(bookingDetails.getEndDate()); - bookingDetailsDTO.setStartingSlot(bookingDetails.getStartingSlot()); - bookingDetailsDTO.setEndingSlot(bookingDetails.getEndingSlot()); - bookingDetailsDTO.setBookingDate(bookingDetails.getBookingDate()); - bookingDetailsDTO.setBookingStatus(bookingDetails.getBookingStatus().name()); - bookingDetailsDTO.setDepositAmount(bookingDetails.getDepositAmount()); - bookingDetailsDTO.setHallAmount(bookingDetails.getHallAmount()); - bookingDetailsDTO.setAmountReceived(bookingDetails.getAmountReceived()); - bookingDetailsDTO.setGst(bookingDetails.getGst()); - bookingDetailsDTO.setApprovedBy(bookingDetails.getApprovedBy()); - bookingDetailsDTO.setRefundStatus(bookingDetails.getRefundStatus().name()); - bookingDetailsDTO.setUpdatedDate(bookingDetails.getUpdatedDate()); - bookingDetailsDTO.setReason(bookingDetails.getReason()); + private PaymentsDTO convertToDto(Payments payment) { + PaymentsDTO paymentsDTO = new PaymentsDTO(); + paymentsDTO.setPaymentId(payment.getPaymentId()); + paymentsDTO.setAmountReceived(payment.getAmountReceived()); + paymentsDTO.setTransactionId(payment.getTransactionId()); + paymentsDTO.setPaymentType(payment.getPaymentType()); + paymentsDTO.setPaymentStatus(payment.getPaymentStatus()); + paymentsDTO.setCdate(payment.getCdate()); - Users user = bookingDetails.getUsers(); - UsersDTO usersDTO = new UsersDTO(); - usersDTO.setUserId(user.getUserId()); - usersDTO.setUserStatus(user.getUserstatus().name()); - usersDTO.setUserType(user.getUsertype().name()); - usersDTO.setName(user.getName()); - usersDTO.setMobileNo(user.getMobileNo()); - usersDTO.setEmail(user.getEmail()); - usersDTO.setDoorNo(user.getDoorNo()); - usersDTO.setStreet(user.getStreet()); - usersDTO.setArea(user.getArea()); - usersDTO.setLocation(user.getLocation()); - usersDTO.setPinCode(user.getPinCode()); - usersDTO.setProfilephoto(user.getProfilephoto()); - usersDTO.setGovernmentId(user.getGovernmentId()); - usersDTO.setActive(user.isActive()); - usersDTO.setCdate(user.getCdate()); + BookingDetails bookingDetails = payment.getBookingDetails(); + BookingDetailsDTO bookingDetailsDTO = new BookingDetailsDTO(); + bookingDetailsDTO.setBookingId(bookingDetails.getBookingId()); + bookingDetailsDTO.setNoOfDays(bookingDetails.getNoOfDays()); + bookingDetailsDTO.setStartDate(bookingDetails.getStartDate()); + bookingDetailsDTO.setEndDate(bookingDetails.getEndDate()); + bookingDetailsDTO.setStartingSlot(bookingDetails.getStartingSlot()); + bookingDetailsDTO.setEndingSlot(bookingDetails.getEndingSlot()); + bookingDetailsDTO.setBookingDate(bookingDetails.getBookingDate()); + bookingDetailsDTO.setBookingStatus(bookingDetails.getBookingStatus().name()); + bookingDetailsDTO.setDepositAmount(bookingDetails.getDepositAmount()); + bookingDetailsDTO.setHallAmount(bookingDetails.getHallAmount()); + bookingDetailsDTO.setAmountReceived(bookingDetails.getAmountReceived()); + bookingDetailsDTO.setGst(bookingDetails.getGst()); + bookingDetailsDTO.setApprovedBy(bookingDetails.getApprovedBy()); + bookingDetailsDTO.setRefundStatus(bookingDetails.getRefundStatus().name()); + bookingDetailsDTO.setUpdatedDate(bookingDetails.getUpdatedDate()); + bookingDetailsDTO.setReason(bookingDetails.getReason()); - bookingDetailsDTO.setUsers(usersDTO); - paymentsDTO.setBookingDetails(bookingDetailsDTO); - return paymentsDTO; - } + Users user = bookingDetails.getUsers(); + UsersDTO usersDTO = new UsersDTO(); + usersDTO.setUserId(user.getUserId()); + usersDTO.setUserStatus(user.getUserstatus().name()); + usersDTO.setUserType(user.getUsertype().name()); + usersDTO.setName(user.getName()); + usersDTO.setMobileNo(user.getMobileNo()); + usersDTO.setEmail(user.getEmail()); + usersDTO.setDoorNo(user.getDoorNo()); + usersDTO.setStreet(user.getStreet()); + usersDTO.setArea(user.getArea()); + usersDTO.setLocation(user.getLocation()); + usersDTO.setPinCode(user.getPinCode()); + usersDTO.setProfilephoto(user.getProfilephoto()); + usersDTO.setGovernmentId(user.getGovernmentId()); + usersDTO.setActive(user.isActive()); + usersDTO.setCdate(user.getCdate()); + bookingDetailsDTO.setUsers(usersDTO); + paymentsDTO.setBookingDetails(bookingDetailsDTO); + return paymentsDTO; + } } diff --git a/src/main/resources/templates/fragments/headquartersMenu.html b/src/main/resources/templates/fragments/headquartersMenu.html index ae063e5e..f8a37a2a 100644 --- a/src/main/resources/templates/fragments/headquartersMenu.html +++ b/src/main/resources/templates/fragments/headquartersMenu.html @@ -24,6 +24,12 @@ User Rejected List + -