feat(datamart): finance inventory audit added

This commit is contained in:
2025-06-16 18:30:05 -05:00
parent 68d75277c2
commit 90be86d972
5 changed files with 158 additions and 0 deletions

View File

@@ -0,0 +1,24 @@
import { format } from "date-fns-tz";
import { tryCatch } from "../../../globalUtils/tryCatch.js";
import { query } from "../../sqlServer/prodSqlServer.js";
import { financeAudit } from "../../sqlServer/querys/dataMart/financeAudit.js";
export const getfinanceAudit = async (date: any) => {
let inventoryAudit: any = [];
const { data, error } = (await tryCatch(
query(financeAudit.replace("[date]", date), "inventory audit")
)) as any;
//console.log(data);
if (error) {
return [];
}
inventoryAudit = data.data.map((i: any) => {
return { ...i, bookinDate: format(i.bookinDate, "MM/dd/yyyy") };
});
return inventoryAudit;
};

View File

@@ -8,6 +8,7 @@ import getDeliveryByDate from "./route/getDeliveryDateByRange.js";
import fakeEDI from "./route/fakeEDI.js";
import addressCorrections from "./route/getCityStateData.js";
import fifoIndex from "./route/getFifoIndex.js";
import financeAudit from "./route/getFinanceAudit.js";
const app = new OpenAPIHono();
@@ -21,6 +22,7 @@ const routes = [
fakeEDI,
addressCorrections,
fifoIndex,
financeAudit,
] as const;
const appRoutes = routes.forEach((route) => {

View File

@@ -111,6 +111,14 @@ const current: any = [
"Returns fifo index for all pallets shipped within the last 90 days.",
//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(

View File

@@ -0,0 +1,69 @@
import { createRoute, OpenAPIHono, z } from "@hono/zod-openapi";
import { apiHit } from "../../../globalUtils/apiHits.js";
import { responses } from "../../../globalUtils/routeDefs/responses.js";
import { getfinanceAudit } from "../controller/getFinanceAudit.js";
import { tryCatch } from "../../../globalUtils/tryCatch.js";
const app = new OpenAPIHono({ strict: false });
const EomStat = z.object({
plant: z.string().openapi({ example: "Salt Lake City" }),
userRan: z.string().openapi({ example: "smith034" }),
eomSheetVersion: z.string().openapi({ example: "0.0.223" }),
});
app.openapi(
createRoute({
tags: ["dataMart"],
summary:
"Returns inventory to date and current sales prices and booking date of the inventory.",
method: "get",
path: "/getfinanceaudit",
responses: responses(),
}),
async (c: any) => {
//const body = await c.req.json();
// make sure we have a vaid user being accessed thats really logged in
const { data, error } = (await tryCatch(c.req.query())) as any;
//console.log(data.date);
if (error) {
return {
success: false,
message: "Missing Mandatory Data",
data: error,
};
}
if (!data.date) {
return {
success: false,
message: "Missing Date",
data: [],
};
}
apiHit(c, { endpoint: "/getfinanceaudit", lastBody: data });
try {
return c.json(
{
success: true,
message: `Inventory older than ${data.date}`,
data: await getfinanceAudit(data.date),
},
200
);
} catch (error) {
return c.json(
{
success: false,
message: "There was an error getting inventory data",
data: error,
},
400
);
}
}
);
export default app;

View File

@@ -0,0 +1,55 @@
export const financeAudit = `
use AlplaPROD_test1
select
(select wert from dbo.T_SystemParameter where Bezeichnung = 'Werkskuerzel') as Plant,
b.IdArtikelVarianten
,ArtikelVariantenAlias
,ArtikelVariantenBez
,sum(EinlagerungsMengeVPKSum) totalPal
,sum(EinlagerungsMengeSum) totalPieces
--,ProduktionsDatumMin
,pp.VKPreis as salesPrice
,sp.EKPreis as purhcasePrice
,convert(date, ProduktionsDatumMin, 111) as bookinDate
,DATEDIFF(DAY, convert(date, ProduktionsDatumMin, 111), getdate()) as aged
--,*
from dbo.V_LagerPositionenBarcodes (nolock) b
/* purhcase price */
left join
(select * from (select
IdArtikelvarianten
,VKPreis
,ROW_NUMBER() OVER (PARTITION BY IdArtikelVarianten ORDER BY gueltigabDatum DESC) AS rn
--,*
from T_HistoryVK (nolock))c
where rn = 1) as pp on
b.IdArtikelVarianten = pp.IdArtikelvarianten
/* sales price */
left join
(select * from (select
IdArtikelvarianten
,EKPreis
,ROW_NUMBER() OVER (PARTITION BY IdArtikelVarianten ORDER BY gueltigabDatum DESC) AS rn
--,*
from T_HistoryEK (nolock) )x
where rn = 1) sp on
sp.IdArtikelvarianten = b.IdArtikelVarianten
where IdWarenlager not in (1,5,6)
and ProduktionsDatumMin < '[date]' -- '2025-05-31'
group by b.IdArtikelVarianten
,ArtikelVariantenAlias
,ArtikelVariantenBez
,convert(date, ProduktionsDatumMin, 111)
,pp.VKPreis
,sp.EKPreis
order by IdArtikelVarianten
`;