fix(est): apply selected estimate classification safely

This commit is contained in:
2026-11-07 16:30:44 +09:00
parent c530ac694c
commit 9eae77d8f2
8 changed files with 138 additions and 9 deletions
+11 -5
View File
@@ -134,13 +134,14 @@ const EstRows = (() => {
finish();
return { rows: output, titles, errors };
}
function estimate(rows, options = {}, resolve = () => null) {
function estimate(rows, options = {}, resolve = () => null, refreshRows = []) {
const output = structuredClone(rows),
errors = [];
errors = [],
refreshErrors = [];
let segment = [],
prior = [],
boundary = false;
for (const row of output) {
for (const [index, row] of output.entries()) {
const level = num(row.Level),
link = num(row.LinkIndex);
if (level > 0) {
@@ -160,12 +161,15 @@ const EstRows = (() => {
if (link === 57) procurement(row, segment);
else if ([62, 67, 58].includes(link)) percent(row, segment, options.EstDigits || 0);
else {
if (options.SourceRefresh && ![1, 3].includes(num(row.CalcIndex))) {
const requested = refreshRows.includes(index);
if ((options.SourceRefresh || requested) && ![1, 3].includes(num(row.CalcIndex))) {
try {
const price = resolve(row);
if (requested && !price) throw Error("원천 단가를 찾을 수 없습니다.");
if (price) units.forEach((key, i) => (row[key] = num(price[components[i]])));
} catch (error) {
errors.push(`${row.Name}: ${error.message}`);
if (requested) refreshErrors.push(error.message);
}
}
amounts(row, options.EstDigits || 0, options.TotalFit);
@@ -186,7 +190,9 @@ const EstRows = (() => {
Object.assign(row, add(children));
}
const direct = output.find((r) => num(r.LinkIndex) === 54) || add(prior);
return { rows: output, direct, errors };
return refreshRows.length
? { rows: output, direct, errors, refreshErrors }
: { rows: output, direct, errors };
}
return { head, estimate, percent, procurement, subtotal, baseKind };
})();