CI / build (push) Successful in 35s
頁面引用共用按鈕樣式表 Co-Authored-By: Claude Sonnet 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01VDJVpPiGiWjJP1yVvvGhzQ
107 lines
7.7 KiB
HTML
107 lines
7.7 KiB
HTML
<!DOCTYPE html>
|
|
<html lang="zh-Hant">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
<title>MoonShine LeadBoard · 年度封存</title>
|
|
<link rel="icon" href="/2022_Moonshine_Logo_MS_logo_w_EN.png">
|
|
<style>
|
|
:root { --bg:#f6f4ef; --card:#ffffff; --text:#1f2328; --muted:#5f6670; --line:#e4e0d8; --accent:#4f6bed; --warn:#b4540a; }
|
|
@media (prefers-color-scheme: dark) { :root { --bg:#16181c; --card:#1f2228; --text:#eceef1; --muted:#a3a9b3; --line:#30343c; --accent:#8fa2ff; --warn:#f0a35a; } }
|
|
* { box-sizing:border-box; }
|
|
body { margin:0; background:var(--bg); color:var(--text); font:15px/1.55 -apple-system, "PingFang TC", "Noto Sans TC", "Microsoft JhengHei", sans-serif; }
|
|
main { max-width:1100px; margin:0 auto; padding:24px 16px 64px; }
|
|
h1 { font-size:1.5rem; margin:0 0 4px; }
|
|
.sub { color:var(--muted); font-size:.85rem; }
|
|
.card { background:var(--card); border:1px solid var(--line); border-radius:14px; padding:18px; margin:16px 0; }
|
|
table { width:100%; border-collapse:collapse; font-size:.88rem; }
|
|
th, td { padding:7px 6px; border-bottom:1px solid var(--line); text-align:left; vertical-align:top; }
|
|
th { color:var(--muted); font-weight:500; font-size:.8rem; }
|
|
td.num, th.num { text-align:right; font-variant-numeric:tabular-nums; white-space:nowrap; }
|
|
.scroll { overflow-x:auto; }
|
|
.years { display:flex; gap:8px; flex-wrap:wrap; }
|
|
.years a, .years span { border:1px solid var(--line); border-radius:99px; padding:3px 12px; text-decoration:none; color:var(--text); }
|
|
.years .on { background:var(--accent); color:#fff; border-color:var(--accent); }
|
|
input[type=text] { font:inherit; padding:4px 8px; border:1px solid var(--line); border-radius:6px; background:var(--bg); color:var(--text); min-width:260px; }
|
|
button { font:inherit; border:1px solid var(--line); background:var(--card); color:var(--text); border-radius:8px; padding:4px 12px; cursor:pointer; }
|
|
button:focus-visible, a:focus-visible, input:focus-visible { outline:2px solid var(--accent); outline-offset:2px; }
|
|
.warn { color:var(--warn); }
|
|
</style>
|
|
<link rel="stylesheet" href="/buttons.css">
|
|
</head>
|
|
<body>
|
|
<main>
|
|
<a href="/" class="sub">← 回到 LeadBoard(目前年度)</a>
|
|
<h1>年度封存與年份切換</h1>
|
|
<p class="sub">年底在 H2 定錨之後封存,封存後的年份唯讀、不能修改或覆蓋。封存只存部門與組的數字和定錨結果,不含個人資料。</p>
|
|
<div class="card"><div class="years" id="years">讀取中…</div><div id="action" style="margin-top:12px;"></div></div>
|
|
<div id="content"></div>
|
|
</main>
|
|
<script>
|
|
const money = v => v === null || v === undefined ? '—' : 'NT$ ' + Math.round(v).toLocaleString();
|
|
const esc = s => String(s ?? '').replace(/[&<>"']/g, c => ({ '&': '&', '<': '<', '>': '>', '"': '"', "'": ''' }[c]));
|
|
const params = new URLSearchParams(location.search);
|
|
let info = null; let confirming = false; let confirmingNext = false;
|
|
|
|
async function startNextYear() {
|
|
const response = await fetch('/api/year/next', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ confirm: true }) });
|
|
const body = await response.json().catch(() => ({}));
|
|
if (!response.ok) { document.getElementById('action').insertAdjacentHTML('beforeend', `<div class="warn" role="alert">沒有完成:${body.error === 'archive_required' ? '要先封存目前年度' : esc(body.error || response.status)}</div>`); return; }
|
|
location.href = '/';
|
|
}
|
|
|
|
function drawAction() {
|
|
const el = document.getElementById('action');
|
|
if (info.years.includes(info.currentYear)) {
|
|
el.innerHTML = confirmingNext
|
|
? `<button type="button" onclick="startNextYear()">確定開始 ${info.currentYear + 1} 年</button> <button type="button" onclick="confirmingNext=false;drawAction()">取消</button>
|
|
<div class="sub">開始後首頁、定錨、對外接口都改用 ${info.currentYear + 1} 年;職能沿用,在職月份重設為全年(再依 HR 到職/離職限縮)。${info.currentYear} 年留在封存裡,可以切回來看。</div>`
|
|
: `<span class="sub">${info.currentYear} 年已封存。</span> <button type="button" onclick="confirmingNext=true;drawAction()">開始 ${info.currentYear + 1} 年…</button>`;
|
|
return;
|
|
}
|
|
el.innerHTML = confirming
|
|
? `<input id="note" type="text" maxlength="500" placeholder="說明(必填)" aria-label="封存說明"> <button type="button" onclick="archiveNow()">確定封存 ${info.currentYear} 年</button> <button type="button" onclick="confirming=false;drawAction()">取消</button>
|
|
<div class="sub">封存後不能修改,請確認 H2 已定錨、年底結算已完成。</div>`
|
|
: `<button type="button" onclick="confirming=true;drawAction()">封存 ${info.currentYear} 年…</button> <span class="sub">(年底、H2 定錨之後)</span>`;
|
|
}
|
|
|
|
async function archiveNow() {
|
|
const note = document.getElementById('note').value.trim();
|
|
if (!note) { document.getElementById('note').focus(); return; }
|
|
const response = await fetch('/api/archive', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ note, confirm: true }) });
|
|
const body = await response.json().catch(() => ({}));
|
|
if (!response.ok) {
|
|
document.getElementById('action').insertAdjacentHTML('beforeend', `<div class="warn" role="alert">沒有封存:${body.error === 'h2_anchor_required' ? '要先完成 H2 定錨' : esc(body.error || response.status)}</div>`);
|
|
return;
|
|
}
|
|
location.href = `/archive?year=${body.year}`;
|
|
}
|
|
|
|
function drawArchive(a) {
|
|
const rows = a.depts.filter(d => d.actualCoda || d.invoice || d.anchoredCoda?.annual).map(d => `<tr><td>${esc(d.dept)}<div class="sub">${esc(d.company)}</div></td>
|
|
<td class="num">${money(d.actualCoda)}</td><td class="num">${money(d.avgDailyCoda)}</td><td class="num">${d.anchoredCoda ? money(d.anchoredCoda.annual) : '—'}</td>
|
|
<td class="num">${d.anchoredInvoice ? money(d.anchoredInvoice.annual) : money(d.invoice)}</td><td class="num">${d.anchoredInvoice ? money(d.anchoredInvoice.h1) + ' / ' + money(d.anchoredInvoice.h2) : '—'}</td></tr>`).join('');
|
|
document.getElementById('content').innerHTML = `<div class="card"><h2 style="margin:0;font-size:1.1rem;">${a.year} 年(已封存)</h2>
|
|
<div class="sub">封存時間 ${new Date(a.archivedAt).toLocaleString('zh-TW', { hour12: false })} 說明:${esc(a.note)} 定錨 ${a.anchors.map(x => x.half).join('、') || '—'} 年度發票目標 ${money(a.invoiceTotal)}</div>
|
|
<div class="scroll" style="margin-top:10px;"><table><thead><tr><th>部門</th><th class="num">實際 CODA</th><th class="num">平均日 CODA</th><th class="num">定錨 CODA</th><th class="num">發票全年</th><th class="num">H1 / H2</th></tr></thead><tbody>${rows}</tbody></table></div></div>`;
|
|
}
|
|
|
|
(async () => {
|
|
const response = await fetch('/api/archive', { cache: 'no-store' });
|
|
if (response.status === 401) { location.href = '/api/auth/login'; return; }
|
|
if (!response.ok) { document.getElementById('years').textContent = '只有最高管理者可以查看年度封存。'; return; }
|
|
info = await response.json();
|
|
const selected = Number(params.get('year')) || null;
|
|
document.getElementById('years').innerHTML = [`<a href="/">${info.currentYear}(目前)</a>`, ...info.years.filter(y => y !== info.currentYear || true).map(y => `<a href="/archive?year=${y}" class="${y === selected ? 'on' : ''}">${y}(已封存)</a>`)].join('')
|
|
+ (info.years.length ? '' : '<span class="sub" style="border:0;">還沒有封存的年度</span>');
|
|
drawAction();
|
|
if (selected) {
|
|
const a = await fetch(`/api/archive?year=${selected}`, { cache: 'no-store' });
|
|
document.getElementById('content').innerHTML = a.ok ? '' : '<div class="card">這一年還沒有封存。</div>';
|
|
if (a.ok) drawArchive(await a.json());
|
|
}
|
|
})();
|
|
</script>
|
|
</body>
|
|
</html>
|