feat(eom): migrated eom endpoints from old version validated working
This commit is contained in:
@@ -29,7 +29,7 @@ Quick summary of current rewrite/migration goal.
|
||||
| Transport Insight | Integrations | ⏳ Not Started |
|
||||
| Quality Request Tool | Add Pallet, Monitor for moved, status changes, alerts | ⏳ Not Started |
|
||||
| Logistics | Consume material, return and print, label info, relocate | ⏳ Not Started |
|
||||
| EOM | Endpoints, Report Pull for finance | ⏳ Not Started |
|
||||
| EOM | ~~Endpoints~~, Report Pull for finance, SSRS report | 🟨 In Progress |
|
||||
| ~~OCME~~ | ~~Custom integration~~ | Canceled |
|
||||
| API Migration | Moving to new REST endpoints | 🔧 In Progress |
|
||||
| System | Tests,Builds, Updates, Remote Logging, DB Backups, Alerting | ⏳ Not Started |
|
||||
|
||||
107
backend/eom/eom.gpdata.route.ts
Normal file
107
backend/eom/eom.gpdata.route.ts
Normal file
@@ -0,0 +1,107 @@
|
||||
import { formatInTimeZone } from "date-fns-tz";
|
||||
import { Router } from "express";
|
||||
import { gpQuery } from "../gpSql/gpSqlQuery.controller.js";
|
||||
import {
|
||||
type SqlGPQuery,
|
||||
sqlGpQuerySelector,
|
||||
} from "../gpSql/gpSqlQuerySelector.utils.js";
|
||||
import { apiReturn } from "../utils/returnHelper.utils.js";
|
||||
import { tryCatch } from "../utils/trycatch.utils.js";
|
||||
|
||||
const r = Router();
|
||||
|
||||
r.get("/", async (req, res) => {
|
||||
const { startDate, endDate, glCode, includePlantToken } = req.query;
|
||||
|
||||
if (
|
||||
!startDate ||
|
||||
startDate === "" ||
|
||||
!endDate ||
|
||||
endDate === "" ||
|
||||
!glCode ||
|
||||
glCode === ""
|
||||
) {
|
||||
return apiReturn(res, {
|
||||
success: false,
|
||||
level: "error",
|
||||
module: "eom",
|
||||
subModule: "GpData",
|
||||
message:
|
||||
"The start date, end date, and gl code are required to run this query.",
|
||||
data: [],
|
||||
status: 400,
|
||||
});
|
||||
}
|
||||
const sqlQuery = sqlGpQuerySelector(`gp.eom.data`) as SqlGPQuery;
|
||||
|
||||
if (!sqlQuery.success) {
|
||||
return apiReturn(res, {
|
||||
success: false,
|
||||
level: "error",
|
||||
module: "eom",
|
||||
subModule: "GpData",
|
||||
message:
|
||||
"Failed to get GpData sql file please, please contact support if this continues.",
|
||||
data: [],
|
||||
status: 400,
|
||||
});
|
||||
}
|
||||
|
||||
const { data, error } = await tryCatch(
|
||||
gpQuery(
|
||||
sqlQuery.query
|
||||
.replace("[startDate]", startDate as string)
|
||||
.replace("[endDate]", endDate as string)
|
||||
.replace("[gpCode]", glCode as string),
|
||||
"Eom GpData data",
|
||||
),
|
||||
);
|
||||
|
||||
if (error) {
|
||||
return apiReturn(res, {
|
||||
success: false,
|
||||
level: "error",
|
||||
module: "eom",
|
||||
subModule: "GpData",
|
||||
message: `Error getting GpData data info`,
|
||||
data: error as any,
|
||||
notify: false,
|
||||
status: 400,
|
||||
});
|
||||
}
|
||||
|
||||
return apiReturn(res, {
|
||||
success: data.success,
|
||||
level: data.success ? "info" : "error",
|
||||
module: "eom",
|
||||
subModule: "GpData",
|
||||
message: data.message,
|
||||
data:
|
||||
includePlantToken === "true" && data.success
|
||||
? data.data.map((i) => {
|
||||
return {
|
||||
plantToken: process.env.PROD_PLANT_TOKEN,
|
||||
...i,
|
||||
Date_Received: formatInTimeZone(
|
||||
i.Date_Received,
|
||||
"etc/utc",
|
||||
"M/d/yyyy",
|
||||
),
|
||||
};
|
||||
})
|
||||
: data.data.map((i) => {
|
||||
return {
|
||||
...i,
|
||||
Date_Received: formatInTimeZone(
|
||||
i.Date_Received,
|
||||
"etc/utc",
|
||||
"M/d/yyyy",
|
||||
),
|
||||
};
|
||||
}),
|
||||
notify: false,
|
||||
status: data.success ? 200 : 400,
|
||||
});
|
||||
});
|
||||
|
||||
export default r;
|
||||
9
backend/eom/eom.history.controller.ts
Normal file
9
backend/eom/eom.history.controller.ts
Normal file
@@ -0,0 +1,9 @@
|
||||
/**
|
||||
* The flow that will trigger all the history functions to run and store the data each day and clean up as needed
|
||||
*
|
||||
* if we are on usmcd1vms036 we will run a get request to all servers in the db so we can store that data as well.
|
||||
*
|
||||
* this will be stored in both. the vms036 functions will store in a bigger server so it can be pulled faster and in ssrs
|
||||
*/
|
||||
|
||||
export const eomHistory = async () => {};
|
||||
61
backend/eom/eom.historyInv.route.ts
Normal file
61
backend/eom/eom.historyInv.route.ts
Normal file
@@ -0,0 +1,61 @@
|
||||
import { format } from "date-fns";
|
||||
import { eq } from "drizzle-orm";
|
||||
import { Router } from "express";
|
||||
import { db } from "../db/db.controller.js";
|
||||
import { invHistoricalData } from "../db/schema/historicalInv.schema.js";
|
||||
import { apiReturn } from "../utils/returnHelper.utils.js";
|
||||
import { tryCatch } from "../utils/trycatch.utils.js";
|
||||
|
||||
const r = Router();
|
||||
|
||||
r.get("/", async (req, res) => {
|
||||
// the params we are wanting to add in. min required will be the month so we dont pass everything over
|
||||
const { date } = req.query;
|
||||
|
||||
if (!date || date === "") {
|
||||
return apiReturn(res, {
|
||||
success: false,
|
||||
level: "error",
|
||||
module: "eom",
|
||||
subModule: "historical inv",
|
||||
message:
|
||||
"The day of the month is required to be included in order to pass.",
|
||||
data: [],
|
||||
status: 400,
|
||||
});
|
||||
}
|
||||
|
||||
// get the date passed over.
|
||||
const { data, error } = await tryCatch(
|
||||
db
|
||||
.select()
|
||||
.from(invHistoricalData)
|
||||
.where(
|
||||
eq(invHistoricalData.histDate, format(date as string, "yyyy-MM-dd")),
|
||||
),
|
||||
);
|
||||
|
||||
if (error) {
|
||||
return apiReturn(res, {
|
||||
success: false,
|
||||
level: "error",
|
||||
module: "eom",
|
||||
subModule: "historical inv",
|
||||
message:
|
||||
"There was an error getting the historical data from the server.",
|
||||
data: error as any,
|
||||
status: 400,
|
||||
});
|
||||
}
|
||||
|
||||
return apiReturn(res, {
|
||||
success: true,
|
||||
level: "info",
|
||||
module: "eom",
|
||||
subModule: "historical inv",
|
||||
message: "Eom Historical Inv Data",
|
||||
data: data,
|
||||
status: 200,
|
||||
});
|
||||
});
|
||||
export default r;
|
||||
78
backend/eom/eom.lastPurchasePrice.route.ts
Normal file
78
backend/eom/eom.lastPurchasePrice.route.ts
Normal file
@@ -0,0 +1,78 @@
|
||||
import { formatInTimeZone } from "date-fns-tz";
|
||||
import { Router } from "express";
|
||||
import { prodQuery } from "../prodSql/prodSqlQuery.controller.js";
|
||||
import {
|
||||
type SqlQuery,
|
||||
sqlQuerySelector,
|
||||
} from "../prodSql/prodSqlQuerySelector.utils.js";
|
||||
import { apiReturn } from "../utils/returnHelper.utils.js";
|
||||
import { tryCatch } from "../utils/trycatch.utils.js";
|
||||
|
||||
const r = Router();
|
||||
|
||||
r.get("/", async (req, res) => {
|
||||
const { includePlantToken } = req.query;
|
||||
|
||||
const sqlQuery = sqlQuerySelector(`eom.lastPurchasePrice`) as SqlQuery;
|
||||
|
||||
if (!sqlQuery.success) {
|
||||
return apiReturn(res, {
|
||||
success: false,
|
||||
level: "error",
|
||||
module: "eom",
|
||||
subModule: "lastPurchasePrice",
|
||||
message:
|
||||
"Failed to get last sales price sql file please, please contact support if this continues.",
|
||||
data: [],
|
||||
status: 400,
|
||||
});
|
||||
}
|
||||
|
||||
const { data, error } = await tryCatch(
|
||||
prodQuery(
|
||||
sqlQuery.query,
|
||||
|
||||
"Eom last purchase price data",
|
||||
),
|
||||
);
|
||||
|
||||
if (error) {
|
||||
return apiReturn(res, {
|
||||
success: false,
|
||||
level: "error",
|
||||
module: "eom",
|
||||
subModule: "lastPurchasePrice",
|
||||
message: `Error getting last purchase Price data info`,
|
||||
data: error as any,
|
||||
notify: false,
|
||||
status: 400,
|
||||
});
|
||||
}
|
||||
|
||||
return apiReturn(res, {
|
||||
success: data.success,
|
||||
level: data.success ? "info" : "error",
|
||||
module: "eom",
|
||||
subModule: "lastPurchasePrice",
|
||||
message: data.message,
|
||||
data:
|
||||
includePlantToken === "true" && data.success
|
||||
? data.data.map((i) => {
|
||||
return {
|
||||
plantToken: process.env.PROD_PLANT_TOKEN,
|
||||
...i,
|
||||
//validDate: formatInTimeZone(i.validDate, "etc/utc", "M/d/yyyy"),
|
||||
};
|
||||
})
|
||||
: data.data.map((i) => {
|
||||
return {
|
||||
...i,
|
||||
//validDate: formatInTimeZone(i.validDate, "etc/utc", "M/d/yyyy"),
|
||||
};
|
||||
}),
|
||||
notify: false,
|
||||
status: data.success ? 200 : 400,
|
||||
});
|
||||
});
|
||||
|
||||
export default r;
|
||||
89
backend/eom/eom.lastSalesPrice.route.ts
Normal file
89
backend/eom/eom.lastSalesPrice.route.ts
Normal file
@@ -0,0 +1,89 @@
|
||||
import { formatInTimeZone } from "date-fns-tz";
|
||||
import { Router } from "express";
|
||||
import { prodQuery } from "../prodSql/prodSqlQuery.controller.js";
|
||||
import {
|
||||
type SqlQuery,
|
||||
sqlQuerySelector,
|
||||
} from "../prodSql/prodSqlQuerySelector.utils.js";
|
||||
import { apiReturn } from "../utils/returnHelper.utils.js";
|
||||
import { tryCatch } from "../utils/trycatch.utils.js";
|
||||
|
||||
const r = Router();
|
||||
|
||||
r.get("/", async (req, res) => {
|
||||
const { date, includePlantToken } = req.query;
|
||||
|
||||
if (!date || date === "") {
|
||||
return apiReturn(res, {
|
||||
success: false,
|
||||
level: "error",
|
||||
module: "eom",
|
||||
subModule: "lastSalesPrice",
|
||||
message: "A date is required to run this query.",
|
||||
data: [],
|
||||
status: 400,
|
||||
});
|
||||
}
|
||||
const sqlQuery = sqlQuerySelector(`eom.lastSalesPrice`) as SqlQuery;
|
||||
|
||||
if (!sqlQuery.success) {
|
||||
return apiReturn(res, {
|
||||
success: false,
|
||||
level: "error",
|
||||
module: "eom",
|
||||
subModule: "lastSalesPrice",
|
||||
message:
|
||||
"Failed to get last sales price sql file please, please contact support if this continues.",
|
||||
data: [],
|
||||
status: 400,
|
||||
});
|
||||
}
|
||||
|
||||
const { data, error } = await tryCatch(
|
||||
prodQuery(
|
||||
sqlQuery.query.replace("[date]", date as string),
|
||||
|
||||
"Eom last sales price data",
|
||||
),
|
||||
);
|
||||
|
||||
if (error) {
|
||||
return apiReturn(res, {
|
||||
success: false,
|
||||
level: "error",
|
||||
module: "eom",
|
||||
subModule: "lastSalesPrice",
|
||||
message: `Error getting last Sales Price data info`,
|
||||
data: error as any,
|
||||
notify: false,
|
||||
status: 400,
|
||||
});
|
||||
}
|
||||
|
||||
return apiReturn(res, {
|
||||
success: data.success,
|
||||
level: data.success ? "info" : "error",
|
||||
module: "eom",
|
||||
subModule: "lastSalesPrice",
|
||||
message: data.message,
|
||||
data:
|
||||
includePlantToken === "true" && data.success
|
||||
? data.data.map((i) => {
|
||||
return {
|
||||
plantToken: process.env.PROD_PLANT_TOKEN,
|
||||
...i,
|
||||
validDate: formatInTimeZone(i.validDate, "etc/utc", "M/d/yyyy"),
|
||||
};
|
||||
})
|
||||
: data.data.map((i) => {
|
||||
return {
|
||||
...i,
|
||||
validDate: formatInTimeZone(i.validDate, "etc/utc", "M/d/yyyy"),
|
||||
};
|
||||
}),
|
||||
notify: false,
|
||||
status: data.success ? 200 : 400,
|
||||
});
|
||||
});
|
||||
|
||||
export default r;
|
||||
98
backend/eom/eom.productionConsumption.route.ts
Normal file
98
backend/eom/eom.productionConsumption.route.ts
Normal file
@@ -0,0 +1,98 @@
|
||||
import { formatInTimeZone } from "date-fns-tz";
|
||||
import { Router } from "express";
|
||||
import { prodQuery } from "../prodSql/prodSqlQuery.controller.js";
|
||||
import {
|
||||
type SqlQuery,
|
||||
sqlQuerySelector,
|
||||
} from "../prodSql/prodSqlQuerySelector.utils.js";
|
||||
import { apiReturn } from "../utils/returnHelper.utils.js";
|
||||
import { tryCatch } from "../utils/trycatch.utils.js";
|
||||
|
||||
const r = Router();
|
||||
|
||||
r.get("/", async (req, res) => {
|
||||
const { startDate, endDate, includePlantToken } = req.query;
|
||||
|
||||
if (!startDate || startDate === "" || !endDate || endDate === "") {
|
||||
return apiReturn(res, {
|
||||
success: false,
|
||||
level: "error",
|
||||
module: "eom",
|
||||
subModule: "productionConsumption",
|
||||
message: "The start date and end date are required to run this query.",
|
||||
data: [],
|
||||
status: 400,
|
||||
});
|
||||
}
|
||||
const sqlQuery = sqlQuerySelector(`eom.productionConsumption`) as SqlQuery;
|
||||
|
||||
if (!sqlQuery.success) {
|
||||
return apiReturn(res, {
|
||||
success: false,
|
||||
level: "error",
|
||||
module: "eom",
|
||||
subModule: "productionConsumption",
|
||||
message:
|
||||
"Failed to get production consumption sql file please, please contact support if this continues.",
|
||||
data: [],
|
||||
status: 400,
|
||||
});
|
||||
}
|
||||
|
||||
const { data, error } = await tryCatch(
|
||||
prodQuery(
|
||||
sqlQuery.query
|
||||
.replace("[startDate]", startDate as string)
|
||||
.replace("[endDate]", endDate as string),
|
||||
"Eom production consumption data",
|
||||
),
|
||||
);
|
||||
|
||||
if (error) {
|
||||
return apiReturn(res, {
|
||||
success: false,
|
||||
level: "error",
|
||||
module: "eom",
|
||||
subModule: "productionConsumption",
|
||||
message: `Error getting production consumption data info`,
|
||||
data: error as any,
|
||||
notify: false,
|
||||
status: 400,
|
||||
});
|
||||
}
|
||||
|
||||
return apiReturn(res, {
|
||||
success: data.success,
|
||||
level: data.success ? "info" : "error",
|
||||
module: "eom",
|
||||
subModule: "productionConsumption",
|
||||
message: data.message,
|
||||
data:
|
||||
includePlantToken === "true" && data.success
|
||||
? data.data.map((i) => {
|
||||
return {
|
||||
plantToken: process.env.PROD_PLANT_TOKEN,
|
||||
...i,
|
||||
// Prod_Date: formatInTimeZone(
|
||||
// i.Prod_Date,
|
||||
// "etc/utc",
|
||||
// "M/d/yyyy",
|
||||
// ),
|
||||
};
|
||||
})
|
||||
: data.data.map((i) => {
|
||||
return {
|
||||
...i,
|
||||
// Prod_Date: formatInTimeZone(
|
||||
// i.Prod_Date,
|
||||
// "etc/utc",
|
||||
// "M/d/yyyy",
|
||||
// ),
|
||||
};
|
||||
}),
|
||||
notify: false,
|
||||
status: data.success ? 200 : 400,
|
||||
});
|
||||
});
|
||||
|
||||
export default r;
|
||||
98
backend/eom/eom.purchased.route.ts
Normal file
98
backend/eom/eom.purchased.route.ts
Normal file
@@ -0,0 +1,98 @@
|
||||
import { formatInTimeZone } from "date-fns-tz";
|
||||
import { Router } from "express";
|
||||
import { prodQuery } from "../prodSql/prodSqlQuery.controller.js";
|
||||
import {
|
||||
type SqlQuery,
|
||||
sqlQuerySelector,
|
||||
} from "../prodSql/prodSqlQuerySelector.utils.js";
|
||||
import { apiReturn } from "../utils/returnHelper.utils.js";
|
||||
import { tryCatch } from "../utils/trycatch.utils.js";
|
||||
|
||||
const r = Router();
|
||||
|
||||
r.get("/", async (req, res) => {
|
||||
const { startDate, endDate, includePlantToken } = req.query;
|
||||
|
||||
if (!startDate || startDate === "" || !endDate || endDate === "") {
|
||||
return apiReturn(res, {
|
||||
success: false,
|
||||
level: "error",
|
||||
module: "eom",
|
||||
subModule: "purchased",
|
||||
message: "The start date and end date are required to run this query.",
|
||||
data: [],
|
||||
status: 400,
|
||||
});
|
||||
}
|
||||
const sqlQuery = sqlQuerySelector(`eom.purchased`) as SqlQuery;
|
||||
|
||||
if (!sqlQuery.success) {
|
||||
return apiReturn(res, {
|
||||
success: false,
|
||||
level: "error",
|
||||
module: "eom",
|
||||
subModule: "purchased",
|
||||
message:
|
||||
"Failed to get purchased sql file please, please contact support if this continues.",
|
||||
data: [],
|
||||
status: 400,
|
||||
});
|
||||
}
|
||||
|
||||
const { data, error } = await tryCatch(
|
||||
prodQuery(
|
||||
sqlQuery.query
|
||||
.replace("[startDate]", startDate as string)
|
||||
.replace("[endDate]", endDate as string),
|
||||
"Eom purchased data",
|
||||
),
|
||||
);
|
||||
|
||||
if (error) {
|
||||
return apiReturn(res, {
|
||||
success: false,
|
||||
level: "error",
|
||||
module: "eom",
|
||||
subModule: "purchased",
|
||||
message: `Error getting purchased data info`,
|
||||
data: error as any,
|
||||
notify: false,
|
||||
status: 400,
|
||||
});
|
||||
}
|
||||
|
||||
return apiReturn(res, {
|
||||
success: data.success,
|
||||
level: data.success ? "info" : "error",
|
||||
module: "eom",
|
||||
subModule: "purchased",
|
||||
message: data.message,
|
||||
data:
|
||||
includePlantToken === "true" && data.success
|
||||
? data.data.map((i) => {
|
||||
return {
|
||||
plantToken: process.env.PROD_PLANT_TOKEN,
|
||||
...i,
|
||||
Received_Date: formatInTimeZone(
|
||||
i.Received_Date,
|
||||
"etc/utc",
|
||||
"M/d/yyyy",
|
||||
),
|
||||
};
|
||||
})
|
||||
: data.data.map((i) => {
|
||||
return {
|
||||
...i,
|
||||
Received_Date: formatInTimeZone(
|
||||
i.Received_Date,
|
||||
"etc/utc",
|
||||
"M/d/yyyy",
|
||||
),
|
||||
};
|
||||
}),
|
||||
notify: false,
|
||||
status: data.success ? 200 : 400,
|
||||
});
|
||||
});
|
||||
|
||||
export default r;
|
||||
98
backend/eom/eom.regrind.route.ts
Normal file
98
backend/eom/eom.regrind.route.ts
Normal file
@@ -0,0 +1,98 @@
|
||||
import { formatInTimeZone } from "date-fns-tz";
|
||||
import { Router } from "express";
|
||||
import { prodQuery } from "../prodSql/prodSqlQuery.controller.js";
|
||||
import {
|
||||
type SqlQuery,
|
||||
sqlQuerySelector,
|
||||
} from "../prodSql/prodSqlQuerySelector.utils.js";
|
||||
import { apiReturn } from "../utils/returnHelper.utils.js";
|
||||
import { tryCatch } from "../utils/trycatch.utils.js";
|
||||
|
||||
const r = Router();
|
||||
|
||||
r.get("/", async (req, res) => {
|
||||
const { startDate, endDate, includePlantToken } = req.query;
|
||||
|
||||
if (!startDate || startDate === "" || !endDate || endDate === "") {
|
||||
return apiReturn(res, {
|
||||
success: false,
|
||||
level: "error",
|
||||
module: "eom",
|
||||
subModule: "regrind",
|
||||
message: "The start date and end date are required to run this query.",
|
||||
data: [],
|
||||
status: 400,
|
||||
});
|
||||
}
|
||||
const sqlQuery = sqlQuerySelector(`eom.regrind`) as SqlQuery;
|
||||
|
||||
if (!sqlQuery.success) {
|
||||
return apiReturn(res, {
|
||||
success: false,
|
||||
level: "error",
|
||||
module: "eom",
|
||||
subModule: "regrind",
|
||||
message:
|
||||
"Failed to get regrind sql file please, please contact support if this continues.",
|
||||
data: [],
|
||||
status: 400,
|
||||
});
|
||||
}
|
||||
|
||||
const { data, error } = await tryCatch(
|
||||
prodQuery(
|
||||
sqlQuery.query
|
||||
.replace("[startDate]", startDate as string)
|
||||
.replace("[endDate]", endDate as string),
|
||||
"Eom regrind data",
|
||||
),
|
||||
);
|
||||
|
||||
if (error) {
|
||||
return apiReturn(res, {
|
||||
success: false,
|
||||
level: "error",
|
||||
module: "eom",
|
||||
subModule: "regrind",
|
||||
message: `Error getting regrind data info`,
|
||||
data: error as any,
|
||||
notify: false,
|
||||
status: 400,
|
||||
});
|
||||
}
|
||||
|
||||
return apiReturn(res, {
|
||||
success: data.success,
|
||||
level: data.success ? "info" : "error",
|
||||
module: "eom",
|
||||
subModule: "regrind",
|
||||
message: data.message,
|
||||
data:
|
||||
includePlantToken === "true" && data.success
|
||||
? data.data.map((i) => {
|
||||
return {
|
||||
plantToken: process.env.PROD_PLANT_TOKEN,
|
||||
...i,
|
||||
Buchungsdatum: formatInTimeZone(
|
||||
i.Buchungsdatum,
|
||||
"etc/utc",
|
||||
"M/d/yyyy",
|
||||
),
|
||||
};
|
||||
})
|
||||
: data.data.map((i) => {
|
||||
return {
|
||||
...i,
|
||||
Buchungsdatum: formatInTimeZone(
|
||||
i.Buchungsdatum,
|
||||
"etc/utc",
|
||||
"M/d/yyyy",
|
||||
),
|
||||
};
|
||||
}),
|
||||
notify: false,
|
||||
status: data.success ? 200 : 400,
|
||||
});
|
||||
});
|
||||
|
||||
export default r;
|
||||
35
backend/eom/eom.routes.ts
Normal file
35
backend/eom/eom.routes.ts
Normal file
@@ -0,0 +1,35 @@
|
||||
import type { Express } from "express";
|
||||
import { featureCheck } from "../middleware/featureActive.middleware.js";
|
||||
import gpData from "./eom.gpdata.route.js";
|
||||
import historyInv from "./eom.historyInv.route.js";
|
||||
import lastPurchasePrice from "./eom.lastPurchasePrice.route.js";
|
||||
import lastSalesPrice from "./eom.lastSalesPrice.route.js";
|
||||
import productionConsumption from "./eom.productionConsumption.route.js";
|
||||
import purchased from "./eom.purchased.route.js";
|
||||
import regrind from "./eom.regrind.route.js";
|
||||
import soldItems from "./eom.soldItems.route.js";
|
||||
|
||||
export const setupEomRoutes = (baseUrl: string, app: Express) => {
|
||||
//stats will be like this as we dont need to change this
|
||||
|
||||
app.use(`${baseUrl}/api/eom/historyInv`, featureCheck("eom"), historyInv);
|
||||
app.use(`${baseUrl}/api/eom/purchased`, featureCheck("eom"), purchased);
|
||||
app.use(
|
||||
`${baseUrl}/api/eom/lastSalesPrice`,
|
||||
featureCheck("eom"),
|
||||
lastSalesPrice,
|
||||
);
|
||||
app.use(
|
||||
`${baseUrl}/api/eom/lastPurchasePrice`,
|
||||
featureCheck("eom"),
|
||||
lastPurchasePrice,
|
||||
);
|
||||
app.use(
|
||||
`${baseUrl}/api/eom/productionConsumption`,
|
||||
featureCheck("eom"),
|
||||
productionConsumption,
|
||||
);
|
||||
app.use(`${baseUrl}/api/eom/regrind`, featureCheck("eom"), regrind);
|
||||
app.use(`${baseUrl}/api/eom/soldItems`, featureCheck("eom"), soldItems);
|
||||
app.use(`${baseUrl}/api/eom/gpData`, featureCheck("eom"), gpData);
|
||||
};
|
||||
98
backend/eom/eom.soldItems.route.ts
Normal file
98
backend/eom/eom.soldItems.route.ts
Normal file
@@ -0,0 +1,98 @@
|
||||
import { formatInTimeZone } from "date-fns-tz";
|
||||
import { Router } from "express";
|
||||
import { prodQuery } from "../prodSql/prodSqlQuery.controller.js";
|
||||
import {
|
||||
type SqlQuery,
|
||||
sqlQuerySelector,
|
||||
} from "../prodSql/prodSqlQuerySelector.utils.js";
|
||||
import { apiReturn } from "../utils/returnHelper.utils.js";
|
||||
import { tryCatch } from "../utils/trycatch.utils.js";
|
||||
|
||||
const r = Router();
|
||||
|
||||
r.get("/", async (req, res) => {
|
||||
const { startDate, endDate, includePlantToken } = req.query;
|
||||
|
||||
if (!startDate || startDate === "" || !endDate || endDate === "") {
|
||||
return apiReturn(res, {
|
||||
success: false,
|
||||
level: "error",
|
||||
module: "eom",
|
||||
subModule: "soldItems",
|
||||
message: "The start date and end date are required to run this query.",
|
||||
data: [],
|
||||
status: 400,
|
||||
});
|
||||
}
|
||||
const sqlQuery = sqlQuerySelector(`eom.soldItems`) as SqlQuery;
|
||||
|
||||
if (!sqlQuery.success) {
|
||||
return apiReturn(res, {
|
||||
success: false,
|
||||
level: "error",
|
||||
module: "eom",
|
||||
subModule: "soldItems",
|
||||
message:
|
||||
"Failed to get soldItems sql file please, please contact support if this continues.",
|
||||
data: [],
|
||||
status: 400,
|
||||
});
|
||||
}
|
||||
|
||||
const { data, error } = await tryCatch(
|
||||
prodQuery(
|
||||
sqlQuery.query
|
||||
.replace("[startDate]", startDate as string)
|
||||
.replace("[endDate]", endDate as string),
|
||||
"Eom soldItems data",
|
||||
),
|
||||
);
|
||||
|
||||
if (error) {
|
||||
return apiReturn(res, {
|
||||
success: false,
|
||||
level: "error",
|
||||
module: "eom",
|
||||
subModule: "soldItems",
|
||||
message: `Error getting soldItems data info`,
|
||||
data: error as any,
|
||||
notify: false,
|
||||
status: 400,
|
||||
});
|
||||
}
|
||||
|
||||
return apiReturn(res, {
|
||||
success: data.success,
|
||||
level: data.success ? "info" : "error",
|
||||
module: "eom",
|
||||
subModule: "soldItems",
|
||||
message: data.message,
|
||||
data:
|
||||
includePlantToken === "true" && data.success
|
||||
? data.data.map((i) => {
|
||||
return {
|
||||
plantToken: process.env.PROD_PLANT_TOKEN,
|
||||
...i,
|
||||
DeliveryDate: formatInTimeZone(
|
||||
i.DeliveryDate,
|
||||
"etc/utc",
|
||||
"M/d/yyyy",
|
||||
),
|
||||
};
|
||||
})
|
||||
: data.data.map((i) => {
|
||||
return {
|
||||
...i,
|
||||
DeliveryDate: formatInTimeZone(
|
||||
i.DeliveryDate,
|
||||
"etc/utc",
|
||||
"M/d/yyyy",
|
||||
),
|
||||
};
|
||||
}),
|
||||
notify: false,
|
||||
status: data.success ? 200 : 400,
|
||||
});
|
||||
});
|
||||
|
||||
export default r;
|
||||
16
backend/gpSql/queries/gp.eom.data.sql
Normal file
16
backend/gpSql/queries/gp.eom.data.sql
Normal file
@@ -0,0 +1,16 @@
|
||||
select * from (
|
||||
select
|
||||
case when x.POPRCTNM is null then p.POPRCTNM else p.POPRCTNM end as RCT_Num,
|
||||
PONUMBER PO,
|
||||
p.VENDORID Supplier,
|
||||
ITEMNMBR Item,
|
||||
QTYSHPPD shipped,
|
||||
UOFM Type,
|
||||
TRXLOCTN Location,
|
||||
case when CONVERT(DATE, x.receiptdate) is null then convert(date, p.DATERECD) else CONVERT(DATE, x.receiptdate) end as Date_Received
|
||||
from ALPLA.dbo.pop10500 (nolock) as p
|
||||
left join
|
||||
ALPLA.dbo.POP10300 as x on p.POPRCTNM = x.POPRCTNM
|
||||
WHERE TRXLOCTN LIKE '[gpCode]%' and p.POPTYPE = 1) a
|
||||
|
||||
where Date_Received BETWEEN '[startDate]' AND '[endDate]'
|
||||
15
backend/prodSql/queries/eom.lastPurchasePrice.sql
Normal file
15
backend/prodSql/queries/eom.lastPurchasePrice.sql
Normal file
@@ -0,0 +1,15 @@
|
||||
use AlplaPROD_test1
|
||||
|
||||
SELECT plant=(SELECT Wert FROM dbo.T_SystemParameter (nolock) WHERE (Bezeichnung = 'Werkskuerzel')),
|
||||
plantName=(SELECT Wert FROM dbo.T_SystemParameter AS T_SystemParameter (nolock) WHERE (Bezeichnung = 'Mandant-intern')),*
|
||||
from
|
||||
(Select IdBestellung as 'Purchase order number',
|
||||
IdArtikelVarianten AS AV,
|
||||
BestellMenge,
|
||||
BestellMengeVPK,
|
||||
PreisProEinheit,
|
||||
convert(varchar,Lieferdatum,23) as deliveryDate,
|
||||
ROW_NUMBER() over(partition by IdArtikelVarianten order by Lieferdatum desc) rn
|
||||
from dbo.V_Bestellpositionen_PURCHASE (nolock)
|
||||
where PositionsStatus = '7' or PositionsStatus = '6' or PositionsStatus = '5' and convert(varchar,Lieferdatum,23) > DATEADD(year, -5, GetDate()) )a
|
||||
where rn = 1
|
||||
14
backend/prodSql/queries/eom.lastSalesPrice.sql
Normal file
14
backend/prodSql/queries/eom.lastSalesPrice.sql
Normal file
@@ -0,0 +1,14 @@
|
||||
use AlplaPROD_test1
|
||||
|
||||
select * from
|
||||
(select IdArtikelvarianten as av,
|
||||
VKPreis as salesPrice,
|
||||
MPB, FWMPAlpla,
|
||||
FWMPB,
|
||||
ROW_NUMBER() over(partition by IdArtikelVarianten order by gueltigabdatum desc) rn,
|
||||
convert(date, gueltigabdatum, 120) as validDate
|
||||
from dbo.T_HistoryVK (nolock)
|
||||
where convert(date, gueltigabdatum, 120) <= '[date]' and StandardKunde = 1) a
|
||||
where rn =1
|
||||
order by av asc,
|
||||
validDate desc
|
||||
7
backend/prodSql/queries/eom.productionConsumption.sql
Normal file
7
backend/prodSql/queries/eom.productionConsumption.sql
Normal file
@@ -0,0 +1,7 @@
|
||||
use alplaprod_test1
|
||||
|
||||
SELECT IdArtikelvarianten AS AV,
|
||||
Menge AS Quantity,
|
||||
CONVERT(DATE, BuchDatum) AS Prod_Date
|
||||
FROM dbo.T_LBW (nolock)
|
||||
WHERE BuchDatum BETWEEN '[startDate]' AND '[endDate]' ORDER BY BuchDatum DESC
|
||||
40
backend/prodSql/queries/eom.purchased.sql
Normal file
40
backend/prodSql/queries/eom.purchased.sql
Normal file
@@ -0,0 +1,40 @@
|
||||
use AlplaPROD_test1
|
||||
|
||||
declare @start_date nvarchar(30) = '[startDate] '
|
||||
declare @end_date nvarchar(30) = '[endDate] '
|
||||
|
||||
select T_Wareneingaenge.IdBestellung AS Purchase_order,
|
||||
T_Adressen.IdAdressen,
|
||||
T_Adressen.Bezeichnung,
|
||||
T_Wareneingaenge.IdArtikelVarianten AS AV,
|
||||
V_Artikel.Alias,
|
||||
x.Bemerkung AS Remark,
|
||||
T_Wareneingaenge.Bemerkung AS Purchase_Remark,
|
||||
x.Add_User,
|
||||
CONVERT(DATE, x.Add_Date) AS Received_Date,
|
||||
x.IdWareneingangPlanung,
|
||||
T_Wareneingaenge.SollMenge As Ordered_QTY,
|
||||
x.EntladeMenge As Received_QTY,
|
||||
case when T_Adressen.Bezeichnung LIKE '%Alpla%' Then 'AlplaPlant' Else 'Supplier' End AS
|
||||
Supplier,
|
||||
x.Typ as incoming_goods_type
|
||||
from dbo.T_WareneingangPlanungen (nolock) as x
|
||||
|
||||
join
|
||||
|
||||
dbo.T_Wareneingaenge (nolock) on
|
||||
x.IdWareneingang=
|
||||
dbo.T_Wareneingaenge.IdWareneingang
|
||||
join
|
||||
dbo.V_Artikel (nolock) on
|
||||
dbo.T_Wareneingaenge.IdArtikelVarianten=
|
||||
dbo.V_Artikel.IdArtikelvarianten
|
||||
|
||||
join
|
||||
dbo.T_Adressen (nolock) on dbo.T_Wareneingaenge.IdLieferantAdresse =
|
||||
dbo.T_Adressen.IdAdressen
|
||||
|
||||
where x.add_date between @start_date + (select top(1) CONVERT(char(8), StartDate, 108) as startTime from [test1_AlplaPROD2.0_Read].masterData.ShiftDefinition (nolock) where TeamNumber = 1)
|
||||
AND @end_date + (select top(1) CONVERT(char(8), StartDate, 108) as startTime from [test1_AlplaPROD2.0_Read].masterData.ShiftDefinition (nolock) where TeamNumber = 1)
|
||||
|
||||
order by x.add_date desc
|
||||
13
backend/prodSql/queries/eom.regrind.sql
Normal file
13
backend/prodSql/queries/eom.regrind.sql
Normal file
@@ -0,0 +1,13 @@
|
||||
select IdArtikelVarianten,
|
||||
ArtikelVariantenAlias,
|
||||
IdRezeptur,
|
||||
Menge,
|
||||
IdBuchungsGrund,
|
||||
Buchungsdatum,
|
||||
ProduktionsLos,
|
||||
IdReinheit,
|
||||
ReinheitBez, HerkunftBez
|
||||
from alplaprod_test1.[dbo].[V_AbfallLagerBuchungen] (nolock)
|
||||
where Buchungsdatum between '[startDate] ' + (select top(1) CONVERT(char(8), StartDate, 108) as startTime from [test1_AlplaPROD2.0_Read].masterData.ShiftDefinition (nolock) where TeamNumber = 1)
|
||||
and '[endDate] ' + (select top(1) CONVERT(char(8), StartDate, 108) as startTime from [test1_AlplaPROD2.0_Read].masterData.ShiftDefinition (nolock) where TeamNumber = 1)
|
||||
and IdBuchungsGrund in (140, 240) and BuchungsTyp = 1
|
||||
15
backend/prodSql/queries/eom.soldItems.sql
Normal file
15
backend/prodSql/queries/eom.soldItems.sql
Normal file
@@ -0,0 +1,15 @@
|
||||
select IdArtikelVarianten AS AV,
|
||||
ArtikelVariantenAlias AS AVDescription,
|
||||
convert(date,AbrufLadeDatum,23) As DeliveryDate,
|
||||
idlieferadresse AS DeliveryAddress,
|
||||
LieferAdressBez,
|
||||
AuftragsNummer AS PO_Number,
|
||||
IdAuftragsPosition AS LineITEM,
|
||||
IdAuftragsAbruf AS ReleaseNumber,
|
||||
AbrufMengeVPK AS PalletsRequested,
|
||||
AbrufMenge AS PiecesRequested,
|
||||
GelieferteMengeVPK AS DeliveredPallets,
|
||||
GelieferteMenge AS DeliveredQTY,
|
||||
case when LieferAdressBez Like '%alpla%' Then 'AlplaPlant' ELSE 'Customer' End as CustomerType
|
||||
from alplaprod_test1.dbo.V_TrackerAuftragsAbrufe (nolock)
|
||||
where AbrufLadeDatum between '[startDate]' and '[endDate]'
|
||||
@@ -5,6 +5,7 @@ import { setupAuthRoutes } from "./auth/auth.routes.js";
|
||||
import { setupApiDocsRoutes } from "./configs/scaler.config.js";
|
||||
import { setupDatamartRoutes } from "./datamart/datamart.routes.js";
|
||||
import { setupDockDoorRoutes } from "./dockdoorScanning/dockdoor.routes.js";
|
||||
import { setupEomRoutes } from "./eom/eom.routes.js";
|
||||
import { setupGPSqlRoutes } from "./gpSql/gpSql.routes.js";
|
||||
import { setupMobileRoutes } from "./mobile/mobile.routes.js";
|
||||
import { setupNotificationRoutes } from "./notification/notification.routes.js";
|
||||
@@ -31,4 +32,5 @@ export const setupRoutes = (baseUrl: string, app: Express) => {
|
||||
setupOCPRoutes(baseUrl, app);
|
||||
setupTCPRoutes(baseUrl, app);
|
||||
setupDockDoorRoutes(baseUrl, app);
|
||||
setupEomRoutes(baseUrl, app);
|
||||
};
|
||||
|
||||
@@ -96,6 +96,16 @@ const newSettings: NewSetting[] = [
|
||||
roles: ["admin"],
|
||||
seedVersion: 1,
|
||||
},
|
||||
{
|
||||
name: "eom",
|
||||
value: "0",
|
||||
active: true,
|
||||
description: "Eom processes to capture data",
|
||||
moduleName: "eom",
|
||||
settingType: "feature",
|
||||
roles: ["admin"],
|
||||
seedVersion: 1,
|
||||
},
|
||||
|
||||
// standard settings
|
||||
{
|
||||
|
||||
@@ -17,7 +17,8 @@ export interface ReturnHelper<T = unknown[]> {
|
||||
| "logistics"
|
||||
| "admin"
|
||||
| "mobile"
|
||||
| "dockdoor";
|
||||
| "dockdoor"
|
||||
| "eom";
|
||||
subModule: string;
|
||||
|
||||
level: "info" | "error" | "debug" | "fatal" | "warn";
|
||||
|
||||
Reference in New Issue
Block a user