Both Volunteers and C and D Waste included in this project
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

162 lines
5.4 KiB

2 years ago
​
2 years ago
​
​
​
​
​
​
​
2 years ago
​
​
2 years ago
2 years ago
​
​
2 years ago
2 years ago
​
​
​
​
​
​
2 years ago
​
​
​
2 years ago
​
​
​
​
​
2 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
2 years ago
2 years ago
​
​
​
2 years ago
​
​
​
​
​
​
​
​
2 years ago
​
​
​
​
​
​
​
​
​
​
​
​
2 years ago
2 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
2 years ago
​
2 years ago
2 years ago
  1. package com.volunteersregistration.controller;
  2. import java.time.LocalDate;
  3. import java.time.LocalDateTime;
  4. import java.time.format.DateTimeFormatter;
  5. import java.util.List;
  6. import java.util.Map;
  7. import org.springframework.beans.factory.annotation.Autowired;
  8. import org.springframework.format.annotation.DateTimeFormat;
  9. import org.springframework.stereotype.Controller;
  10. import org.springframework.ui.Model;
  11. import org.springframework.web.bind.annotation.GetMapping;
  12. import org.springframework.web.bind.annotation.PostMapping;
  13. import org.springframework.web.bind.annotation.RequestMapping;
  14. import org.springframework.web.bind.annotation.RequestParam;
  15. import com.volunteersregistration.config.UserSession;
  16. import com.volunteersregistration.repository.VolunteerRegistrationRepo;
  17. import com.volunteersregistration.service.VolunteerRegistrationService;
  18. import jakarta.servlet.http.HttpServletRequest;
  19. import jakarta.servlet.http.HttpSession;
  20. @Controller
  21. @RequestMapping("/volunteer")
  22. public class VolunteerController {
  23. @Autowired
  24. private HttpSession session;
  25. @Autowired
  26. private UserSession usersession;
  27. @Autowired
  28. public VolunteerRegistrationService volunteerRegistrationService;
  29. @GetMapping("/web")
  30. public String registerweb(@RequestParam(required = false) String ref, Model model) {
  31. System.out.println("indesx page....." + ref);
  32. model.addAttribute("ref", ref);
  33. //return "webindex";
  34. return "coming_soon";
  35. }
  36. @GetMapping("/webtamil")
  37. public String registerwebtamil(@RequestParam(required = false) String ref, Model model) {
  38. System.out.println("indesx page....." + ref);
  39. model.addAttribute("ref", ref);
  40. //return "webindex_tamil";
  41. return "coming_soon";
  42. }
  43. @GetMapping(value = { "/", "", "/index" })
  44. public String MobileViewregister(@RequestParam(required = false) String ref, Model model) {
  45. System.out.println("indesx page....." + ref);
  46. model.addAttribute("ref", ref);
  47. //return "index";
  48. return "coming_soon";
  49. }
  50. @GetMapping(value = {"/index_tamil" })
  51. public String MobileViewtamilregister(@RequestParam(required = false) String ref, Model model) {
  52. System.out.println("indesx page....." + ref);
  53. model.addAttribute("ref", ref);
  54. //return "index_tamil";
  55. return "coming_soon";
  56. }
  57. // Check session and redirect to login if user is not logged in
  58. private boolean isLoggedIn() {
  59. return session.getAttribute("userId") != null; // Check if userId is in session store the user type if the user type not quals to kyn n s pls logout
  60. }
  61. @GetMapping(value = {"/kynreport"})
  62. public String kynreport(Model model, HttpServletRequest request) {
  63. if (!isLoggedIn()) {
  64. return "redirect:/volunteer/kynreportlogin"; // Redirect to login if not logged in
  65. }
  66. return "kynreport"; // Render page if logged in
  67. }
  68. @GetMapping(value = {"/allreports"})
  69. public String allreports(Model model, HttpServletRequest request) {
  70. if (!isLoggedIn()) {
  71. return "redirect:/volunteer/kynreportlogin"; // Redirect to login if not logged in
  72. }
  73. return "allreports"; // Render page if logged in
  74. }
  75. @PostMapping(value = {"/allreports"})
  76. public String allreports(
  77. @RequestParam("fromDate") @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate fromDate,
  78. @RequestParam("toDate") @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate toDate,
  79. @RequestParam("category") int category,
  80. Model model) {
  81. if (!isLoggedIn()) {
  82. return "redirect:/volunteer/kynreportlogin";
  83. }
  84. LocalDateTime fromDateTime = fromDate.atStartOfDay();
  85. LocalDateTime toDateTime = toDate.atTime(23, 59, 59);
  86. String fromDateString = fromDateTime.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
  87. String toDateString = toDateTime.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
  88. List<Map<String, Object>> alldata = volunteerRegistrationService.getAllReport(fromDateString, toDateString, category);
  89. model.addAttribute("alldata", alldata);
  90. model.addAttribute("category", category);
  91. model.addAttribute("fromdate", fromDate);
  92. model.addAttribute("todate", toDate);
  93. return "allreports";
  94. }
  95. @PostMapping(value = {"/kynreport"})
  96. public String kynreport(
  97. @RequestParam("fromDate") @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate fromDate,
  98. @RequestParam("toDate") @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate toDate,
  99. @RequestParam("category") int category,
  100. Model model) {
  101. if (!isLoggedIn()) {
  102. return "redirect:/volunteer/kynreportlogin";
  103. }
  104. LocalDateTime fromDateTime = fromDate.atStartOfDay();
  105. LocalDateTime toDateTime = toDate.atTime(23, 59, 59);
  106. String fromDateString = fromDateTime.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
  107. String toDateString = toDateTime.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
  108. List<Map<String, Object>> reportData = volunteerRegistrationService.getKynReport(fromDateString, toDateString, category);
  109. model.addAttribute("fromdate", fromDate);
  110. model.addAttribute("todate", toDate);
  111. model.addAttribute("reportData", reportData);
  112. model.addAttribute("category", category);
  113. return "kynreport";
  114. }
  115. @GetMapping(value = {"/kynreportlogin"})
  116. public String kynreportlogin(Model model) {
  117. return "kynreportlogin";
  118. }
  119. }