feat(est): manage quantity calculation sheets
This commit is contained in:
@@ -114,9 +114,8 @@ const EstQuantity = (() => {
|
||||
};
|
||||
}
|
||||
function selector(state) {
|
||||
if (!state.project.quantitySheets?.length) return "";
|
||||
const { esc } = EstApp;
|
||||
return `<div class="business-tools"><label>수량산출서 <select id="quantity-sheet-choice"><option value="manual">수식표 직접 작성</option>${state.project.quantitySheets.map((sheet) => `<option value="${esc(sheet.Code)}" ${state.quantitySheet === sheet.Code ? "selected" : ""}>${esc(sheet.Name || sheet.Code)}</option>`).join("")}</select></label></div>`;
|
||||
return `<div class="business-tools"><label>수량산출서 <select id="quantity-sheet-choice"><option value="manual">수식표 직접 작성</option>${(state.project.quantitySheets || []).map((sheet) => `<option value="${esc(sheet.Code)}" ${state.quantitySheet === sheet.Code ? "selected" : ""}>${esc(sheet.Name || sheet.Code)}</option>`).join("")}</select></label><button data-quantity-new>새 산출서</button></div>`;
|
||||
}
|
||||
function render(state) {
|
||||
state.quantitySheet ||= state.project.quantitySheets[0]?.Code;
|
||||
@@ -128,7 +127,7 @@ const EstQuantity = (() => {
|
||||
{ esc, number, byId } = EstApp;
|
||||
byId("work-content").innerHTML =
|
||||
selector(state) +
|
||||
`<div class="business-tools"><b>${esc(sheet.Name)}</b><button data-quantity-apply>내역 수량 반영</button></div><table class="sheet"><thead><tr><th>산출코드</th><th>품명</th><th>규격</th><th>원본 저장 수량</th><th>재계산 수량</th><th>연결 내역코드</th></tr></thead><tbody>${output.items.map((item, index) => `<tr><td>${esc(item.Code)}</td><td>${esc(item.Name)}</td><td>${esc(item.Size)}</td><td>${number(sheet.items[index].GN)}</td><td>${number(item.GN)}</td><td><input data-quantity-target="${index}" value="${esc(item.TargetCode || item.LinkCode || "")}" aria-label="연결 내역코드"></td></tr>`).join("")}</tbody></table><p class="business-note">${esc(output.errors.join(" / "))} 원본 결과 표지의 이름을 유지해 수량을 연결합니다. ESTX 저장 시 원본 결과가 계산과 일치하면 편집 결과와 수량 목록을 갱신합니다.</p><table class="sheet"><thead><tr><th>줄</th><th>산출근거 편집</th></tr></thead><tbody>${sheet.rows.map((row, index) => `<tr><td>${index + 1}</td><td><textarea data-quantity-line="${index}" rows="1" style="min-width:750px" aria-label="산출근거 ${index + 1}">${esc(EstText.display(output.rows[index].LineData))}</textarea></td></tr>`).join("")}</tbody></table>`;
|
||||
`<div class="business-tools"><label>산출서명 <input data-quantity-name value="${esc(sheet.Name)}"></label><button data-quantity-add>산출 행 추가</button><button data-quantity-apply>내역 수량 반영</button><button data-quantity-delete-sheet>산출서 삭제</button></div><table class="sheet"><thead><tr><th>산출코드</th><th>품명</th><th>규격</th><th>저장 수량</th><th>재계산 수량</th><th>연결 내역코드</th></tr></thead><tbody>${output.items.map((item, index) => `<tr><td>${esc(item.Code)}</td><td><input data-quantity-item="Name" data-index="${index}" value="${esc(item.Name || "")}" aria-label="품명"></td><td><input data-quantity-item="Size" data-index="${index}" value="${esc(item.Size || "")}" aria-label="규격"></td><td>${number(sheet.items[index].GN)}</td><td>${number(item.GN)}</td><td><input data-quantity-target="${index}" value="${esc(item.TargetCode ?? item.LinkCode ?? "")}" aria-label="연결 내역코드"></td></tr>`).join("")}</tbody></table><p class="business-note">${esc(output.errors.join(" / "))} 산출 행의 결과 표지로 수량 항목을 연결합니다. 신규 산출서와 행 변경은 JSON으로 저장합니다.</p><table class="sheet"><thead><tr><th>줄</th><th>산출근거 편집</th><th>작업</th></tr></thead><tbody>${sheet.rows.map((row, index) => `<tr><td>${index + 1}</td><td><textarea data-quantity-line="${index}" rows="1" style="min-width:750px" aria-label="산출근거 ${index + 1}">${esc(EstText.display(output.rows[index].LineData))}</textarea></td><td><button data-quantity-add data-index="${index}">아래 추가</button><button data-quantity-move="-1" data-index="${index}" ${index === 0 ? "disabled" : ""}>↑</button><button data-quantity-move="1" data-index="${index}" ${index === sheet.rows.length - 1 ? "disabled" : ""}>↓</button><button data-quantity-delete-row="${index}">삭제</button></td></tr>`).join("")}</tbody></table>`;
|
||||
}
|
||||
function install() {
|
||||
document.addEventListener("change", (event) => {
|
||||
@@ -141,6 +140,13 @@ const EstQuantity = (() => {
|
||||
}
|
||||
const sheet = state.project.quantitySheets?.find((s) => s.Code === state.quantitySheet);
|
||||
if (!sheet) return;
|
||||
if (node.dataset.quantityName !== undefined)
|
||||
EstApp.change(() => (sheet.Name = node.value), false);
|
||||
if (["Name", "Size"].includes(node.dataset.quantityItem))
|
||||
EstApp.change(
|
||||
() => (sheet.items[Number(node.dataset.index)][node.dataset.quantityItem] = node.value),
|
||||
false,
|
||||
);
|
||||
if (node.dataset.quantityLine !== undefined)
|
||||
EstApp.change(
|
||||
() =>
|
||||
@@ -154,16 +160,76 @@ const EstQuantity = (() => {
|
||||
);
|
||||
});
|
||||
document.addEventListener("click", (event) => {
|
||||
const { state } = EstApp;
|
||||
if (event.target.closest("[data-quantity-new]")) {
|
||||
EstApp.change(() => {
|
||||
const code = `Q${crypto.randomUUID()}`;
|
||||
state.project.quantitySheets ||= [];
|
||||
state.project.quantitySheets.push({
|
||||
Code: code,
|
||||
Name: "새 수량산출서",
|
||||
rows: [],
|
||||
items: [],
|
||||
options: { digits: 2, roundMode: 2 },
|
||||
});
|
||||
state.quantitySheet = code;
|
||||
}, false);
|
||||
return;
|
||||
}
|
||||
const sheet = state.project.quantitySheets?.find((s) => s.Code === state.quantitySheet);
|
||||
const addRow = event.target.closest("[data-quantity-add]");
|
||||
if (addRow && sheet) {
|
||||
EstApp.change(() => {
|
||||
const code = `r${crypto.randomUUID()}`;
|
||||
const at =
|
||||
addRow.dataset.index === undefined
|
||||
? sheet.rows.length
|
||||
: Number(addRow.dataset.index) + 1;
|
||||
sheet.rows.splice(at, 0, { LineData: "1 = \x120\x12", markers: [code] });
|
||||
sheet.items.push({ Code: code, Name: "새 항목", Size: "", GN: 0, TargetCode: "" });
|
||||
}, false);
|
||||
return;
|
||||
}
|
||||
const moveRow = event.target.closest("[data-quantity-move]");
|
||||
if (moveRow && sheet) {
|
||||
const index = Number(moveRow.dataset.index),
|
||||
next = index + Number(moveRow.dataset.quantityMove);
|
||||
if (index >= 0 && index < sheet.rows.length && next >= 0 && next < sheet.rows.length)
|
||||
EstApp.change(() => {
|
||||
[sheet.rows[index], sheet.rows[next]] = [sheet.rows[next], sheet.rows[index]];
|
||||
}, false);
|
||||
return;
|
||||
}
|
||||
const deleteRow = event.target.closest("[data-quantity-delete-row]");
|
||||
if (deleteRow && sheet) {
|
||||
if (confirm("이 산출 행과 연결된 수량 항목을 삭제하시겠습니까?"))
|
||||
EstApp.change(() => {
|
||||
const [removed] = sheet.rows.splice(Number(deleteRow.dataset.quantityDeleteRow), 1);
|
||||
const remaining = new Set(sheet.rows.flatMap((row) => row.markers || []));
|
||||
sheet.items = sheet.items.filter(
|
||||
(item) => !removed.markers.includes(item.Code) || remaining.has(item.Code),
|
||||
);
|
||||
}, false);
|
||||
return;
|
||||
}
|
||||
if (event.target.closest("[data-quantity-delete-sheet]") && sheet) {
|
||||
if (confirm("이 수량산출서를 삭제하시겠습니까?"))
|
||||
EstApp.change(() => {
|
||||
state.project.quantitySheets = state.project.quantitySheets.filter(
|
||||
(item) => item !== sheet,
|
||||
);
|
||||
state.quantitySheet = state.project.quantitySheets[0]?.Code || "manual";
|
||||
}, false);
|
||||
return;
|
||||
}
|
||||
if (!event.target.closest("[data-quantity-apply]")) return;
|
||||
try {
|
||||
const { state } = EstApp,
|
||||
sheet = state.project.quantitySheets.find((s) => s.Code === state.quantitySheet),
|
||||
output = calculate(sheet);
|
||||
const output = calculate(sheet);
|
||||
if (output.errors.length) throw Error(output.errors.join(" / "));
|
||||
const quantities = new Map();
|
||||
for (const item of output.items)
|
||||
if (item.TargetCode || item.LinkCode) {
|
||||
const code = item.TargetCode || item.LinkCode;
|
||||
if (item.TargetCode ?? item.LinkCode) {
|
||||
const code = item.TargetCode ?? item.LinkCode;
|
||||
const targets = state.project.tables.EstMainDat.filter(
|
||||
(r) => r.Code === code && !Number(r.Level),
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user