Merge pull request 'Observaciones-vacaciones' (#83) from Observaciones-vacaciones into main
All checks were successful
Builder / Build-Project (push) Successful in 2m48s
All checks were successful
Builder / Build-Project (push) Successful in 2m48s
Reviewed-on: #83
This commit is contained in:
commit
450e121374
BIN
Reporte_Vacaciones.xlsx
Normal file
BIN
Reporte_Vacaciones.xlsx
Normal file
Binary file not shown.
Binary file not shown.
@ -1,36 +1,35 @@
|
|||||||
package com.primefactorsolutions.model;
|
package com.primefactorsolutions.model;
|
||||||
|
|
||||||
public enum DocumentType {
|
public enum DocumentType {
|
||||||
All,
|
TODOS,
|
||||||
ID_CARD,
|
CARNET_DE_IDENTIDAD,
|
||||||
PAY_STUB,
|
RECIBOS_DE_PAGO,
|
||||||
PAY_SLIPS,
|
CONTRATO_DE_TRABAJO,
|
||||||
EMPLOYMENT_CONTRACT,
|
CERTIFICADO_DE_TRABAJO,
|
||||||
WORK_CERTIFICATES,
|
|
||||||
NDA,
|
NDA,
|
||||||
MEMORANDUMS,
|
MEMORÁNDUMS,
|
||||||
CONTRACT_APPROVAL_MTEPS,
|
APROBACIÓN_DE_CONTRATO_MTEPS,
|
||||||
BACKGROUND_CHECK_CERTIFICATE,
|
CERTIFICADO_DE_ANTECEDENTES,
|
||||||
PRE_EMPLOYMENT_EVALUATION,
|
EVALUACIÓN_PRE_EMPLEO,
|
||||||
INSURANCE_REGISTRATION_FORM,
|
FORMULARIO_DE_INSCRIPCIÓN_AL_SEGURO,
|
||||||
INSURANCE_CANCELLATION_FORM,
|
FORMULARIO_DE_CANCELACIÓN_DE_SEGURO,
|
||||||
PROFESSIONAL_DEGREE_1,
|
TÍTULO_PROFESIONAL_1,
|
||||||
PROFESSIONAL_CERTIFICATE_1,
|
CERTIFICACIÓN_PROFESIONAL_1,
|
||||||
PROFESSIONAL_DEGREE_2,
|
TÍTULO_PROFESIONAL_2,
|
||||||
PROFESSIONAL_CERTIFICATE_2,
|
CERTIFICACIÓN_PROFECIONAL_2,
|
||||||
PROFESSIONAL_DEGREE_3,
|
TÍTULO_PROFESIONAL_3,
|
||||||
PROFESSIONAL_CERTIFICATE_3,
|
CERTIFICACIÓN_PROFECIONAL_3,
|
||||||
GENERAL_LABOR_REGULATIONS,
|
NORMATIVA_LABORAL_GENERAL,
|
||||||
REMOTE_WORK_GUIDELINES,
|
NORMAS_DE_TRABAJO_REMOTO,
|
||||||
SAFETY_REGULATIONS,
|
NORMAS_DE_SEGURIDAD,
|
||||||
HUMAN_RESOURCES_GUIDELINES,
|
INSTRUCTIVOS_DE_RECURSOS_HUMANOS,
|
||||||
ADMINISTRATION_FUNCTIONS_MANUAL,
|
MANUAL_DE_FUNCIONES_DE_ADMINISTRACIÓN,
|
||||||
ENGINEERING_FUNCTIONS_MANUAL,
|
MANUAL_DE_FUNCIONES_DE_INGENIERÍA,
|
||||||
GENERAL_LABOR_LAW,
|
LEY_GENERAL_DEL_TRABAJO,
|
||||||
SUPREME_DECREE,
|
DECRETOS_SUPREMOS,
|
||||||
REGULATORY_RESOLUTION,
|
RESOLUCIONES_O_DISPOSICIONES_REGLAMENTARIAS,
|
||||||
COMPLEMENTARY_REGULATION,
|
NORMATIVA_COMPLEMENTARIA,
|
||||||
HEALTH_SAFETY_LAW,
|
LEY_GRAL_DE_HIGIENE_SALUD_SEGURIDAD_OCUPACIONAL_Y_BIENESTAR,
|
||||||
INTERNSHIP_RULES,
|
NORMATIVA_REGLAMENTARIA_PARA_DESARROLLO_DE_PASANTÍAS,
|
||||||
OTHER
|
OTROS
|
||||||
}
|
}
|
||||||
|
@ -10,7 +10,4 @@ public enum TimeOffRequestStatus {
|
|||||||
VENCIDO,
|
VENCIDO,
|
||||||
|
|
||||||
SOLICITADO,
|
SOLICITADO,
|
||||||
EN_REVISION,
|
|
||||||
COMPLETADO,
|
|
||||||
CANCELADO,
|
|
||||||
}
|
}
|
||||||
|
@ -39,9 +39,9 @@ import java.io.InputStream;
|
|||||||
@PageTitle("Document")
|
@PageTitle("Document")
|
||||||
@Route(value = "/documents/:documentId?/:action?", layout = MainLayout.class)
|
@Route(value = "/documents/:documentId?/:action?", layout = MainLayout.class)
|
||||||
public class DocumentView extends BeanValidationForm<Document> implements HasUrlParameter<String> {
|
public class DocumentView extends BeanValidationForm<Document> implements HasUrlParameter<String> {
|
||||||
private final TextField fileName = new TextField("Document Name");
|
private final TextField fileName = new TextField("Nombre del documento");
|
||||||
private final ComboBox<DocumentType> documentType = new ComboBox<>("Document Type");
|
private final ComboBox<DocumentType> documentType = new ComboBox<>("Tipo de documento");
|
||||||
private final ComboBox<Employee> employeeComboBox = new ComboBox<>("Employee");
|
private final ComboBox<Employee> employeeComboBox = new ComboBox<>("Empleado");
|
||||||
private final MemoryBuffer buffer = new MemoryBuffer();
|
private final MemoryBuffer buffer = new MemoryBuffer();
|
||||||
private final Upload uploadButton = new Upload(buffer);
|
private final Upload uploadButton = new Upload(buffer);
|
||||||
private final DocumentService documentService;
|
private final DocumentService documentService;
|
||||||
@ -68,19 +68,19 @@ public class DocumentView extends BeanValidationForm<Document> implements HasUrl
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected Button createSaveButton() {
|
protected Button createSaveButton() {
|
||||||
saveButton = new Button("Save");
|
saveButton = new Button("Guardar");
|
||||||
saveButton.addClickListener(event -> saveDocument());
|
saveButton.addClickListener(event -> saveDocument());
|
||||||
return saveButton;
|
return saveButton;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected Button createCloseButton() {
|
protected Button createCloseButton() {
|
||||||
Button closeButton = new Button("Close");
|
Button closeButton = new Button("Salir");
|
||||||
closeButton.addClickListener(event -> closeForm());
|
closeButton.addClickListener(event -> closeForm());
|
||||||
return closeButton;
|
return closeButton;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected Button createViewDocumentButton() {
|
protected Button createViewDocumentButton() {
|
||||||
viewDocumentButton = new Button("View Document");
|
viewDocumentButton = new Button("Ver documento");
|
||||||
viewDocumentButton.setEnabled(false);
|
viewDocumentButton.setEnabled(false);
|
||||||
viewDocumentButton.addClickListener(event -> viewDocument());
|
viewDocumentButton.addClickListener(event -> viewDocument());
|
||||||
return viewDocumentButton;
|
return viewDocumentButton;
|
||||||
@ -130,7 +130,7 @@ public class DocumentView extends BeanValidationForm<Document> implements HasUrl
|
|||||||
ui.getPage().open(registration.getResourceUri().toString());
|
ui.getPage().open(registration.getResourceUri().toString());
|
||||||
});
|
});
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
Notification.show("Error reading file.");
|
Notification.show("Error al leer el archivo.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -148,10 +148,10 @@ public class DocumentView extends BeanValidationForm<Document> implements HasUrl
|
|||||||
setDocumentCreator(document);
|
setDocumentCreator(document);
|
||||||
|
|
||||||
documentService.saveDocument(document);
|
documentService.saveDocument(document);
|
||||||
Notification.show("File saved successfully.");
|
Notification.show("Archivo guardado correctamente.");
|
||||||
clearForm();
|
clearForm();
|
||||||
} else {
|
} else {
|
||||||
Notification.show("Save failed: Please complete all fields and upload a file.");
|
Notification.show("Error al guardar: Por favor, complete todos los campos y cargue un archivo.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -179,7 +179,7 @@ public class DocumentView extends BeanValidationForm<Document> implements HasUrl
|
|||||||
try {
|
try {
|
||||||
return buffer.getInputStream().readAllBytes();
|
return buffer.getInputStream().readAllBytes();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
Notification.show("Error reading file data.");
|
Notification.show("Error al leer los datos del archivo.");
|
||||||
return new byte[0];
|
return new byte[0];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -220,13 +220,13 @@ public class DocumentView extends BeanValidationForm<Document> implements HasUrl
|
|||||||
uploadButton.setAcceptedFileTypes(".pdf");
|
uploadButton.setAcceptedFileTypes(".pdf");
|
||||||
uploadButton.addSucceededListener(event -> {
|
uploadButton.addSucceededListener(event -> {
|
||||||
fileUploaded = true;
|
fileUploaded = true;
|
||||||
Notification.show("File uploaded successfully.");
|
Notification.show("Archivo cargado correctamente.");
|
||||||
viewDocumentButton.setEnabled(true);
|
viewDocumentButton.setEnabled(true);
|
||||||
updateSaveButtonState();
|
updateSaveButtonState();
|
||||||
});
|
});
|
||||||
uploadButton.getElement().addEventListener("file-remove", event -> {
|
uploadButton.getElement().addEventListener("file-remove", event -> {
|
||||||
fileUploaded = false;
|
fileUploaded = false;
|
||||||
Notification.show("File removed.");
|
Notification.show("Archivo eliminado.");
|
||||||
viewDocumentButton.setEnabled(false);
|
viewDocumentButton.setEnabled(false);
|
||||||
updateSaveButtonState();
|
updateSaveButtonState();
|
||||||
});
|
});
|
||||||
|
@ -56,7 +56,7 @@ public class DocumentsListView extends BaseView {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void initializeView() {
|
private void initializeView() {
|
||||||
getCurrentPageLayout().add(createActionButton("Add Document", this::navigateToAddDocumentView));
|
getCurrentPageLayout().add(createActionButton("Añadir documento", this::navigateToAddDocumentView));
|
||||||
|
|
||||||
final HorizontalLayout hl = new HorizontalLayout();
|
final HorizontalLayout hl = new HorizontalLayout();
|
||||||
hl.add(createDocumentTypeFilter());
|
hl.add(createDocumentTypeFilter());
|
||||||
@ -70,7 +70,10 @@ public class DocumentsListView extends BaseView {
|
|||||||
|
|
||||||
private void configureDocumentGrid() {
|
private void configureDocumentGrid() {
|
||||||
documentGrid.setColumns("fileName", "documentType", "creator");
|
documentGrid.setColumns("fileName", "documentType", "creator");
|
||||||
documentGrid.addComponentColumn(this::createEmployeeSpan).setHeader("Employee");
|
documentGrid.getColumnByKey("fileName").setHeader("Nombre archivo");
|
||||||
|
documentGrid.getColumnByKey("documentType").setHeader("Tipo");
|
||||||
|
documentGrid.getColumnByKey("creator").setHeader("Creador");
|
||||||
|
documentGrid.addComponentColumn(this::createEmployeeSpan).setHeader("Empleado");
|
||||||
addActionColumns();
|
addActionColumns();
|
||||||
configurePagination();
|
configurePagination();
|
||||||
}
|
}
|
||||||
@ -85,13 +88,13 @@ public class DocumentsListView extends BaseView {
|
|||||||
documentGrid.addComponentColumn((ValueProvider<Document, Component>) document -> {
|
documentGrid.addComponentColumn((ValueProvider<Document, Component>) document -> {
|
||||||
final MenuBar menuBar = new MenuBar();
|
final MenuBar menuBar = new MenuBar();
|
||||||
menuBar.addThemeVariants(MenuBarVariant.LUMO_TERTIARY_INLINE);
|
menuBar.addThemeVariants(MenuBarVariant.LUMO_TERTIARY_INLINE);
|
||||||
final MenuItem viewItem = MenuBarUtils.createIconItem(menuBar, VaadinIcon.EYE, "View");
|
final MenuItem viewItem = MenuBarUtils.createIconItem(menuBar, VaadinIcon.EYE, "Ver");
|
||||||
viewItem.addClickListener((ComponentEventListener<ClickEvent<MenuItem>>) menuItemClickEvent ->
|
viewItem.addClickListener((ComponentEventListener<ClickEvent<MenuItem>>) menuItemClickEvent ->
|
||||||
navigateToDocumentView(document));
|
navigateToDocumentView(document));
|
||||||
final MenuItem editItem = MenuBarUtils.createIconItem(menuBar, VaadinIcon.PENCIL, "Edit");
|
final MenuItem editItem = MenuBarUtils.createIconItem(menuBar, VaadinIcon.PENCIL, "Editar");
|
||||||
editItem.addClickListener((ComponentEventListener<ClickEvent<MenuItem>>) menuItemClickEvent ->
|
editItem.addClickListener((ComponentEventListener<ClickEvent<MenuItem>>) menuItemClickEvent ->
|
||||||
navigateToEditDocumentView(document));
|
navigateToEditDocumentView(document));
|
||||||
final MenuItem downloadItem = MenuBarUtils.createIconItem(menuBar, VaadinIcon.DOWNLOAD, "Download");
|
final MenuItem downloadItem = MenuBarUtils.createIconItem(menuBar, VaadinIcon.DOWNLOAD, "Descargar");
|
||||||
downloadItem.addClickListener((ComponentEventListener<ClickEvent<MenuItem>>) menuItemClickEvent ->
|
downloadItem.addClickListener((ComponentEventListener<ClickEvent<MenuItem>>) menuItemClickEvent ->
|
||||||
downloadDocument(document));
|
downloadDocument(document));
|
||||||
return menuBar;
|
return menuBar;
|
||||||
@ -105,7 +108,7 @@ public class DocumentsListView extends BaseView {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private ComboBox<DocumentType> createDocumentTypeFilter() {
|
private ComboBox<DocumentType> createDocumentTypeFilter() {
|
||||||
documentTypeFilter = new ComboBox<>("Document Type");
|
documentTypeFilter = new ComboBox<>("Tipo de documento");
|
||||||
documentTypeFilter.setItems(DocumentType.values());
|
documentTypeFilter.setItems(DocumentType.values());
|
||||||
documentTypeFilter.setValue(DocumentType.values()[0]);
|
documentTypeFilter.setValue(DocumentType.values()[0]);
|
||||||
documentTypeFilter.addValueChangeListener(event -> {
|
documentTypeFilter.addValueChangeListener(event -> {
|
||||||
@ -115,7 +118,7 @@ public class DocumentsListView extends BaseView {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private ComboBox<Employee> createEmployeeFilter() {
|
private ComboBox<Employee> createEmployeeFilter() {
|
||||||
employeeFilter = new ComboBox<>("Employee");
|
employeeFilter = new ComboBox<>("Empleado");
|
||||||
List<Employee> employees = employeeService.findAllEmployees();
|
List<Employee> employees = employeeService.findAllEmployees();
|
||||||
employees.addFirst(createAllEmployeesOption());
|
employees.addFirst(createAllEmployeesOption());
|
||||||
employeeFilter.setItems(employees);
|
employeeFilter.setItems(employees);
|
||||||
@ -129,12 +132,13 @@ public class DocumentsListView extends BaseView {
|
|||||||
|
|
||||||
private Employee createAllEmployeesOption() {
|
private Employee createAllEmployeesOption() {
|
||||||
Employee allEmployeesOption = new Employee();
|
Employee allEmployeesOption = new Employee();
|
||||||
allEmployeesOption.setFirstName("All");
|
allEmployeesOption.setFirstName("TODOS");
|
||||||
return allEmployeesOption;
|
return allEmployeesOption;
|
||||||
}
|
}
|
||||||
|
|
||||||
private String getEmployeeLabel(final Employee employee) {
|
private String getEmployeeLabel(final Employee employee) {
|
||||||
return employee.getFirstName().equals("All") ? "All" : employee.getFirstName() + " " + employee.getLastName();
|
return employee.getFirstName().equals("TODOS")
|
||||||
|
? "TODOS" : employee.getFirstName() + " " + employee.getLastName();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void navigateToEditDocumentView(final Document document) {
|
private void navigateToEditDocumentView(final Document document) {
|
||||||
|
@ -7,6 +7,8 @@ import com.primefactorsolutions.service.VacationService;
|
|||||||
import com.vaadin.flow.component.ClickEvent;
|
import com.vaadin.flow.component.ClickEvent;
|
||||||
import com.vaadin.flow.component.Component;
|
import com.vaadin.flow.component.Component;
|
||||||
import com.vaadin.flow.component.ComponentEventListener;
|
import com.vaadin.flow.component.ComponentEventListener;
|
||||||
|
import com.vaadin.flow.component.UI;
|
||||||
|
import com.vaadin.flow.component.button.Button;
|
||||||
import com.vaadin.flow.component.combobox.ComboBox;
|
import com.vaadin.flow.component.combobox.ComboBox;
|
||||||
import com.vaadin.flow.component.contextmenu.MenuItem;
|
import com.vaadin.flow.component.contextmenu.MenuItem;
|
||||||
import com.vaadin.flow.component.html.H3;
|
import com.vaadin.flow.component.html.H3;
|
||||||
@ -21,11 +23,21 @@ import com.vaadin.flow.router.BeforeEvent;
|
|||||||
import com.vaadin.flow.router.HasUrlParameter;
|
import com.vaadin.flow.router.HasUrlParameter;
|
||||||
import com.vaadin.flow.router.PageTitle;
|
import com.vaadin.flow.router.PageTitle;
|
||||||
import com.vaadin.flow.router.Route;
|
import com.vaadin.flow.router.Route;
|
||||||
|
import com.vaadin.flow.server.StreamRegistration;
|
||||||
|
import com.vaadin.flow.server.StreamResource;
|
||||||
import com.vaadin.flow.spring.annotation.SpringComponent;
|
import com.vaadin.flow.spring.annotation.SpringComponent;
|
||||||
import jakarta.annotation.security.PermitAll;
|
import jakarta.annotation.security.PermitAll;
|
||||||
|
import org.apache.pdfbox.pdmodel.PDDocument;
|
||||||
|
import org.apache.pdfbox.pdmodel.PDPage;
|
||||||
|
import org.apache.pdfbox.pdmodel.PDPageContentStream;
|
||||||
|
import org.apache.pdfbox.pdmodel.font.PDType1Font;
|
||||||
import org.springframework.context.annotation.Scope;
|
import org.springframework.context.annotation.Scope;
|
||||||
import org.vaadin.firitin.components.grid.PagingGrid;
|
import org.vaadin.firitin.components.grid.PagingGrid;
|
||||||
|
|
||||||
|
import java.io.ByteArrayInputStream;
|
||||||
|
import java.io.ByteArrayOutputStream;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.UncheckedIOException;
|
||||||
import java.time.LocalDate;
|
import java.time.LocalDate;
|
||||||
import java.time.Period;
|
import java.time.Period;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
@ -60,6 +72,8 @@ public class RequestEmployeeView extends BaseView implements HasUrlParameter<Str
|
|||||||
|
|
||||||
private void initializeView() {
|
private void initializeView() {
|
||||||
requestService.updateRequestStatuses();
|
requestService.updateRequestStatuses();
|
||||||
|
Button downloadButton = new Button("Descargar reporte", event -> downloadReport());
|
||||||
|
getCurrentPageLayout().add(downloadButton);
|
||||||
setupFilters();
|
setupFilters();
|
||||||
setupGrid();
|
setupGrid();
|
||||||
getCurrentPageLayout().add(requestGrid, new H3("Balance"), createSummaryLayout());
|
getCurrentPageLayout().add(requestGrid, new H3("Balance"), createSummaryLayout());
|
||||||
@ -141,43 +155,47 @@ public class RequestEmployeeView extends BaseView implements HasUrlParameter<Str
|
|||||||
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();
|
int currentYear = LocalDate.now().getYear();
|
||||||
|
LocalDate currentDate = LocalDate.now();
|
||||||
|
|
||||||
List<Vacation> vacations = vacationService.findVacations();
|
List<Vacation> vacations = vacationService.findVacations();
|
||||||
|
|
||||||
double healthLicence = 2;
|
double healthLicence = getHealthLicence(employeeId);
|
||||||
List<TimeOffRequest> healthRequests = requestService
|
|
||||||
.findByEmployeeAndCategory(employeeId, TimeOffRequestType.PERMISOS_DE_SALUD);
|
|
||||||
if (healthRequests != null && !healthRequests.isEmpty()) {
|
|
||||||
healthLicence = healthRequests.getLast().getDaysBalance();
|
|
||||||
}
|
|
||||||
|
|
||||||
double totalFixedAndMovableHolidays = calculateHolidayDays(vacations);
|
double totalFixedAndMovableHolidays = calculateHolidayDays(vacations);
|
||||||
double totalPersonalDays = calculatePersonalDays(vacations, isMale);
|
double totalPersonalDays = calculatePersonalDays(vacations, isMale);
|
||||||
List<Double> vacationDays = calculateVacationDays(employee);
|
List<Double> vacationDays = calculateVacationDays(employee);
|
||||||
|
|
||||||
double utilizedVacationCurrentDays = vacationDays.get(1);
|
double totalVacationCurrentDays = calculateUtilizedVacationDays(
|
||||||
List<TimeOffRequest> vacationCurrentRequests = requestService
|
vacationDays.get(1),
|
||||||
.findByEmployeeAndCategory(employeeId, TimeOffRequestType.VACACION_GESTION_ACTUAL);
|
TimeOffRequestType.VACACION_GESTION_ACTUAL
|
||||||
if (vacationCurrentRequests != null && !vacationCurrentRequests.isEmpty()) {
|
);
|
||||||
utilizedVacationCurrentDays = vacationCurrentRequests.getLast().getDaysBalance();
|
double totalVacationPreviousDays = calculateUtilizedVacationDays(
|
||||||
}
|
vacationDays.get(0),
|
||||||
double totalVacationCurrentDays = vacationDays.get(1) - (vacationDays.get(1) - utilizedVacationCurrentDays);
|
TimeOffRequestType.VACACION_GESTION_ANTERIOR
|
||||||
|
);
|
||||||
double utilizedVacationPreviousDays = vacationDays.get(0);
|
|
||||||
List<TimeOffRequest> vacationPreviousRequests = requestService
|
|
||||||
.findByEmployeeAndCategory(employeeId, TimeOffRequestType.VACACION_GESTION_ANTERIOR);
|
|
||||||
if (vacationPreviousRequests != null && !vacationPreviousRequests.isEmpty()) {
|
|
||||||
utilizedVacationPreviousDays = vacationPreviousRequests.getLast().getDaysBalance();
|
|
||||||
}
|
|
||||||
double totalVacationPreviousDays = vacationDays.getFirst()
|
|
||||||
- (vacationDays.getFirst() - utilizedVacationPreviousDays);
|
|
||||||
|
|
||||||
double utilizedFixedAndMovableHolidays = calculateHolidayUtilizedDays(currentYear);
|
double utilizedFixedAndMovableHolidays = calculateHolidayUtilizedDays(currentYear);
|
||||||
double utilizedPersonalDays = calculatePersonalDaysUtilized(isMale, currentYear);
|
double utilizedPersonalDays = calculatePersonalDaysUtilized(isMale, currentYear);
|
||||||
|
|
||||||
double remainingHolidayDays = totalFixedAndMovableHolidays - utilizedFixedAndMovableHolidays;
|
double remainingHolidayDays = calculateRemainingHolidayDays(
|
||||||
double remainingPersonalDays = (totalPersonalDays - utilizedPersonalDays) + healthLicence;
|
totalFixedAndMovableHolidays,
|
||||||
double remainingVacationDays = totalVacationCurrentDays + totalVacationPreviousDays;
|
utilizedFixedAndMovableHolidays,
|
||||||
|
employee.getDateOfExit(),
|
||||||
|
currentDate
|
||||||
|
);
|
||||||
|
double remainingPersonalDays = calculateRemainingPersonalDays(
|
||||||
|
totalPersonalDays,
|
||||||
|
utilizedPersonalDays,
|
||||||
|
healthLicence,
|
||||||
|
employee.getDateOfExit(),
|
||||||
|
currentDate
|
||||||
|
);
|
||||||
|
double remainingVacationDays = calculateRemainingVacationDays(
|
||||||
|
totalVacationCurrentDays,
|
||||||
|
totalVacationPreviousDays,
|
||||||
|
employee.getDateOfExit(),
|
||||||
|
currentDate
|
||||||
|
);
|
||||||
|
|
||||||
double totalAvailableDays = remainingHolidayDays + remainingPersonalDays + remainingVacationDays;
|
double totalAvailableDays = remainingHolidayDays + remainingPersonalDays + remainingVacationDays;
|
||||||
|
|
||||||
@ -189,6 +207,51 @@ public class RequestEmployeeView extends BaseView implements HasUrlParameter<Str
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private double getHealthLicence(final UUID employeeId) {
|
||||||
|
List<TimeOffRequest> healthRequests = requestService
|
||||||
|
.findByEmployeeAndCategory(employeeId, TimeOffRequestType.PERMISOS_DE_SALUD);
|
||||||
|
return healthRequests != null && !healthRequests.isEmpty() ? healthRequests.getLast().getDaysBalance() : 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
private double calculateUtilizedVacationDays(final double vacationDays, final TimeOffRequestType requestType) {
|
||||||
|
List<TimeOffRequest> vacationRequests = requestService.findByEmployeeAndCategory(employeeId, requestType);
|
||||||
|
if (vacationRequests != null && !vacationRequests.isEmpty()) {
|
||||||
|
return vacationRequests.getLast().getDaysBalance();
|
||||||
|
}
|
||||||
|
return vacationDays;
|
||||||
|
}
|
||||||
|
|
||||||
|
private double calculateRemainingVacationDays(final double totalVacationCurrentDays,
|
||||||
|
final double totalVacationPreviousDays,
|
||||||
|
final LocalDate exitDate,
|
||||||
|
final LocalDate currentDate) {
|
||||||
|
if (exitDate == null || exitDate.isAfter(currentDate)) {
|
||||||
|
return totalVacationCurrentDays + totalVacationPreviousDays;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
private double calculateRemainingHolidayDays(final double totalFixedAndMovableHolidays,
|
||||||
|
final double utilizedFixedAndMovableHolidays,
|
||||||
|
final LocalDate exitDate,
|
||||||
|
final LocalDate currentDate) {
|
||||||
|
if (exitDate == null || exitDate.isAfter(currentDate)) {
|
||||||
|
return totalFixedAndMovableHolidays - utilizedFixedAndMovableHolidays;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
private double calculateRemainingPersonalDays(final double totalPersonalDays,
|
||||||
|
final double utilizedPersonalDays,
|
||||||
|
final double healthLicence,
|
||||||
|
final LocalDate exitDate,
|
||||||
|
final LocalDate currentDate) {
|
||||||
|
if (exitDate == null || exitDate.isAfter(currentDate)) {
|
||||||
|
return (totalPersonalDays - utilizedPersonalDays) + healthLicence;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
private double calculateHolidayDays(final List<Vacation> vacations) {
|
private double calculateHolidayDays(final List<Vacation> vacations) {
|
||||||
return vacations.stream()
|
return vacations.stream()
|
||||||
.filter(req -> req.getType() != Vacation.Type.OTHER)
|
.filter(req -> req.getType() != Vacation.Type.OTHER)
|
||||||
@ -257,7 +320,8 @@ public class RequestEmployeeView extends BaseView implements HasUrlParameter<Str
|
|||||||
private double calculateHolidayUtilizedDays(final int year) {
|
private double calculateHolidayUtilizedDays(final int year) {
|
||||||
return requests.stream()
|
return requests.stream()
|
||||||
.filter(this::verificationIsHoliday)
|
.filter(this::verificationIsHoliday)
|
||||||
.filter(req -> req.getState() == TimeOffRequestStatus.TOMADO)
|
.filter(req -> req.getState() == TimeOffRequestStatus.TOMADO
|
||||||
|
|| req.getState() == TimeOffRequestStatus.APROBADO)
|
||||||
.filter(req -> getStartDateYear(req) == year)
|
.filter(req -> getStartDateYear(req) == year)
|
||||||
.mapToDouble(TimeOffRequest::getDaysToBeTake)
|
.mapToDouble(TimeOffRequest::getDaysToBeTake)
|
||||||
.sum();
|
.sum();
|
||||||
@ -266,7 +330,8 @@ public class RequestEmployeeView extends BaseView implements HasUrlParameter<Str
|
|||||||
private double calculatePersonalDaysUtilized(final boolean isMale, final int year) {
|
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 -> req.getState() == TimeOffRequestStatus.TOMADO)
|
.filter(req -> req.getState() == TimeOffRequestStatus.TOMADO
|
||||||
|
|| req.getState() == TimeOffRequestStatus.APROBADO)
|
||||||
.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"))
|
||||||
@ -302,10 +367,6 @@ public class RequestEmployeeView extends BaseView implements HasUrlParameter<Str
|
|||||||
return vacation.getType() != Vacation.Type.OTHER;
|
return vacation.getType() != Vacation.Type.OTHER;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void navigateToRequestsListView() {
|
|
||||||
getUI().ifPresent(ui -> ui.navigate(RequestsListView.class));
|
|
||||||
}
|
|
||||||
|
|
||||||
private void navigateToEditRequest(final TimeOffRequest request) {
|
private void navigateToEditRequest(final TimeOffRequest request) {
|
||||||
navigateToRequestView(request, "edit");
|
navigateToRequestView(request, "edit");
|
||||||
}
|
}
|
||||||
@ -399,17 +460,164 @@ public class RequestEmployeeView extends BaseView implements HasUrlParameter<Str
|
|||||||
return existingRequest.isEmpty();
|
return existingRequest.isEmpty();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private String getDateString(final LocalDate date) {
|
||||||
|
return (date != null) ? date.toString() : "";
|
||||||
|
}
|
||||||
|
|
||||||
|
private ByteArrayInputStream generatePdfReport() {
|
||||||
|
try (PDDocument document = new PDDocument(); ByteArrayOutputStream out = new ByteArrayOutputStream()) {
|
||||||
|
PDPage page = new PDPage();
|
||||||
|
document.addPage(page);
|
||||||
|
Employee employee = employeeService.getEmployee(employeeId);
|
||||||
|
|
||||||
|
PDPageContentStream contentStream = null;
|
||||||
|
try {
|
||||||
|
contentStream = new PDPageContentStream(document, page);
|
||||||
|
|
||||||
|
contentStream.setFont(PDType1Font.TIMES_BOLD, 18);
|
||||||
|
contentStream.beginText();
|
||||||
|
contentStream.newLineAtOffset(200, 750);
|
||||||
|
contentStream.showText("Reporte de Vacaciones");
|
||||||
|
contentStream.endText();
|
||||||
|
|
||||||
|
contentStream.setFont(PDType1Font.TIMES_ROMAN, 14);
|
||||||
|
contentStream.beginText();
|
||||||
|
contentStream.newLineAtOffset(50, 700);
|
||||||
|
contentStream.showText("Empleado: " + employee.getFirstName() + " " + employee.getLastName());
|
||||||
|
contentStream.newLineAtOffset(0, -15);
|
||||||
|
contentStream.showText("Equipo: " + employee.getTeam().getName());
|
||||||
|
contentStream.endText();
|
||||||
|
|
||||||
|
float tableTopY = 650;
|
||||||
|
float margin = 50;
|
||||||
|
float cellHeight = 20;
|
||||||
|
String[] headers = {"Categoría", "Estado", "Fecha de Inicio", "Fecha de Fin", "Días a Tomar"};
|
||||||
|
int columns = headers.length;
|
||||||
|
|
||||||
|
float[] columnWidths = new float[columns];
|
||||||
|
for (int i = 0; i < columns; i++) {
|
||||||
|
columnWidths[i] = getMaxColumnWidth(headers[i], requests, i);
|
||||||
|
}
|
||||||
|
|
||||||
|
contentStream.setFont(PDType1Font.TIMES_BOLD, 10);
|
||||||
|
float currentX = margin;
|
||||||
|
for (int i = 0; i < columns; i++) {
|
||||||
|
contentStream.addRect(currentX, tableTopY, columnWidths[i], -cellHeight);
|
||||||
|
contentStream.beginText();
|
||||||
|
contentStream.newLineAtOffset(currentX + 5, tableTopY - 15);
|
||||||
|
contentStream.showText(headers[i]);
|
||||||
|
contentStream.endText();
|
||||||
|
currentX += columnWidths[i];
|
||||||
|
}
|
||||||
|
contentStream.stroke();
|
||||||
|
|
||||||
|
contentStream.setFont(PDType1Font.TIMES_ROMAN, 10);
|
||||||
|
float currentY = tableTopY - cellHeight;
|
||||||
|
for (TimeOffRequest request : requests) {
|
||||||
|
String startDate = getDateString(request.getStartDate());
|
||||||
|
String endDate = getDateString(request.getEndDate());
|
||||||
|
|
||||||
|
String[] rowData = {
|
||||||
|
request.getCategory().name() != null ? request.getCategory().name() : "",
|
||||||
|
request.getState().name() != null ? request.getState().name() : "",
|
||||||
|
startDate,
|
||||||
|
endDate,
|
||||||
|
String.valueOf(request.getDaysToBeTake() != null ? request.getDaysToBeTake() : 0)
|
||||||
|
};
|
||||||
|
|
||||||
|
currentX = margin;
|
||||||
|
for (int i = 0; i < columns; i++) {
|
||||||
|
contentStream.addRect(currentX, currentY, columnWidths[i], -cellHeight);
|
||||||
|
contentStream.beginText();
|
||||||
|
contentStream.newLineAtOffset(currentX + 5, currentY - 15);
|
||||||
|
contentStream.showText(rowData[i]);
|
||||||
|
contentStream.endText();
|
||||||
|
currentX += columnWidths[i];
|
||||||
|
}
|
||||||
|
contentStream.stroke();
|
||||||
|
currentY -= cellHeight;
|
||||||
|
|
||||||
|
if (currentY < 50) {
|
||||||
|
contentStream.close();
|
||||||
|
page = new PDPage();
|
||||||
|
document.addPage(page);
|
||||||
|
contentStream = new PDPageContentStream(document, page);
|
||||||
|
currentY = 750;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
if (contentStream != null) {
|
||||||
|
contentStream.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
document.save(out);
|
||||||
|
return new ByteArrayInputStream(out.toByteArray());
|
||||||
|
} catch (IOException e) {
|
||||||
|
throw new UncheckedIOException("Error al generar el reporte", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private float getMaxColumnWidth(final String header, final List<TimeOffRequest> requests, final int columnIndex) {
|
||||||
|
float maxWidth = header.length();
|
||||||
|
for (TimeOffRequest request : requests) {
|
||||||
|
String value = switch (columnIndex) {
|
||||||
|
case 0 -> request.getCategory().name();
|
||||||
|
case 1 -> request.getState().name();
|
||||||
|
case 2 -> getDateString(request.getStartDate());
|
||||||
|
case 3 -> getDateString(request.getEndDate());
|
||||||
|
case 4 -> String.valueOf(request.getDaysToBeTake());
|
||||||
|
default -> "";
|
||||||
|
};
|
||||||
|
if (value != null) {
|
||||||
|
maxWidth = Math.max(maxWidth, value.length());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return maxWidth * 7;
|
||||||
|
}
|
||||||
|
|
||||||
|
private StreamResource generateVacationReport() {
|
||||||
|
Employee employee = employeeService.getEmployee(employeeId);
|
||||||
|
String fileName = String.format("%s_%s-reporte_de_vacaciones_%s.pdf",
|
||||||
|
employee.getFirstName(),
|
||||||
|
employee.getLastName(),
|
||||||
|
LocalDate.now());
|
||||||
|
|
||||||
|
ByteArrayInputStream pdfStream = generatePdfReport();
|
||||||
|
|
||||||
|
return new StreamResource(fileName, () -> pdfStream)
|
||||||
|
.setContentType("application/pdf")
|
||||||
|
.setHeader("Content-Disposition", "attachment; filename=\"" + fileName + "\"");
|
||||||
|
}
|
||||||
|
|
||||||
|
private void downloadReport() {
|
||||||
|
StreamResource resource = generateVacationReport();
|
||||||
|
getUI().ifPresent(ui -> openDocumentStream(resource, ui));
|
||||||
|
}
|
||||||
|
|
||||||
|
private void openDocumentStream(final StreamResource resource, final UI ui) {
|
||||||
|
StreamRegistration registration = ui.getSession().getResourceRegistry().registerResource(resource);
|
||||||
|
ui.getPage().open(registration.getResourceUri().toString());
|
||||||
|
}
|
||||||
|
|
||||||
@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);
|
||||||
Employee employee = employeeService.getEmployee(employeeId);
|
Employee employee = employeeService.getEmployee(employeeId);
|
||||||
requests = requestService.findRequestsByEmployeeId(employeeId);
|
requests = requestService.findRequestsByEmployeeId(employeeId);
|
||||||
setViewTitle(employee.getFirstName() + " " + employee.getLastName(), employee.getTeam().getName());
|
setViewTitle(
|
||||||
|
employee.getFirstName() + " " + employee.getLastName(),
|
||||||
|
employee.getTeam().getName(),
|
||||||
|
employee.getDateOfExit()
|
||||||
|
);
|
||||||
requestGrid.setItems(requests);
|
requestGrid.setItems(requests);
|
||||||
initializeView();
|
initializeView();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setViewTitle(final String employeeName, final String employeeTeam) {
|
private void setViewTitle(final String employeeName, final String employeeTeam, final LocalDate dateOfExit) {
|
||||||
getCurrentPageLayout().addComponentAsFirst(new H3(String.format("%s (%s)", employeeName, employeeTeam)));
|
addComponentAsFirst(new H3("Nombre del empleado: " + employeeName));
|
||||||
|
addComponentAtIndex(1, new H3("Equipo: " + employeeTeam));
|
||||||
|
if (dateOfExit != null) {
|
||||||
|
addComponentAtIndex(2, new H3("Descontado a cero en fecha " + dateOfExit + " por pago de finiquito."));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -19,6 +19,7 @@ import jakarta.annotation.security.PermitAll;
|
|||||||
import org.springframework.context.annotation.Scope;
|
import org.springframework.context.annotation.Scope;
|
||||||
|
|
||||||
import java.time.LocalDate;
|
import java.time.LocalDate;
|
||||||
|
import java.time.DayOfWeek;
|
||||||
import java.time.temporal.ChronoUnit;
|
import java.time.temporal.ChronoUnit;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
@ -91,8 +92,25 @@ public class RequestRegisterView extends VerticalLayout {
|
|||||||
onCategoryChange(event.getValue());
|
onCategoryChange(event.getValue());
|
||||||
handleCategorySelection(event.getValue());
|
handleCategorySelection(event.getValue());
|
||||||
});
|
});
|
||||||
startDatePicker.addValueChangeListener(event -> updateDatePickerMinValues());
|
startDatePicker.addValueChangeListener(event -> {
|
||||||
endDatePicker.addValueChangeListener(event -> calculateDays());
|
LocalDate selectedDate = event.getValue();
|
||||||
|
if (selectedDate != null && (selectedDate.getDayOfWeek().getValue() == 6
|
||||||
|
|| selectedDate.getDayOfWeek().getValue() == 7)) {
|
||||||
|
startDatePicker.setValue(selectedDate.minusDays(1));
|
||||||
|
}
|
||||||
|
updateDatePickerMinValues();
|
||||||
|
});
|
||||||
|
endDatePicker.addValueChangeListener(event -> {
|
||||||
|
if (startDatePicker.getValue() != null) {
|
||||||
|
endDatePicker.setMin(startDatePicker.getValue());
|
||||||
|
}
|
||||||
|
LocalDate selectedDate = event.getValue();
|
||||||
|
if (selectedDate != null && (selectedDate.getDayOfWeek().getValue() == 6
|
||||||
|
|| selectedDate.getDayOfWeek().getValue() == 7)) {
|
||||||
|
endDatePicker.setValue(selectedDate.minusDays(1));
|
||||||
|
}
|
||||||
|
calculateDays();
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private void configureBinder() {
|
private void configureBinder() {
|
||||||
@ -167,7 +185,7 @@ public class RequestRegisterView extends VerticalLayout {
|
|||||||
|
|
||||||
private void onCategoryChange(final TimeOffRequestType selectedCategory) {
|
private void onCategoryChange(final TimeOffRequestType selectedCategory) {
|
||||||
if (selectedCategory == TimeOffRequestType.VACACION_GESTION_ACTUAL
|
if (selectedCategory == TimeOffRequestType.VACACION_GESTION_ACTUAL
|
||||||
|| selectedCategory == TimeOffRequestType.VACACION_GESTION_ANTERIOR) {
|
|| selectedCategory == TimeOffRequestType.VACACION_GESTION_ANTERIOR) {
|
||||||
startDatePicker.setEnabled(true);
|
startDatePicker.setEnabled(true);
|
||||||
endDatePicker.setEnabled(true);
|
endDatePicker.setEnabled(true);
|
||||||
} else {
|
} else {
|
||||||
@ -178,6 +196,10 @@ public class RequestRegisterView extends VerticalLayout {
|
|||||||
|
|
||||||
private boolean isCategoryAvailable(final List<TimeOffRequest> employeeRequests,
|
private boolean isCategoryAvailable(final List<TimeOffRequest> employeeRequests,
|
||||||
final TimeOffRequestType category) {
|
final TimeOffRequestType category) {
|
||||||
|
if (category == TimeOffRequestType.CUMPLEAÑOS && employee.getBirthday() == null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
List<TimeOffRequest> requestsByCategory = employeeRequests.stream()
|
List<TimeOffRequest> requestsByCategory = employeeRequests.stream()
|
||||||
.filter(request -> request.getCategory() == category)
|
.filter(request -> request.getCategory() == category)
|
||||||
.toList();
|
.toList();
|
||||||
@ -199,8 +221,8 @@ public class RequestRegisterView extends VerticalLayout {
|
|||||||
&& latestRequest.getDaysBalance() > 0)
|
&& latestRequest.getDaysBalance() > 0)
|
||||||
|| latestRequest.getState() == TimeOffRequestStatus.RECHAZADO
|
|| latestRequest.getState() == TimeOffRequestStatus.RECHAZADO
|
||||||
|| (latestRequest.getState() == TimeOffRequestStatus.TOMADO
|
|| (latestRequest.getState() == TimeOffRequestStatus.TOMADO
|
||||||
&& latestRequest.getDaysBalance() == 0
|
&& latestRequest.getDaysBalance() == 0
|
||||||
&& latestRequest.getExpiration().isBefore(LocalDate.now()));
|
&& latestRequest.getExpiration().isBefore(LocalDate.now()));
|
||||||
} else {
|
} else {
|
||||||
return (latestRequest.getState() == TimeOffRequestStatus.TOMADO
|
return (latestRequest.getState() == TimeOffRequestStatus.TOMADO
|
||||||
&& latestRequest.getExpiration().isBefore(LocalDate.now()))
|
&& latestRequest.getExpiration().isBefore(LocalDate.now()))
|
||||||
@ -375,6 +397,13 @@ public class RequestRegisterView extends VerticalLayout {
|
|||||||
Double availableDays = availableDaysField.getValue();
|
Double availableDays = availableDaysField.getValue();
|
||||||
|
|
||||||
if (areDatesValid(startDate, endDate)) {
|
if (areDatesValid(startDate, endDate)) {
|
||||||
|
long workDays = countWorkDaysBetween(startDate, endDate);
|
||||||
|
|
||||||
|
daysToBeTakenField.setValue((double) workDays);
|
||||||
|
|
||||||
|
balanceDaysField.setValue(availableDaysField.getValue() - workDays);
|
||||||
|
|
||||||
|
|
||||||
double daysToBeTaken = calculateDaysBetween(startDate, endDate);
|
double daysToBeTaken = calculateDaysBetween(startDate, endDate);
|
||||||
setDaysToBeTakenField(daysToBeTaken);
|
setDaysToBeTakenField(daysToBeTaken);
|
||||||
|
|
||||||
@ -384,6 +413,12 @@ public class RequestRegisterView extends VerticalLayout {
|
|||||||
if (balanceDays < 0.0) {
|
if (balanceDays < 0.0) {
|
||||||
clearFields();
|
clearFields();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (daysToBeTakenField.getValue() > 10
|
||||||
|
&& (categoryComboBox.getValue() == TimeOffRequestType.VACACION_GESTION_ANTERIOR
|
||||||
|
|| categoryComboBox.getValue() == TimeOffRequestType.VACACION_GESTION_ACTUAL)) {
|
||||||
|
clearFields();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -391,8 +426,19 @@ public class RequestRegisterView extends VerticalLayout {
|
|||||||
return startDate != null && endDate != null;
|
return startDate != null && endDate != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private long countWorkDaysBetween(final LocalDate startDate, final LocalDate endDate) {
|
||||||
|
return startDate.datesUntil(endDate.plusDays(1))
|
||||||
|
.filter(date -> date.getDayOfWeek() != DayOfWeek.SATURDAY && date.getDayOfWeek() != DayOfWeek.SUNDAY)
|
||||||
|
.count();
|
||||||
|
}
|
||||||
|
|
||||||
private double calculateDaysBetween(final LocalDate startDate, final LocalDate endDate) {
|
private double calculateDaysBetween(final LocalDate startDate, final LocalDate endDate) {
|
||||||
return java.time.temporal.ChronoUnit.DAYS.between(startDate, endDate) + 1;
|
return startDate.datesUntil(endDate.plusDays(1))
|
||||||
|
.filter(date -> {
|
||||||
|
DayOfWeek day = date.getDayOfWeek();
|
||||||
|
return day != DayOfWeek.SATURDAY && day != DayOfWeek.SUNDAY;
|
||||||
|
})
|
||||||
|
.count();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setDaysToBeTakenField(final double daysToBeTaken) {
|
private void setDaysToBeTakenField(final double daysToBeTaken) {
|
||||||
@ -456,9 +502,16 @@ public class RequestRegisterView extends VerticalLayout {
|
|||||||
handleExistingRequests(request);
|
handleExistingRequests(request);
|
||||||
}
|
}
|
||||||
|
|
||||||
requestService.saveTimeOffRequest(request);
|
long differentDays = ChronoUnit.DAYS.between(LocalDate.now(), request.getStartDate());
|
||||||
Notification.show("Solicitud guardada correctamente.");
|
if (differentDays >= -15 && differentDays <= 90) {
|
||||||
closeForm();
|
requestService.saveTimeOffRequest(request);
|
||||||
|
Notification.show("Solicitud guardada correctamente.");
|
||||||
|
closeForm();
|
||||||
|
} else {
|
||||||
|
Notification.show(
|
||||||
|
"La fecha de inicio debe encontrarse dentro del rango de 15 días a 3 meses de anticipación."
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private TimeOffRequest prepareRequest() {
|
private TimeOffRequest prepareRequest() {
|
||||||
|
@ -8,6 +8,8 @@ import com.primefactorsolutions.service.VacationService;
|
|||||||
import com.vaadin.flow.component.ClickEvent;
|
import com.vaadin.flow.component.ClickEvent;
|
||||||
import com.vaadin.flow.component.Component;
|
import com.vaadin.flow.component.Component;
|
||||||
import com.vaadin.flow.component.ComponentEventListener;
|
import com.vaadin.flow.component.ComponentEventListener;
|
||||||
|
import com.vaadin.flow.component.UI;
|
||||||
|
import com.vaadin.flow.component.button.Button;
|
||||||
import com.vaadin.flow.component.combobox.ComboBox;
|
import com.vaadin.flow.component.combobox.ComboBox;
|
||||||
import com.vaadin.flow.component.contextmenu.MenuItem;
|
import com.vaadin.flow.component.contextmenu.MenuItem;
|
||||||
import com.vaadin.flow.component.icon.VaadinIcon;
|
import com.vaadin.flow.component.icon.VaadinIcon;
|
||||||
@ -17,11 +19,19 @@ import com.vaadin.flow.component.orderedlayout.HorizontalLayout;
|
|||||||
import com.vaadin.flow.function.ValueProvider;
|
import com.vaadin.flow.function.ValueProvider;
|
||||||
import com.vaadin.flow.router.PageTitle;
|
import com.vaadin.flow.router.PageTitle;
|
||||||
import com.vaadin.flow.router.Route;
|
import com.vaadin.flow.router.Route;
|
||||||
|
import com.vaadin.flow.server.StreamRegistration;
|
||||||
|
import com.vaadin.flow.server.StreamResource;
|
||||||
import com.vaadin.flow.spring.annotation.SpringComponent;
|
import com.vaadin.flow.spring.annotation.SpringComponent;
|
||||||
import jakarta.annotation.security.PermitAll;
|
import jakarta.annotation.security.PermitAll;
|
||||||
|
import org.apache.poi.ss.usermodel.*;
|
||||||
|
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
||||||
import org.springframework.context.annotation.Scope;
|
import org.springframework.context.annotation.Scope;
|
||||||
import org.vaadin.firitin.components.grid.PagingGrid;
|
import org.vaadin.firitin.components.grid.PagingGrid;
|
||||||
|
|
||||||
|
import java.io.ByteArrayInputStream;
|
||||||
|
import java.io.ByteArrayOutputStream;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.UncheckedIOException;
|
||||||
import java.time.LocalDate;
|
import java.time.LocalDate;
|
||||||
import java.time.Period;
|
import java.time.Period;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
@ -61,6 +71,8 @@ public class RequestsListView extends BaseView {
|
|||||||
|
|
||||||
private void initializeView() {
|
private void initializeView() {
|
||||||
requestService.updateRequestStatuses();
|
requestService.updateRequestStatuses();
|
||||||
|
Button downloadButton = new Button("Descargar reporte", event -> downloadReport());
|
||||||
|
getCurrentPageLayout().add(downloadButton);
|
||||||
setupFilters();
|
setupFilters();
|
||||||
setupRequestGrid();
|
setupRequestGrid();
|
||||||
getCurrentPageLayout().add(requestGrid);
|
getCurrentPageLayout().add(requestGrid);
|
||||||
@ -71,7 +83,6 @@ public class RequestsListView extends BaseView {
|
|||||||
hl.add(createEmployeeFilter());
|
hl.add(createEmployeeFilter());
|
||||||
hl.add(createTeamFilter());
|
hl.add(createTeamFilter());
|
||||||
hl.add(createStateFilter());
|
hl.add(createStateFilter());
|
||||||
|
|
||||||
getCurrentPageLayout().add(hl);
|
getCurrentPageLayout().add(hl);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -154,7 +165,7 @@ public class RequestsListView extends BaseView {
|
|||||||
private String getEmployeeStatus(final Employee employee) {
|
private String getEmployeeStatus(final Employee employee) {
|
||||||
Optional<TimeOffRequest> activeRequest = requestService
|
Optional<TimeOffRequest> activeRequest = requestService
|
||||||
.findByEmployeeAndState(employee.getId(), TimeOffRequestStatus.EN_USO);
|
.findByEmployeeAndState(employee.getId(), TimeOffRequestStatus.EN_USO);
|
||||||
return activeRequest.isPresent() ? "EN_DESCANSO" : "ACTIVO";
|
return activeRequest.isPresent() ? "EN_DESCANSO" : "EN_FUNCIONES";
|
||||||
}
|
}
|
||||||
|
|
||||||
private String getGeneralTotal(final Employee employee) {
|
private String getGeneralTotal(final Employee employee) {
|
||||||
@ -186,6 +197,13 @@ public class RequestsListView extends BaseView {
|
|||||||
double totalAvailable = calculateTotalAvailable(vacations, employeeRequests, employee);
|
double totalAvailable = calculateTotalAvailable(vacations, employeeRequests, employee);
|
||||||
|
|
||||||
double generalTotal = totalAvailable + totalVacations - totalUtilized;
|
double generalTotal = totalAvailable + totalVacations - totalUtilized;
|
||||||
|
|
||||||
|
if (employee.getDateOfExit() != null
|
||||||
|
&& (employee.getDateOfExit().isBefore(LocalDate.now())
|
||||||
|
|| employee.getDateOfExit().isEqual(LocalDate.now()))) {
|
||||||
|
generalTotal = 0;
|
||||||
|
}
|
||||||
|
|
||||||
return String.valueOf(generalTotal);
|
return String.valueOf(generalTotal);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -212,6 +230,8 @@ public class RequestsListView extends BaseView {
|
|||||||
int currentYear = LocalDate.now().getYear();
|
int currentYear = LocalDate.now().getYear();
|
||||||
return employeeRequests.stream()
|
return employeeRequests.stream()
|
||||||
.filter(Objects::nonNull)
|
.filter(Objects::nonNull)
|
||||||
|
.filter(request -> request.getState() == TimeOffRequestStatus.APROBADO
|
||||||
|
|| request.getState() == TimeOffRequestStatus.TOMADO)
|
||||||
.filter(request -> request.getCategory() != TimeOffRequestType.PERMISOS_DE_SALUD)
|
.filter(request -> request.getCategory() != TimeOffRequestType.PERMISOS_DE_SALUD)
|
||||||
.filter(request -> request.getCategory() != TimeOffRequestType.VACACION_GESTION_ACTUAL)
|
.filter(request -> request.getCategory() != TimeOffRequestType.VACACION_GESTION_ACTUAL)
|
||||||
.filter(request -> request.getCategory() != TimeOffRequestType.VACACION_GESTION_ANTERIOR)
|
.filter(request -> request.getCategory() != TimeOffRequestType.VACACION_GESTION_ANTERIOR)
|
||||||
@ -383,7 +403,7 @@ public class RequestsListView extends BaseView {
|
|||||||
private enum Status {
|
private enum Status {
|
||||||
TODOS,
|
TODOS,
|
||||||
EN_DESCANSO,
|
EN_DESCANSO,
|
||||||
ACTIVO
|
EN_FUNCIONES
|
||||||
}
|
}
|
||||||
|
|
||||||
private Employee createAllEmployeesOption() {
|
private Employee createAllEmployeesOption() {
|
||||||
@ -405,4 +425,50 @@ public class RequestsListView extends BaseView {
|
|||||||
private void navigateToTimeOffRequestView(final UUID idEmployee) {
|
private void navigateToTimeOffRequestView(final UUID idEmployee) {
|
||||||
getUI().ifPresent(ui -> ui.navigate("requests/" + idEmployee.toString()));
|
getUI().ifPresent(ui -> ui.navigate("requests/" + idEmployee.toString()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private ByteArrayInputStream generateExcelReport(final List<Employee> employees) {
|
||||||
|
try (Workbook workbook = new XSSFWorkbook()) {
|
||||||
|
Sheet sheet = workbook.createSheet("REPORTE_GENERAL_DE_VACACIONES");
|
||||||
|
Row headerRow = sheet.createRow(0);
|
||||||
|
|
||||||
|
String[] headers = {"Empleado", "Equipo", "Estado", "Total Horas"};
|
||||||
|
for (int i = 0; i < headers.length; i++) {
|
||||||
|
Cell cell = headerRow.createCell(i);
|
||||||
|
cell.setCellValue(headers[i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
int rowIndex = 1;
|
||||||
|
for (Employee employee : employees) {
|
||||||
|
Row row = sheet.createRow(rowIndex++);
|
||||||
|
row.createCell(0).setCellValue(getEmployeeFullName(employee));
|
||||||
|
row.createCell(1).setCellValue(getTeamName(employee));
|
||||||
|
row.createCell(2).setCellValue(getEmployeeStatus(employee));
|
||||||
|
row.createCell(3).setCellValue(getGeneralTotal(employee));
|
||||||
|
}
|
||||||
|
|
||||||
|
try (ByteArrayOutputStream out = new ByteArrayOutputStream()) {
|
||||||
|
workbook.write(out);
|
||||||
|
return new ByteArrayInputStream(out.toByteArray());
|
||||||
|
}
|
||||||
|
} catch (IOException e) {
|
||||||
|
throw new UncheckedIOException("Error al generar el archivo Excel", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private StreamResource generateGeneralVacationReport() {
|
||||||
|
List<Employee> employees = employeeService.findAllEmployees();
|
||||||
|
ByteArrayInputStream excelStream = generateExcelReport(employees);
|
||||||
|
return new StreamResource("reporte_general_de_vacaciones_" + LocalDate.now() + ".xlsx",
|
||||||
|
() -> excelStream);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void downloadReport() {
|
||||||
|
StreamResource resource = generateGeneralVacationReport();
|
||||||
|
getUI().ifPresent(ui -> openDocumentStream(resource, ui));
|
||||||
|
}
|
||||||
|
|
||||||
|
private void openDocumentStream(final StreamResource resource, final UI ui) {
|
||||||
|
StreamRegistration registration = ui.getSession().getResourceRegistry().registerResource(resource);
|
||||||
|
ui.getPage().open(registration.getResourceUri().toString());
|
||||||
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user