primer commit
This commit is contained in:
parent
1e22223f27
commit
4561a43866
@ -9,6 +9,8 @@ public final class Actividad {
|
|||||||
private double viernes;
|
private double viernes;
|
||||||
private double sabado;
|
private double sabado;
|
||||||
private double domingo;
|
private double domingo;
|
||||||
|
private String descripcion; // Cambié 'tarea' por 'descripcion' para un enfoque más general
|
||||||
|
private double horas;
|
||||||
|
|
||||||
public Actividad(final Builder builder) {
|
public Actividad(final Builder builder) {
|
||||||
this.nombre = builder.nombre;
|
this.nombre = builder.nombre;
|
||||||
@ -19,6 +21,8 @@ public final class Actividad {
|
|||||||
this.viernes = builder.viernes;
|
this.viernes = builder.viernes;
|
||||||
this.sabado = builder.sabado;
|
this.sabado = builder.sabado;
|
||||||
this.domingo = builder.domingo;
|
this.domingo = builder.domingo;
|
||||||
|
this.descripcion = builder.descripcion; // Cambié aquí también
|
||||||
|
this.horas = builder.horas;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getNombre() {
|
public String getNombre() {
|
||||||
@ -53,6 +57,14 @@ public final class Actividad {
|
|||||||
return domingo;
|
return domingo;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getDescripcion() { // Cambié aquí también
|
||||||
|
return descripcion;
|
||||||
|
}
|
||||||
|
|
||||||
|
public double getHoras() {
|
||||||
|
return horas;
|
||||||
|
}
|
||||||
|
|
||||||
// Builder para crear instancias de Actividad
|
// Builder para crear instancias de Actividad
|
||||||
public static class Builder {
|
public static class Builder {
|
||||||
private String nombre;
|
private String nombre;
|
||||||
@ -63,6 +75,14 @@ public final class Actividad {
|
|||||||
private double viernes;
|
private double viernes;
|
||||||
private double sabado;
|
private double sabado;
|
||||||
private double domingo;
|
private double domingo;
|
||||||
|
private String descripcion; // Cambié 'tarea' por 'descripcion'
|
||||||
|
private double horas;
|
||||||
|
|
||||||
|
public Builder descripcion(final String descripcion, final double horas) { // Cambié 'tarea' por 'descripcion'
|
||||||
|
this.descripcion = descripcion;
|
||||||
|
this.horas = horas;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
public Builder nombre(final String nombre) {
|
public Builder nombre(final String nombre) {
|
||||||
this.nombre = nombre;
|
this.nombre = nombre;
|
||||||
@ -108,4 +128,4 @@ public final class Actividad {
|
|||||||
return new Actividad(this);
|
return new Actividad(this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -39,30 +39,44 @@ public class HoursWorkedView extends VerticalLayout {
|
|||||||
private final Grid<Actividad> grid = new Grid<>(Actividad.class);
|
private final Grid<Actividad> grid = new Grid<>(Actividad.class);
|
||||||
|
|
||||||
private final ComboBox<Employee> employeeComboBox = new ComboBox<>("Employee");
|
private final ComboBox<Employee> employeeComboBox = new ComboBox<>("Employee");
|
||||||
|
private final ComboBox<String> equipoDropdown = new ComboBox<>("Equipo");
|
||||||
|
|
||||||
|
private final ComboBox<String> tareasEspecificasDropdown = new ComboBox<>("Tareas Específicas");
|
||||||
|
private TextField horasTareaInput = crearCampoHora("Horas Tareas");
|
||||||
|
|
||||||
private LocalDate selectedStartOfWeek;
|
private LocalDate selectedStartOfWeek;
|
||||||
private int weekNumber;
|
private int weekNumber;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private final EmployeeService employeeService;
|
private final EmployeeService employeeService;
|
||||||
|
@Autowired
|
||||||
|
private final HoursWorkedService hoursWorkedService;
|
||||||
|
|
||||||
private final Label fechasLabel = new Label("Selecciona una semana para ver las fechas.");
|
private final Label fechasLabel = new Label("Selecciona una semana para ver las fechas.");
|
||||||
private final Label totalCompletadoLabel = new Label();
|
private final Label totalCompletadoLabel = new Label();
|
||||||
private final Label horasPendientesLabel = new Label();
|
private final Label horasPendientesLabel = new Label();
|
||||||
|
|
||||||
@Autowired
|
private DatePicker fechaPicker = new DatePicker("Selecciona una fecha");
|
||||||
private final HoursWorkedService hoursWorkedService;
|
|
||||||
|
|
||||||
public HoursWorkedView(final EmployeeService employeeService, final HoursWorkedService hoursWorkedService) {
|
public HoursWorkedView(final EmployeeService employeeService, final HoursWorkedService hoursWorkedService) {
|
||||||
this.employeeService = employeeService;
|
this.employeeService = employeeService;
|
||||||
this.hoursWorkedService = hoursWorkedService;
|
this.hoursWorkedService = hoursWorkedService;
|
||||||
configurarVista();
|
configurarVista();
|
||||||
|
configurarGrid();
|
||||||
cargarDatos();
|
cargarDatos();
|
||||||
|
configurarTareasEspecificas();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void configurarTareasEspecificas() {
|
||||||
|
tareasEspecificasDropdown.setItems("TareaPFS1", "TareaPFS2", "TareaPFS3", "TareaPFS4", "TareaPFS5");
|
||||||
|
tareasEspecificasDropdown.setPlaceholder("Selecciona una tarea...");
|
||||||
}
|
}
|
||||||
|
|
||||||
private void cargarDatos() {
|
private void cargarDatos() {
|
||||||
List<HoursWorked> listaDeHorasTrabajadas = obtenerDatos(); // Obtenemos la lista aquí
|
List<HoursWorked> listaDeHorasTrabajadas = obtenerDatos();
|
||||||
grid.setItems(actividades);
|
grid.setItems(actividades);
|
||||||
|
calcularTotalHoras(listaDeHorasTrabajadas);
|
||||||
double totalHoras = calcularTotalHoras(listaDeHorasTrabajadas); // Pasa la lista aquí
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setEmployeeComboBoxProperties() {
|
private void setEmployeeComboBoxProperties() {
|
||||||
@ -70,7 +84,6 @@ public class HoursWorkedView extends VerticalLayout {
|
|||||||
employeeComboBox.setPlaceholder("Buscar empleado...");
|
employeeComboBox.setPlaceholder("Buscar empleado...");
|
||||||
employeeComboBox.setItems(employeeService.findAllEmployees());
|
employeeComboBox.setItems(employeeService.findAllEmployees());
|
||||||
employeeComboBox.setItemLabelGenerator(employee -> employee.getFirstName() + " " + employee.getLastName());
|
employeeComboBox.setItemLabelGenerator(employee -> employee.getFirstName() + " " + employee.getLastName());
|
||||||
|
|
||||||
employeeComboBox.setAllowCustomValue(false);
|
employeeComboBox.setAllowCustomValue(false);
|
||||||
employeeComboBox.addCustomValueSetListener(event ->
|
employeeComboBox.addCustomValueSetListener(event ->
|
||||||
Notification.show("Selecciona un empleado válido de la lista.")
|
Notification.show("Selecciona un empleado válido de la lista.")
|
||||||
@ -91,10 +104,10 @@ public class HoursWorkedView extends VerticalLayout {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void configurarVista() {
|
private void configurarVista() {
|
||||||
DatePicker fechaPicker = new DatePicker("Selecciona una fecha");
|
|
||||||
fechaPicker.addValueChangeListener(event -> {
|
fechaPicker.addValueChangeListener(event -> {
|
||||||
LocalDate selectedDate = event.getValue();
|
LocalDate selectedDate = event.getValue();
|
||||||
if (selectedDate != null) {
|
if (selectedDate != null) {
|
||||||
|
DayOfWeek dayOfWeek = selectedDate.getDayOfWeek();
|
||||||
selectedStartOfWeek = getStartOfWeek(selectedDate);
|
selectedStartOfWeek = getStartOfWeek(selectedDate);
|
||||||
LocalDate endOfWeek = selectedStartOfWeek.plusDays(6);
|
LocalDate endOfWeek = selectedStartOfWeek.plusDays(6);
|
||||||
fechasLabel.setText("Semana del " + selectedStartOfWeek + " al " + endOfWeek);
|
fechasLabel.setText("Semana del " + selectedStartOfWeek + " al " + endOfWeek);
|
||||||
@ -106,17 +119,16 @@ public class HoursWorkedView extends VerticalLayout {
|
|||||||
getUI().ifPresent(ui -> ui.navigate(HoursWorkedMonthView.class));
|
getUI().ifPresent(ui -> ui.navigate(HoursWorkedMonthView.class));
|
||||||
});
|
});
|
||||||
|
|
||||||
ComboBox<String> equipoDropdown = new ComboBox<>("Equipo");
|
|
||||||
equipoDropdown.setItems("Equipo 1", "Equipo 2", "Equipo 3");
|
equipoDropdown.setItems("Equipo 1", "Equipo 2", "Equipo 3");
|
||||||
equipoDropdown.setWidth("250px");
|
equipoDropdown.setWidth("250px");
|
||||||
|
|
||||||
setEmployeeComboBoxProperties();
|
setEmployeeComboBoxProperties();
|
||||||
|
|
||||||
HorizontalLayout filtersLayout = new HorizontalLayout(equipoDropdown, employeeComboBox);
|
HorizontalLayout filtersLayout = new HorizontalLayout(equipoDropdown, employeeComboBox);
|
||||||
filtersLayout.setSpacing(true);
|
filtersLayout.setSpacing(true);
|
||||||
|
|
||||||
configurarGrid();
|
|
||||||
HorizontalLayout actividadFormLayout = configurarFormularioActividades();
|
HorizontalLayout actividadFormLayout = configurarFormularioActividades();
|
||||||
|
HorizontalLayout tareasEspecificasLayout = configurarTareasEspecificasLayout();
|
||||||
|
|
||||||
|
|
||||||
Button actualizarButton = new Button("Actualizar Totales", event -> actualizarTotales());
|
Button actualizarButton = new Button("Actualizar Totales", event -> actualizarTotales());
|
||||||
Button guardarButton = new Button("Guardar", event -> guardarActividades());
|
Button guardarButton = new Button("Guardar", event -> guardarActividades());
|
||||||
@ -129,8 +141,7 @@ public class HoursWorkedView extends VerticalLayout {
|
|||||||
totalesLayout.setSpacing(true);
|
totalesLayout.setSpacing(true);
|
||||||
totalesLayout.setPadding(true);
|
totalesLayout.setPadding(true);
|
||||||
|
|
||||||
add(fechaPicker, fechasLabel, filtersLayout, grid, actividadFormLayout, buttonsLayout, totalesLayout);
|
add(fechaPicker, fechasLabel, filtersLayout, actividadFormLayout, tareasEspecificasLayout, grid, buttonsLayout, totalesLayout);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void configurarGrid() {
|
private void configurarGrid() {
|
||||||
@ -151,48 +162,62 @@ public class HoursWorkedView extends VerticalLayout {
|
|||||||
TextField actividadNombre = new TextField("Actividad");
|
TextField actividadNombre = new TextField("Actividad");
|
||||||
actividadNombre.setWidth("200px");
|
actividadNombre.setWidth("200px");
|
||||||
|
|
||||||
TextField lunesHoras = crearCampoHora("Lunes");
|
TextField horasInput = crearCampoHora("Horas");
|
||||||
TextField martesHoras = crearCampoHora("Martes");
|
|
||||||
TextField miercolesHoras = crearCampoHora("Miércoles");
|
|
||||||
TextField juevesHoras = crearCampoHora("Jueves");
|
|
||||||
TextField viernesHoras = crearCampoHora("Viernes");
|
|
||||||
TextField sabadoHoras = crearCampoHora("Sábado");
|
|
||||||
TextField domingoHoras = crearCampoHora("Domingo");
|
|
||||||
|
|
||||||
Button agregarActividadButton = new Button("Agregar Actividad", e -> {
|
Button agregarActividadButton = new Button("Agregar Actividad", e -> {
|
||||||
try {
|
try {
|
||||||
Actividad nuevaActividad = new Actividad.Builder()
|
LocalDate selectedDate = fechaPicker.getValue();
|
||||||
.nombre(actividadNombre.getValue())
|
if (selectedDate == null) {
|
||||||
.lunes(parseHoras(lunesHoras.getValue()))
|
Notification.show("Por favor, selecciona una fecha.");
|
||||||
.martes(parseHoras(martesHoras.getValue()))
|
return;
|
||||||
.miercoles(parseHoras(miercolesHoras.getValue()))
|
}
|
||||||
.jueves(parseHoras(juevesHoras.getValue()))
|
DayOfWeek selectedDay = selectedDate.getDayOfWeek();
|
||||||
.viernes(parseHoras(viernesHoras.getValue()))
|
|
||||||
.sabado(parseHoras(sabadoHoras.getValue()))
|
|
||||||
.domingo(parseHoras(domingoHoras.getValue()))
|
|
||||||
.build();
|
|
||||||
|
|
||||||
|
Actividad.Builder actividadBuilder = new Actividad.Builder()
|
||||||
|
.nombre(actividadNombre.getValue());
|
||||||
|
|
||||||
|
double horas = parseHoras(horasInput.getValue());
|
||||||
|
switch (selectedDay) {
|
||||||
|
case MONDAY -> actividadBuilder.lunes(horas);
|
||||||
|
case TUESDAY -> actividadBuilder.martes(horas);
|
||||||
|
case WEDNESDAY -> actividadBuilder.miercoles(horas);
|
||||||
|
case THURSDAY -> actividadBuilder.jueves(horas);
|
||||||
|
case FRIDAY -> actividadBuilder.viernes(horas);
|
||||||
|
case SATURDAY -> actividadBuilder.sabado(horas);
|
||||||
|
case SUNDAY -> actividadBuilder.domingo(horas);
|
||||||
|
}
|
||||||
|
|
||||||
|
String tareaSeleccionada = tareasEspecificasDropdown.getValue();
|
||||||
|
double horasTarea = parseHoras(horasTareaInput.getValue());
|
||||||
|
|
||||||
|
if (tareaSeleccionada != null && !tareaSeleccionada.isEmpty()) {
|
||||||
|
actividadBuilder.descripcion(tareaSeleccionada, horasTarea);
|
||||||
|
}
|
||||||
|
|
||||||
|
Actividad nuevaActividad = actividadBuilder.build();
|
||||||
actividades.add(nuevaActividad);
|
actividades.add(nuevaActividad);
|
||||||
grid.setItems(actividades);
|
grid.setItems(actividades);
|
||||||
|
|
||||||
actualizarTotales();
|
actualizarTotales();
|
||||||
Notification.show("Actividad agregada correctamente");
|
Notification.show("Actividad agregada correctamente");
|
||||||
// Limpiar los campos de entrada
|
|
||||||
actividadNombre.clear();
|
actividadNombre.clear();
|
||||||
lunesHoras.clear();
|
horasInput.clear(); // Limpiar solo el campo de horas
|
||||||
martesHoras.clear();
|
tareasEspecificasDropdown.clear(); // Limpiar el dropdown de tareas
|
||||||
miercolesHoras.clear();
|
horasTareaInput.clear();
|
||||||
juevesHoras.clear();
|
|
||||||
viernesHoras.clear();
|
|
||||||
sabadoHoras.clear();
|
|
||||||
domingoHoras.clear();
|
|
||||||
} catch (NumberFormatException ex) {
|
} catch (NumberFormatException ex) {
|
||||||
Notification.show("Error: Por favor ingresa números válidos para las horas.");
|
Notification.show("Error: Por favor ingresa números válidos para las horas.");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
return new HorizontalLayout(
|
return new HorizontalLayout(actividadNombre, horasInput, tareasEspecificasDropdown, horasTareaInput, agregarActividadButton);
|
||||||
actividadNombre, lunesHoras, martesHoras, miercolesHoras,
|
}
|
||||||
juevesHoras, viernesHoras, sabadoHoras, domingoHoras, agregarActividadButton);
|
|
||||||
|
private HorizontalLayout configurarTareasEspecificasLayout() {
|
||||||
|
HorizontalLayout tareasLayout = new HorizontalLayout();
|
||||||
|
tareasLayout.add(tareasEspecificasDropdown, horasTareaInput);
|
||||||
|
tareasLayout.setSpacing(true);
|
||||||
|
tareasLayout.setWidthFull();
|
||||||
|
return tareasLayout;
|
||||||
}
|
}
|
||||||
|
|
||||||
private TextField crearCampoHora(final String placeholder) {
|
private TextField crearCampoHora(final String placeholder) {
|
||||||
@ -223,6 +248,7 @@ public class HoursWorkedView extends VerticalLayout {
|
|||||||
double totalSemanaCompletada = actividades.stream()
|
double totalSemanaCompletada = actividades.stream()
|
||||||
.mapToDouble(this::calcularTotalPorDia)
|
.mapToDouble(this::calcularTotalPorDia)
|
||||||
.sum();
|
.sum();
|
||||||
|
|
||||||
double horasPendientes = 40 - totalSemanaCompletada;
|
double horasPendientes = 40 - totalSemanaCompletada;
|
||||||
|
|
||||||
totalCompletadoLabel.setText("Total Hrs/Semana Completadas: " + totalSemanaCompletada);
|
totalCompletadoLabel.setText("Total Hrs/Semana Completadas: " + totalSemanaCompletada);
|
||||||
@ -231,9 +257,11 @@ public class HoursWorkedView extends VerticalLayout {
|
|||||||
|
|
||||||
private void guardarActividades() {
|
private void guardarActividades() {
|
||||||
Employee selectedEmployee = employeeComboBox.getValue();
|
Employee selectedEmployee = employeeComboBox.getValue();
|
||||||
|
String selectedEquipo = equipoDropdown.getValue();
|
||||||
|
|
||||||
if (selectedEmployee == null) {
|
|
||||||
Notification.show("Por favor, selecciona un empleado antes de guardar.");
|
if (selectedEmployee == null || selectedEquipo == null) {
|
||||||
|
Notification.show("Por favor selecciona un equipo y un empleado.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -148,7 +148,9 @@ public class MainLayout extends AppLayout {
|
|||||||
LineAwesomeIcon.SUN.create()));
|
LineAwesomeIcon.SUN.create()));
|
||||||
SideNavItem timesheet = new SideNavItem("My Timesheet", TimesheetView.class,
|
SideNavItem timesheet = new SideNavItem("My Timesheet", TimesheetView.class,
|
||||||
LineAwesomeIcon.HOURGLASS_START_SOLID.create());
|
LineAwesomeIcon.HOURGLASS_START_SOLID.create());
|
||||||
timesheet.addItem(new SideNavItem("Hours Worked", HoursWorkedView.class,
|
timesheet.addItem(new SideNavItem("Horas Trabajadas", HoursWorkedView.class,
|
||||||
|
LineAwesomeIcon.ID_CARD_SOLID.create()));
|
||||||
|
timesheet.addItem(new SideNavItem("Reporte Horas Trabajadas", ReporteView.class,
|
||||||
LineAwesomeIcon.ID_CARD_SOLID.create()));
|
LineAwesomeIcon.ID_CARD_SOLID.create()));
|
||||||
|
|
||||||
SideNavItem profile = new SideNavItem("My Profile", ProfileView.class,
|
SideNavItem profile = new SideNavItem("My Profile", ProfileView.class,
|
||||||
|
@ -4,8 +4,11 @@ import com.primefactorsolutions.model.HoursWorked;
|
|||||||
import com.primefactorsolutions.service.HoursWorkedService;
|
import com.primefactorsolutions.service.HoursWorkedService;
|
||||||
import com.primefactorsolutions.service.ReportService;
|
import com.primefactorsolutions.service.ReportService;
|
||||||
import com.vaadin.flow.component.button.Button;
|
import com.vaadin.flow.component.button.Button;
|
||||||
|
import com.vaadin.flow.component.combobox.ComboBox;
|
||||||
|
import com.vaadin.flow.component.datepicker.DatePicker;
|
||||||
import com.vaadin.flow.component.html.Anchor;
|
import com.vaadin.flow.component.html.Anchor;
|
||||||
import com.vaadin.flow.component.html.H2;
|
import com.vaadin.flow.component.html.H2;
|
||||||
|
import com.vaadin.flow.component.orderedlayout.HorizontalLayout;
|
||||||
import com.vaadin.flow.component.orderedlayout.VerticalLayout;
|
import com.vaadin.flow.component.orderedlayout.VerticalLayout;
|
||||||
import com.vaadin.flow.router.PageTitle;
|
import com.vaadin.flow.router.PageTitle;
|
||||||
import com.vaadin.flow.router.Route;
|
import com.vaadin.flow.router.Route;
|
||||||
@ -15,8 +18,11 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|||||||
import com.vaadin.flow.component.notification.Notification;
|
import com.vaadin.flow.component.notification.Notification;
|
||||||
|
|
||||||
import java.io.ByteArrayInputStream;
|
import java.io.ByteArrayInputStream;
|
||||||
|
import java.time.LocalDate;
|
||||||
|
import java.time.temporal.WeekFields;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Locale;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
@ -28,6 +34,10 @@ public class ReporteView extends VerticalLayout {
|
|||||||
private final HoursWorkedService hoursWorkedService;
|
private final HoursWorkedService hoursWorkedService;
|
||||||
private final ReportService reportService;
|
private final ReportService reportService;
|
||||||
|
|
||||||
|
private final ComboBox<String> equipoComboBox = new ComboBox<>("Seleccionar Equipo");
|
||||||
|
private final DatePicker semanaPicker = new DatePicker("Seleccionar Semana");
|
||||||
|
private Anchor downloadLink;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
public ReporteView(final HoursWorkedService hoursWorkedService, final ReportService reportService) {
|
public ReporteView(final HoursWorkedService hoursWorkedService, final ReportService reportService) {
|
||||||
this.hoursWorkedService = hoursWorkedService;
|
this.hoursWorkedService = hoursWorkedService;
|
||||||
@ -36,12 +46,27 @@ public class ReporteView extends VerticalLayout {
|
|||||||
H2 title = new H2("Reporte de Horas Trabajadas");
|
H2 title = new H2("Reporte de Horas Trabajadas");
|
||||||
add(title);
|
add(title);
|
||||||
|
|
||||||
|
equipoComboBox.setItems("Equipo 1", "Equipo 2", "Equipo 3"); // Opciones de equipo
|
||||||
|
semanaPicker.setPlaceholder("Seleccione una fecha dentro de la semana deseada");
|
||||||
|
|
||||||
Button reportButton = new Button("Generar Reporte de Horas Trabajadas", event -> generateHoursWorkedReport());
|
Button reportButton = new Button("Generar Reporte de Horas Trabajadas", event -> generateHoursWorkedReport());
|
||||||
add(reportButton);
|
HorizontalLayout filtersLayout = new HorizontalLayout(equipoComboBox, semanaPicker, reportButton);
|
||||||
|
add(filtersLayout);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void generateHoursWorkedReport() {
|
private void generateHoursWorkedReport() {
|
||||||
List<HoursWorked> hoursWorkedList = hoursWorkedService.findAll(); // Obtener la lista de HoursWorked
|
String selectedEquipo = equipoComboBox.getValue();
|
||||||
|
LocalDate selectedDate = semanaPicker.getValue();
|
||||||
|
if (selectedEquipo == null || selectedDate == null) {
|
||||||
|
Notification.show("Por favor, selecciona un equipo y una semana para generar el reporte.", 3000, Notification.Position.MIDDLE);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
int weekNumber = getWeekOfYear(selectedDate);
|
||||||
|
|
||||||
|
List<HoursWorked> hoursWorkedList = hoursWorkedService.findAll().stream()
|
||||||
|
.filter(hw -> hw.getEmployee().getTeam().equals(selectedEquipo) && hw.getWeekNumber() == weekNumber)
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
|
||||||
if (hoursWorkedList.isEmpty()) {
|
if (hoursWorkedList.isEmpty()) {
|
||||||
Notification.show("No hay horas trabajadas disponibles para generar el reporte.",
|
Notification.show("No hay horas trabajadas disponibles para generar el reporte.",
|
||||||
@ -50,13 +75,14 @@ public class ReporteView extends VerticalLayout {
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
List<String> headers = List.of("ID", "Employee ID", "Week Number", "Total Hours");
|
List<String> headers = List.of("ID", "Employee ID", "Empleado", "Week Number", "Total Hours");
|
||||||
|
|
||||||
List<Map<String, Object>> data = hoursWorkedList.stream()
|
List<Map<String, Object>> data = hoursWorkedList.stream()
|
||||||
.map(hoursWorked -> {
|
.map(hoursWorked -> {
|
||||||
Map<String, Object> map = new HashMap<>();
|
Map<String, Object> map = new HashMap<>();
|
||||||
map.put("ID", hoursWorked.getId().toString());
|
map.put("ID", hoursWorked.getId().toString());
|
||||||
map.put("Employee ID", hoursWorked.getEmployee().getId().toString());
|
map.put("Employee ID", hoursWorked.getEmployee().getId().toString());
|
||||||
|
map.put("Empleado", hoursWorked.getEmployee().getFirstName() + " " + hoursWorked.getEmployee().getLastName());
|
||||||
map.put("Week Number", hoursWorked.getWeekNumber());
|
map.put("Week Number", hoursWorked.getWeekNumber());
|
||||||
map.put("Total Hours", hoursWorked.getTotalHours());
|
map.put("Total Hours", hoursWorked.getTotalHours());
|
||||||
return map;
|
return map;
|
||||||
@ -70,10 +96,14 @@ public class ReporteView extends VerticalLayout {
|
|||||||
excelResource.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
|
excelResource.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
|
||||||
excelResource.setCacheTime(0);
|
excelResource.setCacheTime(0);
|
||||||
|
|
||||||
Anchor downloadLink = new Anchor(excelResource, "Descargar Reporte de Horas Trabajadas");
|
if (downloadLink != null) {
|
||||||
downloadLink.getElement().setAttribute("download", true);
|
remove(downloadLink);
|
||||||
|
}
|
||||||
|
|
||||||
|
downloadLink = new Anchor(excelResource, "Descargar Reporte de Horas Trabajadas");
|
||||||
|
downloadLink.getElement().setAttribute("download", true);
|
||||||
add(downloadLink);
|
add(downloadLink);
|
||||||
|
|
||||||
Notification.show("Reporte de horas trabajadas generado exitosamente.",
|
Notification.show("Reporte de horas trabajadas generado exitosamente.",
|
||||||
3000, Notification.Position.MIDDLE);
|
3000, Notification.Position.MIDDLE);
|
||||||
|
|
||||||
@ -84,4 +114,7 @@ public class ReporteView extends VerticalLayout {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private int getWeekOfYear(final LocalDate date) {
|
||||||
|
return date.get(WeekFields.of(Locale.getDefault()).weekOfWeekBasedYear());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user