Skip to content

Commit

Permalink
fix a bug where total working times always returned total billable hours
Browse files Browse the repository at this point in the history
  • Loading branch information
tomeindl committed Jun 3, 2024
1 parent 22502f5 commit 67447cd
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -49,8 +50,8 @@ public String getBillableTimesForEmployee(@Nonnull List<ProjectTime> projektzeit

}

public String getTotalWorkingTimeForEmployee(@Nonnull List<ProjectTime> projektzeitTypeList, @Nonnull Employee employee) {
Duration totalWorkingTimeForEmployee = getWorkingTimesForEmployee(projektzeitTypeList, employee, $ -> true);
public String getTotalWorkingTimeForEmployee(@Nonnull List<ProjectEntry> projektzeitTypeList, @Nonnull Employee employee) {
Duration totalWorkingTimeForEmployee = getWorkingTimes(projektzeitTypeList);
return DurationFormatUtils.formatDuration(totalWorkingTimeForEmployee.toMillis(), BILLABLE_TIME_FORMAT);
}

Expand Down Expand Up @@ -106,6 +107,13 @@ private Duration getWorkingTimesForEmployee(List<ProjectTime> projektzeitTypeLis
.reduce(Duration.ZERO, Duration::plus);
}

private Duration getWorkingTimes(List<ProjectEntry> 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<AbsenceTime> fehlZeitTypeList, String absenceType, LocalDate date) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -42,12 +48,11 @@ void getBillableTimesForEmployeeTest() {
}

@Test
void getTotalWorkingTimeForEmployee() {
void getTotalWorkingTimes_ProjectTime(){
Employee employee = createEmployee().build();

List<ProjectTime> projectTimes = returnNormalDayProjectTimes(5);
String internalTimesForEmployee = workingTimeUtil.getTotalWorkingTimeForEmployee(projectTimes, employee);
assertThat(internalTimesForEmployee).isEqualTo("40:00");
List<ProjectEntry> projectEntries = getProjectentries();
String totalWorkingTimes = workingTimeUtil.getTotalWorkingTimeForEmployee(projectEntries, employee);
assertThat(totalWorkingTimes).isEqualTo("24:15");
}

@Test
Expand Down Expand Up @@ -175,4 +180,49 @@ private Employee.Builder createEmployee() {
Map.entry(DayOfWeek.SUNDAY, Duration.ofHours(0)))
);
}

private List<ProjectEntry> 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()
);
}
}

0 comments on commit 67447cd

Please sign in to comment.