const EstStandard = (() => { let page = 0; function usage(project) { const sources = new Map(); for (const row of project.tables.SilJukDat || []) { if (!row.Code) continue; const rows = sources.get(row.Code) || []; rows.push(row); sources.set(row.Code, rows); } return (project.tables.EstMainDat || []).flatMap((row, index) => { if (Number(row.Level) > 0 || Number(row.LinkIndex) !== 21) return []; const matches = sources.get(row.Code) || []; const source = matches.length === 1 ? EstNative.price(structuredClone(matches[0]), 21) : null; const appliedPrice = row.TU == null ? EstMath.units.reduce((sum, field) => sum + EstMath.num(row[field]), 0) : EstMath.num(row.TU); const sourcePrice = source ? EstMath.num(source.TC) : null; return [ { index, Code: row.Code || "", Name: row.Name || "", Size: row.Size || "", Unite: row.Unite || "", GN: EstMath.num(row.GN), appliedPrice, sourcePrice, difference: source ? appliedPrice - sourcePrice : null, TC: EstMath.num(row.TC), status: !matches.length ? "연결 없음" : matches.length > 1 ? "코드 중복" : "연결됨", }, ]; }); } function changes(project) { const labels = { new: "신규", deleted: "삭제", changed: "변경", unchanged: "동일" }; return EstBusiness.changes(project) .filter((row) => Number(row.LinkIndex) === 21 || Number(row.originalLinkIndex) === 21) .map((row) => ({ ...row, status: labels[row.status] || row.status })); } function render() { const { state, esc, number, byId } = EstApp, isChange = state.view === "standard-change", rows = isChange ? changes(state.project) : usage(state.project); page = Math.max(0, Math.min(page, Math.ceil(rows.length / 100) - 1)); const visible = rows.slice(page * 100, page * 100 + 100), value = (v) => (v == null ? "" : number(v)); if (isChange) { byId("work-content").innerHTML = `
표준시장단가 설계변경${rows.length}건 · ${page + 1}/${Math.max(1, Math.ceil(rows.length / 100))}쪽
${visible.map((row) => ``).join("")}
구분코드품명당초 수량변경 수량당초 금액변경 금액증감작업
${esc(row.status)}${esc(row.Code)}${esc(row.Name)}${value(row.originalGN)}${value(row.GN)}${value(row.originalTC)}${value(row.TC)}${value(row.difference)}${row.index == null ? "" : ``}
`; return; } byId("work-content").innerHTML = `
표준시장단가 사용 내역${rows.length}건 · ${page + 1}/${Math.max(1, Math.ceil(rows.length / 100))}쪽

내역에 적용된 단가와 현재 표준시장단가 자료를 비교합니다.

${visible.map((row) => ``).join("")}
코드품명규격단위수량내역 단가기초 단가차이금액연결작업
${esc(row.Code)}${esc(row.Name)}${esc(row.Size)}${esc(row.Unite)}${value(row.GN)}${value(row.appliedPrice)}${value(row.sourcePrice)}${value(row.difference)}${value(row.TC)}${esc(row.status)}
`; } function install() { document.addEventListener("click", (event) => { const step = event.target.closest("[data-standard-page]"); if (step) { page += Number(step.dataset.standardPage); render(); return; } const node = event.target.closest("[data-standard-row]"); if (!node) return; const index = Number(node.dataset.standardRow); if (!EstApp.state.project.tables.EstMainDat[index]) return; EstApp.navigate("EstMainDat"); EstApp.state.page = Math.floor(index / 100); EstApp.state.selection = new Set([index]); EstApp.render(); }); } return { usage, changes, render, install }; })();