Compare commits
7 Commits
85577b291f
...
51cc4aa370
| Author | SHA1 | Date | |
|---|---|---|---|
| 51cc4aa370 | |||
| 95bebbde2b | |||
| 85e3d46b2e | |||
| 525de7dab2 | |||
| 1956ee313a | |||
| 536899b6e7 | |||
| d9e60451f8 |
1
.gitignore
vendored
1
.gitignore
vendored
@@ -10,6 +10,7 @@ backend-0.1.2-217.zip
|
||||
backend-0.1.2-218.zip
|
||||
backend-0.1.2.zip
|
||||
postgresql-17.2-3-windows-x64.exe
|
||||
jsTesting
|
||||
|
||||
|
||||
# ---> Node
|
||||
|
||||
34
CHANGELOG.md
34
CHANGELOG.md
@@ -1,5 +1,39 @@
|
||||
# All CHanges to LST can be found below.
|
||||
|
||||
## [2.13.0](https://git.tuffraid.net/cowch/lstV2/compare/v2.12.0...v2.13.0) (2025-04-05)
|
||||
|
||||
|
||||
### 📝 Chore
|
||||
|
||||
* **release:** bump build number to 148 ([2cc81a5](https://git.tuffraid.net/cowch/lstV2/commits/2cc81a5b07e6a31b6c7612bc8393b3e0614442fd))
|
||||
|
||||
|
||||
### 🐛 Bug fixes
|
||||
|
||||
* **database:** correction to the printer modules ([8194798](https://git.tuffraid.net/cowch/lstV2/commits/8194798a3764d44abd7c1aef452ae2f4c8c100e9))
|
||||
* **datamart:** added some fixed some ([5eacbb5](https://git.tuffraid.net/cowch/lstV2/commits/5eacbb5ecfe23ed9ac023649864d2d0a506dc657))
|
||||
* **tcp:** added in a catch if ocme is not active and we dont have a zebra camera ([b9397c0](https://git.tuffraid.net/cowch/lstV2/commits/b9397c029f3c597d755c5b3ab3027dda2dfc0ef2))
|
||||
|
||||
|
||||
### 🛠️ Code Refactor
|
||||
|
||||
* **materials:** moved for better sturcture ([99477ba](https://git.tuffraid.net/cowch/lstV2/commits/99477bac1974da3a0937b4244815a839416eaf40))
|
||||
|
||||
|
||||
### 📝 Testing Code
|
||||
|
||||
* **frontend:** work on the frontend to have better admin ([ad5e770](https://git.tuffraid.net/cowch/lstV2/commits/ad5e77028d59c31405df6cc17fc0c8084dddad5a))
|
||||
* **ocp:** working on more migrations ([9f26f23](https://git.tuffraid.net/cowch/lstV2/commits/9f26f2334f0bcae3ca26acd240ed9b638fe88b03))
|
||||
|
||||
|
||||
### 🌟 Enhancements
|
||||
|
||||
* **notificaitons:** fixed and corrections to get them working properly ([a7818b4](https://git.tuffraid.net/cowch/lstV2/commits/a7818b4ca3bf2df530e3e7df8ec389bf4f5ebc5a))
|
||||
* **siloadjustments:** added email for comments :D ([f1abe7b](https://git.tuffraid.net/cowch/lstV2/commits/f1abe7b33d7b390ee54bc0fa5bd4c39c156f4f05))
|
||||
* **submodules and login redirect:** submodules added and login redirect ([85577b2](https://git.tuffraid.net/cowch/lstV2/commits/85577b291f60744749abfd815efd6feceb393478))
|
||||
* **submodules:** to help with submodules of course ([e1973e4](https://git.tuffraid.net/cowch/lstV2/commits/e1973e4da659948e6d49f6f5d162a8b2fb8e512d))
|
||||
* **update all:** added a new function to update all servers in a row. easier to walk away ([8b5698a](https://git.tuffraid.net/cowch/lstV2/commits/8b5698a8391260fcc400117562668434bbc9e8af))
|
||||
|
||||
## [2.12.0](https://git.tuffraid.net/cowch/lstV2/compare/v2.11.0...v2.12.0) (2025-04-03)
|
||||
|
||||
|
||||
|
||||
@@ -24,7 +24,7 @@ export const printerData = pgTable(
|
||||
lastTimePrinted: timestamp("lastTimePrinted").notNull().defaultNow(),
|
||||
assigned: boolean("assigned").default(false),
|
||||
remark: text("remark"),
|
||||
printDelay: numeric("printDelay"),
|
||||
printDelay: numeric("printDelay").default("90"),
|
||||
monitorState: boolean("monitorState").default(false),
|
||||
add_Date: timestamp("add_Date").defaultNow(),
|
||||
upd_date: timestamp("upd_date").defaultNow(),
|
||||
|
||||
@@ -82,7 +82,7 @@ export function LogisticsSideBar({
|
||||
const { subModules } = useSubModuleStore();
|
||||
|
||||
const items = subModules.filter((m) => m.moduleName === "logistics");
|
||||
console.log(items);
|
||||
//console.log(items);
|
||||
return (
|
||||
<SidebarGroup>
|
||||
<SidebarGroupLabel>Logistics</SidebarGroupLabel>
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
import { LstCard } from "@/components/extendedUI/LstCard";
|
||||
import { CardHeader } from "@/components/ui/card";
|
||||
|
||||
export default function SiloCard(data: any) {
|
||||
const silo = data.silo;
|
||||
return (
|
||||
<LstCard>
|
||||
<CardHeader>{silo.Description}</CardHeader>
|
||||
<div>
|
||||
<hr />
|
||||
</div>
|
||||
</LstCard>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
import { getStockSilo } from "@/utils/querys/logistics/siloAdjustments/getStockSilo";
|
||||
import { useQuery } from "@tanstack/react-query";
|
||||
import SiloCard from "./SiloCard";
|
||||
|
||||
export default function SiloPage() {
|
||||
const { data, isError, error, isLoading } = useQuery(getStockSilo());
|
||||
|
||||
if (isLoading) return;
|
||||
|
||||
if (isError) return;
|
||||
|
||||
if (error)
|
||||
return (
|
||||
<div>
|
||||
{" "}
|
||||
There was an error getting the silos please notify your admin if
|
||||
this continues to be an issue
|
||||
</div>
|
||||
);
|
||||
|
||||
return (
|
||||
<div className="flex flex-row gap-2">
|
||||
{data?.map((s: any) => <SiloCard silo={s} />)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -1,9 +1,28 @@
|
||||
import { createFileRoute } from '@tanstack/react-router'
|
||||
import SiloPage from "@/components/logistics/siloAdjustments/SiloPage";
|
||||
import { createFileRoute, redirect } from "@tanstack/react-router";
|
||||
|
||||
export const Route = createFileRoute('/(logistics)/siloAdjustments/')({
|
||||
component: RouteComponent,
|
||||
})
|
||||
export const Route = createFileRoute("/(logistics)/siloAdjustments/")({
|
||||
component: RouteComponent,
|
||||
beforeLoad: async () => {
|
||||
const auth = localStorage.getItem("auth_token");
|
||||
if (!auth) {
|
||||
throw redirect({
|
||||
to: "/login",
|
||||
search: {
|
||||
// Use the current location to power a redirect after login
|
||||
// (Do not use `router.state.resolvedLocation` as it can
|
||||
// potentially lag behind the actual current location)
|
||||
redirect: location.pathname + location.search,
|
||||
},
|
||||
});
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
function RouteComponent() {
|
||||
return <div>Hello "/(logistics)/siloAdjustments/"!</div>
|
||||
return (
|
||||
<div>
|
||||
<SiloPage />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
import { queryOptions } from "@tanstack/react-query";
|
||||
import axios from "axios";
|
||||
|
||||
export function getStockSilo() {
|
||||
const token = localStorage.getItem("auth_token");
|
||||
return queryOptions({
|
||||
queryKey: ["getUsers"],
|
||||
queryFn: () => fetchStockSilo(token),
|
||||
enabled: !!token, // Prevents query if token is null
|
||||
staleTime: 1000,
|
||||
//refetchInterval: 2 * 2000,
|
||||
refetchOnWindowFocus: true,
|
||||
});
|
||||
}
|
||||
|
||||
const fetchStockSilo = async (token: string | null) => {
|
||||
const { data } = await axios.get(`/api/logistics/getstocksilo`, {
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
Authorization: `Bearer ${token}`,
|
||||
},
|
||||
});
|
||||
// if we are not localhost ignore the devDir setting.
|
||||
//const url: string = window.location.host.split(":")[0];
|
||||
return data.data ?? [];
|
||||
};
|
||||
18040
package-lock.json
generated
18040
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "lstv2",
|
||||
"version": "2.12.0",
|
||||
"version": "2.13.0",
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"dev": "concurrently -n \"server,frontend\" -c \"#007755,#2f6da3\" \"npm run dev:server\" \"cd frontend && npm run dev\"",
|
||||
@@ -35,7 +35,7 @@
|
||||
}
|
||||
},
|
||||
"admConfig": {
|
||||
"build": 169,
|
||||
"build": 171,
|
||||
"oldBuild": "backend-0.1.3.zip"
|
||||
},
|
||||
"devDependencies": {
|
||||
@@ -68,6 +68,7 @@
|
||||
"bcryptjs": "^3.0.2",
|
||||
"croner": "^9.0.0",
|
||||
"date-fns": "^4.1.0",
|
||||
"date-fns-tz": "^3.2.0",
|
||||
"drizzle-kit": "^0.30.5",
|
||||
"drizzle-orm": "^0.41.0",
|
||||
"drizzle-zod": "^0.7.0",
|
||||
@@ -87,4 +88,4 @@
|
||||
"ws": "^8.18.1",
|
||||
"zod": "^3.24.2"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
13
server/globalUtils/timeZoneFix.ts
Normal file
13
server/globalUtils/timeZoneFix.ts
Normal file
@@ -0,0 +1,13 @@
|
||||
import { addHours } from "date-fns";
|
||||
|
||||
export const timeZoneFix = () => {
|
||||
/**
|
||||
* Returns iso date based on current timezone.
|
||||
*/
|
||||
const rawDate = new Date(Date.now()).toISOString();
|
||||
const offsetMinutes = new Date().getTimezoneOffset(); // in minutes
|
||||
const offsetHours =
|
||||
-offsetMinutes / 60 >= 0 ? offsetMinutes / 60 : -offsetMinutes / 60;
|
||||
|
||||
return addHours(rawDate, offsetHours).toISOString();
|
||||
};
|
||||
@@ -35,6 +35,8 @@ const ignoreList = [
|
||||
"frontend/tsconfig.node.json",
|
||||
"frontend/vite.config.ts",
|
||||
"frontend/components.json",
|
||||
//misc files
|
||||
"jsTesting",
|
||||
];
|
||||
|
||||
const shouldIgnore = (itemPath: any) => {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { pino, type LogFn, type Logger } from "pino";
|
||||
|
||||
export let logLevel = process.env.LOGLEVEL || "info";
|
||||
export let logLevel = process.env.LOG_LEVEL || "info";
|
||||
|
||||
const transport = pino.transport({
|
||||
targets: [
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
import { tryCatch } from "../../../../globalUtils/tryCatch.js";
|
||||
import { query } from "../../../sqlServer/prodSqlServer.js";
|
||||
import { siloQuery } from "../../../sqlServer/querys/silo/siloQuery.js";
|
||||
|
||||
export const getStockSiloData = async () => {
|
||||
/**
|
||||
* will return the current stock info where the silo is checked
|
||||
*/
|
||||
|
||||
const { data, error } = await tryCatch(query(siloQuery, "Get silo data"));
|
||||
|
||||
if (error) {
|
||||
return {
|
||||
success: false,
|
||||
message: "There was a n error getting the silo data.",
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
success: true,
|
||||
message: "Current silo data from alplastock.",
|
||||
data: data,
|
||||
};
|
||||
};
|
||||
@@ -4,6 +4,8 @@ import comsumeMaterial from "./route/consumeMaterial.js";
|
||||
import returnMat from "./route/returnMaterial.js";
|
||||
import createSiloAdjustment from "./route/siloAdjustments/createSiloAdjustment.js";
|
||||
import postComment from "./route/siloAdjustments/postComment.js";
|
||||
import getStockSilo from "./route/siloAdjustments/getStockData.js";
|
||||
|
||||
const app = new OpenAPIHono();
|
||||
|
||||
const routes = [
|
||||
@@ -13,6 +15,7 @@ const routes = [
|
||||
// silo
|
||||
createSiloAdjustment,
|
||||
postComment,
|
||||
getStockSilo,
|
||||
] as const;
|
||||
|
||||
// app.route("/server", modules);
|
||||
|
||||
@@ -0,0 +1,50 @@
|
||||
import { createRoute, OpenAPIHono, z } from "@hono/zod-openapi";
|
||||
import { authMiddleware } from "../../../auth/middleware/authMiddleware.js";
|
||||
import { responses } from "../../../../globalUtils/routeDefs/responses.js";
|
||||
import { getStockSiloData } from "../../controller/siloAdjustments/getCurrentStockSiloData.js";
|
||||
|
||||
const app = new OpenAPIHono();
|
||||
|
||||
app.openapi(
|
||||
createRoute({
|
||||
tags: ["logistics"],
|
||||
summary: "Returns current stock levels for silos",
|
||||
method: "get",
|
||||
path: "/getstocksilo",
|
||||
middleware: authMiddleware,
|
||||
// request: {
|
||||
// params: ParamsSchema,
|
||||
// body: { content: { "application/json": { schema: Body } } },
|
||||
// },
|
||||
// description:
|
||||
// "Creates a silo adjustment for the silo if and stores the stock numbers.",
|
||||
responses: responses(),
|
||||
}),
|
||||
async (c) => {
|
||||
//apiHit(c, { endpoint: "api/sqlProd/close" });
|
||||
|
||||
try {
|
||||
//return apiReturn(c, true, access?.message, access?.data, 200);
|
||||
|
||||
const silo = await getStockSiloData();
|
||||
return c.json(
|
||||
{
|
||||
success: silo.success,
|
||||
message: silo.message,
|
||||
data: silo.data,
|
||||
},
|
||||
200
|
||||
);
|
||||
} catch (error) {
|
||||
return c.json(
|
||||
{
|
||||
success: false,
|
||||
message: "Missing data please try again",
|
||||
error,
|
||||
},
|
||||
400
|
||||
);
|
||||
}
|
||||
}
|
||||
);
|
||||
export default app;
|
||||
@@ -29,7 +29,7 @@
|
||||
|
||||
Please add your comment as to why the variance greater than {{variancePer}}<br/><br/>
|
||||
|
||||
<a href="http://{{server}}:5173/siloAdjustments/comment/{{adjustID}}"
|
||||
<a href="http://{{server}}:{{port}}/siloAdjustments/comment/{{adjustID}}"
|
||||
style="display:inline-block; padding:10px 20px; text-decoration:none; border-radius:5px;">
|
||||
Add a Comment
|
||||
</a><br/><br/>
|
||||
|
||||
@@ -3,7 +3,6 @@ import { settings } from "../../../../../database/schema/settings.js";
|
||||
import { tryCatch } from "../../../../globalUtils/tryCatch.js";
|
||||
import { createLog } from "../../../logger/logger.js";
|
||||
import { getLots } from "../lots/lots.js";
|
||||
import { getMac } from "../specialProcesses/utils/getMachineId.js";
|
||||
import { billingCheck } from "../specialProcesses/billingCheck/billingCheck.js";
|
||||
import { isMainMatStaged } from "../materials/mainMaterial.js";
|
||||
import { firstLotLabel } from "../specialProcesses/lotChangeLabel/lotCHangeLabel.js";
|
||||
@@ -12,9 +11,11 @@ import { createLabel } from "./createLabel.js";
|
||||
import { bookInLabel } from "./bookIn.js";
|
||||
import { delieryInhouse } from "../specialProcesses/inhouse/inhouseDelivery.js";
|
||||
import { dualPrintingProcess } from "../specialProcesses/dualPrinting/dualPrinting.js";
|
||||
import { getMac } from "../../utils/getMachineId.js";
|
||||
|
||||
interface Printer {
|
||||
name: string;
|
||||
humanReadableId: string;
|
||||
// Add any other expected properties
|
||||
}
|
||||
|
||||
@@ -72,7 +73,9 @@ export const labelingProcess = async ({
|
||||
if (printer) {
|
||||
// filter the lot based on the printerID
|
||||
// console.log(printer);
|
||||
filteredLot = lots.data.filter((l: any) => l.printerID === printer);
|
||||
filteredLot = lots.data.filter(
|
||||
(l: any) => l.printerID === parseInt(printer?.humanReadableId)
|
||||
);
|
||||
if (filteredLot.length === 0) {
|
||||
// console.log(`There is not a lot assigned to ${printer.name}`);
|
||||
createLog(
|
||||
|
||||
@@ -1,20 +1,81 @@
|
||||
import { eq } from "drizzle-orm";
|
||||
import { db } from "../../../../../database/dbclient.js";
|
||||
import { settings } from "../../../../../database/schema/settings.js";
|
||||
import { tryCatch } from "../../../../globalUtils/tryCatch.js";
|
||||
import { createLog } from "../../../logger/logger.js";
|
||||
import { getPrinters } from "./getPrinters.js";
|
||||
import { printerStatus } from "./printerStatus.js";
|
||||
|
||||
export const printerCycle = async () => {
|
||||
/**
|
||||
* We will cycle through the printers to check there states.
|
||||
*/
|
||||
let printers = await getPrinters();
|
||||
/**
|
||||
* if the last timeprinted would be greater than x well just change the status to idle and extended based on the 2 times.
|
||||
*
|
||||
* to get a printer going again label will need to come from the front end as that will just unpause the printer and start the labeling, or the api for manual print
|
||||
* well need to adjust this to actually print the label then unpause it.
|
||||
*
|
||||
* it will be
|
||||
*
|
||||
* less than x since time printed run the printer status
|
||||
* greater than x but less than y change the status to idle, but ping to make sure its online,
|
||||
* if greater than y change to extended idle but stil also ping to make sure its online.
|
||||
*/
|
||||
|
||||
// get the printers
|
||||
const { data: s, error: se } = await tryCatch(
|
||||
db.select().from(settings).where(eq(settings.name, "ocpCycleDelay"))
|
||||
);
|
||||
if (se) {
|
||||
createLog(
|
||||
"error",
|
||||
"ocp",
|
||||
"ocp",
|
||||
"There was an error getting the ocpCycleDelay."
|
||||
);
|
||||
return {
|
||||
success: false,
|
||||
message: "Error getting printers.",
|
||||
};
|
||||
}
|
||||
|
||||
const ocpDelay: any = s;
|
||||
|
||||
// start the actual printer cycle
|
||||
const actualPrinterCycle = setInterval(async () => {
|
||||
const { data, error } = await tryCatch(getPrinters());
|
||||
|
||||
if (error) {
|
||||
createLog(
|
||||
"error",
|
||||
"ocp",
|
||||
"ocp",
|
||||
"There was an error getting the printers."
|
||||
);
|
||||
return {
|
||||
success: false,
|
||||
message: "Error getting printers.",
|
||||
};
|
||||
}
|
||||
let printers: any = data.data;
|
||||
|
||||
// only keep the assigned ones
|
||||
printers = printers.filter((p: any) => p.assigned === true);
|
||||
|
||||
// for autolabelers like dayton and MCD we want to ignore them from the loop as well.
|
||||
printers = printers.filter(
|
||||
(p: any) => p.name != "Autolabeler" && !p.remark.includes("ignore")
|
||||
);
|
||||
|
||||
printers.forEach(async (p: any) => {
|
||||
/**
|
||||
* if the last timeprinted would be greater than x well just change the status to idle and extended based on the 2 times.
|
||||
*
|
||||
* to get a printer going again label will need to come from the front end as that will just unpause the printer and start the labeling, or the api for manual print
|
||||
* well need to adjust this to actually print the label then unpause it.
|
||||
*
|
||||
* it will be
|
||||
*
|
||||
* less than x since time printed run the printer status
|
||||
* greater than x but less than y change the status to idle, but ping to make sure its online,
|
||||
* if greater than y change to extended idle but stil also ping to make sure its online.
|
||||
*/
|
||||
|
||||
// ignore pdf printer as we want it here for testing purposes
|
||||
if (p.name.toLowerCase() === "pdf24") {
|
||||
return;
|
||||
}
|
||||
|
||||
await printerStatus(p);
|
||||
});
|
||||
}, parseInt(ocpDelay[0]?.value) * 1000);
|
||||
};
|
||||
|
||||
61
server/services/ocp/controller/printers/printerStatUpdate.ts
Normal file
61
server/services/ocp/controller/printers/printerStatUpdate.ts
Normal file
@@ -0,0 +1,61 @@
|
||||
import { eq, sql } from "drizzle-orm";
|
||||
import { db } from "../../../../../database/dbclient.js";
|
||||
import { printerData } from "../../../../../database/schema/printers.js";
|
||||
import { createLog } from "../../../logger/logger.js";
|
||||
|
||||
export const printStatus = [
|
||||
{ code: 1, text: "Printing" },
|
||||
{ code: 2, text: "Pending labels" },
|
||||
{ code: 3, text: "Printing to fast" },
|
||||
{ code: 4, text: "Creating label" },
|
||||
{ code: 6, text: "Printer Paused" },
|
||||
{ code: 7, text: "Printer error" },
|
||||
{
|
||||
code: 8,
|
||||
text: "First time printing",
|
||||
},
|
||||
];
|
||||
|
||||
export const printerUpdate = async (printer: any, status: any) => {
|
||||
/**
|
||||
* Updates the status of the printer.
|
||||
*/
|
||||
|
||||
// get current time
|
||||
let pd = {};
|
||||
const currentTime = sql`NOW()`;
|
||||
|
||||
if (status === 3) {
|
||||
pd = {
|
||||
status: status,
|
||||
statusText: printStatus.filter((c) => c.code === status)[0]?.text,
|
||||
};
|
||||
} else if (status === 6) {
|
||||
pd = {
|
||||
status: status,
|
||||
statusText: printStatus.filter((c) => c.code === status)[0]?.text,
|
||||
};
|
||||
} else {
|
||||
pd = {
|
||||
lastTimePrinted: currentTime,
|
||||
status: status,
|
||||
statusText: printStatus.filter((c) => c.code === status)[0]?.text,
|
||||
};
|
||||
}
|
||||
|
||||
if (printer.humanReadableId) {
|
||||
try {
|
||||
await db
|
||||
.update(printerData)
|
||||
.set(pd)
|
||||
.where(
|
||||
eq(printerData.humanReadableId, printer.humanReadableId)
|
||||
);
|
||||
} catch (error) {
|
||||
createLog("error", "ocp", "ocp", `Error updating printer state`);
|
||||
}
|
||||
}
|
||||
|
||||
// console.log(printerUpdate.name);
|
||||
return;
|
||||
};
|
||||
190
server/services/ocp/controller/printers/printerStatus.ts
Normal file
190
server/services/ocp/controller/printers/printerStatus.ts
Normal file
@@ -0,0 +1,190 @@
|
||||
import net from "net";
|
||||
import { pausePrinter } from "../../utils/pausePrinter.js";
|
||||
import { addHours, differenceInSeconds } from "date-fns";
|
||||
import { printerUpdate } from "./printerStatUpdate.js";
|
||||
import { createLog } from "../../../logger/logger.js";
|
||||
import { unPausePrinter } from "../../utils/unpausePrinter.js";
|
||||
|
||||
import { labelingProcess } from "../labeling/labelProcess.js";
|
||||
import { timeZoneFix } from "../../../../globalUtils/timeZoneFix.js";
|
||||
|
||||
let logLevel: string = process.env.LOG_LEVEL || "info";
|
||||
let errorCheck = false;
|
||||
export const printerStatus = async (p: any) => {
|
||||
/**
|
||||
* Checks each printer to see what the current state is
|
||||
*/
|
||||
createLog("debug", "ocp", "ocp", `Printer cycling`);
|
||||
|
||||
const printer = new net.Socket();
|
||||
|
||||
return new Promise((resolve) => {
|
||||
// connect to the printer, and check its status
|
||||
printer.connect(p.port, p.ipAddress, async () => {
|
||||
// write the message to the printer below gives us a feedback of the printer
|
||||
printer.write("~HS");
|
||||
});
|
||||
|
||||
// read the data from the printer
|
||||
printer.on("data", async (data) => {
|
||||
const res = data.toString();
|
||||
|
||||
// turn the data into an array to make it more easy to deal with
|
||||
const tmp = res.split(",");
|
||||
|
||||
//--------------- time stuff-----------------------------------------------------------------
|
||||
// get last time printed
|
||||
const lastTime = new Date(p.lastTimePrinted).toISOString();
|
||||
// console.log(lastTime);
|
||||
|
||||
// current time?
|
||||
|
||||
/**
|
||||
*
|
||||
* add the time zone to the settings db
|
||||
*/
|
||||
// const currentTime = addHours(
|
||||
// new Date(Date.now()),
|
||||
// -6
|
||||
// ).toISOString();
|
||||
|
||||
const currentTime = timeZoneFix();
|
||||
|
||||
let timeBetween = 0;
|
||||
// if this is our first time printing pause the printer to start the timer, else we just update the time between timer
|
||||
if (lastTime === undefined) {
|
||||
printer.end();
|
||||
printerUpdate(p, 8);
|
||||
pausePrinter(p);
|
||||
resolve({ success: true, message: "First Time printing" });
|
||||
} else {
|
||||
timeBetween = differenceInSeconds(currentTime, lastTime);
|
||||
}
|
||||
|
||||
// --- end time ---
|
||||
|
||||
// --- printer logic ---
|
||||
createLog(
|
||||
"debug",
|
||||
"ocp",
|
||||
"ocp",
|
||||
`${p.name}: timeBetween: ${timeBetween}, delay ${
|
||||
p.printDelay || 90
|
||||
}, ${currentTime}... ${lastTime}`
|
||||
);
|
||||
|
||||
if (tmp[2] === "0" && tmp[4] !== "000") {
|
||||
// unpaused and printing labels - reset timer
|
||||
createLog(
|
||||
"debug",
|
||||
"ocp",
|
||||
"ocp",
|
||||
`Unpaused and printing labels, time remaing ${differenceInSeconds(
|
||||
p.printDelay || 90,
|
||||
timeBetween
|
||||
)}`
|
||||
);
|
||||
|
||||
// update last time printed in the array
|
||||
printerUpdate(p, 1);
|
||||
} else if (tmp[2] === "1" && tmp[4] !== "000") {
|
||||
// was paused or label sent from somewhere else
|
||||
createLog(
|
||||
"info",
|
||||
"ocp",
|
||||
"ocp",
|
||||
`${
|
||||
p.name
|
||||
} paused to soon, unpausing, remaining time: ${differenceInSeconds(
|
||||
p.printDelay || 90,
|
||||
timeBetween
|
||||
)}`
|
||||
);
|
||||
|
||||
// reset the timer for this printer as well other labels shouldnt be sent but if we send them ok
|
||||
printerUpdate(p, 2);
|
||||
|
||||
unPausePrinter(p);
|
||||
} else if ((tmp[2] === "0" && timeBetween < p.printDelay) || 90) {
|
||||
// was unpaused to soon so repause it
|
||||
createLog(
|
||||
"debug",
|
||||
"ocp",
|
||||
"ocp",
|
||||
`${p.name} Unpaused before the time allowed, time left ${
|
||||
differenceInSeconds(p.printDelay || 90, timeBetween) //seconds
|
||||
}`
|
||||
);
|
||||
|
||||
printerUpdate(p, 3);
|
||||
pausePrinter(p);
|
||||
} else if ((tmp[2] === "0" && timeBetween > p.printDelay) || 90) {
|
||||
// its been long enough we can print a label
|
||||
createLog(
|
||||
"debug",
|
||||
"ocp",
|
||||
"ocp",
|
||||
`${p.name} Allowed time passed and printing new label`
|
||||
);
|
||||
|
||||
// update last time printed in the array
|
||||
printerUpdate(p, 4);
|
||||
|
||||
// sending over for labeling.
|
||||
labelingProcess({ printer: p });
|
||||
} else if (tmp[2] === "0") {
|
||||
// printer was unpaused for the first time or made it here
|
||||
createLog(
|
||||
"debug",
|
||||
"ocp",
|
||||
"ocp",
|
||||
`${p.name} Frist time printing`
|
||||
);
|
||||
|
||||
// add the time and printer
|
||||
printerUpdate(p, 4);
|
||||
|
||||
// sending over for labeling.
|
||||
labelingProcess({ printer: p });
|
||||
} else if (tmp[2] === "1") {
|
||||
// printer is paused and waiting
|
||||
createLog(
|
||||
"debug",
|
||||
"ocp",
|
||||
"ocp",
|
||||
`${p.name} paused and waiting`
|
||||
);
|
||||
|
||||
printerUpdate(p, 6);
|
||||
}
|
||||
|
||||
printer.end();
|
||||
|
||||
resolve({ success: true, message: "Print cycle completed." });
|
||||
});
|
||||
|
||||
printer.on("error", async (error) => {
|
||||
// just going to say theres an error with the printer
|
||||
|
||||
if (!errorCheck) {
|
||||
createLog(
|
||||
"error",
|
||||
"ocp",
|
||||
"ocp",
|
||||
`${p.name} encountered an error: ${error}`
|
||||
);
|
||||
}
|
||||
|
||||
await printerUpdate(p, 7);
|
||||
errorCheck = true;
|
||||
|
||||
// send log data
|
||||
// fake line
|
||||
printer.end();
|
||||
resolve({
|
||||
success: false,
|
||||
message: "There was an error with the printer.",
|
||||
});
|
||||
});
|
||||
});
|
||||
};
|
||||
@@ -25,7 +25,7 @@ export const updatePrinters = async () => {
|
||||
);
|
||||
|
||||
if (prodError) {
|
||||
console.log(prodError);
|
||||
//console.log(prodError);
|
||||
return {
|
||||
success: false,
|
||||
message: "there was an error getting the printers.",
|
||||
|
||||
@@ -88,7 +88,7 @@ export const dualPrintingProcess = async (lotInfo: any) => {
|
||||
"info",
|
||||
"ocp",
|
||||
"ocp",
|
||||
`Printing label for ${whatToPrint.MachineDescription}`
|
||||
`Printing label for ${whatToPrint[0].MachineDescription}`
|
||||
);
|
||||
return whatToPrint;
|
||||
}
|
||||
@@ -103,7 +103,7 @@ export const dualPrintingProcess = async (lotInfo: any) => {
|
||||
"info",
|
||||
"ocp",
|
||||
"ocp",
|
||||
`Printing label for ${whatToPrint.MachineDescription}`
|
||||
`Printing label for ${whatToPrint[0].MachineDescription}`
|
||||
);
|
||||
return whatToPrint;
|
||||
}
|
||||
|
||||
@@ -13,6 +13,9 @@ import { dycoConnect } from "./controller/specialProcesses/dyco/plcConnection.js
|
||||
import dycoCon from "./routes/specialProcesses/dyco/connection.js";
|
||||
import dycoClose from "./routes/specialProcesses/dyco/closeConnection.js";
|
||||
import manualprint from "./routes/labeling/manualPrint.js";
|
||||
import { assignedPrinters } from "./utils/checkAssignments.js";
|
||||
import { printerCycle } from "./controller/printers/printerCycle.js";
|
||||
import { tryCatch } from "../../globalUtils/tryCatch.js";
|
||||
|
||||
const app = new OpenAPIHono();
|
||||
|
||||
@@ -43,14 +46,34 @@ app.all("/ocp/*", (c) => {
|
||||
});
|
||||
});
|
||||
|
||||
/**
|
||||
* Get the settings so we only run items when they are truly active
|
||||
*/
|
||||
const dycoActive = setting.filter((n) => n.name == "dycoConnect");
|
||||
const ocpActive = setting.filter((n) => n.name === "ocpActive");
|
||||
// run the printer update on restart just to keep everything good
|
||||
setTimeout(() => {
|
||||
updatePrinters();
|
||||
}, 3 * 1000);
|
||||
|
||||
// do the intnal connection to the dyco
|
||||
setTimeout(() => {
|
||||
dycoConnect();
|
||||
if (dycoActive[0].value === "1") {
|
||||
dycoConnect();
|
||||
}
|
||||
}, 3 * 1000);
|
||||
|
||||
// check for printers being assigned
|
||||
setInterval(() => {
|
||||
if (ocpActive[0].value === "1") {
|
||||
assignedPrinters();
|
||||
}
|
||||
}, 60 * 1000);
|
||||
|
||||
// start the printer process after everything else is up ad running
|
||||
setTimeout(async () => {
|
||||
if (ocpActive[0].value === "1") {
|
||||
await updatePrinters();
|
||||
await assignedPrinters();
|
||||
printerCycle();
|
||||
}
|
||||
}, 10 * 1000);
|
||||
|
||||
export default app;
|
||||
|
||||
@@ -1,9 +1,14 @@
|
||||
import { eq, sql } from "drizzle-orm";
|
||||
import { db } from "../../../../database/dbclient.js";
|
||||
import { printerData } from "../../../../database/schema/printers.js";
|
||||
import { delay } from "../../../globalUtils/delay.js";
|
||||
import { tryCatch } from "../../../globalUtils/tryCatch.js";
|
||||
import { getLots } from "../controller/lots/lots.js";
|
||||
import { getPrinters } from "../controller/printers/getPrinters.js";
|
||||
import { createLog } from "../../logger/logger.js";
|
||||
|
||||
export const assignedPrinters = async () => {
|
||||
createLog("info", "ocp", "ocp", "Lot assignment check");
|
||||
const { data: l, error: lotError } = await tryCatch(getLots());
|
||||
|
||||
if (lotError) {
|
||||
@@ -23,63 +28,44 @@ export const assignedPrinters = async () => {
|
||||
};
|
||||
}
|
||||
|
||||
const printers: any = print;
|
||||
const lots: any = l;
|
||||
const printers: any = print.data;
|
||||
const lots: any = l.data;
|
||||
|
||||
for (let i = 0; i < printers.data.length; i++) {
|
||||
for (let i = 0; i < printers.length; i++) {
|
||||
// is the printer assinged in alplalabel online?
|
||||
const assigned = lots.data.filter(
|
||||
(p: any) => p.printerID === printers[i].humanReadableId
|
||||
const assigned = lots.filter(
|
||||
(p: any) => p.printerID === parseInt(printers[i].humanReadableId)
|
||||
);
|
||||
|
||||
let assignedPrinter = false;
|
||||
// if true update the assigned field to true
|
||||
if (assigned.length >= 1) {
|
||||
assignedPrinter = true;
|
||||
}
|
||||
|
||||
// if the last time printed is greater than 5 min change the status to 10
|
||||
// const lastTime = new Date(printers[i].lastTimePrinted);
|
||||
// let status = printers[i].status;
|
||||
// let statusText = printers[i].statusText;
|
||||
// update the printer to set its assignment
|
||||
const { data: p, error: pe } = await tryCatch(
|
||||
db
|
||||
.update(printerData)
|
||||
.set({ assigned: assignedPrinter, upd_date: sql`NOW()` })
|
||||
.where(
|
||||
eq(printerData.humanReadableId, printers[i].humanReadableId)
|
||||
)
|
||||
);
|
||||
|
||||
// // states we consider idle
|
||||
// const printerStateCheck = [1, 2, 3, 4, 5, 6, 10];
|
||||
// if (
|
||||
// differenceInMinutes(currentTime, lastTime) >= 60 &&
|
||||
// printerStateCheck.includes(printers[i].status) &&
|
||||
// printers[i].assigned
|
||||
// ) {
|
||||
// createLog(
|
||||
// "printerState",
|
||||
// "info",
|
||||
// `${printers[i].name} has been idle for more than 60 min, doing a heartbeat check`
|
||||
// );
|
||||
|
||||
// status = 11;
|
||||
// statusText = "idle";
|
||||
|
||||
// // printerState({printerCheck: printers[i]});
|
||||
// } else if (differenceInMinutes(currentTime, lastTime) > 5 && printers[i].status === 7) {
|
||||
// createLog(
|
||||
// "printerState",
|
||||
// "info",
|
||||
// `${printers[i].name} has been errored for more 5 min changing to idle until, until it gets checked at the hour heartbeat.`
|
||||
// );
|
||||
// status = 10;
|
||||
// statusText = "idle";
|
||||
// }
|
||||
|
||||
// const updatePrinter = await prisma.printers.update({
|
||||
// where: {
|
||||
// humanReadableId: printers[i].humanReadableId,
|
||||
// },
|
||||
// data: {
|
||||
// assigned: assignedPrinter,
|
||||
// // status,
|
||||
// // statusText,
|
||||
// upd_date: new Date(Date.now()).toISOString(),
|
||||
// },
|
||||
// });
|
||||
if (pe) {
|
||||
createLog(
|
||||
"error",
|
||||
"ocp",
|
||||
"ocp",
|
||||
`${printers[i].name} encountered an error updating: ${pe}`
|
||||
);
|
||||
return {
|
||||
success: false,
|
||||
message: "Error while updating the prints.",
|
||||
data: pe,
|
||||
};
|
||||
}
|
||||
|
||||
//delaying 250ms
|
||||
await delay(250);
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { createLog } from "../../../../logger/logger.js";
|
||||
import { query } from "../../../../sqlServer/prodSqlServer.js";
|
||||
import { machineCheck } from "../../../../sqlServer/querys/ocp/machineId.js";
|
||||
import { machineCheck } from "../../sqlServer/querys/ocp/machineId.js";
|
||||
import { createLog } from "../../logger/logger.js";
|
||||
import { query } from "../../sqlServer/prodSqlServer.js";
|
||||
|
||||
export const getMac = async (machine: string) => {
|
||||
let updateQuery = machineCheck.replaceAll("[loc]", machine);
|
||||
@@ -191,33 +191,45 @@ const newSettings = [
|
||||
serviceBelowsTo: "system",
|
||||
roleToChange: "admin",
|
||||
},
|
||||
|
||||
// ocp
|
||||
{
|
||||
name: "acpActive",
|
||||
value: `1`,
|
||||
description: "Are we pritning on demand?",
|
||||
serviceBelowsTo: "ocp",
|
||||
roleToChange: "admin",
|
||||
},
|
||||
{
|
||||
name: "ocpCycleDelay",
|
||||
value: `10`,
|
||||
description: "How long between printer cycles do we want to monitor.",
|
||||
serviceBelowsTo: "ocp",
|
||||
roleToChange: "admin",
|
||||
},
|
||||
];
|
||||
export const areSettingsIn = async () => {
|
||||
// get the roles
|
||||
try {
|
||||
const settingsCheck = await db.select().from(settings);
|
||||
|
||||
if (settingsCheck.length !== newSettings.length) {
|
||||
try {
|
||||
const newRole = await db
|
||||
.insert(settings)
|
||||
.values(newSettings)
|
||||
.onConflictDoNothing() // this will only update the ones that are new :D
|
||||
.returning({ name: settings.name });
|
||||
createLog(
|
||||
"info",
|
||||
"lst",
|
||||
"server",
|
||||
"Settings were just added due to missing them on server startup"
|
||||
);
|
||||
} catch (error) {
|
||||
createLog(
|
||||
"error",
|
||||
"lst",
|
||||
"server",
|
||||
"There was an error adding new roles to the db"
|
||||
);
|
||||
}
|
||||
try {
|
||||
const newRole = await db
|
||||
.insert(settings)
|
||||
.values(newSettings)
|
||||
.onConflictDoNothing() // this will only update the ones that are new :D
|
||||
.returning({ name: settings.name });
|
||||
createLog(
|
||||
"info",
|
||||
"lst",
|
||||
"server",
|
||||
"Settings were just added due to missing them on server startup"
|
||||
);
|
||||
} catch (error) {
|
||||
createLog(
|
||||
"error",
|
||||
"lst",
|
||||
"server",
|
||||
"There was an error adding new roles to the db"
|
||||
);
|
||||
}
|
||||
} catch (error) {
|
||||
createLog(
|
||||
|
||||
@@ -3,10 +3,10 @@ SELECT
|
||||
V_LagerAbteilungen.Bezeichnung AS Description,
|
||||
V_LagerAbteilungen.IdWarenLager AS WarehouseID,
|
||||
V_LagerAbteilungen.IdLagerAbteilung AS LocationID,
|
||||
ROUND(SUM(einlagerungsmengesum), 2) AS Stock_Total,
|
||||
COALESCE(LastAdjustment, '1900-01-01') AS LastAdjustment
|
||||
case when ROUND(SUM(einlagerungsmengesum), 2) is null then 0 else ROUND(SUM(einlagerungsmengesum), 2) end AS Stock_Total
|
||||
,case when ROUND(SUM(einlagerungsmengesum), 2) is null then COALESCE(b.upd_Date, '1900-01-01') else COALESCE(LastAdjustment, '1900-01-01') end AS LastAdjustment
|
||||
FROM AlplaPROD_test1.dbo.V_LagerAbteilungen (NOLOCK)
|
||||
JOIN
|
||||
left JOIN
|
||||
AlplaPROD_test1.dbo.V_LagerPositionenBarcodes ON
|
||||
AlplaPROD_test1.dbo.V_LagerAbteilungen.IdLagerAbteilung =
|
||||
AlplaPROD_test1.dbo.V_LagerPositionenBarcodes.IdLagerAbteilung
|
||||
@@ -18,9 +18,15 @@ SELECT
|
||||
WHERE urheber = 2900
|
||||
GROUP BY IdLagerAbteilung
|
||||
) AS LastAdj ON AlplaPROD_test1.dbo.V_LagerAbteilungen.IdLagerAbteilung = LastAdj.IdLagerAbteilung
|
||||
|
||||
/* add the actual inventory now that we will display an empty silo and need to add this date */
|
||||
left join
|
||||
AlplaPROD_test1.dbo.V_LagerAbteilungenInventuren as b on
|
||||
AlplaPROD_test1.dbo.V_LagerAbteilungen.IdLagerAbteilung = b.IdLagerAbteilung
|
||||
|
||||
WHERE materialsilo = 1
|
||||
AND aktiv = 1
|
||||
|
||||
GROUP BY V_LagerAbteilungen.Bezeichnung, V_LagerAbteilungen.IdWarenLager, V_LagerAbteilungen.IdLagerAbteilung, LastAdjustment
|
||||
GROUP BY V_LagerAbteilungen.Bezeichnung, V_LagerAbteilungen.IdWarenLager, V_LagerAbteilungen.IdLagerAbteilung, LastAdjustment, b.upd_Date
|
||||
ORDER BY V_LagerAbteilungen.Bezeichnung
|
||||
`;
|
||||
|
||||
Reference in New Issue
Block a user