diff --git a/src/main/java/org/tb/dailyreport/viewhelper/matrix/BookingDay.java b/src/main/java/org/tb/dailyreport/viewhelper/matrix/BookingDay.java index 3df5d3dd7..8daf1db02 100644 --- a/src/main/java/org/tb/dailyreport/viewhelper/matrix/BookingDay.java +++ b/src/main/java/org/tb/dailyreport/viewhelper/matrix/BookingDay.java @@ -44,7 +44,7 @@ public String getDurationString() { } public void addBooking(Duration duration, String taskdescription) { - this.duration = duration.plus(duration); + this.duration = this.duration.plus(duration); this.taskdescription += "\n" + taskdescription; bookingCount++; } diff --git a/src/main/java/org/tb/dailyreport/viewhelper/matrix/MatrixDayTotal.java b/src/main/java/org/tb/dailyreport/viewhelper/matrix/MatrixDayTotal.java index 455e31782..a2fe7ec13 100644 --- a/src/main/java/org/tb/dailyreport/viewhelper/matrix/MatrixDayTotal.java +++ b/src/main/java/org/tb/dailyreport/viewhelper/matrix/MatrixDayTotal.java @@ -65,16 +65,6 @@ public boolean isPartiallyNotWorked() { return workingDayType == WorkingDayType.PARTIALLY; } - public Duration getEffectiveTargetTime() { - if(workingDayType == WorkingDayType.PARTIALLY) { - return workingTime; - } - if(workingDayType == WorkingDayType.NOT_WORKED) { - return Duration.ZERO; - } - return contractWorkingTime; - } - public Duration getEffectiveOvertime() { if(workingDayType == WorkingDayType.PARTIALLY) { return contractWorkingTime.minus(workingTime); diff --git a/src/main/java/org/tb/dailyreport/viewhelper/matrix/MatrixHelper.java b/src/main/java/org/tb/dailyreport/viewhelper/matrix/MatrixHelper.java index aba491959..cfeb6a858 100644 --- a/src/main/java/org/tb/dailyreport/viewhelper/matrix/MatrixHelper.java +++ b/src/main/java/org/tb/dailyreport/viewhelper/matrix/MatrixHelper.java @@ -180,8 +180,8 @@ public Matrix createMatrix(LocalDate dateFirst, LocalDate dateLast, long employe Duration totalOvertimeCompensation = null; if(method == MATRIX_SPECIFICDATE_ALLORDERS_SPECIFICEMPLOYEES && employeecontract != null) { - //calculate dayhourstarget // TODO compare with OvertimeService - totalWorkingTimeTarget = dayTotals.stream().map(MatrixDayTotal::getEffectiveTargetTime).reduce(Duration.ZERO, Duration::plus); + //calculate target working time + totalWorkingTimeTarget = overtimeService.calculateWorkingTimeTarget(employeecontract.getId(), dateFirst, dateLast); // calculate overtime compensation totalOvertimeCompensation = overtimeService.calculateOvertimeCompensation(employeecontract.getId(), dateFirst, dateLast); diff --git a/src/main/java/org/tb/employee/service/OvertimeService.java b/src/main/java/org/tb/employee/service/OvertimeService.java index 9bb43d63d..da4d4a5e1 100644 --- a/src/main/java/org/tb/employee/service/OvertimeService.java +++ b/src/main/java/org/tb/employee/service/OvertimeService.java @@ -194,8 +194,8 @@ private boolean isStaticOvertimeAvailable(Employeecontract employeecontract) { return employeecontract.getReportAcceptanceDate() != null; } - private OvertimeInfo calculateOvertime(LocalDate requestedStart, LocalDate requestedEnd, Employeecontract employeecontract, boolean useOverTimeAdjustment) { - + public Duration calculateWorkingTimeTarget(long employeecontractId, LocalDate requestedStart, LocalDate requestedEnd) { + var employeecontract = employeecontractDAO.getEmployeeContractById(employeecontractId); final LocalDate start, end; // do not consider invalid(outside of the validity of the contract) days if (employeecontract.getValidFrom().isAfter(requestedStart)) { @@ -209,9 +209,8 @@ private OvertimeInfo calculateOvertime(LocalDate requestedStart, LocalDate reque end = requestedEnd; } if (end.isBefore(start)) { - return new OvertimeInfo(Duration.ZERO, Duration.ZERO, Duration.ZERO, Duration.ZERO, Duration.ZERO); + return Duration.ZERO; } - long numberOfWorkingDayHolidays = publicholidayDAO.getPublicHolidaysBetween(start, end) .stream() .map(Publicholiday::getRefdate) @@ -222,18 +221,38 @@ private OvertimeInfo calculateOvertime(LocalDate requestedStart, LocalDate reque var expectedWorkingDaysCount = DateUtils.getWorkingDayDistance(start, end); // substract holidays expectedWorkingDaysCount -= numberOfWorkingDayHolidays; - - // calculate working time var dailyWorkingTime = employeecontract.getDailyWorkingTime(); - var expectedWorkingTime = dailyWorkingTime.multipliedBy(expectedWorkingDaysCount); + var workingTimeTarget = dailyWorkingTime.multipliedBy(expectedWorkingDaysCount); + return workingTimeTarget; + } + + private OvertimeInfo calculateOvertime(LocalDate requestedStart, LocalDate requestedEnd, Employeecontract employeecontract, boolean useOverTimeAdjustment) { + + final LocalDate start, end; + // do not consider invalid(outside of the validity of the contract) days + if (employeecontract.getValidFrom().isAfter(requestedStart)) { + start = employeecontract.getValidFrom(); + } else { + start = requestedStart; + } + if (employeecontract.getValidUntil() != null && employeecontract.getValidUntil().isBefore(requestedEnd)) { + end = employeecontract.getValidUntil(); + } else { + end = requestedEnd; + } + if (end.isBefore(start)) { + return new OvertimeInfo(Duration.ZERO, Duration.ZERO, Duration.ZERO, Duration.ZERO, Duration.ZERO); + } + + var workingTimeTarget = calculateWorkingTimeTarget(employeecontract.getId(), requestedStart, requestedEnd); var actualWorkingTime = timereportDAO - .getTimereportsByDatesAndEmployeeContractId(employeecontract.getId(), start, end) + .getTimereportsByDatesAndEmployeeContractId(employeecontract.getId(), requestedStart, requestedEnd) .stream() .map(TimereportDTO::getDuration) .reduce(Duration.ZERO, Duration::plus); var overtimeAdjustment = Duration.ZERO; - Duration overtime = actualWorkingTime.minus(expectedWorkingTime); + Duration overtime = actualWorkingTime.minus(workingTimeTarget); if (useOverTimeAdjustment) { var overtimes = overtimeDAO.getOvertimesByEmployeeContractId(employeecontract.getId()); overtimeAdjustment = overtimes @@ -255,7 +274,7 @@ private OvertimeInfo calculateOvertime(LocalDate requestedStart, LocalDate reque overtime = overtime.plus(overtimeAdjustment); } - return new OvertimeInfo(actualWorkingTime, overtimeAdjustment, actualWorkingTime.plus(overtimeAdjustment), expectedWorkingTime, overtime); + return new OvertimeInfo(actualWorkingTime, overtimeAdjustment, actualWorkingTime.plus(overtimeAdjustment), workingTimeTarget, overtime); } // TODO introduce effective date in Overtime? diff --git a/src/main/webapp/dailyreport/showMatrix.jsp b/src/main/webapp/dailyreport/showMatrix.jsp index 2400292ab..985e8e62b 100644 --- a/src/main/webapp/dailyreport/showMatrix.jsp +++ b/src/main/webapp/dailyreport/showMatrix.jsp @@ -342,37 +342,11 @@