64 lines
2.4 KiB
TypeScript
64 lines
2.4 KiB
TypeScript
import type {User} from "../../../types/users.js";
|
|
import {alplaStockInv} from "./cycleCount/alplaStockInventory.js";
|
|
import {emptyCount} from "./cycleCount/emptyCycleCount.js";
|
|
import {ocmeInv} from "./cycleCount/ocmeInventory.js";
|
|
|
|
export const prepareLane = "https://usday1prod.alpla.net/application/public/v1.1/Warehousing/PrepareLaneForInventory";
|
|
export const openLane = "https://usday1prod.alpla.net/application/public/v1.0/Warehousing/InventoryOpen";
|
|
export const closeLane = "https://usday1prod.alpla.net/application/public/v1.0/Warehousing/InventoryClose";
|
|
export const releaseLane = "https://usday1prod.alpla.net/application/public/v1.1/Warehousing/ReleaseLaneFromInventory";
|
|
export const scannerID = 500;
|
|
export const cycleCount = async (lane: string, user: User) => {
|
|
/**
|
|
* We will get the inventory from both systems and merge them together, intert it into our db then do the cycle count and update each item
|
|
* one it dose it.
|
|
*/
|
|
|
|
// get ocme data first
|
|
const ocme = await ocmeInv(lane);
|
|
|
|
// get alpla stock data
|
|
const alplaStock = await alplaStockInv(ocme[0].alpla_laneID);
|
|
|
|
// create a new array that has the merge happen.
|
|
const mergeOcmeData = ocme.map((d) => {
|
|
// check if its in the ocme array we add it
|
|
const inStock = alplaStock.filter((r: any) => r.runningNumber === d.runningNumber);
|
|
//console.log(inStock);
|
|
if (inStock.length != 0) {
|
|
//console.log(`${d.runningNumber} is good`);
|
|
return {...d, ocme: "Yes", stock: "Yes", info: "Good"};
|
|
} else {
|
|
//console.log(`${d.runningNumber} is bad`);
|
|
return {...d, ocme: "Yes", stock: "No", info: "Quality Check Required"};
|
|
}
|
|
});
|
|
|
|
const mergeStockData = alplaStock
|
|
.filter((r: any) => !ocme.some((d: any) => d.runningNumber === r.runningNumber))
|
|
.map((r: any) => {
|
|
return {
|
|
...r,
|
|
ocme_laneLevelID: "",
|
|
sscc: "",
|
|
ocme: "No",
|
|
stock: "Yes",
|
|
info: "Sent to Inv",
|
|
};
|
|
});
|
|
|
|
const combineBoth = [...mergeOcmeData, ...mergeStockData];
|
|
|
|
// determine what type of count we are doing.
|
|
if (ocme.length === 0) {
|
|
// do empty count
|
|
await emptyCount(user, lane);
|
|
} else {
|
|
// do the full lane inv
|
|
}
|
|
|
|
// store in the db so we have a record.... for later when we fully randomize and automate this.
|
|
|
|
return combineBoth;
|
|
};
|