build(notification): fixed fifo index ts errors

This commit is contained in:
2026-02-16 09:38:10 -06:00
parent 16edf58025
commit 29b3be41a1
2 changed files with 96 additions and 93 deletions

View File

@@ -1,7 +1,9 @@
import { OpenAPIHono } from "@hono/zod-openapi"; import { OpenAPIHono } from "@hono/zod-openapi";
import { migrateAdjustments } from "./controller/siloAdjustments/migrateAdjustments.js"; import { migrateAdjustments } from "./controller/siloAdjustments/migrateAdjustments.js";
import { getLanesToCycleCount } from "./controller/warehouse/cycleCountChecks/cyclecountCheck.js"; import { getLanesToCycleCount } from "./controller/warehouse/cycleCountChecks/cyclecountCheck.js";
import attachSilo from "./route/attachSilo.js"; import attachSilo from "./route/attachSilo.js";
import bookOutPallet from "./route/bookout.js";
import comsumeMaterial from "./route/consumeMaterial.js"; import comsumeMaterial from "./route/consumeMaterial.js";
import detachSilo from "./route/detachSilo.js"; import detachSilo from "./route/detachSilo.js";
import postBulkOrders from "./route/dm/bulkOrdersIn.js"; import postBulkOrders from "./route/dm/bulkOrdersIn.js";
@@ -56,6 +58,7 @@ const routes = [
// logisitcs // logisitcs
removeAsNonReable, removeAsNonReable,
getSSCC, getSSCC,
bookOutPallet,
] as const; ] as const;
// app.route("/server", modules); // app.route("/server", modules);

View File

@@ -1,112 +1,112 @@
import { isBefore } from "date-fns"; import { isBefore } from "date-fns";
import { db } from "../../../../../database/dbclient.js";
import { fifoIndex } from "../../../../../database/schema/fifoIndex.js";
import { tryCatch } from "../../../../globalUtils/tryCatch.js"; import { tryCatch } from "../../../../globalUtils/tryCatch.js";
import { query } from "../../../sqlServer/prodSqlServer.js"; import { query } from "../../../sqlServer/prodSqlServer.js";
import { currentInv } from "../../../sqlServer/querys/notifications/fifoIndex/currentInv.js"; import { currentInv } from "../../../sqlServer/querys/notifications/fifoIndex/currentInv.js";
import { shippedPallets } from "../../../sqlServer/querys/notifications/fifoIndex/shippedPallets.js"; import { shippedPallets } from "../../../sqlServer/querys/notifications/fifoIndex/shippedPallets.js";
import { db } from "../../../../../database/dbclient.js";
import { fifoIndex } from "../../../../../database/schema/fifoIndex.js";
export default async function fifoIndexCheck() { export default async function fifoIndexCheck() {
/** /**
* getting the shipped pallets * getting the shipped pallets
*/ */
const { data: shipped, error: eShipped } = await tryCatch( const { data: shipped, error: eShipped } = await tryCatch(
query(shippedPallets, "notify shipped pallets") query(shippedPallets, "notify shipped pallets"),
); );
const { data: currentStuff, error: eCurrentInv } = await tryCatch( const { data: currentStuff, error: eCurrentInv } = await tryCatch(
query(currentInv, "notify shipped pallets") query(currentInv, "notify shipped pallets"),
); );
// console.log(shipped?.data[2]); // console.log(shipped?.data[2]);
// console.log(currentStuff?.data[2]); // console.log(currentStuff?.data[2]);
/** /**
* We want to check if the each shippened pallet is out of fifo * We want to check if the each shippened pallet is out of fifo
*/ */
const check = shipped?.data.map((n: any) => { const check: any = shipped?.data.map((n: any) => {
/** /**
* Returns all data so we know if we are in or out. * Returns all data so we know if we are in or out.
*/ */
//check if there are pallets older than the current one we are mapped on. //check if there are pallets older than the current one we are mapped on.
const fifoCheck = currentStuff?.data.filter( const fifoCheck = currentStuff?.data.filter(
(i: any) => isBefore(i.prodDate, n.prodDate) && i.av === n.av (i: any) => isBefore(i.prodDate, n.prodDate) && i.av === n.av,
); ) as any;
//console.log(fifoCheck.length); //console.log(fifoCheck.length);
if (fifoCheck.length > 0) { if (fifoCheck.length > 0) {
// console.log("Out of fifo", { // console.log("Out of fifo", {
// av: n.av, // av: n.av,
// rn: n.runningNr, // rn: n.runningNr,
// fRn: fifoCheck[0].runningNr, // fRn: fifoCheck[0].runningNr,
// dates: [fifoCheck[0].prodDate, n.prodDate], // dates: [fifoCheck[0].prodDate, n.prodDate],
// }); // });
} }
return { return {
...n, ...n,
// currentInv: fifoCheck[0], // currentInv: fifoCheck[0],
fifoFollowed: fifoCheck.length === 0 ? true : false, fifoFollowed: fifoCheck.length === 0 ? true : false,
}; };
}); });
/** /**
* lets see just the av that is our or in * lets see just the av that is our or in
*/ */
const avCheck = (check: any) => { const avCheck = (check: any) => {
/** /**
* This will only return the data based on out of fifo. * This will only return the data based on out of fifo.
*/ */
// check how many times each av showed up // check how many times each av showed up
const avCounts = check.reduce((a: any, c: any) => { const avCounts = check.reduce((a: any, c: any) => {
if (c.fifoFollowed === false) { if (c.fifoFollowed === false) {
const avValue = c.av; const avValue = c.av;
a[avValue] = (a[avValue] || 0) + 1; a[avValue] = (a[avValue] || 0) + 1;
} }
return a; return a;
}, {}); }, {});
// transform them back to an avCount Object // transform them back to an avCount Object
const result = Object.keys(avCounts).map((av) => ({ const result = Object.keys(avCounts).map((av) => ({
av: parseInt(av, 10), av: parseInt(av, 10),
count: avCounts[av], count: avCounts[av],
})); }));
return result; return result;
}; };
const outOfFifo: any = avCheck(check); const outOfFifo: any = avCheck(check);
const totalOut = outOfFifo.reduce((sum: any, c: any) => { const totalOut = outOfFifo.reduce((sum: any, c: any) => {
return sum + c.count; return sum + c.count;
}, 0); }, 0);
/** /**
* add the data to the db * add the data to the db
*/ */
for (let i = 0; i < check.length; i++) { for (let i = 0; i < check!.length; i++) {
const { data: dbInsert, error: dbE } = await tryCatch( const { data: dbInsert, error: dbE } = await tryCatch(
db db
.insert(fifoIndex) .insert(fifoIndex)
.values({ .values({
lot: check[i].lot, lot: check[i].lot,
av: check[i].av, av: check[i].av,
runningNr: check[i].runningNr, runningNr: check[i].runningNr,
prodDate: check[i].prodDate, prodDate: check[i].prodDate,
fifoFollowed: check[i].fifoFollowed, fifoFollowed: check[i].fifoFollowed,
add_Date: check[i].add_Date, add_Date: check[i].add_Date,
}) })
.onConflictDoNothing() .onConflictDoNothing(),
); );
} }
return { return {
success: true, success: true,
message: "Fifo index data", message: "Fifo index data",
data: { data: {
palletsOut: check, palletsOut: check,
totalShipped: shipped?.data.length, totalShipped: shipped?.data.length,
inFifo: shipped?.data.length - totalOut, inFifo: shipped!.data.length - totalOut,
outOfFifoData: outOfFifo, outOfFifoData: outOfFifo,
}, },
}; };
} }