fix(materials): more fixes to try and please all plants to use this version and not call me
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -157,3 +157,4 @@ backend-0.1.3.zip
|
|||||||
BulkForecastTemplate
|
BulkForecastTemplate
|
||||||
BulkOrdersTemplate
|
BulkOrdersTemplate
|
||||||
check.json
|
check.json
|
||||||
|
server/services/ocp/controller/materials/materialcheck.bak
|
||||||
|
|||||||
@@ -36,7 +36,7 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"admConfig": {
|
"admConfig": {
|
||||||
"build": 645,
|
"build": 646,
|
||||||
"oldBuild": "backend-0.1.3.zip"
|
"oldBuild": "backend-0.1.3.zip"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
|||||||
@@ -60,13 +60,47 @@ export const isMainMatStaged = async (lot: any) => {
|
|||||||
// isStaged = true;
|
// 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.`);
|
createLog("info", "mainMaterial", "ocp", `Maint material query ran.`);
|
||||||
|
|
||||||
const mainMateiral = res.filter((n: any) => n.IsMainMaterial);
|
const mainMaterial = res.find((n: any) => n.IsMainMaterial);
|
||||||
|
if (mainMaterial?.noMMShortage === "noMM") {
|
||||||
if (mainMateiral[0]?.noMaterialShortage === "noMM") {
|
return {
|
||||||
isStaged = {
|
message: `Main material: ${mainMaterial.MaterialHumanReadableId} - ${mainMaterial.MaterialDescription}: is not staged for ${lot.lot}`,
|
||||||
message: `Main material: ${mainMateiral[0].MaterialHumanReadableId} - ${mainMateiral[0].MaterialDescription}: is not staged for ${lot.lot} `,
|
|
||||||
success: false,
|
success: false,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@@ -75,56 +109,39 @@ export const isMainMatStaged = async (lot: any) => {
|
|||||||
// for manual consume color if active to check colors
|
// for manual consume color if active to check colors
|
||||||
const checkColorSetting = set.filter((n) => n.name === "checkColor");
|
const checkColorSetting = set.filter((n) => n.name === "checkColor");
|
||||||
|
|
||||||
|
// 2. Auto color
|
||||||
if (checkColorSetting[0].value === "1") {
|
if (checkColorSetting[0].value === "1") {
|
||||||
const autoConsumeColor = res.filter(
|
// auto check
|
||||||
(n: any) =>
|
// 2. Auto color
|
||||||
!n.IsMainMaterial &&
|
const autoColor = checkCondition({
|
||||||
!n.isManual &&
|
results: res,
|
||||||
n.noPKGShortage !== "pkgGood" &&
|
lot,
|
||||||
n.noPKGShortage !== "noPkg"
|
filterFn: (n) =>
|
||||||
);
|
n.isManual &&
|
||||||
if (
|
!("noPKGAutoShortage" in n) &&
|
||||||
autoConsumeColor.some(
|
!("noPKGManualShortage" in n), // pool = non-main, auto
|
||||||
(n: any) => n.autoConsumeCheck === "autoConsumeNOK"
|
failCondition: (n) => n.autoConsumeCheck === "autoConsumeNOK", // column = autoConsumeCheck
|
||||||
)
|
failMessage: "for autoconsume",
|
||||||
) {
|
successMessage: "auto color is good",
|
||||||
const onlyNOK = autoConsumeColor.filter(
|
});
|
||||||
(n: any) => n.autoConsumeCheck === "autoConsumeNOK"
|
if (!autoColor.success) return autoColor;
|
||||||
);
|
console.log(autoColor);
|
||||||
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
|
// 3. Manual color
|
||||||
const manualConsumeColor = res.filter(
|
const manualColor = checkCondition({
|
||||||
(n: any) =>
|
results: res,
|
||||||
|
lot,
|
||||||
|
filterFn: (n) =>
|
||||||
!n.IsMainMaterial &&
|
!n.IsMainMaterial &&
|
||||||
n.isManual &&
|
n.isManual &&
|
||||||
n.noPKGShortage !== "pkgGood" &&
|
!("noPKGAutoShortage" in n) &&
|
||||||
n.noPKGShortage !== "noPkg"
|
!("noPKGManualShortage" in n), // pool = non-main, manual
|
||||||
);
|
failCondition: (n) => n.noManualShortage === "noOK", // column = noManualShortage
|
||||||
if (
|
failMessage: "for manual material",
|
||||||
manualConsumeColor.some(
|
successMessage: "manual color is good",
|
||||||
(n: any) => n.noManualShortage === "noOK"
|
});
|
||||||
)
|
if (!manualColor.success) return manualColor;
|
||||||
) {
|
console.log(manualColor);
|
||||||
isStaged = {
|
|
||||||
message: `lot: ${lot.lot}, is missing: ${manualConsumeColor
|
|
||||||
.map(
|
|
||||||
(o: any) =>
|
|
||||||
`${o.MaterialHumanReadableId} - ${o.MaterialDescription}`
|
|
||||||
)
|
|
||||||
.join(",\n ")} for manual Material`,
|
|
||||||
success: false,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
createLog(
|
createLog(
|
||||||
"info",
|
"info",
|
||||||
@@ -137,11 +154,58 @@ export const isMainMatStaged = async (lot: any) => {
|
|||||||
// // if we want to check the packaging
|
// // if we want to check the packaging
|
||||||
const checkPKGSetting = set.filter((n) => n.name === "checkPKG");
|
const checkPKGSetting = set.filter((n) => n.name === "checkPKG");
|
||||||
if (checkPKGSetting[0].value === "1") {
|
if (checkPKGSetting[0].value === "1") {
|
||||||
const packagingCheck = res.filter(
|
const pkgAuto = checkCondition({
|
||||||
(n: any) => !n.IsMainMaterial && n.isManual
|
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
|
message: `lot: ${lot.lot}, is missing: ${packagingCheck
|
||||||
.map(
|
.map(
|
||||||
(o: any) =>
|
(o: any) =>
|
||||||
@@ -149,7 +213,7 @@ export const isMainMatStaged = async (lot: any) => {
|
|||||||
)
|
)
|
||||||
.join(",\n ")} for pkg`,
|
.join(",\n ")} for pkg`,
|
||||||
success: false,
|
success: false,
|
||||||
};
|
});
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
createLog(
|
createLog(
|
||||||
|
|||||||
@@ -63,9 +63,12 @@ MaterialHumanReadableId
|
|||||||
then 'mmGood'
|
then 'mmGood'
|
||||||
else 'noMM' end else null end as noMMShortage
|
else 'noMM' end else null end as noMMShortage
|
||||||
|
|
||||||
-- pkg check
|
-- pkg check auto
|
||||||
,case when pkg.QuantityPosition is null then null else
|
,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
|
-- manualMateiral
|
||||||
,case when IsMainMaterial = 0 and IsManualProcess = 1 then
|
,case when IsMainMaterial = 0 and IsManualProcess = 1 then
|
||||||
case when (case when x.ProvidedAmount <> 0
|
case when (case when x.ProvidedAmount <> 0
|
||||||
@@ -131,5 +134,5 @@ group by IdArtikelVarianten,ArtikelVariantenBez
|
|||||||
) as l on
|
) as l on
|
||||||
l.IdArtikelVarianten = MaterialHumanReadableId
|
l.IdArtikelVarianten = MaterialHumanReadableId
|
||||||
|
|
||||||
where lot.ProductionLotHumanReadableId = @lot
|
where lot.ProductionLotHumanReadableId = @lot and MaterialDescription not like '%nopal%'
|
||||||
`;
|
`;
|
||||||
|
|||||||
Reference in New Issue
Block a user