function login() { const u = document.getElementById("username").value; const p = document.getElementById("password").value; if (u === "admin" && p === "1234") { document.getElementById("login").style.display = "none"; document.getElementById("dashboard").style.display = "block"; chonMuc("pyc"); } else { alert("Sai tên đăng nhập hoặc mật khẩu!"); } } function toggleSubmenu(id) { const submenu = document.getElementById(id); const arrow = document.getElementById("arrow-" + id); if (submenu.style.display === "block") { submenu.style.display = "none"; arrow.innerText = "►"; } else { submenu.style.display = "block"; arrow.innerText = "▼"; } } function anTatCa() { document.querySelectorAll(".fade-in").forEach(el => el.style.display = "none"); } function chonMuc(muc) { anTatCa(); if (muc === "cho_xu_ly") hienThiPYCChoXuLy(); if (muc === "pyc") hienThiDanhSachPYC(); if (muc === "completedRequests") hienThiPYCCompleted(); if (muc === "requestRevenue") hienThiDoanhThuPYC(); } // ===== HIỂN THỊ ===== async function hienThiPYCChoXuLy() { try { const res = await fetch("/ds_pyc_cho_xu_ly"); const data = await res.json(); const tbody = document.querySelector("#tablePYCChoXuLy tbody"); tbody.innerHTML = ""; data.forEach(row => { tbody.innerHTML += `${row["Khách hàng"]}${row["File PYC"]}`; }); document.getElementById("bangPYCChoXuLy").style.display = "block"; if (!$.fn.DataTable.isDataTable("#tablePYCChoXuLy")) { $("#tablePYCChoXuLy").DataTable(); } } catch (err) { console.error("Lỗi chờ xử lý:", err); } } async function hienThiDanhSachPYC() { try { const res = await fetch("/pyc_chua_hoan_thanh"); const data = await res.json(); let html = ` `; data.forEach(item => { html += ``; }); html += "
Mã phiếuKhách hàngNgày tạo
${item["Phiếu yêu cầu"]}${item["Khách hàng"]}${item["Ngày tạo phiếu"]}
"; document.getElementById("noiDungBang").innerHTML = html; $("#bangPYC").DataTable(); document.getElementById("bangChiTiet").style.display = "block"; document.getElementById("tieuDeBang").innerText = "Danh sách phiếu chưa hoàn thành"; } catch (err) { console.error("Lỗi chưa hoàn thành:", err); } } async function hienThiPYCCompleted() { try { const res = await fetch("/dem_pyc_hoan_thanh"); const data = await res.json(); const so = data.tong_so_hoan_thanh || 0; document.getElementById("completedRequests").innerText = so; document.getElementById("daHoanThanh").style.display = "block"; } catch (err) { console.error("Lỗi hoàn thành:", err); } } async function hienThiDoanhThuPYC() { try { const res = await fetch("/doanh_thu_theo_pyc"); // Cần xác nhận API này có tồn tại const data = await res.json(); const dt = data.doanh_thu || 0; document.getElementById("requestRevenue").innerText = dt; document.getElementById("doanhThuPYC").style.display = "block"; } catch (err) { console.error("Lỗi doanh thu:", err); } }