Skip to content

Commit

Permalink
#405 fix calculation of overtime
Browse files Browse the repository at this point in the history
  • Loading branch information
KlausRicharz committed Aug 20, 2024
1 parent 9ba7012 commit 30ce880
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 54 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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++;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
39 changes: 29 additions & 10 deletions src/main/java/org/tb/employee/service/OvertimeService.java
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand All @@ -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)
Expand All @@ -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
Expand All @@ -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?
Expand Down
36 changes: 5 additions & 31 deletions src/main/webapp/dailyreport/showMatrix.jsp
Original file line number Diff line number Diff line change
Expand Up @@ -342,37 +342,11 @@
<td class="matrix"><c:out value="${matrixline.customOrder.sign}"></c:out><br><c:out value="${matrixline.subOrder.sign}" /></td>
<td class="matrix"><c:out value="${matrixline.customOrder.shortdescription}"></c:out><br><c:out value="${matrixline.subOrder.shortdescription}" /></td>
<c:forEach var="bookingday" items="${matrixline.bookingDays}">
<c:if test="${bookingday.satSun==true}">
<c:if test="${bookingday.publicHoliday==true}">
<td title="${fn:escapeXml(bookingday.taskdescription)}"
class="matrix" align="right"
style="font-size: 7pt; border: 1px black solid; background-color: c1c1c1;">
</c:if>
<c:if test="${bookingday.publicHoliday==false}">
<td title="${fn:escapeXml(bookingday.taskdescription)}"
class="matrix" align="right"
style="font-size: 7pt; border: 1px black solid; background-color: lightgrey;">
</c:if>
</c:if>
<c:if test="${bookingday.satSun==false}">
<c:if test="${bookingday.publicHoliday==true}">
<td title="${fn:escapeXml(bookingday.taskdescription)}"
class="matrix" align="right"
style="font-size: 7pt; border: 1px black solid; background-color: c1c1c1;">
</c:if>
<c:if test="${bookingday.publicHoliday==false}">
<td title="${fn:escapeXml(bookingday.taskdescription)}"
class="matrix" align="right"
style="font-size: 7pt; border: 1px black solid;">
</c:if>
</c:if>
<c:if test="${bookingday.bookingCount eq 0}">
&nbsp;
</c:if>
<c:if test="${bookingday.bookingCount gt 0}">
<c:out value="${bookingday.durationString}" />
</c:if>
<td title="${fn:escapeXml(bookingday.taskdescription)}"
class="matrix${matrixdaytotal.publicHoliday ? ' holiday' : (matrixdaytotal.satSun ? ' weekend' : '')}"
align="right"
style="font-size: 7pt; border: 1px black solid;">
<c:out value="${bookingday.bookingCount gt 0 ? bookingday.durationString : ' '}" />
</td>
</c:forEach>
<td class="matrix" align="right"><c:out value="${matrixline.totalString}"></c:out></td>
Expand Down

0 comments on commit 30ce880

Please sign in to comment.