From d9358e997e2f159c9c5db71f24bc986078ae1dbd Mon Sep 17 00:00:00 2001 From: AJITHKUMAR12 Date: Thu, 22 Jan 2026 17:30:27 +0530 Subject: [PATCH] building id dynamically and live issue fixed (wrong build & category) booking by user & fixed the changes officerdashboard page for caretaker2 --- .../controller/BookingController.java | 498 +++-- .../coworkspace/controller/controller.java | 1356 ++++++------ .../coworkspace/service/BookingService.java | 1236 ++++++----- src/main/resources/application.properties | 4 +- .../caretaker/officer-dashboard.html | 1860 +++++++++-------- .../templates/user/book-Conferance.html | 1633 ++++++++------- .../templates/user/book-reading.html | 1485 +++++++------ .../templates/user/book-workdesk.html | 35 +- 8 files changed, 4298 insertions(+), 3809 deletions(-) diff --git a/src/main/java/com/gcc/coworkspace/controller/BookingController.java b/src/main/java/com/gcc/coworkspace/controller/BookingController.java index 9107192..12395ee 100644 --- a/src/main/java/com/gcc/coworkspace/controller/BookingController.java +++ b/src/main/java/com/gcc/coworkspace/controller/BookingController.java @@ -1,11 +1,10 @@ package com.gcc.coworkspace.controller; - - import com.gcc.coworkspace.component.UserSession; import com.gcc.coworkspace.configuration.AppConfig; import com.gcc.coworkspace.configuration.QrGenerator; import com.gcc.coworkspace.constants.AppConstants; +import com.gcc.coworkspace.exception.NoSlotAvailable; import com.gcc.coworkspace.service.BookingService; import com.gcc.coworkspace.service.NormalSMS; import com.gcc.coworkspace.service.PaymentService; @@ -50,66 +49,117 @@ public class BookingController { @Autowired private PaymentService paymentService; - + @Autowired private NormalSMS normalSMS; + /* + * @PostMapping("/saveInTemp") + * public Map booking(@RequestParam("catId") int catId, + * + * @RequestParam("buildId") int buildId, + * + * @RequestParam("subId") int subId, + * + * @RequestParam("noOfPeople") int noOfPeople, + * + * @RequestParam("fromDate") LocalDate fromDate, + * + * @RequestParam("toDate") LocalDate toDate, + * + * @RequestParam("userName") String userName, + * + * @RequestParam("userMobile") long userMobile, + * // @RequestParam("amount") double amount, + * + * @RequestParam("slots") List slots) { + * + * System.out.println(catId); + * System.out.println(slots); + * return bookingService.saveTempBooking(userName, userMobile, slots, fromDate, + * toDate, noOfPeople, catId, buildId, + * subId); + * + * } + */ + @PostMapping("/saveInTemp") - public Map booking(@RequestParam("catId") int catId, - @RequestParam("buildId") int buildId, - @RequestParam("subId") int subId, - @RequestParam("noOfPeople") int noOfPeople, - @RequestParam("fromDate") LocalDate fromDate, - @RequestParam("toDate") LocalDate toDate, - @RequestParam("userName") String userName, - @RequestParam("userMobile") long userMobile, - // @RequestParam("amount") double amount, - @RequestParam("slots") List slots){ - - System.out.println(catId); - System.out.println(slots); - return bookingService.saveTempBooking(userName,userMobile, slots, fromDate, toDate,noOfPeople,catId,buildId,subId) ; + public ResponseEntity> booking( + @RequestParam("catId") int catId, + @RequestParam("buildId") int buildId, + @RequestParam("subId") int subId, + @RequestParam("noOfPeople") int noOfPeople, + @RequestParam("fromDate") LocalDate fromDate, + @RequestParam("toDate") LocalDate toDate, + @RequestParam("userName") String userName, + @RequestParam("userMobile") long userMobile, + @RequestParam("slots") List slots) { + System.out.println("buildId" + buildId); + System.out.println("catId" + catId); - } + Map response = new HashMap<>(); -// @PostMapping("/saveBooking") -// public int saveBooking(@RequestParam("tempBookId") int tempBookId){ -// -// return bookingService.saveBooking(tempBookId); -// } -/* - @GetMapping("/checkAvail") - public Boolean checkAvailability(int bid,int cid,LocalDate bDate,int scid,int noOfPerson,int slotId){ - System.out.println("check Availability"); - return bookingService.checkAvailabilityByBdate(bid,cid,bDate,scid,noOfPerson,slotId); + try { + Map result = bookingService.saveTempBooking( + userName, userMobile, slots, + fromDate, toDate, noOfPeople, + catId, buildId, subId); + + response.put("status", "SUCCESS"); + response.putAll(result); + + return ResponseEntity.ok(response); + + } catch (NoSlotAvailable e) { + + response.put("status", "ERROR"); + response.put("message", e.getMessage()); + + return ResponseEntity + .status(HttpStatus.BAD_REQUEST) + .body(response); + } } -*/ - + + // @PostMapping("/saveBooking") + // public int saveBooking(@RequestParam("tempBookId") int tempBookId){ + // + // return bookingService.saveBooking(tempBookId); + // } + /* + * @GetMapping("/checkAvail") + * public Boolean checkAvailability(int bid,int cid,LocalDate bDate,int scid,int + * noOfPerson,int slotId){ + * System.out.println("check Availability"); + * return + * bookingService.checkAvailabilityByBdate(bid,cid,bDate,scid,noOfPerson,slotId) + * ; + * } + */ + @GetMapping("/checkAvail") - public Boolean checkAvailability(int bid,int cid,LocalDate bDate,int scid,int noOfPerson,int slotId){ + public Boolean checkAvailability(int bid, int cid, LocalDate bDate, int scid, int noOfPerson, int slotId) { System.out.println("check Availability"); - return bookingService.checkAvailabilityByBdate(bid,cid,bDate,scid,noOfPerson,slotId); + return bookingService.checkAvailabilityByBdate(bid, cid, bDate, scid, noOfPerson, slotId); } @GetMapping("/hasTodayAttendance") - public ResponseEntity> hasTodayAttendance( + public ResponseEntity> hasTodayAttendance( @RequestParam("buildingid") int buildingid) { boolean exists = bookingService.hasTodayAttendance(buildingid); - Map response = new HashMap<>(); + Map response = new HashMap<>(); response.put("exists", exists); return ResponseEntity.ok(response); } - - @PostMapping(value="/create_order") - public String create_order(HttpServletRequest request,@RequestParam("id") int tempid) throws RazorpayException { + + @PostMapping(value = "/create_order") + public String create_order(HttpServletRequest request, @RequestParam("id") int tempid) throws RazorpayException { // Get data from the service Map tempBookingInfo = bookingService.getTempBookingByTempId(tempid); - // Check if the list is not empty - if (tempBookingInfo!=null && !tempBookingInfo.isEmpty()) { - + if (tempBookingInfo != null && !tempBookingInfo.isEmpty()) { String tempbookid = tempBookingInfo.get("tempbookid").toString(); String amount = tempBookingInfo.get("amount").toString(); @@ -121,54 +171,52 @@ public class BookingController { System.out.println("Invalid number format for amount: " + amount); } - //To enable testing mode in appConstants if required for testing & development - var client = new RazorpayClient(AppConstants.key_id,AppConstants.key_secret); + // To enable testing mode in appConstants if required for testing & development + var client = new RazorpayClient(AppConstants.key_id, AppConstants.key_secret); JSONObject options = new JSONObject(); options.put("amount", amountDouble * 100); options.put("currency", "INR"); Order od = client.orders.create(options); System.out.println(od); - paymentService.saveorderLog(od.get("id").toString(),od.toString(),tempbookid); + paymentService.saveorderLog(od.get("id").toString(), od.toString(), tempbookid); return od.toString(); - } else { System.out.println("No data found for tempid: " + tempid); return "No data found for tempid: " + tempid; } -// return "error"; + // return "error"; } @PostMapping("/Confirm") - public String updateOrder(@RequestBody Map data){ - String tempid=data.get("id").toString();; - String pay_id= data.get("payment_id").toString(); - String order_id=data.get("order_id").toString(); - String status=data.get("status").toString(); - String amount =(Double.parseDouble(data.get("amount").toString())/100)+""; - - int pid = paymentService.savePayment(amount,pay_id,order_id,status,0+"",0+""); + public String updateOrder(@RequestBody Map data) { + String tempid = data.get("id").toString(); + ; + String pay_id = data.get("payment_id").toString(); + String order_id = data.get("order_id").toString(); + String status = data.get("status").toString(); + String amount = (Double.parseDouble(data.get("amount").toString()) / 100) + ""; + + int pid = paymentService.savePayment(amount, pay_id, order_id, status, 0 + "", 0 + ""); try { - int bookingId = bookingser.saveBooking(Integer.parseInt(tempid),pid); -// - // Print or use the values as required - System.out.println("Temp ID: " + tempid); - System.out.println("Booking ID:- "+bookingId); - return bookingId+""; - + int bookingId = bookingser.saveBooking(Integer.parseInt(tempid), pid); + // + // Print or use the values as required + System.out.println("Temp ID: " + tempid); + System.out.println("Booking ID:- " + bookingId); + return bookingId + ""; - }catch (Exception e){ - System.out.println("error: "+e.getMessage()); + } catch (Exception e) { + System.out.println("error: " + e.getMessage()); System.out.println("No booking data found for tempid: " + tempid); return "error"; } } - - //mobile app development + // mobile app development @GetMapping("/bookings") public ResponseEntity>> getBookingsByMobileNo(@RequestParam long mobileNo) { List> bookings = bookingService.getBookingByMobileNo(mobileNo); @@ -177,6 +225,7 @@ public class BookingController { } return ResponseEntity.ok(bookings); // Return 200 with the bookings data } + @GetMapping("/generate-qrcode") public ResponseEntity generateQRCode(@RequestParam(required = true) String booking_id) { if (booking_id == null) { @@ -184,7 +233,7 @@ public class BookingController { } try { // URL for the booking details API - String url = appConfig.getFull_URL()+"/bookingQRCode?booking_id=" + booking_id; + String url = appConfig.getFull_URL() + "/bookingQRCode?booking_id=" + booking_id; // Generate QR code as base64 string String base64QRCode = QrGenerator.generateQRCode(url); @@ -214,15 +263,14 @@ public class BookingController { int otp = rand.nextInt(90000) + 10000; System.out.print("\n otp---:" + otp); - String bodyMessage = normalSMS.sendOTPNsms(mobileNo,otp+""); - + String bodyMessage = normalSMS.sendOTPNsms(mobileNo, otp + ""); + HttpSession session = request.getSession(); session.setAttribute("otp", otp); session.setAttribute("mobileNo", mobileNo); return bodyMessage; } - @GetMapping(value = "/verifyOTP") @ResponseBody public Map verifyOtp(HttpServletRequest request, @RequestParam String otp) { @@ -270,103 +318,103 @@ public class BookingController { return response; } /* - @GetMapping(value = "/verifyOTP") - public String verifyOtp(HttpServletRequest request, @RequestParam String otp) { - HttpSession session = request.getSession(); + * @GetMapping(value = "/verifyOTP") + * public String verifyOtp(HttpServletRequest request, @RequestParam String otp) + * { + * HttpSession session = request.getSession(); + * + * try { + * Integer session_otp = (Integer) session.getAttribute("otp"); + * System.out.println("session_otp---:" + session_otp); + * Integer entered_otp = Integer.parseInt(otp); + * + * if (session_otp != null && session_otp.equals(entered_otp)) { + * System.out.println("Entered OTP Correct"); + * session.setAttribute("verifiedotp", "success"); + * userSession.setMobileno(Long.parseLong(session.getAttribute("mobileNo"). + * toString())); + * return "Success"; + * } else { + * System.out.println("Incorrect OTP. Please enter correct OTPs."); + * session.setAttribute("verifiedotp", "error"); + * return "Error"; + * } + * } catch (NumberFormatException e) { + * System.out.println("Invalid OTP format: " + otp); + * return "Error"; + * } catch (Exception e) { + * System.out.println("Error verifying OTP: " + e.getMessage()); + * return "Error"; + * } + * } + */ - try { - Integer session_otp = (Integer) session.getAttribute("otp"); - System.out.println("session_otp---:" + session_otp); - Integer entered_otp = Integer.parseInt(otp); - - if (session_otp != null && session_otp.equals(entered_otp)) { - System.out.println("Entered OTP Correct"); - session.setAttribute("verifiedotp", "success"); - userSession.setMobileno(Long.parseLong(session.getAttribute("mobileNo").toString())); - return "Success"; - } else { - System.out.println("Incorrect OTP. Please enter correct OTPs."); - session.setAttribute("verifiedotp", "error"); - return "Error"; - } - } catch (NumberFormatException e) { - System.out.println("Invalid OTP format: " + otp); - return "Error"; - } catch (Exception e) { - System.out.println("Error verifying OTP: " + e.getMessage()); - return "Error"; - } - } - */ - // @PostMapping("/validatelogin") - // public ResponseEntity checkLogin(@RequestParam String usernametxt, @RequestParam String passwordtxt, HttpSession session) { - - // try { - // String userName = bookingser.validateLogin(usernametxt, passwordtxt); - - // if (userName != null) { - // // Set user info in the session - // session.setAttribute("mobileno", usernametxt); - // session.setAttribute("user_name",userName ); - - // return ResponseEntity.ok(userName); - // } else { - // return ResponseEntity.status(HttpStatus.EXPECTATION_FAILED).body("error"); - // } - // } catch (Exception e) { - // e.printStackTrace(); - // return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("Internal server error occurred"); - // } - // } + // public ResponseEntity checkLogin(@RequestParam String usernametxt, + // @RequestParam String passwordtxt, HttpSession session) { + // try { + // String userName = bookingser.validateLogin(usernametxt, passwordtxt); - // added by yogi - @PostMapping("/validatelogin") - public ResponseEntity checkLogin( - @RequestParam String usernametxt, - @RequestParam String passwordtxt, - HttpSession session) { + // if (userName != null) { + // // Set user info in the session + // session.setAttribute("mobileno", usernametxt); + // session.setAttribute("user_name",userName ); - try { - Map userData = bookingser.validateLogin(usernametxt, passwordtxt); + // return ResponseEntity.ok(userName); + // } else { + // return ResponseEntity.status(HttpStatus.EXPECTATION_FAILED).body("error"); + // } + // } catch (Exception e) { + // e.printStackTrace(); + // return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("Internal + // server error occurred"); + // } + // } - if (userData != null) { + // added by yogi + @PostMapping("/validatelogin") + public ResponseEntity checkLogin( + @RequestParam String usernametxt, + @RequestParam String passwordtxt, + HttpSession session) { - String userName = (String) userData.get("user_name"); - //Integer bid = (Integer) userData.get("bid"); + try { + Map userData = bookingser.validateLogin(usernametxt, passwordtxt); - // FIX: Convert BID safely - Integer bid = Integer.valueOf(userData.get("bid").toString()); + if (userData != null) { - // Store in session - // Store in session - session.setAttribute("user_name", userName); - session.setAttribute("bid", bid); - // Return clean JSON - Map response = new HashMap<>(); - response.put("status", "success"); - response.put("user_name", userName); - response.put("bid", bid); + String userName = (String) userData.get("user_name"); + // Integer bid = (Integer) userData.get("bid"); + // FIX: Convert BID safely + Integer bid = Integer.valueOf(userData.get("bid").toString()); - System.out.println("Logged in user=" + userName + ", BID=" + bid); + // Store in session + // Store in session + session.setAttribute("user_name", userName); + session.setAttribute("bid", bid); + // Return clean JSON + Map response = new HashMap<>(); + response.put("status", "success"); + response.put("user_name", userName); + response.put("bid", bid); - return ResponseEntity.ok(response); - } else { - return ResponseEntity.status(HttpStatus.EXPECTATION_FAILED).body("error"); - } + System.out.println("Logged in user=" + userName + ", BID=" + bid); - } catch (Exception e) { - e.printStackTrace(); - return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR) - .body("Internal server error occurred"); + return ResponseEntity.ok(response); + } else { + return ResponseEntity.status(HttpStatus.EXPECTATION_FAILED).body("error"); } - } - + } catch (Exception e) { + e.printStackTrace(); + return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR) + .body("Internal server error occurred"); + } + } - //ak + // ak @GetMapping("/bookinghistorydetails") @ResponseBody @@ -374,7 +422,7 @@ public class BookingController { long mobileNo = Long.parseLong(mobileno); return bookingService.getBookingDetailsByMobileNo(mobileNo); } - + @GetMapping("/bookingDetails") @ResponseBody public List> getBookingDetailsByMobileNo(@RequestParam String mobileno) { @@ -383,94 +431,106 @@ public class BookingController { } @GetMapping("/getAvailabilityBySlot") - public List> getAvailabilityBySlot(@RequestParam int scid, @RequestParam String selectedDate) { + public List> getAvailabilityBySlot(@RequestParam int scid, @RequestParam String selectedDate) { return bookingService.getCalendarBasedOnSubCatId(scid, selectedDate); // Replace with the actual view name } - /* @GetMapping("/getbookingdetailDashBoard") - public List> getbookingdetailDashBoard(@RequestParam String fromDate, @RequestParam String toDate, @RequestParam String status) { - return bookingService.getbookingdetailDashBoard(fromDate,toDate, status); - }*/ - //ak + /* + * @GetMapping("/getbookingdetailDashBoard") + * public List> getbookingdetailDashBoard(@RequestParam + * String fromDate, @RequestParam String toDate, @RequestParam String status) { + * return bookingService.getbookingdetailDashBoard(fromDate,toDate, status); + * } + */ + // ak @GetMapping("/getbookingdetailDashBoard") -public List> getbookingdetailDashBoard( - @RequestParam String fromDate, - @RequestParam String toDate, - @RequestParam String status, - @RequestParam int bid) { - System.out.println("fromdate: " + fromDate); - System.out.println("bid: " + bid); - System.out.println("status: " + status); - System.out.println("toDate: " + toDate); - - return bookingService.getbookingdetailDashBoard(fromDate, toDate, status, bid); -} + public List> getbookingdetailDashBoard( + @RequestParam String fromDate, + @RequestParam String toDate, + @RequestParam String status, + @RequestParam int bid) { + System.out.println("fromdate: " + fromDate); + System.out.println("bid: " + bid); + System.out.println("status: " + status); + System.out.println("toDate: " + toDate); + + return bookingService.getbookingdetailDashBoard(fromDate, toDate, status, bid); + } + /* + * @GetMapping("/amountCollected") + * public List> getAmountCollected(@RequestParam("fromDate") + * String fromDate, + * + * @RequestParam("toDate") String toDate) { + * // Convert the string dates to LocalDate + * LocalDate parsedFromDate = LocalDate.parse(fromDate); + * LocalDate parsedToDate = LocalDate.parse(toDate); + * return bookingService.getAmountCollectedByDate(parsedFromDate, parsedToDate); + * } + */ + @GetMapping("/amountCollected") + public List> getAmountCollected( + @RequestParam("fromDate") String fromDate, + @RequestParam("toDate") String toDate, + @RequestParam("bid") int bid) { - /* @GetMapping("/amountCollected") - public List> getAmountCollected(@RequestParam("fromDate") String fromDate, - @RequestParam("toDate") String toDate) { - // Convert the string dates to LocalDate LocalDate parsedFromDate = LocalDate.parse(fromDate); LocalDate parsedToDate = LocalDate.parse(toDate); - return bookingService.getAmountCollectedByDate(parsedFromDate, parsedToDate); - }*/ - @GetMapping("/amountCollected") -public List> getAmountCollected( - @RequestParam("fromDate") String fromDate, - @RequestParam("toDate") String toDate, - @RequestParam("bid") int bid) { - - LocalDate parsedFromDate = LocalDate.parse(fromDate); - LocalDate parsedToDate = LocalDate.parse(toDate); - - return bookingService.getAmountCollectedByDate(parsedFromDate, parsedToDate, bid); -} + return bookingService.getAmountCollectedByDate(parsedFromDate, parsedToDate, bid); + } - /*@GetMapping("/bookingCountByCategory") - public List> getBookingCountsByCategory(@RequestParam("fromDate") String fromDate, - @RequestParam("toDate") String toDate,) { - // Call the service method to get the booking counts for the specified date range - return bookingService.getBookingCountsByCategory(fromDate, toDate); - }*/ - //ak + /* + * @GetMapping("/bookingCountByCategory") + * public List> + * getBookingCountsByCategory(@RequestParam("fromDate") String fromDate, + * + * @RequestParam("toDate") String toDate,) { + * // Call the service method to get the booking counts for the specified date + * range + * return bookingService.getBookingCountsByCategory(fromDate, toDate); + * } + */ + // ak @GetMapping("/bookingCountByCategory") -public List> getBookingCountsByCategory( - @RequestParam("fromDate") String fromDate, - @RequestParam("toDate") String toDate, - @RequestParam("bid") int bid) { + public List> getBookingCountsByCategory( + @RequestParam("fromDate") String fromDate, + @RequestParam("toDate") String toDate, + @RequestParam("bid") int bid) { - return bookingService.getBookingCountsByCategory(fromDate, toDate, bid); -} + return bookingService.getBookingCountsByCategory(fromDate, toDate, bid); + } - /* @GetMapping("/totalBookingCounts") - public List> getBookingCounts(@RequestParam("fromDate") String fromDate,@RequestParam("toDate")String toDate) { - // Call service method to get booking counts - return bookingService.getBookingCountsByDate(fromDate,toDate); - }*/ - //ak + /* + * @GetMapping("/totalBookingCounts") + * public List> getBookingCounts(@RequestParam("fromDate") + * String fromDate,@RequestParam("toDate")String toDate) { + * // Call service method to get booking counts + * return bookingService.getBookingCountsByDate(fromDate,toDate); + * } + */ + // ak @GetMapping("/totalBookingCounts") -public List> getBookingCounts( - @RequestParam("fromDate") String fromDate, - @RequestParam("toDate") String toDate, - @RequestParam("bid") int bid) { + public List> getBookingCounts( + @RequestParam("fromDate") String fromDate, + @RequestParam("toDate") String toDate, + @RequestParam("bid") int bid) { - return bookingService.getBookingCountsByDate(fromDate, toDate, bid); -} + return bookingService.getBookingCountsByDate(fromDate, toDate, bid); + } - @GetMapping("/bookinghistory") - @ResponseBody - public List> getBookingHistory() { - if (userSession != null && userSession.getMobileno() != 0) { - return bookingService.getBookingByMobileNo(userSession.getMobileno()); - } - return Collections.emptyList(); - } - + @ResponseBody + public List> getBookingHistory() { + if (userSession != null && userSession.getMobileno() != 0) { + return bookingService.getBookingByMobileNo(userSession.getMobileno()); + } + return Collections.emptyList(); + } + @GetMapping("/getComplaintsByMobile") public ResponseEntity getComplaintAndUserDetailsByMobile(@RequestParam("mobileNo") String mobileNo) { Map result = bookingService.getComplaintAndUserDetailsByMobile(mobileNo); diff --git a/src/main/java/com/gcc/coworkspace/controller/controller.java b/src/main/java/com/gcc/coworkspace/controller/controller.java index ff41a3f..625fcc4 100644 --- a/src/main/java/com/gcc/coworkspace/controller/controller.java +++ b/src/main/java/com/gcc/coworkspace/controller/controller.java @@ -1,4 +1,5 @@ package com.gcc.coworkspace.controller; + import java.time.LocalDateTime; import java.time.format.DateTimeFormatter; import java.util.List; @@ -15,6 +16,7 @@ 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.coworkspace.exception.NoSlotAvailable; import com.gcc.coworkspace.component.UserSession; import com.gcc.coworkspace.service.BookingService; @@ -26,9 +28,9 @@ import jakarta.servlet.http.HttpServletResponse; import jakarta.servlet.http.HttpSession; @Controller -@RequestMapping(value = {"/","","/muthalvarpadaippagam"}) -public class controller { - +@RequestMapping(value = { "/", "", "/muthalvarpadaippagam" }) +public class controller { + @Autowired private BuildingService buildingSer; @@ -39,17 +41,17 @@ public class controller { HomeService homeService; @Autowired - private ComplaintService complaintService; - + private ComplaintService complaintService; + @Autowired private UserSession userSession; - + @Autowired private Environment environment; - @Value("${app.full_URL}") - private String baseUrl; - + @Value("${app.full_URL}") + private String baseUrl; + private void setNoCacheHeaders(HttpServletResponse response) { response.setHeader("Cache-Control", "no-store, no-cache, must-revalidate, max-age=0"); response.setHeader("Pragma", "no-cache"); @@ -57,390 +59,387 @@ public class controller { } /* - @GetMapping(value = {"/","","/home"}) - public String viewHome(Model model) { - List> spaces = homeService.getActiveCoWorkingSpaces(); - - List> readingZoneDetails = homeService.getPricingDetailsByCid(1); - List> deskSpaceDetails = homeService.getPricingDetailsByCid(2); - List> conferenceHallDetails = homeService.getPricingDetailsByCid(3); - - model.addAttribute("readingZoneDetails", readingZoneDetails); - model.addAttribute("deskSpaceDetails", deskSpaceDetails); - model.addAttribute("conferenceHallDetails", conferenceHallDetails); - model.addAttribute("homeImg",homeService.getImgByCid(0)); + * @GetMapping(value = {"/","","/home"}) + * public String viewHome(Model model) { + * List> spaces = homeService.getActiveCoWorkingSpaces(); + * + * List> readingZoneDetails = + * homeService.getPricingDetailsByCid(1); + * List> deskSpaceDetails = + * homeService.getPricingDetailsByCid(2); + * List> conferenceHallDetails = + * homeService.getPricingDetailsByCid(3); + * + * model.addAttribute("readingZoneDetails", readingZoneDetails); + * model.addAttribute("deskSpaceDetails", deskSpaceDetails); + * model.addAttribute("conferenceHallDetails", conferenceHallDetails); + * model.addAttribute("homeImg",homeService.getImgByCid(0)); + * + * model.addAttribute("spaces", spaces); + * return "user/home"; + * } + * + */ + // @GetMapping(value = {"/", "", "/workspacelist"}) + // public String viewWorkspaclist(@RequestParam(value = "cid", required = false) + // Integer cidParam, Model model) { + // List> spaces = homeService.getActiveCoWorkingSpaces(bid); + // List> readingZoneDetails = + // homeService.getPricingDetailsByCid(1); + // List> deskSpaceDetails = + // homeService.getPricingDetailsByCid(2); + // List> conferenceHallDetails = + // homeService.getPricingDetailsByCid(3); + + // // Default to Learning Centre (cid = 1) + // Integer cid = (cidParam != null) ? cidParam : 2; + + // // Set type + // for (Map space : spaces) { + // Integer categoryId = (Integer) space.get("cid"); + // if (categoryId != null) { + // switch (categoryId) { + // case 1 -> space.put("type", "reading"); + // case 2 -> space.put("type", "desk"); + // case 3 -> space.put("type", "meeting"); + // default -> space.put("type", "learning"); + // } + // } + // } - model.addAttribute("spaces", spaces); - return "user/home"; - } + // final Integer finalCid = cid; // ✅ Now this is effectively final + // Map selectedSpace = spaces.stream() + // .filter(space -> finalCid.equals(space.get("cid"))) + // .findFirst() + // .orElse(null); + + // model.addAttribute("cid", cid); + // model.addAttribute("spaces", spaces); + // model.addAttribute("selectedSpace", selectedSpace); + // model.addAttribute("readingZoneDetails", readingZoneDetails); + // model.addAttribute("deskSpaceDetails", deskSpaceDetails); + // model.addAttribute("conferenceHallDetails", conferenceHallDetails); + // model.addAttribute("homeImg",homeService.getImgByCid(0)); + // return "user/workspacelist"; + // } - */ - // @GetMapping(value = {"/", "", "/workspacelist"}) - // public String viewWorkspaclist(@RequestParam(value = "cid", required = false) Integer cidParam, Model model) { - // List> spaces = homeService.getActiveCoWorkingSpaces(bid); - // List> readingZoneDetails = homeService.getPricingDetailsByCid(1); - // List> deskSpaceDetails = homeService.getPricingDetailsByCid(2); - // List> conferenceHallDetails = homeService.getPricingDetailsByCid(3); + @GetMapping(value = { "/", "", "/workspacelist" }) + public String viewWorkspaceList(Model model) { + // ✅ Get all active buildings (for workspace list page) + List> buildingList = buildingSer.getBuildingDetails(); - // // Default to Learning Centre (cid = 1) - // Integer cid = (cidParam != null) ? cidParam : 2; + // ✅ You can also fetch coworking space categories (if needed to show as tabs or + // filters) + List> spaces = homeService.getActiveCoWorkingSpaces(); - // // Set type - // for (Map space : spaces) { - // Integer categoryId = (Integer) space.get("cid"); - // if (categoryId != null) { - // switch (categoryId) { - // case 1 -> space.put("type", "reading"); - // case 2 -> space.put("type", "desk"); - // case 3 -> space.put("type", "meeting"); - // default -> space.put("type", "learning"); - // } - // } - // } + // ✅ Add to model + model.addAttribute("buildings", buildingList); + model.addAttribute("spaces", spaces); - // final Integer finalCid = cid; // ✅ Now this is effectively final - // Map selectedSpace = spaces.stream() - // .filter(space -> finalCid.equals(space.get("cid"))) - // .findFirst() - // .orElse(null); + // ✅ Return the list page (user/workspacelist.html) + return "user/workspacelist"; + } - // model.addAttribute("cid", cid); - // model.addAttribute("spaces", spaces); - // model.addAttribute("selectedSpace", selectedSpace); - // model.addAttribute("readingZoneDetails", readingZoneDetails); - // model.addAttribute("deskSpaceDetails", deskSpaceDetails); - // model.addAttribute("conferenceHallDetails", conferenceHallDetails); - // model.addAttribute("homeImg",homeService.getImgByCid(0)); - // return "user/workspacelist"; + // @GetMapping(value = { "/home"}) + // public String viewHome(@RequestParam int bid,@RequestParam(value = "cid", + // required = false) Integer cidParam, Model model) { + // List> spaces = homeService.getActiveCoWorkingSpaces(); + // List> readingZoneDetails = + // homeService.getPricingDetailsByCid(1); + // List> deskSpaceDetails = + // homeService.getPricingDetailsByCid(2); + // List> conferenceHallDetails = + // homeService.getPricingDetailsByCid(3); + + // // Default to Learning Centre (cid = 1) + // Integer cid = (cidParam != null) ? cidParam : 2; + + // // Set type + // for (Map space : spaces) { + // Integer categoryId = (Integer) space.get("cid"); + // if (categoryId != null) { + // switch (categoryId) { + // case 1 -> space.put("type", "reading"); + // case 2 -> space.put("type", "desk"); + // case 3 -> space.put("type", "meeting"); + // default -> space.put("type", "learning"); + // } + // } // } - - @GetMapping(value = {"/", "", "/workspacelist"}) -public String viewWorkspaceList(Model model) { - - // ✅ Get all active buildings (for workspace list page) - List> buildingList = buildingSer.getBuildingDetails(); - // ✅ You can also fetch coworking space categories (if needed to show as tabs or filters) - List> spaces = homeService.getActiveCoWorkingSpaces(); + // final Integer finalCid = cid; // ✅ Now this is effectively final + // Map selectedSpace = spaces.stream() + // .filter(space -> finalCid.equals(space.get("cid"))) + // .findFirst() + // .orElse(null); + + // model.addAttribute("cid", cid); + // model.addAttribute("bid", bid); + // model.addAttribute("spaces", spaces); + // model.addAttribute("selectedSpace", selectedSpace); + // model.addAttribute("readingZoneDetails", readingZoneDetails); + // model.addAttribute("deskSpaceDetails", deskSpaceDetails); + // model.addAttribute("conferenceHallDetails", conferenceHallDetails); + // model.addAttribute("homeImg",homeService.getImgByCid(0)); + // return "user/home"; + // } - // ✅ Add to model - model.addAttribute("buildings", buildingList); - model.addAttribute("spaces", spaces); + @GetMapping("/home") + public String viewHomeGet(@RequestParam(value = "bid", required = false) Integer bid, + @RequestParam(value = "cid", required = false) Integer cidParam, + Model model) { + if (bid == null) { + return "redirect:/muthalvarpadaippagam"; // or show error page + } - // ✅ Return the list page (user/workspacelist.html) - return "user/workspacelist"; -} + return loadHomePage(bid, cidParam, model); + } + // POST – used by hidden form (no URL params visible!) + @PostMapping("/home") + public String viewHomePost(@RequestParam int bid, + @RequestParam(value = "cid", required = false) Integer cidParam, + Model model) { + return loadHomePage(bid, cidParam, model); + } - + // previously used + // @GetMapping("/home") + // public String viewHome(@RequestParam int bid, + // @RequestParam(value = "cid", required = false) Integer cidParam, + // Model model) { + + // // ✅ Get coworking spaces for this building + // List> spaces = + // homeService.getActiveCoWorkingSpacesByBuilding(bid); + + // //System.out.println("home inside:" + spaces); + + // // Remove duplicate category rows (keep first per cid) + // spaces = spaces.stream() + // .collect(Collectors.toMap( + // m -> (Integer) m.get("cid"), + // m -> m, + // (existing, replacement) -> existing + // )) + // .values() + // .stream() + // .toList(); + // // ✅ Default CID → first space of that building + // Integer cid = (cidParam != null) + // ? cidParam + // : (spaces.isEmpty() ? null : (Integer) spaces.get(0).get("cid")); + + // // ✅ Get subcategory (pricing/capacity) details for this category + // /*List> pricingDetails = (cid != null) + // ? homeService.getPricingDetailsByCid(cid) + // : List.of();*/ + // List> readingZoneDetails = + // homeService.getPricingDetailsByCid(cid); + // List> deskSpaceDetails = + // homeService.getPricingDetailsByCid(cid); + // List> conferenceHallDetails = + // homeService.getPricingDetailsByCid(cid); + + // // ✅ Get category images for this category + // List> homeImg = (cid != null) + // ? homeService.getImgByCid(cid) + // : List.of(); + + // // ✅ Identify the selected space + // Map selectedSpace = spaces.stream() + // .filter(space -> cid != null && cid.equals(space.get("cid"))) + // .findFirst() + // .orElse(null); + // //ak + + // // ✅ Add everything to model + // model.addAttribute("bid", bid); + // model.addAttribute("cid", cid); + // model.addAttribute("spaces", spaces); + // System.out.println("spaces:" + spaces); + // model.addAttribute("selectedSpace", selectedSpace); + // //model.addAttribute("pricingDetails", pricingDetails); + // model.addAttribute("readingZoneDetails", readingZoneDetails); + // model.addAttribute("deskSpaceDetails", deskSpaceDetails); + // model.addAttribute("conferenceHallDetails", conferenceHallDetails); + // model.addAttribute("homeImg", homeImg); + + // return "user/home"; + // } + // 🔥 Reusable method + private String loadHomePage(int bid, Integer cidParam, Model model) { + + // Get coworking spaces for this building + List> spaces = homeService.getActiveCoWorkingSpacesByBuilding(bid); + + // Remove duplicate CIDs + spaces = spaces.stream() + .collect(Collectors.toMap( + m -> (Integer) m.get("cid"), + m -> m, + (existing, replacement) -> existing)) + .values() + .stream() + .toList(); + + // Default CID + Integer cid = (cidParam != null) + ? cidParam + : (spaces.isEmpty() ? null : (Integer) spaces.get(0).get("cid")); + + // Pricing details + List> readingZoneDetails = homeService.getPricingDetailsByCid(cid); + List> deskSpaceDetails = homeService.getPricingDetailsByCid(cid); + List> conferenceHallDetails = homeService.getPricingDetailsByCid(cid); + + // Images + List> homeImg = (cid != null) + ? homeService.getImgByCid(cid) + : List.of(); + + // Selected category + Map selectedSpace = spaces.stream() + .filter(space -> cid != null && cid.equals(space.get("cid"))) + .findFirst() + .orElse(null); + + // Add to model + model.addAttribute("bid", bid); + model.addAttribute("cid", cid); + model.addAttribute("spaces", spaces); + model.addAttribute("selectedSpace", selectedSpace); + model.addAttribute("readingZoneDetails", readingZoneDetails); + model.addAttribute("deskSpaceDetails", deskSpaceDetails); + model.addAttribute("conferenceHallDetails", conferenceHallDetails); + model.addAttribute("homeImg", homeImg); + return "user/home"; // Thymeleaf view + } + // ak + @GetMapping("/api/pricing") + @ResponseBody + public List> getPricingDetails(@RequestParam int cid) { + return homeService.getPricingDetailsByCid(cid); + } + // @GetMapping("/book") + // public String showCategoryPage(@RequestParam int buildingId,@RequestParam int + // categoryId, Model model) { + // List> buildingCategoryDetails = + // buildingSer.getBuildingCategoryDetailsById(buildingId,categoryId); // + // Retrieve data + // model.addAttribute("homeImg",homeService.getImgByCid(categoryId)); + // + // if (!buildingCategoryDetails.isEmpty()) { + // model.addAttribute("details", buildingCategoryDetails.get(0)); // Pass the + // first item to the model + // // model.addAttribute("subcategories", + // buildingCategoryDetails.get(0).get("Subcategories")); // Assuming you have a + // list of subcategories + // } + // return "user/booking"; // Return the view + // } - // @GetMapping(value = { "/home"}) - // public String viewHome(@RequestParam int bid,@RequestParam(value = "cid", required = false) Integer cidParam, Model model) { - // List> spaces = homeService.getActiveCoWorkingSpaces(); - // List> readingZoneDetails = homeService.getPricingDetailsByCid(1); - // List> deskSpaceDetails = homeService.getPricingDetailsByCid(2); - // List> conferenceHallDetails = homeService.getPricingDetailsByCid(3); - - - // // Default to Learning Centre (cid = 1) - // Integer cid = (cidParam != null) ? cidParam : 2; - - // // Set type - // for (Map space : spaces) { - // Integer categoryId = (Integer) space.get("cid"); - // if (categoryId != null) { - // switch (categoryId) { - // case 1 -> space.put("type", "reading"); - // case 2 -> space.put("type", "desk"); - // case 3 -> space.put("type", "meeting"); - // default -> space.put("type", "learning"); - // } - // } - // } - - // final Integer finalCid = cid; // ✅ Now this is effectively final - // Map selectedSpace = spaces.stream() - // .filter(space -> finalCid.equals(space.get("cid"))) - // .findFirst() - // .orElse(null); - - // model.addAttribute("cid", cid); - // model.addAttribute("bid", bid); - // model.addAttribute("spaces", spaces); - // model.addAttribute("selectedSpace", selectedSpace); - // model.addAttribute("readingZoneDetails", readingZoneDetails); - // model.addAttribute("deskSpaceDetails", deskSpaceDetails); - // model.addAttribute("conferenceHallDetails", conferenceHallDetails); - // model.addAttribute("homeImg",homeService.getImgByCid(0)); - // return "user/home"; - // } - - - -@GetMapping("/home") -public String viewHomeGet(@RequestParam(value = "bid", required = false) Integer bid, - @RequestParam(value = "cid", required = false) Integer cidParam, - Model model) { - if (bid == null) { - return "redirect:/muthalvarpadaippagam"; // or show error page - } - - - return loadHomePage(bid, cidParam, model); -} - // POST – used by hidden form (no URL params visible!) - @PostMapping("/home") - public String viewHomePost(@RequestParam int bid, - @RequestParam(value = "cid", required = false) Integer cidParam, - Model model) { - return loadHomePage(bid, cidParam, model); - } - - - -// previously used -// @GetMapping("/home") -// public String viewHome(@RequestParam int bid, -// @RequestParam(value = "cid", required = false) Integer cidParam, -// Model model) { - -// // ✅ Get coworking spaces for this building -// List> spaces = homeService.getActiveCoWorkingSpacesByBuilding(bid); - - -// //System.out.println("home inside:" + spaces); - -// // Remove duplicate category rows (keep first per cid) -// spaces = spaces.stream() -// .collect(Collectors.toMap( -// m -> (Integer) m.get("cid"), -// m -> m, -// (existing, replacement) -> existing -// )) -// .values() -// .stream() -// .toList(); -// // ✅ Default CID → first space of that building -// Integer cid = (cidParam != null) -// ? cidParam -// : (spaces.isEmpty() ? null : (Integer) spaces.get(0).get("cid")); - -// // ✅ Get subcategory (pricing/capacity) details for this category -// /*List> pricingDetails = (cid != null) -// ? homeService.getPricingDetailsByCid(cid) -// : List.of();*/ -// List> readingZoneDetails = homeService.getPricingDetailsByCid(cid); -// List> deskSpaceDetails = homeService.getPricingDetailsByCid(cid); -// List> conferenceHallDetails = homeService.getPricingDetailsByCid(cid); - -// // ✅ Get category images for this category -// List> homeImg = (cid != null) -// ? homeService.getImgByCid(cid) -// : List.of(); - -// // ✅ Identify the selected space -// Map selectedSpace = spaces.stream() -// .filter(space -> cid != null && cid.equals(space.get("cid"))) -// .findFirst() -// .orElse(null); -// //ak - - - -// // ✅ Add everything to model -// model.addAttribute("bid", bid); -// model.addAttribute("cid", cid); -// model.addAttribute("spaces", spaces); -// System.out.println("spaces:" + spaces); -// model.addAttribute("selectedSpace", selectedSpace); -// //model.addAttribute("pricingDetails", pricingDetails); -// model.addAttribute("readingZoneDetails", readingZoneDetails); -// model.addAttribute("deskSpaceDetails", deskSpaceDetails); -// model.addAttribute("conferenceHallDetails", conferenceHallDetails); -// model.addAttribute("homeImg", homeImg); - - - -// return "user/home"; -// } - - - - // 🔥 Reusable method - private String loadHomePage(int bid, Integer cidParam, Model model) { - - // Get coworking spaces for this building - List> spaces = homeService.getActiveCoWorkingSpacesByBuilding(bid); - - // Remove duplicate CIDs - spaces = spaces.stream() - .collect(Collectors.toMap( - m -> (Integer) m.get("cid"), - m -> m, - (existing, replacement) -> existing - )) - .values() - .stream() - .toList(); - - // Default CID - Integer cid = (cidParam != null) - ? cidParam - : (spaces.isEmpty() ? null : (Integer) spaces.get(0).get("cid")); - - // Pricing details - List> readingZoneDetails = homeService.getPricingDetailsByCid(cid); - List> deskSpaceDetails = homeService.getPricingDetailsByCid(cid); - List> conferenceHallDetails = homeService.getPricingDetailsByCid(cid); - - // Images - List> homeImg = (cid != null) - ? homeService.getImgByCid(cid) - : List.of(); - - // Selected category - Map selectedSpace = spaces.stream() - .filter(space -> cid != null && cid.equals(space.get("cid"))) - .findFirst() - .orElse(null); - - // Add to model - model.addAttribute("bid", bid); - model.addAttribute("cid", cid); - model.addAttribute("spaces", spaces); - model.addAttribute("selectedSpace", selectedSpace); - model.addAttribute("readingZoneDetails", readingZoneDetails); - model.addAttribute("deskSpaceDetails", deskSpaceDetails); - model.addAttribute("conferenceHallDetails", conferenceHallDetails); - model.addAttribute("homeImg", homeImg); - - return "user/home"; // Thymeleaf view - } - -//ak -@GetMapping("/api/pricing") -@ResponseBody -public List> getPricingDetails(@RequestParam int cid) { - return homeService.getPricingDetailsByCid(cid); -} - - - - -// @GetMapping("/book") -// public String showCategoryPage(@RequestParam int buildingId,@RequestParam int categoryId, Model model) { -// List> buildingCategoryDetails = buildingSer.getBuildingCategoryDetailsById(buildingId,categoryId); // Retrieve data -// model.addAttribute("homeImg",homeService.getImgByCid(categoryId)); -// -// if (!buildingCategoryDetails.isEmpty()) { -// model.addAttribute("details", buildingCategoryDetails.get(0)); // Pass the first item to the model -// // model.addAttribute("subcategories", buildingCategoryDetails.get(0).get("Subcategories")); // Assuming you have a list of subcategories -// } -// return "user/booking"; // Return the view -// } - -// @GetMapping("/book") -// public String showCategoryPage(@RequestParam int buildingId,@RequestParam int categoryId, Model model) { -// List> buildingCategoryDetails = buildingSer.getBuildingCategoryDetailsById(buildingId,categoryId); // Retrieve data -// model.addAttribute("homeImg",homeService.getImgByCid(categoryId)); -// -// if (!buildingCategoryDetails.isEmpty()) { -// model.addAttribute("details", buildingCategoryDetails.get(0)); // Pass the first item to the model -// // model.addAttribute("subcategories", buildingCategoryDetails.get(0).get("Subcategories")); // Assuming you have a list of subcategories -// } -// return "user/booking"; // Return the view -// } + // @GetMapping("/book") + // public String showCategoryPage(@RequestParam int buildingId,@RequestParam int + // categoryId, Model model) { + // List> buildingCategoryDetails = + // buildingSer.getBuildingCategoryDetailsById(buildingId,categoryId); // + // Retrieve data + // model.addAttribute("homeImg",homeService.getImgByCid(categoryId)); + // + // if (!buildingCategoryDetails.isEmpty()) { + // model.addAttribute("details", buildingCategoryDetails.get(0)); // Pass the + // first item to the model + // // model.addAttribute("subcategories", + // buildingCategoryDetails.get(0).get("Subcategories")); // Assuming you have a + // list of subcategories + // } + // return "user/booking"; // Return the view + // } // Endpoint to fetch space content for AJAX // @GetMapping("/home/space") - // public String getSpaceFragment(@RequestParam("cid") Integer cid, Model model) { - // List> spaces = homeService.getActiveCoWorkingSpaces(); - - // // Filter the selected space - // Map selectedSpace = spaces.stream() - // .filter(space -> cid.equals(space.get("cid"))) - // .findFirst() - // .orElse(null); - - // model.addAttribute("space", selectedSpace); - // return "fragments/spaceContent :: content"; + // public String getSpaceFragment(@RequestParam("cid") Integer cid, Model model) + // { + // List> spaces = homeService.getActiveCoWorkingSpaces(); + + // // Filter the selected space + // Map selectedSpace = spaces.stream() + // .filter(space -> cid.equals(space.get("cid"))) + // .findFirst() + // .orElse(null); + + // model.addAttribute("space", selectedSpace); + // return "fragments/spaceContent :: content"; // } - - // @GetMapping("/home/space") // public String getSpaceFragment(@RequestParam("cid") Integer cid, - // @RequestParam("bid") Integer bid, - // Model model) { - // List> spaces = homeService.getActiveCoWorkingSpaces(); - - // Map selectedSpace = spaces.stream() - // .filter(space -> cid.equals(space.get("cid"))) - // .findFirst() - // .orElse(null); - - // model.addAttribute("space", selectedSpace); - // model.addAttribute("bid", bid); // ✅ Add buildingId - // model.addAttribute("cid", cid); - // return "fragments/spaceContent :: content"; + // @RequestParam("bid") Integer bid, + // Model model) { + // List> spaces = homeService.getActiveCoWorkingSpaces(); + + // Map selectedSpace = spaces.stream() + // .filter(space -> cid.equals(space.get("cid"))) + // .findFirst() + // .orElse(null); + + // model.addAttribute("space", selectedSpace); + // model.addAttribute("bid", bid); // ✅ Add buildingId + // model.addAttribute("cid", cid); + // return "fragments/spaceContent :: content"; // } - - @GetMapping("/home/space") -public String getSpaceFragment(@RequestParam("cid") Integer cid, - @RequestParam("bid") Integer bid, - Model model) { - - // ✅ Get spaces for this specific building - List> spaces = homeService.getActiveCoWorkingSpacesByBuilding(bid); - - //System.out.println("home spaces inside:" + spaces); - Map selectedSpace = spaces.stream() - .filter(space -> cid.equals(space.get("cid"))) - .findFirst() - .orElse(null); + public String getSpaceFragment(@RequestParam("cid") Integer cid, + @RequestParam("bid") Integer bid, + Model model) { - // System.out.println("selectedSpace :" + selectedSpace); + // ✅ Get spaces for this specific building + List> spaces = homeService.getActiveCoWorkingSpacesByBuilding(bid); - model.addAttribute("space", selectedSpace); - model.addAttribute("bid", bid); - model.addAttribute("cid", cid); + // System.out.println("home spaces inside:" + spaces); + Map selectedSpace = spaces.stream() + .filter(space -> cid.equals(space.get("cid"))) + .findFirst() + .orElse(null); - return "fragments/spaceContent :: content"; -} + // System.out.println("selectedSpace :" + selectedSpace); + model.addAttribute("space", selectedSpace); + model.addAttribute("bid", bid); + model.addAttribute("cid", cid); -// @GetMapping("/home/space") -// public String getSpaceFragment(@RequestParam("cid") Integer cid, -// @RequestParam("bid") Integer bid, -// Model model) { - -// List> pricingDetails = homeService.getPricingDetailsByCid(cid); -// List> images = homeService.getImgByCid(cid); - -// model.addAttribute("pricingDetails", pricingDetails); -// model.addAttribute("homeImg", images); + return "fragments/spaceContent :: content"; + } -// return "fragments/spaceContent :: content"; -// } + // @GetMapping("/home/space") + // public String getSpaceFragment(@RequestParam("cid") Integer cid, + // @RequestParam("bid") Integer bid, + // Model model) { + // List> pricingDetails = + // homeService.getPricingDetailsByCid(cid); + // List> images = homeService.getImgByCid(cid); + // model.addAttribute("pricingDetails", pricingDetails); + // model.addAttribute("homeImg", images); + // return "fragments/spaceContent :: content"; + // } - @GetMapping("/registercomplaint") public String registercomplaint(Model model, HttpSession session) { String userName = (String) session.getAttribute("user_name"); return "user/registercomplaint"; } - - //complaintlist in caretaker side + + // complaintlist in caretaker side @GetMapping("/complaintlist") public String complaintlist(Model model, HttpSession session) { String userName = (String) session.getAttribute("user_name"); @@ -450,7 +449,7 @@ public String getSpaceFragment(@RequestParam("cid") Integer cid, List> complaintlist = complaintService.getOpenComplaintList(); - List> closedcomplaintlist = complaintService.getClosedComplaintList(); + List> closedcomplaintlist = complaintService.getClosedComplaintList(); // Append base URL to each complaint's upload_photo_url for (Map complaint : complaintlist) { @@ -476,66 +475,66 @@ public String getSpaceFragment(@RequestParam("cid") Integer cid, } } - model.addAttribute("complaintlist", complaintlist); - model.addAttribute("closedcomplaintlist",closedcomplaintlist); + model.addAttribute("closedcomplaintlist", closedcomplaintlist); return "caretaker/complaintlist"; } else { return "redirect:/muthalvarpadaippagam/officiallogin"; } } - - //attendancereport + + // attendancereport @GetMapping("/attendancereport") public String attendancereport(Model model, HttpSession session) { String userName = (String) session.getAttribute("user_name"); - Integer bid = (Integer) session.getAttribute("bid"); // ✅ get BID from session + Integer bid = (Integer) session.getAttribute("bid"); // ✅ get BID from session // Check if the user is logged in if (userName != null && !userName.isEmpty()) { model.addAttribute("user_name", userName); - model.addAttribute("bid", bid); - return "caretaker/attendancereport"; // Render the report page + model.addAttribute("bid", bid); + return "caretaker/attendancereport"; // Render the report page } else { - return "redirect:/muthalvarpadaippagam/officiallogin"; // Redirect to login if not logged in + return "redirect:/muthalvarpadaippagam/officiallogin"; // Redirect to login if not logged in } } @GetMapping("/attendance") public String attendancePage(Model model, HttpSession session) { String userName = (String) session.getAttribute("user_name"); - Integer bid = (Integer) session.getAttribute("bid"); // ✅ get BID from session + Integer bid = (Integer) session.getAttribute("bid"); // ✅ get BID from session // Check if the user is logged in if (userName != null && !userName.isEmpty()) { - //Integer bid = bookingService.getBidByUserName(userName); + // Integer bid = bookingService.getBidByUserName(userName); - model.addAttribute("user_name", userName); - model.addAttribute("bid", bid); + model.addAttribute("user_name", userName); + model.addAttribute("bid", bid); - // (optional) store bid in session for later use - //session.setAttribute("bid", bid); - //model.addAttribute("user_name", userName); - return "caretaker/attendance"; // Render the report page + // (optional) store bid in session for later use + // session.setAttribute("bid", bid); + // model.addAttribute("user_name", userName); + return "caretaker/attendance"; // Render the report page } else { - return "redirect:/muthalvarpadaippagam/officiallogin"; // Redirect to login if not logged in + return "redirect:/muthalvarpadaippagam/officiallogin"; // Redirect to login if not logged in } } - - //checklist - /* - @GetMapping("/CheckList") - public String CheckList(Model model, HttpSession session) { - String userName = (String) session.getAttribute("user_name"); - // Check if the user is logged in - if (userName != null && !userName.isEmpty()) { - model.addAttribute("user_name", userName); - return "caretaker/CheckList"; // Render the report page - } else { - return "redirect:/muthalvarpadaippagam/officiallogin"; // Redirect to login if not logged in - } - } - */ + // checklist + /* + * @GetMapping("/CheckList") + * public String CheckList(Model model, HttpSession session) { + * String userName = (String) session.getAttribute("user_name"); + * + * // Check if the user is logged in + * if (userName != null && !userName.isEmpty()) { + * model.addAttribute("user_name", userName); + * return "caretaker/CheckList"; // Render the report page + * } else { + * return "redirect:/muthalvarpadaippagam/officiallogin"; // Redirect to login + * if not logged in + * } + * } + */ @GetMapping("/CheckList") public String CheckList(Model model, HttpSession session) { String userName = (String) session.getAttribute("user_name"); @@ -543,17 +542,18 @@ public String getSpaceFragment(@RequestParam("cid") Integer cid, // Check if the user is logged in if (userName != null && !userName.isEmpty()) { model.addAttribute("user_name", userName); - //model.addAttribute("serverDate", LocalDate.now().toString()); + // model.addAttribute("serverDate", LocalDate.now().toString()); DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); String dateTimeNow = LocalDateTime.now().format(formatter); model.addAttribute("serverDate", dateTimeNow); - return "caretaker/CheckList"; // Render the report page + return "caretaker/CheckList"; // Render the report page } else { - return "redirect:/muthalvarpadaippagam/officiallogin"; // Redirect to login if not logged in + return "redirect:/muthalvarpadaippagam/officiallogin"; // Redirect to login if not logged in } } - //CheckListReport + + // CheckListReport @GetMapping("/CheckListReport") public String CheckListReport(Model model, HttpSession session) { String userName = (String) session.getAttribute("user_name"); @@ -561,280 +561,277 @@ public String getSpaceFragment(@RequestParam("cid") Integer cid, // Check if the user is logged in if (userName != null && !userName.isEmpty()) { model.addAttribute("user_name", userName); - return "caretaker/CheckListReport"; // Render the report page + return "caretaker/CheckListReport"; // Render the report page } else { - return "redirect:/muthalvarpadaippagam/officiallogin"; // Redirect to login if not logged in + return "redirect:/muthalvarpadaippagam/officiallogin"; // Redirect to login if not logged in } } - - // @GetMapping("/book") - // public String showCategoryPage(@RequestParam int buildingId,@RequestParam int categoryId, Model model) { - // String url=""; - // List> buildingCategoryDetails = buildingSer.getBuildingCategoryDetailsById(buildingId,categoryId); // Retrieve data - // model.addAttribute("homeImg",homeService.getImgByCid(categoryId)); - - // if (!buildingCategoryDetails.isEmpty()) { - // model.addAttribute("details", buildingCategoryDetails.get(0)); // Pass the first item to the model - // } - // // if(categoryId==1) { // Reading / Leaning Zone - // // url = "user/book-reading"; // Return the view - // // } - // // if(categoryId==2) { // Reading / Leaning Zone - // // url = "user/book-workdesk"; // Return the view - // // } - // // if(categoryId==3) { // Reading / Leaning Zone - // // url = "user/book-Conferance"; // Return the view - // // } - // // return url; - - // // ✅ Dynamically determine view name based on categoryId - - // switch (categoryId) { - // case 1 -> url = "user/book-learning"; - // case 2 -> url = "user/book-workdesk"; - // case 3 -> url = "user/book-conference"; - // case 4 -> url = "user/book-learning"; // optional if you add more later - // default -> throw new IllegalArgumentException("Invalid category ID: " + categoryId); - // } - // // ✅ Pass IDs for dynamic usage in JavaScript - // model.addAttribute("buildingId", buildingId); - // model.addAttribute("categoryId", categoryId); - - // return url; + // @GetMapping("/book") + // public String showCategoryPage(@RequestParam int buildingId,@RequestParam int + // categoryId, Model model) { + // String url=""; + // List> buildingCategoryDetails = + // buildingSer.getBuildingCategoryDetailsById(buildingId,categoryId); // + // Retrieve data + // model.addAttribute("homeImg",homeService.getImgByCid(categoryId)); + + // if (!buildingCategoryDetails.isEmpty()) { + // model.addAttribute("details", buildingCategoryDetails.get(0)); // Pass the + // first item to the model + // } + // // if(categoryId==1) { // Reading / Leaning Zone + // // url = "user/book-reading"; // Return the view + // // } + // // if(categoryId==2) { // Reading / Leaning Zone + // // url = "user/book-workdesk"; // Return the view + // // } + // // if(categoryId==3) { // Reading / Leaning Zone + // // url = "user/book-Conferance"; // Return the view + // // } + // // return url; + + // // ✅ Dynamically determine view name based on categoryId + + // switch (categoryId) { + // case 1 -> url = "user/book-learning"; + // case 2 -> url = "user/book-workdesk"; + // case 3 -> url = "user/book-conference"; + // case 4 -> url = "user/book-learning"; // optional if you add more later + // default -> throw new IllegalArgumentException("Invalid category ID: " + + // categoryId); // } + // // ✅ Pass IDs for dynamic usage in JavaScript + // model.addAttribute("buildingId", buildingId); + // model.addAttribute("categoryId", categoryId); + // return url; + // } -//////////existing code for /book with subId handling - -// @GetMapping("/book") -// public String getCategoryPageGet(@RequestParam(value = "buildingId", required = false) Integer buildingId, -// @RequestParam(value = "categoryId", required = false) Integer categoryId, -// @RequestParam(value = "subId", required = false) Integer subId, -// Model model) { - -// // Validate required fields -// if (buildingId == null || categoryId == null) { -// return "redirect:/muthalvarpadaippagam"; // Return home safely -// } - -// return showCategoryPage(buildingId, categoryId, subId, model); -// } - - -// //added by yogi -// @PostMapping("/book") -// public String showCategoryPagePost(@RequestParam int buildingId, -// @RequestParam int categoryId, -// @RequestParam(required = false) Integer subId, -// Model model) { - -// return showCategoryPage(buildingId, categoryId, subId, model); -// } - - - - - - - -// @GetMapping("/book") -// public String showCategoryPage(@RequestParam int buildingId, -// @RequestParam int categoryId, -// @RequestParam(required = false) Integer subId, -// Model model) { -// // System.out.println("buildingId:" + buildingId); -// // System.out.println("categoryId:" + categoryId); - -// List> buildingCategoryDetails = -// buildingSer.getBuildingCategoryDetailsById(buildingId, categoryId); -// //System.out.println("buildingCategoryDetails:" + buildingCategoryDetails); - -// model.addAttribute("homeImg", homeService.getImgByCid(categoryId)); - -// if (!buildingCategoryDetails.isEmpty()) { -// Map firstRecord = buildingCategoryDetails.get(0); -// model.addAttribute("details", firstRecord); -// //ak -// Object buildingName = firstRecord.get("Building_Name"); -// Object buildingAddress = firstRecord.get("Address"); -// Object latitude = firstRecord.get("Latitude"); -// Object longitude = firstRecord.get("Longitude"); - -// model.addAttribute("buildingName", buildingName); -// model.addAttribute("buildingAddress", buildingAddress); -// model.addAttribute("latitude", latitude); -// model.addAttribute("longitude", longitude); - -// // ✅ Prefer URL parameter subId, else fallback from DB -// if (subId == null) { -// Object scidObj = firstRecord.get("scid"); -// subId = (scidObj != null) ? Integer.parseInt(scidObj.toString()) : 0; -// } - -// model.addAttribute("subId", subId); -// System.out.println("SubId: " + subId); -// } - -// model.addAttribute("buildingId", buildingId); -// model.addAttribute("categoryId", categoryId); - -// String url = switch (categoryId) { -// case 1 -> "user/book-reading"; -// case 2 -> "user/book-workdesk"; -// case 3 -> "user/book-Conferance"; -// case 4 -> "user/book-reading"; -// default -> throw new IllegalArgumentException("Invalid category ID: " + categoryId); -// }; - -// return url; -// } - - -// --------------------- GET : Visible URL --------------------- -@GetMapping("/book") -public String getCategoryPage(@RequestParam(value = "buildingId" ,required = false) Integer buildingId, - @RequestParam(value = "categoryId", required = false) Integer categoryId, - @RequestParam(value = "subId", required = false) Integer subId, Model model) { - - // Validate required fields - if (buildingId == null || categoryId == null) { - return "redirect:/muthalvarpadaippagam"; - } - - return showCategoryPage(buildingId, categoryId, subId, model); -} - - - -// --------------------- POST : Hidden Form (no URL params) --------------------- -@PostMapping("/book") -public String postCategoryPage(@RequestParam Integer buildingId, - @RequestParam Integer categoryId, - @RequestParam(required = false) Integer subId, - Model model) { - - return showCategoryPage(buildingId, categoryId, subId, model); -} - + ////////// existing code for /book with subId handling + // @GetMapping("/book") + // public String getCategoryPageGet(@RequestParam(value = "buildingId", required + // = false) Integer buildingId, + // @RequestParam(value = "categoryId", required = false) Integer categoryId, + // @RequestParam(value = "subId", required = false) Integer subId, + // Model model) { + + // // Validate required fields + // if (buildingId == null || categoryId == null) { + // return "redirect:/muthalvarpadaippagam"; // Return home safely + // } + // return showCategoryPage(buildingId, categoryId, subId, model); + // } -// --------------------- COMMON LOADING METHOD --------------------- -private String showCategoryPage(int buildingId, - int categoryId, - Integer subId, - Model model) { + // //added by yogi + // @PostMapping("/book") + // public String showCategoryPagePost(@RequestParam int buildingId, + // @RequestParam int categoryId, + // @RequestParam(required = false) Integer subId, + // Model model) { - List> buildingCategoryDetails = - buildingSer.getBuildingCategoryDetailsById(buildingId, categoryId); + // return showCategoryPage(buildingId, categoryId, subId, model); + // } - model.addAttribute("homeImg", homeService.getImgByCid(categoryId)); + // @GetMapping("/book") + // public String showCategoryPage(@RequestParam int buildingId, + // @RequestParam int categoryId, + // @RequestParam(required = false) Integer subId, + // Model model) { + // // System.out.println("buildingId:" + buildingId); + // // System.out.println("categoryId:" + categoryId); + + // List> buildingCategoryDetails = + // buildingSer.getBuildingCategoryDetailsById(buildingId, categoryId); + // //System.out.println("buildingCategoryDetails:" + buildingCategoryDetails); + + // model.addAttribute("homeImg", homeService.getImgByCid(categoryId)); + + // if (!buildingCategoryDetails.isEmpty()) { + // Map firstRecord = buildingCategoryDetails.get(0); + // model.addAttribute("details", firstRecord); + // //ak + // Object buildingName = firstRecord.get("Building_Name"); + // Object buildingAddress = firstRecord.get("Address"); + // Object latitude = firstRecord.get("Latitude"); + // Object longitude = firstRecord.get("Longitude"); + + // model.addAttribute("buildingName", buildingName); + // model.addAttribute("buildingAddress", buildingAddress); + // model.addAttribute("latitude", latitude); + // model.addAttribute("longitude", longitude); + + // // ✅ Prefer URL parameter subId, else fallback from DB + // if (subId == null) { + // Object scidObj = firstRecord.get("scid"); + // subId = (scidObj != null) ? Integer.parseInt(scidObj.toString()) : 0; + // } - String displayName = null; + // model.addAttribute("subId", subId); + // System.out.println("SubId: " + subId); + // } + // model.addAttribute("buildingId", buildingId); + // model.addAttribute("categoryId", categoryId); - if (!buildingCategoryDetails.isEmpty()) { + // String url = switch (categoryId) { + // case 1 -> "user/book-reading"; + // case 2 -> "user/book-workdesk"; + // case 3 -> "user/book-Conferance"; + // case 4 -> "user/book-reading"; + // default -> throw new IllegalArgumentException("Invalid category ID: " + + // categoryId); + // }; - - Map firstRecord = buildingCategoryDetails.get(0); - displayName = (String) firstRecord.get("Category_Display_Name"); + // return url; + // } - model.addAttribute("details", firstRecord); + // --------------------- GET : Visible URL --------------------- + @GetMapping("/book") + public String getCategoryPage(@RequestParam(value = "buildingId", required = false) Integer buildingId, + @RequestParam(value = "categoryId", required = false) Integer categoryId, + @RequestParam(value = "subId", required = false) Integer subId, Model model) { - model.addAttribute("buildingName", firstRecord.get("Building_Name")); - model.addAttribute("buildingAddress", firstRecord.get("Address")); - model.addAttribute("latitude", firstRecord.get("Latitude")); - model.addAttribute("longitude", firstRecord.get("Longitude")); + // Validate required fields + if (buildingId == null || categoryId == null) { + return "redirect:/muthalvarpadaippagam"; + } + if (!bookingService.checkbuildingbycat(categoryId, buildingId, subId)) { + return "redirect:/muthalvarpadaippagam"; + } + try { + return showCategoryPage(buildingId, categoryId, subId, model); + } catch (Exception e) { + e.printStackTrace(); // for debugging + return "redirect:/muthalvarpadaippagam"; + } - // If subId is not passed, get from DB - if (subId == null) { - Object scidObj = firstRecord.get("scid"); - subId = (scidObj != null) ? Integer.parseInt(scidObj.toString()) : 0; - } - model.addAttribute("subId", subId); - } + // return showCategoryPage(buildingId, categoryId, subId, model); + } - model.addAttribute("buildingId", buildingId); - model.addAttribute("categoryId", categoryId); + // --------------------- POST : Hidden Form (no URL params) + // --------------------- + @PostMapping("/book") + public String postCategoryPage(@RequestParam Integer buildingId, + @RequestParam Integer categoryId, + @RequestParam(required = false) Integer subId, + Model model) { + if (!bookingService.checkbuildingbycat(categoryId, buildingId, subId)) { + return "redirect:/muthalvarpadaippagam"; + } + return showCategoryPage(buildingId, categoryId, subId, model); + } - // Select page by category - // return switch (categoryId) { - // case 1 -> "user/book-reading"; - // case 2 -> "user/book-workdesk"; - // case 3 -> "user/book-Conferance"; - // case 4 -> "user/book-reading"; - // default -> throw new IllegalArgumentException("Invalid category ID: " + categoryId); - // }; + // --------------------- COMMON LOADING METHOD --------------------- + private String showCategoryPage(int buildingId, + int categoryId, + Integer subId, + Model model) { + List> buildingCategoryDetails = buildingSer.getBuildingCategoryDetailsById(buildingId, + categoryId); + model.addAttribute("homeImg", homeService.getImgByCid(categoryId)); - if (displayName == null) { - throw new IllegalArgumentException("Category name not found"); - } + String displayName = null; - String url = switch (displayName.trim()) { - case "Meeting Rooms" -> "user/book-Conferance"; - case "Learning Centre" -> "user/book-reading"; - case "Desk Space" -> "user/book-workdesk"; - default -> throw new IllegalArgumentException("Unknown Category Name: " + displayName); - }; + if (!buildingCategoryDetails.isEmpty()) { - return url; -} + Map firstRecord = buildingCategoryDetails.get(0); + displayName = (String) firstRecord.get("Category_Display_Name"); + model.addAttribute("details", firstRecord); + model.addAttribute("buildingName", firstRecord.get("Building_Name")); + model.addAttribute("buildingAddress", firstRecord.get("Address")); + model.addAttribute("latitude", firstRecord.get("Latitude")); + model.addAttribute("longitude", firstRecord.get("Longitude")); + // If subId is not passed, get from DB + if (subId == null) { + Object scidObj = firstRecord.get("scid"); + subId = (scidObj != null) ? Integer.parseInt(scidObj.toString()) : 0; + } + model.addAttribute("subId", subId); + } -// @GetMapping("/book") -// public String showCategoryPage( -// @RequestParam int buildingId, -// @RequestParam int categoryId, -// Model model) { + model.addAttribute("buildingId", buildingId); + model.addAttribute("categoryId", categoryId); + + // Select page by category + // return switch (categoryId) { + // case 1 -> "user/book-reading"; + // case 2 -> "user/book-workdesk"; + // case 3 -> "user/book-Conferance"; + // case 4 -> "user/book-reading"; + // default -> throw new IllegalArgumentException("Invalid category ID: " + + // categoryId); + // }; + + if (displayName == null) { + throw new IllegalArgumentException("Category name not found"); + } -// // Fetch building + category + subcategory + slot info -// List> buildingCategoryDetails = buildingSer.getBuildingCategoryDetailsById(buildingId, categoryId); -// model.addAttribute("homeImg", homeService.getImgByCid(categoryId)); + String url = switch (displayName.trim()) { + case "Meeting Rooms" -> "user/book-Conferance"; + case "Learning Centre" -> "user/book-reading"; + case "Desk Space" -> "user/book-workdesk"; + default -> throw new IllegalArgumentException("Unknown Category Name: " + displayName); + }; -// if (!buildingCategoryDetails.isEmpty()) { -// model.addAttribute("details", buildingCategoryDetails.get(0)); -// } + return url; + } -// // Dynamically resolve the view name based on category name or ID -// String viewName = switch (categoryId) { -// case 1 -> "user/book-reading"; -// case 2 -> "user/book-workdesk"; -// case 3 -> "user/book-Conference"; -// default -> "user/book-generic"; // fallback if future category added -// }; + // @GetMapping("/book") + // public String showCategoryPage( + // @RequestParam int buildingId, + // @RequestParam int categoryId, + // Model model) { + + // // Fetch building + category + subcategory + slot info + // List> buildingCategoryDetails = + // buildingSer.getBuildingCategoryDetailsById(buildingId, categoryId); + // model.addAttribute("homeImg", homeService.getImgByCid(categoryId)); + + // if (!buildingCategoryDetails.isEmpty()) { + // model.addAttribute("details", buildingCategoryDetails.get(0)); + // } -// return viewName; -// } + // // Dynamically resolve the view name based on category name or ID + // String viewName = switch (categoryId) { + // case 1 -> "user/book-reading"; + // case 2 -> "user/book-workdesk"; + // case 3 -> "user/book-Conference"; + // default -> "user/book-generic"; // fallback if future category added + // }; + // return viewName; + // } @GetMapping("/subcategory-display-names") - public String showSubcategoryDisplayNames(@RequestParam Model model) { - List> displayNames = buildingSer.getSubcategoryDisplayNames(); - model.addAttribute("displayNames", displayNames); - return "user/termsandconditions"; // Ensure this matches your Thymeleaf template file + public String showSubcategoryDisplayNames(@RequestParam Model model) { + List> displayNames = buildingSer.getSubcategoryDisplayNames(); + model.addAttribute("displayNames", displayNames); + return "user/termsandconditions"; // Ensure this matches your Thymeleaf template file } - -// @GetMapping("/bookingdetails") -// public String viewBookingDetails (Model model) { -// return "user/bookingdetails";} + // @GetMapping("/bookingdetails") + // public String viewBookingDetails (Model model) { + // return "user/bookingdetails";} @GetMapping("/bookinghistory") - public String viewbookinghistory (Model model) { - if(userSession!=null && userSession.getMobileno()!=0){ - model.addAttribute("bookinghistorylist",bookingService.getBookingByMobileNo(userSession.getMobileno())); + public String viewbookinghistory(Model model) { + if (userSession != null && userSession.getMobileno() != 0) { + model.addAttribute("bookinghistorylist", bookingService.getBookingByMobileNo(userSession.getMobileno())); } return "user/bookinghistory"; } @GetMapping("/bookingQRCode") - public String getBookingQRCode(HttpServletResponse response,@RequestParam int booking_id, Model model) { + public String getBookingQRCode(HttpServletResponse response, @RequestParam int booking_id, Model model) { setNoCacheHeaders(response); List bookinghistorylist = bookingService.getQrPageByBookingId(booking_id); if (!bookinghistorylist.isEmpty()) { @@ -845,16 +842,15 @@ private String showCategoryPage(int buildingId, return "error"; // A template to handle errors } } - @GetMapping("/officiallogin") - public String officiallogin (HttpServletResponse response, Model model) { + public String officiallogin(HttpServletResponse response, Model model) { setNoCacheHeaders(response); return "caretaker/login"; } @GetMapping("/logout") - public String logout(HttpServletResponse response,HttpSession session) { + public String logout(HttpServletResponse response, HttpSession session) { setNoCacheHeaders(response); try { session.invalidate(); @@ -866,80 +862,82 @@ private String showCategoryPage(int buildingId, } @GetMapping("/bookingdetails") - public String viewbookingdetails (HttpServletResponse response,Model model, HttpSession httpSession) { + public String viewbookingdetails(HttpServletResponse response, Model model, HttpSession httpSession) { setNoCacheHeaders(response); String userName = (String) httpSession.getAttribute("user_name"); - if (userName != null){ - //ak - // Call service to get bid - Integer bid = bookingService.getBidByUserName(userName); + if (userName != null) { + // ak + // Call service to get bid + Integer bid = bookingService.getBidByUserName(userName); + + model.addAttribute("user_name", userName); + model.addAttribute("bid", bid); - model.addAttribute("user_name", userName); - model.addAttribute("bid", bid); + // (optional) store bid in session for later use + httpSession.setAttribute("bid", bid); - // (optional) store bid in session for later use - httpSession.setAttribute("bid", bid); - return "caretaker/bookingdetails"; } else { return "redirect:/muthalvarpadaippagam/officiallogin"; } } - - // @GetMapping("/Dashboard") - // public String Dashboard ( Model model,HttpSession httpSession, HttpServletResponse response) { - // String userName = (String) httpSession.getAttribute("user_name"); - // Integer bid = bookingService.getBidByUserName(userName); - // //System.out.println("username:"+ userName); - // if (userName != null){ - // model.addAttribute("user_name",userName); - // model.addAttribute("bid", bid); - // setNoCacheHeaders(response); - // return "caretaker/officer-dashboard"; - // } else { - // return "redirect:/muthalvarpadaippagam/officiallogin"; - // } + // @GetMapping("/Dashboard") + // public String Dashboard ( Model model,HttpSession httpSession, + // HttpServletResponse response) { + + // String userName = (String) httpSession.getAttribute("user_name"); + // Integer bid = bookingService.getBidByUserName(userName); + // //System.out.println("username:"+ userName); + // if (userName != null){ + // model.addAttribute("user_name",userName); + // model.addAttribute("bid", bid); + // setNoCacheHeaders(response); + // return "caretaker/officer-dashboard"; + // } else { + // return "redirect:/muthalvarpadaippagam/officiallogin"; + // } // } // @GetMapping("/Report") // public String showReportPage(Model model, HttpSession session) { - // String userName = (String) session.getAttribute("user_name"); - - // // Check if the user is logged in - // if (userName != null && !userName.isEmpty()) { - // model.addAttribute("user_name", userName); - // return "caretaker/report"; // Render the report page - // } else { - // return "redirect:/muthalvarpadaippagam/officiallogin"; // Redirect to login if not logged in - // } + // String userName = (String) session.getAttribute("user_name"); + + // // Check if the user is logged in + // if (userName != null && !userName.isEmpty()) { + // model.addAttribute("user_name", userName); + // return "caretaker/report"; // Render the report page + // } else { + // return "redirect:/muthalvarpadaippagam/officiallogin"; // Redirect to login + // if not logged in // } - + // } + // @GetMapping("/Abstract") // public String abstractReportPage(Model model, HttpSession session) { - // String userName = (String) session.getAttribute("user_name"); - - // // Check if the user is logged in - // if (userName != null && !userName.isEmpty()) { - // model.addAttribute("user_name", userName); - // return "caretaker/abstract"; // Render the report page - // } else { - // return "redirect:/muthalvarpadaippagam/officiallogin"; // Redirect to login if not logged in - // } + // String userName = (String) session.getAttribute("user_name"); + + // // Check if the user is logged in + // if (userName != null && !userName.isEmpty()) { + // model.addAttribute("user_name", userName); + // return "caretaker/abstract"; // Render the report page + // } else { + // return "redirect:/muthalvarpadaippagam/officiallogin"; // Redirect to login + // if not logged in + // } // } - // added by yogi @GetMapping("/Dashboard") - public String Dashboard ( Model model,HttpSession httpSession, HttpServletResponse response) { + public String Dashboard(Model model, HttpSession httpSession, HttpServletResponse response) { String userName = (String) httpSession.getAttribute("user_name"); - Integer bid = (Integer) httpSession.getAttribute("bid"); // ✅ get BID from session - //System.out.println("username:"+ userName); - if (userName != null && bid!= null){ - model.addAttribute("user_name",userName); - model.addAttribute("bid",bid); // ✅ pass BID to model + Integer bid = (Integer) httpSession.getAttribute("bid"); // ✅ get BID from session + // System.out.println("username:"+ userName); + if (userName != null && bid != null) { + model.addAttribute("user_name", userName); + model.addAttribute("bid", bid); // ✅ pass BID to model setNoCacheHeaders(response); return "caretaker/officer-dashboard"; } else { @@ -951,34 +949,34 @@ private String showCategoryPage(int buildingId, public String showReportPage(Model model, HttpSession session) { String userName = (String) session.getAttribute("user_name"); - Integer bid = (Integer) session.getAttribute("bid"); // ✅ get BID from session - - //Integer bid = bookingService.getBidByUserName(userName); - System.out.println("bid inside controller: "+bid); + Integer bid = (Integer) session.getAttribute("bid"); // ✅ get BID from session + + // Integer bid = bookingService.getBidByUserName(userName); + System.out.println("bid inside controller: " + bid); // Check if the user is logged in - if (userName != null && !userName.isEmpty() && bid!=null ) { + if (userName != null && !userName.isEmpty() && bid != null) { model.addAttribute("user_name", userName); model.addAttribute("bid", bid); - return "caretaker/report"; // Render the report page + return "caretaker/report"; // Render the report page } else { - return "redirect:/muthalvarpadaippagam/officiallogin"; // Redirect to login if not logged in + return "redirect:/muthalvarpadaippagam/officiallogin"; // Redirect to login if not logged in } } - + @GetMapping("/Abstract") public String abstractReportPage(Model model, HttpSession session) { String userName = (String) session.getAttribute("user_name"); - - //Integer bid = bookingService.getBidByUserName(userName); + + // Integer bid = bookingService.getBidByUserName(userName); Integer bid = (Integer) session.getAttribute("bid"); // Check if the user is logged in if (userName != null && !userName.isEmpty()) { model.addAttribute("user_name", userName); model.addAttribute("bid", bid); - return "caretaker/abstract"; // Render the report page + return "caretaker/abstract"; // Render the report page } else { - return "redirect:/muthalvarpadaippagam/officiallogin"; // Redirect to login if not logged in + return "redirect:/muthalvarpadaippagam/officiallogin"; // Redirect to login if not logged in } } diff --git a/src/main/java/com/gcc/coworkspace/service/BookingService.java b/src/main/java/com/gcc/coworkspace/service/BookingService.java index 2845189..9dc7494 100644 --- a/src/main/java/com/gcc/coworkspace/service/BookingService.java +++ b/src/main/java/com/gcc/coworkspace/service/BookingService.java @@ -37,7 +37,6 @@ import java.time.format.DateTimeParseException; import java.io.*; - import javax.imageio.ImageIO; import javax.imageio.ImageWriteParam; import javax.imageio.ImageWriter; @@ -65,19 +64,19 @@ public class BookingService { @Autowired private PaymentService paymentService; - + @Autowired private WhatsAppService whatsAppService; - + @Autowired private CalendarService calendarService; - + @Autowired - private Environment environment; + private Environment environment; @Value("${app.full_URL}") private String baseUrl; - + public static List getDatesBetween(LocalDate fromDate, LocalDate toDate) { List dates = new ArrayList<>(); @@ -89,17 +88,16 @@ public class BookingService { return dates; } - + public Map getComplaintAndUserDetailsByMobile(String mobile) { String userSql = "SELECT user_name, mobile FROM booking WHERE mobile = ? LIMIT 1"; String complaintSql = """ - SELECT complaint_no,remarks, upload_photo_url, caretaker_remarks, caretaker_photo_url, status - FROM complaint_details - WHERE mobile_number = ? - ORDER BY id DESC - """; - + SELECT complaint_no,remarks, upload_photo_url, caretaker_remarks, caretaker_photo_url, status + FROM complaint_details + WHERE mobile_number = ? + ORDER BY id DESC + """; try { Map result = new HashMap<>(); @@ -142,13 +140,13 @@ public class BookingService { return null; } } - + public boolean isUserRegistered(String mobile) { String sql = "SELECT COUNT(*) FROM booking WHERE mobile = ?"; - Integer count = jdbcTemplate.queryForObject(sql, new Object[]{mobile}, Integer.class); + Integer count = jdbcTemplate.queryForObject(sql, new Object[] { mobile }, Integer.class); return count != null && count > 0; } - + public boolean hasTodayAttendance(int buildingid) { String sql = "" + "SELECT COUNT(*) " @@ -165,89 +163,88 @@ public class BookingService { sql, Integer.class, today, - buildingid - ); + buildingid); return count != null && count > 0; } /* - public Boolean checkAvailabilityByBdate(int bid,int cid,LocalDate Bdate,int scid,int noOfPerson,int slotId){ - - Map getcalendar = getCalendarBySlotId(bid,cid,Bdate,slotId); - Map capacity= getCapacity( scid, cid); + * public Boolean checkAvailabilityByBdate(int bid,int cid,LocalDate Bdate,int + * scid,int noOfPerson,int slotId){ + * + * Map getcalendar = getCalendarBySlotId(bid,cid,Bdate,slotId); + * Map capacity= getCapacity( scid, cid); + * + * int capsint = Integer.parseInt(capacity.get("limits").toString()); + * int capacityint = Integer.parseInt(capacity.get("capacity").toString()); + * + * System.out.println("capsint: "+capsint); + * System.out.println("capacityint: "+capacityint); + * if(capacityint<1) { + * return true; + * } + * if(!getcalendar.isEmpty()){ + * int count= Integer.parseInt(getcalendar.get("filed")+"") + noOfPerson; + * System.out.println("count: "+count); + * if(count > capacityint ){ + * return true; + * } + * + * return false; + * } + * + * return false; + * } + */ - int capsint = Integer.parseInt(capacity.get("limits").toString()); - int capacityint = Integer.parseInt(capacity.get("capacity").toString()); - - System.out.println("capsint: "+capsint); - System.out.println("capacityint: "+capacityint); - if(capacityint<1) { - return true; - } - if(!getcalendar.isEmpty()){ - int count= Integer.parseInt(getcalendar.get("filed")+"") + noOfPerson; - System.out.println("count: "+count); - if(count > capacityint ){ - return true; - } - - return false; - } - - return false; - } - */ - private int getacountfromtable(int bid) { - String sql="SELECT COALESCE(SUM(absent_count),0) " + + String sql = "SELECT COALESCE(SUM(absent_count),0) " + "FROM absent_count " + "WHERE DATE(absent_date) = CURDATE() AND bid=? AND is_active = 1 AND is_delete = 0 LIMIT 1"; - return jdbcTemplate.queryForObject(sql, Integer.class,bid); + return jdbcTemplate.queryForObject(sql, Integer.class, bid); } - - public Boolean checkAvailabilityByBdate(int bid,int cid,LocalDate Bdate,int scid,int noOfPerson,int slotId){ - System.out.println("bid: "+bid); - System.out.println("cid: "+cid); - System.out.println("Bdate: "+Bdate); - System.out.println("scid: "+scid); - System.out.println("noOfPerson: "+noOfPerson); - System.out.println("slotId: "+slotId); + public Boolean checkAvailabilityByBdate(int bid, int cid, LocalDate Bdate, int scid, int noOfPerson, int slotId) { + + System.out.println("bid: " + bid); + System.out.println("cid: " + cid); + System.out.println("Bdate: " + Bdate); + System.out.println("scid: " + scid); + System.out.println("noOfPerson: " + noOfPerson); + System.out.println("slotId: " + slotId); - Map getcalendar = getCalendarBySlotId(bid,cid,Bdate,slotId); - Map capacity= getCapacity( scid, cid); + Map getcalendar = getCalendarBySlotId(bid, cid, Bdate, slotId); + Map capacity = getCapacity(scid, cid); int capsint = Integer.parseInt(capacity.get("limits").toString()); int capacityint = Integer.parseInt(capacity.get("capacity").toString()); - - System.out.println("capsint: "+capsint); - System.out.println("capacityint: "+capacityint); - if(capacityint<1) { + System.out.println("capsint: " + capsint); + System.out.println("capacityint: " + capacityint); + if (capacityint < 1) { return true; } - if(!getcalendar.isEmpty()){ - int count= Integer.parseInt(getcalendar.get("filed")+"") + noOfPerson; - int count1= Integer.parseInt(getcalendar.get("filed")+""); - System.out.println("count======================: "+count1); - System.out.println("count: "+count); - - if(cid==2 && LocalDate.now().equals(Bdate)) // Allow only Disc Work Space and today date + if (!getcalendar.isEmpty()) { + int count = Integer.parseInt(getcalendar.get("filed") + "") + noOfPerson; + int count1 = Integer.parseInt(getcalendar.get("filed") + ""); + System.out.println("count======================: " + count1); + System.out.println("count: " + count); + + if (cid == 2 && LocalDate.now().equals(Bdate)) // Allow only Disc Work Space and today date { - int acount=getacountfromtable(bid); - System.out.println("acount: "+acount); - /////// Balaji - absent_count - if(acount>=0){ - System.out.println("acountinside: "+acount); - int extra_seat = acount/2; - capacityint = capacityint + extra_seat; - System.out.println("capacityint: "+capacityint); - } + int acount = getacountfromtable(bid); + System.out.println("acount: " + acount); + /////// Balaji - absent_count + if (acount >= 0) { + System.out.println("acountinside: " + acount); + int extra_seat = acount / 2; + capacityint = capacityint + extra_seat; + System.out.println("capacityint: " + capacityint); + } } - - if(count > capacityint ){ + + if (count > capacityint) { return true; } @@ -257,56 +254,61 @@ public class BookingService { return false; } - public Map getCapacity(int sId, int catId) { + System.out.println("sid" + sId); + System.out.println("catId" + catId); String sql = "select limits, capacity from subcategory where scid = ? and cid = ?"; - System.out.println("select limits, capacity from subcategory where scid = '"+sId+"' and cid = '"+catId+"'"); + System.out.println( + "select limits, capacity from subcategory where scid = '" + sId + "' and cid = '" + catId + "'"); try { return jdbcTemplate.queryForMap(sql, sId, catId); } catch (Exception e) { e.printStackTrace(); - return Collections.singletonMap("error", "An error occurred while getting capacity."); + return Collections.singletonMap("error", + "An error occurred while getting capacity."); } + } - + public Map getCalendarBySlotId(int bid, int cid, LocalDate Bdate, int slotId) { - String sql=""; - - if(cid==2) { - if(slotId==6 || slotId==7) { - sql = "select sum(bcount) as filed, bdate " - + "from calendar where bdate = ? and cid = ? and bid = ? and slotId IN (?,8,9) " - + "group by bdate"; - - System.out.println("select sum(bcount) as filed, bdate " - + "from calendar where bdate = '"+Bdate+"' and cid = "+cid+" and bid = "+bid+" and slotId IN ("+slotId+",8,9) " - + "group by bdate"); - } - else { - sql = "select sum(bcount) as filed, bdate " - + "from calendar where (bdate = ? and cid = ? and bid = ?) or (0=?) " - + "group by bdate"; - - System.out.println("select slotid, sum(bcount) as filed, bdate " - + "from calendar where (bdate = '"+Bdate+"' and cid = "+cid+" and bid = "+bid+") or (0="+slotId+") " - + "group by bdate"); - } - } - else { - sql = "select sum(bcount) as filed, bdate " - + "from calendar where bdate = ? and cid = ? and bid = ? and slotId = ? " - + "group by slotid, bdate"; - - System.out.println("select sum(bcount) as filed, bdate " - + "from calendar where bdate = '"+Bdate+"' and cid = '"+cid+"' and bid = '"+bid+"' and slotId = '"+slotId+"' " - + "group by bdate"); + String sql = ""; + + if (cid == 2) { + if (slotId == 6 || slotId == 7) { + sql = "select sum(bcount) as filed, bdate " + + "from calendar where bdate = ? and cid = ? and bid = ? and slotId IN (?,8,9) " + + "group by bdate"; + + System.out.println("select sum(bcount) as filed, bdate " + + "from calendar where bdate = '" + Bdate + "' and cid = " + cid + " and bid = " + bid + + " and slotId IN (" + slotId + ",8,9) " + + "group by bdate"); + } else { + sql = "select sum(bcount) as filed, bdate " + + "from calendar where (bdate = ? and cid = ? and bid = ?) or (0=?) " + + "group by bdate"; + + System.out.println("select slotid, sum(bcount) as filed, bdate " + + "from calendar where (bdate = '" + Bdate + "' and cid = " + cid + " and bid = " + bid + + ") or (0=" + slotId + ") " + + "group by bdate"); + } + } else { + sql = "select sum(bcount) as filed, bdate " + + "from calendar where bdate = ? and cid = ? and bid = ? and slotId = ? " + + "group by slotid, bdate"; + + System.out.println("select sum(bcount) as filed, bdate " + + "from calendar where bdate = '" + Bdate + "' and cid = '" + cid + "' and bid = '" + bid + + "' and slotId = '" + slotId + "' " + + "group by bdate"); } - + // Using query() instead of queryForMap to handle no results List> result = jdbcTemplate.query(sql, (rs, rowNum) -> { Map map = new HashMap<>(); - //map.put("slotid", rs.getInt("slotid")); - map.put("filed", rs.getInt("filed")); // Adjust type accordingly + // map.put("slotid", rs.getInt("slotid")); + map.put("filed", rs.getInt("filed")); // Adjust type accordingly map.put("bdate", rs.getDate("bdate").toLocalDate()); return map; }, Bdate, cid, bid, slotId); @@ -317,11 +319,128 @@ public class BookingService { } return result.get(0); // Return the first (and expected only) result } - - public Map saveTempBooking(String userName, long userMobile, - List slots, LocalDate fromDate, LocalDate toDate, - int noOfPeople, int catId, int buildId, int subId) { + /* + * public boolean checkbuildingbycat(int cid, int bid,int subid) { + * String sql = + * "select count(bid) as total from category where (cid = ? and bid = ?) AND (isactive=1 and isdelete=0)" + * ; + * try { + * Map result = jdbcTemplate.queryForMap(sql, cid, bid); + * return Integer.parseInt(result.get("total") + "") > 0; + * } catch (Exception e) { + * e.printStackTrace(); + * return false; + * } + * } + */ + public boolean checkCategoryAgainstSubCategory(int cid, int bid, int subid) { + + String sql = "SELECT COUNT(*) " + + "FROM category c " + + "INNER JOIN subcategory sc ON sc.cid = c.cid " + + "WHERE c.cid = ? " + + "AND c.bid = ? " + + "AND sc.scid = ? " + + "AND c.isactive = 1 " + + "AND c.isdelete = 0 " + + "AND sc.isactive = 1 " + + "AND sc.isdelete = 0"; + + try { + Integer total = jdbcTemplate.queryForObject( + sql, + Integer.class, + cid, + bid, + subid); + return total != null && total > 0; + + } catch (Exception e) { + e.printStackTrace(); + return false; + } + } + + public boolean checkbuildingbycat(int cid, int bid, int subid) { + + String sql = "SELECT COUNT(*) " + + "FROM subcategory sc " + + "JOIN category c ON c.cid = sc.cid " + + "WHERE sc.scid = ? " + + "AND c.cid = ? " + + "AND c.bid = ? " + + "AND sc.isactive = 1 " + + "AND sc.isdelete = 0 " + + "AND c.isactive = 1 " + + "AND c.isdelete = 0"; + + try { + Integer total = jdbcTemplate.queryForObject( + sql, + Integer.class, + subid, + cid, + bid); + return total != null && total > 0; + } catch (Exception e) { + e.printStackTrace(); + return false; + } + } + + /* + * public boolean checkbuildingbycat(int cid, int bid, int subid) { + * + * String sql = "SELECT COUNT(c.bid) " + + * "FROM category c " + + * "INNER JOIN subcategory sc ON sc.cid = c.cid " + + * "WHERE c.cid = ? " + + * "AND c.bid = ? " + + * "AND sc.scid = ? " + + * "AND c.isactive = 1 " + + * "AND c.isdelete = 0"; + * + * try { + * Integer total = jdbcTemplate.queryForObject( + * sql, + * Integer.class, + * cid, + * bid, + * subid); + * + * return total != null && total > 0; + * + * } catch (Exception e) { + * e.printStackTrace(); + * return false; + * } + * } + */ + + /* + * public boolean checkbuildingbycat(int cid, int bid) { + * String sql = "SELECT COUNT(bid) FROM category " + + * "WHERE cid = ? AND bid = ? AND isactive = 1 AND isdelete = 0"; + * + * try { + * Integer total = jdbcTemplate.queryForObject(sql, Integer.class, cid, bid); + * return total != null && total > 0; + * } catch (Exception e) { + * e.printStackTrace(); + * return false; + * } + * } + */ + + public Map saveTempBooking(String userName, long userMobile, + List slots, LocalDate fromDate, LocalDate toDate, + int noOfPeople, int catId, int buildId, int subId) { + if (!checkbuildingbycat(catId, buildId, subId)) { + System.out.println("checkbuildingbycat(catId, buildId)" + checkbuildingbycat(catId, buildId, subId)); + throw new NoSlotAvailable("Selected building is not available for this category"); + + } List btnDates = getDatesBetween(fromDate, toDate); double amount = 0; @@ -331,15 +450,14 @@ public class BookingService { Map amt = amountConfigService.getAmountBySlotid(slot); System.out.println(slot + "============================>" + amt); if (amt != null && !amt.isEmpty()) { - if(catId!=3) { - amount = amount + (Double.parseDouble(amt.get("amount") + "") * noOfPeople); - } - else { - amount = amount + (Double.parseDouble(amt.get("amount") + "") * 1); - } + if (catId != 3) { + amount = amount + (Double.parseDouble(amt.get("amount") + "") * noOfPeople); + } else { + amount = amount + (Double.parseDouble(amt.get("amount") + "") * 1); + } for (LocalDate date : btnDates) { if (checkAvailabilityByBdate(buildId, catId, date, subId, noOfPeople, slot)) { - //return null; + // return null; throw new NoSlotAvailable("Slot not av"); } } @@ -351,32 +469,31 @@ public class BookingService { String Tslot = slots.stream().map(String::valueOf).collect(Collectors.joining(",")); System.out.println(Tslot); - tempBookingId =saveTempBookingDetails(userName, userMobile, - Tslot, fromDate, toDate,noOfPeople, catId, buildId, subId,amount); - - Map temp = new HashMap<>(); - temp.put("tempBookId",tempBookingId); - temp.put("userName",userName); - temp.put("userMobile",userMobile); - temp.put("slotIds",Tslot); - temp.put("fromDate",fromDate); - temp.put("toDate",toDate); - temp.put("noOfPeople",noOfPeople); - temp.put("catId",catId); - temp.put("buildId",buildId); - temp.put("subId",subId); - temp.put("amount",amount); + tempBookingId = saveTempBookingDetails(userName, userMobile, + Tslot, fromDate, toDate, noOfPeople, catId, buildId, subId, amount); + + Map temp = new HashMap<>(); + temp.put("tempBookId", tempBookingId); + temp.put("userName", userName); + temp.put("userMobile", userMobile); + temp.put("slotIds", Tslot); + temp.put("fromDate", fromDate); + temp.put("toDate", toDate); + temp.put("noOfPeople", noOfPeople); + temp.put("catId", catId); + temp.put("buildId", buildId); + temp.put("subId", subId); + temp.put("amount", amount); return temp; } - public int saveTempBookingDetails(String userName, long userMobile, - String Tslot, LocalDate fromDate, LocalDate toDate, - int noOfPeople, int catId, int buildId, int subId,double amount){ + public int saveTempBookingDetails(String userName, long userMobile, + String Tslot, LocalDate fromDate, LocalDate toDate, + int noOfPeople, int catId, int buildId, int subId, double amount) { // Join the slots with commas - String sqlQuery = "INSERT INTO temp_booking (user_name, mobile, slotids, from_date, to_date, no_of_person, amount, cid, bid, sid) " + "VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ? )"; @@ -386,26 +503,26 @@ public class BookingService { int affectedRows = jdbcTemplate.update(new PreparedStatementCreator() { @Override public PreparedStatement createPreparedStatement(Connection connection) throws SQLException { - PreparedStatement ps = connection.prepareStatement(sqlQuery, new String[]{"tempbookid"}); + PreparedStatement ps = connection.prepareStatement(sqlQuery, new String[] { "tempbookid" }); ps.setString(1, userName); - ps.setString(2, userMobile+""); + ps.setString(2, userMobile + ""); ps.setString(3, Tslot); ps.setString(4, fromDate.toString()); ps.setString(5, toDate.toString()); - ps.setString(6, noOfPeople+""); - ps.setString(7, amount+""); - ps.setString(8, catId+""); - ps.setString(9, buildId+""); - ps.setString(10, subId+""); + ps.setString(6, noOfPeople + ""); + ps.setString(7, amount + ""); + ps.setString(8, catId + ""); + ps.setString(9, buildId + ""); + ps.setString(10, subId + ""); return ps; } }, keyHolder); if (affectedRows > 0) { Number generatedId = keyHolder.getKey(); - return (generatedId != null) ? generatedId.intValue() : 0; + return (generatedId != null) ? generatedId.intValue() : 0; } - }catch (DataAccessException e) { + } catch (DataAccessException e) { System.out.println("Data Access Exception:"); Throwable rootCause = e.getMostSpecificCause(); if (rootCause instanceof SQLException) { @@ -416,14 +533,14 @@ public class BookingService { // return 0; } else { System.out.println("Message: " + rootCause.getMessage()); - // return 0; + // return 0; } } return 0; } - + public Map getTempBookingByTempId(int tempbookid) { String sql = "SELECT * FROM temp_booking where tempbookid = ?"; return jdbcTemplate.queryForMap(sql, tempbookid); @@ -434,42 +551,42 @@ public class BookingService { try { return jdbcTemplate.queryForMap(sql, bookingId); } catch (Exception e) { - // e.printStackTrace(); + // e.printStackTrace(); throw new RuntimeException(e.getMessage()); } } - + @Transactional - public int saveBooking(int tempbookid,int pid) { - - Map tempBooking = getTempBookingByTempId(tempbookid); + public int saveBooking(int tempbookid, int pid) { + + Map tempBooking = getTempBookingByTempId(tempbookid); System.out.println(tempBooking); - List> result=null; - Map response = new HashMap<>(); - int bookingId = 0; - - String sqlQuery = "INSERT INTO booking (user_name, mobile, slotids, from_date, to_date, no_of_person, amount, cid, bid, sid) " - + "VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ? )"; - - KeyHolder keyHolder = new GeneratedKeyHolder(); - - String user_name = tempBooking.get("user_name").toString(); - String mobile = tempBooking.get("mobile").toString(); - String slotIds = tempBooking.get("slotIds").toString(); - String from_date = tempBooking.get("from_date").toString(); - String to_date = tempBooking.get("to_date").toString(); - String no_of_person = tempBooking.get("no_of_person").toString(); - String amount = tempBooking.get("amount").toString(); - String cid = tempBooking.get("cid").toString(); - String bid = tempBooking.get("bid").toString(); - String sid = tempBooking.get("sid").toString(); - - try { + List> result = null; + Map response = new HashMap<>(); + int bookingId = 0; + + String sqlQuery = "INSERT INTO booking (user_name, mobile, slotids, from_date, to_date, no_of_person, amount, cid, bid, sid) " + + "VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ? )"; + + KeyHolder keyHolder = new GeneratedKeyHolder(); + + String user_name = tempBooking.get("user_name").toString(); + String mobile = tempBooking.get("mobile").toString(); + String slotIds = tempBooking.get("slotIds").toString(); + String from_date = tempBooking.get("from_date").toString(); + String to_date = tempBooking.get("to_date").toString(); + String no_of_person = tempBooking.get("no_of_person").toString(); + String amount = tempBooking.get("amount").toString(); + String cid = tempBooking.get("cid").toString(); + String bid = tempBooking.get("bid").toString(); + String sid = tempBooking.get("sid").toString(); + + try { int affectedRows = jdbcTemplate.update(new PreparedStatementCreator() { @Override public PreparedStatement createPreparedStatement(Connection connection) throws SQLException { - PreparedStatement ps = connection.prepareStatement(sqlQuery, new String[]{"booking_id"}); + PreparedStatement ps = connection.prepareStatement(sqlQuery, new String[] { "booking_id" }); ps.setString(1, user_name); ps.setString(2, mobile); ps.setString(3, slotIds); @@ -487,16 +604,16 @@ public class BookingService { if (affectedRows > 0) { Number generatedId = keyHolder.getKey(); bookingId = (generatedId != null) ? generatedId.intValue() : 0; - //ak + // ak + + Map buildingDetails = getBuildingDetails(bid); + System.out.println("buildingDetails :" + buildingDetails); + String smsename = buildingDetails.get("smsename").toString(); + // String smstname = buildingDetails.get("smstname").toString(); - Map buildingDetails = getBuildingDetails(bid); - System.out.println("buildingDetails :"+buildingDetails); - String smsename = buildingDetails.get("smsename").toString(); - // String smstname = buildingDetails.get("smstname").toString(); - paymentService.updateBookingIdInPayment( tempBooking.get("mobile").toString(), - bookingId+"",pid+""); + bookingId + "", pid + ""); saveInBookingInCalendar(bookingId, tempBooking.get("from_date").toString(), tempBooking.get("to_date").toString(), @@ -504,19 +621,18 @@ public class BookingService { tempBooking.get("slotIds").toString(), tempBooking.get("bid").toString(), tempBooking.get("cid").toString(), - tempBooking.get("sid").toString() - ); - - - - //sendMessage(user_name,mobile,slotIds,from_date,to_date,no_of_person,amount,cid,bid,sid,bookingId+""); // Sending Message to public - sendMessage(user_name,mobile,slotIds,from_date,to_date,no_of_person,amount,cid,bid,sid,smsename,bookingId+""); // Sending Message to public - + tempBooking.get("sid").toString()); + + // sendMessage(user_name,mobile,slotIds,from_date,to_date,no_of_person,amount,cid,bid,sid,bookingId+""); + // // Sending Message to public + sendMessage(user_name, mobile, slotIds, from_date, to_date, no_of_person, amount, cid, bid, sid, + smsename, bookingId + ""); // Sending Message to public + return bookingId; } else { return 10; } - + } catch (DataAccessException e) { System.out.println("Data Access Exception:"); Throwable rootCause = e.getMostSpecificCause(); @@ -532,83 +648,94 @@ public class BookingService { } } } - //ak - public Map getBuildingDetails(String bid) { - String sql = "SELECT smsename FROM buildings WHERE bid = ?"; - return jdbcTemplate.queryForMap(sql, bid); -} + // ak + public Map getBuildingDetails(String bid) { + String sql = "SELECT smsename FROM buildings WHERE bid = ?"; + return jdbcTemplate.queryForMap(sql, bid); + } @Transactional - public void sendMessage(String user_name,String mobile,String slotIds,String from_date,String to_date, - String no_of_person,String amount,String cid,String bid,String sid,String smsename,String bookingId) { - // System.out.println("smsename :"+smsename); - - String slottxt = ""; - slottxt = calendarService.getSlotText(slotIds); - slottxt = slottxt.replace(" ", "%20"); - - - //System.out.println("cid :"+cid); - //System.out.println("sid :"+sid); + public void sendMessage(String user_name, String mobile, String slotIds, String from_date, String to_date, + String no_of_person, String amount, String cid, String bid, String sid, String smsename, String bookingId) { + // System.out.println("smsename :"+smsename); + + String slottxt = ""; + slottxt = calendarService.getSlotText(slotIds); + slottxt = slottxt.replace(" ", "%20"); + + // System.out.println("cid :"+cid); + // System.out.println("sid :"+sid); // convert dates here - String fromDateFormatted = convertToDDMMYYYY(from_date); - String toDateFormatted = convertToDDMMYYYY(to_date); - - /*if(cid.equals("1")|| cid.equals("4")) { - whatsAppService.sendELearnNmsg(mobile, no_of_person, from_date, slottxt, amount, bookingId); - whatsAppService.sendTLearnNmsg(mobile, no_of_person, from_date, slottxt, amount, bookingId); - } - else if(cid.equals("2")) { - if(sid.equals("4")) { - whatsAppService.sendEMonthDeskspaceNmsg(mobile, no_of_person, from_date, to_date, slottxt, amount, bookingId); - whatsAppService.sendTMonthDeskspaceNmsg(mobile, no_of_person, from_date, to_date, slottxt, amount, bookingId); - } - else { - whatsAppService.sendEDeskspaceNmsg(mobile, no_of_person, from_date, slottxt, amount, bookingId); - whatsAppService.sendTDeskspaceNmsg(mobile, no_of_person, from_date, slottxt, amount, bookingId); + String fromDateFormatted = convertToDDMMYYYY(from_date); + String toDateFormatted = convertToDDMMYYYY(to_date); + + /* + * if(cid.equals("1")|| cid.equals("4")) { + * whatsAppService.sendELearnNmsg(mobile, no_of_person, from_date, slottxt, + * amount, bookingId); + * whatsAppService.sendTLearnNmsg(mobile, no_of_person, from_date, slottxt, + * amount, bookingId); + * } + * else if(cid.equals("2")) { + * if(sid.equals("4")) { + * whatsAppService.sendEMonthDeskspaceNmsg(mobile, no_of_person, from_date, + * to_date, slottxt, amount, bookingId); + * whatsAppService.sendTMonthDeskspaceNmsg(mobile, no_of_person, from_date, + * to_date, slottxt, amount, bookingId); + * } + * else { + * whatsAppService.sendEDeskspaceNmsg(mobile, no_of_person, from_date, slottxt, + * amount, bookingId); + * whatsAppService.sendTDeskspaceNmsg(mobile, no_of_person, from_date, slottxt, + * amount, bookingId); + * } + * } + * else if(cid.equals("3")) { + * whatsAppService.sendEConfeNmsg(mobile, from_date, slottxt, amount,bookingId); + * whatsAppService.sendTConfeNmsg(mobile, from_date, slottxt, amount,bookingId); + * } + */ + if (cid.equals("1") || cid.equals("4")) { + whatsAppService.sendELearnNmsg(mobile, no_of_person, fromDateFormatted, slottxt, smsename, amount, + bookingId); + whatsAppService.sendTLearnNmsg(mobile, no_of_person, fromDateFormatted, slottxt, amount, bookingId); + } else if (cid.equals("2")) { + if (sid.equals("4")) { + whatsAppService.sendEMonthDeskspaceNmsg(mobile, no_of_person, fromDateFormatted, toDateFormatted, + slottxt, smsename, amount, bookingId); + whatsAppService.sendTMonthDeskspaceNmsg(mobile, no_of_person, fromDateFormatted, toDateFormatted, + slottxt, amount, bookingId); + } else { + whatsAppService.sendEDeskspaceNmsg(mobile, no_of_person, fromDateFormatted, slottxt, smsename, amount, + bookingId); + whatsAppService.sendTDeskspaceNmsg(mobile, no_of_person, fromDateFormatted, slottxt, amount, bookingId); } - } - else if(cid.equals("3")) { - whatsAppService.sendEConfeNmsg(mobile, from_date, slottxt, amount,bookingId); - whatsAppService.sendTConfeNmsg(mobile, from_date, slottxt, amount,bookingId); - }*/ - if(cid.equals("1")|| cid.equals("4")) { - whatsAppService.sendELearnNmsg(mobile, no_of_person, fromDateFormatted, slottxt,smsename, amount, bookingId); - whatsAppService.sendTLearnNmsg(mobile, no_of_person, fromDateFormatted, slottxt, amount, bookingId); - } - else if(cid.equals("2")) { - if(sid.equals("4")) { - whatsAppService.sendEMonthDeskspaceNmsg(mobile, no_of_person, fromDateFormatted, toDateFormatted, slottxt,smsename, amount, bookingId); - whatsAppService.sendTMonthDeskspaceNmsg(mobile, no_of_person, fromDateFormatted, toDateFormatted, slottxt, amount, bookingId); - } else { - whatsAppService.sendEDeskspaceNmsg(mobile, no_of_person, fromDateFormatted, slottxt,smsename, amount, bookingId); - whatsAppService.sendTDeskspaceNmsg(mobile, no_of_person, fromDateFormatted, slottxt, amount, bookingId); + } else if (cid.equals("3")) { + whatsAppService.sendEConfeNmsg(mobile, fromDateFormatted, slottxt, smsename, amount, bookingId); + whatsAppService.sendTConfeNmsg(mobile, fromDateFormatted, slottxt, amount, bookingId); } } - else if(cid.equals("3")) { - whatsAppService.sendEConfeNmsg(mobile, fromDateFormatted, slottxt,smsename, amount, bookingId); - whatsAppService.sendTConfeNmsg(mobile, fromDateFormatted, slottxt, amount, bookingId); - } - } - //ak + + // ak private String convertToDDMMYYYY(String date) { - try { - LocalDate parsed = LocalDate.parse(date); // expects yyyy-MM-dd - return parsed.format(DateTimeFormatter.ofPattern("dd-MM-yyyy")); - } catch (Exception e) { - return date; // fallback if format is unexpected + try { + LocalDate parsed = LocalDate.parse(date); // expects yyyy-MM-dd + return parsed.format(DateTimeFormatter.ofPattern("dd-MM-yyyy")); + } catch (Exception e) { + return date; // fallback if format is unexpected + } } -} @Transactional - public void saveInBookingInCalendar(int bookingId,String fromDat,String toDat,String persons,String slotIds,String bid,String cid,String sid){ + public void saveInBookingInCalendar(int bookingId, String fromDat, String toDat, String persons, String slotIds, + String bid, String cid, String sid) { LocalDate fromDate = LocalDate.parse(fromDat); LocalDate toDate = LocalDate.parse(toDat); - int noOfPeople = Integer.parseInt(persons); - int buildId = Integer.parseInt(bid); - int catId = Integer.parseInt(cid); - int subId = Integer.parseInt(sid); + int noOfPeople = Integer.parseInt(persons); + int buildId = Integer.parseInt(bid); + int catId = Integer.parseInt(cid); + int subId = Integer.parseInt(sid); List slots = Arrays.stream(slotIds.split(",")) .map(Integer::parseInt) // Convert to integer @@ -616,29 +743,27 @@ public class BookingService { List btnDates = getDatesBetween(fromDate, toDate); double amount = 0; - if(!btnDates.isEmpty()) { + if (!btnDates.isEmpty()) { for (Integer slot : slots) { - for (LocalDate date : btnDates) { - if (checkAvailabilityByBdate(buildId, catId, date, subId, noOfPeople, slot)) { - throw new NoSlotAvailable("Slot Occupied"); - } - else { - saveInCalendar(buildId,catId,slot,bookingId,date,noOfPeople); - } + for (LocalDate date : btnDates) { + if (checkAvailabilityByBdate(buildId, catId, date, subId, noOfPeople, slot)) { + throw new NoSlotAvailable("Slot Occupied"); + } else { + saveInCalendar(buildId, catId, slot, bookingId, date, noOfPeople); } + } } System.out.println("successfully saved in calendar"); - updateBookingStatus(bookingId,"success"); + updateBookingStatus(bookingId, "success"); } - } - public int saveInCalendar(int bid,int cid,int slotId,int bookId,LocalDate bDate,int noOfPeople) { + public int saveInCalendar(int bid, int cid, int slotId, int bookId, LocalDate bDate, int noOfPeople) { - List> result=null; + List> result = null; Map response = new HashMap<>(); int calendarId = 0; @@ -650,13 +775,13 @@ public class BookingService { int affectedRows = jdbcTemplate.update(new PreparedStatementCreator() { @Override public PreparedStatement createPreparedStatement(Connection connection) throws SQLException { - PreparedStatement ps = connection.prepareStatement(sqlQuery, new String[]{"calid"}); - ps.setString(1, bid+""); - ps.setString(2, cid+""); - ps.setString(3, slotId+""); - ps.setString(4, bookId+""); + PreparedStatement ps = connection.prepareStatement(sqlQuery, new String[] { "calid" }); + ps.setString(1, bid + ""); + ps.setString(2, cid + ""); + ps.setString(3, slotId + ""); + ps.setString(4, bookId + ""); ps.setString(5, bDate.toString()); - ps.setString(6, noOfPeople+""); + ps.setString(6, noOfPeople + ""); return ps; } @@ -685,7 +810,6 @@ public class BookingService { } } - @Transactional public int updateBookingStatus(int bookingId, String bookingStatus) { // SQL UPDATE query with placeholders @@ -709,12 +833,12 @@ public class BookingService { } @Transactional - public List> findByMobileNo(long mobileNo){ + public List> findByMobileNo(long mobileNo) { String sqlQuery = "SELECT booking_id FROM booking WHERE mobile = ?"; System.out.println(mobileNo); return jdbcTemplate.queryForList(sqlQuery, mobileNo); } - + public List> getBookingDetailsByMobileNo(long mobile) { String sqlQuery = "SELECT " + "DATE_FORMAT(bd.from_date, '%d-%m-%Y') AS from_date, " + @@ -746,17 +870,15 @@ public class BookingService { "JOIN slots st ON bd.slotids = st.slotid " + "JOIN buildings bu ON bd.bid = bu.bid " + "JOIN category c ON bd.cid = c.cid " + - "WHERE bd.mobile = ? " ; - + "WHERE bd.mobile = ? "; return jdbcTemplate.queryForList(sqlQuery, mobile); } // "AND (bd.from_date = CURDATE() OR bd.to_date = CURDATE()) "; - public List> getBookingByMobileNo(long mobile) { String sqlQuery = "SELECT " + - "DATE_FORMAT(bd.from_date, '%d-%m-%Y') AS from_date, " + + "DATE_FORMAT(bd.from_date, '%d-%m-%Y') AS from_date, " + "DATE_FORMAT(bd.to_date, '%d-%m-%Y') AS to_date, " + "DATE_FORMAT(bd.cdate, '%d-%m-%Y') AS cdate, " + "bd.booking_id, " + @@ -789,7 +911,7 @@ public class BookingService { return jdbcTemplate.queryForList(sqlQuery, mobile); } - + public List> getQrPageByBookingId(int booking_id) { String sqlQuery = "SELECT " + "DATE_FORMAT(bd.from_date, '%d-%m-%Y') AS from_date, " + @@ -825,65 +947,67 @@ public class BookingService { "JOIN category c ON bd.cid = c.cid " + "WHERE bd.booking_id = ?"; - return jdbcTemplate.queryForList(sqlQuery, booking_id); } - - /* - public List> getQrPageByBookingId(int booking_id) { - String sqlQuery = "SELECT " + - "bd.from_date, " + - "bd.to_date, " + - "bd.booking_id, " + - "bd.user_name, " + - "bd.mobile, " + - "bd.amount, " + - "bd.payment_status, " + - "bd.no_of_person, " + - "bd.slotids, " + - "bu.name AS buildingname, " + - "st.name AS duration, " + - "c.name AS type, " + - "c.display_name AS type_name, " + - "SUBSTRING_INDEX(st.name, ' to ', 1) AS checkin, " + - "SUBSTRING_INDEX(st.name, ' to ', -1) AS checkout, " + - "TIMESTAMPDIFF(HOUR, " + - " STR_TO_DATE(SUBSTRING_INDEX(st.name, ' to ', 1), '%h:%i %p'), " + - " STR_TO_DATE(SUBSTRING_INDEX(st.name, ' to ', -1), '%h:%i %p')" + - ") AS duration_hours, " + - "CASE " + - " WHEN bd.to_date < CURDATE() THEN 'Completed' " + - " WHEN (bd.from_date > CURDATE() or bd.to_date>CURDATE()) THEN 'Upcoming' " + - " ELSE 'Ongoing' " + - "END AS status " + - "FROM booking bd " + - "JOIN slots st ON bd.slotids = st.slotid " + - "JOIN buildings bu ON bd.bid = bu.bid " + - "JOIN category c ON bd.cid = c.cid " + - "WHERE bd.booking_id = ?"; - return jdbcTemplate.queryForList(sqlQuery, booking_id); - } - - */ + /* + * public List> getQrPageByBookingId(int booking_id) { + * String sqlQuery = "SELECT " + + * "bd.from_date, " + + * "bd.to_date, " + + * "bd.booking_id, " + + * "bd.user_name, " + + * "bd.mobile, " + + * "bd.amount, " + + * "bd.payment_status, " + + * "bd.no_of_person, " + + * "bd.slotids, " + + * "bu.name AS buildingname, " + + * "st.name AS duration, " + + * "c.name AS type, " + + * "c.display_name AS type_name, " + + * "SUBSTRING_INDEX(st.name, ' to ', 1) AS checkin, " + + * "SUBSTRING_INDEX(st.name, ' to ', -1) AS checkout, " + + * "TIMESTAMPDIFF(HOUR, " + + * " STR_TO_DATE(SUBSTRING_INDEX(st.name, ' to ', 1), '%h:%i %p'), " + + * " STR_TO_DATE(SUBSTRING_INDEX(st.name, ' to ', -1), '%h:%i %p')" + + * ") AS duration_hours, " + + * "CASE " + + * " WHEN bd.to_date < CURDATE() THEN 'Completed' " + + * " WHEN (bd.from_date > CURDATE() or bd.to_date>CURDATE()) THEN 'Upcoming' " + * + + * " ELSE 'Ongoing' " + + * "END AS status " + + * "FROM booking bd " + + * "JOIN slots st ON bd.slotids = st.slotid " + + * "JOIN buildings bu ON bd.bid = bu.bid " + + * "JOIN category c ON bd.cid = c.cid " + + * "WHERE bd.booking_id = ?"; + * + * return jdbcTemplate.queryForList(sqlQuery, booking_id); + * } + * + */ // public String validateLogin(String usernametxt, String pin) { - - // // SQL query - // String sql = "SELECT * FROM login WHERE user_name = ? AND password = ? LIMIT 0,1"; - - // // Execute the query and pass mobileNo and pin as parameters - // List> results = jdbcTemplate.queryForList(sql, usernametxt, pin); - - // // Check if any results were found - // if (!results.isEmpty()) { - // Map login = results.get(0); - // return (String) login.get("user_name"); // Assuming 'reference_name' is a column - // } else { - // return null; // Return null if no matching record was found - // } - // } + // // SQL query + // String sql = "SELECT * FROM login WHERE user_name = ? AND password = ? LIMIT + // 0,1"; + + // // Execute the query and pass mobileNo and pin as parameters + // List> results = jdbcTemplate.queryForList(sql, + // usernametxt, pin); + + // // Check if any results were found + // if (!results.isEmpty()) { + // Map login = results.get(0); + // return (String) login.get("user_name"); // Assuming 'reference_name' is a + // column + // } else { + // return null; // Return null if no matching record was found + // } + // } public Map validateLogin(String username, String password) { @@ -892,29 +1016,86 @@ public class BookingService { List> results = jdbcTemplate.queryForList(sql, username, password); if (!results.isEmpty()) { - return results.get(0); // Contains user_name and bid - } - return null; - + return results.get(0); // Contains user_name and bid + } + return null; + } - + public List> getCalendarBasedOnSubCatId(int scid, String selectedDate) { String sql = "select sum(c.bcount) as booked_count,b.slotids as slotid,c.bdate from booking b " + - "left join calendar c on b.booking_id = c.bookingid " + - "where c.bdate = ? and b.sid = ? group by b.slotids"; - System.err.println(sql+" "+scid+" "+selectedDate); - return jdbcTemplate.queryForList(sql, selectedDate, scid ); + "left join calendar c on b.booking_id = c.bookingid " + + "where c.bdate = ? and b.sid = ? group by b.slotids"; + System.err.println(sql + " " + scid + " " + selectedDate); + return jdbcTemplate.queryForList(sql, selectedDate, scid); } - /*public List> getbookingdetailDashBoard(String fromDate, String toDate, String status) { + /* + * public List> getbookingdetailDashBoard(String fromDate, + * String toDate, String status) { + * StringBuilder sql = new StringBuilder( + * "SELECT " + + * "concat('#', bd.booking_id) AS booking_id, " + + * "bd.user_name, " + + * "bd.mobile, " + + * "c.display_name AS type_name, " + + * "st.name AS duration, " + + * "DATE_FORMAT(bd.cdate, '%d-%m-%Y') AS booked_date, "+ + * "DATE_FORMAT(bd.from_date, '%d-%m-%Y') AS from_date, " + + * "DATE_FORMAT(bd.to_date, '%d-%m-%Y') AS to_date, " + + * "SUBSTRING_INDEX(st.name, ' to ', 1) AS checkin, " + + * "SUBSTRING_INDEX(st.name, ' to ', -1) AS checkout, " + + * "bd.no_of_person AS no_of_seats, " + + * "bd.amount, " + + * "CASE " + + * " WHEN bd.to_date < CURDATE() THEN 'Completed' " + + * " WHEN bd.from_date > CURDATE() THEN 'Upcoming' " + + * " ELSE 'Ongoing' " + + * "END AS status, " + + * "TIMESTAMPDIFF(HOUR, " + + * " STR_TO_DATE(SUBSTRING_INDEX(st.name, ' to ', 1), '%h:%i %p'), " + + * " STR_TO_DATE(SUBSTRING_INDEX(st.name, ' to ', -1), '%h:%i %p') " + + * ") AS duration_hours " + + * "FROM booking bd " + + * "JOIN slots st ON bd.slotids = st.slotid " + + * "JOIN buildings bu ON bd.bid = bu.bid " + + * "JOIN category c ON bd.cid = c.cid " + + * "WHERE DATE(bd.cdate) BETWEEN STR_TO_DATE(?, '%Y-%m-%d') AND STR_TO_DATE(?, '%Y-%m-%d') " + * ); + * + * // Conditionally add the status filter + * if (status != null && !status.isEmpty()) { + * sql.append(" AND CASE " + + * "WHEN bd.to_date < CURDATE() THEN 'Completed' " + + * "WHEN bd.from_date > CURDATE() THEN 'Upcoming' " + + * "ELSE 'Ongoing' END = ?"); + * } + * + * // Prepare the parameters for the query + * List params = new ArrayList<>(); + * params.add(fromDate); + * params.add(toDate); + * + * if (status != null && !status.isEmpty()) { + * params.add(status); + * } + * + * // Execute the query with the constructed SQL and parameters + * return jdbcTemplate.queryForList(sql.toString(), params.toArray()); + * } + */ + public List> getbookingdetailDashBoard( + String fromDate, String toDate, String status, int bid) { + StringBuilder sql = new StringBuilder( "SELECT " + "concat('#', bd.booking_id) AS booking_id, " + "bd.user_name, " + "bd.mobile, " + + "bu.name as building_name, " + "c.display_name AS type_name, " + "st.name AS duration, " + - "DATE_FORMAT(bd.cdate, '%d-%m-%Y') AS booked_date, "+ + "DATE_FORMAT(bd.cdate, '%d-%m-%Y') AS booked_date, " + "DATE_FORMAT(bd.from_date, '%d-%m-%Y') AS from_date, " + "DATE_FORMAT(bd.to_date, '%d-%m-%Y') AS to_date, " + "SUBSTRING_INDEX(st.name, ' to ', 1) AS checkin, " + @@ -934,10 +1115,11 @@ public class BookingService { "JOIN slots st ON bd.slotids = st.slotid " + "JOIN buildings bu ON bd.bid = bu.bid " + "JOIN category c ON bd.cid = c.cid " + - "WHERE DATE(bd.cdate) BETWEEN STR_TO_DATE(?, '%Y-%m-%d') AND STR_TO_DATE(?, '%Y-%m-%d') " + "WHERE DATE(bd.cdate) BETWEEN STR_TO_DATE(?, '%Y-%m-%d') " + + "AND STR_TO_DATE(?, '%Y-%m-%d') " + + "AND bd.bid = ? " // <<< ADD BUILDING FILTER ); - // Conditionally add the status filter if (status != null && !status.isEmpty()) { sql.append(" AND CASE " + "WHEN bd.to_date < CURDATE() THEN 'Completed' " + @@ -945,213 +1127,215 @@ public class BookingService { "ELSE 'Ongoing' END = ?"); } - // Prepare the parameters for the query List params = new ArrayList<>(); params.add(fromDate); params.add(toDate); + params.add(bid); // <<< ADD bid param if (status != null && !status.isEmpty()) { params.add(status); } - // Execute the query with the constructed SQL and parameters return jdbcTemplate.queryForList(sql.toString(), params.toArray()); - }*/ - public List> getbookingdetailDashBoard( - String fromDate, String toDate, String status, int bid) { - - StringBuilder sql = new StringBuilder( - "SELECT " + - "concat('#', bd.booking_id) AS booking_id, " + - "bd.user_name, " + - "bd.mobile, " + - "bu.name as building_name, " + - "c.display_name AS type_name, " + - "st.name AS duration, " + - "DATE_FORMAT(bd.cdate, '%d-%m-%Y') AS booked_date, " + - "DATE_FORMAT(bd.from_date, '%d-%m-%Y') AS from_date, " + - "DATE_FORMAT(bd.to_date, '%d-%m-%Y') AS to_date, " + - "SUBSTRING_INDEX(st.name, ' to ', 1) AS checkin, " + - "SUBSTRING_INDEX(st.name, ' to ', -1) AS checkout, " + - "bd.no_of_person AS no_of_seats, " + - "bd.amount, " + - "CASE " + - " WHEN bd.to_date < CURDATE() THEN 'Completed' " + - " WHEN bd.from_date > CURDATE() THEN 'Upcoming' " + - " ELSE 'Ongoing' " + - "END AS status, " + - "TIMESTAMPDIFF(HOUR, " + - " STR_TO_DATE(SUBSTRING_INDEX(st.name, ' to ', 1), '%h:%i %p'), " + - " STR_TO_DATE(SUBSTRING_INDEX(st.name, ' to ', -1), '%h:%i %p') " + - ") AS duration_hours " + - "FROM booking bd " + - "JOIN slots st ON bd.slotids = st.slotid " + - "JOIN buildings bu ON bd.bid = bu.bid " + - "JOIN category c ON bd.cid = c.cid " + - "WHERE DATE(bd.cdate) BETWEEN STR_TO_DATE(?, '%Y-%m-%d') " + - "AND STR_TO_DATE(?, '%Y-%m-%d') " + - "AND bd.bid = ? " // <<< ADD BUILDING FILTER - ); - - if (status != null && !status.isEmpty()) { - sql.append(" AND CASE " + - "WHEN bd.to_date < CURDATE() THEN 'Completed' " + - "WHEN bd.from_date > CURDATE() THEN 'Upcoming' " + - "ELSE 'Ongoing' END = ?"); - } - - List params = new ArrayList<>(); - params.add(fromDate); - params.add(toDate); - params.add(bid); // <<< ADD bid param - - if (status != null && !status.isEmpty()) { - params.add(status); } - return jdbcTemplate.queryForList(sql.toString(), params.toArray()); -} - - - /* public List> getAmountCollectedByDate(LocalDate fromDate, LocalDate toDate) { - String sql = "SELECT COALESCE(SUM(b.amount), 0) AS overall_amount_collected, " + - "COALESCE(SUM(CASE WHEN b.sid = 1 THEN b.amount ELSE 0 END), 0) AS learning_zone_amount_collected, " + - "COALESCE(SUM(CASE WHEN b.sid IN (2, 3, 4) THEN b.amount ELSE 0 END), 0) AS desk_space_amount_collected, " + - "COALESCE(SUM(CASE WHEN b.sid IN (5, 6, 7) THEN b.amount ELSE 0 END), 0) AS meeting_room_amount_collected " + + /* + * public List> getAmountCollectedByDate(LocalDate fromDate, + * LocalDate toDate) { + * String sql = + * "SELECT COALESCE(SUM(b.amount), 0) AS overall_amount_collected, " + + * "COALESCE(SUM(CASE WHEN b.sid = 1 THEN b.amount ELSE 0 END), 0) AS learning_zone_amount_collected, " + * + + * "COALESCE(SUM(CASE WHEN b.sid IN (2, 3, 4) THEN b.amount ELSE 0 END), 0) AS desk_space_amount_collected, " + * + + * "COALESCE(SUM(CASE WHEN b.sid IN (5, 6, 7) THEN b.amount ELSE 0 END), 0) AS meeting_room_amount_collected " + * + + * "FROM booking b " + + * "WHERE DATE(b.cdate) BETWEEN ? AND ? " + + * "AND b.booking_status = 'success'"; + * + * System.err.println(sql + " " + fromDate + " to " + toDate); + * return jdbcTemplate.queryForList(sql, fromDate, toDate); + * } + */ + public List> getAmountCollectedByDate(LocalDate fromDate, LocalDate toDate, int bid) { + String sql = "SELECT " + + "b.bid, " + + "COALESCE(SUM(b.amount), 0) AS overall_amount_collected, " + + "COALESCE(SUM(CASE WHEN b.sid IN (1,8) THEN b.amount ELSE 0 END), 0) AS learning_zone_amount_collected, " + + + "COALESCE(SUM(CASE WHEN b.sid IN (2, 3, 4) THEN b.amount ELSE 0 END), 0) AS desk_space_amount_collected, " + + + "COALESCE(SUM(CASE WHEN b.sid IN (5, 6, 7) THEN b.amount ELSE 0 END), 0) AS meeting_room_amount_collected " + + "FROM booking b " + "WHERE DATE(b.cdate) BETWEEN ? AND ? " + - "AND b.booking_status = 'success'"; + "AND b.booking_status = 'success' " + + "AND b.bid = ?"; // <-- added building ID filter - System.err.println(sql + " " + fromDate + " to " + toDate); - return jdbcTemplate.queryForList(sql, fromDate, toDate); - }*/ - public List> getAmountCollectedByDate(LocalDate fromDate, LocalDate toDate, int bid) { - String sql = "SELECT " + - "b.bid, " + - "COALESCE(SUM(b.amount), 0) AS overall_amount_collected, " + - "COALESCE(SUM(CASE WHEN b.sid = 1 THEN b.amount ELSE 0 END), 0) AS learning_zone_amount_collected, " + - "COALESCE(SUM(CASE WHEN b.sid IN (2, 3, 4) THEN b.amount ELSE 0 END), 0) AS desk_space_amount_collected, " + - "COALESCE(SUM(CASE WHEN b.sid IN (5, 6, 7) THEN b.amount ELSE 0 END), 0) AS meeting_room_amount_collected " + - "FROM booking b " + - "WHERE DATE(b.cdate) BETWEEN ? AND ? " + - "AND b.booking_status = 'success' " + - "AND b.bid = ?"; // <-- added building ID filter - - System.err.println(sql + " | " + fromDate + " to " + toDate + " | bid: " + bid); - - return jdbcTemplate.queryForList(sql, fromDate, toDate, bid); -} + System.err.println(sql + " | " + fromDate + " to " + toDate + " | bid: " + bid); + + return jdbcTemplate.queryForList(sql, fromDate, toDate, bid); + } - /* - public List> getBookingCountsByCategory(String fromDate, String toDate) { - String sql = "SELECT " + - "COALESCE(SUM(CASE WHEN sid = 1 AND slotids = 1 THEN no_of_person ELSE 0 END), 0) AS slotId_1_count, " + - "COALESCE(SUM(CASE WHEN sid = 1 AND slotids = 2 THEN no_of_person ELSE 0 END), 0) AS slotId_2_count, " + - "COALESCE(SUM(CASE WHEN sid = 1 AND slotids = 3 THEN no_of_person ELSE 0 END), 0) AS slotId_3_count, " + - "COALESCE(SUM(CASE WHEN sid = 1 AND slotids = 4 THEN no_of_person ELSE 0 END), 0) AS slotId_4_count, " + - "COALESCE(SUM(CASE WHEN sid = 1 AND slotids = 5 THEN no_of_person ELSE 0 END), 0) AS slotId_5_count, " + - "COALESCE(SUM(CASE WHEN sid IN (2, 3, 4) AND slotids IN (6, 7) THEN no_of_person ELSE 0 END), 0) AS half_day_count, " + - "COALESCE(SUM(CASE WHEN sid IN (2, 3, 4) AND slotids = 8 THEN no_of_person ELSE 0 END), 0) AS full_day_count, " + - "COALESCE(SUM(CASE WHEN sid IN (4) AND slotids = 9 THEN no_of_person ELSE 0 END), 0) AS monthly_count, " + - "COALESCE(SUM(CASE WHEN sid IN (5, 6, 7) AND slotids IN (10,11,12,13,14,15,16,17,18,19,20,21,22) THEN no_of_person ELSE 0 END), 0) AS RoomNo1_Count, " + - "COALESCE(SUM(CASE WHEN sid IN (5, 6, 7) AND slotids IN (23,24,25,26,27,28,29,30,31,32,33,34,35) THEN no_of_person ELSE 0 END), 0) AS RoomNo2_Count, " + - "COALESCE(SUM(CASE WHEN sid IN (5, 6, 7) AND slotids IN (36,37,38,39,40,41,42,43,44,45,46,47,48) THEN no_of_person ELSE 0 END), 0) AS RoomNo3_Count " + - "FROM booking " + - "WHERE booking_status = 'success' " + - "AND DATE(cdate) BETWEEN ? AND ?"; + * public List> getBookingCountsByCategory(String fromDate, + * String toDate) { + * String sql = "SELECT " + + * "COALESCE(SUM(CASE WHEN sid = 1 AND slotids = 1 THEN no_of_person ELSE 0 END), 0) AS slotId_1_count, " + * + + * "COALESCE(SUM(CASE WHEN sid = 1 AND slotids = 2 THEN no_of_person ELSE 0 END), 0) AS slotId_2_count, " + * + + * "COALESCE(SUM(CASE WHEN sid = 1 AND slotids = 3 THEN no_of_person ELSE 0 END), 0) AS slotId_3_count, " + * + + * "COALESCE(SUM(CASE WHEN sid = 1 AND slotids = 4 THEN no_of_person ELSE 0 END), 0) AS slotId_4_count, " + * + + * "COALESCE(SUM(CASE WHEN sid = 1 AND slotids = 5 THEN no_of_person ELSE 0 END), 0) AS slotId_5_count, " + * + + * "COALESCE(SUM(CASE WHEN sid IN (2, 3, 4) AND slotids IN (6, 7) THEN no_of_person ELSE 0 END), 0) AS half_day_count, " + * + + * "COALESCE(SUM(CASE WHEN sid IN (2, 3, 4) AND slotids = 8 THEN no_of_person ELSE 0 END), 0) AS full_day_count, " + * + + * "COALESCE(SUM(CASE WHEN sid IN (4) AND slotids = 9 THEN no_of_person ELSE 0 END), 0) AS monthly_count, " + * + + * "COALESCE(SUM(CASE WHEN sid IN (5, 6, 7) AND slotids IN (10,11,12,13,14,15,16,17,18,19,20,21,22) THEN no_of_person ELSE 0 END), 0) AS RoomNo1_Count, " + * + + * "COALESCE(SUM(CASE WHEN sid IN (5, 6, 7) AND slotids IN (23,24,25,26,27,28,29,30,31,32,33,34,35) THEN no_of_person ELSE 0 END), 0) AS RoomNo2_Count, " + * + + * "COALESCE(SUM(CASE WHEN sid IN (5, 6, 7) AND slotids IN (36,37,38,39,40,41,42,43,44,45,46,47,48) THEN no_of_person ELSE 0 END), 0) AS RoomNo3_Count " + * + + * "FROM booking " + + * "WHERE booking_status = 'success' " + + * "AND DATE(cdate) BETWEEN ? AND ?"; + * + * // Query and return result as a List of Maps + * return jdbcTemplate.queryForList(sql, fromDate, toDate); + * } + */ + // previous + /* + * public List> getBookingCountsByCategory(String fromDate, + * String toDate) { + * String sql = "SELECT " + + * "COALESCE(SUM(CASE WHEN sid = 1 AND slotids = 1 THEN 1 ELSE 0 END), 0) AS slotId_1_count, " + * + + * "COALESCE(SUM(CASE WHEN sid = 1 AND slotids = 2 THEN 1 ELSE 0 END), 0) AS slotId_2_count, " + * + + * "COALESCE(SUM(CASE WHEN sid = 1 AND slotids = 3 THEN 1 ELSE 0 END), 0) AS slotId_3_count, " + * + + * "COALESCE(SUM(CASE WHEN sid = 1 AND slotids = 4 THEN 1 ELSE 0 END), 0) AS slotId_4_count, " + * + + * "COALESCE(SUM(CASE WHEN sid = 1 AND slotids = 5 THEN 1 ELSE 0 END), 0) AS slotId_5_count, " + * + + * "COALESCE(SUM(CASE WHEN sid = 2 AND slotids IN (6, 7) THEN 1 ELSE 0 END), 0) AS half_day_count, " + * + + * "COALESCE(SUM(CASE WHEN sid = 3 AND slotids = 8 THEN 1 ELSE 0 END), 0) AS full_day_count, " + * + + * "COALESCE(SUM(CASE WHEN sid = 4 AND slotids = 9 THEN 1 ELSE 0 END), 0) AS monthly_count, " + * + + * "COALESCE(SUM(CASE WHEN sid = 5 AND slotids IN (10,11,12,13,14,15,16,17,18,19,20,21,22) THEN 1 ELSE 0 END), 0) AS RoomNo1_Count, " + * + + * "COALESCE(SUM(CASE WHEN sid = 6 AND slotids IN (23,24,25,26,27,28,29,30,31,32,33,34,35) THEN 1 ELSE 0 END), 0) AS RoomNo2_Count, " + * + + * "COALESCE(SUM(CASE WHEN sid = 7 AND slotids IN (36,37,38,39,40,41,42,43,44,45,46,47,48) THEN 1 ELSE 0 END), 0) AS RoomNo3_Count " + * + + * "FROM booking " + + * "WHERE booking_status = 'success' " + + * "AND DATE(cdate) BETWEEN ? AND ?"; + * + * // Query and return result as a List of Maps + * return jdbcTemplate.queryForList(sql, fromDate, toDate); + * } + */ + + // working changed but build2 is not configured for charts + public List> getBookingCountsByCategory(String fromDate, String toDate, int bid) { - // Query and return result as a List of Maps - return jdbcTemplate.queryForList(sql, fromDate, toDate); - } - */ - //previous - /*public List> getBookingCountsByCategory(String fromDate, String toDate) { String sql = "SELECT " + - "COALESCE(SUM(CASE WHEN sid = 1 AND slotids = 1 THEN 1 ELSE 0 END), 0) AS slotId_1_count, " + - "COALESCE(SUM(CASE WHEN sid = 1 AND slotids = 2 THEN 1 ELSE 0 END), 0) AS slotId_2_count, " + - "COALESCE(SUM(CASE WHEN sid = 1 AND slotids = 3 THEN 1 ELSE 0 END), 0) AS slotId_3_count, " + - "COALESCE(SUM(CASE WHEN sid = 1 AND slotids = 4 THEN 1 ELSE 0 END), 0) AS slotId_4_count, " + - "COALESCE(SUM(CASE WHEN sid = 1 AND slotids = 5 THEN 1 ELSE 0 END), 0) AS slotId_5_count, " + - "COALESCE(SUM(CASE WHEN sid = 2 AND slotids IN (6, 7) THEN 1 ELSE 0 END), 0) AS half_day_count, " + + /* + * "COALESCE(SUM(CASE WHEN sid = 1 AND slotids = 1 THEN 1 ELSE 0 END), 0) AS slotId_1_count, " + * + + * "COALESCE(SUM(CASE WHEN sid = 1 AND slotids = 2 THEN 1 ELSE 0 END), 0) AS slotId_2_count, " + * + + * "COALESCE(SUM(CASE WHEN sid = 1 AND slotids = 3 THEN 1 ELSE 0 END), 0) AS slotId_3_count, " + * + + * "COALESCE(SUM(CASE WHEN sid = 1 AND slotids = 4 THEN 1 ELSE 0 END), 0) AS slotId_4_count, " + * + + * "COALESCE(SUM(CASE WHEN sid = 1 AND slotids = 5 THEN 1 ELSE 0 END), 0) AS slotId_5_count, " + * + + */ + "COALESCE(SUM(CASE WHEN sid in (1,8) AND slotids in (1,49) THEN 1 ELSE 0 END), 0) AS slotId_1_count, " + + + "COALESCE(SUM(CASE WHEN sid in (1,8) AND slotids in (2,50) THEN 1 ELSE 0 END), 0) AS slotId_2_count, " + + "COALESCE(SUM(CASE WHEN sid in (1,8) AND slotids in (3,51) THEN 1 ELSE 0 END), 0) AS slotId_3_count, " + + "COALESCE(SUM(CASE WHEN sid in (1,8) AND slotids in (4,52) THEN 1 ELSE 0 END), 0) AS slotId_4_count, " + + "COALESCE(SUM(CASE WHEN sid in (1,8) AND slotids in (5,53) THEN 1 ELSE 0 END), 0) AS slotId_5_count, " + + + "COALESCE(SUM(CASE WHEN sid = 2 AND slotids IN (6,7) THEN 1 ELSE 0 END), 0) AS half_day_count, " + "COALESCE(SUM(CASE WHEN sid = 3 AND slotids = 8 THEN 1 ELSE 0 END), 0) AS full_day_count, " + "COALESCE(SUM(CASE WHEN sid = 4 AND slotids = 9 THEN 1 ELSE 0 END), 0) AS monthly_count, " + - "COALESCE(SUM(CASE WHEN sid = 5 AND slotids IN (10,11,12,13,14,15,16,17,18,19,20,21,22) THEN 1 ELSE 0 END), 0) AS RoomNo1_Count, " + - "COALESCE(SUM(CASE WHEN sid = 6 AND slotids IN (23,24,25,26,27,28,29,30,31,32,33,34,35) THEN 1 ELSE 0 END), 0) AS RoomNo2_Count, " + - "COALESCE(SUM(CASE WHEN sid = 7 AND slotids IN (36,37,38,39,40,41,42,43,44,45,46,47,48) THEN 1 ELSE 0 END), 0) AS RoomNo3_Count " + - "FROM booking " + - "WHERE booking_status = 'success' " + - "AND DATE(cdate) BETWEEN ? AND ?"; - // Query and return result as a List of Maps - return jdbcTemplate.queryForList(sql, fromDate, toDate); - }*/ - public List> getBookingCountsByCategory(String fromDate, String toDate, int bid) { - - String sql = "SELECT " + - "COALESCE(SUM(CASE WHEN sid = 1 AND slotids = 1 THEN 1 ELSE 0 END), 0) AS slotId_1_count, " + - "COALESCE(SUM(CASE WHEN sid = 1 AND slotids = 2 THEN 1 ELSE 0 END), 0) AS slotId_2_count, " + - "COALESCE(SUM(CASE WHEN sid = 1 AND slotids = 3 THEN 1 ELSE 0 END), 0) AS slotId_3_count, " + - "COALESCE(SUM(CASE WHEN sid = 1 AND slotids = 4 THEN 1 ELSE 0 END), 0) AS slotId_4_count, " + - "COALESCE(SUM(CASE WHEN sid = 1 AND slotids = 5 THEN 1 ELSE 0 END), 0) AS slotId_5_count, " + - - "COALESCE(SUM(CASE WHEN sid = 2 AND slotids IN (6,7) THEN 1 ELSE 0 END), 0) AS half_day_count, " + - "COALESCE(SUM(CASE WHEN sid = 3 AND slotids = 8 THEN 1 ELSE 0 END), 0) AS full_day_count, " + - "COALESCE(SUM(CASE WHEN sid = 4 AND slotids = 9 THEN 1 ELSE 0 END), 0) AS monthly_count, " + + "COALESCE(SUM(CASE WHEN sid = 5 AND slotids IN (10,11,12,13,14,15,16,17,18,19,20,21,22) THEN 1 ELSE 0 END), 0) AS RoomNo1_Count, " + + + "COALESCE(SUM(CASE WHEN sid = 6 AND slotids IN (23,24,25,26,27,28,29,30,31,32,33,34,35) THEN 1 ELSE 0 END), 0) AS RoomNo2_Count, " + + + "COALESCE(SUM(CASE WHEN sid = 7 AND slotids IN (36,37,38,39,40,41,42,43,44,45,46,47,48) THEN 1 ELSE 0 END), 0) AS RoomNo3_Count " + + - "COALESCE(SUM(CASE WHEN sid = 5 AND slotids IN (10,11,12,13,14,15,16,17,18,19,20,21,22) THEN 1 ELSE 0 END), 0) AS RoomNo1_Count, " + - "COALESCE(SUM(CASE WHEN sid = 6 AND slotids IN (23,24,25,26,27,28,29,30,31,32,33,34,35) THEN 1 ELSE 0 END), 0) AS RoomNo2_Count, " + - "COALESCE(SUM(CASE WHEN sid = 7 AND slotids IN (36,37,38,39,40,41,42,43,44,45,46,47,48) THEN 1 ELSE 0 END), 0) AS RoomNo3_Count " + + "FROM booking " + + "WHERE booking_status = 'success' " + + "AND DATE(cdate) BETWEEN ? AND ? " + + "AND bid = ?"; // <--- Filter by building ID - "FROM booking " + - "WHERE booking_status = 'success' " + - "AND DATE(cdate) BETWEEN ? AND ? " + - "AND bid = ?"; // <--- Filter by building ID + return jdbcTemplate.queryForList(sql, fromDate, toDate, bid); + } - return jdbcTemplate.queryForList(sql, fromDate, toDate, bid); -} + // previous + /* + * public List> getBookingCountsByDate(String fromDate, + * String toDate) { + * // SQL query + * String sql = "SELECT " + + * "count(booking_id) AS Total_booking_count, " + + * "SUM(CASE WHEN cid = 1 THEN 1 ELSE 0 END) AS Learning_zone_count, " + + * "SUM(CASE WHEN cid = 2 THEN 1 ELSE 0 END) AS Desk_space_count, " + + * "SUM(CASE WHEN cid = 3 THEN 1 ELSE 0 END) AS Meeting_room_count " + + * "FROM booking " + + * "WHERE booking_status = 'success' and DATE(cdate) BETWEEN ? AND ?"; + * + * // Query and return result as a Map + * return jdbcTemplate.queryForList(sql,fromDate,toDate); + * } + */ + public List> getBookingCountsByDate(String fromDate, String toDate, int bid) { - //previous - /* public List> getBookingCountsByDate(String fromDate, String toDate) { - // SQL query String sql = "SELECT " + - "count(booking_id) AS Total_booking_count, " + - "SUM(CASE WHEN cid = 1 THEN 1 ELSE 0 END) AS Learning_zone_count, " + + "COUNT(booking_id) AS Total_booking_count, " + + "SUM(CASE WHEN cid in (1,4) THEN 1 ELSE 0 END) AS Learning_zone_count, " + "SUM(CASE WHEN cid = 2 THEN 1 ELSE 0 END) AS Desk_space_count, " + "SUM(CASE WHEN cid = 3 THEN 1 ELSE 0 END) AS Meeting_room_count " + "FROM booking " + - "WHERE booking_status = 'success' and DATE(cdate) BETWEEN ? AND ?"; - - // Query and return result as a Map - return jdbcTemplate.queryForList(sql,fromDate,toDate); - }*/ - public List> getBookingCountsByDate(String fromDate, String toDate, int bid) { + "WHERE booking_status = 'success' " + + "AND DATE(cdate) BETWEEN ? AND ? " + + "AND bid = ?"; // <--- ADD BID FILTER - String sql = "SELECT " + - "COUNT(booking_id) AS Total_booking_count, " + - "SUM(CASE WHEN cid = 1 THEN 1 ELSE 0 END) AS Learning_zone_count, " + - "SUM(CASE WHEN cid = 2 THEN 1 ELSE 0 END) AS Desk_space_count, " + - "SUM(CASE WHEN cid = 3 THEN 1 ELSE 0 END) AS Meeting_room_count " + - "FROM booking " + - "WHERE booking_status = 'success' " + - "AND DATE(cdate) BETWEEN ? AND ? " + - "AND bid = ?"; // <--- ADD BID FILTER - - return jdbcTemplate.queryForList(sql, fromDate, toDate, bid); -} + return jdbcTemplate.queryForList(sql, fromDate, toDate, bid); + } - //ak - /* public List> getBidByUserName(String userName) { - String sql = "SELECT bid FROM login WHERE user_name = ?"; - return jdbcTemplate.queryForList(sql, userName); - }*/ + // ak + /* + * public List> getBidByUserName(String userName) { + * String sql = "SELECT bid FROM login WHERE user_name = ?"; + * return jdbcTemplate.queryForList(sql, userName); + * } + */ public Integer getBidByUserName(String userName) { try { String sql = "SELECT bid FROM login WHERE user_name = ?"; - return jdbcTemplate.queryForObject(sql, new Object[]{userName}, Integer.class); + return jdbcTemplate.queryForObject(sql, new Object[] { userName }, Integer.class); } catch (EmptyResultDataAccessException e) { return null; // user not found } } - + } diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index 1f00896..d802b20 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -1,6 +1,6 @@ spring.application.name=conferencehall -#spring.profiles.active=dev -spring.profiles.active=prod +spring.profiles.active=dev +#spring.profiles.active=prod server.port=8074 diff --git a/src/main/resources/templates/caretaker/officer-dashboard.html b/src/main/resources/templates/caretaker/officer-dashboard.html index 6557e51..c5f773f 100644 --- a/src/main/resources/templates/caretaker/officer-dashboard.html +++ b/src/main/resources/templates/caretaker/officer-dashboard.html @@ -1,1020 +1,1040 @@ + -Officer Dashboard - - - - - - - + Officer Dashboard + + + + + + + + * { + box-sizing: border-box; + margin: 0; + padding: 0; + font-family: Arial, sans-serif; + } - + .containers { + background-color: #f4f4f9; + color: #333; + display: flex; + flex-direction: column; + align-items: center; + } - -
- - -
-
- -
- - -
- -
- -
-
- -
-
- -
-
- - - -
-
-
- - -
Overall Amount Collected
-
Rs. 0
-
-
-
-
- -
Desk Space - Amount Collected
-
Rs. 0
-
-
-
-
- -
Conference Hall - Amount - Collected
-
Rs. 1xxxx
-
-
-
-
- -
Learning Centre - Amount - Collected
-
Rs. 1xxxx
-
-
-
- - - -
-
-
- -

Overall Total No of Bookings

-
- -
-
-
- -
-
- - -

Desk Space - Total No of Bookings

-
- -
-
-
-
-
- -

Conference Hall - No of Bookings

-
- -
-
-
-
-
- -

Learning Centre - Total No of Bookings

-
- -
-
-
-
- - + .table-responsive { + overflow-x: auto; + width: 100%; + } + /*.date-div{*/ + /* !*max-width: 1300px;*!*/ + /* !*display: flex;*!*/ + /* align-items: start;*/ + /* justify-content: start;*/ + /*}*/ + .container { + display: flex; + gap: 30px; + max-width: 1125px; + margin-top: 20px; + } -
-
-
- - -
-
- - - - - - - - - - - - - - - - -
-
-
- - - - - - - - - - - - - - - - - - - - - -
S.NoBooking IDBuilding nameUserNamePhoneNumberTypeDurationFrom DateTo DateCheck InCheck OutNo of SeatAmountBooked OnStatus
-
- -
-
-
-
-
- -
-
-
- - - - - - - - - - - - - - + + + + + + + + + + \ No newline at end of file diff --git a/src/main/resources/templates/user/book-Conferance.html b/src/main/resources/templates/user/book-Conferance.html index 972f51e..e7c1937 100644 --- a/src/main/resources/templates/user/book-Conferance.html +++ b/src/main/resources/templates/user/book-Conferance.html @@ -1,42 +1,44 @@ +
+ - -
- -
-
- - - -
- -
-
- -
-
-
- -