/time now also uses workDay instead of grouped booking --> outsourcing
to sql
This commit is contained in:
@@ -136,7 +136,7 @@ func (b *Booking) GetBookingsGrouped(card_uid string, tsFrom time.Time, tsTo tim
|
||||
return bookings[i].Timestamp.Before(bookings[j].Timestamp)
|
||||
})
|
||||
workDay := WorkDay{Day: day, Bookings: bookings}
|
||||
workDay.GetWorkTime()
|
||||
workDay.getWorkTime()
|
||||
result = append(result, workDay)
|
||||
}
|
||||
|
||||
@@ -162,10 +162,14 @@ func (b Booking) Save() {
|
||||
|
||||
func (b *Booking) GetBookingType() string {
|
||||
switch b.CheckInOut {
|
||||
case 1, 3: //manuelle Änderung
|
||||
case 1: //manuelle Änderung
|
||||
return "kommen"
|
||||
case 2, 4: //manuelle Änderung
|
||||
case 3:
|
||||
return "kommen manuell"
|
||||
case 2: //manuelle Änderung
|
||||
return "gehen"
|
||||
case 4:
|
||||
return "gehen manuell"
|
||||
case 255:
|
||||
return "abgemeldet"
|
||||
default:
|
||||
|
||||
@@ -89,13 +89,18 @@ func (d *WorkDay) GetWorkDays(card_uid string, tsFrom, tsTo time.Time) []WorkDay
|
||||
}
|
||||
workDay.workTime = time.Duration(workSec * float64(time.Second))
|
||||
workDay.pauseTime = time.Duration(pauseSec * float64(time.Second))
|
||||
workDay.calcPauseTime()
|
||||
|
||||
err = json.Unmarshal(bookings, &workDay.Bookings)
|
||||
if err != nil {
|
||||
log.Println("Error parsing bookings JSON!", err)
|
||||
return nil
|
||||
}
|
||||
|
||||
if workDay.Day.Equal(time.Now().Truncate(24 * time.Hour)) {
|
||||
workDay.getWorkTime()
|
||||
} else {
|
||||
workDay.calcPauseTime()
|
||||
}
|
||||
|
||||
workDays = append(workDays, workDay)
|
||||
}
|
||||
if err = rows.Err(); err != nil {
|
||||
@@ -119,7 +124,7 @@ func (d *WorkDay) calcPauseTime() {
|
||||
}
|
||||
|
||||
// Gets the duration someone worked that day
|
||||
func (d *WorkDay) GetWorkTime() {
|
||||
func (d *WorkDay) getWorkTime() {
|
||||
var workTime, pauseTime time.Duration
|
||||
var lastBooking Booking
|
||||
for _, booking := range d.Bookings {
|
||||
@@ -142,6 +147,7 @@ func (d *WorkDay) GetWorkTime() {
|
||||
d.calcPauseTime()
|
||||
}
|
||||
|
||||
// Converts duration to string
|
||||
func formatDuration(d time.Duration) string {
|
||||
hours := int(d.Abs().Hours())
|
||||
minutes := int(d.Abs().Minutes()) % 60
|
||||
@@ -155,9 +161,6 @@ func formatDuration(d time.Duration) string {
|
||||
}
|
||||
}
|
||||
|
||||
// Converts duration to string and replaces 0s with in
|
||||
//
|
||||
// -> output xhxmin
|
||||
func (d *WorkDay) GetWorkTimeString() (string, string) {
|
||||
workString := formatDuration(d.workTime)
|
||||
pauseString := formatDuration(d.pauseTime)
|
||||
|
||||
Reference in New Issue
Block a user