Files
Aislo/tools/stmate-test/scr_jaje.js
T

92 lines
3.4 KiB
JavaScript

/**
* STMATE w 8.0 — 재료비 수량집계표를 엑셀파일로 만들기 (scr_jaje.js) · 1번(파일) 메뉴
* 원본: TWM_JAJEXLS(공사목록 ActMkJaje · 「워크쉬트작업」) — 내보내기만(들여오기 없음)
* 공사명 = PNAME · 관리번호 = PNUM · 예산액 = COSTW<차수>(₩#,0원) · 나머지 5칸은 입력
* 줄 = 재료비(M) 집계 수량(report_coll explode — 집계표 0501 과 같은 전개) · 단가 = 차수 합계 단가
* 서버: api_conv.py /api/conv/jaje-sum-xlsx — 「주요건설자재현황」 시트
*/
(function (global) {
"use strict";
const PLUG = (global.STMATE_PLUGINS = global.STMATE_PLUGINS || {
screens: {},
actions: {},
menus: [],
});
function download(blob, name) {
const a = document.createElement("a");
a.href = URL.createObjectURL(blob);
a.download = name;
document.body.appendChild(a);
a.click();
setTimeout(() => (URL.revokeObjectURL(a.href), a.remove()), 1000);
}
// 차수 1 기준 재료비 줄 — 설계내역서 나무 → 투입 수량 전개 → M 코드만(코드순)
function materialRows(ctx) {
const U = global.STMATE_REPORT_UNIT;
const B = global.STMATE_REPORT_BOQ;
const Co = global.STMATE_REPORT_COLL;
const C = global.STMATE_REPORT_CORE;
const dbf = ctx.dbfData;
const u = U.buildUnitSheets(dbf).ctx;
const boq = B.buildBoqSheets(dbf, ctx.state, ctx.computed, 1, {});
const ex = Co.explode(dbf, Co.stageItems(boq.설계내역서._tree));
const rows = [];
for (const r of u.idx.ofPrefix("M")) {
const c = C.code(r);
if (!ex.qty[c]) continue;
const p = u.idx.price(c, 1);
rows.push({
NAME: C.str(r.NAME),
NAME2: C.str(r.NAME2 || ""),
SIZE: C.str(r.SIZE),
SIZE2: C.str(r.SIZE2 || ""),
UNIT: C.unitText(r.UNIT),
QTY: ex.qty[c],
PRICE: C.fix(p.M + p.L + p.S),
});
}
return rows;
}
async function run(ctx) {
if (!ctx.currentSourcePath || !ctx.dbfData) throw new Error("먼저 프로젝트를 불러오세요.");
const prj = ctx.dbfData.prjlst || {};
const won = Number(prj.COSTW1 || 0);
const head = {
PNAME: String(prj.PNAME || "").trim(),
PNUM: String(prj.PNUM || "").trim(),
BUDGET: `₩${won.toLocaleString("ko-KR")}원`,
};
for (const k of ["수요기관", "시공회사", "공사현장", "공사기간", "계약일자"]) {
const v = prompt(`[재료비 수량집계표를 엑셀파일로 만들기] ${k}`, "");
if (v === null) return;
head[k] = v;
}
const rows = materialRows(ctx);
if (!rows.length) throw new Error("재료비 수량집계표에 인쇄할 코드가 없습니다.");
const res = await fetch("/api/conv/jaje-sum-xlsx", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ source_path: ctx.currentSourcePath, head, rows }),
});
if (!res.ok) throw new Error(await res.text());
download(await res.blob(), `${head.PNAME.slice(0, 28) || "공사"}_주요건설자재현황.xlsx`);
}
PLUG.actions.Act_MkJaje = async (ctx) => {
try {
await run(ctx);
} catch (err) {
alert("엑셀파일 만들기 실패: " + err.message);
}
};
PLUG.menus.push({
menu: "m1",
label: "재료비 수량집계표를 엑셀파일로 만들기 (wM_JajeXLS)",
act: "Act_MkJaje",
});
})(window);