Consumo facturacion autorizacion augtorizacion

parent ab1d80dc
......@@ -43,6 +43,7 @@
<dependency>
<groupId>org.springframework.batch</groupId>
<artifactId>spring-batch-core</artifactId>
<version>4.2.4.RELEASE</version>
</dependency>
<dependency>
......
......@@ -78,9 +78,9 @@ public class Task_autorizacion implements Tasklet {
offlineAutorizacionDTO= this.autorizacion(dto.getNumautoriza());
if(offlineRecepcionDTO!=null){
if(offlineAutorizacionDTO!=null){
if(offlineRecepcionDTO.getEstado().equals("AUTORIZADO")){
if(offlineAutorizacionDTO.getEstado().equals("AUTORIZADO")){
dto.setFechaautoriza(offlineAutorizacionDTO.getFechaAutorizacion().toString());
dto.setEstadoFactura(offlineAutorizacionDTO.getEstado());
......@@ -121,7 +121,7 @@ public class Task_autorizacion implements Tasklet {
try {
RespuestaSolicitud respuesta = new RespuestaSolicitud();
byte[] bytes = val.getBytes();
byte[] bytes = xml.getBytes();
String wsdl = "https://cel.sri.gob.ec/comprobantes-electronicos-ws/RecepcionComprobantesOffline?wsdl";
URL url = new URL(wsdl);
......@@ -170,45 +170,48 @@ public class Task_autorizacion implements Tasklet {
offlineDTO.setEstado("DEVUELTA - SN");
}
}
}else{
if (respuesta.getEstado().equals("DEVUELTA")) {
try {
offlineDTO.setMensaje(respuesta.getComprobantes().getComprobante().get(0).getMensajes().getMensaje().get(0).getMensaje());
} catch (Exception e) {
offlineDTO.setMensaje("NINGUN MENSAJE ENCOTRADO");
}
if (respuesta.getEstado().equals("DEVUELTA")) {
try {
offlineDTO.setMensaje(respuesta.getComprobantes().getComprobante().get(0).getMensajes().getMensaje().get(0).getMensaje());
} catch (Exception e) {
offlineDTO.setMensaje("NINGUN MENSAJE ENCOTRADO");
}
try {
offlineDTO.setInfoAdicional(respuesta.getComprobantes().getComprobante().get(0).getMensajes().getMensaje().get(0).getInformacionAdicional());
} catch (Exception e) {
offlineDTO.setInfoAdicional("NO DEFINIDO");
}
try {
offlineDTO.setInfoAdicional(respuesta.getComprobantes().getComprobante().get(0).getMensajes().getMensaje().get(0).getInformacionAdicional());
} catch (Exception e) {
offlineDTO.setInfoAdicional("NO DEFINIDO");
}
try {
offlineDTO.setIdentificador(Integer.valueOf(respuesta.getComprobantes().getComprobante().get(0).getMensajes().getMensaje().get(0).getIdentificador()));
} catch (Exception e) {
offlineDTO.setIdentificador(0);
}
try {
offlineDTO.setIdentificador(Integer.valueOf(respuesta.getComprobantes().getComprobante().get(0).getMensajes().getMensaje().get(0).getIdentificador()));
} catch (Exception e) {
offlineDTO.setIdentificador(0);
}
try {
offlineDTO.setTipo(respuesta.getComprobantes().getComprobante().get(0).getMensajes().getMensaje().get(0).getTipo());
} catch (Exception e) {
offlineDTO.setTipo("ERROR");
}
try {
offlineDTO.setClaveAcceso(respuesta.getComprobantes().getComprobante().get(0).getClaveAcceso());
} catch (Exception e) {
offlineDTO.setClaveAcceso("NO DEFINIDO");
}
try {
offlineDTO.setTipo(respuesta.getComprobantes().getComprobante().get(0).getMensajes().getMensaje().get(0).getTipo());
} catch (Exception e) {
offlineDTO.setTipo("ERROR");
offlineDTO.setEstado("DEVUELTA");
}
try {
offlineDTO.setClaveAcceso(respuesta.getComprobantes().getComprobante().get(0).getClaveAcceso());
} catch (Exception e) {
offlineDTO.setClaveAcceso("NO DEFINIDO");
if (respuesta.getEstado().equals("RECIBIDA")) {
offlineDTO.setEstado("RECIBIDA");
}
offlineDTO.setEstado("DEVUELTA");
}
if (respuesta.getEstado().equals("RECIBIDA")) {
offlineDTO.setEstado("RECIBIDA");
}
System.out.println("ESTADO FACTURA " + respuesta.getEstado());
......@@ -216,7 +219,7 @@ public class Task_autorizacion implements Tasklet {
} catch (Exception e) {
return null;
return offlineDTO;
}
}
......@@ -351,7 +354,7 @@ public class Task_autorizacion implements Tasklet {
String text = cabecera + cuerpoF + pie;
EmailService emailService= new EmailService();
emailService.sendEmail(para, subject, text, "");
emailService.sendEmail(para, subject, text, "", factura.getIdFactura());
}
}
......
......@@ -62,7 +62,7 @@ public class Task_cargaDocumentacion implements Tasklet {
/**OBTENER LA FECHA ACTUAL**/
Date date = new Date();
DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
listFact= consultas.consumoFactContingencia(dateFormat.format(date));
listFact= consultas.consumoFactPDF(dateFormat.format(date));
/**RECORREMOS LA LISTA DE FACTURAS PARA SU AUTORIZACION*/
if(listFact!=null) {
for (FacturaDTO dto : listFact) {
......@@ -165,7 +165,7 @@ public class Task_cargaDocumentacion implements Tasklet {
String text = cabecera + cuerpoF + pie;
EmailService emailService= new EmailService();
emailService.sendEmail(para, subject, text, attachment);
emailService.sendEmail(para, subject, text, attachment, factura.getIdFactura());
}
}
......
......@@ -98,7 +98,7 @@ public class ConsultasFacturacionController implements Serializable {
try {
listFact= jdbcTemplate().query("SELECT * FROM \"Facturacion\".factura WHERE fechafac like ? ", BeanPropertyRowMapper.newInstance(FacturaDTO.class), fecha);
listFact= jdbcTemplate().query("SELECT * FROM \"Facturacion\".factura WHERE fechafac_f like ? AND estado_sri LIKE '%CONTINGENCIA%'", BeanPropertyRowMapper.newInstance(FacturaDTO.class), "%" + fecha + "%");
return listFact;
......@@ -114,7 +114,7 @@ public class ConsultasFacturacionController implements Serializable {
try {
listFact= jdbcTemplate().query("SELECT * FROM \"Facturacion\".factura WHERE path IS NULL AND estado_sri = 'AUTORIZADO' AND fechafac like ? ", BeanPropertyRowMapper.newInstance(FacturaDTO.class), fecha);
listFact= jdbcTemplate().query("SELECT * FROM \"Facturacion\".factura WHERE path IS NULL AND estado_sri = 'AUTORIZADO' AND fechafac_f like ? ", BeanPropertyRowMapper.newInstance(FacturaDTO.class), "%" + fecha + "%");
return listFact;
......
......@@ -59,8 +59,8 @@ public class GeneracionFactOfflinePDF {
DateFormat fecha = new SimpleDateFormat("dd/MM/yyyy");
DateFormat fechaMs = new SimpleDateFormat("dd/MM/yyyy hh:mm:ss");
hoyFecha = fecha.format(hoy);
//String locate = "/FacturaUtils/";
String locate = "C:/facturacion_electronica/facturaUtils/";
String locate = "/datos/FacturaUtils/";
//String locate = "C:/facturacion_electronica/facturaUtils/";
System.out.println("-->" + locate);
......
......@@ -22,7 +22,8 @@ public class GeneracionFactOfflineXML {
BufferedWriter writer = null;
String pathXml="";
pathXml = "C:/facturacion_electronica/facturaUtils/" + factura.getRucCli().trim() + "-" + factura.getIdFactura().trim() + ".xml";
//pathXml = "C:/facturacion_electronica/facturaUtils/" + factura.getRucCli().trim() + "-" + factura.getIdFactura().trim() + ".xml";
pathXml = "/datos/FacturaUtils/" + factura.getRucCli().trim() + "-" + factura.getIdFactura().trim() + ".xml";
File file = new File(pathXml);
try {
......
package ec.edu.epn.consumosriautorizacion.controller;
import ec.edu.epn.consumosriautorizacion.Tasks.Task_autorizacion;
import ec.edu.epn.consumosriautorizacion.Tasks.Task_cargaDocumentacion;
import ec.edu.epn.consumosriautorizacion.dto.DetallefacturaDTO;
import ec.edu.epn.consumosriautorizacion.dto.FacturaDTO;
import ec.edu.epn.consumosriautorizacion.dto.FacturacionOfflineDTO;
......@@ -22,6 +24,7 @@ import java.io.InputStream;
import java.net.URL;
import javax.xml.namespace.QName;
import org.springframework.batch.repeat.RepeatStatus;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
......@@ -47,143 +50,18 @@ public class SriAutorizacionController {
@GetMapping("/pruebas")
public String pruebas() throws FTPErrors, FileNotFoundException {
ftpService.connectToFTP();
// ConsultasFacturacionController consulta= new ConsultasFacturacionController();
FacturaDTO facturaDTO= new FacturaDTO();
List<DetallefacturaDTO> listDetalle= new ArrayList<DetallefacturaDTO>();
List<PagosDTO> listPagos= new ArrayList<PagosDTO>();
facturaDTO= consultas.consumoFactura("001-003-0077105");
listDetalle= consultas.consumoDetalleFact(facturaDTO.getIdFactura());
listPagos= consultas.consumoPagos(facturaDTO.getIdFactura());
GeneracionFactOfflinePDF pdf= new GeneracionFactOfflinePDF();
String attchment= pdf.generarPDFFacturaOffline(facturaDTO, listDetalle, listPagos);
BufferedInputStream buffIn = null;
buffIn = new BufferedInputStream(new FileInputStream(attchment));
ftpService.uploadFileToFTP(buffIn, "1720812633_Facturas", "001-001_german");
return "PRUEBA EXITOSA";
}
@GetMapping("/recepcion/{xml}")
public FacturacionOfflineDTO recepcion(@PathVariable String xml){
String val = "";
FacturacionOfflineDTO offlineDTO = new FacturacionOfflineDTO();
try {
RespuestaSolicitud respuesta = new RespuestaSolicitud();
byte[] bytes = val.getBytes();
String wsdl = "https://cel.sri.gob.ec/comprobantes-electronicos-ws/RecepcionComprobantesOffline?wsdl";
URL url = new URL(wsdl);
QName qname = new QName("http://ec.gob.sri.ws.recepcion", "RecepcionComprobantesOfflineService");
RecepcionComprobantesOfflineService service = new RecepcionComprobantesOfflineService(url, qname);
RecepcionComprobantesOffline port = service.getRecepcionComprobantesOfflinePort(); //getRecepcionComprobantesOfflinePort();
respuesta = port.validarComprobante(bytes);
/*PARA EL CASO DONDE EL ESTADO SEA NULL**/
if (respuesta.getEstado() == null) {
if (respuesta.getComprobantes() != null) {
try {
offlineDTO.setMensaje(respuesta.getComprobantes().getComprobante().get(0).getMensajes().getMensaje().get(0).getMensaje());
} catch (Exception e) {
offlineDTO.setMensaje("NINGUN MENSAJE ENCOTRADO");
}
try {
offlineDTO.setInfoAdicional(respuesta.getComprobantes().getComprobante().get(0).getMensajes().getMensaje().get(0).getInformacionAdicional());
} catch (Exception e) {
offlineDTO.setInfoAdicional("NO DEFINIDO");
}
try {
offlineDTO.setIdentificador(Integer.valueOf(respuesta.getComprobantes().getComprobante().get(0).getMensajes().getMensaje().get(0).getIdentificador()));
} catch (Exception e) {
offlineDTO.setIdentificador(0);
}
try {
offlineDTO.setTipo(respuesta.getComprobantes().getComprobante().get(0).getMensajes().getMensaje().get(0).getTipo());
} catch (Exception e) {
offlineDTO.setTipo("ERROR");
}
try {
offlineDTO.setClaveAcceso(respuesta.getComprobantes().getComprobante().get(0).getClaveAcceso());
} catch (Exception e) {
offlineDTO.setClaveAcceso("NO DEFINIDO");
}
offlineDTO.setEstado("DEVUELTA - SN");
}
}
if (respuesta.getEstado().equals("DEVUELTA")) {
try {
offlineDTO.setMensaje(respuesta.getComprobantes().getComprobante().get(0).getMensajes().getMensaje().get(0).getMensaje());
} catch (Exception e) {
offlineDTO.setMensaje("NINGUN MENSAJE ENCOTRADO");
}
try {
offlineDTO.setInfoAdicional(respuesta.getComprobantes().getComprobante().get(0).getMensajes().getMensaje().get(0).getInformacionAdicional());
} catch (Exception e) {
offlineDTO.setInfoAdicional("NO DEFINIDO");
}
try {
offlineDTO.setIdentificador(Integer.valueOf(respuesta.getComprobantes().getComprobante().get(0).getMensajes().getMensaje().get(0).getIdentificador()));
} catch (Exception e) {
offlineDTO.setIdentificador(0);
}
try {
offlineDTO.setTipo(respuesta.getComprobantes().getComprobante().get(0).getMensajes().getMensaje().get(0).getTipo());
} catch (Exception e) {
offlineDTO.setTipo("ERROR");
}
try {
offlineDTO.setClaveAcceso(respuesta.getComprobantes().getComprobante().get(0).getClaveAcceso());
} catch (Exception e) {
offlineDTO.setClaveAcceso("NO DEFINIDO");
}
offlineDTO.setEstado("DEVUELTA");
}
if (respuesta.getEstado().equals("RECIBIDA")) {
offlineDTO.setEstado("RECIBIDA");
}
System.out.println("ESTADO FACTURA " + respuesta.getEstado());
return offlineDTO;
} catch (Exception e) {
return new FacturacionOfflineDTO();
}
}
@GetMapping("/autorizacion/{numAutorizacion}")
public FacturacionOfflineDTO autorizacion(@PathVariable String numAutorizacion){
public FacturacionOfflineDTO autorizaciona(@PathVariable String numAutorizacion){
FacturacionOfflineDTO offlineDTO = new FacturacionOfflineDTO();
try {
......@@ -335,7 +213,7 @@ public class SriAutorizacionController {
emailService.sendEmail(para, subject, text, attchment);
//emailService.sendEmail(para, subject, text, attchment);
offlineDTO.setMensaje("CORREO ENVIADO CORRECTAMENTE");
return offlineDTO;
......@@ -348,14 +226,169 @@ public class SriAutorizacionController {
return offlineDTOerror;
}
}
@GetMapping("/autorizar/{fecha}")
public FacturacionOfflineDTO autorizar(@PathVariable String fecha) {
FacturacionOfflineDTO offlineDTO = new FacturacionOfflineDTO();
List<FacturaDTO> listFactContingencia= new ArrayList<FacturaDTO>();
FacturacionOfflineDTO offlineDTOerror = new FacturacionOfflineDTO();
try {
/**OBTENER LA FECHA ACTUAL**/
Date date = new Date();
DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
//listFactContingencia= consultas.consumoFactContingencia(dateFormat.format(date));
listFactContingencia= consultas.consumoFactContingencia(fecha);
/**RECORREMOS LA LISTA DE FACTURAS PARA SU AUTORIZACION*/
if(listFactContingencia!=null){
offlineDTO.setMensaje("AUTORIZACIONES CORRECTAMENTE REALIZADAS " + listFactContingencia.size());
for(FacturaDTO dto: listFactContingencia){
Task_autorizacion tarea= new Task_autorizacion();
/**ENVIO PARA RECEPCION DE FACTURAS**/
FacturacionOfflineDTO offlineRecepcionDTO = new FacturacionOfflineDTO();
offlineRecepcionDTO= tarea.recepcion(dto.getXml());
if(offlineRecepcionDTO.getEstado().equals("RECIBIDA")){
tarea.envioCorreoRecepcion(dto);
dto.setEstadoFactura(offlineRecepcionDTO.getEstado());
try {
consultas.actualizarEstadoSRIFact(dto);
}catch(Exception e){
offlineDTOerror.setMensaje(e.getMessage());
return offlineDTOerror;
}
/**ENVIO PARA AUTORIZACIÓN DE FACTURA**/
FacturacionOfflineDTO offlineAutorizacionDTO = new FacturacionOfflineDTO();
offlineAutorizacionDTO= tarea.autorizacion(dto.getNumautoriza());
if(offlineAutorizacionDTO!=null){
if(offlineAutorizacionDTO.getEstado().equals("AUTORIZADO")){
dto.setFechaautoriza(offlineAutorizacionDTO.getFechaAutorizacion().toString());
dto.setEstadoFactura(offlineAutorizacionDTO.getEstado());
try {
consultas.actualizarSRIFact(dto);
}catch(Exception e){
offlineDTOerror.setMensaje(e.getMessage());
return offlineDTOerror;
}
}else{
offlineAutorizacionDTO.setNumeroAutoFac(dto.getIdFactura());
consultas.ingresoErrorSRIFact(offlineAutorizacionDTO);
}
}
}else{
offlineRecepcionDTO.setNumeroAutoFac(dto.getIdFactura());
consultas.ingresoErrorSRIFact(offlineRecepcionDTO);
}
}
}else{
offlineDTO.setMensaje("AUTORIZACIONES CORRECTAMENTE REALIZADAS 0");
}
return offlineDTO;
} catch (Exception e) {
offlineDTOerror.setMensaje(e.getMessage());
return offlineDTOerror;
}
}
@GetMapping("/generardoc/{fecha}")
public FacturacionOfflineDTO generaddoc(@PathVariable String fecha) {
FacturacionOfflineDTO offlineDTO = new FacturacionOfflineDTO();
List<FacturaDTO> listFact= new ArrayList<FacturaDTO>();
FacturacionOfflineDTO offlineDTOerror = new FacturacionOfflineDTO();
try {
/**OBTENER LA FECHA ACTUAL**/
Date date = new Date();
DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
//listFact= consultas.consumoFactContingencia(dateFormat.format(date));
listFact= consultas.consumoFactPDF(fecha);
/**RECORREMOS LA LISTA DE FACTURAS PARA SU AUTORIZACION*/
if(listFact!=null) {
for (FacturaDTO dto : listFact) {
Task_cargaDocumentacion tarea= new Task_cargaDocumentacion();
List<DetallefacturaDTO> listDetalle= new ArrayList<DetallefacturaDTO>();
List<PagosDTO> listPagos= new ArrayList<PagosDTO>();
listDetalle= consultas.consumoDetalleFact(dto.getIdFactura());
listPagos= consultas.consumoPagos(dto.getIdFactura());
GeneracionFactOfflinePDF pdf= new GeneracionFactOfflinePDF();
String attchment= pdf.generarPDFFacturaOffline(dto, listDetalle, listPagos);
BufferedInputStream buffIn = null;
buffIn = new BufferedInputStream(new FileInputStream(attchment));
/**CARGAR FTP FACTURACION*/
ftpService.uploadFileToFTP(buffIn,
dto.getRucCli().trim() + "_Facturas",
dto.getIdFactura().trim() + "-" + dto.getRucCli().trim() + ".pdf");
/**CARGAR XML FACTURA**/
GeneracionFactOfflineXML xmlDOc= new GeneracionFactOfflineXML();
String attchemnXml= xmlDOc.generacionXml(dto);
BufferedInputStream buffInXml = null;
buffInXml = new BufferedInputStream(new FileInputStream(attchemnXml));
ftpService.uploadFileToFTP(buffInXml,
dto.getRucCli().trim() + "_Facturas",
dto.getIdFactura().trim() + "-" + dto.getRucCli().trim() + ".xml");
dto.setPath(dto.getRucCli().trim() + "_Facturas/" + dto.getIdFactura().trim() + "-" + dto.getRucCli().trim() + ".pdf");
dto.setPathxml(dto.getRucCli().trim() + "_Facturas/" + dto.getIdFactura().trim() + "-" + dto.getRucCli().trim() + ".xml");
consultas.actualizarPathPdf(dto);
tarea.enviarCorreo(dto, attchment);
}
}
offlineDTO.setMensaje("DOCUMENTOS GENERADOS CORRECTAMENTE");
return offlineDTO;
}catch (Exception e){
offlineDTOerror.setMensaje(e.getMessage());
return offlineDTOerror;
}
}
}
......@@ -31,13 +31,13 @@ public class EmailService {
@Async
public void sendEmail(List<String> to, String subject, String text, String attachment) {
public void sendEmail(List<String> to, String subject, String text, String attachment, String idFactura) {
try {
JavaMailSenderImpl javaMailSender = new JavaMailSenderImpl();
javaMailSender.setHost("smtp.office365.com");
javaMailSender.setPort(587);
javaMailSender.setUsername("agenda@epn.edu.ec");
javaMailSender.setPassword("Generico2021**");
javaMailSender.setUsername("facturacion.electronica@epn.edu.ec");
javaMailSender.setPassword("Epndgip2023*$");
Properties props = javaMailSender.getJavaMailProperties();
props.put("mail.transport.protocol", "smtp");
props.put("mail.smtp.auth", "true");
......@@ -50,7 +50,7 @@ public class EmailService {
MimeMessageHelper messageHelper = new MimeMessageHelper(mimeMessage, true, "utf-8");
mimeMessage.setContent(text.toString(), "text/html;charset=utf-8");
messageHelper.setTo(to.toArray(new String[to.size()]));
messageHelper.setFrom("agenda@epn.edu.ec");
messageHelper.setFrom("facturacion.electronica@epn.edu.ec");
messageHelper.setSubject(subject);
......
......@@ -117,7 +117,8 @@ public class FileServiceImp implements FTPService {
int creacion= this.ftpconnection.mkd(ftpHostDir);
this.ftpconnection.changeWorkingDirectory("\\" + ftpHostDir);
this.ftpconnection.storeFile(ftpHostDir + serverFilename, input);
this.ftpconnection.setFileType(FTP.BINARY_FILE_TYPE);
this.ftpconnection.storeFile(serverFilename, input);
this.ftpconnection.logout();
this.ftpconnection.disconnect();
......
......@@ -12,8 +12,8 @@ spring.mail.properties.mail.smtp.from=smtp.office365.com
##### SMTP #####
spring.mail.host=smtp.office365.com
spring.mail.port=587
spring.mail.username=agenda@epn.edu.ec
spring.mail.password=Generico2021**
spring.mail.username=facturacion.electronica@epn.edu.ec
spring.mail.password=Epndgip2023*$
##### CONEXION FTP #####
#Multipart file config
......@@ -46,7 +46,7 @@ spring.batch.jdbc.initialize-schema=always
####### CARGA ARCHIVOS FACTURACION
#es.edu.epn.direccion=/FacturaUtils/
es.edu.epn.direccion=C:/facturacion_electronica/facturaUtils/
#### PARA LOS SCHEDULE #####
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment