|
|
@ -149,6 +149,7 @@ public class AdjustmentController { |
|
|
@RequestParam(value = "id", required = false) Integer id, |
|
|
@RequestParam(value = "id", required = false) Integer id, |
|
|
@RequestParam(value = "vend_name", required = false) String vendName, |
|
|
@RequestParam(value = "vend_name", required = false) String vendName, |
|
|
@RequestParam(value = "fin_year", required = false) String finYear, |
|
|
@RequestParam(value = "fin_year", required = false) String finYear, |
|
|
|
|
|
@RequestParam(value = "subject", required = false) String subject, |
|
|
@RequestParam(value = "adv_type_id", required = false) String advTypeId, |
|
|
@RequestParam(value = "adv_type_id", required = false) String advTypeId, |
|
|
@RequestParam(value = "fund_type_id", required = false) String fundTypeId, |
|
|
@RequestParam(value = "fund_type_id", required = false) String fundTypeId, |
|
|
@RequestParam(value = "bal_amt", required = false) Double balAmt, |
|
|
@RequestParam(value = "bal_amt", required = false) Double balAmt, |
|
|
@ -163,6 +164,10 @@ public class AdjustmentController { |
|
|
@RequestParam(value = "ejv_num_file_gen_date", required = false) String ejvNumFileGenDate, |
|
|
@RequestParam(value = "ejv_num_file_gen_date", required = false) String ejvNumFileGenDate, |
|
|
@RequestParam(value = "as_file_gen_date", required = false) String asFileGenDate, |
|
|
@RequestParam(value = "as_file_gen_date", required = false) String asFileGenDate, |
|
|
@RequestParam(value = "as_final_file_gen_date", required = false) String asFinalFileGenDate, |
|
|
@RequestParam(value = "as_final_file_gen_date", required = false) String asFinalFileGenDate, |
|
|
|
|
|
@RequestParam(value = "ac_code", required = false) String acCode, |
|
|
|
|
|
@RequestParam(value = "file_available_status", required = false) String fileAvailableStatus, |
|
|
|
|
|
@RequestParam(value = "rtgs_date", required = false) String rtgsDate, |
|
|
|
|
|
@RequestParam(value = "dc_completed_date", required = false) String dcCompletedDate, |
|
|
@RequestParam(value = "file", required = false) MultipartFile file, |
|
|
@RequestParam(value = "file", required = false) MultipartFile file, |
|
|
@RequestParam(value = "poFile", required = false) MultipartFile poFile, |
|
|
@RequestParam(value = "poFile", required = false) MultipartFile poFile, |
|
|
@RequestParam(value = "dcFile", required = false) MultipartFile dcFile, |
|
|
@RequestParam(value = "dcFile", required = false) MultipartFile dcFile, |
|
|
@ -202,24 +207,38 @@ public class AdjustmentController { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// Save files or keep existing |
|
|
// Save files or keep existing |
|
|
String filePath = saveFile(file, "file", uploadDir, existing != null ? (String) existing.get("file_path") : null); |
|
|
|
|
|
String poPath = saveFile(poFile, "po", uploadDir, existing != null ? (String) existing.get("po_file_path") : null); |
|
|
|
|
|
String dcPath = saveFile(dcFile, "dc", uploadDir, existing != null ? (String) existing.get("dc_file_path") : null); |
|
|
|
|
|
String irPath = saveFile(irFile, "ir", uploadDir, existing != null ? (String) existing.get("ir_file_path") : null); |
|
|
|
|
|
String srPath = saveFile(srFile, "sr", uploadDir, existing != null ? (String) existing.get("sr_filepath") : null); |
|
|
|
|
|
String piPath = saveFile(piFile, "pi", uploadDir, existing != null ? (String) existing.get("pi_file_path") : null); |
|
|
|
|
|
String fiPath = saveFile(fiFile, "fi", uploadDir, existing != null ? (String) existing.get("fi_file_path") : null); |
|
|
|
|
|
String tcPath = saveFile(tcFile, "tc", uploadDir, existing != null ? (String) existing.get("tc_file_path") : null); |
|
|
|
|
|
String rtgsPath = saveFile(rtgsFile, "rtgs", uploadDir, existing != null ? (String) existing.get("rtgs_file_path") : null); |
|
|
|
|
|
String ejvPath = saveFile(ejvFile, "ejv", uploadDir, existing != null ? (String) existing.get("ejv_num_file_path") : null); |
|
|
|
|
|
String asPath = saveFile(asFile, "as", uploadDir, existing != null ? (String) existing.get("as_file_path") : null); |
|
|
|
|
|
String asFinalPath = saveFile(asFinalFile, "as_final", uploadDir, existing != null ? (String) existing.get("as_final_file_path") : null); |
|
|
|
|
|
|
|
|
String filePath = saveFile(file, "file", fileDataNum, uploadDir, |
|
|
|
|
|
existing != null ? (String) existing.get("file_path") : null); |
|
|
|
|
|
String poPath = saveFile(poFile, "po", fileDataNum, uploadDir, |
|
|
|
|
|
existing != null ? (String) existing.get("po_file_path") : null); |
|
|
|
|
|
String dcPath = saveFile(dcFile, "dc", fileDataNum, uploadDir, |
|
|
|
|
|
existing != null ? (String) existing.get("dc_file_path") : null); |
|
|
|
|
|
String irPath = saveFile(irFile, "ir", fileDataNum, uploadDir, |
|
|
|
|
|
existing != null ? (String) existing.get("ir_file_path") : null); |
|
|
|
|
|
String srPath = saveFile(srFile, "sr", fileDataNum, uploadDir, |
|
|
|
|
|
existing != null ? (String) existing.get("sr_filepath") : null); |
|
|
|
|
|
String piPath = saveFile(piFile, "pi", fileDataNum, uploadDir, |
|
|
|
|
|
existing != null ? (String) existing.get("pi_file_path") : null); |
|
|
|
|
|
String fiPath = saveFile(fiFile, "fi", fileDataNum, uploadDir, |
|
|
|
|
|
existing != null ? (String) existing.get("fi_file_path") : null); |
|
|
|
|
|
String tcPath = saveFile(tcFile, "tc", fileDataNum, uploadDir, |
|
|
|
|
|
existing != null ? (String) existing.get("tc_file_path") : null); |
|
|
|
|
|
String rtgsPath = saveFile(rtgsFile, "rtgs", fileDataNum, uploadDir, |
|
|
|
|
|
existing != null ? (String) existing.get("rtgs_file_path") : null); |
|
|
|
|
|
String ejvPath = saveFile(ejvFile, "ejv", fileDataNum, uploadDir, |
|
|
|
|
|
existing != null ? (String) existing.get("ejv_num_file_path") : null); |
|
|
|
|
|
String asPath = saveFile(asFile, "as", fileDataNum, uploadDir, |
|
|
|
|
|
existing != null ? (String) existing.get("as_file_path") : null); |
|
|
|
|
|
String asFinalPath = saveFile(asFinalFile, "as_final", fileDataNum, uploadDir, |
|
|
|
|
|
existing != null ? (String) existing.get("as_final_file_path") : null); |
|
|
|
|
|
|
|
|
// Build data map |
|
|
// Build data map |
|
|
Map<String, Object> data = new HashMap<>(); |
|
|
Map<String, Object> data = new HashMap<>(); |
|
|
if (id != null) data.put("id", id); |
|
|
|
|
|
|
|
|
if (id != null) |
|
|
|
|
|
data.put("id", id); |
|
|
data.put("vend_name", vendName); |
|
|
data.put("vend_name", vendName); |
|
|
data.put("fin_year", finYear); |
|
|
data.put("fin_year", finYear); |
|
|
|
|
|
data.put("subject", subject); |
|
|
data.put("adv_type_id", advTypeId); |
|
|
data.put("adv_type_id", advTypeId); |
|
|
data.put("fund_type_id", fundTypeId); |
|
|
data.put("fund_type_id", fundTypeId); |
|
|
data.put("bal_amt", balAmt); |
|
|
data.put("bal_amt", balAmt); |
|
|
@ -234,6 +253,10 @@ public class AdjustmentController { |
|
|
data.put("ejv_num_file_gen_date", ejvNumFileGenDate); |
|
|
data.put("ejv_num_file_gen_date", ejvNumFileGenDate); |
|
|
data.put("as_file_gen_date", asFileGenDate); |
|
|
data.put("as_file_gen_date", asFileGenDate); |
|
|
data.put("as_final_file_gen_date", asFinalFileGenDate); |
|
|
data.put("as_final_file_gen_date", asFinalFileGenDate); |
|
|
|
|
|
data.put("ac_code", acCode); |
|
|
|
|
|
data.put("file_available_status", fileAvailableStatus); |
|
|
|
|
|
data.put("rtgs_date", rtgsDate); |
|
|
|
|
|
data.put("dc_completed_date", dcCompletedDate); |
|
|
|
|
|
|
|
|
// Paths |
|
|
// Paths |
|
|
data.put("file_path", filePath); |
|
|
data.put("file_path", filePath); |
|
|
@ -281,7 +304,8 @@ public class AdjustmentController { |
|
|
return response; |
|
|
return response; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
boolean deleted = adjustmentService.deleteAdjustmentFile(id, remarks != null ? remarks : "Deleted by user", username); |
|
|
|
|
|
|
|
|
boolean deleted = adjustmentService.deleteAdjustmentFile(id, remarks != null ? remarks : "Deleted by user", |
|
|
|
|
|
username); |
|
|
if (deleted) { |
|
|
if (deleted) { |
|
|
response.put("success", true); |
|
|
response.put("success", true); |
|
|
response.put("message", "Record deleted successfully."); |
|
|
response.put("message", "Record deleted successfully."); |
|
|
@ -293,15 +317,87 @@ public class AdjustmentController { |
|
|
return response; |
|
|
return response; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
private String saveFile(MultipartFile f, String prefix, File dir, String currentPath) throws Exception { |
|
|
|
|
|
|
|
|
@PostMapping("/api/update-ejv") |
|
|
|
|
|
@ResponseBody |
|
|
|
|
|
public Map<String, Object> updateEJV( |
|
|
|
|
|
@RequestParam("id") Integer id, |
|
|
|
|
|
@RequestParam("ejv_num") String ejvNum, |
|
|
|
|
|
@RequestParam(value = "ejvFile", required = false) MultipartFile ejvFile, |
|
|
|
|
|
HttpSession session) { |
|
|
|
|
|
|
|
|
|
|
|
Map<String, Object> response = new HashMap<>(); |
|
|
|
|
|
String username = (String) session.getAttribute("adj_usrName"); |
|
|
|
|
|
if (username == null) { |
|
|
|
|
|
response.put("success", false); |
|
|
|
|
|
response.put("error", "Unauthorized access. Please log in."); |
|
|
|
|
|
return response; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
try { |
|
|
|
|
|
Map<String, Object> existing = adjustmentService.getAdjustmentFileById(id); |
|
|
|
|
|
if (existing == null) { |
|
|
|
|
|
response.put("success", false); |
|
|
|
|
|
response.put("error", "Record not found."); |
|
|
|
|
|
return response; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
File uploadDir = new File(adjustmentUploadPathConfig).getAbsoluteFile(); |
|
|
|
|
|
if (!uploadDir.exists()) { |
|
|
|
|
|
uploadDir.mkdirs(); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
String fileDataNum = (String) existing.get("file_data_num"); |
|
|
|
|
|
String ejvPath = saveFile(ejvFile, "ejv", fileDataNum, uploadDir, |
|
|
|
|
|
existing != null ? (String) existing.get("ejv_num_file_path") : null); |
|
|
|
|
|
|
|
|
|
|
|
boolean updated = adjustmentService.updateEJV(id, ejvNum, ejvPath, username); |
|
|
|
|
|
if (updated) { |
|
|
|
|
|
response.put("success", true); |
|
|
|
|
|
response.put("message", "EJV details updated successfully."); |
|
|
|
|
|
} else { |
|
|
|
|
|
response.put("success", false); |
|
|
|
|
|
response.put("error", "Failed to update EJV details in database."); |
|
|
|
|
|
} |
|
|
|
|
|
} catch (Exception e) { |
|
|
|
|
|
response.put("success", false); |
|
|
|
|
|
response.put("error", "Error occurred: " + e.getMessage()); |
|
|
|
|
|
e.printStackTrace(); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return response; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private String saveFile(MultipartFile f, String category, String fileNum, File dir, String currentPath) |
|
|
|
|
|
throws Exception { |
|
|
if (f == null || f.isEmpty()) { |
|
|
if (f == null || f.isEmpty()) { |
|
|
return currentPath; |
|
|
return currentPath; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Clean fileNum |
|
|
|
|
|
String cleanFileNum = "unknown"; |
|
|
|
|
|
if (fileNum != null && !fileNum.trim().isEmpty()) { |
|
|
|
|
|
// Remove illegal characters, but allow slashes / and \ for hierarchy |
|
|
|
|
|
cleanFileNum = fileNum.trim().replaceAll("[^a-zA-Z0-9.\\/\\\\_-]", "_"); |
|
|
|
|
|
// Normalize path separators to forward slash / |
|
|
|
|
|
cleanFileNum = cleanFileNum.replace('\\', '/'); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Save files inside the physical "uploads" directory in the project root |
|
|
|
|
|
File projectRoot = new File(".").getAbsoluteFile(); |
|
|
|
|
|
String subPath = "uploads/file-data/" + cleanFileNum + "/" + category.toUpperCase(); |
|
|
|
|
|
File folder = new File(projectRoot, subPath).getAbsoluteFile(); |
|
|
|
|
|
if (!folder.exists()) { |
|
|
|
|
|
folder.mkdirs(); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
String orig = f.getOriginalFilename(); |
|
|
String orig = f.getOriginalFilename(); |
|
|
String ext = orig != null && orig.lastIndexOf('.') > 0 ? orig.substring(orig.lastIndexOf('.')) : ".pdf"; |
|
|
String ext = orig != null && orig.lastIndexOf('.') > 0 ? orig.substring(orig.lastIndexOf('.')) : ".pdf"; |
|
|
String filename = prefix + "_" + System.currentTimeMillis() + ext; |
|
|
|
|
|
File dest = new File(dir, filename).getAbsoluteFile(); |
|
|
|
|
|
|
|
|
String cleanName = orig != null |
|
|
|
|
|
? orig.substring(0, orig.lastIndexOf('.')).replaceAll("[^a-zA-Z0-9.-]", "_") + ext |
|
|
|
|
|
: (category + "_" + System.currentTimeMillis() + ext); |
|
|
|
|
|
File dest = new File(folder, cleanName).getAbsoluteFile(); |
|
|
f.transferTo(dest); |
|
|
f.transferTo(dest); |
|
|
return "gccadjustmentmanagementfiles/" + filename; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return "uploads/file-data/" + cleanFileNum + "/" + category.toUpperCase() + "/" + cleanName; |
|
|
} |
|
|
} |
|
|
} |
|
|
} |