Compare commits
2 Commits
9a29f91994
...
d3fdb128b7
Author | SHA1 | Date | |
---|---|---|---|
d3fdb128b7 | |||
91aad85146 |
60
package.json
60
package.json
@ -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.1",
|
"@polymer/polymer": "3.5.2",
|
||||||
"@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,29 +19,30 @@
|
|||||||
"@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.1.4",
|
"lit": "3.2.1",
|
||||||
"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.23.1"
|
"react-router-dom": "6.26.2"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@babel/preset-react": "7.24.7",
|
"@babel/preset-react": "7.25.7",
|
||||||
"@rollup/plugin-replace": "5.0.7",
|
"@preact/signals-react-transform": "0.4.0",
|
||||||
"@rollup/pluginutils": "5.1.0",
|
"@rollup/plugin-replace": "6.0.1",
|
||||||
"@types/react": "18.3.3",
|
"@rollup/pluginutils": "5.1.2",
|
||||||
"@types/react-dom": "18.3.0",
|
"@types/react": "18.3.11",
|
||||||
"@vitejs/plugin-react": "4.3.1",
|
"@types/react-dom": "18.3.1",
|
||||||
"async": "3.2.5",
|
"@vitejs/plugin-react": "4.3.3",
|
||||||
"glob": "10.4.1",
|
"async": "3.2.6",
|
||||||
|
"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.4.5",
|
"typescript": "5.6.3",
|
||||||
"vite": "5.3.3",
|
"vite": "5.4.9",
|
||||||
"vite-plugin-checker": "0.6.4",
|
"vite-plugin-checker": "0.8.0",
|
||||||
"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"
|
||||||
@ -49,7 +50,7 @@
|
|||||||
"vaadin": {
|
"vaadin": {
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@f0rce/ace-widget": "1.0.2",
|
"@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-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",
|
||||||
@ -64,34 +65,35 @@
|
|||||||
"@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.1.4",
|
"lit": "3.2.1",
|
||||||
"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.23.1"
|
"react-router-dom": "6.26.2"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@babel/preset-react": "7.24.7",
|
"@babel/preset-react": "7.25.7",
|
||||||
"@rollup/plugin-replace": "5.0.7",
|
"@preact/signals-react-transform": "0.4.0",
|
||||||
"@rollup/pluginutils": "5.1.0",
|
"@rollup/plugin-replace": "6.0.1",
|
||||||
"@types/react": "18.3.3",
|
"@rollup/pluginutils": "5.1.2",
|
||||||
"@types/react-dom": "18.3.0",
|
"@types/react": "18.3.11",
|
||||||
"@vitejs/plugin-react": "4.3.1",
|
"@types/react-dom": "18.3.1",
|
||||||
"async": "3.2.5",
|
"@vitejs/plugin-react": "4.3.3",
|
||||||
"glob": "10.4.1",
|
"async": "3.2.6",
|
||||||
|
"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.4.5",
|
"typescript": "5.6.3",
|
||||||
"vite": "5.3.3",
|
"vite": "5.4.9",
|
||||||
"vite-plugin-checker": "0.6.4",
|
"vite-plugin-checker": "0.8.0",
|
||||||
"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": "1a0f17d48b329307b5862bc57499307d1b89f7d89260121c2b7189f76957c436"
|
"hash": "2dc40a4f634ae025081ca2239cba00b14a35fe94ab78ac0a4dd3023d882081d5"
|
||||||
},
|
},
|
||||||
"overrides": {
|
"overrides": {
|
||||||
"@vaadin/bundles": "$@vaadin/bundles",
|
"@vaadin/bundles": "$@vaadin/bundles",
|
||||||
|
@ -24,9 +24,6 @@ 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;
|
||||||
@ -158,18 +155,6 @@ 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() {
|
||||||
@ -201,7 +186,7 @@ public class EmployeeView extends BeanValidationForm<Employee> implements HasUrl
|
|||||||
initDialog();
|
initDialog();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void validateNameField(TextField textField, String value) {
|
private void validateNameField(final TextField textField, final 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.");
|
||||||
@ -332,12 +317,15 @@ 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(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);
|
double yearsOfService = ChronoUnit.YEARS.between(employee.getDateOfEntry(), referenceDate);
|
||||||
request.setAvailableDays(calculateAvailableDays(yearsOfService));
|
request.setAvailableDays(calculateAvailableDays(yearsOfService));
|
||||||
}
|
}
|
||||||
|
|
||||||
private double calculateAvailableDays(double yearsOfService) {
|
private double calculateAvailableDays(final double yearsOfService) {
|
||||||
if (yearsOfService > 10) {
|
if (yearsOfService > 10) {
|
||||||
return 30.0;
|
return 30.0;
|
||||||
} else if (yearsOfService > 5) {
|
} else if (yearsOfService > 5) {
|
||||||
@ -367,51 +355,80 @@ public class EmployeeView extends BeanValidationForm<Employee> implements HasUrl
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void processTimeOffRequests(Employee employee) {
|
private void processTimeOffRequests(final Employee employee) {
|
||||||
if (hasTimeOffRequests(employee)) {
|
boolean isCurrentYearEntry = employee.getDateOfEntry().getYear() == LocalDate.now().getYear();
|
||||||
updateExistingTimeOffRequests(employee);
|
|
||||||
} else {
|
deleteExistingTimeOffRequests(employee);
|
||||||
createAndSaveTimeOffRequests(employee);
|
|
||||||
|
if (isCurrentYearEntry) {
|
||||||
|
saveCurrentYearRequest(employee);
|
||||||
|
} else if (LocalDate.now().getYear() > employee.getDateOfEntry().getYear()) {
|
||||||
|
savePreviousAndCurrentYearRequests(employee);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean hasTimeOffRequests(Employee employee) {
|
private void deleteExistingTimeOffRequests(final Employee employee) {
|
||||||
return !requestService.findByEmployeeAndCategory(employee.getId(), TimeOffRequestType.VACACION_GESTION_ACTUAL).isEmpty() ||
|
deleteTimeOffRequestByCategory(employee, TimeOffRequestType.VACACION_GESTION_ANTERIOR);
|
||||||
!requestService.findByEmployeeAndCategory(employee.getId(), TimeOffRequestType.VACACION_GESTION_ANTERIOR).isEmpty();
|
deleteTimeOffRequestByCategory(employee, TimeOffRequestType.VACACION_GESTION_ACTUAL);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateExistingTimeOffRequests(Employee employee) {
|
private void deleteTimeOffRequestByCategory(final Employee employee, final TimeOffRequestType category) {
|
||||||
updateTimeOffRequest(employee, TimeOffRequestType.VACACION_GESTION_ANTERIOR, -1, 729);
|
var requests = requestService.findByEmployeeAndCategory(employee.getId(), category);
|
||||||
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()) {
|
||||||
TimeOffRequest request = requests.getLast();
|
requestService.deleteTimeOffRequest(requests.getFirst().getId());
|
||||||
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 createAndSaveTimeOffRequests(Employee employee) {
|
private void saveCurrentYearRequest(final Employee employee) {
|
||||||
requestService.saveTimeOffRequest(createTimeOffRequest(employee, TimeOffRequestType.VACACION_GESTION_ANTERIOR, -1, 729));
|
LocalDate baseDate = LocalDate.of(
|
||||||
requestService.saveTimeOffRequest(createTimeOffRequest(employee, TimeOffRequestType.VACACION_GESTION_ACTUAL, 0, 1094));
|
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) {
|
private void savePreviousAndCurrentYearRequests(final Employee employee) {
|
||||||
LocalDate baseDate = LocalDate.of(LocalDate.now().getYear() + yearOffset, employee.getDateOfEntry().getMonth(), employee.getDateOfEntry().getDayOfMonth());
|
LocalDate previousBaseDate = LocalDate.of(
|
||||||
LocalDate expirationDate = baseDate.plusDays(daysToAdd);
|
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();
|
TimeOffRequest request = new TimeOffRequest();
|
||||||
|
request.setEmployee(employee);
|
||||||
request.setCategory(category);
|
request.setCategory(category);
|
||||||
request.setState(TimeOffRequestStatus.APROBADO);
|
request.setState(TimeOffRequestStatus.APROBADO);
|
||||||
request.setEmployee(employee);
|
request.setExpiration(baseDate.plusDays(expirationDays));
|
||||||
request.setExpiration(expirationDate);
|
|
||||||
setVacationDuration(employee, request, baseDate);
|
setVacationDuration(employee, request, baseDate);
|
||||||
|
|
||||||
return request;
|
return request;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -428,7 +428,10 @@ public class RequestRegisterView extends VerticalLayout {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void handleVacationRequest(final TimeOffRequest request) {
|
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()) {
|
if (!existingRequests.isEmpty()) {
|
||||||
TimeOffRequest existingRequest = existingRequests.getFirst();
|
TimeOffRequest existingRequest = existingRequests.getFirst();
|
||||||
existingRequest.setCategory(TimeOffRequestType.VACACION_GESTION_ANTERIOR);
|
existingRequest.setCategory(TimeOffRequestType.VACACION_GESTION_ANTERIOR);
|
||||||
|
Loading…
Reference in New Issue
Block a user