feat(helpercommand): bookin pallets
This commit is contained in:
@@ -0,0 +1,102 @@
|
||||
import { LstCard } from "@/components/extendedUI/LstCard";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { CardContent, CardFooter, CardHeader } from "@/components/ui/card";
|
||||
import { Input } from "@/components/ui/input";
|
||||
import { Label } from "@/components/ui/label";
|
||||
import { useForm } from "@tanstack/react-form";
|
||||
import axios from "axios";
|
||||
import { useState } from "react";
|
||||
import { toast } from "sonner";
|
||||
|
||||
export default function Bookin() {
|
||||
const [bookingIn, setBookingIn] = useState(false);
|
||||
const form = useForm({
|
||||
defaultValues: { runningNr: " " },
|
||||
onSubmit: async ({ value }) => {
|
||||
// Do something with form data
|
||||
setBookingIn(true);
|
||||
|
||||
try {
|
||||
const res = await axios.post("/api/ocp/bookin", {
|
||||
runningNr: parseInt(value.runningNr),
|
||||
});
|
||||
|
||||
if (res.data.success) {
|
||||
toast.success(res.data.message);
|
||||
form.reset();
|
||||
setBookingIn(false);
|
||||
} else {
|
||||
console.log(res.data.data.errors);
|
||||
toast.error(res.data.data.errors[0]?.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."
|
||||
);
|
||||
setBookingIn(false);
|
||||
}
|
||||
},
|
||||
});
|
||||
return (
|
||||
<LstCard>
|
||||
<CardHeader>
|
||||
<p>Book in a pallet by running number</p>
|
||||
</CardHeader>
|
||||
<form
|
||||
onSubmit={(e) => {
|
||||
e.preventDefault();
|
||||
e.stopPropagation();
|
||||
}}
|
||||
>
|
||||
<CardContent>
|
||||
<form.Field
|
||||
name="runningNr"
|
||||
validators={{
|
||||
// We can choose between form-wide and field-specific validators
|
||||
onChange: ({ value }) =>
|
||||
value.length > 2
|
||||
? undefined
|
||||
: "Please enter a valid running number",
|
||||
}}
|
||||
children={(field) => {
|
||||
return (
|
||||
<div className="m-2 min-w-48 max-w-96 p-2">
|
||||
<Label htmlFor="runningNr" className="mb-2">
|
||||
Runnning Number
|
||||
</Label>
|
||||
<Input
|
||||
name={field.name}
|
||||
value={field.state.value}
|
||||
onBlur={field.handleBlur}
|
||||
type="number"
|
||||
onChange={(e) =>
|
||||
field.handleChange(e.target.value)
|
||||
}
|
||||
/>
|
||||
{field.state.meta.errors.length ? (
|
||||
<em>
|
||||
{field.state.meta.errors.join(",")}
|
||||
</em>
|
||||
) : null}
|
||||
</div>
|
||||
);
|
||||
}}
|
||||
/>
|
||||
</CardContent>
|
||||
<CardFooter>
|
||||
<div className="flex justify-end">
|
||||
<Button
|
||||
onClick={form.handleSubmit}
|
||||
disabled={bookingIn}
|
||||
>
|
||||
Book in
|
||||
</Button>
|
||||
</div>
|
||||
</CardFooter>
|
||||
</form>
|
||||
</LstCard>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
import Bookin from "./commands/Bookin";
|
||||
|
||||
export default function HelperPage() {
|
||||
return (
|
||||
<div>
|
||||
<Bookin />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -33,6 +33,7 @@ import { Route as ocmeCyclecountIndexImport } from './routes/(ocme)/cyclecount/i
|
||||
import { Route as logisticsSiloAdjustmentsIndexImport } from './routes/(logistics)/siloAdjustments/index'
|
||||
import { Route as logisticsOpenOrdersIndexImport } from './routes/(logistics)/openOrders/index'
|
||||
import { Route as logisticsMaterialHelperIndexImport } from './routes/(logistics)/materialHelper/index'
|
||||
import { Route as logisticsHelperCommandsIndexImport } from './routes/(logistics)/helperCommands/index'
|
||||
import { Route as logisticsDmIndexImport } from './routes/(logistics)/dm/index'
|
||||
import { Route as EomArticleAvImport } from './routes/_eom/article/$av'
|
||||
import { Route as logisticsSiloAdjustmentsHistImport } from './routes/(logistics)/siloAdjustments/$hist'
|
||||
@@ -173,6 +174,13 @@ const logisticsMaterialHelperIndexRoute =
|
||||
getParentRoute: () => rootRoute,
|
||||
} as any)
|
||||
|
||||
const logisticsHelperCommandsIndexRoute =
|
||||
logisticsHelperCommandsIndexImport.update({
|
||||
id: '/(logistics)/helperCommands/',
|
||||
path: '/helperCommands/',
|
||||
getParentRoute: () => rootRoute,
|
||||
} as any)
|
||||
|
||||
const logisticsDmIndexRoute = logisticsDmIndexImport.update({
|
||||
id: '/(logistics)/dm/',
|
||||
path: '/dm/',
|
||||
@@ -364,6 +372,13 @@ declare module '@tanstack/react-router' {
|
||||
preLoaderRoute: typeof logisticsDmIndexImport
|
||||
parentRoute: typeof rootRoute
|
||||
}
|
||||
'/(logistics)/helperCommands/': {
|
||||
id: '/(logistics)/helperCommands/'
|
||||
path: '/helperCommands'
|
||||
fullPath: '/helperCommands'
|
||||
preLoaderRoute: typeof logisticsHelperCommandsIndexImport
|
||||
parentRoute: typeof rootRoute
|
||||
}
|
||||
'/(logistics)/materialHelper/': {
|
||||
id: '/(logistics)/materialHelper/'
|
||||
path: '/materialHelper'
|
||||
@@ -480,6 +495,7 @@ export interface FileRoutesByFullPath {
|
||||
'/siloAdjustments/$hist': typeof logisticsSiloAdjustmentsHistRoute
|
||||
'/article/$av': typeof EomArticleAvRoute
|
||||
'/dm': typeof logisticsDmIndexRoute
|
||||
'/helperCommands': typeof logisticsHelperCommandsIndexRoute
|
||||
'/materialHelper': typeof logisticsMaterialHelperIndexRoute
|
||||
'/openOrders': typeof logisticsOpenOrdersIndexRoute
|
||||
'/siloAdjustments': typeof logisticsSiloAdjustmentsIndexRoute
|
||||
@@ -509,6 +525,7 @@ export interface FileRoutesByTo {
|
||||
'/siloAdjustments/$hist': typeof logisticsSiloAdjustmentsHistRoute
|
||||
'/article/$av': typeof EomArticleAvRoute
|
||||
'/dm': typeof logisticsDmIndexRoute
|
||||
'/helperCommands': typeof logisticsHelperCommandsIndexRoute
|
||||
'/materialHelper': typeof logisticsMaterialHelperIndexRoute
|
||||
'/openOrders': typeof logisticsOpenOrdersIndexRoute
|
||||
'/siloAdjustments': typeof logisticsSiloAdjustmentsIndexRoute
|
||||
@@ -541,6 +558,7 @@ export interface FileRoutesById {
|
||||
'/(logistics)/siloAdjustments/$hist': typeof logisticsSiloAdjustmentsHistRoute
|
||||
'/_eom/article/$av': typeof EomArticleAvRoute
|
||||
'/(logistics)/dm/': typeof logisticsDmIndexRoute
|
||||
'/(logistics)/helperCommands/': typeof logisticsHelperCommandsIndexRoute
|
||||
'/(logistics)/materialHelper/': typeof logisticsMaterialHelperIndexRoute
|
||||
'/(logistics)/openOrders/': typeof logisticsOpenOrdersIndexRoute
|
||||
'/(logistics)/siloAdjustments/': typeof logisticsSiloAdjustmentsIndexRoute
|
||||
@@ -572,6 +590,7 @@ export interface FileRouteTypes {
|
||||
| '/siloAdjustments/$hist'
|
||||
| '/article/$av'
|
||||
| '/dm'
|
||||
| '/helperCommands'
|
||||
| '/materialHelper'
|
||||
| '/openOrders'
|
||||
| '/siloAdjustments'
|
||||
@@ -600,6 +619,7 @@ export interface FileRouteTypes {
|
||||
| '/siloAdjustments/$hist'
|
||||
| '/article/$av'
|
||||
| '/dm'
|
||||
| '/helperCommands'
|
||||
| '/materialHelper'
|
||||
| '/openOrders'
|
||||
| '/siloAdjustments'
|
||||
@@ -630,6 +650,7 @@ export interface FileRouteTypes {
|
||||
| '/(logistics)/siloAdjustments/$hist'
|
||||
| '/_eom/article/$av'
|
||||
| '/(logistics)/dm/'
|
||||
| '/(logistics)/helperCommands/'
|
||||
| '/(logistics)/materialHelper/'
|
||||
| '/(logistics)/openOrders/'
|
||||
| '/(logistics)/siloAdjustments/'
|
||||
@@ -653,6 +674,7 @@ export interface RootRouteChildren {
|
||||
OcpIndexRoute: typeof OcpIndexRoute
|
||||
logisticsSiloAdjustmentsHistRoute: typeof logisticsSiloAdjustmentsHistRoute
|
||||
logisticsDmIndexRoute: typeof logisticsDmIndexRoute
|
||||
logisticsHelperCommandsIndexRoute: typeof logisticsHelperCommandsIndexRoute
|
||||
logisticsMaterialHelperIndexRoute: typeof logisticsMaterialHelperIndexRoute
|
||||
logisticsOpenOrdersIndexRoute: typeof logisticsOpenOrdersIndexRoute
|
||||
logisticsSiloAdjustmentsIndexRoute: typeof logisticsSiloAdjustmentsIndexRoute
|
||||
@@ -675,6 +697,7 @@ const rootRouteChildren: RootRouteChildren = {
|
||||
OcpIndexRoute: OcpIndexRoute,
|
||||
logisticsSiloAdjustmentsHistRoute: logisticsSiloAdjustmentsHistRoute,
|
||||
logisticsDmIndexRoute: logisticsDmIndexRoute,
|
||||
logisticsHelperCommandsIndexRoute: logisticsHelperCommandsIndexRoute,
|
||||
logisticsMaterialHelperIndexRoute: logisticsMaterialHelperIndexRoute,
|
||||
logisticsOpenOrdersIndexRoute: logisticsOpenOrdersIndexRoute,
|
||||
logisticsSiloAdjustmentsIndexRoute: logisticsSiloAdjustmentsIndexRoute,
|
||||
@@ -709,6 +732,7 @@ export const routeTree = rootRoute
|
||||
"/ocp/",
|
||||
"/(logistics)/siloAdjustments/$hist",
|
||||
"/(logistics)/dm/",
|
||||
"/(logistics)/helperCommands/",
|
||||
"/(logistics)/materialHelper/",
|
||||
"/(logistics)/openOrders/",
|
||||
"/(logistics)/siloAdjustments/",
|
||||
@@ -805,6 +829,9 @@ export const routeTree = rootRoute
|
||||
"/(logistics)/dm/": {
|
||||
"filePath": "(logistics)/dm/index.tsx"
|
||||
},
|
||||
"/(logistics)/helperCommands/": {
|
||||
"filePath": "(logistics)/helperCommands/index.tsx"
|
||||
},
|
||||
"/(logistics)/materialHelper/": {
|
||||
"filePath": "(logistics)/materialHelper/index.tsx"
|
||||
},
|
||||
|
||||
@@ -9,6 +9,7 @@ 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"
|
||||
@@ -33,7 +34,9 @@ export const bookInLabel = async (data: any) => {
|
||||
"error",
|
||||
"labeling",
|
||||
"ocp",
|
||||
`${data.printer[0].name}, Error:${res.data}`
|
||||
`${
|
||||
data.printer ? data.printer[0].name : "Manual book in"
|
||||
}, Error:${res.data}`
|
||||
);
|
||||
//printerUpdate(data.printer, 7, "Error while booking in.");
|
||||
|
||||
@@ -43,7 +46,6 @@ export const bookInLabel = async (data: any) => {
|
||||
data: res.data,
|
||||
};
|
||||
}
|
||||
|
||||
// update the label.
|
||||
try {
|
||||
const booked = await db
|
||||
@@ -61,7 +63,7 @@ export const bookInLabel = async (data: any) => {
|
||||
"info",
|
||||
"labeling",
|
||||
"ocp",
|
||||
`${booked[0].runningNr} , was just booked in.`
|
||||
`${parseInt(data.SSCC.slice(10, -1))} , was just booked in.`
|
||||
);
|
||||
|
||||
return {
|
||||
@@ -72,24 +74,35 @@ export const bookInLabel = async (data: any) => {
|
||||
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) {
|
||||
} catch (error: any) {
|
||||
createLog(
|
||||
"error",
|
||||
"labeling",
|
||||
"ocp",
|
||||
`${data.printer[0].name}, "Error: ${error}`
|
||||
`${
|
||||
data.printer ? data.printer[0].name : "Manual book in"
|
||||
}, "Error: ${error}`
|
||||
);
|
||||
// console.log(error.response.data);
|
||||
return {
|
||||
success: false,
|
||||
message: "There was an error booking in the label.",
|
||||
data: error,
|
||||
data: error.response.data,
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
57
server/services/ocp/routes/labeling/bookIn.ts
Normal file
57
server/services/ocp/routes/labeling/bookIn.ts
Normal file
@@ -0,0 +1,57 @@
|
||||
// an external way to creating logs
|
||||
import { createRoute, OpenAPIHono, z } from "@hono/zod-openapi";
|
||||
import { responses } from "../../../../globalUtils/routeDefs/responses.js";
|
||||
import { tryCatch } from "../../../../globalUtils/tryCatch.js";
|
||||
import { labelingProcess } from "../../controller/labeling/labelProcess.js";
|
||||
import { bookInLabel } from "../../controller/labeling/bookIn.js";
|
||||
import { createSSCC } from "../../../../globalUtils/createSSCC.js";
|
||||
|
||||
const app = new OpenAPIHono({ strict: false });
|
||||
|
||||
app.openapi(
|
||||
createRoute({
|
||||
tags: ["ocp"],
|
||||
summary: "Manual bookin by running Number",
|
||||
method: "post",
|
||||
path: "/bookin",
|
||||
responses: responses(),
|
||||
}),
|
||||
async (c) => {
|
||||
//const hours = c.req.query("hours");
|
||||
const { data: bodyData, error: bodyError } = await tryCatch(
|
||||
c.req.json()
|
||||
);
|
||||
|
||||
if (bodyError) {
|
||||
return c.json({
|
||||
success: false,
|
||||
message: "You are missing data",
|
||||
});
|
||||
}
|
||||
|
||||
// get the sscc number
|
||||
const sscc = await createSSCC(bodyData.runningNr);
|
||||
|
||||
const { data: bookinLabel, error: bookInError } = await tryCatch(
|
||||
bookInLabel({ SSCC: sscc })
|
||||
);
|
||||
|
||||
if (bookInError) {
|
||||
return c.json({
|
||||
success: false,
|
||||
message: "There was an error booking in the label.",
|
||||
data: bookInError,
|
||||
});
|
||||
}
|
||||
|
||||
const newLabel: any = bookinLabel;
|
||||
//console.log(newLabel);
|
||||
|
||||
return c.json({
|
||||
success: newLabel.success,
|
||||
message: newLabel.message,
|
||||
data: newLabel.data,
|
||||
});
|
||||
}
|
||||
);
|
||||
export default app;
|
||||
Reference in New Issue
Block a user