Files
Aislo/tools/est-test/native-work-mode.js
T
eomsangdonandClaude Opus 5.5 4cf7ebd783 feat(est-test): 작업모드 표준내역서·표준설계변경, 설치 원가계산서 양식목록, 최근 계약심사목록
- 작업모드 값(CurrentWorkMode) ESTX 읽기·쓰기
- 일반↔표준 묶음 바꿀 때 원가계산서 보관·꺼내기, 없으면 설치 양식(일반·표준 각 30종)에서 고르기
- 저장한 작업 중 계약심사 작업 목록

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-12 19:30:56 +09:00

105 lines
5.1 KiB
JavaScript

// 원본 작업모드 바꾸기(0x10cb8b4 — spec_pc §4): 내역서 1 · 설계변경 2 · 표준내역서 3(mnuProgramSEst) · 표준설계변경 4(mnuProgramSCEst).
// 일반(1·2) ↔ 표준(3·4) 묶음이 바뀌면 지금 원가계산서를 옛 묶음 칸에 두고 새 묶음 원가계산서를 꺼낸다(0x113c80c) — 그 묶음에
// 둔 것이 없으면 설치 원가계산서 양식목록(일반 WongaFileList · 표준 SWongaFileList)에서 고른다. 모드 값은 TCommonOption.CurrentWorkMode.
// 원본은 모드를 바꿀 때 지금 문서를 닫고 최근 작업 목록을 띄우지만, 웹은 지금 작업을 그대로 두고 화면만 옮긴다.
// 그리고 「최근 계약심사목록」(mnuInvestWorkFileList 0x10d0c88): 저장한 작업 중 계약심사 작업만.
const EstWorkMode = (() => {
const NAMES = { 1: "내역서", 2: "설계변경", 3: "표준내역서", 4: "표준설계변경" };
const standard = (mode) => [3, 4, 12].includes(Number(mode));
const groupOf = (mode) => (standard(mode) ? "standard" : "general");
const mode = (project) => Number(project.options.WorkMode) || 1;
// 묶음 바꾸기: 옛 원가계산서를 보관하고 새 묶음 것을 돌려줌(없으면 null)
function swap(project, next) {
const from = groupOf(mode(project)),
to = groupOf(next);
project.options.WorkMode = next;
if (from === to) return { changed: false };
project.wongaByGroup ||= {};
project.wongaByGroup[from] = structuredClone(project.tables.Wonga || []);
const kept = project.wongaByGroup[to];
if (kept) {
project.tables.Wonga = structuredClone(kept);
delete project.wongaByGroup[to];
}
return { changed: true, found: Boolean(kept) };
}
async function picker(state, std, after = "") {
const { esc } = EstApp,
list = await EstApp.api(`/api/wonga-formats?std=${std ? 1 : 0}`);
EstApp.showDialog(
`${std ? "표준" : "일반"} 원가계산서 양식목록`,
`<p>${esc(after)}</p><table class="sheet"><thead><tr><th>No</th><th>양식 이름</th><th></th></tr></thead><tbody>${list
.map(
(f) =>
`<tr><td>${f.index}</td><td style="text-align:left">${esc(f.name)}</td><td><button data-action="wonga-install-open" data-std="${std ? 1 : 0}" data-index="${f.index}">열 기</button></td></tr>`,
)
.join("")}</tbody></table>`,
);
}
async function openForm(state, std, index) {
const form = await EstApp.api(`/api/wonga-formats?std=${std}&index=${index}`);
// 설치 양식은 번호(NumStr)로 서로 가리키는 꼴 — 번호 기준 계산(VerFormat 끔)
EstApp.change((project) => {
project.options.TotalFix = false;
project.options.VerFormat = false;
project.tables.Wonga = structuredClone(form.rows);
});
EstApp.byId("dialog").close();
state.notice = `원가계산서를 「${form.name}」 양식으로 바꿨습니다.`;
EstApp.render();
}
async function switchTo(state, next) {
const project = state.project;
if (mode(project) === next) {
state.view = next === 2 || next === 4 ? "change" : "EstMainDat";
return EstApp.render();
}
let result;
EstApp.change((p) => (result = swap(p, next)));
state.view = next === 2 || next === 4 ? "change" : "EstMainDat";
state.notice = `작업모드: ${NAMES[next]}`;
EstApp.render();
if (result.changed && !result.found)
await picker(
state,
standard(next),
`${NAMES[next]} 모드의 원가계산서 양식을 고르세요. (지금 원가계산서는 ${standard(next) ? "일반" : "표준"} 쪽에 보관)`,
);
}
async function investList(state) {
const { esc } = EstApp,
list = (await EstApp.api("/api/projects")).filter((p) => p.invest);
EstApp.showDialog(
"최근 계약심사목록",
`<button data-action="projects">다른공사열기</button> <button data-action="new">새공사시작</button><table class="sheet" style="margin-top:6px"><thead><tr><th>구 분</th><th>공 사 명</th><th>최종작업일</th><th></th></tr></thead><tbody>${
list
.map(
(p) =>
`<tr><td>계약심사</td><td style="text-align:left">${esc(p.name)}</td><td>${esc(String(p.modified).slice(0, 10))}</td><td><button data-action="load-project" data-id="${p.id}">열 기</button><button data-action="project-hide" data-id="${p.id}">목록에서삭제</button></td></tr>`,
)
.join("") || '<tr><td colspan="4">계약심사 작업이 없습니다.</td></tr>'
}</tbody></table>`,
);
}
function handle(name, state, node) {
const fail = (error) => {
state.notice = error.message;
EstApp.render();
};
if (name === "work-mode") switchTo(state, Number(node.dataset.mode)).catch(fail);
else if (name === "wonga-install-list")
picker(state, standard(mode(state.project))).catch(fail);
else if (name === "wonga-install-open")
openForm(state, node.dataset.std, node.dataset.index).catch(fail);
else if (name === "invest-work-list") investList(state).catch(fail);
else return false;
return true;
}
return { swap, groupOf, NAMES, handle };
})();