Upload script.js
Browse files- static/script.js +10 -16
static/script.js
CHANGED
|
@@ -23,7 +23,6 @@ async function hienThiDanhSachPYC() {
|
|
| 23 |
try {
|
| 24 |
const res = await fetch("/dem_pyc_tat_ca");
|
| 25 |
const data = await res.json();
|
| 26 |
-
|
| 27 |
if (res.ok && data.tong_so_pyc !== undefined) {
|
| 28 |
document.getElementById("pycCount").textContent = data.tong_so_pyc;
|
| 29 |
} else {
|
|
@@ -40,9 +39,8 @@ async function hienThiSoPYCHoanThanh() {
|
|
| 40 |
try {
|
| 41 |
const res = await fetch("/dem_pyc_hoan_thanh");
|
| 42 |
const data = await res.json();
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
document.getElementById("completedRequests").textContent = data.so_pyc_ht;
|
| 46 |
} else {
|
| 47 |
document.getElementById("completedRequests").textContent = "Không tải được";
|
| 48 |
}
|
|
@@ -57,7 +55,6 @@ async function hienThiDoanhThuPYC() {
|
|
| 57 |
try {
|
| 58 |
const res = await fetch("/tong_doanh_thu_pyc");
|
| 59 |
const data = await res.json();
|
| 60 |
-
|
| 61 |
if (res.ok && data.tong_doanh_thu !== undefined) {
|
| 62 |
const formatted = Number(data.tong_doanh_thu).toLocaleString("vi-VN") + " VND";
|
| 63 |
document.getElementById("requestRevenue").textContent = formatted;
|
|
@@ -82,16 +79,17 @@ function chonMuc(muc) {
|
|
| 82 |
bang.style.display = "none";
|
| 83 |
} else if (muc === "pyc") {
|
| 84 |
tieuDe.textContent = "📥 Danh sách phiếu yêu cầu";
|
| 85 |
-
hienThiBangTuAPI("/
|
| 86 |
} else if (muc === "ht") {
|
| 87 |
tieuDe.textContent = "📦 Danh sách phiếu đã hoàn thành";
|
| 88 |
-
hienThiBangTuAPI("/
|
| 89 |
} else if (muc === "dt") {
|
| 90 |
tieuDe.textContent = "💰 Doanh thu theo phiếu yêu cầu";
|
| 91 |
-
hienThiBangTuAPI("/
|
| 92 |
} else if (muc === "dt_thang") {
|
| 93 |
tieuDe.textContent = "📊 Doanh thu theo tháng";
|
| 94 |
-
|
|
|
|
| 95 |
}
|
| 96 |
}
|
| 97 |
|
|
@@ -124,7 +122,6 @@ async function hienThiBangTuAPI(api, noiDung) {
|
|
| 124 |
html += "</tbody></table>";
|
| 125 |
noiDung.innerHTML = html;
|
| 126 |
|
| 127 |
-
// Gắn DataTables
|
| 128 |
$(document).ready(function () {
|
| 129 |
$('#tableAuto').DataTable();
|
| 130 |
});
|
|
@@ -133,6 +130,8 @@ async function hienThiBangTuAPI(api, noiDung) {
|
|
| 133 |
noiDung.innerHTML = "Lỗi khi tải dữ liệu.";
|
| 134 |
}
|
| 135 |
}
|
|
|
|
|
|
|
| 136 |
async function veBieuDoDoanhThuTheoThang() {
|
| 137 |
try {
|
| 138 |
const res = await fetch("/doanh_thu_theo_thang");
|
|
@@ -182,9 +181,4 @@ async function veBieuDoDoanhThuTheoThang() {
|
|
| 182 |
} catch (error) {
|
| 183 |
console.error("❌ Lỗi khi gọi API doanh thu theo tháng:", error);
|
| 184 |
}
|
| 185 |
-
}
|
| 186 |
-
|
| 187 |
-
// ✅ Gọi khi trang sẵn sàng
|
| 188 |
-
window.addEventListener("DOMContentLoaded", () => {
|
| 189 |
-
veBieuDoDoanhThuTheoThang();
|
| 190 |
-
});
|
|
|
|
| 23 |
try {
|
| 24 |
const res = await fetch("/dem_pyc_tat_ca");
|
| 25 |
const data = await res.json();
|
|
|
|
| 26 |
if (res.ok && data.tong_so_pyc !== undefined) {
|
| 27 |
document.getElementById("pycCount").textContent = data.tong_so_pyc;
|
| 28 |
} else {
|
|
|
|
| 39 |
try {
|
| 40 |
const res = await fetch("/dem_pyc_hoan_thanh");
|
| 41 |
const data = await res.json();
|
| 42 |
+
if (res.ok && data.tong_so_hoan_thanh !== undefined) {
|
| 43 |
+
document.getElementById("completedRequests").textContent = data.tong_so_hoan_thanh;
|
|
|
|
| 44 |
} else {
|
| 45 |
document.getElementById("completedRequests").textContent = "Không tải được";
|
| 46 |
}
|
|
|
|
| 55 |
try {
|
| 56 |
const res = await fetch("/tong_doanh_thu_pyc");
|
| 57 |
const data = await res.json();
|
|
|
|
| 58 |
if (res.ok && data.tong_doanh_thu !== undefined) {
|
| 59 |
const formatted = Number(data.tong_doanh_thu).toLocaleString("vi-VN") + " VND";
|
| 60 |
document.getElementById("requestRevenue").textContent = formatted;
|
|
|
|
| 79 |
bang.style.display = "none";
|
| 80 |
} else if (muc === "pyc") {
|
| 81 |
tieuDe.textContent = "📥 Danh sách phiếu yêu cầu";
|
| 82 |
+
hienThiBangTuAPI("/ds_pyc_tat_ca", noiDung);
|
| 83 |
} else if (muc === "ht") {
|
| 84 |
tieuDe.textContent = "📦 Danh sách phiếu đã hoàn thành";
|
| 85 |
+
hienThiBangTuAPI("/ds_pyc_hoan_thanh", noiDung);
|
| 86 |
} else if (muc === "dt") {
|
| 87 |
tieuDe.textContent = "💰 Doanh thu theo phiếu yêu cầu";
|
| 88 |
+
hienThiBangTuAPI("/ds_pyc_tat_ca", noiDung);
|
| 89 |
} else if (muc === "dt_thang") {
|
| 90 |
tieuDe.textContent = "📊 Doanh thu theo tháng";
|
| 91 |
+
noiDung.innerHTML = `<canvas id="barChartMonth" height="100"></canvas>`;
|
| 92 |
+
veBieuDoDoanhThuTheoThang();
|
| 93 |
}
|
| 94 |
}
|
| 95 |
|
|
|
|
| 122 |
html += "</tbody></table>";
|
| 123 |
noiDung.innerHTML = html;
|
| 124 |
|
|
|
|
| 125 |
$(document).ready(function () {
|
| 126 |
$('#tableAuto').DataTable();
|
| 127 |
});
|
|
|
|
| 130 |
noiDung.innerHTML = "Lỗi khi tải dữ liệu.";
|
| 131 |
}
|
| 132 |
}
|
| 133 |
+
|
| 134 |
+
// Vẽ biểu đồ doanh thu theo tháng
|
| 135 |
async function veBieuDoDoanhThuTheoThang() {
|
| 136 |
try {
|
| 137 |
const res = await fetch("/doanh_thu_theo_thang");
|
|
|
|
| 181 |
} catch (error) {
|
| 182 |
console.error("❌ Lỗi khi gọi API doanh thu theo tháng:", error);
|
| 183 |
}
|
| 184 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|