fix(est): preserve links and formula precision

This commit is contained in:
2026-11-05 12:51:49 +09:00
parent d922ad13f3
commit 516d2ae329
10 changed files with 215 additions and 19 deletions
+43 -1
View File
@@ -374,6 +374,48 @@ const EstModel = (() => {
});
return validate(project);
}
function editCode(project, table, index, value) {
const rows = project.tables[table],
row = rows[index];
const grouped = ["HeadMainDat", "CostMainDat", "MachMainDat"].includes(table);
const kind = Number(
Object.entries(EstNative.sourceTables).find(([, name]) => name === table)?.[0] ||
{ HeadMainDat: 103, CostMainDat: 104, MachMainDat: 105 }[table],
);
if (!kind || (grouped && !(Number(row.Index) > 0))) {
row.Code = value;
return;
}
const code = String(value || "").trim(),
old = row.Code;
if (
!code ||
rows.some(
(other, at) =>
at !== index &&
(!grouped || Number(other.Index) > 0) &&
(other.Code === code || other.PreviousCodes?.includes(code)),
)
)
throw Error("비어 있거나 중복된 원천 코드입니다.");
if (old === code) return;
row.Code = code;
row.PreviousCodes = [...new Set([...(row.PreviousCodes || []), old].filter(Boolean))];
for (const list of Object.values(project.tables))
for (const linked of list)
if (old && Number(linked.LinkIndex) === kind && linked.Code === old) linked.Code = code;
if (grouped) {
const titles = project.tables[EstNative.sourceTables[kind]] || [];
const title = titles.find((item) => item.Code === old);
if (title) Object.assign(title, { Code: code, PreviousCodes: [...row.PreviousCodes] });
for (
let at = index;
at < rows.length && (at === index || !(Number(rows[at].Index) > 0));
at++
)
if (rows[at].TitleCode === old) rows[at].TitleCode = code;
}
}
function newRow(table, rows) {
const max = Math.max(0, ...rows.map((r) => Number(r.PkID) || 0));
const row = {
@@ -397,5 +439,5 @@ const EstModel = (() => {
if (table === "CostMainDat") Object.assign(row, { LineData: "Q = 1 + 1 = \x122\x12" });
return row;
}
return { labels, numeric, columns, validate, legacy, newRow };
return { labels, numeric, columns, validate, legacy, newRow, editCode };
})();