diff --git a/frontend/src/components/ocme/ocmeCycleCount.tsx b/frontend/src/components/ocme/ocmeCycleCount.tsx index 63c7342..c1c7ce2 100644 --- a/frontend/src/components/ocme/ocmeCycleCount.tsx +++ b/frontend/src/components/ocme/ocmeCycleCount.tsx @@ -41,13 +41,22 @@ export default function OcmeCycleCount() { setCounting(true); toast.success(`Cycle count started`); try { - const res = await axios.post("/ocme/api/v1/cyclecount", data, { + 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(); + + if (res.data.success) { + toast.success(res.data.message); + setData(res.data.data); + setCounting(false); + reset(); + } + + if (res.data.success) { + toast.success(res.data.message); + + setCounting(false); + } } catch (error) { toast.error("There was an error cycle counting"); setCounting(false); @@ -137,7 +146,7 @@ export default function OcmeCycleCount() { Result - {data.length === 0 ? ( + {data?.length === 0 ? ( {Array(10) .fill(0) diff --git a/server/services/ocme/controller/cycleCount.ts b/server/services/ocme/controller/cycleCount.ts index 716b5ca..5ec4890 100644 --- a/server/services/ocme/controller/cycleCount.ts +++ b/server/services/ocme/controller/cycleCount.ts @@ -1,13 +1,17 @@ -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"; +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"; -export const openLane = "https://usday1prod.alpla.net/application/public/v1.0/Warehousing/InventoryOpen"; -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 prepareLane = + "https://usday1prod.alpla.net/application/public/v1.1/Warehousing/PrepareLaneForInventory"; +export const openLane = + "https://usday1prod.alpla.net/application/public/v1.0/Warehousing/InventoryOpen"; +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: any, user: User) => { /** @@ -24,29 +28,39 @@ export const cycleCount = async (lane: any, user: User) => { // create a new array that has the merge happen. 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); + const inStock = alplaStock.filter( + (r: any) => r.runningNumber === d.runningNumber + ); //console.log(inStock); if (inStock.length != 0) { //console.log(`${d.runningNumber} is good`); - return {...d, ocme: "Yes", stock: "Yes", info: "Good"}; + return { ...d, ocme: "Yes", stock: "Yes", info: "Good" }; } else { //console.log(`${d.runningNumber} is bad`); - return {...d, ocme: "Yes", stock: "No", info: "Quality Check Required"}; + return { + ...d, + ocme: "Yes", + stock: "No", + info: "Validate pallet is ok. ", + }; } }); const mergeStockData = alplaStock - .filter((r: any) => !ocme.some((d: any) => d.runningNumber === r.runningNumber)) - .map((r: any) => { - return { - ...r, - ocme_laneLevelID: "", - sscc: "", - ocme: "No", - stock: "Yes", - info: "Sent to Inv", - }; - }); + .filter( + (r: any) => + !ocme.some((d: any) => d.runningNumber === r.runningNumber) + ) + .map((r: any) => { + return { + ...r, + ocme_laneLevelID: "", + sscc: "", + ocme: "No", + stock: "Yes", + info: "Sent to Inv", + }; + }); const combineBoth = [...mergeOcmeData, ...mergeStockData]; diff --git a/server/services/ocmeServer/routes/getLaneData.ts b/server/services/ocmeServer/routes/getLaneData.ts index e815162..1145b8e 100644 --- a/server/services/ocmeServer/routes/getLaneData.ts +++ b/server/services/ocmeServer/routes/getLaneData.ts @@ -1,10 +1,12 @@ // import {Router} from 'express' // import { runQuery } from '../utils/sql/config/sqlConfig.js' // import { ocmeInventory } from '../utils/sql/querys/getOCMEInventory.js' +// import { getLanes } from '../utils/sql/querys/getLanes.js' // const router = Router() // router.post('/getLaneData', async (req,res)=>{ +// console.log(`Getting lane data`) // let filterdOCMELane // // the body will need to have 1 lane in it. lane: 'B050' @@ -12,30 +14,58 @@ // // add the lane in so we dont crash // if(req.body.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}`) +// if(data.laneType === "laneID"){ +// // get the mapped lane id +// // where alpla_laneID = 30286 +// console.log("getting lane by id") +// filterdOCMELane = ocmeInventory.replaceAll("where alpla_laneDescription = '[lane]'", `where alpla_laneID = ${data.lane}`) -// } else { -// filterdOCMELane = ocmeInventory.replaceAll('[lane]', data.lane) -// } +// } else { +// console.log("getting lane by name") +// 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}) -// return +// try { +// const laneData = await runQuery(filterdOCMELane, 'Getting current ocme lanes linked') + +// let inventory = laneData + +// // if we do not have anything then we will send just the name and id so we can at least do the count. + +// if(laneData.length === 0){ +// console.log(`Sending the name and id over. for an empty count`) +// const lanes = await runQuery(getLanes, 'Getting current ocme lanes linked') + +// let filterLane +// if(data.laneType === "laneID"){ +// filterLane = lanes.filter(n => n.alpla_laneID.includes(req.body.lane)) +// }else { +// filterLane = lanes.filter(n => n.alpla_laneDescription === req.body.lane.toUpperCase()) +// } +// inventory = [{alpla_laneDescription: filterLane[0].alpla_laneDescription,alpla_laneID: filterLane[0].alpla_laneID }] + +// console.log(filterLane, inventory) +// } +// return res.status(200).json({success: true,message: `All current lanes from the ocme system.`, totalpallets: inventory.length,data: inventory}) +// } catch (error) { +// console.log(error) +// return res.status(400).json({success: false,message: `Error getting the lane data`, error}) +// } + // } // // if the plant sends the id over lets change the entire where statement. -// if(req.body.laneID){ -// console.log(`Getting the lane data by id`) -// filterdOCMELane = ocmeInventory.replaceAll(`alpla_laneDescription = '[lane]'`, `alpla_laneID = ${data.laneID}`) -// // 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}) -// return -// } +// // if(req.body.laneID){ +// // console.log(`Getting the lane data by id`) +// // filterdOCMELane = ocmeInventory.replaceAll(`alpla_laneDescription = '[lane]'`, `alpla_laneID = ${data.laneID}`) +// // // 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}) +// // return +// // } // // if everything is missing we send false // res.status(200).json({success: false,message: `Missing either lane name or lane id.`})