diff --git a/simulate.js b/simulate.js index dde9581..4dedfff 100644 --- a/simulate.js +++ b/simulate.js @@ -1,6 +1,7 @@ // 部長模擬試算:在自己部門加人(O/P/A/實習/工讀)或幫現有的人調薪,伺服器算出 // 實際 CODA、平均日 CODA、定錨 CODA、發票各會變多少。不存檔、不影響正式數字。 import { PART_TIME_HOURS_PER_DAY } from './cost-model.js'; +import { multiplierFor } from './scope-view.js'; export const SIM_KINDS = Object.freeze(['P', 'A', 'O', 'intern', 'parttime']); const MAX_ADDITIONS = 30; @@ -78,8 +79,10 @@ export function compareDept(before, after, anchorsBefore, anchorsAfter, dept) { const alloc = model.allocations?.deptData?.[dept]; return { actualCoda: coda.coda, avgDailyCoda: coda.avgDailyCoda, - groups: Object.fromEntries(Object.entries(coda.groups).map(([g, v]) => [g, { actualCoda: v.coda, avgDailyCoda: v.avgDailyCoda }])), + groups: Object.fromEntries(Object.entries(coda.groups).map(([g, v]) => [g, { actualCoda: v.coda, avgDailyCoda: v.avgDailyCoda, headcount: v.people.length }])), invoice: alloc ? model.invoice.finalInvoiceTotal * (alloc.finalPct || 0) : null, + invoiceShare: alloc ? alloc.finalPct || 0 : null, + multiplier: multiplierFor(model, dept)?.value ?? null, anchoredCoda: anchors?.coda?.[dept]?.value ?? null, anchoredInvoice: anchors?.invoice?.[dept]?.annual ?? null, }; @@ -89,11 +92,15 @@ export function compareDept(before, after, anchorsBefore, anchorsAfter, dept) { const delta = (x, y) => (x === null || y === null ? null : Math.round(y - x)); const groups = [...new Set([...Object.keys(a.groups), ...Object.keys(b.groups)])].map(group => ({ group, - before: { actualCoda: Math.round(a.groups[group]?.actualCoda || 0), avgDailyCoda: Math.round(a.groups[group]?.avgDailyCoda || 0) }, - after: { actualCoda: Math.round(b.groups[group]?.actualCoda || 0), avgDailyCoda: Math.round(b.groups[group]?.avgDailyCoda || 0) }, + before: { actualCoda: Math.round(a.groups[group]?.actualCoda || 0), avgDailyCoda: Math.round(a.groups[group]?.avgDailyCoda || 0), headcount: a.groups[group]?.headcount || 0 }, + after: { actualCoda: Math.round(b.groups[group]?.actualCoda || 0), avgDailyCoda: Math.round(b.groups[group]?.avgDailyCoda || 0), headcount: b.groups[group]?.headcount || 0 }, })); const rows = ['actualCoda', 'avgDailyCoda', 'anchoredCoda', 'invoice', 'anchoredInvoice'].map(key => ({ key, before: a[key] === null ? null : Math.round(a[key]), after: b[key] === null ? null : Math.round(b[key]), delta: delta(a[key], b[key]), })); + // 倍率(兩位小數)與發票佔比(0–1):不四捨五入成整數。 + for (const key of ['multiplier', 'invoiceShare']) { + rows.push({ key, before: a[key], after: b[key], delta: a[key] === null || b[key] === null ? null : b[key] - a[key] }); + } return { dept, rows, groups, anchored: Boolean(anchorsBefore?.active) }; }