product performance grouped kpi improvements
This commit is contained in:
@@ -185,97 +185,123 @@ Running AS (
|
|||||||
CountDiffQty
|
CountDiffQty
|
||||||
FROM Collapsed
|
FROM Collapsed
|
||||||
),
|
),
|
||||||
CurrentStock AS (
|
CurrentSource 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
|
|
||||||
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.ItemCode, S.ColorCode, S.ItemDim1Code, S.ItemDim2Code, LTRIM(RTRIM(S.WarehouseCode))
|
|
||||||
),
|
|
||||||
CurrentPick AS (
|
|
||||||
SELECT
|
SELECT
|
||||||
|
SourceTable = 'PickingStates',
|
||||||
|
WarehouseCode = LTRIM(RTRIM(P.WarehouseCode)),
|
||||||
ProductCode = UPPER(LTRIM(RTRIM(P.ItemCode))),
|
ProductCode = UPPER(LTRIM(RTRIM(P.ItemCode))),
|
||||||
ColorCode = UPPER(LTRIM(RTRIM(ISNULL(P.ColorCode, '')))),
|
ColorCode = UPPER(LTRIM(RTRIM(ISNULL(P.ColorCode, '')))),
|
||||||
SizeCode = UPPER(LTRIM(RTRIM(ISNULL(P.ItemDim1Code, '')))),
|
SizeCode = UPPER(LTRIM(RTRIM(ISNULL(P.ItemDim1Code, '')))),
|
||||||
YakaKodu = UPPER(LTRIM(RTRIM(ISNULL(P.ItemDim2Code, '')))),
|
YakaKodu = UPPER(LTRIM(RTRIM(ISNULL(P.ItemDim2Code, '')))),
|
||||||
WarehouseCode = LTRIM(RTRIM(P.WarehouseCode)),
|
Dim3Code = UPPER(LTRIM(RTRIM(ISNULL(P.ItemDim3Code, '')))),
|
||||||
PickingQty1 = SUM(P.Qty1)
|
PickingQty1 = SUM(P.Qty1),
|
||||||
|
ReserveQty1 = CAST(0 AS decimal(18,4)),
|
||||||
|
DispOrderQty1 = CAST(0 AS decimal(18,4)),
|
||||||
|
InventoryQty1 = CAST(0 AS decimal(18,4))
|
||||||
FROM PickingStates P WITH(NOLOCK)
|
FROM PickingStates P WITH(NOLOCK)
|
||||||
INNER JOIN ActiveWarehouses W
|
INNER JOIN ActiveWarehouses W ON W.WarehouseCode = LTRIM(RTRIM(P.WarehouseCode))
|
||||||
ON W.WarehouseCode = LTRIM(RTRIM(P.WarehouseCode))
|
|
||||||
WHERE P.ItemTypeCode = 1
|
WHERE P.ItemTypeCode = 1
|
||||||
AND LEN(LTRIM(RTRIM(P.ItemCode))) = 13
|
AND LEN(LTRIM(RTRIM(P.ItemCode))) = 13
|
||||||
AND (@p3 = '' OR UPPER(LTRIM(RTRIM(P.ItemCode))) LIKE @p3 + '%')
|
AND (@p3 = '' OR UPPER(LTRIM(RTRIM(P.ItemCode))) LIKE @p3 + '%')
|
||||||
GROUP BY P.ItemCode, P.ColorCode, P.ItemDim1Code, P.ItemDim2Code, LTRIM(RTRIM(P.WarehouseCode))
|
GROUP BY P.WarehouseCode, P.ItemCode, P.ColorCode, P.ItemDim1Code, P.ItemDim2Code, P.ItemDim3Code
|
||||||
),
|
UNION ALL
|
||||||
CurrentReserve AS (
|
|
||||||
SELECT
|
SELECT
|
||||||
|
SourceTable = 'ReserveStates',
|
||||||
|
WarehouseCode = LTRIM(RTRIM(R.WarehouseCode)),
|
||||||
ProductCode = UPPER(LTRIM(RTRIM(R.ItemCode))),
|
ProductCode = UPPER(LTRIM(RTRIM(R.ItemCode))),
|
||||||
ColorCode = UPPER(LTRIM(RTRIM(ISNULL(R.ColorCode, '')))),
|
ColorCode = UPPER(LTRIM(RTRIM(ISNULL(R.ColorCode, '')))),
|
||||||
SizeCode = UPPER(LTRIM(RTRIM(ISNULL(R.ItemDim1Code, '')))),
|
SizeCode = UPPER(LTRIM(RTRIM(ISNULL(R.ItemDim1Code, '')))),
|
||||||
YakaKodu = UPPER(LTRIM(RTRIM(ISNULL(R.ItemDim2Code, '')))),
|
YakaKodu = UPPER(LTRIM(RTRIM(ISNULL(R.ItemDim2Code, '')))),
|
||||||
WarehouseCode = LTRIM(RTRIM(R.WarehouseCode)),
|
Dim3Code = UPPER(LTRIM(RTRIM(ISNULL(R.ItemDim3Code, '')))),
|
||||||
ReserveQty1 = SUM(R.Qty1)
|
PickingQty1 = CAST(0 AS decimal(18,4)),
|
||||||
|
ReserveQty1 = SUM(R.Qty1),
|
||||||
|
DispOrderQty1 = CAST(0 AS decimal(18,4)),
|
||||||
|
InventoryQty1 = CAST(0 AS decimal(18,4))
|
||||||
FROM ReserveStates R WITH(NOLOCK)
|
FROM ReserveStates R WITH(NOLOCK)
|
||||||
INNER JOIN ActiveWarehouses W
|
INNER JOIN ActiveWarehouses W ON W.WarehouseCode = LTRIM(RTRIM(R.WarehouseCode))
|
||||||
ON W.WarehouseCode = LTRIM(RTRIM(R.WarehouseCode))
|
|
||||||
WHERE R.ItemTypeCode = 1
|
WHERE R.ItemTypeCode = 1
|
||||||
AND LEN(LTRIM(RTRIM(R.ItemCode))) = 13
|
AND LEN(LTRIM(RTRIM(R.ItemCode))) = 13
|
||||||
AND (@p3 = '' OR UPPER(LTRIM(RTRIM(R.ItemCode))) LIKE @p3 + '%')
|
AND (@p3 = '' OR UPPER(LTRIM(RTRIM(R.ItemCode))) LIKE @p3 + '%')
|
||||||
GROUP BY R.ItemCode, R.ColorCode, R.ItemDim1Code, R.ItemDim2Code, LTRIM(RTRIM(R.WarehouseCode))
|
GROUP BY R.WarehouseCode, R.ItemCode, R.ColorCode, R.ItemDim1Code, R.ItemDim2Code, R.ItemDim3Code
|
||||||
),
|
UNION ALL
|
||||||
CurrentDisp AS (
|
|
||||||
SELECT
|
SELECT
|
||||||
|
SourceTable = 'DispOrderStates',
|
||||||
|
WarehouseCode = LTRIM(RTRIM(D.WarehouseCode)),
|
||||||
ProductCode = UPPER(LTRIM(RTRIM(D.ItemCode))),
|
ProductCode = UPPER(LTRIM(RTRIM(D.ItemCode))),
|
||||||
ColorCode = UPPER(LTRIM(RTRIM(ISNULL(D.ColorCode, '')))),
|
ColorCode = UPPER(LTRIM(RTRIM(ISNULL(D.ColorCode, '')))),
|
||||||
SizeCode = UPPER(LTRIM(RTRIM(ISNULL(D.ItemDim1Code, '')))),
|
SizeCode = UPPER(LTRIM(RTRIM(ISNULL(D.ItemDim1Code, '')))),
|
||||||
YakaKodu = UPPER(LTRIM(RTRIM(ISNULL(D.ItemDim2Code, '')))),
|
YakaKodu = UPPER(LTRIM(RTRIM(ISNULL(D.ItemDim2Code, '')))),
|
||||||
WarehouseCode = LTRIM(RTRIM(D.WarehouseCode)),
|
Dim3Code = UPPER(LTRIM(RTRIM(ISNULL(D.ItemDim3Code, '')))),
|
||||||
DispOrderQty1 = SUM(D.Qty1)
|
PickingQty1 = CAST(0 AS decimal(18,4)),
|
||||||
|
ReserveQty1 = CAST(0 AS decimal(18,4)),
|
||||||
|
DispOrderQty1 = SUM(D.Qty1),
|
||||||
|
InventoryQty1 = CAST(0 AS decimal(18,4))
|
||||||
FROM DispOrderStates D WITH(NOLOCK)
|
FROM DispOrderStates D WITH(NOLOCK)
|
||||||
INNER JOIN ActiveWarehouses W
|
INNER JOIN ActiveWarehouses W ON W.WarehouseCode = LTRIM(RTRIM(D.WarehouseCode))
|
||||||
ON W.WarehouseCode = LTRIM(RTRIM(D.WarehouseCode))
|
|
||||||
WHERE D.ItemTypeCode = 1
|
WHERE D.ItemTypeCode = 1
|
||||||
AND LEN(LTRIM(RTRIM(D.ItemCode))) = 13
|
AND LEN(LTRIM(RTRIM(D.ItemCode))) = 13
|
||||||
AND (@p3 = '' OR UPPER(LTRIM(RTRIM(D.ItemCode))) LIKE @p3 + '%')
|
AND (@p3 = '' OR UPPER(LTRIM(RTRIM(D.ItemCode))) LIKE @p3 + '%')
|
||||||
GROUP BY D.ItemCode, D.ColorCode, D.ItemDim1Code, D.ItemDim2Code, LTRIM(RTRIM(D.WarehouseCode))
|
GROUP BY D.WarehouseCode, D.ItemCode, D.ColorCode, D.ItemDim1Code, D.ItemDim2Code, D.ItemDim3Code
|
||||||
|
UNION ALL
|
||||||
|
SELECT
|
||||||
|
SourceTable = 'trStock',
|
||||||
|
WarehouseCode = LTRIM(RTRIM(S.WarehouseCode)),
|
||||||
|
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, '')))),
|
||||||
|
Dim3Code = UPPER(LTRIM(RTRIM(ISNULL(S.ItemDim3Code, '')))),
|
||||||
|
PickingQty1 = CAST(0 AS decimal(18,4)),
|
||||||
|
ReserveQty1 = CAST(0 AS decimal(18,4)),
|
||||||
|
DispOrderQty1 = CAST(0 AS decimal(18,4)),
|
||||||
|
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 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
|
||||||
|
),
|
||||||
|
CurrentInventory AS (
|
||||||
|
SELECT
|
||||||
|
ProductCode,
|
||||||
|
ColorCode,
|
||||||
|
SizeCode,
|
||||||
|
YakaKodu,
|
||||||
|
Dim3Code,
|
||||||
|
WarehouseCode,
|
||||||
|
PickingQty1 = SUM(PickingQty1),
|
||||||
|
ReserveQty1 = SUM(ReserveQty1),
|
||||||
|
DispOrderQty1 = SUM(DispOrderQty1),
|
||||||
|
InventoryQty1 = SUM(InventoryQty1)
|
||||||
|
FROM CurrentSource
|
||||||
|
GROUP BY WarehouseCode, ProductCode, ColorCode, SizeCode, YakaKodu, Dim3Code
|
||||||
),
|
),
|
||||||
CurrentAvailable AS (
|
CurrentAvailable AS (
|
||||||
SELECT
|
SELECT
|
||||||
StockDate = @p2,
|
StockDate = @p2,
|
||||||
S.ProductCode,
|
I.ProductCode,
|
||||||
S.ColorCode,
|
I.ColorCode,
|
||||||
S.YakaKodu,
|
I.YakaKodu,
|
||||||
StockQty = CAST(ROUND(SUM(
|
StockQty = CAST(ROUND(SUM(
|
||||||
CASE
|
CASE
|
||||||
WHEN ISNULL(S.InventoryQty1, 0)
|
WHEN ISNULL(I.InventoryQty1, 0)
|
||||||
- ISNULL(PK.PickingQty1, 0)
|
- ISNULL(I.PickingQty1, 0)
|
||||||
- ISNULL(RS.ReserveQty1, 0)
|
- ISNULL(I.ReserveQty1, 0)
|
||||||
- ISNULL(DP.DispOrderQty1, 0) < 0 THEN 0
|
- ISNULL(I.DispOrderQty1, 0) < 0 THEN 0
|
||||||
ELSE ISNULL(S.InventoryQty1, 0)
|
ELSE ISNULL(I.InventoryQty1, 0)
|
||||||
- ISNULL(PK.PickingQty1, 0)
|
- ISNULL(I.PickingQty1, 0)
|
||||||
- ISNULL(RS.ReserveQty1, 0)
|
- ISNULL(I.ReserveQty1, 0)
|
||||||
- ISNULL(DP.DispOrderQty1, 0)
|
- ISNULL(I.DispOrderQty1, 0)
|
||||||
END),
|
END),
|
||||||
2
|
2
|
||||||
) AS decimal(18,4)),
|
) AS decimal(18,4)),
|
||||||
@@ -288,14 +314,22 @@ CurrentAvailable AS (
|
|||||||
PurchaseInQty = CAST(0 AS decimal(18,4)),
|
PurchaseInQty = CAST(0 AS decimal(18,4)),
|
||||||
ConsumptionOutQty = CAST(0 AS decimal(18,4)),
|
ConsumptionOutQty = CAST(0 AS decimal(18,4)),
|
||||||
CountDiffQty = CAST(0 AS decimal(18,4))
|
CountDiffQty = CAST(0 AS decimal(18,4))
|
||||||
FROM CurrentStock S
|
FROM CurrentInventory I
|
||||||
LEFT JOIN CurrentPick PK
|
INNER JOIN cdItem WITH(NOLOCK)
|
||||||
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
|
ON cdItem.ItemTypeCode = 1
|
||||||
LEFT JOIN CurrentReserve RS
|
AND UPPER(LTRIM(RTRIM(cdItem.ItemCode))) = I.ProductCode
|
||||||
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
|
AND cdItem.IsBlocked = 0
|
||||||
LEFT JOIN CurrentDisp DP
|
WHERE I.InventoryQty1 >= 0
|
||||||
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
|
AND LEN(I.ProductCode) = 13
|
||||||
GROUP BY S.ProductCode, S.ColorCode, S.YakaKodu
|
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
|
SELECT
|
||||||
StockDate,
|
StockDate,
|
||||||
|
|||||||
Reference in New Issue
Block a user