From 0a6ddea8c0d2773aba00266df7e2839879d10cb1 Mon Sep 17 00:00:00 2001 From: Blake Matthes Date: Wed, 27 Aug 2025 17:17:32 -0500 Subject: [PATCH] refactor(materials): changes to allow exact and eom transfers --- .../consumption/TransferToNextLot.tsx | 443 +++++++++++++----- frontend/src/components/ui/switch.tsx | 29 ++ .../controller/materials/consumeMaterial.ts | 2 + .../ocp/controller/materials/lotTransfer.ts | 130 +++-- .../ocp/routes/materials/lotTransfer.ts | 8 +- 5 files changed, 437 insertions(+), 175 deletions(-) create mode 100644 frontend/src/components/ui/switch.tsx diff --git a/frontend/src/components/logistics/materialHelper/consumption/TransferToNextLot.tsx b/frontend/src/components/logistics/materialHelper/consumption/TransferToNextLot.tsx index b517184..e6ac373 100644 --- a/frontend/src/components/logistics/materialHelper/consumption/TransferToNextLot.tsx +++ b/frontend/src/components/logistics/materialHelper/consumption/TransferToNextLot.tsx @@ -1,19 +1,32 @@ import { LstCard } from "@/components/extendedUI/LstCard"; import { Button } from "@/components/ui/button"; -import { CardHeader } from "@/components/ui/card"; +import { CardContent, CardHeader } from "@/components/ui/card"; +import { Input } from "@/components/ui/input"; +import { Switch } from "@/components/ui/switch"; +import { Tabs, TabsContent, TabsList, TabsTrigger } from "@/components/ui/tabs"; import { useAppForm } from "@/utils/formStuff"; import axios from "axios"; import { useState } from "react"; import { toast } from "sonner"; +import { Info } from "lucide-react"; +import { + Tooltip, + TooltipContent, + TooltipTrigger, +} from "@/components/ui/tooltip"; export default function TransferToNextLot() { const [gaylordFilled, setGaylordFilled] = useState([0]); + const [actualAmount, setActualAmount] = useState(0); + const [tab, setTab] = useState("esitmate"); + const [typeSwitch, setTypeSwitch] = useState(false); const form = useAppForm({ defaultValues: { runnungNumber: "", lotNumber: "", originalAmount: "", + amount: "", }, onSubmit: async ({ value }) => { //console.log(transferData); @@ -32,11 +45,15 @@ export default function TransferToNextLot() { ? 0.75 : gaylordFilled.length === 4 && 0.95 ), + amount: actualAmount, + type: typeSwitch ? "eom" : "lot", }); if (res.data.success) { toast.success(`${res.data.message}`); form.reset(); + setGaylordFilled([0]); + setActualAmount(0); } //console.log(res.data); @@ -64,73 +81,127 @@ export default function TransferToNextLot() {
-
- + + + +
+
+ +
+ + -

- Almost full -

- - - - -
-
- -
+ +

+ Enter the total amount of + the cage/gaylord +

+
+ + + setActualAmount( + Number( + e.target.value + ) + ) + } + /> + + +
@@ -165,20 +236,104 @@ export default function TransferToNextLot() { /> )} /> -
- ( - - )} - /> -
+ {tab !== "actual" && ( +
+ ( + + )} + /> +
+ )}
-
+
+
+ + + {typeSwitch ? ( +
+ + "EOM + Transfer" + + + + + + +

+ Click + the + toggle + if + you + will + be + transfering + at + EOM, + NOTE: + This + will + trigger + the + delayed + transfer. +

+
+
+
+ ) : ( +
+ + "Lot + Transfer" + + + + + + +

+ Click + the + toggle + if + you + will + be + transfering + at + EOM, + NOTE: + This + will + trigger + the + delayed + transfer. +

+
+
+
+ )} +
+
+ Transfer To Lot @@ -197,49 +352,93 @@ export default function TransferToNextLot() { Moving material to the next lot.

+ {tab !== "actual" ? ( +
+
    +
  1. + 1. Grab the gaylord running + number from the gaylord at the + line/next to the tschritter +
  2. +
  3. + 2. Grab the next lot number you + are going to be running (or the + one that state no Main material + prepared) +
  4. +
  5. + 3. Enter the total gaylord + weight (this is how much the + gaylord weighed when it came in + from the supplier.) +
  6. +
  7. + 4. *Click the level of the + gaylord (this is just an + estimate to move to the next + lot.) +
  8. +
  9. + 5. type in running number on the + gaylord. +
  10. +
  11. + 6. Type in the new lot number. +
  12. +
  13. 7. Press "Transfer To Lot"
  14. +
+

+

+ * to reduce the time needed to get + the lot going we will use an + estimate of how full the gaylord is. +

+

+ NOTE: This is not the return + process, this process will just get + the gaylord to the next lot. +

+
+ ) : ( +
+
    +
  1. + 1. Grab the gaylord running + number from the gaylord at the + line/next to the tschritter +
  2. +
  3. + 2. Grab the next lot number you + are going to be running (or the + one that state no Main material + prepared) +
  4. +
  5. + 3. Take the gaylord to the scale + and weight it +
  6. +
  7. + 4. Enter the weight of the + gaylord minus the tar weight. +
  8. +
  9. + 5. type in running number on the + gaylord. +
  10. +
  11. + 6. Type in the new lot number. +
  12. +
  13. 7. Press "Transfer To Lot"
  14. +
+

-
-
    -
  1. - 1. Grab the gaylord running number - from the gaylord at the line/next to - the tschritter -
  2. -
  3. - 2. Grab the next lot number you are - going to be running (or the one that - state no Main material prepared) -
  4. -
  5. - 3. Enter the total gaylord weight - (this is how much the gaylord - weighed when it came in from the - supplier.) -
  6. -
  7. - 4. *Click the level of the gaylord - (this is just an estimate to move to - the next lot.) -
  8. -
  9. - 5. type in running number on the - gaylord. -
  10. -
  11. 6. Type in the new lot number.
  12. -
  13. 7. Press "Transfer To Lot"
  14. -
-

-

- * to reduce the time needed to get the - lot going we will use an estimate of how - full the gaylord is. -

-

- NOTE: This is not the return process, - this process will just get the gaylord - to the next lot. -

-
+

+ NOTE: This is not the return + process, this process will just get + the gaylord to the next lot. +

+
+ )}
diff --git a/frontend/src/components/ui/switch.tsx b/frontend/src/components/ui/switch.tsx new file mode 100644 index 0000000..b0363e3 --- /dev/null +++ b/frontend/src/components/ui/switch.tsx @@ -0,0 +1,29 @@ +import * as React from "react" +import * as SwitchPrimitive from "@radix-ui/react-switch" + +import { cn } from "@/lib/utils" + +function Switch({ + className, + ...props +}: React.ComponentProps) { + return ( + + + + ) +} + +export { Switch } diff --git a/server/services/logistics/controller/materials/consumeMaterial.ts b/server/services/logistics/controller/materials/consumeMaterial.ts index 64888fd..e5fe5a3 100644 --- a/server/services/logistics/controller/materials/consumeMaterial.ts +++ b/server/services/logistics/controller/materials/consumeMaterial.ts @@ -17,6 +17,8 @@ export const consumeMaterial = async (data: Data, prod: any) => { const { runningNr, lotNum } = data; // replace the rn + console.log(data); + const rnReplace = labelData.replaceAll("[rn]", runningNr); let barcode; diff --git a/server/services/ocp/controller/materials/lotTransfer.ts b/server/services/ocp/controller/materials/lotTransfer.ts index b115267..7b75687 100644 --- a/server/services/ocp/controller/materials/lotTransfer.ts +++ b/server/services/ocp/controller/materials/lotTransfer.ts @@ -12,6 +12,8 @@ type NewLotData = { lotNumber: number; originalAmount: number; level: number; + amount: number; + type: "lot" | "eom"; }; /** @@ -22,8 +24,11 @@ type NewLotData = { * Lot number * Orignal Quantity * level of gaylord + * amount can be sent over as a precise amount + * type what way are we lots */ export const lotMaterialTransfer = async (data: NewLotData) => { + let timeoutTrans: number = data.type === "lot" ? 1 : 10; // get the barcode, and layoutID from the running number const { data: label, error: labelError } = (await tryCatch( query( @@ -46,22 +51,21 @@ export const lotMaterialTransfer = async (data: NewLotData) => { }; } - // if ( - // label.data[0]?.stockStatus === "notOnStock" || - // label.data.length === 0 - // ) { - // createLog( - // "error", - // "materials", - // "ocp", - // `${data.runnungNumber}: dose not exist or no longer in stock.` - // ); - // return { - // success: false, - // message: `${data.runnungNumber}: dose not exist or no longer in stock.`, - // data: [], - // }; - // } + if (label.data.length === 0) { + createLog( + "error", + "materials", + "ocp", + `${data.runnungNumber}: dose not exist or no longer in stock.` + ); + return { + success: false, + message: `${data.runnungNumber}: dose not exist or no longer in stock.`, + data: [], + }; + } + + //console.log(label); if (label.data[0]?.stockStatus === "onStock") { createLog( @@ -97,7 +101,12 @@ export const lotMaterialTransfer = async (data: NewLotData) => { } // calculate the remaining amount bascially it will be orignal number * level sent over // level should be sent in a decimal .25 .5 .75 .95 the 95 will allow basically the what looks to be a full gaylord but we always want to consume something - const newQty = (data.originalAmount * data.level).toFixed(0); + const newQty = + data.amount > 0 + ? data.amount + : (data.originalAmount * data.level).toFixed(0); + + //console.log(data.amount); // reprint the label and send it to pdf24 const reprintData = { @@ -109,6 +118,8 @@ export const lotMaterialTransfer = async (data: NewLotData) => { quantity: newQty, } as any; + //console.log(reprintData); + const { data: reprint, error: reprintError } = (await tryCatch( runProdApi({ endpoint: "/public/v1.0/ProductionLabelling/ReprintLabel", @@ -121,11 +132,11 @@ export const lotMaterialTransfer = async (data: NewLotData) => { "error", "materials", "ocp", - `RN:${data.runnungNumber}, Error: ${reprint.data.data.message}` + `RN:${data.runnungNumber}, Reprinting Error: ${reprint.data.data.message}` ); return { success: false, - message: `RN:${data.runnungNumber}, Error: ${reprint.data.data.message}`, + message: `RN:${data.runnungNumber}, Reprinting Error: ${reprint.data.data.message}`, data: reprint, }; } @@ -135,6 +146,8 @@ export const lotMaterialTransfer = async (data: NewLotData) => { barcode: label?.data[0].Barcode, laneId: 10001, }; + + //console.log(matReturnData); const { data: matReturn, error: matReturError } = (await tryCatch( runProdApi({ endpoint: @@ -148,11 +161,11 @@ export const lotMaterialTransfer = async (data: NewLotData) => { "error", "materials", "ocp", - `RN:${data.runnungNumber}, Error ${matReturn.data.data.errors[0].message}` + `RN:${data.runnungNumber}, Return Error ${matReturn.data.data.errors[0].message}` ); return { success: false, - message: `RN:${data.runnungNumber}, Error ${matReturn.data.data.errors[0].message}`, + message: `RN:${data.runnungNumber}, Return Error ${matReturn.data.data.errors[0].message}`, data: matReturn, }; } @@ -161,39 +174,56 @@ export const lotMaterialTransfer = async (data: NewLotData) => { productionLot: data.lotNumber, barcode: label?.data[0].Barcode, }; - const { data: matConsume, error: matConsumeError } = (await tryCatch( - runProdApi({ - endpoint: - "/public/v1.0/IssueMaterial/ConsumeNonPreparedManualMaterial", - data: [consumeLot], - }) - )) as any; - if (!matConsume.success) { - createLog( - "error", - "materials", - "ocp", - `RN:${data.runnungNumber}, Error ${matConsume.data.data.errors[0].message}` - ); + // sets the time out based on the type of transfer sent over. + setTimeout( + async () => { + const { data: matConsume, error: matConsumeError } = + (await tryCatch( + runProdApi({ + endpoint: + "/public/v1.0/IssueMaterial/ConsumeNonPreparedManualMaterial", + data: [consumeLot], + }) + )) as any; + + if (!matConsume.success) { + createLog( + "error", + "materials", + "ocp", + `RN:${data.runnungNumber}, Consume Error ${matConsume.data.data.errors[0].message}` + ); + return { + success: false, + message: `RN:${data.runnungNumber}, Consume Error ${matConsume.data.data.errors[0].message}`, + data: matConsume, + }; + } + + createLog( + "info", + "materials", + "ocp", + `RN:${data.runnungNumber}: qty: ${newQty}, was transfered to lot:${data.lotNumber}` + ); + }, + data.type === "lot" ? timeoutTrans * 1000 : timeoutTrans * 1000 * 60 + ); + + if (data.type === "eom") { return { - success: false, - message: `RN:${data.runnungNumber}, Error ${matConsume.data.data.errors[0].message}`, - data: matConsume, + success: true, + message: `RN:${data.runnungNumber}: qty: ${newQty}, will be transfered to:${data.lotNumber}, in ${timeoutTrans}min`, + data: [], + }; + } else { + return { + success: true, + message: `RN:${data.runnungNumber}: qty: ${newQty}, was transfered to lot:${data.lotNumber}`, + data: [], }; } - - createLog( - "info", - "materials", - "ocp", - `RN:${data.runnungNumber}: qty: ${newQty}, was transfered to lot:${data.lotNumber}` - ); - return { - success: true, - message: `RN:${data.runnungNumber}: qty: ${newQty}, was transfered to lot:${data.lotNumber}`, - data: [], - }; }; // setTimeout(async () => { diff --git a/server/services/ocp/routes/materials/lotTransfer.ts b/server/services/ocp/routes/materials/lotTransfer.ts index 34b8b21..991f63f 100644 --- a/server/services/ocp/routes/materials/lotTransfer.ts +++ b/server/services/ocp/routes/materials/lotTransfer.ts @@ -54,10 +54,12 @@ app.openapi( }); } + console.log(transferMaterial); + return c.json({ - success: transferMaterial.success, - message: transferMaterial.message, - data: transferMaterial.data, + success: transferMaterial?.success, + message: transferMaterial?.message, + data: transferMaterial?.data, }); } );