From cab12f7ae56da28652239769022e34d42a318056 Mon Sep 17 00:00:00 2001 From: Melina Gutierrez Date: Mon, 25 Nov 2024 15:25:01 -0400 Subject: [PATCH 01/14] =?UTF-8?q?A=C3=B1adir=20restriccion=20para=20la=20e?= =?UTF-8?q?dad=20de=20un=20empleado?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 60 ++++++++++--------- .../primefactorsolutions/model/Employee.java | 1 + .../primefactorsolutions/model/MinAge.java | 17 ++++++ .../model/MinAgeValidator.java | 24 ++++++++ .../views/EmployeeView.java | 14 ++++- 5 files changed, 85 insertions(+), 31 deletions(-) create mode 100644 src/main/java/com/primefactorsolutions/model/MinAge.java create mode 100644 src/main/java/com/primefactorsolutions/model/MinAgeValidator.java diff --git a/package.json b/package.json index 3395e11..209a580 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/main/java/com/primefactorsolutions/model/Employee.java b/src/main/java/com/primefactorsolutions/model/Employee.java index bc83005..83b9d42 100644 --- a/src/main/java/com/primefactorsolutions/model/Employee.java +++ b/src/main/java/com/primefactorsolutions/model/Employee.java @@ -27,6 +27,7 @@ public class Employee extends BaseEntity implements UserDetails { @NotNull(message = "El apellido no puede estar vacío") @Pattern(regexp = "^[a-zA-Z ]+$", message = "El apellido solo debe contener letras") private String lastName; + @MinAge(18) private LocalDate birthday; @Pattern(regexp = "^[a-zA-Z ,]+$", message = "La ciudad de nacimiento solo debe contener letras, espacios o comas") private String birthCity; diff --git a/src/main/java/com/primefactorsolutions/model/MinAge.java b/src/main/java/com/primefactorsolutions/model/MinAge.java new file mode 100644 index 0000000..41ad740 --- /dev/null +++ b/src/main/java/com/primefactorsolutions/model/MinAge.java @@ -0,0 +1,17 @@ +package com.primefactorsolutions.model; + +import jakarta.validation.Constraint; +import jakarta.validation.Payload; + +import java.lang.annotation.*; + +@Documented +@Constraint(validatedBy = MinAgeValidator.class) +@Target({ ElementType.FIELD }) +@Retention(RetentionPolicy.RUNTIME) +public @interface MinAge { + String message() default "El empleado debe ser mayor de {value} años"; + Class[] groups() default {}; + Class[] payload() default {}; + int value(); +} diff --git a/src/main/java/com/primefactorsolutions/model/MinAgeValidator.java b/src/main/java/com/primefactorsolutions/model/MinAgeValidator.java new file mode 100644 index 0000000..980967a --- /dev/null +++ b/src/main/java/com/primefactorsolutions/model/MinAgeValidator.java @@ -0,0 +1,24 @@ +package com.primefactorsolutions.model; + +import jakarta.validation.ConstraintValidator; +import jakarta.validation.ConstraintValidatorContext; + +import java.time.LocalDate; +import java.time.temporal.ChronoUnit; + +public class MinAgeValidator implements ConstraintValidator { + private int minAge; + + @Override + public void initialize(MinAge constraintAnnotation) { + this.minAge = constraintAnnotation.value(); + } + + @Override + public boolean isValid(LocalDate birthday, ConstraintValidatorContext context) { + if (birthday == null) { + return true; + } + return ChronoUnit.YEARS.between(birthday, LocalDate.now()) >= minAge; + } +} diff --git a/src/main/java/com/primefactorsolutions/views/EmployeeView.java b/src/main/java/com/primefactorsolutions/views/EmployeeView.java index 642ef2f..fe3ca60 100644 --- a/src/main/java/com/primefactorsolutions/views/EmployeeView.java +++ b/src/main/java/com/primefactorsolutions/views/EmployeeView.java @@ -178,7 +178,17 @@ public class EmployeeView extends BeanValidationForm implements HasUrl editButton.setVisible(true); reportButton.setVisible(true); birthday.addValueChangeListener(event -> calculateAge()); - birthday.setMax(java.time.LocalDate.now().minusYears(18)); + birthday.setMin(LocalDate.now().minusYears(100)); + birthday.setMax(LocalDate.now().minusYears(18)); + birthday.addValueChangeListener(event -> { + LocalDate selectedDate = event.getValue(); + if (selectedDate != null && ChronoUnit.YEARS.between(selectedDate, LocalDate.now()) < 18) { + birthday.setInvalid(true); + birthday.setErrorMessage("El empleado debe ser mayor de 18 años"); + } else { + birthday.setInvalid(false); + } + }); salaryTotal.addValueChangeListener(event -> calculateSalaryTotal()); dateOfEntry.addValueChangeListener(event -> calculateSeniority()); dateOfExit.addValueChangeListener(event -> { @@ -478,7 +488,7 @@ public class EmployeeView extends BeanValidationForm implements HasUrl editButton.setVisible(false); setFieldsEditable(); upload.setVisible(true); - salaryTotal.setValue(String.valueOf(true)); + salaryTotal.setValue(String.valueOf(0.0)); } else { UUID employeeId = UUID.fromString(s); var employee = employeeService.getEmployee(employeeId); -- 2.34.1 From c9f2e0900a3312c9b93de80f87780b5901ee18b7 Mon Sep 17 00:00:00 2001 From: Melina Gutierrez Date: Mon, 25 Nov 2024 15:33:34 -0400 Subject: [PATCH 02/14] =?UTF-8?q?A=C3=B1adir=20restriccion=20para=20la=20e?= =?UTF-8?q?dad=20de=20un=20empleado?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/com/primefactorsolutions/views/EmployeeView.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/primefactorsolutions/views/EmployeeView.java b/src/main/java/com/primefactorsolutions/views/EmployeeView.java index fe3ca60..0fcc551 100644 --- a/src/main/java/com/primefactorsolutions/views/EmployeeView.java +++ b/src/main/java/com/primefactorsolutions/views/EmployeeView.java @@ -184,7 +184,7 @@ public class EmployeeView extends BeanValidationForm implements HasUrl LocalDate selectedDate = event.getValue(); if (selectedDate != null && ChronoUnit.YEARS.between(selectedDate, LocalDate.now()) < 18) { birthday.setInvalid(true); - birthday.setErrorMessage("El empleado debe ser mayor de 18 años"); + birthday.setErrorMessage("El empleado debe ser mayor o tener 18 años"); } else { birthday.setInvalid(false); } -- 2.34.1 From 9c1921df9acb5b555661e1bf1198bc8d464fd1f4 Mon Sep 17 00:00:00 2001 From: Melina Gutierrez Date: Mon, 25 Nov 2024 16:32:02 -0400 Subject: [PATCH 03/14] Corregir nombre de bono por Antiguedad --- .../primefactorsolutions/model/Employee.java | 5 +++ .../views/EmployeeView.java | 35 +++++++++++++++++-- 2 files changed, 37 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/primefactorsolutions/model/Employee.java b/src/main/java/com/primefactorsolutions/model/Employee.java index 83b9d42..d62f09b 100644 --- a/src/main/java/com/primefactorsolutions/model/Employee.java +++ b/src/main/java/com/primefactorsolutions/model/Employee.java @@ -102,6 +102,7 @@ public class Employee extends BaseEntity implements UserDetails { private String bankName; @Pattern(regexp = "^[0-9]+$", message = "El número de cuenta debe contener solo números") private String accountNumber; + private String customContractType; private String gpss; private String sss; @@ -114,6 +115,10 @@ public class Employee extends BaseEntity implements UserDetails { @Enumerated(EnumType.STRING) private Status status; + public void setCustomContractType(String customContractType) { + this.customContractType = customContractType; + } + @Override public Collection getAuthorities() { return Lists.newArrayList(); diff --git a/src/main/java/com/primefactorsolutions/views/EmployeeView.java b/src/main/java/com/primefactorsolutions/views/EmployeeView.java index 0fcc551..1e15de9 100644 --- a/src/main/java/com/primefactorsolutions/views/EmployeeView.java +++ b/src/main/java/com/primefactorsolutions/views/EmployeeView.java @@ -106,10 +106,11 @@ public class EmployeeView extends BeanValidationForm implements HasUrl private final VDatePicker dateOfEntry = new VDatePicker("Fecha de Ingreso"); private final VDatePicker dateOfExit = new VDatePicker("Fecha de Retiro"); private final ComboBox contractType = createContractTypeComboBox(); + private final TextField customContractType = createCustomContractTypeField(); private final TextField seniority = createTextField("Antiguedad", 30, false); private final TextField salaryTotal = createTextField("Salario Total", 10, false); private final TextField salaryBasic = createTextField("Salario Basico", 10, false); - private final TextField antiguedad = createTextField("Descuento por Antiguedad", 10, false); + private final TextField antiguedad = createTextField("Bono de Antiguedad", 10, false); private final TextField bonoProfesional = createTextField("Bono Profesional", 30, false); private final TextField bankName = createTextField("Banco", 30, false); private final TextField accountNumber = createTextField("Nro. de Cuenta", 30, false); @@ -383,10 +384,30 @@ public class EmployeeView extends BeanValidationForm implements HasUrl comboBox.setItemLabelGenerator(Employee.ContractType::name); comboBox.setRequiredIndicatorVisible(true); comboBox.setWidth("300px"); - comboBox.setMinWidth("200px"); + comboBox.addValueChangeListener(event -> handleContractTypeChange(event.getValue())); return comboBox; } + private TextField createCustomContractTypeField() { + TextField textField = new TextField("Especificar Tipo de Contrato"); + textField.setPlaceholder("Ingrese el tipo de contrato..."); + textField.setVisible(false); + textField.setWidth("300px"); + return textField; + } + + private void handleContractTypeChange(Employee.ContractType selectedType) { + if (selectedType == Employee.ContractType.OTROS) { + customContractType.setVisible(true); + customContractType.setRequired(true); + } else { + customContractType.setVisible(false); + customContractType.clear(); + customContractType.setRequired(false); + } + } + + private VerticalLayout createContentLayout() { VerticalLayout contentLayout = new VerticalLayout(); contentLayout.setWidth("100%"); @@ -464,6 +485,12 @@ public class EmployeeView extends BeanValidationForm implements HasUrl employee.setBonoProfesional(bonoProfesional.getValue()); employee.setAntiguedad(antiguedad.getValue()); employee.setSalarytotal((salaryTotal.getValue())); + employee.setContractType(contractType.getValue()); + if (contractType.getValue() == Employee.ContractType.OTROS) { + employee.setCustomContractType(customContractType.getValue()); + } else { + employee.setCustomContractType(null); + } employeeService.createOrUpdate(employee); Notification.show(NOTIFICATION_SAVE_SUCCESS); getUI().ifPresent(ui -> ui.navigate(EmployeesListView.class)); @@ -575,6 +602,7 @@ public class EmployeeView extends BeanValidationForm implements HasUrl dateOfEntry.setReadOnly(true); dateOfExit.setReadOnly(true); contractType.setReadOnly(true); + customContractType.setReadOnly(true); seniority.setReadOnly(true); salaryTotal.setReadOnly(true); salaryBasic.setReadOnly(true); @@ -637,6 +665,7 @@ public class EmployeeView extends BeanValidationForm implements HasUrl dateOfEntry.setReadOnly(false); dateOfExit.setReadOnly(false); contractType.setReadOnly(false); + customContractType.setReadOnly(false); seniority.setReadOnly(false); salaryTotal.setReadOnly(false); salaryBasic.setReadOnly(false); @@ -671,7 +700,7 @@ public class EmployeeView extends BeanValidationForm implements HasUrl idioma, language1, language1Level, language2, language2Level, infoAdm, cod, position, team, leadManager, - infoCont, dateOfEntry, dateOfExit, contractType, seniority, + infoCont, dateOfEntry, dateOfExit, seniority, contractType, customContractType, salaryBasic, bonoProfesional, antiguedad, salaryTotal, datBanc, bankName, accountNumber, datGest, gpss, sss, beneficiarie1, beneficiarie2, -- 2.34.1 From dc1881ffede13e6eeb36fbc52a36c016c8ce499c Mon Sep 17 00:00:00 2001 From: Melina Gutierrez Date: Mon, 25 Nov 2024 19:35:42 -0400 Subject: [PATCH 04/14] Arreglar generar un reporte de Horas Trabajadas --- .../repositories/EmployeeRepository.java | 1 + .../com/primefactorsolutions/service/EmployeeService.java | 7 +------ 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/src/main/java/com/primefactorsolutions/repositories/EmployeeRepository.java b/src/main/java/com/primefactorsolutions/repositories/EmployeeRepository.java index a72f647..573763c 100644 --- a/src/main/java/com/primefactorsolutions/repositories/EmployeeRepository.java +++ b/src/main/java/com/primefactorsolutions/repositories/EmployeeRepository.java @@ -11,5 +11,6 @@ public interface EmployeeRepository extends JpaRepository { Optional findByUsername(String username); Optional findByPersonalEmail(String personalEmail); List findAllByTeamId(UUID teamId); + Optional findByTeamIdAndLeadManagerTrue(UUID teamId); List findByTeamName(String teamName); } \ No newline at end of file diff --git a/src/main/java/com/primefactorsolutions/service/EmployeeService.java b/src/main/java/com/primefactorsolutions/service/EmployeeService.java index 1f374e8..b63bb47 100644 --- a/src/main/java/com/primefactorsolutions/service/EmployeeService.java +++ b/src/main/java/com/primefactorsolutions/service/EmployeeService.java @@ -50,12 +50,7 @@ public class EmployeeService { } public String getTeamLeadName(final UUID teamId) { - // Encuentra al empleado con el rol de lead_manager en el equipo especificado - List teamMembers = employeeRepository.findAllByTeamId(teamId); - Optional leadManager = teamMembers.stream() - .filter(e -> Strings.isNullOrEmpty(e.getLeadManager())) - .findFirst(); - + Optional leadManager = employeeRepository.findByTeamIdAndLeadManagerTrue(teamId); return leadManager.map(employee -> employee.getFirstName() + " " + employee.getLastName()) .orElse("No asignado"); } -- 2.34.1 From b2fc5663fd30e16cc2768d308466e4524208b228 Mon Sep 17 00:00:00 2001 From: Melina Gutierrez Date: Mon, 25 Nov 2024 19:39:59 -0400 Subject: [PATCH 05/14] Aumentar final a parametros --- src/main/java/com/primefactorsolutions/model/Employee.java | 2 +- .../java/com/primefactorsolutions/model/MinAgeValidator.java | 4 ++-- .../com/primefactorsolutions/service/EmployeeService.java | 1 - .../java/com/primefactorsolutions/views/EmployeeView.java | 2 +- 4 files changed, 4 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/primefactorsolutions/model/Employee.java b/src/main/java/com/primefactorsolutions/model/Employee.java index d62f09b..173704a 100644 --- a/src/main/java/com/primefactorsolutions/model/Employee.java +++ b/src/main/java/com/primefactorsolutions/model/Employee.java @@ -115,7 +115,7 @@ public class Employee extends BaseEntity implements UserDetails { @Enumerated(EnumType.STRING) private Status status; - public void setCustomContractType(String customContractType) { + public void setCustomContractType(final String customContractType) { this.customContractType = customContractType; } diff --git a/src/main/java/com/primefactorsolutions/model/MinAgeValidator.java b/src/main/java/com/primefactorsolutions/model/MinAgeValidator.java index 980967a..5c453f2 100644 --- a/src/main/java/com/primefactorsolutions/model/MinAgeValidator.java +++ b/src/main/java/com/primefactorsolutions/model/MinAgeValidator.java @@ -10,12 +10,12 @@ public class MinAgeValidator implements ConstraintValidator { private int minAge; @Override - public void initialize(MinAge constraintAnnotation) { + public void initialize(final MinAge constraintAnnotation) { this.minAge = constraintAnnotation.value(); } @Override - public boolean isValid(LocalDate birthday, ConstraintValidatorContext context) { + public boolean isValid(final LocalDate birthday, final ConstraintValidatorContext context) { if (birthday == null) { return true; } diff --git a/src/main/java/com/primefactorsolutions/service/EmployeeService.java b/src/main/java/com/primefactorsolutions/service/EmployeeService.java index b63bb47..c7ac471 100644 --- a/src/main/java/com/primefactorsolutions/service/EmployeeService.java +++ b/src/main/java/com/primefactorsolutions/service/EmployeeService.java @@ -1,5 +1,4 @@ package com.primefactorsolutions.service; -import com.google.common.base.Strings; import com.primefactorsolutions.model.Employee; import jakarta.persistence.EntityManager; import lombok.AllArgsConstructor; diff --git a/src/main/java/com/primefactorsolutions/views/EmployeeView.java b/src/main/java/com/primefactorsolutions/views/EmployeeView.java index 1e15de9..e717138 100644 --- a/src/main/java/com/primefactorsolutions/views/EmployeeView.java +++ b/src/main/java/com/primefactorsolutions/views/EmployeeView.java @@ -396,7 +396,7 @@ public class EmployeeView extends BeanValidationForm implements HasUrl return textField; } - private void handleContractTypeChange(Employee.ContractType selectedType) { + private void handleContractTypeChange(final Employee.ContractType selectedType) { if (selectedType == Employee.ContractType.OTROS) { customContractType.setVisible(true); customContractType.setRequired(true); -- 2.34.1 From deb7acc4a407f8e976a72c149fe0daf46418f874 Mon Sep 17 00:00:00 2001 From: Melina Gutierrez Date: Mon, 25 Nov 2024 23:30:27 -0400 Subject: [PATCH 06/14] =?UTF-8?q?A=C3=B1adir=20generar=20reporte=20excel?= =?UTF-8?q?=20de=20los=20empleados?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../views/EmployeesListView.java | 47 +++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/src/main/java/com/primefactorsolutions/views/EmployeesListView.java b/src/main/java/com/primefactorsolutions/views/EmployeesListView.java index d910b87..dfffa09 100644 --- a/src/main/java/com/primefactorsolutions/views/EmployeesListView.java +++ b/src/main/java/com/primefactorsolutions/views/EmployeesListView.java @@ -3,15 +3,22 @@ package com.primefactorsolutions.views; import com.primefactorsolutions.model.Employee; import com.primefactorsolutions.service.EmployeeService; import com.vaadin.flow.component.button.Button; +import com.vaadin.flow.component.html.Anchor; import com.vaadin.flow.router.PageTitle; import com.vaadin.flow.router.Route; +import com.vaadin.flow.server.StreamResource; import com.vaadin.flow.spring.annotation.SpringComponent; +import org.apache.poi.ss.usermodel.*; +import org.apache.poi.xssf.usermodel.XSSFWorkbook; import org.vaadin.firitin.components.grid.PagingGrid; import com.vaadin.flow.component.grid.GridSortOrder; import com.vaadin.flow.data.provider.SortDirection; import jakarta.annotation.security.PermitAll; import org.springframework.context.annotation.Scope; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.IOException; import java.util.List; @SpringComponent @@ -33,9 +40,49 @@ public class EmployeesListView extends BaseView { private void setupView() { configureTable(); getCurrentPageLayout().add(createAddEmployeeButton()); + getCurrentPageLayout().add(createExportButton()); getCurrentPageLayout().add(table); } + private Button createExportButton() { + StreamResource excelResource = new StreamResource("employees.xlsx", this::generateExcel); + Anchor downloadLink = new Anchor(excelResource, "Export Employees"); + downloadLink.getElement().setAttribute("download", true); // Forzar descarga + return new Button("Export to Excel", e -> getCurrentPageLayout().add(downloadLink)); + } + + private ByteArrayInputStream generateExcel() { + List employees = employeeService.findAllEmployees(); + try (Workbook workbook = new XSSFWorkbook(); ByteArrayOutputStream out = new ByteArrayOutputStream()) { + Sheet sheet = workbook.createSheet("Employees"); + Row headerRow = sheet.createRow(0); + String[] headers = {"ID", "First Name", "Last Name", "Status", "Team"}; + for (int i = 0; i < headers.length; i++) { + Cell cell = headerRow.createCell(i); + cell.setCellValue(headers[i]); + CellStyle style = workbook.createCellStyle(); + Font font = workbook.createFont(); + font.setBold(true); + style.setFont(font); + cell.setCellStyle(style); + } + int rowIndex = 1; + for (Employee employee : employees) { + Row row = sheet.createRow(rowIndex++); + row.createCell(0).setCellValue(employee.getId().toString()); + row.createCell(1).setCellValue(employee.getFirstName()); + row.createCell(2).setCellValue(employee.getLastName()); + row.createCell(3).setCellValue(employee.getStatus().toString()); + row.createCell(4).setCellValue(employee.getTeam().toString()); + } + workbook.write(out); + return new ByteArrayInputStream(out.toByteArray()); + } catch (IOException e) { + e.printStackTrace(); + return null; + } + } + private void configureTable() { table.setColumns("firstName", "lastName", "status"); addEditButtonColumn("View", this::navigateToEmployeeView); -- 2.34.1 From 3fa90b925b0ed638a0cd95b42409d5b3d72ca3af Mon Sep 17 00:00:00 2001 From: Melina Gutierrez Date: Tue, 26 Nov 2024 10:34:42 -0400 Subject: [PATCH 07/14] Volver a la correcion de getTeamLead --- .../repositories/EmployeeRepository.java | 2 +- .../com/primefactorsolutions/service/EmployeeService.java | 7 ++++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/primefactorsolutions/repositories/EmployeeRepository.java b/src/main/java/com/primefactorsolutions/repositories/EmployeeRepository.java index 573763c..0957e0e 100644 --- a/src/main/java/com/primefactorsolutions/repositories/EmployeeRepository.java +++ b/src/main/java/com/primefactorsolutions/repositories/EmployeeRepository.java @@ -11,6 +11,6 @@ public interface EmployeeRepository extends JpaRepository { Optional findByUsername(String username); Optional findByPersonalEmail(String personalEmail); List findAllByTeamId(UUID teamId); - Optional findByTeamIdAndLeadManagerTrue(UUID teamId); + //Optional findByTeamIdAndLeadManagerTrue(UUID teamId); List findByTeamName(String teamName); } \ No newline at end of file diff --git a/src/main/java/com/primefactorsolutions/service/EmployeeService.java b/src/main/java/com/primefactorsolutions/service/EmployeeService.java index c7ac471..f426d01 100644 --- a/src/main/java/com/primefactorsolutions/service/EmployeeService.java +++ b/src/main/java/com/primefactorsolutions/service/EmployeeService.java @@ -1,4 +1,5 @@ package com.primefactorsolutions.service; +import com.google.common.base.Strings; import com.primefactorsolutions.model.Employee; import jakarta.persistence.EntityManager; import lombok.AllArgsConstructor; @@ -49,7 +50,11 @@ public class EmployeeService { } public String getTeamLeadName(final UUID teamId) { - Optional leadManager = employeeRepository.findByTeamIdAndLeadManagerTrue(teamId); + // Encuentra al empleado con el rol de lead_manager en el equipo especificado + List teamMembers = employeeRepository.findAllByTeamId(teamId); + Optional leadManager = teamMembers.stream() + .filter(e -> Strings.isNullOrEmpty(e.getLeadManager())) + .findFirst(); return leadManager.map(employee -> employee.getFirstName() + " " + employee.getLastName()) .orElse("No asignado"); } -- 2.34.1 From e38c47c0e7c77a36546160c0916c37e76df95cdf Mon Sep 17 00:00:00 2001 From: Melina Gutierrez Date: Wed, 27 Nov 2024 13:21:57 -0400 Subject: [PATCH 08/14] contrarto mixto correccion de nombre --- src/main/java/com/primefactorsolutions/model/Employee.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/primefactorsolutions/model/Employee.java b/src/main/java/com/primefactorsolutions/model/Employee.java index 173704a..02a9e14 100644 --- a/src/main/java/com/primefactorsolutions/model/Employee.java +++ b/src/main/java/com/primefactorsolutions/model/Employee.java @@ -186,7 +186,7 @@ public class Employee extends BaseEntity implements UserDetails { CONTRATO_PLAZO_FIJO, CONSULTORIA_INTERNA, CONSULTORIA_EXTERNA, - MIXTO, + CONTRATO_MIXTO, OTROS } -- 2.34.1 From 69ac876d587cd22a5947725c1b40a619d59b9a7d Mon Sep 17 00:00:00 2001 From: Melina Gutierrez Date: Wed, 27 Nov 2024 13:26:27 -0400 Subject: [PATCH 09/14] =?UTF-8?q?A=C3=B1adir=20nuevas=20columnas=20para=20?= =?UTF-8?q?generar=20el=20reporte=20de=20Empleados?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../views/EmployeesListView.java | 35 +++++++++++++++++-- 1 file changed, 33 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/primefactorsolutions/views/EmployeesListView.java b/src/main/java/com/primefactorsolutions/views/EmployeesListView.java index dfffa09..1541dcc 100644 --- a/src/main/java/com/primefactorsolutions/views/EmployeesListView.java +++ b/src/main/java/com/primefactorsolutions/views/EmployeesListView.java @@ -56,7 +56,14 @@ public class EmployeesListView extends BaseView { try (Workbook workbook = new XSSFWorkbook(); ByteArrayOutputStream out = new ByteArrayOutputStream()) { Sheet sheet = workbook.createSheet("Employees"); Row headerRow = sheet.createRow(0); - String[] headers = {"ID", "First Name", "Last Name", "Status", "Team"}; + String[] headers = { + "ID", "Nombres", "Apellidos", "Status", "Genero", "Fecha de Nacimiento", "Edad", + "Ciudad y Pais de Nacimiento", "Dirección de Residencia", "Departamento y Provincia de Residencia", "Marital Status", + "Numero de Hijos", "CI", "Expedido en", "Teléfono", "E-mail", + "Teléfono Laboral", "E-mail Laboral", "Codigo de Empleado", "Cargo", + "Equipo", "Lead/Manager", "Fecha de Ingreso", "Fecha de Retiro", "Tipo de Contrato", + "Otro Tipo de Contrato", "Antiguedad", "Salario Total" + }; for (int i = 0; i < headers.length; i++) { Cell cell = headerRow.createCell(i); cell.setCellValue(headers[i]); @@ -73,7 +80,30 @@ public class EmployeesListView extends BaseView { row.createCell(1).setCellValue(employee.getFirstName()); row.createCell(2).setCellValue(employee.getLastName()); row.createCell(3).setCellValue(employee.getStatus().toString()); - row.createCell(4).setCellValue(employee.getTeam().toString()); + row.createCell(4).setCellValue(employee.getGender() != null ? employee.getGender().toString() : ""); + row.createCell(5).setCellValue(employee.getBirthday() != null ? employee.getBirthday().toString() : ""); + row.createCell(6).setCellValue(employee.getAge() != null ? employee.getAge().toString() : ""); + row.createCell(7).setCellValue(employee.getBirthCity() != null ? employee.getBirthCity() : ""); + row.createCell(8).setCellValue(employee.getResidenceAddress() != null ? employee.getResidenceAddress() : ""); + row.createCell(9).setCellValue(employee.getLocalAddress() != null ? employee.getLocalAddress() : ""); + row.createCell(10).setCellValue(employee.getMaritalStatus() != null ? employee.getMaritalStatus().toString() : ""); + row.createCell(11).setCellValue(employee.getNumberOfChildren() != null ? employee.getNumberOfChildren().toString() : ""); + row.createCell(12).setCellValue(employee.getCi() != null ? employee.getCi() : ""); + row.createCell(13).setCellValue(employee.getIssuedIn() != null ? employee.getIssuedIn() : ""); + row.createCell(14).setCellValue(employee.getPhoneNumber() != null ? employee.getPhoneNumber() : ""); + row.createCell(15).setCellValue(employee.getPersonalEmail() != null ? employee.getPersonalEmail() : ""); + row.createCell(16).setCellValue(employee.getPhoneNumberProfesional() != null ? employee.getPhoneNumberProfesional() : ""); + row.createCell(17).setCellValue(employee.getProfesionalEmail() != null ? employee.getProfesionalEmail() : ""); + row.createCell(18).setCellValue(employee.getCod() != null ? employee.getCod() : ""); + row.createCell(19).setCellValue(employee.getPosition() != null ? employee.getPosition() : ""); + row.createCell(20).setCellValue(employee.getTeam() != null ? employee.getTeam().getName() : ""); + row.createCell(21).setCellValue(employee.getLeadManager() != null ? employee.getLeadManager() : ""); + row.createCell(22).setCellValue(employee.getDateOfEntry() != null ? employee.getDateOfEntry().toString() : ""); + row.createCell(23).setCellValue(employee.getDateOfExit() != null ? employee.getDateOfExit().toString() : ""); + row.createCell(24).setCellValue(employee.getContractType() != null ? employee.getContractType().toString() : ""); + row.createCell(25).setCellValue(employee.getCustomContractType() != null ? employee.getCustomContractType() : ""); + row.createCell(26).setCellValue(employee.getSeniority() != null ? employee.getSeniority() : ""); + row.createCell(27).setCellValue(employee.getSalarytotal() != null ? employee.getSalarytotal() : ""); } workbook.write(out); return new ByteArrayInputStream(out.toByteArray()); @@ -83,6 +113,7 @@ public class EmployeesListView extends BaseView { } } + private void configureTable() { table.setColumns("firstName", "lastName", "status"); addEditButtonColumn("View", this::navigateToEmployeeView); -- 2.34.1 From fe517735ad313f250c5bcdbe24b83ae884c74e54 Mon Sep 17 00:00:00 2001 From: Melina Gutierrez Date: Wed, 27 Nov 2024 15:06:06 -0400 Subject: [PATCH 10/14] =?UTF-8?q?cambiar=20a=20espa=C3=B1ol=20el=20boton?= =?UTF-8?q?=20de=20exportar=20como=20excel?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/primefactorsolutions/views/EmployeesListView.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/primefactorsolutions/views/EmployeesListView.java b/src/main/java/com/primefactorsolutions/views/EmployeesListView.java index 1541dcc..5f759f0 100644 --- a/src/main/java/com/primefactorsolutions/views/EmployeesListView.java +++ b/src/main/java/com/primefactorsolutions/views/EmployeesListView.java @@ -48,7 +48,7 @@ public class EmployeesListView extends BaseView { StreamResource excelResource = new StreamResource("employees.xlsx", this::generateExcel); Anchor downloadLink = new Anchor(excelResource, "Export Employees"); downloadLink.getElement().setAttribute("download", true); // Forzar descarga - return new Button("Export to Excel", e -> getCurrentPageLayout().add(downloadLink)); + return new Button("Exportar como Excel", e -> getCurrentPageLayout().add(downloadLink)); } private ByteArrayInputStream generateExcel() { -- 2.34.1 From 122ce7fbe305c9bc21bd7a3b3fbcf4a8ed5cdc02 Mon Sep 17 00:00:00 2001 From: Melina Gutierrez Date: Wed, 27 Nov 2024 20:20:14 -0400 Subject: [PATCH 11/14] =?UTF-8?q?A=C3=B1adir=20subtitulo=20de=20insertar?= =?UTF-8?q?=20imagen=20jpg?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/primefactorsolutions/views/EmployeeView.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/primefactorsolutions/views/EmployeeView.java b/src/main/java/com/primefactorsolutions/views/EmployeeView.java index e717138..33f4499 100644 --- a/src/main/java/com/primefactorsolutions/views/EmployeeView.java +++ b/src/main/java/com/primefactorsolutions/views/EmployeeView.java @@ -15,9 +15,7 @@ import com.vaadin.flow.component.button.Button; import com.vaadin.flow.component.button.ButtonVariant; import com.vaadin.flow.component.combobox.ComboBox; import com.vaadin.flow.component.dialog.Dialog; -import com.vaadin.flow.component.html.H2; -import com.vaadin.flow.component.html.H3; -import com.vaadin.flow.component.html.Image; +import com.vaadin.flow.component.html.*; import com.vaadin.flow.component.notification.Notification; import com.vaadin.flow.component.orderedlayout.FlexComponent; import com.vaadin.flow.component.orderedlayout.HorizontalLayout; @@ -130,6 +128,7 @@ public class EmployeeView extends BeanValidationForm implements HasUrl private final PdfViewer pdfViewer = new PdfViewer(); private final H2 infoPer = new H2("Información Personal"); private final H3 infoGenr = new H3("Información General"); + private final H5 imagenSub = new H5("Insertar una imagen .jpg:"); private final H3 contEmerg = new H3("Contacto de Emergencia"); private final H2 infProf = new H2("Información Profesional"); private final H3 titulos = new H3("Titulos Profesionales y Estudios Realizados"); @@ -685,6 +684,7 @@ public class EmployeeView extends BeanValidationForm implements HasUrl username, infoPer, infoGenr, + imagenSub, upload, profileImagePreview, firstName, lastName, gender, status, -- 2.34.1 From 88b3fcdd4f9630a42c943e81161e6d1f67525291 Mon Sep 17 00:00:00 2001 From: Melina Gutierrez Date: Wed, 27 Nov 2024 20:21:36 -0400 Subject: [PATCH 12/14] Modificar boton --- src/main/java/com/primefactorsolutions/views/EmployeeView.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/primefactorsolutions/views/EmployeeView.java b/src/main/java/com/primefactorsolutions/views/EmployeeView.java index 33f4499..0c3c60e 100644 --- a/src/main/java/com/primefactorsolutions/views/EmployeeView.java +++ b/src/main/java/com/primefactorsolutions/views/EmployeeView.java @@ -123,7 +123,7 @@ public class EmployeeView extends BeanValidationForm implements HasUrl private static final String PHONE_NUMBER_ERROR_MESSAGE = "El teléfono debe contener solo números."; private final Button saveButton = new Button(SAVE_BUTTON_TEXT, e -> saveEmployee()); private final Button editButton = new Button(EDIT_BUTTON_TEXT, e -> enableEditMode()); - private final Button reportButton = new Button("Generar Ficha"); + private final Button reportButton = new Button("Generar Ficha de Contratación"); private final Dialog dialog = new Dialog(); private final PdfViewer pdfViewer = new PdfViewer(); private final H2 infoPer = new H2("Información Personal"); -- 2.34.1 From 5d75b322b100a1532f655aab0f74aaec3e87f7ca Mon Sep 17 00:00:00 2001 From: Melina Gutierrez Date: Wed, 27 Nov 2024 20:23:08 -0400 Subject: [PATCH 13/14] Modificar boton de cerrar por cancelar --- .../java/com/primefactorsolutions/views/HoursWorkedView.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/primefactorsolutions/views/HoursWorkedView.java b/src/main/java/com/primefactorsolutions/views/HoursWorkedView.java index e702791..b191f99 100644 --- a/src/main/java/com/primefactorsolutions/views/HoursWorkedView.java +++ b/src/main/java/com/primefactorsolutions/views/HoursWorkedView.java @@ -133,7 +133,7 @@ public class HoursWorkedView extends BeanValidationForm implements } protected Button createCloseButton() { - Button closeButton = new Button("Cerrar"); + Button closeButton = new Button("Cancelar"); closeButton.addClickListener(event -> closeForm()); return closeButton; } -- 2.34.1 From c16405a8d84b2c1faac696d22defc120e9056798 Mon Sep 17 00:00:00 2001 From: Melina Gutierrez Date: Wed, 27 Nov 2024 21:34:26 -0400 Subject: [PATCH 14/14] corregir estilos maven --- .../views/EmployeesListView.java | 38 +++++++++++++------ 1 file changed, 26 insertions(+), 12 deletions(-) diff --git a/src/main/java/com/primefactorsolutions/views/EmployeesListView.java b/src/main/java/com/primefactorsolutions/views/EmployeesListView.java index 5f759f0..31799b2 100644 --- a/src/main/java/com/primefactorsolutions/views/EmployeesListView.java +++ b/src/main/java/com/primefactorsolutions/views/EmployeesListView.java @@ -58,7 +58,8 @@ public class EmployeesListView extends BaseView { Row headerRow = sheet.createRow(0); String[] headers = { "ID", "Nombres", "Apellidos", "Status", "Genero", "Fecha de Nacimiento", "Edad", - "Ciudad y Pais de Nacimiento", "Dirección de Residencia", "Departamento y Provincia de Residencia", "Marital Status", + "Ciudad y Pais de Nacimiento", "Dirección de Residencia", "Departamento y Provincia de Residencia", + "Marital Status", "Numero de Hijos", "CI", "Expedido en", "Teléfono", "E-mail", "Teléfono Laboral", "E-mail Laboral", "Codigo de Empleado", "Cargo", "Equipo", "Lead/Manager", "Fecha de Ingreso", "Fecha de Retiro", "Tipo de Contrato", @@ -81,27 +82,38 @@ public class EmployeesListView extends BaseView { row.createCell(2).setCellValue(employee.getLastName()); row.createCell(3).setCellValue(employee.getStatus().toString()); row.createCell(4).setCellValue(employee.getGender() != null ? employee.getGender().toString() : ""); - row.createCell(5).setCellValue(employee.getBirthday() != null ? employee.getBirthday().toString() : ""); + row.createCell(5).setCellValue(employee.getBirthday() != null ? employee.getBirthday() + .toString() : ""); row.createCell(6).setCellValue(employee.getAge() != null ? employee.getAge().toString() : ""); row.createCell(7).setCellValue(employee.getBirthCity() != null ? employee.getBirthCity() : ""); - row.createCell(8).setCellValue(employee.getResidenceAddress() != null ? employee.getResidenceAddress() : ""); + row.createCell(8).setCellValue(employee.getResidenceAddress() != null ? employee + .getResidenceAddress() : ""); row.createCell(9).setCellValue(employee.getLocalAddress() != null ? employee.getLocalAddress() : ""); - row.createCell(10).setCellValue(employee.getMaritalStatus() != null ? employee.getMaritalStatus().toString() : ""); - row.createCell(11).setCellValue(employee.getNumberOfChildren() != null ? employee.getNumberOfChildren().toString() : ""); + row.createCell(10).setCellValue(employee.getMaritalStatus() != null ? employee.getMaritalStatus() + .toString() : ""); + row.createCell(11).setCellValue(employee.getNumberOfChildren() != null ? employee + .getNumberOfChildren().toString() : ""); row.createCell(12).setCellValue(employee.getCi() != null ? employee.getCi() : ""); row.createCell(13).setCellValue(employee.getIssuedIn() != null ? employee.getIssuedIn() : ""); row.createCell(14).setCellValue(employee.getPhoneNumber() != null ? employee.getPhoneNumber() : ""); - row.createCell(15).setCellValue(employee.getPersonalEmail() != null ? employee.getPersonalEmail() : ""); - row.createCell(16).setCellValue(employee.getPhoneNumberProfesional() != null ? employee.getPhoneNumberProfesional() : ""); - row.createCell(17).setCellValue(employee.getProfesionalEmail() != null ? employee.getProfesionalEmail() : ""); + row.createCell(15).setCellValue(employee.getPersonalEmail() != null ? employee + .getPersonalEmail() : ""); + row.createCell(16).setCellValue(employee.getPhoneNumberProfesional() != null ? employee + .getPhoneNumberProfesional() : ""); + row.createCell(17).setCellValue(employee.getProfesionalEmail() != null ? employee + .getProfesionalEmail() : ""); row.createCell(18).setCellValue(employee.getCod() != null ? employee.getCod() : ""); row.createCell(19).setCellValue(employee.getPosition() != null ? employee.getPosition() : ""); row.createCell(20).setCellValue(employee.getTeam() != null ? employee.getTeam().getName() : ""); row.createCell(21).setCellValue(employee.getLeadManager() != null ? employee.getLeadManager() : ""); - row.createCell(22).setCellValue(employee.getDateOfEntry() != null ? employee.getDateOfEntry().toString() : ""); - row.createCell(23).setCellValue(employee.getDateOfExit() != null ? employee.getDateOfExit().toString() : ""); - row.createCell(24).setCellValue(employee.getContractType() != null ? employee.getContractType().toString() : ""); - row.createCell(25).setCellValue(employee.getCustomContractType() != null ? employee.getCustomContractType() : ""); + row.createCell(22).setCellValue(employee.getDateOfEntry() != null ? employee.getDateOfEntry() + .toString() : ""); + row.createCell(23).setCellValue(employee.getDateOfExit() != null ? employee.getDateOfExit() + .toString() : ""); + row.createCell(24).setCellValue(employee.getContractType() != null ? employee.getContractType() + .toString() : ""); + row.createCell(25).setCellValue(employee.getCustomContractType() != null ? employee + .getCustomContractType() : ""); row.createCell(26).setCellValue(employee.getSeniority() != null ? employee.getSeniority() : ""); row.createCell(27).setCellValue(employee.getSalarytotal() != null ? employee.getSalarytotal() : ""); } @@ -132,6 +144,7 @@ public class EmployeesListView extends BaseView { } private Button createAddEmployeeButton() { + return createButton("Add Employee", this::navigateToAddEmployeeView); } @@ -144,6 +157,7 @@ public class EmployeesListView extends BaseView { } private void navigateToAddEmployeeView() { + getUI().ifPresent(ui -> ui.navigate(EmployeeView.class, "new")); } -- 2.34.1