added Gleitzeit + Kurzarbeit closes #23
All checks were successful
Tests / Run Go Tests (push) Successful in 33s
All checks were successful
Tests / Run Go Tests (push) Successful in 33s
This commit is contained in:
@@ -9,7 +9,7 @@ import (
|
||||
type AbsenceType struct {
|
||||
Id int8
|
||||
Name string
|
||||
WorkTime float32
|
||||
WorkTime int8
|
||||
}
|
||||
|
||||
type Absence struct {
|
||||
|
||||
@@ -7,7 +7,6 @@ import (
|
||||
"fmt"
|
||||
"log"
|
||||
"net/url"
|
||||
"sort"
|
||||
"strconv"
|
||||
"time"
|
||||
)
|
||||
@@ -163,37 +162,6 @@ func (b *Booking) GetBookingsByCardID(card_uid string, tsFrom time.Time, tsTo ti
|
||||
return bookings, nil
|
||||
}
|
||||
|
||||
func (b *Booking) GetBookingsGrouped(card_uid string, tsFrom time.Time, tsTo time.Time) ([]WorkDay, error) {
|
||||
var grouped = make(map[string][]Booking)
|
||||
bookings, err := b.GetBookingsByCardID(card_uid, tsFrom, tsTo)
|
||||
if err != nil {
|
||||
log.Println("Failed to get bookings", err)
|
||||
return []WorkDay{}, nil
|
||||
}
|
||||
for _, booking := range bookings {
|
||||
day := booking.Timestamp.Truncate(24 * time.Hour)
|
||||
key := day.Format("2006-01-02")
|
||||
grouped[key] = append(grouped[key], booking)
|
||||
}
|
||||
|
||||
var result []WorkDay
|
||||
for key, bookings := range grouped {
|
||||
day, _ := time.Parse("2006-01-02", key)
|
||||
sort.Slice(bookings, func(i, j int) bool {
|
||||
return bookings[i].Timestamp.Before(bookings[j].Timestamp)
|
||||
})
|
||||
workDay := WorkDay{Day: day, Bookings: bookings}
|
||||
workDay.getWorkTime()
|
||||
result = append(result, workDay)
|
||||
}
|
||||
|
||||
sort.Slice(result, func(i, j int) bool {
|
||||
return result[i].Day.After(result[j].Day)
|
||||
})
|
||||
|
||||
return result, nil
|
||||
}
|
||||
|
||||
func (b Booking) Save() {
|
||||
qStr, err := DB.Prepare((`UPDATE "anwesenheit" SET "card_uid" = $2, "geraet_id" = $3, "check_in_out" = $4, "timestamp" = $5 WHERE "counter_id" = $1;`))
|
||||
if err != nil {
|
||||
|
||||
@@ -22,6 +22,9 @@ type DBFixture struct {
|
||||
|
||||
func SetupDBFixture(t *testing.T) *DBFixture {
|
||||
t.Helper()
|
||||
if helper.GetEnv("TEST_SQL", "false") != "true" {
|
||||
t.Skip("Skipping Test because TEST_SQL is not 'true'!")
|
||||
}
|
||||
|
||||
dbHost := helper.GetEnv("POSTGRES_HOST", "localhost")
|
||||
dbPort := helper.GetEnv("POSTGRES_PORT", "5433")
|
||||
|
||||
@@ -198,17 +198,6 @@ func (u *User) IsTeamLeader() bool {
|
||||
return len(team) > 0
|
||||
}
|
||||
|
||||
func (u *User) GetWeek(tsFrom time.Time) WorkWeek {
|
||||
var bookings []WorkDay
|
||||
weekStart := tsFrom.AddDate(0, 0, -1*int(tsFrom.Local().Weekday())-1)
|
||||
bookings, err := (*Booking).GetBookingsGrouped(nil, u.CardUID, weekStart, time.Now())
|
||||
if err != nil {
|
||||
log.Println("Error fetching bookings!")
|
||||
return WorkWeek{WorkDays: bookings}
|
||||
}
|
||||
return WorkWeek{WorkDays: bookings}
|
||||
}
|
||||
|
||||
// gets the first week, that needs to be submitted
|
||||
func (u *User) GetNextWeek() WorkWeek {
|
||||
var week WorkWeek
|
||||
|
||||
@@ -45,7 +45,7 @@ func NewWorkWeek(user User, tsMonday time.Time, populate bool) WorkWeek {
|
||||
}
|
||||
|
||||
func (w *WorkWeek) PopulateWithBookings(worktime time.Duration, overtime time.Duration) {
|
||||
w.WorkDays = GetWorkDays(w.User.CardUID, w.WeekStart, w.WeekStart.Add(7*24*time.Hour))
|
||||
w.WorkDays = GetWorkDays(w.User, w.WeekStart, w.WeekStart.Add(7*24*time.Hour))
|
||||
if absences, err := GetAbsencesByCardUID(w.User.CardUID, w.WeekStart, w.WeekStart.Add(7*24*time.Hour)); err == nil {
|
||||
w.Absences = absences
|
||||
} else {
|
||||
@@ -108,10 +108,11 @@ func (w *WorkWeek) aggregateWorkTime() time.Duration {
|
||||
for _, day := range w.WorkDays {
|
||||
workTime += day.workTime
|
||||
}
|
||||
for _, absences := range w.Absences {
|
||||
absenceWorkTime := absences.AbwesenheitTyp.WorkTime - (absences.AbwesenheitTyp.WorkTime - w.User.ArbeitszeitPerTag) // workTime Equivalent of Absence is capped at user Worktime per Day
|
||||
workTime += time.Duration(absenceWorkTime * float32(time.Hour)).Round(time.Minute)
|
||||
}
|
||||
// for _, absence := range w.Absences {
|
||||
// log.Println(absence)
|
||||
// absenceWorkTime := float32(8) // := absences.AbwesenheitTyp.WorkTime - (absences.AbwesenheitTyp.WorkTime - w.User.ArbeitszeitPerTag) // workTime Equivalent of Absence is capped at user Worktime per Day
|
||||
// workTime += time.Duration(absenceWorkTime * float32(time.Hour)).Round(time.Minute)
|
||||
// }
|
||||
return workTime
|
||||
}
|
||||
|
||||
|
||||
@@ -28,6 +28,7 @@ func TestNewWorkWeekNoPopulate(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestCheckStatus(t *testing.T) {
|
||||
SetupDBFixture(t)
|
||||
testWeek := SetupWorkWeekFixture(t)
|
||||
testCases := []struct {
|
||||
name string
|
||||
|
||||
Reference in New Issue
Block a user