Skip to content

Commit b03774b

Browse files
committed
version 0.7
1 parent c9afbc7 commit b03774b

File tree

11 files changed

+20
-25
lines changed

11 files changed

+20
-25
lines changed

src/main/java/com/cibertec/shoesformen_api/MySQLConfig.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
import org.springframework.boot.orm.jpa.EntityManagerFactoryBuilder;
77
import org.springframework.context.annotation.Bean;
88
import org.springframework.context.annotation.Configuration;
9-
import org.springframework.context.annotation.Primary;
109
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
1110
import org.springframework.orm.jpa.JpaTransactionManager;
1211
import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean;

src/main/java/com/cibertec/shoesformen_api/PostgreSQLConfig.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
11
package com.cibertec.shoesformen_api;
22

3-
import jakarta.persistence.EntityManagerFactory;
43
import org.springframework.beans.factory.annotation.Qualifier;
54

6-
import org.springframework.beans.factory.annotation.Qualifier;
75
import org.springframework.boot.autoconfigure.jdbc.DataSourceProperties;
86
import org.springframework.boot.context.properties.ConfigurationProperties;
9-
import org.springframework.boot.jdbc.DataSourceBuilder;
107
import org.springframework.boot.orm.jpa.EntityManagerFactoryBuilder; // <------------------------
118
import org.springframework.context.annotation.Bean;
129
import org.springframework.context.annotation.Configuration;

src/main/java/com/cibertec/shoesformen_api/a_empresa/EmpresaRepository.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package com.cibertec.shoesformen_api.a_empresa;
22

3-
import com.cibertec.shoesformen_api.a_empresa.Empresa;
3+
44
import org.springframework.data.jpa.repository.JpaRepository;
55
import org.springframework.stereotype.Repository;
66

src/main/java/com/cibertec/shoesformen_api/controller/EmpleadoController.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package com.cibertec.shoesformen_api.controller;
22

3-
import com.cibertec.shoesformen_api.exception.EmpleadoNotFoundException;
43
import com.cibertec.shoesformen_api.exception.EntidadNotFoundException;
54
import com.cibertec.shoesformen_api.exception.ListEmptyException;
65
import com.cibertec.shoesformen_api.model.Empleado;
@@ -13,6 +12,7 @@
1312
import jakarta.validation.Valid;
1413
import net.sf.jasperreports.engine.JRException;
1514
import org.springframework.beans.factory.annotation.Autowired;
15+
import org.springframework.core.io.Resource;
1616
import org.springframework.http.HttpStatus;
1717
import org.springframework.http.MediaType;
1818
import org.springframework.http.ResponseEntity;
@@ -74,14 +74,15 @@ public ResponseEntity delete(@PathVariable String id) throws IllegalArgumentExce
7474
}
7575
}
7676

