diff --git a/svc/queries/product_pricing_dims_mssql.go b/svc/queries/product_pricing_dims_mssql.go index d5baf70..f77063a 100644 --- a/svc/queries/product_pricing_dims_mssql.go +++ b/svc/queries/product_pricing_dims_mssql.go @@ -4,15 +4,16 @@ package queries // Pull variant dimension combos from Nebim's variant master table. // We intentionally keep it small: only the keys we need to write dim-aware prices into PG sdprc. // -// Note: Column semantics depend on your Nebim setup. We treat ItemDim1Code/ItemDim3Code as the -// primary variant dimensions used by the e-commerce sdprc dim filters. +// Note: Column semantics depend on your Nebim setup. Here ColorCode and ItemDim2Code are the +// user-visible/key dimensions; PG stores them as mmitem_dim.val1 and mmitem_dim.val3. +// ItemDim1Code is kept only as size context for mmitem_dim seeding. const GetProductVariantDimsForPricing = ` DECLARE @ProductCode NVARCHAR(50) = @p1; SELECT DISTINCT LTRIM(RTRIM(ISNULL(V.ColorCode,''))) AS ColorCode, LTRIM(RTRIM(ISNULL(V.ItemDim1Code,''))) AS ItemDim1Code, - LTRIM(RTRIM(ISNULL(V.ItemDim3Code,''))) AS ItemDim3Code + LTRIM(RTRIM(ISNULL(V.ItemDim2Code,''))) AS ItemDim3Code FROM prItemVariant V WITH(NOLOCK) WHERE V.ItemTypeCode = 1 AND V.ItemCode = @ProductCode @@ -21,5 +22,5 @@ WHERE V.ItemTypeCode = 1 ORDER BY LTRIM(RTRIM(ISNULL(V.ColorCode,''))), LTRIM(RTRIM(ISNULL(V.ItemDim1Code,''))), - LTRIM(RTRIM(ISNULL(V.ItemDim3Code,''))); + LTRIM(RTRIM(ISNULL(V.ItemDim2Code,''))); ` diff --git a/svc/queries/wholesale_campaign_variants_mssql.go b/svc/queries/wholesale_campaign_variants_mssql.go index a31400d..3d37918 100644 --- a/svc/queries/wholesale_campaign_variants_mssql.go +++ b/svc/queries/wholesale_campaign_variants_mssql.go @@ -1,8 +1,9 @@ package queries // GetWholesaleCampaignVariantStockByProducts: -// Returns per-product variant keys (ColorCode/ItemDim1Code/ItemDim3Code) and available stock qty. +// Returns per-product variant keys (ColorCode/ItemDim1Code/ItemDim2Code-as-ItemDim3Code) and available stock qty. // We aggregate across warehouses/stores; semantics align with product-stock-query's "Kullanilabilir_Envanter". +// In this Nebim setup, the second user-visible/key variant maps to ItemDim2Code, while PG stores it in mmitem_dim.val3. const GetWholesaleCampaignVariantStockByProducts = ` DECLARE @Codes NVARCHAR(MAX) = @p1; @@ -20,27 +21,27 @@ VARIANT_MASTER AS ( SELECT V.ItemCode, LTRIM(RTRIM(ISNULL(V.ColorCode,''))) AS ColorCode, - LTRIM(RTRIM(ISNULL(V.ItemDim3Code,''))) AS ItemDim3Code, + LTRIM(RTRIM(ISNULL(V.ItemDim2Code,''))) AS ItemDim3Code, MAX(LTRIM(RTRIM(ISNULL(V.ItemDim1Code,'')))) AS ItemDim1Code FROM prItemVariant V WITH(NOLOCK) JOIN INP ON INP.ItemCode = V.ItemCode WHERE V.ItemTypeCode = 1 AND LEN(V.ItemCode) = 13 GROUP BY - V.ItemCode, V.ColorCode, V.ItemDim3Code + V.ItemCode, V.ColorCode, V.ItemDim2Code ), VARIANT_STOCK AS ( SELECT S.ItemCode, LTRIM(RTRIM(ISNULL(S.ColorCode,''))) AS ColorCode, - LTRIM(RTRIM(ISNULL(S.ItemDim3Code,''))) AS ItemDim3Code, + LTRIM(RTRIM(ISNULL(S.ItemDim2Code,''))) AS ItemDim3Code, MAX(LTRIM(RTRIM(ISNULL(S.ItemDim1Code,'')))) AS ItemDim1Code FROM trStock S WITH(NOLOCK) JOIN INP ON INP.ItemCode = S.ItemCode WHERE S.ItemTypeCode = 1 AND LEN(S.ItemCode) = 13 GROUP BY - S.ItemCode, S.ColorCode, S.ItemDim3Code + S.ItemCode, S.ColorCode, S.ItemDim2Code ), VARIANT AS ( SELECT @@ -59,7 +60,7 @@ STOCK AS ( SELECT S.ItemCode, LTRIM(RTRIM(ISNULL(S.ColorCode,''))) AS ColorCode, - LTRIM(RTRIM(ISNULL(S.ItemDim3Code,''))) AS ItemDim3Code, + LTRIM(RTRIM(ISNULL(S.ItemDim2Code,''))) AS ItemDim3Code, MAX(LTRIM(RTRIM(ISNULL(S.ItemDim1Code,'')))) AS ItemDim1Code, SUM(S.In_Qty1 - S.Out_Qty1) AS InventoryQty1 FROM trStock S WITH(NOLOCK) @@ -67,13 +68,13 @@ STOCK AS ( WHERE S.ItemTypeCode = 1 AND LEN(S.ItemCode) = 13 GROUP BY - S.ItemCode, S.ColorCode, S.ItemDim3Code + S.ItemCode, S.ColorCode, S.ItemDim2Code ), PICK AS ( SELECT P.ItemCode, LTRIM(RTRIM(ISNULL(P.ColorCode,''))) AS ColorCode, - LTRIM(RTRIM(ISNULL(P.ItemDim3Code,''))) AS ItemDim3Code, + LTRIM(RTRIM(ISNULL(P.ItemDim2Code,''))) AS ItemDim3Code, MAX(LTRIM(RTRIM(ISNULL(P.ItemDim1Code,'')))) AS ItemDim1Code, SUM(P.Qty1) AS PickingQty1 FROM PickingStates P @@ -81,13 +82,13 @@ PICK AS ( WHERE P.ItemTypeCode = 1 AND LEN(P.ItemCode) = 13 GROUP BY - P.ItemCode, P.ColorCode, P.ItemDim3Code + P.ItemCode, P.ColorCode, P.ItemDim2Code ), RESERVE AS ( SELECT R.ItemCode, LTRIM(RTRIM(ISNULL(R.ColorCode,''))) AS ColorCode, - LTRIM(RTRIM(ISNULL(R.ItemDim3Code,''))) AS ItemDim3Code, + LTRIM(RTRIM(ISNULL(R.ItemDim2Code,''))) AS ItemDim3Code, MAX(LTRIM(RTRIM(ISNULL(R.ItemDim1Code,'')))) AS ItemDim1Code, SUM(R.Qty1) AS ReserveQty1 FROM ReserveStates R @@ -95,13 +96,13 @@ RESERVE AS ( WHERE R.ItemTypeCode = 1 AND LEN(R.ItemCode) = 13 GROUP BY - R.ItemCode, R.ColorCode, R.ItemDim3Code + R.ItemCode, R.ColorCode, R.ItemDim2Code ), DISP AS ( SELECT D.ItemCode, LTRIM(RTRIM(ISNULL(D.ColorCode,''))) AS ColorCode, - LTRIM(RTRIM(ISNULL(D.ItemDim3Code,''))) AS ItemDim3Code, + LTRIM(RTRIM(ISNULL(D.ItemDim2Code,''))) AS ItemDim3Code, MAX(LTRIM(RTRIM(ISNULL(D.ItemDim1Code,'')))) AS ItemDim1Code, SUM(D.Qty1) AS DispOrderQty1 FROM DispOrderStates D @@ -109,7 +110,7 @@ DISP AS ( WHERE D.ItemTypeCode = 1 AND LEN(D.ItemCode) = 13 GROUP BY - D.ItemCode, D.ColorCode, D.ItemDim3Code + D.ItemCode, D.ColorCode, D.ItemDim2Code ) SELECT V.ItemCode AS ItemCode, diff --git a/svc/routes/product_pricing_save.go b/svc/routes/product_pricing_save.go index 5cbd383..e9606c3 100644 --- a/svc/routes/product_pricing_save.go +++ b/svc/routes/product_pricing_save.go @@ -562,7 +562,7 @@ DO UPDATE SET dim_id = EXCLUDED.dim_id, updated_at = EXCLUDED.updated_at } // Resolve to PG dim ids. For this installation we align with mmitem_dim key: // - dim1 = color - // - dim3 = itemdim3 (optional) + // - dim3 = ItemDim2Code/yaka (optional) // Size (ItemDim1Code) is not part of the key here. d1 := int64(0) if id, ok := resolveDimvalFromToken(pgTx, "dimval1", colorCode); ok { @@ -579,7 +579,7 @@ DO UPDATE SET dim_id = EXCLUDED.dim_id, updated_at = EXCLUDED.updated_at continue } var d3 sql.NullInt64 - // dim3 corresponds to mmitem_dim.val3 (ItemDim3Code). + // dim3 corresponds to mmitem_dim.val3. if id, ok := resolveDimvalFromToken(pgTx, "dimval1", dim3Code); ok { d3 = sql.NullInt64{Int64: id, Valid: true} resolvedDim3++