@ -239,7 +239,8 @@
< / div >
<!-- Total Standby Count -->
< div class = "summary-card interactive" id = "card-total-standby" onclick = "fetchAndShowAllStandbyEmployees()" >
< div class = "summary-card interactive" id = "card-total-standby"
onclick="fetchAndShowAllStandbyEmployees()">
< div class = "summary-icon-container bg-summary-standby" >
< i class = "fa-solid fa-user-gear" > < / i >
< / div >
@ -1173,6 +1174,110 @@
< / div >
< / div >
<!-- Edit Vendor / Work Order Modal -->
< div class = "modal fade" id = "editWorkOrderModal" tabindex = "-1" aria-labelledby = "editWorkOrderModalLabel"
aria-hidden="true">
< div class = "modal-dialog modal-lg modal-dialog-centered" >
< div class = "modal-content"
style="border-radius: 14px; border: none; box-shadow: 0 10px 40px rgba(0,0,0,0.2);">
< div class = "modal-custom-header" >
< h5 class = "modal-custom-title" id = "editWorkOrderModalLabel" >
< i class = "fa-solid fa-pen-to-square" > < / i > Edit Vendor / Work Order
< / h5 >
< button type = "button" class = "btn-close btn-close-white" data-bs-dismiss = "modal"
aria-label="Close">< / button >
< / div >
< div class = "modal-body" >
< form id = "editWorkOrderForm" onsubmit = "updateWorkOrder(event)" >
< input type = "hidden" id = "edit-vo-id" >
< div class = "row g-3" >
<!-- Contractor Name -->
< div class = "col-md-6" >
< label for = "edit-vo-contractor-name"
class="form-label fw-semibold text-secondary">Contractor Name< / label >
< input type = "text" class = "form-control w-100" id = "edit-vo-contractor-name"
placeholder="Enter contractor name"
style="border-radius: 8px; text-transform: uppercase;">
< / div >
<!-- File No -->
< div class = "col-md-6" >
< label for = "edit-vo-file-no" class = "form-label fw-semibold text-secondary" > File
No< / label >
< input type = "text" class = "form-control w-100" id = "edit-vo-file-no"
placeholder="Enter file number"
style="border-radius: 8px; text-transform: uppercase;">
< / div >
<!-- Subject -->
< div class = "col-md-6" >
< label for = "edit-vo-subject"
class="form-label fw-semibold text-secondary">Subject< / label >
< input type = "text" class = "form-control w-100" id = "edit-vo-subject"
placeholder="Enter subject" style="border-radius: 8px;">
< / div >
<!-- Total Employees Count -->
< div class = "col-md-6" >
< label for = "edit-vo-total-employees" class = "form-label fw-semibold text-secondary" > Total
Employees Count< / label >
< input type = "number" class = "form-control w-100" id = "edit-vo-total-employees" min = "1"
placeholder="Number of employees" style="border-radius: 8px;">
< / div >
<!-- Work Order Issue Date -->
< div class = "col-md-6" >
< label for = "edit-vo-issue-date" class = "form-label fw-semibold text-secondary" > Issue
Date< / label >
< input type = "date" class = "form-control w-100" id = "edit-vo-issue-date"
style="border-radius: 8px;" onchange="restrictEditEndDate()"
onclick="this.showPicker()">
< / div >
<!-- Work Order End Date -->
< div class = "col-md-6" >
< label for = "edit-vo-end-date" class = "form-label fw-semibold text-secondary" > End
Date< / label >
< input type = "date" class = "form-control w-100" id = "edit-vo-end-date"
style="border-radius: 8px;" onclick="this.showPicker()">
< / div >
<!-- Current PDF Link & Upload New PDF -->
< div class = "col-md-12" >
< label class = "form-label fw-semibold text-secondary" > Work Order PDF< / label >
< div class = "d-flex align-items-center gap-3 p-2 bg-light rounded border mb-2"
id="edit-vo-current-file-container" style="display: none !important;">
< span class = "text-secondary" style = "font-size: 0.85rem;" > < i
class="fa-solid fa-file-pdf text-danger fs-5 me-1">< / i > Current File:< / span >
< a id = "edit-vo-current-file-link" href = "#" target = "_blank"
class="btn btn-sm btn-outline-primary px-3 py-1 fw-semibold"
style="font-size: 0.8rem; border-radius: 6px;">
< i class = "fa-solid fa-eye" > < / i > View Current PDF
< / a >
< / div >
< div class = "w-100" >
< label for = "edit-vo-file" class = "form-label fw-semibold text-secondary"
style="font-size: 0.8rem; margin-bottom: 4px;">Upload New PDF (Leave empty to
keep existing)< / label >
< input type = "file" class = "form-control w-100" id = "edit-vo-file" accept = ".pdf"
style="border-radius: 8px;">
< / div >
< / div >
< / div >
< div class = "d-flex justify-content-end gap-2 mt-4" >
< button type = "button" class = "btn btn-secondary px-4" data-bs-dismiss = "modal"
style="border-radius: 8px;">Cancel< / button >
< button type = "submit" class = "btn btn-primary px-4"
style="background-color: #0f5c78; border-color: #0f5c78; border-radius: 8px;">
< i class = "fa-solid fa-floppy-disk" > < / i > Update Work Order
< / button >
< / div >
< / form >
< / div >
< / div >
< / div >
< / div >
<!-- Delete Employee Modal -->
< div class = "modal fade" id = "deleteEmployeeModal" tabindex = "-1" aria-labelledby = "deleteEmployeeModalLabel"
aria-hidden="true">
@ -1952,7 +2057,7 @@
if (totalContractedEl) totalContractedEl.textContent = totalContractedEl.getAttribute("data-init") || filteredTotalTender;
if (totalOnRollEl) totalOnRollEl.textContent = totalOnRollEl.getAttribute("data-init") || filteredTotalOnRoll;
if (totalVacantEl) {
console.log("stat-total-vacant dynamic content updating to:", filteredTotalVacant);
// console.log("stat-total-vacant dynamic content updating to:", filteredTotalVacant);
totalVacantEl.textContent = filteredTotalVacant;
}
} else {
@ -1960,11 +2065,11 @@
if (totalContractedEl) totalContractedEl.textContent = filteredTotalTender;
if (totalOnRollEl) totalOnRollEl.textContent = filteredTotalOnRoll;
if (totalVacantEl) {
console.log("stat-total-vacant filtered content updating to:", filteredTotalVacant);
// console.log("stat-total-vacant filtered content updating to:", filteredTotalVacant);
totalVacantEl.textContent = filteredTotalVacant;
}
}
console.log("filterVendorCards finished. anyFilterActive:", anyFilterActive, "filteredTotalVacant:", filteredTotalVacant);
// console.log("filterVendorCards finished. anyFilterActive:", anyFilterActive, "filteredTotalVacant:", filteredTotalVacant);
}
// Globals to store current modal state
@ -2453,6 +2558,10 @@
if (isAdmin) {
actionCellHtml = `
< td class = "text-center" >
< button class = "btn btn-sm btn-outline-primary py-1 px-2 me-1" style = "border-radius: 6px; font-size: 0.8rem;"
onclick="openEditWorkOrderModal('${des.id}', '${escapeHtml(des.contract_name || '').replace(/'/g, "\\'")}', '${escapeHtml(des.File_no || '').replace(/'/g, "\\'")}', '${escapeHtml(des.subject || '').replace(/'/g, "\\'")}', '${des.work_order_issue_date || ''}', '${des.work_order_end_date || ''}', ${des.tender_manpower_designation_wise || 0}, '${escapeHtml(des.file_path || '').replace(/'/g, "\\'")}')">
< i class = "fa-solid fa-pen-to-square" > < / i > Edit
< / button >
< button class = "btn btn-sm btn-danger py-1 px-2" style = "border-radius: 6px; font-size: 0.8rem;" onclick = "deleteWorkOrder('${des.id}', '${escapeHtml(vendorName).replace(/'/g, " \ \ ' " ) } ' ) " >
< i class = "fa-solid fa-trash-can" > < / i > Delete
< / button >
@ -3672,10 +3781,159 @@
}
}
// Enforce Date restrictions dynamically for Edit
function restrictEditEndDate() {
const issueDateVal = document.getElementById("edit-vo-issue-date").value;
const endDateInput = document.getElementById("edit-vo-end-date");
if (issueDateVal) {
endDateInput.min = issueDateVal;
if (endDateInput.value & & endDateInput.value < issueDateVal ) {
endDateInput.value = "";
}
} else {
endDateInput.removeAttribute("min");
}
}
let editWorkOrderModalObj = null;
function openEditWorkOrderModal(id, contractName, fileNo, subject, issueDate, endDate, tenderCount, filePath) {
// Pre-populate fields
document.getElementById("edit-vo-id").value = id;
document.getElementById("edit-vo-contractor-name").value = contractName;
document.getElementById("edit-vo-file-no").value = fileNo;
document.getElementById("edit-vo-subject").value = subject;
document.getElementById("edit-vo-issue-date").value = issueDate;
document.getElementById("edit-vo-end-date").value = endDate;
document.getElementById("edit-vo-total-employees").value = tenderCount;
// Clear file input
document.getElementById("edit-vo-file").value = "";
// Show current file details if exists
const currentFileContainer = document.getElementById("edit-vo-current-file-container");
const currentFileLink = document.getElementById("edit-vo-current-file-link");
if (filePath & & filePath !== "-" & & filePath.trim() !== "") {
let url = filePath;
if (contextPath & & contextPath.endsWith('/') & & url.startsWith('/')) {
url = contextPath + url.substring(1);
} else {
url = contextPath + url;
}
currentFileLink.href = url;
currentFileContainer.setAttribute("style", "display: flex !important;");
} else {
currentFileContainer.setAttribute("style", "display: none !important;");
}
// Close the current work orders list modal
const woModalEl = document.getElementById("modal-wo-table").closest(".modal");
if (woModalEl) {
const woModal = bootstrap.Modal.getInstance(woModalEl);
if (woModal) woModal.hide();
}
// Open the edit modal
if (!editWorkOrderModalObj) {
editWorkOrderModalObj = new bootstrap.Modal(document.getElementById("editWorkOrderModal"));
}
editWorkOrderModalObj.show();
}
function updateWorkOrder(event) {
event.preventDefault();
const id = document.getElementById("edit-vo-id").value;
const contractorName = document.getElementById("edit-vo-contractor-name").value.trim();
const fileNo = document.getElementById("edit-vo-file-no").value.trim();
const subject = document.getElementById("edit-vo-subject").value.trim();
const issueDate = document.getElementById("edit-vo-issue-date").value;
const endDate = document.getElementById("edit-vo-end-date").value;
const totalEmployees = document.getElementById("edit-vo-total-employees").value.trim();
const fileInput = document.getElementById("edit-vo-file");
const form = document.getElementById("editWorkOrderForm");
const prevAlert = form.querySelector(".alert");
if (prevAlert) prevAlert.remove();
// Validate dates
if (issueDate & & endDate & & endDate < issueDate ) {
const alertHtml = `
< div class = "alert alert-danger alert-dismissible fade show mt-3" role = "alert" >
< i class = "fa-solid fa-triangle-exclamation" > < / i > < strong > Validation Error:< / strong > End Date cannot be before Issue Date.
< button type = "button" class = "btn-close" data-bs-dismiss = "alert" aria-label = "Close" > < / button >
< / div >
`;
form.insertAdjacentHTML("afterbegin", alertHtml);
return;
}
const formData = new FormData();
formData.append("id", id);
formData.append("contractorName", contractorName);
formData.append("fileNo", fileNo);
formData.append("subject", subject);
formData.append("issueDate", issueDate);
formData.append("endDate", endDate);
formData.append("totalEmployees", totalEmployees);
if (fileInput & & fileInput.files.length > 0) {
formData.append("file", fileInput.files[0]);
}
//showLoadingOverlay("Updating work order details...");
fetch(contextPath + 'api/vendor/edit-work-order', {
method: 'POST',
body: formData
})
.then(res => res.json())
.then(data => {
hideLoadingOverlay();
if (data.success) {
const alertHtml = `
< div class = "alert alert-success alert-dismissible fade show mt-3" role = "alert" >
< i class = "fa-solid fa-circle-check" > < / i > < strong > Success!< / strong > Work Order updated successfully.
< button type = "button" class = "btn-close" data-bs-dismiss = "alert" aria-label = "Close" > < / button >
< / div >
`;
form.insertAdjacentHTML("afterbegin", alertHtml);
setTimeout(() => {
if (editWorkOrderModalObj) {
editWorkOrderModalObj.hide();
window.location.reload();
}
// window.location.reload();
showLoadingOverlay("Updating work order details...");
}, 1500);
} else {
const alertHtml = `
< div class = "alert alert-danger alert-dismissible fade show mt-3" role = "alert" >
< i class = "fa-solid fa-triangle-exclamation" > < / i > < strong > Error:< / strong > ${data.error || 'Failed to update work order.'}
< button type = "button" class = "btn-close" data-bs-dismiss = "alert" aria-label = "Close" > < / button >
< / div >
`;
form.insertAdjacentHTML("afterbegin", alertHtml);
}
})
.catch(err => {
hideLoadingOverlay();
console.error("Error updating work order:", err);
const alertHtml = `
< div class = "alert alert-danger alert-dismissible fade show mt-3" role = "alert" >
< i class = "fa-solid fa-triangle-exclamation" > < / i > < strong > Error:< / strong > A connection error occurred.
< button type = "button" class = "btn-close" data-bs-dismiss = "alert" aria-label = "Close" > < / button >
< / div >
`;
form.insertAdjacentHTML("afterbegin", alertHtml);
});
}
// Setup uppercase handlers for Contractor Name and File No
document.addEventListener("DOMContentLoaded", () => {
const contractorInput = document.getElementById("add-vo-contractor-name");
const fileNoInput = document.getElementById("add-vo-file-no");
const editContractorInput = document.getElementById("edit-vo-contractor-name");
const editFileNoInput = document.getElementById("edit-vo-file-no");
if (contractorInput) {
contractorInput.addEventListener("input", function () {
@ -3687,6 +3945,16 @@
this.value = this.value.toUpperCase();
});
}
if (editContractorInput) {
editContractorInput.addEventListener("input", function () {
this.value = this.value.toUpperCase();
});
}
if (editFileNoInput) {
editFileNoInput.addEventListener("input", function () {
this.value = this.value.toUpperCase();
});
}
});
// Save Vendor and Work Order form handler
@ -5112,7 +5380,7 @@
function renderPositionHistoryTable(searchQuery = "") {
try {
console.log("renderPositionHistoryTable called with query:", searchQuery);
// console.log("renderPositionHistoryTable called with query:", searchQuery);
const vendorSelect = document.getElementById("history-modal-vendor-select");
const workorderSelect = document.getElementById("history-modal-workorder-select");
const tbody = document.getElementById("position-history-tbody");
@ -5125,13 +5393,13 @@
const selectedVendorId = vendorSelect.value;
const selectedFileNo = workorderSelect.value;
console.log("Selected Vendor ID:", selectedVendorId, "Selected File No:", selectedFileNo);
// console.log("Selected Vendor ID:", selectedVendorId, "Selected File No:", selectedFileNo);
tbody.innerHTML = "";
noHistoryEl.style.display = "none";
if (!selectedVendorId || !selectedFileNo) {
console.log("Vendor or Work Order not selected. Rendering prompt.");
// console.log("Vendor or Work Order not selected. Rendering prompt.");
tbody.innerHTML = `
< tr >
< td colspan = "6" class = "text-center py-5 text-secondary" >
@ -5145,7 +5413,7 @@
}
const vendorObj = vendorDetailsData.find(v => String(v.id) === String(selectedVendorId));
console.log("Found vendor object:", vendorObj);
// console.log("Found vendor object:", vendorObj);
if (!vendorObj || !vendorObj.designationDetails) {
console.warn("Vendor object or designationsDetails missing");
return;
@ -5156,7 +5424,7 @@
const fNo = d.File_no || d.file_no;
return fNo === selectedFileNo;
});
console.log("Designations under selected work order:", designations);
// console.log("Designations under selected work order:", designations);
// If search query is present, filter designations list
const q = searchQuery.toLowerCase().trim();
@ -5165,7 +5433,7 @@
}
if (designations.length === 0) {
console.log("No designations found for selected criteria");
// console.log("No designations found for selected criteria");
noHistoryEl.style.display = "block";
filteredHistoryList = [];
return;
@ -5192,7 +5460,7 @@
return empVendorMatches & & empDesMatches & & empWoMatches;
});
console.log(`Designation "${desName}": found ${employees.length} employees`);
// console.log(`Designation "${desName}": found ${employees.length} employees`);
// Separate active and inactive/deleted
const activeEmps = employees.filter(emp => !(emp.isdelete === true || emp.isactive === false || parseInt(emp.isdelete) === 1 || parseInt(emp.isactive) === 0));