Browse Source

changes in toner management and payment tracker

master
yoganandhank 2 weeks ago
parent
commit
05acba4b41
  1. 179
      src/main/java/com/gcc_manpower/gcctonermanagement/controller/TonerController.java
  2. 251
      src/main/java/com/gcc_manpower/gcctonermanagement/service/TonerService.java
  3. 52
      src/main/resources/templates/gccservicepaymenttracker/dashboard.html
  4. 1519
      src/main/resources/templates/gcctonermanagement/upload.html

179
src/main/java/com/gcc_manpower/gcctonermanagement/controller/TonerController.java

@ -871,4 +871,183 @@ public class TonerController {
}
return tonerService.getWorkorderModelRequestHistory();
}
// Save new department for workorder
@PostMapping("/api/savedepartment")
@ResponseBody
public boolean saveNewDepartment(
@RequestParam("department") String department,
HttpSession session) {
if (session.getAttribute("toner_usrName") == null) {
return false;
}
return tonerService.savenewdepartment(department);
}
@PostMapping("/api/savetonermodel")
@ResponseBody
public boolean saveNewTonerModel(
@RequestParam("tonermodel") String tonermodel,
@RequestParam("pid") int pid,
@RequestParam(required = false) String partCode,
HttpSession session) {
if (session.getAttribute("toner_usrName") == null) {
return false;
}
return tonerService.savetonermodel(pid, tonermodel, partCode);
}
@PostMapping("/api/saveprintermodel")
@ResponseBody
public boolean saveNewPrinterModel(
@RequestParam("printermodel") String printermodel,
HttpSession session) {
if (session.getAttribute("toner_usrName") == null) {
return false;
}
return tonerService.saveprintermodel(printermodel);
}
// ================= MASTER UPDATE ENDPOINTS =================
@PostMapping("/api/updateprintermodel")
@ResponseBody
public boolean updatePrinterModel(
@RequestParam("id") int id,
@RequestParam("printermodel") String printermodel,
HttpSession session) {
if (session.getAttribute("toner_usrName") == null) {
return false;
}
return tonerService.updatePrinterModel(id, printermodel);
}
@PostMapping("/api/updatetonermodel")
@ResponseBody
public boolean updateTonerModel(
@RequestParam("id") int id,
@RequestParam("pid") int pid,
@RequestParam("tonermodel") String tonermodel,
@RequestParam(value = "partCode", required = false) String partCode,
HttpSession session) {
if (session.getAttribute("toner_usrName") == null) {
return false;
}
return tonerService.updateTonerModel(id, pid, tonermodel, partCode);
}
@PostMapping("/api/updatedepartment")
@ResponseBody
public boolean updateDepartment(
@RequestParam("id") int id,
@RequestParam("department") String department,
HttpSession session) {
if (session.getAttribute("toner_usrName") == null) {
return false;
}
return tonerService.updateDepartment(id, department);
}
// ================= MASTER DELETE & RESTORE ENDPOINTS =================
@PostMapping("/api/deleteprintermodel")
@ResponseBody
public boolean deletePrinterModel(@RequestParam("id") int id, HttpSession session) {
if (session.getAttribute("toner_usrName") == null) {
return false;
}
return tonerService.deletePrinterModel(id);
}
@PostMapping("/api/restoreprintermodel")
@ResponseBody
public boolean restorePrinterModel(@RequestParam("id") int id, HttpSession session) {
if (session.getAttribute("toner_usrName") == null) {
return false;
}
return tonerService.restorePrinterModel(id);
}
@PostMapping("/api/deletetonermodel")
@ResponseBody
public boolean deleteTonerModel(@RequestParam("id") int id, HttpSession session) {
if (session.getAttribute("toner_usrName") == null) {
return false;
}
return tonerService.deleteTonerModel(id);
}
@PostMapping("/api/restoretonermodel")
@ResponseBody
public boolean restoreTonerModel(@RequestParam("id") int id, HttpSession session) {
if (session.getAttribute("toner_usrName") == null) {
return false;
}
return tonerService.restoreTonerModel(id);
}
@PostMapping("/api/deletedepartment")
@ResponseBody
public boolean deleteDepartment(@RequestParam("id") int id, HttpSession session) {
if (session.getAttribute("toner_usrName") == null) {
return false;
}
return tonerService.deleteDepartment(id);
}
@PostMapping("/api/restoredepartment")
@ResponseBody
public boolean restoreDepartment(@RequestParam("id") int id, HttpSession session) {
if (session.getAttribute("toner_usrName") == null) {
return false;
}
return tonerService.restoreDepartment(id);
}
// ================= MASTER LISTING ENDPOINTS =================
@GetMapping("/api/master/printers")
@ResponseBody
public List<Map<String, Object>> getMasterPrinters(
@RequestParam(value = "status", defaultValue = "active") String status,
HttpSession session) {
if (session.getAttribute("toner_usrName") == null) {
return java.util.Collections.emptyList();
}
return tonerService.getMasterPrinters(status);
}
@GetMapping("/api/master/toners")
@ResponseBody
public List<Map<String, Object>> getMasterToners(
@RequestParam(value = "status", defaultValue = "active") String status,
HttpSession session) {
if (session.getAttribute("toner_usrName") == null) {
return java.util.Collections.emptyList();
}
return tonerService.getMasterToners(status);
}
@GetMapping("/api/master/departments")
@ResponseBody
public List<Map<String, Object>> getMasterDepartments(
@RequestParam(value = "status", defaultValue = "active") String status,
HttpSession session) {
if (session.getAttribute("toner_usrName") == null) {
return java.util.Collections.emptyList();
}
return tonerService.getMasterDepartments(status);
}
@GetMapping("/api/toners/all")
@ResponseBody
public List<Map<String, Object>> getAllToners(HttpSession session) {
if (session.getAttribute("toner_usrName") == null) {
return java.util.Collections.emptyList();
}
return tonerService.getAllActiveToners();
}
}

