From 823dc16205ad3bc17fdeed2a3872714ae8465921 Mon Sep 17 00:00:00 2001 From: Melina Gutierrez Date: Tue, 12 Nov 2024 07:00:06 -0400 Subject: [PATCH] #45-Registro Semanal de Horas Trabajadas corregir duplicados --- .../primefactorsolutions/model/Actividad.java | 20 +++++----- .../model/HoursWorked.java | 8 ++-- .../views/HoursWorkedView.java | 38 +++++++++++-------- 3 files changed, 36 insertions(+), 30 deletions(-) diff --git a/src/main/java/com/primefactorsolutions/model/Actividad.java b/src/main/java/com/primefactorsolutions/model/Actividad.java index 55402f4..7c7df34 100644 --- a/src/main/java/com/primefactorsolutions/model/Actividad.java +++ b/src/main/java/com/primefactorsolutions/model/Actividad.java @@ -25,7 +25,7 @@ public class Actividad extends BaseEntity { private String tarea; private double horas; - public Actividad() { } + public Actividad() {} public Actividad(final Builder builder) { this.nombre = builder.nombre; @@ -49,46 +49,46 @@ public class Actividad extends BaseEntity { return nombre; } - public void setLunes(final double lunes) { + public void setLunes(double lunes) { this.lunes = lunes; return; } - public void setMartes(final double martes) { + public void setMartes(double martes) { this.martes = martes; return; } - public void setMiercoles(final double miercoles) { + public void setMiercoles(double miercoles) { this.miercoles = miercoles; return; } - public void setJueves(final double jueves) { + public void setJueves(double jueves) { this.jueves = jueves; return; } - public void setViernes(final double viernes) { + public void setViernes(double viernes) { this.viernes = viernes; return; } - public void setSabado(final double sabado) { + public void setSabado(double sabado) { this.sabado = sabado; return; } - public void setDomingo(final double domingo) { + public void setDomingo(double domingo) { this.domingo = domingo; return; } - public void setTarea(final String tarea) { + public void setTarea(String tarea) { this.tarea = tarea; return; } - public void setHoras(final double horas) { + public void setHoras(double horas) { this.horas = horas; return; } diff --git a/src/main/java/com/primefactorsolutions/model/HoursWorked.java b/src/main/java/com/primefactorsolutions/model/HoursWorked.java index 2b918d3..e23e9b0 100644 --- a/src/main/java/com/primefactorsolutions/model/HoursWorked.java +++ b/src/main/java/com/primefactorsolutions/model/HoursWorked.java @@ -27,13 +27,13 @@ public class HoursWorked extends BaseEntity { private LocalDate fecha; - public HoursWorked() { } + public HoursWorked() {} public Actividad getActividad() { return this.actividad; } - public void setActividad(final Actividad actividad) { + public void setActividad(Actividad actividad){ this.actividad = actividad; } @@ -61,9 +61,7 @@ public class HoursWorked extends BaseEntity { this.weekNumber = weekNumber; } - public LocalDate getFecha() { - return this.fecha; - } + public LocalDate getFecha() { return this.fecha;} public double getTotalHours() { return totalHours; diff --git a/src/main/java/com/primefactorsolutions/views/HoursWorkedView.java b/src/main/java/com/primefactorsolutions/views/HoursWorkedView.java index 62ef1cb..a17d6de 100644 --- a/src/main/java/com/primefactorsolutions/views/HoursWorkedView.java +++ b/src/main/java/com/primefactorsolutions/views/HoursWorkedView.java @@ -5,7 +5,6 @@ import com.primefactorsolutions.model.HoursWorked; import com.primefactorsolutions.service.EmployeeService; import com.primefactorsolutions.service.HoursWorkedService; import com.vaadin.flow.component.grid.Grid; -import com.vaadin.flow.component.html.H2; import com.vaadin.flow.component.notification.Notification; import com.vaadin.flow.component.orderedlayout.HorizontalLayout; import com.vaadin.flow.component.textfield.TextField; @@ -16,9 +15,13 @@ import com.vaadin.flow.router.PageTitle; import com.vaadin.flow.router.Route; import com.vaadin.flow.spring.annotation.SpringComponent; import jakarta.annotation.security.PermitAll; +import jakarta.persistence.ManyToOne; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.context.annotation.Scope; import com.vaadin.flow.component.html.Label; +import org.springframework.web.servlet.HandlerMapping; +import org.springframework.web.servlet.view.InternalResourceViewResolver; import org.vaadin.firitin.components.datepicker.VDatePicker; @@ -33,18 +36,19 @@ import java.util.Locale; @SpringComponent @PermitAll @Scope("prototype") -@PageTitle("Horas Trabajadas") +@PageTitle("Hours Worked") @Route(value = "/hours-worked/me", layout = MainLayout.class) public class HoursWorkedView extends VerticalLayout { + @ManyToOne + private Actividad actividad; + private final List actividades = new ArrayList<>(); private final List actividadesEspecificas = new ArrayList<>(); // Nueva lista para tareas específicas private final Grid grid = new Grid<>(Actividad.class); private final Grid gridActividadesEspecificas = new Grid<>(Actividad.class); - private final ComboBox employeeComboBox = new ComboBox<>("Empleado"); + private final ComboBox employeeComboBox = new ComboBox<>("Employee"); private final ComboBox equipoDropdown = new ComboBox<>("Equipo"); - private VDatePicker fechaPicker = new VDatePicker("Selecciona una fecha"); - private final ComboBox tareasEspecificasDropdown = new ComboBox<>("Tareas Específicas"); private final TextField tareaEspecificaInput = new TextField("Especificar Tarea"); @@ -58,11 +62,15 @@ public class HoursWorkedView extends VerticalLayout { @Autowired private final HoursWorkedService hoursWorkedService; - private final H2 equipoLabel = new H2("Tareas del Cliente/Equipo"); - private final H2 empresaLabel = new H2("Tareas de la Empresa"); + private final Label fechasLabel = new Label("Selecciona una semana para ver las fechas."); private final Label totalCompletadoLabel = new Label(); private final Label horasPendientesLabel = new Label(); + private final Label numeroSemanaLabel = new Label("Número de la Semana: "); + + private VDatePicker fechaPicker = new VDatePicker("Selecciona una fecha"); + + public HoursWorkedView(final EmployeeService employeeService, final HoursWorkedService hoursWorkedService) { this.employeeService = employeeService; this.hoursWorkedService = hoursWorkedService; @@ -141,7 +149,10 @@ public class HoursWorkedView extends VerticalLayout { LocalDate selectedDate = event.getValue(); if (selectedDate != null) { selectedStartOfWeek = getStartOfWeek(selectedDate); + LocalDate endOfWeek = selectedStartOfWeek.plusDays(6); weekNumber = getWeekOfYear(selectedDate); + fechasLabel.setText("Semana del " + selectedStartOfWeek + " al " + endOfWeek); + numeroSemanaLabel.setText("Número de la Semana: " + weekNumber); cargarDatos(); } }); @@ -178,14 +189,12 @@ public class HoursWorkedView extends VerticalLayout { HorizontalLayout buttonsLayout = new HorizontalLayout(actualizarButton, guardarButton, cerrarButton, verMesButton); - VerticalLayout totalesLayout = new VerticalLayout(totalCompletadoLabel, - horasPendientesLabel); + VerticalLayout totalesLayout = new VerticalLayout(totalCompletadoLabel, horasPendientesLabel); totalesLayout.setSpacing(true); totalesLayout.setPadding(true); - add(fechaPicker, filtersLayout, actividadFormLayout, - equipoLabel, grid, empresaLabel, tareasEspecificasLayout, - gridActividadesEspecificas, buttonsLayout, totalesLayout); + add(fechaPicker, fechasLabel, numeroSemanaLabel, filtersLayout, actividadFormLayout, + tareasEspecificasLayout, grid, gridActividadesEspecificas, buttonsLayout, totalesLayout); } private void configurarGrid() { @@ -200,7 +209,6 @@ public class HoursWorkedView extends VerticalLayout { grid.addColumn(Actividad::getSabado).setHeader("Sábado"); grid.addColumn(Actividad::getDomingo).setHeader("Domingo"); grid.addColumn(this::calcularTotalPorDia).setHeader("Total Día").setKey("totalDia"); - grid.setItems(actividades); } private void configurarGridActividadesEspecificas() { @@ -286,7 +294,7 @@ public class HoursWorkedView extends VerticalLayout { return new HorizontalLayout(actividadNombre, horasInput, agregarActividadButton); } - private void agregarOActualizarActividad(final Actividad nuevaActividad, final DayOfWeek dia, final double horas) { + private void agregarOActualizarActividad(Actividad nuevaActividad, DayOfWeek dia, double horas) { Actividad actividadExistente = actividades.stream() .filter(a -> a.getNombre().equals(nuevaActividad.getNombre())) .findFirst() @@ -406,7 +414,7 @@ public class HoursWorkedView extends VerticalLayout { private LocalDate getStartOfWeek(final LocalDate date) { WeekFields weekFields = WeekFields.of(Locale.getDefault()); - return date.with(weekFields.dayOfWeek(), DayOfWeek.FRIDAY.getValue()); + return date.with(weekFields.dayOfWeek(), DayOfWeek.MONDAY.getValue()); } private double calcularTotalPorDia(final Actividad actividad) {