product performance grouped kpi improvements
This commit is contained in:
@@ -189,7 +189,9 @@ CurrentStock AS (
|
||||
SELECT
|
||||
ProductCode = UPPER(LTRIM(RTRIM(S.ItemCode))),
|
||||
ColorCode = UPPER(LTRIM(RTRIM(ISNULL(S.ColorCode, '')))),
|
||||
SizeCode = UPPER(LTRIM(RTRIM(ISNULL(S.ItemDim1Code, '')))),
|
||||
YakaKodu = UPPER(LTRIM(RTRIM(ISNULL(S.ItemDim2Code, '')))),
|
||||
WarehouseCode = LTRIM(RTRIM(S.WarehouseCode)),
|
||||
InventoryQty1 = SUM(S.In_Qty1 - S.Out_Qty1)
|
||||
FROM trStock S WITH(NOLOCK)
|
||||
INNER JOIN ActiveWarehouses W
|
||||
@@ -208,13 +210,15 @@ CurrentStock AS (
|
||||
)
|
||||
AND (@p3 = '' OR UPPER(LTRIM(RTRIM(S.ItemCode))) LIKE @p3 + '%')
|
||||
AND S.DocumentDate < DATEADD(DAY, 1, @p2)
|
||||
GROUP BY S.ItemCode, S.ColorCode, S.ItemDim2Code
|
||||
GROUP BY S.ItemCode, S.ColorCode, S.ItemDim1Code, S.ItemDim2Code, LTRIM(RTRIM(S.WarehouseCode))
|
||||
),
|
||||
CurrentPick AS (
|
||||
SELECT
|
||||
ProductCode = UPPER(LTRIM(RTRIM(P.ItemCode))),
|
||||
ColorCode = UPPER(LTRIM(RTRIM(ISNULL(P.ColorCode, '')))),
|
||||
SizeCode = UPPER(LTRIM(RTRIM(ISNULL(P.ItemDim1Code, '')))),
|
||||
YakaKodu = UPPER(LTRIM(RTRIM(ISNULL(P.ItemDim2Code, '')))),
|
||||
WarehouseCode = LTRIM(RTRIM(P.WarehouseCode)),
|
||||
PickingQty1 = SUM(P.Qty1)
|
||||
FROM PickingStates P WITH(NOLOCK)
|
||||
INNER JOIN ActiveWarehouses W
|
||||
@@ -222,13 +226,15 @@ CurrentPick AS (
|
||||
WHERE P.ItemTypeCode = 1
|
||||
AND LEN(LTRIM(RTRIM(P.ItemCode))) = 13
|
||||
AND (@p3 = '' OR UPPER(LTRIM(RTRIM(P.ItemCode))) LIKE @p3 + '%')
|
||||
GROUP BY P.ItemCode, P.ColorCode, P.ItemDim2Code
|
||||
GROUP BY P.ItemCode, P.ColorCode, P.ItemDim1Code, P.ItemDim2Code, LTRIM(RTRIM(P.WarehouseCode))
|
||||
),
|
||||
CurrentReserve AS (
|
||||
SELECT
|
||||
ProductCode = UPPER(LTRIM(RTRIM(R.ItemCode))),
|
||||
ColorCode = UPPER(LTRIM(RTRIM(ISNULL(R.ColorCode, '')))),
|
||||
SizeCode = UPPER(LTRIM(RTRIM(ISNULL(R.ItemDim1Code, '')))),
|
||||
YakaKodu = UPPER(LTRIM(RTRIM(ISNULL(R.ItemDim2Code, '')))),
|
||||
WarehouseCode = LTRIM(RTRIM(R.WarehouseCode)),
|
||||
ReserveQty1 = SUM(R.Qty1)
|
||||
FROM ReserveStates R WITH(NOLOCK)
|
||||
INNER JOIN ActiveWarehouses W
|
||||
@@ -236,13 +242,15 @@ CurrentReserve AS (
|
||||
WHERE R.ItemTypeCode = 1
|
||||
AND LEN(LTRIM(RTRIM(R.ItemCode))) = 13
|
||||
AND (@p3 = '' OR UPPER(LTRIM(RTRIM(R.ItemCode))) LIKE @p3 + '%')
|
||||
GROUP BY R.ItemCode, R.ColorCode, R.ItemDim2Code
|
||||
GROUP BY R.ItemCode, R.ColorCode, R.ItemDim1Code, R.ItemDim2Code, LTRIM(RTRIM(R.WarehouseCode))
|
||||
),
|
||||
CurrentDisp AS (
|
||||
SELECT
|
||||
ProductCode = UPPER(LTRIM(RTRIM(D.ItemCode))),
|
||||
ColorCode = UPPER(LTRIM(RTRIM(ISNULL(D.ColorCode, '')))),
|
||||
SizeCode = UPPER(LTRIM(RTRIM(ISNULL(D.ItemDim1Code, '')))),
|
||||
YakaKodu = UPPER(LTRIM(RTRIM(ISNULL(D.ItemDim2Code, '')))),
|
||||
WarehouseCode = LTRIM(RTRIM(D.WarehouseCode)),
|
||||
DispOrderQty1 = SUM(D.Qty1)
|
||||
FROM DispOrderStates D WITH(NOLOCK)
|
||||
INNER JOIN ActiveWarehouses W
|
||||
@@ -250,7 +258,7 @@ CurrentDisp AS (
|
||||
WHERE D.ItemTypeCode = 1
|
||||
AND LEN(LTRIM(RTRIM(D.ItemCode))) = 13
|
||||
AND (@p3 = '' OR UPPER(LTRIM(RTRIM(D.ItemCode))) LIKE @p3 + '%')
|
||||
GROUP BY D.ItemCode, D.ColorCode, D.ItemDim2Code
|
||||
GROUP BY D.ItemCode, D.ColorCode, D.ItemDim1Code, D.ItemDim2Code, LTRIM(RTRIM(D.WarehouseCode))
|
||||
),
|
||||
CurrentAvailable AS (
|
||||
SELECT
|
||||
@@ -258,11 +266,17 @@ CurrentAvailable AS (
|
||||
S.ProductCode,
|
||||
S.ColorCode,
|
||||
S.YakaKodu,
|
||||
StockQty = CAST(ROUND(
|
||||
ISNULL(S.InventoryQty1, 0)
|
||||
StockQty = CAST(ROUND(SUM(
|
||||
CASE
|
||||
WHEN ISNULL(S.InventoryQty1, 0)
|
||||
- ISNULL(PK.PickingQty1, 0)
|
||||
- ISNULL(RS.ReserveQty1, 0)
|
||||
- ISNULL(DP.DispOrderQty1, 0),
|
||||
- ISNULL(DP.DispOrderQty1, 0) < 0 THEN 0
|
||||
ELSE ISNULL(S.InventoryQty1, 0)
|
||||
- ISNULL(PK.PickingQty1, 0)
|
||||
- ISNULL(RS.ReserveQty1, 0)
|
||||
- ISNULL(DP.DispOrderQty1, 0)
|
||||
END),
|
||||
2
|
||||
) AS decimal(18,4)),
|
||||
InQty = CAST(0 AS decimal(18,4)),
|
||||
@@ -276,11 +290,12 @@ CurrentAvailable AS (
|
||||
CountDiffQty = CAST(0 AS decimal(18,4))
|
||||
FROM CurrentStock S
|
||||
LEFT JOIN CurrentPick PK
|
||||
ON PK.ProductCode = S.ProductCode AND PK.ColorCode = S.ColorCode AND PK.YakaKodu = S.YakaKodu
|
||||
ON PK.ProductCode = S.ProductCode AND PK.ColorCode = S.ColorCode AND PK.SizeCode = S.SizeCode AND PK.YakaKodu = S.YakaKodu AND PK.WarehouseCode = S.WarehouseCode
|
||||
LEFT JOIN CurrentReserve RS
|
||||
ON RS.ProductCode = S.ProductCode AND RS.ColorCode = S.ColorCode AND RS.YakaKodu = S.YakaKodu
|
||||
ON RS.ProductCode = S.ProductCode AND RS.ColorCode = S.ColorCode AND RS.SizeCode = S.SizeCode AND RS.YakaKodu = S.YakaKodu AND RS.WarehouseCode = S.WarehouseCode
|
||||
LEFT JOIN CurrentDisp DP
|
||||
ON DP.ProductCode = S.ProductCode AND DP.ColorCode = S.ColorCode AND DP.YakaKodu = S.YakaKodu
|
||||
ON DP.ProductCode = S.ProductCode AND DP.ColorCode = S.ColorCode AND DP.SizeCode = S.SizeCode AND DP.YakaKodu = S.YakaKodu AND DP.WarehouseCode = S.WarehouseCode
|
||||
GROUP BY S.ProductCode, S.ColorCode, S.YakaKodu
|
||||
)
|
||||
SELECT
|
||||
StockDate,
|
||||
@@ -3867,6 +3882,9 @@ func ListProductPerformanceStockSizes(ctx context.Context, productCode, colorCod
|
||||
if db.MssqlDB == nil {
|
||||
return nil, fmt.Errorf("mssql db nil")
|
||||
}
|
||||
productCode = normalizeProductPerformanceProductCode(productCode)
|
||||
colorCode = normalizeProductPerformanceCode(colorCode)
|
||||
yakaKodu = normalizeProductPerformanceCode(yakaKodu)
|
||||
rows, err := db.MssqlDB.QueryContext(ctx, `
|
||||
;WITH ActiveWarehouses AS (
|
||||
SELECT WarehouseCode
|
||||
@@ -3878,76 +3896,86 @@ func ListProductPerformanceStockSizes(ctx context.Context, productCode, colorCod
|
||||
),
|
||||
Stock AS (
|
||||
SELECT
|
||||
SizeCode = LTRIM(RTRIM(ISNULL(S.ItemDim1Code, ''))),
|
||||
SizeCode = UPPER(LTRIM(RTRIM(ISNULL(S.ItemDim1Code, '')))),
|
||||
WarehouseCode = LTRIM(RTRIM(S.WarehouseCode)),
|
||||
InventoryQty1 = SUM(S.In_Qty1 - S.Out_Qty1)
|
||||
FROM trStock S WITH(NOLOCK)
|
||||
INNER JOIN ActiveWarehouses W
|
||||
ON W.WarehouseCode = LTRIM(RTRIM(S.WarehouseCode))
|
||||
WHERE S.ItemTypeCode = 1
|
||||
AND LTRIM(RTRIM(S.ItemCode)) = @p1
|
||||
AND LTRIM(RTRIM(ISNULL(S.ColorCode, ''))) = @p2
|
||||
AND LTRIM(RTRIM(ISNULL(S.ItemDim2Code, ''))) = @p3
|
||||
GROUP BY LTRIM(RTRIM(ISNULL(S.ItemDim1Code, '')))
|
||||
AND UPPER(LTRIM(RTRIM(S.ItemCode))) = @p1
|
||||
AND UPPER(LTRIM(RTRIM(ISNULL(S.ColorCode, '')))) = @p2
|
||||
AND UPPER(LTRIM(RTRIM(ISNULL(S.ItemDim2Code, '')))) = @p3
|
||||
GROUP BY UPPER(LTRIM(RTRIM(ISNULL(S.ItemDim1Code, '')))), LTRIM(RTRIM(S.WarehouseCode))
|
||||
),
|
||||
Pick AS (
|
||||
SELECT
|
||||
SizeCode = LTRIM(RTRIM(ISNULL(P.ItemDim1Code, ''))),
|
||||
SizeCode = UPPER(LTRIM(RTRIM(ISNULL(P.ItemDim1Code, '')))),
|
||||
WarehouseCode = LTRIM(RTRIM(P.WarehouseCode)),
|
||||
PickingQty1 = SUM(P.Qty1)
|
||||
FROM PickingStates P WITH(NOLOCK)
|
||||
INNER JOIN ActiveWarehouses W
|
||||
ON W.WarehouseCode = LTRIM(RTRIM(P.WarehouseCode))
|
||||
WHERE P.ItemTypeCode = 1
|
||||
AND LTRIM(RTRIM(P.ItemCode)) = @p1
|
||||
AND LTRIM(RTRIM(ISNULL(P.ColorCode, ''))) = @p2
|
||||
AND LTRIM(RTRIM(ISNULL(P.ItemDim2Code, ''))) = @p3
|
||||
GROUP BY LTRIM(RTRIM(ISNULL(P.ItemDim1Code, '')))
|
||||
AND UPPER(LTRIM(RTRIM(P.ItemCode))) = @p1
|
||||
AND UPPER(LTRIM(RTRIM(ISNULL(P.ColorCode, '')))) = @p2
|
||||
AND UPPER(LTRIM(RTRIM(ISNULL(P.ItemDim2Code, '')))) = @p3
|
||||
GROUP BY UPPER(LTRIM(RTRIM(ISNULL(P.ItemDim1Code, '')))), LTRIM(RTRIM(P.WarehouseCode))
|
||||
),
|
||||
Reserve AS (
|
||||
SELECT
|
||||
SizeCode = LTRIM(RTRIM(ISNULL(R.ItemDim1Code, ''))),
|
||||
SizeCode = UPPER(LTRIM(RTRIM(ISNULL(R.ItemDim1Code, '')))),
|
||||
WarehouseCode = LTRIM(RTRIM(R.WarehouseCode)),
|
||||
ReserveQty1 = SUM(R.Qty1)
|
||||
FROM ReserveStates R WITH(NOLOCK)
|
||||
INNER JOIN ActiveWarehouses W
|
||||
ON W.WarehouseCode = LTRIM(RTRIM(R.WarehouseCode))
|
||||
WHERE R.ItemTypeCode = 1
|
||||
AND LTRIM(RTRIM(R.ItemCode)) = @p1
|
||||
AND LTRIM(RTRIM(ISNULL(R.ColorCode, ''))) = @p2
|
||||
AND LTRIM(RTRIM(ISNULL(R.ItemDim2Code, ''))) = @p3
|
||||
GROUP BY LTRIM(RTRIM(ISNULL(R.ItemDim1Code, '')))
|
||||
AND UPPER(LTRIM(RTRIM(R.ItemCode))) = @p1
|
||||
AND UPPER(LTRIM(RTRIM(ISNULL(R.ColorCode, '')))) = @p2
|
||||
AND UPPER(LTRIM(RTRIM(ISNULL(R.ItemDim2Code, '')))) = @p3
|
||||
GROUP BY UPPER(LTRIM(RTRIM(ISNULL(R.ItemDim1Code, '')))), LTRIM(RTRIM(R.WarehouseCode))
|
||||
),
|
||||
Disp AS (
|
||||
SELECT
|
||||
SizeCode = LTRIM(RTRIM(ISNULL(D.ItemDim1Code, ''))),
|
||||
SizeCode = UPPER(LTRIM(RTRIM(ISNULL(D.ItemDim1Code, '')))),
|
||||
WarehouseCode = LTRIM(RTRIM(D.WarehouseCode)),
|
||||
DispOrderQty1 = SUM(D.Qty1)
|
||||
FROM DispOrderStates D WITH(NOLOCK)
|
||||
INNER JOIN ActiveWarehouses W
|
||||
ON W.WarehouseCode = LTRIM(RTRIM(D.WarehouseCode))
|
||||
WHERE D.ItemTypeCode = 1
|
||||
AND LTRIM(RTRIM(D.ItemCode)) = @p1
|
||||
AND LTRIM(RTRIM(ISNULL(D.ColorCode, ''))) = @p2
|
||||
AND LTRIM(RTRIM(ISNULL(D.ItemDim2Code, ''))) = @p3
|
||||
GROUP BY LTRIM(RTRIM(ISNULL(D.ItemDim1Code, '')))
|
||||
)
|
||||
SELECT
|
||||
AND UPPER(LTRIM(RTRIM(D.ItemCode))) = @p1
|
||||
AND UPPER(LTRIM(RTRIM(ISNULL(D.ColorCode, '')))) = @p2
|
||||
AND UPPER(LTRIM(RTRIM(ISNULL(D.ItemDim2Code, '')))) = @p3
|
||||
GROUP BY UPPER(LTRIM(RTRIM(ISNULL(D.ItemDim1Code, '')))), LTRIM(RTRIM(D.WarehouseCode))
|
||||
),
|
||||
AvailableBySizeWarehouse AS (
|
||||
SELECT
|
||||
S.SizeCode,
|
||||
StockQty = CAST(ROUND(
|
||||
ISNULL(S.InventoryQty1, 0)
|
||||
StockQty =
|
||||
CASE
|
||||
WHEN ISNULL(S.InventoryQty1, 0)
|
||||
- ISNULL(P.PickingQty1, 0)
|
||||
- ISNULL(R.ReserveQty1, 0)
|
||||
- ISNULL(D.DispOrderQty1, 0),
|
||||
2
|
||||
) AS FLOAT)
|
||||
FROM Stock S
|
||||
LEFT JOIN Pick P ON P.SizeCode = S.SizeCode
|
||||
LEFT JOIN Reserve R ON R.SizeCode = S.SizeCode
|
||||
LEFT JOIN Disp D ON D.SizeCode = S.SizeCode
|
||||
WHERE (
|
||||
ISNULL(S.InventoryQty1, 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)
|
||||
) <> 0
|
||||
ORDER BY S.SizeCode
|
||||
END
|
||||
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
|
||||
)
|
||||
SELECT
|
||||
SizeCode,
|
||||
StockQty = CAST(ROUND(SUM(StockQty), 2) AS FLOAT)
|
||||
FROM AvailableBySizeWarehouse
|
||||
GROUP BY SizeCode
|
||||
HAVING SUM(StockQty) > 0
|
||||
ORDER BY SizeCode
|
||||
`, strings.TrimSpace(productCode), strings.TrimSpace(colorCode), strings.TrimSpace(yakaKodu))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
||||
Reference in New Issue
Block a user