Compare commits

...

2 Commits

Author SHA1 Message Date
d63138d746 helper scripts 2026-02-03 15:40:51 -06:00
84a28f2d01 added relocate 2026-02-03 15:40:41 -06:00
8 changed files with 461 additions and 15 deletions

View File

@@ -12,14 +12,15 @@ import { LstCard } from "../../../extendedUi/LstCard";
export default function Relocate() {
const [bookingIn, setBookingIn] = useState(false);
const form = useForm({
defaultValues: { runningNr: " ", lane: "" },
defaultValues: { runningNr: " ", laneID: "" },
onSubmit: async ({ value }) => {
// Do something with form data
setBookingIn(true);
try {
const res = await axios.post("/lst/old/api/ocp/bookin", {
const res = await axios.post("/lst/old/api/logistics/relocate", {
runningNr: parseInt(value.runningNr),
laneID: parseInt(value.laneID),
});
if (res.data.success) {
@@ -27,15 +28,15 @@ export default function Relocate() {
form.reset();
setBookingIn(false);
} else {
console.log(res.data.data.errors);
toast.error(res.data.data.errors[0]?.message);
form.reset();
console.log(res.data.message);
toast.error(res.data.message);
//form.reset();
setBookingIn(false);
}
} catch (error) {
console.log(error);
toast.error(
"There was an error booking in pallet please validate you entered the correct info and try again.",
"There was an error relocating the pallet please validate the data.",
);
setBookingIn(false);
}
@@ -83,19 +84,17 @@ export default function Relocate() {
}}
/>
<form.Field
name="lane"
name="laneID"
validators={{
// We can choose between form-wide and field-specific validators
onChange: ({ value }) =>
value.length > 2
? undefined
: "Please enter a valid running number",
value.length > 2 ? undefined : "Please enter a valid lane ID",
}}
children={(field) => {
return (
<div className="">
<Label htmlFor="runningNr" className="mb-2">
Enter lane
<Label htmlFor="laneID" className="mb-2">
Enter lane ID
</Label>
<Input
name={field.name}

View File

@@ -6,15 +6,19 @@ export default function HelperPage() {
const url: string = window.location.host.split(":")[0];
return (
<div className="flex flex-wrap m-2 justify-center">
<div className="m-1">
<div className="m-1 ">
<Bookin />
</div>
<div className="w-96 m-1">
<Relocate />
</div>
</div>
<div className="m-1">
{url === "localhost" && (
<div className="m-1">
<RemoveAsNonReusable />
<Relocate />
</div>
)}
</div>

View File

@@ -0,0 +1,70 @@
import axios from "axios";
import { db } from "../../../../../database/dbclient.js";
import { commandLog } from "../../../../../database/schema/commandLog.js";
import { createSSCC } from "../../../../globalUtils/createSSCC.js";
import { prodEndpointCreation } from "../../../../globalUtils/createUrl.js";
import { tryCatch } from "../../../../globalUtils/tryCatch.js";
import { createLog } from "../../../logger/logger.js";
type Data = {
runningNr: number;
laneID: number;
};
export const relatePallet = async (data: Data) => {
const { runningNr, laneID } = data;
// replace the rn
// console.log(data);
// create the url to post
const url = await prodEndpointCreation("/public/v1.0/Warehousing/Relocate");
const SSCC = await createSSCC(runningNr);
const consumeSomething = {
ScannerId: 999,
laneId: laneID,
sscc: SSCC.slice(2),
};
console.log(consumeSomething);
try {
const results = await axios.post(url, consumeSomething, {
headers: {
"X-API-Key": process.env.TEC_API_KEY || "",
"Content-Type": "application/json",
},
});
if (results.data.Errors) {
return {
success: false,
message: results.data.Errors.Error.Description,
};
}
if (results.data.Result !== 0) {
return {
success: false,
message: results.data.Message,
};
}
const { data: commandL, error: ce } = await tryCatch(
db.insert(commandLog).values({
commandUsed: "relocate",
bodySent: data,
}),
);
return {
success: true,
message: "Pallet Was Relocated",
status: results.status,
};
} catch (error: any) {
console.log(error);
return {
success: false,
status: 200,
message: error.response?.data.errors[0].message,
};
}
};

View File

@@ -16,6 +16,7 @@ import outbound from "./route/getOutbound.js";
import getPPOO from "./route/getPPOO.js";
import getConnectionType from "./route/getSiloConnectionData.js";
import getSSCC from "./route/getSSCCNumber.js";
import relocate from "./route/relocate.js";
import removeAsNonReable from "./route/removeAsNonReusable.js";
import returnMat from "./route/returnMaterial.js";
import createSiloAdjustment from "./route/siloAdjustments/createSiloAdjustment.js";
@@ -28,7 +29,7 @@ const app = new OpenAPIHono();
const routes = [
comsumeMaterial,
returnMat,
relocate,
// silo
createSiloAdjustment,
postComment,

View File

@@ -0,0 +1,80 @@
import { createRoute, OpenAPIHono, z } from "@hono/zod-openapi";
import { apiHit } from "../../../globalUtils/apiHits.js";
import { tryCatch } from "../../../globalUtils/tryCatch.js";
import { authMiddleware } from "../../auth/middleware/authMiddleware.js";
import { relatePallet } from "../controller/commands/relocated.js";
const app = new OpenAPIHono();
const responseSchema = z.object({
success: z.boolean().optional().openapi({ example: true }),
message: z.string().optional().openapi({ example: "user access" }),
});
app.openapi(
createRoute({
tags: ["logistics"],
summary: "Consumes material based on its running number",
method: "post",
path: "/relocate",
//middleware: authMiddleware,
description:
"Provided a running number and lot number you can consume material.",
responses: {
200: {
content: { "application/json": { schema: responseSchema } },
description: "stopped",
},
400: {
content: { "application/json": { schema: responseSchema } },
description: "Failed to stop",
},
401: {
content: { "application/json": { schema: responseSchema } },
description: "Failed to stop",
},
},
}),
async (c) => {
const { data, error } = await tryCatch(c.req.json());
if (error) {
return c.json(
{
success: false,
message: "Missing data please try again",
error,
},
400,
);
}
apiHit(c, { endpoint: "/relocate", lastBody: data });
//const authHeader = c.req.header("Authorization");
//const token = authHeader?.split("Bearer ")[1] || "";
//const payload = await verify(token, process.env.JWT_SECRET!);
try {
//return apiReturn(c, true, access?.message, access?.data, 200);
const consume = await relatePallet(data);
console.log(consume);
return c.json(
{ success: consume?.success, message: consume?.message },
200,
);
} catch (error) {
//console.log(error);
//return apiReturn(c, false, "Error in setting the user access", error, 400);
return c.json(
{
success: false,
message: "Missing data please try again",
error,
},
400,
);
}
},
);
export default app;

View File

@@ -0,0 +1,105 @@
import net from "net";
/**
* This uses a kinda fake scanner to mimic the scanning process to a server and creates the bol.
*/
const scannerID = "98@";
const scannerCommand = "Alplaprodcmd10"; // to consume all the pallets
const lot = "AlplaPRODchg#00000016700"; // to consume to the lot make sure its showing in 2.0 to be able to consume to it
const labels = [
"1000000000000000000000000000000005512460",
"1000000000000000000000000000000005512470",
"1000000000000000000000000000000005512480",
"1000000000000000000000000000000005512490",
"1000000000000000000000000000000005512500",
"1000000000000000000000000000000005512510",
"1000000000000000000000000000000005512520",
"1000000000000000000000000000000005512530",
"1000000000000000000000000000000005512540",
"1000000000000000000000000000000005512550",
"1000000000000000000000000000000005512560",
"1000000000000000000000000000000005512570",
"1000000000000000000000000000000005512580",
"1000000000000000000000000000000005512590",
"1000000000000000000000000000000005512600",
"1000000000000000000000000000000005512610",
"1000000000000000000000000000000005512620",
"1000000000000000000000000000000005512630",
"1000000000000000000000000000000005512640",
"1000000000000000000000000000000005512650",
"1000000000000000000000000000000005512660",
"1000000000000000000000000000000005512670",
"1000000000000000000000000000000005512680",
"1000000000000000000000000000000005512690",
"1000000000000000000000000000000005512700",
"1000000000000000000000000000000005512710",
"1000000000000000000000000000000005512720",
"1000000000000000000000000000000005512730",
"1000000000000000000000000000000005512740",
"1000000000000000000000000000000005512750",
"1000000000000000000000000000000005512760",
"1000000000000000000000000000000005512770",
"1000000000000000000000000000000005512780",
"1000000000000000000000000000000005512790",
"1000000000000000000000000000000005512800",
"1000000000000000000000000000000005512810",
"1000000000000000000000000000000005512820",
"1000000000000000000000000000000005512830",
"1000000000000000000000000000000005512840",
"1000000000000000000000000000000005512850",
"1000000000000000000000000000000005512860",
"1000000000000000000000000000000005512870",
"1000000000000000000000000000000005512880",
"1000000000000000000000000000000005512890",
"1000000000000000000000000000000005512900",
"1000000000000000000000000000000005512910",
"1000000000000000000000000000000005512920",
"1000000000000000000000000000000005512930",
"1000000000000000000000000000000005512940",
"1000000000000000000000000000000005512950",
"1000000000000000000000000000000005512960",
];
const STX = "\x02";
const ETX = "\x03";
const scanner = new net.Socket();
scanner.connect(50000, "10.204.0.26", async () => {
console.log("Connected to scanner");
// change the scanner to the to 112
let message = Buffer.from(
`${STX}${scannerID}${scannerCommand}${ETX}`,
"ascii",
);
console.log("Sending:", message.toString("ascii"));
scanner.write(message);
await new Promise((resolve) => setTimeout(resolve, 2000));
// bookin all the pallets in the array
await new Promise((resolve) => setTimeout(resolve, 2000));
for (let i = 0; i < labels.length; i++) {
const l = labels[i];
message = Buffer.from(`${STX}${scannerID}${l}${ETX}`, "ascii");
console.log("Sending:", message.toString("ascii"));
scanner.write(message);
await new Promise((resolve) => setTimeout(resolve, 1200));
}
await new Promise((resolve) => setTimeout(resolve, 1500));
scanner.destroy();
});
scanner.on("data", async (data) => {
console.log("Response:", data.toString("ascii"));
});
scanner.on("close", () => {
console.log("Connection closed");
});
scanner.on("error", (err) => {
console.error("Scanner error:", err);
});

View File

@@ -0,0 +1,88 @@
import net from "net";
/**
* This uses a kinda fake scanner to mimic the scanning process to a server and creates the bol.
*/
const scannerID = "98@";
const scannerCommand = "Alplaprodcmd112"; // to consume all the pallets
const lot = "AlplaPRODchg#00000016706"; // to consume to the lot make sure its showing in 2.0 to be able to consume to it
const labels = [
"1000000000000000000000000000000005106656",
"1000000000000000000000000000000005106386",
"1000000000000000000000000000000005106446",
"1000000000000000000000000000000005106326",
"1000000000000000000000000000000005105726",
"1000000000000000000000000000000005106056",
"1000000000000000000000000000000005106256",
"1000000000000000000000000000000005105836",
"1000000000000000000000000000000005105986",
"1000000000000000000000000000000005105506",
"1000000000000000000000000000000005106136",
"1000000000000000000000000000000005105696",
"1000000000000000000000000000000005105426",
"1000000000000000000000000000000005105916",
"1000000000000000000000000000000005105216",
"1000000000000000000000000000000005105416",
"1000000000000000000000000000000005105196",
"1000000000000000000000000000000005105226",
"1000000000000000000000000000000005105816",
"1000000000000000000000000000000005110186",
"1000000000000000000000000000000005110256",
"1000000000000000000000000000000005109926",
"1000000000000000000000000000000005110096",
"1000000000000000000000000000000005110026",
"1000000000000000000000000000000005110036",
"1000000000000000000000000000000005109716",
"1000000000000000000000000000000005110006",
"1000000000000000000000000000000005109446",
"1000000000000000000000000000000005109606",
"1000000000000000000000000000000005109076",
];
const STX = "\x02";
const ETX = "\x03";
const scanner = new net.Socket();
scanner.connect(50000, "10.204.0.26", async () => {
console.log("Connected to scanner");
// change the scanner to the to 112
let message = Buffer.from(
`${STX}${scannerID}${scannerCommand}${ETX}`,
"ascii",
);
console.log("Sending:", message.toString("ascii"));
scanner.write(message);
await new Promise((resolve) => setTimeout(resolve, 2000));
// consume all the pallets in the array
await new Promise((resolve) => setTimeout(resolve, 2000));
for (let i = 0; i < labels.length; i++) {
const l = labels[i];
// trigger the lot
let message = Buffer.from(`${STX}${scannerID}${lot}${ETX}`, "ascii");
console.log("Sending:", message.toString("ascii"));
scanner.write(message);
message = Buffer.from(`${STX}${scannerID}${l}${ETX}`, "ascii");
console.log("Sending:", message.toString("ascii"));
scanner.write(message);
await new Promise((resolve) => setTimeout(resolve, 1200));
}
await new Promise((resolve) => setTimeout(resolve, 1500));
scanner.destroy();
});
scanner.on("data", async (data) => {
console.log("Response:", data.toString("ascii"));
});
scanner.on("close", () => {
console.log("Connection closed");
});
scanner.on("error", (err) => {
console.error("Scanner error:", err);
});

View File

@@ -0,0 +1,99 @@
import net from "net";
/**
* This uses a kinda fake scanner to mimic the scanning process to a server and creates the bol.
*/
const prodIP = "10.44.0.26";
const prodPort = 50001;
const scannerID = "98@";
const scannerCommand = "AlplaPRODcmd00000042#000047909"; // top of the picksheet
const scannerCommand2 = ""; // bottom of the pick sheet
const labels = [
"1000000000000000000000000000000006544320",
"1000000000000000000000000000000006544280",
"1000000000000000000000000000000006544410",
"1000000000000000000000000000000006544490",
"1000000000000000000000000000000006544450",
"1000000000000000000000000000000006544520",
"1000000000000000000000000000000006544590",
"1000000000000000000000000000000006544560",
"1000000000000000000000000000000006544860",
"1000000000000000000000000000000006544830",
"1000000000000000000000000000000006544930",
"1000000000000000000000000000000006544890",
"1000000000000000000000000000000006545100",
"1000000000000000000000000000000006545060",
"1000000000000000000000000000000006545270",
"1000000000000000000000000000000006545220",
"1000000000000000000000000000000006544990",
"1000000000000000000000000000000006545040",
"1000000000000000000000000000000006545520",
"1000000000000000000000000000000006545490",
"1000000000000000000000000000000006545450",
"1000000000000000000000000000000006545560",
"1000000000000000000000000000000006545760",
"1000000000000000000000000000000006545640",
"1000000000000000000000000000000006545690",
"1000000000000000000000000000000006545620",
"1000000000000000000000000000000006546450",
"1000000000000000000000000000000006546500",
"1000000000000000000000000000000006545940",
"1000000000000000000000000000000006545900",
"1000000000000000000000000000000006545850",
"1000000000000000000000000000000006545820",
"1000000000000000000000000000000006546530",
"1000000000000000000000000000000006545330",
"1000000000000000000000000000000006546090",
"1000000000000000000000000000000006546220",
"1000000000000000000000000000000006546120",
"1000000000000000000000000000000006546140",
"1000000000000000000000000000000006546260",
"1000000000000000000000000000000006546310",
];
const STX = "\x02";
const ETX = "\x03";
const scanner = new net.Socket();
scanner.connect(prodPort, prodIP, async () => {
console.log("Connected to scanner");
const message = Buffer.from(
`${STX}${scannerID}${scannerCommand}${ETX}`,
"ascii",
);
console.log("Sending:", message.toString("ascii"));
scanner.write(message);
await new Promise((resolve) => setTimeout(resolve, 2000));
for (let i = 0; i < labels.length; i++) {
const l = labels[i];
const message = Buffer.from(`${STX}${scannerID}${l}${ETX}`, "ascii");
console.log("Sending:", message.toString("ascii"));
scanner.write(message);
await new Promise((resolve) => setTimeout(resolve, 1200));
}
// //close the incoming
// await new Promise(resolve => setTimeout(resolve, 1500));
// const message2 = Buffer.from(`${STX}${scannerID}${scannerCommand2}${ETX}`, "ascii");
// console.log("Sending:", message2.toString("ascii"));
// scanner.write(message2);
await new Promise((resolve) => setTimeout(resolve, 1500));
scanner.destroy();
});
scanner.on("data", async (data) => {
console.log("Response:", data.toString("ascii"));
});
scanner.on("close", () => {
console.log("Connection closed");
});
scanner.on("error", (err) => {
console.error("Scanner error:", err);
});