Vacaciones #79

Merged
jesus.pelaez merged 36 commits from Vacaciones into En-desarrollo 2024-11-24 01:19:42 +00:00
6 changed files with 21 additions and 16 deletions
Showing only changes of commit 03146b1b9b - Show all commits

View File

@ -34,13 +34,13 @@ public class HoursWorked extends BaseEntity {
private double horaspendientes; private double horaspendientes;
private double totalHours; private double totalHours;
public static double calculateTotalHours(List<HoursWorked> activities) { public static double calculateTotalHours(final List<HoursWorked> activities) {
return activities.stream() return activities.stream()
.mapToDouble(activity -> activity.hours + activity.horasTareasEspecificas) .mapToDouble(activity -> activity.hours + activity.horasTareasEspecificas)
.sum(); .sum();
} }
public static double calculatePendingHours(List<HoursWorked> activities) { public static double calculatePendingHours(final List<HoursWorked> activities) {
double totalHoursWorked = calculateTotalHours(activities); double totalHoursWorked = calculateTotalHours(activities);
return Math.max(0, 40 - totalHoursWorked); return Math.max(0, 40 - totalHoursWorked);
} }

View File

@ -11,7 +11,7 @@ public interface EmployeeRepository extends JpaRepository<Employee, UUID> {
Optional<Employee> findByUsername(String username); Optional<Employee> findByUsername(String username);
Optional<Employee> findByPersonalEmail(String personalEmail); Optional<Employee> findByPersonalEmail(String personalEmail);
Optional<Employee> findByTeamIdAndLeadManagerTrue(UUID teamId); Optional<Employee> findByTeamIdAndLeadManager(UUID teamId);
List<Employee> findByTeamName(String teamName); List<Employee> findByTeamName(String teamName);
} }

View File

@ -50,7 +50,7 @@ public class EmployeeService {
public String getTeamLeadName(final UUID teamId) { public String getTeamLeadName(final UUID teamId) {
// Encuentra al empleado con el rol de lead_manager en el equipo especificado // Encuentra al empleado con el rol de lead_manager en el equipo especificado
Optional<Employee> leadManager = employeeRepository.findByTeamIdAndLeadManagerTrue(teamId); Optional<Employee> leadManager = employeeRepository.findByTeamIdAndLeadManager(teamId);
return leadManager.map(employee -> employee.getFirstName() + " " + employee.getLastName()) return leadManager.map(employee -> employee.getFirstName() + " " + employee.getLastName())
.orElse("No asignado"); .orElse("No asignado");

View File

@ -22,7 +22,7 @@ public class HoursWorkedService {
return hoursWorkedRepository.findAll(); return hoursWorkedRepository.findAll();
} }
public double getTotalHoursWorkedByEmployeeForWeek(UUID employeeId, int weekNumber) { public double getTotalHoursWorkedByEmployeeForWeek(final UUID employeeId, final int weekNumber) {
List<HoursWorked> hoursWorkedList = hoursWorkedRepository.findByWeekNumber(weekNumber); List<HoursWorked> hoursWorkedList = hoursWorkedRepository.findByWeekNumber(weekNumber);
return hoursWorkedList.stream() return hoursWorkedList.stream()
.filter(hw -> hw.getEmployee().getId().equals(employeeId)) .filter(hw -> hw.getEmployee().getId().equals(employeeId))
@ -44,12 +44,12 @@ public class HoursWorkedService {
return hoursWorkedRepository.save(hoursWorked); return hoursWorkedRepository.save(hoursWorked);
} }
public double getTotalHoursForEmployee(UUID employeeId, int weekNumber) { public double getTotalHoursForEmployee(final UUID employeeId, final int weekNumber) {
List<HoursWorked> activities = hoursWorkedRepository.findByEmployeeIdAndWeekNumber(employeeId, weekNumber); List<HoursWorked> activities = hoursWorkedRepository.findByEmployeeIdAndWeekNumber(employeeId, weekNumber);
return HoursWorked.calculateTotalHours(activities); return HoursWorked.calculateTotalHours(activities);
} }
public double getPendingHoursForEmployee(UUID employeeId, int weekNumber) { public double getPendingHoursForEmployee(final UUID employeeId, final int weekNumber) {
List<HoursWorked> activities = hoursWorkedRepository.findByEmployeeIdAndWeekNumber(employeeId, weekNumber); List<HoursWorked> activities = hoursWorkedRepository.findByEmployeeIdAndWeekNumber(employeeId, weekNumber);
return HoursWorked.calculatePendingHours(activities); return HoursWorked.calculatePendingHours(activities);
} }

View File

@ -172,5 +172,6 @@ public class ReportService {
cfg.setFallbackOnNullLoopVariable(false); cfg.setFallbackOnNullLoopVariable(false);
cfg.setSQLDateAndTimeTimeZone(TimeZone.getDefault()); cfg.setSQLDateAndTimeTimeZone(TimeZone.getDefault());
return cfg;} return cfg;
}
} }

View File

