Descarte funcionalidad generar automaticamente solicitud vacacion
All checks were successful
PR Builder / Build-PR (pull_request) Successful in 2m42s
All checks were successful
PR Builder / Build-PR (pull_request) Successful in 2m42s
This commit is contained in:
parent
d3fdb128b7
commit
cb34868b9c
@ -343,10 +343,6 @@ public class EmployeeView extends BeanValidationForm<Employee> implements HasUrl
|
|||||||
employee.setStatus(status.getValue());
|
employee.setStatus(status.getValue());
|
||||||
employee.setAge(age.getValue());
|
employee.setAge(age.getValue());
|
||||||
|
|
||||||
if (employee.getDateOfEntry() != null) {
|
|
||||||
processTimeOffRequests(employee);
|
|
||||||
}
|
|
||||||
|
|
||||||
employeeService.createOrUpdate(employee);
|
employeeService.createOrUpdate(employee);
|
||||||
Notification.show(NOTIFICATION_SAVE_SUCCESS);
|
Notification.show(NOTIFICATION_SAVE_SUCCESS);
|
||||||
getUI().ifPresent(ui -> ui.navigate(EmployeesListView.class));
|
getUI().ifPresent(ui -> ui.navigate(EmployeesListView.class));
|
||||||
@ -355,83 +351,6 @@ public class EmployeeView extends BeanValidationForm<Employee> implements HasUrl
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void processTimeOffRequests(final Employee employee) {
|
|
||||||
boolean isCurrentYearEntry = employee.getDateOfEntry().getYear() == LocalDate.now().getYear();
|
|
||||||
|
|
||||||
deleteExistingTimeOffRequests(employee);
|
|
||||||
|
|
||||||
if (isCurrentYearEntry) {
|
|
||||||
saveCurrentYearRequest(employee);
|
|
||||||
} else if (LocalDate.now().getYear() > employee.getDateOfEntry().getYear()) {
|
|
||||||
savePreviousAndCurrentYearRequests(employee);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void deleteExistingTimeOffRequests(final Employee employee) {
|
|
||||||
deleteTimeOffRequestByCategory(employee, TimeOffRequestType.VACACION_GESTION_ANTERIOR);
|
|
||||||
deleteTimeOffRequestByCategory(employee, TimeOffRequestType.VACACION_GESTION_ACTUAL);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void deleteTimeOffRequestByCategory(final Employee employee, final TimeOffRequestType category) {
|
|
||||||
var requests = requestService.findByEmployeeAndCategory(employee.getId(), category);
|
|
||||||
if (!requests.isEmpty()) {
|
|
||||||
requestService.deleteTimeOffRequest(requests.getFirst().getId());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void saveCurrentYearRequest(final Employee employee) {
|
|
||||||
LocalDate baseDate = LocalDate.of(
|
|
||||||
LocalDate.now().getYear(),
|
|
||||||
employee.getDateOfEntry().getMonth(),
|
|
||||||
employee.getDateOfEntry().getDayOfMonth()
|
|
||||||
);
|
|
||||||
TimeOffRequest currentRequest = createTimeOffRequest(
|
|
||||||
employee,
|
|
||||||
TimeOffRequestType.VACACION_GESTION_ACTUAL,
|
|
||||||
baseDate,
|
|
||||||
729
|
|
||||||
);
|
|
||||||
requestService.saveTimeOffRequest(currentRequest);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void savePreviousAndCurrentYearRequests(final Employee employee) {
|
|
||||||
LocalDate previousBaseDate = LocalDate.of(
|
|
||||||
LocalDate.now().getYear() - 1,
|
|
||||||
employee.getDateOfEntry().getMonth(),
|
|
||||||
employee.getDateOfEntry().getDayOfMonth()
|
|
||||||
);
|
|
||||||
TimeOffRequest previousRequest = createTimeOffRequest(
|
|
||||||
employee,
|
|
||||||
TimeOffRequestType.VACACION_GESTION_ANTERIOR,
|
|
||||||
previousBaseDate,
|
|
||||||
729
|
|
||||||
);
|
|
||||||
|
|
||||||
LocalDate currentBaseDate = previousBaseDate.plusYears(1);
|
|
||||||
TimeOffRequest currentRequest = createTimeOffRequest(
|
|
||||||
employee,
|
|
||||||
TimeOffRequestType.VACACION_GESTION_ACTUAL,
|
|
||||||
currentBaseDate,
|
|
||||||
1094
|
|
||||||
);
|
|
||||||
|
|
||||||
requestService.saveTimeOffRequest(previousRequest);
|
|
||||||
requestService.saveTimeOffRequest(currentRequest);
|
|
||||||
}
|
|
||||||
|
|
||||||
private TimeOffRequest createTimeOffRequest(final Employee employee,
|
|
||||||
final TimeOffRequestType category,
|
|
||||||
final LocalDate baseDate,
|
|
||||||
final int expirationDays) {
|
|
||||||
TimeOffRequest request = new TimeOffRequest();
|
|
||||||
request.setEmployee(employee);
|
|
||||||
request.setCategory(category);
|
|
||||||
request.setState(TimeOffRequestStatus.APROBADO);
|
|
||||||
request.setExpiration(baseDate.plusDays(expirationDays));
|
|
||||||
setVacationDuration(employee, request, baseDate);
|
|
||||||
return request;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void enableEditMode() {
|
private void enableEditMode() {
|
||||||
setFieldsEditable();
|
setFieldsEditable();
|
||||||
saveButton.setVisible(true);
|
saveButton.setVisible(true);
|
||||||
|
@ -122,7 +122,7 @@ public class RequestEmployeeView extends Div implements HasUrlParameter<String>
|
|||||||
double totalAvailableDays = totalHoliday + totalVacations + totalPersonalDays;
|
double totalAvailableDays = totalHoliday + totalVacations + totalPersonalDays;
|
||||||
|
|
||||||
return new VerticalLayout(
|
return new VerticalLayout(
|
||||||
new Span("Total días libres: " + totalHoliday),
|
new Span("Total feriados: " + totalHoliday),
|
||||||
new Span("Total vacaciones: " + totalVacations),
|
new Span("Total vacaciones: " + totalVacations),
|
||||||
new Span("Total días personales: " + totalPersonalDays),
|
new Span("Total días personales: " + totalPersonalDays),
|
||||||
new Span("Total general: " + totalAvailableDays)
|
new Span("Total general: " + totalAvailableDays)
|
||||||
|
Loading…
Reference in New Issue
Block a user