añadir nuevos requisitos en Empleado
This commit is contained in:
parent
cdb53c3766
commit
77c64ee7e8
@ -61,7 +61,7 @@ public class Employee extends BaseEntity implements UserDetails {
|
|||||||
@Email(message = "El correo de contacto de emergencia no tiene un formato válido")
|
@Email(message = "El correo de contacto de emergencia no tiene un formato válido")
|
||||||
private String emergencyCEmail;
|
private String emergencyCEmail;
|
||||||
private String numberOfChildren;
|
private String numberOfChildren;
|
||||||
|
@Pattern(regexp = "^[a-zA-Z0-9]+$", message = "El CI debe contener solo letras y números")
|
||||||
private String ci;
|
private String ci;
|
||||||
private String issuedIn;
|
private String issuedIn;
|
||||||
private String pTitle1;
|
private String pTitle1;
|
||||||
@ -173,11 +173,17 @@ public class Employee extends BaseEntity implements UserDetails {
|
|||||||
|
|
||||||
@Enumerated(EnumType.STRING)
|
@Enumerated(EnumType.STRING)
|
||||||
private ContractType contractType;
|
private ContractType contractType;
|
||||||
|
|
||||||
public enum ContractType {
|
public enum ContractType {
|
||||||
CONTRATO_LABORAL,
|
CONTRATO_LABORAL,
|
||||||
CONTRATO_CIVIL_O_SERVICIOS,
|
CONTRATO_CIVIL_O_SERVICIOS,
|
||||||
CONTRATO_PLAZO_FIJO,
|
CONTRATO_PLAZO_FIJO,
|
||||||
CONSULTORIA_INTERNA,
|
CONSULTORIA_INTERNA,
|
||||||
CONSULTORIA_EXTERNA
|
CONSULTORIA_EXTERNA,
|
||||||
|
MIXTO,
|
||||||
|
OTROS
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Size(max = 255, message = "El detalle del contrato no debe exceder 255 caracteres")
|
||||||
|
private String otherContractDetail;
|
||||||
}
|
}
|
@ -28,15 +28,24 @@ public class HoursWorked extends BaseEntity {
|
|||||||
private int weekNumber;
|
private int weekNumber;
|
||||||
private LocalDate date;
|
private LocalDate date;
|
||||||
private String actividad;
|
private String actividad;
|
||||||
private String tareasEspecificas;
|
|
||||||
private double hours;
|
private double hours;
|
||||||
private double horasTareasEspecificas;
|
|
||||||
private double horaspendientes;
|
private double horaspendientes;
|
||||||
private double totalHours;
|
private double totalHours;
|
||||||
|
|
||||||
|
private String tareaEspecifica;
|
||||||
|
|
||||||
|
public String getTareaEspecifica() {
|
||||||
|
return tareaEspecifica;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTareaEspecifica(String tareaEspecifica) {
|
||||||
|
this.tareaEspecifica = tareaEspecifica;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public static double calculateTotalHours(final 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)
|
||||||
.sum();
|
.sum();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -105,21 +114,6 @@ public class HoursWorked extends BaseEntity {
|
|||||||
this.team = team;
|
this.team = team;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getTareasEspecificas() {
|
|
||||||
return tareasEspecificas;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setTareasEspecificas(final String tareasEspecificas) {
|
|
||||||
this.tareasEspecificas = tareasEspecificas;
|
|
||||||
}
|
|
||||||
|
|
||||||
public double getHorasTareasEspecificas() {
|
|
||||||
return horasTareasEspecificas;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setHorasTareasEspecificas(final double horasTareasEspecificas) {
|
|
||||||
this.tareasEspecificas = tareasEspecificas;
|
|
||||||
}
|
|
||||||
public double getHoraspendientes() {
|
public double getHoraspendientes() {
|
||||||
//double horasTrabajadas = this.getTotalHours() + this.getHorasTareasEspecificas();
|
//double horasTrabajadas = this.getTotalHours() + this.getHorasTareasEspecificas();
|
||||||
return 40;
|
return 40;
|
||||||
@ -129,21 +123,4 @@ public class HoursWorked extends BaseEntity {
|
|||||||
this.horaspendientes = horaspendientes;
|
this.horaspendientes = horaspendientes;
|
||||||
}
|
}
|
||||||
|
|
||||||
public double getHoursWorked() {
|
|
||||||
return hours;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setHoursWorked(final double hoursWorked) {
|
|
||||||
this.hours = hoursWorked;
|
|
||||||
}
|
|
||||||
|
|
||||||
public double getTotalHoursWorked() {
|
|
||||||
return totalHours;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setTotalHoursWorked(final double totalHoursWorked) {
|
|
||||||
this.totalHours = totalHoursWorked;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -114,7 +114,6 @@ public class HoursWorkedListView extends BaseView {
|
|||||||
setupFilters();
|
setupFilters();
|
||||||
setupListHoursWorkedGrid();
|
setupListHoursWorkedGrid();
|
||||||
getCurrentPageLayout().add(hoursWorkedGrid);
|
getCurrentPageLayout().add(hoursWorkedGrid);
|
||||||
getCurrentPageLayout().add(createActionButtons());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setupFilters() {
|
private void setupFilters() {
|
||||||
@ -137,11 +136,21 @@ public class HoursWorkedListView extends BaseView {
|
|||||||
hoursWorkedGrid.addColumn(hw -> hw.getEmployee().getTeam() != null ? hw.getEmployee().getTeam()
|
hoursWorkedGrid.addColumn(hw -> hw.getEmployee().getTeam() != null ? hw.getEmployee().getTeam()
|
||||||
.getName() : "Sin asignar")
|
.getName() : "Sin asignar")
|
||||||
.setHeader("Equipo");
|
.setHeader("Equipo");
|
||||||
hoursWorkedGrid.addColumn(HoursWorked::getActividad).setHeader("Actividad");
|
hoursWorkedGrid.addColumn(hw -> {
|
||||||
hoursWorkedGrid.addColumn(HoursWorked::getHours).setHeader("Total Horas").setSortable(true);
|
String actividad = hw.getActividad() != null ? hw.getActividad() : "Sin Actividad";
|
||||||
|
String tareaEspecifica = hw.getTareaEspecifica() != null ? hw.getTareaEspecifica() : "";
|
||||||
|
return !tareaEspecifica.isEmpty() ? tareaEspecifica : actividad;
|
||||||
|
}).setHeader("Actividad");
|
||||||
|
hoursWorkedGrid.addColumn(hw -> {
|
||||||
|
if (hw.getTareaEspecifica() != null && !hw.getTareaEspecifica().isEmpty()) {
|
||||||
|
return calcularHorasPorTareaEspecifica(hw);
|
||||||
|
} else {
|
||||||
|
return calcularHorasPorActividadGeneral(hw);
|
||||||
|
}
|
||||||
|
}).setHeader("Total Horas").setSortable(true);
|
||||||
|
|
||||||
hoursWorkedGrid.addColumn(hw -> hw.getHoraspendientes() - calcularTotal(hw)).setHeader("Horas Pendientes")
|
hoursWorkedGrid.addColumn(hw -> hw.getHoraspendientes() - calcularTotal(hw)).setHeader("Horas Pendientes")
|
||||||
.setSortable(true);
|
.setSortable(true);
|
||||||
|
|
||||||
hoursWorkedGrid.setPaginationBarMode(PagingGrid.PaginationBarMode.BOTTOM);
|
hoursWorkedGrid.setPaginationBarMode(PagingGrid.PaginationBarMode.BOTTOM);
|
||||||
hoursWorkedGrid.setPageSize(PAGE_SIZE);
|
hoursWorkedGrid.setPageSize(PAGE_SIZE);
|
||||||
hoursWorkedGrid.asSingleSelect().addValueChangeListener(event -> {
|
hoursWorkedGrid.asSingleSelect().addValueChangeListener(event -> {
|
||||||
@ -152,6 +161,36 @@ public class HoursWorkedListView extends BaseView {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private double calcularHorasPorTareaEspecifica(HoursWorked hoursWorked) {
|
||||||
|
List<HoursWorked> tareas = hoursWorkedService.findListHoursWorkedEmployee(
|
||||||
|
hoursWorked.getEmployee().getId(), hoursWorked.getWeekNumber());
|
||||||
|
return tareas.stream()
|
||||||
|
.filter(hw -> Objects.equals(hw.getTareaEspecifica(), hoursWorked.getTareaEspecifica()))
|
||||||
|
.mapToDouble(HoursWorked::getHours)
|
||||||
|
.sum();
|
||||||
|
}
|
||||||
|
|
||||||
|
private double calcularHorasPorActividadGeneral(HoursWorked hoursWorked) {
|
||||||
|
List<HoursWorked> actividades = hoursWorkedService.findListHoursWorkedEmployee(
|
||||||
|
hoursWorked.getEmployee().getId(), hoursWorked.getWeekNumber());
|
||||||
|
return actividades.stream()
|
||||||
|
.filter(hw -> Objects.equals(hw.getActividad(), hoursWorked.getActividad())
|
||||||
|
&& (hw.getTareaEspecifica() == null || hw.getTareaEspecifica().isEmpty()))
|
||||||
|
.mapToDouble(HoursWorked::getHours)
|
||||||
|
.sum();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private double calcularTotalHorasTareaEspecifica(HoursWorked hoursWorked) {
|
||||||
|
List<HoursWorked> horasTareas = hoursWorkedService.findListHoursWorkedEmployee(
|
||||||
|
hoursWorked.getEmployee().getId(), hoursWorked.getWeekNumber());
|
||||||
|
return horasTareas.stream()
|
||||||
|
.filter(hw -> Objects.equals(hw.getTareaEspecifica(), hoursWorked.getTareaEspecifica()))
|
||||||
|
.mapToDouble(HoursWorked::getHours)
|
||||||
|
.sum();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
private double calcularTotal(final 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());
|
||||||
@ -165,25 +204,6 @@ public class HoursWorkedListView extends BaseView {
|
|||||||
.sum();
|
.sum();
|
||||||
}
|
}
|
||||||
|
|
||||||
private HorizontalLayout createActionButtons() {
|
|
||||||
Button viewButton = new Button("Ver", event -> {
|
|
||||||
if (selectedEmployeeId != null) {
|
|
||||||
navigateToHoursWorkedView(selectedEmployeeId);
|
|
||||||
} else {
|
|
||||||
Notification.show("Seleccione una solicitud.", 3000, Notification.Position.MIDDLE);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
Button closeButton = new Button("Salir", event -> navigateToListView());
|
|
||||||
return new HorizontalLayout(viewButton, closeButton);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void navigateToListView() {
|
|
||||||
getUI().ifPresent(ui -> ui.navigate(MainView.class));
|
|
||||||
}
|
|
||||||
|
|
||||||
private void navigateToHoursWorkedView(final UUID idEmployee) {
|
|
||||||
getUI().ifPresent(ui -> ui.navigate("hours-worked-list/" + idEmployee.toString()));
|
|
||||||
}
|
|
||||||
|
|
||||||
private Button createButton(final String label, final Runnable onClickAction) {
|
private Button createButton(final String label, final Runnable onClickAction) {
|
||||||
final Button button = new Button(label);
|
final Button button = new Button(label);
|
||||||
|
@ -108,7 +108,8 @@ public class HoursWorkedView extends BeanValidationForm<HoursWorked> implements
|
|||||||
|
|
||||||
private void configureTareasEspecificas() {
|
private void configureTareasEspecificas() {
|
||||||
tareasEspecificasDropdown.setItems("Entrevistas", "Reuniones",
|
tareasEspecificasDropdown.setItems("Entrevistas", "Reuniones",
|
||||||
"Colaboraciones", "Aprendizajes", "Proyectos PFS", "Otros");
|
"Colaboraciones", "Aprendizajes", "Proyectos PFS",
|
||||||
|
"Consulta Medica", "Afiliación al Seguro", "Fallas Tecnicas", "Otros");
|
||||||
tareasEspecificasDropdown.setPlaceholder("Selecciona una tarea...");
|
tareasEspecificasDropdown.setPlaceholder("Selecciona una tarea...");
|
||||||
|
|
||||||
tareasEspecificasDropdown.addValueChangeListener(event -> {
|
tareasEspecificasDropdown.addValueChangeListener(event -> {
|
||||||
@ -192,13 +193,39 @@ public class HoursWorkedView extends BeanValidationForm<HoursWorked> implements
|
|||||||
private void saveHoursWorked() {
|
private void saveHoursWorked() {
|
||||||
if (isFormValid()) {
|
if (isFormValid()) {
|
||||||
HoursWorked hoursWorked = getEntity();
|
HoursWorked hoursWorked = getEntity();
|
||||||
|
String actividad = activityField.getValue();
|
||||||
|
String tareaEspecifica = tareasEspecificasDropdown.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;
|
||||||
|
}
|
||||||
|
if (actividad != null && !actividad.isEmpty()) {
|
||||||
|
hoursWorked.setActividad(actividad);
|
||||||
|
} else if (tareaEspecifica != null) {
|
||||||
|
if ("Otros".equals(tareaEspecifica)) {
|
||||||
|
// Validar que se ingresó una tarea específica en el campo de texto
|
||||||
|
String tareaEspecificaInputValue = tareaEspecificaInput.getValue();
|
||||||
|
if (tareaEspecificaInputValue == null || tareaEspecificaInputValue.isEmpty()) {
|
||||||
|
Notification.show("Por favor, ingresa una tarea específica.", 3000, Notification.Position.BOTTOM_CENTER);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
hoursWorked.setTareaEspecifica(tareaEspecificaInputValue);
|
||||||
|
} else {
|
||||||
|
hoursWorked.setTareaEspecifica(tareaEspecifica);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
Notification.show("Por favor, selecciona una actividad o tarea para guardar.", 3000, Notification.Position.BOTTOM_CENTER);
|
||||||
|
return;
|
||||||
|
}
|
||||||
setFieldValues(hoursWorked);
|
setFieldValues(hoursWorked);
|
||||||
hoursWorkedService.save(hoursWorked);
|
hoursWorkedService.save(hoursWorked);
|
||||||
Notification.show("Horas trabajadas guardadas correctamente.");
|
Notification.show("Horas trabajadas guardadas correctamente.", 3000, Notification.Position.BOTTOM_CENTER);
|
||||||
closeForm();
|
closeForm();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
private void setFieldValues(final HoursWorked hoursWorked) {
|
private void setFieldValues(final HoursWorked hoursWorked) {
|
||||||
hoursWorked.setDate(dateField.getValue());
|
hoursWorked.setDate(dateField.getValue());
|
||||||
hoursWorked.setTeam(teamField.getValue());
|
hoursWorked.setTeam(teamField.getValue());
|
||||||
@ -211,10 +238,10 @@ 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())) {
|
||||||
hoursWorked.setTareasEspecificas(tareaEspecificaInput.getValue());
|
hoursWorked.setActividad(tareaEspecificaInput.getValue());
|
||||||
try {
|
try {
|
||||||
double horasEspecifica = Double.parseDouble(horasTareaEspecificaField.getValue());
|
double horasEspecifica = Double.parseDouble(horasTareaEspecificaField.getValue());
|
||||||
hoursWorked.setHorasTareasEspecificas(horasEspecifica);
|
hoursWorked.setHours(horasEspecifica);
|
||||||
double totalHoras = hoursWorked.getHours() + horasEspecifica;
|
double totalHoras = hoursWorked.getHours() + horasEspecifica;
|
||||||
hoursWorked.setTotalHours(totalHoras);
|
hoursWorked.setTotalHours(totalHoras);
|
||||||
} catch (NumberFormatException e) {
|
} catch (NumberFormatException e) {
|
||||||
@ -224,20 +251,27 @@ public class HoursWorkedView extends BeanValidationForm<HoursWorked> implements
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void closeForm() {
|
private void closeForm() {
|
||||||
|
if (hoursWorked != null) {
|
||||||
getUI().ifPresent(ui -> ui.navigate("hours-worked-list/" + hoursWorked.getId().toString()));
|
getUI().ifPresent(ui -> ui.navigate("hours-worked-list/" + hoursWorked.getId().toString()));
|
||||||
|
} else {
|
||||||
|
getUI().ifPresent(ui -> ui.navigate("hours-worked-list"));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean isFormValid() {
|
private boolean isFormValid() {
|
||||||
|
boolean isTareaEspecificaValida = "Otros".equals(tareasEspecificasDropdown.getValue())
|
||||||
|
? !tareaEspecificaInput.isEmpty()
|
||||||
|
: tareasEspecificasDropdown.getValue() != null;
|
||||||
|
boolean isActividadValida = !activityField.isEmpty();
|
||||||
|
boolean isSoloUnaOpcionElegida = (isActividadValida && tareasEspecificasDropdown.isEmpty())
|
||||||
|
|| (!isActividadValida && isTareaEspecificaValida);
|
||||||
return dateField.getValue() != null
|
return dateField.getValue() != null
|
||||||
&&
|
&& teamField.getValue() != null
|
||||||
teamField.getValue() != null
|
&& employeeField.getValue() != null
|
||||||
&&
|
&& isSoloUnaOpcionElegida;
|
||||||
employeeField.getValue() != null
|
|
||||||
&&
|
|
||||||
!activityField.isEmpty();
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private void configureViewOrEditAction(final String action) {
|
private void configureViewOrEditAction(final String action) {
|
||||||
if ("edit".equals(action) && hoursWorked != null) {
|
if ("edit".equals(action) && hoursWorked != null) {
|
||||||
setFieldsReadOnly(false);
|
setFieldsReadOnly(false);
|
||||||
|
Loading…
Reference in New Issue
Block a user