77-
@GetMapping("/rpt_EXCEL")
78-
private ResponseEntity<Void> reporteEmpleadoEXCEL(HttpServletResponse response) throws JRException, IOException {
77+
@GetMapping(value = "/rpt_EXCEL", produces = MediaType.MULTIPART_FORM_DATA_VALUE)
78+
private ResponseEntity<Resource> reporteEmpleadoEXCEL(HttpServletResponse response) throws JRException, IOException {
7979
empleadoServ.exportarReporte("excel", response);
8080
return ResponseEntity.ok().build();
8181
}
8282

8383
@GetMapping(value = "/rpt_PDF", produces = MediaType.APPLICATION_PDF_VALUE)
8484
private ResponseEntity<Void> reporteEmpleadoPDF(HttpServletResponse response) throws JRException,IOException{
85+
response.setHeader("","");
8586
empleadoServ.exportarReporte("pdf", response);
8687
return ResponseEntity.ok().build();
8788
}

src/main/java/com/cibertec/shoesformen_api/exception/ApplicationExceptionHandler.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
package com.cibertec.shoesformen_api.exception;
22

3-
import org.postgresql.util.PSQLException;
43
import org.springframework.http.HttpStatus;
54
import org.springframework.http.ResponseEntity;
65
import org.springframework.web.bind.MethodArgumentNotValidException;
76
import org.springframework.web.bind.annotation.ExceptionHandler;
87
import org.springframework.web.bind.annotation.ResponseStatus;
9-
import org.springframework.web.bind.annotation.RestController;
108
import org.springframework.web.bind.annotation.RestControllerAdvice;
119

1210
import java.sql.SQLException;

src/main/java/com/cibertec/shoesformen_api/model/dto/EmpleadoDTO.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
import lombok.AllArgsConstructor;
88
import lombok.Data;
99

10-
import java.util.Collection;
1110

1211
@Data
1312
@AllArgsConstructor()

src/main/java/com/cibertec/shoesformen_api/repository/EmpleadoRepository.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package com.cibertec.shoesformen_api.repository;
22

33
import com.cibertec.shoesformen_api.model.Empleado;
4-
import com.cibertec.shoesformen_api.model.dto.EmpleadoDTO;
54
import com.cibertec.shoesformen_api.model.pojo.EmpleadoPOJO;
65
import org.springframework.data.jpa.repository.JpaRepository;
76
import org.springframework.data.jpa.repository.Query;
@@ -31,7 +30,7 @@ public interface EmpleadoRepository extends JpaRepository<Empleado, String> {
3130

3231
// CONSULTA NATIVA
3332
@Query(value="SELECT CONCAT('EM',CAST(SUBSTRING(MAX(e.cod_empleado),3) AS INT) + 1) FROM empleado AS e", nativeQuery = true)
34-
public abstract String getUltimoCodigo();
33+
public abstract String getNuevoCodigo();
3534

3635
// Automatico
3736
public abstract Empleado findByUsuario(String usuario);

src/main/java/com/cibertec/shoesformen_api/service/EmpleadoService.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,12 @@
11
package com.cibertec.shoesformen_api.service;
22

3-
import com.cibertec.shoesformen_api.exception.EmpleadoNotFoundException;
43
import com.cibertec.shoesformen_api.exception.EntidadNotFoundException;
54
import com.cibertec.shoesformen_api.exception.ListEmptyException;
65
import com.cibertec.shoesformen_api.model.Empleado;
76
import com.cibertec.shoesformen_api.model.dto.EmpleadoDTO;
87
import jakarta.servlet.http.HttpServletResponse;
98
import net.sf.jasperreports.engine.JRException;
10-
import org.springframework.http.ResponseEntity;
119

12-
import javax.management.JMRuntimeException;
1310
import java.io.IOException;
1411
import java.util.List;
1512
import java.util.Optional;

src/main/java/com/cibertec/shoesformen_api/service/EmpleadoServiceImpl.java

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package com.cibertec.shoesformen_api.service;
22

3+
import com.cibertec.shoesformen_api.a_empresa.Empresa;
4+
import com.cibertec.shoesformen_api.a_empresa.EmpresaRepository;
35
import com.cibertec.shoesformen_api.exception.EntidadNotFoundException;
46
import com.cibertec.shoesformen_api.exception.ListEmptyException;
57
import com.cibertec.shoesformen_api.model.Distrito;
@@ -22,7 +24,6 @@
2224
import org.springframework.http.HttpHeaders;
2325
import org.springframework.stereotype.Service;
2426

25-
import javax.management.JMRuntimeException;
2627
import java.io.FileInputStream;
2728
import java.io.IOException;
2829
import java.text.SimpleDateFormat;
@@ -39,6 +40,8 @@ public class EmpleadoServiceImpl implements EmpleadoService{
3940
private EstadoRepository estadoRepo;
4041
@Autowired
4142
private RolRepository rolRepo;
43+
@Autowired
44+
private EmpresaRepository empresaRepo;
4245

4346

4447
@Override
@@ -67,7 +70,7 @@ public Optional<Empleado> getEmpleadoByCodigo(String codigo) throws EntidadNotFo
6770

6871
@Override
6972
public String createNewCodigo() {
70-
String codigo_ultimo = empleadoRepo.getUltimoCodigo();
73+
String codigo_ultimo = empleadoRepo.getNuevoCodigo();
7174
String codigo_nuevo = "EM10001";
7275
if(codigo_ultimo != null){
7376
return codigo_ultimo;
@@ -118,14 +121,16 @@ public void exportarReporte(String tipo, HttpServletResponse response) throws JR
118121
String fecha1 = formato1.format(fecha);
119122
String fecha2 = formato2.format(fecha);
120123

121-
String imagen = "logo_reporte_2.png";
122-
parametros.put("imagen_logo","src/main/resources/static/img/" + imagen);
123-
parametros.put("nombre_empresa","SHOES FOR MEN");
124+
Empresa empresa = empresaRepo.findById("EP1").orElseThrow(() -> new EntidadNotFoundException("EP1"));
125+
//String imagen = "logo_reporte_01.png";
126+
//parametros.put("imagen_logo","src/main/resources/static/img/" + imagen);
127+
parametros.put("imagen_logo",empresa.getImagen());
128+
parametros.put("nombre_empresa",empresa.getNombre().toUpperCase());
124129
parametros.put("direccion_empresa","AV. URUGUAY N 000 ");
125130
parametros.put("distrito_empresa","SAN ISIDRO");
126131
parametros.put("nombre_empleado","KEVIN B");
127-
parametros.put("ruc_empresa","55555555555");
128-
parametros.put("telefono_empresa","777-7777");
132+
parametros.put("ruc_empresa",empresa.getRuc());
133+
parametros.put("telefono_empresa",empresa.getTelefono());
129134
parametros.put("fecha_generacion", fecha1);
130135
parametros.put("DataEmpleado", dataSource);
131136

@@ -144,9 +149,9 @@ public void exportarReporte(String tipo, HttpServletResponse response) throws JR
144149
else if(tipo.equalsIgnoreCase("excel")) {
145150
JRXlsxExporter exporter = new JRXlsxExporter(); // la configuracion se hace en el mismo JASPER STUDIO
146151
exporter.setExporterInput(new SimpleExporterInput(jasperPrint)); //
147-
response.setContentType("application/octet-stream");
148152
exporter.setExporterOutput(new SimpleOutputStreamExporterOutput(response.getOutputStream()));
149-
response.setHeader(HttpHeaders.CONTENT_DISPOSITION, "attachment;filename=listaEmpleado_" + fecha2 + ".xlsx");
153+
response.setContentType("application/vnd.ms-excel");
154+
response.setHeader(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=listaEmpleado_" + fecha2 + ".xlsx");
150155
exporter.exportReport();
151156
}
152157

File renamed without changes.

0 commit comments

Comments
 (0)