61 lines
1.9 KiB
JavaScript
61 lines
1.9 KiB
JavaScript
function exportMachines(project, tables, map, ambiguous, num, next, source, warnings) {
|
||
const groups = new Map();
|
||
let group;
|
||
for (const row of project.tables.MachMainDat || []) {
|
||
if (num(row.Index) > 0) {
|
||
group = [];
|
||
if (groups.has(row.Code)) groups.set(row.Code, null);
|
||
else groups.set(row.Code, group);
|
||
} else if (group) group.push(row);
|
||
}
|
||
for (const title of project.tables.MachTitleDat || []) {
|
||
const parts = groups.get(title.Code);
|
||
if (
|
||
!title.Code ||
|
||
ambiguous.has("105:" + title.Code) ||
|
||
!parts?.length ||
|
||
num(title.SC) ||
|
||
parts.some((row) => !row.JdlSummary || num(row.CalcIndex) !== 1 || num(row.SC)) ||
|
||
["GC", "NC", "JC"].some(
|
||
(field) =>
|
||
Math.abs(parts.reduce((sum, row) => sum + num(row[field]), 0) - num(title[field])) > 1e-6,
|
||
)
|
||
)
|
||
continue;
|
||
const code = "J" + String(next()).padStart(10, "0");
|
||
map.set("105:" + title.Code, code);
|
||
tables["junit.txt"].push({
|
||
F_CODE: code,
|
||
F_DES: title.Name,
|
||
F_SIZE: title.Size,
|
||
F_UNIT: title.Unite,
|
||
F_MPRICE: num(title.GC),
|
||
F_LPRICE: num(title.NC),
|
||
F_EPRICE: num(title.JC),
|
||
F_ORICODE: "00000000000",
|
||
});
|
||
for (const [index, row] of parts.entries()) {
|
||
const code1 = source(0, { ...row, Code: "MACHINE-PART-" + next() });
|
||
tables["jpart.txt"].push({
|
||
F_CODE: code,
|
||
F_SEQ: String(index + 1),
|
||
F_CODE1: code1,
|
||
F_DES: row.Name,
|
||
F_SIZE: row.Size,
|
||
F_UNIT: row.Unite,
|
||
F_QQTY: ["%", "%"].includes(row.Unite) ? 100 : 1,
|
||
F_MPRICE: num(row.GC),
|
||
F_LPRICE: num(row.NC),
|
||
F_EPRICE: num(row.JC),
|
||
F_SPROPER: "0",
|
||
F_LOADBM: "T",
|
||
F_SAVEBM: "T",
|
||
F_ORICODE: "00000000000",
|
||
});
|
||
}
|
||
warnings.push(`${title.Code}: 기계 상세를 고정 금액으로 내보냅니다.`);
|
||
}
|
||
}
|
||
|
||
module.exports = { exportMachines };
|