251
src/main/java/com/gcc_manpower/gcctonermanagement/service/TonerService.java

@ -222,6 +222,253 @@ public class TonerService {
return map;
}
// ================ Adding department & toners & printers ================
public boolean savenewdepartment(String department) {
if (department == null || department.trim().isEmpty()) return false;
String cleanDept = department.trim();
try {
String sql = "INSERT INTO toner_department_list (dept_name, is_active, is_delete) VALUES (?, 1, 0)";
jdbcTemplate.update(sql, cleanDept);
return true;
} catch (Exception e) {
try {
String sql2 = "INSERT INTO toner_department_list (department_name, is_active, is_delete) VALUES (?, 1, 0)";
jdbcTemplate.update(sql2, cleanDept);
return true;
} catch (Exception ex) {
try {
String sql3 = "INSERT INTO toner_department_list (dept_name) VALUES (?)";
jdbcTemplate.update(sql3, cleanDept);
return true;
} catch (Exception ex2) {
ex2.printStackTrace();
return false;
}
}
}
}
public boolean savetonermodel(int pid, String modelname, String partcode) {
if (pid <= 0 || modelname == null || modelname.trim().isEmpty()) return false;
String cleanModel = modelname.trim();
String cleanPart = (partcode != null && !partcode.trim().isEmpty()) ? partcode.trim() : null;
try {
String sql = "INSERT INTO toner_model_list (pid, model_name, part_code, is_active, is_delete) VALUES (?, ?, ?, 1, 0)";
jdbcTemplate.update(sql, pid, cleanModel, cleanPart);
return true;
} catch (Exception e) {
try {
String sql2 = "INSERT INTO toner_model_list (pid, model_name, part_code) VALUES (?, ?, ?)";
jdbcTemplate.update(sql2, pid, cleanModel, cleanPart);
return true;
} catch (Exception ex) {
ex.printStackTrace();
return false;
}
}
}
public boolean saveprintermodel(String printermodel) {
if (printermodel == null || printermodel.trim().isEmpty()) return false;
String cleanPrinter = printermodel.trim();
try {
String sql = "INSERT INTO toner_printer_model_list (printer_name, is_active, is_delete) VALUES (?, 1, 0)";
jdbcTemplate.update(sql, cleanPrinter);
return true;
} catch (Exception e) {
try {
String sql2 = "INSERT INTO toner_printer_model_list (printer_name) VALUES (?)";
jdbcTemplate.update(sql2, cleanPrinter);
return true;
} catch (Exception ex) {
ex.printStackTrace();
return false;
}
}
}
public boolean updatePrinterModel(int id, String printermodel) {
if (id <= 0 || printermodel == null || printermodel.trim().isEmpty()) return false;
String cleanPrinter = printermodel.trim();
try {
String sql = "UPDATE toner_printer_model_list SET printer_name = ? WHERE id = ?";
return jdbcTemplate.update(sql, cleanPrinter, id) > 0;
} catch (Exception e) {
e.printStackTrace();
return false;
}
}
public boolean updateTonerModel(int id, int pid, String modelname, String partcode) {
if (id <= 0 || pid <= 0 || modelname == null || modelname.trim().isEmpty()) return false;
String cleanModel = modelname.trim();
String cleanPart = (partcode != null && !partcode.trim().isEmpty()) ? partcode.trim() : null;
try {
String sql = "UPDATE toner_model_list SET pid = ?, model_name = ?, part_code = ? WHERE id = ?";
return jdbcTemplate.update(sql, pid, cleanModel, cleanPart, id) > 0;
} catch (Exception e) {
e.printStackTrace();
return false;
}
}
public boolean updateDepartment(int id, String department) {
if (id <= 0 || department == null || department.trim().isEmpty()) return false;
String cleanDept = department.trim();
try {
String sql = "UPDATE toner_department_list SET dept_name = ? WHERE id = ?";
return jdbcTemplate.update(sql, cleanDept, id) > 0;
} catch (Exception e) {
try {
String sql2 = "UPDATE toner_department_list SET department_name = ? WHERE id = ?";
return jdbcTemplate.update(sql2, cleanDept, id) > 0;
} catch (Exception ex) {
ex.printStackTrace();
return false;
}
}
}
public boolean deletePrinterModel(int id) {
if (id <= 0) return false;
try {
String sql = "UPDATE toner_printer_model_list SET is_active = 0, is_delete = 1 WHERE id = ?";
return jdbcTemplate.update(sql, id) > 0;
} catch (Exception e) {
e.printStackTrace();
return false;
}
}
public boolean restorePrinterModel(int id) {
if (id <= 0) return false;
try {
String sql = "UPDATE toner_printer_model_list SET is_active = 1, is_delete = 0 WHERE id = ?";
return jdbcTemplate.update(sql, id) > 0;
} catch (Exception e) {
e.printStackTrace();
return false;
}
}
public boolean deleteTonerModel(int id) {
if (id <= 0) return false;
try {
String sql = "UPDATE toner_model_list SET is_active = 0, is_delete = 1 WHERE id = ?";
return jdbcTemplate.update(sql, id) > 0;
} catch (Exception e) {
e.printStackTrace();
return false;
}
}
public boolean restoreTonerModel(int id) {
if (id <= 0) return false;
try {
String sql = "UPDATE toner_model_list SET is_active = 1, is_delete = 0 WHERE id = ?";
return jdbcTemplate.update(sql, id) > 0;
} catch (Exception e) {
e.printStackTrace();
return false;
}
}
public boolean deleteDepartment(int id) {
if (id <= 0) return false;
try {
String sql = "UPDATE toner_department_list SET is_active = 0, is_delete = 1 WHERE id = ?";
return jdbcTemplate.update(sql, id) > 0;
} catch (Exception e) {
e.printStackTrace();
return false;
}
}
public boolean restoreDepartment(int id) {
if (id <= 0) return false;
try {
String sql = "UPDATE toner_department_list SET is_active = 1, is_delete = 0 WHERE id = ?";
return jdbcTemplate.update(sql, id) > 0;
} catch (Exception e) {
e.printStackTrace();
return false;
}
}
public List<Map<String, Object>> getMasterPrinters(String status) {
try {
String sql;
if ("deleted".equalsIgnoreCase(status)) {
sql = "SELECT id, printer_name, is_active, is_delete FROM toner_printer_model_list WHERE (is_delete = 1 OR is_active = 0) ORDER BY id DESC";
} else if ("all".equalsIgnoreCase(status)) {
sql = "SELECT id, printer_name, is_active, is_delete FROM toner_printer_model_list ORDER BY printer_name ASC";
} else {
sql = "SELECT id, printer_name, is_active, is_delete FROM toner_printer_model_list WHERE (is_active IS NULL OR is_active = 1) AND (is_delete IS NULL OR is_delete = 0) ORDER BY printer_name ASC";
}
return jdbcTemplate.queryForList(sql);
} catch (Exception e) {
e.printStackTrace();
return new ArrayList<>();
}
}
public List<Map<String, Object>> getMasterToners(String status) {
try {
String sql;
if ("deleted".equalsIgnoreCase(status)) {
sql = "SELECT t.id, t.pid, t.model_name, t.part_code, p.printer_name, t.is_active, t.is_delete FROM toner_model_list t " +
"LEFT JOIN toner_printer_model_list p ON t.pid = p.id " +
"WHERE (t.is_delete = 1 OR t.is_active = 0) ORDER BY t.id DESC";
} else if ("all".equalsIgnoreCase(status)) {
sql = "SELECT t.id, t.pid, t.model_name, t.part_code, p.printer_name, t.is_active, t.is_delete FROM toner_model_list t " +
"LEFT JOIN toner_printer_model_list p ON t.pid = p.id ORDER BY p.printer_name ASC, t.model_name ASC";
} else {
sql = "SELECT t.id, t.pid, t.model_name, t.part_code, p.printer_name, t.is_active, t.is_delete FROM toner_model_list t " +
"LEFT JOIN toner_printer_model_list p ON t.pid = p.id " +
"WHERE (t.is_active IS NULL OR t.is_active = 1) AND (t.is_delete IS NULL OR t.is_delete = 0) " +
"ORDER BY p.printer_name ASC, t.model_name ASC";
}
return jdbcTemplate.queryForList(sql);
} catch (Exception e) {
e.printStackTrace();
return new ArrayList<>();
}
}
public List<Map<String, Object>> getMasterDepartments(String status) {
try {
String sql;
if ("deleted".equalsIgnoreCase(status)) {
sql = "SELECT id, dept_name, is_active, is_delete FROM toner_department_list WHERE (is_delete = 1 OR is_active = 0) ORDER BY id DESC";
} else if ("all".equalsIgnoreCase(status)) {
sql = "SELECT id, dept_name, is_active, is_delete FROM toner_department_list ORDER BY dept_name ASC";
} else {
sql = "SELECT id, dept_name, is_active, is_delete FROM toner_department_list WHERE (is_active IS NULL OR is_active = 1) AND (is_delete IS NULL OR is_delete = 0) ORDER BY dept_name ASC";
}
return jdbcTemplate.queryForList(sql);
} catch (Exception e) {
try {
String fallbackSql;
if ("deleted".equalsIgnoreCase(status)) {
fallbackSql = "SELECT id, department_name AS dept_name, is_active, is_delete FROM toner_department_list WHERE (is_delete = 1 OR is_active = 0) ORDER BY id DESC";
} else if ("all".equalsIgnoreCase(status)) {
fallbackSql = "SELECT id, department_name AS dept_name, is_active, is_delete FROM toner_department_list ORDER BY department_name ASC";
} else {
fallbackSql = "SELECT id, department_name AS dept_name, is_active, is_delete FROM toner_department_list WHERE (is_active IS NULL OR is_active = 1) AND (is_delete IS NULL OR is_delete = 0) ORDER BY department_name ASC";
}
return jdbcTemplate.queryForList(fallbackSql);
} catch (Exception ex) {
ex.printStackTrace();
return new ArrayList<>();
}
}
}
public List<Map<String, Object>> getAllActiveToners() {
return getMasterToners("active");
}
// ================= PRINTERS & TONERS =================
public List<Map<String, Object>> getActivePrinters() {
String sql = "SELECT id, printer_name FROM toner_printer_model_list WHERE is_active = 1 AND is_delete = 0";
@ -441,7 +688,9 @@ public class TonerService {
int pid, int tid, int qtyRequested, String newUploadPath, String username) {
Timestamp now = new Timestamp(System.currentTimeMillis());
try {
String safeZoneId = (zoneId != null && !zoneId.trim().isEmpty() && !"null".equalsIgnoreCase(zoneId)) ? zoneId.trim() : null;
String safeZoneId = (zoneId != null && !zoneId.trim().isEmpty() && !"null".equalsIgnoreCase(zoneId))
? zoneId.trim()
: null;
if (newUploadPath != null && !newUploadPath.trim().isEmpty()) {
String sql = "UPDATE toner_department_requested_details SET " +
"itcell_ref_no = ?, dept_id = ?, zone_id = ?, pid = ?, tid = ?, " +

52
src/main/resources/templates/gccservicepaymenttracker/dashboard.html

@ -305,6 +305,16 @@
color: #991b1b;
}
.pending-split-box {
transition: all 0.2s ease-in-out;
}
.pending-split-box:hover {
transform: translateY(-2px);
box-shadow: 0 4px 10px rgba(0, 0, 0, 0.08);
filter: brightness(0.97);
}
.category-card:hover {
transform: translateY(-4px);
box-shadow: 0 8px 25px rgba(0, 0, 0, 0.06);
@ -1083,11 +1093,37 @@
<!-- Pending Bills -->
<div class="category-card card-pending"
onclick="openModalForCount('pending_custom', null, 'Pending Bills')">
<div class="card-left">
<h3 class="card-title">Pending Bills</h3>
<p class="card-value" id="count-pending">0</p>
<div class="card-left flex-grow-1">
<div class="d-flex justify-content-between align-items-center">
<div>
<h3 class="card-title">Pending Bills</h3>
<p class="card-value" id="count-pending">0</p>
</div>
</div>
<!-- Split: Pending with IT Cell & Pending with Others -->
<div class="d-flex gap-2 mt-2 pt-2 border-top" style="border-color: #fee2e2 !important;">
<div class="pending-split-box flex-fill text-center py-1 px-2 rounded-2"
style="background-color: #e0f2fe; border: 1px solid #bae6fd; cursor: pointer;"
onclick="event.stopPropagation(); openModalForCount('it_cell_custom', null, 'Pending with IT Cell');"
title="Click to view Pending with IT Cell">
<span class="d-block fw-bold"
style="font-size: 0.68rem; color: #0369a1; text-transform: uppercase; letter-spacing: 0.3px;">IT
Cell</span>
<span class="fw-bold font-monospace" id="count-pending-itcell"
style="font-size: 0.95rem; color: #0284c7;">0</span>
</div>
<div class="pending-split-box flex-fill text-center py-1 px-2 rounded-2"
style="background-color: #fff7ed; border: 1px solid #ffedd5; cursor: pointer;"
onclick="event.stopPropagation(); openModalForCount('others_custom', null, 'Pending with Others');"
title="Click to view Pending with Others">
<span class="d-block fw-bold"
style="font-size: 0.68rem; color: #c2410c; text-transform: uppercase; letter-spacing: 0.3px;">Others</span>
<span class="fw-bold font-monospace" id="count-pending-others"
style="font-size: 0.95rem; color: #ea580c;">0</span>
</div>
</div>
</div>
<i class="fa-solid fa-clock card-icon"></i>
<i class="fa-solid fa-clock card-icon ms-3"></i>
</div>
</div>
@ -3258,6 +3294,8 @@
const vendorMap = {};
let allCompletedCount = 0;
let totalItCell = 0;
let totalOthers = 0;
allRecords.forEach(row => {
const statusName = String(row.resolved_status || getStatusName(row.status) || '').trim();
@ -3333,8 +3371,10 @@
} else {
const group = getStatusGroup(statusName);
if (group === 'it_cell') {
totalItCell++;
vData.itCellCount++;
} else {
totalOthers++;
vData.othersCount++;
}
@ -3358,6 +3398,10 @@
if (cardCompletedEl) cardCompletedEl.textContent = completedTotal;
const cardPendingEl = document.getElementById('count-pending');
if (cardPendingEl) cardPendingEl.textContent = pendingTotal;
const cardPendingItCellEl = document.getElementById('count-pending-itcell');
if (cardPendingItCellEl) cardPendingItCellEl.textContent = totalItCell;
const cardPendingOthersEl = document.getElementById('count-pending-others');
if (cardPendingOthersEl) cardPendingOthersEl.textContent = totalOthers;
let summaryBodyHtml = `
<td id="summary-total" class="cursor-pointer text-primary" style="background-color: #f8fafc;" onclick="openModalForCount('total', null, 'Total No of Bills')">${total}</td>

1519
src/main/resources/templates/gcctonermanagement/upload.html
File diff suppressed because it is too large
View File

Loading…
Cancel
Save