Browse Source

modified for downloading pdf on acknowledgement page

master
AJITHKUMAR12 9 months ago
parent
commit
fe55d8550b
  1. 206
      src/main/java/com/gcc/communityHall/controller/UserController.java
  2. 7
      src/main/resources/templates/user/acknowledgement.html

206
src/main/java/com/gcc/communityHall/controller/UserController.java

@ -1,6 +1,5 @@
package com.gcc.communityHall.controller; package com.gcc.communityHall.controller;
import java.time.LocalDate; import java.time.LocalDate;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
@ -36,7 +35,7 @@ import com.gcc.communityHall.service.UserService;
import com.gcc.communityHall.service.Impl.WhatsappMsgServiceImpl; import com.gcc.communityHall.service.Impl.WhatsappMsgServiceImpl;
@Controller @Controller
@RequestMapping(value = {"/communityhall/user", "/communityhall", "", "/"})
@RequestMapping(value = { "/communityhall/user", "/communityhall", "", "/" })
public class UserController { public class UserController {
@Autowired @Autowired
@ -49,7 +48,6 @@ public class UserController {
@Autowired @Autowired
private HallDetailService hallDetailsService; private HallDetailService hallDetailsService;
@Autowired @Autowired
private UserService userService; private UserService userService;
@ -65,7 +63,7 @@ public class UserController {
@Autowired @Autowired
private NotificationRepository notificationRepository; private NotificationRepository notificationRepository;
@GetMapping(value = {"", "/", "/dashboard", "/index"})
@GetMapping(value = { "", "/", "/dashboard", "/index" })
public String viewDashboard(Model model) { public String viewDashboard(Model model) {
List<HallDetails> halls = hallDetailsRepository.findActiveHalls(); List<HallDetails> halls = hallDetailsRepository.findActiveHalls();
List<HallDetails> hallnames = hallDetailsService.getHallNames(); List<HallDetails> hallnames = hallDetailsService.getHallNames();
@ -82,28 +80,29 @@ public class UserController {
for (Notification notification : newnotification) { for (Notification notification : newnotification) {
notificationText.append(notification.getNotification_description()); 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 // Pass the concatenated string to the model
model.addAttribute("newnotification", notificationText.toString()); model.addAttribute("newnotification", notificationText.toString());
model.addAttribute("userName", userSession.getDispayName()); model.addAttribute("userName", userSession.getDispayName());
model.addAttribute("halls", halls); model.addAttribute("halls", halls);
model.addAttribute("hallnames", hallnames); 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("counter", userSession.getCounter());
model.addAttribute("counterName", userSession.getCounterName()); model.addAttribute("counterName", userSession.getCounterName());
return "user/dashboard"; return "user/dashboard";
} }
//Checkavilability Api
// Checkavilability Api
@GetMapping("/checkAvail") @GetMapping("/checkAvail")
public String checkAvail(@RequestParam("fromDate") String fromDate, 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<Notification> newnotification = notificationRepository.findActivenotifications(); List<Notification> newnotification = notificationRepository.findActivenotifications();
@ -138,7 +137,8 @@ public class UserController {
} }
// Fetch calendar data based on provided parameters // Fetch calendar data based on provided parameters
List<BookingCalendar> data = calendarService.getCalendarByDateAndHallIdAndSlot(fromDate, toDate, starting, ending, hallIdd);
List<BookingCalendar> data = calendarService.getCalendarByDateAndHallIdAndSlot(fromDate, toDate, starting,
ending, hallIdd);
HashSet<Integer> removeHallId = new HashSet<>(); HashSet<Integer> removeHallId = new HashSet<>();
// Collect hall IDs to be removed // Collect hall IDs to be removed
@ -151,16 +151,21 @@ public class UserController {
if (isSameDay) { if (isSameDay) {
// Same day booking cases // 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()); 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()); removeHallId.add(calendar.getHallId());
} else if (isMorningStart && isEveningEnd && } else if (isMorningStart && isEveningEnd &&
((calendar.getBdate().toString().equals(fromDate) && calendar.isMorningSlot()) || ((calendar.getBdate().toString().equals(fromDate) && calendar.isMorningSlot()) ||
(calendar.getBdate().toString().equals(toDate) && calendar.isEveningSlot()))) { (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()); removeHallId.add(calendar.getHallId());
} }
} else { } else {
@ -168,22 +173,26 @@ public class UserController {
if ((isMorningStart && isMorningEnd) && if ((isMorningStart && isMorningEnd) &&
((calendar.getBdate().toString().equals(fromDate) && calendar.isMorningSlot()) || ((calendar.getBdate().toString().equals(fromDate) && calendar.isMorningSlot()) ||
(calendar.getBdate().toString().equals(toDate) && 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()); removeHallId.add(calendar.getHallId());
} else if ((isEveningStart && isEveningEnd) && } else if ((isEveningStart && isEveningEnd) &&
((calendar.getBdate().toString().equals(fromDate) && calendar.isEveningSlot()) || ((calendar.getBdate().toString().equals(fromDate) && calendar.isEveningSlot()) ||
(calendar.getBdate().toString().equals(toDate) && 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()); removeHallId.add(calendar.getHallId());
} else if (isMorningStart && isEveningEnd && } else if (isMorningStart && isEveningEnd &&
((calendar.getBdate().toString().equals(fromDate) && calendar.isMorningSlot()) || ((calendar.getBdate().toString().equals(fromDate) && calendar.isMorningSlot()) ||
(calendar.getBdate().toString().equals(toDate) && calendar.isEveningSlot()))) { (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()); removeHallId.add(calendar.getHallId());
} else if (isEveningStart && isMorningEnd && } else if (isEveningStart && isMorningEnd &&
((calendar.getBdate().toString().equals(fromDate) && calendar.isEveningSlot()) || ((calendar.getBdate().toString().equals(fromDate) && calendar.isEveningSlot()) ||
(calendar.getBdate().toString().equals(toDate) && calendar.isMorningSlot()))) { (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()); removeHallId.add(calendar.getHallId());
} }
} }
@ -216,7 +225,6 @@ public class UserController {
return "user/dashboard"; return "user/dashboard";
} }
@PostMapping("/newregistrationform") @PostMapping("/newregistrationform")
public String showRegistrationForm(@ModelAttribute("newform") Users newform, Model model) { public String showRegistrationForm(@ModelAttribute("newform") Users newform, Model model) {
Users user = userService.user(newform); Users user = userService.user(newform);
@ -225,18 +233,26 @@ public class UserController {
userSession.setUserId(user.getUserId()); userSession.setUserId(user.getUserId());
userSession.setUserType(user.getUsertype().toString()); userSession.setUserType(user.getUsertype().toString());
System.out.println("usetrtype==" + 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) { if (user.getUsertype() == userType.PUBLIC) {
String registersms = "Welcome to GCC, Your User Registration for booking Community Centre is successful."; 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.sendMsg(registerwhatsupmsg);
whatsappMsgServiceImpl.sendSMS(registerurlString); whatsappMsgServiceImpl.sendSMS(registerurlString);
} else { } else {
String registerpendingsms = "Welcome to GCC, Your User Registration request for booking Community Centre is submitted successfully."; 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.sendMsg(registerpendingwhatsupmsg);
whatsappMsgServiceImpl.sendSMS(registerpendingurlString); whatsappMsgServiceImpl.sendSMS(registerpendingurlString);
} }
@ -246,40 +262,43 @@ public class UserController {
@GetMapping("/hallbookingform") @GetMapping("/hallbookingform")
public String viewform(Model model) { public String viewform(Model model) {
String username = userSession.getDispayName(); 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("userName", username);
model.addAttribute("counter", userSession.getCounter()); model.addAttribute("counter", userSession.getCounter());
model.addAttribute("counterName", userSession.getCounterName()); model.addAttribute("counterName", userSession.getCounterName());
return "user/hallbookingform"; return "user/hallbookingform";
} }
// ak
/* @GetMapping("/acknowledgement")
@GetMapping("/acknowledgementwithoutrefid")
public String viewakowledgement(Model model, int bookingId) { public String viewakowledgement(Model model, int bookingId) {
BookingDetails bookingsDetails = bookingService.getBookingsById(bookingId); BookingDetails bookingsDetails = bookingService.getBookingsById(bookingId);
model.addAttribute("bookingsDetails", bookingsDetails); // Add single BookingDetails object model.addAttribute("bookingsDetails", bookingsDetails); // Add single BookingDetails object
model.addAttribute("userName", userSession.getDispayName()); model.addAttribute("userName", userSession.getDispayName());
return "user/acknowledgement"; return "user/acknowledgement";
}*/
//ak
}
// ak
@GetMapping("/acknowledgement") @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";
}
//ak
@PostMapping("/migrate-old-bookings")
return "user/acknowledgement";
}
// ak
@PostMapping("/migrate-old-bookings")
@ResponseBody @ResponseBody
public ResponseEntity<String> migrateOldBookings() { public ResponseEntity<String> migrateOldBookings() {
try { try {
@ -292,9 +311,6 @@ public String viewAcknowledgement(@RequestParam("ref_id") String refId, Model mo
} }
} }
@GetMapping("/logout") @GetMapping("/logout")
public String logout(Model model) { public String logout(Model model) {
// Clear all login session (Check API Controller /gcc-login) // 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"; 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<String> test = new ArrayList<>();
* model.addAttribute("userName", userSession.getDispayName());
* model.addAttribute("counter", userSession.getCounter());
* model.addAttribute("counterName", userSession.getCounterName());
*
* List<Map<String, Object>> 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(); Integer userId = userSession.getUserId();
model.addAttribute("userName", userSession.getDispayName());
//List<String> test = new ArrayList<>();
model.addAttribute("userName", userSession.getDispayName()); model.addAttribute("userName", userSession.getDispayName());
model.addAttribute("counter", userSession.getCounter()); model.addAttribute("counter", userSession.getCounter());
model.addAttribute("counterName", userSession.getCounterName()); model.addAttribute("counterName", userSession.getCounterName());
// Fetch all past bookings
List<Map<String, Object>> bookingPast = bookingService.getAllBookingEventsByUserId(userId); List<Map<String, Object>> 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<Integer, String> refIdMap = new HashMap<>();
model.addAttribute("userName", userSession.getDispayName());
model.addAttribute("counter", userSession.getCounter());
model.addAttribute("counterName", userSession.getCounterName());
for (Map<String, Object> row : bookingPast) {
// Fetch all past bookings
List<Map<String, Object>> 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<Integer, String> refIdMap = new HashMap<>();
for (Map<String, Object> 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") @GetMapping("/CommunityHallList")
public String viewhalllist(Model model) { public String viewhalllist(Model model) {
@ -397,10 +416,9 @@ public String viewBookingDetails(Model model,
public String viewhallform(Model model) { public String viewhallform(Model model) {
String username = userSession.getDispayName(); String username = userSession.getDispayName();
model.addAttribute("userName", username); 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"; return "user/viewhallform";
} }
} }

7
src/main/resources/templates/user/acknowledgement.html

@ -1,5 +1,6 @@
<!DOCTYPE html> <!DOCTYPE html>
<html lang="en" xmlns:th="http://www.w3.org/1999/xhtml"> <html lang="en" xmlns:th="http://www.w3.org/1999/xhtml">
<head th:replace="~{fragments/head :: head}"> <head th:replace="~{fragments/head :: head}">
<style> <style>
@media print { @media print {
@ -15,6 +16,7 @@
} }
</style> </style>
</head> </head>
<body> <body>
<div th:replace="~{fragments/Details :: div}"></div> <div th:replace="~{fragments/Details :: div}"></div>
<script th:replace="~{fragments/script :: script}"></script> <script th:replace="~{fragments/script :: script}"></script>
@ -22,8 +24,8 @@
function printTables(bookingId) { function printTables(bookingId) {
$.ajax({ $.ajax({
type: "GET", type: "GET",
url: '/communityhall/user/acknowledgement',
data: {bookingId: bookingId},
url: '/communityhall/user/acknowledgementwithoutrefid',
data: { bookingId: bookingId },
success: function (bodyMessage) { success: function (bodyMessage) {
exportLicToPDF(bodyMessage, bookingId); exportLicToPDF(bodyMessage, bookingId);
// console.log(bodyMessage); // console.log(bodyMessage);
@ -113,4 +115,5 @@
} }
</script> </script>
</body> </body>
</html> </html>
Loading…
Cancel
Save