diff --git a/resources/tester/test_est_documents.py b/resources/tester/test_est_documents.py index 7dab80c36..cb62065c2 100644 --- a/resources/tester/test_est_documents.py +++ b/resources/tester/test_est_documents.py @@ -44,3 +44,48 @@ def test_schedule_dates_ranges_and_weighted_user_progress(): assert result["valid"]["rows"][0]["width"] == 50 assert result["valid"]["rows"][1]["left"] == 50 assert result["bad"] == [True] * 4 + + +def test_schedule_import_and_update_weights_preserve_user_schedule(): + result = run( + "math", + """(()=>{ + const p=EstNative.empty(); + p.tables.EstMainDat=[{Code:'A',Name:'one',TC:100}, {Code:'B',Name:'two',TC:300}, + {Code:'HEADER',Level:1,TC:999},{Code:'TOTAL',LinkIndex:54,TC:400}]; + p.schedule=[{id:'old',Code:'A',Name:'custom',start:'2026-01-01',end:'2026-01-10',weight:1,progress:40}, + {id:'manual',Code:'other',Name:'manual',start:'',end:'',weight:5,progress:20}]; + let id=0;const added=EstSchedule.fromEstimate(p,()=>String(++id));p.schedule.push(...added); + p.tables.EstMainDat[0].TC=200;p.schedule=EstSchedule.refreshWeights(p); + let duplicate='';p.tables.EstMainDat.push({Code:'A',TC:20}); + try{EstSchedule.fromEstimate(p,()=>String(++id))}catch(e){duplicate=e.message} + return {added,rows:p.schedule,duplicate}; + })()""", + ) + assert [row["Code"] for row in result["added"]] == ["B"] + assert [row["weight"] for row in result["rows"]] == [200, 5, 300] + assert result["rows"][0]["Name"] == "custom" + assert result["rows"][0]["start"] == "2026-01-01" + assert result["rows"][0]["progress"] == 40 + assert result["duplicate"] + + +def test_schedule_imports_distinct_rows_with_repeated_or_empty_codes(): + result = run( + "math", + """(()=>{ + const p=EstNative.empty();p.tables.EstMainDat=[ + {PkID:1,Code:'X',Name:'one',TC:100},{PkID:2,Code:'X',Name:'two',TC:200}, + {PkID:3,Code:null,Name:'three',TC:300}]; + let id=0;p.schedule=EstSchedule.fromEstimate(p,()=>String(++id)); + p.schedule[0].start='2026-01-01';p.schedule[0].progress=50; + p.tables.EstMainDat.reverse();p.tables.EstMainDat[0].TC=400; + const updated=EstSchedule.refreshWeights(p); + return {rows:p.schedule,updated,again:EstSchedule.fromEstimate(p,()=>String(++id))}; + })()""", + ) + assert [row["SourceKey"] for row in result["rows"]] == ["id:1", "id:2", "id:3"] + assert [row["weight"] for row in result["updated"]] == [100, 200, 400] + assert result["updated"][0]["start"] == "2026-01-01" + assert result["updated"][0]["progress"] == 50 + assert result["again"] == [] diff --git a/tools/est-test/README.md b/tools/est-test/README.md index 61807ca56..348b2670d 100644 --- a/tools/est-test/README.md +++ b/tools/est-test/README.md @@ -14,7 +14,7 @@ - **조달청 XML**: DB에 보관된 공사원가호환규정 XSD 1.0.5의 요소 순서와 필드를 사용합니다. 작성업체·공사구분을 입력하며 코드/문구 길이와 연결 자료를 검사합니다. 내역·일위·산근·기계·기초 단가·원가를 내보내고 다시 읽습니다. 연결 없는 고정 금액·기계 상세는 독립 단가로 전개하며 변환 전에 알립니다. 가져온 저장 금액과 원문을 보존하고 자동계산을 끕니다. 이는 제출기관 인증/등록 검사나 최신 규정 적합 판정을 뜻하지 않습니다. - **JDL 기본 표**: 원본 검사 DLL의 필드 정의와 EST 처리기의 TAB/ENQ·CP949 표 구조에 따라 ZIP 안의 Global.ini·Main.txt·자원/공종/내역/원가 표를 생성·읽습니다. 일위대가 상세는 기본 플래그와 연결 자원이 확인된 행을 저장 금액과 함께 불러오며 특수 행은 원문에 보존하고 경고합니다. 자재·노무로 구성된 기본 일위대가는 상세표로 내보냅니다. 가져온 작업을 변경하지 않았다면 원본 JDL을 바이트 그대로 내보내 확장 자료를 보존합니다. 변경된 작업의 특수 일위·산근·기계는 저장 금액의 고정 단가로 전개하며 제외 행은 생략 사실을 알립니다. 확장 산식·기성/물가 파일의 완전 변환과 원본 검사 DLL 인증은 미확인입니다. - **원본 구조 유지 ESTX 수정 저장**: 가져온 파일의 공사명·계산 옵션과 행 수 및 인덱스 키가 유지된 단가·수량·문구·금액, 기존 BLOB과 원가 서식을 기록하고 재읽기로 검산합니다. 수량산출서는 기존 서식 구간 안의 텍스트 편집을 저장하며 표지와 문서 구조는 보존합니다. 한 줄에서 표지로 구분된 여러 구간을 함께 수정하거나 연속 글자 서식에 걸친 텍스트를 수정할 수도 있습니다. 새 텍스트에는 변경 시작 위치의 서식이 적용됩니다. 원본 결과가 기존 계산과 모두 일치하면 수정된 계산 결과 표지와 수량 목록을 함께 갱신합니다. 불일치나 계산 오류가 있으면 저장을 거부합니다. 기존 BLOB은 공간이 부족하면 블록을 추가합니다. 원본 파일을 덮어쓰지 않으며 `.idx`와 CAD 바이너리를 보존합니다. 새 문서, 행 추가·삭제·인덱스 키 변경, 표지나 위첨자 등 복잡한 구조를 가로지르는 편집과 목록·연결 변경, 웹 기성·연차·당초 사본은 지원하지 않아 저장을 거부합니다. 이 범위는 JSON으로 보관합니다. 원본 EST 실행 검증은 못했습니다. -- **예정공정표**: 공정별 기간·진도와 가중치를 입력하고 기간 막대 및 입력 진도의 가중평균을 표시합니다. 금액 가중치를 수정할 수 있으며 날짜 역전·잘못된 진도를 차단합니다. 공휴일/공기 산정 기준을 임의 적용하지 않습니다. +- **예정공정표**: 내역 행을 공정으로 일괄 추가하고 내역 금액으로 가중치를 갱신할 수 있습니다. 코드가 없거나 같은 코드가 반복된 행은 내역의 행 식별자로 구분합니다. 기존 공정의 기간·진도·이름은 유지합니다. 공정별 기간 막대와 입력 진도의 가중평균을 표시하며, 날짜 역전·잘못된 진도를 차단합니다. 공휴일/공기 산정 기준을 임의 적용하지 않습니다. - **공종별 동원 출력**: 한 번의 원천 계산에서 공종별 인원·자재·장비·실적·견적을 나누며 전체 합계와 금액/수량을 대조합니다. 문서 본문과 인쇄 설정도 저장·복원·취소 대상입니다. Ctrl+S는 입력 중인 셀도 확정한 뒤 저장합니다. 연속 저장 요청은 순서대로 처리하며, 저장 대기 중의 추가 입력이나 새로 연 문서를 이전 저장 응답으로 덮어쓰지 않습니다. 실행 취소는 현재 작업 파일의 연결을 유지합니다. diff --git a/tools/est-test/native-schedule.js b/tools/est-test/native-schedule.js index f376386af..0138f9a08 100644 --- a/tools/est-test/native-schedule.js +++ b/tools/est-test/native-schedule.js @@ -16,6 +16,11 @@ const EstSchedule = (() => { if (!row || typeof row.id !== "string" || !row.id || ids.has(row.id)) throw Error("공정 항목 ID 오류"); ids.add(row.id); + if ( + row.SourceKey != null && + (typeof row.SourceKey !== "string" || row.SourceKey.length > 1000) + ) + throw Error("공정 내역 연결 오류"); for (const key of ["Code", "Name", "start", "end"]) if (typeof row[key] !== "string" || row[key].length > 1000) throw Error("공정 문자열 오류"); for (const key of ["weight", "progress"]) @@ -53,33 +58,100 @@ const EstSchedule = (() => { end: dated.length ? new Date(last * 86400000).toISOString().slice(0, 10) : "", }; } + function estimateRows(project) { + const rows = new Map(), + codes = new Map(); + for (const row of project.tables.EstMainDat) { + if ( + Number(row.Level) > 0 || + Number(row.CalcIndex) >= 2 || + [54, 55, 58, 59].includes(Number(row.LinkIndex)) + ) + continue; + const key = row.PkID != null ? `id:${row.PkID}` : row.Code ? `code:${row.Code}` : ""; + if (!key) continue; + if (rows.has(key)) throw Error(`내역 행 식별자 중복: ${key}`); + rows.set(key, row); + if (row.Code) { + const matches = codes.get(row.Code) || []; + matches.push(key); + codes.set(row.Code, matches); + } + } + function sourceKey(row) { + if (row.SourceKey) return rows.has(row.SourceKey) ? row.SourceKey : ""; + const matches = codes.get(row.Code) || []; + if (matches.length > 1) throw Error(`기존 공정의 내역코드 중복: ${row.Code}`); + return matches[0] || ""; + } + return { rows, sourceKey }; + } + function fromEstimate(project, makeId) { + const { rows, sourceKey } = estimateRows(project), + existing = new Set((project.schedule || []).map(sourceKey).filter(Boolean)); + return [...rows.entries()] + .filter(([key]) => !existing.has(key)) + .map(([key, row]) => ({ + id: makeId(), + SourceKey: key, + Code: String(row.Code || ""), + Name: String(row.Name || ""), + start: "", + end: "", + weight: Math.max(0, Number(row.TC) || 0), + progress: 0, + })); + } + function refreshWeights(project) { + const { rows, sourceKey } = estimateRows(project); + return (project.schedule || []).map((row) => { + const key = sourceKey(row); + return { ...row, weight: key ? Math.max(0, Number(rows.get(key).TC) || 0) : row.weight }; + }); + } function render() { const { esc, number, state } = EstApp, output = calculate(state.project); EstApp.byId("work-content").innerHTML = - `
기간과 진도는 직접 입력합니다. 가중치는 공종 금액 또는 사용자가 정한 값을 사용합니다.
| ${h} | `).join("")}||
|---|---|---|
| `).join("")} |
기간과 진도는 직접 입력합니다. 가중치는 공종 금액 또는 사용자가 정한 값을 사용합니다.
| ${h} | `).join("")}||
|---|---|---|
| `).join("")} |