Merge origin/sub_laptop_7 into sub_laptop_8 — PLAN 704-4 규격 표 1차 · M02 일위대가 셈 짝 머리 설명 겹침 양쪽 살림(705-1 고정 줄 · 704-4 규격 열)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -86,10 +86,11 @@ def now_text() -> str:
|
||||
|
||||
|
||||
def same_item(manifest: Any, item: dict[str, Any]) -> bool:
|
||||
"""같은 항목 · 같은 규격 열(704-4 · 열이 바뀌면 다른 사본 · 덮개는 폴더 열쇠라 그대로 남음)."""
|
||||
origin = manifest.get("원본") if isinstance(manifest, dict) else None
|
||||
if not isinstance(origin, dict):
|
||||
return False
|
||||
return all(origin.get(k) == item.get(k) for k in ("layer", "owner", "key"))
|
||||
return all(origin.get(k) == item.get(k) for k in ("layer", "owner", "key", "spec"))
|
||||
|
||||
|
||||
def origin_of(item: dict[str, Any]) -> dict[str, Any]:
|
||||
@@ -142,6 +143,9 @@ def write_snapshot(target: Path, item: dict[str, Any], owner_id: str, extra: dic
|
||||
atomic_write_json(target / name, content)
|
||||
stamp = now_text()
|
||||
source = version_of(source_files(files))
|
||||
spec = ((files.get(LABOR_FILE) or {}).get("줄") or {}).get("규격") # 굳힌 규격 열(704-4)
|
||||
if isinstance(spec, dict):
|
||||
extra = {**extra, "규격": {"이름": spec.get("이름"), "열": spec.get("기본")}}
|
||||
manifest = {
|
||||
"원본": origin_of(item),
|
||||
"판": source,
|
||||
|
||||
@@ -2,7 +2,8 @@
|
||||
|
||||
모으는 것 = `{파일 이름: 내용}`:
|
||||
`집계.json` SS 줄 + 열 정의 · `도면.json` SD · `면적.json` SA ·
|
||||
`일위대가.json` = 층 `labor/<열id>.json` 문서(39-1c · 없으면 옛 UA 조합 줄)
|
||||
`일위대가.json` = 층 `labor/<열id>.json` 문서(39-1c · 없으면 옛 UA 조합 줄 ·
|
||||
규격 열 = summary_item `spec` 열 수량을 손으로 굳힘 · 704-4)
|
||||
+ 담은 로직 줄(M01 시스템) + 알약(가져온 때 그대로) +
|
||||
참조사본(단가승격 · 사전조합을 값으로 굳힘) ·
|
||||
`단가.json` 계산에 닿는 마스터 줄 전부(담은 로직 + 일위대가 자재 MT)
|
||||
@@ -146,7 +147,9 @@ def build_source(item: dict[str, Any]) -> dict[str, Any]:
|
||||
files[name] = part
|
||||
doc = read_json(root / LABOR_KIND / f"{column_id}.json") if column_id else None
|
||||
if isinstance(doc, dict):
|
||||
labor = labor_doc_rows(doc)
|
||||
from M02_MasterTemplete import M02_Labor_Spec as labor_spec
|
||||
|
||||
labor = labor_doc_rows(labor_spec.freeze(doc, item.get("spec"))) # 고른 규격 열(704-4)
|
||||
else:
|
||||
labor = labor_rows(str(row["일위대가"])) if row.get("일위대가") else None
|
||||
if labor is not None:
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
분모 = 그 문서 단위 · 배 1 · 알약 키 = `ref_id` · 같은 참조 두 번 금지 · 위 층만.
|
||||
짝(CLAUDE.md 5장 ①): 수량 · 반영 · 합 `settle` ↔ `M02_MasterTemplete_Labor_Calc.ts` —
|
||||
거울 시험 `resources/tester/test_m02_labor_calc_mirror.py`.
|
||||
규격 열(704-4) = 문서 `규격?` 칸 · 열마다 줄 수량(`M02_Labor_Spec` · settle `col`) · 계산값 `규격합`.
|
||||
로직 자재(103-1) = 담은 로직 맨 위 층 호표 재료 줄(`logic_mats` · 줄마다 `재료`) ·
|
||||
고름 = `{호표 차례: MT키}`(엔진 `choosing` 그대로) · 금액은 로직 재료비 안이라 합 · 알약에 안 더함(보기만) · 사용자 자재와
|
||||
같은 품목 두 번은 [저장] 때 400.
|
||||
@@ -42,6 +43,7 @@ from M01_MasterData import M01_MasterData_Store_Combo as combo_store
|
||||
from M02_MasterTemplete import M02_Labor_Fixed as fixed
|
||||
from M02_MasterTemplete import M02_Labor_Inputs as labor_inputs
|
||||
from M02_MasterTemplete import M02_Labor_Ref as refs
|
||||
from M02_MasterTemplete import M02_Labor_Spec as spec
|
||||
from M02_MasterTemplete import M02_MasterTemplete_Store as store
|
||||
from M02_MasterTemplete import M02_Material_Own as own
|
||||
|
||||
@@ -192,7 +194,11 @@ def clean(doc: Any) -> dict[str, Any]:
|
||||
}
|
||||
if doc.get("일위대가번"):
|
||||
out["일위대가번"] = doc["일위대가번"]
|
||||
return out
|
||||
try: # 규격 열(704-4 · `M02_Labor_Spec`) — 없으면 칸 없음(옛 문서)
|
||||
cols = spec.clean(doc.get("규격"), {spec.line_key(x) for x in [*lines, *mats]})
|
||||
except spec.SpecError as e:
|
||||
raise _bad(str(e)) from e
|
||||
return {**out, "규격": cols} if cols else out
|
||||
|
||||
|
||||
def _alias(alias: Any, where: str) -> str | None:
|
||||
@@ -424,9 +430,10 @@ def line_id(one: dict) -> Any:
|
||||
return refs.ref_id(one["참조"]) if _is_ref(one) else one.get("로직")
|
||||
|
||||
|
||||
def settle(result: dict, doc: dict, given: dict[str, Any]) -> dict[str, Any]:
|
||||
def settle(result: dict, doc: dict, given: dict[str, Any], col: Any = None) -> dict[str, Any]:
|
||||
"""기준이 선 계산 답에 수량 · 반영 · 합을 채움 — 수량만 바뀌면 이것만 다시
|
||||
(짝: `Labor_Calc.ts` `settle` · 자재 = 재료비)."""
|
||||
(짝: `Labor_Calc.ts` `settle` · 자재 = 재료비 · `col` = 규격 열 · 없으면 기본 · 704-4)."""
|
||||
doc = spec.at(doc, col)
|
||||
have = {str(k): v for k, raw in given.items() if (v := _number(raw)) is not None}
|
||||
hands = {line_id(one): one.get("수량") for one in doc.get("담은로직") or []}
|
||||
mhands = {one.get("코드"): one.get("수량") for one in doc.get("자재") or []}
|
||||
@@ -658,7 +665,14 @@ def server(doc: Any) -> dict[str, Any]:
|
||||
got = clean(doc)
|
||||
out = calc(got)
|
||||
no_twice(got, out)
|
||||
return {**got, "계산값": out}
|
||||
return {**got, "계산값": {**out, **spec_sums(got, out)}}
|
||||
|
||||
|
||||
def spec_sums(doc: dict, out: dict) -> dict[str, Any]:
|
||||
"""규격 열마다 반영합(704-4 · 고르기 창 열 단추) `{규격합: {열: 합}}` — 규격 없음 = 빈 것."""
|
||||
cols = (doc.get("규격") or {}).get("열") or []
|
||||
have = spec.given_of(out)
|
||||
return {"규격합": {c: settle(out, doc, have, c)["반영합"] for c in cols}} if cols else {}
|
||||
|
||||
|
||||
def no_twice(got: dict, out: dict) -> None:
|
||||
|
||||
@@ -0,0 +1,184 @@
|
||||
"""일위대가 규격 열(PLAN 704-4) — 문서 `규격` 칸 검사 · 열 끼우기 · 사본 굳히기 · 쓰는 사본 찾기.
|
||||
|
||||
규격 = `{이름: "H", 열: ["1.5", "2.0"], 기본: "2.0", 수량: {줄 id: {열: 수}}}` —
|
||||
줄 id = 로직 키 · 참조 `ref_id`(`M02_Labor_Doc.line_id`) · 자재 코드.
|
||||
규격 수량이 있는 줄 = 고른 열 값이 `{손}` 자리 · 없는 줄 · 빈 열 = 문서 `수량` 그대로(공통).
|
||||
규격 없음 = 옛 문서(열 하나 · 셈 그대로 · 옮김 없음).
|
||||
짝(CLAUDE.md 5장 ①): `at` ↔ `M02_MasterTemplete_Labor_Calc.ts` `atSpec` —
|
||||
거울 시험 `resources/tester/test_m02_labor_calc_mirror.py`.
|
||||
사본(`M02_Item_Source.build_source`) = 설계가 고른 열(summary_item `spec`)을 `{손}` 으로 굳히고
|
||||
`규격` 은 그 열 하나만 남김(`freeze`).
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from decimal import Decimal, InvalidOperation
|
||||
from pathlib import Path
|
||||
from typing import Any
|
||||
|
||||
from M02_MasterTemplete import M02_Labor_Ref as refs
|
||||
|
||||
NAME_MAX = 20 # 규격 이름 · 열 이름 글자 수 상한 — 화면 칸과 같음
|
||||
COLS_MAX = 20
|
||||
|
||||
|
||||
class SpecError(ValueError):
|
||||
"""규격 칸 꼴이 틀림 — 부르는 쪽이 400 으로."""
|
||||
|
||||
|
||||
def _num(raw: Any) -> int | float | None:
|
||||
if raw is None or isinstance(raw, bool):
|
||||
return None
|
||||
try:
|
||||
got = Decimal(str(raw).replace(",", "").strip())
|
||||
except InvalidOperation:
|
||||
return None
|
||||
if not got.is_finite():
|
||||
return None
|
||||
return int(got) if got == got.to_integral_value() else float(got)
|
||||
|
||||
|
||||
def _text(raw: Any, what: str) -> str:
|
||||
text = str(raw).strip() if isinstance(raw, (str, int, float)) and raw is not True else ""
|
||||
if not text or len(text) > NAME_MAX:
|
||||
raise SpecError(f"규격 {what}은 1~{NAME_MAX}자 글")
|
||||
return text
|
||||
|
||||
|
||||
def line_key(one: dict) -> Any:
|
||||
"""줄 id — 참조 줄 = `ref_id` · 로직 줄 = 로직 키 · 자재 줄 = 코드."""
|
||||
if isinstance(one.get("참조"), dict):
|
||||
return refs.ref_id(one["참조"])
|
||||
return one.get("로직") or one.get("코드")
|
||||
|
||||
|
||||
def clean(raw: Any, ids: set[Any]) -> dict[str, Any] | None:
|
||||
"""받은 `규격` → 저장 꼴 — 열이 없으면 None(규격 없음) · 이름 · 열 이름이 비거나 겹치면 ·
|
||||
수량이 수 아니면 SpecError · 없는 줄 · 없는 열 수량은 버림(지운 줄)."""
|
||||
if raw is None:
|
||||
return None
|
||||
if not isinstance(raw, dict):
|
||||
raise SpecError("규격은 묶음")
|
||||
cols: list[str] = []
|
||||
for one in raw.get("열") or []:
|
||||
col = _text(one, "열 이름")
|
||||
if col in cols:
|
||||
raise SpecError(f"같은 규격 열 두 번 「{col}」")
|
||||
cols.append(col)
|
||||
if not cols:
|
||||
return None
|
||||
if len(cols) > COLS_MAX:
|
||||
raise SpecError(f"규격 열은 {COLS_MAX}개까지")
|
||||
qty: dict[str, dict[str, int | float]] = {}
|
||||
for lid, row in (raw.get("수량") or {}).items():
|
||||
if lid not in ids or not isinstance(row, dict):
|
||||
continue
|
||||
kept = {}
|
||||
for col, value in row.items():
|
||||
if col not in cols or value in (None, ""):
|
||||
continue
|
||||
got = _num(value)
|
||||
if got is None:
|
||||
raise SpecError(f"규격 수량 「{lid} · {col}」 은 수")
|
||||
kept[col] = got
|
||||
if kept:
|
||||
qty[str(lid)] = kept
|
||||
return {
|
||||
"이름": _text(raw.get("이름"), "이름"),
|
||||
"열": cols,
|
||||
"기본": raw.get("기본") if raw.get("기본") in cols else cols[0],
|
||||
"수량": qty,
|
||||
}
|
||||
|
||||
|
||||
def column(doc: Any, col: Any = None) -> str | None:
|
||||
"""쓸 열 — 고른 열이 규격에 있으면 그것 · 없으면 기본 · 규격 없음 = None."""
|
||||
spec = doc.get("규격") if isinstance(doc, dict) else None
|
||||
if not isinstance(spec, dict) or not spec.get("열"):
|
||||
return None
|
||||
return col if col in spec["열"] else spec.get("기본") or spec["열"][0]
|
||||
|
||||
|
||||
def at(doc: dict, col: Any = None) -> dict:
|
||||
"""열 끼우기 — 그 열 규격 수량이 있는 줄 · 자재의 `수량` 을 `{손: 값}` 으로
|
||||
(규격 없음 = 그대로)."""
|
||||
use = column(doc, col)
|
||||
if use is None:
|
||||
return doc
|
||||
qty = doc["규격"].get("수량") or {}
|
||||
|
||||
def put(one: Any) -> Any:
|
||||
if not isinstance(one, dict):
|
||||
return one
|
||||
value = (qty.get(line_key(one)) or {}).get(use)
|
||||
return {**one, "수량": {"손": value}} if value is not None else one
|
||||
|
||||
return {
|
||||
**doc,
|
||||
"담은로직": [put(one) for one in doc.get("담은로직") or []],
|
||||
"자재": [put(one) for one in doc.get("자재") or []],
|
||||
}
|
||||
|
||||
|
||||
def given_of(result: dict) -> dict[str, Any]:
|
||||
"""셈 답에서 칸 값 되살림 `{알약: 수량}` — 열마다 다시 셀 때 면적 칸 값
|
||||
(문서 · 층을 다시 안 읽음)."""
|
||||
rows = [*(result.get("줄") or []), *(result.get("자재") or [])]
|
||||
return {r["알약"]: r["수량"] for r in rows if r.get("수량출처") == "칸" and r.get("알약")}
|
||||
|
||||
|
||||
def freeze(doc: dict, col: Any = None) -> dict:
|
||||
"""사본 굳히기 — 고른 열(없거나 지운 열 = 기본)을 `{손}` 으로 끼우고 규격은 그 열 하나만."""
|
||||
use = column(doc, col)
|
||||
if use is None:
|
||||
return doc
|
||||
got = {k: v for k, v in at(doc, use).items() if k != "계산값"} # 기본 열 계산값은 버림
|
||||
return {**got, "규격": {"이름": doc["규격"].get("이름"), "열": [use], "기본": use, "수량": {}}}
|
||||
|
||||
|
||||
def users(layer_root: Path, keys: set[str], cols: set[str]) -> list[str]:
|
||||
"""그 층 항목(`keys`) · 그 규격 열(`cols`)을 쓰는 프로젝트 사본 —
|
||||
`프로젝트 폴더/사본 폴더` 목록.
|
||||
|
||||
ponytail: 저장소 프로젝트 사본 manifest 를 통째로 훑음 — 열 지우기 · 이름 바꾸기 [저장] 때만 ·
|
||||
느리면 사본 색인을 둠."""
|
||||
from M02_MasterTemplete import M02_Template_Layers as layers
|
||||
from M02_MasterTemplete.M02_Item_Source import layer_root as root_of
|
||||
from M02_MasterTemplete.M02_Item_Source import read_json
|
||||
|
||||
found = []
|
||||
here = Path(layer_root).resolve()
|
||||
for path in layers.storage_root().glob("*/*/*/templates/structures/*/manifest.json"):
|
||||
origin = (read_json(path) or {}).get("원본")
|
||||
if not isinstance(origin, dict) or origin.get("key") not in keys:
|
||||
continue
|
||||
if origin.get("spec") not in cols:
|
||||
continue
|
||||
try:
|
||||
same = root_of(origin).resolve() == here
|
||||
except (KeyError, ValueError, TypeError):
|
||||
same = False
|
||||
if same:
|
||||
found.append(f"{path.parents[3].name}/{path.parent.name}")
|
||||
return found
|
||||
|
||||
|
||||
def guard(path: Path, new: Any, column: str) -> None:
|
||||
"""[저장] 때 빠진 규격 열(지움 · 이름 바꿈)을 쓰는 프로젝트 사본이 있으면 409 —
|
||||
지금 층(`store.root`) 그 열 항목(SS 키 · 옛 키) 기준."""
|
||||
from M02_MasterTemplete import M02_MasterTemplete_Store as store
|
||||
from M02_MasterTemplete.M02_Item_Source import read_json
|
||||
|
||||
old = (read_json(path) or {}).get("규격") if path.is_file() else None
|
||||
gone = set((old or {}).get("열") or []) - set(((new or {}).get("규격") or {}).get("열") or [])
|
||||
if not gone:
|
||||
return
|
||||
rows = [r for r in store.read_combos().get("줄", []) if str(r.get("열")) == column]
|
||||
keys = {str(k) for r in rows for k in [r.get("키"), *(r.get("옛키") or [])] if k}
|
||||
used = users(store.root(), keys, gone)
|
||||
if used:
|
||||
raise store.StoreError(
|
||||
409,
|
||||
f"규격 열 「{', '.join(sorted(gone))}」 을 쓰는 프로젝트 사본 {len(used)}개 — 지울 수 없음 "
|
||||
f"({', '.join(used[:3])}{' …' if len(used) > 3 else ''})",
|
||||
)
|
||||
@@ -119,6 +119,14 @@ def _list_extras(folder: Path, col: str) -> dict[str, Any]:
|
||||
"기준": _number(calc.get("기준합")), # 수량 없는 일위대가 = 단가 합(39-8 B2)
|
||||
"단위": doc.get("단위"), # 일위대가 문서 단위(구조물 열 단위 아님 · B3)
|
||||
}
|
||||
spec = doc.get("규격") if isinstance(doc.get("규격"), dict) else None
|
||||
if spec and spec.get("열"): # 규격 열(704-4) — 고르기 창 열 단추 · 열마다 합계
|
||||
sums = calc.get("규격합") or {}
|
||||
labor["규격"] = {
|
||||
"이름": spec.get("이름"),
|
||||
"열": [{"이름": c, "합계": _number(sums.get(c))} for c in spec["열"]],
|
||||
"기본": spec.get("기본"),
|
||||
}
|
||||
return {"수정일": stamps, "labor": labor}
|
||||
|
||||
|
||||
|
||||
@@ -11,7 +11,7 @@ import {
|
||||
type LogicSummary,
|
||||
type SubBrief,
|
||||
} from "../M01_MasterData/M01_MasterData_UI_Logic_Api";
|
||||
import type { LaborCalc, LaborRef } from "./M02_MasterTemplete_Labor_Calc";
|
||||
import type { LaborCalc, LaborRef, LaborSpec } from "./M02_MasterTemplete_Labor_Calc";
|
||||
import {
|
||||
call,
|
||||
getActiveLayer,
|
||||
@@ -238,6 +238,8 @@ export interface LaborDoc {
|
||||
담은로직: LaborRow[];
|
||||
자재: LaborMat[];
|
||||
계산값?: unknown;
|
||||
/** 규격 열(704-4 · `Labor_Spec`) — 없으면 옛 문서(열 하나) */
|
||||
규격?: LaborSpec | null;
|
||||
}
|
||||
/** 받은 문서를 화면 모양으로 — 빈 칸 · 옛 모양도 받음(빈 일위대가) */
|
||||
export function normalizeLabor(doc: unknown, column: string): LaborDoc {
|
||||
|
||||
@@ -6,7 +6,8 @@
|
||||
* 수량(손이 칸보다 앞섬 · 칸 = 알약 키 값) · 반영 = 기준 × 수량 ÷ 배 · 자재 = 재료비만.
|
||||
* 별도계상 자재(222-1 · 빈 칸 = 기본 별도계상) = 반영은 보이되 합에 안 더함(짝 `apart`).
|
||||
* 참조 줄(단가승격 · 사전조합 · 50-3)은 `lineId` = 「참조|층|주인|키」(짝 `M02_Labor_Ref.ref_id`) ·
|
||||
* 고정 줄(705-1)은 「고정|이름|규격|단위」(짝 `M02_Labor_Fixed.fixed_id`) · 기준 = 서버가 낸 줄 단가. */
|
||||
* 고정 줄(705-1)은 「고정|이름|규격|단위」(짝 `M02_Labor_Fixed.fixed_id`) · 기준 = 서버가 낸 줄 단가.
|
||||
* 규격 열(704-4) = 문서 `규격` · 그 열 수량이 있는 줄 = `{손}` 자리(`atSpec` · 짝 `M02_Labor_Spec.at`). */
|
||||
|
||||
import type { CalcLine as LogicLine } from "../M01_MasterData/M01_MasterData_UI_Logic_Api";
|
||||
import type { LogicMat } from "./M02_Labor_LogicMats_Model";
|
||||
@@ -91,10 +92,19 @@ export interface LaborCalc {
|
||||
반영합?: Money;
|
||||
}
|
||||
|
||||
/** 수량만 보는 문서 조각 — 담은 로직 · 자재의 손 값 */
|
||||
/** 규격 열(704-4) — 이름(H · Φ) · 열(화면 차례) · 기본 · 줄 id 마다 열 수량 */
|
||||
export interface LaborSpec {
|
||||
이름: string;
|
||||
열: string[];
|
||||
기본: string;
|
||||
수량: Record<string, Record<string, number>>;
|
||||
}
|
||||
|
||||
/** 수량만 보는 문서 조각 — 담은 로직 · 자재의 손 값 · 규격 열 */
|
||||
export interface LaborQtyDoc {
|
||||
담은로직?: { 로직?: string; 참조?: LaborRef; 고정?: LaborFixed; 수량?: Qty }[];
|
||||
자재?: { 코드: string; 수량?: Qty; 별도계상?: string }[];
|
||||
규격?: LaborSpec | null;
|
||||
}
|
||||
|
||||
function num(raw: unknown): number | null {
|
||||
@@ -116,6 +126,37 @@ export function lineId(one: {
|
||||
return one.로직;
|
||||
}
|
||||
|
||||
/** 쓸 규격 열 — 고른 열이 있으면 그것 · 없으면 기본 · 규격 없음 = null(짝 `M02_Labor_Spec.column`) */
|
||||
export function specColumn(doc: LaborQtyDoc, col?: string | null): string | null {
|
||||
const cols = doc.규격?.열 ?? [];
|
||||
if (!cols.length) return null;
|
||||
return col && cols.includes(col) ? col : doc.규격?.기본 || cols[0];
|
||||
}
|
||||
|
||||
/** 열 끼우기 — 그 열 규격 수량이 있는 줄 · 자재의 수량을 `{손}` 으로(짝 `M02_Labor_Spec.at`) */
|
||||
export function atSpec<D extends LaborQtyDoc>(doc: D, col?: string | null): D {
|
||||
const use = specColumn(doc, col);
|
||||
if (use === null) return doc;
|
||||
const qty = doc.규격?.수량 ?? {};
|
||||
const put = <T extends { 수량?: Qty }>(one: T, id: string | undefined): T => {
|
||||
const v = id !== undefined ? qty[id]?.[use] : undefined;
|
||||
return v !== undefined && v !== null ? { ...one, 수량: { 손: v } } : one;
|
||||
};
|
||||
return {
|
||||
...doc,
|
||||
담은로직: (doc.담은로직 ?? []).map((one) => put(one, lineId(one))),
|
||||
자재: (doc.자재 ?? []).map((one) => put(one, one.코드)),
|
||||
};
|
||||
}
|
||||
|
||||
/** 셈 답에서 칸 값 되살림 `{알약: 수량}` — 열마다 다시 셀 때(짝 `M02_Labor_Spec.given_of`) */
|
||||
export function givenOf(result: LaborCalc): Record<string, number> {
|
||||
const out: Record<string, number> = {};
|
||||
for (const r of [...result.줄, ...result.자재])
|
||||
if (r.수량출처 === "칸" && r.알약 && r.수량 != null) out[r.알약] = r.수량;
|
||||
return out;
|
||||
}
|
||||
|
||||
function zero(): Money {
|
||||
return { 노무비: 0, 재료비: 0, 경비: 0, 계: 0 };
|
||||
}
|
||||
@@ -139,12 +180,15 @@ export function reflect(base: Money, qty: number | null, times: number): Money |
|
||||
return out;
|
||||
}
|
||||
|
||||
/** 기준이 선 계산 답 + 문서 손 값 + 알약 값(`{키: 값}`) → 수량 · 반영 · 합을 새로 채운 답 */
|
||||
/** 기준이 선 계산 답 + 문서 손 값 + 알약 값(`{키: 값}`) → 수량 · 반영 · 합을 새로 채운 답 ·
|
||||
* `col` = 규격 열(없으면 기본 · 704-4) */
|
||||
export function settle(
|
||||
result: LaborCalc,
|
||||
doc: LaborQtyDoc,
|
||||
whole: LaborQtyDoc,
|
||||
given: Record<string, unknown>,
|
||||
col?: string | null,
|
||||
): LaborCalc {
|
||||
const doc = atSpec(whole, col);
|
||||
const have: Record<string, number> = {};
|
||||
for (const [k, raw] of Object.entries(given)) {
|
||||
const v = num(raw);
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
* · 서고 모드(50-3 · `mode`) = 사전조합 — 이름 칸 · 단가산출 로직 표 · 자재목록(175-1) · 원문(면적 · 다이어그램 없음) ·
|
||||
* 정보 칸 구분 · 상세구분(51-12 · 고름) · 일위대가 상세와 같은 [로직 추가] · 표 · 동작(51-11) · 수량 손 입력(기본 1)
|
||||
* · 로직 줄 구분 드롭다운(134-1 · 단가산출 | 단가승격 · 서고 모드엔 없음)
|
||||
* · 맨 위 엑셀 꼴 격자(704-3 · `Labor_Grid`) · 읽기만 카드는 격자만
|
||||
* · 맨 위 엑셀 꼴 격자(704-3 · `Labor_Grid`) · 읽기만 카드는 격자만 · 규격 표(704-4 · `Labor_Spec`)
|
||||
* ========================================================================== */
|
||||
|
||||
import {
|
||||
@@ -218,7 +218,7 @@ export function mountLaborDetail(
|
||||
),
|
||||
);
|
||||
const draw = (): void => {
|
||||
gridHost.replaceChildren(laborGrid(cur, calc ?? last, logics));
|
||||
gridHost.replaceChildren(laborGrid(cur, calc ?? last, logics, edit && !lib && changed));
|
||||
drawLogic();
|
||||
matHost.replaceChildren(
|
||||
matTable(
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
* 로직 줄 = 이름(별칭 앞섬) · 규격(옵션 값 · 켜쌓기) · 수량 · 분모 · 단가 = 기준 ÷ 배 · 금액 = 반영 · 꼬리표 품셈
|
||||
* 자재 줄 = 이름 · 규격 · 수량 · 단위 · 재료비 단가 = 기준단가 · 금액 = 반영 · 별도계상은 비고 「합계 밖」
|
||||
* 빈 줄(금액 모름 · 수량 없음) = 합계 줄 「빈 줄 n」 붉게 — 701-4 경고와 같은 줄
|
||||
* 규격 열(704-4 · `Labor_Spec`) = 수량 칸 열마다 · 고칠 때 격자 위 규격 줄 + 수량 칸 고침
|
||||
* ========================================================================== */
|
||||
|
||||
import {
|
||||
@@ -20,6 +21,7 @@ import type { LaborCalc, LaborCost, LaborDoc } from "./M02_MasterTemplete_Labor_
|
||||
import { lineId } from "./M02_MasterTemplete_Labor_Calc";
|
||||
import { tc } from "./M02_MasterTemplete_Labor_Text";
|
||||
import { valueLine } from "./M02_Labor_Values_Model";
|
||||
import { specBar, specCells, withSpecs, type SpecEdit } from "./M02_MasterTemplete_Labor_Spec";
|
||||
|
||||
const money = (m: LaborCost | null | undefined, times = 1): HopyoMoney =>
|
||||
m
|
||||
@@ -77,7 +79,7 @@ export function laborBlock(
|
||||
};
|
||||
});
|
||||
const lines = [...logicLines, ...matLines];
|
||||
return {
|
||||
const block: HopyoBlock = {
|
||||
key: doc.열,
|
||||
name: doc.일위대가번 || doc.열,
|
||||
unit: doc.단위 ?? "",
|
||||
@@ -85,11 +87,20 @@ export function laborBlock(
|
||||
lines,
|
||||
...(calc ? {} : { blank: 0 }),
|
||||
};
|
||||
return withSpecs(block, doc, calc);
|
||||
}
|
||||
|
||||
/** 격자 하나(읽기 전용) */
|
||||
/** 격자 하나 — `edit` 있으면 위에 규격 줄 · 규격 수량 칸 고침(704-4) */
|
||||
export const laborGrid = (
|
||||
doc: LaborDoc,
|
||||
calc: LaborCalc | null,
|
||||
logics: ReadonlyMap<string, ItemLogic>,
|
||||
): HTMLElement => createHopyoGrid([laborBlock(doc, calc, logics)]).root;
|
||||
edit?: SpecEdit | false,
|
||||
): HTMLElement => {
|
||||
const block = laborBlock(doc, calc, logics);
|
||||
if (!edit) return createHopyoGrid([block]).root;
|
||||
const grid = createHopyoGrid([block], specCells(block, doc, edit)).root;
|
||||
const box = document.createElement("div");
|
||||
box.append(specBar(doc, calc, edit), grid);
|
||||
return box;
|
||||
};
|
||||
|
||||
@@ -0,0 +1,191 @@
|
||||
/* =============================================================================
|
||||
* M02_MasterTemplete_Labor_Spec.ts
|
||||
* 일위대가 규격 표(PLAN 704-4) — 704-3 격자에 규격 열(H=1.5 | 2.0 …)을 폄 · 고칠 때 격자 위 규격 줄.
|
||||
* 문서 `규격` = {이름, 열, 기본, 수량: {줄 id: {열: 수}}}(짝 `M02_Labor_Spec.py`) · 화면 캐시만(저장은 [저장])
|
||||
* 규격 줄 = 규격 이름 · 열마다 이름 칸 · [기본] · [×] · [+ 열](새 열 수량 = 지금 기본 열 값 그대로)
|
||||
* 격자 수량 칸(열마다) 고침 = 그 줄 · 그 열 수량(빈 글 = 공통 수량을 따름)
|
||||
* 열마다 수량 · 1 단위 합계 = 짝 셈 `settle(…, 열)`(서버 안 부름) · 금액 칸 = 기본 열
|
||||
* 쓰는 사본이 있는 열 지움 · 이름 바꿈은 [저장] 때 서버가 막음(409 까닭 그대로)
|
||||
* ========================================================================== */
|
||||
|
||||
import { createButton, createInputField, el } from "@ui/ui_template_elements";
|
||||
import type { DataTableOptions } from "@ui/ui_template_data_table";
|
||||
import { hopyoGrid, hopyoSpecKey, type HopyoBlock } from "@ui/ui_template_hopyo_grid";
|
||||
import { createToolbar } from "@ui/ui_template_toolbar";
|
||||
import { createText } from "@ui/ui_template_text";
|
||||
import type { LaborCalc, LaborDoc } from "./M02_MasterTemplete_Labor_Api";
|
||||
import { givenOf, lineId, settle, specColumn } from "./M02_MasterTemplete_Labor_Calc";
|
||||
|
||||
/** 고칠 때 — 규격이 바뀌면 `true`(수량만 · 기준 그대로 · 짝 셈으로 바로) */
|
||||
export type SpecEdit = (qtyOnly: boolean) => void;
|
||||
|
||||
const TEXT = {
|
||||
none: "규격 열 없음 — [+ 열] = H 같은 규격마다 줄 수량만 다른 열",
|
||||
add: "+ 열",
|
||||
name: "규격 이름",
|
||||
base: "기본",
|
||||
remove: "열 지움",
|
||||
first: "1",
|
||||
next: "새 열",
|
||||
};
|
||||
|
||||
/** 줄 id 차례 — 격자 줄 차례(로직 줄 → 자재 줄)와 같음 */
|
||||
const lineIds = (doc: LaborDoc): string[] => [
|
||||
...doc.담은로직.map((r) => lineId(r) ?? ""),
|
||||
...doc.자재.map((m) => m.코드),
|
||||
];
|
||||
|
||||
/** 열마다 셈 → 블록 `specs` · 줄 `qtys`(규격 없음 = 그대로) */
|
||||
export function withSpecs(block: HopyoBlock, doc: LaborDoc, calc: LaborCalc | null): HopyoBlock {
|
||||
const spec = doc.규격;
|
||||
if (!spec?.열.length) return block;
|
||||
const per = calc ? spec.열.map((c) => settle(calc, doc, givenOf(calc), c)) : [];
|
||||
const ids = lineIds(doc);
|
||||
const logics = doc.담은로직.length;
|
||||
const qtyOf = (p: LaborCalc, n: number): number | null =>
|
||||
(n < logics
|
||||
? p.줄.find((l) => lineId(l) === ids[n])?.수량
|
||||
: p.자재.find((m) => m.코드 === ids[n])?.수량) ?? null;
|
||||
return {
|
||||
...block,
|
||||
specs: {
|
||||
name: spec.이름,
|
||||
cols: spec.열,
|
||||
pick: specColumn(doc),
|
||||
totals: per.map((p) => p.반영합?.계 ?? null),
|
||||
},
|
||||
lines: block.lines.map((ln, n) => ({ ...ln, qtys: per.map((p) => qtyOf(p, n)) })),
|
||||
};
|
||||
}
|
||||
|
||||
/** 격자 수량 칸 고침(열마다) — 공용 표 옵션 덧 */
|
||||
export function specCells(
|
||||
block: HopyoBlock,
|
||||
doc: LaborDoc,
|
||||
edit: SpecEdit,
|
||||
): Partial<DataTableOptions> {
|
||||
const spec = doc.규격;
|
||||
if (!spec?.열.length) return {};
|
||||
const g = hopyoGrid([block]);
|
||||
const ids = lineIds(doc);
|
||||
const col = (key: string): string | undefined => spec.열.find((_, n) => hopyoSpecKey(n) === key);
|
||||
return {
|
||||
editable: (i, key) => g.at.has(i) && col(key) !== undefined,
|
||||
onEdit: (i, key, text) => {
|
||||
const id = ids[g.at.get(i)?.[1] ?? -1];
|
||||
const name = col(key);
|
||||
if (id === undefined || name === undefined) return;
|
||||
const v = Number(text.replace(/,/g, "").trim());
|
||||
const row = { ...(spec.수량[id] ?? {}) };
|
||||
if (text.trim() === "" || !Number.isFinite(v)) delete row[name];
|
||||
else row[name] = v;
|
||||
if (Object.keys(row).length) spec.수량[id] = row;
|
||||
else delete spec.수량[id];
|
||||
edit(true);
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
/** 새 열 이름 — 겹치면 뒤에 번호 */
|
||||
const fresh = (cols: string[], want: string): string => {
|
||||
let out = want;
|
||||
for (let n = 2; cols.includes(out); n++) out = `${want} ${n}`;
|
||||
return out;
|
||||
};
|
||||
|
||||
/** [+ 열] — 규격이 없으면 지금 수량 열(1) + 새 열 · 새 열 수량 = 기본 열 손 값 그대로 */
|
||||
function addColumn(doc: LaborDoc, calc: LaborCalc | null): void {
|
||||
const spec = (doc.규격 ??= { 이름: "H", 열: [TEXT.first], 기본: TEXT.first, 수량: {} });
|
||||
const col = fresh(spec.열, TEXT.next);
|
||||
const base = specColumn(doc) ?? spec.열[0];
|
||||
spec.열.push(col);
|
||||
const ids = lineIds(doc);
|
||||
const logics = doc.담은로직.length;
|
||||
ids.forEach((id, n) => {
|
||||
const own = spec.수량[id]?.[base];
|
||||
const line =
|
||||
n < logics ? calc?.줄.find((l) => lineId(l) === id) : calc?.자재.find((m) => m.코드 === id);
|
||||
const v = own ?? (line?.수량출처 === "손" ? line.수량 : null);
|
||||
if (v != null) spec.수량[id] = { ...(spec.수량[id] ?? {}), [col]: v };
|
||||
});
|
||||
}
|
||||
|
||||
function renameColumn(doc: LaborDoc, from: string, to: string): boolean {
|
||||
const spec = doc.규격;
|
||||
const name = to.trim();
|
||||
if (!spec || !name || name.length > 20 || name === from || spec.열.includes(name)) return false;
|
||||
spec.열 = spec.열.map((c) => (c === from ? name : c));
|
||||
if (spec.기본 === from) spec.기본 = name;
|
||||
for (const row of Object.values(spec.수량))
|
||||
if (from in row) {
|
||||
row[name] = row[from];
|
||||
delete row[from];
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
function removeColumn(doc: LaborDoc, col: string): void {
|
||||
const spec = doc.규격;
|
||||
if (!spec) return;
|
||||
spec.열 = spec.열.filter((c) => c !== col);
|
||||
for (const [id, row] of Object.entries(spec.수량)) {
|
||||
delete row[col];
|
||||
if (!Object.keys(row).length) delete spec.수량[id];
|
||||
}
|
||||
if (!spec.열.length)
|
||||
doc.규격 = null; // 마지막 열 = 규격 없음(옛 문서 꼴)
|
||||
else if (spec.기본 === col) spec.기본 = spec.열[0];
|
||||
}
|
||||
|
||||
/** 격자 위 규격 줄(고칠 때만) */
|
||||
export function specBar(doc: LaborDoc, calc: LaborCalc | null, edit: SpecEdit): HTMLElement {
|
||||
const add = createButton({
|
||||
label: TEXT.add,
|
||||
variant: "ghost",
|
||||
onClick: () => {
|
||||
addColumn(doc, calc);
|
||||
edit(true);
|
||||
},
|
||||
});
|
||||
const spec = doc.규격;
|
||||
if (!spec?.열.length)
|
||||
return createToolbar({ items: [createText(TEXT.none, "muted"), add], label: TEXT.name });
|
||||
const name = createInputField({ value: spec.이름, compact: true, placeholder: TEXT.name });
|
||||
name.input.title = TEXT.name;
|
||||
name.root.style.width = "6em"; // 짧은 글 칸 — 열 이름 칸도 같은 폭(카드 한 줄에)
|
||||
name.input.addEventListener("change", () => {
|
||||
const v = name.input.value.trim();
|
||||
if (v && v.length <= 20) spec.이름 = v;
|
||||
edit(true);
|
||||
});
|
||||
const cols = spec.열.flatMap((col) => {
|
||||
const box = createInputField({ value: col, compact: true });
|
||||
box.input.setAttribute("data-spec-col", col);
|
||||
box.root.style.width = "6em";
|
||||
box.input.addEventListener("change", () => {
|
||||
renameColumn(doc, col, box.input.value);
|
||||
edit(true);
|
||||
});
|
||||
const base = createButton({
|
||||
label: TEXT.base,
|
||||
variant: col === spec.기본 ? "filled" : "ghost",
|
||||
size: "sm",
|
||||
onClick: () => {
|
||||
spec.기본 = col;
|
||||
edit(true);
|
||||
},
|
||||
});
|
||||
const drop = createButton({
|
||||
label: "×",
|
||||
variant: "ghost",
|
||||
size: "sm",
|
||||
onClick: () => {
|
||||
removeColumn(doc, col);
|
||||
edit(true);
|
||||
},
|
||||
});
|
||||
drop.title = TEXT.remove;
|
||||
return [el("span", { children: [box.root] }), base, drop, "divider" as const];
|
||||
});
|
||||
return createToolbar({ items: [name.root, "divider", ...cols, add], label: TEXT.name });
|
||||
}
|
||||
@@ -166,6 +166,10 @@ def write(kind: str, name: str, version: str, doc: Any, screen: bool = False) ->
|
||||
if kind == "table" and name == STRUCTURE_TABLE:
|
||||
doc = tree.normalize_table(doc) # 경로 · 머리 줄 수 · 빈 폴더(표 저장 · 나무 고침 한 줄기)
|
||||
doc = _server(kind, doc)
|
||||
if kind == "labor": # 쓰는 규격 열 지움 막음(704-4)
|
||||
from M02_MasterTemplete import M02_Labor_Spec as labor_spec
|
||||
|
||||
labor_spec.guard(path, doc, name)
|
||||
fresh: list[dict[str, Any]] = []
|
||||
with _LOCK:
|
||||
have = version_of(path.read_bytes()) if path.is_file() else ""
|
||||
|
||||
Reference in New Issue
Block a user