Vacaciones #57

Merged
jesus.pelaez merged 3 commits from Vacaciones into En-desarrollo 2024-10-18 17:35:13 +00:00
Showing only changes of commit 34940ff794 - Show all commits

View File

@ -20,6 +20,7 @@ import com.vaadin.flow.spring.annotation.SpringComponent;
import jakarta.annotation.security.PermitAll; import jakarta.annotation.security.PermitAll;
import org.springframework.context.annotation.Scope; import org.springframework.context.annotation.Scope;
import java.time.Year;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.UUID; import java.util.UUID;
@ -44,7 +45,6 @@ public class RequestEmployeeView extends Div implements HasUrlParameter<String>
public RequestEmployeeView(final TimeOffRequestService requestService, final EmployeeService employeeService) { public RequestEmployeeView(final TimeOffRequestService requestService, final EmployeeService employeeService) {
this.requestService = requestService; this.requestService = requestService;
this.employeeService = employeeService; this.employeeService = employeeService;
initializeView();
} }
private void initializeView() { private void initializeView() {
@ -97,9 +97,17 @@ public class RequestEmployeeView extends Div implements HasUrlParameter<String>
} }
private VerticalLayout createSummaryLayout() { private VerticalLayout createSummaryLayout() {
int totalVacations = 15; int currentYear = Year.now().getValue();
int totalTimeOff = 2; String yearCategory = "YEAR_" + currentYear;
int totalAvailableDays = totalVacations + totalTimeOff; 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( return new VerticalLayout(
new Span("TOTAL HOLIDAYS: " + totalVacations), new Span("TOTAL HOLIDAYS: " + totalVacations),
new Span("TOTAL TIME OFF: " + totalTimeOff), new Span("TOTAL TIME OFF: " + totalTimeOff),
@ -176,6 +184,7 @@ public class RequestEmployeeView extends Div implements HasUrlParameter<String>
requests = requestService.findRequestsByEmployeeId(employeeId); requests = requestService.findRequestsByEmployeeId(employeeId);
setViewTitle(employee.getFirstName() + " " + employee.getLastName(), employee.getTeam().getName()); setViewTitle(employee.getFirstName() + " " + employee.getLastName(), employee.getTeam().getName());
requestGrid.setItems(requests); requestGrid.setItems(requests);
initializeView();
} }
private void setViewTitle(final String employeeName, final String employeeTeam) { private void setViewTitle(final String employeeName, final String employeeTeam) {