Update static/script.js
Browse files- static/script.js +91 -0
static/script.js
CHANGED
|
@@ -211,6 +211,11 @@ function chonMuc(muc) {
|
|
| 211 |
document.getElementById('appMain')?.scrollIntoView({ behavior: 'smooth', block: 'start' });
|
| 212 |
return;
|
| 213 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 214 |
}
|
| 215 |
|
| 216 |
|
|
@@ -1572,3 +1577,89 @@ document.addEventListener('DOMContentLoaded', () => {
|
|
| 1572 |
});
|
| 1573 |
}
|
| 1574 |
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 211 |
document.getElementById('appMain')?.scrollIntoView({ behavior: 'smooth', block: 'start' });
|
| 212 |
return;
|
| 213 |
}
|
| 214 |
+
if (muc === "pycinc") {
|
| 215 |
+
const section = document.getElementById("pycinc");
|
| 216 |
+
if (section) section.style.display = "block";
|
| 217 |
+
refreshAndLoadPYCInc(); // gọi cập nhật và tải thống kê
|
| 218 |
+
}
|
| 219 |
}
|
| 220 |
|
| 221 |
|
|
|
|
| 1577 |
});
|
| 1578 |
}
|
| 1579 |
});
|
| 1580 |
+
// ===== PYC Incremental (frontend) =====
|
| 1581 |
+
function _fmtVND(v) {
|
| 1582 |
+
try { return Number(v||0).toLocaleString('vi-VN') + ' VND'; } catch { return v; }
|
| 1583 |
+
}
|
| 1584 |
+
|
| 1585 |
+
async function pycIncRefresh() {
|
| 1586 |
+
const el = document.getElementById('incStatus');
|
| 1587 |
+
el.textContent = 'Đang cập nhật file mới...';
|
| 1588 |
+
try {
|
| 1589 |
+
const r = await fetch(`${BACKEND_URL}/pyc_incremental/refresh`, { method: 'POST' });
|
| 1590 |
+
const d = await r.json();
|
| 1591 |
+
el.textContent = `Đã biết ${d.known} file, thêm mới ${d.added}` + (d.newest_num ? ` (PYC mới nhất: ${d.newest_num})` : '');
|
| 1592 |
+
} catch (e) {
|
| 1593 |
+
el.textContent = '⚠ Không cập nhật được: ' + e;
|
| 1594 |
+
}
|
| 1595 |
+
}
|
| 1596 |
+
|
| 1597 |
+
async function pycIncStats() {
|
| 1598 |
+
const mSel = document.getElementById('incMonth');
|
| 1599 |
+
const pSel = document.getElementById('incPeriod');
|
| 1600 |
+
const box = document.getElementById('incStats');
|
| 1601 |
+
const list = document.getElementById('incFiles');
|
| 1602 |
+
|
| 1603 |
+
const month = mSel?.value || '';
|
| 1604 |
+
const period = pSel?.value || '';
|
| 1605 |
+
|
| 1606 |
+
const url = new URL(`${BACKEND_URL}/pyc_incremental/stats`);
|
| 1607 |
+
if (month) url.searchParams.set('month', month);
|
| 1608 |
+
if (period) url.searchParams.set('period', period);
|
| 1609 |
+
url.searchParams.set('refresh_first', 'false'); // đã refresh riêng
|
| 1610 |
+
|
| 1611 |
+
box.innerHTML = 'Đang tải thống kê...';
|
| 1612 |
+
try {
|
| 1613 |
+
const r = await fetch(url);
|
| 1614 |
+
const d = await r.json();
|
| 1615 |
+
const t = d.totals || {}, rv = d.revenue || {};
|
| 1616 |
+
|
| 1617 |
+
box.innerHTML = `
|
| 1618 |
+
<div>
|
| 1619 |
+
<div><b>KĐ</b>: ${t['KĐ']||0} | Doanh thu: <b>${_fmtVND(rv['KĐ']||0)}</b></div>
|
| 1620 |
+
<div><b>HC</b>: ${t['HC']||0} | Doanh thu: <b>${_fmtVND(rv['HC']||0)}</b></div>
|
| 1621 |
+
<div><b>ĐTN</b>: ${t['ĐTN']||0} | Doanh thu: <b>${_fmtVND(rv['ĐTN']||0)}</b></div>
|
| 1622 |
+
<hr/>
|
| 1623 |
+
<div><b>Tổng doanh thu:</b> ${_fmtVND((rv['KĐ']||0)+(rv['HC']||0)+(rv['ĐTN']||0))}</div>
|
| 1624 |
+
</div>
|
| 1625 |
+
<div style="margin-top:8px">
|
| 1626 |
+
<b>Khách hàng (${(d.customers||[]).length}):</b> ${ (d.customers||[]).slice(0,50).join(', ') }
|
| 1627 |
+
</div>
|
| 1628 |
+
`;
|
| 1629 |
+
|
| 1630 |
+
const files = d.files || [];
|
| 1631 |
+
list.innerHTML = files.length
|
| 1632 |
+
? `<ul style="margin:0;padding-left:20px">${files.map(f=>`<li>${f}</li>`).join('')}</ul>`
|
| 1633 |
+
: '<i>Chưa có file khớp điều kiện lọc.</i>';
|
| 1634 |
+
} catch (e) {
|
| 1635 |
+
box.innerHTML = '⚠ Không lấy được thống kê: ' + e;
|
| 1636 |
+
}
|
| 1637 |
+
}
|
| 1638 |
+
|
| 1639 |
+
async function refreshAndLoadPYCInc() {
|
| 1640 |
+
const btn = document.getElementById('incReload');
|
| 1641 |
+
if (btn && !btn.dataset.bound) {
|
| 1642 |
+
btn.dataset.bound = '1';
|
| 1643 |
+
btn.addEventListener('click', async () => {
|
| 1644 |
+
btn.disabled = true; const txt = btn.textContent; btn.textContent = 'Đang cập nhật...';
|
| 1645 |
+
await pycIncRefresh();
|
| 1646 |
+
await pycIncStats();
|
| 1647 |
+
btn.disabled = false; btn.textContent = txt;
|
| 1648 |
+
});
|
| 1649 |
+
}
|
| 1650 |
+
// lần đầu vào màn: refresh + load
|
| 1651 |
+
await pycIncRefresh();
|
| 1652 |
+
await pycIncStats();
|
| 1653 |
+
|
| 1654 |
+
// thay đổi filter là tự load lại
|
| 1655 |
+
const mSel = document.getElementById('incMonth');
|
| 1656 |
+
const pSel = document.getElementById('incPeriod');
|
| 1657 |
+
if (mSel && !mSel.dataset.bound) {
|
| 1658 |
+
mSel.dataset.bound = '1';
|
| 1659 |
+
mSel.addEventListener('change', pycIncStats);
|
| 1660 |
+
}
|
| 1661 |
+
if (pSel && !pSel.dataset.bound) {
|
| 1662 |
+
pSel.dataset.bound = '1';
|
| 1663 |
+
pSel.addEventListener('change', pycIncStats);
|
| 1664 |
+
}
|
| 1665 |
+
}
|