feat(inhouse): delivery by pallet and lot added

This commit is contained in:
2025-12-08 13:16:23 -06:00
parent 4459742cf0
commit 5013228384
5 changed files with 323 additions and 160 deletions

View File

@@ -0,0 +1,81 @@
import { addDays, format } from "date-fns";
import { query } from "../../sqlServer/prodSqlServer.js";
import { inhouseDelivery } from "../../sqlServer/querys/dataMart/inhouseDelivery.js";
export const getInhouseDeliveryByDateRange = async (data: any | null) => {
// const { data: plantToken, error: plantError } = await tryCatch(
// db.select().from(settings).where(eq(settings.name, "plantToken"))
// );
// if (plantError) {
// return {
// success: false,
// message: "Error getting Settings",
// data: plantError,
// };
// }
let deliverys: any = [];
let updatedQuery = inhouseDelivery;
// start days can be sent over
if (data?.start) {
updatedQuery = updatedQuery.replaceAll("[startDate]", data.start[0]);
} else {
updatedQuery = updatedQuery.replaceAll("[startDate]", "1990-1-1");
}
// end days can be sent over
if (data?.end) {
updatedQuery = updatedQuery.replaceAll("[endDate]", data.end[0]);
} else {
const defaultEndDate = format(addDays(new Date(Date.now()), 5), "yyyy-M-d");
updatedQuery = updatedQuery.replaceAll("[endDate]", defaultEndDate);
}
try {
const res: any = await query(
updatedQuery,
"Get inhouse Delivery by date range",
);
deliverys = res.data;
//console.log(res.data);
} catch (error) {
console.log(error);
return {
success: false,
message: "All In-House Deliveries within the range.",
data: error,
};
}
if (!data) {
deliverys = deliverys.splice(1000, 0);
}
// add plant token in
// const pOrders = deliverys.map((item: any) => {
// // const dateCon = new Date(item.loadingDate).toLocaleString("en-US", {
// // month: "numeric",
// // day: "numeric",
// // year: "numeric",
// // hour: "2-digit",
// // minute: "2-digit",
// // hour12: false,
// // });
// //const dateCon = new Date(item.loadingDate).toISOString().replace("T", " ").split(".")[0];
// const dateCon = new Date(item.loadingDate).toISOString().split("T")[0];
// //const delDate = new Date(item.deliveryDate).toISOString().replace("T", " ").split(".")[0];
// const delDate = new Date(item.deliveryDate).toISOString().split("T")[0];
// return {
// plantToken: plantToken[0].value,
// ...item,
// loadingDate: dateCon,
// deliveryDate: delDate,
// };
// });
return {
success: true,
message: "Current In-House deliveries by range",
data: deliverys,
};
};

View File

@@ -1,43 +1,46 @@
import { OpenAPIHono } from "@hono/zod-openapi"; import { OpenAPIHono } from "@hono/zod-openapi";
import activequerys from "./route/getCurrentQuerys.js";
import getArticles from "./route/getActiveArticles.js";
import currentInv from "./route/getInventory.js";
import getCustomerInv from "./route/getCustomerInv.js";
import getOpenOrders from "./route/getOpenOrders.js";
import getDeliveryByDate from "./route/getDeliveryDateByRange.js";
import fakeEDI from "./route/fakeEDI.js"; import fakeEDI from "./route/fakeEDI.js";
import getArticles from "./route/getActiveArticles.js";
import addressCorrections from "./route/getCityStateData.js"; import addressCorrections from "./route/getCityStateData.js";
import activequerys from "./route/getCurrentQuerys.js";
import getCustomerInv from "./route/getCustomerInv.js";
import getDeliveryByDate from "./route/getDeliveryDateByRange.js";
import getDeliveryByDateRangeAndAv from "./route/getDeliveryDateByRangeAndAv.js";
import fifoIndex from "./route/getFifoIndex.js"; import fifoIndex from "./route/getFifoIndex.js";
import financeAudit from "./route/getFinanceAudit.js"; import financeAudit from "./route/getFinanceAudit.js";
import getForecastByAv from "./route/getForecastDataByAv.js";
import getInhouseDeliveryByDate from "./route/getInHouseDeliveryDateByRange.js";
import currentInv from "./route/getInventory.js";
import getOpenOrders from "./route/getOpenOrders.js";
import psiArticleData from "./route/getPsiArticleData.js"; import psiArticleData from "./route/getPsiArticleData.js";
import psiInventory from "./route/getPsiinventory.js";
import psiPlanningData from "./route/getPsiPlanningData.js"; import psiPlanningData from "./route/getPsiPlanningData.js";
import psiProductionData from "./route/getPsiProductionData.js"; import psiProductionData from "./route/getPsiProductionData.js";
import psiInventory from "./route/getPsiinventory.js";
import getForecastByAv from "./route/getForecastDataByAv.js";
import getDeliveryByDateRangeAndAv from "./route/getDeliveryDateByRangeAndAv.js";
const app = new OpenAPIHono(); const app = new OpenAPIHono();
const routes = [ const routes = [
activequerys, activequerys,
getArticles, getArticles,
currentInv, currentInv,
getCustomerInv, getCustomerInv,
getOpenOrders, getOpenOrders,
getDeliveryByDate, getDeliveryByDate,
getDeliveryByDateRangeAndAv, getInhouseDeliveryByDate,
getForecastByAv, getDeliveryByDateRangeAndAv,
fakeEDI, getForecastByAv,
addressCorrections, fakeEDI,
fifoIndex, addressCorrections,
financeAudit, fifoIndex,
psiArticleData, financeAudit,
psiPlanningData, psiArticleData,
psiProductionData, psiPlanningData,
psiInventory, psiProductionData,
psiInventory,
] as const; ] as const;
const appRoutes = routes.forEach((route) => { const appRoutes = routes.forEach((route) => {
app.route("/datamart", route); app.route("/datamart", route);
}); });
export default app; export default app;

