Formulario de registro de horas trabajadas mas el formulario

This commit is contained in:
Melina Gutierrez 2024-11-15 10:23:40 -04:00
parent 97d4bdf508
commit 6fbf6e8fa7
6 changed files with 47 additions and 4 deletions

View File

@ -7,6 +7,9 @@ import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor; import lombok.NoArgsConstructor;
import java.time.LocalDate; import java.time.LocalDate;
import java.time.temporal.WeekFields;
import java.util.List;
import java.util.Locale;
@Data @Data
@Entity @Entity
@ -31,6 +34,17 @@ public class HoursWorked extends BaseEntity {
private double horaspendientes; private double horaspendientes;
private double totalHours; private double totalHours;
public static double calculateTotalHours(List<HoursWorked> activities) {
return activities.stream()
.mapToDouble(activity -> activity.hours + activity.horasTareasEspecificas)
.sum();
}
public static double calculatePendingHours(List<HoursWorked> activities) {
double totalHoursWorked = calculateTotalHours(activities);
return Math.max(0, 40 - totalHoursWorked);
}
public Employee getEmployee() { public Employee getEmployee() {
return employee; return employee;
} }
@ -46,13 +60,16 @@ public class HoursWorked extends BaseEntity {
public void setWeekNumber(final int weekNumber) { public void setWeekNumber(final int weekNumber) {
this.weekNumber = weekNumber; this.weekNumber = weekNumber;
} }
public LocalDate getDate() { public LocalDate getDate() {
return date; return date;
} }
public void setDate(final LocalDate date) { public void setDate(final LocalDate date) {
this.date = date; this.date = date;
if (date != null) {
WeekFields weekFields = WeekFields.of(Locale.getDefault());
this.weekNumber = date.get(weekFields.weekOfWeekBasedYear());
}
} }
public String getActividad() { public String getActividad() {

View File

@ -44,6 +44,16 @@ public class HoursWorkedService {
return hoursWorkedRepository.save(hoursWorked); return hoursWorkedRepository.save(hoursWorked);
} }
public double getTotalHoursForEmployee(UUID employeeId, int weekNumber) {
List<HoursWorked> activities = hoursWorkedRepository.findByEmployeeIdAndWeekNumber(employeeId, weekNumber);
return HoursWorked.calculateTotalHours(activities);
}
public double getPendingHoursForEmployee(UUID employeeId, int weekNumber) {
List<HoursWorked> activities = hoursWorkedRepository.findByEmployeeIdAndWeekNumber(employeeId, weekNumber);
return HoursWorked.calculatePendingHours(activities);
}
public List<HoursWorked> findByWeekNumber(final int weekNumber) { public List<HoursWorked> findByWeekNumber(final int weekNumber) {
return hoursWorkedRepository.findByWeekNumber(weekNumber); return hoursWorkedRepository.findByWeekNumber(weekNumber);
} }

View File

@ -125,6 +125,9 @@ public class HoursWorkedListView extends Main {
hoursWorkedGrid.addColumn(hw -> hw.getDate() != null ? hw.getDate().toString() : "") hoursWorkedGrid.addColumn(hw -> hw.getDate() != null ? hw.getDate().toString() : "")
.setHeader("Fecha") .setHeader("Fecha")
.setSortable(true); .setSortable(true);
hoursWorkedGrid.addColumn(hw -> hw.getWeekNumber())
.setHeader("Semana")
.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")

View File

@ -21,6 +21,7 @@ import org.vaadin.firitin.form.BeanValidationForm;
import java.time.LocalDate; import java.time.LocalDate;
import java.time.YearMonth; import java.time.YearMonth;
import java.time.temporal.IsoFields;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.UUID; import java.util.UUID;
@ -175,7 +176,16 @@ public class HoursWorkedView extends BeanValidationForm<HoursWorked> implements
dateField.setMax(maxSelectableDate); dateField.setMax(maxSelectableDate);
dateField.setValue(today); dateField.setValue(today);
dateField.setLabel("Fecha"); dateField.addValueChangeListener(event -> {
LocalDate selectedDate = event.getValue();
if (selectedDate != null) {
int weekNumber = selectedDate.get(IsoFields.WEEK_OF_WEEK_BASED_YEAR);
Notification.show("Número de la semana: " + weekNumber, 3000, Notification.Position.BOTTOM_CENTER);
if (hoursWorked != null) {
hoursWorked.setWeekNumber(weekNumber);
}
}
});
} }
private void saveHoursWorked() { private void saveHoursWorked() {
@ -200,11 +210,12 @@ public class HoursWorkedView extends BeanValidationForm<HoursWorked> implements
Notification.show("Por favor, ingrese un número válido para las horas."); Notification.show("Por favor, ingrese un número válido para las horas.");
} }
if ("Otros".equals(tareasEspecificasDropdown.getValue())) { if ("Otros".equals(tareasEspecificasDropdown.getValue())) {
// Maneja horas y actividad específica adicional
hoursWorked.setTareasEspecificas(tareaEspecificaInput.getValue()); hoursWorked.setTareasEspecificas(tareaEspecificaInput.getValue());
try { try {
double horasEspecifica = Double.parseDouble(horasTareaEspecificaField.getValue()); double horasEspecifica = Double.parseDouble(horasTareaEspecificaField.getValue());
hoursWorked.setHorasTareasEspecificas(horasEspecifica); hoursWorked.setHorasTareasEspecificas(horasEspecifica);
double totalHoras = hoursWorked.getHours() + horasEspecifica;
hoursWorked.setTotalHours(totalHoras);
} catch (NumberFormatException e) { } catch (NumberFormatException e) {
Notification.show("Por favor, ingrese un número válido para las horas de la tarea específica."); Notification.show("Por favor, ingrese un número válido para las horas de la tarea específica.");
} }

View File

@ -142,7 +142,9 @@ public class ReporteView extends VerticalLayout {
.getId()) && hw.getWeekNumber() == weekNumber) .getId()) && hw.getWeekNumber() == weekNumber)
.collect(Collectors.toList()); .collect(Collectors.toList());
System.out.println(hoursWorkedList);
if (hoursWorkedList.isEmpty()) { if (hoursWorkedList.isEmpty()) {
Notification.show("No hay horas trabajadas disponibles para generar el reporte.", Notification.show("No hay horas trabajadas disponibles para generar el reporte.",
3000, Notification.Position.MIDDLE); 3000, Notification.Position.MIDDLE);
return; return;

View File

@ -92,4 +92,4 @@ insert into time_off_request (id, version, employee_id, category, state, availab
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); 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, ACTIVIDAD, DATE, HORAS_TAREAS_ESPECIFICAS, HORASPENDIENTES, HOURS, TAREAS_ESPECIFICAS, TOTAL_HOURS, WEEK_NUMBER, EMPLOYEE_ID, TEAM_ID) INSERT INTO HOURS_WORKED (ID, VERSION, ACTIVIDAD, DATE, HORAS_TAREAS_ESPECIFICAS, HORASPENDIENTES, HOURS, TAREAS_ESPECIFICAS, TOTAL_HOURS, WEEK_NUMBER, EMPLOYEE_ID, TEAM_ID)
VALUES ('6d6b3a71-9b11-4526-8335-b089627a8cd6', 0, 'Scrum Meeting', '2024-11-15', 0.0, 0.0, 2.0, NULL, 0.0, 0, '5c6f11fe-c341-4be7-a9a6-bba0081ad7c6', 'b0e8f394-78c1-4d8a-9c57-dc6e8b36a5fa'); VALUES ('6d6b3a71-9b11-4526-8335-b089627a8cd6', 0, 'Scrum Meeting', '2024-11-15', 0.0, 0.0, 2.0, NULL, 0.0, 46, '5c6f11fe-c341-4be7-a9a6-bba0081ad7c6', 'b0e8f394-78c1-4d8a-9c57-dc6e8b36a5fa');