/* ============================================================================= * M02_MasterTemplete_Labor_LogicMats.ts * 자재목록 표의 로직 자재 줄(103-1) — 담은 로직 맨 위 층 재료 줄(서버 calc `줄[].재료`) · 사용자 자재 줄과 같은 칸 * (코드 · 이름 · 규격 · 수량 · 단위 · 가격 다섯 · 단가 / 금액) · 사용자 자재 앞. * · 보기만(856-3 — 로직 줄 창 · [바꾸기] · [기본] · 세 칸 고침 걷음 · 일위대가 면적 보기 `Labor_View` 가 씀) * · 금액은 로직 단가 안이라 합에 다시 안 더함 · 수량은 로직 것 · 하위 로직 안 재료는 안 보임(엔진이 맨 위 층만 고름) * ========================================================================== */ import { el } from "@ui/ui_template_elements"; import { formatMoney } from "../common_util/common_util_money"; import type { LaborCalc, LaborRow } from "./M02_MasterTemplete_Labor_Api"; import { lineId } from "./M02_MasterTemplete_Labor_Calc"; import { markCells } from "./M02_MasterTemplete_Labor_MatMarks"; import { moneyCell, PRICE_SLOTS } from "./M02_MasterTemplete_Labor_Rows"; import { tc } from "./M02_MasterTemplete_Labor_Text"; import type { LogicMat } from "./M02_Labor_LogicMats_Model"; const num = (v: number | null): string => v === null ? "—" : Number(v.toPrecision(12)).toLocaleString("ko-KR", { maximumFractionDigits: 6 }); /** 담은 로직 차례대로 그 줄 로직 자재 — calc 답이 없으면 빈 것(답이 오면 다시 그림) */ export function logicMatRows( rows: LaborRow[], calc: LaborCalc | null, wait: boolean, ): HTMLElement[] { return rows.flatMap((row) => { const line = row.참조 ? undefined : calc?.줄.find((l) => lineId(l) === lineId(row)); return (line?.재료 ?? []).map((mat) => matRow(row, mat, wait)); }); } function matRow(row: LaborRow, mat: LogicMat, wait: boolean): HTMLElement { const item = mat.품목; const name = item?.이름 ?? mat.이름; const owner = `${row.별칭 ?? row.로직} · ${mat.이름}`; const priceCell = (slot: (typeof PRICE_SLOTS)[number]): HTMLElement => { const base = !!item?.값칸 && item.값칸 === slot; const v = mat.가격?.[slot]; return el("td", { className: `m02-labrow__num m02-labrow__price${base ? " is-base-price" : ""}`, text: wait ? "…" : v === null || v === undefined ? "—" : formatMoney(v), attrs: { "data-label": slot, "data-price-slot": slot }, }); }; const money = moneyCell(mat.단가, mat.금액, wait, tc("Labor_AppliedSum")); money.title = tc("LogicMat_Inside"); return el("tr", { className: `m02-labrow__row m02-labrow__logic-mat${mat.고름 ? " is-picked-mat" : ""}`, attrs: { "data-labor-logic-mat": `${row.로직}|${mat.차례}` }, children: [ el("td", { className: "m02-labrow__code", text: item?.키 ?? "—" }), el("td", { className: "m02-labrow__name", children: [ el("strong", { text: name, attrs: { title: name } }), el("small", { className: "m02-labrow__key", text: mat.고름 ? `${owner} · ${tc("LogicMat_Picked")}` : owner, attrs: { title: owner }, }), ...(mat.까닭 ? [el("small", { className: "ui-text ui-text--error", text: mat.까닭 })] : []), ], }), el("td", { className: "m02-labrow__spec", text: item?.규격 ?? "", attrs: { title: item?.규격 ?? "" }, }), el("td", { className: "m02-labrow__qty", text: wait ? "…" : num(mat.수량), attrs: { "data-label": tc("Labor_QtyCol") }, }), el("td", { className: "m02-labrow__unit", text: mat.단위, attrs: { "data-label": tc("Labor_Unit") }, }), ...markCells(row.자재표시?.[String(mat.차례)] ?? {}), ...PRICE_SLOTS.map(priceCell), money, ], }); }