From fe55d8550b0593577b70199ba58a5789a6375dbc Mon Sep 17 00:00:00 2001 From: AJITHKUMAR12 Date: Sat, 3 Jan 2026 15:42:26 +0530 Subject: [PATCH] modified for downloading pdf on acknowledgement page --- .../controller/UserController.java | 206 ++++++++++-------- .../templates/user/acknowledgement.html | 9 +- 2 files changed, 118 insertions(+), 97 deletions(-) diff --git a/src/main/java/com/gcc/communityHall/controller/UserController.java b/src/main/java/com/gcc/communityHall/controller/UserController.java index 14fb7c0f..66464c01 100644 --- a/src/main/java/com/gcc/communityHall/controller/UserController.java +++ b/src/main/java/com/gcc/communityHall/controller/UserController.java @@ -1,6 +1,5 @@ package com.gcc.communityHall.controller; - import java.time.LocalDate; import java.util.ArrayList; import java.util.HashMap; @@ -36,7 +35,7 @@ import com.gcc.communityHall.service.UserService; import com.gcc.communityHall.service.Impl.WhatsappMsgServiceImpl; @Controller -@RequestMapping(value = {"/communityhall/user", "/communityhall", "", "/"}) +@RequestMapping(value = { "/communityhall/user", "/communityhall", "", "/" }) public class UserController { @Autowired @@ -49,7 +48,6 @@ public class UserController { @Autowired private HallDetailService hallDetailsService; - @Autowired private UserService userService; @@ -65,7 +63,7 @@ public class UserController { @Autowired private NotificationRepository notificationRepository; - @GetMapping(value = {"", "/", "/dashboard", "/index"}) + @GetMapping(value = { "", "/", "/dashboard", "/index" }) public String viewDashboard(Model model) { List halls = hallDetailsRepository.findActiveHalls(); List hallnames = hallDetailsService.getHallNames(); @@ -82,28 +80,29 @@ public class UserController { for (Notification notification : newnotification) { notificationText.append(notification.getNotification_description()); } -// System.out.println("user controller \nCounter Id: "+userSession.getCounter()+"\nCounter Name: "+userSession.getCounterName()); + // System.out.println("user controller \nCounter Id: + // "+userSession.getCounter()+"\nCounter Name: "+userSession.getCounterName()); // Pass the concatenated string to the model model.addAttribute("newnotification", notificationText.toString()); model.addAttribute("userName", userSession.getDispayName()); model.addAttribute("halls", halls); model.addAttribute("hallnames", hallnames); - model.addAttribute("serverDate", LocalDate.now().toString()); //for server date + model.addAttribute("serverDate", LocalDate.now().toString()); // for server date model.addAttribute("counter", userSession.getCounter()); model.addAttribute("counterName", userSession.getCounterName()); return "user/dashboard"; } - //Checkavilability Api + // Checkavilability Api @GetMapping("/checkAvail") public String checkAvail(@RequestParam("fromDate") String fromDate, - @RequestParam("toDate") String toDate, - @RequestParam("starting") String starting, - @RequestParam("ending") String ending, - @RequestParam(name = "hallId", required = false) String hallId, - @RequestParam(name = "zone", required = false) String zone, - Model model) { + @RequestParam("toDate") String toDate, + @RequestParam("starting") String starting, + @RequestParam("ending") String ending, + @RequestParam(name = "hallId", required = false) String hallId, + @RequestParam(name = "zone", required = false) String zone, + Model model) { List newnotification = notificationRepository.findActivenotifications(); @@ -138,7 +137,8 @@ public class UserController { } // Fetch calendar data based on provided parameters - List data = calendarService.getCalendarByDateAndHallIdAndSlot(fromDate, toDate, starting, ending, hallIdd); + List data = calendarService.getCalendarByDateAndHallIdAndSlot(fromDate, toDate, starting, + ending, hallIdd); HashSet removeHallId = new HashSet<>(); // Collect hall IDs to be removed @@ -151,16 +151,21 @@ public class UserController { if (isSameDay) { // Same day booking cases - if (isMorningStart && isMorningEnd && (calendar.getBdate().toString().equals(fromDate) && calendar.isMorningSlot())) { - // System.out.println("Same day morning-morning match found: hallId=" + calendar.getHallId()); + if (isMorningStart && isMorningEnd + && (calendar.getBdate().toString().equals(fromDate) && calendar.isMorningSlot())) { + // System.out.println("Same day morning-morning match found: hallId=" + + // calendar.getHallId()); removeHallId.add(calendar.getHallId()); - } else if (isEveningStart && isEveningEnd && (calendar.getBdate().toString().equals(fromDate) && calendar.isEveningSlot())) { - // System.out.println("Same day evening-evening match found: hallId=" + calendar.getHallId()); + } else if (isEveningStart && isEveningEnd + && (calendar.getBdate().toString().equals(fromDate) && calendar.isEveningSlot())) { + // System.out.println("Same day evening-evening match found: hallId=" + + // calendar.getHallId()); removeHallId.add(calendar.getHallId()); } else if (isMorningStart && isEveningEnd && ((calendar.getBdate().toString().equals(fromDate) && calendar.isMorningSlot()) || (calendar.getBdate().toString().equals(toDate) && calendar.isEveningSlot()))) { - // System.out.println("Same day morning-evening match found: hallId=" + calendar.getHallId()); + // System.out.println("Same day morning-evening match found: hallId=" + + // calendar.getHallId()); removeHallId.add(calendar.getHallId()); } } else { @@ -168,22 +173,26 @@ public class UserController { if ((isMorningStart && isMorningEnd) && ((calendar.getBdate().toString().equals(fromDate) && calendar.isMorningSlot()) || (calendar.getBdate().toString().equals(toDate) && calendar.isMorningSlot()))) { - // System.out.println("Multi-day morning-morning match found: hallId=" + calendar.getHallId()); + // System.out.println("Multi-day morning-morning match found: hallId=" + + // calendar.getHallId()); removeHallId.add(calendar.getHallId()); } else if ((isEveningStart && isEveningEnd) && ((calendar.getBdate().toString().equals(fromDate) && calendar.isEveningSlot()) || (calendar.getBdate().toString().equals(toDate) && calendar.isEveningSlot()))) { - // System.out.println("Multi-day evening-evening match found: hallId=" + calendar.getHallId()); + // System.out.println("Multi-day evening-evening match found: hallId=" + + // calendar.getHallId()); removeHallId.add(calendar.getHallId()); } else if (isMorningStart && isEveningEnd && ((calendar.getBdate().toString().equals(fromDate) && calendar.isMorningSlot()) || (calendar.getBdate().toString().equals(toDate) && calendar.isEveningSlot()))) { - // System.out.println("Multi-day morning-evening match found: hallId=" + calendar.getHallId()); + // System.out.println("Multi-day morning-evening match found: hallId=" + + // calendar.getHallId()); removeHallId.add(calendar.getHallId()); } else if (isEveningStart && isMorningEnd && ((calendar.getBdate().toString().equals(fromDate) && calendar.isEveningSlot()) || (calendar.getBdate().toString().equals(toDate) && calendar.isMorningSlot()))) { - //System.out.println("Multi-day evening-morning match found: hallId=" + calendar.getHallId()); + // System.out.println("Multi-day evening-morning match found: hallId=" + + // calendar.getHallId()); removeHallId.add(calendar.getHallId()); } } @@ -216,7 +225,6 @@ public class UserController { return "user/dashboard"; } - @PostMapping("/newregistrationform") public String showRegistrationForm(@ModelAttribute("newform") Users newform, Model model) { Users user = userService.user(newform); @@ -225,18 +233,26 @@ public class UserController { userSession.setUserId(user.getUserId()); userSession.setUserType(user.getUsertype().toString()); System.out.println("usetrtype==" + user.getUsertype().toString()); - //System.out.println("employee id"+user.getGovernmentId()); - //System.out.println("employee id"+user.getDepartment()); + // System.out.println("employee id"+user.getGovernmentId()); + // System.out.println("employee id"+user.getDepartment()); if (user.getUsertype() == userType.PUBLIC) { String registersms = "Welcome to GCC, Your User Registration for booking Community Centre is successful."; - String registerurlString = "https://tmegov.onex-aura.com/api/sms?key=pfTEYN6H&to=" + user.getMobileNo() + "&from=GCCCRP&body=" + registersms + "&entityid=1401572690000011081&templateid=1407172346621223019"; - String registerwhatsupmsg = "https://media.smsgupshup.com/GatewayAPI/rest?userid=2000233507&password=h2YjFNcJ&send_to=" + user.getMobileNo() + "&v=1.1&format=json&msg_type=TEXT&method=SENDMESSAGE&msg=Welcome+to+GCC%2C+%0A%0AYour+User+Registration+for+booking+Community+Centre+is+successful."; + String registerurlString = "https://tmegov.onex-aura.com/api/sms?key=pfTEYN6H&to=" + user.getMobileNo() + + "&from=GCCCRP&body=" + registersms + + "&entityid=1401572690000011081&templateid=1407172346621223019"; + String registerwhatsupmsg = "https://media.smsgupshup.com/GatewayAPI/rest?userid=2000233507&password=h2YjFNcJ&send_to=" + + user.getMobileNo() + + "&v=1.1&format=json&msg_type=TEXT&method=SENDMESSAGE&msg=Welcome+to+GCC%2C+%0A%0AYour+User+Registration+for+booking+Community+Centre+is+successful."; whatsappMsgServiceImpl.sendMsg(registerwhatsupmsg); whatsappMsgServiceImpl.sendSMS(registerurlString); } else { String registerpendingsms = "Welcome to GCC, Your User Registration request for booking Community Centre is submitted successfully."; - String registerpendingurlString = "https://tmegov.onex-aura.com/api/sms?key=pfTEYN6H&to=" + user.getMobileNo() + "&from=GCCCRP&body=" + registerpendingsms + "&entityid=1401572690000011081&templateid=1407172346629919381"; - String registerpendingwhatsupmsg = "https://media.smsgupshup.com/GatewayAPI/rest?userid=2000233507&password=h2YjFNcJ&send_to=" + user.getMobileNo() + "&v=1.1&format=json&msg_type=TEXT&method=SENDMESSAGE&msg=Welcome+to+GCC%2C+%0A%0AYour+User+Registration+request+for+booking+Community+Centre+submitted+successfully."; + String registerpendingurlString = "https://tmegov.onex-aura.com/api/sms?key=pfTEYN6H&to=" + + user.getMobileNo() + "&from=GCCCRP&body=" + registerpendingsms + + "&entityid=1401572690000011081&templateid=1407172346629919381"; + String registerpendingwhatsupmsg = "https://media.smsgupshup.com/GatewayAPI/rest?userid=2000233507&password=h2YjFNcJ&send_to=" + + user.getMobileNo() + + "&v=1.1&format=json&msg_type=TEXT&method=SENDMESSAGE&msg=Welcome+to+GCC%2C+%0A%0AYour+User+Registration+request+for+booking+Community+Centre+submitted+successfully."; whatsappMsgServiceImpl.sendMsg(registerpendingwhatsupmsg); whatsappMsgServiceImpl.sendSMS(registerpendingurlString); } @@ -246,40 +262,43 @@ public class UserController { @GetMapping("/hallbookingform") public String viewform(Model model) { String username = userSession.getDispayName(); -// System.out.println("server Date22....."+LocalDate.now().toString()); - model.addAttribute("serverDate", LocalDate.now().toString()); //for server date + // System.out.println("server Date22....."+LocalDate.now().toString()); + model.addAttribute("serverDate", LocalDate.now().toString()); // for server date model.addAttribute("userName", username); model.addAttribute("counter", userSession.getCounter()); model.addAttribute("counterName", userSession.getCounterName()); return "user/hallbookingform"; } + // ak - /* @GetMapping("/acknowledgement") + @GetMapping("/acknowledgementwithoutrefid") public String viewakowledgement(Model model, int bookingId) { BookingDetails bookingsDetails = bookingService.getBookingsById(bookingId); model.addAttribute("bookingsDetails", bookingsDetails); // Add single BookingDetails object model.addAttribute("userName", userSession.getDispayName()); return "user/acknowledgement"; - }*/ - //ak + } + + // ak @GetMapping("/acknowledgement") -public String viewAcknowledgement(@RequestParam("ref_id") String refId, Model model) { + public String viewAcknowledgement(@RequestParam("ref_id") String refId, Model model) { - // Fetch booking using booking_ref_id - BookingDetails bookingsDetails = bookingService.getBookingByRefId(refId); + // Fetch booking using booking_ref_id + BookingDetails bookingsDetails = bookingService.getBookingByRefId(refId); - if (bookingsDetails == null) { - model.addAttribute("errorMsg", "Invalid booking reference number."); - return "user/error"; - } + if (bookingsDetails == null) { + model.addAttribute("errorMsg", "Invalid booking reference number."); + return "user/error"; + } + + model.addAttribute("bookingsDetails", bookingsDetails); + model.addAttribute("userName", userSession.getDispayName()); - model.addAttribute("bookingsDetails", bookingsDetails); - model.addAttribute("userName", userSession.getDispayName()); + return "user/acknowledgement"; + } - return "user/acknowledgement"; -} -//ak - @PostMapping("/migrate-old-bookings") + // ak + @PostMapping("/migrate-old-bookings") @ResponseBody public ResponseEntity migrateOldBookings() { try { @@ -292,9 +311,6 @@ public String viewAcknowledgement(@RequestParam("ref_id") String refId, Model mo } } - - - @GetMapping("/logout") public String logout(Model model) { // Clear all login session (Check API Controller /gcc-login) @@ -305,61 +321,64 @@ public String viewAcknowledgement(@RequestParam("ref_id") String refId, Model mo return "redirect:/communityhall/user/dashboard"; } - /*@GetMapping("/viewhistory") - public String viewBookingDetails(Model model, @RequestParam(name = "bookingStatus", required = false) String bookingStatus) { - // Retrieve userId from session + /* + * @GetMapping("/viewhistory") + * public String viewBookingDetails(Model model, @RequestParam(name = + * "bookingStatus", required = false) String bookingStatus) { + * // Retrieve userId from session + * Integer userId = userSession.getUserId(); + * model.addAttribute("userName", userSession.getDispayName()); + * + * //List test = new ArrayList<>(); + * model.addAttribute("userName", userSession.getDispayName()); + * model.addAttribute("counter", userSession.getCounter()); + * model.addAttribute("counterName", userSession.getCounterName()); + * + * List> bookingPast = + * bookingService.getAllBookingEventsByUserId(userId); + * + * model.addAttribute("userBookingspast", bookingPast); + * model.addAttribute("serverDate", LocalDate.now().toString()); //for server + * date + * + * return "user/viewhistory"; + * } + */ + // ak + @GetMapping("/viewhistory") + public String viewBookingDetails(Model model, + @RequestParam(name = "bookingStatus", required = false) String bookingStatus) { + Integer userId = userSession.getUserId(); - model.addAttribute("userName", userSession.getDispayName()); - //List test = new ArrayList<>(); model.addAttribute("userName", userSession.getDispayName()); model.addAttribute("counter", userSession.getCounter()); model.addAttribute("counterName", userSession.getCounterName()); + // Fetch all past bookings List> bookingPast = bookingService.getAllBookingEventsByUserId(userId); - model.addAttribute("userBookingspast", bookingPast); - model.addAttribute("serverDate", LocalDate.now().toString()); //for server date - - return "user/viewhistory"; - }*/ - //ak - @GetMapping("/viewhistory") -public String viewBookingDetails(Model model, - @RequestParam(name = "bookingStatus", required = false) String bookingStatus) { - - Integer userId = userSession.getUserId(); + // Extract booking_ref_id per booking + Map refIdMap = new HashMap<>(); - model.addAttribute("userName", userSession.getDispayName()); - model.addAttribute("counter", userSession.getCounter()); - model.addAttribute("counterName", userSession.getCounterName()); + for (Map row : bookingPast) { - // Fetch all past bookings - List> bookingPast = bookingService.getAllBookingEventsByUserId(userId); + Integer bookingId = (Integer) row.get("booking_id"); + String refId = (String) row.get("booking_ref_id"); // <-- coming from SQL - // Extract booking_ref_id per booking - Map refIdMap = new HashMap<>(); - - for (Map row : bookingPast) { - - Integer bookingId = (Integer) row.get("booking_id"); - String refId = (String) row.get("booking_ref_id"); // <-- coming from SQL - - if (bookingId != null && refId != null) { - refIdMap.put(bookingId, refId); + if (bookingId != null && refId != null) { + refIdMap.put(bookingId, refId); + } } - } - System.out.println("Row keys: " + bookingPast.get(0).keySet()); - System.out.println("RefId Map123: " + refIdMap); - - model.addAttribute("userBookingspast", bookingPast); - model.addAttribute("bookingRefIds", refIdMap); // <-- SENT TO FRONTEND - model.addAttribute("serverDate", LocalDate.now().toString()); - - return "user/viewhistory"; -} + System.out.println("Row keys: " + bookingPast.get(0).keySet()); + System.out.println("RefId Map123: " + refIdMap); + model.addAttribute("userBookingspast", bookingPast); + model.addAttribute("bookingRefIds", refIdMap); // <-- SENT TO FRONTEND + model.addAttribute("serverDate", LocalDate.now().toString()); + return "user/viewhistory"; + } @GetMapping("/CommunityHallList") public String viewhalllist(Model model) { @@ -397,10 +416,9 @@ public String viewBookingDetails(Model model, public String viewhallform(Model model) { String username = userSession.getDispayName(); model.addAttribute("userName", username); - model.addAttribute("serverDate", LocalDate.now().toString()); //for server date + model.addAttribute("serverDate", LocalDate.now().toString()); // for server date return "user/viewhallform"; } - } diff --git a/src/main/resources/templates/user/acknowledgement.html b/src/main/resources/templates/user/acknowledgement.html index bea52c95..77f4e683 100644 --- a/src/main/resources/templates/user/acknowledgement.html +++ b/src/main/resources/templates/user/acknowledgement.html @@ -1,5 +1,6 @@ + +
@@ -22,8 +24,8 @@ function printTables(bookingId) { $.ajax({ type: "GET", - url: '/communityhall/user/acknowledgement', - data: {bookingId: bookingId}, + url: '/communityhall/user/acknowledgementwithoutrefid', + data: { bookingId: bookingId }, success: function (bodyMessage) { exportLicToPDF(bodyMessage, bookingId); // console.log(bodyMessage); @@ -103,7 +105,7 @@ console.error('Date element not found'); } } - window.onload = updateGeneratedDate; + window.onload = updateGeneratedDate; function redirect(bookingtype) { if (bookingtype === 'OFFLINE') { window.location.href = "/communityhall/counter/counterbooking"; @@ -113,4 +115,5 @@ } + \ No newline at end of file