En-desarrollo #71
@ -3,13 +3,14 @@ package com.primefactorsolutions.model;
|
|||||||
public enum TimeOffRequestStatus {
|
public enum TimeOffRequestStatus {
|
||||||
TODOS,
|
TODOS,
|
||||||
TOMADO,
|
TOMADO,
|
||||||
SOLICITADO,
|
|
||||||
APROBADO,
|
APROBADO,
|
||||||
EN_USO,
|
EN_USO,
|
||||||
EN_REVISION,
|
|
||||||
PENDIENTE,
|
PENDIENTE,
|
||||||
RECHAZADO,
|
RECHAZADO,
|
||||||
|
VENCIDO,
|
||||||
|
|
||||||
|
SOLICITADO,
|
||||||
|
EN_REVISION,
|
||||||
COMPLETADO,
|
COMPLETADO,
|
||||||
CANCELADO,
|
CANCELADO,
|
||||||
VENCIDO
|
|
||||||
}
|
}
|
||||||
|
@ -3,8 +3,10 @@ package com.primefactorsolutions.service;
|
|||||||
import com.primefactorsolutions.model.*;
|
import com.primefactorsolutions.model.*;
|
||||||
import com.primefactorsolutions.repositories.TimeOffRequestRepository;
|
import com.primefactorsolutions.repositories.TimeOffRequestRepository;
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
|
import org.springframework.scheduling.annotation.Scheduled;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import java.time.LocalDate;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
@ -50,4 +52,28 @@ public class TimeOffRequestService {
|
|||||||
public List<TimeOffRequest> findByEmployeeAndCategory(final UUID employeeId, final TimeOffRequestType category) {
|
public List<TimeOffRequest> findByEmployeeAndCategory(final UUID employeeId, final TimeOffRequestType category) {
|
||||||
return timeOffRequestRepository.findByEmployeeIdAndCategory(employeeId, category);
|
return timeOffRequestRepository.findByEmployeeIdAndCategory(employeeId, category);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Scheduled(cron = "0 0 0 * * ?")
|
||||||
|
private void updateRequestStatuses() {
|
||||||
|
List<TimeOffRequest> requests = findAllTimeOffRequests();
|
||||||
|
LocalDate now = LocalDate.now();
|
||||||
|
|
||||||
|
for (TimeOffRequest request : requests) {
|
||||||
|
if (request.getState() != TimeOffRequestStatus.RECHAZADO) {
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
saveAll(requests);
|
||||||
|
}
|
||||||
}
|
}
|
@ -1,7 +1,5 @@
|
|||||||
package com.primefactorsolutions.views;
|
package com.primefactorsolutions.views;
|
||||||
|
|
||||||
import com.primefactorsolutions.model.TimeOffRequest;
|
|
||||||
import com.primefactorsolutions.model.TimeOffRequestStatus;
|
|
||||||
import com.primefactorsolutions.service.TimeOffRequestService;
|
import com.primefactorsolutions.service.TimeOffRequestService;
|
||||||
import com.vaadin.flow.component.Text;
|
import com.vaadin.flow.component.Text;
|
||||||
import com.vaadin.flow.component.html.Main;
|
import com.vaadin.flow.component.html.Main;
|
||||||
@ -9,42 +7,12 @@ import com.vaadin.flow.router.PageTitle;
|
|||||||
import com.vaadin.flow.router.Route;
|
import com.vaadin.flow.router.Route;
|
||||||
import jakarta.annotation.security.PermitAll;
|
import jakarta.annotation.security.PermitAll;
|
||||||
|
|
||||||
import java.time.LocalDate;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
@PageTitle("Home")
|
@PageTitle("Home")
|
||||||
@Route(value = "", layout = MainLayout.class)
|
@Route(value = "", layout = MainLayout.class)
|
||||||
@PermitAll
|
@PermitAll
|
||||||
public class MainView extends Main {
|
public class MainView extends Main {
|
||||||
|
|
||||||
private final TimeOffRequestService requestService;
|
|
||||||
|
|
||||||
public MainView(final TimeOffRequestService requestService) {
|
public MainView(final TimeOffRequestService requestService) {
|
||||||
this.requestService = requestService;
|
|
||||||
add(new Text("Welcome"));
|
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);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -107,24 +107,49 @@ public class RequestEmployeeView extends Div implements HasUrlParameter<String>
|
|||||||
}
|
}
|
||||||
|
|
||||||
private VerticalLayout createSummaryLayout() {
|
private VerticalLayout createSummaryLayout() {
|
||||||
double totalHoliday = requests.stream()
|
List<Vacation> vacations = vacationService.findVacations();
|
||||||
|
|
||||||
|
double holiday = vacations.stream()
|
||||||
|
.filter(req -> req.getType() != Vacation.Type.OTHER)
|
||||||
|
.mapToDouble(Vacation::getDuration)
|
||||||
|
.sum();
|
||||||
|
|
||||||
|
double personalDays = vacations.stream()
|
||||||
|
.filter(req -> req.getType() == Vacation.Type.OTHER)
|
||||||
|
.filter(req -> !req.getCategory().name().startsWith("VACACION"))
|
||||||
|
|
||||||
|
.mapToDouble(Vacation::getDuration)
|
||||||
|
.sum();
|
||||||
|
|
||||||
|
double vacation = calculateVacationDays(employeeService.getEmployee(employeeId));
|
||||||
|
|
||||||
|
double holidayUtilized = requests.stream()
|
||||||
.filter(this::verificationIsHoliday)
|
.filter(this::verificationIsHoliday)
|
||||||
.mapToDouble(TimeOffRequest::getAvailableDays)
|
.mapToDouble(TimeOffRequest::getAvailableDays)
|
||||||
.sum();
|
.sum();
|
||||||
double totalVacations = calculateVacationDays(employeeService.getEmployee(employeeId));
|
|
||||||
double totalPersonalDays = requests.stream()
|
double vacationUtilized = requests.stream()
|
||||||
|
.filter(req -> req.getCategory() == TimeOffRequestType.VACACION_GESTION_ACTUAL)
|
||||||
|
.mapToDouble(TimeOffRequest::getAvailableDays)
|
||||||
|
.sum();
|
||||||
|
|
||||||
|
double personalDaysUtilized = requests.stream()
|
||||||
.filter(req -> !verificationIsHoliday(req))
|
.filter(req -> !verificationIsHoliday(req))
|
||||||
.filter(req -> !req.getCategory().name().startsWith("VACACION"))
|
.filter(req -> !req.getCategory().name().startsWith("VACACION"))
|
||||||
.mapToDouble(TimeOffRequest::getAvailableDays)
|
.mapToDouble(TimeOffRequest::getAvailableDays)
|
||||||
.sum();
|
.sum();
|
||||||
|
|
||||||
|
double totalHoliday = holiday - holidayUtilized;
|
||||||
|
double totalPersonalDays = personalDays - personalDaysUtilized;
|
||||||
|
double totalVacations = vacation - vacationUtilized;
|
||||||
|
|
||||||
double totalAvailableDays = totalHoliday + totalVacations + totalPersonalDays;
|
double totalAvailableDays = totalHoliday + totalVacations + totalPersonalDays;
|
||||||
|
|
||||||
return new VerticalLayout(
|
return new VerticalLayout(
|
||||||
new Span("Total feriados: " + totalHoliday),
|
new Span("Total feriados fijos y movibles: " + totalHoliday),
|
||||||
new Span("Total vacaciones: " + totalVacations),
|
new Span("Total días libres personales: " + totalPersonalDays),
|
||||||
new Span("Total días personales: " + totalPersonalDays),
|
new Span("Total vacaciones pendientes de uso: " + totalVacations),
|
||||||
new Span("Total general: " + totalAvailableDays)
|
new Span("Total general de días disponibles: " + totalAvailableDays)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -84,8 +84,6 @@ public class RequestRegisterView extends VerticalLayout {
|
|||||||
employeeComboBox.setItemLabelGenerator(emp -> emp.getFirstName() + " " + emp.getLastName());
|
employeeComboBox.setItemLabelGenerator(emp -> emp.getFirstName() + " " + emp.getLastName());
|
||||||
employeeComboBox.addValueChangeListener(event -> {
|
employeeComboBox.addValueChangeListener(event -> {
|
||||||
employee = event.getValue();
|
employee = event.getValue();
|
||||||
System.out.println("Clearing form..." + employee);
|
|
||||||
|
|
||||||
handleEmployeeSelection(event.getValue());
|
handleEmployeeSelection(event.getValue());
|
||||||
});
|
});
|
||||||
categoryComboBox.addValueChangeListener(event -> {
|
categoryComboBox.addValueChangeListener(event -> {
|
||||||
@ -173,7 +171,7 @@ public class RequestRegisterView extends VerticalLayout {
|
|||||||
return latestRequest.getState() == TimeOffRequestStatus.VENCIDO
|
return latestRequest.getState() == TimeOffRequestStatus.VENCIDO
|
||||||
|| (latestRequest.getState() == TimeOffRequestStatus.TOMADO && latestRequest.getDaysBalance() > 0);
|
|| (latestRequest.getState() == TimeOffRequestStatus.TOMADO && latestRequest.getDaysBalance() > 0);
|
||||||
} else {
|
} else {
|
||||||
return latestRequest.getState() == TimeOffRequestStatus.VENCIDO;
|
return latestRequest.getState() == TimeOffRequestStatus.VENCIDO || latestRequest.getState() == TimeOffRequestStatus.RECHAZADO;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -248,11 +246,29 @@ public class RequestRegisterView extends VerticalLayout {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (startDate != null) {
|
if (startDate != null) {
|
||||||
endDate = startDate.plusDays(vacation.getExpiration().intValue() - 1);
|
if (vacation.getExpiration() != null) {
|
||||||
|
endDate = startDate.plusDays(vacation.getExpiration().intValue() - 1);
|
||||||
|
} else {
|
||||||
|
endDate = LocalDate.of(startDate.getYear(), 12, 31);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
startDate = LocalDate.now();
|
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);
|
setPickerValues(vacation, startDate);
|
||||||
setPickerLimits(startDate, endDate);
|
setPickerLimits(startDate, endDate);
|
||||||
}
|
}
|
||||||
@ -267,19 +283,23 @@ public class RequestRegisterView extends VerticalLayout {
|
|||||||
.map(request -> request.getStartDate().getYear())
|
.map(request -> request.getStartDate().getYear())
|
||||||
.orElse(LocalDate.now().getYear());
|
.orElse(LocalDate.now().getYear());
|
||||||
|
|
||||||
|
if (previousRequests.getLast().getState() != TimeOffRequestStatus.RECHAZADO) {
|
||||||
|
lastRequestYear = lastRequestYear + 1;
|
||||||
|
}
|
||||||
|
|
||||||
int currentYear = LocalDate.now().getYear();
|
int currentYear = LocalDate.now().getYear();
|
||||||
return Math.max(lastRequestYear + 1, currentYear);
|
return Math.max(lastRequestYear, currentYear);
|
||||||
}
|
}
|
||||||
|
|
||||||
private LocalDate determineStartDate(final Vacation vacation, final int startYear) {
|
private LocalDate determineStartDate(final Vacation vacation, final int startYear) {
|
||||||
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) {
|
if (vacation.getCategory() == TimeOffRequestType.CUMPLEAÑOS && employee.getBirthday() != null) {
|
||||||
return LocalDate.of(startYear, employee.getBirthday().getMonth(), employee.getBirthday().getDayOfMonth());
|
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.PERMISOS_DE_SALUD) {
|
if (vacation.getCategory() == TimeOffRequestType.PERMISOS_DE_SALUD) {
|
||||||
return LocalDate.now();
|
return LocalDate.now();
|
||||||
}
|
}
|
||||||
@ -290,8 +310,24 @@ public class RequestRegisterView extends VerticalLayout {
|
|||||||
private void setPickerValues(final Vacation vacation, final LocalDate startDate) {
|
private void setPickerValues(final Vacation vacation, final LocalDate startDate) {
|
||||||
startDatePicker.setValue(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)
|
if ((vacation.getDuration() != null && vacation.getDuration() == 0.5)
|
||||||
|| vacation.getCategory() == TimeOffRequestType.PERMISOS_DE_SALUD) {
|
|| vacation.getCategory() == TimeOffRequestType.PERMISOS_DE_SALUD
|
||||||
|
|| vacation.getCategory() == TimeOffRequestType.CUMPLEAÑOS) {
|
||||||
|
|
||||||
endDatePicker.setValue(startDate);
|
endDatePicker.setValue(startDate);
|
||||||
} else {
|
} else {
|
||||||
int durationDays = (vacation.getDuration() != null ? vacation.getDuration().intValue() - 1 : 0);
|
int durationDays = (vacation.getDuration() != null ? vacation.getDuration().intValue() - 1 : 0);
|
||||||
@ -330,7 +366,7 @@ public class RequestRegisterView extends VerticalLayout {
|
|||||||
double balanceDays = calculateBalanceDays(availableDays, daysToBeTakenField.getValue());
|
double balanceDays = calculateBalanceDays(availableDays, daysToBeTakenField.getValue());
|
||||||
balanceDaysField.setValue(balanceDays);
|
balanceDaysField.setValue(balanceDays);
|
||||||
|
|
||||||
if (balanceDays < 0) {
|
if (balanceDays < 0.0) {
|
||||||
clearFields();
|
clearFields();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -345,7 +381,12 @@ public class RequestRegisterView extends VerticalLayout {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void setDaysToBeTakenField(final double daysToBeTaken) {
|
private void setDaysToBeTakenField(final double daysToBeTaken) {
|
||||||
if (vacation.getCategory() == TimeOffRequestType.PERMISOS_DE_SALUD) {
|
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) {
|
||||||
daysToBeTakenField.setValue(0.5);
|
daysToBeTakenField.setValue(0.5);
|
||||||
} else {
|
} else {
|
||||||
daysToBeTakenField.setValue(daysToBeTaken);
|
daysToBeTakenField.setValue(daysToBeTaken);
|
||||||
@ -418,7 +459,7 @@ public class RequestRegisterView extends VerticalLayout {
|
|||||||
List<TimeOffRequest> existingRequests =
|
List<TimeOffRequest> existingRequests =
|
||||||
requestService.findByEmployeeAndCategory(employee.getId(), request.getCategory());
|
requestService.findByEmployeeAndCategory(employee.getId(), request.getCategory());
|
||||||
|
|
||||||
int maxRequests = request.getCategory() == TimeOffRequestType.PERMISOS_DE_SALUD ? 4 : 2;
|
int maxRequests = request.getCategory().name().startsWith("VACACION") ? 2 : 1;
|
||||||
|
|
||||||
if (existingRequests.size() >= maxRequests) {
|
if (existingRequests.size() >= maxRequests) {
|
||||||
existingRequests.stream()
|
existingRequests.stream()
|
||||||
|
@ -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, 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, duration, expiration, type) VALUES ('c23e4567-e89b-12d3-a456-42661417400c', 1, 'CUMPLEAÑOS', 0.5, 365, 'OTHER');
|
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-42661417400d', 1, 'MATERNIDAD', 90, 90, '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-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');
|
INSERT INTO vacation (id, version, category, duration, expiration, type) VALUES ('c23e4567-e89b-12d3-a456-42661417400f', 1, 'MATRIMONIO', 3, 3, 'OTHER');
|
||||||
|
Loading…
Reference in New Issue
Block a user