Compare commits

..

No commits in common. "d3fdb128b76d41577469541dfa51fdcc9bee36f6" and "9a29f91994443f759c649acc2c0ca7b5347c1057" have entirely different histories.

3 changed files with 77 additions and 99 deletions

View File

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

View File

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

View File

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