diff --git a/.vscode/settings.json b/.vscode/settings.json index 4bbc598..02b0046 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -49,9 +49,11 @@ "go.formatTool": "goimports", "cSpell.words": [ "acitve", + "actaully", "alpla", "alplamart", "alplaprod", + "autoconsume", "intiallally", "ppoo", "prodlabels", diff --git a/lstV2/server/services/ocp/controller/materials/mainMaterial.ts b/lstV2/server/services/ocp/controller/materials/mainMaterial.ts index 2ecc889..36c7066 100644 --- a/lstV2/server/services/ocp/controller/materials/mainMaterial.ts +++ b/lstV2/server/services/ocp/controller/materials/mainMaterial.ts @@ -7,7 +7,10 @@ import { mmQuery } from "../../../sqlServer/querys/ocp/mainMaterial.js"; export const isMainMatStaged = async (lot: any) => { const set = serverSettings.length === 0 ? [] : serverSettings; - // make staged false by deefault and error logged if theres an issue + const checkColorSetting = set.filter((n) => n.name === "checkColor"); + const checkPKGSetting = set.filter((n) => n.name === "checkPKG"); + + // make staged false by default and error logged if theres an issue let isStaged = { message: "Material is staged", success: true }; const { data, error } = (await tryCatch( @@ -43,7 +46,7 @@ export const isMainMatStaged = async (lot: any) => { }; } - // strangly the lot is not always sending over in slc so adding this in for now to see what line is cauing this issue + // strangely the lot is not always sending over in slc so adding this in for now to see what line is cauing this issue if (!lot) { createLog("info", "mainMaterial", "ocp", "No lot was passed correctly."); return isStaged; @@ -125,7 +128,11 @@ export const isMainMatStaged = async (lot: any) => { createLog("info", "mainMaterial", "ocp", `Maint material query ran.`); const mainMaterial = res.find((n: any) => n.IsMainMaterial); - if (mainMaterial?.Staged === 1) { + + if ( + mainMaterial?.Staged === 1 && + (checkColorSetting[0].value !== "1" || checkPKGSetting[0].value !== "1") + ) { createLog( "info", "mainMaterial", @@ -152,7 +159,6 @@ export const isMainMatStaged = async (lot: any) => { // we need to filter the color stuff and then look for includes instead of a standard name. this way we can capture a everything and not a single type // for manual consume color if active to check colors - const checkColorSetting = set.filter((n) => n.name === "checkColor"); // 2. Auto color if (checkColorSetting[0].value === "1") { @@ -162,7 +168,7 @@ export const isMainMatStaged = async (lot: any) => { results: res, lot, filterFn: (n) => - n.isManual && + !n.isManual && !("noPKGAutoShortage" in n) && !("noPKGManualShortage" in n), // pool = non-main, auto failCondition: (n) => n.autoConsumeCheck === "autoConsumeNOK", // column = autoConsumeCheck @@ -202,7 +208,7 @@ export const isMainMatStaged = async (lot: any) => { } // // if we want to check the packaging - const checkPKGSetting = set.filter((n) => n.name === "checkPKG"); + if (checkPKGSetting[0].value === "1") { const pkgAuto = checkCondition({ results: res, diff --git a/lstV2/server/services/ocp/controller/materials/materialChecks.ts b/lstV2/server/services/ocp/controller/materials/materialChecks.ts new file mode 100644 index 0000000..1b70179 --- /dev/null +++ b/lstV2/server/services/ocp/controller/materials/materialChecks.ts @@ -0,0 +1,148 @@ +import { tryCatch } from "../../../../globalUtils/tryCatch.js"; +import { createLog } from "../../../logger/logger.js"; +import { serverSettings } from "../../../server/controller/settings/getSettings.js"; +import { query } from "../../../sqlServer/prodSqlServer.js"; +import { machineCheck } from "../../../sqlServer/querys/ocp/machineId.js"; +import { mmQuery } from "../../../sqlServer/querys/ocp/mainMaterial.js"; + +export const isMainMatStaged = async (lot: any) => { + const set = serverSettings.length === 0 ? [] : serverSettings; + // make staged false by default and error logged if theres an issue + let isStaged = { message: "Material is staged", success: true }; + + // validate the machine actaully needs materials to print + const { data, error } = (await tryCatch( + query( + machineCheck.replace("where Active = 1 and [Location] = [loc]", ""), + "check machine needs mm", + ), + )) as any; + + const machine = data.data.filter( + (m: any) => m.HumanReadableId === lot.machineID, + ); + + // just in case we encounter an issue with the machines + if (machine.length === 0) { + createLog( + "error", + "mainMaterial", + "ocp-system", + "Invalid machine passed over.", + ); + return { + success: false, + message: "Invalid machine passed over.", + }; + } + + // we have a check on ksc side to ignore the tetra machine for now as its not updating in 2.0 + if (!machine[0].StagingMainMaterialMandatory) { + createLog( + "info", + "mainMaterial", + "ocp", + `The machine dose not require mm to print and book in.`, + ); + return { + message: "Machine dose not require material to be staged", + success: true, + }; + } + + // strangely the lot is not always sending over in slc so adding this in for now to see what line is cauing this issue + if (!lot) { + createLog("info", "mainMaterial", "ocp", "No lot was passed correctly."); + return isStaged; + } + + if (typeof lot !== "object" || lot === null || Array.isArray(lot)) { + createLog( + "info", + "mainMaterial", + "ocp", + `The lot sent over is not an object: ${JSON.stringify(lot)}`, + ); + return isStaged; + } + + // get the materials needed for the passed over lot + const { data: material, error: errorMat } = (await tryCatch( + query(mmQuery.replaceAll("[lotNumber]", lot.lot), "Main Material Check"), + )) as any; + + if (errorMat) { + return { message: "Failed to get lot info", success: false }; + } + + const mat = material.data; + + const mainMaterial = mat.find((n: any) => n.IsMainMaterial); + const checkColorSetting = set.filter((n) => n.name === "checkColor"); + const checkPKGSetting = set.filter((n) => n.name === "checkPKG"); + + // if we only care about having the check for mm staged and dont care about the rules we just let it fly by. + // risk here is getting $Shortage if there really is nothing + if ( + mainMaterial?.Staged === 1 && + (checkColorSetting[0].value !== "1" || checkPKGSetting[0].value !== "1") + ) { + createLog( + "info", + "mainMaterial", + "ocp", + `Main material: ${mainMaterial.MaterialHumanReadableId} - ${mainMaterial.MaterialDescription}: is staged for ${lot.lot}`, + ); + return { + message: `Main material: ${mainMaterial.MaterialHumanReadableId} - ${mainMaterial.MaterialDescription}: is staged for ${lot.lot}`, + success: true, + }; + } + + // do we have enough main material for the next pallet + if (mainMaterial?.noMMShortage === "noMM") { + createLog( + "info", + "mainMaterial", + "ocp", + `Main material: ${mainMaterial.MaterialHumanReadableId} - ${mainMaterial.MaterialDescription}: is not staged for ${lot.lot}`, + ); + return { + message: `Main material: ${mainMaterial.MaterialHumanReadableId} - ${mainMaterial.MaterialDescription}: is not staged for ${lot.lot}`, + success: false, + }; + } + + // do we have color to the line + if (checkColorSetting[0].value === "1") { + const autoConsumeColor = mat.find( + (n: any) => + !n.isManual && + !("noPKGAutoShortage" in n) && + !("noPKGManualShortage" in n), + ); + + if (autoConsumeColor.autoConsumeCheck === "autoConsumeNOK") { + createLog( + "info", + "mainMaterial", + "ocp", + `lot: ${lot.lot}, is missing: ${autoConsumeColor + .map( + (o: any) => + `${o.MaterialHumanReadableId} - ${o.MaterialDescription}`, + ) + .join(",\n ")} for autoconsume`, + ); + return { + message: `lot: ${lot.lot}, is missing: ${autoConsumeColor + .map( + (o: any) => + `${o.MaterialHumanReadableId} - ${o.MaterialDescription}`, + ) + .join(",\n ")} for autoconsume`, + success: false, + }; + } + } +}; diff --git a/lstV2/server/services/sqlServer/querys/ocp/mainMaterial.ts b/lstV2/server/services/sqlServer/querys/ocp/mainMaterial.ts index 1679a89..62dfd72 100644 --- a/lstV2/server/services/sqlServer/querys/ocp/mainMaterial.ts +++ b/lstV2/server/services/sqlServer/querys/ocp/mainMaterial.ts @@ -157,3 +157,259 @@ where lot.ProductionLotHumanReadableId = @lot and MaterialDescription not like ' and MaterialDescription NOT LIKE '%bb%' and MaterialDescription NOT LIKE '%mcg%' `; + +export const something = [ + { + MaterialHumanReadableId: 98, + MaterialDescription: "BAN Banding 51544 1cyc", + Staged: 0, + isManual: false, + IsMainMaterial: false, + TotalPlannedLoadingUnits: 88, + TotalProducedLoadingUnits: 0, + remainingPallets: 88, + Provided: 0, + consumption: 0, + totalDemand: 352, + totalNeeded: 66.2904, + noMMShortage: null, + noPKGAutoShortage: "pkgAutoGood", + noPKGManualShortage: "noManPkg", + noManualShortage: null, + autoConsumeCheck: "autoConsumeOk", + invForAutoConsume: 1314200, + Percentage: 0, + QuantityPosition: 4, + "": null, + }, + { + MaterialHumanReadableId: 174, + MaterialDescription: "MB PE Ampacet BW 11744", + Staged: 0, + isManual: true, + IsMainMaterial: false, + TotalPlannedLoadingUnits: 88, + TotalProducedLoadingUnits: 0, + remainingPallets: 88, + Provided: 0, + consumption: 0, + totalDemand: 162.728623, + totalNeeded: 1.814699, + noMMShortage: null, + noPKGAutoShortage: null, + noPKGManualShortage: null, + noManualShortage: "noOK", + autoConsumeCheck: "autoConsumeNOK", + invForAutoConsume: null, + Percentage: 2.19, + QuantityPosition: null, + "": 0, + }, + { + MaterialHumanReadableId: 99, + MaterialDescription: "TOP Plastic 6040643 44x56x4 w/o CB 30cyc", + Staged: 0, + isManual: false, + IsMainMaterial: false, + TotalPlannedLoadingUnits: 88, + TotalProducedLoadingUnits: 0, + remainingPallets: 88, + Provided: 0, + consumption: 0, + totalDemand: 88, + totalNeeded: 66.2904, + noMMShortage: null, + noPKGAutoShortage: "pkgAutoGood", + noPKGManualShortage: "noManPkg", + noManualShortage: null, + autoConsumeCheck: "autoConsumeOk", + invForAutoConsume: 2048, + Percentage: 0, + QuantityPosition: 1, + "": null, + }, + { + MaterialHumanReadableId: 119, + MaterialDescription: "MM HDPE PCR KW Plastics KWR 101-150", + Staged: 1, + isManual: false, + IsMainMaterial: false, + TotalPlannedLoadingUnits: 88, + TotalProducedLoadingUnits: 0, + remainingPallets: 88, + Provided: 53643.717, + consumption: 0, + totalDemand: 3744.977905, + totalNeeded: 41.762952, + noMMShortage: null, + noPKGAutoShortage: null, + noPKGManualShortage: null, + noManualShortage: null, + autoConsumeCheck: "autoConsumeOk", + invForAutoConsume: 53754.112, + Percentage: 50.4, + QuantityPosition: null, + "": 0, + }, + { + MaterialHumanReadableId: 504, + MaterialDescription: "LBL IML Label F 1.8L Evolution 1265677", + Staged: 0, + isManual: false, + IsMainMaterial: false, + TotalPlannedLoadingUnits: 88, + TotalProducedLoadingUnits: 0, + remainingPallets: 88, + Provided: 0, + consumption: 0, + totalDemand: 79357.090909, + totalNeeded: 1, + noMMShortage: null, + noPKGAutoShortage: null, + noPKGManualShortage: null, + noManualShortage: null, + autoConsumeCheck: "autoConsumeOk", + invForAutoConsume: 900500, + Percentage: 0, + QuantityPosition: null, + "": 1, + }, + { + MaterialHumanReadableId: 176, + MaterialDescription: "MM HDPE Dow DMDF 6230", + Staged: 1, + isManual: false, + IsMainMaterial: true, + TotalPlannedLoadingUnits: 88, + TotalProducedLoadingUnits: 0, + remainingPallets: 88, + Provided: 74063.734, + consumption: 0, + totalDemand: 3522.805744, + totalNeeded: 39.285348, + noMMShortage: "mmGood", + noPKGAutoShortage: null, + noPKGManualShortage: null, + noManualShortage: null, + autoConsumeCheck: "autoConsumeOk", + invForAutoConsume: 182624.771, + Percentage: 47.41, + QuantityPosition: null, + "": 0, + }, + { + MaterialHumanReadableId: 397, + MaterialDescription: "STW Film 20x45ga 180567", + Staged: 0, + isManual: false, + IsMainMaterial: false, + TotalPlannedLoadingUnits: 88, + TotalProducedLoadingUnits: 0, + remainingPallets: 88, + Provided: 0, + consumption: 0, + totalDemand: 17.6, + totalNeeded: 66.2904, + noMMShortage: null, + noPKGAutoShortage: "pkgAutoGood", + noPKGManualShortage: "noManPkg", + noManualShortage: null, + autoConsumeCheck: "autoConsumeOk", + invForAutoConsume: 1063.92, + Percentage: 0, + QuantityPosition: 0.2, + "": null, + }, + { + MaterialHumanReadableId: 96, + MaterialDescription: "PAL PRA 44x56x5 50cyc", + Staged: 0, + isManual: false, + IsMainMaterial: false, + TotalPlannedLoadingUnits: 88, + TotalProducedLoadingUnits: 0, + remainingPallets: 88, + Provided: 0, + consumption: 0, + totalDemand: 88, + totalNeeded: 66.2904, + noMMShortage: null, + noPKGAutoShortage: "pkgAutoGood", + noPKGManualShortage: "noManPkg", + noManualShortage: null, + autoConsumeCheck: "autoConsumeOk", + invForAutoConsume: 1529, + Percentage: 0, + QuantityPosition: 1, + "": null, + }, + { + MaterialHumanReadableId: 505, + MaterialDescription: "LBL IML Label B 1.8L Evolution 1265678", + Staged: 0, + isManual: false, + IsMainMaterial: false, + TotalPlannedLoadingUnits: 88, + TotalProducedLoadingUnits: 0, + remainingPallets: 88, + Provided: 0, + consumption: 0, + totalDemand: 79357.090909, + totalNeeded: 1, + noMMShortage: null, + noPKGAutoShortage: null, + noPKGManualShortage: null, + noManualShortage: null, + autoConsumeCheck: "autoConsumeOk", + invForAutoConsume: 903000, + Percentage: 0, + QuantityPosition: null, + "": 1, + }, + { + MaterialHumanReadableId: 97, + MaterialDescription: "SSH Plastic 48100349 44x56x0.06 30cyc", + Staged: 0, + isManual: false, + IsMainMaterial: false, + TotalPlannedLoadingUnits: 88, + TotalProducedLoadingUnits: 0, + remainingPallets: 88, + Provided: 0, + consumption: 0, + totalDemand: 792, + totalNeeded: 66.2904, + noMMShortage: null, + noPKGAutoShortage: "pkgAutoGood", + noPKGManualShortage: "noManPkg", + noManualShortage: null, + autoConsumeCheck: "autoConsumeOk", + invForAutoConsume: 29962, + Percentage: 0, + QuantityPosition: 9, + "": null, + }, + { + MaterialHumanReadableId: 169, + MaterialDescription: "LBL Label 4x6 white 9396", + Staged: 0, + isManual: false, + IsMainMaterial: false, + TotalPlannedLoadingUnits: 88, + TotalProducedLoadingUnits: 0, + remainingPallets: 88, + Provided: 0, + consumption: 0, + totalDemand: 264, + totalNeeded: 66.2904, + noMMShortage: null, + noPKGAutoShortage: "pkgAutoGood", + noPKGManualShortage: "noManPkg", + noManualShortage: null, + autoConsumeCheck: "autoConsumeOk", + invForAutoConsume: 55637, + Percentage: 0, + QuantityPosition: 3, + "": null, + }, +];