product performance grouped kpi improvements

This commit is contained in:
M_Kececi
2026-07-03 15:39:39 +03:00
parent 4cd1b118d0
commit 95d72ec74b
2 changed files with 32 additions and 269 deletions
+13 -74
View File
@@ -56,7 +56,7 @@ func productPerformanceStockQuery() string {
FROM (VALUES
('1-0-14'),('1-0-10'),('1-0-8'),('1-2-5'),('1-2-4'),('1-0-12'),('100'),('1-0-28'),
('1-0-24'),('1-2-6'),('1-1-14'),('1-0-2'),('1-0-52'),('1-1-2'),('1-0-21'),('1-1-3'),
('1-0-33'),('101'),('1-014'),('1-0-49'),('1-0-36')
('1-0-33'),('101'),('1-014'),('1-0-49'),('1-0-36'),('1-0-4'),('1-0-29')
) W(WarehouseCode)
),
Raw AS (
@@ -76,17 +76,7 @@ Raw AS (
INNER JOIN ActiveWarehouses W
ON W.WarehouseCode = LTRIM(RTRIM(S.WarehouseCode))
WHERE S.ItemTypeCode = 1
AND (
LEN(LTRIM(RTRIM(S.ItemCode))) = 13
AND (
UPPER(LTRIM(RTRIM(S.ItemCode))) LIKE 'S%'
OR UPPER(LTRIM(RTRIM(S.ItemCode))) LIKE 'O%'
OR UPPER(LTRIM(RTRIM(S.ItemCode))) LIKE 'N%'
OR UPPER(LTRIM(RTRIM(S.ItemCode))) LIKE 'X%'
OR UPPER(LTRIM(RTRIM(S.ItemCode))) LIKE 'I%'
OR UPPER(LTRIM(RTRIM(S.ItemCode))) LIKE 'A%'
)
)
AND LEN(LTRIM(RTRIM(S.ItemCode))) = 13
AND (@p3 = '' OR UPPER(LTRIM(RTRIM(S.ItemCode))) LIKE @p3 + '%')
AND S.DocumentDate < DATEADD(DAY, 1, @p2)
GROUP BY
@@ -259,14 +249,6 @@ CurrentSource AS (
INNER JOIN ActiveWarehouses W ON W.WarehouseCode = LTRIM(RTRIM(S.WarehouseCode))
WHERE S.ItemTypeCode = 1
AND LEN(LTRIM(RTRIM(S.ItemCode))) = 13
AND (
UPPER(LTRIM(RTRIM(S.ItemCode))) LIKE 'S%'
OR UPPER(LTRIM(RTRIM(S.ItemCode))) LIKE 'O%'
OR UPPER(LTRIM(RTRIM(S.ItemCode))) LIKE 'N%'
OR UPPER(LTRIM(RTRIM(S.ItemCode))) LIKE 'X%'
OR UPPER(LTRIM(RTRIM(S.ItemCode))) LIKE 'I%'
OR UPPER(LTRIM(RTRIM(S.ItemCode))) LIKE 'A%'
)
AND (@p3 = '' OR UPPER(LTRIM(RTRIM(S.ItemCode))) LIKE @p3 + '%')
AND S.DocumentDate < DATEADD(DAY, 1, @p2)
GROUP BY S.WarehouseCode, S.ItemCode, S.ColorCode, S.ItemDim1Code, S.ItemDim2Code, S.ItemDim3Code
@@ -293,16 +275,10 @@ CurrentAvailable AS (
I.ColorCode,
I.YakaKodu,
StockQty = CAST(ROUND(SUM(
CASE
WHEN ISNULL(I.InventoryQty1, 0)
- ISNULL(I.PickingQty1, 0)
- ISNULL(I.ReserveQty1, 0)
- ISNULL(I.DispOrderQty1, 0) < 0 THEN 0
ELSE ISNULL(I.InventoryQty1, 0)
- ISNULL(I.PickingQty1, 0)
- ISNULL(I.ReserveQty1, 0)
- ISNULL(I.DispOrderQty1, 0)
END),
ISNULL(I.InventoryQty1, 0)
- ISNULL(I.PickingQty1, 0)
- ISNULL(I.ReserveQty1, 0)
- ISNULL(I.DispOrderQty1, 0)),
2
) AS decimal(18,4)),
InQty = CAST(0 AS decimal(18,4)),
@@ -321,14 +297,6 @@ CurrentAvailable AS (
AND cdItem.IsBlocked = 0
WHERE I.InventoryQty1 >= 0
AND LEN(I.ProductCode) = 13
AND (
I.ProductCode LIKE 'S%'
OR I.ProductCode LIKE 'O%'
OR I.ProductCode LIKE 'N%'
OR I.ProductCode LIKE 'X%'
OR I.ProductCode LIKE 'I%'
OR I.ProductCode LIKE 'A%'
)
GROUP BY I.ProductCode, I.ColorCode, I.YakaKodu
)
SELECT
@@ -718,13 +686,7 @@ func productPerformanceRefreshStage(raw string) string {
}
func productPerformanceProductPrefix(raw string) string {
prefix := strings.ToUpper(strings.TrimSpace(raw))
switch prefix {
case "", "S", "O", "N", "X", "I", "A":
return prefix
default:
return ""
}
return strings.ToUpper(strings.TrimSpace(raw))
}
func normalizeProductPerformanceProductCode(raw string) string {
@@ -1648,14 +1610,6 @@ WITH OpenOrderLines AS (
AND l.ItemTypeCode = 1
AND ISNULL(l.Qty1, 0) > 0
AND LEN(LTRIM(RTRIM(l.ItemCode))) = 13
AND (
UPPER(LTRIM(RTRIM(l.ItemCode))) LIKE 'S%'
OR UPPER(LTRIM(RTRIM(l.ItemCode))) LIKE 'O%'
OR UPPER(LTRIM(RTRIM(l.ItemCode))) LIKE 'N%'
OR UPPER(LTRIM(RTRIM(l.ItemCode))) LIKE 'X%'
OR UPPER(LTRIM(RTRIM(l.ItemCode))) LIKE 'I%'
OR UPPER(LTRIM(RTRIM(l.ItemCode))) LIKE 'A%'
)
),
Spread AS (
SELECT
@@ -1867,14 +1821,6 @@ WITH OpenOrderLines AS (
AND l.ItemTypeCode = 1
AND ISNULL(l.Qty1, 0) > 0
AND LEN(LTRIM(RTRIM(l.ItemCode))) = 13
AND (
UPPER(LTRIM(RTRIM(l.ItemCode))) LIKE 'S%'
OR UPPER(LTRIM(RTRIM(l.ItemCode))) LIKE 'O%'
OR UPPER(LTRIM(RTRIM(l.ItemCode))) LIKE 'N%'
OR UPPER(LTRIM(RTRIM(l.ItemCode))) LIKE 'X%'
OR UPPER(LTRIM(RTRIM(l.ItemCode))) LIKE 'I%'
OR UPPER(LTRIM(RTRIM(l.ItemCode))) LIKE 'A%'
)
)
SELECT TOP (@p1)
ProductCode,
@@ -2082,7 +2028,6 @@ WITH OpenOrderLines AS (
AND l.ItemTypeCode = 1
AND ISNULL(l.Qty1, 0) > 0
AND LEN(LTRIM(RTRIM(l.ItemCode))) = 13
AND (UPPER(LTRIM(RTRIM(l.ItemCode))) LIKE 'S%' OR UPPER(LTRIM(RTRIM(l.ItemCode))) LIKE 'O%' OR UPPER(LTRIM(RTRIM(l.ItemCode))) LIKE 'N%' OR UPPER(LTRIM(RTRIM(l.ItemCode))) LIKE 'X%' OR UPPER(LTRIM(RTRIM(l.ItemCode))) LIKE 'I%' OR UPPER(LTRIM(RTRIM(l.ItemCode))) LIKE 'A%')
)
SELECT TOP (@p1)
ProductCode, ColorCode, YakaKodu, MAX(ItemDescription), MarketKey, CurrAccCode, CustomerName,
@@ -2207,7 +2152,6 @@ WITH OpenOrderLines AS (
AND l.ItemTypeCode = 1
AND ISNULL(l.Qty1, 0) > 0
AND LEN(LTRIM(RTRIM(l.ItemCode))) = 13
AND (UPPER(LTRIM(RTRIM(l.ItemCode))) LIKE 'S%' OR UPPER(LTRIM(RTRIM(l.ItemCode))) LIKE 'O%' OR UPPER(LTRIM(RTRIM(l.ItemCode))) LIKE 'N%' OR UPPER(LTRIM(RTRIM(l.ItemCode))) LIKE 'X%' OR UPPER(LTRIM(RTRIM(l.ItemCode))) LIKE 'I%' OR UPPER(LTRIM(RTRIM(l.ItemCode))) LIKE 'A%')
)
SELECT TOP (@p1)
MarketKey, CurrAccCode, CustomerName, OrderNumber, CONVERT(varchar, OrderDate, 23), CONVERT(varchar, DueDate, 23),
@@ -3925,7 +3869,7 @@ func ListProductPerformanceStockSizes(ctx context.Context, productCode, colorCod
FROM (VALUES
('1-0-14'),('1-0-10'),('1-0-8'),('1-2-5'),('1-2-4'),('1-0-12'),('100'),('1-0-28'),
('1-0-24'),('1-2-6'),('1-1-14'),('1-0-2'),('1-0-52'),('1-1-2'),('1-0-21'),('1-1-3'),
('1-0-33'),('101'),('1-014'),('1-0-49'),('1-0-36')
('1-0-33'),('101'),('1-014'),('1-0-49'),('1-0-36'),('1-0-4'),('1-0-29')
) W(WarehouseCode)
),
Stock AS (
@@ -3988,20 +3932,15 @@ AvailableBySizeWarehouse AS (
SELECT
S.SizeCode,
StockQty =
CASE
WHEN ISNULL(S.InventoryQty1, 0)
- ISNULL(P.PickingQty1, 0)
- ISNULL(R.ReserveQty1, 0)
- ISNULL(D.DispOrderQty1, 0) < 0 THEN 0
ELSE ISNULL(S.InventoryQty1, 0)
- ISNULL(P.PickingQty1, 0)
- ISNULL(R.ReserveQty1, 0)
- ISNULL(D.DispOrderQty1, 0)
END
ISNULL(S.InventoryQty1, 0)
- ISNULL(P.PickingQty1, 0)
- ISNULL(R.ReserveQty1, 0)
- ISNULL(D.DispOrderQty1, 0)
FROM Stock S
LEFT JOIN Pick P ON P.SizeCode = S.SizeCode AND P.WarehouseCode = S.WarehouseCode
LEFT JOIN Reserve R ON R.SizeCode = S.SizeCode AND R.WarehouseCode = S.WarehouseCode
LEFT JOIN Disp D ON D.SizeCode = S.SizeCode AND D.WarehouseCode = S.WarehouseCode
WHERE S.InventoryQty1 >= 0
)
SELECT
SizeCode,