refactor(materials): added in if staged just pass the check
This commit is contained in:
@@ -13,12 +13,12 @@ export const isMainMatStaged = async (lot: any) => {
|
|||||||
const { data, error } = (await tryCatch(
|
const { data, error } = (await tryCatch(
|
||||||
query(
|
query(
|
||||||
machineCheck.replace("where Active = 1 and [Location] = [loc]", ""),
|
machineCheck.replace("where Active = 1 and [Location] = [loc]", ""),
|
||||||
"check machine needs mm"
|
"check machine needs mm",
|
||||||
)
|
),
|
||||||
)) as any;
|
)) as any;
|
||||||
|
|
||||||
const machine = data.data.filter(
|
const machine = data.data.filter(
|
||||||
(m: any) => m.HumanReadableId === lot.machineID
|
(m: any) => m.HumanReadableId === lot.machineID,
|
||||||
);
|
);
|
||||||
// we have a check on ksc side to ignore the tetra machine for now as its not updating in 2.0
|
// 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) {
|
if (!machine[0].StagingMainMaterialMandatory) {
|
||||||
@@ -26,7 +26,7 @@ export const isMainMatStaged = async (lot: any) => {
|
|||||||
"info",
|
"info",
|
||||||
"mainMaterial",
|
"mainMaterial",
|
||||||
"ocp",
|
"ocp",
|
||||||
`The machine dose not require mm to print and book in.`
|
`The machine dose not require mm to print and book in.`,
|
||||||
);
|
);
|
||||||
return {
|
return {
|
||||||
message: "Machine dose not require material to be staged",
|
message: "Machine dose not require material to be staged",
|
||||||
@@ -36,12 +36,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
|
// strangly 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) {
|
if (!lot) {
|
||||||
createLog(
|
createLog("info", "mainMaterial", "ocp", "No lot was passed correctly.");
|
||||||
"info",
|
|
||||||
"mainMaterial",
|
|
||||||
"ocp",
|
|
||||||
"No lot was passed correctly."
|
|
||||||
);
|
|
||||||
return isStaged;
|
return isStaged;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -50,7 +45,7 @@ export const isMainMatStaged = async (lot: any) => {
|
|||||||
"info",
|
"info",
|
||||||
"mainMaterial",
|
"mainMaterial",
|
||||||
"ocp",
|
"ocp",
|
||||||
`The lot sent over is not an object: ${JSON.stringify(lot)}`
|
`The lot sent over is not an object: ${JSON.stringify(lot)}`,
|
||||||
);
|
);
|
||||||
return isStaged;
|
return isStaged;
|
||||||
}
|
}
|
||||||
@@ -94,15 +89,15 @@ export const isMainMatStaged = async (lot: any) => {
|
|||||||
`lot: ${lot.lot}, is missing: ${failing
|
`lot: ${lot.lot}, is missing: ${failing
|
||||||
.map(
|
.map(
|
||||||
(o: any) =>
|
(o: any) =>
|
||||||
`${o.MaterialHumanReadableId} - ${o.MaterialDescription}`
|
`${o.MaterialHumanReadableId} - ${o.MaterialDescription}`,
|
||||||
)
|
)
|
||||||
.join(",\n ")} ${failMessage}`
|
.join(",\n ")} ${failMessage}`,
|
||||||
);
|
);
|
||||||
return {
|
return {
|
||||||
message: `lot: ${lot.lot}, is missing: ${failing
|
message: `lot: ${lot.lot}, is missing: ${failing
|
||||||
.map(
|
.map(
|
||||||
(o: any) =>
|
(o: any) =>
|
||||||
`${o.MaterialHumanReadableId} - ${o.MaterialDescription}`
|
`${o.MaterialHumanReadableId} - ${o.MaterialDescription}`,
|
||||||
)
|
)
|
||||||
.join(",\n ")} ${failMessage}`,
|
.join(",\n ")} ${failMessage}`,
|
||||||
success: false,
|
success: false,
|
||||||
@@ -112,7 +107,7 @@ export const isMainMatStaged = async (lot: any) => {
|
|||||||
"info",
|
"info",
|
||||||
"mainMaterial",
|
"mainMaterial",
|
||||||
"ocp",
|
"ocp",
|
||||||
`lot: ${lot.lot}, ${JSON.stringify(results)}`
|
`lot: ${lot.lot}, ${JSON.stringify(results)}`,
|
||||||
);
|
);
|
||||||
return { message: successMessage, success: true };
|
return { message: successMessage, success: true };
|
||||||
}
|
}
|
||||||
@@ -121,12 +116,24 @@ export const isMainMatStaged = async (lot: any) => {
|
|||||||
createLog("info", "mainMaterial", "ocp", `Maint material query ran.`);
|
createLog("info", "mainMaterial", "ocp", `Maint material query ran.`);
|
||||||
|
|
||||||
const mainMaterial = res.find((n: any) => n.IsMainMaterial);
|
const mainMaterial = res.find((n: any) => n.IsMainMaterial);
|
||||||
|
if (mainMaterial?.Staged === 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,
|
||||||
|
};
|
||||||
|
}
|
||||||
if (mainMaterial?.noMMShortage === "noMM") {
|
if (mainMaterial?.noMMShortage === "noMM") {
|
||||||
createLog(
|
createLog(
|
||||||
"info",
|
"info",
|
||||||
"mainMaterial",
|
"mainMaterial",
|
||||||
"ocp",
|
"ocp",
|
||||||
`Main material: ${mainMaterial.MaterialHumanReadableId} - ${mainMaterial.MaterialDescription}: is not staged for ${lot.lot}`
|
`Main material: ${mainMaterial.MaterialHumanReadableId} - ${mainMaterial.MaterialDescription}: is not staged for ${lot.lot}`,
|
||||||
);
|
);
|
||||||
return {
|
return {
|
||||||
message: `Main material: ${mainMaterial.MaterialHumanReadableId} - ${mainMaterial.MaterialDescription}: is not staged for ${lot.lot}`,
|
message: `Main material: ${mainMaterial.MaterialHumanReadableId} - ${mainMaterial.MaterialDescription}: is not staged for ${lot.lot}`,
|
||||||
@@ -158,7 +165,7 @@ export const isMainMatStaged = async (lot: any) => {
|
|||||||
"info",
|
"info",
|
||||||
"mainMaterial",
|
"mainMaterial",
|
||||||
"ocp",
|
"ocp",
|
||||||
`Auto Color: ${JSON.stringify(autoColor)}`
|
`Auto Color: ${JSON.stringify(autoColor)}`,
|
||||||
);
|
);
|
||||||
|
|
||||||
// 3. Manual color
|
// 3. Manual color
|
||||||
@@ -179,15 +186,10 @@ export const isMainMatStaged = async (lot: any) => {
|
|||||||
"info",
|
"info",
|
||||||
"mainMaterial",
|
"mainMaterial",
|
||||||
"ocp",
|
"ocp",
|
||||||
`Manual Color: ${JSON.stringify(manualColor)}`
|
`Manual Color: ${JSON.stringify(manualColor)}`,
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
createLog(
|
createLog("info", "mainMaterial", "ocp", "Color check is not active.");
|
||||||
"info",
|
|
||||||
"mainMaterial",
|
|
||||||
"ocp",
|
|
||||||
"Color check is not active."
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// // if we want to check the packaging
|
// // if we want to check the packaging
|
||||||
@@ -197,9 +199,7 @@ export const isMainMatStaged = async (lot: any) => {
|
|||||||
results: res,
|
results: res,
|
||||||
lot,
|
lot,
|
||||||
filterFn: (n) =>
|
filterFn: (n) =>
|
||||||
!n.IsMainMaterial &&
|
!n.IsMainMaterial && !n.isManual && "noPKGAutoShortage" in n,
|
||||||
!n.isManual &&
|
|
||||||
"noPKGAutoShortage" in n,
|
|
||||||
failCondition: (n) => n.noPKGAutoShortage === "noAutoPkg",
|
failCondition: (n) => n.noPKGAutoShortage === "noAutoPkg",
|
||||||
failMessage: "for pkg",
|
failMessage: "for pkg",
|
||||||
successMessage: "auto PKG is good",
|
successMessage: "auto PKG is good",
|
||||||
@@ -209,16 +209,14 @@ export const isMainMatStaged = async (lot: any) => {
|
|||||||
"info",
|
"info",
|
||||||
"mainMaterial",
|
"mainMaterial",
|
||||||
"ocp",
|
"ocp",
|
||||||
`PKG Auto: ${JSON.stringify(pkgAuto)}`
|
`PKG Auto: ${JSON.stringify(pkgAuto)}`,
|
||||||
);
|
);
|
||||||
// 5. Packaging manual
|
// 5. Packaging manual
|
||||||
const pkgManual = checkCondition({
|
const pkgManual = checkCondition({
|
||||||
results: res,
|
results: res,
|
||||||
lot,
|
lot,
|
||||||
filterFn: (n) =>
|
filterFn: (n) =>
|
||||||
!n.IsMainMaterial &&
|
!n.IsMainMaterial && n.isManual && "noPKGManualShortage" in n,
|
||||||
n.isManual &&
|
|
||||||
"noPKGManualShortage" in n,
|
|
||||||
failCondition: (n) => n.noPKGManualShortage === "noManPkg",
|
failCondition: (n) => n.noPKGManualShortage === "noManPkg",
|
||||||
failMessage: "for pkg",
|
failMessage: "for pkg",
|
||||||
successMessage: "manual PKG is good",
|
successMessage: "manual PKG is good",
|
||||||
@@ -229,29 +227,20 @@ export const isMainMatStaged = async (lot: any) => {
|
|||||||
"info",
|
"info",
|
||||||
"mainMaterial",
|
"mainMaterial",
|
||||||
"ocp",
|
"ocp",
|
||||||
`PKG Manual: ${JSON.stringify(pkgManual)}`
|
`PKG Manual: ${JSON.stringify(pkgManual)}`,
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
createLog(
|
createLog("info", "mainMaterial", "ocp", "PKG check is not active.");
|
||||||
"info",
|
|
||||||
"mainMaterial",
|
|
||||||
"ocp",
|
|
||||||
"PKG check is not active."
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// manual pkg
|
// manual pkg
|
||||||
if (checkPKGSetting[0].value === "1") {
|
if (checkPKGSetting[0].value === "1") {
|
||||||
const packagingCheck = res.filter(
|
const packagingCheck = res.filter(
|
||||||
(n: any) =>
|
(n: any) =>
|
||||||
!n.IsMainMaterial &&
|
!n.IsMainMaterial && n.isManual && "noPKGManualShortage" in n,
|
||||||
n.isManual &&
|
|
||||||
"noPKGManualShortage" in n
|
|
||||||
);
|
);
|
||||||
if (
|
if (
|
||||||
packagingCheck.some(
|
packagingCheck.some((n: any) => n.noPKGManualShortage === "noManPkg")
|
||||||
(n: any) => n.noPKGManualShortage === "noManPkg"
|
|
||||||
)
|
|
||||||
) {
|
) {
|
||||||
createLog(
|
createLog(
|
||||||
"info",
|
"info",
|
||||||
@@ -260,34 +249,29 @@ export const isMainMatStaged = async (lot: any) => {
|
|||||||
`lot: ${lot.lot}, is missing: ${packagingCheck
|
`lot: ${lot.lot}, is missing: ${packagingCheck
|
||||||
.map(
|
.map(
|
||||||
(o: any) =>
|
(o: any) =>
|
||||||
`${o.MaterialHumanReadableId} - ${o.MaterialDescription}`
|
`${o.MaterialHumanReadableId} - ${o.MaterialDescription}`,
|
||||||
)
|
)
|
||||||
.join(",\n ")} for pkg`
|
.join(",\n ")} for pkg`,
|
||||||
);
|
);
|
||||||
return (isStaged = {
|
return (isStaged = {
|
||||||
message: `lot: ${lot.lot}, is missing: ${packagingCheck
|
message: `lot: ${lot.lot}, is missing: ${packagingCheck
|
||||||
.map(
|
.map(
|
||||||
(o: any) =>
|
(o: any) =>
|
||||||
`${o.MaterialHumanReadableId} - ${o.MaterialDescription}`
|
`${o.MaterialHumanReadableId} - ${o.MaterialDescription}`,
|
||||||
)
|
)
|
||||||
.join(",\n ")} for pkg`,
|
.join(",\n ")} for pkg`,
|
||||||
success: false,
|
success: false,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
createLog(
|
createLog("info", "mainMaterial", "ocp", "PKG check is not active.");
|
||||||
"info",
|
|
||||||
"mainMaterial",
|
|
||||||
"ocp",
|
|
||||||
"PKG check is not active."
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
createLog(
|
createLog(
|
||||||
"error",
|
"error",
|
||||||
"mainMaterial",
|
"mainMaterial",
|
||||||
"ocp",
|
"ocp",
|
||||||
`Error from running the Main Material query: ${err}`
|
`Error from running the Main Material query: ${err}`,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
return isStaged;
|
return isStaged;
|
||||||
|
|||||||
Reference in New Issue
Block a user