Merge remote-tracking branch 'origin/master'

This commit is contained in:
2026-02-14 19:44:53 +03:00
parent ce110ed86f
commit 237f73a923
3 changed files with 47 additions and 6 deletions

View File

@@ -10,6 +10,7 @@ import (
"log" "log"
"math" "math"
"net/http" "net/http"
"runtime/debug"
"sort" "sort"
"strings" "strings"
"time" "time"
@@ -895,10 +896,17 @@ func calcRowHeight(pdf *gofpdf.Fpdf, layout pdfLayout, row PdfRow) float64 {
return base return base
} }
// Yeni: açıklama genişliği = sol + sağ // Açıklama tek kolonda (ColDescLeft) render ediliyor.
descW := layout.ColDescW // 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 lineH := 3.2
h := float64(len(lines))*lineH + 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) { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
orderID := mux.Vars(r)["id"] 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 == "" { if orderID == "" {
http.Error(w, "missing order id", http.StatusBadRequest) http.Error(w, "missing order id", http.StatusBadRequest)
return return
@@ -1343,7 +1359,7 @@ func OrderPDFHandler(db *sql.DB) http.Handler {
http.Error(w, "order not found", http.StatusNotFound) http.Error(w, "order not found", http.StatusNotFound)
return return
} }
http.Error(w, "header not found", http.StatusInternalServerError) http.Error(w, "header not found: "+err.Error(), http.StatusInternalServerError)
return return
} }
@@ -1351,7 +1367,7 @@ func OrderPDFHandler(db *sql.DB) http.Handler {
lines, err := getOrderLinesFromDB(db, orderID) lines, err := getOrderLinesFromDB(db, orderID)
if err != nil { if err != nil {
log.Println("lines error:", err) log.Println("lines error:", err)
http.Error(w, "lines not found", http.StatusInternalServerError) http.Error(w, "lines not found: "+err.Error(), http.StatusInternalServerError)
return return
} }
// 🔹 Satırlardan KDV bilgisi yakala (ilk pozitif orana göre) // 🔹 Satırlardan KDV bilgisi yakala (ilk pozitif orana göre)
@@ -1377,6 +1393,10 @@ func OrderPDFHandler(db *sql.DB) http.Handler {
return return
} }
renderOrderGrid(pdf, header, rows, hasVat, vatRate) 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 var buf bytes.Buffer
if err := pdf.Output(&buf); err != nil { if err := pdf.Output(&buf); err != nil {

View File

@@ -9,6 +9,7 @@ import (
"fmt" "fmt"
"log" "log"
"net/http" "net/http"
"runtime/debug"
"sort" "sort"
"strings" "strings"
"time" "time"
@@ -262,6 +263,14 @@ func hDrawMainDataRow(pdf *gofpdf.Fpdf, row []string, widths []float64, rowH flo
func ExportStatementHeaderReportPDFHandler(mssql *sql.DB) http.HandlerFunc { func ExportStatementHeaderReportPDFHandler(mssql *sql.DB) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) { 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()) claims, ok := auth.GetClaimsFromContext(r.Context())
if !ok || claims == nil { if !ok || claims == nil {
http.Error(w, "unauthorized", http.StatusUnauthorized) http.Error(w, "unauthorized", http.StatusUnauthorized)
@@ -373,6 +382,11 @@ func ExportStatementHeaderReportPDFHandler(mssql *sql.DB) http.HandlerFunc {
pdf.Ln(1) pdf.Ln(1)
} }
if err := pdf.Error(); err != nil {
http.Error(w, "PDF render hatası: "+err.Error(), http.StatusInternalServerError)
return
}
var buf bytes.Buffer var buf bytes.Buffer
if err := pdf.Output(&buf); err != nil { if err := pdf.Output(&buf); err != nil {
http.Error(w, "PDF oluşturulamadı: "+err.Error(), http.StatusInternalServerError) http.Error(w, "PDF oluşturulamadı: "+err.Error(), http.StatusInternalServerError)

View File

@@ -10,6 +10,7 @@ import (
"fmt" "fmt"
"log" "log"
"net/http" "net/http"
"runtime/debug"
"sort" "sort"
"strings" "strings"
"time" "time"
@@ -421,7 +422,8 @@ func ExportPDFHandler(mssql *sql.DB) http.HandlerFunc {
defer func() { defer func() {
if rec := recover(); rec != nil { if rec := recover(); rec != nil {
log.Printf("❌ PANIC ExportPDFHandler: %v", rec) 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ı // 7) Çıktı
if err := pdf.Error(); err != nil {
http.Error(w, "PDF render hatası: "+err.Error(), http.StatusInternalServerError)
return
}
var buf bytes.Buffer var buf bytes.Buffer
if err := pdf.Output(&buf); err != nil { if err := pdf.Output(&buf); err != nil {
http.Error(w, "PDF oluşturulamadı: "+err.Error(), http.StatusInternalServerError) http.Error(w, "PDF oluşturulamadı: "+err.Error(), http.StatusInternalServerError)