View File

@@ -1,146 +1,153 @@
import { createRoute, OpenAPIHono, z } from "@hono/zod-openapi"; import { createRoute, OpenAPIHono, z } from "@hono/zod-openapi";
import { responses } from "../../../globalUtils/routeDefs/responses.js";
import { apiHit } from "../../../globalUtils/apiHits.js"; import { apiHit } from "../../../globalUtils/apiHits.js";
import { responses } from "../../../globalUtils/routeDefs/responses.js";
const app = new OpenAPIHono({ strict: false }); const app = new OpenAPIHono({ strict: false });
const current: any = [ const current: any = [
{ {
name: "getActiveAv", name: "getActiveAv",
endpoint: "/api/datamart/getarticles", endpoint: "/api/datamart/getarticles",
description: "Gets all current active AV, with specific critiera.", description: "Gets all current active AV, with specific critiera.",
}, },
// { // {
// name: "getStockLaneDims", // name: "getStockLaneDims",
// endpoint: "/api/v1/masterData/getStockDims", // endpoint: "/api/v1/masterData/getStockDims",
// description: "Returns the lane dims along with a column to send actaul dims to be updated.", // description: "Returns the lane dims along with a column to send actaul dims to be updated.",
// }, // },
// { // {
// name: "getAddressInfo", // name: "getAddressInfo",
// endpoint: "/api/v1/masterData/getAddressInfo", // endpoint: "/api/v1/masterData/getAddressInfo",
// description: "Returns current active addresses with street and zip", // description: "Returns current active addresses with street and zip",
// }, // },
// { // {
// name: "getMissingPkgData", // name: "getMissingPkgData",
// endpoint: "/api/v1/masterData/getMissingPKGData", // endpoint: "/api/v1/masterData/getMissingPKGData",
// description: "Returns all packaging data that is missing either printer, layout, or carton layout", // description: "Returns all packaging data that is missing either printer, layout, or carton layout",
// }, // },
{ {
name: "getCustomerInventory", name: "getCustomerInventory",
endpoint: "/api/datamart/getcustomerinventory", endpoint: "/api/datamart/getcustomerinventory",
description: description:
"Returns specific customer inventory based on there address ID, with optional to include warehouses, IE 36,41,5. leaving warehouse blank will just pull everything", "Returns specific customer inventory based on there address ID, with optional to include warehouses, IE 36,41,5. leaving warehouse blank will just pull everything",
criteria: "customer,whseToInclude", criteria: "customer,whseToInclude",
}, },
// { // {
// name: "getPalletLabels", // name: "getPalletLabels",
// endpoint: "/api/v1/masterData/getPalletLabels", // endpoint: "/api/v1/masterData/getPalletLabels",
// description: "Returns specific amount of pallets RN, Needs label number and printer, Specfic to Dayton.", // description: "Returns specific amount of pallets RN, Needs label number and printer, Specfic to Dayton.",
// criteria: "runningNumber,printerName,count", // criteria: "runningNumber,printerName,count",
// }, // },
{ {
name: "getopenorders", name: "getopenorders",
endpoint: "/api/datamart/getopenorders", endpoint: "/api/datamart/getopenorders",
description: description:
"Returns open orders based on day count sent over, sDay 15 days in the past eDay 5 days in the future, can be left empty for this default days", "Returns open orders based on day count sent over, sDay 15 days in the past eDay 5 days in the future, can be left empty for this default days",
criteria: "sDay,eDay", criteria: "sDay,eDay",
}, },
// { // {
// name: "getOpenIncoming", // name: "getOpenIncoming",
// endpoint: "/api/v1/masterData/getOpenIncoming", // endpoint: "/api/v1/masterData/getOpenIncoming",
// description: // description:
// "Returns open orders based on day count sent over, sDay 15 days in the past eDay 5 days in the future, can be left empty for this default days", // "Returns open orders based on day count sent over, sDay 15 days in the past eDay 5 days in the future, can be left empty for this default days",
// criteria: "sDay,eDay", // criteria: "sDay,eDay",
// }, // },
// { // {
// name: "planningCheckPkg", // name: "planningCheckPkg",
// endpoint: "/api/v1/masterData/planningPkgCheck", // endpoint: "/api/v1/masterData/planningPkgCheck",
// description: "Returns all lots starting later than today and has a pkg that is missing layouts.", // description: "Returns all lots starting later than today and has a pkg that is missing layouts.",
// }, // },
{ {
name: "getinventory", name: "getinventory",
endpoint: "/api/datamart/getinventory", endpoint: "/api/datamart/getinventory",
// description: "Returns all inventory, by default excludes running numebrs, also excludes inv locations.", // description: "Returns all inventory, by default excludes running numebrs, also excludes inv locations.",
description: description:
"Returns all inventory, excludes inv locations. no running numbers", "Returns all inventory, excludes inv locations. no running numbers",
criteria: "includeRunnningNumbers", // uncomment this out once the improt process can be faster criteria: "includeRunnningNumbers", // uncomment this out once the improt process can be faster
}, },
// { // {
// name: "getOpenOrderUpdates", // name: "getOpenOrderUpdates",
// endpoint: "/api/v1/masterData/getOpenOrderUpdates", // endpoint: "/api/v1/masterData/getOpenOrderUpdates",
// // description: "Returns all inventory, by default excludes running numebrs, also excludes inv locations.", // // description: "Returns all inventory, by default excludes running numebrs, also excludes inv locations.",
// description: "Returns all orders based on customer id, leaving empty will pull everythinng in.", // description: "Returns all orders based on customer id, leaving empty will pull everythinng in.",
// criteria: "customer", // uncomment this out once the improt process can be faster // criteria: "customer", // uncomment this out once the improt process can be faster
// }, // },
{ {
name: "getSiloAdjustment", name: "getSiloAdjustment",
endpoint: "/api/logistics/getsilosdjustment", endpoint: "/api/logistics/getsilosdjustment",
// description: "Returns all inventory, by default excludes running numebrs, also excludes inv locations.", // description: "Returns all inventory, by default excludes running numebrs, also excludes inv locations.",
description: description:
"Returns all siloadjustments in selected date range IE: 1/1/2025 to 1/31/2025", "Returns all siloadjustments in selected date range IE: 1/1/2025 to 1/31/2025",
criteria: "startDate,endDate", // uncomment this out once the improt process can be faster criteria: "startDate,endDate", // uncomment this out once the improt process can be faster
}, },
{ {
name: "Delivery by date trange", name: "Delivery by date range",
endpoint: "/api/datamart/deliverybydaterange", endpoint: "/api/datamart/deliverybydaterange",
// description: "Returns all inventory, by default excludes running numebrs, also excludes inv locations.", // description: "Returns all inventory, by default excludes running numebrs, also excludes inv locations.",
description: description:
"Returns all Deliverys in selected date range IE: 1/1/2025 to 1/31/2025", "Returns all Deliverys in selected date range IE: 1/1/2025 to 1/31/2025",
criteria: "start,end", // uncomment this out once the improt process can be faster criteria: "start,end", // uncomment this out once the improt process can be faster
}, },
{ {
name: "Fake Edi Update", name: "In House Delivery by date range",
endpoint: "/api/datamart/fakeediupdate", endpoint: "/api/datamart/inhousedeliverybydaterange",
// description: "Returns all inventory, by default excludes running numebrs, also excludes inv locations.", // description: "Returns all inventory, by default excludes running numebrs, also excludes inv locations.",
description: description:
"Returns all open orders to correct and resubmit, leaving blank will get everything putting an address only returns the specified address", "Returns all in-house deliveries in selected date range IE: 1/1/2025 to 1/31/2025",
criteria: "address", // uncomment this out once the improt process can be faster criteria: "start,end", // uncomment this out once the improt process can be faster
}, },
{ {
name: "Address Corrections", name: "Fake Edi Update",
endpoint: "/api/datamart/getaddressdata", endpoint: "/api/datamart/fakeediupdate",
// description: "Returns all inventory, by default excludes running numebrs, also excludes inv locations.", // description: "Returns all inventory, by default excludes running numebrs, also excludes inv locations.",
description: description:
"Returns all addresses that will not process correctly in tms due to incorrect city state setup.", "Returns all open orders to correct and resubmit, leaving blank will get everything putting an address only returns the specified address",
//criteria: "address", // uncomment this out once the improt process can be faster criteria: "address", // uncomment this out once the improt process can be faster
}, },
{ {
name: "Fifo index", name: "Address Corrections",
endpoint: "/api/datamart/getfifoindex", endpoint: "/api/datamart/getaddressdata",
// description: "Returns all inventory, by default excludes running numebrs, also excludes inv locations.", // description: "Returns all inventory, by default excludes running numebrs, also excludes inv locations.",
description: description:
"Returns fifo index for all pallets shipped within the last 90 days.", "Returns all addresses that will not process correctly in tms due to incorrect city state setup.",
//criteria: "address", // uncomment this out once the improt process can be faster //criteria: "address", // uncomment this out once the improt process can be faster
}, },
{ {
name: "Finance Audit inv", name: "Fifo index",
endpoint: "/api/datamart/getfinanceaudit", endpoint: "/api/datamart/getfifoindex",
// description: "Returns all inventory, by default excludes running numebrs, also excludes inv locations.", // description: "Returns all inventory, by default excludes running numebrs, also excludes inv locations.",
description: description:
"Returns all inventory past the date provided, ie: 5/31/2025", "Returns fifo index for all pallets shipped within the last 90 days.",
criteria: "date", // uncomment this out once the improt process can be faster //criteria: "address", // uncomment this out once the improt process can be faster
}, },
{
name: "Finance Audit inv",
endpoint: "/api/datamart/getfinanceaudit",
// description: "Returns all inventory, by default excludes running numebrs, also excludes inv locations.",
description: "Returns all inventory past the date provided, ie: 5/31/2025",
criteria: "date", // uncomment this out once the improt process can be faster
},
]; ];
app.openapi( app.openapi(
createRoute({ createRoute({
tags: ["dataMart"], tags: ["dataMart"],
summary: "Returns all avalible querys.", summary: "Returns all avalible querys.",
method: "get", method: "get",
path: "/getavalibleaquerys", path: "/getavalibleaquerys",
responses: responses(), responses: responses(),
}), }),
async (c) => { async (c) => {
//const body = await c.req.json(); //const body = await c.req.json();
// make sure we have a vaid user being accessed thats really logged in // make sure we have a vaid user being accessed thats really logged in
apiHit(c, { endpoint: "/getavalibleaquerys" }); apiHit(c, { endpoint: "/getavalibleaquerys" });
return c.json({ return c.json({
success: true, success: true,
message: "All Current Active Querys.", message: "All Current Active Querys.",
sheetVersion: 2.8, sheetVersion: 2.8,
data: current, data: current,
}); });
} },
); );
export default app; export default app;

