feat(exports): added in a button to export the lanes to cycle count
This commit is contained in:
@@ -9,14 +9,14 @@ import { cycleCountCheck } from "../../../../sqlServer/querys/warehouse/cycleCou
|
|||||||
// setting timer for updating stockCheck on a restart will always check.
|
// setting timer for updating stockCheck on a restart will always check.
|
||||||
let lastCheck = 0;
|
let lastCheck = 0;
|
||||||
|
|
||||||
export const lanes: any = [];
|
export let lanes: any = [];
|
||||||
|
|
||||||
export const getLanesToCycleCount = async () => {
|
export const getLanesToCycleCount = async () => {
|
||||||
const currentTime: any = timeZoneFix();
|
const currentTime: any = timeZoneFix();
|
||||||
// store the lanes in memeory
|
// store the lanes in memeory
|
||||||
createLog("info", "warehouse", "logistics", "Lane triggered update.");
|
createLog("info", "warehouse", "logistics", "Lane triggered update.");
|
||||||
lastCheck = currentTime;
|
lastCheck = currentTime;
|
||||||
const ageQuery = cycleCountCheck.replaceAll("[ageOfRow]", `1000`);
|
const ageQuery = cycleCountCheck.replaceAll("[ageOfRow]", "90");
|
||||||
const { data: prodLanes, error: pl } = await tryCatch(
|
const { data: prodLanes, error: pl } = await tryCatch(
|
||||||
query(ageQuery, "Get Stock lane date.")
|
query(ageQuery, "Get Stock lane date.")
|
||||||
);
|
);
|
||||||
@@ -39,23 +39,25 @@ export const getLanesToCycleCount = async () => {
|
|||||||
warehouseName: prodLanes[i]?.warehouseName || "na",
|
warehouseName: prodLanes[i]?.warehouseName || "na",
|
||||||
Description: prodLanes[i]?.Description,
|
Description: prodLanes[i]?.Description,
|
||||||
LastMoveDate: prodLanes[i]?.LastMoveDate
|
LastMoveDate: prodLanes[i]?.LastMoveDate
|
||||||
? format(prodLanes[i]?.LastInv, "M/d/yyyy")
|
? format(prodLanes[i]?.LastMoveDate, "M/d/yyyy")
|
||||||
: undefined,
|
: undefined,
|
||||||
LastInv: format(prodLanes[i]?.LastInv, "M/d/yyyy"),
|
LastInv: format(prodLanes[i]?.LastInv, "M/d/yyyy"),
|
||||||
rowType: prodLanes[i].rowType,
|
rowType: prodLanes[i].rowType,
|
||||||
DaysSinceLast:
|
DaysSinceLast: differenceInDays(
|
||||||
differenceInDays(
|
new Date(Date.now()),
|
||||||
new Date(prodLanes[i].LastInv),
|
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"),
|
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);
|
lanes.push(createLane);
|
||||||
createLog(
|
createLog(
|
||||||
"debug",
|
"debug",
|
||||||
|
|||||||
@@ -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;
|
||||||
|
};
|
||||||
@@ -10,6 +10,7 @@ import getSiloAdjustments from "./route/siloAdjustments/getSiloAdjustments.js";
|
|||||||
import { getLanesToCycleCount } from "./controller/warehouse/cycleCountChecks/cyclecountCheck.js";
|
import { getLanesToCycleCount } from "./controller/warehouse/cycleCountChecks/cyclecountCheck.js";
|
||||||
import getCycleCountCheck from "./route/getCycleCountChecks.js";
|
import getCycleCountCheck from "./route/getCycleCountChecks.js";
|
||||||
import getPPOO from "./route/getPPOO.js";
|
import getPPOO from "./route/getPPOO.js";
|
||||||
|
import getcyclecount from "./route/getCycleCountLanes.js";
|
||||||
|
|
||||||
const app = new OpenAPIHono();
|
const app = new OpenAPIHono();
|
||||||
|
|
||||||
@@ -26,6 +27,7 @@ const routes = [
|
|||||||
getCycleCountCheck,
|
getCycleCountCheck,
|
||||||
//warehouse
|
//warehouse
|
||||||
getPPOO,
|
getPPOO,
|
||||||
|
getcyclecount,
|
||||||
] as const;
|
] as const;
|
||||||
|
|
||||||
// app.route("/server", modules);
|
// app.route("/server", modules);
|
||||||
|
|||||||
Reference in New Issue
Block a user