working compound days + working public holidays
Some checks failed
Tests / Run Go Tests (push) Failing after 44s
Some checks failed
Tests / Run Go Tests (push) Failing after 44s
This commit is contained in:
@@ -22,6 +22,11 @@ type Absence struct {
|
||||
DateTo time.Time
|
||||
}
|
||||
|
||||
// IsEmpty implements [IWorkDay].
|
||||
func (a *Absence) IsEmpty() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
func NewAbsence(card_uid string, abwesenheit_typ int, datum time.Time) (Absence, error) {
|
||||
if abwesenheit_typ < 0 {
|
||||
return Absence{
|
||||
@@ -95,7 +100,7 @@ func (a *Absence) GetTimes(u User, base WorktimeBase, includeKurzarbeit bool) (w
|
||||
}
|
||||
|
||||
func (a *Absence) ToString() string {
|
||||
return "Abwesenheit"
|
||||
return a.AbwesenheitTyp.Name
|
||||
}
|
||||
|
||||
func (a *Absence) IsWorkDay() bool {
|
||||
@@ -107,7 +112,7 @@ func (a *Absence) IsKurzArbeit() bool {
|
||||
}
|
||||
|
||||
func (a *Absence) GetDayProgress(u User) int8 {
|
||||
return 100
|
||||
return a.AbwesenheitTyp.WorkTime
|
||||
}
|
||||
|
||||
func (a *Absence) RequiresAction() bool {
|
||||
|
||||
105
Backend/models/compoundDay.go
Normal file
105
Backend/models/compoundDay.go
Normal file
@@ -0,0 +1,105 @@
|
||||
package models
|
||||
|
||||
import (
|
||||
"log/slog"
|
||||
"time"
|
||||
)
|
||||
|
||||
type CompoundDay struct {
|
||||
Day time.Time
|
||||
DayParts []IWorkDay
|
||||
}
|
||||
|
||||
func NewCompondDay(date time.Time, dayParts ...IWorkDay) *CompoundDay {
|
||||
return &CompoundDay{Day: date, DayParts: dayParts}
|
||||
}
|
||||
|
||||
func (c *CompoundDay) AddDayPart(dayPart IWorkDay) {
|
||||
c.DayParts = append(c.DayParts, dayPart)
|
||||
}
|
||||
|
||||
func (c *CompoundDay) GetWorkDay() WorkDay {
|
||||
workday, ok := c.DayParts[0].(*WorkDay)
|
||||
if ok {
|
||||
return *workday
|
||||
}
|
||||
return WorkDay{}
|
||||
}
|
||||
|
||||
// IsEmpty implements [IWorkDay].
|
||||
func (c *CompoundDay) IsEmpty() bool {
|
||||
return len(c.DayParts) > 0
|
||||
}
|
||||
|
||||
// Date implements [IWorkDay].
|
||||
func (c *CompoundDay) Date() time.Time {
|
||||
return c.Day
|
||||
}
|
||||
|
||||
// GetDayProgress implements [IWorkDay].
|
||||
func (c *CompoundDay) GetDayProgress(u User) int8 {
|
||||
var dayProcess int8
|
||||
for _, day := range c.DayParts {
|
||||
dayProcess += day.GetDayProgress(u)
|
||||
}
|
||||
return dayProcess
|
||||
}
|
||||
|
||||
// GetOvertime implements [IWorkDay].
|
||||
func (c *CompoundDay) GetOvertime(u User, base WorktimeBase, includeKurzarbeit bool) time.Duration {
|
||||
|
||||
var overtime time.Duration
|
||||
for _, day := range c.DayParts {
|
||||
overtime += day.GetOvertime(u, base, includeKurzarbeit)
|
||||
}
|
||||
return overtime
|
||||
}
|
||||
|
||||
// GetPausetime implements [IWorkDay].
|
||||
func (c *CompoundDay) GetPausetime(u User, base WorktimeBase, includeKurzarbeit bool) time.Duration {
|
||||
var pausetime time.Duration
|
||||
for _, day := range c.DayParts {
|
||||
pausetime += day.GetPausetime(u, base, includeKurzarbeit)
|
||||
}
|
||||
return pausetime
|
||||
}
|
||||
|
||||
// GetTimes implements [IWorkDay].
|
||||
func (c *CompoundDay) GetTimes(u User, base WorktimeBase, includeKurzarbeit bool) (work time.Duration, pause time.Duration, overtime time.Duration) {
|
||||
return c.GetWorktime(u, base, includeKurzarbeit), c.GetPausetime(u, base, includeKurzarbeit), c.GetOvertime(u, base, includeKurzarbeit)
|
||||
}
|
||||
|
||||
// GetWorktime implements [IWorkDay].
|
||||
func (c *CompoundDay) GetWorktime(u User, base WorktimeBase, includeKurzarbeit bool) time.Duration {
|
||||
var worktime time.Duration
|
||||
for _, day := range c.DayParts {
|
||||
worktime += day.GetWorktime(u, base, includeKurzarbeit)
|
||||
slog.Info("Calc worktime for day", "day", day, "worktime", worktime.String())
|
||||
}
|
||||
return worktime
|
||||
}
|
||||
|
||||
// IsKurzArbeit implements [IWorkDay].
|
||||
func (c *CompoundDay) IsKurzArbeit() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
// IsWorkDay implements [IWorkDay].
|
||||
func (c *CompoundDay) IsWorkDay() bool {
|
||||
return true
|
||||
}
|
||||
|
||||
// RequiresAction implements [IWorkDay].
|
||||
func (c *CompoundDay) RequiresAction() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
// ToString implements [IWorkDay].
|
||||
func (c *CompoundDay) ToString() string {
|
||||
return "Compound Day"
|
||||
}
|
||||
|
||||
// Type implements [IWorkDay].
|
||||
func (c *CompoundDay) Type() DayType {
|
||||
return DayTypeCompound
|
||||
}
|
||||
@@ -1,8 +1,6 @@
|
||||
package models
|
||||
|
||||
import (
|
||||
"arbeitszeitmessung/helper"
|
||||
"log"
|
||||
"log/slog"
|
||||
"time"
|
||||
)
|
||||
@@ -19,57 +17,73 @@ type IWorkDay interface {
|
||||
GetPausetime(User, WorktimeBase, bool) time.Duration
|
||||
GetTimes(User, WorktimeBase, bool) (work, pause, overtime time.Duration)
|
||||
GetOvertime(User, WorktimeBase, bool) time.Duration
|
||||
IsEmpty() bool
|
||||
}
|
||||
|
||||
type DayType int
|
||||
|
||||
const (
|
||||
DayTypeWorkday DayType = 1
|
||||
DayTypeAbsence DayType = 2
|
||||
DayTypeHoliday DayType = 3
|
||||
DayTypeWorkday DayType = 1
|
||||
DayTypeAbsence DayType = 2
|
||||
DayTypeHoliday DayType = 3
|
||||
DayTypeCompound DayType = 4
|
||||
)
|
||||
|
||||
func GetDays(user User, tsFrom, tsTo time.Time, orderedForward bool) []IWorkDay {
|
||||
var allDays map[string]IWorkDay = make(map[string]IWorkDay)
|
||||
|
||||
for _, day := range GetWorkDays(user, tsFrom, tsTo) {
|
||||
allDays[day.Date().Format(time.DateOnly)] = &day
|
||||
}
|
||||
workdays := GetWorkDays(user, tsFrom, tsTo)
|
||||
absences, err := GetAbsencesByCardUID(user.CardUID, tsFrom, tsTo)
|
||||
if err != nil {
|
||||
log.Println("Error gettings absences for all Days!", err)
|
||||
slog.Warn("Error gettings absences!", slog.Any("Error", err))
|
||||
return nil
|
||||
}
|
||||
holidays, err := GetHolidaysFromTo(tsFrom, tsTo)
|
||||
if err != nil {
|
||||
slog.Warn("Error getting holidays from DB!", slog.Any("Error", err))
|
||||
slog.Warn("Error getting holidays!", slog.Any("Error", err))
|
||||
return nil
|
||||
}
|
||||
for _, day := range absences {
|
||||
if helper.IsWeekend(day.Date()) {
|
||||
|
||||
for _, day := range workdays {
|
||||
allDays[day.Date().Format(time.DateOnly)] = &day
|
||||
}
|
||||
|
||||
for _, absentDay := range absences {
|
||||
// Kurzarbeit should be integrated in workday
|
||||
existingDay, ok := allDays[absentDay.Date().Format(time.DateOnly)]
|
||||
if !ok {
|
||||
allDays[absentDay.Date().Format(time.DateOnly)] = &absentDay
|
||||
continue
|
||||
}
|
||||
// Absence should be integrated in workday
|
||||
switch {
|
||||
case day.AbwesenheitTyp.WorkTime < 0:
|
||||
if workDay, ok := allDays[day.Date().Format(time.DateOnly)].(*WorkDay); ok {
|
||||
case absentDay.AbwesenheitTyp.WorkTime < 0:
|
||||
if workDay, ok := allDays[absentDay.Date().Format(time.DateOnly)].(*WorkDay); ok {
|
||||
workDay.kurzArbeit = true
|
||||
workDay.kurzArbeitAbsence = day
|
||||
}
|
||||
case day.AbwesenheitTyp.WorkTime < 100:
|
||||
if workDay, ok := allDays[day.Date().Format(time.DateOnly)].(*WorkDay); ok {
|
||||
workDay.worktimeAbsece = day
|
||||
workDay.kurzArbeitAbsence = absentDay
|
||||
}
|
||||
case !existingDay.IsEmpty():
|
||||
allDays[absentDay.Date().Format(time.DateOnly)] = NewCompondDay(absentDay.Date(), existingDay, &absentDay)
|
||||
default:
|
||||
allDays[day.Date().Format(time.DateOnly)] = &day
|
||||
allDays[absentDay.Date().Format(time.DateOnly)] = &absentDay
|
||||
}
|
||||
}
|
||||
|
||||
for _, day := range holidays {
|
||||
if helper.IsWeekend(day.Date()) {
|
||||
for _, holiday := range holidays {
|
||||
existingDay, ok := allDays[holiday.Date().Format(time.DateOnly)]
|
||||
if !ok {
|
||||
allDays[holiday.Date().Format(time.DateOnly)] = &holiday
|
||||
continue
|
||||
}
|
||||
allDays[day.Date().Format(time.DateOnly)] = &day
|
||||
slog.Debug("Logging Holiday: ", slog.String("HolidayName", allDays[day.Date().Format(time.DateOnly)].ToString()), slog.Any("Overtime", day.GetOvertime(user, WorktimeBaseDay, false).String()), "wokrtie", float32(day.worktime)/100)
|
||||
slog.Info("Existing Day", "day", existingDay)
|
||||
switch {
|
||||
case existingDay.Type() == DayTypeCompound:
|
||||
allDays[holiday.Date().Format(time.DateOnly)].(*CompoundDay).AddDayPart(&holiday)
|
||||
case existingDay.Type() != DayTypeCompound && !existingDay.IsEmpty():
|
||||
allDays[holiday.Date().Format(time.DateOnly)] = NewCompondDay(holiday.Date(), existingDay, &holiday)
|
||||
default:
|
||||
allDays[holiday.Date().Format(time.DateOnly)] = &holiday
|
||||
}
|
||||
slog.Debug("Logging Holiday: ", slog.String("HolidayName", allDays[holiday.Date().Format(time.DateOnly)].ToString()), slog.Any("Overtime", holiday.GetOvertime(user, WorktimeBaseDay, false).String()), "wokrtie", float32(holiday.worktime)/100)
|
||||
}
|
||||
|
||||
sortedDays := sortDays(allDays, orderedForward)
|
||||
|
||||
@@ -14,6 +14,11 @@ type PublicHoliday struct {
|
||||
worktime int8
|
||||
}
|
||||
|
||||
// IsEmpty implements [IWorkDay].
|
||||
func (p *PublicHoliday) IsEmpty() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
func NewHolidayFromFeiertag(f feiertage.Feiertag) PublicHoliday {
|
||||
return PublicHoliday{
|
||||
Feiertag: f,
|
||||
@@ -106,9 +111,9 @@ func (p *PublicHoliday) RequiresAction() bool {
|
||||
func (p *PublicHoliday) GetWorktime(u User, base WorktimeBase, includeKurzarbeit bool) time.Duration {
|
||||
switch base {
|
||||
case WorktimeBaseDay:
|
||||
return u.ArbeitszeitProTagFrac(float32(p.worktime / 100))
|
||||
return u.ArbeitszeitProTagFrac(float32(p.worktime) / 100)
|
||||
case WorktimeBaseWeek:
|
||||
return u.ArbeitszeitProWocheFrac(float32(p.worktime/100) * 0.2)
|
||||
return u.ArbeitszeitProWocheFrac(float32(p.worktime) / 500)
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
@@ -23,6 +23,11 @@ type WorkDay struct {
|
||||
worktimeAbsece Absence
|
||||
}
|
||||
|
||||
// IsEmpty implements [IWorkDay].
|
||||
func (d *WorkDay) IsEmpty() bool {
|
||||
return len(d.Bookings) == 0
|
||||
}
|
||||
|
||||
type WorktimeBase int
|
||||
|
||||
const (
|
||||
|
||||
Reference in New Issue
Block a user