Files
Aislo/resources/tester/helper_stmate_report.cjs
T

55 lines
2.7 KiB
JavaScript

// STMATE 재현 앱 보고서 묶음 — stdin = { load: /api/load 결과, stage, mode(pps = 조달청 XML · forms = 양식 변형 ·
// ui = 인쇄 선택 화면 상태(scr_report_opts effective)로 묶음), opts } · 연쇄 재계산(계산완료) 뒤 시트 모형(_f 수식 칸 포함)
globalThis.window = globalThis;
globalThis.document = globalThis.document || { readyState: "complete" }; // 노드 — 화면 전용 분기 막음
require("../../tools/stmate-test/calc.js");
require("../../tools/stmate-test/smt_eval.js");
require("../../tools/stmate-test/smt_engine.js");
require("../../tools/stmate-test/view_prj_boq.js");
require("../../tools/stmate-test/report_core.js");
require("../../tools/stmate-test/report_unit.js");
require("../../tools/stmate-test/report_boq.js");
const Book = require("../../tools/stmate-test/report_book.js");
const Pps = require("../../tools/stmate-test/report_pps.js");
let buf = "";
process.stdin.setEncoding("utf8");
process.stdin.on("data", (d) => (buf += d));
process.stdin.on("end", () => {
const { load, stage, mode, opts } = JSON.parse(buf);
const ctx = { dbfData: load, state: load.sim_state, uiState: {} };
window.STMATE_ENGINE.cascadeRecalculateAll(ctx);
const computed = window.STMATE_CALC.calculateAll(ctx.state);
if (mode === "pps") {
const xml = Pps.buildPpsXml(load, ctx.state, computed, stage || 1, { today: "2026-01-01" });
process.stdout.write(JSON.stringify({ xml }));
return;
}
if (mode === "forms") {
const U = require("../../tools/stmate-test/report_unit.js");
const Fm = require("../../tools/stmate-test/report_forms.js");
const u = U.unitContext(load);
const forms = Fm.buildFormSheets(u, load, ctx.state, computed, stage || 1, opts || {});
const out = {};
for (const [id, sh] of Object.entries(forms)) out[id] = { name: sh.name, rows: sh.rows };
out._grand =
computed.stages && computed.stages[stage || 1]
? computed.stages[stage || 1].kanjub.grandTotal
: null;
process.stdout.write(JSON.stringify(out));
return;
}
if (mode === "ui") {
require("../../tools/stmate-test/scr_report_opts.js");
const uctx = { dbfData: load, uiState: { reportOpts: opts || {} } };
const eff = globalThis.STMATE_REPORT_OPTS.effective(uctx);
const bk = Book.buildBook(eff.dbf, ctx.state, computed, stage || 1, eff.opts);
const sheets = bk.sheets.map((s) => ({ id: s.id || s.name, name: s.name, rows: s.rows }));
process.stdout.write(JSON.stringify({ sheets, print: eff.print, formulas: eff.formulas }));
return;
}
const book = Book.buildBook(load, ctx.state, computed, stage || 1, opts || {});
const out = {};
for (const s of book.sheets) out[s.id || s.name] = Object.assign({}, s);
process.stdout.write(JSON.stringify(out));
});