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"
"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 {