Compare commits
4 Commits
12f61e373f
...
2bfff006ed
Author | SHA1 | Date | |
---|---|---|---|
2bfff006ed | |||
53eab5db94 | |||
af73b35b18 | |||
692f378eab |
@ -47,7 +47,7 @@ func GenerateCertificate(c *fiber.Ctx) error {
|
||||
}
|
||||
|
||||
genConfig := &models.CertificateTemplateOptions{
|
||||
Runners: certificateRequest.Runners,
|
||||
Runners: addUpRunnerDonations(certificateRequest.Runners),
|
||||
EventName: "Event name",
|
||||
Footer: "Footer",
|
||||
CurrencySymbol: "€",
|
||||
@ -71,3 +71,13 @@ func GenerateCertificate(c *fiber.Ctx) error {
|
||||
c.Set(fiber.HeaderContentType, "application/pdf")
|
||||
return c.Send(pdf)
|
||||
}
|
||||
|
||||
func addUpRunnerDonations(runners []models.RunnerWithDonations) []models.RunnerWithDonations {
|
||||
for i := 0; i < len(runners); i++ {
|
||||
for j := 0; j < len(runners[i].DistanceDonations); j++ {
|
||||
runners[i].TotalDonations += runners[i].DistanceDonations[j].Amount
|
||||
runners[i].TotalPerDistance += runners[i].DistanceDonations[j].AmountPerDistance
|
||||
}
|
||||
}
|
||||
return runners
|
||||
}
|
||||
|
@ -4,8 +4,10 @@ import (
|
||||
"bytes"
|
||||
"encoding/base64"
|
||||
"errors"
|
||||
"fmt"
|
||||
"html/template"
|
||||
"image/png"
|
||||
"strings"
|
||||
|
||||
"git.odit.services/lfk/document-server/templates"
|
||||
"github.com/boombuler/barcode"
|
||||
@ -89,10 +91,24 @@ func (t *DefaultTemplater) SelectSponsorImage(id int) (string, error) {
|
||||
return templates.GetImage(sponsors[id%len(sponsors)]), nil
|
||||
}
|
||||
|
||||
func FormatUnit(unit string, amount int) (string, error) {
|
||||
var formatted string
|
||||
switch unit {
|
||||
case "kilometer":
|
||||
formatted = fmt.Sprintf("%.3f", float64(amount)/1000)
|
||||
case "euro":
|
||||
formatted = fmt.Sprintf("%.2f", float64(amount)/100)
|
||||
default:
|
||||
return "", errors.New("unknown unit")
|
||||
}
|
||||
return strings.Replace(formatted, ".", ",", -1), nil
|
||||
}
|
||||
|
||||
func (t *DefaultTemplater) StringToTemplate(templateString string) (*template.Template, error) {
|
||||
return template.New("template").Funcs(template.FuncMap{
|
||||
"barcode": t.GenerateBarcode,
|
||||
"sponsorLogo": t.SelectSponsorImage,
|
||||
"formatUnit": FormatUnit,
|
||||
}).Parse(templateString)
|
||||
}
|
||||
|
||||
|
File diff suppressed because one or more lines are too long
1
templates/images/certificate_footer.base64
Normal file
1
templates/images/certificate_footer.base64
Normal file
File diff suppressed because one or more lines are too long
BIN
templates/images/certificate_footer.png
Normal file
BIN
templates/images/certificate_footer.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 19 KiB |
Loading…
x
Reference in New Issue
Block a user