Compare commits
No commits in common. "3c626e3c85c48dd7cc5e9d392eec56c96e212655" and "dee4bcaf3bbadf09e6e38878b9f4ecaada5af8b7" have entirely different histories.
3c626e3c85
...
dee4bcaf3b
@ -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<Actividad> actividades = new ArrayList<>();
|
||||
private final List<Actividad> actividadesEspecificas = new ArrayList<>(); // Nueva lista para tareas específicas
|
||||
private final Grid<Actividad> grid = new Grid<>(Actividad.class);
|
||||
private final Grid<Actividad> gridActividadesEspecificas = new Grid<>(Actividad.class);
|
||||
|
||||
private final ComboBox<Employee> employeeComboBox = new ComboBox<>("Empleado");
|
||||
private final ComboBox<Employee> employeeComboBox = new ComboBox<>("Employee");
|
||||
private final ComboBox<String> equipoDropdown = new ComboBox<>("Equipo");
|
||||
private VDatePicker fechaPicker = new VDatePicker("Selecciona una fecha");
|
||||
|
||||
|
||||
private final ComboBox<String> 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) {
|
||||
|
@ -50,6 +50,7 @@ public class ReporteView extends VerticalLayout {
|
||||
|
||||
private final Span semanaInfoSpan = new Span();
|
||||
|
||||
|
||||
// Obtener el año actual
|
||||
private int currentYear = LocalDate.now().getYear();
|
||||
|
||||
@ -75,19 +76,22 @@ public class ReporteView extends VerticalLayout {
|
||||
// Listener para actualizar `semanaInfoSpan` con la selección del usuario en `semanaComboBox`
|
||||
semanaComboBox.addValueChangeListener(event -> {
|
||||
String selectedWeek = event.getValue();
|
||||
semanaInfoSpan.setText(selectedWeek != null ? selectedWeek : "Selecciona una semana");
|
||||
semanaInfoSpan.setText(selectedWeek != null
|
||||
? selectedWeek : "Selecciona una semana");
|
||||
});
|
||||
|
||||
Button reportButton = new Button("Generar Reporte de Horas Trabajadas",
|
||||
event -> generateHoursWorkedReport());
|
||||
HorizontalLayout filtersLayout = new HorizontalLayout(equipoComboBox, semanaComboBox, reportButton);
|
||||
HorizontalLayout filtersLayout = new HorizontalLayout(equipoComboBox,
|
||||
semanaComboBox, reportButton);
|
||||
add(filtersLayout);
|
||||
|
||||
// Añadir `headerLayout` al diseño principal para el encabezado dinámico
|
||||
add(headerLayout);
|
||||
updateHeaderLayout(null, null);
|
||||
|
||||
grid.addColumn(map -> map.get("ID")).setHeader("ID").getElement().getStyle().set("font-weight", "bold");
|
||||
grid.addColumn(map -> map.get("ID")).setHeader("ID")
|
||||
.getElement().getStyle().set("font-weight", "bold");
|
||||
grid.addColumn(map -> map.get("Employee ID")).setHeader("Employee ID");
|
||||
grid.addColumn(map -> map.get("Empleado")).setHeader("Empleado");
|
||||
grid.addColumn(map -> map.get("Horas Trabajadas")).setHeader("Horas Trabajadas");
|
||||
@ -101,7 +105,8 @@ public class ReporteView extends VerticalLayout {
|
||||
int year = LocalDate.now().getYear();
|
||||
LocalDate startOfYear = LocalDate.of(year, 1, 5); // Suponemos que la semana comienza el 5 de enero.
|
||||
|
||||
List<String> semanas = startOfYear.datesUntil(LocalDate.of(year + 1, 1, 1),
|
||||
List<String> semanas = startOfYear.datesUntil(LocalDate
|
||||
.of(year + 1, 1, 1),
|
||||
java.time.Period.ofWeeks(1))
|
||||
.map(date -> {
|
||||
int weekNumber = date.get(WeekFields.of(DayOfWeek.MONDAY, 1)
|
||||
@ -128,23 +133,27 @@ public class ReporteView extends VerticalLayout {
|
||||
String selectedWeek = semanaComboBox.getValue();
|
||||
if (selectedEquipo == null || selectedWeek == null) {
|
||||
Notification.show("Por favor, selecciona un equipo y una semana para generar el reporte.",
|
||||
3000, Notification.Position.MIDDLE);
|
||||
3000,
|
||||
Notification.Position.MIDDLE);
|
||||
return;
|
||||
}
|
||||
|
||||
int weekNumber = Integer.parseInt(selectedWeek.split(" ")[1].replace(":", ""));
|
||||
LocalDate selectedDate = LocalDate.now().with(WeekFields.of(DayOfWeek.FRIDAY, 1)
|
||||
.weekOfWeekBasedYear(), weekNumber);
|
||||
int weekNumber = Integer.parseInt(selectedWeek.split(" ")[1]
|
||||
.replace(":", ""));
|
||||
LocalDate selectedDate = LocalDate.now()
|
||||
.with(WeekFields.of(DayOfWeek.FRIDAY, 1)
|
||||
.weekOfWeekBasedYear(), weekNumber);
|
||||
updateHeaderLayout(selectedEquipo, selectedDate);
|
||||
|
||||
List<HoursWorked> hoursWorkedList = hoursWorkedService.findAll().stream()
|
||||
.filter(hw -> hw.getEmployee().getTeam().getId().equals(selectedEquipo
|
||||
.getId()) && hw.getWeekNumber() == weekNumber)
|
||||
.filter(hw -> hw.getEmployee().getTeam().getId()
|
||||
.equals(selectedEquipo.getId()) && hw.getWeekNumber() == weekNumber)
|
||||
.collect(Collectors.toList());
|
||||
|
||||
if (hoursWorkedList.isEmpty()) {
|
||||
Notification.show("No hay horas trabajadas disponibles para generar el reporte.",
|
||||
3000, Notification.Position.MIDDLE);
|
||||
3000,
|
||||
Notification.Position.MIDDLE);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -179,8 +188,8 @@ public class ReporteView extends VerticalLayout {
|
||||
String formattedEndDate = endOfWeek.getDayOfMonth() + " de "
|
||||
+ endOfWeek.getMonth().getDisplayName(TextStyle.FULL, Locale.getDefault());
|
||||
|
||||
headerLayout.add(new Span("Informe "
|
||||
+ String.format("%03d", weekNumber) + "/" + currentYear) {{
|
||||
headerLayout.add(new Span("Informe " + String.format("%03d", weekNumber)
|
||||
+ "/" + currentYear) {{
|
||||
getStyle().set("font-size", "24px");
|
||||
getStyle().set("font-weight", "bold");
|
||||
}});
|
||||
@ -204,13 +213,14 @@ public class ReporteView extends VerticalLayout {
|
||||
}
|
||||
}
|
||||
|
||||
private void generateExcelDownloadLink(final List<Map<String, Object>> data, final int weekNumber) {
|
||||
private void generateExcelDownloadLink(final List<Map<String, Object>> data,
|
||||
final int weekNumber) {
|
||||
try {
|
||||
List<String> headers = List.of("ID", "Employee ID", "Empleado",
|
||||
"Horas Trabajadas", "Horas Pendientes", "Observaciones");
|
||||
String selectedTeam = equipoComboBox.getValue().getName();
|
||||
byte[] excelBytes = reportService.writeAsExcel(
|
||||
"hours_worked_report", headers, data, selectedTeam, weekNumber, currentYear);
|
||||
byte[] excelBytes = reportService.writeAsExcel("hours_worked_report",
|
||||
headers, data, selectedTeam, weekNumber, currentYear);
|
||||
|
||||
StreamResource excelResource = new StreamResource("hours_worked_report.xlsx",
|
||||
() -> new ByteArrayInputStream(excelBytes));
|
||||
@ -231,4 +241,13 @@ public class ReporteView extends VerticalLayout {
|
||||
return date.get(WeekFields.of(Locale.getDefault()).weekOfWeekBasedYear());
|
||||
}
|
||||
|
||||
public int getCurrentYear() {
|
||||
return currentYear;
|
||||
}
|
||||
|
||||
// Opcional: Si deseas permitir cambiar el año actual manualmente, agrega un setter
|
||||
public void setCurrentYear(final int currentYear) {
|
||||
this.currentYear = currentYear;
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user