Skip to content

Commit

Permalink
Adapt criteria to support search by idFiscal (#496)
Browse files Browse the repository at this point in the history
  • Loading branch information
belluccifranco authored Nov 15, 2024
1 parent fe89e1e commit 5c2393e
Show file tree
Hide file tree
Showing 11 changed files with 101 additions and 131 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>org.opencommercial</groupId>
<artifactId>api</artifactId>
<version>1.3.1</version>
<version>1.3.2</version>
<packaging>jar</packaging>

<parent>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public class BusquedaClienteCriteria {

private String nombreFiscal;
private String nombreFantasia;
private Long idFiscal;
private String idFiscal;
private Long idViajante;
private Long idProvincia;
private Long idLocalidad;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public class BusquedaCuentaCorrienteClienteCriteria {
private Long idCliente;
private String nombreFiscal;
private String nombreFantasia;
private Long idFiscal;
private String idFiscal;
private Long idViajante;
private Long idProvincia;
private Long idLocalidad;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public class BusquedaCuentaCorrienteProveedorCriteria {

private String nroProveedor;
private String razonSocial;
private Long idFiscal;
private String idFiscal;
private Long idProvincia;
private Long idLocalidad;
private Integer pagina;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public class BusquedaProveedorCriteria {

private String nroProveedor;
private String razonSocial;
private Long idFiscal;
private String idFiscal;
private Long idProvincia;
private Long idLocalidad;
private Integer pagina;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,29 +85,29 @@ public void autorizar(ComprobanteAutorizable comprobanteAutorizable) {
// errores generales de la request
if (response.getErrors() != null) {
msjError =
response.getErrors().getErr().get(0).getCode()
response.getErrors().getErr().getFirst().getCode()
+ "-"
+ response.getErrors().getErr().get(0).getMsg();
+ response.getErrors().getErr().getFirst().getMsg();
log.error(msjError);
throw new BusinessServiceException(msjError);
}
// errores particulares de cada comprobante
if (response.getFeDetResp().getFECAEDetResponse().get(0).getResultado().equals("R")) {
if (response.getFeDetResp().getFECAEDetResponse().getFirst().getResultado().equals("R")) {
msjError +=
response
.getFeDetResp()
.getFECAEDetResponse()
.get(0)
.getFirst()
.getObservaciones()
.getObs()
.get(0)
.getFirst()
.getMsg();
log.error(msjError);
throw new BusinessServiceException(msjError);
}
long cae = Long.parseLong(response.getFeDetResp().getFECAEDetResponse().get(0).getCAE());
long cae = Long.parseLong(response.getFeDetResp().getFECAEDetResponse().getFirst().getCAE());
comprobanteAutorizableAFIP.setCae(cae);
String fechaVencimientoCaeResponse = response.getFeDetResp().getFECAEDetResponse().get(0).getCAEFchVto();
String fechaVencimientoCaeResponse = response.getFeDetResp().getFECAEDetResponse().getFirst().getCAEFchVto();
comprobanteAutorizableAFIP.setVencimientoCAE(LocalDate.parse(fechaVencimientoCaeResponse, DateTimeFormatter.BASIC_ISO_DATE));
comprobanteAutorizableAFIP.setNumSerieAfip(nroPuntoDeVentaAfip);
comprobanteAutorizableAFIP.setNumFacturaAfip(siguienteNroComprobante);
Expand All @@ -134,8 +134,7 @@ private FEAuthRequest getFEAuth(Sucursal sucursal) {
String p12pass = configSucursal.getPasswordCertificadoAfip();
long ticketTimeInHours = 12L; // siempre devuelve por 12hs
byte[] loginTicketRequestXmlCms =
afipWebServiceSOAPClient.crearCMS(
p12file, p12pass, p12signer, WEBSERVICE_FACTURA_ELECTRONICA, ticketTimeInHours);
afipWebServiceSOAPClient.crearCMS(p12file, p12pass, p12signer, WEBSERVICE_FACTURA_ELECTRONICA, ticketTimeInHours);
LoginCms loginCms = new LoginCms();
loginCms.setIn0(Base64.getEncoder().encodeToString(loginTicketRequestXmlCms));
try {
Expand Down Expand Up @@ -177,13 +176,12 @@ private int getSiguienteNroComprobante(FEAuthRequest feAuthRequest, TipoDeCompro
case FACTURA_C -> solicitud.setCbteTipo(11);
case NOTA_DEBITO_C -> solicitud.setCbteTipo(12);
case NOTA_CREDITO_C -> solicitud.setCbteTipo(13);
default -> throw new BusinessServiceException(messageSource.getMessage(
MENSAJE_COMPROBANTE_AFIP_INVALIDO, null, Locale.getDefault()));
default -> throw new BusinessServiceException(
messageSource.getMessage(MENSAJE_COMPROBANTE_AFIP_INVALIDO, null, Locale.getDefault()));
}
solicitud.setPtoVta(nroPuntoDeVentaAfip);
try {
FERecuperaLastCbteResponse response =
afipWebServiceSOAPClient.getUltimoComprobanteAutorizado(solicitud);
FERecuperaLastCbteResponse response = afipWebServiceSOAPClient.getUltimoComprobanteAutorizado(solicitud);
return response.getCbteNro() + 1;
} catch (WebServiceClientException | IOException ex) {
throw new ServiceException(messageSource.getMessage(
Expand Down Expand Up @@ -243,8 +241,8 @@ private FECAERequest transformComprobanteToFECAERequest(ComprobanteAutorizableAF
cabecera.setCbteTipo(13);
this.procesarDetalle(detalle, comprobante);
}
default -> throw new BusinessServiceException(messageSource.getMessage(
MENSAJE_COMPROBANTE_AFIP_INVALIDO, null, Locale.getDefault()));
default -> throw new BusinessServiceException(
messageSource.getMessage(MENSAJE_COMPROBANTE_AFIP_INVALIDO, null, Locale.getDefault()));
}
// Cantidad de registros del detalle del comprobante o lote de comprobantes de ingreso
cabecera.setCantReg(1);
Expand Down Expand Up @@ -359,8 +357,7 @@ private void procesarDetalle(FECAEDetRequest detalle, ComprobanteAutorizableAFIP
detalle.setDocNro(0);
} else {
this.validarCliente(comprobante.getCliente());
detalle.setDocTipo(
(comprobante.getCliente().getCategoriaIVACliente() == CategoriaIVA.CONSUMIDOR_FINAL) ? 96 : 80);
detalle.setDocTipo((comprobante.getCliente().getCategoriaIVACliente() == CategoriaIVA.CONSUMIDOR_FINAL) ? 96 : 80);
detalle.setDocNro(comprobante.getCliente().getIdFiscalCliente());
}
}
Expand All @@ -382,8 +379,7 @@ private void agregarPeriodoAlDetalle(ComprobanteAutorizableAFIP comprobante, FEC
private void validarCliente(ClienteEmbeddable cliente) {
if (cliente.getIdFiscalCliente() == null) {
throw new BusinessServiceException(
messageSource.getMessage(
"mensaje_cliente_sin_idFiscal_error", null, Locale.getDefault()));
messageSource.getMessage("mensaje_cliente_sin_idFiscal_error", null, Locale.getDefault()));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@
import lombok.extern.slf4j.Slf4j;
import org.bouncycastle.cms.*;
import org.bouncycastle.jce.provider.BouncyCastleProvider;
import org.opencommercial.exception.BusinessServiceException;
import org.opencommercial.exception.ServiceException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.MessageSource;
import org.springframework.ws.WebServiceMessage;
import org.springframework.ws.client.core.support.WebServiceGatewaySupport;
import org.springframework.ws.soap.SoapMessage;
import org.springframework.xml.transform.StringResult;
import org.opencommercial.exception.BusinessServiceException;
import org.opencommercial.exception.ServiceException;

import java.io.ByteArrayInputStream;
import java.io.IOException;
Expand All @@ -32,6 +32,7 @@ public class AfipWebServiceSOAPClient extends WebServiceGatewaySupport {

private static final String SOAP_ACTION_FE_CAE_SOLICITAR = "http://ar.gov.afip.dif.FEV1/FECAESolicitar";
private static final String SOAP_ACTION_FE_COMPROBANTE_ULTIMO_AUTORIZADO = "http://ar.gov.afip.dif.FEV1/FECompUltimoAutorizado";
private static final String MENSAJE_SERVICIO_NO_CONFIGURADO = "mensaje_taxation_afip_no_configurado";

@Autowired
private MessageSource messageSource;
Expand All @@ -48,8 +49,8 @@ public boolean isServicioConfigurado() {
}

public String loginCMS(LoginCms loginCMS) throws IOException {
if (!isServicioConfigurado()) throw new ServiceException(messageSource.getMessage(
"mensaje_taxation_afip_no_configurado", null, Locale.getDefault()));
if (!isServicioConfigurado())
throw new ServiceException(messageSource.getMessage(MENSAJE_SERVICIO_NO_CONFIGURADO, null, Locale.getDefault()));
var result = new StringResult();
this.getWebServiceTemplate().getMarshaller().marshal(loginCMS, result);
log.info("TOKEN WSAA XML REQUEST: {}", result);
Expand All @@ -60,8 +61,8 @@ public String loginCMS(LoginCms loginCMS) throws IOException {
}

public byte[] crearCMS(byte[] p12file, String p12pass, String signer, String service, long ticketTimeInHours) {
if (!isServicioConfigurado()) throw new ServiceException(messageSource.getMessage(
"mensaje_taxation_afip_no_configurado", null, Locale.getDefault()));
if (!isServicioConfigurado())
throw new ServiceException(messageSource.getMessage(MENSAJE_SERVICIO_NO_CONFIGURADO, null, Locale.getDefault()));
PrivateKey pKey;
X509Certificate pCertificate;
byte[] asn1Cms;
Expand Down Expand Up @@ -111,8 +112,8 @@ public byte[] crearCMS(byte[] p12file, String p12pass, String signer, String ser
}

public String crearTicketRequerimientoAcceso(String service, long ticketTimeInHours) {
if (!isServicioConfigurado()) throw new ServiceException(messageSource.getMessage(
"mensaje_taxation_afip_no_configurado", null, Locale.getDefault()));
if (!isServicioConfigurado())
throw new ServiceException(messageSource.getMessage(MENSAJE_SERVICIO_NO_CONFIGURADO, null, Locale.getDefault()));
var now = LocalDateTime.now();
var zdt = now.atZone(ZoneId.systemDefault());
var uniqueId = Long.toString(zdt.toInstant().toEpochMilli() / 1000);
Expand All @@ -135,8 +136,8 @@ public String crearTicketRequerimientoAcceso(String service, long ticketTimeInHo
}

public FERecuperaLastCbteResponse getUltimoComprobanteAutorizado(FECompUltimoAutorizado solicitud) throws IOException {
if (!isServicioConfigurado()) throw new ServiceException(messageSource.getMessage(
"mensaje_taxation_afip_no_configurado", null, Locale.getDefault()));
if (!isServicioConfigurado())
throw new ServiceException(messageSource.getMessage(MENSAJE_SERVICIO_NO_CONFIGURADO, null, Locale.getDefault()));
var result = new StringResult();
this.getWebServiceTemplate().getMarshaller().marshal(solicitud, result);
log.info("ULTIMO COMPROBANTE AUTORIZADO XML REQUEST: {}", result);
Expand All @@ -154,8 +155,8 @@ public FERecuperaLastCbteResponse getUltimoComprobanteAutorizado(FECompUltimoAut
}

public FECAEResponse solicitarCAE(FECAESolicitar solicitud) throws IOException {
if (!isServicioConfigurado()) throw new ServiceException(messageSource.getMessage(
"mensaje_taxation_afip_no_configurado", null, Locale.getDefault()));
if (!isServicioConfigurado())
throw new ServiceException(messageSource.getMessage(MENSAJE_SERVICIO_NO_CONFIGURADO, null, Locale.getDefault()));
var result = new StringResult();
this.getWebServiceTemplate().getMarshaller().marshal(solicitud, result);
log.info("SOLICITAR cae XML REQUEST: {}", result);
Expand Down
Loading

0 comments on commit 5c2393e

Please sign in to comment.