feat(ocp): materials contorls and transfer to next lot logic
This commit is contained in:
@@ -1,12 +1,14 @@
|
||||
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 deefault and error logged if theres an issue
|
||||
let isStaged = false;
|
||||
let isStaged = { message: "Material is staged", success: true };
|
||||
|
||||
const { data, error } = (await tryCatch(
|
||||
query(
|
||||
@@ -26,7 +28,10 @@ export const isMainMatStaged = async (lot: any) => {
|
||||
"ocp",
|
||||
`The machine dose not require mm to print and book in.`
|
||||
);
|
||||
return true;
|
||||
return {
|
||||
message: "Machine dose not require material to be staged",
|
||||
success: true,
|
||||
};
|
||||
}
|
||||
|
||||
// strangly the lot is not always sending over in slc so adding this in for now to see what line is cauing this issue
|
||||
@@ -51,20 +56,101 @@ export const isMainMatStaged = async (lot: any) => {
|
||||
|
||||
const res: any = r.data;
|
||||
|
||||
createLog(
|
||||
"info",
|
||||
"mainMaterial",
|
||||
"ocp",
|
||||
`MainMaterial results: ${JSON.stringify(res)}`
|
||||
);
|
||||
|
||||
if (res[0].Staged >= 1) {
|
||||
isStaged = true;
|
||||
}
|
||||
|
||||
// if (res[0].noShortage === "good") {
|
||||
// if (res[0].Staged >= 1) {
|
||||
// isStaged = true;
|
||||
// }
|
||||
|
||||
createLog("info", "mainMaterial", "ocp", `Maint material query ran.`);
|
||||
|
||||
const mainMateiral = res.filter((n: any) => n.IsMainMaterial);
|
||||
|
||||
if (mainMateiral[0]?.noMaterialShortage === "no") {
|
||||
isStaged = {
|
||||
message: `Main material: ${mainMateiral[0].MaterialHumanReadableId} - ${mainMateiral[0].MaterialDescription}: is not staged for ${lot.lot} `,
|
||||
success: false,
|
||||
};
|
||||
}
|
||||
|
||||
// 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");
|
||||
|
||||
if (checkColorSetting[0].value === "1") {
|
||||
const autoConsumeColor = res.filter(
|
||||
(n: any) => !n.IsMainMaterial && !n.isManual
|
||||
);
|
||||
if (
|
||||
autoConsumeColor.some(
|
||||
(n: any) => n.autoConsumeCheck === "autoConsumeNOK"
|
||||
)
|
||||
) {
|
||||
const onlyNOK = autoConsumeColor.filter(
|
||||
(n: any) => n.autoConsumeCheck === "autoConsumeNOK"
|
||||
);
|
||||
isStaged = {
|
||||
message: `lot: ${lot.lot}, is missing: ${onlyNOK
|
||||
.map(
|
||||
(o: any) =>
|
||||
`${o.MaterialHumanReadableId} - ${o.MaterialDescription}`
|
||||
)
|
||||
.join(",\n ")} for autoconsume`,
|
||||
success: false,
|
||||
};
|
||||
}
|
||||
|
||||
// // for manual consume color
|
||||
const manualConsumeColor = res.filter(
|
||||
(n: any) => !n.IsMainMaterial && n.isManual
|
||||
);
|
||||
if (
|
||||
manualConsumeColor.some(
|
||||
(n: any) => n.noMaterialShortage === "yes"
|
||||
)
|
||||
) {
|
||||
isStaged = {
|
||||
message: `lot: ${lot.lot}, is missing: ${manualConsumeColor
|
||||
.map(
|
||||
(o: any) =>
|
||||
`${o.MaterialHumanReadableId} - ${o.MaterialDescription}`
|
||||
)
|
||||
.join(",\n ")} for manual Material`,
|
||||
success: false,
|
||||
};
|
||||
}
|
||||
} else {
|
||||
createLog(
|
||||
"info",
|
||||
"mainMaterial",
|
||||
"ocp",
|
||||
"Color check is not active."
|
||||
);
|
||||
}
|
||||
|
||||
// // if we want to check the packaging
|
||||
const checkPKGSetting = set.filter((n) => n.name === "checkPKG");
|
||||
if (checkPKGSetting[0].value === "1") {
|
||||
const packagingCheck = res.filter(
|
||||
(n: any) => !n.IsMainMaterial && n.isManual
|
||||
);
|
||||
if (packagingCheck.some((n: any) => n.noPKGShortage === "noPkg")) {
|
||||
isStaged = {
|
||||
message: `lot: ${lot.lot}, is missing: ${packagingCheck
|
||||
.map(
|
||||
(o: any) =>
|
||||
`${o.MaterialHumanReadableId} - ${o.MaterialDescription}`
|
||||
)
|
||||
.join(",\n ")} for pkg`,
|
||||
success: false,
|
||||
};
|
||||
}
|
||||
} else {
|
||||
createLog(
|
||||
"info",
|
||||
"mainMaterial",
|
||||
"ocp",
|
||||
"PKG check is not active."
|
||||
);
|
||||
}
|
||||
} catch (err) {
|
||||
createLog(
|
||||
"error",
|
||||
|
||||
Reference in New Issue
Block a user