feat: pdf
This commit is contained in:
@@ -5,6 +5,8 @@ import (
|
||||
_ "embed"
|
||||
"fmt"
|
||||
"html/template"
|
||||
"math"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
@@ -19,27 +21,46 @@ func (r Report) ToHTML() string {
|
||||
template.New("report").Funcs(template.FuncMap{
|
||||
"md": mdToHTML,
|
||||
"oh": offsetHTags,
|
||||
"price": applyRate,
|
||||
"time": fmtTime,
|
||||
"price": r.applyRate,
|
||||
"time": fmtDateTime,
|
||||
"date": fmtDate,
|
||||
"duration": fmtDuration,
|
||||
"brakes": func(text string) template.HTML {
|
||||
return template.HTML(strings.ReplaceAll(template.HTMLEscapeString(text), "\n", "<br>"))
|
||||
},
|
||||
}).Parse(htmlTemplate))
|
||||
|
||||
r.Style = style
|
||||
|
||||
buf := new(bytes.Buffer)
|
||||
tmpl.Execute(buf, r)
|
||||
_ = tmpl.Execute(buf, r)
|
||||
return buf.String()
|
||||
}
|
||||
|
||||
func applyRate(dur time.Duration) string {
|
||||
cost := dur.Hours() * 16
|
||||
func (r Report) applyRate(dur time.Duration) string {
|
||||
cost := dur.Hours() * r.Rate
|
||||
cost = math.Round(cost/0.05) * 0.05
|
||||
return fmt.Sprintf("%.2f", cost)
|
||||
}
|
||||
|
||||
func fmtTime(t time.Time) string {
|
||||
func fmtDateTime(t time.Time) string {
|
||||
return t.Format("02.08.2006 15:04")
|
||||
}
|
||||
|
||||
func fmtDate(t time.Time) string {
|
||||
return t.Format("02.08.2006")
|
||||
}
|
||||
|
||||
func fmtDuration(d time.Duration) string {
|
||||
return fmt.Sprintf("%.2f h", d.Hours())
|
||||
}
|
||||
|
||||
func (r Report) Total() string {
|
||||
dur := time.Duration(0)
|
||||
|
||||
for _, i := range r.Issues {
|
||||
dur += i.Duration
|
||||
}
|
||||
|
||||
return r.applyRate(dur)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user