product performance grouped kpi improvements

This commit is contained in:
M_Kececi
2026-07-03 03:14:52 +03:00
parent 9f45160648
commit c2d27b2d77
2 changed files with 148 additions and 81 deletions
+21 -19
View File
@@ -1133,7 +1133,7 @@ Dim AS (
color_code,
yaka_kodu,
item_description,
kategori,
COALESCE(NULLIF(kategori,''), yas_grubu, '') AS kategori,
seri,
yas_grubu,
askili_yan,
@@ -2311,10 +2311,10 @@ 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": "MAX(s.kategori)",
"kategori": "COALESCE(NULLIF(MAX(s.kategori),''), MAX(s.yas_grubu), '')",
"askili_yan": "MAX(s.askili_yan)",
"urun_ilk_grubu": "MAX(s.urun_ilk_grubu)",
"urun_ana_grubu": "MAX(s.urun_ana_grubu)",
"urun_ilk_grubu": "COALESCE(NULLIF(MAX(s.seri),''), 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",
"country": "s.customer_country",
@@ -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", "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.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"}
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", "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.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"}
}
selectExpr := func(name string) string {
@@ -2419,10 +2419,10 @@ WITH LatestKPI AS (
product_code,
color_code,
yaka_kodu,
kategori,
COALESCE(NULLIF(kategori,''), yas_grubu, '') AS kategori,
askili_yan,
COALESCE(NULLIF(urun_ilk_grubu,''), yas_grubu) AS urun_ilk_grubu,
COALESCE(NULLIF(urun_ana_grubu,''), seri) AS urun_ana_grubu,
COALESCE(NULLIF(seri,''), urun_ilk_grubu, '') AS urun_ilk_grubu,
COALESCE(urun_ana_grubu,'') AS urun_ana_grubu,
urun_alt_grubu
FROM mk_product_performance_kpi_daily
WHERE kpi_date = (SELECT MAX(kpi_date) FROM mk_product_performance_kpi_daily)
@@ -3016,8 +3016,8 @@ WITH Source AS (
seri,
yas_grubu,
askili_yan,
COALESCE(NULLIF(urun_ilk_grubu,''), yas_grubu) AS urun_ilk_grubu,
COALESCE(NULLIF(urun_ana_grubu,''), seri) AS urun_ana_grubu,
COALESCE(NULLIF(seri,''), urun_ilk_grubu, '') AS urun_ilk_grubu,
COALESCE(urun_ana_grubu,'') AS urun_ana_grubu,
urun_alt_grubu,
market_key,
COALESCE(stock_qty,0) AS stock_qty,
@@ -3499,16 +3499,18 @@ func defaultProductPerformanceGroupLevels(mode string) []string {
func mapGroupValue(row map[string]any, field string) string {
switch field {
case "urun_ilk_grubu":
if value := stringFromMap(row, "urun_ilk_grubu"); value != "" {
case "kategori":
if value := stringFromMap(row, "kategori"); value != "" {
return value
}
return stringFromMap(row, "yas_grubu")
case "urun_ana_grubu":
if value := stringFromMap(row, "urun_ana_grubu"); value != "" {
case "urun_ilk_grubu":
if value := stringFromMap(row, "seri"); value != "" {
return value
}
return stringFromMap(row, "seri")
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:
@@ -3970,10 +3972,10 @@ SELECT DISTINCT ON (product_code, color_code, yaka_kodu)
color_code,
yaka_kodu,
COALESCE(item_description,'') AS item_description,
COALESCE(kategori,'') AS kategori,
COALESCE(NULLIF(kategori,''), yas_grubu, '') AS kategori,
COALESCE(askili_yan,'') AS askili_yan,
COALESCE(NULLIF(urun_ilk_grubu,''), yas_grubu, '') AS urun_ilk_grubu,
COALESCE(NULLIF(urun_ana_grubu,''), seri, '') AS urun_ana_grubu,
COALESCE(NULLIF(seri,''), 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
WHERE kpi_date = (SELECT kpi_date FROM Latest)