#46 Perfil de Empleado - Registro Semanal Y Mensual falta bd

This commit is contained in:
Melina Gutierrez 2024-10-21 13:07:42 -04:00
parent 6c1c0e5ea7
commit e3d672c00b
3 changed files with 1 additions and 281 deletions

View File

@ -1,6 +1,5 @@
package com.primefactorsolutions.model; package com.primefactorsolutions.model;
<<<<<<< HEAD
import com.vaadin.flow.component.template.Id; import com.vaadin.flow.component.template.Id;
import jakarta.persistence.Entity; import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue; import jakarta.persistence.GeneratedValue;
@ -47,64 +46,5 @@ public class HoursWorked extends BaseEntity {
public void setTotalHours(double totalHours) { public void setTotalHours(double totalHours) {
this.totalHours = totalHours; this.totalHours = totalHours;
=======
import jakarta.persistence.*;
import jakarta.validation.constraints.AssertTrue;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import java.time.LocalDate;
@Data
@Entity
@AllArgsConstructor
@NoArgsConstructor
@EqualsAndHashCode(callSuper = true)
public class HoursWorked extends BaseEntity {
@ManyToOne
@JoinColumn(name = "employee_id", nullable = false)
private Employee employee;
private LocalDate workDate;
private int regularHours;
private int overtimeHours;
private int weekendHours;
private int holidayHours;
@Enumerated(EnumType.STRING)
private WorkType workType;
@Enumerated(EnumType.STRING)
private ApprovalStatus approvalStatus;
@Column(columnDefinition = "TEXT")
private String notes;
public enum WorkType {
ONSITE, REMOTE, HYBRID
}
public enum ApprovalStatus {
PENDING, APPROVED, REJECTED
}
@AssertTrue(message = "Las horas no pueden ser negativas")
public boolean areHoursValid() {
return regularHours >= 0 && overtimeHours >= 0 &&
weekendHours >= 0 && holidayHours >= 0;
}
@AssertTrue(message = "La suma de horas no puede superar 24 en un día")
public boolean isTotalHoursValid() {
int totalHours = regularHours + overtimeHours + weekendHours + holidayHours;
return totalHours <= 24;
>>>>>>> b19496ca1563c947f536a725625c26e81bd04c25
} }
} }

View File

@ -1,6 +1,5 @@
package com.primefactorsolutions.views; package com.primefactorsolutions.views;
<<<<<<< HEAD
import com.primefactorsolutions.model.Employee; import com.primefactorsolutions.model.Employee;
import com.primefactorsolutions.model.Actividad; import com.primefactorsolutions.model.Actividad;
import com.primefactorsolutions.service.EmployeeService; import com.primefactorsolutions.service.EmployeeService;
@ -12,31 +11,16 @@ import com.vaadin.flow.component.html.Label;
import com.vaadin.flow.component.notification.Notification; import com.vaadin.flow.component.notification.Notification;
import com.vaadin.flow.component.orderedlayout.HorizontalLayout; 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.component.button.Button;
import com.vaadin.flow.component.combobox.ComboBox;
import com.vaadin.flow.component.grid.Grid;
import com.vaadin.flow.component.html.H2;
import com.vaadin.flow.component.html.Label;
import com.vaadin.flow.component.orderedlayout.VerticalLayout;
import com.vaadin.flow.component.textfield.TextField;
>>>>>>> b19496ca1563c947f536a725625c26e81bd04c25
import com.vaadin.flow.router.PageTitle; import com.vaadin.flow.router.PageTitle;
import com.vaadin.flow.router.Route; import com.vaadin.flow.router.Route;
import com.vaadin.flow.spring.annotation.SpringComponent; import com.vaadin.flow.spring.annotation.SpringComponent;
import jakarta.annotation.security.PermitAll; import jakarta.annotation.security.PermitAll;
<<<<<<< HEAD
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 java.time.LocalDate; import java.time.LocalDate;
import java.time.temporal.TemporalAdjusters; import java.time.temporal.TemporalAdjusters;
import java.util.ArrayList; import java.util.ArrayList;
=======
import org.springframework.context.annotation.Scope;
>>>>>>> b19496ca1563c947f536a725625c26e81bd04c25
import java.util.List; import java.util.List;
@SpringComponent @SpringComponent
@ -45,7 +29,6 @@ import java.util.List;
@PageTitle("Hours Worked Month") @PageTitle("Hours Worked Month")
@Route(value = "/hours-worked-month/me", layout = MainLayout.class) @Route(value = "/hours-worked-month/me", layout = MainLayout.class)
public class HoursWorkedMonthView extends VerticalLayout { public class HoursWorkedMonthView extends VerticalLayout {
<<<<<<< HEAD
private final EmployeeService employeeService; private final EmployeeService employeeService;
private final ComboBox<Employee> employeeComboBox = new ComboBox<>("Empleado"); private final ComboBox<Employee> employeeComboBox = new ComboBox<>("Empleado");
private final ComboBox<String> equipoDropdown = new ComboBox<>("Equipo"); private final ComboBox<String> equipoDropdown = new ComboBox<>("Equipo");
@ -176,59 +159,5 @@ public class HoursWorkedMonthView extends VerticalLayout {
private void closeView() { private void closeView() {
getUI().ifPresent(ui -> ui.navigate("")); getUI().ifPresent(ui -> ui.navigate(""));
=======
private final Grid<HoursWorkedView.Actividad> grid;
private final ComboBox<String> equipoComboBox;
private final TextField empleadoSearch;
private final Button actualizarButton;
private final Button guardarButton;
private final Button cerrarButton;
public HoursWorkedMonthView() {
add(new H2("Registro de Horas Trabajadas"));
Label mesLabel = new Label("SEPTIEMBRE 2024, MES 9");
add(mesLabel);
equipoComboBox = new ComboBox<>("Equipo");
equipoComboBox.setItems(getEquipos());
add(equipoComboBox);
empleadoSearch = new TextField("Empleado (Search):");
add(empleadoSearch);
grid = new Grid<>(HoursWorkedView.Actividad.class);
grid.setItems(getActividades());
grid.setColumns("lunes", "martes", "miercoles", "jueves", "viernes", "sabado", "domingo", "totalSem");
add(grid);
actualizarButton = new Button("Actualizar", e -> actualizar());
guardarButton = new Button("Guardar", e -> guardar());
cerrarButton = new Button("Cerrar", e -> cerrar());
add(actualizarButton, guardarButton, cerrarButton);
}
private List<String> getEquipos() {
return List.of("Equipo A", "Equipo B", "Equipo C");
}
private List<HoursWorkedView.Actividad> getActividades() {
return List.of(
new HoursWorkedView.Actividad(1, 7, 8, 8, 8, 8, 1, 40),
new HoursWorkedView.Actividad(2, 1, 7, 8, 8, 8, 1, 40)
);
}
private void actualizar() {
grid.setItems(getActividades());
}
private void guardar() {
}
private void cerrar() {
>>>>>>> b19496ca1563c947f536a725625c26e81bd04c25
} }
} }

View File

@ -1,11 +1,7 @@
package com.primefactorsolutions.views; package com.primefactorsolutions.views;
<<<<<<< HEAD
import com.primefactorsolutions.model.Actividad; import com.primefactorsolutions.model.Actividad;
import com.primefactorsolutions.model.Employee; import com.primefactorsolutions.model.Employee;
import com.primefactorsolutions.model.HoursWorked; import com.primefactorsolutions.model.HoursWorked;
=======
import com.primefactorsolutions.model.Employee;
>>>>>>> b19496ca1563c947f536a725625c26e81bd04c25
import com.primefactorsolutions.service.EmployeeService; import com.primefactorsolutions.service.EmployeeService;
import com.vaadin.flow.component.datepicker.DatePicker; import com.vaadin.flow.component.datepicker.DatePicker;
import com.vaadin.flow.component.grid.Grid; import com.vaadin.flow.component.grid.Grid;
@ -26,10 +22,7 @@ import com.vaadin.flow.component.html.Label;
import java.time.DayOfWeek; import java.time.DayOfWeek;
import java.time.LocalDate; import java.time.LocalDate;
<<<<<<< HEAD
import java.time.temporal.IsoFields; import java.time.temporal.IsoFields;
=======
>>>>>>> b19496ca1563c947f536a725625c26e81bd04c25
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;
@ -43,31 +36,21 @@ import java.util.Locale;
public class HoursWorkedView extends VerticalLayout { public class HoursWorkedView extends VerticalLayout {
private final List<Actividad> actividades = new ArrayList<>(); private final List<Actividad> actividades = new ArrayList<>();
private final Grid<Actividad> grid = new Grid<>(Actividad.class); private final Grid<Actividad> grid = new Grid<>(Actividad.class);
<<<<<<< HEAD
private final ComboBox<Employee> employeeComboBox = new ComboBox<>("Employee"); private final ComboBox<Employee> employeeComboBox = new ComboBox<>("Employee");
private LocalDate selectedStartOfWeek; private LocalDate selectedStartOfWeek;
private int weekNumber; private int weekNumber;
=======
private final Grid<Actividad> totalsGrid = new Grid<>(Actividad.class);
private final ComboBox<Employee> employeeComboBox = new ComboBox<>("Employee");
private LocalDate selectedStartOfWeek;
>>>>>>> b19496ca1563c947f536a725625c26e81bd04c25
@Autowired @Autowired
private final EmployeeService employeeService; private final EmployeeService employeeService;
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.");
<<<<<<< HEAD
private final Label totalCompletadoLabel = new Label(); private final Label totalCompletadoLabel = new Label();
private final Label horasPendientesLabel = new Label(); private final Label horasPendientesLabel = new Label();
=======
>>>>>>> b19496ca1563c947f536a725625c26e81bd04c25
@Autowired @Autowired
public HoursWorkedView(final EmployeeService employeeService) { public HoursWorkedView(final EmployeeService employeeService) {
this.employeeService = employeeService; this.employeeService = employeeService;
configurarVista(); configurarVista();
<<<<<<< HEAD
cargarDatos(); cargarDatos();
} }
@ -76,8 +59,6 @@ public class HoursWorkedView extends VerticalLayout {
grid.setItems(actividades); grid.setItems(actividades);
double totalHoras = calcularTotalHoras(listaDeHorasTrabajadas); // Pasa la lista aquí double totalHoras = calcularTotalHoras(listaDeHorasTrabajadas); // Pasa la lista aquí
=======
>>>>>>> b19496ca1563c947f536a725625c26e81bd04c25
} }
private void setEmployeeComboBoxProperties() { private void setEmployeeComboBoxProperties() {
@ -100,13 +81,10 @@ public class HoursWorkedView extends VerticalLayout {
}); });
} }
<<<<<<< HEAD
private int getWeekOfYear(LocalDate date) { private int getWeekOfYear(LocalDate date) {
return date.get(IsoFields.WEEK_OF_WEEK_BASED_YEAR); return date.get(IsoFields.WEEK_OF_WEEK_BASED_YEAR);
} }
=======
>>>>>>> b19496ca1563c947f536a725625c26e81bd04c25
private void configurarVista() { private void configurarVista() {
DatePicker fechaPicker = new DatePicker("Selecciona una fecha"); DatePicker fechaPicker = new DatePicker("Selecciona una fecha");
fechaPicker.addValueChangeListener(event -> { fechaPicker.addValueChangeListener(event -> {
@ -115,7 +93,6 @@ public class HoursWorkedView extends VerticalLayout {
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);
<<<<<<< HEAD
weekNumber = getWeekOfYear(selectedDate); weekNumber = getWeekOfYear(selectedDate);
} }
}); });
@ -123,10 +100,6 @@ public class HoursWorkedView extends VerticalLayout {
Button verMesButton = new Button("Ver Mes", event -> { Button verMesButton = new Button("Ver Mes", event -> {
getUI().ifPresent(ui -> ui.navigate(HoursWorkedMonthView.class)); getUI().ifPresent(ui -> ui.navigate(HoursWorkedMonthView.class));
}); });
=======
}
});
>>>>>>> b19496ca1563c947f536a725625c26e81bd04c25
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");
@ -141,7 +114,6 @@ public class HoursWorkedView extends VerticalLayout {
HorizontalLayout actividadFormLayout = configurarFormularioActividades(); HorizontalLayout actividadFormLayout = configurarFormularioActividades();
Button actualizarButton = new Button("Actualizar Totales", event -> actualizarTotales()); Button actualizarButton = new Button("Actualizar Totales", event -> actualizarTotales());
<<<<<<< HEAD
Button guardarButton = new Button("Guardar", event -> guardarActividades()); Button guardarButton = new Button("Guardar", event -> guardarActividades());
Button cerrarButton = new Button("Cerrar", event -> this.closeView()); Button cerrarButton = new Button("Cerrar", event -> this.closeView());
@ -153,15 +125,6 @@ public class HoursWorkedView extends VerticalLayout {
add(fechaPicker, fechasLabel, filtersLayout, grid, actividadFormLayout, buttonsLayout, totalesLayout); add(fechaPicker, fechasLabel, filtersLayout, grid, actividadFormLayout, buttonsLayout, totalesLayout);
=======
Button guardarButton = new Button("Guardar");
Button cerrarButton = new Button("Cerrar");
HorizontalLayout buttonsLayout = new HorizontalLayout(actualizarButton, guardarButton, cerrarButton);
add(fechaPicker, fechasLabel, filtersLayout, grid, actividadFormLayout, buttonsLayout, totalsGrid);
configurarTablaTotales();
>>>>>>> b19496ca1563c947f536a725625c26e81bd04c25
} }
private void configurarGrid() { private void configurarGrid() {
@ -176,118 +139,6 @@ public class HoursWorkedView extends VerticalLayout {
grid.addColumn(Actividad::getSabado).setHeader("Sábado"); grid.addColumn(Actividad::getSabado).setHeader("Sábado");
grid.addColumn(Actividad::getDomingo).setHeader("Domingo"); grid.addColumn(Actividad::getDomingo).setHeader("Domingo");
grid.addColumn(this::calcularTotalPorDia).setHeader("Total Día").setKey("totalDia"); grid.addColumn(this::calcularTotalPorDia).setHeader("Total Día").setKey("totalDia");
<<<<<<< HEAD
=======
}
private HorizontalLayout configurarFormularioActividades() {
TextField actividadNombre = new TextField("Actividad");
TextField lunesHoras = new TextField("Lunes");
TextField martesHoras = new TextField("Martes");
TextField miercolesHoras = new TextField("Miércoles");
TextField juevesHoras = new TextField("Jueves");
TextField viernesHoras = new TextField("Viernes");
TextField sabadoHoras = new TextField("Sábado");
TextField domingoHoras = new TextField("Domingo");
Button agregarActividadButton = new Button("Agregar Actividad", e -> {
try {
Actividad nuevaActividad = new Actividad.Builder()
.nombre(actividadNombre.getValue())
.lunes(Double.parseDouble(lunesHoras.getValue()))
.martes(Double.parseDouble(martesHoras.getValue()))
.miercoles(Double.parseDouble(miercolesHoras.getValue()))
.jueves(Double.parseDouble(juevesHoras.getValue()))
.viernes(Double.parseDouble(viernesHoras.getValue()))
.sabado(Double.parseDouble(sabadoHoras.getValue()))
.domingo(Double.parseDouble(domingoHoras.getValue()))
.build();
actividades.add(nuevaActividad);
grid.setItems(actividades);
actualizarTotales();
Notification.show("Actividad agregada correctamente");
} catch (NumberFormatException ex) {
Notification.show("Error: Por favor ingresa números válidos para las horas.");
}
});
return new HorizontalLayout(
actividadNombre, lunesHoras, martesHoras, miercolesHoras,
juevesHoras, viernesHoras, sabadoHoras, domingoHoras, agregarActividadButton);
}
private LocalDate getStartOfWeek(final LocalDate date) {
WeekFields weekFields = WeekFields.of(Locale.getDefault());
return date.with(weekFields.dayOfWeek(), DayOfWeek.MONDAY.getValue());
}
private double calcularTotalPorDia(final Actividad actividad) {
return actividad.getLunes() + actividad.getMartes() + actividad.getMiercoles()
+ actividad.getJueves() + actividad.getViernes() + actividad.getSabado() + actividad.getDomingo();
}
private void configurarTablaTotales() {
totalsGrid.removeAllColumns();
totalsGrid.addColumn(Actividad::getNombre).setHeader("Descripción");
totalsGrid.addColumn(Actividad::getLunes).setHeader("Lunes");
totalsGrid.addColumn(Actividad::getMartes).setHeader("Martes");
totalsGrid.addColumn(Actividad::getMiercoles).setHeader("Miércoles");
totalsGrid.addColumn(Actividad::getJueves).setHeader("Jueves");
totalsGrid.addColumn(Actividad::getViernes).setHeader("Viernes");
totalsGrid.addColumn(Actividad::getSabado).setHeader("Sábado");
totalsGrid.addColumn(Actividad::getDomingo).setHeader("Domingo");
totalsGrid.addColumn(this::calcularTotalPorSemana).setHeader("Total");
totalsGrid.setItems(calcularTotales());
}
private double calcularTotalPorSemana(final Actividad actividad) {
return actividad.getLunes() + actividad.getMartes() + actividad.getMiercoles()
+ actividad.getJueves() + actividad.getViernes() + actividad.getSabado()
+ actividad.getDomingo();
}
private List<Actividad> calcularTotales() {
Actividad totalActividad = new Actividad.Builder()
.nombre("Total Semanal")
.lunes(actividades.stream().mapToDouble(Actividad::getLunes).sum())
.martes(actividades.stream().mapToDouble(Actividad::getMartes).sum())
.miercoles(actividades.stream().mapToDouble(Actividad::getMiercoles).sum())
.jueves(actividades.stream().mapToDouble(Actividad::getJueves).sum())
.viernes(actividades.stream().mapToDouble(Actividad::getViernes).sum())
.sabado(actividades.stream().mapToDouble(Actividad::getSabado).sum())
.domingo(actividades.stream().mapToDouble(Actividad::getDomingo).sum())
.build();
return List.of(totalActividad);
}
private void actualizarTotales() {
double totalLunes = actividades.stream().mapToDouble(Actividad::getLunes).sum();
double totalMartes = actividades.stream().mapToDouble(Actividad::getMartes).sum();
double totalMiercoles = actividades.stream().mapToDouble(Actividad::getMiercoles).sum();
double totalJueves = actividades.stream().mapToDouble(Actividad::getJueves).sum();
double totalViernes = actividades.stream().mapToDouble(Actividad::getViernes).sum();
double totalSabado = actividades.stream().mapToDouble(Actividad::getSabado).sum();
double totalDomingo = actividades.stream().mapToDouble(Actividad::getDomingo).sum();
double totalSemanaCompletada = totalLunes + totalMartes + totalMiercoles + totalJueves + totalViernes + totalSabado + totalDomingo;
double horasPendientes = 40 - totalSemanaCompletada;
List<Actividad> totales = new ArrayList<>();
totales.add(new Actividad.Builder()
.nombre("Total Hrs/Semana Completadas")
.lunes(totalSemanaCompletada)
.build());
totales.add(new Actividad.Builder()
.nombre("Total Hrs/Semana Pendientes")
.lunes(horasPendientes)
.build());
totalsGrid.setItems(totales);
>>>>>>> b19496ca1563c947f536a725625c26e81bd04c25
} }
private HorizontalLayout configurarFormularioActividades() { private HorizontalLayout configurarFormularioActividades() {