feat: PDF — total claim in header, wider merchant column (52mm)
This commit is contained in:
parent
e9460a6a7d
commit
f1b029949e
2 changed files with 47 additions and 7 deletions
|
|
@ -681,13 +681,33 @@ func generatePDF(eventName string, expenses []database.Expense, userName, userDe
|
|||
infoLine += fmt.Sprintf(" | Department: %s", userDept)
|
||||
}
|
||||
pdf.Cell(0, 6, infoLine)
|
||||
pdf.Ln(10)
|
||||
pdf.Ln(6)
|
||||
}
|
||||
|
||||
// Total claim summary.
|
||||
var totalClaim float64
|
||||
claimCur := ""
|
||||
for _, exp := range expenses {
|
||||
cAmt := exp.ConvertedAmount
|
||||
if cAmt <= 0 {
|
||||
cAmt = exp.Amount
|
||||
}
|
||||
totalClaim += cAmt
|
||||
if claimCur == "" && exp.BaseCurrency != "" {
|
||||
claimCur = exp.BaseCurrency
|
||||
}
|
||||
}
|
||||
if claimCur == "" && len(expenses) > 0 {
|
||||
claimCur = expenses[0].Currency
|
||||
}
|
||||
pdf.SetFont("Helvetica", "B", 10)
|
||||
pdf.Cell(0, 8, fmt.Sprintf("Total Claim: %.2f %s", totalClaim, claimCur))
|
||||
pdf.Ln(12)
|
||||
|
||||
// Table header.
|
||||
pdf.SetFont("Helvetica", "B", 8)
|
||||
headers := []string{"#", "Date", "Merchant", "Local Amt", "Cur", "Claim Amt", "Claim", "Category", "Description"}
|
||||
colWidths := []float64{7, 22, 40, 18, 12, 18, 12, 38, 110}
|
||||
colWidths := []float64{7, 22, 52, 18, 12, 18, 12, 36, 100}
|
||||
for i, h := range headers {
|
||||
pdf.Cell(colWidths[i], 7, h)
|
||||
}
|
||||
|
|
@ -696,7 +716,7 @@ func generatePDF(eventName string, expenses []database.Expense, userName, userDe
|
|||
// Table data rows.
|
||||
pdf.SetFont("Helvetica", "", 8)
|
||||
marginBottom := 18.0
|
||||
var totalLocal, totalClaim float64
|
||||
var totalLocal, tableClaim float64
|
||||
for i, exp := range expenses {
|
||||
if pdf.GetY() > 210-marginBottom {
|
||||
pdf.AddPage()
|
||||
|
|
@ -728,7 +748,7 @@ func generatePDF(eventName string, expenses []database.Expense, userName, userDe
|
|||
pdf.Cell(colWidths[8], 6, exp.Description)
|
||||
pdf.Ln(6)
|
||||
totalLocal += exp.Amount
|
||||
totalClaim += claimAmt
|
||||
tableClaim += claimAmt
|
||||
}
|
||||
|
||||
// Totals row in claim currency.
|
||||
|
|
@ -751,7 +771,7 @@ func generatePDF(eventName string, expenses []database.Expense, userName, userDe
|
|||
pdf.Cell(colWidths[2], 8, "TOTAL")
|
||||
pdf.Cell(colWidths[3], 8, fmt.Sprintf("%.2f", totalLocal))
|
||||
pdf.Cell(colWidths[4], 8, "")
|
||||
pdf.Cell(colWidths[5], 8, fmt.Sprintf("%.2f", totalClaim))
|
||||
pdf.Cell(colWidths[5], 8, fmt.Sprintf("%.2f", tableClaim))
|
||||
pdf.Cell(colWidths[6], 8, claimTotalCur)
|
||||
pdf.Cell(colWidths[7], 8, "")
|
||||
pdf.Cell(colWidths[8], 8, "")
|
||||
|
|
|
|||
|
|
@ -646,9 +646,29 @@ func generateMonthlyPDF(monthName string, events []database.Event, expenses []da
|
|||
infoLine += fmt.Sprintf(" | Department: %s", userDept)
|
||||
}
|
||||
pdf.Cell(0, 6, infoLine)
|
||||
pdf.Ln(10)
|
||||
pdf.Ln(6)
|
||||
}
|
||||
|
||||
// Total claim summary.
|
||||
var totalClaim float64
|
||||
claimCur := ""
|
||||
for _, exp := range expenses {
|
||||
cAmt := exp.ConvertedAmount
|
||||
if cAmt <= 0 {
|
||||
cAmt = exp.Amount
|
||||
}
|
||||
totalClaim += cAmt
|
||||
if claimCur == "" && exp.BaseCurrency != "" {
|
||||
claimCur = exp.BaseCurrency
|
||||
}
|
||||
}
|
||||
if claimCur == "" && len(expenses) > 0 {
|
||||
claimCur = expenses[0].Currency
|
||||
}
|
||||
pdf.SetFont("Helvetica", "B", 10)
|
||||
pdf.Cell(0, 8, fmt.Sprintf("Total Claim: %.2f %s", totalClaim, claimCur))
|
||||
pdf.Ln(12)
|
||||
|
||||
// Group expenses by event.
|
||||
expensesByEvent := make(map[string][]database.Expense)
|
||||
eventNames := make(map[string]string)
|
||||
|
|
@ -661,7 +681,7 @@ func generateMonthlyPDF(monthName string, events []database.Event, expenses []da
|
|||
|
||||
itemNum := 1
|
||||
// Landscape A4: 297mm wide, 10mm margins → 277mm usable.
|
||||
colWidths := []float64{7, 22, 38, 18, 12, 18, 12, 36, 114}
|
||||
colWidths := []float64{7, 22, 52, 18, 12, 18, 12, 36, 100}
|
||||
headers := []string{"#", "Date", "Merchant", "Local Amt", "Cur", "Claim Amt", "Claim", "Category", "Description"}
|
||||
marginBottom := 18.0
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue