feat(silo): adjustments completed :D
This commit is contained in:
@@ -1,14 +1,181 @@
|
||||
import { LstCard } from "@/components/extendedUI/LstCard";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { CardHeader } from "@/components/ui/card";
|
||||
import { Input } from "@/components/ui/input";
|
||||
import { Label } from "@/components/ui/label";
|
||||
import {
|
||||
Tooltip,
|
||||
TooltipContent,
|
||||
TooltipProvider,
|
||||
TooltipTrigger,
|
||||
} from "@/components/ui/tooltip";
|
||||
import { getStockSilo } from "@/utils/querys/logistics/siloAdjustments/getStockSilo";
|
||||
import { useForm } from "@tanstack/react-form";
|
||||
import { useQuery } from "@tanstack/react-query";
|
||||
import axios from "axios";
|
||||
import { format } from "date-fns";
|
||||
import { CircleAlert } from "lucide-react";
|
||||
import { useState } from "react";
|
||||
import { toast } from "sonner";
|
||||
|
||||
export default function SiloCard(data: any) {
|
||||
const token = localStorage.getItem("auth_token");
|
||||
const [submitting, setSubmitting] = useState(false);
|
||||
const { refetch } = useQuery(getStockSilo());
|
||||
const silo = data.silo;
|
||||
|
||||
const form = useForm({
|
||||
defaultValues: {
|
||||
newLevel: "",
|
||||
},
|
||||
onSubmit: async ({ value }) => {
|
||||
setSubmitting(true);
|
||||
const dataToSubmit = {
|
||||
quantity: parseFloat(value.newLevel),
|
||||
warehouseId: silo.WarehouseID,
|
||||
laneId: silo.LocationID,
|
||||
};
|
||||
|
||||
try {
|
||||
const res = await axios.post(
|
||||
"/api/logistics/createsiloadjustment",
|
||||
dataToSubmit,
|
||||
{ headers: { Authorization: `Bearer ${token}` } }
|
||||
);
|
||||
console.log(res.data);
|
||||
|
||||
if (res.data.success) {
|
||||
toast.success(res.data.message);
|
||||
refetch();
|
||||
form.reset();
|
||||
}
|
||||
if (!res.data.success && res.data.data?.status === 400) {
|
||||
if (res.data.data.status === 400) {
|
||||
toast.error(res.data.data.data.errors[0].message);
|
||||
}
|
||||
} else if (!res.data.success) {
|
||||
toast.error(res.data.message);
|
||||
}
|
||||
setSubmitting(false);
|
||||
} catch (error: any) {
|
||||
//console.log(error);
|
||||
if (error.status === 401) {
|
||||
toast.error(error.response.statusText);
|
||||
setSubmitting(false);
|
||||
}
|
||||
}
|
||||
},
|
||||
});
|
||||
return (
|
||||
<LstCard>
|
||||
<CardHeader>{silo.Description}</CardHeader>
|
||||
<div>
|
||||
<hr />
|
||||
<div className="flex flex-row">
|
||||
<LstCard className="grow m-1 max-w-[400px]">
|
||||
<CardHeader>{silo.Description}</CardHeader>
|
||||
<div className="m-1">
|
||||
<hr className="m-2" />
|
||||
<span>Current Stock: </span>
|
||||
{silo.Stock_Total}
|
||||
<hr className="m-2" />
|
||||
<span>Last date adjusted </span>
|
||||
{format(silo.LastAdjustment, "M/dd/yyyy")}
|
||||
<hr className="m-2" />
|
||||
</div>
|
||||
<div>
|
||||
<form
|
||||
onSubmit={(e) => {
|
||||
e.preventDefault();
|
||||
e.stopPropagation();
|
||||
}}
|
||||
>
|
||||
<form.Field
|
||||
name="newLevel"
|
||||
validators={{
|
||||
// We can choose between form-wide and field-specific validators
|
||||
onChange: ({ value }) =>
|
||||
value.length > 1
|
||||
? undefined
|
||||
: "You must enter a value greate than 1",
|
||||
}}
|
||||
children={(field) => {
|
||||
return (
|
||||
<div className="m-2 min-w-48 max-w-96 p-2">
|
||||
<div className="flex flex-row">
|
||||
<Label htmlFor="newLevel">
|
||||
New level
|
||||
</Label>
|
||||
<div>
|
||||
<Disclaimer />
|
||||
</div>
|
||||
</div>
|
||||
<div className="flex flex-row">
|
||||
<Input
|
||||
name={field.name}
|
||||
value={field.state.value}
|
||||
onBlur={field.handleBlur}
|
||||
type="decimal"
|
||||
onChange={(e) =>
|
||||
field.handleChange(
|
||||
e.target.value
|
||||
)
|
||||
}
|
||||
/>
|
||||
<Button
|
||||
className="ml-1"
|
||||
type="submit"
|
||||
onClick={form.handleSubmit}
|
||||
disabled={submitting}
|
||||
>
|
||||
{submitting ? (
|
||||
<span className="w-24">
|
||||
Submitting...
|
||||
</span>
|
||||
) : (
|
||||
<span className="w-24">
|
||||
Submit
|
||||
</span>
|
||||
)}
|
||||
</Button>
|
||||
</div>
|
||||
|
||||
{field.state.meta.errors.length ? (
|
||||
<em>
|
||||
{field.state.meta.errors.join(
|
||||
","
|
||||
)}
|
||||
</em>
|
||||
) : null}
|
||||
</div>
|
||||
);
|
||||
}}
|
||||
/>
|
||||
</form>
|
||||
</div>
|
||||
</LstCard>
|
||||
<div className="grow max-w-[400px]">
|
||||
<LstCard className="m-1 ">charts go here</LstCard>
|
||||
<LstCard className="m-1">extra options here</LstCard>
|
||||
</div>
|
||||
</div>
|
||||
</LstCard>
|
||||
);
|
||||
}
|
||||
|
||||
const Disclaimer = () => {
|
||||
return (
|
||||
<TooltipProvider>
|
||||
<Tooltip>
|
||||
<TooltipTrigger asChild>
|
||||
<CircleAlert className="ml-1 w-[14px]" />
|
||||
</TooltipTrigger>
|
||||
<TooltipContent className="max-w-48">
|
||||
<p className="text-pretty">
|
||||
If you have had this page open for a period of time
|
||||
before submitting your data, there is a chance that the
|
||||
stock levels will be different from the ones you see
|
||||
above
|
||||
</p>
|
||||
</TooltipContent>
|
||||
</Tooltip>
|
||||
</TooltipProvider>
|
||||
);
|
||||
};
|
||||
|
||||
@@ -19,8 +19,12 @@ export default function SiloPage() {
|
||||
);
|
||||
|
||||
return (
|
||||
<div className="flex flex-row gap-2">
|
||||
{data?.map((s: any) => <SiloCard silo={s} />)}
|
||||
<div className="flex flex-wrap">
|
||||
{data?.map((s: any) => (
|
||||
<div key={s.LocationID} className="grow m-2 max-w-[800px]">
|
||||
<SiloCard silo={s} />
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -58,6 +58,17 @@ export const createSiloAdjustment = async (
|
||||
* Checking to see the difference, and send email if +/- 5% will change later if needed
|
||||
*/
|
||||
|
||||
const sa: any = a;
|
||||
|
||||
if (!sa.success) {
|
||||
console.log(`insde error`);
|
||||
return {
|
||||
success: sa.success,
|
||||
message: sa.message,
|
||||
data: sa.data,
|
||||
};
|
||||
}
|
||||
|
||||
const stockNummy = stock.filter((s: any) => s.LocationID === data.laneId);
|
||||
const theDiff =
|
||||
((data.quantity - stockNummy[0].Stock_Total) /
|
||||
@@ -91,7 +102,7 @@ export const createSiloAdjustment = async (
|
||||
data: postAdjError,
|
||||
};
|
||||
}
|
||||
|
||||
let adj: any = a;
|
||||
if (Math.abs(theDiff) > 5) {
|
||||
// console.log(`Send for comment due to being: ${theDiff.toFixed(2)}%`);
|
||||
const server = set.filter((n: any) => n.name === "server");
|
||||
@@ -123,8 +134,14 @@ export const createSiloAdjustment = async (
|
||||
//console.log(emailSetup);
|
||||
|
||||
await sendEmail(emailSetup);
|
||||
return {
|
||||
success: adj.success,
|
||||
message: `Silo adjustmnet was completed you will also receive and email due to the adjustment having a variation of ${Math.abs(
|
||||
theDiff
|
||||
).toFixed(2)}%`,
|
||||
data: adj.data,
|
||||
};
|
||||
} else {
|
||||
return { success: adj.success, message: adj.message, data: adj.data };
|
||||
}
|
||||
|
||||
let adj: any = a;
|
||||
return { success: adj.success, message: adj.message, data: adj.data };
|
||||
};
|
||||
|
||||
@@ -45,22 +45,45 @@ export const postAdjustment = async (data: any, prod: any) => {
|
||||
})
|
||||
);
|
||||
let e = error as any;
|
||||
if (error) {
|
||||
return {
|
||||
success: false,
|
||||
message: "Error in posting the silo adjustment.",
|
||||
data: {
|
||||
status: e.response?.status,
|
||||
statusText: e.response?.statusText,
|
||||
data: e.response?.data,
|
||||
},
|
||||
};
|
||||
if (e) {
|
||||
if (e.status === 401) {
|
||||
const data = {
|
||||
success: false,
|
||||
message: "Incorrect alpla prod password.",
|
||||
data: {
|
||||
status: e.response?.status,
|
||||
statusText: e.response?.statusText,
|
||||
data: e.response?.data,
|
||||
},
|
||||
};
|
||||
return data;
|
||||
} else {
|
||||
return {
|
||||
success: false,
|
||||
message: "Error in posting the silo adjustment.",
|
||||
data: {
|
||||
status: e.response?.status,
|
||||
statusText: e.response?.statusText,
|
||||
data: e.response?.data,
|
||||
},
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
if (silo.status !== 200) {
|
||||
if (silo?.status !== 200) {
|
||||
return {
|
||||
success: false,
|
||||
message: "Error in posting the silo adjustment",
|
||||
data: {
|
||||
status: silo?.status,
|
||||
statusText: silo?.statusText,
|
||||
data: silo?.data,
|
||||
},
|
||||
};
|
||||
} else {
|
||||
return {
|
||||
success: true,
|
||||
message: "Adjustment was completed",
|
||||
data: {
|
||||
status: silo.status,
|
||||
statusText: silo.statusText,
|
||||
@@ -68,14 +91,4 @@ export const postAdjustment = async (data: any, prod: any) => {
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
success: true,
|
||||
message: "Adjustment was completed",
|
||||
data: {
|
||||
status: silo.status,
|
||||
statusText: silo.statusText,
|
||||
data: silo.data,
|
||||
},
|
||||
};
|
||||
};
|
||||
|
||||
@@ -36,6 +36,7 @@ app.openapi(
|
||||
data,
|
||||
payload.user
|
||||
);
|
||||
|
||||
return c.json(
|
||||
{
|
||||
success: createSiloAdj.success,
|
||||
|
||||
Reference in New Issue
Block a user