fix: weekbased calculation pdf report
with this change the time calculations for pdf reports should be better line with the reports send as "week_report"
This commit is contained in:
@@ -6,6 +6,7 @@ package models
|
||||
// this type is based on the "wochen_report" table
|
||||
|
||||
import (
|
||||
"arbeitszeitmessung/helper"
|
||||
"database/sql"
|
||||
"errors"
|
||||
"log"
|
||||
@@ -24,10 +25,12 @@ type WorkWeek struct {
|
||||
Days []IWorkDay
|
||||
User User
|
||||
WeekStart time.Time
|
||||
weekEnd time.Time
|
||||
Worktime time.Duration
|
||||
WorktimeVirtual time.Duration
|
||||
Overtime time.Duration
|
||||
Status WeekStatus
|
||||
WeekBase WorktimeBase
|
||||
}
|
||||
|
||||
type WeekStatus int8
|
||||
@@ -40,10 +43,15 @@ const (
|
||||
WeekStatusDifferences
|
||||
)
|
||||
|
||||
func NewWorkWeek(user User, tsMonday time.Time, populate bool) WorkWeek {
|
||||
func NewWorkWeekSimple(user User, tsMonday time.Time, populate bool) WorkWeek {
|
||||
return NewWorkWeek(user, tsMonday, tsMonday.Add(6*24*time.Hour), populate)
|
||||
}
|
||||
|
||||
func NewWorkWeek(user User, tsStart, tsEnd time.Time, populate bool) WorkWeek {
|
||||
var week WorkWeek = WorkWeek{
|
||||
User: user,
|
||||
WeekStart: tsMonday,
|
||||
WeekStart: tsStart,
|
||||
weekEnd: tsEnd,
|
||||
Status: WeekStatusNone,
|
||||
}
|
||||
if populate {
|
||||
@@ -53,13 +61,20 @@ func NewWorkWeek(user User, tsMonday time.Time, populate bool) WorkWeek {
|
||||
}
|
||||
|
||||
func (w *WorkWeek) PopulateWithDays(worktime time.Duration, overtime time.Duration) {
|
||||
slog.Debug("Populating Workweek for user", "user", w.User)
|
||||
slog.Debug("Got Days with overtime and worktime", slog.String("worktime", worktime.String()), slog.String("overtime", overtime.String()))
|
||||
w.Days = GetDays(w.User, w.WeekStart, w.WeekStart.Add(6*24*time.Hour), false)
|
||||
w.Days = GetDays(w.User, w.WeekStart, w.weekEnd, false)
|
||||
slog.Debug("Populating Workweek for user", "user", w.User.Name, "Days", lenWorkDays(w.Days), "Start", w.WeekStart, "End", w.weekEnd, "workdays", helper.GetWorkingDays(w.WeekStart, w.weekEnd))
|
||||
|
||||
if lenWorkDays(w.Days) == helper.GetWorkingDays(w.WeekStart, w.weekEnd) {
|
||||
w.WeekBase = WorktimeBaseWeek
|
||||
} else {
|
||||
w.WeekBase = WorktimeBaseDay
|
||||
}
|
||||
|
||||
for _, day := range w.Days {
|
||||
w.Worktime += day.GetWorktime(w.User, WorktimeBaseDay, false)
|
||||
w.WorktimeVirtual += day.GetWorktime(w.User, WorktimeBaseDay, true)
|
||||
w.Worktime += day.GetWorktime(w.User, w.WeekBase, false)
|
||||
w.WorktimeVirtual += day.GetWorktime(w.User, w.WeekBase, true)
|
||||
slog.Debug("Calculated Worktime", "Day", day.ToString(), "worktime", w.Worktime.String())
|
||||
}
|
||||
slog.Debug("Got worktime for user", "worktime", w.Worktime.String(), "virtualWorkTime", w.WorktimeVirtual.String())
|
||||
|
||||
@@ -79,6 +94,16 @@ func (w *WorkWeek) PopulateWithDays(worktime time.Duration, overtime time.Durati
|
||||
}
|
||||
}
|
||||
|
||||
func lenWorkDays(workDays []IWorkDay) int {
|
||||
var lenght int
|
||||
for _, day := range workDays {
|
||||
if !day.IsEmpty() || day.IsKurzArbeit() {
|
||||
lenght += 1
|
||||
}
|
||||
}
|
||||
return lenght
|
||||
}
|
||||
|
||||
func (w *WorkWeek) CheckStatus() WeekStatus {
|
||||
if w.Status != WeekStatusNone {
|
||||
return w.Status
|
||||
|
||||
Reference in New Issue
Block a user