migration #51
@@ -1,26 +1,30 @@
|
|||||||
import {LstCard} from "@/components/extendedUI/LstCard";
|
import { LstCard } from "@/components/extendedUI/LstCard";
|
||||||
import {Button} from "@/components/ui/button";
|
import { Button } from "@/components/ui/button";
|
||||||
import {CardHeader} from "@/components/ui/card";
|
import { CardHeader } from "@/components/ui/card";
|
||||||
import {Input} from "@/components/ui/input";
|
import { Input } from "@/components/ui/input";
|
||||||
import {Label} from "@/components/ui/label";
|
import { Label } from "@/components/ui/label";
|
||||||
import {useSessionStore} from "@/lib/store/sessionStore";
|
|
||||||
import axios from "axios";
|
|
||||||
import {useState} from "react";
|
|
||||||
|
|
||||||
import {useForm} from "react-hook-form";
|
import axios from "axios";
|
||||||
import {toast} from "sonner";
|
import { useState } from "react";
|
||||||
|
|
||||||
|
import { useForm } from "react-hook-form";
|
||||||
|
import { toast } from "sonner";
|
||||||
|
|
||||||
export default function ConsumeMaterial() {
|
export default function ConsumeMaterial() {
|
||||||
const {register: register1, handleSubmit: handleSubmit1, reset} = useForm();
|
const {
|
||||||
|
register: register1,
|
||||||
|
handleSubmit: handleSubmit1,
|
||||||
|
reset,
|
||||||
|
} = useForm();
|
||||||
const [submitting, setSubmitting] = useState(false);
|
const [submitting, setSubmitting] = useState(false);
|
||||||
const {token} = useSessionStore();
|
|
||||||
|
|
||||||
const handleConsume = async (data: any) => {
|
const handleConsume = async (data: any) => {
|
||||||
setSubmitting(true);
|
setSubmitting(true);
|
||||||
try {
|
try {
|
||||||
const result = await axios.post(`/api/logistics/consume`, data, {
|
// const result = await axios.post(`/api/logistics/consume`, data, {
|
||||||
headers: {Authorization: `Bearer ${token}`},
|
// headers: {Authorization: `Bearer ${token}`},
|
||||||
});
|
// });
|
||||||
|
const result = await axios.post(`/api/logistics/consume`, data);
|
||||||
if (result.data.success) {
|
if (result.data.success) {
|
||||||
toast.success(result.data.message);
|
toast.success(result.data.message);
|
||||||
setSubmitting(false);
|
setSubmitting(false);
|
||||||
@@ -33,12 +37,14 @@ export default function ConsumeMaterial() {
|
|||||||
toast.error(result.data.message);
|
toast.error(result.data.message);
|
||||||
}
|
}
|
||||||
} catch (error: any) {
|
} catch (error: any) {
|
||||||
//console.log(error);
|
console.log(error);
|
||||||
setSubmitting(false);
|
setSubmitting(false);
|
||||||
if (error.status === 401) {
|
if (error.status === 401) {
|
||||||
toast.error("Unauthorized to do this task.");
|
toast.error("Unauthorized to do this task.");
|
||||||
} else {
|
} else {
|
||||||
toast.error("Unexpected error if this continues please constact an admin.");
|
toast.error(
|
||||||
|
"Unexpected error if this continues please constact an admin."
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -53,7 +59,9 @@ export default function ConsumeMaterial() {
|
|||||||
<LstCard>
|
<LstCard>
|
||||||
<form onSubmit={handleSubmit1(handleConsume)}>
|
<form onSubmit={handleSubmit1(handleConsume)}>
|
||||||
<div className="m-2">
|
<div className="m-2">
|
||||||
<Label htmlFor="runningNr">Enter unit running number</Label>
|
<Label htmlFor="runningNr">
|
||||||
|
Enter unit running number
|
||||||
|
</Label>
|
||||||
<Input
|
<Input
|
||||||
className="mt-2"
|
className="mt-2"
|
||||||
//defaultValue="634"
|
//defaultValue="634"
|
||||||
@@ -62,7 +70,9 @@ export default function ConsumeMaterial() {
|
|||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
<div className="m-2">
|
<div className="m-2">
|
||||||
<Label htmlFor="lotNum">Enter lot number</Label>
|
<Label htmlFor="lotNum">
|
||||||
|
Enter lot number
|
||||||
|
</Label>
|
||||||
<Input
|
<Input
|
||||||
className="mt-2"
|
className="mt-2"
|
||||||
//defaultValue="634"
|
//defaultValue="634"
|
||||||
@@ -71,7 +81,12 @@ export default function ConsumeMaterial() {
|
|||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<Button className="m-2" color="primary" type="submit" disabled={submitting}>
|
<Button
|
||||||
|
className="m-2"
|
||||||
|
color="primary"
|
||||||
|
type="submit"
|
||||||
|
disabled={submitting}
|
||||||
|
>
|
||||||
Consume materal
|
Consume materal
|
||||||
</Button>
|
</Button>
|
||||||
</form>
|
</form>
|
||||||
@@ -81,12 +96,19 @@ export default function ConsumeMaterial() {
|
|||||||
<LstCard>
|
<LstCard>
|
||||||
<div className="w-96 p-1">
|
<div className="w-96 p-1">
|
||||||
<ol>
|
<ol>
|
||||||
<li>1. Enter the running number of the material you would like to consume</li>
|
<li>
|
||||||
<li>2. Enter the lot number you will be consuming to</li>
|
1. Enter the running number of the
|
||||||
|
material you would like to consume
|
||||||
|
</li>
|
||||||
|
<li>
|
||||||
|
2. Enter the lot number you will be
|
||||||
|
consuming to
|
||||||
|
</li>
|
||||||
<li>3. Press consume material</li>
|
<li>3. Press consume material</li>
|
||||||
</ol>
|
</ol>
|
||||||
<p className="text-pretty w-96">
|
<p className="text-pretty w-96">
|
||||||
*This process is only for barcoded material, if it is set to auto consume you will
|
*This process is only for barcoded material,
|
||||||
|
if it is set to auto consume you will
|
||||||
encounter and error.
|
encounter and error.
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ type Data = {
|
|||||||
runningNr: string;
|
runningNr: string;
|
||||||
lotNum: number;
|
lotNum: number;
|
||||||
};
|
};
|
||||||
export const consumeMaterial = async (data: Data, prod: any) => {
|
export const consumeMaterial = async (data: Data) => {
|
||||||
const { runningNr, lotNum } = data;
|
const { runningNr, lotNum } = data;
|
||||||
// replace the rn
|
// replace the rn
|
||||||
|
|
||||||
@@ -28,12 +28,7 @@ export const consumeMaterial = async (data: Data, prod: any) => {
|
|||||||
barcode = r?.data;
|
barcode = r?.data;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.log(error);
|
console.log(error);
|
||||||
createLog(
|
createLog("error", "", "logistics", `Error getting barcode: ${error}`);
|
||||||
"error",
|
|
||||||
prod.user.username,
|
|
||||||
"logistics",
|
|
||||||
`Error getting barcode: ${error}`
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (barcode.length === 0) {
|
if (barcode.length === 0) {
|
||||||
|
|||||||
@@ -51,33 +51,29 @@ app.openapi(
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
apiHit(c, { endpoint: "/consume", lastBody: data });
|
apiHit(c, { endpoint: "/consume", lastBody: data });
|
||||||
const authHeader = c.req.header("Authorization");
|
//const authHeader = c.req.header("Authorization");
|
||||||
const token = authHeader?.split("Bearer ")[1] || "";
|
//const token = authHeader?.split("Bearer ")[1] || "";
|
||||||
|
|
||||||
|
//const payload = await verify(token, process.env.JWT_SECRET!);
|
||||||
try {
|
try {
|
||||||
const payload = await verify(token, process.env.JWT_SECRET!);
|
//return apiReturn(c, true, access?.message, access?.data, 200);
|
||||||
try {
|
|
||||||
//return apiReturn(c, true, access?.message, access?.data, 200);
|
|
||||||
|
|
||||||
const consume = await consumeMaterial(data, payload);
|
const consume = await consumeMaterial(data);
|
||||||
return c.json(
|
return c.json(
|
||||||
{ success: consume?.success, message: consume?.message },
|
{ success: consume?.success, message: consume?.message },
|
||||||
200
|
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
|
|
||||||
);
|
|
||||||
}
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
return c.json({ success: false, message: "Unauthorized" }, 401);
|
//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
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|||||||
Reference in New Issue
Block a user