@ -15,7 +15,6 @@ 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;
import org.joda.time.Hours;
import org.springframework.context.annotation.Scope; import org.springframework.context.annotation.Scope;
import org.vaadin.firitin.components.grid.PagingGrid; import org.vaadin.firitin.components.grid.PagingGrid;
@ -63,7 +62,8 @@ public class HoursWorkedListView extends Main {
.mapToDouble(HoursWorked::getTotalHours) .mapToDouble(HoursWorked::getTotalHours)
.sum(); .sum();
Notification.show("Total de horas trabajadas: " + totalHours, 3000, Notification.Position.BOTTOM_CENTER); Notification.show("Total de horas trabajadas: " + totalHours,
3000, Notification.Position.BOTTOM_CENTER);
return hoursWorkedList; return hoursWorkedList;
}); });
@ -84,7 +84,8 @@ public class HoursWorkedListView extends Main {
if (team != null && !"TODOS".equals(team.getName())) { if (team != null && !"TODOS".equals(team.getName())) {
filteredHoursWorked = filteredHoursWorked.stream() filteredHoursWorked = filteredHoursWorked.stream()
.filter(hw -> hw.getEmployee().getTeam() != null && hw.getEmployee().getTeam().getId().equals(team.getId())) .filter(hw -> hw.getEmployee().getTeam() != null
&& hw.getEmployee().getTeam().getId().equals(team.getId()))
.collect(Collectors.toList()); .collect(Collectors.toList());
} }
@ -94,7 +95,8 @@ public class HoursWorkedListView extends Main {
int currentWeek = date.get(IsoFields.WEEK_OF_WEEK_BASED_YEAR); int currentWeek = date.get(IsoFields.WEEK_OF_WEEK_BASED_YEAR);
double totalWorkedInSameWeek = filteredHoursWorked.stream() double totalWorkedInSameWeek = filteredHoursWorked.stream()
.filter(hw -> hw.getEmployee().getId().equals(employee.getId()) && .filter(hw -> hw.getEmployee().getId().equals(employee.getId())
&&
hw.getDate().get(IsoFields.WEEK_OF_WEEK_BASED_YEAR) == currentWeek) hw.getDate().get(IsoFields.WEEK_OF_WEEK_BASED_YEAR) == currentWeek)
.mapToDouble(HoursWorked::getHours) .mapToDouble(HoursWorked::getHours)
.sum(); .sum();
@ -130,11 +132,13 @@ public class HoursWorkedListView extends Main {
.setSortable(true); .setSortable(true);
hoursWorkedGrid.addColumn(hw -> hw.getEmployee().getFirstName() + " " + hw.getEmployee().getLastName()) hoursWorkedGrid.addColumn(hw -> hw.getEmployee().getFirstName() + " " + hw.getEmployee().getLastName())
.setHeader("Empleado"); .setHeader("Empleado");
hoursWorkedGrid.addColumn(hw -> hw.getEmployee().getTeam() != null ? hw.getEmployee().getTeam().getName() : "Sin asignar") hoursWorkedGrid.addColumn(hw -> hw.getEmployee().getTeam() != null ? hw.getEmployee().getTeam()
.getName() : "Sin asignar")
.setHeader("Equipo"); .setHeader("Equipo");
hoursWorkedGrid.addColumn(HoursWorked::getActividad).setHeader("Actividad"); hoursWorkedGrid.addColumn(HoursWorked::getActividad).setHeader("Actividad");
hoursWorkedGrid.addColumn(hw -> hw.getHours()).setHeader("Total Horas").setSortable(true); hoursWorkedGrid.addColumn(hw -> hw.getHours()).setHeader("Total Horas").setSortable(true);
hoursWorkedGrid.addColumn(hw -> hw.getHoraspendientes() - calcularTotal(hw)).setHeader("Horas Pendientes").setSortable(true); hoursWorkedGrid.addColumn(hw -> hw.getHoraspendientes() - calcularTotal(hw)).setHeader("Horas Pendientes")
.setSortable(true);
hoursWorkedGrid.setPaginationBarMode(PagingGrid.PaginationBarMode.BOTTOM); hoursWorkedGrid.setPaginationBarMode(PagingGrid.PaginationBarMode.BOTTOM);
hoursWorkedGrid.setPageSize(5); hoursWorkedGrid.setPageSize(5);
@ -146,7 +150,7 @@ public class HoursWorkedListView extends Main {
}); });
} }
private double calcularTotal(HoursWorked hoursWorked){ private double calcularTotal(final HoursWorked hoursWorked) {
List<HoursWorked> listHoursworkedemploye = hoursWorkedService.findListHoursWorkedEmployee( List<HoursWorked> listHoursworkedemploye = hoursWorkedService.findListHoursWorkedEmployee(
hoursWorked.getEmployee().getId(), hoursWorked.getWeekNumber()); hoursWorked.getEmployee().getId(), hoursWorked.getWeekNumber());
return calculateTotalUtilized(listHoursworkedemploye); return calculateTotalUtilized(listHoursworkedemploye);