feat(est): add document and exchange workflows
This commit is contained in:
@@ -117,11 +117,28 @@ const EstNative = (() => {
|
||||
errors = [],
|
||||
warnings = [];
|
||||
for (const key of allTables) tables[key] ||= [];
|
||||
function saveTitles(table, calculated) {
|
||||
const byCode = new Map(calculated.map((row) => [row.Code, row]));
|
||||
const existing = new Set(tables[table].map((row) => row.Code));
|
||||
tables[table] = tables[table]
|
||||
.map((row) => {
|
||||
const result = byCode.get(row.Code);
|
||||
if (!result) return row;
|
||||
const merged = { ...row, ...result };
|
||||
// Main-row identities belong to a different native table/index.
|
||||
for (const key of ["PkID", "Index", "RecNo", "Flag"]) {
|
||||
if (Object.hasOwn(row, key)) merged[key] = row[key];
|
||||
else delete merged[key];
|
||||
}
|
||||
return merged;
|
||||
})
|
||||
.concat(calculated.filter((row) => !existing.has(row.Code)));
|
||||
}
|
||||
for (const kind of [5, 6, 21, 101])
|
||||
for (const row of tables[sourceTables[kind]]) price(row, kind);
|
||||
const machine = EstMachine.calculate(tables.MachMainDat, tables.MachGijunDat, options);
|
||||
tables.MachMainDat = machine.rows;
|
||||
tables.MachTitleDat = machine.titles;
|
||||
saveTitles("MachTitleDat", machine.titles);
|
||||
errors.push(...machine.errors);
|
||||
const costs = groups(tables.CostMainDat),
|
||||
heads = groups(tables.HeadMainDat),
|
||||
@@ -219,9 +236,10 @@ const EstNative = (() => {
|
||||
errors.push(error.message);
|
||||
}
|
||||
}
|
||||
tables.CostTitleDat = [...costs.keys()]
|
||||
.map((code) => completed.get(`104:${code}`))
|
||||
.filter(Boolean);
|
||||
saveTitles(
|
||||
"CostTitleDat",
|
||||
[...costs.keys()].map((code) => completed.get(`104:${code}`)).filter(Boolean),
|
||||
);
|
||||
for (const [code] of heads) {
|
||||
try {
|
||||
calculateGroup(103, code);
|
||||
@@ -229,9 +247,10 @@ const EstNative = (() => {
|
||||
errors.push(error.message);
|
||||
}
|
||||
}
|
||||
tables.HeadTitleDat = [...heads.keys()]
|
||||
.map((code) => completed.get(`103:${code}`))
|
||||
.filter(Boolean);
|
||||
saveTitles(
|
||||
"HeadTitleDat",
|
||||
[...heads.keys()].map((code) => completed.get(`103:${code}`)).filter(Boolean),
|
||||
);
|
||||
const estimate = EstRows.estimate(tables.EstMainDat, options, resolve);
|
||||
tables.EstMainDat = estimate.rows;
|
||||
errors.push(...estimate.errors);
|
||||
|
||||
Reference in New Issue
Block a user