Compare commits
2 Commits
ce110ed86f
...
d0f20674ea
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d0f20674ea | ||
|
|
237f73a923 |
@@ -10,6 +10,7 @@ import (
|
|||||||
"log"
|
"log"
|
||||||
"math"
|
"math"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"runtime/debug"
|
||||||
"sort"
|
"sort"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
@@ -238,6 +239,13 @@ func s64(v sql.NullString) string {
|
|||||||
return v.String
|
return v.String
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func sOrEmpty(v sql.NullString) string {
|
||||||
|
if !v.Valid {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
return strings.TrimSpace(v.String)
|
||||||
|
}
|
||||||
|
|
||||||
func normalizeBedenLabelGo(v string) string {
|
func normalizeBedenLabelGo(v string) string {
|
||||||
// 1️⃣ NULL / boş / whitespace → " " (aksbir null kolonu)
|
// 1️⃣ NULL / boş / whitespace → " " (aksbir null kolonu)
|
||||||
s := strings.TrimSpace(v)
|
s := strings.TrimSpace(v)
|
||||||
@@ -388,24 +396,36 @@ func getOrderHeaderFromDB(db *sql.DB, orderID string) (*OrderHeader, error) {
|
|||||||
|
|
||||||
var h OrderHeader
|
var h OrderHeader
|
||||||
var orderDate sql.NullTime
|
var orderDate sql.NullTime
|
||||||
|
var orderNumber, currAccCode, currAccName, docCurrency sql.NullString
|
||||||
|
var description, internalDesc, officeCode, createdUser, customerRep sql.NullString
|
||||||
|
|
||||||
err := row.Scan(
|
err := row.Scan(
|
||||||
&h.OrderHeaderID,
|
&h.OrderHeaderID,
|
||||||
&h.OrderNumber,
|
&orderNumber,
|
||||||
&h.CurrAccCode,
|
&currAccCode,
|
||||||
&h.CurrAccName,
|
&currAccName,
|
||||||
&h.DocCurrency,
|
&docCurrency,
|
||||||
&orderDate,
|
&orderDate,
|
||||||
&h.Description,
|
&description,
|
||||||
&h.InternalDesc,
|
&internalDesc,
|
||||||
&h.OfficeCode,
|
&officeCode,
|
||||||
&h.CreatedUser,
|
&createdUser,
|
||||||
&h.CustomerRep, // 🆕 buradan geliyor
|
&customerRep, // 🆕 buradan geliyor
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
h.OrderNumber = sOrEmpty(orderNumber)
|
||||||
|
h.CurrAccCode = sOrEmpty(currAccCode)
|
||||||
|
h.CurrAccName = sOrEmpty(currAccName)
|
||||||
|
h.DocCurrency = sOrEmpty(docCurrency)
|
||||||
|
h.Description = sOrEmpty(description)
|
||||||
|
h.InternalDesc = sOrEmpty(internalDesc)
|
||||||
|
h.OfficeCode = sOrEmpty(officeCode)
|
||||||
|
h.CreatedUser = sOrEmpty(createdUser)
|
||||||
|
h.CustomerRep = sOrEmpty(customerRep)
|
||||||
|
|
||||||
if orderDate.Valid {
|
if orderDate.Valid {
|
||||||
h.OrderDate = orderDate.Time
|
h.OrderDate = orderDate.Time
|
||||||
}
|
}
|
||||||
@@ -895,10 +915,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 +1353,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 +1378,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 +1386,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 +1412,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 {
|
||||||
|
|||||||
@@ -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)
|
||||||
|
|||||||
@@ -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)
|
||||||
|
|||||||
Reference in New Issue
Block a user