122 lines
4.1 KiB
TypeScript
122 lines
4.1 KiB
TypeScript
import type { VMState } from "../index.js";
|
|
import type { PayslipMatchConfidence } from "./payslip-match.js";
|
|
|
|
/**
|
|
* HR payslip view-models (AK-P17b). Pure functions. Own list (PDF open marks
|
|
* read), admin list, and the bulk-upload match preview (hard/soft/none with a
|
|
* color-confidence key). No React, no Prisma, no app imports.
|
|
*/
|
|
|
|
export interface HrPayslipRow {
|
|
readonly id: string;
|
|
readonly periodLabel: string;
|
|
readonly periodYear: number;
|
|
readonly periodMonth: number;
|
|
readonly isRead: boolean;
|
|
readonly openHref: string;
|
|
}
|
|
|
|
export interface HrPayslipOwnData {
|
|
readonly rows: readonly HrPayslipRow[];
|
|
readonly emptyHeadlineKey: string;
|
|
readonly emptyBodyKey: string;
|
|
}
|
|
|
|
export type HrPayslipOwnVM = VMState<HrPayslipOwnData>;
|
|
|
|
export interface HrPayslipAdminRow extends HrPayslipRow {
|
|
readonly employeeLabel: string;
|
|
readonly uploadedByLabel: string;
|
|
}
|
|
|
|
export interface HrPayslipAdminData {
|
|
readonly rows: readonly HrPayslipAdminRow[];
|
|
readonly uploadHref: string;
|
|
readonly emptyHeadlineKey: string;
|
|
readonly emptyBodyKey: string;
|
|
}
|
|
|
|
export type HrPayslipAdminVM = VMState<HrPayslipAdminData>;
|
|
|
|
export interface HrPayslipMatchRow {
|
|
readonly fileId: string;
|
|
readonly fileName: string;
|
|
readonly confidence: PayslipMatchConfidence;
|
|
/** i18n key for the confidence badge, e.g. `hr.payslips.match.confidence.hard`. */
|
|
readonly confidenceKey: string;
|
|
/** Color token for the confidence badge (UI maps to its palette). */
|
|
readonly confidenceTone: "success" | "warning" | "neutral";
|
|
readonly employeeUserId: string | null;
|
|
readonly employeeLabel: string | null;
|
|
readonly candidateUserIds: readonly string[];
|
|
}
|
|
|
|
export interface HrPayslipMatchPreviewData {
|
|
readonly rows: readonly HrPayslipMatchRow[];
|
|
readonly hardCount: number;
|
|
readonly softCount: number;
|
|
readonly noneCount: number;
|
|
readonly emptyHeadlineKey: string;
|
|
readonly emptyBodyKey: string;
|
|
}
|
|
|
|
export type HrPayslipMatchPreviewVM = VMState<HrPayslipMatchPreviewData>;
|
|
|
|
function monthLabel(year: number, month: number): string {
|
|
// Plain numeric period (e.g. "2026-07"); locale month names are the UI's job.
|
|
return `${year}-${String(month).padStart(2, "0")}`;
|
|
}
|
|
|
|
export function buildHrPayslipOwnVM(input: { rows: ReadonlyArray<Omit<HrPayslipRow, "periodLabel">> }): HrPayslipOwnVM {
|
|
return {
|
|
status: "ready",
|
|
data: {
|
|
rows: input.rows.map((row) => ({ ...row, periodLabel: monthLabel(row.periodYear, row.periodMonth) })),
|
|
emptyHeadlineKey: "hr.payslips.own.empty.headline",
|
|
emptyBodyKey: "hr.payslips.own.empty.body",
|
|
},
|
|
};
|
|
}
|
|
|
|
export function buildHrPayslipAdminVM(input: { rows: ReadonlyArray<Omit<HrPayslipAdminRow, "periodLabel">>; uploadHref: string }): HrPayslipAdminVM {
|
|
return {
|
|
status: "ready",
|
|
data: {
|
|
rows: input.rows.map((row) => ({ ...row, periodLabel: monthLabel(row.periodYear, row.periodMonth) })),
|
|
uploadHref: input.uploadHref,
|
|
emptyHeadlineKey: "hr.payslips.admin.empty.headline",
|
|
emptyBodyKey: "hr.payslips.admin.empty.body",
|
|
},
|
|
};
|
|
}
|
|
|
|
const CONFIDENCE_TONE: Record<PayslipMatchConfidence, "success" | "warning" | "neutral"> = { hard: "success", soft: "warning", none: "neutral" };
|
|
|
|
export interface HrPayslipMatchInputRow {
|
|
readonly fileId: string;
|
|
readonly fileName: string;
|
|
readonly confidence: PayslipMatchConfidence;
|
|
readonly employeeUserId: string | null;
|
|
readonly employeeLabel: string | null;
|
|
readonly candidateUserIds: readonly string[];
|
|
}
|
|
|
|
export function buildHrPayslipMatchPreviewVM(input: { rows: readonly HrPayslipMatchInputRow[] }): HrPayslipMatchPreviewVM {
|
|
const rows: HrPayslipMatchRow[] = input.rows.map((row) => ({
|
|
...row,
|
|
confidenceKey: `hr.payslips.match.confidence.${row.confidence}`,
|
|
confidenceTone: CONFIDENCE_TONE[row.confidence],
|
|
}));
|
|
return {
|
|
status: "ready",
|
|
data: {
|
|
rows,
|
|
hardCount: rows.filter((r) => r.confidence === "hard").length,
|
|
softCount: rows.filter((r) => r.confidence === "soft").length,
|
|
noneCount: rows.filter((r) => r.confidence === "none").length,
|
|
emptyHeadlineKey: "hr.payslips.match.empty.headline",
|
|
emptyBodyKey: "hr.payslips.match.empty.body",
|
|
},
|
|
};
|
|
}
|