diff --git a/src/main/java/com/primefactorsolutions/views/RequestEmployeeView.java b/src/main/java/com/primefactorsolutions/views/RequestEmployeeView.java index 8af34ea..95c9592 100644 --- a/src/main/java/com/primefactorsolutions/views/RequestEmployeeView.java +++ b/src/main/java/com/primefactorsolutions/views/RequestEmployeeView.java @@ -20,6 +20,7 @@ import com.vaadin.flow.spring.annotation.SpringComponent; import jakarta.annotation.security.PermitAll; import org.springframework.context.annotation.Scope; +import java.time.Year; import java.util.Collections; import java.util.List; import java.util.UUID; @@ -44,7 +45,6 @@ public class RequestEmployeeView extends Div implements HasUrlParameter public RequestEmployeeView(final TimeOffRequestService requestService, final EmployeeService employeeService) { this.requestService = requestService; this.employeeService = employeeService; - initializeView(); } private void initializeView() { @@ -97,9 +97,17 @@ public class RequestEmployeeView extends Div implements HasUrlParameter } private VerticalLayout createSummaryLayout() { - int totalVacations = 15; - int totalTimeOff = 2; - int totalAvailableDays = totalVacations + totalTimeOff; + int currentYear = Year.now().getValue(); + String yearCategory = "YEAR_" + currentYear; + double totalVacations = requests.stream() + .filter(req -> req.getCategory().name().equals(yearCategory)) + .mapToDouble(TimeOffRequest::getAvailableDays) + .sum(); + double totalTimeOff = requests.stream() + .filter(req -> !req.getCategory().name().startsWith("YEAR")) + .mapToDouble(TimeOffRequest::getDaysBalance) + .sum(); + double totalAvailableDays = totalVacations + totalTimeOff; return new VerticalLayout( new Span("TOTAL HOLIDAYS: " + totalVacations), new Span("TOTAL TIME OFF: " + totalTimeOff), @@ -176,6 +184,7 @@ public class RequestEmployeeView extends Div implements HasUrlParameter requests = requestService.findRequestsByEmployeeId(employeeId); setViewTitle(employee.getFirstName() + " " + employee.getLastName(), employee.getTeam().getName()); requestGrid.setItems(requests); + initializeView(); } private void setViewTitle(final String employeeName, final String employeeTeam) {