Compare commits

...

8 Commits

Author SHA1 Message Date
Melina Gutierrez
addba4b70f crear tabla para visuaizar las actividades creadas 2024-11-13 16:08:20 -04:00
Melina Gutierrez
090a4bb67a crear tabla para visuaizar las actividades creadas 2024-11-13 15:57:49 -04:00
Melina Gutierrez
3c626e3c85 Merge remote-tracking branch 'origin/hoursworked' into hoursworked
Some checks failed
PR Builder / Build-PR (pull_request) Failing after 19s
# Conflicts:
#	src/main/java/com/primefactorsolutions/views/HoursWorkedView.java
2024-11-12 20:57:30 -04:00
Melina Gutierrez
e45d0d828f #45-Registro Semanal de Horas Trabajadas corregir duplicados y actividades 2024-11-12 20:55:52 -04:00
Melina Gutierrez
b94ec365c7 #45-Registro Semanal de Horas Trabajadas corregir duplicados 2024-11-12 20:29:21 -04:00
Melina Gutierrez
e2f128c301 #45-Registro Semanal de Horas Trabajadas corregir duplicados 2024-11-12 20:20:35 -04:00
Melina Gutierrez
ebb5454b29 #45-Registro Semanal de Horas Trabajadas corregir duplicados 2024-11-12 07:00:43 -04:00
Melina Gutierrez
dee4bcaf3b #45-Registro Semanal de Horas Trabajadas corregir duplicados
Some checks failed
PR Builder / Build-PR (pull_request) Failing after 23s
2024-11-12 07:00:06 -04:00
15 changed files with 391 additions and 274 deletions

View File

@ -1,14 +0,0 @@
name: PR Builder
run-name: ${{ gitea.actor }} building PR
on: [pull_request]
jobs:
Build-PR:
runs-on: ubuntu-22.04
steps:
- run: echo "The job was automatically triggered by a ${{ gitea.event_name }} event on branch ${{ gitea.head_ref }} and ref is ${{ gitea.ref }} and your repository is ${{ gitea.repository }}."
- name: Build PR
if: gitea.base_ref == 'main'
run: |
git clone --single-branch --branch "${{ gitea.head_ref }}" https://git.primefactorsolutions.com/PFS/pfs-intra.git && cd pfs-intra && ./mvnw clean package -Pproduction
- run: echo "This job's status is ${{ job.status }}."

View File

@ -1,16 +0,0 @@
name: Builder
run-name: ${{ gitea.actor }} building
on:
push:
branches:
- main
jobs:
Build-Project:
runs-on: ubuntu-22.04
steps:
- run: echo "The job was automatically triggered by a ${{ gitea.event_name }} event on branch is ${{ gitea.ref }} and your repository is ${{ gitea.repository }}."
- name: Build package
run: |
git clone --single-branch --branch main https://git.primefactorsolutions.com/PFS/pfs-intra.git && cd pfs-intra && ./mvnw clean package -Pproduction && unlink /home/ubuntu/pfs-intra/app.jar && cp target/*.jar /home/ubuntu/pfs-intra/app.jar && sudo systemctl restart pfs-intra
- run: echo "This job's status is ${{ job.status }}."

View File

@ -1,118 +0,0 @@
/*
* Copyright 2007-present the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import java.io.*;
import java.net.*;
import java.nio.channels.*;
import java.util.Properties;
public class MavenWrapperDownloader {
private static final String WRAPPER_VERSION = "0.5.6";
/**
* Default URL to download the maven-wrapper.jar from, if no 'downloadUrl' is
* provided.
*/
private static final String DEFAULT_DOWNLOAD_URL = "https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/"
+ WRAPPER_VERSION + "/maven-wrapper-" + WRAPPER_VERSION + ".jar";
/**
* Path to the maven-wrapper.properties file, which might contain a downloadUrl
* property to use instead of the default one.
*/
private static final String MAVEN_WRAPPER_PROPERTIES_PATH = ".mvn/wrapper/maven-wrapper.properties";
/**
* Path where the maven-wrapper.jar will be saved to.
*/
private static final String MAVEN_WRAPPER_JAR_PATH = ".mvn/wrapper/maven-wrapper.jar";
/**
* Name of the property which should be used to override the default download
* url for the wrapper.
*/
private static final String PROPERTY_NAME_WRAPPER_URL = "wrapperUrl";
public static void main(String args[]) {
System.out.println("- Downloader started");
File baseDirectory = new File(args[0]);
System.out.println("- Using base directory: " + baseDirectory.getAbsolutePath());
// If the maven-wrapper.properties exists, read it and check if it contains a
// custom
// wrapperUrl parameter.
File mavenWrapperPropertyFile = new File(baseDirectory, MAVEN_WRAPPER_PROPERTIES_PATH);
String url = DEFAULT_DOWNLOAD_URL;
if (mavenWrapperPropertyFile.exists()) {
FileInputStream mavenWrapperPropertyFileInputStream = null;
try {
mavenWrapperPropertyFileInputStream = new FileInputStream(mavenWrapperPropertyFile);
Properties mavenWrapperProperties = new Properties();
mavenWrapperProperties.load(mavenWrapperPropertyFileInputStream);
url = mavenWrapperProperties.getProperty(PROPERTY_NAME_WRAPPER_URL, url);
} catch (IOException e) {
System.out.println("- ERROR loading '" + MAVEN_WRAPPER_PROPERTIES_PATH + "'");
} finally {
try {
if (mavenWrapperPropertyFileInputStream != null) {
mavenWrapperPropertyFileInputStream.close();
}
} catch (IOException e) {
// Ignore ...
}
}
}
System.out.println("- Downloading from: " + url);
File outputFile = new File(baseDirectory.getAbsolutePath(), MAVEN_WRAPPER_JAR_PATH);
if (!outputFile.getParentFile().exists()) {
if (!outputFile.getParentFile().mkdirs()) {
System.out.println(
"- ERROR creating output directory '" + outputFile.getParentFile().getAbsolutePath() + "'");
}
}
System.out.println("- Downloading to: " + outputFile.getAbsolutePath());
try {
downloadFileFromURL(url, outputFile);
System.out.println("Done");
System.exit(0);
} catch (Throwable e) {
System.out.println("- Error downloading");
e.printStackTrace();
System.exit(1);
}
}
private static void downloadFileFromURL(String urlString, File destination) throws Exception {
if (System.getenv("MVNW_USERNAME") != null && System.getenv("MVNW_PASSWORD") != null) {
String username = System.getenv("MVNW_USERNAME");
char[] password = System.getenv("MVNW_PASSWORD").toCharArray();
Authenticator.setDefault(new Authenticator() {
@Override
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(username, password);
}
});
}
URL website = new URL(urlString);
ReadableByteChannel rbc;
rbc = Channels.newChannel(website.openStream());
FileOutputStream fos = new FileOutputStream(destination);
fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE);
fos.close();
rbc.close();
}
}

