product performance grouped kpi improvements
This commit is contained in:
@@ -18,76 +18,11 @@ func productPerformanceSalesSQL() string {
|
||||
AND cdItemDesc.ItemCode = I.ItemCode
|
||||
AND cdItemDesc.LangCode = 'TR'
|
||||
), SPACE(0))),
|
||||
UrunAnaGrubu = dbo.HG_Temizlik(ISNULL((
|
||||
SELECT AttributeDescription
|
||||
FROM cdItemAttributeDesc WITH(NOLOCK)
|
||||
WHERE cdItemAttributeDesc.ItemTypeCode = I.ItemTypeCode
|
||||
AND cdItemAttributeDesc.AttributeTypeCode = 1
|
||||
AND cdItemAttributeDesc.AttributeCode = (
|
||||
SELECT TOP 1 AttributeCode
|
||||
FROM prItemAttribute WITH(NOLOCK)
|
||||
WHERE AttributeTypeCode = 1
|
||||
AND prItemAttribute.ItemTypeCode = I.ItemTypeCode
|
||||
AND prItemAttribute.ItemCode = I.ItemCode
|
||||
)
|
||||
AND cdItemAttributeDesc.LangCode = 'TR'
|
||||
), SPACE(0))),
|
||||
UrunAltGrubu = dbo.HG_Temizlik(ISNULL((
|
||||
SELECT AttributeDescription
|
||||
FROM cdItemAttributeDesc WITH(NOLOCK)
|
||||
WHERE cdItemAttributeDesc.ItemTypeCode = I.ItemTypeCode
|
||||
AND cdItemAttributeDesc.AttributeTypeCode = 2
|
||||
AND cdItemAttributeDesc.AttributeCode = (
|
||||
SELECT TOP 1 AttributeCode
|
||||
FROM prItemAttribute WITH(NOLOCK)
|
||||
WHERE AttributeTypeCode = 2
|
||||
AND prItemAttribute.ItemTypeCode = I.ItemTypeCode
|
||||
AND prItemAttribute.ItemCode = I.ItemCode
|
||||
)
|
||||
AND cdItemAttributeDesc.LangCode = 'TR'
|
||||
), SPACE(0))),
|
||||
Kategori = dbo.HG_Temizlik(ISNULL((
|
||||
SELECT AttributeDescription
|
||||
FROM cdItemAttributeDesc WITH(NOLOCK)
|
||||
WHERE cdItemAttributeDesc.ItemTypeCode = I.ItemTypeCode
|
||||
AND cdItemAttributeDesc.AttributeTypeCode = 44
|
||||
AND cdItemAttributeDesc.AttributeCode = (
|
||||
SELECT TOP 1 AttributeCode
|
||||
FROM prItemAttribute WITH(NOLOCK)
|
||||
WHERE AttributeTypeCode = 44
|
||||
AND prItemAttribute.ItemTypeCode = I.ItemTypeCode
|
||||
AND prItemAttribute.ItemCode = I.ItemCode
|
||||
)
|
||||
AND cdItemAttributeDesc.LangCode = 'TR'
|
||||
), SPACE(0))),
|
||||
UrunIlkGrubu = dbo.HG_Temizlik(ISNULL((
|
||||
SELECT AttributeDescription
|
||||
FROM cdItemAttributeDesc WITH(NOLOCK)
|
||||
WHERE cdItemAttributeDesc.ItemTypeCode = I.ItemTypeCode
|
||||
AND cdItemAttributeDesc.AttributeTypeCode = 42
|
||||
AND cdItemAttributeDesc.AttributeCode = (
|
||||
SELECT TOP 1 AttributeCode
|
||||
FROM prItemAttribute WITH(NOLOCK)
|
||||
WHERE AttributeTypeCode = 42
|
||||
AND prItemAttribute.ItemTypeCode = I.ItemTypeCode
|
||||
AND prItemAttribute.ItemCode = I.ItemCode
|
||||
)
|
||||
AND cdItemAttributeDesc.LangCode = 'TR'
|
||||
), SPACE(0))),
|
||||
AskiliYan = dbo.HG_Temizlik(ISNULL((
|
||||
SELECT AttributeDescription
|
||||
FROM cdItemAttributeDesc WITH(NOLOCK)
|
||||
WHERE cdItemAttributeDesc.ItemTypeCode = I.ItemTypeCode
|
||||
AND cdItemAttributeDesc.AttributeTypeCode = 45
|
||||
AND cdItemAttributeDesc.AttributeCode = (
|
||||
SELECT TOP 1 AttributeCode
|
||||
FROM prItemAttribute WITH(NOLOCK)
|
||||
WHERE AttributeTypeCode = 45
|
||||
AND prItemAttribute.ItemTypeCode = I.ItemTypeCode
|
||||
AND prItemAttribute.ItemCode = I.ItemCode
|
||||
)
|
||||
AND cdItemAttributeDesc.LangCode = 'TR'
|
||||
), SPACE(0))),
|
||||
UrunAnaGrubu = dbo.HG_Temizlik(ISNULL(PAF.ProductAtt01, SPACE(0))),
|
||||
UrunAltGrubu = dbo.HG_Temizlik(ISNULL(PAF.ProductAtt02, SPACE(0))),
|
||||
Kategori = dbo.HG_Temizlik(ISNULL(PAF.ProductAtt44, SPACE(0))),
|
||||
UrunIlkGrubu = dbo.HG_Temizlik(ISNULL(PAF.ProductAtt42, SPACE(0))),
|
||||
AskiliYan = dbo.HG_Temizlik(ISNULL(PAF.ProductAtt45, SPACE(0))),
|
||||
ChannelCode = CASE
|
||||
WHEN I.ProcessCode IN ('R') THEN dbo.HG_Temizlik(ISNULL((
|
||||
SELECT OfficeDescription
|
||||
@@ -159,20 +94,12 @@ func productPerformanceSalesSQL() string {
|
||||
LEFT OUTER JOIN CustomerAttributesFilter CAF WITH(NOLOCK)
|
||||
ON CAF.CurrAccTypeCode = I.CurrAccTypeCode
|
||||
AND CAF.CurrAccCode = I.CurrAccCode
|
||||
LEFT OUTER JOIN ProductAttributesFilter PAF WITH(NOLOCK)
|
||||
ON PAF.ItemCode = I.ItemCode
|
||||
WHERE I.InvoiceDate >= @p1
|
||||
AND I.InvoiceDate < DATEADD(DAY, 1, @p2)
|
||||
AND I.ItemTypeCode = 1
|
||||
AND (
|
||||
LEN(LTRIM(RTRIM(I.ItemCode))) = 13
|
||||
AND (
|
||||
UPPER(LTRIM(RTRIM(I.ItemCode))) LIKE 'S%'
|
||||
OR UPPER(LTRIM(RTRIM(I.ItemCode))) LIKE 'O%'
|
||||
OR UPPER(LTRIM(RTRIM(I.ItemCode))) LIKE 'N%'
|
||||
OR UPPER(LTRIM(RTRIM(I.ItemCode))) LIKE 'X%'
|
||||
OR UPPER(LTRIM(RTRIM(I.ItemCode))) LIKE 'I%'
|
||||
OR UPPER(LTRIM(RTRIM(I.ItemCode))) LIKE 'A%'
|
||||
)
|
||||
)
|
||||
AND LEN(LTRIM(RTRIM(I.ItemCode))) = 13
|
||||
AND (@p3 = '' OR UPPER(LTRIM(RTRIM(I.ItemCode))) LIKE @p3 + '%')
|
||||
AND (
|
||||
(I.CompanyCode = 1 AND I.ATAtt01 IN (1,2) AND I.ProcessCode IN ('WS','R'))
|
||||
@@ -249,17 +176,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
|
||||
@@ -385,49 +302,19 @@ func productPerformancePriceSQL() string {
|
||||
SELECT DISTINCT ItemCode
|
||||
FROM cdItem WITH(NOLOCK)
|
||||
WHERE ItemTypeCode = 1
|
||||
AND (
|
||||
LEN(LTRIM(RTRIM(ItemCode))) = 13
|
||||
AND (
|
||||
UPPER(LTRIM(RTRIM(ItemCode))) LIKE 'S%'
|
||||
OR UPPER(LTRIM(RTRIM(ItemCode))) LIKE 'O%'
|
||||
OR UPPER(LTRIM(RTRIM(ItemCode))) LIKE 'N%'
|
||||
OR UPPER(LTRIM(RTRIM(ItemCode))) LIKE 'X%'
|
||||
OR UPPER(LTRIM(RTRIM(ItemCode))) LIKE 'I%'
|
||||
OR UPPER(LTRIM(RTRIM(ItemCode))) LIKE 'A%'
|
||||
)
|
||||
)
|
||||
AND LEN(LTRIM(RTRIM(ItemCode))) = 13
|
||||
AND (@p1 = '' OR UPPER(LTRIM(RTRIM(ItemCode))) LIKE @p1 + '%')
|
||||
UNION
|
||||
SELECT DISTINCT ItemCode
|
||||
FROM trPriceListLine WITH(NOLOCK)
|
||||
WHERE ItemTypeCode = 1
|
||||
AND (
|
||||
LEN(LTRIM(RTRIM(ItemCode))) = 13
|
||||
AND (
|
||||
UPPER(LTRIM(RTRIM(ItemCode))) LIKE 'S%'
|
||||
OR UPPER(LTRIM(RTRIM(ItemCode))) LIKE 'O%'
|
||||
OR UPPER(LTRIM(RTRIM(ItemCode))) LIKE 'N%'
|
||||
OR UPPER(LTRIM(RTRIM(ItemCode))) LIKE 'X%'
|
||||
OR UPPER(LTRIM(RTRIM(ItemCode))) LIKE 'I%'
|
||||
OR UPPER(LTRIM(RTRIM(ItemCode))) LIKE 'A%'
|
||||
)
|
||||
)
|
||||
AND LEN(LTRIM(RTRIM(ItemCode))) = 13
|
||||
AND (@p1 = '' OR UPPER(LTRIM(RTRIM(ItemCode))) LIKE @p1 + '%')
|
||||
UNION
|
||||
SELECT DISTINCT ItemCode
|
||||
FROM prItemBasePrice WITH(NOLOCK)
|
||||
WHERE ItemTypeCode = 1
|
||||
AND (
|
||||
LEN(LTRIM(RTRIM(ItemCode))) = 13
|
||||
AND (
|
||||
UPPER(LTRIM(RTRIM(ItemCode))) LIKE 'S%'
|
||||
OR UPPER(LTRIM(RTRIM(ItemCode))) LIKE 'O%'
|
||||
OR UPPER(LTRIM(RTRIM(ItemCode))) LIKE 'N%'
|
||||
OR UPPER(LTRIM(RTRIM(ItemCode))) LIKE 'X%'
|
||||
OR UPPER(LTRIM(RTRIM(ItemCode))) LIKE 'I%'
|
||||
OR UPPER(LTRIM(RTRIM(ItemCode))) LIKE 'A%'
|
||||
)
|
||||
)
|
||||
AND LEN(LTRIM(RTRIM(ItemCode))) = 13
|
||||
AND (@p1 = '' OR UPPER(LTRIM(RTRIM(ItemCode))) LIKE @p1 + '%')
|
||||
),
|
||||
LatestPrice AS (
|
||||
@@ -483,81 +370,18 @@ SELECT
|
||||
AND cdItemDesc.ItemCode = pc.ItemCode
|
||||
AND cdItemDesc.LangCode = 'TR'
|
||||
), SPACE(0))),
|
||||
Kategori = dbo.HG_Temizlik(ISNULL((
|
||||
SELECT AttributeDescription
|
||||
FROM cdItemAttributeDesc WITH(NOLOCK)
|
||||
WHERE cdItemAttributeDesc.ItemTypeCode = 1
|
||||
AND cdItemAttributeDesc.AttributeTypeCode = 44
|
||||
AND cdItemAttributeDesc.AttributeCode = (
|
||||
SELECT TOP 1 AttributeCode
|
||||
FROM prItemAttribute WITH(NOLOCK)
|
||||
WHERE AttributeTypeCode = 44
|
||||
AND prItemAttribute.ItemTypeCode = 1
|
||||
AND prItemAttribute.ItemCode = pc.ItemCode
|
||||
)
|
||||
AND cdItemAttributeDesc.LangCode = 'TR'
|
||||
), SPACE(0))),
|
||||
AskiliYan = dbo.HG_Temizlik(ISNULL((
|
||||
SELECT AttributeDescription
|
||||
FROM cdItemAttributeDesc WITH(NOLOCK)
|
||||
WHERE cdItemAttributeDesc.ItemTypeCode = 1
|
||||
AND cdItemAttributeDesc.AttributeTypeCode = 45
|
||||
AND cdItemAttributeDesc.AttributeCode = (
|
||||
SELECT TOP 1 AttributeCode
|
||||
FROM prItemAttribute WITH(NOLOCK)
|
||||
WHERE AttributeTypeCode = 45
|
||||
AND prItemAttribute.ItemTypeCode = 1
|
||||
AND prItemAttribute.ItemCode = pc.ItemCode
|
||||
)
|
||||
AND cdItemAttributeDesc.LangCode = 'TR'
|
||||
), SPACE(0))),
|
||||
UrunIlkGrubu = dbo.HG_Temizlik(ISNULL((
|
||||
SELECT AttributeDescription
|
||||
FROM cdItemAttributeDesc WITH(NOLOCK)
|
||||
WHERE cdItemAttributeDesc.ItemTypeCode = 1
|
||||
AND cdItemAttributeDesc.AttributeTypeCode = 42
|
||||
AND cdItemAttributeDesc.AttributeCode = (
|
||||
SELECT TOP 1 AttributeCode
|
||||
FROM prItemAttribute WITH(NOLOCK)
|
||||
WHERE AttributeTypeCode = 42
|
||||
AND prItemAttribute.ItemTypeCode = 1
|
||||
AND prItemAttribute.ItemCode = pc.ItemCode
|
||||
)
|
||||
AND cdItemAttributeDesc.LangCode = 'TR'
|
||||
), SPACE(0))),
|
||||
UrunAnaGrubu = dbo.HG_Temizlik(ISNULL((
|
||||
SELECT AttributeDescription
|
||||
FROM cdItemAttributeDesc WITH(NOLOCK)
|
||||
WHERE cdItemAttributeDesc.ItemTypeCode = 1
|
||||
AND cdItemAttributeDesc.AttributeTypeCode = 1
|
||||
AND cdItemAttributeDesc.AttributeCode = (
|
||||
SELECT TOP 1 AttributeCode
|
||||
FROM prItemAttribute WITH(NOLOCK)
|
||||
WHERE AttributeTypeCode = 1
|
||||
AND prItemAttribute.ItemTypeCode = 1
|
||||
AND prItemAttribute.ItemCode = pc.ItemCode
|
||||
)
|
||||
AND cdItemAttributeDesc.LangCode = 'TR'
|
||||
), SPACE(0))),
|
||||
UrunAltGrubu = dbo.HG_Temizlik(ISNULL((
|
||||
SELECT AttributeDescription
|
||||
FROM cdItemAttributeDesc WITH(NOLOCK)
|
||||
WHERE cdItemAttributeDesc.ItemTypeCode = 1
|
||||
AND cdItemAttributeDesc.AttributeTypeCode = 2
|
||||
AND cdItemAttributeDesc.AttributeCode = (
|
||||
SELECT TOP 1 AttributeCode
|
||||
FROM prItemAttribute WITH(NOLOCK)
|
||||
WHERE AttributeTypeCode = 2
|
||||
AND prItemAttribute.ItemTypeCode = 1
|
||||
AND prItemAttribute.ItemCode = pc.ItemCode
|
||||
)
|
||||
AND cdItemAttributeDesc.LangCode = 'TR'
|
||||
), SPACE(0))),
|
||||
Kategori = dbo.HG_Temizlik(ISNULL(paf.ProductAtt44, SPACE(0))),
|
||||
AskiliYan = dbo.HG_Temizlik(ISNULL(paf.ProductAtt45, SPACE(0))),
|
||||
UrunIlkGrubu = dbo.HG_Temizlik(ISNULL(paf.ProductAtt42, SPACE(0))),
|
||||
UrunAnaGrubu = dbo.HG_Temizlik(ISNULL(paf.ProductAtt01, SPACE(0))),
|
||||
UrunAltGrubu = dbo.HG_Temizlik(ISNULL(paf.ProductAtt02, SPACE(0))),
|
||||
CostPriceUsd = ISNULL(c.CostPriceUsd, 0),
|
||||
BasePriceUsd = ISNULL(bp.BasePriceUsd, 0),
|
||||
BasePriceTry = ISNULL(bp.BasePriceTry, 0),
|
||||
c.LastPricingDate
|
||||
FROM ProductCodes pc
|
||||
LEFT JOIN ProductAttributesFilter paf WITH(NOLOCK)
|
||||
ON paf.ItemCode = pc.ItemCode
|
||||
LEFT JOIN BasePrice bp ON bp.ItemCode = pc.ItemCode
|
||||
LEFT JOIN Cost c ON c.ItemCode = pc.ItemCode AND c.rn = 1
|
||||
`
|
||||
|
||||
Reference in New Issue
Block a user