feat(lstv2 move): moved lstv2 into this app to keep them combined and easier to maintain

This commit is contained in:
2025-09-19 22:22:05 -05:00
parent caf2315191
commit e4477402ad
847 changed files with 165801 additions and 0 deletions

View File

@@ -0,0 +1,73 @@
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 let lanes: any = [];
export const getLanesToCycleCount = async () => {
const currentTime: any = timeZoneFix();
// store the lanes in memeory
createLog("info", "warehouse", "logistics", "Lane triggered update.");
lastCheck = currentTime;
const ageQuery = cycleCountCheck.replaceAll("[ageOfRow]", "90");
const { data: p, error: pl } = await tryCatch(
query(ageQuery, "Get Stock lane date.")
);
if (pl) {
createLog(
"error",
"warehouse",
"logistics",
`There was an error getting lanes: ${pl}`
);
return;
}
const prodLanes: any = p?.data;
// 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]?.LastMoveDate, "M/d/yyyy")
: undefined,
LastInv: format(prodLanes[i]?.LastInv, "M/d/yyyy"),
rowType: prodLanes[i].rowType,
DaysSinceLast: differenceInDays(
new Date(Date.now()),
new Date(prodLanes[i].LastInv)
),
upd_date: format(new Date(Date.now()), "M/d/yyyy"),
};
const existing = lanes.filter(
(l: any) => l.laneID === prodLanes[i]?.laneID
);
if (existing) {
lanes = lanes.filter((l: any) => l.laneID !== prodLanes[i]?.laneID);
}
lanes.push(createLane);
createLog(
"debug",
"warehouse",
"logistics",
`${lanes[i].Description} was just added`
);
await delay(10);
//delay to slow this thing down
}
};

View File

@@ -0,0 +1,42 @@
import * as XLSX from "xlsx";
import { lanes } from "./cyclecountCheck.js";
export const lanesToExcel = async (age: string | null) => {
// Convert JSON data to an array of arrays (AOA)
let processLanes = lanes;
if (age) {
processLanes = lanes.filter(
(l: any) => l.DaysSinceLast >= parseInt(age)
);
}
const headers = Object.keys(processLanes[0]); // Get headers from JSON keys
const data = processLanes.map((item: any) =>
headers.map((header) => item[header])
);
// Create the workbook and worksheet
const wb = XLSX.utils.book_new();
const ws = XLSX.utils.aoa_to_sheet([headers, ...data]); // Combine headers and data
// Auto-resize columns based on the longest content in each column
const colWidths = headers.map((_, colIndex) => {
let maxLength = 0;
data.forEach((row: any) => {
const cellValue = row[colIndex] ? row[colIndex].toString() : "";
maxLength = Math.max(maxLength, cellValue.length);
});
return { wch: maxLength + 2 }; // Add a little padding
});
ws["!cols"] = colWidths; // Set the column widths
// Add the worksheet to the workbook
XLSX.utils.book_append_sheet(wb, ws, "CycleCount");
// Write the workbook to a buffer and return it
const excelBuffer = XLSX.write(wb, { bookType: "xlsx", type: "buffer" });
return excelBuffer;
};

View File

@@ -0,0 +1,41 @@
import { lanes } from "./cyclecountCheck.js";
export const getCycleCountCheck = async (age: number = 1000, type: any) => {
/**
* Get the lane data based on the age and type
*/
let filteredLanes = lanes;
if (type === "empty") {
let empty = lanes.filter((t: any) => t.rowType === type.toUpperCase());
return {
sucess: true,
message: `${empty.length} lanes that are of type ${type}.`,
data: empty.sort(
(a: any, b: any) => b.DaysSinceLast - a.DaysSinceLast
),
};
}
if (type != "") {
let noType = lanes.filter((t: any) => t.DaysSinceLast >= age);
return {
sucess: true,
message: `${noType.length} lanes that are of type ${type} and have not been cycle counted in the last ${age} days.`,
data: noType
.filter((t: any) => t.rowType === type?.toUpperCase())
.sort((a: any, b: any) => b.DaysSinceLast - a.DaysSinceLast),
};
}
return {
success: true,
message: `${filteredLanes.length} lanes grabed that have not been cycle counted in the last ${age} days.`,
data: filteredLanes.sort(
(a: any, b: any) => b.DaysSinceLast - a.DaysSinceLast
),
};
};