Compare commits
No commits in common. "8e1f0fdd7d13da3038b04a8cebd284ec10c0fc4e" and "efca245c1db45de90f09643f3beb685b6d365ca3" have entirely different histories.
8e1f0fdd7d
...
efca245c1d
@ -57,8 +57,7 @@ public class TimeOffRequestService {
|
||||
LocalDate now = LocalDate.now();
|
||||
|
||||
for (TimeOffRequest request : requests) {
|
||||
if (request.getState() == TimeOffRequestStatus.APROBADO
|
||||
|| request.getState() == TimeOffRequestStatus.EN_USO) {
|
||||
if (request.getState() == TimeOffRequestStatus.APROBADO) {
|
||||
LocalDate startDate = request.getStartDate();
|
||||
LocalDate endDate = request.getEndDate();
|
||||
|
||||
|
@ -113,7 +113,7 @@ public class PendingRequestsListView extends Main {
|
||||
final Team team,
|
||||
final TimeOffRequestType category) {
|
||||
List<TimeOffRequest> filteredPendingRequests
|
||||
= requestService.findRequestsByState(TimeOffRequestStatus.SOLICITADO);
|
||||
= requestService.findRequestsByState(TimeOffRequestStatus.PENDIENTE);
|
||||
|
||||
if (employee != null && !"TODOS".equals(employee.getFirstName())) {
|
||||
filteredPendingRequests = filteredPendingRequests.stream()
|
||||
|
@ -127,7 +127,6 @@ public class RequestEmployeeView extends Div implements HasUrlParameter<String>
|
||||
private VerticalLayout createSummaryLayout() {
|
||||
Employee employee = employeeService.getEmployee(employeeId);
|
||||
boolean isMale = employee.getGender() == Employee.Gender.MALE;
|
||||
int currentYear = LocalDate.now().getYear();
|
||||
|
||||
List<Vacation> vacations = vacationService.findVacations();
|
||||
|
||||
@ -135,9 +134,9 @@ public class RequestEmployeeView extends Div implements HasUrlParameter<String>
|
||||
double totalPersonalDays = calculatePersonalDays(vacations, isMale);
|
||||
double totalVacationDays = calculateVacationDays(employee);
|
||||
|
||||
double utilizedFixedAndMovableHolidays = calculateHolidayUtilizedDays(currentYear);
|
||||
double utilizedVacationDays = calculateVacationUtilizedDays(currentYear);
|
||||
double utilizedPersonalDays = calculatePersonalDaysUtilized(isMale, currentYear);
|
||||
double utilizedFixedAndMovableHolidays = calculateHolidayUtilizedDays();
|
||||
double utilizedVacationDays = calculateVacationUtilizedDays();
|
||||
double utilizedPersonalDays = calculatePersonalDaysUtilized(isMale);
|
||||
|
||||
double remainingHolidayDays = totalFixedAndMovableHolidays - utilizedFixedAndMovableHolidays;
|
||||
double remainingPersonalDays = totalPersonalDays - utilizedPersonalDays;
|
||||
@ -149,7 +148,7 @@ public class RequestEmployeeView extends Div implements HasUrlParameter<String>
|
||||
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 general de días disponibles: " + totalAvailableDays)
|
||||
);
|
||||
}
|
||||
|
||||
@ -213,40 +212,30 @@ public class RequestEmployeeView extends Div implements HasUrlParameter<String>
|
||||
}
|
||||
}
|
||||
|
||||
private double calculateHolidayUtilizedDays(final int year) {
|
||||
private double calculateHolidayUtilizedDays() {
|
||||
return requests.stream()
|
||||
.filter(this::verificationIsHoliday)
|
||||
.filter(req -> getStartDateYear(req) == year)
|
||||
.mapToDouble(TimeOffRequest::getDaysToBeTake)
|
||||
.mapToDouble(TimeOffRequest::getAvailableDays)
|
||||
.sum();
|
||||
}
|
||||
|
||||
private double calculateVacationUtilizedDays(final int year) {
|
||||
private double calculateVacationUtilizedDays() {
|
||||
return requests.stream()
|
||||
.filter(req -> req.getCategory().name().startsWith("VACACION"))
|
||||
.filter(req -> getStartDateYear(req) == year || getStartDateYear(req) == year - 1)
|
||||
.mapToDouble(TimeOffRequest::getDaysToBeTake)
|
||||
.filter(req -> req.getCategory() == TimeOffRequestType.VACACION_GESTION_ACTUAL)
|
||||
.mapToDouble(TimeOffRequest::getAvailableDays)
|
||||
.sum();
|
||||
}
|
||||
|
||||
private double calculatePersonalDaysUtilized(final boolean isMale, final int year) {
|
||||
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"))
|
||||
.filter(req -> getStartDateYear(req) == year)
|
||||
.mapToDouble(TimeOffRequest::getDaysToBeTake)
|
||||
.mapToDouble(TimeOffRequest::getAvailableDays)
|
||||
.sum();
|
||||
}
|
||||
|
||||
private int getStartDateYear(TimeOffRequest request) {
|
||||
if (request.getStartDate() != null) {
|
||||
return request.getStartDate().getYear();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
private double calculateVacationDaysSinceEntry(final LocalDate dateOfEntry, final LocalDate date) {
|
||||
int yearsOfService = dateOfEntry != null ? Period.between(dateOfEntry, date).getYears() : 0;
|
||||
if (yearsOfService > 10) {
|
||||
@ -312,9 +301,7 @@ public class RequestEmployeeView extends Div implements HasUrlParameter<String>
|
||||
final int pageSize,
|
||||
final TimeOffRequestType category,
|
||||
final TimeOffRequestStatus state) {
|
||||
|
||||
requests = requestService.findRequestsByEmployeeId(employeeId);
|
||||
generateRequests();
|
||||
if (category != null && !"TODOS".equals(category.name())) {
|
||||
requests = requests.stream()
|
||||
.filter(req -> req.getCategory().equals(category))
|
||||
@ -329,58 +316,6 @@ public class RequestEmployeeView extends Div implements HasUrlParameter<String>
|
||||
return requests.subList(start, end);
|
||||
}
|
||||
|
||||
public void generateRequests() {
|
||||
boolean isMale = isEmployeeMale();
|
||||
|
||||
for (TimeOffRequestType type : TimeOffRequestType.values()) {
|
||||
if (shouldIncludeRequest(type) && isValidRequestType(type, isMale)) {
|
||||
TimeOffRequest request = createRequest(type);
|
||||
if (isVacationExpired(request)) {
|
||||
request.setState(TimeOffRequestStatus.VENCIDO);
|
||||
} else {
|
||||
request.setState(TimeOffRequestStatus.PENDIENTE);
|
||||
}
|
||||
requests.add(request);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isEmployeeMale() {
|
||||
return employeeService.getEmployee(employeeId).getGender() == Employee.Gender.MALE;
|
||||
}
|
||||
|
||||
private boolean isValidRequestType(TimeOffRequestType type, boolean isMale) {
|
||||
return !getStandardExclusions().contains(type)
|
||||
&& !(isMale && getMaleSpecificExclusions().contains(type))
|
||||
&& type != TimeOffRequestType.TODOS;
|
||||
}
|
||||
|
||||
private TimeOffRequest createRequest(TimeOffRequestType type) {
|
||||
TimeOffRequest request = new TimeOffRequest();
|
||||
request.setCategory(type);
|
||||
return request;
|
||||
}
|
||||
|
||||
private boolean isVacationExpired(TimeOffRequest request) {
|
||||
Vacation vacation = vacationService.findVacationByCategory(request.getCategory());
|
||||
|
||||
if (vacation != null && vacation.getMonthOfYear() != null && vacation.getDayOfMonth() != null) {
|
||||
int vacationMonth = vacation.getMonthOfYear();
|
||||
int vacationDay = vacation.getDayOfMonth();
|
||||
int currentMonth = LocalDate.now().getMonthValue();
|
||||
int currentDay = LocalDate.now().getDayOfMonth();
|
||||
|
||||
return vacationMonth < currentMonth || (vacationMonth == currentMonth && vacationDay < currentDay);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private boolean shouldIncludeRequest(TimeOffRequestType type) {
|
||||
List<TimeOffRequest> existingRequest = requestService.findByEmployeeAndCategory(employeeId, type);
|
||||
return existingRequest.isEmpty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setParameter(final BeforeEvent event, final String parameter) {
|
||||
employeeId = UUID.fromString(parameter);
|
||||
|
@ -312,6 +312,20 @@ 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) {
|
||||
@ -439,7 +453,7 @@ public class RequestRegisterView extends VerticalLayout {
|
||||
request.setStartDate(startDatePicker.getValue());
|
||||
request.setAvailableDays(availableDaysField.getValue());
|
||||
request.setExpiration(endDate != null ? endDate : endDatePicker.getValue());
|
||||
request.setState(TimeOffRequestStatus.SOLICITADO);
|
||||
request.setState(TimeOffRequestStatus.PENDIENTE);
|
||||
return request;
|
||||
}
|
||||
|
||||
@ -447,15 +461,7 @@ public class RequestRegisterView extends VerticalLayout {
|
||||
List<TimeOffRequest> existingRequests =
|
||||
requestService.findByEmployeeAndCategory(employee.getId(), request.getCategory());
|
||||
|
||||
int maxRequests;
|
||||
|
||||
if (request.getCategory() == TimeOffRequestType.PERMISOS_DE_SALUD) {
|
||||
maxRequests = 4;
|
||||
} else if (request.getCategory().name().startsWith("VACACION")) {
|
||||
maxRequests = 2;
|
||||
} else {
|
||||
maxRequests = 1;
|
||||
}
|
||||
int maxRequests = request.getCategory().name().startsWith("VACACION") ? 2 : 1;
|
||||
|
||||
if (existingRequests.size() >= maxRequests) {
|
||||
existingRequests.stream()
|
||||
|
@ -192,13 +192,8 @@ public class RequestsListView extends Main {
|
||||
}
|
||||
|
||||
private double calculateTotalUtilized(final List<TimeOffRequest> employeeRequests) {
|
||||
int currentYear = LocalDate.now().getYear();
|
||||
return employeeRequests.stream()
|
||||
.filter(Objects::nonNull)
|
||||
.filter(request -> request.getStartDate() != null && (
|
||||
request.getStartDate().getYear() == currentYear ||
|
||||
(request.getCategory().name().startsWith("VACACION") && request.getStartDate().getYear() == currentYear - 1)
|
||||
))
|
||||
.mapToDouble(request -> request.getDaysToBeTake() != null ? request.getDaysToBeTake() : 0.0)
|
||||
.sum();
|
||||
}
|
||||
|
@ -74,19 +74,19 @@ values ('9a6f12ba-e111-4e7a-b8a6-caa0982bd8a1', 1, '5c6f11fe-c341-4be7-a9a6-bba0
|
||||
insert into time_off_request (id, version, employee_id, category, state, available_days, expiration, start_date, end_date, days_to_be_take, days_balance)
|
||||
values ('9b6f12ba-e222-4e7a-b8a6-caa0982bd8b2', 1, '5c6f11fe-c341-4be7-a9a6-bba0081ad7c6', 'LUNES_CARNAVAL', 'APROBADO', 1, '2025-02-12', '2025-02-12', '2025-02-12', 1, 0);
|
||||
insert into time_off_request (id, version, employee_id, category, state, available_days, expiration, start_date, end_date, days_to_be_take, days_balance)
|
||||
values ('9c6f12ba-e333-4e7a-b8a6-caa0982bd8c3', 1, '5c6f11fe-c341-4be7-a9a6-bba0081ad7c6', 'MARTES_CARNAVAL', 'SOLICITADO', 1, '2025-02-13', '2025-02-13', '2025-02-13', 1, 0);
|
||||
values ('9c6f12ba-e333-4e7a-b8a6-caa0982bd8c3', 1, '5c6f11fe-c341-4be7-a9a6-bba0081ad7c6', 'MARTES_CARNAVAL', 'PENDIENTE', 1, '2025-02-13', '2025-02-13', '2025-02-13', 1, 0);
|
||||
insert into time_off_request (id, version, employee_id, category, state, available_days, expiration, start_date, end_date, days_to_be_take, days_balance)
|
||||
values ('9d6f12ba-e444-4e7a-b8a6-caa0982bd8d4', 1, '5c6f11fe-c341-4be7-a9a6-bba0081ad7c6', 'VIERNES_SANTO', 'APROBADO', 1, '2024-03-29', '2024-03-29', '2024-03-29', 1, 0);
|
||||
insert into time_off_request (id, version, employee_id, category, state, available_days, expiration, start_date, end_date, days_to_be_take, days_balance)
|
||||
values ('9e6f12ba-e555-4e7a-b8a6-caa0982bd8e5', 1, '5c6f11fe-c341-4be7-a9a6-bba0081ad7c6', 'VACACION_GESTION_ACTUAL', 'APROBADO', 30, '2025-11-01', '2023-11-01', '2023-11-30', 30, 0);
|
||||
values ('9e6f12ba-e555-4e7a-b8a6-caa0982bd8e5', 1, '5c6f11fe-c341-4be7-a9a6-bba0081ad7c6', 'VACACION_GESTION_ACTUAL', 'APROBADO', 30, '2024-11-01', '2022-11-01', '2022-11-30', 30, 0);
|
||||
|
||||
insert into time_off_request (id, version, employee_id, category, state, available_days, expiration, start_date, end_date, days_to_be_take, days_balance)
|
||||
values ('8c653f2a-f9a3-4d67-b3b6-12ad98fe0983', 1, 'f6ab3c6d-7078-45f6-9b22-4e37637bfec6', 'DIA_DEL_TRABAJADOR', 'APROBADO', 1, '2024-05-01', '2024-05-01', '2024-05-01', 1, 0);
|
||||
insert into time_off_request (id, version, employee_id, category, state, available_days, expiration, start_date, end_date, days_to_be_take, days_balance)
|
||||
values ('fb9d9d75-b2ab-4ea4-b8b3-0a8f89e5c123', 1, '2e2293b1-3f9a-4f3d-abc8-32639b0a5e15', 'DIA_DE_LA_INDEPENDENCIA', 'APROBADO', 1, '2024-08-06', '2024-08-06', '2024-08-06', 1, 0);
|
||||
insert into time_off_request (id, version, employee_id, category, state, available_days, expiration, start_date, end_date, days_to_be_take, days_balance)
|
||||
values ('6fdc47a8-127b-41c4-8d12-7fc12098ab12', 1, 'b2436b82-7b9f-4f0d-9463-f2c3173a45c3', 'DIA_DE_TODOS_LOS_DIFUNTOS', 'SOLICITADO', 1, '2025-12-01', '2025-11-02', '2025-11-02', 1, 0);
|
||||
values ('6fdc47a8-127b-41c4-8d12-7fc12098ab12', 1, 'b2436b82-7b9f-4f0d-9463-f2c3173a45c3', 'DIA_DE_TODOS_LOS_DIFUNTOS', 'PENDIENTE', 1, '2025-12-01', '2025-11-02', '2025-11-02', 1, 0);
|
||||
insert into time_off_request (id, version, employee_id, category, state, available_days, expiration, start_date, end_date, days_to_be_take, days_balance)
|
||||
values ('12ec8b74-983d-4a17-b67e-134f45ae904c', 1, '5c1a7b82-832d-4f24-8377-54b77b91b6a8', 'AÑO_NUEVO', 'SOLICITADO', 1, '2025-01-01', '2025-01-01', '2025-01-01', 1, 0);
|
||||
values ('12ec8b74-983d-4a17-b67e-134f45ae904c', 1, '5c1a7b82-832d-4f24-8377-54b77b91b6a8', 'AÑO_NUEVO', 'PENDIENTE', 1, '2025-01-01', '2025-01-01', '2025-01-01', 1, 0);
|
||||
insert into time_off_request (id, version, employee_id, category, state, available_days, expiration, start_date, end_date, days_to_be_take, days_balance)
|
||||
values ('89bc4b2a-943f-487c-a9f3-bacf78145e67', 1, 'cba3efb7-32bc-44be-9fdc-fc5e4f211254', 'LUNES_CARNAVAL', 'APROBADO', 1, '2024-02-12', '2024-02-12', '2024-02-12', 1, 0);
|
||||
|
Loading…
Reference in New Issue
Block a user