Binary file not shown.

View File

@ -1,18 +0,0 @@
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.8.4/apache-maven-3.8.4-bin.zip
wrapperUrl=https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.1.0/maven-wrapper-3.1.0.jar

View File

@ -4,7 +4,7 @@
"type": "module", "type": "module",
"dependencies": { "dependencies": {
"@f0rce/ace-widget": "1.0.2", "@f0rce/ace-widget": "1.0.2",
"@polymer/polymer": "3.5.2", "@polymer/polymer": "3.5.1",
"@vaadin-component-factory/vcf-pdf-viewer": "2.0.1", "@vaadin-component-factory/vcf-pdf-viewer": "2.0.1",
"@vaadin/bundles": "24.5.1", "@vaadin/bundles": "24.5.1",
"@vaadin/common-frontend": "0.0.19", "@vaadin/common-frontend": "0.0.19",
@ -19,30 +19,30 @@
"@vaadin/vaadin-usage-statistics": "2.1.3", "@vaadin/vaadin-usage-statistics": "2.1.3",
"construct-style-sheets-polyfill": "3.1.0", "construct-style-sheets-polyfill": "3.1.0",
"date-fns": "2.29.3", "date-fns": "2.29.3",
"lit": "3.2.1", "lit": "3.1.4",
"print-js": "1.6.0", "print-js": "1.6.0",
"proj4": "2.12.1", "proj4": "2.12.1",
"react": "18.3.1", "react": "18.3.1",
"react-dom": "18.3.1", "react-dom": "18.3.1",
"react-router-dom": "6.26.2" "react-router-dom": "6.23.1"
}, },
"devDependencies": { "devDependencies": {
"@babel/preset-react": "7.25.7", "@babel/preset-react": "7.24.7",
"@preact/signals-react-transform": "0.4.0", "@preact/signals-react-transform": "0.4.0",
"@rollup/plugin-replace": "6.0.1", "@rollup/plugin-replace": "5.0.7",
"@rollup/pluginutils": "5.1.2", "@rollup/pluginutils": "5.1.0",
"@types/react": "18.3.11", "@types/react": "18.3.3",
"@types/react-dom": "18.3.1", "@types/react-dom": "18.3.0",
"@vitejs/plugin-react": "4.3.3", "@vitejs/plugin-react": "4.3.1",
"async": "3.2.6", "async": "3.2.5",
"glob": "10.4.5", "glob": "10.4.1",
"rollup-plugin-brotli": "3.1.0", "rollup-plugin-brotli": "3.1.0",
"rollup-plugin-visualizer": "5.12.0", "rollup-plugin-visualizer": "5.12.0",
"strip-css-comments": "5.0.0", "strip-css-comments": "5.0.0",
"transform-ast": "2.4.4", "transform-ast": "2.4.4",
"typescript": "5.6.3", "typescript": "5.4.5",
"vite": "5.4.9", "vite": "5.3.3",
"vite-plugin-checker": "0.8.0", "vite-plugin-checker": "0.6.4",
"workbox-build": "7.1.1", "workbox-build": "7.1.1",
"workbox-core": "7.1.0", "workbox-core": "7.1.0",
"workbox-precaching": "7.1.0" "workbox-precaching": "7.1.0"
@ -50,7 +50,7 @@
"vaadin": { "vaadin": {
"dependencies": { "dependencies": {
"@f0rce/ace-widget": "1.0.2", "@f0rce/ace-widget": "1.0.2",
"@polymer/polymer": "3.5.2", "@polymer/polymer": "3.5.1",
"@vaadin-component-factory/vcf-pdf-viewer": "2.0.1", "@vaadin-component-factory/vcf-pdf-viewer": "2.0.1",
"@vaadin/bundles": "24.5.1", "@vaadin/bundles": "24.5.1",
"@vaadin/common-frontend": "0.0.19", "@vaadin/common-frontend": "0.0.19",
@ -65,30 +65,30 @@
"@vaadin/vaadin-usage-statistics": "2.1.3", "@vaadin/vaadin-usage-statistics": "2.1.3",
"construct-style-sheets-polyfill": "3.1.0", "construct-style-sheets-polyfill": "3.1.0",
"date-fns": "2.29.3", "date-fns": "2.29.3",
"lit": "3.2.1", "lit": "3.1.4",
"print-js": "1.6.0", "print-js": "1.6.0",
"proj4": "2.12.1", "proj4": "2.12.1",
"react": "18.3.1", "react": "18.3.1",
"react-dom": "18.3.1", "react-dom": "18.3.1",
"react-router-dom": "6.26.2" "react-router-dom": "6.23.1"
}, },
"devDependencies": { "devDependencies": {
"@babel/preset-react": "7.25.7", "@babel/preset-react": "7.24.7",
"@preact/signals-react-transform": "0.4.0", "@preact/signals-react-transform": "0.4.0",
"@rollup/plugin-replace": "6.0.1", "@rollup/plugin-replace": "5.0.7",
"@rollup/pluginutils": "5.1.2", "@rollup/pluginutils": "5.1.0",
"@types/react": "18.3.11", "@types/react": "18.3.3",
"@types/react-dom": "18.3.1", "@types/react-dom": "18.3.0",
"@vitejs/plugin-react": "4.3.3", "@vitejs/plugin-react": "4.3.1",
"async": "3.2.6", "async": "3.2.5",
"glob": "10.4.5", "glob": "10.4.1",
"rollup-plugin-brotli": "3.1.0", "rollup-plugin-brotli": "3.1.0",
"rollup-plugin-visualizer": "5.12.0", "rollup-plugin-visualizer": "5.12.0",
"strip-css-comments": "5.0.0", "strip-css-comments": "5.0.0",
"transform-ast": "2.4.4", "transform-ast": "2.4.4",
"typescript": "5.6.3", "typescript": "5.4.5",
"vite": "5.4.9", "vite": "5.3.3",
"vite-plugin-checker": "0.8.0", "vite-plugin-checker": "0.6.4",
"workbox-build": "7.1.1", "workbox-build": "7.1.1",
"workbox-core": "7.1.0", "workbox-core": "7.1.0",
"workbox-precaching": "7.1.0" "workbox-precaching": "7.1.0"

View File

@ -1,6 +1,19 @@
package com.primefactorsolutions.model; package com.primefactorsolutions.model;
public final class Actividad { import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import java.util.UUID;
@Entity
public class Actividad extends BaseEntity {
@Id
@GeneratedValue(strategy = GenerationType.UUID)
private UUID id;
private String nombre; private String nombre;
private double lunes; private double lunes;
private double martes; private double martes;
@ -12,6 +25,8 @@ public final class Actividad {
private String tarea; private String tarea;
private double horas; private double horas;
public Actividad() { }
public Actividad(final Builder builder) { public Actividad(final Builder builder) {
this.nombre = builder.nombre; this.nombre = builder.nombre;
this.lunes = builder.lunes; this.lunes = builder.lunes;
@ -25,10 +40,59 @@ public final class Actividad {
this.horas = builder.horas; this.horas = builder.horas;
} }
public String setNombre(final String nombre) {
this.nombre = nombre;
return nombre;
}
public String getNombre() { public String getNombre() {
return nombre; return nombre;
} }
public void setLunes(final double lunes) {
this.lunes = lunes;
return;
}
public void setMartes(final double martes) {
this.martes = martes;
return;
}
public void setMiercoles(final double miercoles) {
this.miercoles = miercoles;
return;
}
public void setJueves(final double jueves) {
this.jueves = jueves;
return;
}
public void setViernes(final double viernes) {
this.viernes = viernes;
return;
}
public void setSabado(final double sabado) {
this.sabado = sabado;
return;
}
public void setDomingo(final double domingo) {
this.domingo = domingo;
return;
}
public void setTarea(final String tarea) {
this.tarea = tarea;
return;
}
public void setHoras(final double horas) {
this.horas = horas;
return;
}
public double getLunes() { public double getLunes() {
return lunes; return lunes;
} }

View File

@ -0,0 +1,81 @@
package com.primefactorsolutions.model;
import jakarta.persistence.*;
import java.time.LocalDate;
import java.util.UUID;
@Entity
@Table(name = "Actividades_hours")
public class ActividadesHours {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private UUID id;
@ManyToOne
@JoinColumn(name = "employee_id", nullable = false)
private Employee employee;
@ManyToOne
@JoinColumn(name = "actividad_id", nullable = false)
private Actividad actividad;
@Column(nullable = false)
private double totalHours;
@Column(nullable = false)
private int weekNumber;
@Column(nullable = false)
private LocalDate fecha;
// Getters y Setters
public UUID getId() {
return id;
}
public void setId(final UUID id) {
this.id = id;
}
public Employee getEmployee() {
return employee;
}
public void setEmployee(final Employee employee) {
this.employee = employee;
}
public Actividad getActividad() {
return actividad;
}
public void setActividad(final Actividad actividad) {
this.actividad = actividad;
}
public double getTotalHours() {
return totalHours;
}
public void setTotalHours(final double totalHours) {
this.totalHours = totalHours;
}
public int getWeekNumber() {
return weekNumber;
}
public void setWeekNumber(final int weekNumber) {
this.weekNumber = weekNumber;
}
public LocalDate getFecha() {
return fecha;
}
public void setFecha(final LocalDate fecha) {
this.fecha = fecha;
}
}

View File

@ -5,7 +5,11 @@ import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType; import jakarta.persistence.GenerationType;
import jakarta.persistence.Id; import jakarta.persistence.Id;
import jakarta.persistence.ManyToOne; import jakarta.persistence.ManyToOne;
import jakarta.persistence.CascadeType;
import java.time.LocalDate;
import java.time.temporal.WeekFields;
import java.util.Locale;
import java.util.UUID; import java.util.UUID;
@Entity @Entity
@ -17,11 +21,16 @@ public class HoursWorked extends BaseEntity {
@ManyToOne @ManyToOne
private Employee employee; private Employee employee;
@ManyToOne(cascade = CascadeType.PERSIST) // Añadimos cascade para que persista la actividad automáticamente
private Actividad actividad;
private int weekNumber; private int weekNumber;
private double totalHours; private double totalHours;
private LocalDate fecha;
public HoursWorked() { } public HoursWorked() { }
// Getters y Setters
public UUID getId() { public UUID getId() {
return id; return id;
} }
@ -34,8 +43,16 @@ public class HoursWorked extends BaseEntity {
return employee; return employee;
} }
public void setEmployee(final Employee value) { public void setEmployee(final Employee employee) {
this.employee = value; this.employee = employee;
}
public Actividad getActividad() {
return actividad;
}
public void setActividad(final Actividad actividad) {
this.actividad = actividad;
} }
public int getWeekNumber() { public int getWeekNumber() {
@ -53,4 +70,33 @@ public class HoursWorked extends BaseEntity {
public void setTotalHours(final double totalHours) { public void setTotalHours(final double totalHours) {
this.totalHours = totalHours; this.totalHours = totalHours;
} }
public LocalDate getFecha() {
return fecha;
}
public void setFecha(final LocalDate fecha) {
this.fecha = fecha;
// Actualiza el número de semana automáticamente al establecer la fecha
if (fecha != null) {
this.weekNumber = calculateWeekNumber(fecha);
}
}
// Método adicional para calcular el número de semana basado en la fecha
private int calculateWeekNumber(final LocalDate date) {
WeekFields weekFields = WeekFields.of(Locale.getDefault());
return date.get(weekFields.weekOfWeekBasedYear());
}
@Override
public String toString() {
return "HoursWorked{"
+ "id=" + id
+ ", employee=" + (employee != null ? employee.getFirstName() : "N/A")
+ ", actividad=" + (actividad != null ? actividad.getNombre() : "N/A")
+ ", weekNumber=" + weekNumber
+ ", totalHours=" + totalHours
+ ", fecha=" + fecha + '}';
}
} }

View File

@ -0,0 +1,6 @@
package com.primefactorsolutions.repositories;
import com.primefactorsolutions.model.ActividadesHours;
import org.springframework.data.jpa.repository.JpaRepository;
import java.util.UUID;
public interface ActividadesHoursRepository extends JpaRepository<ActividadesHours, UUID> {
}

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> findByTeamId(UUID teamId); Optional<Employee> findByTeamIdAndLeadManagerTrue(UUID teamId);
List<Employee> findByTeamName(String teamName); List<Employee> findByTeamName(String teamName);
} }

View File

@ -8,7 +8,5 @@ import java.util.List;
@Repository @Repository
public interface HoursWorkedRepository extends JpaRepository<HoursWorked, Long> { public interface HoursWorkedRepository extends JpaRepository<HoursWorked, Long> {
// Puedes definir consultas personalizadas aquí si es necesario.
List<HoursWorked> findByWeekNumber(int weekNumber); List<HoursWorked> findByWeekNumber(int weekNumber);
} }

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.findByTeamId(teamId); Optional<Employee> leadManager = employeeRepository.findByTeamIdAndLeadManagerTrue(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

@ -2,10 +2,11 @@ package com.primefactorsolutions.views;
import com.primefactorsolutions.model.Actividad; import com.primefactorsolutions.model.Actividad;
import com.primefactorsolutions.model.Employee; import com.primefactorsolutions.model.Employee;
import com.primefactorsolutions.model.HoursWorked; import com.primefactorsolutions.model.HoursWorked;
import com.primefactorsolutions.repositories.ActividadesHoursRepository;
import com.primefactorsolutions.service.EmployeeService; import com.primefactorsolutions.service.EmployeeService;
import com.primefactorsolutions.service.HoursWorkedService; import com.primefactorsolutions.service.HoursWorkedService;
import com.vaadin.flow.component.datepicker.DatePicker;
import com.vaadin.flow.component.grid.Grid; import com.vaadin.flow.component.grid.Grid;
import com.vaadin.flow.component.html.H2;
import com.vaadin.flow.component.notification.Notification; import com.vaadin.flow.component.notification.Notification;
import com.vaadin.flow.component.orderedlayout.HorizontalLayout; import com.vaadin.flow.component.orderedlayout.HorizontalLayout;
import com.vaadin.flow.component.textfield.TextField; import com.vaadin.flow.component.textfield.TextField;
@ -17,11 +18,9 @@ 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.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Scope; import org.springframework.context.annotation.Scope;
import com.vaadin.flow.component.html.Label; import com.vaadin.flow.component.html.Label;
import org.springframework.web.servlet.HandlerMapping; import org.vaadin.firitin.components.datepicker.VDatePicker;
import org.springframework.web.servlet.view.InternalResourceViewResolver;
import java.time.DayOfWeek; import java.time.DayOfWeek;
@ -35,7 +34,7 @@ import java.util.Locale;
@SpringComponent @SpringComponent
@PermitAll @PermitAll
@Scope("prototype") @Scope("prototype")
@PageTitle("Hours Worked") @PageTitle("Horas Trabajadas")
@Route(value = "/hours-worked/me", layout = MainLayout.class) @Route(value = "/hours-worked/me", layout = MainLayout.class)
public class HoursWorkedView extends VerticalLayout { public class HoursWorkedView extends VerticalLayout {
private final List<Actividad> actividades = new ArrayList<>(); private final List<Actividad> actividades = new ArrayList<>();
@ -43,8 +42,10 @@ public class HoursWorkedView extends VerticalLayout {
private final Grid<Actividad> grid = new Grid<>(Actividad.class); private final Grid<Actividad> grid = new Grid<>(Actividad.class);
private final Grid<Actividad> gridActividadesEspecificas = new Grid<>(Actividad.class); private final Grid<Actividad> gridActividadesEspecificas = new Grid<>(Actividad.class);
private final ComboBox<Employee> employeeComboBox = new ComboBox<>("Employee"); private final ComboBox<Employee> employeeComboBox = new ComboBox<>("Empleado");
private final ComboBox<String> equipoDropdown = new ComboBox<>("Equipo"); private final ComboBox<String> equipoDropdown = new ComboBox<>("Equipo");
private VDatePicker fechaPicker = new VDatePicker("Selecciona una fecha");
private final ComboBox<String> tareasEspecificasDropdown = new ComboBox<>("Tareas Específicas"); private final ComboBox<String> tareasEspecificasDropdown = new ComboBox<>("Tareas Específicas");
private final TextField tareaEspecificaInput = new TextField("Especificar Tarea"); private final TextField tareaEspecificaInput = new TextField("Especificar Tarea");
@ -58,21 +59,18 @@ public class HoursWorkedView extends VerticalLayout {
@Autowired @Autowired
private final HoursWorkedService hoursWorkedService; private final HoursWorkedService hoursWorkedService;
private final Label fechasLabel = new Label("Selecciona una semana para ver las fechas.");
@Autowired
private ActividadesHoursRepository actividadesHoursRepository;
private final H2 equipoLabel = new H2("Tareas del Cliente/Equipo");
private final H2 empresaLabel = new H2("Tareas de la Empresa");
private final Label totalCompletadoLabel = new Label(); private final Label totalCompletadoLabel = new Label();
private final Label horasPendientesLabel = new Label(); private final Label horasPendientesLabel = new Label();
private final Label numeroSemanaLabel = new Label("Número de la Semana: "); public HoursWorkedView(final EmployeeService employeeService,
final HoursWorkedService hoursWorkedService) {
private DatePicker fechaPicker = new DatePicker("Selecciona una fecha");
@Autowired
private InternalResourceViewResolver defaultViewResolver;
@Qualifier("defaultServletHandlerMapping")
@Autowired
private HandlerMapping defaultServletHandlerMapping;
public HoursWorkedView(final EmployeeService employeeService, final HoursWorkedService hoursWorkedService) {
this.employeeService = employeeService; this.employeeService = employeeService;
this.hoursWorkedService = hoursWorkedService; this.hoursWorkedService = hoursWorkedService;
configurarVista(); configurarVista();
@ -100,9 +98,20 @@ public class HoursWorkedView extends VerticalLayout {
private void cargarDatos() { private void cargarDatos() {
if (selectedStartOfWeek != null && weekNumber > 0) { if (selectedStartOfWeek != null && weekNumber > 0) {
actividades.clear();
actividadesEspecificas.clear();
List<HoursWorked> listaDeHorasTrabajadas = obtenerDatos(); List<HoursWorked> listaDeHorasTrabajadas = obtenerDatos();
for (HoursWorked hours : listaDeHorasTrabajadas) {
LocalDate activityDate = hours.getFecha();
int activityWeek = getWeekOfYear(activityDate);
if (activityWeek == weekNumber) {
Actividad actividad = hours.getActividad();
if (actividad != null) {
DayOfWeek dayOfWeek = activityDate.getDayOfWeek();
agregarOActualizarActividad(actividad, dayOfWeek, hours.getTotalHours());
}
}
}
grid.setItems(actividades); grid.setItems(actividades);
gridActividadesEspecificas.setItems(actividadesEspecificas); gridActividadesEspecificas.setItems(actividadesEspecificas);
calcularTotalHoras(listaDeHorasTrabajadas); calcularTotalHoras(listaDeHorasTrabajadas);
@ -113,7 +122,8 @@ public class HoursWorkedView extends VerticalLayout {
employeeComboBox.setWidth("250px"); employeeComboBox.setWidth("250px");
employeeComboBox.setPlaceholder("Buscar empleado..."); employeeComboBox.setPlaceholder("Buscar empleado...");
employeeComboBox.setItems(employeeService.findAllEmployees()); employeeComboBox.setItems(employeeService.findAllEmployees());
employeeComboBox.setItemLabelGenerator(employee -> employee.getFirstName() + " " + employee.getLastName()); employeeComboBox.setItemLabelGenerator(employee -> employee.getFirstName()
+ " " + employee.getLastName());
employeeComboBox.setAllowCustomValue(false); employeeComboBox.setAllowCustomValue(false);
employeeComboBox.addCustomValueSetListener(event -> employeeComboBox.addCustomValueSetListener(event ->
Notification.show("Selecciona un empleado válido de la lista.") Notification.show("Selecciona un empleado válido de la lista.")
@ -134,14 +144,12 @@ public class HoursWorkedView extends VerticalLayout {
} }
private void configurarVista() { private void configurarVista() {
fechaPicker.setMax(LocalDate.now());
fechaPicker.addValueChangeListener(event -> { fechaPicker.addValueChangeListener(event -> {
LocalDate selectedDate = event.getValue(); LocalDate selectedDate = event.getValue();
if (selectedDate != null) { if (selectedDate != null) {
selectedStartOfWeek = getStartOfWeek(selectedDate); selectedStartOfWeek = getStartOfWeek(selectedDate);
LocalDate endOfWeek = selectedStartOfWeek.plusDays(6);
weekNumber = getWeekOfYear(selectedDate); weekNumber = getWeekOfYear(selectedDate);
fechasLabel.setText("Semana del " + selectedStartOfWeek + " al " + endOfWeek);
numeroSemanaLabel.setText("Número de la Semana: " + weekNumber);
cargarDatos(); cargarDatos();
} }
}); });
@ -178,12 +186,14 @@ public class HoursWorkedView extends VerticalLayout {
HorizontalLayout buttonsLayout = new HorizontalLayout(actualizarButton, guardarButton, HorizontalLayout buttonsLayout = new HorizontalLayout(actualizarButton, guardarButton,
cerrarButton, verMesButton); cerrarButton, verMesButton);
VerticalLayout totalesLayout = new VerticalLayout(totalCompletadoLabel, horasPendientesLabel); VerticalLayout totalesLayout = new VerticalLayout(totalCompletadoLabel,
horasPendientesLabel);
totalesLayout.setSpacing(true); totalesLayout.setSpacing(true);
totalesLayout.setPadding(true); totalesLayout.setPadding(true);
add(fechaPicker, fechasLabel, numeroSemanaLabel, filtersLayout, actividadFormLayout, add(fechaPicker, filtersLayout, actividadFormLayout,
tareasEspecificasLayout, grid, gridActividadesEspecificas, buttonsLayout, totalesLayout); equipoLabel, grid, empresaLabel, tareasEspecificasLayout,
gridActividadesEspecificas, buttonsLayout, totalesLayout);
} }
private void configurarGrid() { private void configurarGrid() {
@ -198,6 +208,7 @@ public class HoursWorkedView extends VerticalLayout {
grid.addColumn(Actividad::getSabado).setHeader("Sábado"); grid.addColumn(Actividad::getSabado).setHeader("Sábado");
grid.addColumn(Actividad::getDomingo).setHeader("Domingo"); grid.addColumn(Actividad::getDomingo).setHeader("Domingo");
grid.addColumn(this::calcularTotalPorDia).setHeader("Total Día").setKey("totalDia"); grid.addColumn(this::calcularTotalPorDia).setHeader("Total Día").setKey("totalDia");
grid.setItems(actividades);
} }
private void configurarGridActividadesEspecificas() { private void configurarGridActividadesEspecificas() {
@ -228,6 +239,13 @@ public class HoursWorkedView extends VerticalLayout {
Notification.show("Por favor, selecciona una fecha."); Notification.show("Por favor, selecciona una fecha.");
return; return;
} }
int selectedWeekNumber = getWeekOfYear(selectedDate);
if (selectedWeekNumber != weekNumber) {
Notification.show("Solo puedes agregar actividades dentro de la semana actual.");
return;
}
DayOfWeek selectedDay = selectedDate.getDayOfWeek(); DayOfWeek selectedDay = selectedDate.getDayOfWeek();
Actividad.Builder actividadBuilder = new Actividad.Builder() Actividad.Builder actividadBuilder = new Actividad.Builder()
@ -258,6 +276,10 @@ public class HoursWorkedView extends VerticalLayout {
actividades.add(nuevaActividad); actividades.add(nuevaActividad);
grid.setItems(actividades); grid.setItems(actividades);
} }
Actividad nuevaActividad = actividadBuilder.build();
agregarOActualizarActividad(nuevaActividad, selectedDay, horas);
actualizarTotales(); actualizarTotales();
Notification.show("Actividad agregada correctamente"); Notification.show("Actividad agregada correctamente");
actividadNombre.clear(); actividadNombre.clear();
@ -272,6 +294,44 @@ public class HoursWorkedView extends VerticalLayout {
return new HorizontalLayout(actividadNombre, horasInput, agregarActividadButton); return new HorizontalLayout(actividadNombre, horasInput, agregarActividadButton);
} }
private void agregarOActualizarActividad(final Actividad nuevaActividad, final DayOfWeek dia, final double horas) {
Actividad actividadExistente = actividades.stream()
.filter(a -> a.getNombre().equals(nuevaActividad.getNombre()))
.findFirst()
.orElse(null);
if (actividadExistente != null) {
// Si la actividad ya existe, actualiza las horas para el día correspondiente
switch (dia) {
case MONDAY -> actividadExistente.setLunes(horas);
case TUESDAY -> actividadExistente.setMartes(horas);
case WEDNESDAY -> actividadExistente.setMiercoles(horas);
case THURSDAY -> actividadExistente.setJueves(horas);
case FRIDAY -> actividadExistente.setViernes(horas);
case SATURDAY -> actividadExistente.setSabado(horas);
case SUNDAY -> actividadExistente.setDomingo(horas);
default -> throw new IllegalArgumentException("Día seleccionado no válido: " + dia);
}
} else {
// Si no existe, se agrega como nueva actividad
switch (dia) {
case MONDAY -> nuevaActividad.setLunes(horas);
case TUESDAY -> nuevaActividad.setMartes(horas);
case WEDNESDAY -> nuevaActividad.setMiercoles(horas);
case THURSDAY -> nuevaActividad.setJueves(horas);
case FRIDAY -> nuevaActividad.setViernes(horas);
case SATURDAY -> nuevaActividad.setSabado(horas);
case SUNDAY -> nuevaActividad.setDomingo(horas);
default -> throw new IllegalArgumentException("Día seleccionado no válido: " + dia);
}
actividades.add(nuevaActividad);
}
// Actualiza el Grid
grid.setItems(actividades);
}
private HorizontalLayout configurarTareasEspecificasLayout() { private HorizontalLayout configurarTareasEspecificasLayout() {
Button agregarTareaButton = new Button("Agregar Tarea PFS", e -> { Button agregarTareaButton = new Button("Agregar Tarea PFS", e -> {
@ -354,7 +414,7 @@ public class HoursWorkedView extends VerticalLayout {
private LocalDate getStartOfWeek(final LocalDate date) { private LocalDate getStartOfWeek(final LocalDate date) {
WeekFields weekFields = WeekFields.of(Locale.getDefault()); WeekFields weekFields = WeekFields.of(Locale.getDefault());
return date.with(weekFields.dayOfWeek(), DayOfWeek.MONDAY.getValue()); return date.with(weekFields.dayOfWeek(), DayOfWeek.FRIDAY.getValue());
} }
private double calcularTotalPorDia(final Actividad actividad) { private double calcularTotalPorDia(final Actividad actividad) {
@ -385,24 +445,71 @@ public class HoursWorkedView extends VerticalLayout {
return; return;
} }
// Verificar que hay actividades para guardar
if (actividades.isEmpty()) {
Notification.show("No hay actividades para guardar.");
return;
}
// Sumar el total de horas para la semana
double totalHorasSemana = actividades.stream() double totalHorasSemana = actividades.stream()
.mapToDouble(this::calcularTotalPorDia) .mapToDouble(this::calcularTotalPorDia)
.sum(); .sum();
HoursWorked hoursWorked = new HoursWorked(); // Crear un objeto HoursWorked por cada actividad
hoursWorked.setEmployee(selectedEmployee); List<HoursWorked> savedHoursWorked = new ArrayList<>(); // Para almacenar los objetos guardados
hoursWorked.setWeekNumber(weekNumber);
hoursWorked.setTotalHours(totalHorasSemana);
try { // Recorrer todas las actividades y guardar un registro para cada una
hoursWorkedService.saveHoursWorked(hoursWorked); // Usa saveHoursWorked directamente for (Actividad actividad : actividades) {
Notification.show("Actividades guardadas correctamente."); HoursWorked hoursWorked = new HoursWorked();
System.out.println(hoursWorked); hoursWorked.setEmployee(selectedEmployee);
} catch (Exception e) { hoursWorked.setWeekNumber(weekNumber);
Notification.show("Error al guardar actividades: " + e.getMessage()); hoursWorked.setTotalHours(totalHorasSemana);
// Asignar cada actividad individualmente
hoursWorked.setActividad(actividad);
hoursWorked.setFecha(LocalDate.now()); // Establecer la fecha actual o la seleccionada si es otra
// Mostrar información de la actividad para depuración
System.out.println("Guardando actividad: " + actividad.getNombre()
+ " con " + totalHorasSemana + " horas.");
try {
// Guardar en el servicio
hoursWorkedService.saveHoursWorked(hoursWorked);
savedHoursWorked.add(hoursWorked); // Agregar a la lista de registros guardados
Notification.show("Actividad guardada correctamente: " + actividad.getNombre());
} catch (Exception e) {
Notification.show("Error al guardar la actividad: " + actividad.getNombre()
+ " - " + e.getMessage());
}
} }
// Mostrar los registros guardados
savedHoursWorked.forEach(hw -> System.out.println("Horas trabajadas guardadas: " + hw));
// Crear el Grid
Grid<HoursWorked> grid = new Grid<>();
// Configurar columnas para mostrar la información deseada
grid.addColumn(hw -> hw.getEmployee().getFirstName()).setHeader("Empleado");
grid.addColumn(hw -> hw.getEmployee().getId()).setHeader("ID Empleado");
grid.addColumn(hw -> hw.getActividad().getNombre()).setHeader("Actividad");
grid.addColumn(hw -> hw.getTotalHours()).setHeader("Horas Trabajadas");
grid.addColumn(hw -> hw.getWeekNumber()).setHeader("Número de Semana");
grid.addColumn(hw -> hw.getFecha().toString()).setHeader("Fecha");
// Llenar el Grid con los datos de savedHoursWorked
grid.setItems(savedHoursWorked);
// Agregar el Grid a la vista
add(grid);
} }
private double calcularTotalHoras(final List<HoursWorked> listaDeHorasTrabajadas) { private double calcularTotalHoras(final List<HoursWorked> listaDeHorasTrabajadas) {
return listaDeHorasTrabajadas.stream() return listaDeHorasTrabajadas.stream()
.mapToDouble(HoursWorked::getTotalHours) .mapToDouble(HoursWorked::getTotalHours)

View File

@ -50,7 +50,6 @@ public class ReporteView extends VerticalLayout {
private final Span semanaInfoSpan = new Span(); private final Span semanaInfoSpan = new Span();
// Obtener el año actual // Obtener el año actual
private int currentYear = LocalDate.now().getYear(); private int currentYear = LocalDate.now().getYear();
@ -76,22 +75,19 @@ public class ReporteView extends VerticalLayout {
// Listener para actualizar `semanaInfoSpan` con la selección del usuario en `semanaComboBox` // Listener para actualizar `semanaInfoSpan` con la selección del usuario en `semanaComboBox`
semanaComboBox.addValueChangeListener(event -> { semanaComboBox.addValueChangeListener(event -> {
String selectedWeek = event.getValue(); String selectedWeek = event.getValue();
semanaInfoSpan.setText(selectedWeek != null semanaInfoSpan.setText(selectedWeek != null ? selectedWeek : "Selecciona una semana");
? selectedWeek : "Selecciona una semana");
}); });
Button reportButton = new Button("Generar Reporte de Horas Trabajadas", Button reportButton = new Button("Generar Reporte de Horas Trabajadas",
event -> generateHoursWorkedReport()); event -> generateHoursWorkedReport());
HorizontalLayout filtersLayout = new HorizontalLayout(equipoComboBox, HorizontalLayout filtersLayout = new HorizontalLayout(equipoComboBox, semanaComboBox, reportButton);
semanaComboBox, reportButton);
add(filtersLayout); add(filtersLayout);
// Añadir `headerLayout` al diseño principal para el encabezado dinámico // Añadir `headerLayout` al diseño principal para el encabezado dinámico
add(headerLayout); add(headerLayout);
updateHeaderLayout(null, null); updateHeaderLayout(null, null);
grid.addColumn(map -> map.get("ID")).setHeader("ID") grid.addColumn(map -> map.get("ID")).setHeader("ID").getElement().getStyle().set("font-weight", "bold");
.getElement().getStyle().set("font-weight", "bold");
grid.addColumn(map -> map.get("Employee ID")).setHeader("Employee ID"); grid.addColumn(map -> map.get("Employee ID")).setHeader("Employee ID");
grid.addColumn(map -> map.get("Empleado")).setHeader("Empleado"); grid.addColumn(map -> map.get("Empleado")).setHeader("Empleado");
grid.addColumn(map -> map.get("Horas Trabajadas")).setHeader("Horas Trabajadas"); grid.addColumn(map -> map.get("Horas Trabajadas")).setHeader("Horas Trabajadas");
@ -105,8 +101,7 @@ public class ReporteView extends VerticalLayout {
int year = LocalDate.now().getYear(); int year = LocalDate.now().getYear();
LocalDate startOfYear = LocalDate.of(year, 1, 5); // Suponemos que la semana comienza el 5 de enero. LocalDate startOfYear = LocalDate.of(year, 1, 5); // Suponemos que la semana comienza el 5 de enero.
List<String> semanas = startOfYear.datesUntil(LocalDate List<String> semanas = startOfYear.datesUntil(LocalDate.of(year + 1, 1, 1),
.of(year + 1, 1, 1),
java.time.Period.ofWeeks(1)) java.time.Period.ofWeeks(1))
.map(date -> { .map(date -> {
int weekNumber = date.get(WeekFields.of(DayOfWeek.MONDAY, 1) int weekNumber = date.get(WeekFields.of(DayOfWeek.MONDAY, 1)
@ -133,27 +128,23 @@ public class ReporteView extends VerticalLayout {
String selectedWeek = semanaComboBox.getValue(); String selectedWeek = semanaComboBox.getValue();
if (selectedEquipo == null || selectedWeek == null) { if (selectedEquipo == null || selectedWeek == null) {
Notification.show("Por favor, selecciona un equipo y una semana para generar el reporte.", Notification.show("Por favor, selecciona un equipo y una semana para generar el reporte.",
3000, 3000, Notification.Position.MIDDLE);
Notification.Position.MIDDLE);
return; return;
} }
int weekNumber = Integer.parseInt(selectedWeek.split(" ")[1] int weekNumber = Integer.parseInt(selectedWeek.split(" ")[1].replace(":", ""));
.replace(":", "")); LocalDate selectedDate = LocalDate.now().with(WeekFields.of(DayOfWeek.FRIDAY, 1)
LocalDate selectedDate = LocalDate.now() .weekOfWeekBasedYear(), weekNumber);
.with(WeekFields.of(DayOfWeek.FRIDAY, 1)
.weekOfWeekBasedYear(), weekNumber);
updateHeaderLayout(selectedEquipo, selectedDate); updateHeaderLayout(selectedEquipo, selectedDate);
List<HoursWorked> hoursWorkedList = hoursWorkedService.findAll().stream() List<HoursWorked> hoursWorkedList = hoursWorkedService.findAll().stream()
.filter(hw -> hw.getEmployee().getTeam().getId() .filter(hw -> hw.getEmployee().getTeam().getId().equals(selectedEquipo
.equals(selectedEquipo.getId()) && hw.getWeekNumber() == weekNumber) .getId()) && hw.getWeekNumber() == weekNumber)
.collect(Collectors.toList()); .collect(Collectors.toList());
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, 3000, Notification.Position.MIDDLE);
Notification.Position.MIDDLE);
return; return;
} }
@ -188,8 +179,8 @@ public class ReporteView extends VerticalLayout {
String formattedEndDate = endOfWeek.getDayOfMonth() + " de " String formattedEndDate = endOfWeek.getDayOfMonth() + " de "
+ endOfWeek.getMonth().getDisplayName(TextStyle.FULL, Locale.getDefault()); + endOfWeek.getMonth().getDisplayName(TextStyle.FULL, Locale.getDefault());
headerLayout.add(new Span("Informe " + String.format("%03d", weekNumber) headerLayout.add(new Span("Informe "
+ "/" + currentYear) {{ + String.format("%03d", weekNumber) + "/" + currentYear) {{
getStyle().set("font-size", "24px"); getStyle().set("font-size", "24px");
getStyle().set("font-weight", "bold"); getStyle().set("font-weight", "bold");
}}); }});
@ -213,14 +204,13 @@ public class ReporteView extends VerticalLayout {
} }
} }
private void generateExcelDownloadLink(final List<Map<String, Object>> data, private void generateExcelDownloadLink(final List<Map<String, Object>> data, final int weekNumber) {
final int weekNumber) {
try { try {
List<String> headers = List.of("ID", "Employee ID", "Empleado", List<String> headers = List.of("ID", "Employee ID", "Empleado",
"Horas Trabajadas", "Horas Pendientes", "Observaciones"); "Horas Trabajadas", "Horas Pendientes", "Observaciones");
String selectedTeam = equipoComboBox.getValue().getName(); String selectedTeam = equipoComboBox.getValue().getName();
byte[] excelBytes = reportService.writeAsExcel("hours_worked_report", byte[] excelBytes = reportService.writeAsExcel(
headers, data, selectedTeam, weekNumber, currentYear); "hours_worked_report", headers, data, selectedTeam, weekNumber, currentYear);
StreamResource excelResource = new StreamResource("hours_worked_report.xlsx", StreamResource excelResource = new StreamResource("hours_worked_report.xlsx",
() -> new ByteArrayInputStream(excelBytes)); () -> new ByteArrayInputStream(excelBytes));
@ -241,13 +231,4 @@ public class ReporteView extends VerticalLayout {
return date.get(WeekFields.of(Locale.getDefault()).weekOfWeekBasedYear()); return date.get(WeekFields.of(Locale.getDefault()).weekOfWeekBasedYear());
} }
public int getCurrentYear() {
return currentYear;
}
// Opcional: Si deseas permitir cambiar el año actual manualmente, agrega un setter
public void setCurrentYear(final int currentYear) {
this.currentYear = currentYear;
}
} }