fix(est): match prior unnamed cost codes

This commit is contained in:
2026-11-07 02:38:42 +09:00
parent c03929e369
commit 19097b7255
3 changed files with 33 additions and 5 deletions
+13 -4
View File
@@ -224,11 +224,20 @@ const EstProgress = (() => {
row[prefix + field] = children.reduce((n, child) => n + num(child[prefix + field]), 0);
}
const acceptedCost = round.approved ? sa : gum;
const priorCosts = new Map(
(previous?.costs || previous?.wonga || []).map((row) => [row.Gubun ?? row.Name, row]),
);
const costKeys = (items) => {
const occurrences = new Map();
return items.map((row) => {
const identity = JSON.stringify(row.Gubun ? ["code", row.Gubun] : ["name", row.Name || ""]);
const occurrence = occurrences.get(identity) || 0;
occurrences.set(identity, occurrence + 1);
return JSON.stringify([identity, occurrence]);
});
};
const oldCosts = previous?.costs || previous?.wonga || [];
const priorCosts = new Map(costKeys(oldCosts).map((key, index) => [key, oldCosts[index]]));
const currentKeys = costKeys(acceptedCost.rows);
const costs = acceptedCost.rows.map((row, index) => {
const previous = priorCosts.get(row.Gubun ?? row.Name);
const previous = priorCosts.get(currentKeys[index]);
const jun = num(previous?.TotalCost ?? previous?.Cost);
return {
...row,