feat(cyclecountcheck): added i cycle count check this is in mem right now
if this becomes a resource hog we will move it to the db. no need for it to really be presitant
This commit is contained in:
@@ -0,0 +1,59 @@
|
||||
import { differenceInDays, differenceInSeconds, format } from "date-fns";
|
||||
import { timeZoneFix } from "../../../../../globalUtils/timeZoneFix.js";
|
||||
import { createLog } from "../../../../logger/logger.js";
|
||||
import { delay } from "../../../../../globalUtils/delay.js";
|
||||
import { tryCatch } from "../../../../../globalUtils/tryCatch.js";
|
||||
import { query } from "../../../../sqlServer/prodSqlServer.js";
|
||||
import { cycleCountCheck } from "../../../../sqlServer/querys/warehouse/cycleCountCheck.js";
|
||||
|
||||
// setting timer for updating stockCheck on a restart will always check.
|
||||
let lastCheck = 0;
|
||||
|
||||
export const lanes: any = [];
|
||||
|
||||
export const getLanesToCycleCount = async () => {
|
||||
const currentTime: any = timeZoneFix();
|
||||
// store the lanes in memeory
|
||||
createLog("info", "warehouse", "logistics", "Empty lane triggered update.");
|
||||
lastCheck = currentTime;
|
||||
const ageQuery = cycleCountCheck.replaceAll("[ageOfRow]", `1000`);
|
||||
const { data: prodLanes, error: pl } = await tryCatch(
|
||||
query(ageQuery, "Get Stock lane date.")
|
||||
);
|
||||
|
||||
// run the update on the lanes
|
||||
for (let i = 0; i < prodLanes.length; i++) {
|
||||
const createLane = {
|
||||
laneID: prodLanes[i]?.laneID,
|
||||
warehouseID: prodLanes[i]?.warehouseID,
|
||||
warehouseName: prodLanes[i]?.warehouseName || "na",
|
||||
Description: prodLanes[i]?.Description,
|
||||
LastMoveDate: prodLanes[i]?.LastMoveDate
|
||||
? format(prodLanes[i]?.LastInv, "M/d/yyyy")
|
||||
: undefined,
|
||||
LastInv: format(prodLanes[i]?.LastInv, "M/d/yyyy"),
|
||||
rowType: prodLanes[i].rowType,
|
||||
DaysSinceLast:
|
||||
differenceInDays(
|
||||
new Date(prodLanes[i].LastInv),
|
||||
new Date(prodLanes[i].LastMoveDate)
|
||||
) <= 0
|
||||
? 0
|
||||
: differenceInDays(
|
||||
new Date(prodLanes[i].LastInv),
|
||||
new Date(prodLanes[i].LastMoveDate)
|
||||
),
|
||||
upd_date: format(new Date(Date.now()), "M/d/yyyy"),
|
||||
};
|
||||
|
||||
lanes.push(createLane);
|
||||
createLog(
|
||||
"debug",
|
||||
"warehouse",
|
||||
"logistics",
|
||||
`${lanes[i].Description} was just added`
|
||||
);
|
||||
await delay(10);
|
||||
//delay to slow this thing down
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,28 @@
|
||||
import { lanes } from "./cyclecountCheck.js";
|
||||
|
||||
export const getCycleCountCheck = async (
|
||||
age: number = 1000,
|
||||
type: string = ""
|
||||
) => {
|
||||
/**
|
||||
* Get the lane data based on the age and type
|
||||
*/
|
||||
|
||||
let filteredLanes = lanes.filter((t: any) => t.DaysSinceLast >= age);
|
||||
|
||||
if (type != "") {
|
||||
return {
|
||||
sucess: true,
|
||||
message: `${filteredLanes.length} lanes that are of type ${type} and have not been cycle counted in the last ${age} days.`,
|
||||
data: filteredLanes.filter(
|
||||
(t: any) => t.rowType === type.toUpperCase()
|
||||
),
|
||||
};
|
||||
} else {
|
||||
return {
|
||||
success: true,
|
||||
message: `${filteredLanes.length} lanes grabed that have not been cycle counted in the last ${age} days.`,
|
||||
data: filteredLanes,
|
||||
};
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user