From 74bcd6e805c34e181f0c48310a799daf3afaee66 Mon Sep 17 00:00:00 2001 From: Blake Matthes Date: Thu, 20 Mar 2025 14:02:19 -0500 Subject: [PATCH] feat(ocme): cycle count implemeneted --- .../src/components/ocme/CycleCountLog.tsx | 23 ++ .../src/components/ocme/ocmeCycleCount.tsx | 184 ++++++++--- server/services/ocme/controller/cycleCount.ts | 8 +- .../cycleCount/fullLaneCycleCount.ts | 126 ++++++++ .../controller/cycleCount/ocmeInventory.ts | 288 +----------------- .../services/ocmeServer/routes/getLaneData.ts | 9 +- 6 files changed, 316 insertions(+), 322 deletions(-) diff --git a/frontend/src/components/ocme/CycleCountLog.tsx b/frontend/src/components/ocme/CycleCountLog.tsx index 9bc0e4b..2df884d 100644 --- a/frontend/src/components/ocme/CycleCountLog.tsx +++ b/frontend/src/components/ocme/CycleCountLog.tsx @@ -1,8 +1,30 @@ +import {useEffect, useState} from "react"; import {LstCard} from "../extendedUI/LstCard"; import {CardContent, CardHeader} from "../ui/card"; import {Skeleton} from "../ui/skeleton"; +import {Button} from "../ui/button"; export default function CycleCountLog() { + const [logs, setLogs] = useState([]); + const [streaming, setStreaming] = useState(false); // Track if streaming is active + + useEffect(() => { + // Start streaming when the button is clicked + let es; + + es = new EventSource("http://localhost:4000/api/logger/logs/stream?service=ocme-count&level=info"); + es.onopen = () => console.log(">>> Connection opened!"); + es.onerror = (e) => console.log("ERROR!", e); + es.onmessage = (e) => { + console.log(">>>", JSON.stringify(e)); + }; + + return () => es.close(); + }, []); // Effect runs when `streaming` state changes + + const handleStartStreaming = () => { + setStreaming(true); // Start streaming when button is clicked + }; return ( @@ -17,6 +39,7 @@ export default function CycleCountLog() { ))} + ); } diff --git a/frontend/src/components/ocme/ocmeCycleCount.tsx b/frontend/src/components/ocme/ocmeCycleCount.tsx index 7c0f65a..0990c85 100644 --- a/frontend/src/components/ocme/ocmeCycleCount.tsx +++ b/frontend/src/components/ocme/ocmeCycleCount.tsx @@ -5,20 +5,88 @@ import {Input} from "../ui/input"; import {Table, TableBody, TableCell, TableHead, TableHeader, TableRow} from "../ui/table"; import {Skeleton} from "../ui/skeleton"; import CycleCountLog from "./CycleCountLog"; +import {Select, SelectContent, SelectItem, SelectTrigger, SelectValue} from "../ui/select"; +import {Controller, useForm} from "react-hook-form"; +import axios from "axios"; +import {useState} from "react"; export default function OcmeCycleCount() { + const token = localStorage.getItem("auth_token"); + const [data, setData] = useState([]); + const [counting, setCounting] = useState(false); + const { + register, + handleSubmit, + //watch, + formState: {errors}, + reset, + control, + } = useForm(); + + const onSubmit = async (data: any) => { + setData([]); + setCounting(true); + toast.success(`Cycle count started`); + try { + const res = await axios.post("/ocme/api/v1/cyclecount", data, { + headers: {Authorization: `Bearer ${token}`}, + }); + toast.success(res.data.message); + setData(res.data.data); + setCounting(false); + reset(); + } catch (error) { + toast.error("There was an error cycle counting"); + setCounting(false); + reset(); + } + }; return ( -
+
+

Please enter the name or laneID you want to cycle count.

-
+
-
- +
+ +
+ ( + + )} + /> +
-
@@ -37,45 +105,81 @@ export default function OcmeCycleCount() { Result - - {Array(10) - .fill(0) - .map((_, i) => ( - - - - - - - - - - - - - - - - - - - - - - - - - - - ))} - + {data.length === 0 ? ( + + {Array(10) + .fill(0) + .map((_, i) => ( + + + + + + + + + + + + + + + + + + + + + + + + + + + ))} + + ) : ( + <> + {data.map((i: any) => { + let classname = ``; + if (i.info === "Quality Check Required") { + classname = `bg-red-500`; + } + if (i.info === "Sent to Inv") { + classname = `bg-amber-700`; + } + return ( + + + {i.alpla_laneID} + + + {i.alpla_laneDescription} + + + {i.Article} + + + {i.alpla_laneDescription} + + + {i.runningNumber} + + {i.ocme} + {i.stock} + {i.info} + + ); + })} + + )}
-
+ {/*
-
+
*/}
); } diff --git a/server/services/ocme/controller/cycleCount.ts b/server/services/ocme/controller/cycleCount.ts index d698500..716b5ca 100644 --- a/server/services/ocme/controller/cycleCount.ts +++ b/server/services/ocme/controller/cycleCount.ts @@ -1,6 +1,7 @@ import type {User} from "../../../types/users.js"; import {alplaStockInv} from "./cycleCount/alplaStockInventory.js"; import {emptyCount} from "./cycleCount/emptyCycleCount.js"; +import {fullLaneCount} from "./cycleCount/fullLaneCycleCount.js"; import {ocmeInv} from "./cycleCount/ocmeInventory.js"; export const prepareLane = "https://usday1prod.alpla.net/application/public/v1.1/Warehousing/PrepareLaneForInventory"; @@ -8,7 +9,7 @@ export const openLane = "https://usday1prod.alpla.net/application/public/v1.0/Wa export const closeLane = "https://usday1prod.alpla.net/application/public/v1.0/Warehousing/InventoryClose"; export const releaseLane = "https://usday1prod.alpla.net/application/public/v1.1/Warehousing/ReleaseLaneFromInventory"; export const scannerID = 500; -export const cycleCount = async (lane: string, user: User) => { +export const cycleCount = async (lane: any, user: User) => { /** * We will get the inventory from both systems and merge them together, intert it into our db then do the cycle count and update each item * one it dose it. @@ -21,7 +22,7 @@ export const cycleCount = async (lane: string, user: User) => { const alplaStock = await alplaStockInv(ocme[0].alpla_laneID); // create a new array that has the merge happen. - const mergeOcmeData = ocme.map((d) => { + const mergeOcmeData = ocme.map((d: any) => { // check if its in the ocme array we add it const inStock = alplaStock.filter((r: any) => r.runningNumber === d.runningNumber); //console.log(inStock); @@ -52,9 +53,10 @@ export const cycleCount = async (lane: string, user: User) => { // determine what type of count we are doing. if (ocme.length === 0) { // do empty count - await emptyCount(user, lane); + await emptyCount(user, ocme[0].alpla_laneID); } else { // do the full lane inv + await fullLaneCount(user, ocme[0].alpla_laneID, ocme); } // store in the db so we have a record.... for later when we fully randomize and automate this. diff --git a/server/services/ocme/controller/cycleCount/fullLaneCycleCount.ts b/server/services/ocme/controller/cycleCount/fullLaneCycleCount.ts index e69de29..25efe66 100644 --- a/server/services/ocme/controller/cycleCount/fullLaneCycleCount.ts +++ b/server/services/ocme/controller/cycleCount/fullLaneCycleCount.ts @@ -0,0 +1,126 @@ +// full lane count +import axios from "axios"; +import {delay} from "../../../../globalUtils/delay.js"; +import {createLog} from "../../../logger/logger.js"; +import {openLane, prepareLane, scannerID} from "../cycleCount.js"; +import type {User} from "../../../../types/users.js"; + +let delayTime = 100; + +export const fullLaneCount = async (user: User, lane: string, ocmeLanes: any) => { + // prepare the lane. + try { + const openlane = await axios({ + method: "POST", + url: prepareLane, + headers: { + Authorization: `Basic ${user.prod}`, + "Content-Type": "application/json", + }, + data: { + scannerId: scannerID, + laneId: lane, + }, + }); + + createLog("info", user.username!, "ocme-count", openlane.data.message); + try { + const open = await axios({ + method: "POST", + url: openLane, + headers: { + Authorization: `Basic ${user.prod}`, + "Content-Type": "application/json", + }, + data: { + scannerId: scannerID, + laneId: lane, + }, + }); + + createLog("info", user.username!, "ocme-count", open.data.Message); + } catch (error) { + console.log(error); + } + } catch (error) { + console.log(error); + } + + // do the inv + + for (let i = 0; i < ocmeLanes.length; i++) { + const count = { + scannerId: scannerID, + sscc: ocmeLanes[i].sscc, + }; + //createLog("cyclecounting", "info", `Processing running: ${ocmeLanes[i].runningNumber}`); + await delay(delayTime); + + try { + const openLane = await axios({ + method: "POST", + url: "https://usday1prod.alpla.net/application/public/v1.0/Warehousing/InventoryCount", + headers: { + Authorization: `Basic ${user.prod}`, + "Content-Type": "application/json", + }, + data: count, + }); + + createLog( + "info", + user.username!, + "ocme-count", + `${openLane.data.Message} on running: ${ocmeLanes[i].runningNumber}` + ); + await delay(delayTime); + } catch (error) { + createLog("error", user.username!, "ocme-count", `${error}`); + } + } + + // close the count + // close the order + try { + const openLane = await axios({ + method: "POST", + url: "https://usday1prod.alpla.net/application/public/v1.0/Warehousing/InventoryClose", + headers: { + Authorization: `Basic ${user.prod}`, + "Content-Type": "application/json", + }, + data: { + scannerId: scannerID, + laneId: lane, + }, + }); + + createLog("info", user.username!, "ocme-count", openLane.data.Message); + + if (openLane.data.Result === 0) { + //release the lane + //---------------------------------------------------- + try { + const openLane = await axios({ + method: "POST", + url: "https://usday1prod.alpla.net/application/public/v1.1/Warehousing/ReleaseLaneFromInventory", + headers: { + Authorization: `Basic ${user.prod}`, + "Content-Type": "application/json", + }, + data: { + laneId: lane, + }, + }); + + createLog("info", user.username!, "ocme-count", openLane.data.message); + } catch (error) { + createLog("error", user.username!, "ocme-count", `${error}`); + } + } + } catch (error) { + createLog("error", user.username!, "ocme-count", `${error}`); + } + + return {success: true, message: `Lane completed`}; +}; diff --git a/server/services/ocme/controller/cycleCount/ocmeInventory.ts b/server/services/ocme/controller/cycleCount/ocmeInventory.ts index fdb88ac..964d2f3 100644 --- a/server/services/ocme/controller/cycleCount/ocmeInventory.ts +++ b/server/services/ocme/controller/cycleCount/ocmeInventory.ts @@ -1,284 +1,16 @@ import axios from "axios"; -const data = [ - { - ocme_laneLevelID: "P3F36PZ1PN1", - alpla_laneID: "30285 ", - alpla_laneDescription: "L064", - Article: "146", - description: "HDPE Trigger 16oz White", - sscc: "090103830005256402", - runningNumber: "525640", - }, - { - ocme_laneLevelID: "P3F36PZ1PN2", - alpla_laneID: "30285 ", - alpla_laneDescription: "L064", - Article: "146", - description: "HDPE Trigger 16oz White", - sscc: "090103830005402649", - runningNumber: "540264", - }, - { - ocme_laneLevelID: "P3F36PZ1PN3", - alpla_laneID: "30285 ", - alpla_laneDescription: "L064", - Article: "146", - description: "HDPE Trigger 16oz White", - sscc: "090103830005312559", - runningNumber: "531255", - }, - { - ocme_laneLevelID: "P3F36PZ1PN4", - alpla_laneID: "30285 ", - alpla_laneDescription: "L064", - Article: "146", - description: "HDPE Trigger 16oz White", - sscc: "090103830005312658", - runningNumber: "531265", - }, - { - ocme_laneLevelID: "P3F36PZ2PN1", - alpla_laneID: "30285 ", - alpla_laneDescription: "L064", - Article: "146", - description: "HDPE Trigger 16oz White", - sscc: "090103830005404186", - runningNumber: "540418", - }, - { - ocme_laneLevelID: "P3F36PZ2PN2", - alpla_laneID: "30285 ", - alpla_laneDescription: "L064", - Article: "146", - description: "HDPE Trigger 16oz White", - sscc: "090103830005404193", - runningNumber: "540419", - }, - { - ocme_laneLevelID: "P3F36PZ2PN3", - alpla_laneID: "30285 ", - alpla_laneDescription: "L064", - Article: "146", - description: "HDPE Trigger 16oz White", - sscc: "090103830005404155", - runningNumber: "540415", - }, - { - ocme_laneLevelID: "P3F36PZ2PN4", - alpla_laneID: "30285 ", - alpla_laneDescription: "L064", - Article: "146", - description: "HDPE Trigger 16oz White", - sscc: "090103830005404230", - runningNumber: "540423", - }, - { - ocme_laneLevelID: "P3F36PZ3PN1", - alpla_laneID: "30285 ", - alpla_laneDescription: "L064", - Article: "146", - description: "HDPE Trigger 16oz White", - sscc: "090103830005306589", - runningNumber: "530658", - }, - { - ocme_laneLevelID: "P3F36PZ3PN2", - alpla_laneID: "30285 ", - alpla_laneDescription: "L064", - Article: "164", - description: "HDPE Trigger 16oz Orange", - sscc: "090103830005408634", - runningNumber: "540841", - }, - { - ocme_laneLevelID: "P3F36PZ3PN3", - alpla_laneID: "30285 ", - alpla_laneDescription: "L064", - Article: "164", - description: "HDPE Trigger 16oz Orange", - sscc: "090103830005836888", - runningNumber: "583688", - }, - { - ocme_laneLevelID: "P3F36PZ3PN4", - alpla_laneID: "30285 ", - alpla_laneDescription: "L064", - Article: "164", - description: "HDPE Trigger 16oz Orange", - sscc: "090103830005836871", - runningNumber: "583687", - }, - { - ocme_laneLevelID: "P3F36PZ4PN1", - alpla_laneID: "30285 ", - alpla_laneDescription: "L064", - Article: "164", - description: "HDPE Trigger 16oz Orange", - sscc: "090103830005845279", - runningNumber: "584527", - }, - { - ocme_laneLevelID: "P3F36PZ4PN2", - alpla_laneID: "30285 ", - alpla_laneDescription: "L064", - Article: "164", - description: "HDPE Trigger 16oz Orange", - sscc: "090103830005845231", - runningNumber: "584523", - }, - { - ocme_laneLevelID: "P3F36PZ4PN3", - alpla_laneID: "30285 ", - alpla_laneDescription: "L064", - Article: "164", - description: "HDPE Trigger 16oz Orange", - sscc: "090103830005845170", - runningNumber: "584517", - }, - { - ocme_laneLevelID: "P3F36PZ4PN4", - alpla_laneID: "30285 ", - alpla_laneDescription: "L064", - Article: "164", - description: "HDPE Trigger 16oz Orange", - sscc: "090103830005845156", - runningNumber: "584515", - }, - { - ocme_laneLevelID: "P3F36PZ5PN1", - alpla_laneID: "30285 ", - alpla_laneDescription: "L064", - Article: "164", - description: "HDPE Trigger 16oz Orange", - sscc: "090103830005870325", - runningNumber: "587032", - }, - { - ocme_laneLevelID: "P3F36PZ5PN2", - alpla_laneID: "30285 ", - alpla_laneDescription: "L064", - Article: "164", - description: "HDPE Trigger 16oz Orange", - sscc: "090103830005871490", - runningNumber: "587149", - }, - { - ocme_laneLevelID: "P3F36PZ5PN3", - alpla_laneID: "30285 ", - alpla_laneDescription: "L064", - Article: "164", - description: "HDPE Trigger 16oz Orange", - sscc: "090103830005851782", - runningNumber: "585178", - }, - { - ocme_laneLevelID: "P3F36PZ5PN4", - alpla_laneID: "30285 ", - alpla_laneDescription: "L064", - Article: "164", - description: "HDPE Trigger 16oz Orange", - sscc: "090103830005855339", - runningNumber: "585533", - }, - { - ocme_laneLevelID: "P3F36PZ6PN1", - alpla_laneID: "30285 ", - alpla_laneDescription: "L064", - Article: "164", - description: "HDPE Trigger 16oz Orange", - sscc: "090103830005867660", - runningNumber: "586766", - }, - { - ocme_laneLevelID: "P3F36PZ6PN2", - alpla_laneID: "30285 ", - alpla_laneDescription: "L064", - Article: "164", - description: "HDPE Trigger 16oz Orange", - sscc: "090103830005867622", - runningNumber: "586762", - }, - { - ocme_laneLevelID: "P3F36PZ6PN3", - alpla_laneID: "30285 ", - alpla_laneDescription: "L064", - Article: "164", - description: "HDPE Trigger 16oz Orange", - sscc: "090103830005865871", - runningNumber: "586587", - }, - { - ocme_laneLevelID: "P3F36PZ6PN4", - alpla_laneID: "30285 ", - alpla_laneDescription: "L064", - Article: "164", - description: "HDPE Trigger 16oz Orange", - sscc: "090103830005865895", - runningNumber: "586589", - }, - { - ocme_laneLevelID: "P3F36PZ7PN1", - alpla_laneID: "30285 ", - alpla_laneDescription: "L064", - Article: "164", - description: "HDPE Trigger 16oz Orange", - sscc: "090103830005866052", - runningNumber: "586605", - }, - { - ocme_laneLevelID: "P3F36PZ7PN2", - alpla_laneID: "30285 ", - alpla_laneDescription: "L064", - Article: "164", - description: "HDPE Trigger 16oz Orange", - sscc: "090103830005865970", - runningNumber: "586597", - }, - { - ocme_laneLevelID: "P3F36PZ7PN3", - alpla_laneID: "30285 ", - alpla_laneDescription: "L064", - Article: "164", - description: "HDPE Trigger 16oz Orange", - sscc: "090103830005877089", - runningNumber: "587708", - }, - { - ocme_laneLevelID: "P3F36PZ8PN1", - alpla_laneID: "30285 ", - alpla_laneDescription: "L064", - Article: "164", - description: "HDPE Trigger 16oz Orange", - sscc: "090103830005844975", - runningNumber: "584497", - }, - { - ocme_laneLevelID: "P3F36PZ8PN2", - alpla_laneID: "30285 ", - alpla_laneDescription: "L064", - Article: "164", - description: "HDPE Trigger 16oz Orange", - sscc: "090103830005844944", - runningNumber: "584494", - }, - { - ocme_laneLevelID: "P3F36PZ8PN3", - alpla_laneID: "30285 ", - alpla_laneDescription: "L064", - Article: "164", - description: "HDPE Trigger 16oz Orange", - sscc: "090103830005844890", - runningNumber: "584489", - }, -]; -export const ocmeInv = async (lane: string) => { - try { - const res = await axios.post("http://usday1vms010:3250/api/v1/getLaneData", {lane: lane}); - console.log(res.data); - return data; +export const ocmeInv = async (data: any) => { + try { + const res = await axios.post( + "http://usday1vms010:3250/api/v1/getLaneData", + {lane: data.lane, laneType: data.laneType}, + {headers: {"Content-Type": "application/json", Connection: "keep-alive"}} + ); + // console.log(res.data.data); + + return res.data.data; } catch (error: any) { console.log(error.code); - return data; } }; diff --git a/server/services/ocmeServer/routes/getLaneData.ts b/server/services/ocmeServer/routes/getLaneData.ts index 417015d..e815162 100644 --- a/server/services/ocmeServer/routes/getLaneData.ts +++ b/server/services/ocmeServer/routes/getLaneData.ts @@ -12,7 +12,14 @@ // // add the lane in so we dont crash // if(req.body.lane){ -// filterdOCMELane = ocmeInventory.replaceAll('[lane]', data.lane) +// if(data.laneType === "laneID"){ +// get the mapped lane id +// where alpla_laneID = 30286 +// filterdOCMELane = ocmeInventory.replaceAll("where alpla_laneDescription = '[lane]'", `where alpla_laneID = ${data.lane}`) + +// } else { +// filterdOCMELane = ocmeInventory.replaceAll('[lane]', data.lane) +// } // // get lanes // const laneData = await runQuery(filterdOCMELane, 'Getting current ocme lanes linked') // res.status(200).json({success: true,message: `All current lanes from the ocme system.`, totalpallets: laneData.length,data: laneData})