From 5b1c88546ff9a42dc572450fe05ad68015edb627 Mon Sep 17 00:00:00 2001 From: Blake Matthes Date: Wed, 15 Apr 2026 08:45:48 -0500 Subject: [PATCH] fix(datamart): if we do not have 2.0 warehousing activate we need to use legacy --- backend/datamart/datamart.controller.ts | 27 ++++++++++- .../queries/datamart.legacy.inventory.sql | 48 +++++++++++++++++++ backend/prodSql/queries/featureCheck.sql | 11 +++++ 3 files changed, 85 insertions(+), 1 deletion(-) create mode 100644 backend/prodSql/queries/datamart.legacy.inventory.sql create mode 100644 backend/prodSql/queries/featureCheck.sql diff --git a/backend/datamart/datamart.controller.ts b/backend/datamart/datamart.controller.ts index 954b488..7a8291d 100644 --- a/backend/datamart/datamart.controller.ts +++ b/backend/datamart/datamart.controller.ts @@ -95,7 +95,32 @@ export const runDatamartQuery = async (data: Data) => { notify: false, }); } - const sqlQuery = sqlQuerySelector(`datamart.${data.name}`) as SqlQuery; + + const featureQ = sqlQuerySelector(`featureCheck`) as SqlQuery; + + const { data: fd, error: fe } = await tryCatch( + prodQuery(featureQ.query, `Running feature check`), + ); + + if (fe) { + return returnFunc({ + success: false, + level: "error", + module: "datamart", + subModule: "query", + message: `feature check failed`, + data: fe as any, + notify: false, + }); + } + + // 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}`}`, + ) as SqlQuery; + + // checking if warehousing is as it will start to effect a lot of queries for plants that are not on 2. const getDataMartInfo = datamartData.filter((x) => x.endpoint === data.name); diff --git a/backend/prodSql/queries/datamart.legacy.inventory.sql b/backend/prodSql/queries/datamart.legacy.inventory.sql new file mode 100644 index 0000000..07b1885 --- /dev/null +++ b/backend/prodSql/queries/datamart.legacy.inventory.sql @@ -0,0 +1,48 @@ +select +x.idartikelVarianten as article, +x.ArtikelVariantenAlias as alias +--x.Lfdnr as RunningNumber, +,round(sum(EinlagerungsMengeVPKSum),2) as total_pallets +,sum(EinlagerungsMengeSum) as total_palletQTY +,round(sum(VerfuegbareMengeVPKSum),0) as available_Pallets +,sum(VerfuegbareMengeSum) as available_QTY +,sum(case when c.Description LIKE '%COA%' then GesperrteMengeVPKSum else 0 end) as coa_Pallets +,sum(case when c.Description LIKE '%COA%' then GesperrteMengeSum else 0 end) as coa_QTY +,sum(case when c.Description NOT LIKE '%COA%' or x.IdMainDefect = -1 then GesperrteMengeVPKSum else 0 end) as held_Pallets +,sum(case when c.Description NOT LIKE '%COA%' or x.IdMainDefect = -1 then GesperrteMengeSum else 0 end) as held_QTY +,sum(case when x.WarenLagerLagerTyp = 8 then VerfuegbareMengeSum else 0 end) as consignment_qty +,IdProdPlanung as lot +----,IdAdressen, +,x.AdressBez +,x.IdLagerAbteilung as locationId +,x.LagerAbteilungKurzBez as laneDescription +,x.IdWarenlager as warehouseId +,x.WarenLagerKurzBez as warehouseDescription +--,* +from [AlplaPROD_test1].dbo.[V_LagerPositionenBarcodes] (nolock) x + +left join +[AlplaPROD_test1].dbo.T_EtikettenGedruckt as l(nolock) on +x.Lfdnr = l.Lfdnr AND l.Lfdnr > 1 + +left join + +(SELECT * + FROM [AlplaPROD_test1].[dbo].[T_BlockingDefects] where Active = 1) as c + on x.IdMainDefect = c.IdBlockingDefect +/* +The data below will be controlled by the user in excell by default everything will be passed over + IdAdressen = 3 +*/ +where /*IdArtikelTyp = 1 and */x.IdWarenlager not in (6, 1) + +group by x.idartikelVarianten, ArtikelVariantenAlias, c.Description +--,IdAdressen +,x.AdressBez +,IdProdPlanung +,x.IdLagerAbteilung +,x.LagerAbteilungKurzBez +,x.IdWarenlager +,x.WarenLagerKurzBez +--, x.Lfdnr +order by x.IdArtikelVarianten \ No newline at end of file diff --git a/backend/prodSql/queries/featureCheck.sql b/backend/prodSql/queries/featureCheck.sql new file mode 100644 index 0000000..8ef54f4 --- /dev/null +++ b/backend/prodSql/queries/featureCheck.sql @@ -0,0 +1,11 @@ +SELECT count(*) as activated + FROM [test1_AlplaPROD2.0_Read].[support].[FeatureActivation] + + where feature in (108,7) + + +/* +as more features get activated and need to have this checked to include the new endpoints add here so we can check this. +108 = waste +7 = warehousing +*/