added relocate

This commit is contained in:
2026-02-03 15:40:41 -06:00
parent 9be6614972
commit 84a28f2d01
5 changed files with 169 additions and 15 deletions

View File

@@ -12,14 +12,15 @@ import { LstCard } from "../../../extendedUi/LstCard";
export default function Relocate() { export default function Relocate() {
const [bookingIn, setBookingIn] = useState(false); const [bookingIn, setBookingIn] = useState(false);
const form = useForm({ const form = useForm({
defaultValues: { runningNr: " ", lane: "" }, defaultValues: { runningNr: " ", laneID: "" },
onSubmit: async ({ value }) => { onSubmit: async ({ value }) => {
// Do something with form data // Do something with form data
setBookingIn(true); setBookingIn(true);
try { 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), runningNr: parseInt(value.runningNr),
laneID: parseInt(value.laneID),
}); });
if (res.data.success) { if (res.data.success) {
@@ -27,15 +28,15 @@ export default function Relocate() {
form.reset(); form.reset();
setBookingIn(false); setBookingIn(false);
} else { } else {
console.log(res.data.data.errors); console.log(res.data.message);
toast.error(res.data.data.errors[0]?.message); toast.error(res.data.message);
form.reset(); //form.reset();
setBookingIn(false); setBookingIn(false);
} }
} catch (error) { } catch (error) {
console.log(error); console.log(error);
toast.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); setBookingIn(false);
} }
@@ -83,19 +84,17 @@ export default function Relocate() {
}} }}
/> />
<form.Field <form.Field
name="lane" name="laneID"
validators={{ validators={{
// We can choose between form-wide and field-specific validators // We can choose between form-wide and field-specific validators
onChange: ({ value }) => onChange: ({ value }) =>
value.length > 2 value.length > 2 ? undefined : "Please enter a valid lane ID",
? undefined
: "Please enter a valid running number",
}} }}
children={(field) => { children={(field) => {
return ( return (
<div className=""> <div className="">
<Label htmlFor="runningNr" className="mb-2"> <Label htmlFor="laneID" className="mb-2">
Enter lane Enter lane ID
</Label> </Label>
<Input <Input
name={field.name} name={field.name}

View File

@@ -7,14 +7,18 @@ export default function HelperPage() {
return ( return (
<div className="flex flex-wrap m-2 justify-center"> <div className="flex flex-wrap m-2 justify-center">
<div className="m-1"> <div className="m-1">
<Bookin /> <div className="m-1 ">
<Bookin />
</div>
<div className="w-96 m-1">
<Relocate />
</div>
</div> </div>
<div className="m-1"> <div className="m-1">
{url === "localhost" && ( {url === "localhost" && (
<div className="m-1"> <div className="m-1">
<RemoveAsNonReusable /> <RemoveAsNonReusable />
<Relocate />
</div> </div>
)} )}
</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 getPPOO from "./route/getPPOO.js";
import getConnectionType from "./route/getSiloConnectionData.js"; import getConnectionType from "./route/getSiloConnectionData.js";
import getSSCC from "./route/getSSCCNumber.js"; import getSSCC from "./route/getSSCCNumber.js";
import relocate from "./route/relocate.js";
import removeAsNonReable from "./route/removeAsNonReusable.js"; import removeAsNonReable from "./route/removeAsNonReusable.js";
import returnMat from "./route/returnMaterial.js"; import returnMat from "./route/returnMaterial.js";
import createSiloAdjustment from "./route/siloAdjustments/createSiloAdjustment.js"; import createSiloAdjustment from "./route/siloAdjustments/createSiloAdjustment.js";
@@ -28,7 +29,7 @@ const app = new OpenAPIHono();
const routes = [ const routes = [
comsumeMaterial, comsumeMaterial,
returnMat, returnMat,
relocate,
// silo // silo
createSiloAdjustment, createSiloAdjustment,
postComment, 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;