From f562ef2a332995e0004cb0a26ddadb5951330caf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=20Tr=C3=B6ger?= Date: Fri, 19 Dec 2025 09:15:58 +0100 Subject: [PATCH] added public holidays + updated templ to v0.3.960 --- Backend/endpoints/pdf-create.go | 9 ++-- Backend/go.mod | 2 +- Backend/go.sum | 2 + Backend/helper/paramParser/main.go | 5 +- Backend/models/publicHoliday.go | 53 ++++++++++++++++++++ Backend/templates/headerComponent_templ.go | 2 +- Backend/templates/pages_templ.go | 3 +- Backend/templates/pdf_templ.go | 4 +- Backend/templates/presencePage_templ.go | 2 +- Backend/templates/teamComponents_templ.go | 7 +-- Backend/templates/timeComponents_templ.go | 4 +- Backend/templates/timePage_templ.go | 8 +-- DB/initdb/01_schema.sql | 7 ++- migrations/20251217215955_feiertage.down.sql | 6 +++ migrations/20251217215955_feiertage.up.sql | 11 ++++ migrations/atlas.sum | 3 +- 16 files changed, 95 insertions(+), 33 deletions(-) create mode 100644 Backend/models/publicHoliday.go create mode 100644 migrations/20251217215955_feiertage.down.sql create mode 100644 migrations/20251217215955_feiertage.up.sql diff --git a/Backend/endpoints/pdf-create.go b/Backend/endpoints/pdf-create.go index 7b37bc9..443a2a1 100644 --- a/Backend/endpoints/pdf-create.go +++ b/Backend/endpoints/pdf-create.go @@ -143,9 +143,9 @@ func createReports(employes []models.User, startDate time.Time) []typstData { endDate := startDate.AddDate(0, 1, -1) var employeData []typstData - for _, employe := range employes { - if data, err := createEmployeReport(employe, startDate, endDate); err != nil { - slog.Warn("Error when creating employeReport", slog.Any("user", employe), slog.Any("error", err)) + for _, employee := range employes { + if data, err := createEmployeReport(employee, startDate, endDate); err != nil { + slog.Warn("Error when creating employeReport", slog.Any("user", employee), slog.Any("error", err)) } else { employeData = append(employeData, data) } @@ -154,7 +154,8 @@ func createReports(employes []models.User, startDate time.Time) []typstData { } func createEmployeReport(employee models.User, startDate, endDate time.Time) (typstData, error) { - targetHoursThisMonth := employee.ArbeitszeitProWocheFrac(.2) * time.Duration(helper.GetWorkingDays(startDate, endDate)) + publicHolidays, err := models.GetHolidaysFromTo(startDate, endDate) + targetHoursThisMonth := employee.ArbeitszeitProWocheFrac(.2) * time.Duration(helper.GetWorkingDays(startDate, endDate)-len(publicHolidays)) workDaysThisMonth := models.GetDays(employee, startDate, endDate.AddDate(0, 0, 1), false) slog.Debug("Baseline Working hours", "targetHours", targetHoursThisMonth.Hours()) diff --git a/Backend/go.mod b/Backend/go.mod index f11e0c9..3c70ca4 100644 --- a/Backend/go.mod +++ b/Backend/go.mod @@ -4,7 +4,7 @@ go 1.24.7 require github.com/lib/pq v1.10.9 -require github.com/a-h/templ v0.3.943 +require github.com/a-h/templ v0.3.960 require github.com/alexedwards/scs/v2 v2.8.0 diff --git a/Backend/go.sum b/Backend/go.sum index 9cfab85..0c9f849 100644 --- a/Backend/go.sum +++ b/Backend/go.sum @@ -6,6 +6,8 @@ github.com/Microsoft/go-winio v0.6.2 h1:F2VQgta7ecxGYO8k3ZZz3RS8fVIXVxONVUPlNERo github.com/Microsoft/go-winio v0.6.2/go.mod h1:yd8OoFMLzJbo9gZq8j5qaps8bJ9aShtEA8Ipt1oGCvU= github.com/a-h/templ v0.3.943 h1:o+mT/4yqhZ33F3ootBiHwaY4HM5EVaOJfIshvd5UNTY= github.com/a-h/templ v0.3.943/go.mod h1:oCZcnKRf5jjsGpf2yELzQfodLphd2mwecwG4Crk5HBo= +github.com/a-h/templ v0.3.960 h1:trshEpGa8clF5cdI39iY4ZrZG8Z/QixyzEyUnA7feTM= +github.com/a-h/templ v0.3.960/go.mod h1:oCZcnKRf5jjsGpf2yELzQfodLphd2mwecwG4Crk5HBo= github.com/alexedwards/scs/v2 v2.8.0 h1:h31yUYoycPuL0zt14c0gd+oqxfRwIj6SOjHdKRZxhEw= github.com/alexedwards/scs/v2 v2.8.0/go.mod h1:ToaROZxyKukJKT/xLcVQAChi5k6+Pn1Gvmdl7h3RRj8= github.com/bytedance/gopkg v0.1.3/go.mod h1:576VvJ+eJgyCzdjS+c4+77QF3p7ubbtiKARP3TxducM= diff --git a/Backend/helper/paramParser/main.go b/Backend/helper/paramParser/main.go index dcce66d..8dd6586 100644 --- a/Backend/helper/paramParser/main.go +++ b/Backend/helper/paramParser/main.go @@ -26,10 +26,9 @@ func (p ParamsParser) ParseIntListFallback(key string, delimiter string, fallbac if !p.urlParams.Has(key) { return fallback } - paramList := p.urlParams.Get(key) - list := strings.Split(paramList, delimiter) + paramList := p.urlParams[key] parsedList := make([]int, 0) - for _, item := range list { + for _, item := range paramList { if parsedItem, err := strconv.Atoi(item); err == nil { parsedList = append(parsedList, parsedItem) } diff --git a/Backend/models/publicHoliday.go b/Backend/models/publicHoliday.go new file mode 100644 index 0000000..351ae6a --- /dev/null +++ b/Backend/models/publicHoliday.go @@ -0,0 +1,53 @@ +package models + +import "time" + +type PublicHoliday struct { + name string + date time.Time +} + +func GetHolidaysFromTo(tsFrom, tsTo time.Time) ([]PublicHoliday, error) { + return make([]PublicHoliday, 0), nil +} + +// Interface implementation +func (p *PublicHoliday) Date() time.Time { + return time.Now() +} + +func (p *PublicHoliday) ToString() string { + return "" +} + +func (p *PublicHoliday) IsWorkDay() bool { + return false +} + +func (p *PublicHoliday) IsKurzArbeit() bool { + return false +} + +func (p *PublicHoliday) GetDayProgress(User) int8 { + return 0 +} + +func (p *PublicHoliday) RequiresAction() bool { + return false +} + +func (p *PublicHoliday) GetWorktime(User, WorktimeBase, bool) time.Duration { + return 0 +} + +func (p *PublicHoliday) GetPausetime(User, WorktimeBase, bool) time.Duration { + return 0 +} + +func (p *PublicHoliday) GetTimes(User, WorktimeBase, bool) (work, pause, overtime time.Duration) { + return 0, 0, 0 +} + +func (p *PublicHoliday) GetOvertime(User, WorktimeBase, bool) time.Duration { + return 0 +} diff --git a/Backend/templates/headerComponent_templ.go b/Backend/templates/headerComponent_templ.go index 39e8195..aa67d81 100644 --- a/Backend/templates/headerComponent_templ.go +++ b/Backend/templates/headerComponent_templ.go @@ -1,6 +1,6 @@ // Code generated by templ - DO NOT EDIT. -// templ: version: v0.3.943 +// templ: version: v0.3.960 package templates //lint:file-ignore SA4006 This context is only used if a nested component is present. diff --git a/Backend/templates/pages_templ.go b/Backend/templates/pages_templ.go index 6e32b44..933f53c 100644 --- a/Backend/templates/pages_templ.go +++ b/Backend/templates/pages_templ.go @@ -1,6 +1,6 @@ // Code generated by templ - DO NOT EDIT. -// templ: version: v0.3.943 +// templ: version: v0.3.960 package templates //lint:file-ignore SA4006 This context is only used if a nested component is present. @@ -116,7 +116,6 @@ func SettingsPage(status int) templ.Component { templ_7745c5c3_Var4 = templ.NopComponent } ctx = templ.ClearChildren(ctx) - user := ctx.Value("user").(models.User) templ_7745c5c3_Err = Base().Render(ctx, templ_7745c5c3_Buffer) if templ_7745c5c3_Err != nil { diff --git a/Backend/templates/pdf_templ.go b/Backend/templates/pdf_templ.go index ffc7c06..b45c4c7 100644 --- a/Backend/templates/pdf_templ.go +++ b/Backend/templates/pdf_templ.go @@ -1,6 +1,6 @@ // Code generated by templ - DO NOT EDIT. -// templ: version: v0.3.943 +// templ: version: v0.3.960 package templates //lint:file-ignore SA4006 This context is only used if a nested component is present. @@ -130,7 +130,6 @@ func CheckboxComponent(pNr int, label string) templ.Component { templ_7745c5c3_Var5 = templ.NopComponent } ctx = templ.ClearChildren(ctx) - id := fmt.Sprintf("pdf-%d", pNr) templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 8, "