refactor timeoff summary
All checks were successful
Builder / Build-Project (push) Successful in 2m53s
All checks were successful
Builder / Build-Project (push) Successful in 2m53s
This commit is contained in:
parent
b57f5a7f2c
commit
118813c8e4
Binary file not shown.
@ -1,7 +1,8 @@
|
|||||||
package com.primefactorsolutions.views;
|
package com.primefactorsolutions.views;
|
||||||
|
|
||||||
import com.primefactorsolutions.model.Employee;
|
import com.primefactorsolutions.model.Employee;
|
||||||
import com.primefactorsolutions.views.admin.EmployeesListView;
|
import com.primefactorsolutions.views.employee.DocumentsListView;
|
||||||
|
import com.primefactorsolutions.views.employee.EmployeesListView;
|
||||||
import com.primefactorsolutions.views.admin.TimeOffListView;
|
import com.primefactorsolutions.views.admin.TimeOffListView;
|
||||||
import com.primefactorsolutions.views.assessment.AssessmentsListView;
|
import com.primefactorsolutions.views.assessment.AssessmentsListView;
|
||||||
import com.primefactorsolutions.views.assessment.CandidatesListView;
|
import com.primefactorsolutions.views.assessment.CandidatesListView;
|
||||||
|
@ -1,17 +0,0 @@
|
|||||||
package com.primefactorsolutions.views;
|
|
||||||
|
|
||||||
import com.vaadin.flow.component.html.Main;
|
|
||||||
import com.vaadin.flow.router.PageTitle;
|
|
||||||
import com.vaadin.flow.router.Route;
|
|
||||||
import com.vaadin.flow.spring.annotation.SpringComponent;
|
|
||||||
import jakarta.annotation.security.PermitAll;
|
|
||||||
import org.springframework.context.annotation.Scope;
|
|
||||||
|
|
||||||
@SpringComponent
|
|
||||||
@PermitAll
|
|
||||||
@Scope("prototype")
|
|
||||||
@PageTitle("Profile")
|
|
||||||
@Route(value = "/profiles", layout = MainLayout.class)
|
|
||||||
public class ProfileView extends Main {
|
|
||||||
}
|
|
||||||
|
|
@ -1,10 +1,12 @@
|
|||||||
package com.primefactorsolutions.views;
|
package com.primefactorsolutions.views.employee;
|
||||||
|
|
||||||
import com.primefactorsolutions.model.Document;
|
import com.primefactorsolutions.model.Document;
|
||||||
import com.primefactorsolutions.model.DocumentType;
|
import com.primefactorsolutions.model.DocumentType;
|
||||||
import com.primefactorsolutions.model.Employee;
|
import com.primefactorsolutions.model.Employee;
|
||||||
import com.primefactorsolutions.service.DocumentService;
|
import com.primefactorsolutions.service.DocumentService;
|
||||||
import com.primefactorsolutions.service.EmployeeService;
|
import com.primefactorsolutions.service.EmployeeService;
|
||||||
|
import com.primefactorsolutions.views.BaseEntityForm;
|
||||||
|
import com.primefactorsolutions.views.MainLayout;
|
||||||
import com.vaadin.flow.component.Component;
|
import com.vaadin.flow.component.Component;
|
||||||
import com.vaadin.flow.component.button.Button;
|
import com.vaadin.flow.component.button.Button;
|
||||||
import com.vaadin.flow.component.combobox.ComboBox;
|
import com.vaadin.flow.component.combobox.ComboBox;
|
@ -1,4 +1,4 @@
|
|||||||
package com.primefactorsolutions.views;
|
package com.primefactorsolutions.views.employee;
|
||||||
|
|
||||||
import com.google.common.collect.Lists;
|
import com.google.common.collect.Lists;
|
||||||
import com.primefactorsolutions.model.Document;
|
import com.primefactorsolutions.model.Document;
|
||||||
@ -6,6 +6,8 @@ import com.primefactorsolutions.model.DocumentType;
|
|||||||
import com.primefactorsolutions.model.Employee;
|
import com.primefactorsolutions.model.Employee;
|
||||||
import com.primefactorsolutions.service.DocumentService;
|
import com.primefactorsolutions.service.DocumentService;
|
||||||
import com.primefactorsolutions.service.EmployeeService;
|
import com.primefactorsolutions.service.EmployeeService;
|
||||||
|
import com.primefactorsolutions.views.BaseView;
|
||||||
|
import com.primefactorsolutions.views.MainLayout;
|
||||||
import com.primefactorsolutions.views.util.MenuBarUtils;
|
import com.primefactorsolutions.views.util.MenuBarUtils;
|
||||||
import com.vaadin.flow.component.ClickEvent;
|
import com.vaadin.flow.component.ClickEvent;
|
||||||
import com.vaadin.flow.component.Component;
|
import com.vaadin.flow.component.Component;
|
@ -1,4 +1,4 @@
|
|||||||
package com.primefactorsolutions.views.admin;
|
package com.primefactorsolutions.views.employee;
|
||||||
|
|
||||||
import com.primefactorsolutions.model.Employee;
|
import com.primefactorsolutions.model.Employee;
|
||||||
import com.primefactorsolutions.service.EmployeeService;
|
import com.primefactorsolutions.service.EmployeeService;
|
@ -1,4 +1,4 @@
|
|||||||
package com.primefactorsolutions.views;
|
package com.primefactorsolutions.views.employee;
|
||||||
|
|
||||||
import com.primefactorsolutions.model.Employee;
|
import com.primefactorsolutions.model.Employee;
|
||||||
import com.primefactorsolutions.model.Team;
|
import com.primefactorsolutions.model.Team;
|
||||||
@ -7,8 +7,8 @@ import com.primefactorsolutions.service.EmployeeService;
|
|||||||
import com.primefactorsolutions.service.ReportService;
|
import com.primefactorsolutions.service.ReportService;
|
||||||
import com.primefactorsolutions.service.TeamService;
|
import com.primefactorsolutions.service.TeamService;
|
||||||
import com.primefactorsolutions.service.TimeOffRequestService;
|
import com.primefactorsolutions.service.TimeOffRequestService;
|
||||||
import com.primefactorsolutions.views.admin.EmployeeReportView;
|
import com.primefactorsolutions.views.BaseEntityForm;
|
||||||
import com.primefactorsolutions.views.admin.EmployeesListView;
|
import com.primefactorsolutions.views.MainLayout;
|
||||||
import com.vaadin.componentfactory.pdfviewer.PdfViewer;
|
import com.vaadin.componentfactory.pdfviewer.PdfViewer;
|
||||||
import com.vaadin.flow.component.ClickEvent;
|
import com.vaadin.flow.component.ClickEvent;
|
||||||
import com.vaadin.flow.component.Component;
|
import com.vaadin.flow.component.Component;
|
@ -1,10 +1,9 @@
|
|||||||
package com.primefactorsolutions.views.admin;
|
package com.primefactorsolutions.views.employee;
|
||||||
|
|
||||||
import com.primefactorsolutions.model.Employee;
|
import com.primefactorsolutions.model.Employee;
|
||||||
import com.primefactorsolutions.service.EmployeeService;
|
import com.primefactorsolutions.service.EmployeeService;
|
||||||
import com.primefactorsolutions.views.BaseView;
|
import com.primefactorsolutions.views.BaseView;
|
||||||
import com.primefactorsolutions.views.Constants;
|
import com.primefactorsolutions.views.Constants;
|
||||||
import com.primefactorsolutions.views.EmployeeView;
|
|
||||||
import com.primefactorsolutions.views.MainLayout;
|
import com.primefactorsolutions.views.MainLayout;
|
||||||
import com.primefactorsolutions.views.util.MenuBarUtils;
|
import com.primefactorsolutions.views.util.MenuBarUtils;
|
||||||
import com.vaadin.flow.component.button.Button;
|
import com.vaadin.flow.component.button.Button;
|
@ -7,10 +7,10 @@ import com.primefactorsolutions.service.TimeOffRequestService;
|
|||||||
import com.primefactorsolutions.service.TimeOffService;
|
import com.primefactorsolutions.service.TimeOffService;
|
||||||
import com.primefactorsolutions.views.BaseView;
|
import com.primefactorsolutions.views.BaseView;
|
||||||
import com.primefactorsolutions.views.MainLayout;
|
import com.primefactorsolutions.views.MainLayout;
|
||||||
|
import com.primefactorsolutions.views.util.MenuBarUtils;
|
||||||
import com.vaadin.flow.component.UI;
|
import com.vaadin.flow.component.UI;
|
||||||
import com.vaadin.flow.component.button.Button;
|
import com.vaadin.flow.component.button.Button;
|
||||||
import com.vaadin.flow.component.combobox.ComboBox;
|
import com.vaadin.flow.component.combobox.ComboBox;
|
||||||
import com.vaadin.flow.component.html.Span;
|
|
||||||
import com.vaadin.flow.component.orderedlayout.HorizontalLayout;
|
import com.vaadin.flow.component.orderedlayout.HorizontalLayout;
|
||||||
import com.vaadin.flow.router.PageTitle;
|
import com.vaadin.flow.router.PageTitle;
|
||||||
import com.vaadin.flow.router.Route;
|
import com.vaadin.flow.router.Route;
|
||||||
@ -19,6 +19,7 @@ import com.vaadin.flow.server.StreamResource;
|
|||||||
import com.vaadin.flow.spring.annotation.SpringComponent;
|
import com.vaadin.flow.spring.annotation.SpringComponent;
|
||||||
import com.vaadin.flow.spring.security.AuthenticationContext;
|
import com.vaadin.flow.spring.security.AuthenticationContext;
|
||||||
import jakarta.annotation.security.PermitAll;
|
import jakarta.annotation.security.PermitAll;
|
||||||
|
import org.apache.commons.lang3.tuple.Pair;
|
||||||
import org.apache.pdfbox.pdmodel.PDDocument;
|
import org.apache.pdfbox.pdmodel.PDDocument;
|
||||||
import org.apache.pdfbox.pdmodel.PDPage;
|
import org.apache.pdfbox.pdmodel.PDPage;
|
||||||
import org.apache.pdfbox.pdmodel.PDPageContentStream;
|
import org.apache.pdfbox.pdmodel.PDPageContentStream;
|
||||||
@ -36,6 +37,7 @@ import java.time.LocalDate;
|
|||||||
import java.time.Period;
|
import java.time.Period;
|
||||||
import java.time.Year;
|
import java.time.Year;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import static com.primefactorsolutions.views.Constants.PAGE_SIZE;
|
import static com.primefactorsolutions.views.Constants.PAGE_SIZE;
|
||||||
@ -47,6 +49,7 @@ import static com.primefactorsolutions.views.Constants.PAGE_SIZE;
|
|||||||
@PermitAll
|
@PermitAll
|
||||||
public class TimeOffSummaryListView extends BaseView {
|
public class TimeOffSummaryListView extends BaseView {
|
||||||
|
|
||||||
|
private static final Map<UUID, TimeOffSummary> SUMMARY_MAP = new ConcurrentHashMap<>();
|
||||||
private final TimeOffRequestService requestService;
|
private final TimeOffRequestService requestService;
|
||||||
private final EmployeeService employeeService;
|
private final EmployeeService employeeService;
|
||||||
private final TeamService teamService;
|
private final TeamService teamService;
|
||||||
@ -93,12 +96,44 @@ public class TimeOffSummaryListView extends BaseView {
|
|||||||
private void setupRequestGrid() {
|
private void setupRequestGrid() {
|
||||||
requestGrid.addColumn(this::getEmployeeFullName).setHeader("Empleado");
|
requestGrid.addColumn(this::getEmployeeFullName).setHeader("Empleado");
|
||||||
requestGrid.addColumn(this::getTeamName).setHeader("Equipo");
|
requestGrid.addColumn(this::getTeamName).setHeader("Equipo");
|
||||||
requestGrid.addColumn(this::getGeneralTotal).setHeader("Total general");
|
requestGrid.addColumn(this::getRemainingHolidays).setHeader("Remaining holiday");
|
||||||
|
requestGrid.addColumn(this::getRemainingPersonal).setHeader("Remaining personal");
|
||||||
|
requestGrid.addColumn(this::getRemainingVacation).setHeader("Remaining vacation");
|
||||||
|
requestGrid.addColumn(this::getRemainingTotal).setHeader("Remaining total");
|
||||||
|
|
||||||
|
if (isRoleAdmin()) {
|
||||||
|
requestGrid.addComponentColumn(employee -> MenuBarUtils.menuBar(
|
||||||
|
Pair.of("Download", __ -> downloadEmployeeReport(employee.getId()))));
|
||||||
|
}
|
||||||
|
|
||||||
requestGrid.setPaginationBarMode(PagingGrid.PaginationBarMode.BOTTOM);
|
requestGrid.setPaginationBarMode(PagingGrid.PaginationBarMode.BOTTOM);
|
||||||
requestGrid.setPageSize(PAGE_SIZE);
|
requestGrid.setPageSize(PAGE_SIZE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private Double getRemainingHolidays(final Employee employee) {
|
||||||
|
final TimeOffSummary summary = SUMMARY_MAP.computeIfAbsent(employee.getId(), __ -> getTimeOffSummary(employee));
|
||||||
|
|
||||||
|
return summary.remainingHolidayDays;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Double getRemainingPersonal(final Employee employee) {
|
||||||
|
final TimeOffSummary summary = SUMMARY_MAP.computeIfAbsent(employee.getId(), __ -> getTimeOffSummary(employee));
|
||||||
|
|
||||||
|
return summary.remainingPersonalDays;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Double getRemainingVacation(final Employee employee) {
|
||||||
|
final TimeOffSummary summary = SUMMARY_MAP.computeIfAbsent(employee.getId(), __ -> getTimeOffSummary(employee));
|
||||||
|
|
||||||
|
return summary.remainingVacationDays;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Double getRemainingTotal(final Employee employee) {
|
||||||
|
final TimeOffSummary summary = SUMMARY_MAP.computeIfAbsent(employee.getId(), __ -> getTimeOffSummary(employee));
|
||||||
|
|
||||||
|
return summary.getTotalRemaining();
|
||||||
|
}
|
||||||
|
|
||||||
private void refreshGeneralRequestGrid(final Employee employee,
|
private void refreshGeneralRequestGrid(final Employee employee,
|
||||||
final Team team) {
|
final Team team) {
|
||||||
requestGrid.setPagingDataProvider((page, pageSize) -> {
|
requestGrid.setPagingDataProvider((page, pageSize) -> {
|
||||||
@ -150,32 +185,34 @@ public class TimeOffSummaryListView extends BaseView {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private String getGeneralTotal(final Employee employee) {
|
private String getGeneralTotal(final Employee employee) {
|
||||||
List<TimeOffRequest> employeeRequests = requestService.findRequestsByEmployeeId(employee.getId());
|
final List<TimeOffRequest> employeeRequests = requestService.findRequestsByEmployeeId(employee.getId());
|
||||||
List<TimeOff> timeOffs = timeOffService.findVacations();
|
final List<TimeOff> timeOffs = timeOffService.findVacations();
|
||||||
|
final List<Double> vacationDays = calculateVacationDays(employee);
|
||||||
List<Double> vacationDays = calculateVacationDays(employee);
|
|
||||||
|
|
||||||
double utilizedVacationCurrentDays = vacationDays.get(1);
|
double utilizedVacationCurrentDays = vacationDays.get(1);
|
||||||
List<TimeOffRequest> vacationCurrentRequests = requestService
|
|
||||||
|
final List<TimeOffRequest> vacationCurrentRequests = requestService
|
||||||
.findByEmployeeAndCategory(employee.getId(), TimeOffRequestType.VACACION_GESTION_ACTUAL);
|
.findByEmployeeAndCategory(employee.getId(), TimeOffRequestType.VACACION_GESTION_ACTUAL);
|
||||||
|
|
||||||
if (vacationCurrentRequests != null && !vacationCurrentRequests.isEmpty()) {
|
if (vacationCurrentRequests != null && !vacationCurrentRequests.isEmpty()) {
|
||||||
utilizedVacationCurrentDays = vacationCurrentRequests.getLast().getDaysBalance();
|
utilizedVacationCurrentDays = vacationCurrentRequests.getLast().getDaysBalance();
|
||||||
}
|
}
|
||||||
double totalVacationCurrentDays = vacationDays.get(1) - (vacationDays.get(1) - utilizedVacationCurrentDays);
|
double totalVacationCurrentDays = vacationDays.get(1) - (vacationDays.get(1) - utilizedVacationCurrentDays);
|
||||||
|
|
||||||
double utilizedVacationPreviousDays = vacationDays.get(0);
|
double utilizedVacationPreviousDays = vacationDays.get(0);
|
||||||
List<TimeOffRequest> vacationPreviousRequests = requestService
|
final List<TimeOffRequest> vacationPreviousRequests = requestService
|
||||||
.findByEmployeeAndCategory(employee.getId(), TimeOffRequestType.VACACION_GESTION_ANTERIOR);
|
.findByEmployeeAndCategory(employee.getId(), TimeOffRequestType.VACACION_GESTION_ANTERIOR);
|
||||||
|
|
||||||
if (vacationPreviousRequests != null && !vacationPreviousRequests.isEmpty()) {
|
if (vacationPreviousRequests != null && !vacationPreviousRequests.isEmpty()) {
|
||||||
utilizedVacationPreviousDays = vacationPreviousRequests.getLast().getDaysBalance();
|
utilizedVacationPreviousDays = vacationPreviousRequests.getLast().getDaysBalance();
|
||||||
}
|
}
|
||||||
double totalVacationPreviousDays = vacationDays.getFirst()
|
|
||||||
|
final double totalVacationPreviousDays = vacationDays.getFirst()
|
||||||
- (vacationDays.getFirst() - utilizedVacationPreviousDays);
|
- (vacationDays.getFirst() - utilizedVacationPreviousDays);
|
||||||
|
|
||||||
|
|
||||||
double totalUtilized = calculateTotalUtilized(employeeRequests);
|
final double totalUtilized = calculateTotalUtilized(employeeRequests);
|
||||||
double totalVacations = totalVacationCurrentDays + totalVacationPreviousDays;
|
final double totalVacations = totalVacationCurrentDays + totalVacationPreviousDays;
|
||||||
double totalAvailable = calculateTotalAvailable(timeOffs, employeeRequests, employee);
|
final double totalAvailable = calculateTotalAvailable(timeOffs, employeeRequests, employee);
|
||||||
|
|
||||||
double generalTotal = totalAvailable + totalVacations - totalUtilized;
|
double generalTotal = totalAvailable + totalVacations - totalUtilized;
|
||||||
|
|
||||||
@ -269,6 +306,7 @@ public class TimeOffSummaryListView extends BaseView {
|
|||||||
vacationDays.add(0.0);
|
vacationDays.add(0.0);
|
||||||
vacationDays.add(0.0);
|
vacationDays.add(0.0);
|
||||||
}
|
}
|
||||||
|
|
||||||
return vacationDays;
|
return vacationDays;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -419,20 +457,7 @@ public class TimeOffSummaryListView extends BaseView {
|
|||||||
ui.getPage().open(registration.getResourceUri().toString());
|
ui.getPage().open(registration.getResourceUri().toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
private HorizontalLayout createSummaryLayout(final Employee employee) {
|
private TimeOffSummary getTimeOffSummary(final Employee employee) {
|
||||||
ResultEmp result = extracted(employee);
|
|
||||||
double totalAvailableDays = result.remainingHolidayDays() + result.remainingPersonalDays()
|
|
||||||
+ result.remainingVacationDays();
|
|
||||||
|
|
||||||
return new HorizontalLayout(
|
|
||||||
new Span("Total feriados fijos y movibles: " + result.remainingHolidayDays()),
|
|
||||||
new Span("Total días libres personales: " + result.remainingPersonalDays()),
|
|
||||||
new Span("Total vacaciones pendientes de uso: " + result.remainingVacationDays()),
|
|
||||||
new Span("TOTAL GENERAL DE DÍAS DISPONIBLES: " + totalAvailableDays)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
private ResultEmp extracted(final Employee employee) {
|
|
||||||
final boolean isMale = employee.getGender() == Employee.Gender.MALE;
|
final boolean isMale = employee.getGender() == Employee.Gender.MALE;
|
||||||
final int currentYear = LocalDate.now().getYear();
|
final int currentYear = LocalDate.now().getYear();
|
||||||
final LocalDate currentDate = LocalDate.now();
|
final LocalDate currentDate = LocalDate.now();
|
||||||
@ -478,10 +503,14 @@ public class TimeOffSummaryListView extends BaseView {
|
|||||||
currentDate
|
currentDate
|
||||||
);
|
);
|
||||||
|
|
||||||
return new ResultEmp(remainingHolidayDays, remainingPersonalDays, remainingVacationDays);
|
return new TimeOffSummary(remainingHolidayDays, remainingPersonalDays, remainingVacationDays);
|
||||||
}
|
}
|
||||||
|
|
||||||
private record ResultEmp(double remainingHolidayDays, double remainingPersonalDays, double remainingVacationDays) {
|
private record TimeOffSummary(double remainingHolidayDays, double remainingPersonalDays,
|
||||||
|
double remainingVacationDays) {
|
||||||
|
public double getTotalRemaining() {
|
||||||
|
return remainingHolidayDays + remainingPersonalDays + remainingVacationDays;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private double getHealthLicence(final UUID employeeId) {
|
private double getHealthLicence(final UUID employeeId) {
|
||||||
@ -612,7 +641,7 @@ public class TimeOffSummaryListView extends BaseView {
|
|||||||
private ByteArrayInputStream generatePdfReport(final UUID employeeId) {
|
private ByteArrayInputStream generatePdfReport(final UUID employeeId) {
|
||||||
final List<TimeOffRequest> requests = requestService.findRequestsByEmployeeId(employeeId);
|
final List<TimeOffRequest> requests = requestService.findRequestsByEmployeeId(employeeId);
|
||||||
final Employee employee = employeeService.getEmployee(employeeId);
|
final Employee employee = employeeService.getEmployee(employeeId);
|
||||||
final ResultEmp result = extracted(employee);
|
final TimeOffSummary result = getTimeOffSummary(employee);
|
||||||
|
|
||||||
try (PDDocument document = new PDDocument(); ByteArrayOutputStream out = new ByteArrayOutputStream()) {
|
try (PDDocument document = new PDDocument(); ByteArrayOutputStream out = new ByteArrayOutputStream()) {
|
||||||
PDPage page = new PDPage();
|
PDPage page = new PDPage();
|
||||||
|
@ -18,7 +18,8 @@ public class MenuBarUtils {
|
|||||||
"View", VaadinIcon.EYE,
|
"View", VaadinIcon.EYE,
|
||||||
"Edit", VaadinIcon.PENCIL,
|
"Edit", VaadinIcon.PENCIL,
|
||||||
"Copy", VaadinIcon.COPY,
|
"Copy", VaadinIcon.COPY,
|
||||||
"Email", VaadinIcon.ENVELOPE
|
"Email", VaadinIcon.ENVELOPE,
|
||||||
|
"Download", VaadinIcon.DOWNLOAD
|
||||||
);
|
);
|
||||||
|
|
||||||
public static MenuItem createIconItem(final MenuBar menu, final VaadinIcon iconName, final String ariaLabel) {
|
public static MenuItem createIconItem(final MenuBar menu, final VaadinIcon iconName, final String ariaLabel) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user