Browse Source

Nulm and vehicle service updated

main
kanimozhi 8 months ago
parent
commit
4584c1bff0
  1. 742
      gcc_officer_portal/src/main/java/in/gov/chennaicorporation/gccoffice/nulm/controller/NulmAPIController.java
  2. 3839
      gcc_officer_portal/src/main/java/in/gov/chennaicorporation/gccoffice/nulm/service/NulmService.java
  3. 1205
      gcc_officer_portal/src/main/java/in/gov/chennaicorporation/gccoffice/vtrack/service/VehicleService.java
  4. 4
      gcc_officer_portal/src/main/resources/application.properties

742
gcc_officer_portal/src/main/java/in/gov/chennaicorporation/gccoffice/nulm/controller/NulmAPIController.java

@ -38,28 +38,27 @@ import in.gov.chennaicorporation.gccoffice.nulm.service.NulmService;
@RestController("nulmAPI")
public class NulmAPIController {
private final Environment environment;
private final Environment environment;
@Autowired
private NulmService nulmService;
@Autowired
private NulmService nulmService;
@Autowired
@Autowired
private JdbcTemplate nulmJdbcTemplate;
@Autowired
public NulmAPIController(NulmService nulmService,JdbcTemplate nulmJdbcTemplate,Environment environment) {
this.nulmService = nulmService;
this.nulmJdbcTemplate = nulmJdbcTemplate;
this.environment = environment;
}
@Autowired
public void setDataSource(@Qualifier("mysqlNulmDataSource") DataSource dataSource) {
this.nulmJdbcTemplate = new JdbcTemplate(dataSource);
}
@Autowired
public NulmAPIController(NulmService nulmService, JdbcTemplate nulmJdbcTemplate, Environment environment) {
this.nulmService = nulmService;
this.nulmJdbcTemplate = nulmJdbcTemplate;
this.environment = environment;
}
@Autowired
public void setDataSource(@Qualifier("mysqlNulmDataSource") DataSource dataSource) {
this.nulmJdbcTemplate = new JdbcTemplate(dataSource);
}
@GetMapping("/getYear")
@GetMapping("/getYear")
public ResponseEntity<List<Map<String, Object>>> getYear() {
List<Map<String, Object>> yearList = nulmService.getYearList();
return ResponseEntity.ok(yearList);
@ -67,7 +66,7 @@ public class NulmAPIController {
@GetMapping("/getMonth")
public ResponseEntity<List<Map<String, Object>>> getMonth(int year) {
//System.out.println("year: "+year);
// System.out.println("year: "+year);
List<Map<String, Object>> monthList = nulmService.getMonthList(year);
return ResponseEntity.ok(monthList);
}
@ -85,9 +84,8 @@ public class NulmAPIController {
return ResponseEntity.ok(divisionList);
}
@PostMapping("/saveGroup")
public ResponseEntity<String> saveSchemeGroup(@RequestBody Map<String, Object> payload) {
@PostMapping("/saveGroup")
public ResponseEntity<String> saveSchemeGroup(@RequestBody Map<String, Object> payload) {
try {
Map<String, Object> groupData = new HashMap<>(payload);
nulmService.saveSchemeGroup(groupData);
@ -96,24 +94,27 @@ public class NulmAPIController {
return ResponseEntity.status(500).body("Error saving Scheme Group: " + e.getMessage());
}
}
/*
@PostMapping("/saveOrder")
public ResponseEntity<String> saveOrderDetails(@RequestBody Map<String, Object> payload) {
try {
Map<String, Object> orderData = new HashMap<>(payload);
nulmService.saveOrderDetails(orderData);
return ResponseEntity.ok("Order saved successfully.");
} catch (IllegalArgumentException e) {
return ResponseEntity.badRequest().body("Invalid data: " + e.getMessage());
} catch (Exception e) {
return ResponseEntity.status(500).body("Error saving order: " + e.getMessage());
}
}
*/
/*
* @PostMapping("/saveOrder")
* public ResponseEntity<String> saveOrderDetails(@RequestBody Map<String,
* Object> payload) {
* try {
* Map<String, Object> orderData = new HashMap<>(payload);
* nulmService.saveOrderDetails(orderData);
* return ResponseEntity.ok("Order saved successfully.");
* } catch (IllegalArgumentException e) {
* return ResponseEntity.badRequest().body("Invalid data: " + e.getMessage());
* } catch (Exception e) {
* return ResponseEntity.status(500).body("Error saving order: " +
* e.getMessage());
* }
* }
*/
@PostMapping("/saveStaff")
public ResponseEntity<String> saveStaffDetails(@RequestBody Map<String, Object> payload) {
try {
nulmService.saveStaffDetails(payload);
nulmService.saveStaffDetails(payload);
return ResponseEntity.ok("Staff details saved successfully.");
} catch (IllegalArgumentException e) {
return ResponseEntity.badRequest().body("Error: " + e.getMessage());
@ -142,9 +143,11 @@ public class NulmAPIController {
if (orderDetails != null) {
// Step 2: Build the SQL for updating enrollments with dynamic IN clause
StringBuilder updateSql = new StringBuilder("UPDATE enrollment_table SET order_id = ?, appointed = 'Yes', facial_attendance = 'No', incharge_phoneno = ?, designation = ?, appointed_date = CURRENT_DATE WHERE enrollment_id IN (");
StringBuilder updateSql = new StringBuilder(
"UPDATE enrollment_table SET order_id = ?, appointed = 'Yes', facial_attendance = 'No', incharge_phoneno = ?, designation = ?, appointed_date = CURRENT_DATE WHERE enrollment_id IN (");
// Add placeholders for the IN clause based on the size of the enrollmentIds list
// Add placeholders for the IN clause based on the size of the enrollmentIds
// list
for (int i = 0; i < enrollmentIds.size(); i++) {
updateSql.append("?");
if (i < enrollmentIds.size() - 1) {
@ -153,7 +156,8 @@ public class NulmAPIController {
}
updateSql.append(")");
// Combine the orderId, inchargePhoneno, designation, and the list of enrollmentIds
// Combine the orderId, inchargePhoneno, designation, and the list of
// enrollmentIds
List<Object> parameters = new ArrayList<>();
parameters.add(orderId);
parameters.add(inchargePhoneno);
@ -166,7 +170,8 @@ public class NulmAPIController {
return new ResponseEntity<>("Order assigned to enrollments and appointed successfully.", HttpStatus.OK);
} catch (DataAccessException e) {
// Handle any data access exceptions
return new ResponseEntity<>("Error updating enrollments: " + e.getMessage(), HttpStatus.INTERNAL_SERVER_ERROR);
return new ResponseEntity<>("Error updating enrollments: " + e.getMessage(),
HttpStatus.INTERNAL_SERVER_ERROR);
}
}
@ -191,9 +196,11 @@ public class NulmAPIController {
if (orderDetails != null) {
// Step 2: Build the SQL for updating enrollments with dynamic IN clause
StringBuilder updateSql = new StringBuilder("UPDATE enrollment_table SET appointed = 'Drop', dropout = 'Yes', dropout_date = CURRENT_DATE WHERE enrollment_id IN (");
StringBuilder updateSql = new StringBuilder(
"UPDATE enrollment_table SET appointed = 'Drop', dropout = 'Yes', dropout_date = CURRENT_DATE WHERE enrollment_id IN (");
// Add placeholders for the IN clause based on the size of the enrollmentIds list
// Add placeholders for the IN clause based on the size of the enrollmentIds
// list
for (int i = 0; i < enrollmentIds.size(); i++) {
updateSql.append("?");
if (i < enrollmentIds.size() - 1) {
@ -210,13 +217,15 @@ public class NulmAPIController {
try {
int rowsAffected = nulmJdbcTemplate.update(updateSql.toString(), parameters.toArray());
if (rowsAffected > 0) {
return new ResponseEntity<>("Order assigned to enrollments has been Dropout successfully.", HttpStatus.OK);
return new ResponseEntity<>("Order assigned to enrollments has been Dropout successfully.",
HttpStatus.OK);
} else {
return new ResponseEntity<>("No matching records found to update.", HttpStatus.NOT_FOUND);
}
} catch (DataAccessException e) {
// Handle any data access exceptions
return new ResponseEntity<>("Error updating enrollments: " + e.getMessage(), HttpStatus.INTERNAL_SERVER_ERROR);
return new ResponseEntity<>("Error updating enrollments: " + e.getMessage(),
HttpStatus.INTERNAL_SERVER_ERROR);
}
}
@ -226,11 +235,11 @@ public class NulmAPIController {
@GetMapping("/getAllSchemeGroupNames")
public ResponseEntity<List<Map<String, Object>>> getAllSchemeGroupNames() {
try {
List<Map<String,Object>> schemeGroupNames = nulmService.getAllSchemeGroupNames();
List<Map<String, Object>> schemeGroupNames = nulmService.getAllSchemeGroupNames();
return ResponseEntity.ok(schemeGroupNames);
} catch (Exception e) {
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR)
.body(Collections.emptyList());
.body(Collections.emptyList());
}
}
@ -241,7 +250,7 @@ public class NulmAPIController {
return ResponseEntity.ok(schemeGroupNames);
} catch (Exception e) {
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR)
.body(Collections.emptyList());
.body(Collections.emptyList());
}
}
@ -255,10 +264,10 @@ public class NulmAPIController {
}
}
///////get all list of orders////////////////////////////
/////// get all list of orders////////////////////////////
@GetMapping("/getAllOrders")
public ResponseEntity<List<Map<String, Object>>> getAllOrders() {
try {
try {
List<Map<String, Object>> groups = nulmService.getAllOrders();
return ResponseEntity.ok(groups);
} catch (Exception e) {
@ -273,7 +282,7 @@ public class NulmAPIController {
return ResponseEntity.ok(schemeGroupNames);
} catch (Exception e) {
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR)
.body(Collections.emptyList());
.body(Collections.emptyList());
}
}
@ -292,7 +301,8 @@ public class NulmAPIController {
return ResponseEntity.ok(counts);
} catch (Exception e) {
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(null); // You can also return the error message
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(null); // You can also return the error
// message
}
}
@ -303,7 +313,8 @@ public class NulmAPIController {
if (result > 0) {
return ResponseEntity.ok("Employee marked as absent successfully.");
} else {
return ResponseEntity.status(304).body("No update made. Employee may already be marked as absent or has attended.");
return ResponseEntity.status(304)
.body("No update made. Employee may already be marked as absent or has attended.");
}
}
@ -334,7 +345,6 @@ public class NulmAPIController {
}
}
@GetMapping("/getAllOrderDetails")
public ResponseEntity<List<Map<String, Object>>> getAllOrderDetails() {
try {
@ -351,7 +361,6 @@ public class NulmAPIController {
return ResponseEntity.ok(counts);
}
@GetMapping("/dropOutCounts")
public ResponseEntity<Map<String, Integer>> getDropCounts(@RequestParam int orderId) {
Map<String, Integer> counts = nulmService.getDropCounts(orderId);
@ -377,7 +386,8 @@ public class NulmAPIController {
}
@GetMapping("/getEnrollmentdeatilsByID/{enrollmentId}")
public ResponseEntity<List<Map<String, Object>>> getEnrollmentsById(@PathVariable("enrollmentId") int enrollmentId) {
public ResponseEntity<List<Map<String, Object>>> getEnrollmentsById(
@PathVariable("enrollmentId") int enrollmentId) {
List<Map<String, Object>> enrollments = nulmService.getEnrollmentsById(enrollmentId);
if (enrollments.isEmpty()) {
@ -405,7 +415,7 @@ public class NulmAPIController {
@RequestParam String dateOfBirth,
@RequestParam String gender,
@RequestParam int groupId, // New parameter
@RequestParam int orderId // New parameter
@RequestParam int orderId // New parameter
) {
int rowsAffected = nulmService.updateEnrollment(id, dateOfBirth, gender, groupId, orderId);
@ -416,15 +426,15 @@ public class NulmAPIController {
}
}
@PostMapping("/saveOrder")
@PostMapping("/saveOrder")
public ResponseEntity<String> saveOrderDetails(@RequestParam String order_number,
@RequestParam @DateTimeFormat(pattern = "yyyy-MM-dd") Date order_date,
@RequestParam int no_of_staffs,
@RequestParam String order_description,
@RequestParam MultipartFile ordercopyurl,
@RequestParam String order_generated_by,
@RequestParam String category,
@RequestParam @DateTimeFormat(pattern = "yyyy-MM-dd") Date validity_date) {
@RequestParam @DateTimeFormat(pattern = "yyyy-MM-dd") Date order_date,
@RequestParam int no_of_staffs,
@RequestParam String order_description,
@RequestParam MultipartFile ordercopyurl,
@RequestParam String order_generated_by,
@RequestParam String category,
@RequestParam @DateTimeFormat(pattern = "yyyy-MM-dd") Date validity_date) {
String order_copy_url = "";
try {
// Fetch the upload directory and folder name from environment
@ -447,15 +457,14 @@ public class NulmAPIController {
// Save the order details using the service method
String savedOrderNumber = nulmService.saveOrderDetails(
order_number,
order_date,
no_of_staffs,
order_description,
order_copy_url,
order_generated_by,
category,
validity_date
);
order_number,
order_date,
no_of_staffs,
order_description,
order_copy_url,
order_generated_by,
category,
validity_date);
return ResponseEntity.ok("Order saved successfully with order number: " + savedOrderNumber);
@ -464,199 +473,263 @@ public class NulmAPIController {
return ResponseEntity.status(500).body("Error saving order: " + e.getMessage());
}
}
/*
@GetMapping("/staffInititeadList")
public ResponseEntity<List<Map<String, Object>>> getAttendanceWithInitiatedSalaryByGroupId(@RequestParam("inchargeName") String inchargeName,
@RequestParam("month") String month) {
List<Map<String, Object>> staffList = nulmService.getAttendanceWithInitiatedSalary(inchargeName, month);
return ResponseEntity.ok(staffList);
}
@GetMapping("/staffInititeadList")
public ResponseEntity<List<Map<String, Object>>> getAttendanceWithInitiatedSalaryByGroupId(
@RequestParam(value = "inchargeId", required = false) String inchargeId,
@RequestParam(value = "month", required = false) String month,
@RequestParam(value = "inchargeName", required = false) String inchargeName,
@RequestParam(value = "zone", required = false) Integer zone) {
List<Map<String, Object>> staffList = nulmService.getAttendanceWithInitiatedSalary(inchargeId, month, inchargeName, zone);
return ResponseEntity.ok(staffList);
}
*/
@GetMapping("/staffInititeadList")
/*
* @GetMapping("/staffInititeadList")
* public ResponseEntity<List<Map<String, Object>>>
* getAttendanceWithInitiatedSalaryByGroupId(@RequestParam("inchargeName")
* String inchargeName,
*
* @RequestParam("month") String month) {
* List<Map<String, Object>> staffList =
* nulmService.getAttendanceWithInitiatedSalary(inchargeName, month);
* return ResponseEntity.ok(staffList);
* }
*
* @GetMapping("/staffInititeadList")
* public ResponseEntity<List<Map<String, Object>>>
* getAttendanceWithInitiatedSalaryByGroupId(
*
* @RequestParam(value = "inchargeId", required = false) String inchargeId,
*
* @RequestParam(value = "month", required = false) String month,
*
* @RequestParam(value = "inchargeName", required = false) String inchargeName,
*
* @RequestParam(value = "zone", required = false) Integer zone) {
*
* List<Map<String, Object>> staffList =
* nulmService.getAttendanceWithInitiatedSalary(inchargeId, month, inchargeName,
* zone);
* return ResponseEntity.ok(staffList);
* }
*/
@GetMapping("/staffInititeadList")
public ResponseEntity<List<Map<String, Object>>> getAttendanceWithInitiatedSalaryByGroupId(
@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 = "enrollmentIds", required = false) List<Integer> enrollmentIds) {
@RequestParam(value = "enrollmentIds", required = false) List<Integer> enrollmentIds) {
List<Map<String, Object>> staffList = nulmService.getAttendanceWithInitiatedSalary(inchargeId, month, year, inchargeName, enrollmentIds);
List<Map<String, Object>> staffList = nulmService.getAttendanceWithInitiatedSalary(inchargeId, month, year,
inchargeName, enrollmentIds);
return ResponseEntity.ok(staffList);
}
/*
@PostMapping("/salaryDetailUpdate")
public ResponseEntity<String> addSalaryDetails(@RequestBody List<Map<String, Object>> requestList) {
System.out.println("Received POST request with data: " + requestList);
try {
for (Map<String, Object> request : requestList) {
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());
// 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";
// Call the service method to insert the salary details
int rowsAffected = nulmService.addSalaryDetails(totalDaysPresent, totalDaysOd, totalDaysSalary, 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.");
} catch (Exception e) {
e.printStackTrace(); // Log the exception for debugging
return ResponseEntity.status(HttpStatus.BAD_REQUEST)
.body("Invalid request data: " + e.getMessage());
}
}
*/
@PostMapping("/salaryDetailUpdate")
public ResponseEntity<String> addSalaryDetails(@RequestBody List<Map<String, Object>> requestList) {
System.out.println("Received POST request with data: " + requestList);
try {
for (Map<String, Object> 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(enrollmentId, month, year);
System.out.println("checkexist: " + checkexist);
if (!checkexist) {
// Call the service method to insert the salary details
int rowsAffected = nulmService.addSalaryDetails(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(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) {
// Get the current month and year
LocalDate currentDate = LocalDate.now();
Month currentMonth = currentDate.getMonth();
int currentYear = currentDate.getYear();
// Convert the string month from the request to Month enum
Month requestMonth = Month.valueOf(month.toUpperCase()); // Ensure that month is passed in capitalized format like "JANUARY", "FEBRUARY", etc.
// Compare the request month and year with the current date
if (year > currentYear) {
return true; // Future year
} else if (year == currentYear && requestMonth.compareTo(currentMonth) >= 0) {
return true; // Current or future month in the current year
}
return false; // Past month
}
// @PostMapping("/salaryDetailUpdate")
// public ResponseEntity<String> addSalaryDetails(@RequestBody List<Map<String, Object>> requestList) {
// System.out.println("Received POST request with data: " + requestList);
// try {
// for (Map<String, Object> request : requestList) {
// 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());
//
// String salaryStatus = "Initiated";
//
// // Call the service method to insert the salary details
// int rowsAffected = nulmService.addSalaryDetails(totalDaysPresent, totalDaysOd, totalDaysSalary, 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.");
// } catch (Exception e) {
// e.printStackTrace(); // Log the exception for debugging
// return ResponseEntity.status(HttpStatus.BAD_REQUEST).body("Invalid request data: " + e.getMessage());
// }
// }
@PostMapping("/update-salary-status")
/*
* @PostMapping("/salaryDetailUpdate")
* public ResponseEntity<String> addSalaryDetails(@RequestBody List<Map<String,
* Object>> requestList) {
* System.out.println("Received POST request with data: " + requestList);
* try {
* for (Map<String, Object> request : requestList) {
* 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());
*
* // 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";
*
* // Call the service method to insert the salary details
* int rowsAffected = nulmService.addSalaryDetails(totalDaysPresent,
* totalDaysOd, totalDaysSalary, 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.");
* } catch (Exception e) {
* e.printStackTrace(); // Log the exception for debugging
* return ResponseEntity.status(HttpStatus.BAD_REQUEST)
* .body("Invalid request data: " + e.getMessage());
* }
* }
*/
@PostMapping("/salaryDetailUpdate")
public ResponseEntity<String> addSalaryDetails(@RequestBody List<Map<String, Object>> requestList) {
System.out.println("Received POST request with data: " + requestList);
try {
for (Map<String, Object> 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(enrollmentId, month, year);
System.out.println("checkexist: " + checkexist);
if (!checkexist) {
// Call the service method to insert the salary details
int rowsAffected = nulmService.addSalaryDetails(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(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) {
// Get the current month and year
LocalDate currentDate = LocalDate.now();
Month currentMonth = currentDate.getMonth();
int currentYear = currentDate.getYear();
// Convert the string month from the request to Month enum
Month requestMonth = Month.valueOf(month.toUpperCase()); // Ensure that month is passed in capitalized format
// like "JANUARY", "FEBRUARY", etc.
// Compare the request month and year with the current date
if (year > currentYear) {
return true; // Future year
} else if (year == currentYear && requestMonth.compareTo(currentMonth) >= 0) {
return true; // Current or future month in the current year
}
return false; // Past month
}
// @PostMapping("/salaryDetailUpdate")
// public ResponseEntity<String> addSalaryDetails(@RequestBody List<Map<String,
// Object>> requestList) {
// System.out.println("Received POST request with data: " + requestList);
// try {
// for (Map<String, Object> request : requestList) {
// 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());
//
// String salaryStatus = "Initiated";
//
// // Call the service method to insert the salary details
// int rowsAffected = nulmService.addSalaryDetails(totalDaysPresent,
// totalDaysOd, totalDaysSalary, 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.");
// } catch (Exception e) {
// e.printStackTrace(); // Log the exception for debugging
// return ResponseEntity.status(HttpStatus.BAD_REQUEST).body("Invalid request
// data: " + e.getMessage());
// }
// }
@PostMapping("/update-salary-status")
public ResponseEntity<String> updateSalaryStatus(
@RequestParam List<Integer> enrollmentIds,
@RequestParam String month,
@RequestParam int year) {
System.out.println("Enrollment IDs: " + enrollmentIds);
System.out.println("Month: " + month);
System.out.println("Year: " + year);
System.out.println("Enrollment IDs: " + enrollmentIds);
System.out.println("Month: " + month);
System.out.println("Year: " + year);
nulmService.updateSalaryStatusToApproved(enrollmentIds, month, year);
return ResponseEntity.ok("Salary status updated to 'Approved' for the provided enrollments.");
}
/***************API For Mobile Application*********************************/
/*
/*************** API For Mobile Application *********************************/
/*
* @GetMapping("/attendanceWithSalary")
* public ResponseEntity<List<Map<String, Object>>>
* getAttendanceWithSalaryByInchargeId(
*
* @RequestParam(value = "month", required = false) String month,
*
* @RequestParam(value = "year", required = false) Integer year,
*
* @RequestParam(value = "incharge_id", required = false) Integer inchargeId) {
*
* try {
* // Call the service method to fetch the data
* List<Map<String, Object>> attendanceWithSalary =
* nulmService.getAttendanceWithSalaryByInchargeId(month, year, inchargeId);
*
* // If no data is found, return a NOT FOUND response
* if (attendanceWithSalary.isEmpty()) {
* return ResponseEntity.status(404).body(List.of(Map.of("error",
* "No attendance records found for the specified parameters.")));
* }
*
* // 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())));
* }
* }
*/
@GetMapping("/attendanceWithSalary")
public ResponseEntity<List<Map<String, Object>>> getAttendanceWithSalaryByInchargeId(
@RequestParam(value = "month", required = false) String month,
@ -664,115 +737,98 @@ public class NulmAPIController {
@RequestParam(value = "incharge_id", required = false) Integer inchargeId) {
try {
// Call the service method to fetch the data
List<Map<String, Object>> attendanceWithSalary = nulmService.getAttendanceWithSalaryByInchargeId(month, year, inchargeId);
// If no data is found, return a NOT FOUND response
//List<Map<String, Object>> attendanceWithSalary = new ArrayList<>();
//Integer check = nulmService.checkInchargeID(inchargeId);
// if (check == 1) {
// Call the service method to fetch the data
List<Map<String, Object>> 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()) {
return ResponseEntity.status(404).body(List.of(Map.of("error", "No attendance records found for the specified parameters.")));
return ResponseEntity.status(404)
.body(List.of(Map.of("error", "No attendance records found for the specified parameters.")));
}
// 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())));
}
}
*/
for (Map<String, Object> 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();
@GetMapping("/attendanceWithSalary")
public ResponseEntity<List<Map<String, Object>>> getAttendanceWithSalaryByInchargeId(
@RequestParam(value = "month", required = false) String month,
@RequestParam(value = "year", required = false) Integer year,
@RequestParam(value = "incharge_id", required = false) Integer inchargeId) {
long totalPresent = present + od;
long totalAbsent = days - totalPresent;
long totalSalary = totalPresent * salaryPerDay;
try {
// Call the service method to fetch the data
List<Map<String, Object>> 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()) {
return ResponseEntity.status(404).body(List.of(Map.of("error", "No attendance records found for the specified parameters.")));
aa.put("total_salary", totalSalary);
aa.put("total_days_absent", totalAbsent);
aa.put("total_days_salary", totalPresent);
}
for (Map<String, Object> 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())));
return ResponseEntity.status(500).body(
List.of(Map.of("error", "An error occurred while fetching attendance data: " + ex.getMessage())));
}
}
@PostMapping("/salaryDetailInitiate")
public ResponseEntity<String> addInitiatedSalaryDetails(
@RequestParam("total_days_present") List<Integer> totalDaysPresentList,
@RequestParam("total_days_od") List<Integer> totalDaysOdList,
@RequestParam("total_days_salary") List<Integer> totalDaysSalaryList,
@RequestParam("total_days_absent") List<Integer> totalDaysAbsentList,
@RequestParam("month") List<String> monthList,
@RequestParam("year") List<Integer> yearList,
@RequestParam("salary_amount") List<Integer> salaryAmountList,
@RequestParam("enrollment_id") List<Integer> enrollmentIdList,
@RequestParam("group_id") List<Integer> groupIdList,
@RequestParam("wage_id") List<Integer> 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(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.");
} 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<Map<String, Object>> getFilteredSalaryDetails(
// @RequestParam(required = false) String month,
// @RequestParam(required = false) Integer year,
// @RequestParam(required = false) String salaryStatus) {
//
// // Call the service method to get the filtered salary details
// return nulmService.getFilteredSalaryDetails(month, year, salaryStatus);
// }
@RequestParam("total_days_present") List<Integer> totalDaysPresentList,
@RequestParam("total_days_od") List<Integer> totalDaysOdList,
@RequestParam("total_days_salary") List<Integer> totalDaysSalaryList,
@RequestParam("total_days_absent") List<Integer> totalDaysAbsentList,
@RequestParam("month") List<String> monthList,
@RequestParam("year") List<Integer> yearList,
@RequestParam("salary_amount") List<Integer> salaryAmountList,
@RequestParam("enrollment_id") List<Integer> enrollmentIdList,
@RequestParam("group_id") List<Integer> groupIdList,
@RequestParam("wage_id") List<Integer> 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(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.");
} 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<Map<String, Object>> getFilteredSalaryDetails(
// @RequestParam(required = false) String month,
// @RequestParam(required = false) Integer year,
// @RequestParam(required = false) String salaryStatus) {
//
// // Call the service method to get the filtered salary details
// return nulmService.getFilteredSalaryDetails(month, year, salaryStatus);
// }
}

3839
gcc_officer_portal/src/main/java/in/gov/chennaicorporation/gccoffice/nulm/service/NulmService.java
File diff suppressed because it is too large
View File

1205
gcc_officer_portal/src/main/java/in/gov/chennaicorporation/gccoffice/vtrack/service/VehicleService.java
File diff suppressed because it is too large
View File

4
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

Loading…
Cancel
Save