From e3d672c00ba10047ab46584bef732238de3638a2 Mon Sep 17 00:00:00 2001 From: Melina Gutierrez Date: Mon, 21 Oct 2024 13:07:42 -0400 Subject: [PATCH] #46 Perfil de Empleado - Registro Semanal Y Mensual falta bd --- .../model/HoursWorked.java | 60 ------- .../views/HoursWorkedMonthView.java | 73 +-------- .../views/HoursWorkedView.java | 149 ------------------ 3 files changed, 1 insertion(+), 281 deletions(-) diff --git a/src/main/java/com/primefactorsolutions/model/HoursWorked.java b/src/main/java/com/primefactorsolutions/model/HoursWorked.java index 8435b53..3824bfe 100644 --- a/src/main/java/com/primefactorsolutions/model/HoursWorked.java +++ b/src/main/java/com/primefactorsolutions/model/HoursWorked.java @@ -1,6 +1,5 @@ package com.primefactorsolutions.model; -<<<<<<< HEAD import com.vaadin.flow.component.template.Id; import jakarta.persistence.Entity; import jakarta.persistence.GeneratedValue; @@ -47,64 +46,5 @@ public class HoursWorked extends BaseEntity { public void setTotalHours(double 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 } } diff --git a/src/main/java/com/primefactorsolutions/views/HoursWorkedMonthView.java b/src/main/java/com/primefactorsolutions/views/HoursWorkedMonthView.java index 95b2ab6..a908f16 100644 --- a/src/main/java/com/primefactorsolutions/views/HoursWorkedMonthView.java +++ b/src/main/java/com/primefactorsolutions/views/HoursWorkedMonthView.java @@ -1,6 +1,5 @@ package com.primefactorsolutions.views; -<<<<<<< HEAD import com.primefactorsolutions.model.Employee; import com.primefactorsolutions.model.Actividad; 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.orderedlayout.HorizontalLayout; 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.Route; import com.vaadin.flow.spring.annotation.SpringComponent; import jakarta.annotation.security.PermitAll; -<<<<<<< HEAD import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Scope; import java.time.LocalDate; import java.time.temporal.TemporalAdjusters; import java.util.ArrayList; -======= -import org.springframework.context.annotation.Scope; - ->>>>>>> b19496ca1563c947f536a725625c26e81bd04c25 import java.util.List; @SpringComponent @@ -45,7 +29,6 @@ import java.util.List; @PageTitle("Hours Worked Month") @Route(value = "/hours-worked-month/me", layout = MainLayout.class) public class HoursWorkedMonthView extends VerticalLayout { -<<<<<<< HEAD private final EmployeeService employeeService; private final ComboBox employeeComboBox = new ComboBox<>("Empleado"); private final ComboBox equipoDropdown = new ComboBox<>("Equipo"); @@ -176,59 +159,5 @@ public class HoursWorkedMonthView extends VerticalLayout { private void closeView() { getUI().ifPresent(ui -> ui.navigate("")); -======= - - private final Grid grid; - private final ComboBox 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 getEquipos() { - return List.of("Equipo A", "Equipo B", "Equipo C"); - } - - private List 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 - } -} \ No newline at end of file +} diff --git a/src/main/java/com/primefactorsolutions/views/HoursWorkedView.java b/src/main/java/com/primefactorsolutions/views/HoursWorkedView.java index b6d2ba7..183c2c6 100644 --- a/src/main/java/com/primefactorsolutions/views/HoursWorkedView.java +++ b/src/main/java/com/primefactorsolutions/views/HoursWorkedView.java @@ -1,11 +1,7 @@ package com.primefactorsolutions.views; -<<<<<<< HEAD import com.primefactorsolutions.model.Actividad; import com.primefactorsolutions.model.Employee; import com.primefactorsolutions.model.HoursWorked; -======= -import com.primefactorsolutions.model.Employee; ->>>>>>> b19496ca1563c947f536a725625c26e81bd04c25 import com.primefactorsolutions.service.EmployeeService; import com.vaadin.flow.component.datepicker.DatePicker; 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.LocalDate; -<<<<<<< HEAD import java.time.temporal.IsoFields; -======= ->>>>>>> b19496ca1563c947f536a725625c26e81bd04c25 import java.time.temporal.WeekFields; import java.util.ArrayList; import java.util.List; @@ -43,31 +36,21 @@ import java.util.Locale; public class HoursWorkedView extends VerticalLayout { private final List actividades = new ArrayList<>(); private final Grid grid = new Grid<>(Actividad.class); -<<<<<<< HEAD private final ComboBox employeeComboBox = new ComboBox<>("Employee"); private LocalDate selectedStartOfWeek; private int weekNumber; -======= - private final Grid totalsGrid = new Grid<>(Actividad.class); - private final ComboBox employeeComboBox = new ComboBox<>("Employee"); - private LocalDate selectedStartOfWeek; ->>>>>>> b19496ca1563c947f536a725625c26e81bd04c25 @Autowired private final EmployeeService employeeService; private final Label fechasLabel = new Label("Selecciona una semana para ver las fechas."); -<<<<<<< HEAD private final Label totalCompletadoLabel = new Label(); private final Label horasPendientesLabel = new Label(); -======= ->>>>>>> b19496ca1563c947f536a725625c26e81bd04c25 @Autowired public HoursWorkedView(final EmployeeService employeeService) { this.employeeService = employeeService; configurarVista(); -<<<<<<< HEAD cargarDatos(); } @@ -76,8 +59,6 @@ public class HoursWorkedView extends VerticalLayout { grid.setItems(actividades); double totalHoras = calcularTotalHoras(listaDeHorasTrabajadas); // Pasa la lista aquí -======= ->>>>>>> b19496ca1563c947f536a725625c26e81bd04c25 } private void setEmployeeComboBoxProperties() { @@ -100,13 +81,10 @@ public class HoursWorkedView extends VerticalLayout { }); } -<<<<<<< HEAD private int getWeekOfYear(LocalDate date) { return date.get(IsoFields.WEEK_OF_WEEK_BASED_YEAR); } -======= ->>>>>>> b19496ca1563c947f536a725625c26e81bd04c25 private void configurarVista() { DatePicker fechaPicker = new DatePicker("Selecciona una fecha"); fechaPicker.addValueChangeListener(event -> { @@ -115,7 +93,6 @@ public class HoursWorkedView extends VerticalLayout { selectedStartOfWeek = getStartOfWeek(selectedDate); LocalDate endOfWeek = selectedStartOfWeek.plusDays(6); fechasLabel.setText("Semana del " + selectedStartOfWeek + " al " + endOfWeek); -<<<<<<< HEAD weekNumber = getWeekOfYear(selectedDate); } }); @@ -123,10 +100,6 @@ public class HoursWorkedView extends VerticalLayout { Button verMesButton = new Button("Ver Mes", event -> { getUI().ifPresent(ui -> ui.navigate(HoursWorkedMonthView.class)); }); -======= - } - }); ->>>>>>> b19496ca1563c947f536a725625c26e81bd04c25 ComboBox equipoDropdown = new ComboBox<>("Equipo"); equipoDropdown.setItems("Equipo 1", "Equipo 2", "Equipo 3"); @@ -141,7 +114,6 @@ public class HoursWorkedView extends VerticalLayout { HorizontalLayout actividadFormLayout = configurarFormularioActividades(); Button actualizarButton = new Button("Actualizar Totales", event -> actualizarTotales()); -<<<<<<< HEAD Button guardarButton = new Button("Guardar", event -> guardarActividades()); 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); -======= - 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() { @@ -176,118 +139,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"); -<<<<<<< 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 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 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() {