From cfbc1565172f7c2e27f0a1593fe8e99b00d91bb7 Mon Sep 17 00:00:00 2001 From: Blake Matthes Date: Fri, 17 Apr 2026 08:02:44 -0500 Subject: [PATCH] fix(logistics): historical issue where it was being really weird --- backend/datamart/datamart.controller.ts | 29 +++++++------------ backend/logistics/logistics.historicalInv.ts | 5 +++- .../prodSql/queries/datamart.inventory.sql | 6 ---- 3 files changed, 14 insertions(+), 26 deletions(-) diff --git a/backend/datamart/datamart.controller.ts b/backend/datamart/datamart.controller.ts index 7a8291d..ef24c9e 100644 --- a/backend/datamart/datamart.controller.ts +++ b/backend/datamart/datamart.controller.ts @@ -117,7 +117,7 @@ export const runDatamartQuery = async (data: Data) => { // for queries that will need to be ran on legacy until we get the plant updated need to go in here const doubleQueries = ["inventory"]; const sqlQuery = sqlQuerySelector( - `datamart.${fd.data[0].activated > 0 && doubleQueries.includes(data.name) ? data.name : `legacy.${data.name}`}`, + `datamart.${fd.data[0].activated > 0 && !doubleQueries.includes(data.name) ? data.name : `legacy.${data.name}`}`, ) as SqlQuery; // checking if warehousing is as it will start to effect a lot of queries for plants that are not on 2. @@ -166,7 +166,13 @@ export const runDatamartQuery = async (data: Data) => { case "deliveryByDateRange": datamartQuery = datamartQuery .replace("[startDate]", `${data.options.startDate}`) - .replace("[endDate]", `${data.options.endDate}`); + .replace("[endDate]", `${data.options.endDate}`) + .replace( + "--and r.ArticleHumanReadableId in ([articles]) ", + data.options.articles + ? `and r.ArticleHumanReadableId in (${data.options.articles})` + : "--and r.ArticleHumanReadableId in ([articles]) ", + ); break; case "customerInventory": @@ -199,19 +205,6 @@ export const runDatamartQuery = async (data: Data) => { "--,l.WarehouseDescription,l.LaneDescription", `${data.options.locations ? `,l.WarehouseDescription,l.LaneDescription` : `--,l.WarehouseDescription,l.LaneDescription`}`, ); - - // adding in a test for historical check. - if (data.options.historical) { - datamartQuery = datamartQuery - .replace( - "--,l.ProductionLotRunningNumber as lot,l.warehousehumanreadableid as warehouseId,l.WarehouseDescription as warehouseDescription,l.lanehumanreadableid as locationId,l.lanedescription as laneDescription", - ",l.ProductionLotRunningNumber as lot,l.warehousehumanreadableid as warehouseId,l.WarehouseDescription as warehouseDescription,l.lanehumanreadableid as locationId,l.lanedescription as laneDescription", - ) - .replace( - "--,l.ProductionLotRunningNumber,l.warehousehumanreadableid,l.WarehouseDescription,l.lanehumanreadableid,l.lanedescription", - ",l.ProductionLotRunningNumber,l.warehousehumanreadableid,l.WarehouseDescription,l.lanehumanreadableid,l.lanedescription", - ); - } break; case "fakeEDIUpdate": datamartQuery = datamartQuery.replace( @@ -244,10 +237,8 @@ export const runDatamartQuery = async (data: Data) => { .replace("[startDate]", `${data.options.startDate}`) .replace("[endDate]", `${data.options.endDate}`) .replace( - "and IdArtikelVarianten in ([articles])", - data.options.articles - ? `and IdArtikelVarianten in (${data.options.articles})` - : "--and IdArtikelVarianten in ([articles])", + "[articles]", + data.options.articles ? `${data.options.articles}` : "[articles]", ); break; case "productionData": diff --git a/backend/logistics/logistics.historicalInv.ts b/backend/logistics/logistics.historicalInv.ts index 34c7725..f1e53ea 100644 --- a/backend/logistics/logistics.historicalInv.ts +++ b/backend/logistics/logistics.historicalInv.ts @@ -66,7 +66,10 @@ const historicalInvImport = async () => { const { data: inv, error: invError } = await tryCatch( //prodQuery(sqlQuery.query, "Inventory data"), - runDatamartQuery({ name: "inventory", options: { historical: "x" } }), + runDatamartQuery({ + name: "inventory", + options: { lots: "x", locations: "x" }, + }), ); const { data: av, error: avError } = (await tryCatch( diff --git a/backend/prodSql/queries/datamart.inventory.sql b/backend/prodSql/queries/datamart.inventory.sql index bc963e3..4d89424 100644 --- a/backend/prodSql/queries/datamart.inventory.sql +++ b/backend/prodSql/queries/datamart.inventory.sql @@ -21,9 +21,6 @@ ArticleHumanReadableId as article /** data mart include location data **/ --,l.WarehouseDescription,l.LaneDescription -/** historical section **/ ---,l.ProductionLotRunningNumber as lot,l.warehousehumanreadableid as warehouseId,l.WarehouseDescription as warehouseDescription,l.lanehumanreadableid as locationId,l.lanedescription as laneDescription - ,articleTypeName FROM [warehousing].[WarehouseUnit] as l (nolock) @@ -58,7 +55,4 @@ ArticleTypeName /** data mart include location data **/ --,l.WarehouseDescription,l.LaneDescription -/** historical section **/ ---,l.ProductionLotRunningNumber,l.warehousehumanreadableid,l.WarehouseDescription,l.lanehumanreadableid,l.lanedescription - order by ArticleHumanReadableId \ No newline at end of file