Compare commits
8 Commits
7a22b52c91
...
18daca904e
| Author | SHA1 | Date | |
|---|---|---|---|
| 18daca904e | |||
| e833c48cc8 | |||
| 0bd217c727 | |||
| 74974323f0 | |||
| f3c4c26ef9 | |||
| 74bcd6e805 | |||
| eb2c34c557 | |||
| 808e3d84ef |
@@ -1,8 +1,30 @@
|
||||
import {useEffect, useState} from "react";
|
||||
import {LstCard} from "../extendedUI/LstCard";
|
||||
import {CardContent, CardHeader} from "../ui/card";
|
||||
import {Skeleton} from "../ui/skeleton";
|
||||
import {Button} from "../ui/button";
|
||||
|
||||
export default function CycleCountLog() {
|
||||
const [logs, setLogs] = useState([]);
|
||||
const [streaming, setStreaming] = useState(false); // Track if streaming is active
|
||||
|
||||
useEffect(() => {
|
||||
// Start streaming when the button is clicked
|
||||
let es;
|
||||
|
||||
es = new EventSource("http://localhost:4000/api/logger/logs/stream?service=ocme-count&level=info");
|
||||
es.onopen = () => console.log(">>> Connection opened!");
|
||||
es.onerror = (e) => console.log("ERROR!", e);
|
||||
es.onmessage = (e) => {
|
||||
console.log(">>>", JSON.stringify(e));
|
||||
};
|
||||
|
||||
return () => es.close();
|
||||
}, []); // Effect runs when `streaming` state changes
|
||||
|
||||
const handleStartStreaming = () => {
|
||||
setStreaming(true); // Start streaming when button is clicked
|
||||
};
|
||||
return (
|
||||
<LstCard className="w-48">
|
||||
<CardHeader className="flex justify-center">
|
||||
@@ -17,6 +39,7 @@ export default function CycleCountLog() {
|
||||
</div>
|
||||
))}
|
||||
</CardContent>
|
||||
<Button onClick={handleStartStreaming}>Start Stream</Button>
|
||||
</LstCard>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -5,20 +5,88 @@ import {Input} from "../ui/input";
|
||||
import {Table, TableBody, TableCell, TableHead, TableHeader, TableRow} from "../ui/table";
|
||||
import {Skeleton} from "../ui/skeleton";
|
||||
import CycleCountLog from "./CycleCountLog";
|
||||
import {Select, SelectContent, SelectItem, SelectTrigger, SelectValue} from "../ui/select";
|
||||
import {Controller, useForm} from "react-hook-form";
|
||||
import axios from "axios";
|
||||
import {useState} from "react";
|
||||
|
||||
export default function OcmeCycleCount() {
|
||||
const token = localStorage.getItem("auth_token");
|
||||
const [data, setData] = useState([]);
|
||||
const [counting, setCounting] = useState(false);
|
||||
const {
|
||||
register,
|
||||
handleSubmit,
|
||||
//watch,
|
||||
formState: {errors},
|
||||
reset,
|
||||
control,
|
||||
} = useForm();
|
||||
|
||||
const onSubmit = async (data: any) => {
|
||||
setData([]);
|
||||
setCounting(true);
|
||||
toast.success(`Cycle count started`);
|
||||
try {
|
||||
const res = await axios.post("/ocme/api/v1/cyclecount", data, {
|
||||
headers: {Authorization: `Bearer ${token}`},
|
||||
});
|
||||
toast.success(res.data.message);
|
||||
setData(res.data.data);
|
||||
setCounting(false);
|
||||
reset();
|
||||
} catch (error) {
|
||||
toast.error("There was an error cycle counting");
|
||||
setCounting(false);
|
||||
reset();
|
||||
}
|
||||
};
|
||||
return (
|
||||
<div className="flex flex-row w-fill">
|
||||
<div className="flex flex-row w-screen">
|
||||
<div className="m-2 w-5/6">
|
||||
<LstCard>
|
||||
<p className="ml-2">Please enter the name or laneID you want to cycle count.</p>
|
||||
<div>
|
||||
<form>
|
||||
<form onSubmit={handleSubmit(onSubmit)}>
|
||||
<div className="flex justify-between">
|
||||
<div className="m-2">
|
||||
<Input placeholder="enter lane: L064" />
|
||||
<div className="m-2 flex flex-row">
|
||||
<Input
|
||||
placeholder="enter lane: L064"
|
||||
className={errors.lane ? "border-red-500" : ""}
|
||||
aria-invalid={!!errors.lane}
|
||||
{...register("lane", {
|
||||
required: true,
|
||||
minLength: {
|
||||
value: 3,
|
||||
message: "The lane is too short!",
|
||||
},
|
||||
})}
|
||||
/>
|
||||
<div className="ml-2">
|
||||
<Controller
|
||||
control={control}
|
||||
name="laneType"
|
||||
defaultValue={""}
|
||||
render={({
|
||||
field: {onChange},
|
||||
fieldState: {},
|
||||
//formState,
|
||||
}) => (
|
||||
<Select onValueChange={onChange}>
|
||||
<SelectTrigger className="w-[180px]">
|
||||
<SelectValue placeholder="Select name or id" />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
<SelectItem value="name">Name</SelectItem>
|
||||
<SelectItem value="laneId">Lane ID</SelectItem>
|
||||
</SelectContent>
|
||||
</Select>
|
||||
)}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
<Button className="m-2" onClick={() => toast.success("Cycle Count completed")}>
|
||||
CycleCount
|
||||
<Button className="m-2" type="submit" disabled={counting}>
|
||||
{counting ? <span>Counting...</span> : <span>CycleCount</span>}
|
||||
</Button>
|
||||
</div>
|
||||
</form>
|
||||
@@ -37,45 +105,81 @@ export default function OcmeCycleCount() {
|
||||
<TableHead>Result</TableHead>
|
||||
</TableRow>
|
||||
</TableHeader>
|
||||
<TableBody>
|
||||
{Array(10)
|
||||
.fill(0)
|
||||
.map((_, i) => (
|
||||
<TableRow key={i}>
|
||||
<TableCell className="font-medium">
|
||||
<Skeleton className="h-4" />
|
||||
</TableCell>
|
||||
<TableCell>
|
||||
<Skeleton className="h-4" />
|
||||
</TableCell>
|
||||
<TableCell>
|
||||
<Skeleton className="h-4" />
|
||||
</TableCell>
|
||||
<TableCell>
|
||||
<Skeleton className="h-4" />
|
||||
</TableCell>
|
||||
<TableCell>
|
||||
<Skeleton className="h-4" />
|
||||
</TableCell>
|
||||
<TableCell>
|
||||
<Skeleton className="h-4" />
|
||||
</TableCell>
|
||||
<TableCell>
|
||||
<Skeleton className="h-4" />
|
||||
</TableCell>
|
||||
<TableCell>
|
||||
<Skeleton className="h-4" />
|
||||
</TableCell>
|
||||
</TableRow>
|
||||
))}
|
||||
</TableBody>
|
||||
{data.length === 0 ? (
|
||||
<TableBody>
|
||||
{Array(10)
|
||||
.fill(0)
|
||||
.map((_, i) => (
|
||||
<TableRow key={i}>
|
||||
<TableCell className="font-medium">
|
||||
<Skeleton className="h-4" />
|
||||
</TableCell>
|
||||
<TableCell>
|
||||
<Skeleton className="h-4" />
|
||||
</TableCell>
|
||||
<TableCell>
|
||||
<Skeleton className="h-4" />
|
||||
</TableCell>
|
||||
<TableCell>
|
||||
<Skeleton className="h-4" />
|
||||
</TableCell>
|
||||
<TableCell>
|
||||
<Skeleton className="h-4" />
|
||||
</TableCell>
|
||||
<TableCell>
|
||||
<Skeleton className="h-4" />
|
||||
</TableCell>
|
||||
<TableCell>
|
||||
<Skeleton className="h-4" />
|
||||
</TableCell>
|
||||
<TableCell>
|
||||
<Skeleton className="h-4" />
|
||||
</TableCell>
|
||||
</TableRow>
|
||||
))}
|
||||
</TableBody>
|
||||
) : (
|
||||
<>
|
||||
{data.map((i: any) => {
|
||||
let classname = ``;
|
||||
if (i.info === "Quality Check Required") {
|
||||
classname = `bg-red-500`;
|
||||
}
|
||||
if (i.info === "Sent to Inv") {
|
||||
classname = `bg-amber-700`;
|
||||
}
|
||||
return (
|
||||
<TableRow key={i.runningNumber}>
|
||||
<TableCell className={`font-medium ${classname}`}>
|
||||
{i.alpla_laneID}
|
||||
</TableCell>
|
||||
<TableCell className={`font-medium ${classname}`}>
|
||||
{i.alpla_laneDescription}
|
||||
</TableCell>
|
||||
<TableCell className={`font-medium ${classname}`}>
|
||||
{i.Article}
|
||||
</TableCell>
|
||||
<TableCell className={`font-medium ${classname}`}>
|
||||
{i.alpla_laneDescription}
|
||||
</TableCell>
|
||||
<TableCell className={`font-medium ${classname}`}>
|
||||
{i.runningNumber}
|
||||
</TableCell>
|
||||
<TableCell className={`font-medium ${classname}`}>{i.ocme}</TableCell>
|
||||
<TableCell className={`font-medium ${classname}`}>{i.stock}</TableCell>
|
||||
<TableCell className={`font-medium ${classname}`}>{i.info}</TableCell>
|
||||
</TableRow>
|
||||
);
|
||||
})}
|
||||
</>
|
||||
)}
|
||||
</Table>
|
||||
</div>
|
||||
</LstCard>
|
||||
</div>
|
||||
<div className="m-2">
|
||||
{/* <div className="m-2">
|
||||
<CycleCountLog />
|
||||
</div>
|
||||
</div> */}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import {LstCard} from "@/components/extendedUI/LstCard";
|
||||
import {CardHeader} from "@/components/ui/card";
|
||||
|
||||
import {Skeleton} from "@/components/ui/skeleton";
|
||||
import {Table, TableBody, TableCell, TableHead, TableHeader, TableRow} from "@/components/ui/table";
|
||||
// import {useSessionStore} from "@/lib/store/sessionStore";
|
||||
@@ -17,7 +17,7 @@ const labelLogs = [
|
||||
//{key: "reprint", label: "Reprint"}, // removing the reprint button for now until repritning is working as intended
|
||||
];
|
||||
export default function LabelLog() {
|
||||
const {data, isError, error, isLoading} = useQuery(getlabels("4"));
|
||||
const {data, isError, isLoading} = useQuery(getlabels("4"));
|
||||
//const {user} = useSessionStore();
|
||||
//const {settings} = useSettingStore();
|
||||
//const server = settings.filter((n) => n.name === "server")[0]?.value || "";
|
||||
@@ -26,10 +26,42 @@ export default function LabelLog() {
|
||||
|
||||
if (isError) {
|
||||
return (
|
||||
<div>
|
||||
<div className="m-2 p-2 min-h-2/5">
|
||||
<LstCard>
|
||||
<CardHeader>There was an error loading the lots</CardHeader>
|
||||
{JSON.stringify(error)}
|
||||
<p className="text-center">Labels for the last 2 hours</p>
|
||||
<Table>
|
||||
<TableHeader>
|
||||
<TableRow>
|
||||
{labelLogs.map((l) => (
|
||||
<TableHead key={l.key}>{l.label}</TableHead>
|
||||
))}
|
||||
</TableRow>
|
||||
</TableHeader>
|
||||
|
||||
<TableBody>
|
||||
{Array(7)
|
||||
.fill(0)
|
||||
.map((_, i) => (
|
||||
<TableRow key={i}>
|
||||
<TableCell className="font-medium">
|
||||
<Skeleton className="h-4" />
|
||||
</TableCell>
|
||||
<TableCell>
|
||||
<Skeleton className="h-4" />
|
||||
</TableCell>
|
||||
<TableCell>
|
||||
<Skeleton className="h-4" />
|
||||
</TableCell>
|
||||
<TableCell>
|
||||
<Skeleton className="h-4" />
|
||||
</TableCell>
|
||||
<TableCell>
|
||||
<Skeleton className="h-4" />
|
||||
</TableCell>
|
||||
</TableRow>
|
||||
))}
|
||||
</TableBody>
|
||||
</Table>
|
||||
</LstCard>
|
||||
</div>
|
||||
);
|
||||
@@ -37,6 +69,7 @@ export default function LabelLog() {
|
||||
|
||||
return (
|
||||
<LstCard className="m-2 p-2 min-h-2/5">
|
||||
<p className="text-center">Labels for the last 2 hours</p>
|
||||
<Table>
|
||||
<TableHeader>
|
||||
<TableRow>
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import {LstCard} from "@/components/extendedUI/LstCard";
|
||||
import {CardHeader} from "@/components/ui/card";
|
||||
|
||||
import {Skeleton} from "@/components/ui/skeleton";
|
||||
import {Table, TableBody, TableCell, TableHead, TableHeader, TableRow} from "@/components/ui/table";
|
||||
import {useSessionStore} from "@/lib/store/sessionStore";
|
||||
@@ -57,7 +57,7 @@ let lotColumns = [
|
||||
// },
|
||||
];
|
||||
export default function Lots() {
|
||||
const {data, isError, error, isLoading} = useQuery(getlots());
|
||||
const {data, isError, isLoading} = useQuery(getlots());
|
||||
const {user} = useSessionStore();
|
||||
const {settings} = useSettingStore();
|
||||
const server = settings.filter((n) => n.name === "server")[0]?.value || "";
|
||||
@@ -82,10 +82,54 @@ export default function Lots() {
|
||||
|
||||
if (isError) {
|
||||
return (
|
||||
<div>
|
||||
<div className="m-2 p-2 min-h-2/5">
|
||||
<LstCard>
|
||||
<CardHeader>There was an error loading the lots</CardHeader>
|
||||
{JSON.stringify(error)}
|
||||
<p className="text-center">Current Assigned lots</p>
|
||||
<Table>
|
||||
<TableHeader>
|
||||
<TableRow>
|
||||
{lotColumns.map((l) => (
|
||||
<TableHead key={l.key}>{l.label}</TableHead>
|
||||
))}
|
||||
</TableRow>
|
||||
</TableHeader>
|
||||
|
||||
<TableBody>
|
||||
{Array(10)
|
||||
.fill(0)
|
||||
.map((_, i) => (
|
||||
<TableRow key={i}>
|
||||
<TableCell className="font-medium">
|
||||
<Skeleton className="h-4" />
|
||||
</TableCell>
|
||||
<TableCell>
|
||||
<Skeleton className="h-4" />
|
||||
</TableCell>
|
||||
<TableCell>
|
||||
<Skeleton className="h-4" />
|
||||
</TableCell>
|
||||
<TableCell>
|
||||
<Skeleton className="h-4" />
|
||||
</TableCell>
|
||||
<TableCell>
|
||||
<Skeleton className="h-4" />
|
||||
</TableCell>
|
||||
<TableCell>
|
||||
<Skeleton className="h-4" />
|
||||
</TableCell>
|
||||
<TableCell>
|
||||
<Skeleton className="h-4" />
|
||||
</TableCell>
|
||||
<TableCell>
|
||||
<Skeleton className="h-4" />
|
||||
</TableCell>
|
||||
<TableCell>
|
||||
<Skeleton className="h-4" />
|
||||
</TableCell>
|
||||
</TableRow>
|
||||
))}
|
||||
</TableBody>
|
||||
</Table>
|
||||
</LstCard>
|
||||
</div>
|
||||
);
|
||||
@@ -93,6 +137,7 @@ export default function Lots() {
|
||||
|
||||
return (
|
||||
<LstCard className="m-2 p-2 min-h-2/5">
|
||||
<p className="text-center">Current Assigned lots</p>
|
||||
<Table>
|
||||
<TableHeader>
|
||||
<TableRow>
|
||||
|
||||
@@ -1,5 +1,52 @@
|
||||
import {LstCard} from "@/components/extendedUI/LstCard";
|
||||
import {Skeleton} from "@/components/ui/skeleton";
|
||||
import {Table, TableBody, TableCell, TableHead, TableHeader, TableRow} from "@/components/ui/table";
|
||||
|
||||
let printerCols = [
|
||||
{
|
||||
key: "status",
|
||||
label: "Status",
|
||||
},
|
||||
{
|
||||
key: "printer",
|
||||
label: "Printer",
|
||||
},
|
||||
{
|
||||
key: "statusMessage",
|
||||
label: "Status Message",
|
||||
},
|
||||
];
|
||||
export default function PrinterStatus() {
|
||||
return <LstCard className="m-2 p-2">Printer Status</LstCard>;
|
||||
return (
|
||||
<LstCard className="m-2 p-2">
|
||||
<p className="text-center">Printer Status</p>
|
||||
<Table>
|
||||
<TableHeader>
|
||||
<TableRow>
|
||||
{printerCols.map((l) => (
|
||||
<TableHead key={l.key}>{l.label}</TableHead>
|
||||
))}
|
||||
</TableRow>
|
||||
</TableHeader>
|
||||
|
||||
<TableBody>
|
||||
{Array(10)
|
||||
.fill(0)
|
||||
.map((_, i) => (
|
||||
<TableRow key={i}>
|
||||
<TableCell className="font-medium">
|
||||
<Skeleton className="h-4" />
|
||||
</TableCell>
|
||||
<TableCell>
|
||||
<Skeleton className="h-4" />
|
||||
</TableCell>
|
||||
<TableCell>
|
||||
<Skeleton className="h-4" />
|
||||
</TableCell>
|
||||
</TableRow>
|
||||
))}
|
||||
</TableBody>
|
||||
</Table>
|
||||
</LstCard>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -19,6 +19,7 @@ export default defineConfig({
|
||||
server: {
|
||||
proxy: {
|
||||
"/api": {target: `http://localhost:${Number(process.env.VITE_SERVER_PORT || 4400)}`, changeOrigin: true},
|
||||
"/ocme": {target: `http://localhost:${Number(process.env.VITE_SERVER_PORT || 4400)}`, changeOrigin: true},
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
@@ -73,7 +73,7 @@
|
||||
}
|
||||
},
|
||||
"admConfig": {
|
||||
"build": 43,
|
||||
"build": 44,
|
||||
"oldBuild": "backend-0.1.3.zip"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
3
server/globalUtils/delay.ts
Normal file
3
server/globalUtils/delay.ts
Normal file
@@ -0,0 +1,3 @@
|
||||
export const delay = (ms: number) => {
|
||||
return new Promise((resolve) => setTimeout(resolve, ms));
|
||||
};
|
||||
@@ -43,7 +43,7 @@ app.use(
|
||||
origin: "*", // Allow all origins
|
||||
allowHeaders: ["Content-Type", "Authorization", "X-Requested-With"],
|
||||
allowMethods: ["GET", "POST", "PUT", "DELETE", "OPTIONS", "PATCH"],
|
||||
exposeHeaders: ["Content-Length", "X-Kuma-Revision"],
|
||||
//exposeHeaders: ["Content-Length", "X-Kuma-Revision"],
|
||||
credentials: true, // Allow credentials if needed
|
||||
maxAge: 600,
|
||||
})
|
||||
|
||||
@@ -127,4 +127,11 @@ INSERT INTO "users" ("username", "email", "role", "password") VALUES
|
||||
('brandon001','brandon.harry@alpla.com','manager','wdm1RSXJlZnJDYTZP');
|
||||
;
|
||||
```
|
||||
* You could have many users and just add like above with the identical info from the db
|
||||
* You could have many users and just add like above with the identical info from the db
|
||||
|
||||
|
||||
## Running v1 along Side V2 for the interm
|
||||
* change v2 prod port to 4000 in the env and db
|
||||
* change v1 env to 4400 in the env. and in the db you will need to change the auth server to 4000 and the serverPort to 4400
|
||||
|
||||
This will change so that v2 is the main server now, this is needed for ocme mainly.
|
||||
29
server/services/logger/controller/streamLogs.ts
Normal file
29
server/services/logger/controller/streamLogs.ts
Normal file
@@ -0,0 +1,29 @@
|
||||
import type {Context} from "hono";
|
||||
import {db} from "../../../../database/dbclient.js";
|
||||
import {and, eq, gt} from "drizzle-orm";
|
||||
import {streamSSE} from "hono/streaming";
|
||||
import {logs} from "../../../../database/schema/logs.js";
|
||||
|
||||
export async function streamLogs(c: Context) {
|
||||
let id = 0;
|
||||
let running = true;
|
||||
// c.header("Content-Type", "text/event-stream");
|
||||
// c.header("Cache-Control", "no-cache");
|
||||
// c.header("Connection", "keep-alive");
|
||||
|
||||
const getLogs = async () => {};
|
||||
return streamSSE(c, async (stream) => {
|
||||
while (running) {
|
||||
const message = `It is ${new Date().toISOString()}`;
|
||||
await stream.writeSSE({
|
||||
data: message,
|
||||
event: "time-update",
|
||||
id: String(id++),
|
||||
});
|
||||
await stream.sleep(1000);
|
||||
if (id === 5) {
|
||||
running = false;
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -8,6 +8,15 @@ type Log = {
|
||||
level: string;
|
||||
msg: string;
|
||||
};
|
||||
|
||||
const pinoLogLevels: any = {
|
||||
10: "trace",
|
||||
20: "debug",
|
||||
30: "info",
|
||||
40: "warn",
|
||||
50: "error",
|
||||
60: "fatal",
|
||||
};
|
||||
// Create a custom transport function
|
||||
export default async function (log: Log) {
|
||||
//const {username, service, level, msg, ...extra} = log;
|
||||
@@ -15,8 +24,11 @@ export default async function (log: Log) {
|
||||
return build(async function (source) {
|
||||
for await (let obj of source) {
|
||||
// Insert log entry into the PostgreSQL database using Drizzle ORM
|
||||
|
||||
// convert to the name to make it more easy to find later :P
|
||||
const levelName = pinoLogLevels[obj.level] || "unknown";
|
||||
await db.insert(logs).values({
|
||||
level: obj.level,
|
||||
level: levelName,
|
||||
username: obj?.username.toLowerCase(),
|
||||
service: obj?.service.toLowerCase(),
|
||||
message: obj.msg,
|
||||
|
||||
@@ -7,10 +7,11 @@ import {settings} from "../../../database/schema/settings.js";
|
||||
import {logCleanup} from "./controller/logCleanup.js";
|
||||
import createNewLog from "./routes/createLog.js";
|
||||
import getLogs from "./routes/getLogs.js";
|
||||
import stream from "./routes/streamLogs.js";
|
||||
|
||||
const app = new OpenAPIHono();
|
||||
|
||||
const routes = [clearLog, createNewLog, getLogs] as const;
|
||||
const routes = [clearLog, createNewLog, getLogs, stream] as const;
|
||||
const setting = await db.select().from(settings);
|
||||
|
||||
const appRoutes = routes.forEach((route) => {
|
||||
|
||||
35
server/services/logger/routes/streamLogs.ts
Normal file
35
server/services/logger/routes/streamLogs.ts
Normal file
@@ -0,0 +1,35 @@
|
||||
// an external way to creating logs
|
||||
//@ts-nocheck
|
||||
import {createRoute, OpenAPIHono, z} from "@hono/zod-openapi";
|
||||
import {apiHit} from "../../../globalUtils/apiHits.js";
|
||||
import {responses} from "../../../globalUtils/routeDefs/responses.js";
|
||||
import {createLog} from "../logger.js";
|
||||
import {getLogs} from "../controller/getLogs.js";
|
||||
import {streamLogs} from "../controller/streamLogs.js";
|
||||
import {streamSSE} from "hono/streaming";
|
||||
|
||||
const app = new OpenAPIHono({strict: false});
|
||||
|
||||
app.openapi(
|
||||
createRoute({
|
||||
tags: ["server:logger"],
|
||||
summary: "Streams the logs to the frontend.",
|
||||
method: "get",
|
||||
path: "/logs/stream",
|
||||
description: "This should only be used on the event you need to monitor logs.",
|
||||
|
||||
responses: {
|
||||
200: {
|
||||
content: {
|
||||
"application/json": {schema: z.object({message: z.string().optional()})},
|
||||
},
|
||||
description: "Response message",
|
||||
},
|
||||
},
|
||||
}),
|
||||
async (c) => {
|
||||
apiHit(c, {endpoint: `api/logger/logs`});
|
||||
return streamLogs(c);
|
||||
}
|
||||
);
|
||||
export default app;
|
||||
@@ -1,6 +1,7 @@
|
||||
import type {User} from "../../../types/users.js";
|
||||
import {alplaStockInv} from "./cycleCount/alplaStockInventory.js";
|
||||
import {emptyCount} from "./cycleCount/emptyCycleCount.js";
|
||||
import {fullLaneCount} from "./cycleCount/fullLaneCycleCount.js";
|
||||
import {ocmeInv} from "./cycleCount/ocmeInventory.js";
|
||||
|
||||
export const prepareLane = "https://usday1prod.alpla.net/application/public/v1.1/Warehousing/PrepareLaneForInventory";
|
||||
@@ -8,7 +9,7 @@ export const openLane = "https://usday1prod.alpla.net/application/public/v1.0/Wa
|
||||
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) => {
|
||||
export const cycleCount = async (lane: any, 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.
|
||||
@@ -21,7 +22,7 @@ export const cycleCount = async (lane: string, user: User) => {
|
||||
const alplaStock = await alplaStockInv(ocme[0].alpla_laneID);
|
||||
|
||||
// create a new array that has the merge happen.
|
||||
const mergeOcmeData = ocme.map((d) => {
|
||||
const mergeOcmeData = ocme.map((d: any) => {
|
||||
// check if its in the ocme array we add it
|
||||
const inStock = alplaStock.filter((r: any) => r.runningNumber === d.runningNumber);
|
||||
//console.log(inStock);
|
||||
@@ -52,9 +53,10 @@ export const cycleCount = async (lane: string, user: User) => {
|
||||
// determine what type of count we are doing.
|
||||
if (ocme.length === 0) {
|
||||
// do empty count
|
||||
await emptyCount(user, lane);
|
||||
await emptyCount(user, ocme[0].alpla_laneID);
|
||||
} else {
|
||||
// do the full lane inv
|
||||
await fullLaneCount(user, ocme[0].alpla_laneID, ocme);
|
||||
}
|
||||
|
||||
// store in the db so we have a record.... for later when we fully randomize and automate this.
|
||||
|
||||
@@ -0,0 +1,126 @@
|
||||
// full lane count
|
||||
import axios from "axios";
|
||||
import {delay} from "../../../../globalUtils/delay.js";
|
||||
import {createLog} from "../../../logger/logger.js";
|
||||
import {openLane, prepareLane, scannerID} from "../cycleCount.js";
|
||||
import type {User} from "../../../../types/users.js";
|
||||
|
||||
let delayTime = 100;
|
||||
|
||||
export const fullLaneCount = async (user: User, lane: string, ocmeLanes: any) => {
|
||||
// prepare the lane.
|
||||
try {
|
||||
const openlane = await axios({
|
||||
method: "POST",
|
||||
url: prepareLane,
|
||||
headers: {
|
||||
Authorization: `Basic ${user.prod}`,
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
data: {
|
||||
scannerId: scannerID,
|
||||
laneId: lane,
|
||||
},
|
||||
});
|
||||
|
||||
createLog("info", user.username!, "ocme-count", openlane.data.message);
|
||||
try {
|
||||
const open = await axios({
|
||||
method: "POST",
|
||||
url: openLane,
|
||||
headers: {
|
||||
Authorization: `Basic ${user.prod}`,
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
data: {
|
||||
scannerId: scannerID,
|
||||
laneId: lane,
|
||||
},
|
||||
});
|
||||
|
||||
createLog("info", user.username!, "ocme-count", open.data.Message);
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
}
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
}
|
||||
|
||||
// do the inv
|
||||
|
||||
for (let i = 0; i < ocmeLanes.length; i++) {
|
||||
const count = {
|
||||
scannerId: scannerID,
|
||||
sscc: ocmeLanes[i].sscc,
|
||||
};
|
||||
//createLog("cyclecounting", "info", `Processing running: ${ocmeLanes[i].runningNumber}`);
|
||||
await delay(delayTime);
|
||||
|
||||
try {
|
||||
const openLane = await axios({
|
||||
method: "POST",
|
||||
url: "https://usday1prod.alpla.net/application/public/v1.0/Warehousing/InventoryCount",
|
||||
headers: {
|
||||
Authorization: `Basic ${user.prod}`,
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
data: count,
|
||||
});
|
||||
|
||||
createLog(
|
||||
"info",
|
||||
user.username!,
|
||||
"ocme-count",
|
||||
`${openLane.data.Message} on running: ${ocmeLanes[i].runningNumber}`
|
||||
);
|
||||
await delay(delayTime);
|
||||
} catch (error) {
|
||||
createLog("error", user.username!, "ocme-count", `${error}`);
|
||||
}
|
||||
}
|
||||
|
||||
// close the count
|
||||
// close the order
|
||||
try {
|
||||
const openLane = await axios({
|
||||
method: "POST",
|
||||
url: "https://usday1prod.alpla.net/application/public/v1.0/Warehousing/InventoryClose",
|
||||
headers: {
|
||||
Authorization: `Basic ${user.prod}`,
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
data: {
|
||||
scannerId: scannerID,
|
||||
laneId: lane,
|
||||
},
|
||||
});
|
||||
|
||||
createLog("info", user.username!, "ocme-count", openLane.data.Message);
|
||||
|
||||
if (openLane.data.Result === 0) {
|
||||
//release the lane
|
||||
//----------------------------------------------------
|
||||
try {
|
||||
const openLane = await axios({
|
||||
method: "POST",
|
||||
url: "https://usday1prod.alpla.net/application/public/v1.1/Warehousing/ReleaseLaneFromInventory",
|
||||
headers: {
|
||||
Authorization: `Basic ${user.prod}`,
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
data: {
|
||||
laneId: lane,
|
||||
},
|
||||
});
|
||||
|
||||
createLog("info", user.username!, "ocme-count", openLane.data.message);
|
||||
} catch (error) {
|
||||
createLog("error", user.username!, "ocme-count", `${error}`);
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
createLog("error", user.username!, "ocme-count", `${error}`);
|
||||
}
|
||||
|
||||
return {success: true, message: `Lane completed`};
|
||||
};
|
||||
|
||||
@@ -1,284 +1,16 @@
|
||||
import axios from "axios";
|
||||
const data = [
|
||||
{
|
||||
ocme_laneLevelID: "P3F36PZ1PN1",
|
||||
alpla_laneID: "30285 ",
|
||||
alpla_laneDescription: "L064",
|
||||
Article: "146",
|
||||
description: "HDPE Trigger 16oz White",
|
||||
sscc: "090103830005256402",
|
||||
runningNumber: "525640",
|
||||
},
|
||||
{
|
||||
ocme_laneLevelID: "P3F36PZ1PN2",
|
||||
alpla_laneID: "30285 ",
|
||||
alpla_laneDescription: "L064",
|
||||
Article: "146",
|
||||
description: "HDPE Trigger 16oz White",
|
||||
sscc: "090103830005402649",
|
||||
runningNumber: "540264",
|
||||
},
|
||||
{
|
||||
ocme_laneLevelID: "P3F36PZ1PN3",
|
||||
alpla_laneID: "30285 ",
|
||||
alpla_laneDescription: "L064",
|
||||
Article: "146",
|
||||
description: "HDPE Trigger 16oz White",
|
||||
sscc: "090103830005312559",
|
||||
runningNumber: "531255",
|
||||
},
|
||||
{
|
||||
ocme_laneLevelID: "P3F36PZ1PN4",
|
||||
alpla_laneID: "30285 ",
|
||||
alpla_laneDescription: "L064",
|
||||
Article: "146",
|
||||
description: "HDPE Trigger 16oz White",
|
||||
sscc: "090103830005312658",
|
||||
runningNumber: "531265",
|
||||
},
|
||||
{
|
||||
ocme_laneLevelID: "P3F36PZ2PN1",
|
||||
alpla_laneID: "30285 ",
|
||||
alpla_laneDescription: "L064",
|
||||
Article: "146",
|
||||
description: "HDPE Trigger 16oz White",
|
||||
sscc: "090103830005404186",
|
||||
runningNumber: "540418",
|
||||
},
|
||||
{
|
||||
ocme_laneLevelID: "P3F36PZ2PN2",
|
||||
alpla_laneID: "30285 ",
|
||||
alpla_laneDescription: "L064",
|
||||
Article: "146",
|
||||
description: "HDPE Trigger 16oz White",
|
||||
sscc: "090103830005404193",
|
||||
runningNumber: "540419",
|
||||
},
|
||||
{
|
||||
ocme_laneLevelID: "P3F36PZ2PN3",
|
||||
alpla_laneID: "30285 ",
|
||||
alpla_laneDescription: "L064",
|
||||
Article: "146",
|
||||
description: "HDPE Trigger 16oz White",
|
||||
sscc: "090103830005404155",
|
||||
runningNumber: "540415",
|
||||
},
|
||||
{
|
||||
ocme_laneLevelID: "P3F36PZ2PN4",
|
||||
alpla_laneID: "30285 ",
|
||||
alpla_laneDescription: "L064",
|
||||
Article: "146",
|
||||
description: "HDPE Trigger 16oz White",
|
||||
sscc: "090103830005404230",
|
||||
runningNumber: "540423",
|
||||
},
|
||||
{
|
||||
ocme_laneLevelID: "P3F36PZ3PN1",
|
||||
alpla_laneID: "30285 ",
|
||||
alpla_laneDescription: "L064",
|
||||
Article: "146",
|
||||
description: "HDPE Trigger 16oz White",
|
||||
sscc: "090103830005306589",
|
||||
runningNumber: "530658",
|
||||
},
|
||||
{
|
||||
ocme_laneLevelID: "P3F36PZ3PN2",
|
||||
alpla_laneID: "30285 ",
|
||||
alpla_laneDescription: "L064",
|
||||
Article: "164",
|
||||
description: "HDPE Trigger 16oz Orange",
|
||||
sscc: "090103830005408634",
|
||||
runningNumber: "540841",
|
||||
},
|
||||
{
|
||||
ocme_laneLevelID: "P3F36PZ3PN3",
|
||||
alpla_laneID: "30285 ",
|
||||
alpla_laneDescription: "L064",
|
||||
Article: "164",
|
||||
description: "HDPE Trigger 16oz Orange",
|
||||
sscc: "090103830005836888",
|
||||
runningNumber: "583688",
|
||||
},
|
||||
{
|
||||
ocme_laneLevelID: "P3F36PZ3PN4",
|
||||
alpla_laneID: "30285 ",
|
||||
alpla_laneDescription: "L064",
|
||||
Article: "164",
|
||||
description: "HDPE Trigger 16oz Orange",
|
||||
sscc: "090103830005836871",
|
||||
runningNumber: "583687",
|
||||
},
|
||||
{
|
||||
ocme_laneLevelID: "P3F36PZ4PN1",
|
||||
alpla_laneID: "30285 ",
|
||||
alpla_laneDescription: "L064",
|
||||
Article: "164",
|
||||
description: "HDPE Trigger 16oz Orange",
|
||||
sscc: "090103830005845279",
|
||||
runningNumber: "584527",
|
||||
},
|
||||
{
|
||||
ocme_laneLevelID: "P3F36PZ4PN2",
|
||||
alpla_laneID: "30285 ",
|
||||
alpla_laneDescription: "L064",
|
||||
Article: "164",
|
||||
description: "HDPE Trigger 16oz Orange",
|
||||
sscc: "090103830005845231",
|
||||
runningNumber: "584523",
|
||||
},
|
||||
{
|
||||
ocme_laneLevelID: "P3F36PZ4PN3",
|
||||
alpla_laneID: "30285 ",
|
||||
alpla_laneDescription: "L064",
|
||||
Article: "164",
|
||||
description: "HDPE Trigger 16oz Orange",
|
||||
sscc: "090103830005845170",
|
||||
runningNumber: "584517",
|
||||
},
|
||||
{
|
||||
ocme_laneLevelID: "P3F36PZ4PN4",
|
||||
alpla_laneID: "30285 ",
|
||||
alpla_laneDescription: "L064",
|
||||
Article: "164",
|
||||
description: "HDPE Trigger 16oz Orange",
|
||||
sscc: "090103830005845156",
|
||||
runningNumber: "584515",
|
||||
},
|
||||
{
|
||||
ocme_laneLevelID: "P3F36PZ5PN1",
|
||||
alpla_laneID: "30285 ",
|
||||
alpla_laneDescription: "L064",
|
||||
Article: "164",
|
||||
description: "HDPE Trigger 16oz Orange",
|
||||
sscc: "090103830005870325",
|
||||
runningNumber: "587032",
|
||||
},
|
||||
{
|
||||
ocme_laneLevelID: "P3F36PZ5PN2",
|
||||
alpla_laneID: "30285 ",
|
||||
alpla_laneDescription: "L064",
|
||||
Article: "164",
|
||||
description: "HDPE Trigger 16oz Orange",
|
||||
sscc: "090103830005871490",
|
||||
runningNumber: "587149",
|
||||
},
|
||||
{
|
||||
ocme_laneLevelID: "P3F36PZ5PN3",
|
||||
alpla_laneID: "30285 ",
|
||||
alpla_laneDescription: "L064",
|
||||
Article: "164",
|
||||
description: "HDPE Trigger 16oz Orange",
|
||||
sscc: "090103830005851782",
|
||||
runningNumber: "585178",
|
||||
},
|
||||
{
|
||||
ocme_laneLevelID: "P3F36PZ5PN4",
|
||||
alpla_laneID: "30285 ",
|
||||
alpla_laneDescription: "L064",
|
||||
Article: "164",
|
||||
description: "HDPE Trigger 16oz Orange",
|
||||
sscc: "090103830005855339",
|
||||
runningNumber: "585533",
|
||||
},
|
||||
{
|
||||
ocme_laneLevelID: "P3F36PZ6PN1",
|
||||
alpla_laneID: "30285 ",
|
||||
alpla_laneDescription: "L064",
|
||||
Article: "164",
|
||||
description: "HDPE Trigger 16oz Orange",
|
||||
sscc: "090103830005867660",
|
||||
runningNumber: "586766",
|
||||
},
|
||||
{
|
||||
ocme_laneLevelID: "P3F36PZ6PN2",
|
||||
alpla_laneID: "30285 ",
|
||||
alpla_laneDescription: "L064",
|
||||
Article: "164",
|
||||
description: "HDPE Trigger 16oz Orange",
|
||||
sscc: "090103830005867622",
|
||||
runningNumber: "586762",
|
||||
},
|
||||
{
|
||||
ocme_laneLevelID: "P3F36PZ6PN3",
|
||||
alpla_laneID: "30285 ",
|
||||
alpla_laneDescription: "L064",
|
||||
Article: "164",
|
||||
description: "HDPE Trigger 16oz Orange",
|
||||
sscc: "090103830005865871",
|
||||
runningNumber: "586587",
|
||||
},
|
||||
{
|
||||
ocme_laneLevelID: "P3F36PZ6PN4",
|
||||
alpla_laneID: "30285 ",
|
||||
alpla_laneDescription: "L064",
|
||||
Article: "164",
|
||||
description: "HDPE Trigger 16oz Orange",
|
||||
sscc: "090103830005865895",
|
||||
runningNumber: "586589",
|
||||
},
|
||||
{
|
||||
ocme_laneLevelID: "P3F36PZ7PN1",
|
||||
alpla_laneID: "30285 ",
|
||||
alpla_laneDescription: "L064",
|
||||
Article: "164",
|
||||
description: "HDPE Trigger 16oz Orange",
|
||||
sscc: "090103830005866052",
|
||||
runningNumber: "586605",
|
||||
},
|
||||
{
|
||||
ocme_laneLevelID: "P3F36PZ7PN2",
|
||||
alpla_laneID: "30285 ",
|
||||
alpla_laneDescription: "L064",
|
||||
Article: "164",
|
||||
description: "HDPE Trigger 16oz Orange",
|
||||
sscc: "090103830005865970",
|
||||
runningNumber: "586597",
|
||||
},
|
||||
{
|
||||
ocme_laneLevelID: "P3F36PZ7PN3",
|
||||
alpla_laneID: "30285 ",
|
||||
alpla_laneDescription: "L064",
|
||||
Article: "164",
|
||||
description: "HDPE Trigger 16oz Orange",
|
||||
sscc: "090103830005877089",
|
||||
runningNumber: "587708",
|
||||
},
|
||||
{
|
||||
ocme_laneLevelID: "P3F36PZ8PN1",
|
||||
alpla_laneID: "30285 ",
|
||||
alpla_laneDescription: "L064",
|
||||
Article: "164",
|
||||
description: "HDPE Trigger 16oz Orange",
|
||||
sscc: "090103830005844975",
|
||||
runningNumber: "584497",
|
||||
},
|
||||
{
|
||||
ocme_laneLevelID: "P3F36PZ8PN2",
|
||||
alpla_laneID: "30285 ",
|
||||
alpla_laneDescription: "L064",
|
||||
Article: "164",
|
||||
description: "HDPE Trigger 16oz Orange",
|
||||
sscc: "090103830005844944",
|
||||
runningNumber: "584494",
|
||||
},
|
||||
{
|
||||
ocme_laneLevelID: "P3F36PZ8PN3",
|
||||
alpla_laneID: "30285 ",
|
||||
alpla_laneDescription: "L064",
|
||||
Article: "164",
|
||||
description: "HDPE Trigger 16oz Orange",
|
||||
sscc: "090103830005844890",
|
||||
runningNumber: "584489",
|
||||
},
|
||||
];
|
||||
export const ocmeInv = async (lane: string) => {
|
||||
try {
|
||||
const res = await axios.post("http://usday1vms010:3250/api/v1/getLaneData", {lane: lane});
|
||||
console.log(res.data);
|
||||
|
||||
return data;
|
||||
export const ocmeInv = async (data: any) => {
|
||||
try {
|
||||
const res = await axios.post(
|
||||
"http://usday1vms010:3250/api/v1/getLaneData",
|
||||
{lane: data.lane, laneType: data.laneType},
|
||||
{headers: {"Content-Type": "application/json", Connection: "keep-alive"}}
|
||||
);
|
||||
// console.log(res.data.data);
|
||||
|
||||
return res.data.data;
|
||||
} catch (error: any) {
|
||||
console.log(error.code);
|
||||
return data;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -12,7 +12,14 @@
|
||||
|
||||
// // add the lane in so we dont crash
|
||||
// if(req.body.lane){
|
||||
// filterdOCMELane = ocmeInventory.replaceAll('[lane]', data.lane)
|
||||
// if(data.laneType === "laneID"){
|
||||
// get the mapped lane id
|
||||
// where alpla_laneID = 30286
|
||||
// filterdOCMELane = ocmeInventory.replaceAll("where alpla_laneDescription = '[lane]'", `where alpla_laneID = ${data.lane}`)
|
||||
|
||||
// } else {
|
||||
// filterdOCMELane = ocmeInventory.replaceAll('[lane]', data.lane)
|
||||
// }
|
||||
// // get lanes
|
||||
// const laneData = await runQuery(filterdOCMELane, 'Getting current ocme lanes linked')
|
||||
// res.status(200).json({success: true,message: `All current lanes from the ocme system.`, totalpallets: laneData.length,data: laneData})
|
||||
|
||||
Reference in New Issue
Block a user