Compare commits

..

No commits in common. "ca5fb122fb375eb8dc9e8e3a825a731c2ac07eb4" and "39222204390bfd9162d231202dc2d4fbf00491b0" have entirely different histories.

8 changed files with 68 additions and 165 deletions

View File

@ -4,6 +4,7 @@ import com.vaadin.flow.component.page.AppShellConfigurator;
import com.vaadin.flow.theme.Theme;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
/**
* The entry point of the Spring Boot application.
*

View File

@ -3,14 +3,13 @@ package com.primefactorsolutions.model;
public enum TimeOffRequestStatus {
TODOS,
TOMADO,
SOLICITADO,
APROBADO,
EN_USO,
EN_REVISION,
PENDIENTE,
RECHAZADO,
VENCIDO,
SOLICITADO,
EN_REVISION,
COMPLETADO,
CANCELADO,
VENCIDO
}

View File

@ -5,7 +5,6 @@ import com.primefactorsolutions.repositories.TimeOffRequestRepository;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;
import java.time.LocalDate;
import java.util.List;
import java.util.UUID;
import java.util.Optional;
@ -51,23 +50,4 @@ public class TimeOffRequestService {
public List<TimeOffRequest> findByEmployeeAndCategory(final UUID employeeId, final TimeOffRequestType category) {
return timeOffRequestRepository.findByEmployeeIdAndCategory(employeeId, category);
}
public void updateRequestStatuses() {
List<TimeOffRequest> requests = findAllTimeOffRequests();
LocalDate now = LocalDate.now();
for (TimeOffRequest request : requests) {
if (request.getState() == TimeOffRequestStatus.APROBADO) {
LocalDate startDate = request.getStartDate();
LocalDate endDate = request.getEndDate();
if (now.isAfter(endDate)) {
request.setState(TimeOffRequestStatus.TOMADO);
} else if (now.isEqual(startDate) || now.isAfter(startDate) && now.isBefore(endDate)) {
request.setState(TimeOffRequestStatus.EN_USO);
}
}
}
saveAll(requests);
}
}

View File

@ -1,5 +1,7 @@
package com.primefactorsolutions.views;
import com.primefactorsolutions.model.TimeOffRequest;
import com.primefactorsolutions.model.TimeOffRequestStatus;
import com.primefactorsolutions.service.TimeOffRequestService;
import com.vaadin.flow.component.Text;
import com.vaadin.flow.component.html.Main;
@ -7,12 +9,42 @@ import com.vaadin.flow.router.PageTitle;
import com.vaadin.flow.router.Route;
import jakarta.annotation.security.PermitAll;
import java.time.LocalDate;
import java.util.List;
@PageTitle("Home")
@Route(value = "", layout = MainLayout.class)
@PermitAll
public class MainView extends Main {
private final TimeOffRequestService requestService;
public MainView(final TimeOffRequestService requestService) {
this.requestService = requestService;
add(new Text("Welcome"));
updateRequestStatuses();
}
private void updateRequestStatuses() {
List<TimeOffRequest> requests = requestService.findAllTimeOffRequests();
LocalDate now = LocalDate.now();
for (TimeOffRequest request : requests) {
if (request.getState() == TimeOffRequestStatus.APROBADO) {
LocalDate expirationDate = request.getExpiration();
LocalDate startDate = request.getStartDate();
LocalDate endDate = request.getEndDate();
if (now.isAfter(expirationDate)) {
request.setState(TimeOffRequestStatus.VENCIDO);
} else if (now.isAfter(endDate) && now.isBefore(expirationDate)) {
request.setState(TimeOffRequestStatus.TOMADO);
} else if (now.isEqual(startDate) || now.isAfter(startDate) && now.isBefore(endDate)) {
request.setState(TimeOffRequestStatus.EN_USO);
}
}
}
requestService.saveAll(requests);
}
}

View File

@ -23,7 +23,9 @@ import org.vaadin.firitin.components.grid.PagingGrid;
import java.time.LocalDate;
import java.time.Period;
import java.util.*;
import java.util.Collections;
import java.util.List;
import java.util.UUID;
import java.util.stream.Collectors;
@SpringComponent
@ -52,7 +54,6 @@ public class RequestEmployeeView extends Div implements HasUrlParameter<String>
}
private void initializeView() {
requestService.updateRequestStatuses();
setupFilters();
setupGrid();
add(requestGrid, createActionButtons(), createSummaryLayout());
@ -105,70 +106,28 @@ public class RequestEmployeeView extends Div implements HasUrlParameter<String>
});
}
private Set<TimeOffRequestType> getStandardExclusions() {
return Set.of(
TimeOffRequestType.MATERNIDAD,
TimeOffRequestType.PATERNIDAD,
TimeOffRequestType.MATRIMONIO,
TimeOffRequestType.DUELO_1ER_GRADO,
TimeOffRequestType.DUELO_2ER_GRADO,
TimeOffRequestType.DIA_DEL_PADRE,
TimeOffRequestType.DIA_DE_LA_MADRE
);
}
private Set<TimeOffRequestType> getMaleSpecificExclusions() {
return Set.of(
TimeOffRequestType.DIA_DE_LA_MUJER_INTERNACIONAL,
TimeOffRequestType.DIA_DE_LA_MUJER_NACIONAL
);
}
private VerticalLayout createSummaryLayout() {
Employee employee = employeeService.getEmployee(employeeId);
boolean isMale = employee.getGender() == Employee.Gender.MALE;
double totalHoliday = requests.stream()
.filter(this::verificationIsHoliday)
.mapToDouble(TimeOffRequest::getAvailableDays)
.sum();
double totalVacations = calculateVacationDays(employeeService.getEmployee(employeeId));
double totalPersonalDays = requests.stream()
.filter(req -> !verificationIsHoliday(req))
.filter(req -> !req.getCategory().name().startsWith("VACACION"))
.mapToDouble(TimeOffRequest::getAvailableDays)
.sum();
List<Vacation> vacations = vacationService.findVacations();
double totalFixedAndMovableHolidays = calculateHolidayDays(vacations);
double totalPersonalDays = calculatePersonalDays(vacations, isMale);
double totalVacationDays = calculateVacationDays(employee);
double utilizedFixedAndMovableHolidays = calculateHolidayUtilizedDays();
double utilizedVacationDays = calculateVacationUtilizedDays();
double utilizedPersonalDays = calculatePersonalDaysUtilized(isMale);
double remainingHolidayDays = totalFixedAndMovableHolidays - utilizedFixedAndMovableHolidays;
double remainingPersonalDays = totalPersonalDays - utilizedPersonalDays;
double remainingVacationDays = totalVacationDays - utilizedVacationDays;
double totalAvailableDays = remainingHolidayDays + remainingPersonalDays + remainingVacationDays;
double totalAvailableDays = totalHoliday + totalVacations + totalPersonalDays;
return new VerticalLayout(
new Span("Total feriados fijos y movibles: " + remainingHolidayDays),
new Span("Total días libres personales: " + remainingPersonalDays),
new Span("Total vacaciones pendientes de uso: " + remainingVacationDays),
new Span("Total general de días disponibles: " + totalAvailableDays)
new Span("Total feriados: " + totalHoliday),
new Span("Total vacaciones: " + totalVacations),
new Span("Total días personales: " + totalPersonalDays),
new Span("Total general: " + totalAvailableDays)
);
}
private double calculateHolidayDays(final List<Vacation> vacations) {
return vacations.stream()
.filter(req -> req.getType() != Vacation.Type.OTHER)
.mapToDouble(Vacation::getDuration)
.sum();
}
private double calculatePersonalDays(final List<Vacation> vacations, final boolean isMale) {
return vacations.stream()
.filter(req -> req.getType() == Vacation.Type.OTHER)
.filter(req -> !getStandardExclusions().contains(req.getCategory()))
.filter(req -> !(isMale && getMaleSpecificExclusions().contains(req.getCategory())))
.filter(req -> !req.getCategory().name().startsWith("VACACION"))
.mapToDouble(Vacation::getDuration)
.sum();
}
private double calculateVacationDays(final Employee employee) {
if (employee.getDateOfEntry() != null) {
LocalDate entryDate = employee.getDateOfEntry();
@ -212,30 +171,6 @@ public class RequestEmployeeView extends Div implements HasUrlParameter<String>
}
}
private double calculateHolidayUtilizedDays() {
return requests.stream()
.filter(this::verificationIsHoliday)
.mapToDouble(TimeOffRequest::getAvailableDays)
.sum();
}
private double calculateVacationUtilizedDays() {
return requests.stream()
.filter(req -> req.getCategory() == TimeOffRequestType.VACACION_GESTION_ACTUAL)
.mapToDouble(TimeOffRequest::getAvailableDays)
.sum();
}
private double calculatePersonalDaysUtilized(final boolean isMale) {
return requests.stream()
.filter(req -> !verificationIsHoliday(req))
.filter(req -> !getStandardExclusions().contains(req.getCategory()))
.filter(req -> !(isMale && getMaleSpecificExclusions().contains(req.getCategory())))
.filter(req -> !req.getCategory().name().startsWith("VACACION"))
.mapToDouble(TimeOffRequest::getAvailableDays)
.sum();
}
private double calculateVacationDaysSinceEntry(final LocalDate dateOfEntry, final LocalDate date) {
int yearsOfService = dateOfEntry != null ? Period.between(dateOfEntry, date).getYears() : 0;
if (yearsOfService > 10) {

View File

@ -63,7 +63,6 @@ public class RequestRegisterView extends VerticalLayout {
}
private void initializeView() {
requestService.updateRequestStatuses();
configureFormFields();
configureButtons();
configureBinder();
@ -85,6 +84,8 @@ public class RequestRegisterView extends VerticalLayout {
employeeComboBox.setItemLabelGenerator(emp -> emp.getFirstName() + " " + emp.getLastName());
employeeComboBox.addValueChangeListener(event -> {
employee = event.getValue();
System.out.println("Clearing form..." + employee);
handleEmployeeSelection(event.getValue());
});
categoryComboBox.addValueChangeListener(event -> {
@ -172,8 +173,7 @@ public class RequestRegisterView extends VerticalLayout {
return latestRequest.getState() == TimeOffRequestStatus.VENCIDO
|| (latestRequest.getState() == TimeOffRequestStatus.TOMADO && latestRequest.getDaysBalance() > 0);
} else {
return latestRequest.getState() == TimeOffRequestStatus.VENCIDO
|| latestRequest.getState() == TimeOffRequestStatus.RECHAZADO;
return latestRequest.getState() == TimeOffRequestStatus.VENCIDO;
}
}
@ -248,29 +248,11 @@ public class RequestRegisterView extends VerticalLayout {
}
if (startDate != null) {
if (vacation.getExpiration() != null) {
endDate = startDate.plusDays(vacation.getExpiration().intValue() - 1);
} else {
endDate = LocalDate.of(startDate.getYear(), 12, 31);
}
} else {
startDate = LocalDate.now();
}
System.out.println(vacation);
System.out.println(vacation);
System.out.println(vacation);
System.out.println(vacation);
System.out.println(vacation);
System.out.println(vacation);
System.out.println(startDate);
System.out.println(startDate);
System.out.println(startDate);
System.out.println(startDate);
System.out.println(startDate);
System.out.println(startDate);
setPickerValues(vacation, startDate);
setPickerLimits(startDate, endDate);
}
@ -285,23 +267,19 @@ public class RequestRegisterView extends VerticalLayout {
.map(request -> request.getStartDate().getYear())
.orElse(LocalDate.now().getYear());
if (previousRequests.getLast().getState() != TimeOffRequestStatus.RECHAZADO) {
lastRequestYear = lastRequestYear + 1;
}
int currentYear = LocalDate.now().getYear();
return Math.max(lastRequestYear, currentYear);
return Math.max(lastRequestYear + 1, currentYear);
}
private LocalDate determineStartDate(final Vacation vacation, final int startYear) {
if (vacation.getCategory() == TimeOffRequestType.CUMPLEAÑOS && employee.getBirthday() != null) {
return LocalDate.of(startYear, employee.getBirthday().getMonth(), employee.getBirthday().getDayOfMonth());
}
if (vacation.getMonthOfYear() != null && vacation.getDayOfMonth() != null) {
return LocalDate.of(startYear, vacation.getMonthOfYear().intValue(), vacation.getDayOfMonth().intValue());
}
if (vacation.getCategory() == TimeOffRequestType.CUMPLEAÑOS && employee.getBirthday() != null) {
return LocalDate.of(startYear, employee.getBirthday().getMonth(), employee.getBirthday().getDayOfMonth());
}
if (vacation.getCategory() == TimeOffRequestType.PERMISOS_DE_SALUD) {
return LocalDate.now();
}
@ -312,24 +290,8 @@ public class RequestRegisterView extends VerticalLayout {
private void setPickerValues(final Vacation vacation, final LocalDate startDate) {
startDatePicker.setValue(startDate);
System.out.println(vacation);
System.out.println(vacation);
System.out.println(vacation);
System.out.println(vacation);
System.out.println(vacation);
System.out.println(vacation);
System.out.println(startDate);
System.out.println(startDate);
System.out.println(startDate);
System.out.println(startDate);
System.out.println(startDate);
System.out.println(startDate);
if ((vacation.getDuration() != null && vacation.getDuration() == 0.5)
|| vacation.getCategory() == TimeOffRequestType.PERMISOS_DE_SALUD
|| vacation.getCategory() == TimeOffRequestType.CUMPLEAÑOS) {
|| vacation.getCategory() == TimeOffRequestType.PERMISOS_DE_SALUD) {
endDatePicker.setValue(startDate);
} else {
int durationDays = (vacation.getDuration() != null ? vacation.getDuration().intValue() - 1 : 0);
@ -368,7 +330,7 @@ public class RequestRegisterView extends VerticalLayout {
double balanceDays = calculateBalanceDays(availableDays, daysToBeTakenField.getValue());
balanceDaysField.setValue(balanceDays);
if (balanceDays < 0.0) {
if (balanceDays < 0) {
clearFields();
}
}
@ -383,12 +345,7 @@ public class RequestRegisterView extends VerticalLayout {
}
private void setDaysToBeTakenField(final double daysToBeTaken) {
if (vacation.getCategory() == TimeOffRequestType.PERMISOS_DE_SALUD
|| vacation.getCategory() == TimeOffRequestType.CUMPLEAÑOS
|| vacation.getCategory() == TimeOffRequestType.DIA_DEL_PADRE
|| vacation.getCategory() == TimeOffRequestType.DIA_DE_LA_MADRE
|| vacation.getCategory() == TimeOffRequestType.DIA_DE_LA_MUJER_INTERNACIONAL
|| vacation.getCategory() == TimeOffRequestType.DIA_DE_LA_MUJER_NACIONAL) {
if (vacation.getCategory() == TimeOffRequestType.PERMISOS_DE_SALUD) {
daysToBeTakenField.setValue(0.5);
} else {
daysToBeTakenField.setValue(daysToBeTaken);
@ -461,7 +418,7 @@ public class RequestRegisterView extends VerticalLayout {
List<TimeOffRequest> existingRequests =
requestService.findByEmployeeAndCategory(employee.getId(), request.getCategory());
int maxRequests = request.getCategory().name().startsWith("VACACION") ? 2 : 1;
int maxRequests = request.getCategory() == TimeOffRequestType.PERMISOS_DE_SALUD ? 4 : 2;
if (existingRequests.size() >= maxRequests) {
existingRequests.stream()

View File

@ -57,7 +57,6 @@ public class RequestsListView extends Main {
}
private void initializeView() {
requestService.updateRequestStatuses();
setupFilters();
setupRequestGrid();
add(requestGrid);

View File

@ -32,7 +32,7 @@ INSERT INTO vacation (id, version, category, month_of_year, day_of_month, durati
INSERT INTO vacation (id, version, category, month_of_year, day_of_month, duration, expiration, type) VALUES ('c23e4567-e89b-12d3-a456-42661417400b', 1, 'DIA_DE_TODOS_LOS_DIFUNTOS', 11, 2, 1, 30, 'MOVABLE');
INSERT INTO vacation (id, version, category, month_of_year, day_of_month, duration, type) VALUES ('c23e4567-e89b-12d3-a456-42661417400c', 1, 'CUMPLEAÑOS', 12, 31, 0.5, 'OTHER');
INSERT INTO vacation (id, version, category, duration, expiration, type) VALUES ('c23e4567-e89b-12d3-a456-42661417400c', 1, 'CUMPLEAÑOS', 0.5, 365, 'OTHER');
INSERT INTO vacation (id, version, category, duration, expiration, type) VALUES ('c23e4567-e89b-12d3-a456-42661417400d', 1, 'MATERNIDAD', 90, 90, 'OTHER');
INSERT INTO vacation (id, version, category, duration, expiration, type) VALUES ('c23e4567-e89b-12d3-a456-42661417400e', 1, 'PATERNIDAD', 3, 3, 'OTHER');
INSERT INTO vacation (id, version, category, duration, expiration, type) VALUES ('c23e4567-e89b-12d3-a456-42661417400f', 1, 'MATRIMONIO', 3, 3, 'OTHER');