From dc809df1dad27b01accf1d695511602f7fdbd29f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?walkdoggo=2Eyeh=5F=E8=91=89=E5=82=B3=E8=80=80?= Date: Wed, 25 Nov 2026 08:07:27 +0000 Subject: [PATCH] =?UTF-8?q?=E9=83=A8=E9=95=B7=E9=A0=81=E5=B8=B6=E5=87=BA?= =?UTF-8?q?=E9=83=A8=E9=96=80=E7=9A=84=E4=BA=BA=E5=93=A1=E7=95=B0=E5=8B=95?= =?UTF-8?q?=EF=BC=88=E8=AA=B0=E9=9B=A2=E9=96=8B=E3=80=81=E8=AA=B0=E5=8A=A0?= =?UTF-8?q?=E5=85=A5=E3=80=81=E7=94=9F=E6=95=88=E6=9C=88=E4=BB=BD=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Claude Opus 5 Claude-Session: https://claude.ai/code/session_01VDJVpPiGiWjJP1yVvvGhzQ --- scope-view.js | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/scope-view.js b/scope-view.js index 0929af1..2271254 100644 --- a/scope-view.js +++ b/scope-view.js @@ -66,7 +66,29 @@ function anchoredGroup(anchors, dept, group) { return g ? { annual: round(g.value), h1: round(g.h1), h2: g.h2 === null ? null : round(g.h2) } : null; } -export function buildScopedView(model, anchors, permission, { year } = {}) { +// 部長看得到的人員異動:誰離開、誰加入、哪個月生效。 +// 刻意不分離職或轉調,也不顯示轉調去哪裡,部長只需要知道編制什麼時候變。 +// 只掛在看得到整個部門的人身上;只看單一組別的人不給,免得看到別組的人。 +export function changesFor(dept, model, plans) { + const name = (employeeNumber) => (model.people || []) + .find(p => String(p.employeeNumber || '') === String(employeeNumber))?.name || ''; + const out = []; + for (const person of model.people || []) { + if (String(person.dept || '').trim() !== dept) continue; + if (person.plannedLeave) out.push({ kind: 'leave', name: person.name || '', month: person.plannedLeave }); + // 拆成兩段時,前段掛在原部門,那是「離開」不是「加入」(下面用 fromDept 處理)。 + if (person.plannedTransfer && person.transferSplit !== 'before') out.push({ kind: 'join', name: person.name || '', month: person.plannedTransfer }); + if (person.plannedHire) out.push({ kind: 'join', name: person.name || '', month: person.plannedHire }); + } + for (const plan of plans?.transfers || []) { + if (String(plan.fromDept || '').trim() !== dept) continue; + out.push({ kind: 'leave', name: name(plan.employeeNumber), month: plan.effectiveMonth }); + } + return out.filter(change => change.name && change.month) + .sort((a, b) => String(a.month).localeCompare(String(b.month)) || a.name.localeCompare(b.name, 'zh-Hant')); +} + +export function buildScopedView(model, anchors, permission, { year, plans } = {}) { const allDepts = Object.keys(model.codaGroups || {}); const fullDepts = permission.admin || permission.company ? allDepts : allDepts.filter(d => permission.depts.includes(d)); const groupOnly = permission.groups.map(key => key.split('|')).filter(([d]) => !fullDepts.includes(d)); @@ -86,6 +108,7 @@ export function buildScopedView(model, anchors, permission, { year } = {}) { multiplier: multiplierFor(model, dept), headcount: headcountByKind(model.people.filter(p => (p.dept || '').trim() === dept)), totalCost: round(model.staffCost?.depts?.[dept]), + changes: changesFor(dept, model, plans), anchoredInvoice: anchoredInvoice ? { annual: round(anchoredInvoice.annual), h1: round(anchoredInvoice.h1), h2: anchoredInvoice.h2 === null ? null : round(anchoredInvoice.h2) } : null, groups: Object.entries(data.groups).map(([group, g]) => ({ group, actualCoda: round(g.coda), avgDailyCoda: round(g.avgDailyCoda), headcount: g.people.length,