fix(est): apply head cost classification safely

This commit is contained in:
2026-11-07 16:39:55 +09:00
parent 9eae77d8f2
commit 5e72aff136
7 changed files with 68 additions and 18 deletions
+11 -5
View File
@@ -82,10 +82,11 @@ const EstRows = (() => {
);
return amounts(row, digits);
}
function head(rows, options = {}, resolve = () => null) {
function head(rows, options = {}, resolve = () => null, refreshRows = []) {
const output = structuredClone(rows),
titles = [],
errors = [];
errors = [],
refreshErrors = [];
let current = null,
body = [];
function finish() {
@@ -93,7 +94,7 @@ const EstRows = (() => {
Object.assign(current, add(body));
titles.push({ ...current });
}
for (const row of output) {
for (const [index, row] of output.entries()) {
if (num(row.Index) > 0) {
finish();
current = row;
@@ -119,12 +120,15 @@ const EstRows = (() => {
body = [row];
continue;
} 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(`${current.Name}: ${error.message}`);
if (requested) refreshErrors.push(error.message);
}
}
amounts(row, options.HeadDigits || 0, options.TotalFit);
@@ -132,7 +136,9 @@ const EstRows = (() => {
body.push(row);
}
finish();
return { rows: output, titles, errors };
return refreshRows.length
? { rows: output, titles, errors, refreshErrors }
: { rows: output, titles, errors };
}
function estimate(rows, options = {}, resolve = () => null, refreshRows = []) {
const output = structuredClone(rows),