Formulario de registro de horas trabajadas mas el formulario
This commit is contained in:
parent
97d4bdf508
commit
6fbf6e8fa7
@ -7,6 +7,9 @@ import lombok.EqualsAndHashCode;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.time.temporal.WeekFields;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
@Data
|
||||
@Entity
|
||||
@ -31,6 +34,17 @@ public class HoursWorked extends BaseEntity {
|
||||
private double horaspendientes;
|
||||
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() {
|
||||
return employee;
|
||||
}
|
||||
@ -46,13 +60,16 @@ public class HoursWorked extends BaseEntity {
|
||||
public void setWeekNumber(final int weekNumber) {
|
||||
this.weekNumber = weekNumber;
|
||||
}
|
||||
|
||||
public LocalDate getDate() {
|
||||
return date;
|
||||
}
|
||||
|
||||
public void setDate(final LocalDate date) {
|
||||
this.date = date;
|
||||
if (date != null) {
|
||||
WeekFields weekFields = WeekFields.of(Locale.getDefault());
|
||||
this.weekNumber = date.get(weekFields.weekOfWeekBasedYear());
|
||||
}
|
||||
}
|
||||
|
||||
public String getActividad() {
|
||||
|
@ -44,6 +44,16 @@ public class HoursWorkedService {
|
||||
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) {
|
||||
return hoursWorkedRepository.findByWeekNumber(weekNumber);
|
||||
}
|
||||
|
@ -125,6 +125,9 @@ public class HoursWorkedListView extends Main {
|
||||
hoursWorkedGrid.addColumn(hw -> hw.getDate() != null ? hw.getDate().toString() : "")
|
||||
.setHeader("Fecha")
|
||||
.setSortable(true);
|
||||
hoursWorkedGrid.addColumn(hw -> hw.getWeekNumber())
|
||||
.setHeader("Semana")
|
||||
.setSortable(true);
|
||||
hoursWorkedGrid.addColumn(hw -> hw.getEmployee().getFirstName() + " " + hw.getEmployee().getLastName())
|
||||
.setHeader("Empleado");
|
||||
hoursWorkedGrid.addColumn(hw -> hw.getEmployee().getTeam() != null ? hw.getEmployee().getTeam().getName() : "Sin asignar")
|
||||
|
@ -21,6 +21,7 @@ import org.vaadin.firitin.form.BeanValidationForm;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.time.YearMonth;
|
||||
import java.time.temporal.IsoFields;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
@ -175,7 +176,16 @@ public class HoursWorkedView extends BeanValidationForm<HoursWorked> implements
|
||||
dateField.setMax(maxSelectableDate);
|
||||
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() {
|
||||
@ -200,11 +210,12 @@ public class HoursWorkedView extends BeanValidationForm<HoursWorked> implements
|
||||
Notification.show("Por favor, ingrese un número válido para las horas.");
|
||||
}
|
||||
if ("Otros".equals(tareasEspecificasDropdown.getValue())) {
|
||||
// Maneja horas y actividad específica adicional
|
||||
hoursWorked.setTareasEspecificas(tareaEspecificaInput.getValue());
|
||||
try {
|
||||
double horasEspecifica = Double.parseDouble(horasTareaEspecificaField.getValue());
|
||||
hoursWorked.setHorasTareasEspecificas(horasEspecifica);
|
||||
double totalHoras = hoursWorked.getHours() + horasEspecifica;
|
||||
hoursWorked.setTotalHours(totalHoras);
|
||||
} catch (NumberFormatException e) {
|
||||
Notification.show("Por favor, ingrese un número válido para las horas de la tarea específica.");
|
||||
}
|
||||
|
@ -142,7 +142,9 @@ public class ReporteView extends VerticalLayout {
|
||||
.getId()) && hw.getWeekNumber() == weekNumber)
|
||||
.collect(Collectors.toList());
|
||||
|
||||
System.out.println(hoursWorkedList);
|
||||
if (hoursWorkedList.isEmpty()) {
|
||||
|
||||
Notification.show("No hay horas trabajadas disponibles para generar el reporte.",
|
||||
3000, Notification.Position.MIDDLE);
|
||||
return;
|
||||
|
@ -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);
|
||||
|
||||
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');
|
||||
|
Loading…
Reference in New Issue
Block a user