#46 Perfil de Empleado - Registro Semanal de Horas trabajadas con el numero de semanas

This commit is contained in:
Melina Gutierrez 2024-10-15 10:11:14 -04:00
parent 3e57c50378
commit b5396ae373

View File

@ -18,15 +18,16 @@ import com.vaadin.flow.spring.annotation.SpringComponent;
import jakarta.annotation.security.PermitAll; import jakarta.annotation.security.PermitAll;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope; import org.springframework.context.annotation.Scope;
import com.vaadin.flow.component.html.Label;
import java.time.DayOfWeek; import java.time.DayOfWeek;
import java.time.LocalDate; import java.time.LocalDate;
import java.time.temporal.TemporalAdjusters;
import java.time.temporal.WeekFields; import java.time.temporal.WeekFields;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Locale; import java.util.Locale;
import java.util.Optional; import java.util.stream.IntStream;
@SpringComponent @SpringComponent
@PermitAll @PermitAll
@ -42,21 +43,28 @@ public class HoursWorkedView extends VerticalLayout {
@Autowired @Autowired
private EmployeeService employeeService; private EmployeeService employeeService;
private final Label fechasLabel = new Label("Selecciona una semana para ver las fechas.");
public HoursWorkedView() { public HoursWorkedView() {
actividades = new ArrayList<>(); actividades = new ArrayList<>();
grid = new Grid<>(Actividad.class, false); grid = new Grid<>(Actividad.class, false);
totalsGrid = new Grid<>(Actividad.class, false); totalsGrid = new Grid<>(Actividad.class, false);
DatePicker datePicker = new DatePicker("Selecciona una fecha"); ComboBox<String> semanaComboBox = new ComboBox<>("Selecciona una semana");
datePicker.setValue(LocalDate.now()); semanaComboBox.setItems(getWeeksOfYear());
datePicker.addValueChangeListener(event -> { semanaComboBox.addValueChangeListener(event -> {
LocalDate selectedDate = event.getValue(); String selectedWeek = event.getValue();
if (selectedDate != null) { if (selectedWeek != null) {
selectedStartOfWeek = selectedDate.with(TemporalAdjusters.previousOrSame(DayOfWeek.MONDAY)); int weekNumber = Integer.parseInt(selectedWeek.split(" ")[1]);
selectedStartOfWeek = getStartOfWeek(weekNumber);
LocalDate endOfWeek = selectedStartOfWeek.plusDays(6);
fechasLabel.setText(("Semana del " + selectedStartOfWeek + " al " + endOfWeek));
mostrarActividadesDeLaSemana(); mostrarActividadesDeLaSemana();
} }
}); });
datePicker.setWidth("250px"); semanaComboBox.setWidth("250px");
ComboBox<String> equipoDropdown = new ComboBox<>("Equipo"); ComboBox<String> equipoDropdown = new ComboBox<>("Equipo");
equipoDropdown.setItems("Equipo 1", "Equipo 2", "Equipo 3"); equipoDropdown.setItems("Equipo 1", "Equipo 2", "Equipo 3");
@ -130,15 +138,29 @@ public class HoursWorkedView extends VerticalLayout {
HorizontalLayout buttonsLayout = new HorizontalLayout(actualizarButton, guardarButton, cerrarButton); HorizontalLayout buttonsLayout = new HorizontalLayout(actualizarButton, guardarButton, cerrarButton);
add(datePicker, filtersLayout, grid, actividadFormLayout, buttonsLayout); add(semanaComboBox, fechasLabel, filtersLayout, grid, actividadFormLayout, buttonsLayout);
add(totalsGrid); add(totalsGrid);
configurarTablaTotales(); configurarTablaTotales();
} }
private List<String> getWeeksOfYear() {
return IntStream.rangeClosed(1, 52)
.mapToObj(week -> "Semana " + week)
.toList();
}
private LocalDate getStartOfWeek(int weekNumber) {
WeekFields weekFields = WeekFields.of(Locale.getDefault());
return LocalDate.now()
.with(weekFields.weekOfYear(), weekNumber)
.with(weekFields.dayOfWeek(), DayOfWeek.MONDAY.getValue());
}
private void mostrarActividadesDeLaSemana() { private void mostrarActividadesDeLaSemana() {
if (selectedStartOfWeek != null) { if (selectedStartOfWeek != null) {
Notification.show("Mostrando actividades de la semana del " + selectedStartOfWeek + " al " + selectedStartOfWeek.plusDays(6)); Notification.show("Mostrando actividades de la semana del " +
selectedStartOfWeek + " al " + selectedStartOfWeek.plusDays(6));
} }
} }