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