From 237f73a92383817d0f970565ec6700616493e84a Mon Sep 17 00:00:00 2001 From: MEHMETKECECI Date: Sat, 14 Feb 2026 19:44:53 +0300 Subject: [PATCH] Merge remote-tracking branch 'origin/master' --- svc/routes/order_pdf.go | 30 +++++++++++++++++++++++++----- svc/routes/statement_header_pdf.go | 14 ++++++++++++++ svc/routes/statements_pdf.go | 9 ++++++++- 3 files changed, 47 insertions(+), 6 deletions(-) diff --git a/svc/routes/order_pdf.go b/svc/routes/order_pdf.go index 65021c6..668066b 100644 --- a/svc/routes/order_pdf.go +++ b/svc/routes/order_pdf.go @@ -10,6 +10,7 @@ import ( "log" "math" "net/http" + "runtime/debug" "sort" "strings" "time" @@ -895,10 +896,17 @@ func calcRowHeight(pdf *gofpdf.Fpdf, layout pdfLayout, row PdfRow) float64 { return base } - // Yeni: açıklama genişliği = sol + sağ - descW := layout.ColDescW + // Açıklama tek kolonda (ColDescLeft) render ediliyor. + // ColDescW set edilmediği için 0 kalabiliyor; bu durumda SplitLines patlayabiliyor. + descW := layout.ColDescLeft + if descW <= float64(2*OcellPadX) { + descW = layout.ColDescLeft + layout.ColDescRight + } + if descW <= float64(2*OcellPadX) { + return base + } - lines := pdf.SplitLines([]byte(desc), descW-2*OcellPadX) + lines := pdf.SplitLines([]byte(desc), descW-float64(2*OcellPadX)) lineH := 3.2 h := float64(len(lines))*lineH + 2 @@ -1326,6 +1334,14 @@ func OrderPDFHandler(db *sql.DB) http.Handler { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { orderID := mux.Vars(r)["id"] + defer func() { + if rec := recover(); rec != nil { + log.Printf("❌ PANIC OrderPDFHandler orderID=%s: %v", orderID, rec) + debug.PrintStack() + http.Error(w, fmt.Sprintf("order pdf panic: %v", rec), http.StatusInternalServerError) + } + }() + if orderID == "" { http.Error(w, "missing order id", http.StatusBadRequest) return @@ -1343,7 +1359,7 @@ func OrderPDFHandler(db *sql.DB) http.Handler { http.Error(w, "order not found", http.StatusNotFound) return } - http.Error(w, "header not found", http.StatusInternalServerError) + http.Error(w, "header not found: "+err.Error(), http.StatusInternalServerError) return } @@ -1351,7 +1367,7 @@ func OrderPDFHandler(db *sql.DB) http.Handler { lines, err := getOrderLinesFromDB(db, orderID) if err != nil { log.Println("lines error:", err) - http.Error(w, "lines not found", http.StatusInternalServerError) + http.Error(w, "lines not found: "+err.Error(), http.StatusInternalServerError) return } // 🔹 Satırlardan KDV bilgisi yakala (ilk pozitif orana göre) @@ -1377,6 +1393,10 @@ func OrderPDFHandler(db *sql.DB) http.Handler { return } renderOrderGrid(pdf, header, rows, hasVat, vatRate) + if err := pdf.Error(); err != nil { + http.Error(w, "pdf render error: "+err.Error(), http.StatusInternalServerError) + return + } var buf bytes.Buffer if err := pdf.Output(&buf); err != nil { diff --git a/svc/routes/statement_header_pdf.go b/svc/routes/statement_header_pdf.go index dd045a8..8c40972 100644 --- a/svc/routes/statement_header_pdf.go +++ b/svc/routes/statement_header_pdf.go @@ -9,6 +9,7 @@ import ( "fmt" "log" "net/http" + "runtime/debug" "sort" "strings" "time" @@ -262,6 +263,14 @@ func hDrawMainDataRow(pdf *gofpdf.Fpdf, row []string, widths []float64, rowH flo func ExportStatementHeaderReportPDFHandler(mssql *sql.DB) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { + defer func() { + if rec := recover(); rec != nil { + log.Printf("❌ PANIC ExportStatementHeaderReportPDFHandler: %v", rec) + debug.PrintStack() + http.Error(w, fmt.Sprintf("header PDF panic: %v", rec), http.StatusInternalServerError) + } + }() + claims, ok := auth.GetClaimsFromContext(r.Context()) if !ok || claims == nil { http.Error(w, "unauthorized", http.StatusUnauthorized) @@ -373,6 +382,11 @@ func ExportStatementHeaderReportPDFHandler(mssql *sql.DB) http.HandlerFunc { pdf.Ln(1) } + if err := pdf.Error(); err != nil { + http.Error(w, "PDF render hatası: "+err.Error(), http.StatusInternalServerError) + return + } + var buf bytes.Buffer if err := pdf.Output(&buf); err != nil { http.Error(w, "PDF oluşturulamadı: "+err.Error(), http.StatusInternalServerError) diff --git a/svc/routes/statements_pdf.go b/svc/routes/statements_pdf.go index b490e8c..987a164 100644 --- a/svc/routes/statements_pdf.go +++ b/svc/routes/statements_pdf.go @@ -10,6 +10,7 @@ import ( "fmt" "log" "net/http" + "runtime/debug" "sort" "strings" "time" @@ -421,7 +422,8 @@ func ExportPDFHandler(mssql *sql.DB) http.HandlerFunc { defer func() { if rec := recover(); rec != nil { log.Printf("❌ PANIC ExportPDFHandler: %v", rec) - http.Error(w, "PDF oluşturulurken hata oluştu", http.StatusInternalServerError) + debug.PrintStack() + http.Error(w, fmt.Sprintf("PDF oluşturulurken panic oluştu: %v", rec), http.StatusInternalServerError) } }() @@ -603,6 +605,11 @@ func ExportPDFHandler(mssql *sql.DB) http.HandlerFunc { } // 7) Çıktı + if err := pdf.Error(); err != nil { + http.Error(w, "PDF render hatası: "+err.Error(), http.StatusInternalServerError) + return + } + var buf bytes.Buffer if err := pdf.Output(&buf); err != nil { http.Error(w, "PDF oluşturulamadı: "+err.Error(), http.StatusInternalServerError)