This commit is contained in:
2025-03-25 07:57:55 -05:00
5 changed files with 421 additions and 254 deletions

View File

@@ -41,22 +41,19 @@ export default function OcmeCycleCount() {
setCounting(true); setCounting(true);
toast.success(`Cycle count started`); toast.success(`Cycle count started`);
try { try {
const res = await axios.post("/ocme/api/v1/cycleCount", data, { const res = await axios.post("/ocme/api/v1/cyclecount", data, {
headers: { Authorization: `Bearer ${token}` }, headers: { Authorization: `Bearer ${token}` },
}); });
console.log(data);
toast.success(res.data.message); toast.success(res.data.message);
setData(res.data.data); setData(res.data.data);
setCounting(false); setCounting(false);
reset(); reset();
} catch (error) { } catch (error) {
console.log(error);
toast.error("There was an error cycle counting"); toast.error("There was an error cycle counting");
setCounting(false); setCounting(false);
reset(); reset();
} }
}; };
return ( return (
<div className="flex flex-row w-screen"> <div className="flex flex-row w-screen">
<div className="m-2 w-5/6"> <div className="m-2 w-5/6">
@@ -70,13 +67,16 @@ export default function OcmeCycleCount() {
<div className="m-2 flex flex-row"> <div className="m-2 flex flex-row">
<Input <Input
placeholder="enter lane: L064" placeholder="enter lane: L064"
className={errors.lane ? "border-red-500" : ""} className={
errors.lane ? "border-red-500" : ""
}
aria-invalid={!!errors.lane} aria-invalid={!!errors.lane}
{...register("lane", { {...register("lane", {
required: true, required: true,
minLength: { minLength: {
value: 3, value: 3,
message: "The lane is too short!", message:
"The lane is too short!",
}, },
})} })}
/> />
@@ -90,20 +90,30 @@ export default function OcmeCycleCount() {
fieldState: {}, fieldState: {},
//formState, //formState,
}) => ( }) => (
<Select onValueChange={onChange}> <Select
onValueChange={onChange}
>
<SelectTrigger className="w-[180px]"> <SelectTrigger className="w-[180px]">
<SelectValue placeholder="Select name or id" /> <SelectValue placeholder="Select name or id" />
</SelectTrigger> </SelectTrigger>
<SelectContent> <SelectContent>
<SelectItem value="name">Name</SelectItem> <SelectItem value="name">
<SelectItem value="laneID">Lane ID</SelectItem> Name
</SelectItem>
<SelectItem value="laneId">
Lane ID
</SelectItem>
</SelectContent> </SelectContent>
</Select> </Select>
)} )}
/> />
</div> </div>
</div> </div>
<Button className="m-2" type="submit" disabled={counting}> <Button
className="m-2"
type="submit"
disabled={counting}
>
{counting ? ( {counting ? (
<span>Counting...</span> <span>Counting...</span>
) : ( ) : (
@@ -127,7 +137,7 @@ export default function OcmeCycleCount() {
<TableHead>Result</TableHead> <TableHead>Result</TableHead>
</TableRow> </TableRow>
</TableHeader> </TableHeader>
{data?.length === 0 ? ( {data.length === 0 ? (
<TableBody> <TableBody>
{Array(10) {Array(10)
.fill(0) .fill(0)
@@ -162,9 +172,11 @@ export default function OcmeCycleCount() {
</TableBody> </TableBody>
) : ( ) : (
<> <>
{data?.map((i: any) => { {data.map((i: any) => {
let classname = ``; let classname = ``;
if (i.info === "Quality Check Required") { if (
i.info === "Quality Check Required"
) {
classname = `bg-red-500`; classname = `bg-red-500`;
} }
if (i.info === "Sent to Inv") { if (i.info === "Sent to Inv") {
@@ -172,28 +184,44 @@ export default function OcmeCycleCount() {
} }
return ( return (
<TableRow key={i.runningNumber}> <TableRow key={i.runningNumber}>
<TableCell className={`font-medium ${classname}`}> <TableCell
className={`font-medium ${classname}`}
>
{i.alpla_laneID} {i.alpla_laneID}
</TableCell> </TableCell>
<TableCell className={`font-medium ${classname}`}> <TableCell
className={`font-medium ${classname}`}
>
{i.alpla_laneDescription} {i.alpla_laneDescription}
</TableCell> </TableCell>
<TableCell className={`font-medium ${classname}`}> <TableCell
className={`font-medium ${classname}`}
>
{i.Article} {i.Article}
</TableCell> </TableCell>
<TableCell className={`font-medium ${classname}`}> <TableCell
className={`font-medium ${classname}`}
>
{i.alpla_laneDescription} {i.alpla_laneDescription}
</TableCell> </TableCell>
<TableCell className={`font-medium ${classname}`}> <TableCell
className={`font-medium ${classname}`}
>
{i.runningNumber} {i.runningNumber}
</TableCell> </TableCell>
<TableCell className={`font-medium ${classname}`}> <TableCell
className={`font-medium ${classname}`}
>
{i.ocme} {i.ocme}
</TableCell> </TableCell>
<TableCell className={`font-medium ${classname}`}> <TableCell
className={`font-medium ${classname}`}
>
{i.stock} {i.stock}
</TableCell> </TableCell>
<TableCell className={`font-medium ${classname}`}> <TableCell
className={`font-medium ${classname}`}
>
{i.info} {i.info}
</TableCell> </TableCell>
</TableRow> </TableRow>

View File

@@ -21,7 +21,7 @@
"deploy": "standard-version --conventional-commits && npm run prodBuild", "deploy": "standard-version --conventional-commits && npm run prodBuild",
"zipServer": "dotenvx run -f .env -- tsx server/scripts/zipUpBuild.ts \"C:\\Users\\matthes01\\Documents\\lstv2\"", "zipServer": "dotenvx run -f .env -- tsx server/scripts/zipUpBuild.ts \"C:\\Users\\matthes01\\Documents\\lstv2\"",
"v1Build": "cd C:\\Users\\matthes01\\Documents\\logisticsSupportTool && npm run oldBuilder", "v1Build": "cd C:\\Users\\matthes01\\Documents\\logisticsSupportTool && npm run oldBuilder",
"prodBuild": "npm run v1Build && powershell -ExecutionPolicy Bypass -File server/scripts/build.ps1 -dir \"C:\\Users\\matthes01\\Documents\\lstv2\" && npm run zipServer", "prodBuild": "npm run v1Build && powershell -ExecutionPolicy Bypass -File server/scripts/build.ps1 -dir \"C:\\Users\\matthes01\\Documents\\lstv2-dev\" && npm run zipServer",
"commit": "cz", "commit": "cz",
"prodinstall": "npm i --omit=dev && npm run db:migrate", "prodinstall": "npm i --omit=dev && npm run db:migrate",
"checkupdates": "npx npm-check-updates" "checkupdates": "npx npm-check-updates"

View File

@@ -4,12 +4,26 @@ import { db } from "../../database/dbclient.js";
import { serverData } from "../../database/schema/serverData.js"; import { serverData } from "../../database/schema/serverData.js";
import { eq, sql } from "drizzle-orm"; import { eq, sql } from "drizzle-orm";
import { createLog } from "../services/logger/logger.js"; import { createLog } from "../services/logger/logger.js";
import { spawn } from "child_process";
import { getAppInfo } from "../globalUtils/appInfo.js";
import { db } from "../../database/dbclient.js";
import { serverData } from "../../database/schema/serverData.js";
import { eq, sql } from "drizzle-orm";
import { createLog } from "../services/logger/logger.js";
type UpdateServerResponse = { type UpdateServerResponse = {
success: boolean; success: boolean;
message: string; message: string;
success: boolean;
message: string;
}; };
export const updateServer = async (
devApp: string,
server: string | null
): Promise<UpdateServerResponse> => {
const app = await getAppInfo(devApp);
const serverInfo = await db
export const updateServer = async ( export const updateServer = async (
devApp: string, devApp: string,
server: string | null server: string | null
@@ -33,7 +47,32 @@ export const updateServer = async (
"Looks like you are missing the plant token or have entered an incorrect one please try again.", "Looks like you are missing the plant token or have entered an incorrect one please try again.",
}; };
} }
if (serverInfo.length === 0) {
createLog(
"error",
"lst",
"serverUpdater",
`Looks like you are missing the plant token or have entered an incorrect one please try again.`
);
return {
success: false,
message:
"Looks like you are missing the plant token or have entered an incorrect one please try again.",
};
}
if (serverInfo[0].isUpgrading) {
createLog(
"error",
"lst",
"serverUpdater",
`Looks like ${serverInfo[0].plantToken} is upgrading already you cant do this again.`
);
return {
success: false,
message: `Looks like ${serverInfo[0].plantToken} is upgrading already you cant do this again.`,
};
}
if (serverInfo[0].isUpgrading) { if (serverInfo[0].isUpgrading) {
createLog( createLog(
"error", "error",
@@ -77,6 +116,15 @@ export const updateServer = async (
, ,
]; ];
return new Promise(async (resolve, reject) => {
const process = spawn("powershell", args);
// change the server to upgradeing
await db
.update(serverData)
.set({ isUpgrading: true })
.where(eq(serverData.plantToken, server?.toLowerCase() ?? ""));
//let stdout = "";
//let stderr = "";
return new Promise(async (resolve, reject) => { return new Promise(async (resolve, reject) => {
const process = spawn("powershell", args); const process = spawn("powershell", args);
// change the server to upgradeing // change the server to upgradeing
@@ -87,6 +135,12 @@ export const updateServer = async (
//let stdout = ""; //let stdout = "";
//let stderr = ""; //let stderr = "";
// Collect stdout data
process.stdout.on("data", (data) => {
const output = data.toString().trim();
createLog("info", "lst", "serverUpdater", `${output}`);
//onData(output);
});
// Collect stdout data // Collect stdout data
process.stdout.on("data", (data) => { process.stdout.on("data", (data) => {
const output = data.toString().trim(); const output = data.toString().trim();
@@ -94,6 +148,12 @@ export const updateServer = async (
//onData(output); //onData(output);
}); });
// Collect stderr data
process.stderr.on("data", (data) => {
const output = data.toString().trim();
createLog("info", "lst", "serverUpdater", `${output}`);
//onData(output);
});
// Collect stderr data // Collect stderr data
process.stderr.on("data", (data) => { process.stderr.on("data", (data) => {
const output = data.toString().trim(); const output = data.toString().trim();
@@ -101,6 +161,13 @@ export const updateServer = async (
//onData(output); //onData(output);
}); });
// Handle process close
process.on("close", async (code) => {
if (code === 0) {
// if (count >= servers) {
// //onClose(`Server completed with code: ${code}`);
// }
createLog("info", "lst", "serverUpdater", `${server}`);
// Handle process close // Handle process close
process.on("close", async (code) => { process.on("close", async (code) => {
if (code === 0) { if (code === 0) {
@@ -109,6 +176,26 @@ export const updateServer = async (
// } // }
createLog("info", "lst", "serverUpdater", `${server}`); createLog("info", "lst", "serverUpdater", `${server}`);
//update the last build.
try {
await db
.update(serverData)
.set({ lastUpdated: sql`NOW()`, isUpgrading: false })
.where(eq(serverData.plantToken, server?.toLowerCase() ?? ""));
createLog(
"info",
"lst",
"serverUpdater",
`${server?.toLowerCase()}, has been updated and can now be used again.`
);
} catch (error) {
createLog(
"error",
"lst",
"serverUpdater",
`There was an error updating the last time the server was updated: ${error}`
);
}
//update the last build. //update the last build.
try { try {
await db await db
@@ -130,6 +217,12 @@ export const updateServer = async (
); );
} }
resolve({
success: true,
message: `${server?.toLowerCase()}, has been updated and can now be used again.`,
});
} else {
const errorMessage = `Process exited with code ${code}`;
resolve({ resolve({
success: true, success: true,
message: `${server?.toLowerCase()}, has been updated and can now be used again.`, message: `${server?.toLowerCase()}, has been updated and can now be used again.`,
@@ -137,6 +230,9 @@ export const updateServer = async (
} else { } else {
const errorMessage = `Process exited with code ${code}`; const errorMessage = `Process exited with code ${code}`;
// if (count >= servers) {
// //onClose(code);
// }
// if (count >= servers) { // if (count >= servers) {
// //onClose(code); // //onClose(code);
// } // }
@@ -147,6 +243,12 @@ export const updateServer = async (
}); });
} }
}); });
reject({
success: false,
message: `${server?.toLowerCase()}, Has encounted an error while updating.`,
});
}
});
// Handle errors with the process itself // Handle errors with the process itself
process.on("error", (error) => { process.on("error", (error) => {
@@ -155,11 +257,31 @@ export const updateServer = async (
reject(error); reject(error);
}); });
}); });
// Handle errors with the process itself
process.on("error", (error) => {
//onError(err.message);
createLog("error", "lst", "serverUpdater", `${error}`);
reject(error);
});
});
}; };
export async function processAllServers(devApp: string) { export async function processAllServers(devApp: string) {
const servers = await db.select().from(serverData); const servers = await db.select().from(serverData);
const servers = await db.select().from(serverData);
createLog(
"info",
"lst",
"serverUpdater",
`Running the update on all servers`
);
let count = 1;
for (const server of servers) {
try {
const updateToServer = await updateServer(devApp, server.plantToken);
createLog("info", "lst", "serverUpdater", `${server.sName} was updated.`);
count = count + 1;
createLog( createLog(
"info", "info",
"lst", "lst",
@@ -184,4 +306,15 @@ export async function processAllServers(devApp: string) {
//return {success: false, message: `Error updating ${server.sName}: ${error.message}`}; //return {success: false, message: `Error updating ${server.sName}: ${error.message}`};
} }
} }
//return {success: true, message: `${server.sName} was updated.`, data: updateToServer};
} catch (error: any) {
createLog(
"info",
"lst",
"serverUpdater",
`Error updating ${server.sName}: ${error.message}`
);
//return {success: false, message: `Error updating ${server.sName}: ${error.message}`};
}
}
} }

View File

@@ -4,6 +4,12 @@ import { createSSCC } from "../../../globalUtils/createSSCC.js";
import { createLog } from "../../logger/logger.js"; import { createLog } from "../../logger/logger.js";
import { query } from "../../sqlServer/prodSqlServer.js"; import { query } from "../../sqlServer/prodSqlServer.js";
import { labelData } from "../../sqlServer/querys/materialHelpers/labelInfo.js"; import { labelData } from "../../sqlServer/querys/materialHelpers/labelInfo.js";
import { db } from "../../../../database/dbclient.js";
import { ocmeData } from "../../../../database/schema/ocme.js";
import { createSSCC } from "../../../globalUtils/createSSCC.js";
import { createLog } from "../../logger/logger.js";
import { query } from "../../sqlServer/prodSqlServer.js";
import { labelData } from "../../sqlServer/querys/materialHelpers/labelInfo.js";
export const postLabelData = async (data: any) => { export const postLabelData = async (data: any) => {
console.log(data); console.log(data);