feat(preprint): added in preprint function to help with operations planning constraints
This commit is contained in:
133
app/src/internal/logistics/controller/labeling/preprint.ts
Normal file
133
app/src/internal/logistics/controller/labeling/preprint.ts
Normal file
@@ -0,0 +1,133 @@
|
||||
/**
|
||||
* we want to be able to preprint labels from finished lots.
|
||||
* we will need a lot number
|
||||
* machine
|
||||
* printer
|
||||
* qty will come over as one by default
|
||||
* copies will come over as 0 by default
|
||||
* layout
|
||||
*/
|
||||
|
||||
import { createLogger } from "../../../../pkg/logger/logger.js";
|
||||
import { delay } from "../../../../pkg/utils/delay.js";
|
||||
import { prodEndpoint } from "../../../../pkg/utils/prodEndpoint.js";
|
||||
import type { returnFunc } from "../../../../pkg/utils/return.js";
|
||||
|
||||
export type Preprint = {
|
||||
scannerId: number;
|
||||
lotNr: number;
|
||||
machineId: number;
|
||||
printerId: number;
|
||||
layoutId: number;
|
||||
numberOfCopies: number;
|
||||
qtyToPrint: number;
|
||||
};
|
||||
|
||||
export const preprintLabels = async (preprint: Preprint) => {
|
||||
const log = createLogger({
|
||||
module: "logistics",
|
||||
subModule: "preprint",
|
||||
});
|
||||
let x = 0;
|
||||
|
||||
const labelsPrinted: number[] = [];
|
||||
if (preprint.qtyToPrint > 1) {
|
||||
do {
|
||||
const labels = await prodEndpoint(
|
||||
"POST",
|
||||
"/public/v1.0/Warehousing/GenerateAndPrintLabel",
|
||||
{
|
||||
scannerId: preprint.scannerId,
|
||||
lotNr: preprint.lotNr,
|
||||
machineId: preprint.machineId, // 457=22, 458=23
|
||||
printerId: preprint.printerId, // 457=22, 458=23
|
||||
layoutId: preprint.layoutId,
|
||||
numberOfCopies: preprint.numberOfCopies,
|
||||
},
|
||||
);
|
||||
if (labels?.data.Result === 1) {
|
||||
log.error(
|
||||
{},
|
||||
`There was an error printing the label: ${labels.data.Message}`,
|
||||
);
|
||||
return {
|
||||
success: false,
|
||||
message: `${labels.data.Message}`,
|
||||
};
|
||||
} else {
|
||||
if (!labels?.success) {
|
||||
log.error(
|
||||
{ error: labels?.data },
|
||||
`There was an error printing the label`,
|
||||
);
|
||||
return {
|
||||
success: false,
|
||||
message: `${labels?.message}`,
|
||||
data: labels?.data,
|
||||
};
|
||||
}
|
||||
labelsPrinted.push(parseInt(labels?.data.SSCC.slice(10, -1)));
|
||||
log.info(
|
||||
{},
|
||||
`Label just created ${parseInt(labels?.data.SSCC.slice(10, -1))} and printed, remaining to print ${preprint.qtyToPrint - x}`,
|
||||
);
|
||||
}
|
||||
await delay(250);
|
||||
x++;
|
||||
} while (x < preprint.qtyToPrint);
|
||||
|
||||
return {
|
||||
success: true,
|
||||
message: `${preprint.qtyToPrint} were just printed`,
|
||||
data: labelsPrinted,
|
||||
};
|
||||
} else {
|
||||
const labels = await prodEndpoint(
|
||||
"POST",
|
||||
"/public/v1.0/Warehousing/GenerateAndPrintLabel",
|
||||
{
|
||||
scannerId: preprint.scannerId,
|
||||
lotNr: preprint.lotNr,
|
||||
machineId: preprint.machineId, // 457=22, 458=23
|
||||
printerId: preprint.printerId, // 457=22, 458=23
|
||||
layoutId: preprint.layoutId,
|
||||
numberOfCopies: preprint.numberOfCopies,
|
||||
},
|
||||
);
|
||||
|
||||
if (labels?.data.Result === 1) {
|
||||
log.error(
|
||||
{},
|
||||
`There was an error printing the label: ${labels.data.Message}`,
|
||||
);
|
||||
return {
|
||||
success: false,
|
||||
message: `${labels.data.Message}`,
|
||||
};
|
||||
} else {
|
||||
if (!labels?.success) {
|
||||
log.error(
|
||||
{ error: labels?.data },
|
||||
`There was an error printing the label`,
|
||||
);
|
||||
return {
|
||||
success: false,
|
||||
message: `${labels?.message}`,
|
||||
data: labels?.data,
|
||||
};
|
||||
}
|
||||
|
||||
labelsPrinted.push(parseInt(labels.data.SSCC.slice(10, -1)));
|
||||
log.info(
|
||||
{},
|
||||
`Label just created ${parseInt(labels.data.SSCC.slice(10, -1))} and printed`,
|
||||
);
|
||||
|
||||
return {
|
||||
success: true,
|
||||
message: `${preprint.qtyToPrint} were just printed.`,
|
||||
data: labelsPrinted,
|
||||
};
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -1,16 +1,17 @@
|
||||
import type { Express, Request, Response } from "express";
|
||||
import { requireAuth } from "../../pkg/middleware/authMiddleware.js";
|
||||
import labeling from "./routes/labeling/labelingRoutes.js";
|
||||
import schedule from "./routes/scheduler/scheduleRoutes.js";
|
||||
|
||||
export const setupLogisticsRoutes = (app: Express, basePath: string) => {
|
||||
app.use(basePath + "/api/logistics/schedule", schedule);
|
||||
app.use(basePath + "/api/logistics/schedule", schedule);
|
||||
app.use(basePath + "/api/logistics/labeling", labeling);
|
||||
|
||||
app.use(
|
||||
basePath + "/api/admin/users",
|
||||
requireAuth("user", ["systemAdmin"]) // will pass bc system admin but this is just telling us we need this
|
||||
);
|
||||
app.use(
|
||||
basePath + "/api/admin",
|
||||
requireAuth("user", ["systemAdmin", "admin"]) // will pass bc system admin but this is just telling us we need this
|
||||
);
|
||||
// app.use(
|
||||
// basePath + "/api/admin/users",
|
||||
// requireAuth("user", ["systemAdmin"]), // will pass bc system admin but this is just telling us we need this
|
||||
// );
|
||||
// app.use(
|
||||
// basePath + "/api/admin",
|
||||
// requireAuth("user", ["systemAdmin", "admin"]), // will pass bc system admin but this is just telling us we need this
|
||||
// );
|
||||
};
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
import { Router } from "express";
|
||||
import preprint from "./perprint.js";
|
||||
|
||||
const router = Router();
|
||||
|
||||
router.use("/", preprint);
|
||||
|
||||
export default router;
|
||||
27
app/src/internal/logistics/routes/labeling/perprint.ts
Normal file
27
app/src/internal/logistics/routes/labeling/perprint.ts
Normal file
@@ -0,0 +1,27 @@
|
||||
import type { Request, Response } from "express";
|
||||
import { Router } from "express";
|
||||
import z from "zod";
|
||||
import { preprintLabels } from "../../controller/labeling/preprint.js";
|
||||
|
||||
export const Preprint = z.object({
|
||||
scannerId: z.number(),
|
||||
lotNr: z.number(),
|
||||
machineId: z.number(), // 457=22, 458=23
|
||||
printerId: z.number(), // 457=22, 458=23
|
||||
layoutId: z.number(),
|
||||
numberOfCopies: z.number(),
|
||||
qtyToPrint: z.number().default(1),
|
||||
});
|
||||
|
||||
const router = Router();
|
||||
|
||||
router.post("/preprint", async (req: Request, res: Response) => {
|
||||
const parsed = Preprint.safeParse(req.body);
|
||||
const print = await preprintLabels(req.body);
|
||||
|
||||
res
|
||||
.status(200)
|
||||
.json({ success: print.success, message: print.message, data: print.data });
|
||||
});
|
||||
|
||||
export default router;
|
||||
Reference in New Issue
Block a user