const EstReport = (() => { function preview(all = false) { const { state, esc } = EstApp; const number = (value) => new Intl.NumberFormat("ko-KR", { maximumFractionDigits: 12 }).format(Number(value) || 0); const root = document.createElement("div"); if (state.project.tables[state.view]) { const rows = all ? state.project.tables[state.view].map((row, index) => ({ row, index })) : EstApp.visibleRows(); const common = ["Code", "Name", "Size", "Unite"]; const columns = { EstMainDat: [...common, "GN", "TU", "TC", "NC", "GC", "JC", "SC"], HeadMainDat: [...common, "GN", "NU", "GU", "JU", "SU", "TU", "NC", "GC", "JC", "SC", "TC"], CostMainDat: ["LineData"], MachMainDat: [...common, "GN", "TU", "NC", "GC", "JC", "TC"], Wonga: ["Gubun", "Name", "Youl", "VSusic", "Cost"], }; root.innerHTML = EstViews.grid( state.view, rows, columns[state.view] || EstModel.columns(state.view).filter( (key) => ![ "ValueIndex", "SelectField", "Ratio", "NachalRatio", "Diget", "DigetIndex", ].includes(key), ), ); } else root.innerHTML = EstApp.byId("work-content").innerHTML; root .querySelectorAll("button,.row-number,.business-tools,select#quantity-sheet") .forEach((node) => node.remove()); root.querySelectorAll("input,textarea,select").forEach((node) => { const value = node.tagName === "SELECT" ? node.selectedOptions[0]?.textContent || "" : node.type === "number" && node.value !== "" ? number(node.value) : EstText.clean(EstText.encode(node.value)); if (node.tagName === "TEXTAREA") node.parentElement.classList.add("col-LineData"); if (node.type === "number") node.parentElement.classList.add("numeric"); node.replaceWith(document.createTextNode(value)); }); root .querySelectorAll("[contenteditable]") .forEach((node) => node.removeAttribute("contenteditable")); const title = EstApp.titles[state.view] || state.view; const detail = state.view === "quantity" ? state.project.quantitySheets?.find((sheet) => sheet.Code === state.quantitySheet)?.Name : state.view === "progress" ? state.project.progress.find((round) => round.id === state.roundId)?.name : state.group ? EstNative.groups(state.project.tables[state.view] || []).get(state.group)?.rows[0] ?.Name : ""; const totals = state.project.calculation; const errors = totals?.errors || []; const source = `${esc(state.project.name)} · ${esc(title)}

${esc(state.project.name)}

${esc(title)}

${detail ? `

${esc(detail)}

` : ""}${totals ? `
순공사비 ${number(totals.direct?.TC)}원 · 도급액 ${number(totals.total)}원
` : ""} ${root.innerHTML}${errors.length ? `

계산 오류 ${errors.length}건: ${esc(errors.join(" / "))}

` : ""}`; EstApp.byId("print-frame").srcdoc = source; } function open() { const table = EstApp.state.project.tables[EstApp.state.view]; EstApp.showDialog( "인쇄 미리보기", `
${table ? '' : ""}
`, ); EstApp.byId("print-scope")?.addEventListener("change", (event) => preview(event.target.value === "all"), ); preview(); } function print() { const frame = EstApp.byId("print-frame"); if (!frame?.contentDocument?.body) throw Error("인쇄 미리보기가 준비되지 않았습니다."); frame.contentWindow.focus(); frame.contentWindow.print(); } return { open, preview, print }; })();