/* ============================================================================= * M01_MasterData_UI_MachineImpact.ts * M01 기계 정본 저장 전 영향 확인창(PLAN 848-5 · 요구서 889 6 장) — 페이지 [저장] 이 저장 전에 부름. * 기계 줄 값 고침이 없으면 묻지 않음 · 서버가 셈(`/m01/machine/impact` — 쓰기 없음): * 쓰는 기초(직접 · 부름 사슬) · 그 칸을 따로 고쳐 두어 안 바뀌는 곳 · 쓰는 단가산출(프로젝트 안 = 안 바뀜) * · 금액이 바뀌는 기초 수 · 가장 크게 바뀌는 다섯(전 → 후) → [저장] / [취소]. * 부품 = 확인창(`askConfirm` detail) · 값 목록 · 표 · 글. * ========================================================================== */ import { createDataTable } from "@ui/ui_template_data_table"; import { createKv } from "@ui/ui_template_kv"; import { askConfirm } from "@ui/ui_template_modal"; import { createText } from "@ui/ui_template_text"; import { el } from "@ui/ui_template_elements"; import type { FileChanges } from "./M01_MasterData_Api_Fetch"; import { fetchMachineImpact, type MachineImpact } from "./M01_MasterData_Machine_Api"; const MACHINE_FILE = "기계.json"; const n = (v: number): string => v.toLocaleString("ko-KR"); /** 저장해도 되면 true — 기계 값 고침이 없거나 [저장] 을 누름 */ export async function confirmMachineImpact(files: FileChanges[]): Promise { const part = files.find((f) => f.file === MACHINE_FILE); if (!part?.changes.some((c) => c.op === "edit")) return true; let got: MachineImpact; try { got = await fetchMachineImpact([part]); } catch (error) { return askConfirm({ title: "기계 정본 고침", message: `영향을 셀 수 없음 — ${error instanceof Error ? error.message : ""} · 그래도 저장`, okLabel: "저장", }); } if (!got.기계.length) return true; return askConfirm({ title: "기계 정본 고침 — 영향 확인", message: "이 기계 값은 쓰는 모든 곳에 걸림 — 아래를 보고 저장", okLabel: "저장", cancelLabel: "취소", detail: impactView(got), }); } function impactView(got: MachineImpact): HTMLElement { const machines = got.기계.map((m) => { const sk = m.단가산출; const all = sk.마스터 + sk.회사 + sk.개인 + sk.프로젝트; return el("div", { className: "m01-machine-impact__one", children: [ el("strong", { text: `${m.이름} ${m.규격 ?? ""} — 바뀐 칸: ${m.칸.join(" · ")}` }), createKv([ { label: "쓰는 기초", value: `${n(m.직접 + m.사슬)} 개(직접 ${n(m.직접)} · 부름 사슬 ${n(m.사슬)})`, }, { label: "따로 고쳐 두어 안 바뀌는 곳", value: `${n(m.고침.기초 + m.고침.단가산출 + m.고침.위층)} 곳(기초 ${n(m.고침.기초)} · 단가산출 내 고침 ${n(m.고침.단가산출)} · 위 층 고침 ${n(m.고침.위층)})`, }, { label: "쓰는 단가산출", value: `${n(all)} 개(프로젝트 안 ${n(sk.프로젝트)} 개는 안 바뀜)`, }, ]), ], }); }); const table = createDataTable({ caption: "가장 크게 바뀌는 기초", columns: [ { key: "키", label: "기초", width: 72 }, { key: "이름", label: "이름", width: 170 }, { key: "단위", label: "단위", width: 70 }, { key: "전", label: "전", kind: "number", width: 80 }, { key: "후", label: "후", kind: "number", width: 80 }, { key: "율", label: "바뀜 %", kind: "number", decimals: 2, width: 60 }, ], rows: got.위.map((r) => ({ ...r, 율: r.전 && r.후 !== null ? ((r.후 - r.전) / Math.abs(r.전)) * 100 : null, })), empty: "-", }); return el("div", { className: "m01-machine-impact", children: [ ...machines, createText( `금액이 바뀌는 기초 ${n(got.바뀜)} 개(기본 옵션으로 ${n(got.셈)} 개 다시 셈)`, got.바뀜 ? "warning" : "muted", ), ...(got.위.length ? [table.root] : []), ], }); }