diff --git a/src/main/bundles/prod.bundle b/src/main/bundles/prod.bundle index 3ca2c8c..f581870 100644 Binary files a/src/main/bundles/prod.bundle and b/src/main/bundles/prod.bundle differ diff --git a/src/main/java/com/primefactorsolutions/model/HoursWorked.java b/src/main/java/com/primefactorsolutions/model/HoursWorked.java deleted file mode 100644 index 87efef0..0000000 --- a/src/main/java/com/primefactorsolutions/model/HoursWorked.java +++ /dev/null @@ -1,42 +0,0 @@ -package com.primefactorsolutions.model; - -import jakarta.persistence.*; -import lombok.*; - -import java.time.LocalDate; -import java.time.temporal.IsoFields; -import java.util.List; - -@Data -@Entity -@AllArgsConstructor -@NoArgsConstructor -@EqualsAndHashCode(callSuper = true) -public class HoursWorked extends BaseEntity { - - private String task; - private String activity; - private LocalDate date; - private double hours; - @ManyToOne - @JoinColumn(name = "employee_id") - private Employee employee; - @ManyToOne - @JoinColumn(name = "team_id") - private Team team; - - public static double calculateTotalHours(final List activities) { - return activities.stream() - .mapToDouble(activity -> activity.hours) - .sum(); - } - - public static double calculatePendingHours(final List activities) { - double totalHoursWorked = calculateTotalHours(activities); - return Math.max(0, 40 - totalHoursWorked); - } - - public int getWeekNumber() { - return date.get(IsoFields.WEEK_OF_WEEK_BASED_YEAR); - } -} diff --git a/src/main/java/com/primefactorsolutions/model/Timesheet.java b/src/main/java/com/primefactorsolutions/model/Timesheet.java deleted file mode 100644 index 041cc3c..0000000 --- a/src/main/java/com/primefactorsolutions/model/Timesheet.java +++ /dev/null @@ -1,21 +0,0 @@ -package com.primefactorsolutions.model; - -import io.hypersistence.utils.hibernate.type.json.JsonType; -import jakarta.persistence.Column; -import jakarta.persistence.Entity; -import lombok.AllArgsConstructor; -import lombok.Data; -import lombok.EqualsAndHashCode; -import org.hibernate.annotations.Type; - -import java.util.List; - -@Entity -@Data -@AllArgsConstructor -@EqualsAndHashCode(callSuper = true) -public class Timesheet extends BaseEntity { - @Type(JsonType.class) - @Column(columnDefinition = "json") - private List entries; -} diff --git a/src/main/java/com/primefactorsolutions/model/TimesheetEntry.java b/src/main/java/com/primefactorsolutions/model/TimesheetEntry.java index dc09bc4..ef44b72 100644 --- a/src/main/java/com/primefactorsolutions/model/TimesheetEntry.java +++ b/src/main/java/com/primefactorsolutions/model/TimesheetEntry.java @@ -1,13 +1,30 @@ package com.primefactorsolutions.model; -import lombok.AllArgsConstructor; -import lombok.Data; -import lombok.NoArgsConstructor; +import jakarta.persistence.*; +import lombok.*; + +import java.time.LocalDate; +import java.time.temporal.IsoFields; @Data +@Entity @AllArgsConstructor @NoArgsConstructor -public class TimesheetEntry { - private TaskType taskType; - private int hours; +@EqualsAndHashCode(callSuper = true) +public class TimesheetEntry extends BaseEntity { + + private String task; + private String details; + private LocalDate date; + private double hours; + @ManyToOne + @JoinColumn(name = "employee_id") + private Employee employee; + @ManyToOne + @JoinColumn(name = "team_id") + private Team team; + + public int getWeekNumber() { + return date.get(IsoFields.WEEK_OF_WEEK_BASED_YEAR); + } } diff --git a/src/main/java/com/primefactorsolutions/repositories/HoursWorkedRepository.java b/src/main/java/com/primefactorsolutions/repositories/HoursWorkedRepository.java index 286d82a..f6bcb96 100644 --- a/src/main/java/com/primefactorsolutions/repositories/HoursWorkedRepository.java +++ b/src/main/java/com/primefactorsolutions/repositories/HoursWorkedRepository.java @@ -1,12 +1,12 @@ package com.primefactorsolutions.repositories; -import com.primefactorsolutions.model.HoursWorked; +import com.primefactorsolutions.model.TimesheetEntry; import org.springframework.data.jpa.repository.JpaRepository; import java.time.LocalDate; import java.util.List; import java.util.UUID; -public interface HoursWorkedRepository extends JpaRepository { - List findByEmployeeIdAndDateBetween(UUID employeeId, LocalDate from, LocalDate to); +public interface HoursWorkedRepository extends JpaRepository { + List findByEmployeeIdAndDateBetween(UUID employeeId, LocalDate from, LocalDate to); } diff --git a/src/main/java/com/primefactorsolutions/service/HoursWorkedService.java b/src/main/java/com/primefactorsolutions/service/TimesheetService.java similarity index 65% rename from src/main/java/com/primefactorsolutions/service/HoursWorkedService.java rename to src/main/java/com/primefactorsolutions/service/TimesheetService.java index 6f6fc42..ac10a3c 100644 --- a/src/main/java/com/primefactorsolutions/service/HoursWorkedService.java +++ b/src/main/java/com/primefactorsolutions/service/TimesheetService.java @@ -1,6 +1,6 @@ package com.primefactorsolutions.service; -import com.primefactorsolutions.model.HoursWorked; +import com.primefactorsolutions.model.TimesheetEntry; import com.primefactorsolutions.repositories.HoursWorkedRepository; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -11,28 +11,28 @@ import java.time.temporal.WeekFields; import java.util.*; @Service -public class HoursWorkedService { +public class TimesheetService { private final HoursWorkedRepository hoursWorkedRepository; @Autowired - public HoursWorkedService(final HoursWorkedRepository hoursWorkedRepository) { + public TimesheetService(final HoursWorkedRepository hoursWorkedRepository) { this.hoursWorkedRepository = hoursWorkedRepository; } - public List findAll() { + public List findAll() { return hoursWorkedRepository.findAll(); } - public HoursWorked save(final HoursWorked hoursWorked) { - return hoursWorkedRepository.save(hoursWorked); + public TimesheetEntry save(final TimesheetEntry timesheetEntry) { + return hoursWorkedRepository.save(timesheetEntry); } - public HoursWorked getHoursWorked(final UUID id) { - final Optional hoursWorked = hoursWorkedRepository.findById(id); + public TimesheetEntry getHoursWorked(final UUID id) { + final Optional hoursWorked = hoursWorkedRepository.findById(id); return hoursWorked.orElse(null); } - public List findListHoursWorkedEmployee(final UUID employeeId, final int weekNumber) { + public List findListHoursWorkedEmployee(final UUID employeeId, final int weekNumber) { final LocalDate from = getFirstDayOfWeek(weekNumber); final LocalDate to = from.plusDays(7); diff --git a/src/main/java/com/primefactorsolutions/views/MainLayout.java b/src/main/java/com/primefactorsolutions/views/MainLayout.java index 07ad80c..ef0540a 100644 --- a/src/main/java/com/primefactorsolutions/views/MainLayout.java +++ b/src/main/java/com/primefactorsolutions/views/MainLayout.java @@ -1,6 +1,11 @@ package com.primefactorsolutions.views; import com.primefactorsolutions.model.Employee; +import com.primefactorsolutions.views.timeoff.TimeOffNewRequestView; +import com.primefactorsolutions.views.timeoff.TimeOffPendingRequestsListView; +import com.primefactorsolutions.views.timeoff.TimeOffRequestListView; +import com.primefactorsolutions.views.timesheet.TimesheetListView; +import com.primefactorsolutions.views.timesheet.TimesheetReportView; import com.vaadin.flow.component.Component; import com.vaadin.flow.component.Text; import com.vaadin.flow.component.applayout.AppLayout; diff --git a/src/main/java/com/primefactorsolutions/views/TimeOffNewRequestView.java b/src/main/java/com/primefactorsolutions/views/timeoff/TimeOffNewRequestView.java similarity index 97% rename from src/main/java/com/primefactorsolutions/views/TimeOffNewRequestView.java rename to src/main/java/com/primefactorsolutions/views/timeoff/TimeOffNewRequestView.java index d8537e1..c73e9b5 100644 --- a/src/main/java/com/primefactorsolutions/views/TimeOffNewRequestView.java +++ b/src/main/java/com/primefactorsolutions/views/timeoff/TimeOffNewRequestView.java @@ -1,9 +1,10 @@ -package com.primefactorsolutions.views; +package com.primefactorsolutions.views.timeoff; import com.primefactorsolutions.model.*; import com.primefactorsolutions.service.EmployeeService; import com.primefactorsolutions.service.TimeOffRequestService; import com.primefactorsolutions.service.VacationService; +import com.primefactorsolutions.views.MainLayout; import com.vaadin.flow.component.button.Button; import com.vaadin.flow.component.combobox.ComboBox; import com.vaadin.flow.component.datepicker.DatePicker; diff --git a/src/main/java/com/primefactorsolutions/views/TimeOffPendingRequestsListView.java b/src/main/java/com/primefactorsolutions/views/timeoff/TimeOffPendingRequestsListView.java similarity index 96% rename from src/main/java/com/primefactorsolutions/views/TimeOffPendingRequestsListView.java rename to src/main/java/com/primefactorsolutions/views/timeoff/TimeOffPendingRequestsListView.java index a1e96ba..ca0ab40 100644 --- a/src/main/java/com/primefactorsolutions/views/TimeOffPendingRequestsListView.java +++ b/src/main/java/com/primefactorsolutions/views/timeoff/TimeOffPendingRequestsListView.java @@ -1,9 +1,11 @@ -package com.primefactorsolutions.views; +package com.primefactorsolutions.views.timeoff; import com.primefactorsolutions.model.*; import com.primefactorsolutions.service.EmployeeService; import com.primefactorsolutions.service.TeamService; import com.primefactorsolutions.service.TimeOffRequestService; +import com.primefactorsolutions.views.BaseView; +import com.primefactorsolutions.views.MainLayout; import com.primefactorsolutions.views.util.MenuBarUtils; import com.vaadin.flow.component.ClickEvent; import com.vaadin.flow.component.Component; diff --git a/src/main/java/com/primefactorsolutions/views/TimeOffRequestListView.java b/src/main/java/com/primefactorsolutions/views/timeoff/TimeOffRequestListView.java similarity index 99% rename from src/main/java/com/primefactorsolutions/views/TimeOffRequestListView.java rename to src/main/java/com/primefactorsolutions/views/timeoff/TimeOffRequestListView.java index dde3426..e68a599 100644 --- a/src/main/java/com/primefactorsolutions/views/TimeOffRequestListView.java +++ b/src/main/java/com/primefactorsolutions/views/timeoff/TimeOffRequestListView.java @@ -1,10 +1,12 @@ -package com.primefactorsolutions.views; +package com.primefactorsolutions.views.timeoff; import com.primefactorsolutions.model.*; import com.primefactorsolutions.service.EmployeeService; import com.primefactorsolutions.service.TeamService; import com.primefactorsolutions.service.TimeOffRequestService; import com.primefactorsolutions.service.VacationService; +import com.primefactorsolutions.views.BaseView; +import com.primefactorsolutions.views.MainLayout; import com.vaadin.flow.component.ClickEvent; import com.vaadin.flow.component.Component; import com.vaadin.flow.component.ComponentEventListener; diff --git a/src/main/java/com/primefactorsolutions/views/TimeOffRequestView.java b/src/main/java/com/primefactorsolutions/views/timeoff/TimeOffRequestView.java similarity index 95% rename from src/main/java/com/primefactorsolutions/views/TimeOffRequestView.java rename to src/main/java/com/primefactorsolutions/views/timeoff/TimeOffRequestView.java index 571d1b4..b42cd32 100644 --- a/src/main/java/com/primefactorsolutions/views/TimeOffRequestView.java +++ b/src/main/java/com/primefactorsolutions/views/timeoff/TimeOffRequestView.java @@ -1,9 +1,10 @@ -package com.primefactorsolutions.views; +package com.primefactorsolutions.views.timeoff; import com.primefactorsolutions.model.*; import com.primefactorsolutions.service.EmployeeService; import com.primefactorsolutions.service.TeamService; import com.primefactorsolutions.service.TimeOffRequestService; +import com.primefactorsolutions.views.MainLayout; import com.vaadin.flow.component.Component; import com.vaadin.flow.component.button.Button; import com.vaadin.flow.component.combobox.ComboBox; diff --git a/src/main/java/com/primefactorsolutions/views/TimeOffRequestsByEmployeeView.java b/src/main/java/com/primefactorsolutions/views/timeoff/TimeOffRequestsByEmployeeView.java similarity index 96% rename from src/main/java/com/primefactorsolutions/views/TimeOffRequestsByEmployeeView.java rename to src/main/java/com/primefactorsolutions/views/timeoff/TimeOffRequestsByEmployeeView.java index f6c21b2..1e53428 100644 --- a/src/main/java/com/primefactorsolutions/views/TimeOffRequestsByEmployeeView.java +++ b/src/main/java/com/primefactorsolutions/views/timeoff/TimeOffRequestsByEmployeeView.java @@ -1,9 +1,11 @@ -package com.primefactorsolutions.views; +package com.primefactorsolutions.views.timeoff; import com.primefactorsolutions.model.*; import com.primefactorsolutions.service.EmployeeService; import com.primefactorsolutions.service.TimeOffRequestService; import com.primefactorsolutions.service.VacationService; +import com.primefactorsolutions.views.BaseView; +import com.primefactorsolutions.views.MainLayout; import com.vaadin.flow.component.ClickEvent; import com.vaadin.flow.component.Component; import com.vaadin.flow.component.ComponentEventListener; @@ -651,10 +653,11 @@ public class TimeOffRequestsByEmployeeView extends BaseView implements HasUrlPar } private void setViewTitle(final String employeeName, final String employeeTeam, final LocalDate dateOfExit) { - addComponentAsFirst(new H3("Nombre del empleado: " + employeeName)); - addComponentAtIndex(1, new H3("Equipo: " + employeeTeam)); + getCurrentPageLayout().addComponentAsFirst(new H3("Nombre del empleado: " + employeeName)); + getCurrentPageLayout().addComponentAtIndex(1, new H3("Equipo: " + employeeTeam)); + if (dateOfExit != null) { - addComponentAtIndex( + getCurrentPageLayout().addComponentAtIndex( 2, new H3("Descontado a cero en fecha " + dateOfExit + " por pago de finiquito incluidas duodecima.")); diff --git a/src/main/java/com/primefactorsolutions/views/TimesheetRecordView.java b/src/main/java/com/primefactorsolutions/views/timesheet/TimesheetEntryView.java similarity index 64% rename from src/main/java/com/primefactorsolutions/views/TimesheetRecordView.java rename to src/main/java/com/primefactorsolutions/views/timesheet/TimesheetEntryView.java index 6b17a4e..be850f0 100644 --- a/src/main/java/com/primefactorsolutions/views/TimesheetRecordView.java +++ b/src/main/java/com/primefactorsolutions/views/timesheet/TimesheetEntryView.java @@ -1,13 +1,13 @@ -package com.primefactorsolutions.views; +package com.primefactorsolutions.views.timesheet; import com.primefactorsolutions.model.Employee; -import com.primefactorsolutions.model.HoursWorked; +import com.primefactorsolutions.model.TimesheetEntry; import com.primefactorsolutions.model.Team; import com.primefactorsolutions.service.EmployeeService; -import com.primefactorsolutions.service.HoursWorkedService; +import com.primefactorsolutions.service.TimesheetService; import com.primefactorsolutions.service.TeamService; +import com.primefactorsolutions.views.MainLayout; import com.vaadin.flow.component.Component; -import com.vaadin.flow.component.notification.Notification; import com.vaadin.flow.component.textfield.NumberField; import com.vaadin.flow.component.textfield.TextField; import com.vaadin.flow.component.button.Button; @@ -32,30 +32,32 @@ import java.util.stream.Collectors; @Scope("prototype") @PageTitle("Horas Trabajadas") @Route(value = "/timesheet/:hours-workedId?/:action?", layout = MainLayout.class) -public class TimesheetRecordView extends BeanValidationForm implements HasUrlParameter { +public class TimesheetEntryView extends BeanValidationForm implements HasUrlParameter { private final ComboBox team = new ComboBox<>("Equipo"); private ComboBox employee; - private final ComboBox task = new ComboBox<>("Tarea Específica"); - private final TextField activity = new TextField("Actividad"); + private final ComboBox task = new ComboBox<>("Tarea"); + private final TextField details = new TextField("Detalle"); private final VDatePicker date = new VDatePicker("Fecha"); - private final NumberField hours = new NumberField("Horas Tarea Específica"); + private final NumberField hours = new NumberField("Horas"); private Button saveButton; - private final HoursWorkedService hoursWorkedService; + private final TimesheetService timesheetService; private final EmployeeService employeeService; private final TeamService teamService; - private HoursWorked hoursWorked; + private TimesheetEntry timesheetEntry; - public TimesheetRecordView(final HoursWorkedService hoursWorkedService, - final EmployeeService employeeService, - final TeamService teamService) { - super(HoursWorked.class); - this.hoursWorkedService = hoursWorkedService; + public TimesheetEntryView(final TimesheetService timesheetService, + final EmployeeService employeeService, + final TeamService teamService) { + super(TimesheetEntry.class); + this.timesheetService = timesheetService; this.employeeService = employeeService; this.teamService = teamService; + task.setRequired(true); + initializeDateField(); initializeTeamField(); initializeEmployeeField(); @@ -68,11 +70,11 @@ public class TimesheetRecordView extends BeanValidationForm impleme final String s = params.get("hours-workedId").orElse(null); if ("new".equals(action) || s == null) { - setEntityWithEnabledSave(new HoursWorked()); + setEntityWithEnabledSave(new TimesheetEntry()); } else { final UUID hoursWorkedId = UUID.fromString(s); - hoursWorked = hoursWorkedService.getHoursWorked(hoursWorkedId); - setEntityWithEnabledSave(hoursWorked); + timesheetEntry = timesheetService.getHoursWorked(hoursWorkedId); + setEntityWithEnabledSave(timesheetEntry); if ("edit".equals(action) && !s.isEmpty()) { saveButton.setVisible(true); @@ -88,8 +90,8 @@ public class TimesheetRecordView extends BeanValidationForm impleme date, team, employee, - activity, task, + details, hours, createCloseButton() ); @@ -154,8 +156,7 @@ public class TimesheetRecordView extends BeanValidationForm impleme } private String getEmployeeFullName(final Employee employee) { - return "TODOS".equals(employee.getFirstName()) - ? "TODOS" : employee.getFirstName() + " " + employee.getLastName(); + return employee.getFirstName() + " " + employee.getLastName(); } private void initializeDateField() { @@ -170,47 +171,29 @@ public class TimesheetRecordView extends BeanValidationForm impleme private void saveHoursWorked() { if (isFormValid()) { - HoursWorked hoursWorked = getEntity(); - String actividad = this.activity.getValue(); - String tareaEspecifica = task.getValue(); + final TimesheetEntry timesheetEntry = getEntity(); + final String details = this.details.getValue(); + final String task = this.task.getValue(); - if (actividad != null && !actividad.isEmpty() && tareaEspecifica != null) { - Notification.show("Solo puedes elegir una: actividad del proyecto o tarea de la empresa.", - 3000, Notification.Position.BOTTOM_CENTER); - return; - } + timesheetEntry.setDetails(details); + timesheetEntry.setTask(task); - if (actividad != null && !actividad.isEmpty()) { - hoursWorked.setActivity(actividad); - } else if (tareaEspecifica != null) { - hoursWorked.setTask(tareaEspecifica); - } else { - Notification.show("Por favor, selecciona una actividad o tarea para guardar.", - 3000, Notification.Position.BOTTOM_CENTER); - return; - } - - setFieldValues(hoursWorked); - hoursWorkedService.save(hoursWorked); + setFieldValues(timesheetEntry); + timesheetService.save(timesheetEntry); closeForm(); } } - private void setFieldValues(final HoursWorked hoursWorked) { - hoursWorked.setDate(date.getValue()); - hoursWorked.setTeam(team.getValue()); - hoursWorked.setEmployee(employee.getValue()); - hoursWorked.setActivity(activity.getValue()); - hoursWorked.setHours(hours.getValue()); + private void setFieldValues(final TimesheetEntry timesheetEntry) { + timesheetEntry.setDate(date.getValue()); + timesheetEntry.setTeam(team.getValue()); + timesheetEntry.setEmployee(employee.getValue()); + timesheetEntry.setDetails(details.getValue()); + timesheetEntry.setHours(hours.getValue()); } private void closeForm() { - if (hoursWorked != null) { - getUI().ifPresent(ui -> ui.navigate(TimesheetRecordView.class, - hoursWorked.getEmployee().getId().toString() + "/view")); - } else { - getUI().ifPresent(ui -> ui.navigate(TimesheetListView.class)); - } + getUI().ifPresent(ui -> ui.navigate(TimesheetListView.class)); } private boolean isFormValid() { diff --git a/src/main/java/com/primefactorsolutions/views/TimesheetListView.java b/src/main/java/com/primefactorsolutions/views/timesheet/TimesheetListView.java similarity index 60% rename from src/main/java/com/primefactorsolutions/views/TimesheetListView.java rename to src/main/java/com/primefactorsolutions/views/timesheet/TimesheetListView.java index b5ab724..b8c237c 100644 --- a/src/main/java/com/primefactorsolutions/views/TimesheetListView.java +++ b/src/main/java/com/primefactorsolutions/views/timesheet/TimesheetListView.java @@ -1,11 +1,13 @@ -package com.primefactorsolutions.views; +package com.primefactorsolutions.views.timesheet; import com.primefactorsolutions.model.Employee; -import com.primefactorsolutions.model.HoursWorked; +import com.primefactorsolutions.model.TimesheetEntry; import com.primefactorsolutions.model.Team; import com.primefactorsolutions.service.EmployeeService; -import com.primefactorsolutions.service.HoursWorkedService; +import com.primefactorsolutions.service.TimesheetService; import com.primefactorsolutions.service.TeamService; +import com.primefactorsolutions.views.BaseView; +import com.primefactorsolutions.views.MainLayout; import com.primefactorsolutions.views.util.MenuBarUtils; import com.vaadin.flow.component.ClickEvent; import com.vaadin.flow.component.Component; @@ -16,7 +18,6 @@ import com.vaadin.flow.component.contextmenu.MenuItem; import com.vaadin.flow.component.icon.VaadinIcon; import com.vaadin.flow.component.menubar.MenuBar; import com.vaadin.flow.component.menubar.MenuBarVariant; -import com.vaadin.flow.component.notification.Notification; import com.vaadin.flow.component.orderedlayout.HorizontalLayout; import com.vaadin.flow.function.ValueProvider; import com.vaadin.flow.router.PageTitle; @@ -39,19 +40,19 @@ import static com.primefactorsolutions.views.Constants.PAGE_SIZE; @Route(value = "/timesheet/records", layout = MainLayout.class) public class TimesheetListView extends BaseView { - private final HoursWorkedService hoursWorkedService; + private final TimesheetService timesheetService; private final EmployeeService employeeService; private final TeamService teamService; - private final PagingGrid hoursWorkedGrid = new PagingGrid<>(); + private final PagingGrid timesheetPagingGrid = new PagingGrid<>(); private ComboBox employeeFilter; private ComboBox teamFilter; public TimesheetListView(final AuthenticationContext authenticationContext, - final HoursWorkedService hoursWorkedService, + final TimesheetService timesheetService, final EmployeeService employeeService, final TeamService teamService) { super(authenticationContext); - this.hoursWorkedService = hoursWorkedService; + this.timesheetService = timesheetService; this.employeeService = employeeService; this.teamService = teamService; @@ -61,51 +62,42 @@ public class TimesheetListView extends BaseView { private void refreshGridListHoursWorked(final Employee employee, final Team team) { - hoursWorkedGrid.setPagingDataProvider((page, pageSize) -> { - int start = (int) (page * hoursWorkedGrid.getPageSize()); - List hoursWorkedList = fetchFilteredHoursWorked(start, pageSize, employee, team); - - double totalHours = hoursWorkedList.stream() - .mapToDouble(HoursWorked::getHours) - .sum(); - - Notification.show("Total de horas trabajadas: " + totalHours, - 3000, Notification.Position.BOTTOM_CENTER); - - return hoursWorkedList; + timesheetPagingGrid.setPagingDataProvider((page, pageSize) -> { + final int start = (int) (page * timesheetPagingGrid.getPageSize()); + return fetchFilteredHoursWorked(start, pageSize, employee, team); }); - hoursWorkedGrid.getDataProvider().refreshAll(); + timesheetPagingGrid.getDataProvider().refreshAll(); } - private List fetchFilteredHoursWorked(final int start, - final int pageSize, - final Employee employee, - final Team team) { - List filteredHoursWorked = hoursWorkedService.findAll(); + private List fetchFilteredHoursWorked(final int start, + final int pageSize, + final Employee employee, + final Team team) { + List filteredTimesheetEntry = timesheetService.findAll(); if (employee != null) { - filteredHoursWorked = filteredHoursWorked.stream() + filteredTimesheetEntry = filteredTimesheetEntry.stream() .filter(hw -> hw.getEmployee().getId().equals(employee.getId())) .collect(Collectors.toList()); } if (team != null) { - filteredHoursWorked = filteredHoursWorked.stream() + filteredTimesheetEntry = filteredTimesheetEntry.stream() .filter(hw -> hw.getEmployee().getTeam() != null && hw.getEmployee().getTeam().getId().equals(team.getId())) .collect(Collectors.toList()); } - int end = Math.min(start + pageSize, filteredHoursWorked.size()); + int end = Math.min(start + pageSize, filteredTimesheetEntry.size()); - return filteredHoursWorked.subList(start, end); + return filteredTimesheetEntry.subList(start, end); } private void initializeView() { getCurrentPageLayout().add(createAddHoursWorked()); setupFilters(); setupListHoursWorkedGrid(); - getCurrentPageLayout().add(hoursWorkedGrid); + getCurrentPageLayout().add(timesheetPagingGrid); } private void setupFilters() { @@ -117,23 +109,23 @@ public class TimesheetListView extends BaseView { } private void setupListHoursWorkedGrid() { - hoursWorkedGrid.addColumn(hw -> hw.getDate() != null ? hw.getDate().toString() : "") + timesheetPagingGrid.addColumn(hw -> hw.getDate() != null ? hw.getDate().toString() : "") .setHeader("Fecha") .setSortable(true); - hoursWorkedGrid.addColumn(HoursWorked::getWeekNumber) + timesheetPagingGrid.addColumn(TimesheetEntry::getWeekNumber) .setHeader("Semana") .setSortable(true); - hoursWorkedGrid.addColumn(hw -> hw.getEmployee().getFirstName() + " " + hw.getEmployee().getLastName()) + timesheetPagingGrid.addColumn(hw -> hw.getEmployee().getFirstName() + " " + hw.getEmployee().getLastName()) .setHeader("Empleado"); - hoursWorkedGrid.addColumn(hw -> hw.getEmployee().getTeam() != null ? hw.getEmployee().getTeam() + timesheetPagingGrid.addColumn(hw -> hw.getEmployee().getTeam() != null ? hw.getEmployee().getTeam() .getName() : "Sin asignar") .setHeader("Equipo"); - hoursWorkedGrid.addColumn(hw -> { - String actividad = hw.getActivity() != null ? hw.getActivity() : "Sin Actividad"; - String tareaEspecifica = hw.getTask() != null ? hw.getTask() : ""; - return !tareaEspecifica.isEmpty() ? tareaEspecifica : actividad; - }).setHeader("Actividad"); - hoursWorkedGrid.addColumn(hw -> { + timesheetPagingGrid.addColumn(hw -> { + String details = hw.getDetails() != null ? hw.getDetails() : "Sin Detalle"; + String task = hw.getTask() != null ? hw.getTask() : ""; + return !task.isEmpty() ? task : details; + }).setHeader("Details"); + timesheetPagingGrid.addColumn(hw -> { if (hw.getTask() != null && !hw.getTask().isEmpty()) { return calculateHoursPerTask(hw); } else { @@ -141,9 +133,9 @@ public class TimesheetListView extends BaseView { } }).setHeader("Total Horas").setSortable(true); - hoursWorkedGrid.addColumn(hw -> 40 - calculateTotal(hw)).setHeader("Horas Pendientes") + timesheetPagingGrid.addColumn(hw -> 40 - calculateTotal(hw)).setHeader("Horas Pendientes") .setSortable(true); - hoursWorkedGrid.addComponentColumn((ValueProvider) hoursWorked -> { + timesheetPagingGrid.addComponentColumn((ValueProvider) hoursWorked -> { final MenuBar menuBar = new MenuBar(); menuBar.addThemeVariants(MenuBarVariant.LUMO_TERTIARY_INLINE); final MenuItem viewItem = MenuBarUtils.createIconItem(menuBar, VaadinIcon.EYE, "Ver"); @@ -153,33 +145,33 @@ public class TimesheetListView extends BaseView { return menuBar; }); - hoursWorkedGrid.setPaginationBarMode(PagingGrid.PaginationBarMode.BOTTOM); - hoursWorkedGrid.setPageSize(PAGE_SIZE); + timesheetPagingGrid.setPaginationBarMode(PagingGrid.PaginationBarMode.BOTTOM); + timesheetPagingGrid.setPageSize(PAGE_SIZE); } - private double calculateHoursPerTask(final HoursWorked hoursWorked) { - final List tasks = hoursWorkedService.findListHoursWorkedEmployee( - hoursWorked.getEmployee().getId(), hoursWorked.getWeekNumber()); + private double calculateHoursPerTask(final TimesheetEntry timesheetEntry) { + final List tasks = timesheetService.findListHoursWorkedEmployee( + timesheetEntry.getEmployee().getId(), timesheetEntry.getWeekNumber()); return tasks.stream() - .filter(hw -> Objects.equals(hw.getTask(), hoursWorked.getTask())) - .mapToDouble(HoursWorked::getHours) + .filter(hw -> Objects.equals(hw.getTask(), timesheetEntry.getTask())) + .mapToDouble(TimesheetEntry::getHours) .sum(); } private void navigateToHoursWorkedView(final UUID idRecord) { - getUI().ifPresent(ui -> ui.navigate(TimesheetRecordView.class, idRecord.toString() + "/view")); + getUI().ifPresent(ui -> ui.navigate(TimesheetEntryView.class, idRecord.toString() + "/view")); } - private double calculateTotal(final HoursWorked hoursWorked) { - final List listHoursworkedEmployee = hoursWorkedService.findListHoursWorkedEmployee( - hoursWorked.getEmployee().getId(), hoursWorked.getWeekNumber()); + private double calculateTotal(final TimesheetEntry timesheetEntry) { + final List listHoursworkedEmployee = timesheetService.findListHoursWorkedEmployee( + timesheetEntry.getEmployee().getId(), timesheetEntry.getWeekNumber()); return calculateTotalUtilized(listHoursworkedEmployee); } - private double calculateTotalUtilized(final List employeeRequests) { + private double calculateTotalUtilized(final List employeeRequests) { return employeeRequests.stream() .filter(Objects::nonNull) - .mapToDouble(HoursWorked::getHours) + .mapToDouble(TimesheetEntry::getHours) .sum(); } @@ -195,7 +187,7 @@ public class TimesheetListView extends BaseView { } private void navigateToHours() { - getUI().ifPresent(ui -> ui.navigate(TimesheetRecordView.class, "new")); + getUI().ifPresent(ui -> ui.navigate(TimesheetEntryView.class, "new")); } private ComboBox createEmployeeFilter() { @@ -216,8 +208,7 @@ public class TimesheetListView extends BaseView { } private String getEmployeeFullName(final Employee employee) { - return "TODOS".equals(employee.getFirstName()) - ? "TODOS" : employee.getFirstName() + " " + employee.getLastName(); + return employee.getFirstName() + " " + employee.getLastName(); } private ComboBox createTeamFilter() { @@ -237,6 +228,6 @@ public class TimesheetListView extends BaseView { } private String getTeamLabel(final Team team) { - return team != null && !"TODOS".equals(team.getName()) ? team.getName() : "TODOS"; + return team.getName(); } } diff --git a/src/main/java/com/primefactorsolutions/views/TimesheetReportView.java b/src/main/java/com/primefactorsolutions/views/timesheet/TimesheetReportView.java similarity index 88% rename from src/main/java/com/primefactorsolutions/views/TimesheetReportView.java rename to src/main/java/com/primefactorsolutions/views/timesheet/TimesheetReportView.java index bdb3684..d589b7e 100644 --- a/src/main/java/com/primefactorsolutions/views/TimesheetReportView.java +++ b/src/main/java/com/primefactorsolutions/views/timesheet/TimesheetReportView.java @@ -1,10 +1,12 @@ -package com.primefactorsolutions.views; +package com.primefactorsolutions.views.timesheet; -import com.primefactorsolutions.model.HoursWorked; +import com.primefactorsolutions.model.TimesheetEntry; import com.primefactorsolutions.model.Team; -import com.primefactorsolutions.service.HoursWorkedService; +import com.primefactorsolutions.service.TimesheetService; import com.primefactorsolutions.service.ReportService; import com.primefactorsolutions.service.TeamService; +import com.primefactorsolutions.views.BaseView; +import com.primefactorsolutions.views.MainLayout; import com.vaadin.flow.component.button.Button; import com.vaadin.flow.component.combobox.ComboBox; import com.vaadin.flow.component.grid.Grid; @@ -39,7 +41,7 @@ import java.util.stream.Collectors; public class TimesheetReportView extends BaseView { private final EmployeeService employeeService; - private final HoursWorkedService hoursWorkedService; + private final TimesheetService timesheetService; private final ReportService reportService; private final TeamService teamService; private final ComboBox equipoComboBox = new ComboBox<>("Seleccionar Equipo"); @@ -52,27 +54,24 @@ public class TimesheetReportView extends BaseView { @Autowired public TimesheetReportView(final AuthenticationContext authenticationContext, - final HoursWorkedService hoursWorkedService, + final TimesheetService timesheetService, final ReportService reportService, final TeamService teamService, final EmployeeService employeeService) { super(authenticationContext); - this.hoursWorkedService = hoursWorkedService; + this.timesheetService = timesheetService; this.reportService = reportService; this.teamService = teamService; this.employeeService = employeeService; - H2 title = new H2("Reporte de Horas Trabajadas"); + final H2 title = new H2("Reporte de Horas Trabajadas"); getCurrentPageLayout().add(title); final List teams = teamService.findAllTeams(); equipoComboBox.setItems(teams); equipoComboBox.setItemLabelGenerator(Team::getName); + initializeWeekComboBox(); - // Configurar el ComboBox de semanas - initializeSemanaComboBox(); - - // 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"); @@ -81,7 +80,6 @@ public class TimesheetReportView extends BaseView { final Button reportButton = new Button("Generar Reporte de Horas Trabajadas", event -> generateHoursWorkedReport()); getCurrentPageLayout().add(reportButton); - final HorizontalLayout filtersLayout = new HorizontalLayout(equipoComboBox, semanaComboBox); getCurrentPageLayout().add(filtersLayout); @@ -96,15 +94,15 @@ public class TimesheetReportView extends BaseView { getCurrentPageLayout().add(grid); } - private void initializeSemanaComboBox() { + private void initializeWeekComboBox() { int year = LocalDate.now().getYear(); - final LocalDate startOfYear = LocalDate.of(year, 1, 5); // Suponemos que la semana comienza el 5 de enero. + final LocalDate startOfYear = LocalDate.of(year, 1, 5); final List weeks = startOfYear.datesUntil(LocalDate.of(year + 1, 1, 1), java.time.Period.ofWeeks(1)) .map(date -> { - int weekNumber = date.get(WeekFields.of(DayOfWeek.MONDAY, 1) - .weekOfWeekBasedYear()); - LocalDate endOfWeek = date.plusDays(6); + final int weekNumber = date.get( + WeekFields.of(DayOfWeek.MONDAY, 1).weekOfWeekBasedYear()); + final LocalDate endOfWeek = date.plusDays(6); return String.format("Semana %d: %s - %s", weekNumber, @@ -135,19 +133,19 @@ public class TimesheetReportView extends BaseView { .weekOfWeekBasedYear(), weekNumber); updateHeaderLayout(selectedTeam, selectedDate); - final List hoursWorkedList = hoursWorkedService.findAll().stream() + final List timesheetEntryList = timesheetService.findAll().stream() .filter(hw -> hw.getEmployee().getTeam().getId().equals(selectedTeam .getId()) && hw.getWeekNumber() == weekNumber) .toList(); - if (hoursWorkedList.isEmpty()) { + if (timesheetEntryList.isEmpty()) { Notification.show("No hay horas trabajadas disponibles para generar el reporte.", 3000, Notification.Position.MIDDLE); return; } - List> data = hoursWorkedList.stream() + List> data = timesheetEntryList.stream() .map(hoursWorked -> { Map map = new HashMap<>(); map.put("ID", hoursWorked.getId().toString()); diff --git a/src/main/resources/data.sql b/src/main/resources/data.sql index 600d7ac..9e5a024 100644 --- a/src/main/resources/data.sql +++ b/src/main/resources/data.sql @@ -91,5 +91,5 @@ values ('12ec8b74-983d-4a17-b67e-134f45ae904c', 1, '5c1a7b82-832d-4f24-8377-54b7 insert into time_off_request (id, version, employee_id, category, state, available_days, expiration, start_date, end_date, days_to_be_take, days_balance) values ('89bc4b2a-943f-487c-a9f3-bacf78145e67', 1, 'cba3efb7-32bc-44be-9fdc-fc5e4f211254', 'LUNES_CARNAVAL', 'APROBADO', 1, '2024-02-12', '2024-02-12', '2024-02-12', 1, 0); -insert into hours_worked (id, version, task, activity, date, hours, employee_id, team_id) +insert into timesheet_entry (id, version, task, details, date, hours, employee_id, team_id) values ('389389ce-7b2e-4f39-aa06-2a251a2b35ea', 0, 'coding', 'meet', '2024-11-27', 4, '5c6f11fe-c341-4be7-a9a6-bba0081ad7c6', 'b0e8f394-78c1-4d8a-9c57-dc6e8b36a5fa'); \ No newline at end of file