From 67447cd943b5230159d73e0ad5777cddbdd15c57 Mon Sep 17 00:00:00 2001 From: Tobias Meindl Date: Mon, 3 Jun 2024 09:59:17 +0200 Subject: [PATCH] fix a bug where total working times always returned total billable hours --- .../mega/service/helper/WorkingTimeUtil.java | 12 +++- .../impl/MonthlyReportServiceImpl.java | 2 +- .../monthlyreport/WorkingTimeUtilTest.java | 60 +++++++++++++++++-- 3 files changed, 66 insertions(+), 8 deletions(-) diff --git a/src/main/java/com/gepardec/mega/service/helper/WorkingTimeUtil.java b/src/main/java/com/gepardec/mega/service/helper/WorkingTimeUtil.java index 61fae8e51..41fa7c160 100644 --- a/src/main/java/com/gepardec/mega/service/helper/WorkingTimeUtil.java +++ b/src/main/java/com/gepardec/mega/service/helper/WorkingTimeUtil.java @@ -4,6 +4,7 @@ import com.gepardec.mega.domain.model.AbsenceTime; import com.gepardec.mega.domain.model.Employee; import com.gepardec.mega.domain.model.ProjectTime; +import com.gepardec.mega.domain.model.monthlyreport.ProjectEntry; import com.gepardec.mega.domain.utils.DateUtils; import jakarta.annotation.Nonnull; import jakarta.enterprise.context.ApplicationScoped; @@ -49,8 +50,8 @@ public String getBillableTimesForEmployee(@Nonnull List projektzeit } - public String getTotalWorkingTimeForEmployee(@Nonnull List projektzeitTypeList, @Nonnull Employee employee) { - Duration totalWorkingTimeForEmployee = getWorkingTimesForEmployee(projektzeitTypeList, employee, $ -> true); + public String getTotalWorkingTimeForEmployee(@Nonnull List projektzeitTypeList, @Nonnull Employee employee) { + Duration totalWorkingTimeForEmployee = getWorkingTimes(projektzeitTypeList); return DurationFormatUtils.formatDuration(totalWorkingTimeForEmployee.toMillis(), BILLABLE_TIME_FORMAT); } @@ -106,6 +107,13 @@ private Duration getWorkingTimesForEmployee(List projektzeitTypeLis .reduce(Duration.ZERO, Duration::plus); } + private Duration getWorkingTimes(List projectEntries) { + return projectEntries.stream() + .map(ProjectEntry::getDurationInHours) + .map(hours -> Duration.ofMinutes(Double.valueOf(hours * 60).longValue())) + .reduce(Duration.ZERO, Duration::plus); + } + // Calculator functions for AbsenceTime public int getAbsenceTimesForEmployee(@Nonnull List fehlZeitTypeList, String absenceType, LocalDate date) { diff --git a/src/main/java/com/gepardec/mega/service/impl/MonthlyReportServiceImpl.java b/src/main/java/com/gepardec/mega/service/impl/MonthlyReportServiceImpl.java index f1c55b495..0c0aa1166 100644 --- a/src/main/java/com/gepardec/mega/service/impl/MonthlyReportServiceImpl.java +++ b/src/main/java/com/gepardec/mega/service/impl/MonthlyReportServiceImpl.java @@ -197,7 +197,7 @@ private MonthlyReport buildMonthlyReport( .employeeProgresses(pmProgressDtos) .otherChecksDone(isMonthCompletedForEmployee(employee, date)) .billableTime(workingTimeUtil.getBillableTimesForEmployee(billableEntries, employee)) - .totalWorkingTime(workingTimeUtil.getTotalWorkingTimeForEmployee(billableEntries, employee)) + .totalWorkingTime(workingTimeUtil.getTotalWorkingTimeForEmployee(projectEntries, employee)) .compensatoryDays(workingTimeUtil.getAbsenceTimesForEmployee(absenceEntries, AbsenceType.COMPENSATORY_DAYS.getAbsenceName(), date)) .homeofficeDays(workingTimeUtil.getAbsenceTimesForEmployee(absenceEntries, AbsenceType.HOME_OFFICE_DAYS.getAbsenceName(), date)) .vacationDays(workingTimeUtil.getAbsenceTimesForEmployee(absenceEntries, AbsenceType.VACATION_DAYS.getAbsenceName(), date)) diff --git a/src/test/java/com/gepardec/mega/service/impl/monthlyreport/WorkingTimeUtilTest.java b/src/test/java/com/gepardec/mega/service/impl/monthlyreport/WorkingTimeUtilTest.java index 5e7f68571..0bd84e337 100644 --- a/src/test/java/com/gepardec/mega/service/impl/monthlyreport/WorkingTimeUtilTest.java +++ b/src/test/java/com/gepardec/mega/service/impl/monthlyreport/WorkingTimeUtilTest.java @@ -2,6 +2,11 @@ import com.gepardec.mega.domain.model.*; +import com.gepardec.mega.domain.model.monthlyreport.JourneyTimeEntry; +import com.gepardec.mega.domain.model.monthlyreport.ProjectEntry; +import com.gepardec.mega.domain.model.monthlyreport.ProjectTimeEntry; +import com.gepardec.mega.domain.model.monthlyreport.Task; +import com.gepardec.mega.domain.model.monthlyreport.WorkingLocation; import com.gepardec.mega.service.helper.WorkingTimeUtil; import io.quarkus.test.junit.QuarkusTest; import jakarta.inject.Inject; @@ -10,6 +15,7 @@ import java.time.DayOfWeek; import java.time.Duration; import java.time.LocalDate; +import java.time.LocalDateTime; import java.util.ArrayList; import java.util.List; import java.util.Map; @@ -42,12 +48,11 @@ void getBillableTimesForEmployeeTest() { } @Test - void getTotalWorkingTimeForEmployee() { + void getTotalWorkingTimes_ProjectTime(){ Employee employee = createEmployee().build(); - - List projectTimes = returnNormalDayProjectTimes(5); - String internalTimesForEmployee = workingTimeUtil.getTotalWorkingTimeForEmployee(projectTimes, employee); - assertThat(internalTimesForEmployee).isEqualTo("40:00"); + List projectEntries = getProjectentries(); + String totalWorkingTimes = workingTimeUtil.getTotalWorkingTimeForEmployee(projectEntries, employee); + assertThat(totalWorkingTimes).isEqualTo("24:15"); } @Test @@ -175,4 +180,49 @@ private Employee.Builder createEmployee() { Map.entry(DayOfWeek.SUNDAY, Duration.ofHours(0))) ); } + + private List getProjectentries() { + return List.of( + ProjectTimeEntry.builder() + .fromTime(LocalDateTime.of(2023, 11, 1, 8, 0)) + .toTime(LocalDateTime.of(2023, 11, 1, 12, 15)) + .task(Task.BEARBEITEN) + .workingLocation(WorkingLocation.MAIN) + .process("1") + .build(), + ProjectTimeEntry.builder() + .fromTime(LocalDateTime.of(2023, 11, 1, 13, 0)) + .toTime(LocalDateTime.of(2023, 11, 1, 17, 0)) + .task(Task.BEARBEITEN) + .workingLocation(WorkingLocation.MAIN) + .process("1") + .build(), + ProjectTimeEntry.builder() + .fromTime(LocalDateTime.of(2023, 11, 2, 8, 0)) + .toTime(LocalDateTime.of(2023, 11, 2, 12, 0)) + .task(Task.BEARBEITEN) + .workingLocation(WorkingLocation.MAIN) + .process("1") + .build(), + ProjectTimeEntry.builder() + .fromTime(LocalDateTime.of(2023, 11, 2, 13, 0)) + .toTime(LocalDateTime.of(2023, 11, 2, 17, 0)) + .task(Task.BEARBEITEN) + .workingLocation(WorkingLocation.MAIN) + .process("1") + .build(), + JourneyTimeEntry.builder() + .fromTime(LocalDateTime.of(2023, 11, 3, 8, 0)) + .toTime(LocalDateTime.of(2023, 11, 3, 12, 0)) + .task(Task.REISEN) + .workingLocation(WorkingLocation.MAIN) + .build(), + JourneyTimeEntry.builder() + .fromTime(LocalDateTime.of(2023, 11, 3, 13, 0)) + .toTime(LocalDateTime.of(2023, 11, 3, 17, 0)) + .task(Task.REISEN) + .workingLocation(WorkingLocation.MAIN) + .build() + ); + } }