diff --git a/gcc_officer_portal/src/main/java/in/gov/chennaicorporation/gccoffice/nulm/controller/NulmAPIController.java b/gcc_officer_portal/src/main/java/in/gov/chennaicorporation/gccoffice/nulm/controller/NulmAPIController.java index 03f4960e..c2c5730a 100644 --- a/gcc_officer_portal/src/main/java/in/gov/chennaicorporation/gccoffice/nulm/controller/NulmAPIController.java +++ b/gcc_officer_portal/src/main/java/in/gov/chennaicorporation/gccoffice/nulm/controller/NulmAPIController.java @@ -30,6 +30,7 @@ import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.ResponseBody; import org.springframework.web.bind.annotation.RestController; import org.springframework.web.multipart.MultipartFile; @@ -513,17 +514,16 @@ public class NulmAPIController { @RequestParam(value = "year", required = false) String year, @RequestParam(value = "inchargeName", required = false) String inchargeName, @RequestParam(value = "enrollmentIds", required = false) List enrollmentIds) { - - System.out.println("inchargeName="+inchargeName); + + System.out.println("inchargeName=" + inchargeName); List> staffList = nulmService.getAttendanceWithInitiatedSalary(inchargeId, month, year, inchargeName, enrollmentIds); return ResponseEntity.ok(staffList); } - + ///// - - + @GetMapping("/staffInititeadList-park") public ResponseEntity>> getAttendanceWithInitiatedSalaryByGroupId_Park( @RequestParam(value = "inchargeId", required = false) Integer inchargeId, @@ -536,9 +536,8 @@ public class NulmAPIController { inchargeName, enrollmentIds); return ResponseEntity.ok(staffList); } - - - ///// + + ///// /* * @PostMapping("/salaryDetailUpdate") * public ResponseEntity addSalaryDetails(@RequestBody List addSalaryDetails_Park(@RequestBody List> requestList) { System.out.println("Received POST request with data: " + requestList); try { for (Map request : requestList) { - - System.out.println("enrollment_id = " + request.get("enrollment_id").toString()); + System.out.println("enrollment_id = " + request.get("enrollment_id").toString()); int totalDaysPresent = Integer.parseInt(request.get("total_days_present").toString()); int totalDaysOd = Integer.parseInt(request.get("total_days_od").toString()); int totalDaysSalary = Integer.parseInt(request.get("total_days_salary").toString()); @@ -691,7 +688,8 @@ public class NulmAPIController { .body("Failed to add salary details for enrollment ID: " + enrollmentId); } } else { - int rowsAffected = nulmService.updateSalaryDetails_park(totalDaysPresent, totalDaysOd, totalDaysSalary, + int rowsAffected = nulmService.updateSalaryDetails_park(totalDaysPresent, totalDaysOd, + totalDaysSalary, totalDaysAbsent, month, year, salaryAmount, salaryStatus, enrollmentId, groupId, wageId, inchargeID); if (rowsAffected <= 0) { @@ -708,12 +706,8 @@ public class NulmAPIController { .body("Invalid request data: " + e.getMessage()); } } - - - + /// - - // Helper method to check if the month is future or current private boolean isFutureOrCurrentMonth(String month, int year) { @@ -787,28 +781,32 @@ public class NulmAPIController { nulmService.updateSalaryStatusToApproved(enrollmentIds, month, year); return ResponseEntity.ok("Salary status updated to 'Approved' for the provided enrollments."); } - - + //// - + @GetMapping("/salary-approve-park-testdata") public List> getsalaryInitiatedCounts(@RequestParam(required = false) String month, - @RequestParam(required = false) Integer year, - @RequestParam(required = false) String salaryStatus, - @RequestParam (required = false) String LoginUserId){ - - List> salaryInitiatedCounts; - - // Fetch data if both month and year are provided, otherwise return an empty list - if (month != null && year != null) { - salaryInitiatedCounts = nulmService.getFilteredSalaryDetails_park(month, year, salaryStatus,LoginUserId); // Pass department to the service method - } else { - salaryInitiatedCounts = Collections.emptyList(); // Empty list if no month and year are provided - } - return salaryInitiatedCounts; + @RequestParam(required = false) Integer year, + @RequestParam(required = false) String salaryStatus, + @RequestParam(required = false) String LoginUserId) { + + List> salaryInitiatedCounts; + + // Fetch data if both month and year are provided, otherwise return an empty + // list + if (month != null && year != null) { + salaryInitiatedCounts = nulmService.getFilteredSalaryDetails_park(month, year, salaryStatus, LoginUserId); // Pass + // department + // to + // the + // service + // method + } else { + salaryInitiatedCounts = Collections.emptyList(); // Empty list if no month and year are provided + } + return salaryInitiatedCounts; } - - + @PostMapping("/update-salary-status-park") public ResponseEntity updateSalaryStatus_Park( @RequestParam List enrollmentIds, @@ -820,7 +818,7 @@ public class NulmAPIController { nulmService.updateSalaryStatusToApproved_Park(enrollmentIds, month, year); return ResponseEntity.ok("Salary status updated to 'Approved' for the provided enrollments."); } - + //// /*************** API For Mobile Application *********************************/ @@ -864,12 +862,13 @@ public class NulmAPIController { try { - //List> attendanceWithSalary = new ArrayList<>(); - //Integer check = nulmService.checkInchargeID(inchargeId); - // if (check == 1) { - // Call the service method to fetch the data - List> attendanceWithSalary = nulmService.getAttendanceWithSalaryByInchargeId(month, year, inchargeId); - //} + // List> attendanceWithSalary = new ArrayList<>(); + // Integer check = nulmService.checkInchargeID(inchargeId); + // if (check == 1) { + // Call the service method to fetch the data + List> attendanceWithSalary = nulmService.getAttendanceWithSalaryByInchargeId(month, + year, inchargeId); + // } // If no data is found, return a NOT FOUND response total_days_salary, // total_salary and total_days_absent if (attendanceWithSalary.isEmpty()) { @@ -900,10 +899,9 @@ public class NulmAPIController { List.of(Map.of("error", "An error occurred while fetching attendance data: " + ex.getMessage()))); } } - - + //// - + @GetMapping("/attendanceWithSalary_New") public ResponseEntity>> getAttendanceWithSalaryByInchargeId_New( @RequestParam(value = "month", required = false) String month, @@ -915,10 +913,11 @@ public class NulmAPIController { List> attendanceWithSalary = new ArrayList<>(); String ids = nulmService.checkInchargeID(inchargeId); - System.out.println("IDS = "+ids); - if (ids != null || !ids.trim().isEmpty()) { - // Call the service method to fetch the data - attendanceWithSalary = nulmService.getAttendanceWithSalaryByInchargeId_New(month, year, inchargeId, type, ids); + System.out.println("IDS = " + ids); + if (ids != null || !ids.trim().isEmpty()) { + // Call the service method to fetch the data + attendanceWithSalary = nulmService.getAttendanceWithSalaryByInchargeId_New(month, year, inchargeId, + type, ids); } // If no data is found, return a NOT FOUND response total_days_salary, // total_salary and total_days_absent @@ -950,8 +949,7 @@ public class NulmAPIController { List.of(Map.of("error", "An error occurred while fetching attendance data: " + ex.getMessage()))); } } - - + //// @PostMapping("/salaryDetailInitiate") @@ -1000,62 +998,60 @@ public class NulmAPIController { return ResponseEntity.status(HttpStatus.BAD_REQUEST).body("Invalid request data: " + e.getMessage()); } } - + //// - - -// @PostMapping("/salaryDetailInitiate_park") -// public ResponseEntity addInitiatedSalaryDetails_park( -// @RequestParam("total_days_present") List totalDaysPresentList, -// @RequestParam("total_days_od") List totalDaysOdList, -// @RequestParam("total_days_salary") List totalDaysSalaryList, -// @RequestParam("total_days_absent") List totalDaysAbsentList, -// @RequestParam("month") List monthList, -// @RequestParam("year") List yearList, -// @RequestParam("salary_amount") List salaryAmountList, -// @RequestParam("enrollment_id") List enrollmentIdList, -// @RequestParam("group_id") List groupIdList, -// @RequestParam("wage_id") List wageIdList) { -// // System.out.println("Received POST request with form-data"); -// -// try { -// // Iterate through each list to process the form data -// for (int i = 0; i < totalDaysPresentList.size(); i++) { -// int totalDaysPresent = totalDaysPresentList.get(i); -// int totalDaysOd = totalDaysOdList.get(i); -// int total_days_salary = totalDaysSalaryList.get(i); -// int totalDaysAbsent = totalDaysAbsentList.get(i); -// String month = monthList.get(i); -// int year = yearList.get(i); -// int salaryAmount = salaryAmountList.get(i); -// int enrollmentId = enrollmentIdList.get(i); -// int groupId = groupIdList.get(i); -// int wageId = wageIdList.get(i); -// -// String salaryStatus = "Initiated"; -// -// // Call the service method to insert the salary details -// int rowsAffected = nulmService.addSalaryDetails_park(totalDaysPresent, totalDaysOd, total_days_salary, -// totalDaysAbsent, month, year, salaryAmount, salaryStatus, enrollmentId, groupId, wageId); -// -// if (rowsAffected <= 0) { -// return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR) -// .body("Failed to add salary details for enrollment ID: " + enrollmentId); -// } -// } -// return ResponseEntity.status(HttpStatus.CREATED) -// .body("Salary details added successfully for all selected entries in park."); -// } catch (Exception e) { -// e.printStackTrace(); // Log the exception for debugging -// return ResponseEntity.status(HttpStatus.BAD_REQUEST).body("Invalid request data: " + e.getMessage()); -// } -// } - - + + // @PostMapping("/salaryDetailInitiate_park") + // public ResponseEntity addInitiatedSalaryDetails_park( + // @RequestParam("total_days_present") List totalDaysPresentList, + // @RequestParam("total_days_od") List totalDaysOdList, + // @RequestParam("total_days_salary") List totalDaysSalaryList, + // @RequestParam("total_days_absent") List totalDaysAbsentList, + // @RequestParam("month") List monthList, + // @RequestParam("year") List yearList, + // @RequestParam("salary_amount") List salaryAmountList, + // @RequestParam("enrollment_id") List enrollmentIdList, + // @RequestParam("group_id") List groupIdList, + // @RequestParam("wage_id") List wageIdList) { + // // System.out.println("Received POST request with form-data"); + // + // try { + // // Iterate through each list to process the form data + // for (int i = 0; i < totalDaysPresentList.size(); i++) { + // int totalDaysPresent = totalDaysPresentList.get(i); + // int totalDaysOd = totalDaysOdList.get(i); + // int total_days_salary = totalDaysSalaryList.get(i); + // int totalDaysAbsent = totalDaysAbsentList.get(i); + // String month = monthList.get(i); + // int year = yearList.get(i); + // int salaryAmount = salaryAmountList.get(i); + // int enrollmentId = enrollmentIdList.get(i); + // int groupId = groupIdList.get(i); + // int wageId = wageIdList.get(i); + // + // String salaryStatus = "Initiated"; + // + // // Call the service method to insert the salary details + // int rowsAffected = nulmService.addSalaryDetails_park(totalDaysPresent, + // totalDaysOd, total_days_salary, + // totalDaysAbsent, month, year, salaryAmount, salaryStatus, enrollmentId, + // groupId, wageId); + // + // if (rowsAffected <= 0) { + // return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR) + // .body("Failed to add salary details for enrollment ID: " + enrollmentId); + // } + // } + // return ResponseEntity.status(HttpStatus.CREATED) + // .body("Salary details added successfully for all selected entries in park."); + // } catch (Exception e) { + // e.printStackTrace(); // Log the exception for debugging + // return ResponseEntity.status(HttpStatus.BAD_REQUEST).body("Invalid request + // data: " + e.getMessage()); + // } + // } + //// - - - // @GetMapping("/filtered-details") // public List> getFilteredSalaryDetails( @@ -1066,4 +1062,74 @@ public class NulmAPIController { // // Call the service method to get the filtered salary details // return nulmService.getFilteredSalaryDetails(month, year, salaryStatus); // } + + // ak + // 1. Get Zones + @GetMapping("/zones") + public List getZones() { + return nulmService.getZones(); + } + + // 2. Get Divisions by Zone + @GetMapping("/divisions") + public List getDivisions(@RequestParam int zone) { + return nulmService.getDivisions(zone); + } + + // 3. Get Parks by Zone and Division + @GetMapping("/list") + public List> getParks( + @RequestParam int zone, + // @RequestParam int division) { + @RequestParam(required = false) Integer division) { + + return nulmService.getParks(zone, division); + } + + @GetMapping("/staff") + public List> getStaffByPark(@RequestParam int parkId) { + return nulmService.getStaffByPark(parkId); + } + + @GetMapping("/staff-details") + public Map getStaffDetails(@RequestParam int enrollmentId) { + + return nulmService.getStaffDetails(enrollmentId); + + } + + @PostMapping("/update-staff") + public ResponseEntity updateStaff( + @RequestParam int enrollmentId, + @RequestParam(required = false) String fhName, + @RequestParam(required = false) String designation, + @RequestParam(required = false) Integer designationId, + @RequestParam(required = false) String aadharNo, + @RequestParam(required = false) String bankAccNo, + @RequestParam(required = false) String phoneNumber, + @RequestParam(required = false) String address, + // ak + @RequestParam(required = false) String bankName, + @RequestParam(required = false) String ifscCode, + @RequestParam(required = false) String branch, + @RequestParam(required = false) String branchAddress, + + @RequestParam(required = false) Integer notFound, + @RequestParam(required = false) Integer error, + @RequestParam(required = false) String remarks, + @RequestParam(required = false) MultipartFile uploadform, + @RequestParam(required = false) MultipartFile aadharcard, + @RequestParam(required = false) MultipartFile bankpassbook, @RequestParam String createdBy) { + + return ResponseEntity.ok(nulmService.updateStaff( + enrollmentId, fhName, designation, designationId, + aadharNo, bankAccNo, bankName, ifscCode, branch, branchAddress, phoneNumber, address, + uploadform, aadharcard, bankpassbook, notFound, error, remarks, createdBy)); + } + + @GetMapping("/designations") + @ResponseBody + public List> getDesignations() { + return nulmService.getDesignations(); + } } diff --git a/gcc_officer_portal/src/main/java/in/gov/chennaicorporation/gccoffice/nulm/controller/NulmController.java b/gcc_officer_portal/src/main/java/in/gov/chennaicorporation/gccoffice/nulm/controller/NulmController.java index fe852d98..14a69de9 100644 --- a/gcc_officer_portal/src/main/java/in/gov/chennaicorporation/gccoffice/nulm/controller/NulmController.java +++ b/gcc_officer_portal/src/main/java/in/gov/chennaicorporation/gccoffice/nulm/controller/NulmController.java @@ -21,10 +21,10 @@ import in.gov.chennaicorporation.gccoffice.service.LoginUserInfo; @Controller @RequestMapping("/gcc/nulm") public class NulmController { - + @Autowired private NulmService nulmService; - + @GetMapping("/appointment") public String viewappoinmentMaster(Model model) { System.out.println("appointment"); @@ -42,118 +42,135 @@ public class NulmController { System.out.println("create-order"); return "modules/nulm/create-order"; } - + @GetMapping("/scheme-group") public String viewschemegroup(Model model) { System.out.println("scheme-group"); return "modules/nulm/scheme-group"; } - + @GetMapping("/dropout") public String viewappointmentscreengroup(Model model) { System.out.println("dropout"); return "modules/nulm/dropout"; } - + @GetMapping("/updateStaff") - public String viewUpdateScreen( - @RequestParam(value = "department", required = false) String department, - @RequestParam(value = "division", required = false) String division, - Model model) { - - // Fetch the full list or filtered list based on parameters - List> enrollments = nulmService.getEnrollments(department, null); - - // Add the list to the model to be accessed in the view - model.addAttribute("enrollments", enrollments); - model.addAttribute("selectedDepartment", department); // Pass the selected department - - // Return the view name - return "modules/nulm/updated-staff"; - } - + public String viewUpdateScreen( + @RequestParam(value = "department", required = false) String department, + @RequestParam(value = "division", required = false) String division, + Model model) { + + // Fetch the full list or filtered list based on parameters + List> enrollments = nulmService.getEnrollments(department, null); + + // Add the list to the model to be accessed in the view + model.addAttribute("enrollments", enrollments); + model.addAttribute("selectedDepartment", department); // Pass the selected department + + // Return the view name + return "modules/nulm/updated-staff"; + } + @GetMapping("/salaryDetails") public String getSalaryDetails( - @RequestParam(value = "month", required = false) String month, - @RequestParam(value = "year", required = false) Integer year, // Use Integer instead of int - Model model) { - - List> salaryDetails = new ArrayList<>(); - - // Check if month and year are provided - if (month != null && year != null) { - salaryDetails = nulmService.getAttendanceWithSalary(month, year); - } else { - // Handle case when no month or year is provided - model.addAttribute("message", "Please select a month and year."); - } - - model.addAttribute("salaryCounts", salaryDetails); - System.out.println("salarydetails for month: " + month + ", year: " + year); - return "modules/nulm/salary-details"; + @RequestParam(value = "month", required = false) String month, + @RequestParam(value = "year", required = false) Integer year, // Use Integer instead of int + Model model) { + + List> salaryDetails = new ArrayList<>(); + + // Check if month and year are provided + if (month != null && year != null) { + salaryDetails = nulmService.getAttendanceWithSalary(month, year); + } else { + // Handle case when no month or year is provided + model.addAttribute("message", "Please select a month and year."); + } + + model.addAttribute("salaryCounts", salaryDetails); + System.out.println("salarydetails for month: " + month + ", year: " + year); + return "modules/nulm/salary-details"; } + /* + * @GetMapping("/salary-approve") + * public String viewSalaryApproveScreen(@RequestParam(required = false) String + * month, + * + * @RequestParam(required = false) Integer year, + * + * @RequestParam(required = false) String salaryStatus, + * Model model) { + * List> salaryInitiatedCounts; + * + * // If both month and year are provided, fetch the data; otherwise, return an + * empty list + * if (month != null && year != null) { + * salaryInitiatedCounts = nulmService.getFilteredSalaryDetails(month, year, + * salaryStatus); + * } else { + * salaryInitiatedCounts = Collections.emptyList(); // Empty list if no month + * and year are provided + * } + * + * model.addAttribute("salaryInitiatedCounts", salaryInitiatedCounts); + * return "modules/nulm/salary-approve"; + * } + */ @GetMapping("/salary-approve") public String viewSalaryApproveScreen(@RequestParam(required = false) String month, - @RequestParam(required = false) Integer year, - @RequestParam(required = false) String salaryStatus, - Model model) { - List> salaryInitiatedCounts; - - // If both month and year are provided, fetch the data; otherwise, return an empty list - if (month != null && year != null) { - salaryInitiatedCounts = nulmService.getFilteredSalaryDetails(month, year, salaryStatus); - } else { - salaryInitiatedCounts = Collections.emptyList(); // Empty list if no month and year are provided - } - - model.addAttribute("salaryInitiatedCounts", salaryInitiatedCounts); - return "modules/nulm/salary-approve"; - } - */ - @GetMapping("/salary-approve") - public String viewSalaryApproveScreen(@RequestParam(required = false) String month, - @RequestParam(required = false) Integer year, - @RequestParam(required = false) String salaryStatus, // Added department parameter - Model model) { - - String LoginUserId = LoginUserInfo.getLoginUserId(); - model.addAttribute("LoginUserId",LoginUserId); - - System.out.println("LoginUserId=="+LoginUserId); - + @RequestParam(required = false) Integer year, + @RequestParam(required = false) String salaryStatus, // Added department parameter + Model model) { + + String LoginUserId = LoginUserInfo.getLoginUserId(); + model.addAttribute("LoginUserId", LoginUserId); + + System.out.println("LoginUserId==" + LoginUserId); + List> salaryInitiatedCounts; - // Fetch data if both month and year are provided, otherwise return an empty list - if (month != null && year != null) { - salaryInitiatedCounts = nulmService.getFilteredSalaryDetails(month, year, salaryStatus,LoginUserId); // Pass department to the service method - } else { - salaryInitiatedCounts = Collections.emptyList(); // Empty list if no month and year are provided - } + // Fetch data if both month and year are provided, otherwise return an empty + // list + if (month != null && year != null) { + salaryInitiatedCounts = nulmService.getFilteredSalaryDetails(month, year, salaryStatus, LoginUserId); // Pass + // department + // to + // the + // service + // method + } else { + salaryInitiatedCounts = Collections.emptyList(); // Empty list if no month and year are provided + } + + model.addAttribute("salaryInitiatedCounts", salaryInitiatedCounts); - model.addAttribute("salaryInitiatedCounts", salaryInitiatedCounts); - - return "modules/nulm/salary-approve"; + return "modules/nulm/salary-approve"; } - - + //// - - + @GetMapping("/salary-approve-park") public String viewSalaryApproveScreen_park(@RequestParam(required = false) String month, - @RequestParam(required = false) Integer year, - @RequestParam(required = false) String salaryStatus, // Added department parameter - Model model) { + @RequestParam(required = false) Integer year, + @RequestParam(required = false) String salaryStatus, // Added department parameter + Model model) { - String LoginUserId = LoginUserInfo.getLoginUserId(); - model.addAttribute("LoginUserId",LoginUserId); + String LoginUserId = LoginUserInfo.getLoginUserId(); + model.addAttribute("LoginUserId", LoginUserId); List> salaryInitiatedCounts; - // Fetch data if both month and year are provided, otherwise return an empty list + // Fetch data if both month and year are provided, otherwise return an empty + // list if (month != null && year != null) { - salaryInitiatedCounts = nulmService.getFilteredSalaryDetails_park(month, year, salaryStatus,LoginUserId); // Pass department to the service method + salaryInitiatedCounts = nulmService.getFilteredSalaryDetails_park(month, year, salaryStatus, LoginUserId); // Pass + // department + // to + // the + // service + // method } else { salaryInitiatedCounts = Collections.emptyList(); // Empty list if no month and year are provided } @@ -162,185 +179,202 @@ public class NulmController { return "modules/nulm/salary-approve-park"; } - - + //// - - - + @GetMapping("/salary-report") public String viewSalaryReport( - @RequestParam(required = false) String month, - @RequestParam(required = false) Integer year, - @RequestParam(required = false) String salaryStatus, - @RequestParam(required = false) String groupName, - Model model) { - - String LoginUserId = LoginUserInfo.getLoginUserId(); - model.addAttribute("LoginUserId",LoginUserId); - - // Initialize an empty salaryReport list - List> salaryReport = new ArrayList<>(); - - // Only fetch the report if month and year are provided - if (month != null && year != null) { - salaryReport = nulmService.getSalaryReport(month, year, salaryStatus, groupName, LoginUserId); - } - - // Add the fetched data to the model - model.addAttribute("salaryReport", salaryReport); - - return "modules/nulm/salary-report"; // Returns the view 'salary-report' + @RequestParam(required = false) String month, + @RequestParam(required = false) Integer year, + @RequestParam(required = false) String salaryStatus, + @RequestParam(required = false) String groupName, + Model model) { + + String LoginUserId = LoginUserInfo.getLoginUserId(); + model.addAttribute("LoginUserId", LoginUserId); + + // Initialize an empty salaryReport list + List> salaryReport = new ArrayList<>(); + + // Only fetch the report if month and year are provided + if (month != null && year != null) { + salaryReport = nulmService.getSalaryReport(month, year, salaryStatus, groupName, LoginUserId); + } + + // Add the fetched data to the model + model.addAttribute("salaryReport", salaryReport); + + return "modules/nulm/salary-report"; // Returns the view 'salary-report' } - + //// - - @GetMapping("/salary-report-park") + + @GetMapping("/salary-report-park") public String viewSalaryReport_Park( - @RequestParam(required = false) String month, - @RequestParam(required = false) Integer year, - @RequestParam(required = false) String salaryStatus, - @RequestParam(required = false) String groupName, - Model model) { - - String LoginUserId = LoginUserInfo.getLoginUserId(); - model.addAttribute("LoginUserId",LoginUserId); - - // Initialize an empty salaryReport list - List> salaryReport = new ArrayList<>(); - - // Only fetch the report if month and year are provided - if (month != null && year != null) { - salaryReport = nulmService.getSalaryReport_park(month, year, salaryStatus, groupName, LoginUserId); - } - - // Add the fetched data to the model - model.addAttribute("salaryReport", salaryReport); - - return "modules/nulm/salary-report-park"; // Returns the view 'salary-report' + @RequestParam(required = false) String month, + @RequestParam(required = false) Integer year, + @RequestParam(required = false) String salaryStatus, + @RequestParam(required = false) String groupName, + Model model) { + + String LoginUserId = LoginUserInfo.getLoginUserId(); + model.addAttribute("LoginUserId", LoginUserId); + + // Initialize an empty salaryReport list + List> salaryReport = new ArrayList<>(); + + // Only fetch the report if month and year are provided + if (month != null && year != null) { + salaryReport = nulmService.getSalaryReport_park(month, year, salaryStatus, groupName, LoginUserId); + } + + // Add the fetched data to the model + model.addAttribute("salaryReport", salaryReport); + + return "modules/nulm/salary-report-park"; // Returns the view 'salary-report' } - + //// @GetMapping("/salary-zonereport") public String viewZoneWiseReport( - @RequestParam(required = false) String month, - @RequestParam(required = false) Integer year, - @RequestParam(required = false) String salaryStatus, - @RequestParam(required = false) String groupName, - @RequestParam(required = false) String zone, - @RequestParam(required = false) String division, - Model model) { - //System.out.println("Zone: "+zone); - - // Initialize an empty salaryReport list - List> zoneWiseReport = new ArrayList<>(); - - // Only fetch the report if month, year and zone are provided - if (month != null && year != null && zone!= null) { - zoneWiseReport = nulmService.getZoneWiseReport(month, year, salaryStatus ,groupName, zone, division); - } - - // Add the fetched data to the model - model.addAttribute("zonewiseReport", zoneWiseReport); - - return "modules/nulm/zone-wise-report"; // Returns the view 'salary-zonereport' + @RequestParam(required = false) String month, + @RequestParam(required = false) Integer year, + @RequestParam(required = false) String salaryStatus, + @RequestParam(required = false) String groupName, + @RequestParam(required = false) String zone, + @RequestParam(required = false) String division, + Model model) { + // System.out.println("Zone: "+zone); + + // Initialize an empty salaryReport list + List> zoneWiseReport = new ArrayList<>(); + + // Only fetch the report if month, year and zone are provided + if (month != null && year != null && zone != null) { + zoneWiseReport = nulmService.getZoneWiseReport(month, year, salaryStatus, groupName, zone, division); + } + + // Add the fetched data to the model + model.addAttribute("zonewiseReport", zoneWiseReport); + + return "modules/nulm/zone-wise-report"; // Returns the view 'salary-zonereport' } - + @GetMapping("/attendance-report") - public String viewAttendanceReport( - @RequestParam(required = false) String fromdate, - @RequestParam(required = false) String todate, - @RequestParam(required = false) String groupName, - @RequestParam(required = false) String zone, - @RequestParam(required = false) String division, - Model model) { - - // Initialize an empty salaryReport list - List> attendanceReport = new ArrayList<>(); - - // Only fetch the report if month, year and zone are provided - if (division != null && zone!= null) { - attendanceReport = nulmService.getAttendanceReport(fromdate ,todate ,groupName, zone, division); - } - - // Add the fetched data to the model - model.addAttribute("attendanceReport", attendanceReport); - - return "modules/nulm/attendance-report"; + public String viewAttendanceReport( + @RequestParam(required = false) String fromdate, + @RequestParam(required = false) String todate, + @RequestParam(required = false) String groupName, + @RequestParam(required = false) String zone, + @RequestParam(required = false) String division, + Model model) { + + // Initialize an empty salaryReport list + List> attendanceReport = new ArrayList<>(); + + // Only fetch the report if month, year and zone are provided + if (division != null && zone != null) { + attendanceReport = nulmService.getAttendanceReport(fromdate, todate, groupName, zone, division); + } + + // Add the fetched data to the model + model.addAttribute("attendanceReport", attendanceReport); + + return "modules/nulm/attendance-report"; } - + @GetMapping("/consolidated-attendance-report") // need to add - public String viewConsolidatedAttendanceReport( - @RequestParam(required = false) String fromdate, - @RequestParam(required = false) String todate, - @RequestParam(required = false) String groupName, - @RequestParam(required = false) String zone, - @RequestParam(required = false) String division, - Model model) { + public String viewConsolidatedAttendanceReport( + @RequestParam(required = false) String fromdate, + @RequestParam(required = false) String todate, + @RequestParam(required = false) String groupName, + @RequestParam(required = false) String zone, + @RequestParam(required = false) String division, + Model model) { + + // Initialize an empty salaryReport list + List> consolidatedAttendanceReport = new ArrayList<>(); + + // Only fetch the report if month, year and zone are provided + if (division != null && zone != null) { + consolidatedAttendanceReport = nulmService.getConsolidatedAttendanceReport(fromdate, todate, groupName, + zone, division); + } + + // Add the fetched data to the model + model.addAttribute("consolidatedAttendanceReport", consolidatedAttendanceReport); + model.addAttribute("fromdate", fromdate); + model.addAttribute("todate", todate); + + return "modules/nulm/attendance-report"; + } + + @GetMapping("/attendance-dates") // need to add + public ResponseEntity>> getAttendanceDates( + @RequestParam(required = false) String enrollmentId, + @RequestParam(required = false) String fromdate, + @RequestParam(required = false) String todate, + @RequestParam(required = false) String type, + Model model) { + + return ResponseEntity.ok(nulmService.fetchAttendanceDates(enrollmentId, fromdate, todate, type)); - // Initialize an empty salaryReport list - List> consolidatedAttendanceReport = new ArrayList<>(); + } - // Only fetch the report if month, year and zone are provided - if (division != null && zone != null) { - consolidatedAttendanceReport = nulmService.getConsolidatedAttendanceReport(fromdate, todate, groupName, zone, division); - } + @GetMapping("/self-help-group") // need to add + public String viewSelfHelpGroup(Model model) { - // Add the fetched data to the model - model.addAttribute("consolidatedAttendanceReport", consolidatedAttendanceReport); - model.addAttribute("fromdate", fromdate); - model.addAttribute("todate", todate); + // Fetch the full list or filtered list based on parameters + List> selfHelpGroup = nulmService.getSelfHelpGroupDetails(); - return "modules/nulm/attendance-report"; - } + // Add the list to the model to be accessed in the view + model.addAttribute("selfHelpGroup", selfHelpGroup); - @GetMapping("/attendance-dates") //need to add - public ResponseEntity>> getAttendanceDates( - @RequestParam(required = false) String enrollmentId, - @RequestParam(required = false) String fromdate, - @RequestParam(required = false) String todate, - @RequestParam(required = false) String type, - Model model) { + // Return the view name + return "modules/nulm/selfHelpGroup"; + } - return ResponseEntity.ok(nulmService.fetchAttendanceDates(enrollmentId, fromdate, todate, type)); + @GetMapping("/salary-nonInitiated") + public String viewSalaryNotInitiatedReport( + @RequestParam(required = false) String month, + @RequestParam(required = false) Integer year, + @RequestParam(required = false) String groupName, + Model model) { + System.out.println(" salary-nonInitiated groupname====" + groupName); + if (groupName != null && !groupName.isEmpty()) { + groupName = URLDecoder.decode(groupName, StandardCharsets.UTF_8); + } - } + List> salaryNotInitiatedReport = new ArrayList<>(); + if (month != null && year != null) { + salaryNotInitiatedReport = nulmService.getSalaryNotInitiatedReport(month, year, groupName); + } -@GetMapping("/self-help-group") // need to add - public String viewSelfHelpGroup(Model model) { + model.addAttribute("salaryNonInitiatedReport", salaryNotInitiatedReport); - // Fetch the full list or filtered list based on parameters - List> selfHelpGroup = nulmService.getSelfHelpGroupDetails(); + return "modules/nulm/salary-nonInitiatedreport"; + } - // Add the list to the model to be accessed in the view - model.addAttribute("selfHelpGroup", selfHelpGroup); + @GetMapping("/staffupdate") + public String viewSalaryReport(Model model) { - // Return the view name - return "modules/nulm/selfHelpGroup"; - } + String LoginUserId = LoginUserInfo.getLoginUserId(); + System.out.println("===" + LoginUserId); + model.addAttribute("LoginUserId", LoginUserId); + boolean hasAccess = nulmService.hasStaffUpdateAccess(LoginUserId); -@GetMapping("/salary-nonInitiated") - public String viewSalaryNotInitiatedReport( - @RequestParam(required = false) String month, - @RequestParam(required = false) Integer year, - @RequestParam(required = false) String groupName, - Model model) { - System.out.println(" salary-nonInitiated groupname====" + groupName); - if (groupName != null && !groupName.isEmpty()) { - groupName = URLDecoder.decode(groupName, StandardCharsets.UTF_8); - } + if (hasAccess) { - List> salaryNotInitiatedReport = new ArrayList<>(); + model.addAttribute("LoginUserId", LoginUserId); + return "modules/nulm/staffupdate"; - if (month != null && year != null) { - salaryNotInitiatedReport = nulmService.getSalaryNotInitiatedReport(month, year, groupName); - } + } else { - model.addAttribute("salaryNonInitiatedReport", salaryNotInitiatedReport); + return "modules/nulm/staffupdatenoacess"; + } + } - return "modules/nulm/salary-nonInitiatedreport"; - } } diff --git a/gcc_officer_portal/src/main/java/in/gov/chennaicorporation/gccoffice/nulm/service/NulmService.java b/gcc_officer_portal/src/main/java/in/gov/chennaicorporation/gccoffice/nulm/service/NulmService.java index f3a1a369..f18906da 100644 --- a/gcc_officer_portal/src/main/java/in/gov/chennaicorporation/gccoffice/nulm/service/NulmService.java +++ b/gcc_officer_portal/src/main/java/in/gov/chennaicorporation/gccoffice/nulm/service/NulmService.java @@ -1,5 +1,6 @@ package in.gov.chennaicorporation.gccoffice.nulm.service; +import java.nio.file.Path; import java.sql.Timestamp; import java.time.LocalDate; import java.util.ArrayList; @@ -11,17 +12,30 @@ import java.util.List; import java.util.Map; import java.util.Objects; import java.util.stream.Collectors; - +import java.nio.file.Files; import javax.sql.DataSource; +import java.nio.file.Paths; +import java.awt.image.BufferedImage; +import javax.imageio.ImageIO; +import java.io.ByteArrayInputStream; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.core.env.Environment; import org.springframework.dao.DataAccessException; import org.springframework.dao.EmptyResultDataAccessException; import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; - +import org.springframework.web.multipart.MultipartFile; +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import javax.imageio.ImageWriteParam; +import javax.imageio.ImageWriter; +import javax.imageio.stream.ImageOutputStream; + +import in.gov.chennaicorporation.gccoffice.controller.DateTimeUtil; import in.gov.chennaicorporation.gccoffice.nulm.repository.NulmRepository; @Service @@ -29,16 +43,30 @@ public class NulmService { @Autowired private NulmRepository nulmRepository; + @Autowired + private Environment environment; @Autowired private JdbcTemplate jdbcTemplate; + @Value("${fileBaseUrl}") + + private String fileBaseUrl; + @Autowired public NulmService(NulmRepository nulmRepository, JdbcTemplate jdbcTemplate) { this.nulmRepository = nulmRepository; this.jdbcTemplate = jdbcTemplate; + } + /* + * public NulmService(Environment environment) { + * this.environment = environment; + * this.fileBaseUrl = environment.getProperty("fileBaseUrl"); + * } + */ + @Autowired public void setDataSource(@Qualifier("mysqlNulmDataSource") DataSource dataSource) { this.jdbcTemplate = new JdbcTemplate(dataSource); @@ -478,23 +506,25 @@ public class NulmService { return jdbcTemplate.update(sql, totalDaysPresent, totalDaysOd, totalDaysSalary, totalDaysAbsent, month, year, salaryAmount, salaryStatus, enrollmentId, groupId, wageId); } - - - + //// - -// public int addSalaryDetails_park(int totalDaysPresent, int totalDaysOd, int totalDaysSalary, int totalDaysAbsent, -// String month, int year, int salaryAmount, -// String salaryStatus, int enrollmentId, int groupId, int wageId) -// { -// String sql = "INSERT INTO salary_details_park (total_days_present, total_days_od, total_days_salary, total_days_absent, month, year, salary_amount, salary_status, enrollment_id, group_id, wage_id) " -// + -// "VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"; -// -// return jdbcTemplate.update(sql, totalDaysPresent, totalDaysOd, totalDaysSalary, totalDaysAbsent, month, year, -// salaryAmount, salaryStatus, enrollmentId, groupId, wageId); -// } - + + // public int addSalaryDetails_park(int totalDaysPresent, int totalDaysOd, int + // totalDaysSalary, int totalDaysAbsent, + // String month, int year, int salaryAmount, + // String salaryStatus, int enrollmentId, int groupId, int wageId) + // { + // String sql = "INSERT INTO salary_details_park (total_days_present, + // total_days_od, total_days_salary, total_days_absent, month, year, + // salary_amount, salary_status, enrollment_id, group_id, wage_id) " + // + + // "VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"; + // + // return jdbcTemplate.update(sql, totalDaysPresent, totalDaysOd, + // totalDaysSalary, totalDaysAbsent, month, year, + // salaryAmount, salaryStatus, enrollmentId, groupId, wageId); + // } + //// public List> getAttendanceWithSalary(String month, Integer year) { @@ -905,11 +935,11 @@ public class NulmService { List> results = jdbcTemplate.queryForList(sql.toString(), params.toArray()); return results; } - + /// - - - public List> getSalaryReport_park(String month, Integer year, String salaryStatus, String groupName, + + public List> getSalaryReport_park(String month, Integer year, String salaryStatus, + String groupName, String loginId) { // Retrieve zone access for the user @@ -987,12 +1017,9 @@ public class NulmService { List> results = jdbcTemplate.queryForList(sql.toString(), params.toArray()); return results; } - - + /// - - - + /* * public List> getSalaryReport(String month, Integer year, * String salaryStatus, String groupName) { @@ -1440,11 +1467,9 @@ public class NulmService { * return results; * } */ - - - + ///// - + public boolean checkSalaryDetails_park(int enrollmentId, String month, int year) { String sql = "select enrollment_id from salary_details_park where enrollment_id =? and month = ? and year = ?"; @@ -1452,7 +1477,7 @@ public class NulmService { return !results.isEmpty(); } - + public int addSalaryDetails_park( int totalDaysPresent, int totalDaysOd, int totalDaysSalary, int totalDaysAbsent, String month, int year, int salaryAmount, @@ -1464,7 +1489,7 @@ public class NulmService { return jdbcTemplate.update(sql, totalDaysPresent, totalDaysOd, totalDaysSalary, totalDaysAbsent, month, year, salaryAmount, salaryStatus, enrollmentId, groupId, wageId, inchargeID); } - + public int updateSalaryDetails_park( int totalDaysPresent, int totalDaysOd, int totalDaysSalary, int totalDaysAbsent, String month, int year, int salaryAmount, @@ -1476,10 +1501,8 @@ public class NulmService { return jdbcTemplate.update(sql, totalDaysPresent, totalDaysOd, totalDaysSalary, totalDaysAbsent, month, year, salaryAmount, salaryStatus, enrollmentId, groupId, wageId, inchargeID, enrollmentId, month, year); } - - + ///// - public List> getAttendanceWithInitiatedSalary( int inchargeId, String month, String year, String inchargeName, List enrollmentIds) { @@ -1514,7 +1537,7 @@ public class NulmService { "AND s.year = YEAR(COALESCE(a.indatetime, a.leavedatetime, a.oddatetime)) " + "WHERE (a.inby IS NOT NULL OR a.leaveby IS NOT NULL OR a.odby IS NOT NULL) " + "AND (? IS NULL OR e.incharge_id = ?) " + - "AND (? IS NULL OR e.incharge_name = ?) "+ + "AND (? IS NULL OR e.incharge_name = ?) " + "AND e.emp_type = 'NULM' "; if (month != null && !month.isEmpty()) { @@ -1566,10 +1589,9 @@ public class NulmService { return jdbcTemplate.queryForList(sql, params.toArray()); } - - + /// - + public List> getAttendanceWithInitiatedSalary_Park( int inchargeId, String month, String year, String inchargeName, List enrollmentIds) { @@ -1580,7 +1602,8 @@ public class NulmService { "a.enrollment_id, e.emp_id, e.name, e.incharge_id, " + "(SELECT salary_per_day FROM staff_wages_park WHERE isactive = 1 AND e.designation_id = staff_wages_park.designation_id) AS salary_per_day, " + - "(SELECT wage_id FROM staff_wages_park WHERE isactive = 1 AND e.designation_id = staff_wages_park.designation_id) AS wage_id, " + + "(SELECT wage_id FROM staff_wages_park WHERE isactive = 1 AND e.designation_id = staff_wages_park.designation_id) AS wage_id, " + + "YEAR(COALESCE(a.indatetime, a.leavedatetime, a.oddatetime)) AS year, " + "MONTHNAME(COALESCE(a.indatetime, a.leavedatetime, a.oddatetime)) AS month, " + "DAY(LAST_DAY(COALESCE(a.indatetime, a.leavedatetime, a.oddatetime))) AS total_days, " + @@ -1603,8 +1626,8 @@ public class NulmService { "AND s.year = YEAR(COALESCE(a.indatetime, a.leavedatetime, a.oddatetime)) " + "WHERE (a.inby IS NOT NULL OR a.leaveby IS NOT NULL OR a.odby IS NOT NULL) " + "AND (? IS NULL OR e.incharge_id = ?) " + - "AND (? IS NULL OR e.incharge_name = ?) "+ - "AND e.emp_type = 'Park' " ; + "AND (? IS NULL OR e.incharge_name = ?) " + + "AND e.emp_type = 'Park' "; if (month != null && !month.isEmpty()) { sql += "AND MONTHNAME(COALESCE(a.indatetime, a.leavedatetime, a.oddatetime)) = ? "; @@ -1629,8 +1652,10 @@ public class NulmService { "GROUP BY a.enrollment_id, e.group_id, " + "YEAR(COALESCE(a.indatetime, a.leavedatetime, a.oddatetime)), " + "MONTHNAME(COALESCE(a.indatetime, a.leavedatetime, a.oddatetime)), " + - "(SELECT salary_per_day FROM staff_wages_park WHERE isactive = 1 AND e.designation_id = staff_wages_park.designation_id), " + - "(SELECT wage_id FROM staff_wages_park WHERE isactive = 1 AND e.designation_id = staff_wages_park.designation_id), " + + "(SELECT salary_per_day FROM staff_wages_park WHERE isactive = 1 AND e.designation_id = staff_wages_park.designation_id), " + + + "(SELECT wage_id FROM staff_wages_park WHERE isactive = 1 AND e.designation_id = staff_wages_park.designation_id), " + + "(SELECT group_name FROM suyaudavi_kuzhu WHERE suyaudavi_kuzhu.group_id = e.group_id LIMIT 1), " + "DAY(LAST_DAY(COALESCE(a.indatetime, a.leavedatetime, a.oddatetime))), " + "s.salary_status"; @@ -1655,7 +1680,7 @@ public class NulmService { return jdbcTemplate.queryForList(sql, params.toArray()); } - + //// @Transactional @@ -1667,9 +1692,9 @@ public class NulmService { jdbcTemplate.update(sql, enrollmentId, month, year); } } - + //// - + @Transactional public void updateSalaryStatusToApproved_Park(List enrollmentIds, String month, int year) { String sql = "UPDATE salary_details_park SET salary_status = 'Approved' WHERE enrollment_id = ? AND month = ? AND year = ?"; @@ -1679,10 +1704,9 @@ public class NulmService { jdbcTemplate.update(sql, enrollmentId, month, year); } } - + //// - - + /* * public List> getFilteredSalaryDetails(String month, * Integer year, String salaryStatus) { @@ -1954,155 +1978,152 @@ public class NulmService { } } - - + //// - - + public List> getFilteredSalaryDetails_park(String month, Integer year, String salaryStatus, - String loginId) { - StringBuilder sql = new StringBuilder("SELECT " + - "e.incharge_name, " + - "e.incharge_id, " + - "e.zone, " + - "GROUP_CONCAT(e.enrollment_id) AS enrollment_ids, " + - "COUNT(e.enrollment_id) AS total_staff_count, " + - "sd.month, " + - "sd.year, " + - "sd.salary_status, " + - "COUNT(CASE WHEN sd.salary_status = 'Initiated' THEN 1 END) AS total_initiated_count, " + - "COUNT(CASE WHEN sd.salary_status = 'Approved' THEN 1 END) AS total_approved_count, " + - "SUM(CASE WHEN sd.salary_status IN ('Initiated', 'Approved') THEN sd.salary_amount ELSE 0 END) AS total_salary_amount, " - + - "e.department " + // Select the department as well - "FROM enrollment_table e " + - "JOIN salary_details_park sd ON e.enrollment_id = sd.enrollment_id " + - "WHERE 1=1 AND e.emp_type = 'Park' "); // Placeholder for dynamic conditions - - // Add filters for month, year, salary status, and department - if (month != null && !month.isEmpty()) { - sql.append(" AND sd.month = '").append(month).append("'"); - } - if (year != null) { - sql.append(" AND sd.year = ").append(year); - } - if (salaryStatus != null && !salaryStatus.isEmpty()) { - sql.append(" AND sd.salary_status = '").append(salaryStatus).append("'"); - } - - // Retrieve zone access for the user - String zoneAccessSQL = "SELECT zone FROM gcc_apps.login_mapping_user WHERE appuser_id = ?"; - List> getAccess = jdbcTemplate.queryForList(zoneAccessSQL, loginId); - System.out.println(zoneAccessSQL + "->" + loginId); - // Extract the zones from getAccess - /* - * List zones = getAccess.stream() - * .map(access -> (String) access.get("zone")) - * .filter(Objects::nonNull) - * .collect(Collectors.toList()); - * - * // If the user has zone acc ess, add it to the WHERE clause - * if (!zones.isEmpty()) { - * String zoneList = zones.stream() - * .map(zone -> "'" + zone + "'") - * .collect(Collectors.joining(", ")); - * sql.append(" AND e.zone IN (").append(zoneList).append(")"); - * // System.out.println("AND e.zone IN ("+zoneList+")"); - * } - * else { - * sql.append(" AND e.zone IN (").append("0").append(")"); - * } - */ - // Extract zones from getAccess - List zones = new ArrayList(); - for (Map access : getAccess) { - Object zoneObj = access.get("zone"); + String loginId) { + StringBuilder sql = new StringBuilder("SELECT " + + "e.incharge_name, " + + "e.incharge_id, " + + "e.zone, " + + "GROUP_CONCAT(e.enrollment_id) AS enrollment_ids, " + + "COUNT(e.enrollment_id) AS total_staff_count, " + + "sd.month, " + + "sd.year, " + + "sd.salary_status, " + + "COUNT(CASE WHEN sd.salary_status = 'Initiated' THEN 1 END) AS total_initiated_count, " + + "COUNT(CASE WHEN sd.salary_status = 'Approved' THEN 1 END) AS total_approved_count, " + + "SUM(CASE WHEN sd.salary_status IN ('Initiated', 'Approved') THEN sd.salary_amount ELSE 0 END) AS total_salary_amount, " + + + "e.department " + // Select the department as well + "FROM enrollment_table e " + + "JOIN salary_details_park sd ON e.enrollment_id = sd.enrollment_id " + + "WHERE 1=1 AND e.emp_type = 'Park' "); // Placeholder for dynamic conditions + + // Add filters for month, year, salary status, and department + if (month != null && !month.isEmpty()) { + sql.append(" AND sd.month = '").append(month).append("'"); + } + if (year != null) { + sql.append(" AND sd.year = ").append(year); + } + if (salaryStatus != null && !salaryStatus.isEmpty()) { + sql.append(" AND sd.salary_status = '").append(salaryStatus).append("'"); + } + + // Retrieve zone access for the user + String zoneAccessSQL = "SELECT zone FROM gcc_apps.login_mapping_user WHERE appuser_id = ?"; + List> getAccess = jdbcTemplate.queryForList(zoneAccessSQL, loginId); + System.out.println(zoneAccessSQL + "->" + loginId); + // Extract the zones from getAccess + /* + * List zones = getAccess.stream() + * .map(access -> (String) access.get("zone")) + * .filter(Objects::nonNull) + * .collect(Collectors.toList()); + * + * // If the user has zone acc ess, add it to the WHERE clause + * if (!zones.isEmpty()) { + * String zoneList = zones.stream() + * .map(zone -> "'" + zone + "'") + * .collect(Collectors.joining(", ")); + * sql.append(" AND e.zone IN (").append(zoneList).append(")"); + * // System.out.println("AND e.zone IN ("+zoneList+")"); + * } + * else { + * sql.append(" AND e.zone IN (").append("0").append(")"); + * } + */ + // Extract zones from getAccess + List zones = new ArrayList(); + for (Map access : getAccess) { + Object zoneObj = access.get("zone"); if (zoneObj != null) { zones.add(zoneObj.toString()); } - } - - // If the user has zone access, add it to the WHERE clause - if (!zones.isEmpty()) { + } + + // If the user has zone access, add it to the WHERE clause + if (!zones.isEmpty()) { StringBuilder zoneList = new StringBuilder(); for (int i = 0; i < zones.size(); i++) { - zoneList.append("'").append(zones.get(i)).append("'"); - if (i < zones.size() - 1) { - zoneList.append(", "); - } + zoneList.append("'").append(zones.get(i)).append("'"); + if (i < zones.size() - 1) { + zoneList.append(", "); + } } sql.append(" AND e.zone IN (").append(zoneList.toString()).append(")"); - } else { + } else { sql.append(" AND e.zone IN (0)"); - } - sql.append( - " GROUP BY e.incharge_name, e.incharge_id, e.zone, sd.month, sd.year, sd.salary_status, e.department "); - sql.append(" ORDER BY sd.year DESC, sd.month DESC"); - /* - * try { - * List> result = jdbcTemplate.queryForList(sql.toString()); - * for (Map row : result) { - * String enrollmentIdsString = (String) row.get("enrollment_ids"); - * if (enrollmentIdsString != null) { - * List enrollmentIds = Arrays.stream(enrollmentIdsString.split(",")) - * .map(String::trim) - * .filter(id -> !id.isEmpty()) - * .map(Integer::parseInt) - * .collect(Collectors.toList()); - * row.put("enrollment_ids", enrollmentIds); - * } - * } - * return result; - * } catch (Exception e) { - * e.printStackTrace(); - * return Collections.emptyList(); - * } - */ - - try { + } + sql.append( + " GROUP BY e.incharge_name, e.incharge_id, e.zone, sd.month, sd.year, sd.salary_status, e.department "); + sql.append(" ORDER BY sd.year DESC, sd.month DESC"); + /* + * try { + * List> result = jdbcTemplate.queryForList(sql.toString()); + * for (Map row : result) { + * String enrollmentIdsString = (String) row.get("enrollment_ids"); + * if (enrollmentIdsString != null) { + * List enrollmentIds = Arrays.stream(enrollmentIdsString.split(",")) + * .map(String::trim) + * .filter(id -> !id.isEmpty()) + * .map(Integer::parseInt) + * .collect(Collectors.toList()); + * row.put("enrollment_ids", enrollmentIds); + * } + * } + * return result; + * } catch (Exception e) { + * e.printStackTrace(); + * return Collections.emptyList(); + * } + */ + + try { List> result = jdbcTemplate.queryForList(sql.toString()); - + for (Map row : result) { - String enrollmentIdsString = (String) row.get("enrollment_ids"); - if (enrollmentIdsString != null) { - String[] parts = enrollmentIdsString.split(","); - List enrollmentIds = new ArrayList(); - for (int i = 0; i < parts.length; i++) { - String part = parts[i].trim(); - if (!part.isEmpty()) { - try { - enrollmentIds.add(Integer.parseInt(part)); - } catch (NumberFormatException nfe) { - // Ignore or log invalid integers - nfe.printStackTrace(); - } - } - } - row.put("enrollment_ids", enrollmentIds); - } + String enrollmentIdsString = (String) row.get("enrollment_ids"); + if (enrollmentIdsString != null) { + String[] parts = enrollmentIdsString.split(","); + List enrollmentIds = new ArrayList(); + for (int i = 0; i < parts.length; i++) { + String part = parts[i].trim(); + if (!part.isEmpty()) { + try { + enrollmentIds.add(Integer.parseInt(part)); + } catch (NumberFormatException nfe) { + // Ignore or log invalid integers + nfe.printStackTrace(); + } + } + } + row.put("enrollment_ids", enrollmentIds); + } } - + return result; - } catch (Exception e) { + } catch (Exception e) { e.printStackTrace(); return Collections.emptyList(); - } + } } - - + //// -// public Integer checkInchargeID(Integer inchargeId) { -// -// String sql = "SELECT EXISTS( " + -// "SELECT 1 FROM additional_incharge " + -// "WHERE incharge_id = ? AND is_active = 1 AND is_delete = 0)"; -// -// Integer result = jdbcTemplate.queryForObject(sql, Integer.class, inchargeId); -// -// return result; -// } + // public Integer checkInchargeID(Integer inchargeId) { + // + // String sql = "SELECT EXISTS( " + + // "SELECT 1 FROM additional_incharge " + + // "WHERE incharge_id = ? AND is_active = 1 AND is_delete = 0)"; + // + // Integer result = jdbcTemplate.queryForObject(sql, Integer.class, inchargeId); + // + // return result; + // } public List> getAttendanceWithSalaryByInchargeId(String month, Integer year, Integer incharge_id) { @@ -2141,7 +2162,7 @@ public class NulmService { "LEFT JOIN salary_details AS s ON a.enrollment_id = s.enrollment_id " + "AND s.month = MONTHNAME(COALESCE(a.indatetime, a.leavedatetime, a.oddatetime)) " + "AND s.year = YEAR(COALESCE(a.indatetime, a.leavedatetime, a.oddatetime)) " + - "WHERE (a.inby IS NOT NULL OR a.leaveby IS NOT NULL OR a.odby IS NOT NULL) AND e.emp_type = 'NULM' "); + "WHERE (a.inby IS NOT NULL OR a.leaveby IS NOT NULL OR a.odby IS NOT NULL) "); // Append condition for incharge_id sql.append("AND (? IS NULL OR e.incharge_id = ?) "); @@ -2189,21 +2210,129 @@ public class NulmService { List> results = jdbcTemplate.queryForList(sql.toString(), params.toArray()); return results; } - - + /// - - + public List> getAttendanceWithSalaryByInchargeId_New(String month, Integer year, - Integer incharge_id, String type, String ids) - { + Integer incharge_id, String type, String ids) { List> results = new ArrayList<>(); - if(type.equalsIgnoreCase("1")){ - results = getAttendanceWithSalaryByInchargeId(month,year, incharge_id); - } - else - { + if (type.equalsIgnoreCase("1")) { + results = getAttendanceWithSalaryByInchargeId_Nulm(month, year, incharge_id); + } else { StringBuilder sql = new StringBuilder("SELECT " + + "e.group_id, " + + "(SELECT group_name FROM suyaudavi_kuzhu WHERE suyaudavi_kuzhu.group_id = e.group_id LIMIT 1) AS group_name, " + + + "a.enrollment_id, " + + "e.emp_id, " + + "e.name, " + + "e.incharge_id, " + + "e.incharge_name, " + + "(SELECT salary_per_day FROM staff_wages_park WHERE isactive = 1 AND e.designation_id = staff_wages_park.designation_id) AS salary_per_day, " + + + "(SELECT wage_id FROM staff_wages_park WHERE isactive = 1 AND e.designation_id = staff_wages_park.designation_id) AS wage_id, " + + + "YEAR(COALESCE(a.indatetime, a.leavedatetime, a.oddatetime)) AS year, " + + "MONTHNAME(COALESCE(a.indatetime, a.leavedatetime, a.oddatetime)) AS month, " + + "DAY(LAST_DAY(COALESCE(a.indatetime, a.leavedatetime, a.oddatetime))) AS total_days, " + + "COUNT(DISTINCT DATE(a.indatetime)) AS total_days_present, " + + // Subquery to get total_days_od + "(SELECT COUNT(DISTINCT DATE(a2.oddatetime)) " + + " FROM attendance AS a2 " + + " WHERE MONTHNAME(a2.oddatetime) = ? " + // Use placeholder for month + " AND YEAR(a2.oddatetime) = ? " + // Use placeholder for year + " AND a2.enrollment_id = a.enrollment_id " + + " AND DATE(a2.oddatetime) NOT IN ( " + + " SELECT DISTINCT DATE(a3.indatetime) " + + " FROM attendance AS a3 " + + " WHERE MONTHNAME(a3.indatetime) = ? " + // Use placeholder for month + " AND YEAR(a3.indatetime) = ? " + // Use placeholder for year + " AND a3.enrollment_id = a.enrollment_id " + + ")) AS total_days_od, " + + "IFNULL(s.salary_status, '') AS salary_status " + + "FROM attendance AS a " + + "INNER JOIN enrollment_table AS e ON a.enrollment_id = e.enrollment_id " + + "LEFT JOIN salary_details_park AS s ON a.enrollment_id = s.enrollment_id " + + "AND s.month = MONTHNAME(COALESCE(a.indatetime, a.leavedatetime, a.oddatetime)) " + + "AND s.year = YEAR(COALESCE(a.indatetime, a.leavedatetime, a.oddatetime)) " + + "WHERE (a.inby IS NOT NULL OR a.leaveby IS NOT NULL OR a.odby IS NOT NULL) AND e.emp_type = 'Park' "); + + List params = new ArrayList<>(); + params.add(month); // Add month for total_days_od + params.add(year); // Add year for total_days_od + params.add(month); // Add month for the inner subquery + params.add(year); // Add year for the inner subquery + + // Append condition for incharge_id + // sql.append("AND (? IS NULL OR e.incharge_id = ?) "); + if (ids != null && !ids.trim().isEmpty()) { + + List idList = Arrays.stream(ids.split(",")) + .map(String::trim) + .map(Integer::parseInt) + .toList(); + + String placeholders = idList.stream() + .map(i -> "?") + .collect(Collectors.joining(",")); + System.out.println("placeholders = " + placeholders); + + sql.append(" AND e.incharge_id IN (").append(placeholders).append(") "); + + System.out.println("idList = " + idList); + params.addAll(idList); + } + + // Append condition for month if provided + if (month != null && !month.isEmpty()) { + sql.append("AND MONTHNAME(COALESCE(a.indatetime, a.leavedatetime, a.oddatetime)) = ? "); + params.add(month); + } + + // Append condition for year if provided + if (year != null) { + sql.append("AND YEAR(COALESCE(a.indatetime, a.leavedatetime, a.oddatetime)) = ? "); + params.add(year); + } + + // Group by necessary columns + sql.append("GROUP BY a.enrollment_id, e.group_id, " + + "YEAR(COALESCE(a.indatetime, a.leavedatetime, a.oddatetime)), " + + "MONTHNAME(COALESCE(a.indatetime, a.leavedatetime, a.oddatetime)), " + + "(SELECT salary_per_day FROM staff_wages_park WHERE isactive = 1 AND e.designation_id = staff_wages_park.designation_id), " + + + "(SELECT wage_id FROM staff_wages_park WHERE isactive = 1 AND e.designation_id = staff_wages_park.designation_id), " + + + "(SELECT group_name FROM suyaudavi_kuzhu WHERE suyaudavi_kuzhu.group_id = e.group_id LIMIT 1), " + + "DAY(LAST_DAY(COALESCE(a.indatetime, a.leavedatetime, a.oddatetime))), " + + "s.salary_status"); + + System.out.println("Query = " + sql); + + // Create a list of parameters + + // params.add(incharge_id); + // params.add(incharge_id); // Added twice for the conditional check in the SQL + // if (month != null && !month.isEmpty()) { + // params.add(month); + // } + // if (year != null) { + // params.add(year); + // } + + // Log the SQL and parameters (optional for debugging) + System.out.println("Generated SQL: " + sql.toString()); + System.out.println("Parameters: " + params); + + // Execute the query using JdbcTemplate + results = jdbcTemplate.queryForList(sql.toString(), params.toArray()); + } + return results; + } + + private List> getAttendanceWithSalaryByInchargeId_Nulm(String month, Integer year, + Integer incharge_id) { + StringBuilder sql = new StringBuilder("SELECT " + "e.group_id, " + "(SELECT group_name FROM suyaudavi_kuzhu WHERE suyaudavi_kuzhu.group_id = e.group_id LIMIT 1) AS group_name, " + @@ -2212,9 +2341,9 @@ public class NulmService { "e.name, " + "e.incharge_id, " + "e.incharge_name, " + - "(SELECT salary_per_day FROM staff_wages_park WHERE isactive = 1 AND e.designation_id = staff_wages_park.designation_id) AS salary_per_day, " + "(SELECT salary_per_day FROM staff_wages WHERE isactive = 1 ORDER BY wage_id DESC LIMIT 1) AS salary_per_day, " + - "(SELECT wage_id FROM staff_wages_park WHERE isactive = 1 AND e.designation_id = staff_wages_park.designation_id) AS wage_id, " + + "(SELECT wage_id FROM staff_wages WHERE isactive = 1 ORDER BY wage_id DESC LIMIT 1) AS wage_id, " + "YEAR(COALESCE(a.indatetime, a.leavedatetime, a.oddatetime)) AS year, " + "MONTHNAME(COALESCE(a.indatetime, a.leavedatetime, a.oddatetime)) AS month, " + "DAY(LAST_DAY(COALESCE(a.indatetime, a.leavedatetime, a.oddatetime))) AS total_days, " + @@ -2235,89 +2364,59 @@ public class NulmService { "IFNULL(s.salary_status, '') AS salary_status " + "FROM attendance AS a " + "INNER JOIN enrollment_table AS e ON a.enrollment_id = e.enrollment_id " + - "LEFT JOIN salary_details_park AS s ON a.enrollment_id = s.enrollment_id " + + "LEFT JOIN salary_details AS s ON a.enrollment_id = s.enrollment_id " + "AND s.month = MONTHNAME(COALESCE(a.indatetime, a.leavedatetime, a.oddatetime)) " + "AND s.year = YEAR(COALESCE(a.indatetime, a.leavedatetime, a.oddatetime)) " + - "WHERE (a.inby IS NOT NULL OR a.leaveby IS NOT NULL OR a.odby IS NOT NULL) AND e.emp_type = 'Park' "); - - List params = new ArrayList<>(); - params.add(month); // Add month for total_days_od - params.add(year); // Add year for total_days_od - params.add(month); // Add month for the inner subquery - params.add(year); // Add year for the inner subquery - - - // Append condition for incharge_id - //sql.append("AND (? IS NULL OR e.incharge_id = ?) "); - if (ids != null && !ids.trim().isEmpty()) { - - List idList = Arrays.stream(ids.split(",")) - .map(String::trim) - .map(Integer::parseInt) - .toList(); - - String placeholders = idList.stream() - .map(i -> "?") - .collect(Collectors.joining(",")); - System.out.println("placeholders = "+placeholders); - - sql.append(" AND e.incharge_id IN (").append(placeholders).append(") "); - - System.out.println("idList = "+idList); - params.addAll(idList); - } - - - // Append condition for month if provided - if (month != null && !month.isEmpty()) { - sql.append("AND MONTHNAME(COALESCE(a.indatetime, a.leavedatetime, a.oddatetime)) = ? "); - params.add(month); - } - - // Append condition for year if provided - if (year != null) { - sql.append("AND YEAR(COALESCE(a.indatetime, a.leavedatetime, a.oddatetime)) = ? "); - params.add(year); - } - - // Group by necessary columns - sql.append("GROUP BY a.enrollment_id, e.group_id, " + + "WHERE (a.inby IS NOT NULL OR a.leaveby IS NOT NULL OR a.odby IS NOT NULL) AND e.emp_type = 'NULM' "); + + // Append condition for incharge_id + sql.append("AND (? IS NULL OR e.incharge_id = ?) "); + + // Append condition for month if provided + if (month != null && !month.isEmpty()) { + sql.append("AND MONTHNAME(COALESCE(a.indatetime, a.leavedatetime, a.oddatetime)) = ? "); + } + + // Append condition for year if provided + if (year != null) { + sql.append("AND YEAR(COALESCE(a.indatetime, a.leavedatetime, a.oddatetime)) = ? "); + } + + // Group by necessary columns + sql.append("GROUP BY a.enrollment_id, e.group_id, " + "YEAR(COALESCE(a.indatetime, a.leavedatetime, a.oddatetime)), " + "MONTHNAME(COALESCE(a.indatetime, a.leavedatetime, a.oddatetime)), " + - "(SELECT salary_per_day FROM staff_wages_park WHERE isactive = 1 AND e.designation_id = staff_wages_park.designation_id), " + - "(SELECT wage_id FROM staff_wages_park WHERE isactive = 1 AND e.designation_id = staff_wages_park.designation_id), " + + "(SELECT salary_per_day FROM staff_wages WHERE isactive = 1 ORDER BY wage_id DESC LIMIT 1), " + + "(SELECT wage_id FROM staff_wages WHERE isactive = 1 ORDER BY wage_id DESC LIMIT 1), " + "(SELECT group_name FROM suyaudavi_kuzhu WHERE suyaudavi_kuzhu.group_id = e.group_id LIMIT 1), " + "DAY(LAST_DAY(COALESCE(a.indatetime, a.leavedatetime, a.oddatetime))), " + "s.salary_status"); - - System.out.println("Query = " + sql); - - // Create a list of parameters - - - //params.add(incharge_id); - //params.add(incharge_id); // Added twice for the conditional check in the SQL - //if (month != null && !month.isEmpty()) { - //params.add(month); - //} - //if (year != null) { - //params.add(year); - //} - - // Log the SQL and parameters (optional for debugging) - System.out.println("Generated SQL: " + sql.toString()); - System.out.println("Parameters: " + params); - - // Execute the query using JdbcTemplate - results = jdbcTemplate.queryForList(sql.toString(), params.toArray()); - } - return results; + + // Create a list of parameters + List params = new ArrayList<>(); + params.add(month); // Add month for total_days_od + params.add(year); // Add year for total_days_od + params.add(month); // Add month for the inner subquery + params.add(year); // Add year for the inner subquery + params.add(incharge_id); + params.add(incharge_id); // Added twice for the conditional check in the SQL + if (month != null && !month.isEmpty()) { + params.add(month); + } + if (year != null) { + params.add(year); } - - + + // Log the SQL and parameters (optional for debugging) + System.out.println("Generated SQL: " + sql.toString()); + System.out.println("Parameters: " + params); + + // Execute the query using JdbcTemplate + List> results = jdbcTemplate.queryForList(sql.toString(), params.toArray()); + return results; + } + //// - - public List> getZoneWiseReport(String month, Integer year, String salaryStatus, String groupName, String zone, String division) { @@ -2777,8 +2876,7 @@ public class NulmService { return jdbcTemplate.update(sql, totalDaysPresent, totalDaysOd, totalDaysSalary, totalDaysAbsent, month, year, salaryAmount, salaryStatus, enrollmentId, groupId, wageId, inchargeID, enrollmentId, month, year); } - - + public String checkInchargeID(Integer inchargeId) { String sql = "SELECT " + @@ -2799,4 +2897,464 @@ public class NulmService { return result; } + + // ak + public List getZones() { + + String sql = "select distinct zone from park_details " + + "where is_active = 1 and is_delete = 0 order by zone"; + + return jdbcTemplate.queryForList(sql, Integer.class); + } + + // 2. Get Divisions by Zone + public List getDivisions(int zone) { + + String sql = "select distinct division from park_details " + + "where is_active = 1 and is_delete = 0 and zone = ? " + + "order by division"; + + return jdbcTemplate.queryForList(sql, Integer.class, zone); + } + + // 3. Get Parks by Zone and Division + /* + * public List> getParks(int zone, int division) { + * + * String sql = "select park_id, park_name from park_details " + + * "where is_active = 1 and is_delete = 0 " + + * "and zone = ? and division = ? " + + * "order by park_name"; + * + * return jdbcTemplate.queryForList(sql, zone, division); + * } + */ + public List> getParks(int zone, Integer division) { + + String sql = "select park_id, park_name from park_details " + + "where is_active = 1 and is_delete = 0 and zone = ? "; + + List params = new ArrayList<>(); + params.add(zone); + + if (division != null) { + sql += " and division = ? "; + params.add(division); + } + + sql += " order by park_name"; + + return jdbcTemplate.queryForList(sql, params.toArray()); + } + + public List> getStaffByPark(int parkId) { + + String sql = "select et.emp_id, et.enrollment_id, pd.park_name, " + + "et.name as empname, et.phone_number, " + + "et.designation, et.incharge_name " + + "from enrollment_table et " + + "left join park_details pd on et.park_id = pd.park_id " + + "where pd.park_id = ? " + + "and et.isactive = 1 " + + "and et.isdelete = 0 " + + "and pd.is_active = 1 " + + "and et.emp_type = 'Park'"; + + return jdbcTemplate.queryForList(sql, parkId); + } + + public Map getStaffDetails(int enrollmentId) { + + String sql = "select pd.park_name, et.incharge_name, et.name as name, et.designation,et.designation_id, " + + "ifnull(sk.group_name,'-') as groupname, et.aadhar_no, ifnull(et.f_h_name,'') as f_h_name, " + + "ifnull(et.bank_acc_no,'-') as bankaccNo, et.phone_number,et.not_found,et.error,et.remarks, " + + "ifnull(et.address,'-') as address, " + + "ifnull(et.bank_name,'') as bank_name, " + + "ifnull(et.ifsc_code,'') as ifsc_code, " + + "ifnull(et.branch,'') as branch, " + + "ifnull(et.branch_address,'') as branch_address, " + + "IFNULL(CONCAT('" + fileBaseUrl + "/gcc/files', et.form_url),'') AS formUrl, " + + "IFNULL(CONCAT('" + fileBaseUrl + "/gcc/files', et.bank_passbook_url),'') AS bankpassbookUrl, " + + "IFNULL(CONCAT('" + fileBaseUrl + "/gcc/files', et.aadhar_card_url),'') AS aadharUrl " + + "from enrollment_table et " + + "left join park_details pd on et.park_id = pd.park_id " + + "left join suyaudavi_kuzhu sk on et.group_id = sk.group_id " + + "where et.isactive = 1 and et.enrollment_id = ?"; + + return jdbcTemplate.queryForMap(sql, enrollmentId); + } + + /* + * public String updateStaff( + * int enrollmentId, + * String fhName, + * String designation, + * Integer designationId, + * String aadharNo, + * String bankAccNo, + * String phoneNumber, + * String address, + * MultipartFile uploadform, + * MultipartFile aadharcard, + * MultipartFile bankpassbook,String createdBy) { + * + * StringBuilder sql = new StringBuilder("UPDATE enrollment_table SET "); + * List params = new ArrayList<>(); + * + * if (fhName != null && !fhName.isEmpty()) { + * sql.append("f_h_name=?, "); + * params.add(fhName); + * } + * + * if (designation != null && !designation.isEmpty()) { + * sql.append("designation=?, "); + * params.add(designation); + * } + * + * if (designationId != null) { + * sql.append("designation_id=?, "); + * params.add(designationId); + * } + * + * if (aadharNo != null && !aadharNo.isEmpty()) { + * sql.append("aadhar_no=?, "); + * params.add(aadharNo); + * } + * + * if (bankAccNo != null && !bankAccNo.isEmpty()) { + * sql.append("bank_acc_no=?, "); + * params.add(bankAccNo); + * } + * + * if (phoneNumber != null && !phoneNumber.isEmpty()) { + * sql.append("phone_number=?, "); + * params.add(phoneNumber); + * } + * + * if (address != null && !address.isEmpty()) { + * sql.append("res_adress=?, "); + * params.add(address); + * } + * + * // File uploads + * if (uploadform != null && !uploadform.isEmpty()) { + * String path = fileUpload("uploadform", String.valueOf(enrollmentId), + * uploadform); + * sql.append("form_url=?, "); + * params.add(path); + * } + * + * if (aadharcard != null && !aadharcard.isEmpty()) { + * String path = fileUpload("aadharcard", String.valueOf(enrollmentId), + * aadharcard); + * sql.append("aadhar_card_url=?, "); + * params.add(path); + * } + * + * if (bankpassbook != null && !bankpassbook.isEmpty()) { + * String path = fileUpload("bankpassbook", String.valueOf(enrollmentId), + * bankpassbook); + * sql.append("bank_passbook_url=?, "); + * params.add(path); + * } + * + * // Remove last comma + * sql.setLength(sql.length() - 2); + * + * sql.append(" WHERE enrollment_id=?"); + * params.add(enrollmentId); + * + * jdbcTemplate.update(sql.toString(), params.toArray()); + * + * return "Updated Successfully"; + * } + */ + @Transactional + public String updateStaff( + int enrollmentId, + String fhName, + String designation, + Integer designationId, + String aadharNo, + String bankAccNo, + String bankName, + String ifscCode, + String branch, + String branchAddress, + String phoneNumber, + String address, + MultipartFile uploadform, + MultipartFile aadharcard, + MultipartFile bankpassbook, + Integer notFound, + Integer error, + String remarks, + String createdBy) { + + // 1️⃣ Fetch existing record + String fetchSql = "SELECT * FROM enrollment_table WHERE enrollment_id = ?"; + Map existing = jdbcTemplate.queryForMap(fetchSql, enrollmentId); + + // 2️⃣ Insert existing record into log table + String logSql = "INSERT INTO enrollment_table_log(" + + "enrollment_id,name,department,division,incharge_id,incharge_name,incharge_designation,RFID_CARD_NO," + + "designation,incharge_phoneno,emp_id,isactive,isdelete,created_date,appointed,facial_attendance," + + "staff_photo_url,order_id,group_id,dropout_date,dropout,registered_date,appointed_date,res_adress," + + "f_h_name,form_url,bank_passbook_url,bank_acc_no,ration_card_url,aadhar_no,aadhar_card_url," + + "additional_skills,education_qualification,address,phone_number,gender,date_of_birth,zone," + + "remarks,emp_type,park_name,park_id,designation_id,not_found,error,updatedby,bank_name,ifsc_code,branch,branch_address)" + + " VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)"; + + jdbcTemplate.update(logSql, + + existing.get("enrollment_id"), + existing.get("name"), + existing.get("department"), + existing.get("division"), + existing.get("incharge_id"), + existing.get("incharge_name"), + existing.get("incharge_designation"), + existing.get("RFID_CARD_NO"), + existing.get("designation"), + existing.get("incharge_phoneno"), + existing.get("emp_id"), + existing.get("isactive"), + existing.get("isdelete"), + existing.get("created_date"), + existing.get("appointed"), + existing.get("facial_attendance"), + existing.get("staff_photo_url"), + existing.get("order_id"), + existing.get("group_id"), + existing.get("dropout_date"), + existing.get("dropout"), + existing.get("registered_date"), + existing.get("appointed_date"), + existing.get("res_adress"), + existing.get("f_h_name"), + existing.get("form_url"), + existing.get("bank_passbook_url"), + existing.get("bank_acc_no"), + existing.get("ration_card_url"), + existing.get("aadhar_no"), + existing.get("aadhar_card_url"), + existing.get("additional_skills"), + existing.get("education_qualification"), + existing.get("address"), + existing.get("phone_number"), + existing.get("gender"), + existing.get("date_of_birth"), + existing.get("zone"), + existing.get("remarks"), + existing.get("emp_type"), + existing.get("park_name"), + existing.get("park_id"), + // existing.get("designation_id"), + existing.get("designation_id") == null ? 0 : existing.get("designation_id"), + existing.get("not_found"), + existing.get("error"), + + createdBy, + existing.get("bank_name"), + existing.get("ifsc_code"), + existing.get("branch"), + existing.get("branch_address")); + + // 3️⃣ Build dynamic update query + StringBuilder sql = new StringBuilder("UPDATE enrollment_table SET "); + List params = new ArrayList<>(); + + if (fhName != null && !fhName.isEmpty()) { + sql.append("f_h_name=?, "); + params.add(fhName); + } + + if (designation != null && !designation.isEmpty()) { + sql.append("designation=?, "); + params.add(designation); + } + + if (designationId != null) { + sql.append("designation_id=?, "); + params.add(designationId); + } + + if (aadharNo != null && !aadharNo.isEmpty()) { + sql.append("aadhar_no=?, "); + params.add(aadharNo); + } + + if (bankAccNo != null && !bankAccNo.isEmpty()) { + sql.append("bank_acc_no=?, "); + params.add(bankAccNo); + } + // ak + if (bankName != null && !bankName.isEmpty()) { + sql.append("bank_name=?, "); + params.add(bankName); + } + + if (ifscCode != null && !ifscCode.isEmpty()) { + sql.append("ifsc_code=?, "); + params.add(ifscCode); + } + + if (branch != null && !branch.isEmpty()) { + sql.append("branch=?, "); + params.add(branch); + } + + if (branchAddress != null && !branchAddress.isEmpty()) { + sql.append("branch_address=?, "); + params.add(branchAddress); + } + + if (phoneNumber != null && !phoneNumber.isEmpty()) { + sql.append("phone_number=?, "); + params.add(phoneNumber); + } + + if (address != null && !address.isEmpty()) { + sql.append("address=?, "); + params.add(address); + } + + // 4️⃣ File Upload Handling + + if (uploadform != null && !uploadform.isEmpty()) { + String path = fileUpload("uploadform", String.valueOf(enrollmentId), uploadform); + sql.append("form_url=?, "); + params.add(path); + } + + if (aadharcard != null && !aadharcard.isEmpty()) { + String path = fileUpload("aadharcard", String.valueOf(enrollmentId), aadharcard); + sql.append("aadhar_card_url=?, "); + params.add(path); + } + + if (bankpassbook != null && !bankpassbook.isEmpty()) { + String path = fileUpload("bankpassbook", String.valueOf(enrollmentId), bankpassbook); + sql.append("bank_passbook_url=?, "); + params.add(path); + } + if (notFound != null) { + sql.append("not_found=?, "); + params.add(notFound); + } + + if (error != null) { + sql.append("error=?, "); + params.add(error); + } + + if (remarks != null) { + sql.append("remarks=?, "); + params.add(remarks); + } + + // Remove last comma + sql.setLength(sql.length() - 2); + + sql.append(" WHERE enrollment_id=?"); + params.add(enrollmentId); + + jdbcTemplate.update(sql.toString(), params.toArray()); + + return "Staff updated successfully"; + } + + public String fileUpload(String name, String id, MultipartFile file) { + + int lastInsertId = 0; + // Set the file path where you want to save it + String uploadDirectory = environment.getProperty("file.upload.directory"); + String serviceFolderName = environment.getProperty("nulm_foldername"); + var year = DateTimeUtil.getCurrentYear(); + var month = DateTimeUtil.getCurrentMonth(); + var date = DateTimeUtil.getCurrentDay(); + + uploadDirectory = uploadDirectory + serviceFolderName + year + "/" + month + "/" + date; + + try { + // Create directory if it doesn't exist + Path directoryPath = Paths.get(uploadDirectory); + if (!Files.exists(directoryPath)) { + Files.createDirectories(directoryPath); + } + + // Datetime string + String datetimetxt = DateTimeUtil.getCurrentDateTime(); + // File name + System.out.println(file.getOriginalFilename()); + String fileName = name + "_" + id + "_" + datetimetxt + "_" + + file.getOriginalFilename(); + fileName = fileName.replaceAll("\\s+", ""); // Remove space on filename + + String filePath = uploadDirectory + "/" + fileName; + + String filepath_txt = "/" + serviceFolderName + year + "/" + month + "/" + date + "/" + fileName; + + // Create a new Path object + Path path = Paths.get(filePath); + + // Get the bytes of the file + byte[] bytes = file.getBytes(); + + // Compress the image + BufferedImage image = ImageIO.read(new ByteArrayInputStream(bytes)); + byte[] compressedBytes = compressImage(image, 0.5f); // Compress with 50% quality + + // Write the bytes to the file + Files.write(path, bytes); + + System.out.println(filePath); + return filepath_txt; + + } catch (IOException e) { + e.printStackTrace(); + return "Failed to save file " + file.getOriginalFilename(); + } + } + + private byte[] compressImage(BufferedImage image, float quality) throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + ImageOutputStream imageOutputStream = ImageIO.createImageOutputStream(byteArrayOutputStream); + + ImageWriter writer = ImageIO.getImageWritersByFormatName("jpg").next(); + writer.setOutput(imageOutputStream); + + ImageWriteParam param = writer.getDefaultWriteParam(); + if (param.canWriteCompressed()) { + param.setCompressionMode(ImageWriteParam.MODE_EXPLICIT); + param.setCompressionQuality(quality); + } + + writer.write(null, new javax.imageio.IIOImage(image, null, null), param); + + writer.dispose(); + imageOutputStream.close(); + + return byteArrayOutputStream.toByteArray(); + } + + public boolean hasStaffUpdateAccess(String LoginUserId) { + + String sql = "SELECT COUNT(*) FROM login_mapping_1913 " + + "WHERE appuser_id = ? AND isactive = 1 AND isdelete = 0"; + + Integer count = jdbcTemplate.queryForObject(sql, Integer.class, LoginUserId); + + return count != null && count > 0; + } + + public List> getDesignations() { + + String sql = "SELECT designation_id, designation " + + "FROM designation_master " + + "WHERE is_active = 1 AND is_delete = 0"; + + return jdbcTemplate.queryForList(sql); + } + } \ No newline at end of file diff --git a/gcc_officer_portal/src/main/resources/templates/modules/nulm/staffupdate.html b/gcc_officer_portal/src/main/resources/templates/modules/nulm/staffupdate.html new file mode 100644 index 00000000..3d94d42a --- /dev/null +++ b/gcc_officer_portal/src/main/resources/templates/modules/nulm/staffupdate.html @@ -0,0 +1,1509 @@ + + + + + + + +
+
+ +
+
+
+
+ + +
+ + +
+
+ + +
+ +
+ + +
+ +
+ + +
+ + + +
+ + + + +
+
+ + +
+ + + + + + + + + + + + + + + + + + + + + +
S.NoEmployee IdPark NameEmployee NameMobile NumberEmployee DesignationIncharge NameAction
+
+ +
+
+ + +
+
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/gcc_officer_portal/src/main/resources/templates/modules/nulm/staffupdatenoacess.html b/gcc_officer_portal/src/main/resources/templates/modules/nulm/staffupdatenoacess.html new file mode 100644 index 00000000..c379f84a --- /dev/null +++ b/gcc_officer_portal/src/main/resources/templates/modules/nulm/staffupdatenoacess.html @@ -0,0 +1,63 @@ + + + + + + + +
+
+ +
+
+
+
+ + +
+ +
+
+ You Have No access for staff Update, Please contact admin... +
+
+ + +
+
+ + +
+
+
+ +
+ + + + + + + \ No newline at end of file