feat(printer delay): printer delay option to grab the delay based off cycle time
This commit is contained in:
@@ -6,11 +6,13 @@ import { tryCatch } from "../../../globalUtils/tryCatch.js";
|
|||||||
import { getLots } from "../controller/lots/lots.js";
|
import { getLots } from "../controller/lots/lots.js";
|
||||||
import { getPrinters } from "../controller/printers/getPrinters.js";
|
import { getPrinters } from "../controller/printers/getPrinters.js";
|
||||||
import { createLog } from "../../logger/logger.js";
|
import { createLog } from "../../logger/logger.js";
|
||||||
|
import { printerDelayByLot } from "./printerDelayByLot.js";
|
||||||
|
|
||||||
export const assignedPrinters = async () => {
|
export const assignedPrinters = async () => {
|
||||||
createLog("debug", "ocp", "ocp", "Lot assignment check");
|
createLog("debug", "ocp", "ocp", "Lot assignment check");
|
||||||
const { data: lot, error: lotError } = await tryCatch(getLots());
|
const { data: lot, error: lotError } = await tryCatch(getLots());
|
||||||
const l: any = lot;
|
const l: any = lot;
|
||||||
|
|
||||||
if (lotError) {
|
if (lotError) {
|
||||||
return {
|
return {
|
||||||
success: false,
|
success: false,
|
||||||
@@ -41,6 +43,9 @@ export const assignedPrinters = async () => {
|
|||||||
data: [],
|
data: [],
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// update the printers if we have the setting checked
|
||||||
|
printerDelayByLot(l.data);
|
||||||
const { data: print, error: printerError } = await tryCatch(getPrinters());
|
const { data: print, error: printerError } = await tryCatch(getPrinters());
|
||||||
|
|
||||||
if (printerError) {
|
if (printerError) {
|
||||||
|
|||||||
111
lstV2/server/services/ocp/utils/printerDelayByLot.ts
Normal file
111
lstV2/server/services/ocp/utils/printerDelayByLot.ts
Normal file
@@ -0,0 +1,111 @@
|
|||||||
|
import { eq, sql } from "drizzle-orm";
|
||||||
|
import { db } from "../../../../database/dbclient.js";
|
||||||
|
import { printerData } from "../../../../database/schema/printers.js";
|
||||||
|
import { settings } from "../../../../database/schema/settings.js";
|
||||||
|
import { tryCatch } from "../../../globalUtils/tryCatch.js";
|
||||||
|
import { createLog } from "../../logger/logger.js";
|
||||||
|
import { delay } from "../../../globalUtils/delay.js";
|
||||||
|
import { getPrinters } from "../controller/printers/getPrinters.js";
|
||||||
|
|
||||||
|
//**The logic here will be when the setting is active to utilize the lots times it will update the printDelay in the printer data table */
|
||||||
|
export const printerDelayByLot = async (lot: any) => {
|
||||||
|
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 printDelay = settingData.filter((n) => n.name === "lotPrintDelay");
|
||||||
|
|
||||||
|
const ignorePrinters = [
|
||||||
|
"Autolabeler",
|
||||||
|
"pdf24",
|
||||||
|
"PDF24",
|
||||||
|
"zecchetti_1",
|
||||||
|
"zecchetti2",
|
||||||
|
];
|
||||||
|
const printers = (await getPrinters()) as any;
|
||||||
|
const p = printers.data;
|
||||||
|
|
||||||
|
if (printDelay[0].value === "0") {
|
||||||
|
for (let i = 0; i < p.length; i++) {
|
||||||
|
if (p[i].printDelay > 90) {
|
||||||
|
if (ignorePrinters.includes(lot[i].PrinterName)) continue;
|
||||||
|
|
||||||
|
const { data, error } = await tryCatch(
|
||||||
|
db
|
||||||
|
.update(printerData)
|
||||||
|
.set({
|
||||||
|
printDelay: "90",
|
||||||
|
upd_date: sql`NOW()`,
|
||||||
|
})
|
||||||
|
.where(
|
||||||
|
eq(printerData.humanReadableId, lot[i].printerID)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
// if (data) {
|
||||||
|
// createLog(
|
||||||
|
// "info",
|
||||||
|
// "printers",
|
||||||
|
// "ocp",
|
||||||
|
// `${printerData.name} had its delay time updated to 90 seconds `
|
||||||
|
// );
|
||||||
|
// }
|
||||||
|
|
||||||
|
// if (error) {
|
||||||
|
// createLog(
|
||||||
|
// "error",
|
||||||
|
// "printers",
|
||||||
|
// "ocp",
|
||||||
|
// `${printerData.name} encountered an error updating the printer delay time `
|
||||||
|
// );
|
||||||
|
// }
|
||||||
|
await delay(500);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (printDelay[0].value === "1") {
|
||||||
|
for (let i = 0; i < lot.length; i++) {
|
||||||
|
if (ignorePrinters.includes(lot[i].PrinterName)) continue;
|
||||||
|
|
||||||
|
const { data, error } = await tryCatch(
|
||||||
|
db
|
||||||
|
.update(printerData)
|
||||||
|
.set({
|
||||||
|
printDelay: lot[i].timeTOmakeInSeconds.toFixed(2),
|
||||||
|
upd_date: sql`NOW()`,
|
||||||
|
})
|
||||||
|
.where(eq(printerData.humanReadableId, lot[i].printerID))
|
||||||
|
);
|
||||||
|
|
||||||
|
// if (data) {
|
||||||
|
// createLog(
|
||||||
|
// "info",
|
||||||
|
// "printers",
|
||||||
|
// "ocp",
|
||||||
|
// `${lot[i].PrinterName} had its delay time updated to ${lot[
|
||||||
|
// i
|
||||||
|
// ].timeTOmakeInSeconds.toFixed(2)} seconds `
|
||||||
|
// );
|
||||||
|
// }
|
||||||
|
|
||||||
|
// if (error) {
|
||||||
|
// createLog(
|
||||||
|
// "error",
|
||||||
|
// "printers",
|
||||||
|
// "ocp",
|
||||||
|
// `${lot[i].PrinterName} encountered an error updating the printer delay time `
|
||||||
|
// );
|
||||||
|
// }
|
||||||
|
await delay(500);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
@@ -280,6 +280,14 @@ const newSettings = [
|
|||||||
serviceBelowsTo: "admin",
|
serviceBelowsTo: "admin",
|
||||||
roleToChange: "admin",
|
roleToChange: "admin",
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: "lotPrintDelay",
|
||||||
|
value: `0`,
|
||||||
|
description:
|
||||||
|
"Changes the print delay to be based on the pallet completion time",
|
||||||
|
serviceBelowsTo: "admin",
|
||||||
|
roleToChange: "admin",
|
||||||
|
},
|
||||||
];
|
];
|
||||||
export const areSettingsIn = async () => {
|
export const areSettingsIn = async () => {
|
||||||
// get the roles
|
// get the roles
|
||||||
|
|||||||
Reference in New Issue
Block a user