diff --git a/src/main/java/com/primefactorsolutions/model/Employee.java b/src/main/java/com/primefactorsolutions/model/Employee.java index d728388..bc83005 100644 --- a/src/main/java/com/primefactorsolutions/model/Employee.java +++ b/src/main/java/com/primefactorsolutions/model/Employee.java @@ -61,7 +61,7 @@ public class Employee extends BaseEntity implements UserDetails { @Email(message = "El correo de contacto de emergencia no tiene un formato válido") private String emergencyCEmail; private String numberOfChildren; - + @Pattern(regexp = "^[a-zA-Z0-9]+$", message = "El CI debe contener solo letras y números") private String ci; private String issuedIn; private String pTitle1; @@ -173,11 +173,17 @@ public class Employee extends BaseEntity implements UserDetails { @Enumerated(EnumType.STRING) private ContractType contractType; + public enum ContractType { CONTRATO_LABORAL, CONTRATO_CIVIL_O_SERVICIOS, CONTRATO_PLAZO_FIJO, CONSULTORIA_INTERNA, - CONSULTORIA_EXTERNA + CONSULTORIA_EXTERNA, + MIXTO, + OTROS } -} + + @Size(max = 255, message = "El detalle del contrato no debe exceder 255 caracteres") + private String otherContractDetail; +} \ No newline at end of file diff --git a/src/main/java/com/primefactorsolutions/model/HoursWorked.java b/src/main/java/com/primefactorsolutions/model/HoursWorked.java index 888b5fb..4ee8934 100644 --- a/src/main/java/com/primefactorsolutions/model/HoursWorked.java +++ b/src/main/java/com/primefactorsolutions/model/HoursWorked.java @@ -28,15 +28,24 @@ public class HoursWorked extends BaseEntity { private int weekNumber; private LocalDate date; private String actividad; - private String tareasEspecificas; private double hours; - private double horasTareasEspecificas; private double horaspendientes; private double totalHours; + private String tareaEspecifica; + + public String getTareaEspecifica() { + return tareaEspecifica; + } + + public void setTareaEspecifica(String tareaEspecifica) { + this.tareaEspecifica = tareaEspecifica; + } + + public static double calculateTotalHours(final List activities) { return activities.stream() - .mapToDouble(activity -> activity.hours + activity.horasTareasEspecificas) + .mapToDouble(activity -> activity.hours) .sum(); } @@ -105,21 +114,6 @@ public class HoursWorked extends BaseEntity { this.team = team; } - public String getTareasEspecificas() { - return tareasEspecificas; - } - - public void setTareasEspecificas(final String tareasEspecificas) { - this.tareasEspecificas = tareasEspecificas; - } - - public double getHorasTareasEspecificas() { - return horasTareasEspecificas; - } - - public void setHorasTareasEspecificas(final double horasTareasEspecificas) { - this.tareasEspecificas = tareasEspecificas; - } public double getHoraspendientes() { //double horasTrabajadas = this.getTotalHours() + this.getHorasTareasEspecificas(); return 40; @@ -129,21 +123,4 @@ public class HoursWorked extends BaseEntity { this.horaspendientes = horaspendientes; } - public double getHoursWorked() { - return hours; - } - - public void setHoursWorked(final double hoursWorked) { - this.hours = hoursWorked; - } - - public double getTotalHoursWorked() { - return totalHours; - } - - public void setTotalHoursWorked(final double totalHoursWorked) { - this.totalHours = totalHoursWorked; - } - - } diff --git a/src/main/java/com/primefactorsolutions/views/HoursWorkedListView.java b/src/main/java/com/primefactorsolutions/views/HoursWorkedListView.java index 6b8bf52..7b5e446 100644 --- a/src/main/java/com/primefactorsolutions/views/HoursWorkedListView.java +++ b/src/main/java/com/primefactorsolutions/views/HoursWorkedListView.java @@ -114,7 +114,6 @@ public class HoursWorkedListView extends BaseView { setupFilters(); setupListHoursWorkedGrid(); getCurrentPageLayout().add(hoursWorkedGrid); - getCurrentPageLayout().add(createActionButtons()); } private void setupFilters() { @@ -137,11 +136,21 @@ public class HoursWorkedListView extends BaseView { hoursWorkedGrid.addColumn(hw -> hw.getEmployee().getTeam() != null ? hw.getEmployee().getTeam() .getName() : "Sin asignar") .setHeader("Equipo"); - hoursWorkedGrid.addColumn(HoursWorked::getActividad).setHeader("Actividad"); - hoursWorkedGrid.addColumn(HoursWorked::getHours).setHeader("Total Horas").setSortable(true); + hoursWorkedGrid.addColumn(hw -> { + String actividad = hw.getActividad() != null ? hw.getActividad() : "Sin Actividad"; + String tareaEspecifica = hw.getTareaEspecifica() != null ? hw.getTareaEspecifica() : ""; + return !tareaEspecifica.isEmpty() ? tareaEspecifica : actividad; + }).setHeader("Actividad"); + hoursWorkedGrid.addColumn(hw -> { + if (hw.getTareaEspecifica() != null && !hw.getTareaEspecifica().isEmpty()) { + return calcularHorasPorTareaEspecifica(hw); + } else { + return calcularHorasPorActividadGeneral(hw); + } + }).setHeader("Total Horas").setSortable(true); + hoursWorkedGrid.addColumn(hw -> hw.getHoraspendientes() - calcularTotal(hw)).setHeader("Horas Pendientes") .setSortable(true); - hoursWorkedGrid.setPaginationBarMode(PagingGrid.PaginationBarMode.BOTTOM); hoursWorkedGrid.setPageSize(PAGE_SIZE); hoursWorkedGrid.asSingleSelect().addValueChangeListener(event -> { @@ -152,6 +161,36 @@ public class HoursWorkedListView extends BaseView { }); } + private double calcularHorasPorTareaEspecifica(HoursWorked hoursWorked) { + List tareas = hoursWorkedService.findListHoursWorkedEmployee( + hoursWorked.getEmployee().getId(), hoursWorked.getWeekNumber()); + return tareas.stream() + .filter(hw -> Objects.equals(hw.getTareaEspecifica(), hoursWorked.getTareaEspecifica())) + .mapToDouble(HoursWorked::getHours) + .sum(); + } + + private double calcularHorasPorActividadGeneral(HoursWorked hoursWorked) { + List actividades = hoursWorkedService.findListHoursWorkedEmployee( + hoursWorked.getEmployee().getId(), hoursWorked.getWeekNumber()); + return actividades.stream() + .filter(hw -> Objects.equals(hw.getActividad(), hoursWorked.getActividad()) + && (hw.getTareaEspecifica() == null || hw.getTareaEspecifica().isEmpty())) + .mapToDouble(HoursWorked::getHours) + .sum(); + } + + + private double calcularTotalHorasTareaEspecifica(HoursWorked hoursWorked) { + List horasTareas = hoursWorkedService.findListHoursWorkedEmployee( + hoursWorked.getEmployee().getId(), hoursWorked.getWeekNumber()); + return horasTareas.stream() + .filter(hw -> Objects.equals(hw.getTareaEspecifica(), hoursWorked.getTareaEspecifica())) + .mapToDouble(HoursWorked::getHours) + .sum(); + } + + private double calcularTotal(final HoursWorked hoursWorked) { List listHoursworkedemploye = hoursWorkedService.findListHoursWorkedEmployee( hoursWorked.getEmployee().getId(), hoursWorked.getWeekNumber()); @@ -165,25 +204,6 @@ public class HoursWorkedListView extends BaseView { .sum(); } - private HorizontalLayout createActionButtons() { - Button viewButton = new Button("Ver", event -> { - if (selectedEmployeeId != null) { - navigateToHoursWorkedView(selectedEmployeeId); - } else { - Notification.show("Seleccione una solicitud.", 3000, Notification.Position.MIDDLE); - } - }); - Button closeButton = new Button("Salir", event -> navigateToListView()); - return new HorizontalLayout(viewButton, closeButton); - } - - private void navigateToListView() { - getUI().ifPresent(ui -> ui.navigate(MainView.class)); - } - - private void navigateToHoursWorkedView(final UUID idEmployee) { - getUI().ifPresent(ui -> ui.navigate("hours-worked-list/" + idEmployee.toString())); - } private Button createButton(final String label, final Runnable onClickAction) { final Button button = new Button(label); diff --git a/src/main/java/com/primefactorsolutions/views/HoursWorkedView.java b/src/main/java/com/primefactorsolutions/views/HoursWorkedView.java index f870414..249477d 100644 --- a/src/main/java/com/primefactorsolutions/views/HoursWorkedView.java +++ b/src/main/java/com/primefactorsolutions/views/HoursWorkedView.java @@ -108,7 +108,8 @@ public class HoursWorkedView extends BeanValidationForm implements private void configureTareasEspecificas() { tareasEspecificasDropdown.setItems("Entrevistas", "Reuniones", - "Colaboraciones", "Aprendizajes", "Proyectos PFS", "Otros"); + "Colaboraciones", "Aprendizajes", "Proyectos PFS", + "Consulta Medica", "Afiliación al Seguro", "Fallas Tecnicas", "Otros"); tareasEspecificasDropdown.setPlaceholder("Selecciona una tarea..."); tareasEspecificasDropdown.addValueChangeListener(event -> { @@ -192,13 +193,39 @@ public class HoursWorkedView extends BeanValidationForm implements private void saveHoursWorked() { if (isFormValid()) { HoursWorked hoursWorked = getEntity(); + String actividad = activityField.getValue(); + String tareaEspecifica = tareasEspecificasDropdown.getValue(); + if (actividad != null && !actividad.isEmpty() && tareaEspecifica != null) { + Notification.show("Solo puedes elegir una: actividad del proyecto o tarea de la empresa.", 3000, Notification.Position.BOTTOM_CENTER); + return; + } + if (actividad != null && !actividad.isEmpty()) { + hoursWorked.setActividad(actividad); + } else if (tareaEspecifica != null) { + if ("Otros".equals(tareaEspecifica)) { + // Validar que se ingresó una tarea específica en el campo de texto + String tareaEspecificaInputValue = tareaEspecificaInput.getValue(); + if (tareaEspecificaInputValue == null || tareaEspecificaInputValue.isEmpty()) { + Notification.show("Por favor, ingresa una tarea específica.", 3000, Notification.Position.BOTTOM_CENTER); + return; + } + hoursWorked.setTareaEspecifica(tareaEspecificaInputValue); + } else { + hoursWorked.setTareaEspecifica(tareaEspecifica); + } + } else { + Notification.show("Por favor, selecciona una actividad o tarea para guardar.", 3000, Notification.Position.BOTTOM_CENTER); + return; + } setFieldValues(hoursWorked); hoursWorkedService.save(hoursWorked); - Notification.show("Horas trabajadas guardadas correctamente."); + Notification.show("Horas trabajadas guardadas correctamente.", 3000, Notification.Position.BOTTOM_CENTER); closeForm(); } } + + private void setFieldValues(final HoursWorked hoursWorked) { hoursWorked.setDate(dateField.getValue()); hoursWorked.setTeam(teamField.getValue()); @@ -211,10 +238,10 @@ public class HoursWorkedView extends BeanValidationForm implements Notification.show("Por favor, ingrese un número válido para las horas."); } if ("Otros".equals(tareasEspecificasDropdown.getValue())) { - hoursWorked.setTareasEspecificas(tareaEspecificaInput.getValue()); + hoursWorked.setActividad(tareaEspecificaInput.getValue()); try { double horasEspecifica = Double.parseDouble(horasTareaEspecificaField.getValue()); - hoursWorked.setHorasTareasEspecificas(horasEspecifica); + hoursWorked.setHours(horasEspecifica); double totalHoras = hoursWorked.getHours() + horasEspecifica; hoursWorked.setTotalHours(totalHoras); } catch (NumberFormatException e) { @@ -224,20 +251,27 @@ public class HoursWorkedView extends BeanValidationForm implements } private void closeForm() { - getUI().ifPresent(ui -> ui.navigate("hours-worked-list/" + hoursWorked.getId().toString())); + if (hoursWorked != null) { + getUI().ifPresent(ui -> ui.navigate("hours-worked-list/" + hoursWorked.getId().toString())); + } else { + getUI().ifPresent(ui -> ui.navigate("hours-worked-list")); + } } private boolean isFormValid() { + boolean isTareaEspecificaValida = "Otros".equals(tareasEspecificasDropdown.getValue()) + ? !tareaEspecificaInput.isEmpty() + : tareasEspecificasDropdown.getValue() != null; + boolean isActividadValida = !activityField.isEmpty(); + boolean isSoloUnaOpcionElegida = (isActividadValida && tareasEspecificasDropdown.isEmpty()) + || (!isActividadValida && isTareaEspecificaValida); return dateField.getValue() != null - && - teamField.getValue() != null - && - employeeField.getValue() != null - && - !activityField.isEmpty(); - + && teamField.getValue() != null + && employeeField.getValue() != null + && isSoloUnaOpcionElegida; } + private void configureViewOrEditAction(final String action) { if ("edit".equals(action) && hoursWorked != null) { setFieldsReadOnly(false); @@ -253,4 +287,4 @@ public class HoursWorkedView extends BeanValidationForm implements employeeField.setReadOnly(readOnly); activityField.setReadOnly(readOnly); } -} +} \ No newline at end of file