En-desarrollo #71

Merged
alex merged 10 commits from En-desarrollo into main 2024-11-15 00:24:15 +00:00
4 changed files with 78 additions and 27 deletions
Showing only changes of commit 9579b33acc - Show all commits

View File

@ -113,7 +113,7 @@ public class PendingRequestsListView extends Main {
final Team team, final Team team,
final TimeOffRequestType category) { final TimeOffRequestType category) {
List<TimeOffRequest> filteredPendingRequests List<TimeOffRequest> filteredPendingRequests
= requestService.findRequestsByState(TimeOffRequestStatus.PENDIENTE); = requestService.findRequestsByState(TimeOffRequestStatus.SOLICITADO);
if (employee != null && !"TODOS".equals(employee.getFirstName())) { if (employee != null && !"TODOS".equals(employee.getFirstName())) {
filteredPendingRequests = filteredPendingRequests.stream() filteredPendingRequests = filteredPendingRequests.stream()

View File

@ -127,6 +127,7 @@ public class RequestEmployeeView extends Div implements HasUrlParameter<String>
private VerticalLayout createSummaryLayout() { private VerticalLayout createSummaryLayout() {
Employee employee = employeeService.getEmployee(employeeId); Employee employee = employeeService.getEmployee(employeeId);
boolean isMale = employee.getGender() == Employee.Gender.MALE; boolean isMale = employee.getGender() == Employee.Gender.MALE;
int currentYear = LocalDate.now().getYear();
List<Vacation> vacations = vacationService.findVacations(); List<Vacation> vacations = vacationService.findVacations();
@ -134,9 +135,9 @@ public class RequestEmployeeView extends Div implements HasUrlParameter<String>
double totalPersonalDays = calculatePersonalDays(vacations, isMale); double totalPersonalDays = calculatePersonalDays(vacations, isMale);
double totalVacationDays = calculateVacationDays(employee); double totalVacationDays = calculateVacationDays(employee);
double utilizedFixedAndMovableHolidays = calculateHolidayUtilizedDays(); double utilizedFixedAndMovableHolidays = calculateHolidayUtilizedDays(currentYear);
double utilizedVacationDays = calculateVacationUtilizedDays(); double utilizedVacationDays = calculateVacationUtilizedDays(currentYear);
double utilizedPersonalDays = calculatePersonalDaysUtilized(isMale); double utilizedPersonalDays = calculatePersonalDaysUtilized(isMale, currentYear);
double remainingHolidayDays = totalFixedAndMovableHolidays - utilizedFixedAndMovableHolidays; double remainingHolidayDays = totalFixedAndMovableHolidays - utilizedFixedAndMovableHolidays;
double remainingPersonalDays = totalPersonalDays - utilizedPersonalDays; double remainingPersonalDays = totalPersonalDays - utilizedPersonalDays;
@ -148,7 +149,7 @@ public class RequestEmployeeView extends Div implements HasUrlParameter<String>
new Span("Total feriados fijos y movibles: " + remainingHolidayDays), new Span("Total feriados fijos y movibles: " + remainingHolidayDays),
new Span("Total días libres personales: " + remainingPersonalDays), new Span("Total días libres personales: " + remainingPersonalDays),
new Span("Total vacaciones pendientes de uso: " + remainingVacationDays), 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)
); );
} }
@ -212,30 +213,40 @@ public class RequestEmployeeView extends Div implements HasUrlParameter<String>
} }
} }
private double calculateHolidayUtilizedDays() { private double calculateHolidayUtilizedDays(final int year) {
return requests.stream() return requests.stream()
.filter(this::verificationIsHoliday) .filter(this::verificationIsHoliday)
.filter(req -> getStartDateYear(req) == year)
.mapToDouble(TimeOffRequest::getAvailableDays) .mapToDouble(TimeOffRequest::getAvailableDays)
.sum(); .sum();
} }
private double calculateVacationUtilizedDays() { private double calculateVacationUtilizedDays(final int year) {
return requests.stream() return requests.stream()
.filter(req -> req.getCategory() == TimeOffRequestType.VACACION_GESTION_ACTUAL) .filter(req -> req.getCategory() == TimeOffRequestType.VACACION_GESTION_ACTUAL)
.filter(req -> getStartDateYear(req) == year)
.mapToDouble(TimeOffRequest::getAvailableDays) .mapToDouble(TimeOffRequest::getAvailableDays)
.sum(); .sum();
} }
private double calculatePersonalDaysUtilized(final boolean isMale) { private double calculatePersonalDaysUtilized(final boolean isMale, final int year) {
return requests.stream() return requests.stream()
.filter(req -> !verificationIsHoliday(req)) .filter(req -> !verificationIsHoliday(req))
.filter(req -> !getStandardExclusions().contains(req.getCategory())) .filter(req -> !getStandardExclusions().contains(req.getCategory()))
.filter(req -> !(isMale && getMaleSpecificExclusions().contains(req.getCategory()))) .filter(req -> !(isMale && getMaleSpecificExclusions().contains(req.getCategory())))
.filter(req -> !req.getCategory().name().startsWith("VACACION")) .filter(req -> !req.getCategory().name().startsWith("VACACION"))
.filter(req -> getStartDateYear(req) == year)
.mapToDouble(TimeOffRequest::getAvailableDays) .mapToDouble(TimeOffRequest::getAvailableDays)
.sum(); .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) { private double calculateVacationDaysSinceEntry(final LocalDate dateOfEntry, final LocalDate date) {
int yearsOfService = dateOfEntry != null ? Period.between(dateOfEntry, date).getYears() : 0; int yearsOfService = dateOfEntry != null ? Period.between(dateOfEntry, date).getYears() : 0;
if (yearsOfService > 10) { if (yearsOfService > 10) {
@ -301,7 +312,9 @@ public class RequestEmployeeView extends Div implements HasUrlParameter<String>
final int pageSize, final int pageSize,
final TimeOffRequestType category, final TimeOffRequestType category,
final TimeOffRequestStatus state) { final TimeOffRequestStatus state) {
requests = requestService.findRequestsByEmployeeId(employeeId); requests = requestService.findRequestsByEmployeeId(employeeId);
generateRequests();
if (category != null && !"TODOS".equals(category.name())) { if (category != null && !"TODOS".equals(category.name())) {
requests = requests.stream() requests = requests.stream()
.filter(req -> req.getCategory().equals(category)) .filter(req -> req.getCategory().equals(category))
@ -316,6 +329,58 @@ public class RequestEmployeeView extends Div implements HasUrlParameter<String>
return requests.subList(start, end); 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 @Override
public void setParameter(final BeforeEvent event, final String parameter) { public void setParameter(final BeforeEvent event, final String parameter) {
employeeId = UUID.fromString(parameter); employeeId = UUID.fromString(parameter);

View File

@ -310,21 +310,7 @@ 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
@ -453,7 +439,7 @@ public class RequestRegisterView extends VerticalLayout {
request.setStartDate(startDatePicker.getValue()); request.setStartDate(startDatePicker.getValue());
request.setAvailableDays(availableDaysField.getValue()); request.setAvailableDays(availableDaysField.getValue());
request.setExpiration(endDate != null ? endDate : endDatePicker.getValue()); request.setExpiration(endDate != null ? endDate : endDatePicker.getValue());
request.setState(TimeOffRequestStatus.PENDIENTE); request.setState(TimeOffRequestStatus.SOLICITADO);
return request; return request;
} }

View File

@ -74,7 +74,7 @@ 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) 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); 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) 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', 'PENDIENTE', 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', 'SOLICITADO', 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) 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); 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) insert into time_off_request (id, version, employee_id, category, state, available_days, expiration, start_date, end_date, days_to_be_take, days_balance)
@ -85,8 +85,8 @@ values ('8c653f2a-f9a3-4d67-b3b6-12ad98fe0983', 1, 'f6ab3c6d-7078-45f6-9b22-4e37
insert into time_off_request (id, version, employee_id, category, state, available_days, expiration, start_date, end_date, days_to_be_take, days_balance) 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); 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) 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', 'PENDIENTE', 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', 'SOLICITADO', 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) 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', 'PENDIENTE', 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', 'SOLICITADO', 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) 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); 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);