product performance grouped kpi improvements

This commit is contained in:
M_Kececi
2026-07-03 03:29:31 +03:00
parent c2d27b2d77
commit a0dd832d2b
3 changed files with 77 additions and 63 deletions
+18 -30
View File
@@ -1133,7 +1133,7 @@ Dim AS (
color_code,
yaka_kodu,
item_description,
COALESCE(NULLIF(kategori,''), yas_grubu, '') AS kategori,
COALESCE(kategori,'') AS kategori,
seri,
yas_grubu,
askili_yan,
@@ -2311,9 +2311,9 @@ func ListProductPerformanceSalesBreakdown(ctx context.Context, pg *sql.DB, break
"color_code": "s.color_code",
"yaka_kodu": "s.yaka_kodu",
"item_description": "MAX(s.item_description)",
"kategori": "COALESCE(NULLIF(MAX(s.kategori),''), MAX(s.yas_grubu), '')",
"kategori": "COALESCE(MAX(s.kategori),'')",
"askili_yan": "MAX(s.askili_yan)",
"urun_ilk_grubu": "COALESCE(NULLIF(MAX(s.seri),''), MAX(s.urun_ilk_grubu), '')",
"urun_ilk_grubu": "COALESCE(MAX(s.urun_ilk_grubu),'')",
"urun_ana_grubu": "COALESCE(MAX(s.urun_ana_grubu),'')",
"urun_alt_grubu": "MAX(s.urun_alt_grubu)",
"market_key": "s.market_key",
@@ -2340,7 +2340,7 @@ func ListProductPerformanceSalesBreakdown(ctx context.Context, pg *sql.DB, break
selected["market_key"] = true
selected["customer_code"] = true
selected["customer_name"] = true
groupCols = []string{"s.color_code", "s.yaka_kodu", "s.askili_yan", "COALESCE(NULLIF(s.seri,''), s.urun_ilk_grubu, '')", "s.urun_ana_grubu", "s.urun_alt_grubu", "s.product_code", "s.customer_country", "s.market_key", "s.customer_segment", "s.customer_code"}
groupCols = []string{"s.color_code", "s.yaka_kodu", "s.urun_ilk_grubu", "s.askili_yan", "s.kategori", "s.urun_ana_grubu", "s.urun_alt_grubu", "s.product_code", "s.customer_country", "s.market_key", "s.customer_segment", "s.customer_code"}
case "product_country_segment_market_customer":
selected["product_code"] = true
selected["item_description"] = true
@@ -2403,7 +2403,7 @@ func ListProductPerformanceSalesBreakdown(ctx context.Context, pg *sql.DB, break
selected["market_key"] = true
selected["customer_code"] = true
selected["customer_name"] = true
groupCols = []string{"s.color_code", "s.yaka_kodu", "s.askili_yan", "COALESCE(NULLIF(s.seri,''), s.urun_ilk_grubu, '')", "s.urun_ana_grubu", "s.urun_alt_grubu", "s.product_code", "s.customer_country", "s.market_key", "s.customer_segment", "s.customer_code"}
groupCols = []string{"s.color_code", "s.yaka_kodu", "s.urun_ilk_grubu", "s.askili_yan", "s.kategori", "s.urun_ana_grubu", "s.urun_alt_grubu", "s.product_code", "s.customer_country", "s.market_key", "s.customer_segment", "s.customer_code"}
}
selectExpr := func(name string) string {
@@ -2419,9 +2419,9 @@ WITH LatestKPI AS (
product_code,
color_code,
yaka_kodu,
COALESCE(NULLIF(kategori,''), yas_grubu, '') AS kategori,
COALESCE(kategori,'') AS kategori,
askili_yan,
COALESCE(NULLIF(seri,''), urun_ilk_grubu, '') AS urun_ilk_grubu,
COALESCE(urun_ilk_grubu,'') AS urun_ilk_grubu,
COALESCE(urun_ana_grubu,'') AS urun_ana_grubu,
urun_alt_grubu
FROM mk_product_performance_kpi_daily
@@ -3016,7 +3016,7 @@ WITH Source AS (
seri,
yas_grubu,
askili_yan,
COALESCE(NULLIF(seri,''), urun_ilk_grubu, '') AS urun_ilk_grubu,
COALESCE(urun_ilk_grubu,'') AS urun_ilk_grubu,
COALESCE(urun_ana_grubu,'') AS urun_ana_grubu,
urun_alt_grubu,
market_key,
@@ -3479,38 +3479,26 @@ func sanitizeProductPerformanceGroupLevels(levels []string) []string {
func defaultProductPerformanceGroupLevels(mode string) []string {
switch mode {
case "sales_color_yaka_market_customer":
return []string{"color_code", "yaka_kodu", "askili_yan", "urun_ilk_grubu", "urun_ana_grubu", "urun_alt_grubu", "product_code", "item_description", "country", "market_key", "customer_segment", "customer_code", "customer_name"}
return []string{"color_code", "yaka_kodu", "urun_ilk_grubu", "askili_yan", "kategori", "urun_ana_grubu", "urun_alt_grubu", "product_code", "item_description", "country", "market_key", "customer_segment", "customer_code", "customer_name"}
case "idle":
return []string{"askili_yan", "urun_ilk_grubu", "urun_ana_grubu", "urun_alt_grubu", "product_code", "item_description", "color_code", "yaka_kodu"}
return []string{"urun_ilk_grubu", "askili_yan", "kategori", "urun_ana_grubu", "urun_alt_grubu", "product_code", "item_description", "color_code", "yaka_kodu"}
case "sales_product_country_segment_market_customer":
return []string{"market_key", "customer_code", "customer_name", "kategori", "askili_yan", "urun_ilk_grubu", "urun_ana_grubu", "urun_alt_grubu", "product_code", "item_description", "color_code", "yaka_kodu"}
return []string{"market_key", "customer_code", "customer_name", "urun_ilk_grubu", "askili_yan", "kategori", "urun_ana_grubu", "urun_alt_grubu", "product_code", "item_description", "color_code", "yaka_kodu"}
case "sales_market_customer_product":
return []string{"market_key", "customer_code", "customer_name", "kategori", "askili_yan", "urun_ilk_grubu", "urun_ana_grubu", "urun_alt_grubu", "product_code", "item_description", "color_code", "yaka_kodu"}
return []string{"market_key", "customer_code", "customer_name", "urun_ilk_grubu", "askili_yan", "kategori", "urun_ana_grubu", "urun_alt_grubu", "product_code", "item_description", "color_code", "yaka_kodu"}
case "sales_country_segment_market_customer_product":
return []string{"market_key", "customer_code", "customer_name", "kategori", "askili_yan", "urun_ilk_grubu", "urun_ana_grubu", "urun_alt_grubu", "product_code", "item_description", "color_code", "yaka_kodu"}
return []string{"market_key", "customer_code", "customer_name", "urun_ilk_grubu", "askili_yan", "kategori", "urun_ana_grubu", "urun_alt_grubu", "product_code", "item_description", "color_code", "yaka_kodu"}
case "order_product_customers":
return []string{"market_key", "customer_code", "customer_name", "kategori", "askili_yan", "urun_ilk_grubu", "urun_ana_grubu", "urun_alt_grubu", "product_code", "item_description", "color_code", "yaka_kodu"}
return []string{"market_key", "customer_code", "customer_name", "urun_ilk_grubu", "askili_yan", "kategori", "urun_ana_grubu", "urun_alt_grubu", "product_code", "item_description", "color_code", "yaka_kodu"}
case "order_market_details":
return []string{"market_key", "customer_code", "customer_name", "kategori", "askili_yan", "urun_ilk_grubu", "urun_ana_grubu", "urun_alt_grubu", "product_code", "item_description", "color_code", "yaka_kodu"}
return []string{"market_key", "customer_code", "customer_name", "urun_ilk_grubu", "askili_yan", "kategori", "urun_ana_grubu", "urun_alt_grubu", "product_code", "item_description", "color_code", "yaka_kodu"}
default:
return []string{"kategori", "askili_yan", "urun_ilk_grubu", "urun_ana_grubu", "urun_alt_grubu", "product_code", "item_description", "color_code", "yaka_kodu", "market_key"}
return []string{"urun_ilk_grubu", "askili_yan", "kategori", "urun_ana_grubu", "urun_alt_grubu", "product_code", "item_description", "color_code", "yaka_kodu", "market_key"}
}
}
func mapGroupValue(row map[string]any, field string) string {
switch field {
case "kategori":
if value := stringFromMap(row, "kategori"); value != "" {
return value
}
return stringFromMap(row, "yas_grubu")
case "urun_ilk_grubu":
if value := stringFromMap(row, "seri"); value != "" {
return value
}
return stringFromMap(row, "urun_ilk_grubu")
case "urun_ana_grubu":
return stringFromMap(row, "urun_ana_grubu")
case "market_key":
return displayProductPerformanceMarketName(stringFromMap(row, "market_key"))
default:
@@ -3972,9 +3960,9 @@ SELECT DISTINCT ON (product_code, color_code, yaka_kodu)
color_code,
yaka_kodu,
COALESCE(item_description,'') AS item_description,
COALESCE(NULLIF(kategori,''), yas_grubu, '') AS kategori,
COALESCE(kategori,'') AS kategori,
COALESCE(askili_yan,'') AS askili_yan,
COALESCE(NULLIF(seri,''), urun_ilk_grubu, '') AS urun_ilk_grubu,
COALESCE(urun_ilk_grubu,'') AS urun_ilk_grubu,
COALESCE(urun_ana_grubu,'') AS urun_ana_grubu,
COALESCE(urun_alt_grubu,'') AS urun_alt_grubu
FROM mk_product_performance_kpi_daily
+2 -2
View File
@@ -194,8 +194,8 @@ SELECT
YakaKodu,
ItemDescription = MAX(ItemDescription),
Kategori = MAX(Kategori),
Seri = MAX(Kategori),
YasGrubu = MAX(UrunIlkGrubu),
Seri = '',
YasGrubu = '',
AskiliYan = MAX(AskiliYan),
UrunIlkGrubu = MAX(UrunIlkGrubu),
UrunAnaGrubu = MAX(UrunAnaGrubu),