fix(materials): more fixes to try and please all plants to use this version and not call me
This commit is contained in:
@@ -60,13 +60,47 @@ export const isMainMatStaged = async (lot: any) => {
|
||||
// isStaged = true;
|
||||
// }
|
||||
|
||||
type CheckConditionArgs = {
|
||||
results: any[];
|
||||
filterFn: (n: any) => boolean;
|
||||
failCondition: (n: any) => boolean;
|
||||
failMessage: string;
|
||||
successMessage: string;
|
||||
lot: { lot: string | number };
|
||||
};
|
||||
|
||||
const checkCondition = ({
|
||||
results,
|
||||
filterFn,
|
||||
failCondition,
|
||||
failMessage,
|
||||
successMessage,
|
||||
lot,
|
||||
}: CheckConditionArgs): { message: string; success: boolean } => {
|
||||
const subset = results.filter(filterFn);
|
||||
|
||||
if (subset.some(failCondition)) {
|
||||
const failing = subset.filter(failCondition);
|
||||
return {
|
||||
message: `lot: ${lot.lot}, is missing: ${failing
|
||||
.map(
|
||||
(o: any) =>
|
||||
`${o.MaterialHumanReadableId} - ${o.MaterialDescription}`
|
||||
)
|
||||
.join(",\n ")} ${failMessage}`,
|
||||
success: false,
|
||||
};
|
||||
} else {
|
||||
return { message: successMessage, success: true };
|
||||
}
|
||||
};
|
||||
|
||||
createLog("info", "mainMaterial", "ocp", `Maint material query ran.`);
|
||||
|
||||
const mainMateiral = res.filter((n: any) => n.IsMainMaterial);
|
||||
|
||||
if (mainMateiral[0]?.noMaterialShortage === "noMM") {
|
||||
isStaged = {
|
||||
message: `Main material: ${mainMateiral[0].MaterialHumanReadableId} - ${mainMateiral[0].MaterialDescription}: is not staged for ${lot.lot} `,
|
||||
const mainMaterial = res.find((n: any) => n.IsMainMaterial);
|
||||
if (mainMaterial?.noMMShortage === "noMM") {
|
||||
return {
|
||||
message: `Main material: ${mainMaterial.MaterialHumanReadableId} - ${mainMaterial.MaterialDescription}: is not staged for ${lot.lot}`,
|
||||
success: false,
|
||||
};
|
||||
}
|
||||
@@ -75,56 +109,39 @@ export const isMainMatStaged = async (lot: any) => {
|
||||
// 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") {
|
||||
const autoConsumeColor = res.filter(
|
||||
(n: any) =>
|
||||
!n.IsMainMaterial &&
|
||||
!n.isManual &&
|
||||
n.noPKGShortage !== "pkgGood" &&
|
||||
n.noPKGShortage !== "noPkg"
|
||||
);
|
||||
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,
|
||||
};
|
||||
}
|
||||
// auto check
|
||||
// 2. Auto color
|
||||
const autoColor = checkCondition({
|
||||
results: res,
|
||||
lot,
|
||||
filterFn: (n) =>
|
||||
n.isManual &&
|
||||
!("noPKGAutoShortage" in n) &&
|
||||
!("noPKGManualShortage" in n), // pool = non-main, auto
|
||||
failCondition: (n) => n.autoConsumeCheck === "autoConsumeNOK", // column = autoConsumeCheck
|
||||
failMessage: "for autoconsume",
|
||||
successMessage: "auto color is good",
|
||||
});
|
||||
if (!autoColor.success) return autoColor;
|
||||
console.log(autoColor);
|
||||
|
||||
// // for manual consume color
|
||||
const manualConsumeColor = res.filter(
|
||||
(n: any) =>
|
||||
// 3. Manual color
|
||||
const manualColor = checkCondition({
|
||||
results: res,
|
||||
lot,
|
||||
filterFn: (n) =>
|
||||
!n.IsMainMaterial &&
|
||||
n.isManual &&
|
||||
n.noPKGShortage !== "pkgGood" &&
|
||||
n.noPKGShortage !== "noPkg"
|
||||
);
|
||||
if (
|
||||
manualConsumeColor.some(
|
||||
(n: any) => n.noManualShortage === "noOK"
|
||||
)
|
||||
) {
|
||||
isStaged = {
|
||||
message: `lot: ${lot.lot}, is missing: ${manualConsumeColor
|
||||
.map(
|
||||
(o: any) =>
|
||||
`${o.MaterialHumanReadableId} - ${o.MaterialDescription}`
|
||||
)
|
||||
.join(",\n ")} for manual Material`,
|
||||
success: false,
|
||||
};
|
||||
}
|
||||
!("noPKGAutoShortage" in n) &&
|
||||
!("noPKGManualShortage" in n), // pool = non-main, manual
|
||||
failCondition: (n) => n.noManualShortage === "noOK", // column = noManualShortage
|
||||
failMessage: "for manual material",
|
||||
successMessage: "manual color is good",
|
||||
});
|
||||
if (!manualColor.success) return manualColor;
|
||||
console.log(manualColor);
|
||||
} else {
|
||||
createLog(
|
||||
"info",
|
||||
@@ -137,11 +154,58 @@ 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 packagingCheck = res.filter(
|
||||
(n: any) => !n.IsMainMaterial && n.isManual
|
||||
const pkgAuto = checkCondition({
|
||||
results: res,
|
||||
lot,
|
||||
filterFn: (n) =>
|
||||
!n.IsMainMaterial &&
|
||||
!n.isManual &&
|
||||
"noPKGAutoShortage" in n,
|
||||
failCondition: (n) => n.noPKGAutoShortage === "noAutoPkg",
|
||||
failMessage: "for pkg",
|
||||
successMessage: "auto PKG is good",
|
||||
});
|
||||
if (!pkgAuto.success) return pkgAuto;
|
||||
console.log(pkgAuto);
|
||||
|
||||
// 5. Packaging manual
|
||||
const pkgManual = checkCondition({
|
||||
results: res,
|
||||
lot,
|
||||
filterFn: (n) =>
|
||||
!n.IsMainMaterial &&
|
||||
n.isManual &&
|
||||
"noPKGManualShortage" in n,
|
||||
failCondition: (n) => n.noPKGManualShortage === "noManPkg",
|
||||
failMessage: "for pkg",
|
||||
successMessage: "manual PKG is good",
|
||||
});
|
||||
|
||||
if (!pkgManual.success) return pkgManual;
|
||||
console.log(pkgManual);
|
||||
} else {
|
||||
createLog(
|
||||
"info",
|
||||
"mainMaterial",
|
||||
"ocp",
|
||||
"PKG check is not active."
|
||||
);
|
||||
if (packagingCheck.some((n: any) => n.noPKGShortage === "noPkg")) {
|
||||
isStaged = {
|
||||
}
|
||||
|
||||
// manual pkg
|
||||
if (checkPKGSetting[0].value === "1") {
|
||||
const packagingCheck = res.filter(
|
||||
(n: any) =>
|
||||
!n.IsMainMaterial &&
|
||||
n.isManual &&
|
||||
"noPKGManualShortage" in n
|
||||
);
|
||||
if (
|
||||
packagingCheck.some(
|
||||
(n: any) => n.noPKGManualShortage === "noManPkg"
|
||||
)
|
||||
) {
|
||||
return (isStaged = {
|
||||
message: `lot: ${lot.lot}, is missing: ${packagingCheck
|
||||
.map(
|
||||
(o: any) =>
|
||||
@@ -149,7 +213,7 @@ export const isMainMatStaged = async (lot: any) => {
|
||||
)
|
||||
.join(",\n ")} for pkg`,
|
||||
success: false,
|
||||
};
|
||||
});
|
||||
}
|
||||
} else {
|
||||
createLog(
|
||||
|
||||
@@ -23,7 +23,7 @@
|
||||
|
||||
export const mmQuery = `
|
||||
use [test1_AlplaPROD2.0_Read]
|
||||
declare @lot as NVARCHAR(max) = [lotNumber]
|
||||
declare @lot as NVARCHAR(max) = [lotNumber]
|
||||
/*
|
||||
checks all needed material including pkg
|
||||
|
||||
@@ -63,9 +63,12 @@ MaterialHumanReadableId
|
||||
then 'mmGood'
|
||||
else 'noMM' end else null end as noMMShortage
|
||||
|
||||
-- pkg check
|
||||
-- pkg check auto
|
||||
,case when pkg.QuantityPosition is null then null else
|
||||
(case when l.qty > ((lot.TotalProducedLoadingUnits+1) * pkg.QuantityPosition) then 'pkgGood' else 'noPkg' end) end as noPKGShortage
|
||||
(case when l.qty > ((lot.TotalProducedLoadingUnits+1) * pkg.QuantityPosition) and IsManualProcess = 0 then 'pkgAutoGood' else 'noAutoPkg' end) end as noPKGAutoShortage
|
||||
-- plg check manual
|
||||
,case when pkg.QuantityPosition is null then null else
|
||||
(case when x.EffectiveConsumption > ((lot.TotalProducedLoadingUnits+1) * pkg.QuantityPosition) and IsManualProcess = 1 then 'pkgManGood' else 'noManPkg' end) end as noPKGManualShortage
|
||||
-- manualMateiral
|
||||
,case when IsMainMaterial = 0 and IsManualProcess = 1 then
|
||||
case when (case when x.ProvidedAmount <> 0
|
||||
@@ -131,5 +134,5 @@ group by IdArtikelVarianten,ArtikelVariantenBez
|
||||
) as l on
|
||||
l.IdArtikelVarianten = MaterialHumanReadableId
|
||||
|
||||
where lot.ProductionLotHumanReadableId = @lot
|
||||
where lot.ProductionLotHumanReadableId = @lot and MaterialDescription not like '%nopal%'
|
||||
`;
|
||||
|
||||
Reference in New Issue
Block a user