refactor(ocp): lots of work for rfid and dyco contorl

This commit is contained in:
2025-03-27 21:12:22 -05:00
parent 27d6b6e884
commit ba3d721940
19 changed files with 360 additions and 162 deletions

View File

@@ -10,7 +10,9 @@ export const bookInLabel = async (data: any) => {
// update sscc so we can book in
const SSCC = data.SSCC.slice(2);
// api url
const url = await prodEndpointCreation("public/v1.0/Warehousing/BookIn");
const url = await prodEndpointCreation(
"/public/v1.1/Manufacturing/ProductionControlling/BookIn"
);
// create bookin
const newBookin = {
@@ -26,12 +28,12 @@ export const bookInLabel = async (data: any) => {
},
});
if (res.data.Result !== 0) {
if (res.status != 200) {
createLog(
"error",
"labeling",
"ocp",
`${data.printer.name}, Error:${res.data.Message}`
`${data.printer[0].name}, Error:${res.data}`
);
//printerUpdate(data.printer, 7, "Error while booking in.");
@@ -44,7 +46,7 @@ export const bookInLabel = async (data: any) => {
// update the label.
try {
await db
const booked = await db
.update(prodlabels)
.set({
status: "Booked in",
@@ -52,7 +54,22 @@ export const bookInLabel = async (data: any) => {
})
.where(
eq(prodlabels.runningNr, parseInt(data.SSCC.slice(10, -1)))
);
)
.returning({ runningNr: prodlabels.runningNr });
createLog(
"info",
"labeling",
"ocp",
`${booked[0].runningNr} , was just booked in.`
);
return {
success: true,
message: `${parseInt(
data.SSCC.slice(10, -1)
)}, was just booked in`,
};
} catch (error) {
createLog(
"error",
@@ -61,24 +78,12 @@ export const bookInLabel = async (data: any) => {
`Error creating new runningNumber in the DB.`
);
}
// label was booked in
createLog(
"info",
"labeling",
"ocp",
`${parseInt(data.SSCC.slice(10, -1))}, was just booked in`
);
return {
success: true,
message: `${parseInt(data.SSCC.slice(10, -1))}, was just booked in`,
};
} catch (error) {
createLog(
"error",
"labeling",
"ocp",
`${data.printer.name}, "Error: ${error}`
`${data.printer[0].name}, "Error: ${error}`
);
return {
success: false,

View File

@@ -43,7 +43,7 @@ export const createLabel = async (data: any, userPrinted: any) => {
const plantToken = settingsData.filter((n) => n.name === "plantToken");
const newLabel = {
scannerId: 99,
lotNr: data.LOT,
lotNr: data.lot,
machineId: data.machineID,
printerId: data.printerID,
//layoutId: cartonCustomers.includes(data.CustomerId.toString()) ? data.cartonLabel : data.palletLabel,
@@ -87,14 +87,24 @@ export const createLabel = async (data: any, userPrinted: any) => {
let newlabel = res.data;
try {
await db.insert(prodlabels).values({
printerID: parseInt(printer[0]?.humanReadableId!, 10),
runningNr: parseInt(newlabel.SSCC.slice(10, -1)),
printerName: printer[0].name.toLowerCase(),
line: data.MachineLocation,
status: "printed",
add_user: userPrinted || "LST_System",
});
const insertLabel = await db
.insert(prodlabels)
.values({
printerID: parseInt(printer[0]?.humanReadableId!, 10),
runningNr: parseInt(newlabel.SSCC.slice(10, -1)),
printerName: printer[0].name.toLowerCase(),
line: data.MachineLocation,
status: "printed",
add_user: userPrinted || "LST_System",
})
.returning({ runningNr: prodlabels.runningNr });
createLog(
"info",
"labeling",
"ocp",
`${insertLabel[0]?.runningNr} was just inserted into the db.`
);
} catch (error) {
createLog(
"error",
@@ -119,7 +129,7 @@ export const createLabel = async (data: any, userPrinted: any) => {
};
// check if we can remove labels or not
deleteLabels();
//deleteLabels();
return { sucess: true, message: "Label created", data: returnData }; // returning label data to be able to book in if active
} catch (error) {
createLog(

View File

@@ -1,4 +1,4 @@
import { desc, lte, sql } from "drizzle-orm";
import { desc, gte, lte, sql } from "drizzle-orm";
import { db } from "../../../../../database/dbclient.js";
import { prodlabels } from "../../../../../database/schema/prodLabels.js";
import { tryCatch } from "../../../../globalUtils/tryCatch.js";
@@ -8,7 +8,7 @@ export const getLabels = async (hours: string) => {
.select()
.from(prodlabels)
.where(
lte(
gte(
prodlabels.upd_date,
sql.raw(`NOW() - INTERVAL '${hours} hours'`)
)
@@ -27,6 +27,7 @@ export const getLabels = async (hours: string) => {
return {
success: true,
message: "Current labels order by upd_Date.",
count: labelInfo.length,
data: labelInfo,
};
};

View File

@@ -50,9 +50,10 @@ export const labelingProcess = async ({
// if we got a line passed over we need to get the machine id from this.
if (line) {
const macId = await getMac(line);
// filter out the lot for the line
filteredLot = lots.data.filter((l: any) => l.machineId === macId);
filteredLot = lots.data.filter(
(l: any) => l.MachineID === macId[0].HumanReadableId
);
if (filteredLot.length === 0) {
createLog(
@@ -160,7 +161,10 @@ export const labelingProcess = async ({
`Main material is not prepaired for lot ${filteredLot[0].lot}`
);
return;
return {
success: false,
message: `Main material is not prepaired for lot ${filteredLot[0].lot}`,
};
}
// comment only but will check for color
@@ -198,16 +202,19 @@ export const labelingProcess = async ({
"ocp",
`Prolink does not match for ${filteredLot[0].MachineDescription}`
);
return;
return {
success: false,
message: `Prolink does not match for ${filteredLot[0].MachineDescription}`,
};
}
createLog("info", "labeling", "ocp", `Is prolink good? ${prolink}`);
// create the label
const label = await createLabel(filteredLot[0], userPrinted);
if (!label.success) {
return { sucess: false, message: label.message, data: label.data };
}
// if (!label.success) {
// return { sucess: false, message: label.message, data: label.data };
// }
// send over to be booked in if we can do it.
const bookin = settingData.filter((s) => s.name === "bookin");

View File

@@ -0,0 +1,52 @@
import { db } from "../../../../../database/dbclient.js";
import { manualPrinting } from "../../../../../database/schema/ocpManualPrint.js";
import { tryCatch } from "../../../../globalUtils/tryCatch.js";
import { manualTag } from "../../../rfid/controller/tags/manualTag.js";
import { labelingProcess } from "./labelProcess.js";
export const manualPrint = async (manualPrint: any) => {
/**
* add the reason we did a manual print.
*/
const manualPrintData = {
line: manualPrint.line,
printReason: manualPrint.printReason,
initials: manualPrint.initials,
additionalComments: manualPrint?.additionalComments,
add_user: "lst",
};
const { data, error } = await tryCatch(
db.insert(manualPrinting).values(manualPrintData).returning({
line: manualPrinting.line,
printReason: manualPrinting.printReason,
initials: manualPrinting.initials,
additionalComments: manualPrinting?.additionalComments,
add_user: manualPrinting.add_user,
})
);
if (error) {
return {
success: false,
message: "There was an error posting the manualPrintData",
data: error,
};
}
let label = await labelingProcess({ line: manualPrint.line });
if (manualPrint.rfidTag) {
manualTag(
manualPrint.rfidTag,
"wrapper1",
parseInt(label.data.SSCC.slice(10, -1))
);
}
return {
success: true,
message: "Log Entered label will be coming soon.",
data,
};
};