CHANGE: added team page + working on function
This commit is contained in:
@@ -3,6 +3,7 @@ package models
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"time"
|
||||
)
|
||||
|
||||
type User struct {
|
||||
@@ -115,3 +116,27 @@ func (u *User) ChangePass(password, newPassword string) (bool, error) {
|
||||
}
|
||||
return true, nil
|
||||
}
|
||||
|
||||
func (u *User) GetTeamMembers() ([]User, error) {
|
||||
var teamMembers []User
|
||||
teamMembers = append(teamMembers, *u)
|
||||
return teamMembers, nil
|
||||
}
|
||||
|
||||
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
|
||||
return week
|
||||
|
||||
}
|
||||
|
||||
@@ -6,38 +6,38 @@ import (
|
||||
)
|
||||
|
||||
type WorkDay struct {
|
||||
Day time.Time
|
||||
Bookings []Booking
|
||||
workTime time.Duration
|
||||
Day time.Time
|
||||
Bookings []Booking
|
||||
workTime time.Duration
|
||||
pauseTime time.Duration
|
||||
}
|
||||
|
||||
// Gets the duration someone worked that day
|
||||
func (d *WorkDay) GetWorkTime() time.Duration{
|
||||
func (d *WorkDay) GetWorkTime() time.Duration {
|
||||
var workTime, pauseTime time.Duration
|
||||
var lastBooking Booking
|
||||
for _, booking := range d.Bookings{
|
||||
if booking.CheckInOut % 2 == 1 {
|
||||
for _, booking := range d.Bookings {
|
||||
if booking.CheckInOut%2 == 1 {
|
||||
if !lastBooking.Timestamp.IsZero() {
|
||||
pauseTime += booking.Timestamp.Sub(lastBooking.Timestamp)
|
||||
}
|
||||
}else {
|
||||
} else {
|
||||
workTime += booking.Timestamp.Sub(lastBooking.Timestamp)
|
||||
}
|
||||
lastBooking = booking
|
||||
}
|
||||
// checks if booking is today and has no gehen yet, so the time since last kommen booking is added to workTime
|
||||
if(d.Day.Day() == time.Now().Day() && len(d.Bookings) % 2 == 1){
|
||||
if d.Day.Day() == time.Now().Day() && len(d.Bookings)%2 == 1 {
|
||||
workTime += time.Since(lastBooking.Timestamp.Local())
|
||||
}
|
||||
|
||||
if workTime > 6 * time.Hour && pauseTime < 45 * time.Minute {
|
||||
if workTime < 9 * time.Hour && pauseTime < 30 * time.Minute {
|
||||
diff := 30 * time.Minute - pauseTime
|
||||
if workTime > 6*time.Hour && pauseTime < 45*time.Minute {
|
||||
if workTime < 9*time.Hour && pauseTime < 30*time.Minute {
|
||||
diff := 30*time.Minute - pauseTime
|
||||
workTime -= diff
|
||||
pauseTime += diff
|
||||
}else if pauseTime < 45 * time.Minute {
|
||||
diff := 45 * time.Minute - pauseTime
|
||||
} else if pauseTime < 45*time.Minute {
|
||||
diff := 45*time.Minute - pauseTime
|
||||
workTime -= diff
|
||||
pauseTime += diff
|
||||
}
|
||||
@@ -47,15 +47,15 @@ func (d *WorkDay) GetWorkTime() time.Duration{
|
||||
return workTime
|
||||
}
|
||||
|
||||
func formatDuration(d time.Duration) string{
|
||||
func formatDuration(d time.Duration) string {
|
||||
hours := int(d.Hours())
|
||||
minutes := int(d.Minutes()) % 60
|
||||
switch{
|
||||
case hours > 0:
|
||||
switch {
|
||||
case hours > 0:
|
||||
return fmt.Sprintf("%dh %dmin", hours, minutes)
|
||||
case minutes >0:
|
||||
case minutes > 0:
|
||||
return fmt.Sprintf("%dmin", minutes)
|
||||
default:
|
||||
default:
|
||||
return ""
|
||||
}
|
||||
}
|
||||
@@ -77,6 +77,6 @@ func (d *WorkDay) RequiresAction() bool {
|
||||
// returns a integer percentage of how much day has been worked of
|
||||
func (d *WorkDay) GetWorkDayProgress(user User) uint8 {
|
||||
defaultWorkTime := time.Duration(user.Arbeitszeit * float32(time.Hour))
|
||||
progress := (d.workTime.Seconds()/defaultWorkTime.Seconds())*100
|
||||
progress := (d.workTime.Seconds() / defaultWorkTime.Seconds()) * 100
|
||||
return uint8(progress)
|
||||
}
|
||||
|
||||
5
Backend/models/workWeek.go
Normal file
5
Backend/models/workWeek.go
Normal file
@@ -0,0 +1,5 @@
|
||||
package models
|
||||
|
||||
type WorkWeek struct {
|
||||
WorkDays []WorkDay
|
||||
}
|
||||
Reference in New Issue
Block a user