diff --git a/frontend/src/components/layout/side-components/logistics.tsx b/frontend/src/components/layout/side-components/logistics.tsx index 924429a..e8e1608 100644 --- a/frontend/src/components/layout/side-components/logistics.tsx +++ b/frontend/src/components/layout/side-components/logistics.tsx @@ -82,7 +82,7 @@ export function LogisticsSideBar({ const { subModules } = useSubModuleStore(); const items = subModules.filter((m) => m.moduleName === "logistics"); - console.log(items); + //console.log(items); return ( Logistics diff --git a/frontend/src/components/logistics/siloAdjustments/SiloCard.tsx b/frontend/src/components/logistics/siloAdjustments/SiloCard.tsx new file mode 100644 index 0000000..83cff80 --- /dev/null +++ b/frontend/src/components/logistics/siloAdjustments/SiloCard.tsx @@ -0,0 +1,14 @@ +import { LstCard } from "@/components/extendedUI/LstCard"; +import { CardHeader } from "@/components/ui/card"; + +export default function SiloCard(data: any) { + const silo = data.silo; + return ( + + {silo.Description} +
+
+
+
+ ); +} diff --git a/frontend/src/components/logistics/siloAdjustments/SiloPage.tsx b/frontend/src/components/logistics/siloAdjustments/SiloPage.tsx new file mode 100644 index 0000000..09ad19e --- /dev/null +++ b/frontend/src/components/logistics/siloAdjustments/SiloPage.tsx @@ -0,0 +1,26 @@ +import { getStockSilo } from "@/utils/querys/logistics/siloAdjustments/getStockSilo"; +import { useQuery } from "@tanstack/react-query"; +import SiloCard from "./SiloCard"; + +export default function SiloPage() { + const { data, isError, error, isLoading } = useQuery(getStockSilo()); + + if (isLoading) return; + + if (isError) return; + + if (error) + return ( +
+ {" "} + There was an error getting the silos please notify your admin if + this continues to be an issue +
+ ); + + return ( +
+ {data?.map((s: any) => )} +
+ ); +} diff --git a/frontend/src/routes/(logistics)/siloAdjustments/index.tsx b/frontend/src/routes/(logistics)/siloAdjustments/index.tsx index bed2f05..191cf14 100644 --- a/frontend/src/routes/(logistics)/siloAdjustments/index.tsx +++ b/frontend/src/routes/(logistics)/siloAdjustments/index.tsx @@ -1,9 +1,28 @@ -import { createFileRoute } from '@tanstack/react-router' +import SiloPage from "@/components/logistics/siloAdjustments/SiloPage"; +import { createFileRoute, redirect } from "@tanstack/react-router"; -export const Route = createFileRoute('/(logistics)/siloAdjustments/')({ - component: RouteComponent, -}) +export const Route = createFileRoute("/(logistics)/siloAdjustments/")({ + component: RouteComponent, + beforeLoad: async () => { + const auth = localStorage.getItem("auth_token"); + if (!auth) { + throw redirect({ + to: "/login", + search: { + // Use the current location to power a redirect after login + // (Do not use `router.state.resolvedLocation` as it can + // potentially lag behind the actual current location) + redirect: location.pathname + location.search, + }, + }); + } + }, +}); function RouteComponent() { - return
Hello "/(logistics)/siloAdjustments/"!
+ return ( +
+ +
+ ); } diff --git a/frontend/src/utils/querys/logistics/siloAdjustments/getStockSilo.tsx b/frontend/src/utils/querys/logistics/siloAdjustments/getStockSilo.tsx new file mode 100644 index 0000000..6cd43b2 --- /dev/null +++ b/frontend/src/utils/querys/logistics/siloAdjustments/getStockSilo.tsx @@ -0,0 +1,26 @@ +import { queryOptions } from "@tanstack/react-query"; +import axios from "axios"; + +export function getStockSilo() { + const token = localStorage.getItem("auth_token"); + return queryOptions({ + queryKey: ["getUsers"], + queryFn: () => fetchStockSilo(token), + enabled: !!token, // Prevents query if token is null + staleTime: 1000, + //refetchInterval: 2 * 2000, + refetchOnWindowFocus: true, + }); +} + +const fetchStockSilo = async (token: string | null) => { + const { data } = await axios.get(`/api/logistics/getstocksilo`, { + headers: { + "Content-Type": "application/json", + Authorization: `Bearer ${token}`, + }, + }); + // if we are not localhost ignore the devDir setting. + //const url: string = window.location.host.split(":")[0]; + return data.data ?? []; +}; diff --git a/server/scripts/zipUpBuild.ts b/server/scripts/zipUpBuild.ts index fa6e7d8..00e2ec7 100644 --- a/server/scripts/zipUpBuild.ts +++ b/server/scripts/zipUpBuild.ts @@ -35,6 +35,8 @@ const ignoreList = [ "frontend/tsconfig.node.json", "frontend/vite.config.ts", "frontend/components.json", + //misc files + "jsTesting", ]; const shouldIgnore = (itemPath: any) => { diff --git a/server/services/logistics/controller/siloAdjustments/getCurrentStockSiloData.ts b/server/services/logistics/controller/siloAdjustments/getCurrentStockSiloData.ts new file mode 100644 index 0000000..775ca17 --- /dev/null +++ b/server/services/logistics/controller/siloAdjustments/getCurrentStockSiloData.ts @@ -0,0 +1,24 @@ +import { tryCatch } from "../../../../globalUtils/tryCatch.js"; +import { query } from "../../../sqlServer/prodSqlServer.js"; +import { siloQuery } from "../../../sqlServer/querys/silo/siloQuery.js"; + +export const getStockSiloData = async () => { + /** + * will return the current stock info where the silo is checked + */ + + const { data, error } = await tryCatch(query(siloQuery, "Get silo data")); + + if (error) { + return { + success: false, + message: "There was a n error getting the silo data.", + }; + } + + return { + success: true, + message: "Current silo data from alplastock.", + data: data, + }; +}; diff --git a/server/services/logistics/route/siloAdjustments/getStockData.ts b/server/services/logistics/route/siloAdjustments/getStockData.ts new file mode 100644 index 0000000..1a8ae86 --- /dev/null +++ b/server/services/logistics/route/siloAdjustments/getStockData.ts @@ -0,0 +1,50 @@ +import { createRoute, OpenAPIHono, z } from "@hono/zod-openapi"; +import { authMiddleware } from "../../../auth/middleware/authMiddleware.js"; +import { responses } from "../../../../globalUtils/routeDefs/responses.js"; +import { getStockSiloData } from "../../controller/siloAdjustments/getCurrentStockSiloData.js"; + +const app = new OpenAPIHono(); + +app.openapi( + createRoute({ + tags: ["logistics"], + summary: "Returns current stock levels for silos", + method: "get", + path: "/getstocksilo", + middleware: authMiddleware, + // request: { + // params: ParamsSchema, + // body: { content: { "application/json": { schema: Body } } }, + // }, + // description: + // "Creates a silo adjustment for the silo if and stores the stock numbers.", + responses: responses(), + }), + async (c) => { + //apiHit(c, { endpoint: "api/sqlProd/close" }); + + try { + //return apiReturn(c, true, access?.message, access?.data, 200); + + const silo = await getStockSiloData(); + return c.json( + { + success: silo.success, + message: silo.message, + data: silo.data, + }, + 200 + ); + } catch (error) { + return c.json( + { + success: false, + message: "Missing data please try again", + error, + }, + 400 + ); + } + } +); +export default app; diff --git a/server/services/notifications/utils/views/siloAdjustmentComment.hbs b/server/services/notifications/utils/views/siloAdjustmentComment.hbs index 89fae5f..11f79f7 100644 --- a/server/services/notifications/utils/views/siloAdjustmentComment.hbs +++ b/server/services/notifications/utils/views/siloAdjustmentComment.hbs @@ -29,7 +29,7 @@ Please add your comment as to why the variance greater than {{variancePer}}

- Add a Comment

diff --git a/server/services/sqlServer/querys/silo/siloQuery.ts b/server/services/sqlServer/querys/silo/siloQuery.ts index f482366..d219810 100644 --- a/server/services/sqlServer/querys/silo/siloQuery.ts +++ b/server/services/sqlServer/querys/silo/siloQuery.ts @@ -3,10 +3,10 @@ SELECT V_LagerAbteilungen.Bezeichnung AS Description, V_LagerAbteilungen.IdWarenLager AS WarehouseID, V_LagerAbteilungen.IdLagerAbteilung AS LocationID, - ROUND(SUM(einlagerungsmengesum), 2) AS Stock_Total, - COALESCE(LastAdjustment, '1900-01-01') AS LastAdjustment + case when ROUND(SUM(einlagerungsmengesum), 2) is null then 0 else ROUND(SUM(einlagerungsmengesum), 2) end AS Stock_Total + ,case when ROUND(SUM(einlagerungsmengesum), 2) is null then COALESCE(b.upd_Date, '1900-01-01') else COALESCE(LastAdjustment, '1900-01-01') end AS LastAdjustment FROM AlplaPROD_test1.dbo.V_LagerAbteilungen (NOLOCK) - JOIN + left JOIN AlplaPROD_test1.dbo.V_LagerPositionenBarcodes ON AlplaPROD_test1.dbo.V_LagerAbteilungen.IdLagerAbteilung = AlplaPROD_test1.dbo.V_LagerPositionenBarcodes.IdLagerAbteilung @@ -18,9 +18,15 @@ SELECT WHERE urheber = 2900 GROUP BY IdLagerAbteilung ) AS LastAdj ON AlplaPROD_test1.dbo.V_LagerAbteilungen.IdLagerAbteilung = LastAdj.IdLagerAbteilung + + /* add the actual inventory now that we will display an empty silo and need to add this date */ + left join + AlplaPROD_test1.dbo.V_LagerAbteilungenInventuren as b on + AlplaPROD_test1.dbo.V_LagerAbteilungen.IdLagerAbteilung = b.IdLagerAbteilung + WHERE materialsilo = 1 AND aktiv = 1 - GROUP BY V_LagerAbteilungen.Bezeichnung, V_LagerAbteilungen.IdWarenLager, V_LagerAbteilungen.IdLagerAbteilung, LastAdjustment + GROUP BY V_LagerAbteilungen.Bezeichnung, V_LagerAbteilungen.IdWarenLager, V_LagerAbteilungen.IdLagerAbteilung, LastAdjustment, b.upd_Date ORDER BY V_LagerAbteilungen.Bezeichnung `;