const EstForms = (() => { const common = ["Code", "Name", "Size", "Unite"]; function data(id, project) { if (id === 171) { const output = EstReview.calculate(project); const rows = output.baseline.tables.EstMainDat.map((row, index) => ({ row, result: output.reviewed.tables.EstMainDat[index], })) .filter(({ row }) => row.Code || row.Name) .map(({ row, result }) => ({ Code: row.Code, Name: row.Name, originalGN: row.GN, GN: result.GN, originalTC: row.TC, TC: result.TC, difference: EstMath.num(result.TC) - EstMath.num(row.TC), })); rows.unshift({ Name: "심사 도급액", originalTC: output.before, TC: output.after, difference: output.after - output.before, }); return { columns: ["Code", "Name", "originalGN", "GN", "originalTC", "TC", "difference"], rows, errors: output.errors, }; } if (id === 109) return { columns: ["Code", "Name", "start", "end", "weight", "progress"], rows: EstSchedule.calculate(project).rows, }; const table = { 1: "EstMainDat", 117: "EstMainDat", 2: "HeadMainDat", 115: "HeadMainDat", 3: "CostMainDat", 4: "MachMainDat", 119: "MachGijunDat", 101: "EstiMateDat", 21: "SilJukDat", 5: "StuffcDat", 6: "LaborcDat", 7: "Wonga", 22: "Wonga", }[id]; if (table) { const columns = table === "Wonga" ? ["Gubun", "Name", "Youl", "VSusic", "Cost"] : table === "CostMainDat" ? ["Code", "LineData"] : table === "HeadMainDat" ? [...common, "GN", "NU", "GU", "JU", "SU", "TC"] : [...common, "GN", "TU", "TC", "NC", "GC", "JC", "SC"]; return { table, columns, rows: project.tables[table] || [] }; } const totals = { 106: "EstMainDat", 118: "EstMainDat", 103: "HeadMainDat", 116: "HeadMainDat", 104: "CostMainDat", 105: "MachMainDat", }[id]; if (totals) { const rows = totals === "EstMainDat" ? (project.tables[totals] || []).filter((r) => Number(r.Level) > 0) : [...EstNative.groups(project.tables[totals] || []).values()].map((group) => { const row = { ...group.rows[0] }; const titleTable = { HeadMainDat: "HeadTitleDat", CostMainDat: "CostTitleDat", MachMainDat: "MachTitleDat", }[totals]; const title = project.tables[titleTable]?.find((item) => item.Code === row.Code); if (title) return { ...row, ...title }; for (const key of [...EstMath.components, "TC"]) row[key] = group.rows .slice(1) .filter((r) => Number(r.CalcIndex || 0) < 2) .reduce((n, r) => n + EstMath.num(r[key]), 0); return row; }); return { table: totals, columns: [...common, "NC", "GC", "JC", "SC", "TC"], rows }; } if ([107, 108].includes(id)) return { columns: ["Code", "Name", "originalGN", "GN", "originalTC", "TC", "difference", "status"], rows: EstBusiness.changes(project), }; const kinds = { 13: 6, 110: 5, 111: 105, 161: 21, 162: 101, 112: 6, 113: 5, 114: 105, 163: 21, 164: 101, }; if (kinds[id]) { const output = EstResources.calculate(project, [112, 113, 114, 163, 164].includes(id)); return { columns: [ ...([112, 113, 114, 163, 164].includes(id) ? ["WorkCode", "WorkName"] : []), "Code", "Name", "Size", "Unite", "quantity", "amount", ], errors: output.errors, rows: output.rows.filter((r) => r.kind === kinds[id]), }; } if (id === 14) { const target = (item) => { if (!item.TargetKey) return item.TargetCode ?? item.LinkCode ?? ""; const row = project.tables.EstMainDat.find( (entry) => entry.PkID != null && `id:${entry.PkID}` === item.TargetKey, ); return row ? `${row.Name || "내역"} (${row.Code || item.TargetKey})` : item.TargetKey; }; const manual = EstQuantity.manual(project.quantities || []), rows = manual.rows.map((row) => ({ ...row, SheetName: "수식표", formula: row.formula || "", TargetCode: target(row), })), errors = [...manual.errors]; for (const sheet of project.quantitySheets || []) { const calculated = EstQuantity.calculate(sheet); errors.push(...calculated.errors.map((error) => `${sheet.Name || sheet.Code}: ${error}`)); for (const item of calculated.items) { const index = sheet.rows.findIndex((row) => (row.markers || []).includes(item.Code)); rows.push({ ...item, SheetName: sheet.Name || sheet.Code, formula: index < 0 ? "" : EstText.clean(calculated.rows[index].LineData), TargetCode: target(item), }); } } return { columns: ["SheetName", "Code", "Name", "formula", "GN", "TargetCode", "Error"], rows, errors, }; } return null; } const labels = { originalGN: "당초 수량", originalTC: "당초 금액", difference: "증감", status: "상태", quantity: "소요량/시간", amount: "금액", start: "시작일", end: "종료일", weight: "가중치", progress: "진도(%)", WorkCode: "공종 코드", WorkName: "공종명", formula: "산식", SheetName: "산출서", Error: "계산 오류", TargetCode: "연결 내역", TU: "단가", TC: "금액", NC: "노무비", GC: "재료비", JC: "경비", SC: "산출경비", }; function grid(output) { const { esc } = EstApp, number = (v) => new Intl.NumberFormat("ko-KR", { maximumFractionDigits: 12 }).format(v); return `
| ${esc(labels[key] || EstModel.labels[key] || key)} | `).join("")}
|---|
| ${esc(typeof row[key] === "number" ? number(row[key]) : key === "LineData" ? EstText.clean(row[key] || "") : (row[key] ?? ""))} | `).join("")}