Merge remote-tracking branch 'origin/master'

This commit is contained in:
M_Kececi
2026-03-03 01:11:19 +03:00
parent a4f4c2457f
commit ecf3a8bd07
4 changed files with 177 additions and 138 deletions

View File

@@ -226,7 +226,7 @@ func drawCustomerBalancePDF(
tableW := pageW - marginL - marginR
summaryCols := []string{"Ana Cari Kod", "Ana Cari Detay", "Piyasa", "Temsilci", "Risk", "1_2 Pr.Br", "1_3 Pr.Br", "1_2 USD", "1_2 TRY", "1_3 USD", "1_3 TRY"}
summaryW := normalizeWidths([]float64{20, 43, 18, 18, 16, 27, 27, 15, 15, 15, 15}, tableW)
summaryW := normalizeWidths([]float64{20, 52, 16, 20, 14, 24, 24, 14, 14, 14, 14}, tableW)
detailCols := []string{"Cari Kod", "Cari Detay", "Sirket", "Muhasebe", "Doviz", "1_2 Pr.Br", "1_3 Pr.Br", "1_2 USD", "1_2 TRY", "1_3 USD", "1_3 TRY"}
detailW := normalizeWidths([]float64{26, 46, 10, 20, 10, 24, 24, 15, 15, 15, 15}, tableW)
@@ -265,6 +265,44 @@ func drawCustomerBalancePDF(
return pdf.GetY()+needH+marginB > 210.0
}
wrappedLines := func(text string, w float64) [][]byte {
t := strings.TrimSpace(text)
if t == "" {
t = "-"
}
return pdf.SplitLines([]byte(t), w)
}
calcWrappedRowHeight := func(row []string, widths []float64, wrapIdx map[int]bool, lineH float64, minH float64) float64 {
maxLines := 1
for i, v := range row {
if !wrapIdx[i] {
continue
}
ln := len(wrappedLines(v, widths[i]-2))
if ln > maxLines {
maxLines = ln
}
}
h := float64(maxLines)*lineH + 1.2
if h < minH {
return minH
}
return h
}
drawWrapped := func(text string, x, y, w, rowH, lineH float64, align string) {
lines := wrappedLines(text, w-2)
total := float64(len(lines)) * lineH
startY := y + (rowH-total)/2
cy := startY
for _, ln := range lines {
pdf.SetXY(x+1, cy)
pdf.CellFormat(w-2, lineH, string(ln), "", 0, align, false, 0, "")
cy += lineH
}
}
drawSummaryHeader := func() {
pdf.SetFont("dejavu", "B", 7.5)
pdf.SetFillColor(149, 113, 22)
@@ -301,12 +339,7 @@ func drawCustomerBalancePDF(
pdf.SetFont("dejavu", "", 7.2)
pdf.SetTextColor(20, 20, 20)
for _, s := range summaries {
if needPage(6.2) {
header()
drawSummaryHeader()
}
drawSummaryRow := func(s balanceSummaryPDF) {
row := []string{
s.AnaCariKodu,
s.AnaCariAdi,
@@ -320,30 +353,46 @@ func drawCustomerBalancePDF(
formatMoneyPDF(s.USDBakiye13),
formatMoneyPDF(s.TLBakiye13),
}
wrapCols := map[int]bool{1: true, 3: true}
rowH := calcWrappedRowHeight(row, summaryW, wrapCols, 3.2, 6.2)
if needPage(rowH) {
header()
drawSummaryHeader()
}
y := pdf.GetY()
x := marginL
for i, v := range row {
pdf.Rect(x, y, summaryW[i], 6.2, "")
pdf.Rect(x, y, summaryW[i], rowH, "")
align := "L"
if i >= 7 {
align = "R"
}
pdf.SetXY(x+1, y+1)
pdf.CellFormat(summaryW[i]-2, 4.2, v, "", 0, align, false, 0, "")
if wrapCols[i] {
drawWrapped(v, x, y, summaryW[i], rowH, 3.2, "L")
} else {
pdf.SetXY(x+1, y+(rowH-4.2)/2)
pdf.CellFormat(summaryW[i]-2, 4.2, v, "", 0, align, false, 0, "")
}
x += summaryW[i]
}
pdf.SetY(y + 6.2)
pdf.SetY(y + rowH)
}
if !detailed {
for _, s := range summaries {
drawSummaryRow(s)
}
return
}
pdf.Ln(1.8)
for _, s := range summaries {
drawSummaryRow(s)
pdf.Ln(1.2)
rows := detailsByMaster[s.AnaCariKodu]
if len(rows) == 0 {
pdf.Ln(1.0)
continue
}