diff --git a/svc/routes/order_pdf.go b/svc/routes/order_pdf.go index 60b0577..1d74e60 100644 --- a/svc/routes/order_pdf.go +++ b/svc/routes/order_pdf.go @@ -12,6 +12,7 @@ import ( "net/http" "runtime/debug" "sort" + "strconv" "strings" "time" ) @@ -289,25 +290,88 @@ func normalizeBedenLabelGo(v string) string { return s } +func parseNumericSize(v string) (int, bool) { + s := strings.TrimSpace(strings.ToUpper(v)) + if s == "" { + return 0, false + } + n, err := strconv.Atoi(s) + if err != nil { + return 0, false + } + return n, true +} + func detectBedenGroupGo(bedenList []string, ana, alt string) string { ana = safeTrimUpper(ana) alt = safeTrimUpper(alt) + // Ürün grubu adı doğrudan ayakkabı ise öncelikli. + if strings.Contains(ana, "AYAKKABI") || strings.Contains(alt, "AYAKKABI") { + return catAyk + } + + var hasYasNumeric bool + var hasAykNumeric bool + var hasPanNumeric bool + for _, b := range bedenList { + b = safeTrimUpper(b) + switch b { - case "XS", "S", "M", "L", "XL": + case "XS", "S", "M", "L", "XL", + "2XL", "3XL", "4XL", "5XL", "6XL", "7XL": return catGom } + + if n, ok := parseNumericSize(b); ok { + if n >= 2 && n <= 14 { + hasYasNumeric = true + } + if n >= 39 && n <= 45 { + hasAykNumeric = true + } + if n >= 38 && n <= 68 { + hasPanNumeric = true + } + } + } + + if hasAykNumeric { + return catAyk } if strings.Contains(ana, "PANTOLON") { return catPan } + if hasPanNumeric { + return catPan + } if strings.Contains(alt, "ÇOCUK") || strings.Contains(alt, "GARSON") { return catYas } + if hasYasNumeric { + return catYas + } + return catTak } + +func formatSizeQtyForLog(m map[string]int) string { + if len(m) == 0 { + return "{}" + } + keys := make([]string, 0, len(m)) + for k := range m { + keys = append(keys, k) + } + sort.Strings(keys) + parts := make([]string, 0, len(keys)) + for _, k := range keys { + parts = append(parts, fmt.Sprintf("%s:%d", k, m[k])) + } + return "{" + strings.Join(parts, ", ") + "}" +} func defaultSizeListFor(cat string) []string { switch cat { case catAyk: @@ -1408,6 +1472,22 @@ func OrderPDFHandler(db *sql.DB) http.Handler { // Normalize rows := normalizeOrderLinesForPdf(lines) log.Printf("📄 OrderPDF normalized rows orderID=%s rowCount=%d", orderID, len(rows)) + for i, rr := range rows { + if i >= 30 { + break + } + log.Printf( + "📄 OrderPDF row[%d] model=%s color=%s groupMain=%q groupSub=%q category=%s totalQty=%d sizeQty=%s", + i, + rr.Model, + rr.Color, + rr.GroupMain, + rr.GroupSub, + rr.Category, + rr.TotalQty, + formatSizeQtyForLog(rr.SizeQty), + ) + } // PDF pdf, err := newOrderPdf()