diff --git a/gcc_officer_portal/src/main/java/in/gov/chennaicorporation/gccoffice/configuration/DataSourceConfig.java b/gcc_officer_portal/src/main/java/in/gov/chennaicorporation/gccoffice/configuration/DataSourceConfig.java index 0b0c7de6..6faee8d8 100644 --- a/gcc_officer_portal/src/main/java/in/gov/chennaicorporation/gccoffice/configuration/DataSourceConfig.java +++ b/gcc_officer_portal/src/main/java/in/gov/chennaicorporation/gccoffice/configuration/DataSourceConfig.java @@ -24,15 +24,14 @@ import java.util.Properties; @EnableTransactionManagement public class DataSourceConfig { - private static String host = "localhost:3306"; - private static String dbpassword = "root"; +// private static String host = "localhost:3306"; +// private static String dbpassword = "root"; // private static String dbpassword = "gccroot"; // AWS - // private static String host = - // "gcc-facial-db-instance-1.cf48eqcciziq.ap-south-1.rds.amazonaws.com:3306"; - // private static String dbpassword = "gcc-facial-password"; + private static String host ="gcc-facial-db-instance-1.cf48eqcciziq.ap-south-1.rds.amazonaws.com:3306"; + private static String dbpassword = "gcc-facial-password"; ////////////////////////////// (For GCC APP) //////////////////////// @Configuration 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 cdd8df4c..03f4960e 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 @@ -16,6 +16,7 @@ import javax.sql.DataSource; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.beans.factory.annotation.Required; import org.springframework.core.env.Environment; import org.springframework.dao.DataAccessException; import org.springframework.dao.EmptyResultDataAccessException; @@ -33,6 +34,7 @@ import org.springframework.web.bind.annotation.RestController; import org.springframework.web.multipart.MultipartFile; import in.gov.chennaicorporation.gccoffice.nulm.service.NulmService; +import in.gov.chennaicorporation.gccoffice.service.LoginUserInfo; @RequestMapping("/gcc/api/nulm") @RestController("nulmAPI") @@ -509,14 +511,34 @@ public class NulmAPIController { @RequestParam(value = "inchargeId", required = false) Integer inchargeId, @RequestParam(value = "month", required = false) String month, @RequestParam(value = "year", required = false) String year, - @RequestParam(value = "incharge_name", required = false) String inchargeName, + @RequestParam(value = "inchargeName", required = false) String inchargeName, @RequestParam(value = "enrollmentIds", required = false) List enrollmentIds) { + + 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, + @RequestParam(value = "month", required = false) String month, + @RequestParam(value = "year", required = false) String year, + @RequestParam(value = "inchargeName", required = false) String inchargeName, + @RequestParam(value = "enrollmentIds", required = false) List enrollmentIds) { + List> staffList = nulmService.getAttendanceWithInitiatedSalary_Park(inchargeId, month, year, + 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()); + 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()); + int totalDaysAbsent = Integer.parseInt(request.get("total_days_absent").toString()); + String month = request.get("month").toString(); + int year = Integer.parseInt(request.get("year").toString()); + int salaryAmount = Integer.parseInt(request.get("salary_amount").toString()); + int enrollmentId = Integer.parseInt(request.get("enrollment_id").toString()); + int groupId = Integer.parseInt(request.get("group_id").toString()); + int wageId = Integer.parseInt(request.get("wage_id").toString()); + int inchargeID = 0;// Integer.parseInt(""+request.get("incharge_id")); + + // Check if the month and year are valid for salary initiation (past month) + if (isFutureOrCurrentMonth(month, year)) { + return ResponseEntity.status(HttpStatus.BAD_REQUEST) + .body("Salary cannot be initiated for the current or future months. Please select a past month."); + } + + String salaryStatus = "Initiated"; + + boolean checkexist = nulmService.checkSalaryDetails_park(enrollmentId, month, year); + + System.out.println("checkexist: " + checkexist); + + if (!checkexist) { + // Call the service method to insert the salary details + int rowsAffected = nulmService.addSalaryDetails_park(totalDaysPresent, totalDaysOd, totalDaysSalary, + totalDaysAbsent, month, year, salaryAmount, salaryStatus, enrollmentId, groupId, wageId, + inchargeID); + if (rowsAffected <= 0) { + return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR) + .body("Failed to add salary details for enrollment ID: " + enrollmentId); + } + } else { + int rowsAffected = nulmService.updateSalaryDetails_park(totalDaysPresent, totalDaysOd, totalDaysSalary, + totalDaysAbsent, month, year, salaryAmount, salaryStatus, enrollmentId, groupId, wageId, + inchargeID); + if (rowsAffected <= 0) { + return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR) + .body("Failed to update salary details for enrollment ID: " + enrollmentId); + } + } + } + return ResponseEntity.status(HttpStatus.CREATED) + .body("Salary details added successfully for all selected entries."); + } catch (Exception e) { + e.printStackTrace(); // Log the exception for debugging + return ResponseEntity.status(HttpStatus.BAD_REQUEST) + .body("Invalid request data: " + e.getMessage()); + } + } + + + + /// + + // Helper method to check if the month is future or current private boolean isFutureOrCurrentMonth(String month, int year) { @@ -696,6 +787,41 @@ 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; + } + + + @PostMapping("/update-salary-status-park") + public ResponseEntity updateSalaryStatus_Park( + @RequestParam List enrollmentIds, + @RequestParam String month, + @RequestParam int year) { + System.out.println("Enrollment IDs: " + enrollmentIds); + System.out.println("Month: " + month); + System.out.println("Year: " + year); + nulmService.updateSalaryStatusToApproved_Park(enrollmentIds, month, year); + return ResponseEntity.ok("Salary status updated to 'Approved' for the provided enrollments."); + } + + //// /*************** API For Mobile Application *********************************/ /* @@ -774,6 +900,59 @@ 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, + @RequestParam(value = "year", required = false) Integer year, + @RequestParam(value = "incharge_id", required = false) Integer inchargeId, + @RequestParam(value = "type", required = false) String type) { + + try { + + 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); + } + // If no data is found, return a NOT FOUND response total_days_salary, + // total_salary and total_days_absent + if (attendanceWithSalary.isEmpty()) { + return ResponseEntity.status(404) + .body(List.of(Map.of("error", "No attendance records found for the specified parameters."))); + } + + for (Map aa : attendanceWithSalary) { + long days = ((Number) aa.get("total_days")).longValue(); + long present = ((Number) aa.get("total_days_present")).longValue(); + long od = ((Number) aa.get("total_days_od")).longValue(); + long salaryPerDay = ((Number) aa.get("salary_per_day")).longValue(); + + long totalPresent = present + od; + long totalAbsent = days - totalPresent; + long totalSalary = totalPresent * salaryPerDay; + + aa.put("total_salary", totalSalary); + aa.put("total_days_absent", totalAbsent); + aa.put("total_days_salary", totalPresent); + } + + // Return the data in the response + return ResponseEntity.ok(attendanceWithSalary); + } catch (Exception ex) { + // Return a 500 Internal Server Error with the error message + return ResponseEntity.status(500).body( + List.of(Map.of("error", "An error occurred while fetching attendance data: " + ex.getMessage()))); + } + } + + + //// @PostMapping("/salaryDetailInitiate") public ResponseEntity addInitiatedSalaryDetails( @@ -821,6 +1000,62 @@ 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()); +// } +// } + + + //// + + + // @GetMapping("/filtered-details") // public List> getFilteredSalaryDetails( 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 ef2b9f42..fe852d98 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 @@ -120,6 +120,8 @@ public class NulmController { 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 @@ -134,6 +136,38 @@ public class NulmController { 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) { + + String LoginUserId = LoginUserInfo.getLoginUserId(); + model.addAttribute("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_park(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); + + return "modules/nulm/salary-approve-park"; + } + + + //// + + + @GetMapping("/salary-report") public String viewSalaryReport( @RequestParam(required = false) String month, @@ -159,6 +193,34 @@ public class NulmController { return "modules/nulm/salary-report"; // Returns the view 'salary-report' } + //// + + @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' + } + + //// @GetMapping("/salary-zonereport") public String viewZoneWiseReport( 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 dd7e9907..f3a1a369 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 @@ -478,6 +478,24 @@ 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 List> getAttendanceWithSalary(String month, Integer year) { StringBuilder sql = new StringBuilder("SELECT " + @@ -887,6 +905,94 @@ 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, + String loginId) { + + // Retrieve zone access for the user + String ZoneWhare = ""; + 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()); + */ + // Extract the zones from getAccess + List zones = new ArrayList(); + + if (getAccess != null) { + 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()) { + * String zoneList = zones.stream() + * .map(zone -> "'" + zone + "'") + * .collect(Collectors.joining(", ")); + * ZoneWhare = " AND en.zone IN ("+zoneList+")"; + * } + * else { + * ZoneWhare = " AND en.zone IN (0)"; + * } + */ + // If the user has zone access, add it to the WHERE clause + // String ZoneWhare = ""; + if (zones != null && !zones.isEmpty()) { + StringBuilder zoneListBuilder = new StringBuilder(); + for (int i = 0; i < zones.size(); i++) { + zoneListBuilder.append("'").append(zones.get(i)).append("'"); + if (i < zones.size() - 1) { + zoneListBuilder.append(", "); + } + } + ZoneWhare = " AND en.zone IN (" + zoneListBuilder.toString() + ")"; + } else { + ZoneWhare = " AND en.zone IN (0)"; + } + + String sql = "select en.emp_id, en.name, en.incharge_name, en.designation, en.incharge_designation, sk.group_name, s.total_days_present, s.total_days_od, " + + "s.total_days_absent, s.total_days_salary, s.month as imonth,s.year as iyear, s.salary_status, s.salary_amount as total_salary, " + + "DAY(LAST_DAY(STR_TO_DATE(CONCAT(s.year, '-', s.month, '-01'), '%Y-%M-%d'))) AS total_days from salary_details_park s " + + "left join enrollment_table en on s.enrollment_id = en.enrollment_id " + + "left join suyaudavi_kuzhu sk on s.group_id = sk.group_id " + + "where s.month = ? and s.year =? " + + "AND (s.salary_status = 'Initiated' OR s.salary_status = 'Approved') " + + (salaryStatus != null && !salaryStatus.isEmpty() ? "AND s.salary_status = ? " : "") + + (groupName != null && !groupName.isEmpty() ? "AND sk.group_name = ? " : "") + + ZoneWhare; + + // Prepare the query parameters based on provided inputs + List params = new ArrayList<>(); + params.add(month); + params.add(year); + if (salaryStatus != null && !salaryStatus.isEmpty()) { + params.add(salaryStatus); + } + if (groupName != null && !groupName.isEmpty()) { + params.add(groupName); + } + + List> results = jdbcTemplate.queryForList(sql.toString(), params.toArray()); + return results; + } + + + /// + + + /* * public List> getSalaryReport(String month, Integer year, * String salaryStatus, String groupName) { @@ -1334,6 +1440,46 @@ 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 = ?"; + + List results = jdbcTemplate.queryForList(sql, Integer.class, enrollmentId, month, year); + return !results.isEmpty(); + + } + + 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, int inchargeID) { + 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, incharge_id) " + + "VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"; + + 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, + String salaryStatus, int enrollmentId, int groupId, + int wageId, int inchargeID) { + String sql = "update salary_details_park set total_days_present =?, total_days_od=?, total_days_salary = ? , total_days_absent = ?, month = ?, year = ?, " + + "salary_amount = ?, salary_status = ?, enrollment_id = ?, group_id= ?, wage_id= ?, incharge_id = ? where enrollment_id =? and month = ? and year = ? "; + + 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) { @@ -1368,7 +1514,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 (? IS NULL OR e.incharge_name = ?) "+ + "AND e.emp_type = 'NULM' "; if (month != null && !month.isEmpty()) { sql += "AND MONTHNAME(COALESCE(a.indatetime, a.leavedatetime, a.oddatetime)) = ? "; @@ -1419,6 +1566,97 @@ public class NulmService { return jdbcTemplate.queryForList(sql, params.toArray()); } + + + /// + + public List> getAttendanceWithInitiatedSalary_Park( + int inchargeId, String month, String year, String inchargeName, List enrollmentIds) { + + String sql = "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, " + + "(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, " + + "COUNT(DISTINCT CASE WHEN a.indatetime IS NULL THEN DATE(a.oddatetime) END) AS total_days_od, " + + "COUNT(DISTINCT DATE(a.indatetime)) + COUNT(DISTINCT CASE WHEN a.indatetime IS NULL THEN DATE(a.oddatetime) END) AS total_days_salary, " + + + "((COUNT(DISTINCT DATE(a.indatetime)) + COUNT(DISTINCT CASE WHEN a.indatetime IS NULL THEN DATE(a.oddatetime) END)) * " + + + "(SELECT salary_per_day FROM staff_wages WHERE isactive = 1 ORDER BY wage_id DESC LIMIT 1)) AS total_salary, " + + + "(MAX(DAY(LAST_DAY(COALESCE(a.indatetime, a.leavedatetime, a.oddatetime)))) - " + + "(COUNT(DISTINCT DATE(a.indatetime)) + COUNT(DISTINCT CASE WHEN a.indatetime IS NULL THEN DATE(a.oddatetime) END))) AS total_days_absent, " + + + "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 (? IS NULL OR e.incharge_id = ?) " + + "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)) = ? "; + } + if (year != null && !year.isEmpty()) { + sql += "AND YEAR(COALESCE(a.indatetime, a.leavedatetime, a.oddatetime)) = ? "; + } + + // Assuming enrollmentIds is a List or List + StringBuilder placeholders = new StringBuilder(); + for (int i = 0; i < enrollmentIds.size(); i++) { + placeholders.append("?"); + if (i < enrollmentIds.size() - 1) { + placeholders.append(", "); + } + } + String inClause = placeholders.toString() + ") "; + + sql += "AND IFNULL(s.salary_status, '') IN ('Initiated', 'Approved') " + + "AND e.enrollment_id IN (" + + inClause + + "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"; + + List params = new ArrayList<>(); + params.add(inchargeId); + params.add(inchargeId); + params.add(inchargeName); + params.add(inchargeName); + + if (month != null && !month.isEmpty()) { + params.add(month); + } + if (year != null && !year.isEmpty()) { + params.add(year); + } + + params.addAll(enrollmentIds); + + System.out.println("SQL = " + sql); + System.out.println("Parameter = " + params); + + return jdbcTemplate.queryForList(sql, params.toArray()); + } + + //// @Transactional public void updateSalaryStatusToApproved(List enrollmentIds, String month, int year) { @@ -1429,6 +1667,22 @@ 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 = ?"; + + for (Integer enrollmentId : enrollmentIds) { + // Pass the individual enrollmentId instead of the entire list + jdbcTemplate.update(sql, enrollmentId, month, year); + } + } + + //// + + /* * public List> getFilteredSalaryDetails(String month, * Integer year, String salaryStatus) { @@ -1588,7 +1842,7 @@ public class NulmService { "e.department " + // Select the department as well "FROM enrollment_table e " + "JOIN salary_details sd ON e.enrollment_id = sd.enrollment_id " + - "WHERE 1=1 "); // Placeholder for dynamic conditions + "WHERE 1=1 AND e.emp_type = 'NULM' "); // Placeholder for dynamic conditions // Add filters for month, year, salary status, and department if (month != null && !month.isEmpty()) { @@ -1700,17 +1954,155 @@ 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"); + if (zoneObj != null) { + zones.add(zoneObj.toString()); + } + } + + // 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(", "); + } + } + sql.append(" AND e.zone IN (").append(zoneList.toString()).append(")"); + } 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 { + 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); + } + } + + return result; + } 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) { @@ -1749,7 +2141,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) "); + "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 = ?) "); @@ -1797,6 +2189,135 @@ 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) + { + List> results = new ArrayList<>(); + if(type.equalsIgnoreCase("1")){ + results = getAttendanceWithSalaryByInchargeId(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; + } + + + //// + + public List> getZoneWiseReport(String month, Integer year, String salaryStatus, String groupName, String zone, String division) { @@ -2256,4 +2777,26 @@ 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 " + + " CONCAT_WS( " + + " ',', " + + " GROUP_CONCAT(DISTINCT " + + " TRIM(SUBSTRING_INDEX(additional_id, ',', 1)) " + + " ), " + + " incharge_id " + + " ) AS final_ids " + + " FROM gcc_nulm.additional_incharge " + + " WHERE incharge_id = ? " + + " AND is_active = 1 " + + " AND is_delete = 0 " + + " GROUP BY incharge_id "; + + String result = jdbcTemplate.queryForObject(sql, String.class, inchargeId); + + return result; + } } \ No newline at end of file diff --git a/gcc_officer_portal/src/main/resources/application.properties b/gcc_officer_portal/src/main/resources/application.properties index e4b93c87..65d10c34 100644 --- a/gcc_officer_portal/src/main/resources/application.properties +++ b/gcc_officer_portal/src/main/resources/application.properties @@ -1,5 +1,5 @@ -# spring.profiles.active=local -spring.profiles.active=production + spring.profiles.active=local +#spring.profiles.active=production #For Server production #assets.base-url=/gcc/assets/ #For local test diff --git a/gcc_officer_portal/src/main/resources/templates/modules/nulm/salary-approve-park.html b/gcc_officer_portal/src/main/resources/templates/modules/nulm/salary-approve-park.html new file mode 100644 index 00000000..a6879b9d --- /dev/null +++ b/gcc_officer_portal/src/main/resources/templates/modules/nulm/salary-approve-park.html @@ -0,0 +1,394 @@ + + + + + + + + +
+
+
+
+
+
+ + +
+ +
+
+ + +
+ +
+ + +
+ +
+ + +
+ +
+ +
+
+ +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
S.NoIncharge NameTotal Staff CountSalary ProcessedTotal Salary AmountSalary StatusAction
0 + + + + Approved + +
S.NoIncharge NameTotal Staff CountSalary ProcessedTotal Salary AmountSalary StatusAction
+
+
+ + + + + +
+ +
+
+
+ + + + + + +
+
+ + \ No newline at end of file diff --git a/gcc_officer_portal/src/main/resources/templates/modules/nulm/salary-approve.html b/gcc_officer_portal/src/main/resources/templates/modules/nulm/salary-approve.html index ea39b23b..10e3ac98 100644 --- a/gcc_officer_portal/src/main/resources/templates/modules/nulm/salary-approve.html +++ b/gcc_officer_portal/src/main/resources/templates/modules/nulm/salary-approve.html @@ -183,9 +183,11 @@ -
+ + +
diff --git a/gcc_officer_portal/src/main/resources/templates/modules/nulm/salary-report-park.html b/gcc_officer_portal/src/main/resources/templates/modules/nulm/salary-report-park.html new file mode 100644 index 00000000..b72c07c9 --- /dev/null +++ b/gcc_officer_portal/src/main/resources/templates/modules/nulm/salary-report-park.html @@ -0,0 +1,274 @@ + + + + + + + +
+
+ +
+
+
+
+ + +
+ + +
+
+ + +
+ +
+ + +
+ +
+ + +
+ +
+ + +
+ + + +
+ + +
+
+ + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
S.NoEmployee IdEmployee NameEmployee DesignationIncharge NameIncharge DesignationSelf Help GroupDays PresentODTotal Days for SalaryTotal DaysTotal Days AbsentMonthYearSalary AmountSalary Status
1
S.NoEmployee IdEmployee NameEmployee DesignationIncharge NameIncharge DesignationSelf Help GroupDays PresentODTotal Days for SalaryTotal DaysTotal Days AbsentMonthYearSalary AmountSalary Status
+
+ +
+
+ +
+
+
+ +
+ + + + + \ No newline at end of file