View File

@@ -0,0 +1,54 @@
import { createRoute, OpenAPIHono, z } from "@hono/zod-openapi";
import { apiHit } from "../../../globalUtils/apiHits.js";
import { responses } from "../../../globalUtils/routeDefs/responses.js";
import { tryCatch } from "../../../globalUtils/tryCatch.js";
import { getInhouseDeliveryByDateRange } from "../controller/getInhouseDeliveryByDateRange.js";
const app = new OpenAPIHono({ strict: false });
const Body = z.object({
includeRunnningNumbers: z.string().openapi({ example: "x" }),
});
app.openapi(
createRoute({
tags: ["dataMart"],
summary: "Returns deliveries by date range.",
method: "get",
path: "/inhousedeliverybydaterange",
request: {
body: {
content: {
"application/json": { schema: Body },
},
},
},
responses: responses(),
}),
async (c) => {
const delivery: any = c.req.queries();
// make sure we have a vaid user being accessed thats really logged in
apiHit(c, { endpoint: "/inhousedeliverybydaterange" });
const { data, error } = await tryCatch(
getInhouseDeliveryByDateRange(delivery ? delivery : null),
);
if (error) {
console.log(error);
return c.json(
{
success: false,
message: "There was an error getting the deliveries.",
data: error,
},
400,
);
}
return c.json({
success: data.success,
message: data.message,
data: data.data,
});
},
);
export default app;

View File

@@ -0,0 +1,18 @@
export const inhouseDelivery = `
declare @shiftStart varchar(max) = (select top(1) CAST(StartDate AS time(0)) from [test1_AlplaPROD2.0_Read].[masterData].[ShiftDefinition] (nolock) order by TeamNumber)
SELECT TOP (1000)
ProduktionsLos as lot
,Menge as qty
,Barcode as barcode
,IdArtikelVarianten as av
,ArtikelVariantenAlias as alias
,LieferDatum as deliveryDate
--.*
FROM [AlplaPROD_test1].[dbo].V_LieferBuchungen (nolock)
where Urheber = 1350 and ProduktionsLos > 0
and LieferDatum between '[startDate]' + ' ' + @shiftStart
and '[endDate]' + ' ' + @shiftStart
order by LieferDatum desc
`;