Compare commits

..

2 Commits

3 changed files with 99 additions and 77 deletions

View File

@ -4,7 +4,7 @@
"type": "module",
"dependencies": {
"@f0rce/ace-widget": "1.0.2",
"@polymer/polymer": "3.5.1",
"@polymer/polymer": "3.5.2",
"@vaadin-component-factory/vcf-pdf-viewer": "2.0.1",
"@vaadin/bundles": "24.5.1",
"@vaadin/common-frontend": "0.0.19",
@ -19,29 +19,30 @@
"@vaadin/vaadin-usage-statistics": "2.1.3",
"construct-style-sheets-polyfill": "3.1.0",
"date-fns": "2.29.3",
"lit": "3.1.4",
"lit": "3.2.1",
"print-js": "1.6.0",
"proj4": "2.12.1",
"react": "18.3.1",
"react-dom": "18.3.1",
"react-router-dom": "6.23.1"
"react-router-dom": "6.26.2"
},
"devDependencies": {
"@babel/preset-react": "7.24.7",
"@rollup/plugin-replace": "5.0.7",
"@rollup/pluginutils": "5.1.0",
"@types/react": "18.3.3",
"@types/react-dom": "18.3.0",
"@vitejs/plugin-react": "4.3.1",
"async": "3.2.5",
"glob": "10.4.1",
"@babel/preset-react": "7.25.7",
"@preact/signals-react-transform": "0.4.0",
"@rollup/plugin-replace": "6.0.1",
"@rollup/pluginutils": "5.1.2",
"@types/react": "18.3.11",
"@types/react-dom": "18.3.1",
"@vitejs/plugin-react": "4.3.3",
"async": "3.2.6",
"glob": "10.4.5",
"rollup-plugin-brotli": "3.1.0",
"rollup-plugin-visualizer": "5.12.0",
"strip-css-comments": "5.0.0",
"transform-ast": "2.4.4",
"typescript": "5.4.5",
"vite": "5.3.3",
"vite-plugin-checker": "0.6.4",
"typescript": "5.6.3",
"vite": "5.4.9",
"vite-plugin-checker": "0.8.0",
"workbox-build": "7.1.1",
"workbox-core": "7.1.0",
"workbox-precaching": "7.1.0"
@ -49,7 +50,7 @@
"vaadin": {
"dependencies": {
"@f0rce/ace-widget": "1.0.2",
"@polymer/polymer": "3.5.1",
"@polymer/polymer": "3.5.2",
"@vaadin-component-factory/vcf-pdf-viewer": "2.0.1",
"@vaadin/bundles": "24.5.1",
"@vaadin/common-frontend": "0.0.19",
@ -64,34 +65,35 @@
"@vaadin/vaadin-usage-statistics": "2.1.3",
"construct-style-sheets-polyfill": "3.1.0",
"date-fns": "2.29.3",
"lit": "3.1.4",
"lit": "3.2.1",
"print-js": "1.6.0",
"proj4": "2.12.1",
"react": "18.3.1",
"react-dom": "18.3.1",
"react-router-dom": "6.23.1"
"react-router-dom": "6.26.2"
},
"devDependencies": {
"@babel/preset-react": "7.24.7",
"@rollup/plugin-replace": "5.0.7",
"@rollup/pluginutils": "5.1.0",
"@types/react": "18.3.3",
"@types/react-dom": "18.3.0",
"@vitejs/plugin-react": "4.3.1",
"async": "3.2.5",
"glob": "10.4.1",
"@babel/preset-react": "7.25.7",
"@preact/signals-react-transform": "0.4.0",
"@rollup/plugin-replace": "6.0.1",
"@rollup/pluginutils": "5.1.2",
"@types/react": "18.3.11",
"@types/react-dom": "18.3.1",
"@vitejs/plugin-react": "4.3.3",
"async": "3.2.6",
"glob": "10.4.5",
"rollup-plugin-brotli": "3.1.0",
"rollup-plugin-visualizer": "5.12.0",
"strip-css-comments": "5.0.0",
"transform-ast": "2.4.4",
"typescript": "5.4.5",
"vite": "5.3.3",
"vite-plugin-checker": "0.6.4",
"typescript": "5.6.3",
"vite": "5.4.9",
"vite-plugin-checker": "0.8.0",
"workbox-build": "7.1.1",
"workbox-core": "7.1.0",
"workbox-precaching": "7.1.0"
},
"hash": "1a0f17d48b329307b5862bc57499307d1b89f7d89260121c2b7189f76957c436"
"hash": "2dc40a4f634ae025081ca2239cba00b14a35fe94ab78ac0a4dd3023d882081d5"
},
"overrides": {
"@vaadin/bundles": "$@vaadin/bundles",

View File

@ -24,9 +24,6 @@ import com.vaadin.flow.component.textfield.EmailField;
import com.vaadin.flow.component.textfield.TextField;
import com.vaadin.flow.component.upload.Upload;
import com.vaadin.flow.component.upload.receivers.MemoryBuffer;
import com.vaadin.flow.data.binder.Result;
import com.vaadin.flow.data.binder.ValueContext;
import com.vaadin.flow.data.converter.Converter;
import com.vaadin.flow.data.value.ValueChangeMode;
import com.vaadin.flow.router.*;
import com.vaadin.flow.server.StreamResource;
@ -158,18 +155,6 @@ public class EmployeeView extends BeanValidationForm<Employee> implements HasUrl
configureComponents();
addClassName("main-layout");
getBinder().setConverter("team", new Converter<Object, Object>() {
@Override
public Result<Object> convertToModel(final Object o, final ValueContext valueContext) {
return Result.ok(new Team((String) o));
}
@Override
public Object convertToPresentation(final Object o, final ValueContext valueContext) {
return ((Team) o).getName();
}
});
}
private void configureComponents() {
@ -201,7 +186,7 @@ public class EmployeeView extends BeanValidationForm<Employee> implements HasUrl
initDialog();
}
private void validateNameField(TextField textField, String value) {
private void validateNameField(final TextField textField, final String value) {
if (!value.matches("^[a-zA-ZáéíóúÁÉÍÓÚñÑ\\s]*$")) {
textField.setInvalid(true);
textField.setErrorMessage("Este campo solo debe contener letras.");
@ -332,12 +317,15 @@ public class EmployeeView extends BeanValidationForm<Employee> implements HasUrl
return !firstName.isEmpty() && !lastName.isEmpty() && status.getValue() != null;
}
private void setVacationDuration(Employee employee, TimeOffRequest request, LocalDate referenceDate) {
private void setVacationDuration(
final Employee employee,
final TimeOffRequest request,
final LocalDate referenceDate) {
double yearsOfService = ChronoUnit.YEARS.between(employee.getDateOfEntry(), referenceDate);
request.setAvailableDays(calculateAvailableDays(yearsOfService));
}
private double calculateAvailableDays(double yearsOfService) {
private double calculateAvailableDays(final double yearsOfService) {
if (yearsOfService > 10) {
return 30.0;
} else if (yearsOfService > 5) {
@ -367,51 +355,80 @@ public class EmployeeView extends BeanValidationForm<Employee> implements HasUrl
}
}
private void processTimeOffRequests(Employee employee) {
if (hasTimeOffRequests(employee)) {
updateExistingTimeOffRequests(employee);
} else {
createAndSaveTimeOffRequests(employee);
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 boolean hasTimeOffRequests(Employee employee) {
return !requestService.findByEmployeeAndCategory(employee.getId(), TimeOffRequestType.VACACION_GESTION_ACTUAL).isEmpty() ||
!requestService.findByEmployeeAndCategory(employee.getId(), TimeOffRequestType.VACACION_GESTION_ANTERIOR).isEmpty();
private void deleteExistingTimeOffRequests(final Employee employee) {
deleteTimeOffRequestByCategory(employee, TimeOffRequestType.VACACION_GESTION_ANTERIOR);
deleteTimeOffRequestByCategory(employee, TimeOffRequestType.VACACION_GESTION_ACTUAL);
}
private void updateExistingTimeOffRequests(Employee employee) {
updateTimeOffRequest(employee, TimeOffRequestType.VACACION_GESTION_ANTERIOR, -1, 729);
updateTimeOffRequest(employee, TimeOffRequestType.VACACION_GESTION_ACTUAL, 0, 1094);
}
private void updateTimeOffRequest(Employee employee, TimeOffRequestType category, int yearOffset, int daysToAdd) {
List<TimeOffRequest> requests = requestService.findByEmployeeAndCategory(employee.getId(), category);
private void deleteTimeOffRequestByCategory(final Employee employee, final TimeOffRequestType category) {
var requests = requestService.findByEmployeeAndCategory(employee.getId(), category);
if (!requests.isEmpty()) {
TimeOffRequest request = requests.getLast();
LocalDate newBaseDate = LocalDate.of(LocalDate.now().getYear() + yearOffset, employee.getDateOfEntry().getMonth(), employee.getDateOfEntry().getDayOfMonth());
request.setExpiration(newBaseDate.plusDays(daysToAdd));
setVacationDuration(employee, request, newBaseDate);
requestService.saveTimeOffRequest(request);
requestService.deleteTimeOffRequest(requests.getFirst().getId());
}
}
private void createAndSaveTimeOffRequests(Employee employee) {
requestService.saveTimeOffRequest(createTimeOffRequest(employee, TimeOffRequestType.VACACION_GESTION_ANTERIOR, -1, 729));
requestService.saveTimeOffRequest(createTimeOffRequest(employee, TimeOffRequestType.VACACION_GESTION_ACTUAL, 0, 1094));
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 TimeOffRequest createTimeOffRequest(Employee employee, TimeOffRequestType category, int yearOffset, int daysToAdd) {
LocalDate baseDate = LocalDate.of(LocalDate.now().getYear() + yearOffset, employee.getDateOfEntry().getMonth(), employee.getDateOfEntry().getDayOfMonth());
LocalDate expirationDate = baseDate.plusDays(daysToAdd);
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.setEmployee(employee);
request.setExpiration(expirationDate);
request.setExpiration(baseDate.plusDays(expirationDays));
setVacationDuration(employee, request, baseDate);
return request;
}

View File

@ -428,7 +428,10 @@ public class RequestRegisterView extends VerticalLayout {
}
private void handleVacationRequest(final TimeOffRequest request) {
List<TimeOffRequest> existingRequests = requestService.findByEmployeeAndCategory(employee.getId(), TimeOffRequestType.VACACION_GESTION_ACTUAL);
List<TimeOffRequest> existingRequests = requestService.findByEmployeeAndCategory(
employee.getId(),
TimeOffRequestType.VACACION_GESTION_ACTUAL
);
if (!existingRequests.isEmpty()) {
TimeOffRequest existingRequest = existingRequests.getFirst();
existingRequest.setCategory(TimeOffRequestType.VACACION_GESTION_ANTERIOR);