Update static/script.js
Browse files- static/script.js +25 -30
static/script.js
CHANGED
|
@@ -539,10 +539,9 @@ async function hienThiHoaChat() {
|
|
| 539 |
const columns = data.columns;
|
| 540 |
const rows = data.rows;
|
| 541 |
|
| 542 |
-
|
| 543 |
-
const
|
| 544 |
-
const
|
| 545 |
-
const idxTinhTrang = columns.findIndex(c => c.includes("TÌNH TRẠNG"));
|
| 546 |
|
| 547 |
const table = document.getElementById("bangHoaChat");
|
| 548 |
table.innerHTML = "";
|
|
@@ -551,7 +550,7 @@ async function hienThiHoaChat() {
|
|
| 551 |
const headerRow = thead.insertRow();
|
| 552 |
columns.forEach(col => {
|
| 553 |
const th = document.createElement("th");
|
| 554 |
-
th.textContent = col
|
| 555 |
th.style.background = "#f2f2f2";
|
| 556 |
th.style.padding = "8px";
|
| 557 |
th.style.border = "1px solid #ddd";
|
|
@@ -569,37 +568,32 @@ async function hienThiHoaChat() {
|
|
| 569 |
input.classList.add("input-cell");
|
| 570 |
input.style.width = "100%";
|
| 571 |
|
| 572 |
-
//
|
| 573 |
if (colIndex === idxTinhTrang) {
|
| 574 |
input.readOnly = true;
|
| 575 |
input.style.fontWeight = "bold";
|
| 576 |
|
| 577 |
-
|
| 578 |
-
|
| 579 |
-
|
| 580 |
-
|
| 581 |
-
|
| 582 |
-
const
|
| 583 |
-
|
| 584 |
-
|
| 585 |
-
|
| 586 |
-
|
| 587 |
-
|
| 588 |
-
|
| 589 |
-
|
| 590 |
-
|
| 591 |
-
|
| 592 |
-
|
| 593 |
-
|
| 594 |
-
} else {
|
| 595 |
-
statusText = `CÒN: ${daysLeft} NGÀY`;
|
| 596 |
-
}
|
| 597 |
}
|
| 598 |
-
|
| 599 |
-
input.value = statusText;
|
| 600 |
-
input.style.color = color;
|
| 601 |
-
} catch (e) {
|
| 602 |
input.value = "Không xác định";
|
|
|
|
| 603 |
}
|
| 604 |
}
|
| 605 |
|
|
@@ -617,6 +611,7 @@ async function hienThiHoaChat() {
|
|
| 617 |
}
|
| 618 |
|
| 619 |
|
|
|
|
| 620 |
// ==== Lưu dữ liệu đã chỉnh sửa ====
|
| 621 |
async function luuHoaChat() {
|
| 622 |
const table = document.getElementById("bangHoaChat");
|
|
|
|
| 539 |
const columns = data.columns;
|
| 540 |
const rows = data.rows;
|
| 541 |
|
| 542 |
+
const idxNgayNhap = columns.findIndex(c => c.toUpperCase().includes("NGÀY NHẬP"));
|
| 543 |
+
const idxHanSD = columns.findIndex(c => c.toUpperCase().includes("HẾT HẠN"));
|
| 544 |
+
const idxTinhTrang = columns.findIndex(c => c.toUpperCase().includes("TÌNH TRẠNG"));
|
|
|
|
| 545 |
|
| 546 |
const table = document.getElementById("bangHoaChat");
|
| 547 |
table.innerHTML = "";
|
|
|
|
| 550 |
const headerRow = thead.insertRow();
|
| 551 |
columns.forEach(col => {
|
| 552 |
const th = document.createElement("th");
|
| 553 |
+
th.textContent = col;
|
| 554 |
th.style.background = "#f2f2f2";
|
| 555 |
th.style.padding = "8px";
|
| 556 |
th.style.border = "1px solid #ddd";
|
|
|
|
| 568 |
input.classList.add("input-cell");
|
| 569 |
input.style.width = "100%";
|
| 570 |
|
| 571 |
+
// Tính lại tình trạng tự động
|
| 572 |
if (colIndex === idxTinhTrang) {
|
| 573 |
input.readOnly = true;
|
| 574 |
input.style.fontWeight = "bold";
|
| 575 |
|
| 576 |
+
const ngayNhap = new Date(row[idxNgayNhap]);
|
| 577 |
+
const ngayHetHan = new Date(row[idxHanSD]);
|
| 578 |
+
const today = new Date();
|
| 579 |
+
|
| 580 |
+
if (ngayNhap instanceof Date && !isNaN(ngayNhap) && ngayHetHan instanceof Date && !isNaN(ngayHetHan)) {
|
| 581 |
+
const timeDiff = (ngayHetHan - today) / (1000 * 3600 * 24); // ngày còn lại
|
| 582 |
+
const daysLeft = Math.floor(timeDiff);
|
| 583 |
+
|
| 584 |
+
if (daysLeft < 0) {
|
| 585 |
+
input.value = "HẾT HẠN";
|
| 586 |
+
input.style.color = "red";
|
| 587 |
+
} else if (daysLeft <= 30) {
|
| 588 |
+
input.value = `CÒN: ${daysLeft} NGÀY`;
|
| 589 |
+
input.style.color = "orange";
|
| 590 |
+
} else {
|
| 591 |
+
input.value = `CÒN: ${daysLeft} NGÀY`;
|
| 592 |
+
input.style.color = "black";
|
|
|
|
|
|
|
|
|
|
| 593 |
}
|
| 594 |
+
} else {
|
|
|
|
|
|
|
|
|
|
| 595 |
input.value = "Không xác định";
|
| 596 |
+
input.style.color = "gray";
|
| 597 |
}
|
| 598 |
}
|
| 599 |
|
|
|
|
| 611 |
}
|
| 612 |
|
| 613 |
|
| 614 |
+
|
| 615 |
// ==== Lưu dữ liệu đã chỉnh sửa ====
|
| 616 |
async function luuHoaChat() {
|
| 617 |
const table = document.getElementById("bangHoaChat");
|