- 서버 master_equation.subtotals — 호표 줄(하위 로직 블록 한 줄씩 · 자원 · 덧줄)의 버린 줄 비목 + 끝수(합계 − 줄 합) - 부품 ui_template_equation_sum — 줄 이음 아래 소계 표(M01 · M02 수식 탭 같이) - 시험 test_799_1_subtotals — 줄 합 + 끝수 = 합계 · 합계 = 엔진 끝수 입힌 비목 합(전후 같음) Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
48 lines
2.3 KiB
TypeScript
48 lines
2.3 KiB
TypeScript
/* =============================================================================
|
|
* ui_template_equation_sum.ts
|
|
* 부품 「수식」 셋째 파일(799-1 · 요구 655-1 · 요구서_655 2 장 4) — 단가산출 소계 · 합계(보이기만 · 금액 셈 그대로).
|
|
* 표 = 줄(하위 로직 블록마다 한 줄 · 자기 자원 · 덧줄) × 노무비 · 재료비 · 경비 · 계 → 합계(엔진 비목 합) → 끝수(합계 − 줄 합)
|
|
* 값 = 서버 `소계`(`master_equation.subtotals` · 버린 줄 비목 0.1 원) · 끝수가 0 이면 줄을 안 그림 · 소계가 없으면(결과 로직) 아무것도 안 그림
|
|
* 쓰는 법 = `createEqSum(tree)` → 요소 | null — 줄 이음(`createEqChain`) 아래에 붙임
|
|
* ========================================================================== */
|
|
|
|
import { eqText, type EqTree } from "./ui_template_equation";
|
|
|
|
const COLS = ["노무비", "재료비", "경비", "계"] as const;
|
|
const KIND: Record<string, string> = { 자원: "자기 자원", 덧줄: "덧줄" };
|
|
|
|
const node = (tag: "div" | "span", className: string, text = ""): HTMLElement => {
|
|
const out = document.createElement(tag);
|
|
out.className = className;
|
|
if (text) out.textContent = text;
|
|
return out;
|
|
};
|
|
|
|
function row(kind: string, name: string, get: (k: (typeof COLS)[number]) => unknown): HTMLElement {
|
|
const line = node("div", "ui-eq__sum-row");
|
|
line.dataset.eqSumKind = kind;
|
|
line.append(node("span", "ui-eq__sum-name", name));
|
|
for (const k of COLS) {
|
|
const cell = node("span", "ui-eq__sum-cell", eqText(get(k)) || "0");
|
|
cell.dataset.eqSumCol = k;
|
|
line.append(cell);
|
|
}
|
|
return line;
|
|
}
|
|
|
|
export function createEqSum(tree: Pick<EqTree, "합계" | "소계">): HTMLElement | null {
|
|
const sub = tree.소계;
|
|
if (!sub?.줄.length) return null;
|
|
const box = node("div", "ui-eq__sum");
|
|
box.dataset.eqSum = "";
|
|
const head = node("div", "ui-eq__sum-row ui-eq__sum-head");
|
|
head.append(node("span", "ui-eq__sum-name", "소계"));
|
|
for (const k of COLS) head.append(node("span", "ui-eq__sum-cell", k));
|
|
box.append(head);
|
|
for (const r of sub.줄) box.append(row(r.갈래, KIND[r.갈래] ?? r.이름, (k) => r[k]));
|
|
const rest = sub.끝수;
|
|
if (COLS.some((k) => Number(rest[k] ?? 0) !== 0)) box.append(row("끝수", "끝수", (k) => rest[k]));
|
|
box.append(row("합계", "합계", (k) => tree.합계[k]));
|
|
return box;
|
|
}
|