diff --git a/CLAUDE.md b/CLAUDE.md index d691efd..435be30 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -201,7 +201,7 @@ If Playwright's browser download fails (CDN returns 403 on this machine), set `P - An override must be ≤ that person's personal cap (`adjustOverPaidMessage`), and the sum of all overrides ≤ the cap (`adjustOverCapMessage`); restoring is never limited. - Allocations keep `system_eligible`. `AllocationTable` shows 「已調整」, the system value and the reason, also on the admin detail (read-only). - The audit action is `settlement.eligible_adjusted`. - - The quota block shows four stats: 計算人數|月上限|補助合計|超額 (no 「每人額度」, no 「可補助總額」; the admin detail keeps 每人額度 in its parameter snapshot). 補助合計 is the personal-cap total (`totalEligible`, live for an open trial; user decision 2026-10-20); 超額 = 補助合計 − cap and turns `text-danger` when it is > 0. The paid total appears only in the allocation table's total row. 「支付金額(當月合計)」 is the person's sum of approved cases. + - The quota block shows four stats: 計算人數|月上限|補助合計|超額 (no 「每人額度」, no 「可補助總額」; the admin detail keeps 每人額度 in its parameter snapshot). 補助合計 is the personal-cap total (`totalEligible`, live for an open trial; user decision 2026-10-20); 超額 = 補助合計 − cap and turns `text-danger` when it is > 0. The paid total appears only in the allocation table's total row, which starts with 「核准人數 N 人」 (`add-approved-count`: the number of allocation rows, i.e. people with approved cases that month, new applicants included; also on the admin detail). 「支付金額(當月合計)」 is the person's sum of approved cases. - `AllocationTable` and the department CSV preview have a 「個人上限(50%)」 column (`settlement_allocations.personal_cap`; rows from before it are null and show 「—」). - The department CSV preview (`department/settlement/export/route.ts`) and the admin approved list share one settlement sheet (`unify-settlement-sheet`, user decision 2026-10-29): `SETTLEMENT_SHEET_COLUMNS` / `departmentSheetRows` / `sheetCells` in `src/lib/settlement-sheet.ts` — 刷卡月份, 發放月份 (card month + 2), 部門, 員工編號, 姓名, 平台, 實際支付金額, 個人可補助上限, 系統計算可補助/部門分配上限, 佔月上限/部門成員補助比例 (final ÷ cap), 最終補助, 尾差調整, then a 「部門合計」 row (format from the user, 2026-10-22). The preview uses `display` cells (NT$ text, same as the page); new applicants leave the calculated columns blank. - The allocation table's 「占月上限」 column (page, admin detail, CSV) is final ÷ cap (`capShareBp`, computed at display time; 「—」 when the cap is 0). The stored `share_bp` is final ÷ cap too (not shown). diff --git a/openspec/changes/archive/2026-11-18-add-approved-count/.openspec.yaml b/openspec/changes/archive/2026-11-18-add-approved-count/.openspec.yaml new file mode 100644 index 0000000..41484f3 --- /dev/null +++ b/openspec/changes/archive/2026-11-18-add-approved-count/.openspec.yaml @@ -0,0 +1,2 @@ +schema: spec-driven +created: 2026-11-18 diff --git a/openspec/changes/archive/2026-11-18-add-approved-count/design.md b/openspec/changes/archive/2026-11-18-add-approved-count/design.md new file mode 100644 index 0000000..0b00539 --- /dev/null +++ b/openspec/changes/archive/2026-11-18-add-approved-count/design.md @@ -0,0 +1,19 @@ +## Context + +`AllocationTable` 的合計列是 `
`,部門月結頁與 `/admin/settlements/:departmentId/:month` 共用。分配明細的每一列就是一位有審核通過案件的申請人(`v.allocations`)。 + +## Goals / Non-Goals + +**Goals:** 合計列一眼看出核准人數。 + +**Non-Goals:** 不加到額度區、CSV 預覽或核定名單匯出;不區分最終補助為 0 的人。 + +## Decisions + +- **人數 = `v.allocations.length`**:與表格列數一致,不另外查詢。新申請人(`newApplicant`)也算,因為他們同樣有審核通過案件;金額部分照舊顯示「待重新計算」。 +- **位置放在合計列第一項**,文字「核准人數」+「N 人」,沿用其他項目的 `dt text-muted` / `dd` 樣式,加 `data-testid="approved-count"`。 +- **名稱用「核准人數」**(使用者用語),與額度區的「計算人數」(人數快照)區分;不改額度區。 + +## Risks / Trade-offs + +- 「核准人數」與「計算人數」名稱相近,可能被誤以為相關 → 兩者位置不同(合計列 vs 額度區),維持現有額度區說明即可。 diff --git a/openspec/changes/archive/2026-11-18-add-approved-count/proposal.md b/openspec/changes/archive/2026-11-18-add-approved-count/proposal.md new file mode 100644 index 0000000..db03e3e --- /dev/null +++ b/openspec/changes/archive/2026-11-18-add-approved-count/proposal.md @@ -0,0 +1,26 @@ +## Why + +部門月結的分配明細合計列只有金額(支付金額合計、個人上限合計、最終補助合計、占月上限合計),主管與管理端要知道這個月有幾個人拿到補助,得自己數表格的列數(使用者要求,2026-11-18)。 + +## What Changes + +- 分配明細合計列最前面新增「核准人數 N 人」:本月有審核通過案件、列在分配明細的人數(一人多筆案件只算一人)。 +- 部門月結頁與管理端月結詳情共用同一張表,兩邊一起出現。 +- 試算後才出現的新申請人(「待重新計算」)也算在內,與表格列數一致。 +- 不改計算、不改 CSV/核定名單匯出、不改額度區的「計算人數」(那是人數快照,不是核准人數)。 + +## Capabilities + +### New Capabilities + +(無) + +### Modified Capabilities + +- `department-settlement`:「分配明細與尾差說明」的合計列加上核准人數。 + +## Impact + +- `src/app/(app)/department/settlement/allocation-table.tsx`(合計列) +- 元件測試與 e2e(`tests/e2e/` 月結相關 spec) +- 無資料庫、API 或權限變更 diff --git a/openspec/changes/archive/2026-11-18-add-approved-count/specs/department-settlement/spec.md b/openspec/changes/archive/2026-11-18-add-approved-count/specs/department-settlement/spec.md new file mode 100644 index 0000000..c974a5c --- /dev/null +++ b/openspec/changes/archive/2026-11-18-add-approved-count/specs/department-settlement/spec.md @@ -0,0 +1,20 @@ +## MODIFIED Requirements + +### Requirement: 分配明細與尾差說明 +部門月結頁 SHALL 列出每位申請人的姓名、平台、支付金額(當月合計:該申請人當月所有審核通過案件的台幣金額總和)、個人上限(50%:各筆台幣金額 50% 無條件捨去後加總)、個人可補助、占月上限(最終補助 ÷ 部門月上限,小數兩位百分比;月上限為 0 時顯示「—」)與最終補助,並顯示合計列(依序為核准人數、支付金額合計、個人上限合計、最終補助合計與占月上限合計)。核准人數 SHALL 等於分配明細列出的人數(當月有審核通過案件的申請人,一人多筆只算一人;試算後才出現、待重新計算的申請人也計入),管理端月結詳情的分配明細同樣顯示。若有申請人因平分的零頭加 1 元,頁面 SHALL 說明零頭規則並標示該申請人。 + +#### Scenario: 顯示分配明細 +- **WHEN** 月上限 NT$1,000,A 當月兩筆審核通過案件 NT$500 與 NT$399、B 一筆 NT$1,700 +- **THEN** 明細列出 A 支付金額 NT$899、個人上限 NT$449、個人可補助 NT$449、占月上限 44.90%,B 支付金額 NT$1,700、個人上限 NT$850、個人可補助 NT$551、占月上限 55.10%,合計核准人數 2 人、支付 NT$2,599、個人上限 NT$1,299、最終 NT$1,000、占月上限 100.00% + +#### Scenario: 待重新計算的申請人計入核准人數 +- **WHEN** 試算後 C 的案件才審核通過,C 在明細顯示「待重新計算」,明細共 3 人 +- **THEN** 合計列顯示核准人數 3 人 + +#### Scenario: 尾差標示 +- **WHEN** 平分的零頭依員工編號給某位申請人加 1 元 +- **THEN** 該列標示「含尾差調整 +1」,頁面說明零頭依員工編號由小到大每人加 1 元 + +#### Scenario: 未超額時的占月上限 +- **WHEN** 月上限 NT$1,000,A 最終 NT$200、B 最終 NT$300 +- **THEN** A 占月上限 20.00%、B 30.00%,合計 50.00% diff --git a/openspec/changes/archive/2026-11-18-add-approved-count/tasks.md b/openspec/changes/archive/2026-11-18-add-approved-count/tasks.md new file mode 100644 index 0000000..8719890 --- /dev/null +++ b/openspec/changes/archive/2026-11-18-add-approved-count/tasks.md @@ -0,0 +1,10 @@ +## 1. 合計列 + +- [x] 1.1 `allocation-table.tsx` 合計列最前面加「核准人數 N 人」(`v.allocations.length`,`data-testid="approved-count"`) +- [x] 1.2 元件或整合測試:兩位申請人(其中一人兩筆案件)→ 顯示「2 人」;新申請人也計入 + +## 2. E2E 與文件 + +- [x] 2.1 部門月結 e2e 斷言合計列有核准人數;管理端月結詳情同樣顯示 +- [x] 2.2 CLAUDE.md 部門月結段落補一句合計列含核准人數 +- [x] 2.3 lint、typecheck、`npm test`、相關 e2e 通過 diff --git a/openspec/specs/department-settlement/spec.md b/openspec/specs/department-settlement/spec.md index 4156b79..ef2866e 100644 --- a/openspec/specs/department-settlement/spec.md +++ b/openspec/specs/department-settlement/spec.md @@ -47,11 +47,15 @@ - **THEN** 超額顯示 NT$5,899(NT$32,899 − NT$27,000),不因調整改變 ### Requirement: 分配明細與尾差說明 -部門月結頁 SHALL 列出每位申請人的姓名、平台、支付金額(當月合計:該申請人當月所有審核通過案件的台幣金額總和)、個人上限(50%:各筆台幣金額 50% 無條件捨去後加總)、個人可補助、占月上限(最終補助 ÷ 部門月上限,小數兩位百分比;月上限為 0 時顯示「—」)與最終補助,並顯示合計列(含個人上限合計與占月上限合計)。若有申請人因平分的零頭加 1 元,頁面 SHALL 說明零頭規則並標示該申請人。 +部門月結頁 SHALL 列出每位申請人的姓名、平台、支付金額(當月合計:該申請人當月所有審核通過案件的台幣金額總和)、個人上限(50%:各筆台幣金額 50% 無條件捨去後加總)、個人可補助、占月上限(最終補助 ÷ 部門月上限,小數兩位百分比;月上限為 0 時顯示「—」)與最終補助,並顯示合計列(依序為核准人數、支付金額合計、個人上限合計、最終補助合計與占月上限合計)。核准人數 SHALL 等於分配明細列出的人數(當月有審核通過案件的申請人,一人多筆只算一人;試算後才出現、待重新計算的申請人也計入),管理端月結詳情的分配明細同樣顯示。若有申請人因平分的零頭加 1 元,頁面 SHALL 說明零頭規則並標示該申請人。 #### Scenario: 顯示分配明細 - **WHEN** 月上限 NT$1,000,A 當月兩筆審核通過案件 NT$500 與 NT$399、B 一筆 NT$1,700 -- **THEN** 明細列出 A 支付金額 NT$899、個人上限 NT$449、個人可補助 NT$449、占月上限 44.90%,B 支付金額 NT$1,700、個人上限 NT$850、個人可補助 NT$551、占月上限 55.10%,合計支付 NT$2,599、個人上限 NT$1,299、最終 NT$1,000、占月上限 100.00% +- **THEN** 明細列出 A 支付金額 NT$899、個人上限 NT$449、個人可補助 NT$449、占月上限 44.90%,B 支付金額 NT$1,700、個人上限 NT$850、個人可補助 NT$551、占月上限 55.10%,合計核准人數 2 人、支付 NT$2,599、個人上限 NT$1,299、最終 NT$1,000、占月上限 100.00% + +#### Scenario: 待重新計算的申請人計入核准人數 +- **WHEN** 試算後 C 的案件才審核通過,C 在明細顯示「待重新計算」,明細共 3 人 +- **THEN** 合計列顯示核准人數 3 人 #### Scenario: 尾差標示 - **WHEN** 平分的零頭依員工編號給某位申請人加 1 元 diff --git a/src/app/(app)/department/settlement/allocation-table.test.tsx b/src/app/(app)/department/settlement/allocation-table.test.tsx new file mode 100644 index 0000000..9d6c4b1 --- /dev/null +++ b/src/app/(app)/department/settlement/allocation-table.test.tsx @@ -0,0 +1,72 @@ +// @vitest-environment jsdom +import { cleanup, render, screen } from "@testing-library/react"; +import { afterEach, describe, expect, it, vi } from "vitest"; +import type { AllocationRow, SettlementView } from "@/server/settlement/service"; + +vi.mock("./adjust-eligible", () => ({ AdjustEligible: () => null })); +const { AllocationTable } = await import("./allocation-table"); + +afterEach(cleanup); + +function row(userId: number, name: string, paid: number, extra: Partial = {}) { + const cap = Math.floor(paid / 2); + return { + userId, + name, + employeeNo: `E${userId}`, + platforms: "Claude", + paidTotal: paid, + personalCap: cap, + personalEligible: cap, + systemEligible: cap, + adjustment: null, + shareBp: 0, + finalAmount: cap, + remainderAdjustment: 0, + stale: false, + newApplicant: false, + overPaid: false, + ...extra, + } satisfies AllocationRow; +} + +function view(allocations: AllocationRow[]): SettlementView { + return { + departmentId: 1, + month: "2026-10", + status: "open", + ratePercent: 50, + cap: 1000, + paidTotal: allocations.reduce((s, a) => s + a.paidTotal, 0), + finalTotal: allocations.reduce((s, a) => s + a.finalAmount, 0), + allocations, + } as unknown as SettlementView; +} + +describe("AllocationTable 合計列", () => { + it("第一項顯示核准人數(明細列數;一人多筆合併為一列只算一人)", () => { + // 甲兩筆案件合計 899 → 明細一列 + render(); + const total = screen.getByTestId("allocation-total"); + expect(total.querySelector("dt")?.textContent).toBe("核准人數"); + expect(screen.getByTestId("approved-count").textContent).toBe("2 人"); + }); + + it("待重新計算的新申請人也計入", () => { + render( + , + ); + expect(screen.getByTestId("approved-count").textContent).toBe("3 人"); + }); + + it("沒有核准案件時不顯示合計列", () => { + render(); + expect(screen.queryByTestId("approved-count")).toBeNull(); + }); +}); diff --git a/src/app/(app)/department/settlement/allocation-table.tsx b/src/app/(app)/department/settlement/allocation-table.tsx index a445b99..6a43510 100644 --- a/src/app/(app)/department/settlement/allocation-table.tsx +++ b/src/app/(app)/department/settlement/allocation-table.tsx @@ -11,7 +11,7 @@ import { AdjustEligible } from "./adjust-eligible"; /** * 分配明細(部門月結頁與管理端詳情共用):姓名、平台、支付金額、個人上限(支付金額 × 補助比例,逐筆取整)、 * 個人可補助、占月上限(最終 ÷ 月上限)、最終補助, - * 合計列與尾差說明。提交前的金額標示「預估」,提交後標示「最終」。 + * 合計列(核准人數=明細列數、各項金額合計)與尾差說明。提交前的金額標示「預估」,提交後標示「最終」。 * 主管調整過的個人可補助標示「已調整」與系統計算值、原因;`adjustable`(部門月結頁、未提交)時可調整與還原。 */ export function AllocationTable({ @@ -133,6 +133,12 @@ export function AllocationTable({ data-testid="allocation-total" className="mt-4 flex flex-wrap justify-end gap-x-6 gap-y-1 border-t border-border pt-4" > +
+
核准人數
+
+ {v.allocations.length} 人 +
+
支付金額合計
diff --git a/tests/e2e/settlement.spec.ts b/tests/e2e/settlement.spec.ts index af5ee38..7e4a625 100644 --- a/tests/e2e/settlement.spec.ts +++ b/tests/e2e/settlement.spec.ts @@ -84,6 +84,14 @@ test("預設最早未提交月份;額度卡(無每人額度、可補助總 await expect(row(page, "乙員工")).toContainText("55.00%"); await expect(row(page, "乙員工")).toContainText("NT$550"); const total = page.getByTestId("allocation-total"); + await expect(total.locator("dt")).toHaveText([ + "核准人數", + "支付金額合計", + "個人上限合計", + "最終補助合計", + "占月上限合計", + ]); + await expect(page.getByTestId("approved-count")).toHaveText("2 人"); await expect(total).toContainText("支付金額合計NT$2,600"); await expect(total).toContainText("個人上限合計NT$1,300"); await expect(total).toContainText("NT$1,000"); @@ -169,6 +177,8 @@ test("已存試算後再核准:支付金額即時更新並提示重新計算 await expect(row(page, "庚員工")).toContainText("NT$300"); await expect(row(page, "庚員工")).toContainText("待重新計算"); await expect(page.getByTestId("allocation-total")).toContainText("支付金額合計NT$4,400"); + // 待重新計算的新申請人也計入核准人數 + await expect(page.getByTestId("approved-count")).toHaveText("3 人"); await expect(page.getByTestId("subsidy-total")).toContainText("NT$2,200"); await expect(page.getByTestId("allocation-total")).toContainText("個人上限合計NT$2,200"); // 超額隨個人上限即時更新(2,200 − 1,000),不必等重新計算 @@ -367,6 +377,7 @@ test("超額紅色且不受調整影響;手動調整個人可補助(原因 .getByRole("row") .filter({ hasText: "乙員工" }); await expect(adminRow).toContainText("已調整"); + await expect(adminPage.getByTestId("approved-count")).toHaveText("2 人"); await expect(adminPage.getByRole("button", { name: /^調整 / })).toHaveCount(0); await admin.close();