const EstReport = (() => { let catalog = []; function setting() { const project = EstApp.state.project, settings = project.printSettings || {}; return { form: "current", paper: "A4", orientation: "landscape", margin: 12, font: 9, company: "", startPage: 1, rowsPerPage: 30, notes: "", ...settings, }; } function preview(all = false) { const { state, esc } = EstApp; const settings = setting(), form = catalog.find((row) => String(row.Index) === settings.form), output = form ? EstForms.data(form.Index, state.project) : null; const number = (value) => new Intl.NumberFormat("ko-KR", { maximumFractionDigits: 12 }).format(Number(value) || 0); const root = document.createElement("div"); if (output) root.innerHTML = EstForms.grid(output); else if (form) { const total = state.project.calculation?.total || 0; root.innerHTML = `
${esc(settings.company)}
` : ""}`; } else 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 = form?.Name2 || 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 || []), ...(output?.errors || [])]; const source = `계산 오류 ${errors.length}건: ${esc(errors.join(" / "))}
` : ""}`; EstApp.byId("print-frame").srcdoc = source; } function paginate(root, settings) { const table = root.querySelector("table"); if (!table || root.querySelectorAll("table").length !== 1) return root.innerHTML; const rows = [...table.querySelectorAll("tbody>tr")], pages = []; for (let at = 0; at < rows.length; at += settings.rowsPerPage) { const copy = table.cloneNode(false); copy.innerHTML = table.querySelector("thead")?.outerHTML || ""; const body = document.createElement("tbody"); rows.slice(at, at + settings.rowsPerPage).forEach((row) => body.append(row.cloneNode(true))); copy.append(body); pages.push( `