refactor(materials): changes to allow exact and eom transfers
This commit is contained in:
@@ -17,6 +17,8 @@ export const consumeMaterial = async (data: Data, prod: any) => {
|
||||
const { runningNr, lotNum } = data;
|
||||
// replace the rn
|
||||
|
||||
console.log(data);
|
||||
|
||||
const rnReplace = labelData.replaceAll("[rn]", runningNr);
|
||||
|
||||
let barcode;
|
||||
|
||||
@@ -12,6 +12,8 @@ type NewLotData = {
|
||||
lotNumber: number;
|
||||
originalAmount: number;
|
||||
level: number;
|
||||
amount: number;
|
||||
type: "lot" | "eom";
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -22,8 +24,11 @@ type NewLotData = {
|
||||
* Lot number
|
||||
* Orignal Quantity
|
||||
* level of gaylord
|
||||
* amount can be sent over as a precise amount
|
||||
* type what way are we lots
|
||||
*/
|
||||
export const lotMaterialTransfer = async (data: NewLotData) => {
|
||||
let timeoutTrans: number = data.type === "lot" ? 1 : 10;
|
||||
// get the barcode, and layoutID from the running number
|
||||
const { data: label, error: labelError } = (await tryCatch(
|
||||
query(
|
||||
@@ -46,22 +51,21 @@ export const lotMaterialTransfer = async (data: NewLotData) => {
|
||||
};
|
||||
}
|
||||
|
||||
// if (
|
||||
// label.data[0]?.stockStatus === "notOnStock" ||
|
||||
// label.data.length === 0
|
||||
// ) {
|
||||
// createLog(
|
||||
// "error",
|
||||
// "materials",
|
||||
// "ocp",
|
||||
// `${data.runnungNumber}: dose not exist or no longer in stock.`
|
||||
// );
|
||||
// return {
|
||||
// success: false,
|
||||
// message: `${data.runnungNumber}: dose not exist or no longer in stock.`,
|
||||
// data: [],
|
||||
// };
|
||||
// }
|
||||
if (label.data.length === 0) {
|
||||
createLog(
|
||||
"error",
|
||||
"materials",
|
||||
"ocp",
|
||||
`${data.runnungNumber}: dose not exist or no longer in stock.`
|
||||
);
|
||||
return {
|
||||
success: false,
|
||||
message: `${data.runnungNumber}: dose not exist or no longer in stock.`,
|
||||
data: [],
|
||||
};
|
||||
}
|
||||
|
||||
//console.log(label);
|
||||
|
||||
if (label.data[0]?.stockStatus === "onStock") {
|
||||
createLog(
|
||||
@@ -97,7 +101,12 @@ export const lotMaterialTransfer = async (data: NewLotData) => {
|
||||
}
|
||||
// calculate the remaining amount bascially it will be orignal number * level sent over
|
||||
// level should be sent in a decimal .25 .5 .75 .95 the 95 will allow basically the what looks to be a full gaylord but we always want to consume something
|
||||
const newQty = (data.originalAmount * data.level).toFixed(0);
|
||||
const newQty =
|
||||
data.amount > 0
|
||||
? data.amount
|
||||
: (data.originalAmount * data.level).toFixed(0);
|
||||
|
||||
//console.log(data.amount);
|
||||
|
||||
// reprint the label and send it to pdf24
|
||||
const reprintData = {
|
||||
@@ -109,6 +118,8 @@ export const lotMaterialTransfer = async (data: NewLotData) => {
|
||||
quantity: newQty,
|
||||
} as any;
|
||||
|
||||
//console.log(reprintData);
|
||||
|
||||
const { data: reprint, error: reprintError } = (await tryCatch(
|
||||
runProdApi({
|
||||
endpoint: "/public/v1.0/ProductionLabelling/ReprintLabel",
|
||||
@@ -121,11 +132,11 @@ export const lotMaterialTransfer = async (data: NewLotData) => {
|
||||
"error",
|
||||
"materials",
|
||||
"ocp",
|
||||
`RN:${data.runnungNumber}, Error: ${reprint.data.data.message}`
|
||||
`RN:${data.runnungNumber}, Reprinting Error: ${reprint.data.data.message}`
|
||||
);
|
||||
return {
|
||||
success: false,
|
||||
message: `RN:${data.runnungNumber}, Error: ${reprint.data.data.message}`,
|
||||
message: `RN:${data.runnungNumber}, Reprinting Error: ${reprint.data.data.message}`,
|
||||
data: reprint,
|
||||
};
|
||||
}
|
||||
@@ -135,6 +146,8 @@ export const lotMaterialTransfer = async (data: NewLotData) => {
|
||||
barcode: label?.data[0].Barcode,
|
||||
laneId: 10001,
|
||||
};
|
||||
|
||||
//console.log(matReturnData);
|
||||
const { data: matReturn, error: matReturError } = (await tryCatch(
|
||||
runProdApi({
|
||||
endpoint:
|
||||
@@ -148,11 +161,11 @@ export const lotMaterialTransfer = async (data: NewLotData) => {
|
||||
"error",
|
||||
"materials",
|
||||
"ocp",
|
||||
`RN:${data.runnungNumber}, Error ${matReturn.data.data.errors[0].message}`
|
||||
`RN:${data.runnungNumber}, Return Error ${matReturn.data.data.errors[0].message}`
|
||||
);
|
||||
return {
|
||||
success: false,
|
||||
message: `RN:${data.runnungNumber}, Error ${matReturn.data.data.errors[0].message}`,
|
||||
message: `RN:${data.runnungNumber}, Return Error ${matReturn.data.data.errors[0].message}`,
|
||||
data: matReturn,
|
||||
};
|
||||
}
|
||||
@@ -161,39 +174,56 @@ export const lotMaterialTransfer = async (data: NewLotData) => {
|
||||
productionLot: data.lotNumber,
|
||||
barcode: label?.data[0].Barcode,
|
||||
};
|
||||
const { data: matConsume, error: matConsumeError } = (await tryCatch(
|
||||
runProdApi({
|
||||
endpoint:
|
||||
"/public/v1.0/IssueMaterial/ConsumeNonPreparedManualMaterial",
|
||||
data: [consumeLot],
|
||||
})
|
||||
)) as any;
|
||||
|
||||
if (!matConsume.success) {
|
||||
createLog(
|
||||
"error",
|
||||
"materials",
|
||||
"ocp",
|
||||
`RN:${data.runnungNumber}, Error ${matConsume.data.data.errors[0].message}`
|
||||
);
|
||||
// sets the time out based on the type of transfer sent over.
|
||||
setTimeout(
|
||||
async () => {
|
||||
const { data: matConsume, error: matConsumeError } =
|
||||
(await tryCatch(
|
||||
runProdApi({
|
||||
endpoint:
|
||||
"/public/v1.0/IssueMaterial/ConsumeNonPreparedManualMaterial",
|
||||
data: [consumeLot],
|
||||
})
|
||||
)) as any;
|
||||
|
||||
if (!matConsume.success) {
|
||||
createLog(
|
||||
"error",
|
||||
"materials",
|
||||
"ocp",
|
||||
`RN:${data.runnungNumber}, Consume Error ${matConsume.data.data.errors[0].message}`
|
||||
);
|
||||
return {
|
||||
success: false,
|
||||
message: `RN:${data.runnungNumber}, Consume Error ${matConsume.data.data.errors[0].message}`,
|
||||
data: matConsume,
|
||||
};
|
||||
}
|
||||
|
||||
createLog(
|
||||
"info",
|
||||
"materials",
|
||||
"ocp",
|
||||
`RN:${data.runnungNumber}: qty: ${newQty}, was transfered to lot:${data.lotNumber}`
|
||||
);
|
||||
},
|
||||
data.type === "lot" ? timeoutTrans * 1000 : timeoutTrans * 1000 * 60
|
||||
);
|
||||
|
||||
if (data.type === "eom") {
|
||||
return {
|
||||
success: false,
|
||||
message: `RN:${data.runnungNumber}, Error ${matConsume.data.data.errors[0].message}`,
|
||||
data: matConsume,
|
||||
success: true,
|
||||
message: `RN:${data.runnungNumber}: qty: ${newQty}, will be transfered to:${data.lotNumber}, in ${timeoutTrans}min`,
|
||||
data: [],
|
||||
};
|
||||
} else {
|
||||
return {
|
||||
success: true,
|
||||
message: `RN:${data.runnungNumber}: qty: ${newQty}, was transfered to lot:${data.lotNumber}`,
|
||||
data: [],
|
||||
};
|
||||
}
|
||||
|
||||
createLog(
|
||||
"info",
|
||||
"materials",
|
||||
"ocp",
|
||||
`RN:${data.runnungNumber}: qty: ${newQty}, was transfered to lot:${data.lotNumber}`
|
||||
);
|
||||
return {
|
||||
success: true,
|
||||
message: `RN:${data.runnungNumber}: qty: ${newQty}, was transfered to lot:${data.lotNumber}`,
|
||||
data: [],
|
||||
};
|
||||
};
|
||||
|
||||
// setTimeout(async () => {
|
||||
|
||||
@@ -54,10 +54,12 @@ app.openapi(
|
||||
});
|
||||
}
|
||||
|
||||
console.log(transferMaterial);
|
||||
|
||||
return c.json({
|
||||
success: transferMaterial.success,
|
||||
message: transferMaterial.message,
|
||||
data: transferMaterial.data,
|
||||
success: transferMaterial?.success,
|
||||
message: transferMaterial?.message,
|
||||
data: transferMaterial?.data,
|
||||
});
|
||||
}
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user