feat(lstv2 move): moved lstv2 into this app to keep them combined and easier to maintain
This commit is contained in:
108
lstV2/server/services/ocp/controller/labeling/bookIn.ts
Normal file
108
lstV2/server/services/ocp/controller/labeling/bookIn.ts
Normal file
@@ -0,0 +1,108 @@
|
||||
import axios from "axios";
|
||||
import { prodEndpointCreation } from "../../../../globalUtils/createUrl.js";
|
||||
import { lstAuth } from "../../../../index.js";
|
||||
import { createLog } from "../../../logger/logger.js";
|
||||
import { db } from "../../../../../database/dbclient.js";
|
||||
import { prodlabels } from "../../../../../database/schema/prodLabels.js";
|
||||
import { eq, sql } from "drizzle-orm";
|
||||
|
||||
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.1/Manufacturing/ProductionControlling/BookIn"
|
||||
);
|
||||
|
||||
// create bookin
|
||||
const newBookin = {
|
||||
scannerId: 777,
|
||||
sscc: SSCC,
|
||||
};
|
||||
|
||||
try {
|
||||
const res = await axios.post(url, newBookin, {
|
||||
headers: {
|
||||
Authorization: `Basic ${lstAuth}`,
|
||||
accept: "text/plain",
|
||||
},
|
||||
});
|
||||
|
||||
if (res.status != 200) {
|
||||
createLog(
|
||||
"error",
|
||||
"labeling",
|
||||
"ocp",
|
||||
`${
|
||||
data.printer ? data.printer[0].name : "Manual book in"
|
||||
}, Error:${res.data}`
|
||||
);
|
||||
//printerUpdate(data.printer, 7, "Error while booking in.");
|
||||
|
||||
return {
|
||||
success: false,
|
||||
message: "There was an error booking in the label.",
|
||||
data: res.data,
|
||||
};
|
||||
}
|
||||
// update the label.
|
||||
try {
|
||||
const booked = await db
|
||||
.update(prodlabels)
|
||||
.set({
|
||||
status: "Booked in",
|
||||
upd_date: sql`NOW()`,
|
||||
})
|
||||
.where(
|
||||
eq(prodlabels.runningNr, parseInt(data.SSCC.slice(10, -1)))
|
||||
)
|
||||
.returning({ runningNr: prodlabels.runningNr });
|
||||
|
||||
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`,
|
||||
data: { SSCC: data.SSCC },
|
||||
};
|
||||
} catch (error) {
|
||||
//console.log(error);
|
||||
createLog(
|
||||
"error",
|
||||
"labeling",
|
||||
"ocp",
|
||||
`Error creating new runningNumber in the DB.`
|
||||
);
|
||||
return {
|
||||
success: true,
|
||||
message: `${parseInt(
|
||||
data.SSCC.slice(10, -1)
|
||||
)}, encoutnered an error posting to the db`,
|
||||
data: error,
|
||||
};
|
||||
}
|
||||
} catch (error: any) {
|
||||
createLog(
|
||||
"error",
|
||||
"labeling",
|
||||
"ocp",
|
||||
`${
|
||||
data.printer ? data.printer[0].name : "Manual book in"
|
||||
}, "Error: ${error?.response.data}`
|
||||
);
|
||||
// console.log(error.response.data);
|
||||
return {
|
||||
success: false,
|
||||
message: "There was an error booking in the label.",
|
||||
data: error.response.data,
|
||||
};
|
||||
}
|
||||
};
|
||||
150
lstV2/server/services/ocp/controller/labeling/createLabel.ts
Normal file
150
lstV2/server/services/ocp/controller/labeling/createLabel.ts
Normal file
@@ -0,0 +1,150 @@
|
||||
import { eq, gte, lt, sql } from "drizzle-orm";
|
||||
import { db } from "../../../../../database/dbclient.js";
|
||||
import { printerData } from "../../../../../database/schema/printers.js";
|
||||
import { tryCatch } from "../../../../globalUtils/tryCatch.js";
|
||||
import { createLog } from "../../../logger/logger.js";
|
||||
import { prodEndpointCreation } from "../../../../globalUtils/createUrl.js";
|
||||
import { settings } from "../../../../../database/schema/settings.js";
|
||||
import { lstAuth } from "../../../../index.js";
|
||||
import axios from "axios";
|
||||
import { prodlabels } from "../../../../../database/schema/prodLabels.js";
|
||||
import { addDays } from "date-fns";
|
||||
|
||||
export const createLabel = async (data: any, userPrinted: any) => {
|
||||
createLog("info", "labeling", "ocp", `Label being created`);
|
||||
|
||||
const { data: printer, error: printerError } = await tryCatch(
|
||||
db
|
||||
.select()
|
||||
.from(printerData)
|
||||
.where(eq(printerData.humanReadableId, data.printerID))
|
||||
);
|
||||
const { data: settingsData, error: settingsError } = await tryCatch(
|
||||
db.select().from(settings)
|
||||
);
|
||||
if (printerError) {
|
||||
return {
|
||||
success: false,
|
||||
message: "There was an error getting the printer.",
|
||||
printerError,
|
||||
};
|
||||
}
|
||||
|
||||
if (settingsError) {
|
||||
return {
|
||||
success: false,
|
||||
message: "There was an error getting the settings.",
|
||||
settingsError,
|
||||
};
|
||||
}
|
||||
|
||||
const url = await prodEndpointCreation(
|
||||
"/public/v1.0/Warehousing/GenerateAndPrintLabelExtended"
|
||||
);
|
||||
const plantToken = settingsData.filter((n) => n.name === "plantToken");
|
||||
const newLabel = {
|
||||
scannerId: 99,
|
||||
lotNr: data.lot,
|
||||
machineId: data.machineID,
|
||||
printerId: data.printerID,
|
||||
//layoutId: cartonCustomers.includes(data.CustomerId.toString()) ? data.cartonLabel : data.palletLabel,
|
||||
layoutId:
|
||||
plantToken[0].value === "usksc1"
|
||||
? data.cartonLabel
|
||||
: data.palletLabel,
|
||||
//numberOfCopies: cartonCustomers.includes(data.CustomerId.toString()) ? data.cartonCopies : data.pallerCopies,
|
||||
numberOfCopies:
|
||||
plantToken[0].value === "usksc1"
|
||||
? data.cartonCopies
|
||||
: data.pallerCopies,
|
||||
};
|
||||
|
||||
// create the label
|
||||
// create the label with the data we have
|
||||
try {
|
||||
const res = await axios.post(url, newLabel, {
|
||||
headers: {
|
||||
Authorization: `Basic ${lstAuth}`,
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
});
|
||||
|
||||
// error handling
|
||||
if (res.data.Result != 0) {
|
||||
createLog(
|
||||
"error",
|
||||
"labeling",
|
||||
"ocp",
|
||||
`${data.MachineDescription}, has an error while printing: Error: ${res.data.Message}.`
|
||||
);
|
||||
return {
|
||||
success: false,
|
||||
mesasge: `${data.MachineDescription}, has an error while printing`,
|
||||
data: res.data,
|
||||
};
|
||||
}
|
||||
|
||||
// save the data to lst db (only saved for x time see the db clean up functions)
|
||||
let newlabel = res.data;
|
||||
|
||||
try {
|
||||
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",
|
||||
"labeling",
|
||||
"ocp",
|
||||
`Error creating new runningNumber in the DB.`
|
||||
);
|
||||
}
|
||||
|
||||
createLog(
|
||||
"info",
|
||||
"labeling",
|
||||
"ocp",
|
||||
`New label was created for: ${
|
||||
data.MachineDescription
|
||||
}, Running number: ${parseInt(newlabel.SSCC.slice(10, -1))}`
|
||||
);
|
||||
|
||||
const returnData = {
|
||||
...newlabel,
|
||||
printer,
|
||||
};
|
||||
|
||||
// check if we can remove labels or not
|
||||
//deleteLabels();
|
||||
return { success: true, message: "Label created", data: returnData }; // returning label data to be able to book in if active
|
||||
} catch (error) {
|
||||
createLog(
|
||||
"info",
|
||||
"labeling",
|
||||
"ocp",
|
||||
`There was an error creating the label for, ${printer[0].name}, "Error: ${error}`
|
||||
);
|
||||
return {
|
||||
success: false,
|
||||
message: "There was an error creating the label",
|
||||
data: error,
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
// run the label delete process we want to delate them older than 90 days right now
|
||||
@@ -0,0 +1,23 @@
|
||||
import { eq } from "drizzle-orm";
|
||||
import { db } from "../../../../../database/dbclient.js";
|
||||
import { labelRatio } from "../../../../../database/schema/ratios.js";
|
||||
import { tryCatch } from "../../../../globalUtils/tryCatch.js";
|
||||
export const getLabelRatio = async () => {
|
||||
const { data: labelInfo, error: labelError } = await tryCatch(
|
||||
db.select().from(labelRatio).where(eq(labelRatio.name, "label"))
|
||||
);
|
||||
|
||||
if (labelError) {
|
||||
return {
|
||||
success: false,
|
||||
message: "There was an error getting the labelratio",
|
||||
data: [labelError],
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
success: true,
|
||||
message: "Current labelratio.",
|
||||
data: labelInfo,
|
||||
};
|
||||
};
|
||||
33
lstV2/server/services/ocp/controller/labeling/getLabels.ts
Normal file
33
lstV2/server/services/ocp/controller/labeling/getLabels.ts
Normal file
@@ -0,0 +1,33 @@
|
||||
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";
|
||||
export const getLabels = async (hours: string) => {
|
||||
const { data: labelInfo, error: labelError } = await tryCatch(
|
||||
db
|
||||
.select()
|
||||
.from(prodlabels)
|
||||
.where(
|
||||
gte(
|
||||
prodlabels.upd_date,
|
||||
sql.raw(`NOW() - INTERVAL '${hours} hours'`)
|
||||
)
|
||||
)
|
||||
.orderBy(desc(prodlabels.upd_date))
|
||||
);
|
||||
|
||||
if (labelError) {
|
||||
return {
|
||||
success: false,
|
||||
message: "There was an error getting the labels",
|
||||
data: [labelError],
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
success: true,
|
||||
message: "Current labels order by upd_Date.",
|
||||
count: labelInfo.length,
|
||||
data: labelInfo,
|
||||
};
|
||||
};
|
||||
322
lstV2/server/services/ocp/controller/labeling/labelProcess.ts
Normal file
322
lstV2/server/services/ocp/controller/labeling/labelProcess.ts
Normal file
@@ -0,0 +1,322 @@
|
||||
import { db } from "../../../../../database/dbclient.js";
|
||||
import { settings } from "../../../../../database/schema/settings.js";
|
||||
import { tryCatch } from "../../../../globalUtils/tryCatch.js";
|
||||
import { createLog } from "../../../logger/logger.js";
|
||||
import { getLots } from "../lots/lots.js";
|
||||
import { billingCheck } from "../specialProcesses/billingCheck/billingCheck.js";
|
||||
import { isMainMatStaged } from "../materials/mainMaterial.js";
|
||||
import { firstLotLabel } from "../specialProcesses/lotChangeLabel/lotCHangeLabel.js";
|
||||
import { prolinkCheck } from "../lots/prolinkCheck.js";
|
||||
import { createLabel } from "./createLabel.js";
|
||||
import { bookInLabel } from "./bookIn.js";
|
||||
import { delieryInhouse } from "../specialProcesses/inhouse/inhouseDelivery.js";
|
||||
import { dualPrintingProcess } from "../specialProcesses/dualPrinting/dualPrinting.js";
|
||||
import { getMac } from "../../utils/getMachineId.js";
|
||||
|
||||
interface Printer {
|
||||
name: string;
|
||||
humanReadableId: string;
|
||||
// Add any other expected properties
|
||||
}
|
||||
|
||||
interface Zechetti {
|
||||
line: string;
|
||||
printer: number;
|
||||
printerName: string;
|
||||
}
|
||||
|
||||
export const labelingProcess = async ({
|
||||
line = null as string | null,
|
||||
printer = null as Printer | null,
|
||||
userPrinted = null,
|
||||
rfidTag = null,
|
||||
zechette = null as Zechetti | null,
|
||||
} = {}) => {
|
||||
/**
|
||||
* Creates a label once all logic is passed
|
||||
*/
|
||||
let filteredLot: any = [];
|
||||
createLog("debug", "labeling", "ocp", `Starting labeling process`);
|
||||
const { data: settingData, error: settingError } = await tryCatch(
|
||||
db.select().from(settings)
|
||||
);
|
||||
|
||||
if (settingError) {
|
||||
return {
|
||||
success: false,
|
||||
message: "There was an error getting the settings.",
|
||||
settingError,
|
||||
};
|
||||
}
|
||||
// get the plantToken
|
||||
const plantToken = settingData.filter((n) => n.name === "plantToken");
|
||||
|
||||
// get the current lots
|
||||
const lots = await getLots();
|
||||
|
||||
// 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[0]?.HumanReadableId
|
||||
);
|
||||
|
||||
if (filteredLot.length === 0) {
|
||||
createLog(
|
||||
"error",
|
||||
"labeling",
|
||||
"ocp",
|
||||
`There is not a lot assigned to ${line}.`
|
||||
);
|
||||
return {
|
||||
success: false,
|
||||
message: `There is not a lot assigned to ${line}.`,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
// if we are running the zechettii
|
||||
if (zechette) {
|
||||
const macId = await getMac(zechette.line);
|
||||
// filter out the lot for the line
|
||||
filteredLot = lots.data.filter(
|
||||
(l: any) => l.MachineID === macId[0]?.HumanReadableId
|
||||
);
|
||||
|
||||
if (filteredLot.length === 0) {
|
||||
createLog(
|
||||
"error",
|
||||
"labeling",
|
||||
"ocp",
|
||||
`There is not a lot assigned to ${line}.`
|
||||
);
|
||||
return {
|
||||
success: false,
|
||||
message: `There is not a lot assigned to ${line}.`,
|
||||
};
|
||||
}
|
||||
|
||||
// remap the printer so its the zechetti one
|
||||
filteredLot = filteredLot.map((p: any) => ({
|
||||
...p,
|
||||
printerID: zechette.printer,
|
||||
PrinterName: zechette.printerName,
|
||||
}));
|
||||
}
|
||||
// if we came from a printer
|
||||
if (printer) {
|
||||
// filter the lot based on the printerID
|
||||
// console.log(printer);
|
||||
filteredLot = lots.data.filter(
|
||||
(l: any) => l.printerID === parseInt(printer?.humanReadableId)
|
||||
);
|
||||
if (filteredLot.length === 0) {
|
||||
// console.log(`There is not a lot assigned to ${printer.name}`);
|
||||
createLog(
|
||||
"error",
|
||||
"labeling",
|
||||
"ocp",
|
||||
`There is not a lot assigned to ${printer.name}`
|
||||
);
|
||||
//printerUpdate(printer, 7, `There is no lot assigned to this printer.`);
|
||||
return {
|
||||
success: false,
|
||||
message: `There is not a lot assigned to ${printer.name}.`,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* The checks we do before we can actually print a label will take place meow.
|
||||
*
|
||||
*/
|
||||
|
||||
// if the plant does not want to have dual printing and we have >2 assigned well return and send error.
|
||||
let dualPrinting = settingData.filter((d) => d.name === "dualPrinting")[0]
|
||||
?.value;
|
||||
|
||||
if (filteredLot.length > 1 && dualPrinting === "0") {
|
||||
createLog(
|
||||
"error",
|
||||
"labeling",
|
||||
"ocp",
|
||||
`${printer?.name}, has more than one lot assigned to it, and dual printing shut off.`
|
||||
);
|
||||
return {
|
||||
success: false,
|
||||
message: `${printer?.name}, has more than one lot assigned to it, and dual printing shut off.`,
|
||||
};
|
||||
}
|
||||
|
||||
if (filteredLot.length > 1 && dualPrinting === "1") {
|
||||
// send over for dual printing processing
|
||||
createLog(
|
||||
"info",
|
||||
"labeling",
|
||||
"ocp",
|
||||
`${printer?.name}, being sent over for dual printing processing.`
|
||||
);
|
||||
// process what line to print the label for and return the lot info and change filteredLot to returned one.
|
||||
filteredLot = await dualPrintingProcess(filteredLot);
|
||||
}
|
||||
|
||||
// if there are more than 2 lots it might be an auto labeler, autolabeler will be defined by its id for now only dayton
|
||||
if (filteredLot?.length > 2 && plantToken[0].value !== "usday1") {
|
||||
createLog(
|
||||
"error",
|
||||
"labeling",
|
||||
"ocp",
|
||||
`${printer?.name}, has more than 2 lot assigned to it, and not in ${plantToken[0].value}`
|
||||
);
|
||||
return {
|
||||
success: false,
|
||||
message: `${printer?.name}, has more than 2 lot assigned to it, and not in ${plantToken[0].value}`,
|
||||
};
|
||||
}
|
||||
|
||||
// special process for florence
|
||||
const isBillingTime = await billingCheck();
|
||||
|
||||
if (isBillingTime) {
|
||||
// billing is inside the window we dont want to bill now.
|
||||
return {
|
||||
success: false,
|
||||
message: "Billing time cant print.",
|
||||
};
|
||||
}
|
||||
|
||||
// check if we actaully have a lot passed over so we do not error out again.
|
||||
if (filteredLot.length === 0) {
|
||||
createLog(
|
||||
"error",
|
||||
"labeling",
|
||||
"ocp",
|
||||
`Error getting lot info from ${
|
||||
printer ? printer.name : "Missing printer info"
|
||||
}`
|
||||
);
|
||||
return {
|
||||
success: false,
|
||||
message: `Error getting lot info from ${
|
||||
printer ? printer.name : "Missing printer info"
|
||||
}`,
|
||||
};
|
||||
}
|
||||
|
||||
// check the material... mm,color (auto and manual combined), pkg
|
||||
const mmStaged = await isMainMatStaged(filteredLot[0]);
|
||||
|
||||
if (!mmStaged.success) {
|
||||
createLog("error", "labeling", "ocp", mmStaged.message);
|
||||
|
||||
return {
|
||||
success: false,
|
||||
message: mmStaged.message,
|
||||
};
|
||||
}
|
||||
|
||||
// comment only but will check for color
|
||||
createLog(
|
||||
"info",
|
||||
"labeling",
|
||||
"ocp",
|
||||
`Remaining pallets for: ${filteredLot[0].MachineDescription} is ${filteredLot[0].Remaining}`
|
||||
);
|
||||
|
||||
// do we want to over run
|
||||
if (filteredLot[0].overPrinting === "no" && filteredLot[0].Remaining <= 0) {
|
||||
createLog(
|
||||
"error",
|
||||
"labeling",
|
||||
"ocp",
|
||||
`Over Printing on ${filteredLot[0].MachineDescription} is not allowed please change the lot`
|
||||
);
|
||||
// for slc we want to run the first label for henkel
|
||||
firstLotLabel(filteredLot[0]);
|
||||
return {
|
||||
success: false,
|
||||
message: `Over Printing on ${filteredLot[0].MachineDescription} is not allowed please change the lot`,
|
||||
};
|
||||
}
|
||||
|
||||
// prolink check by lot
|
||||
const prolink = await prolinkCheck(filteredLot[0].lot);
|
||||
|
||||
if (!prolink) {
|
||||
//console.error(`Prolink does not match for ${filteredLot[0].MachineDescription}`);
|
||||
createLog(
|
||||
"error",
|
||||
"labeling",
|
||||
"ocp",
|
||||
`Prolink does not match for ${filteredLot[0].MachineDescription}`
|
||||
);
|
||||
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) {
|
||||
createLog(
|
||||
"error",
|
||||
"labeling",
|
||||
"ocp",
|
||||
`There was an error creating the label: ${label.message}`
|
||||
);
|
||||
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");
|
||||
let book: any = [];
|
||||
if (bookin[0].value === "1") {
|
||||
book = await bookInLabel(label.data);
|
||||
|
||||
if (!book.success) {
|
||||
// createLog(
|
||||
// "error",
|
||||
// "labeling",
|
||||
// "ocp",
|
||||
// `Error Booking in label: ${book.errors[0].message}`
|
||||
// );
|
||||
createLog(
|
||||
"error",
|
||||
"labeling",
|
||||
"ocp",
|
||||
`There was an error booking in the label: ${JSON.stringify(
|
||||
book.data
|
||||
)}`
|
||||
);
|
||||
return {
|
||||
success: false,
|
||||
message: `Error Booking in label`,
|
||||
data: book,
|
||||
};
|
||||
}
|
||||
} else {
|
||||
createLog("info", "labeling", "ocp", "Bookin is turned off.");
|
||||
|
||||
// will add later!!! :P
|
||||
}
|
||||
|
||||
// inhouse - if the inhouse funtion is turned on we will deliver to inhouse as long as we did not hit an error state
|
||||
const inhouseDelivery = settingData.filter(
|
||||
(s) => s.name === "inhouseDelivery"
|
||||
);
|
||||
if (inhouseDelivery[0].value === "1") {
|
||||
const deliverPallet = await delieryInhouse(book.data);
|
||||
// console.log(deliverPallet);
|
||||
}
|
||||
|
||||
return {
|
||||
success: true,
|
||||
message: "Label fully processed.",
|
||||
data: label.data,
|
||||
};
|
||||
};
|
||||
84
lstV2/server/services/ocp/controller/labeling/labelRatio.ts
Normal file
84
lstV2/server/services/ocp/controller/labeling/labelRatio.ts
Normal file
@@ -0,0 +1,84 @@
|
||||
import { eq, sql } from "drizzle-orm";
|
||||
import { db } from "../../../../../database/dbclient.js";
|
||||
import { labelRatio } from "../../../../../database/schema/ratios.js";
|
||||
import { tryCatch } from "../../../../globalUtils/tryCatch.js";
|
||||
import { createLog } from "../../../logger/logger.js";
|
||||
|
||||
export const autoLabelCreated = async () => {
|
||||
const { error } = await tryCatch(
|
||||
db
|
||||
.insert(labelRatio)
|
||||
.values({
|
||||
name: "label",
|
||||
autoLabel: 1,
|
||||
})
|
||||
.onConflictDoUpdate({
|
||||
target: labelRatio.name,
|
||||
set: { autoLabel: sql`${labelRatio.autoLabel} + 1` },
|
||||
})
|
||||
);
|
||||
|
||||
if (error) {
|
||||
createLog(
|
||||
"error",
|
||||
"labeling",
|
||||
"ocp",
|
||||
"There was an error updating auto label ratio"
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
export const manualLabelCreated = async () => {
|
||||
const { error } = await tryCatch(
|
||||
db
|
||||
.insert(labelRatio)
|
||||
.values({
|
||||
name: "label",
|
||||
manualLabel: 1,
|
||||
})
|
||||
.onConflictDoUpdate({
|
||||
target: labelRatio.name,
|
||||
set: { manualLabel: sql`${labelRatio.manualLabel} + 1` },
|
||||
})
|
||||
);
|
||||
|
||||
if (error) {
|
||||
createLog(
|
||||
"error",
|
||||
"labeling",
|
||||
"ocp",
|
||||
"There was an error updating manual Label Ratio"
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
export const resetLabelRatio = async () => {
|
||||
const { error } = await tryCatch(
|
||||
db
|
||||
.update(labelRatio)
|
||||
.set({
|
||||
name: sql`'label-' || (SELECT count(*) FROM ${labelRatio})`,
|
||||
lastReset: sql`NOW()`,
|
||||
})
|
||||
.where(eq(labelRatio.name, "label"))
|
||||
);
|
||||
|
||||
if (error) {
|
||||
console.log(error);
|
||||
createLog(
|
||||
"error",
|
||||
"labeling",
|
||||
"ocp",
|
||||
"There was an error resetting Label Ratio"
|
||||
);
|
||||
return {
|
||||
success: false,
|
||||
message: "There was an issue resetting the label data.",
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
success: true,
|
||||
message: "Label Ratio has been reset.",
|
||||
};
|
||||
};
|
||||
@@ -0,0 +1,53 @@
|
||||
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";
|
||||
import { manualLabelCreated } from "./labelRatio.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 });
|
||||
manualLabelCreated();
|
||||
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,
|
||||
};
|
||||
};
|
||||
Reference in New Issue
Block a user