go #49
@ -4,6 +4,7 @@ import (
|
|||||||
"bytes"
|
"bytes"
|
||||||
"encoding/base64"
|
"encoding/base64"
|
||||||
"errors"
|
"errors"
|
||||||
|
"fmt"
|
||||||
"html/template"
|
"html/template"
|
||||||
"image/png"
|
"image/png"
|
||||||
|
|
||||||
@ -89,10 +90,22 @@ func (t *DefaultTemplater) SelectSponsorImage(id int) (string, error) {
|
|||||||
return templates.GetImage(sponsors[id%len(sponsors)]), nil
|
return templates.GetImage(sponsors[id%len(sponsors)]), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func FormatUnit(unit string, amount int) (string, error) {
|
||||||
|
switch unit {
|
||||||
|
case "kilometer":
|
||||||
|
return fmt.Sprintf("%.3f", float64(amount)/1000), nil
|
||||||
|
case "euro":
|
||||||
|
return fmt.Sprintf("%.2f", float64(amount)/100), nil
|
||||||
|
default:
|
||||||
|
return "", errors.New("unknown unit")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func (t *DefaultTemplater) StringToTemplate(templateString string) (*template.Template, error) {
|
func (t *DefaultTemplater) StringToTemplate(templateString string) (*template.Template, error) {
|
||||||
return template.New("template").Funcs(template.FuncMap{
|
return template.New("template").Funcs(template.FuncMap{
|
||||||
"barcode": t.GenerateBarcode,
|
"barcode": t.GenerateBarcode,
|
||||||
"sponsorLogo": t.SelectSponsorImage,
|
"sponsorLogo": t.SelectSponsorImage,
|
||||||
|
"formatUnit": FormatUnit,
|
||||||
}).Parse(templateString)
|
}).Parse(templateString)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -56,7 +56,7 @@
|
|||||||
{{ .MiddleName }} {{ .LastName }}
|
{{ .MiddleName }} {{ .LastName }}
|
||||||
</p>
|
</p>
|
||||||
<p style="font-size: 1cm; margin-bottom: 0;">hat beim {{ $.EventName }}</p>
|
<p style="font-size: 1cm; margin-bottom: 0;">hat beim {{ $.EventName }}</p>
|
||||||
<p style="font-size: 2cm; font-weight: bold; margin-bottom: 0;">{{unitFormat "kilometer" .Distance}}km</p>
|
<p style="font-size: 2cm; font-weight: bold; margin-bottom: 0;">{{formatUnit "kilometer" .Distance}}km</p>
|
||||||
<p style="font-size: 1cm;">für den guten Zweck zurückgelegt</p>
|
<p style="font-size: 1cm;">für den guten Zweck zurückgelegt</p>
|
||||||
</main>
|
</main>
|
||||||
<footer class="certificate-footer">
|
<footer class="certificate-footer">
|
||||||
@ -78,15 +78,15 @@
|
|||||||
{{ range .DistanceDonations}}
|
{{ range .DistanceDonations}}
|
||||||
<tr>
|
<tr>
|
||||||
<td>{{ .Donor.FirstName }} {{ .Donor.MiddleName }} {{ .Donor.LastName }}</td>
|
<td>{{ .Donor.FirstName }} {{ .Donor.MiddleName }} {{ .Donor.LastName }}</td>
|
||||||
<td>{{ unitFormat "euro" .AmountPerDistance }} {{ $.CurrencySymbol }}</td>
|
<td>{{ formatUnit "euro" .AmountPerDistance }} {{ $.CurrencySymbol }}</td>
|
||||||
<td>{{ unitFormat "euro" .Amount }} {{ $.CurrencySymbol }}</td>
|
<td>{{ formatUnit "euro" .Amount }} {{ $.CurrencySymbol }}</td>
|
||||||
</tr>
|
</tr>
|
||||||
{{ end }}
|
{{ end }}
|
||||||
</tbody>
|
</tbody>
|
||||||
<tfoot>
|
<tfoot>
|
||||||
<td>Gesamt</td>
|
<td>Gesamt</td>
|
||||||
<td>{{ unitFormat .TotalPerDistance }} {{ $.CurrencySymbol }}</td>
|
<td>{{ formatUnit "euro" .TotalPerDistance }} {{ $.CurrencySymbol }}</td>
|
||||||
<td>{{ unitFormat .TotalDonations }} {{ $.CurrencySymbol }}</td>
|
<td>{{ formatUnit "euro" .TotalDonations }} {{ $.CurrencySymbol }}</td>
|
||||||
</tfoot>
|
</tfoot>
|
||||||
</table>
|
</table>
|
||||||
</main>
|
</main>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user