From c57c04e12aebc5151780dd7691628101fe062db1 Mon Sep 17 00:00:00 2001 From: M_Kececi Date: Tue, 3 Mar 2026 11:26:52 +0300 Subject: [PATCH] Merge remote-tracking branch 'origin/master' --- svc/routes/customer_balance_pdf.go | 2 +- svc/routes/statement_aging_pdf.go | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/svc/routes/customer_balance_pdf.go b/svc/routes/customer_balance_pdf.go index a1ff7dd..48a1d12 100644 --- a/svc/routes/customer_balance_pdf.go +++ b/svc/routes/customer_balance_pdf.go @@ -284,7 +284,7 @@ func drawCustomerBalancePDF( if t == "" { t = "-" } - return pdf.SplitLines([]byte(t), w) + return splitLinesSafe(pdf, t, w) } calcWrappedRowHeight := func(row []string, widths []float64, wrapIdx map[int]bool, lineH float64, minH float64) float64 { diff --git a/svc/routes/statement_aging_pdf.go b/svc/routes/statement_aging_pdf.go index f430275..8ee3eba 100644 --- a/svc/routes/statement_aging_pdf.go +++ b/svc/routes/statement_aging_pdf.go @@ -7,8 +7,10 @@ import ( "bytes" "database/sql" "fmt" + "log" "math" "net/http" + "runtime/debug" "sort" "strconv" "strings" @@ -76,6 +78,13 @@ type agingMasterPDF struct { func ExportStatementAgingPDFHandler(_ *sql.DB) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { + defer func() { + if rec := recover(); rec != nil { + log.Printf("PANIC ExportStatementAgingPDFHandler: %v\n%s", rec, string(debug.Stack())) + http.Error(w, "internal server error", http.StatusInternalServerError) + } + }() + claims, ok := auth.GetClaimsFromContext(r.Context()) if !ok || claims == nil { http.Error(w, "unauthorized", http.StatusUnauthorized) @@ -99,6 +108,11 @@ func ExportStatementAgingPDFHandler(_ *sql.DB) http.HandlerFunc { excludeZero12 := parseBoolQuery(r.URL.Query().Get("exclude_zero_12")) excludeZero13 := parseBoolQuery(r.URL.Query().Get("exclude_zero_13")) + if err := queries.RebuildStatementAgingCache(r.Context()); err != nil { + http.Error(w, "cache rebuild error: "+err.Error(), http.StatusInternalServerError) + return + } + rows, err := queries.GetStatementAgingBalanceList(r.Context(), listParams) if err != nil { http.Error(w, "db error: "+err.Error(), http.StatusInternalServerError)