diff --git a/frontend/src/components/logistics/barcodeGenerator/CommonCommands.tsx b/frontend/src/components/logistics/barcodeGenerator/CommonCommands.tsx index 139405f..cdd2a06 100644 --- a/frontend/src/components/logistics/barcodeGenerator/CommonCommands.tsx +++ b/frontend/src/components/logistics/barcodeGenerator/CommonCommands.tsx @@ -6,7 +6,10 @@ import Barcode from "react-barcode"; import { BarcodePDFExport } from "./BarcodeExport"; import { BulkBarcodePDFExport } from "./BulkExport"; -const commoncmd = [{ name: "Relocate", commandId: 33 }]; +const commoncmd = [ + { name: "Relocate", commandId: 33 }, + //-{ name: "Stock in", commandId: 22 }, +]; export default function CommonCommands() { const [checked, setChecked] = useState([]); diff --git a/server/services/eom/controller/getHistoricalInvByDate.ts b/server/services/eom/controller/getHistoricalInvByDate.ts new file mode 100644 index 0000000..e9f245c --- /dev/null +++ b/server/services/eom/controller/getHistoricalInvByDate.ts @@ -0,0 +1,32 @@ +import { eq } from "drizzle-orm"; +import { db } from "../../../../database/dbclient.js"; +import { invHistoricalData } from "../../../../database/schema/historicalINV.js"; +import { tryCatch } from "../../../globalUtils/tryCatch.js"; +import { format } from "date-fns"; + +export const historicalInvByDate = async (date: string) => { + const histDate = new Date(date); + + const { data, error } = (await tryCatch( + db + .select() + .from(invHistoricalData) + .where( + eq(invHistoricalData.histDate, format(histDate, "yyyy-MM-dd")) + ) + )) as any; + + if (error) { + return { + success: false, + message: "There was an error with getting the inventory", + data: error, + }; + } + + return { + success: true, + message: `Historical inventory for ${date}`, + data: data, + }; +}; diff --git a/server/services/eom/controller/getLastPurchasesPrice.ts b/server/services/eom/controller/getLastPurchasesPrice.ts new file mode 100644 index 0000000..1ccf2a4 --- /dev/null +++ b/server/services/eom/controller/getLastPurchasesPrice.ts @@ -0,0 +1,24 @@ +import { tryCatch } from "../../../globalUtils/tryCatch.js"; +import { format } from "date-fns"; +import { query } from "../../sqlServer/prodSqlServer.js"; +import { lastPurchasePrice } from "../../sqlServer/querys/eom/lstPurchasePrice.js"; + +export const lastPurchase = async () => { + const { data, error } = (await tryCatch( + query(lastPurchasePrice, "Last purchase price") + )) as any; + + if (error) { + return { + success: false, + message: "Error getting the last purchase price", + data: error, + }; + } + + return { + success: true, + message: `Last purchase price for all av in the last 5 years`, + data: data.data, + }; +}; diff --git a/server/services/eom/controller/getLastestSalesPrice.ts b/server/services/eom/controller/getLastestSalesPrice.ts new file mode 100644 index 0000000..707a1cf --- /dev/null +++ b/server/services/eom/controller/getLastestSalesPrice.ts @@ -0,0 +1,23 @@ +import { tryCatch } from "../../../globalUtils/tryCatch.js"; +import { query } from "../../sqlServer/prodSqlServer.js"; +import { lastSalesPriceCheck } from "../../sqlServer/querys/eom/lastSalesprice.js"; + +export const lastSales = async (date: string) => { + const { data, error } = (await tryCatch( + query(lastSalesPriceCheck.replace("[date]", date), "Last sales price") + )) as any; + + if (error) { + return { + success: false, + message: "Error getting the last sales price", + data: error, + }; + } + + return { + success: true, + message: `Last sales price for all av in the last 5 years`, + data: data.data, + }; +}; diff --git a/server/services/eom/eomService.ts b/server/services/eom/eomService.ts index 2821216..c220a2e 100644 --- a/server/services/eom/eomService.ts +++ b/server/services/eom/eomService.ts @@ -10,7 +10,10 @@ import { tryCatch } from "../../globalUtils/tryCatch.js"; import { query } from "../sqlServer/prodSqlServer.js"; import { shiftChange } from "../sqlServer/querys/misc/shiftChange.js"; import { createLog } from "../logger/logger.js"; -const routes = [stats, history] as const; +import lastPurch from "./route/getLastPurchPrice.js"; +import lastSales from "./route/getLastSalesPrice.js"; + +const routes = [stats, history, lastPurch, lastSales] as const; const appRoutes = routes.forEach((route) => { app.route("/eom", route); diff --git a/server/services/eom/route/getLastPurchPrice.ts b/server/services/eom/route/getLastPurchPrice.ts new file mode 100644 index 0000000..ad54cd9 --- /dev/null +++ b/server/services/eom/route/getLastPurchPrice.ts @@ -0,0 +1,41 @@ +import { createRoute, OpenAPIHono, z } from "@hono/zod-openapi"; +import { apiHit } from "../../../globalUtils/apiHits.js"; +import { responses } from "../../../globalUtils/routeDefs/responses.js"; + +import { lastPurchase } from "../controller/getLastPurchasesPrice.js"; + +const app = new OpenAPIHono({ strict: false }); + +app.openapi( + createRoute({ + tags: ["eom"], + summary: "Returns last sales price.", + method: "get", + path: "/lastpurchprice", + responses: responses(), + }), + async (c) => { + //const body = await c.req.json(); + // make sure we have a vaid user being accessed thats really logged in + + apiHit(c, { endpoint: "/lastpurchprice" }); + try { + const res = await lastPurchase(); + + return c.json( + { success: res.success, message: res.message, data: res.data }, + 200 + ); + } catch (error) { + return c.json( + { + success: false, + message: "There was an error posting the eom stat.", + data: error, + }, + 400 + ); + } + } +); +export default app; diff --git a/server/services/eom/route/getLastSalesPrice.ts b/server/services/eom/route/getLastSalesPrice.ts new file mode 100644 index 0000000..61150b3 --- /dev/null +++ b/server/services/eom/route/getLastSalesPrice.ts @@ -0,0 +1,43 @@ +import { createRoute, OpenAPIHono, z } from "@hono/zod-openapi"; +import { apiHit } from "../../../globalUtils/apiHits.js"; +import { responses } from "../../../globalUtils/routeDefs/responses.js"; + +import { lastPurchase } from "../controller/getLastPurchasesPrice.js"; +import { lastSales } from "../controller/getLastestSalesPrice.js"; + +const app = new OpenAPIHono({ strict: false }); + +app.openapi( + createRoute({ + tags: ["eom"], + summary: "Returns last sales price.", + method: "get", + path: "/lastsalesprice", + responses: responses(), + }), + async (c) => { + //const body = await c.req.json(); + const month: string = c.req.query("month") ?? ""; + // make sure we have a vaid user being accessed thats really logged in + + apiHit(c, { endpoint: "/lastsalesprice" }); + try { + const res = await lastSales(month); + + return c.json( + { success: res.success, message: res.message, data: res.data }, + 200 + ); + } catch (error) { + return c.json( + { + success: false, + message: "There was an error posting the eom stat.", + data: error, + }, + 400 + ); + } + } +); +export default app; diff --git a/server/services/eom/route/invHistory.ts b/server/services/eom/route/invHistory.ts index bb7a420..9f1d54b 100644 --- a/server/services/eom/route/invHistory.ts +++ b/server/services/eom/route/invHistory.ts @@ -1,6 +1,7 @@ import { createRoute, OpenAPIHono, z } from "@hono/zod-openapi"; import { apiHit } from "../../../globalUtils/apiHits.js"; import { responses } from "../../../globalUtils/routeDefs/responses.js"; +import { historicalInvByDate } from "../controller/getHistoricalInvByDate.js"; const app = new OpenAPIHono({ strict: false }); const EomStat = z.object({ @@ -12,20 +13,24 @@ const EomStat = z.object({ app.openapi( createRoute({ tags: ["eom"], - summary: "Gets the correct eom history.", - method: "post", + summary: "Gets History Data by date.", + method: "get", path: "/histinv", - request: { - params: EomStat, - }, responses: responses(), }), async (c) => { //const body = await c.req.json(); // make sure we have a vaid user being accessed thats really logged in + const month: string = c.req.query("month") ?? ""; + apiHit(c, { endpoint: "/histinv" }); try { - return c.json({ success: true, message: "", data: [] }, 200); + const res = await historicalInvByDate(month); + + return c.json( + { success: res.success, message: res.message, data: res.data }, + 200 + ); } catch (error) { return c.json( { diff --git a/server/services/eom/utils/historicalInv.ts b/server/services/eom/utils/historicalInv.ts index 9e63f15..767cc56 100644 --- a/server/services/eom/utils/historicalInv.ts +++ b/server/services/eom/utils/historicalInv.ts @@ -8,6 +8,7 @@ import { totalInvNoRn } from "../../sqlServer/querys/dataMart/totalINV.js"; import { format } from "date-fns-tz"; import { serverSettings } from "../../server/controller/settings/getSettings.js"; import { deleteHistory } from "./removeHistorical.js"; +import { activeArticle } from "../../sqlServer/querys/dataMart/article.js"; export const historicalInvIMmport = async () => { const plantToken = serverSettings.filter((n) => n.name === "plantToken"); @@ -52,6 +53,12 @@ export const historicalInvIMmport = async () => { return; } + const { data: articles, error: avError } = (await tryCatch( + query(activeArticle, "Get active articles") + )) as any; + + const av = articles.data.length > 0 ? articles.data : ([] as any); + const importInv = inv.data ? inv.data : []; const eomImportData = importInv.map((i: any) => { return { @@ -59,7 +66,13 @@ export const historicalInvIMmport = async () => { plantToken: plantToken[0].value, article: i.av, articleDescription: i.Alias, - materialType: "", + materialType: + av.filter((a: any) => a.IdArtikelvarianten === i.av) + .length > 0 + ? av.filter( + (a: any) => a.IdArtikelvarianten === i.av + )[0]?.TypeOfMaterial + : "Item not defined", total_QTY: i.Total_PalletQTY, avaliable_QTY: i.Avaliable_PalletQTY, coa_QTY: i.COA_QTY, diff --git a/server/services/sqlServer/querys/dataMart/article.ts b/server/services/sqlServer/querys/dataMart/article.ts index 4a42127..268a158 100644 --- a/server/services/sqlServer/querys/dataMart/article.ts +++ b/server/services/sqlServer/querys/dataMart/article.ts @@ -43,7 +43,9 @@ V_Artikel.ArtikelvariantenTypBez = 'Gaylord' or V_Artikel.ArtikelvariantenTypBez = 'Misc. Packaging' or V_Artikel.ArtikelvariantenTypBez = 'Sleeve' or V_Artikel.ArtikelvariantenTypBez = 'Plastic Bag' or -V_Artikel.ArtikelvariantenTypBez = 'Purch Spout' +V_Artikel.ArtikelvariantenTypBez = 'Purch Spout' or +V_Artikel.ArtikelvariantenTypBez = 'Seal' or +V_Artikel.ArtikelvariantenTypBez = 'Tape' THEN 'PKG' WHEN V_Artikel.ArtikelvariantenTypBez='HD-PE' or V_Artikel.ArtikelvariantenTypBez='HD-PE PCR' or @@ -77,7 +79,8 @@ V_Artikel.ArtikelvariantenTypBez = 'Purchased Caps' or V_Artikel.ArtikelvariantenTypBez = 'Purchased_preform' THEN 'Purchased_preform' When -V_Artikel.ArtikelvariantenTypBez = 'Closures' +V_Artikel.ArtikelvariantenTypBez = 'Closures' or +V_Artikel.ArtikelvariantenTypBez = 'Cap' THEN 'Caps' When V_Artikel.ArtikelvariantenTypBez = 'Dummy' @@ -95,7 +98,8 @@ V_Artikel.ProdBereichBez = 'IM-Caps' or V_Artikel.ProdBereichBez = 'IM-PET' or V_Artikel.ProdBereichBez = 'PRINT OFFICE' or V_Artikel.ProdBereichBez = 'EBM' or -V_Artikel.ProdBereichBez = 'ISBM' +V_Artikel.ProdBereichBez = 'ISBM' or +V_Artikel.ProdBereichBez = 'IM-Finishing' Then 'FG' Else 'not Defined Profit Center' end, diff --git a/server/services/sqlServer/querys/eom/lastSalesprice.ts b/server/services/sqlServer/querys/eom/lastSalesprice.ts new file mode 100644 index 0000000..87e8303 --- /dev/null +++ b/server/services/sqlServer/querys/eom/lastSalesprice.ts @@ -0,0 +1,17 @@ +export const lastSalesPriceCheck = ` +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 + +`; diff --git a/server/services/sqlServer/querys/eom/lstPurchasePrice.ts b/server/services/sqlServer/querys/eom/lstPurchasePrice.ts new file mode 100644 index 0000000..d08f393 --- /dev/null +++ b/server/services/sqlServer/querys/eom/lstPurchasePrice.ts @@ -0,0 +1,17 @@ +export const lastPurchasePrice = ` +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 +`;