Merge remote-tracking branch 'origin/master'

# Conflicts:
#	svc/queries/product_performance_sql.go
#	ui/src/pages/ProductPerformanceProfitability.vue
This commit is contained in:
M_Kececi
2026-07-03 20:40:35 +03:00
parent 9e22cc5ec5
commit 3b2bcda462
2 changed files with 291 additions and 53 deletions
+16 -4
View File
@@ -3234,7 +3234,7 @@ SELECT jsonb_build_object(
'group_value', group_value,
'label', group_value,
'count', row_count,
'recommendation', row_count::text || ' satir',
'recommendation', CASE WHEN recommendation <> '' THEN recommendation ELSE row_count::text || ' satir' END,
'image_product_code', image_product_code,
'image_color_code', image_color_code,
'image_yaka_kodu', image_yaka_kodu,
@@ -3356,6 +3356,7 @@ FROM (
CASE WHEN SUM(sales_qty_90d) > 0 THEN SUM(margin_index_90d * sales_qty_90d) / NULLIF(SUM(sales_qty_90d),0) ELSE 0 END AS margin_index_90d,
CASE WHEN SUM(sales_qty_90d) > 0 THEN SUM(performance_score * sales_qty_90d) / NULLIF(SUM(sales_qty_90d),0) ELSE 0 END AS performance_score,
MODE() WITHIN GROUP (ORDER BY performance_bucket) AS performance_bucket,
COALESCE(MODE() WITHIN GROUP (ORDER BY NULLIF(recommendation,'')), '') AS recommendation,
COALESCE(SUM(CASE WHEN stock_variant_rank = 1 THEN idle_cost_usd ELSE 0 END),0) AS idle_cost_usd
FROM (
SELECT
@@ -3537,6 +3538,8 @@ func productPerformanceSQLGroupExpr(field string) (string, bool) {
return "CASE WHEN btrim(COALESCE(askili_yan,'')) = '-' THEN '' ELSE COALESCE(askili_yan,'') END", true
case "kategori", "urun_ana_grubu", "urun_alt_grubu", "product_code", "item_description", "color_code", "yaka_kodu":
return field, true
case "color_yaka":
return "concat_ws('/', NULLIF(btrim(COALESCE(color_code,'')), ''), NULLIF(btrim(COALESCE(yaka_kodu,'')), ''))", true
case "market_key":
return "btrim(regexp_replace(COALESCE(market_key,''), '^.*\\|', ''))", true
default:
@@ -3939,7 +3942,7 @@ func maxFloat(a, b float64) float64 {
func sanitizeProductPerformanceGroupLevels(levels []string) []string {
allowed := map[string]bool{
"kategori": true, "askili_yan": true, "urun_ilk_grubu": true, "urun_ana_grubu": true, "urun_alt_grubu": true,
"product_code": true, "item_description": true, "color_code": true, "yaka_kodu": true, "market_key": true, "customer_code": true,
"product_code": true, "item_description": true, "color_code": true, "yaka_kodu": true, "color_yaka": true, "market_key": true, "customer_code": true,
"customer_name": true, "country": true, "customer_segment": true,
}
out := make([]string, 0, len(levels))
@@ -3957,9 +3960,9 @@ func sanitizeProductPerformanceGroupLevels(levels []string) []string {
func defaultProductPerformanceGroupLevels(mode string) []string {
switch mode {
case "sales_color_yaka_market_customer":
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"}
return []string{"color_yaka", "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 "product_detail":
return []string{"urun_ana_grubu", "urun_alt_grubu", "product_code", "item_description", "color_code", "yaka_kodu", "market_key"}
return []string{"urun_ana_grubu", "urun_alt_grubu", "product_code", "item_description", "color_yaka", "market_key"}
case "idle":
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":
@@ -3983,6 +3986,15 @@ func mapGroupValue(row map[string]any, field string) string {
return cleanProductPerformanceFirstGroup(stringFromMap(row, "urun_ilk_grubu"))
case "market_key":
return displayProductPerformanceMarketName(stringFromMap(row, "market_key"))
case "color_yaka":
parts := make([]string, 0, 2)
if color := strings.TrimSpace(stringFromMap(row, "color_code")); color != "" {
parts = append(parts, color)
}
if yaka := strings.TrimSpace(stringFromMap(row, "yaka_kodu")); yaka != "" {
parts = append(parts, yaka)
}
return strings.Join(parts, "/")
default:
return stringFromMap(row, field)
}