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:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user