feat(exports): added in a button to export the lanes to cycle count

This commit is contained in:
2025-04-14 12:26:56 -05:00
parent 087d14c585
commit 25785703db
3 changed files with 59 additions and 13 deletions

View File

@@ -9,14 +9,14 @@ import { cycleCountCheck } from "../../../../sqlServer/querys/warehouse/cycleCou
// setting timer for updating stockCheck on a restart will always check.
let lastCheck = 0;
export const lanes: any = [];
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]", `1000`);
const ageQuery = cycleCountCheck.replaceAll("[ageOfRow]", "90");
const { data: prodLanes, error: pl } = await tryCatch(
query(ageQuery, "Get Stock lane date.")
);
@@ -39,23 +39,25 @@ export const getLanesToCycleCount = async () => {
warehouseName: prodLanes[i]?.warehouseName || "na",
Description: prodLanes[i]?.Description,
LastMoveDate: prodLanes[i]?.LastMoveDate
? format(prodLanes[i]?.LastInv, "M/d/yyyy")
? format(prodLanes[i]?.LastMoveDate, "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)
),
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",

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

@@ -10,6 +10,7 @@ import getSiloAdjustments from "./route/siloAdjustments/getSiloAdjustments.js";
import { getLanesToCycleCount } from "./controller/warehouse/cycleCountChecks/cyclecountCheck.js";
import getCycleCountCheck from "./route/getCycleCountChecks.js";
import getPPOO from "./route/getPPOO.js";
import getcyclecount from "./route/getCycleCountLanes.js";
const app = new OpenAPIHono();
@@ -26,6 +27,7 @@ const routes = [
getCycleCountCheck,
//warehouse
getPPOO,
getcyclecount,
] as const;
// app.route("/server", modules);