Compare commits

..

4 Commits

5 changed files with 34 additions and 7 deletions

View File

@ -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
}

View File

@ -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

File diff suppressed because one or more lines are too long

Binary file not shown.

After

Width:  |  Height:  |  Size: 19 KiB