diff --git a/pom.xml b/pom.xml index a9cae3e..b27ada9 100644 --- a/pom.xml +++ b/pom.xml @@ -72,6 +72,12 @@ runtime + + org.apache.pdfbox + pdfbox + 2.0.29 + + org.springframework.boot spring-boot-starter-data-jpa diff --git a/src/main/java/com/primefactorsolutions/repositories/HoursWorkedRepository.java b/src/main/java/com/primefactorsolutions/repositories/HoursWorkedRepository.java new file mode 100644 index 0000000..e5ad85b --- /dev/null +++ b/src/main/java/com/primefactorsolutions/repositories/HoursWorkedRepository.java @@ -0,0 +1,10 @@ +package com.primefactorsolutions.repositories; + +import com.primefactorsolutions.model.HoursWorked; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.stereotype.Repository; + +@Repository +public interface HoursWorkedRepository extends JpaRepository { + // Puedes definir consultas personalizadas aquĆ­ si es necesario. +} diff --git a/src/main/java/com/primefactorsolutions/service/HoursWorkedService.java b/src/main/java/com/primefactorsolutions/service/HoursWorkedService.java new file mode 100644 index 0000000..855a305 --- /dev/null +++ b/src/main/java/com/primefactorsolutions/service/HoursWorkedService.java @@ -0,0 +1,35 @@ +package com.primefactorsolutions.service; + +import com.primefactorsolutions.model.HoursWorked; +import com.primefactorsolutions.repositories.HoursWorkedRepository; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import java.util.List; + +@Service +public class HoursWorkedService { + private final HoursWorkedRepository hoursWorkedRepository; + + @Autowired + public HoursWorkedService(HoursWorkedRepository hoursWorkedRepository) { + this.hoursWorkedRepository = hoursWorkedRepository; + } + + public List findAll() { + return hoursWorkedRepository.findAll(); + } + + public HoursWorked saveHoursWorked(HoursWorked hoursWorked) { + return hoursWorkedRepository.save(hoursWorked); + } + + public HoursWorked save(HoursWorked hoursWorked) { + return hoursWorkedRepository.save(hoursWorked); + } + + public void deleteHoursWorked(Long id) { + hoursWorkedRepository.deleteById(id); + } +} + diff --git a/src/main/java/com/primefactorsolutions/views/HoursWorkedView.java b/src/main/java/com/primefactorsolutions/views/HoursWorkedView.java index 183c2c6..2eb0c19 100644 --- a/src/main/java/com/primefactorsolutions/views/HoursWorkedView.java +++ b/src/main/java/com/primefactorsolutions/views/HoursWorkedView.java @@ -3,6 +3,7 @@ import com.primefactorsolutions.model.Actividad; import com.primefactorsolutions.model.Employee; import com.primefactorsolutions.model.HoursWorked; import com.primefactorsolutions.service.EmployeeService; +import com.primefactorsolutions.service.HoursWorkedService; import com.vaadin.flow.component.datepicker.DatePicker; import com.vaadin.flow.component.grid.Grid; import com.vaadin.flow.component.notification.Notification; @@ -48,8 +49,10 @@ public class HoursWorkedView extends VerticalLayout { private final Label horasPendientesLabel = new Label(); @Autowired - public HoursWorkedView(final EmployeeService employeeService) { + private final HoursWorkedService hoursWorkedService; + public HoursWorkedView(final EmployeeService employeeService, final HoursWorkedService hoursWorkedService) { this.employeeService = employeeService; + this.hoursWorkedService = hoursWorkedService; configurarVista(); cargarDatos(); } @@ -218,6 +221,9 @@ public class HoursWorkedView extends VerticalLayout { HoursWorked hoursWorked = new HoursWorked(); hoursWorked.setEmployee(employeeComboBox.getValue()); hoursWorked.setWeekNumber(weekNumber); + hoursWorked.setTotalHours((actividades.stream() + .mapToDouble(this::calcularTotalPorDia).sum())); + hoursWorkedService.save(hoursWorked); Notification.show("Actividades guardadas correctamente."); } diff --git a/src/main/java/com/primefactorsolutions/views/MainLayout.java b/src/main/java/com/primefactorsolutions/views/MainLayout.java index e64ad07..f2a465c 100644 --- a/src/main/java/com/primefactorsolutions/views/MainLayout.java +++ b/src/main/java/com/primefactorsolutions/views/MainLayout.java @@ -148,6 +148,8 @@ public class MainLayout extends AppLayout { LineAwesomeIcon.HOURGLASS_START_SOLID.create()); timesheet.addItem(new SideNavItem("Hours Worked", HoursWorkedView.class, LineAwesomeIcon.ID_CARD_SOLID.create())); +// timesheet.addItem(new SideNavItem("Reporte", ReportHoursWorkedView.class, +// LineAwesomeIcon.CAR_ALT_SOLID.create())); SideNavItem profile = new SideNavItem("My Profile", ProfileView.class, LineAwesomeIcon.USER_EDIT_SOLID.create());