-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmodules.js
More file actions
151 lines (136 loc) · 6.57 KB
/
modules.js
File metadata and controls
151 lines (136 loc) · 6.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
/**
* Modules Variable File
* Maps product numbers (unit names) to their standard unit variant numbers
*
* This file serves as a lookup table for generating Bill of Materials (BOM)
* and enriching unit data with product information.
*/
/**
* Module definition
* @typedef {Object} Module
* @property {string} productNumber - The product number (unit name)
* @property {string} standardUnitVariantNumber - The standard unit variant number
* @property {string} description - Optional description of the module
*/
/**
* All available modules from EBP files
* @type {Module[]}
*/
export const MODULES = [
// From connect50_v-1+.ebp
{ productNumber: "010-02575-10_mcuv2", standardUnitVariantNumber: "100257510", description: "MCU v2" },
{ productNumber: "010-02223-11_mcu100", standardUnitVariantNumber: "2051011", description: "MCU 100" },
{ productNumber: "010-02225-10", standardUnitVariantNumber: "2110110", description: "" },
{ productNumber: "010-02225-16", standardUnitVariantNumber: "2110115", description: "" },
{ productNumber: "010-02225-17", standardUnitVariantNumber: "2110116", description: "" },
{ productNumber: "010-02225-18", standardUnitVariantNumber: "2110117", description: "" },
{ productNumber: "010-02275-01", standardUnitVariantNumber: "0152", description: "" },
{ productNumber: "010-02275-02", standardUnitVariantNumber: "0151", description: "" },
{ productNumber: "010-02225-19", standardUnitVariantNumber: "2110118", description: "" },
{ productNumber: "010-02275-03", standardUnitVariantNumber: "0152", description: "" },
{ productNumber: "010-02225-05", standardUnitVariantNumber: "2110103", description: "" },
{ productNumber: "010-02225-06", standardUnitVariantNumber: "2110104", description: "" },
{ productNumber: "010-02225-07", standardUnitVariantNumber: "2110105", description: "" },
{ productNumber: "010-02279-02", standardUnitVariantNumber: "2210102", description: "" },
{ productNumber: "010-02279-03", standardUnitVariantNumber: "2210103", description: "" },
// From connect50 v2_v-1+.ebp
{ productNumber: "010-02575-10", standardUnitVariantNumber: "100257510", description: "MCU v2" },
{ productNumber: "MFD / WDU", standardUnitVariantNumber: "88888888", description: "MFD / WDU" },
{ productNumber: "010-02225-30", standardUnitVariantNumber: "100222530", description: "" },
{ productNumber: "010-02225-31", standardUnitVariantNumber: "100222531", description: "" },
{ productNumber: "010-02278-21", standardUnitVariantNumber: "100227821", description: "" },
{ productNumber: "010-02279-20", standardUnitVariantNumber: "100227920", description: "" },
{ productNumber: "010-02279-21", standardUnitVariantNumber: "100227921", description: "" },
// From DCM.ebp
{ productNumber: "MCU v2", standardUnitVariantNumber: "100257510", description: "MCU v2" },
{ productNumber: "010-02219-01", standardUnitVariantNumber: "11", description: "" },
{ productNumber: "010-02219-02", standardUnitVariantNumber: "12", description: "" },
{ productNumber: "010-02219-03", standardUnitVariantNumber: "13", description: "" },
{ productNumber: "010-02219-04", standardUnitVariantNumber: "14", description: "" },
{ productNumber: "010-02219-05", standardUnitVariantNumber: "15", description: "" },
{ productNumber: "010-02219-55", standardUnitVariantNumber: "55", description: "" },
{ productNumber: "010-02220-06", standardUnitVariantNumber: "16", description: "" },
{ productNumber: "010-02220-07", standardUnitVariantNumber: "17", description: "" },
{ productNumber: "010-02220-08", standardUnitVariantNumber: "18", description: "" },
{ productNumber: "010-02220-09", standardUnitVariantNumber: "19", description: "" },
{ productNumber: "010-02220-10", standardUnitVariantNumber: "20", description: "" },
{ productNumber: "010-02221-08", standardUnitVariantNumber: "28", description: "" },
{ productNumber: "010-02222-10", standardUnitVariantNumber: "30", description: "" }
];
/**
* Create a lookup map for quick access by product number
* @type {Map<string, Module>}
*/
export const MODULE_MAP = new Map(
MODULES.map(module => [module.productNumber, module])
);
/**
* Create a reverse lookup map by standard unit variant number
* @type {Map<string, Module[]>}
*/
export const VARIANT_MAP = MODULES.reduce((map, module) => {
const variant = module.standardUnitVariantNumber;
if (!map.has(variant)) {
map.set(variant, []);
}
map.get(variant).push(module);
return map;
}, new Map());
/**
* Get module information by product number
* @param {string} productNumber - The product number to look up
* @returns {Module|undefined} The module information or undefined if not found
*/
export function getModuleByProductNumber(productNumber) {
return MODULE_MAP.get(productNumber);
}
/**
* Get module(s) by standard unit variant number
* @param {string} variantNumber - The variant number to look up
* @returns {Module[]} Array of modules with this variant number
*/
export function getModulesByVariantNumber(variantNumber) {
return VARIANT_MAP.get(variantNumber) || [];
}
/**
* Generate a Bill of Materials from an array of units
* @param {Array} units - Array of unit objects with name and standardUnitVariantNumber
* @returns {Array} BOM entries with product number, variant number, and quantity
*/
export function generateBOM(units) {
const bomMap = new Map();
units.forEach(unit => {
const key = `${unit.name}|${unit.standardUnitVariantNumber || ''}`;
if (bomMap.has(key)) {
bomMap.get(key).quantity++;
} else {
bomMap.set(key, {
productNumber: unit.name,
standardUnitVariantNumber: unit.standardUnitVariantNumber || 'N/A',
quantity: 1,
serial: unit.serial || '0',
unitTypeId: unit.unitTypeId || 'N/A'
});
}
});
return Array.from(bomMap.values()).sort((a, b) =>
a.productNumber.localeCompare(b.productNumber)
);
}
/**
* Get unique modules from the MODULES array
* Removes duplicates based on product number and variant number combination
* @returns {Module[]} Array of unique modules
*/
export function getUniqueModules() {
const uniqueMap = new Map();
MODULES.forEach(module => {
const key = `${module.productNumber}|${module.standardUnitVariantNumber}`;
if (!uniqueMap.has(key)) {
uniqueMap.set(key, module);
}
});
return Array.from(uniqueMap.values()).sort((a, b) =>
a.productNumber.localeCompare(b.productNumber)
);
}