fixes bug #AL-2093
correção de erro no preenchimento do código de desconto e melhoriasmaster
parent
cd6234bf00
commit
149a361812
12
pom.xml
12
pom.xml
|
@ -1,9 +1,9 @@
|
|||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>br.com.rjconsultores</groupId>
|
||||
<artifactId>ModelWeb</artifactId>
|
||||
<version>1.0.36</version>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>br.com.rjconsultores</groupId>
|
||||
<artifactId>ModelWeb</artifactId>
|
||||
<version>1.0.37</version>
|
||||
<distributionManagement>
|
||||
<repository>
|
||||
<id>rj-releases</id>
|
||||
|
|
|
@ -75,6 +75,10 @@ import com.rjconsultores.ventaboletos.utilerias.CustomEnum;
|
|||
@SuppressWarnings({"unchecked"})
|
||||
public class RemessaCNABBancosHibernateDAO extends GenericHibernateDAO<FechamentoBoleto, Long> implements RemessaCNABBancosDAO{
|
||||
|
||||
private static final String DATA_ATE = "dataAte";
|
||||
private static final String DATA_DE = "dataDe";
|
||||
private static final String EMPRESA_ID = "empresaId";
|
||||
private static final String ZERO_ESQUERDA = "00000000";
|
||||
private static Logger log = Logger.getLogger(RemessaCNABBancosHibernateDAO.class);
|
||||
|
||||
@Autowired
|
||||
|
@ -85,8 +89,7 @@ public class RemessaCNABBancosHibernateDAO extends GenericHibernateDAO<Fechament
|
|||
public String findBanco(Empresa empresa){
|
||||
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append("SELECT ");
|
||||
sb.append("DISTINCT fp.BOLETO_BANCO_COD ");
|
||||
sb.append("SELECT DISTINCT fp.BOLETO_BANCO_COD ");
|
||||
sb.append("FROM ");
|
||||
sb.append("FECHAMENTO_PARAMGERAL fp ");
|
||||
sb.append("WHERE fp.activo = 1 AND ");
|
||||
|
@ -131,11 +134,11 @@ public class RemessaCNABBancosHibernateDAO extends GenericHibernateDAO<Fechament
|
|||
writeFROMClause(sb, dataDe != null && dataAte != null, reenviar);
|
||||
|
||||
Query query = getSession().createSQLQuery(sb.toString());
|
||||
query.setInteger("empresaId", empresa.getEmpresaId());
|
||||
query.setInteger(EMPRESA_ID, empresa.getEmpresaId());
|
||||
|
||||
if(dataDe != null && dataAte != null){
|
||||
query.setDate("dataDe", dataDe);
|
||||
query.setDate("dataAte", dataAte);
|
||||
query.setDate(DATA_DE, dataDe);
|
||||
query.setDate(DATA_ATE, dataAte);
|
||||
}
|
||||
List<Object[]> list = query.list();
|
||||
|
||||
|
@ -203,7 +206,7 @@ public class RemessaCNABBancosHibernateDAO extends GenericHibernateDAO<Fechament
|
|||
detalhe.setDataOcorrencia(null);
|
||||
detalhe.setNumeroDoDocumento(StringUtils.right(doc[0], 10));
|
||||
detalhe.setVencimento((Date) tupla[9]);
|
||||
detalhe.setValor(new BigDecimal(tupla[10].toString().replaceAll(",", ".")));
|
||||
detalhe.setValor(new BigDecimal(tupla[10].toString().replace(",", ".")));
|
||||
detalhe.setEmissao((Date) tupla[12]);
|
||||
detalhe.setPercentualMulta( (BigDecimal) tupla[24] );
|
||||
|
||||
|
@ -226,7 +229,7 @@ public class RemessaCNABBancosHibernateDAO extends GenericHibernateDAO<Fechament
|
|||
|
||||
try{
|
||||
if( tupla[15] != null ) {
|
||||
detalhe.setValorAtraso(new BigDecimal(tupla[15].toString().replaceAll(",", ".")));
|
||||
detalhe.setValorAtraso(new BigDecimal(tupla[15].toString().replace(",", ".")));
|
||||
}else if( tupla[23] != null ) {
|
||||
detalhe.setValorAtraso( calculaValorMora( (BigDecimal) tupla[23], new BigDecimal(tupla[10].toString().replaceAll(",", ".") )) );
|
||||
}else {
|
||||
|
@ -238,12 +241,12 @@ public class RemessaCNABBancosHibernateDAO extends GenericHibernateDAO<Fechament
|
|||
}
|
||||
|
||||
try{
|
||||
detalhe.setValorDesconto(new BigDecimal(tupla[16].toString().replaceAll(",", ".")));
|
||||
detalhe.setValorDesconto(new BigDecimal(tupla[16].toString().replace(",", ".")));
|
||||
}catch(Exception e){
|
||||
}
|
||||
|
||||
try{
|
||||
detalhe.setValorAbatimentoConcedido(new BigDecimal(tupla[17].toString().replaceAll(",", ".")));
|
||||
detalhe.setValorAbatimentoConcedido(new BigDecimal(tupla[17].toString().replace(",", ".")));
|
||||
}catch(Exception e){
|
||||
}
|
||||
|
||||
|
@ -320,11 +323,11 @@ public class RemessaCNABBancosHibernateDAO extends GenericHibernateDAO<Fechament
|
|||
writeFROMClause(sb, dataDe != null && dataAte != null, reenviar);
|
||||
|
||||
Query query = getSession().createSQLQuery(sb.toString());
|
||||
query.setInteger("empresaId", empresa.getEmpresaId());
|
||||
query.setInteger(EMPRESA_ID, empresa.getEmpresaId());
|
||||
|
||||
if(dataDe != null && dataAte != null){
|
||||
query.setDate("dataDe", dataDe);
|
||||
query.setDate("dataAte", dataAte);
|
||||
query.setDate(DATA_DE, dataDe);
|
||||
query.setDate(DATA_ATE, dataAte);
|
||||
}
|
||||
List<Object[]> list = query.list();
|
||||
|
||||
|
@ -523,11 +526,11 @@ public class RemessaCNABBancosHibernateDAO extends GenericHibernateDAO<Fechament
|
|||
writeFROMClause(sb, dataDe != null && dataAte != null, reenviar);
|
||||
|
||||
Query query = getSession().createSQLQuery(sb.toString());
|
||||
query.setInteger("empresaId", empresa.getEmpresaId());
|
||||
query.setInteger(EMPRESA_ID, empresa.getEmpresaId());
|
||||
|
||||
if(dataDe != null && dataAte != null){
|
||||
query.setDate("dataDe", dataDe);
|
||||
query.setDate("dataAte", dataAte);
|
||||
query.setDate(DATA_DE, dataDe);
|
||||
query.setDate(DATA_ATE, dataAte);
|
||||
}
|
||||
List<Object[]> list = query.list();
|
||||
|
||||
|
@ -704,10 +707,10 @@ public class RemessaCNABBancosHibernateDAO extends GenericHibernateDAO<Fechament
|
|||
writeFROMClause(sb, dataDe != null && dataAte != null, reenviar);
|
||||
|
||||
Query query = getSession().createSQLQuery(sb.toString());
|
||||
query.setInteger("empresaId", empresa.getEmpresaId());
|
||||
query.setInteger(EMPRESA_ID, empresa.getEmpresaId());
|
||||
if(dataDe != null && dataAte != null){
|
||||
query.setDate("dataDe", dataDe);
|
||||
query.setDate("dataAte", dataAte);
|
||||
query.setDate(DATA_DE, dataDe);
|
||||
query.setDate(DATA_ATE, dataAte);
|
||||
}
|
||||
List<Object[]> list = query.list();
|
||||
|
||||
|
@ -896,10 +899,10 @@ public class RemessaCNABBancosHibernateDAO extends GenericHibernateDAO<Fechament
|
|||
writeFROMClause(sb, dataDe != null && dataAte != null, reenviar);
|
||||
|
||||
Query query = getSession().createSQLQuery(sb.toString());
|
||||
query.setInteger("empresaId", empresa.getEmpresaId());
|
||||
query.setInteger(EMPRESA_ID, empresa.getEmpresaId());
|
||||
if(dataDe != null && dataAte != null){
|
||||
query.setDate("dataDe", dataDe);
|
||||
query.setDate("dataAte", dataAte);
|
||||
query.setDate(DATA_DE, dataDe);
|
||||
query.setDate(DATA_ATE, dataAte);
|
||||
}
|
||||
List<Object[]> list = query.list();
|
||||
|
||||
|
@ -994,14 +997,14 @@ public class RemessaCNABBancosHibernateDAO extends GenericHibernateDAO<Fechament
|
|||
titulosBancoBrasil.setIdentDistribuicao(" ");
|
||||
titulosBancoBrasil.setNumeroDoDocumento(tupla[0].toString());
|
||||
titulosBancoBrasil.setVencimento((Date) tupla[10]);
|
||||
titulosBancoBrasil.setValor(new BigDecimal(tupla[11].toString().replaceAll(",", ".")));
|
||||
titulosBancoBrasil.setValor(new BigDecimal(tupla[11].toString().replace(",", ".")));
|
||||
titulosBancoBrasil.setAgenciaCobradora(null);
|
||||
titulosBancoBrasil.setDigAgenciaCobradora(null);
|
||||
titulosBancoBrasil.setAceite(AceiteBB.NAO_ACEITE);
|
||||
titulosBancoBrasil.setEmissao((Date) tupla[13]);
|
||||
try{
|
||||
titulosBancoBrasil.setCodMora(1);
|
||||
titulosBancoBrasil.setJurosDeMora(new BigDecimal(tupla[16].toString().replaceAll(",", ".")));
|
||||
titulosBancoBrasil.setJurosDeMora(new BigDecimal(tupla[16].toString().replace(",", ".")));
|
||||
titulosBancoBrasil.setDataMora((Date) tupla[10]);
|
||||
}catch(NullPointerException e){
|
||||
titulosBancoBrasil.setCodMora(1);
|
||||
|
@ -1012,16 +1015,16 @@ public class RemessaCNABBancosHibernateDAO extends GenericHibernateDAO<Fechament
|
|||
try{
|
||||
titulosBancoBrasil.setCodigoDesconto(1);
|
||||
titulosBancoBrasil.setDataDesconto((Date) tupla[10]);
|
||||
titulosBancoBrasil.setDescontoConcedido(new BigDecimal(tupla[17].toString().replaceAll(",", ".")));
|
||||
titulosBancoBrasil.setDescontoConcedido(new BigDecimal(tupla[17].toString().replace(",", ".")));
|
||||
}catch(NullPointerException e){
|
||||
titulosBancoBrasil.setCodigoDesconto(1);
|
||||
titulosBancoBrasil.setCodigoDesconto(0);
|
||||
titulosBancoBrasil.setDataDesconto((Date) tupla[10]);
|
||||
titulosBancoBrasil.setDescontoConcedido(BigDecimal.ZERO);
|
||||
}
|
||||
|
||||
titulosBancoBrasil.setIOF_Devido(BigDecimal.ZERO);
|
||||
try{
|
||||
titulosBancoBrasil.setAbatimentoConcedido(new BigDecimal(tupla[18].toString().replaceAll(",", ".")));
|
||||
titulosBancoBrasil.setAbatimentoConcedido(new BigDecimal(tupla[18].toString().replace(",", ".")));
|
||||
}catch(NullPointerException e){
|
||||
titulosBancoBrasil.setAbatimentoConcedido(BigDecimal.ZERO);
|
||||
}
|
||||
|
@ -1034,12 +1037,13 @@ public class RemessaCNABBancosHibernateDAO extends GenericHibernateDAO<Fechament
|
|||
|
||||
DetalheObrigatorioDadosPagadorBancoBrasil pagadorBancoBrasil = new DetalheObrigatorioDadosPagadorBancoBrasil();
|
||||
pagadorBancoBrasil.setTipoInscricaoSacado(Integer.parseInt(TipoInscricaoPagador.CNPJ.getId()));
|
||||
pagadorBancoBrasil.setNomeSacado(tupla[21].toString());
|
||||
String ptoVenda = tupla[21].toString();
|
||||
pagadorBancoBrasil.setNomeSacado(ptoVenda.toString());
|
||||
String cep = "";
|
||||
try{
|
||||
cep = StringUtils.right("00000000" + tupla[24].toString(), 8);
|
||||
cep = StringUtils.right(ZERO_ESQUERDA + tupla[24].toString(), 8);
|
||||
}catch(Exception e){
|
||||
cep = "00000000";
|
||||
cep = ZERO_ESQUERDA;
|
||||
}
|
||||
int cepPrefix = Integer.parseInt(cep.substring(0, 5));
|
||||
int cepSufix = Integer.parseInt(cep.substring(5));
|
||||
|
@ -1050,31 +1054,51 @@ public class RemessaCNABBancosHibernateDAO extends GenericHibernateDAO<Fechament
|
|||
try{
|
||||
pagadorBancoBrasil.setNumeroInscricaoSacado(tupla[20].toString());
|
||||
}catch(Exception e){
|
||||
throw new ValidacaoRemessaException("O CNPJ do ponto de venda "+tupla[21]+" está fora do padrão, favor corrigir");
|
||||
throw new ValidacaoRemessaException(
|
||||
String.format(
|
||||
"O CNPJ do ponto de venda %s está fora do padrão, favor corrigir",
|
||||
ptoVenda)
|
||||
);
|
||||
}
|
||||
|
||||
try{
|
||||
pagadorBancoBrasil.setLogradouroSacado(tupla[22].toString());
|
||||
}catch(Exception e){
|
||||
throw new ValidacaoRemessaException("O Logradouro do ponto de venda "+tupla[21]+" está fora do padrão, favor corrigir");
|
||||
throw new ValidacaoRemessaException(
|
||||
String.format(
|
||||
"O Logradouro do ponto de venda %s está fora do padrão, favor corrigir",
|
||||
ptoVenda)
|
||||
);
|
||||
}
|
||||
|
||||
try{
|
||||
pagadorBancoBrasil.setBairroSacado(tupla[23].toString());
|
||||
}catch(Exception e){
|
||||
throw new ValidacaoRemessaException("O Bairro do ponto de venda "+tupla[21]+" está fora do padrão, favor corrigir");
|
||||
throw new ValidacaoRemessaException(
|
||||
String.format(
|
||||
"O Bairro do ponto de venda %s está fora do padrão, favor corrigir",
|
||||
ptoVenda)
|
||||
);
|
||||
}
|
||||
|
||||
try{
|
||||
pagadorBancoBrasil.setCidade(tupla[25].toString());
|
||||
}catch(Exception e){
|
||||
throw new ValidacaoRemessaException("A cidade do ponto de venda "+tupla[21]+" está fora do padrão, favor corrigir");
|
||||
throw new ValidacaoRemessaException(
|
||||
String.format(
|
||||
"A cidade do ponto de venda %s está fora do padrão, favor corrigir",
|
||||
ptoVenda)
|
||||
);
|
||||
}
|
||||
|
||||
try{
|
||||
pagadorBancoBrasil.setEstado(tupla[26].toString());
|
||||
}catch(Exception e){
|
||||
throw new ValidacaoRemessaException("O Estado do ponto de venda "+tupla[21]+" está fora do padrão, favor corrigir");
|
||||
throw new ValidacaoRemessaException(
|
||||
String.format(
|
||||
"O Estado do ponto de venda %s está fora do padrão, favor corrigir",
|
||||
ptoVenda)
|
||||
);
|
||||
}
|
||||
|
||||
titulosBancoBrasil.setDetalheObrigatorioDadosPagadorBancoBrasil(pagadorBancoBrasil);
|
||||
|
@ -1140,10 +1164,10 @@ public class RemessaCNABBancosHibernateDAO extends GenericHibernateDAO<Fechament
|
|||
writeFROMClause(sb, dataDe != null && dataAte != null, reenviar);
|
||||
|
||||
Query query = getSession().createSQLQuery(sb.toString());
|
||||
query.setInteger("empresaId", empresa.getEmpresaId());
|
||||
query.setInteger(EMPRESA_ID, empresa.getEmpresaId());
|
||||
if(dataDe != null && dataAte != null){
|
||||
query.setDate("dataDe", dataDe);
|
||||
query.setDate("dataAte", dataAte);
|
||||
query.setDate(DATA_DE, dataDe);
|
||||
query.setDate(DATA_ATE, dataAte);
|
||||
}
|
||||
List<Object[]> list = query.list();
|
||||
|
||||
|
@ -1267,9 +1291,9 @@ public class RemessaCNABBancosHibernateDAO extends GenericHibernateDAO<Fechament
|
|||
pagadorSicoob.setNomeSacado(tupla[21].toString());
|
||||
String cep = "";
|
||||
try{
|
||||
cep = StringUtils.right("00000000" + tupla[24].toString(), 8);
|
||||
cep = StringUtils.right(ZERO_ESQUERDA + tupla[24].toString(), 8);
|
||||
}catch(Exception e){
|
||||
cep = "00000000";
|
||||
cep = ZERO_ESQUERDA;
|
||||
}
|
||||
int cepPrefix = Integer.parseInt(cep.substring(0, 5));
|
||||
int cepSufix = Integer.parseInt(cep.substring(5));
|
||||
|
@ -1365,10 +1389,10 @@ public class RemessaCNABBancosHibernateDAO extends GenericHibernateDAO<Fechament
|
|||
writeFROMClause(sb, dataDe != null && dataAte != null, reenviar);
|
||||
|
||||
Query query = getSession().createSQLQuery(sb.toString());
|
||||
query.setInteger("empresaId", empresa.getEmpresaId());
|
||||
query.setInteger(EMPRESA_ID, empresa.getEmpresaId());
|
||||
if(dataDe != null && dataAte != null){
|
||||
query.setDate("dataDe", dataDe);
|
||||
query.setDate("dataAte", dataAte);
|
||||
query.setDate(DATA_DE, dataDe);
|
||||
query.setDate(DATA_ATE, dataAte);
|
||||
}
|
||||
List<Object[]> list = query.list();
|
||||
|
||||
|
@ -1453,9 +1477,9 @@ public class RemessaCNABBancosHibernateDAO extends GenericHibernateDAO<Fechament
|
|||
|
||||
String cep = "";
|
||||
try{
|
||||
cep = StringUtils.right("00000000" + tupla[18].toString(), 8);
|
||||
cep = StringUtils.right(ZERO_ESQUERDA + tupla[18].toString(), 8);
|
||||
}catch(Exception e){
|
||||
cep = "00000000";
|
||||
cep = ZERO_ESQUERDA;
|
||||
}
|
||||
|
||||
titulosCaixa.setCepSacado(cep);
|
||||
|
@ -1560,11 +1584,11 @@ public class RemessaCNABBancosHibernateDAO extends GenericHibernateDAO<Fechament
|
|||
writeFROMClause(sb, dataDe != null && dataAte != null, reenviar);
|
||||
|
||||
Query query = getSession().createSQLQuery(sb.toString());
|
||||
query.setInteger("empresaId", empresa.getEmpresaId());
|
||||
query.setInteger(EMPRESA_ID, empresa.getEmpresaId());
|
||||
|
||||
if(dataDe != null && dataAte != null){
|
||||
query.setDate("dataDe", dataDe);
|
||||
query.setDate("dataAte", dataAte);
|
||||
query.setDate(DATA_DE, dataDe);
|
||||
query.setDate(DATA_ATE, dataAte);
|
||||
}
|
||||
|
||||
List<Object[]> list = query.list();
|
||||
|
@ -1720,7 +1744,7 @@ public class RemessaCNABBancosHibernateDAO extends GenericHibernateDAO<Fechament
|
|||
.setResultTransformer(new AliasToBeanResultTransformer(FechamentoBoleto.class));
|
||||
|
||||
query.setString("nossoNumero", nossoNumero);
|
||||
query.setInteger("empresaId", empresaId);
|
||||
query.setInteger(EMPRESA_ID, empresaId);
|
||||
|
||||
FechamentoBoleto retorno = (FechamentoBoleto)query.uniqueResult();
|
||||
|
||||
|
|
|
@ -1,172 +1,174 @@
|
|||
package com.rjconsultores.ventaboletos.dao.hibernate;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.sql.Connection;
|
||||
import java.sql.Statement;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
|
||||
import org.hibernate.Query;
|
||||
import org.hibernate.SessionFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.stereotype.Repository;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import com.rjconsultores.ventaboletos.dao.SapDAO;
|
||||
import com.rjconsultores.ventaboletos.entidad.Empresa;
|
||||
import com.rjconsultores.ventaboletos.entidad.FechamentoCntcorrente;
|
||||
import com.rjconsultores.ventaboletos.entidad.PuntoVenta;
|
||||
import com.rjconsultores.ventaboletos.enums.StatusIntegracaoSap;
|
||||
import com.rjconsultores.ventaboletos.utilerias.DateUtil;
|
||||
import com.rjconsultores.ventaboletos.vo.integracao.FechamentoCntCorrenteVO;
|
||||
|
||||
@Repository("sapDAO")
|
||||
public class SapHibernateDAO extends GenericHibernateDAO<FechamentoCntcorrente, Long> implements SapDAO {
|
||||
|
||||
@Autowired
|
||||
public SapHibernateDAO(@Qualifier("sessionFactory") SessionFactory factory) {
|
||||
setSessionFactory(factory);
|
||||
}
|
||||
|
||||
@Autowired
|
||||
@Qualifier("dataSourceWrite")
|
||||
DataSource scoDs;
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public List<FechamentoCntCorrenteVO> obtenerTodosParaRemessa(Empresa empresa, Date dataDe, Date dataAte, String status) {
|
||||
return obtenerTodosParaRemessa(empresa, dataDe, dataAte, status, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public List<FechamentoCntCorrenteVO> obtenerTodosParaRemessa(Empresa empresa, Date dataDe, Date dataAte, String status, PuntoVenta puntoVenta) {
|
||||
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append(" SELECT ");
|
||||
sb.append(" fc.fechamentocntcorrente_id, ");
|
||||
sb.append(" to_char(fc.fecfechamento, 'yyyy-mm-DD'), ");
|
||||
sb.append(" fc.total, ");
|
||||
sb.append(" es.cveestado, ");
|
||||
sb.append(" pv.numpuntoventa, ");
|
||||
sb.append(" pv.numdocpuntoventa, ");
|
||||
sb.append(" pv.nombpuntoventa, ");
|
||||
sb.append(" fc.empresa_id, ");
|
||||
sb.append(" emp.nombempresa, ");
|
||||
sb.append(" fc.indintegradosap, ");
|
||||
sb.append(" to_char(fc.fecfechamento, 'yyyy'), ");
|
||||
sb.append(" to_char(fc.fecfechamento, 'mm'), ");
|
||||
sb.append(" CASE to_char(fc.fecfechamento, 'D') ");
|
||||
sb.append(" WHEN '6' THEN to_char(fc.fecfechamento+3, 'yyyy-mm-DD') ");
|
||||
sb.append(" WHEN '7' THEN to_char(fc.fecfechamento+2, 'yyyy-mm-DD') ");
|
||||
sb.append(" ELSE to_char(fc.fecfechamento+1, 'yyyy-mm-DD') END as feclancamento ");
|
||||
sb.append(" FROM ");
|
||||
sb.append(" fechamento_cntcorrente fc ");
|
||||
sb.append(" INNER JOIN punto_venta pv ON pv.puntoventa_id = fc.puntoventa_id AND pv.activo = 1 ");
|
||||
sb.append(" INNER JOIN empresa emp ON emp.empresa_id = fc.empresa_id AND emp.activo = 1 ");
|
||||
sb.append(" INNER JOIN FECHAMENTO_PARAMPTOVTA fp ON fp.PUNTOVENTA_ID = fc.puntoventa_id AND fp.activo =1 ");
|
||||
sb.append(" AND fp.empresa_id = fc.empresa_id AND fp.TIPOPAGAMENTO = 'B'" );
|
||||
sb.append(" LEFT JOIN ciudad ci ON ci.ciudad_id = emp.ciudad_id AND ci.activo = 1 ");
|
||||
sb.append(" LEFT JOIN plaza pl ON pl.plaza_id = ci.plaza_id AND pl.activo = 1 ");
|
||||
sb.append(" LEFT JOIN estado es ON es.estado_id = ci.estado_id AND es.activo = 1 ");
|
||||
sb.append(" WHERE ");
|
||||
sb.append(" fc.activo = 1 ");
|
||||
sb.append(" AND fc.fecfechamento BETWEEN :dataDe AND :dataAte ");
|
||||
|
||||
if( empresa != null ) {
|
||||
sb.append(" AND fc.EMPRESA_ID = :empresaId ");
|
||||
}
|
||||
|
||||
if( puntoVenta != null ) {
|
||||
sb.append(" AND pv.puntoventa_id = :puntoVentaId ");
|
||||
}
|
||||
|
||||
if(status != null && !status.isEmpty()){
|
||||
sb.append(" AND fc.indintegradosap in ("+status+")");
|
||||
}
|
||||
|
||||
sb.append(" ORDER BY ");
|
||||
sb.append(" pv.nombpuntoventa, fc.fecfechamento ");
|
||||
|
||||
Query query = getSession().createSQLQuery(sb.toString());
|
||||
|
||||
if( empresa != null ) {
|
||||
query.setInteger("empresaId", empresa.getEmpresaId());
|
||||
}
|
||||
|
||||
if( puntoVenta != null ) {
|
||||
query.setInteger("puntoVentaId", puntoVenta.getPuntoventaId());
|
||||
}
|
||||
|
||||
if(dataDe != null && dataAte != null){
|
||||
query.setDate("dataDe", DateUtil.normalizarToFecha(dataDe));
|
||||
query.setDate("dataAte", DateUtil.normalizarToFecha(dataAte));
|
||||
}
|
||||
|
||||
query.setMaxResults(100);
|
||||
|
||||
List<Object[]> list = query.list();
|
||||
List<FechamentoCntCorrenteVO> retorno = new ArrayList<FechamentoCntCorrenteVO>();
|
||||
|
||||
for(Object[] tupla : list){
|
||||
|
||||
FechamentoCntCorrenteVO fcc = new FechamentoCntCorrenteVO();
|
||||
fcc.setFechamentocntcorrenteId( Long.valueOf(tupla[0].toString()));
|
||||
fcc.setFecfechamento( tupla[1].toString() );
|
||||
fcc.setTotal( (BigDecimal)tupla[2] );
|
||||
fcc.setUfEmpresa(tupla[3].toString());
|
||||
fcc.setNumPuntoVenta(tupla[4].toString());
|
||||
|
||||
try {
|
||||
String cnpj = tupla[5].toString().replaceAll("[^0-9]", "");
|
||||
fcc.setCnpjPuntoVenta(cnpj);
|
||||
}catch (Exception e) {
|
||||
throw new RuntimeException( "CNPJ fora do padrao no ponto de venda: "+tupla[6] );
|
||||
}
|
||||
fcc.setNombpuntoventa(tupla[6].toString());
|
||||
|
||||
fcc.setEmpresaId( Integer.valueOf( tupla[7].toString() ));
|
||||
fcc.setNombEmpresa( tupla[8].toString());
|
||||
|
||||
fcc.setIntegradoSap( StatusIntegracaoSap.getStatusIntegracaoSap( tupla[9]==null?0:Integer.valueOf(tupla[9].toString()) ));
|
||||
|
||||
fcc.setAnofechamento(tupla[10].toString());
|
||||
fcc.setMesfechamento(tupla[11].toString());
|
||||
fcc.setFeclancamento(tupla[12].toString());
|
||||
|
||||
//empresa enviada nula apenas no processo automatico
|
||||
if(empresa == null) {
|
||||
fcc.setEnviar(true);
|
||||
}
|
||||
|
||||
retorno.add(fcc);
|
||||
}
|
||||
|
||||
return retorno;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public synchronized boolean atualizaFechamento(Long fechamentocntcorrenteId, int status) throws Exception {
|
||||
|
||||
if(fechamentocntcorrenteId == null ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
//é feito update manualmente porque o hibernate utiliza sco_read e nao tem permissao de escrita no banco
|
||||
try(Connection con = scoDs.getConnection();
|
||||
Statement stmt = con.createStatement()){
|
||||
stmt.addBatch("UPDATE FECHAMENTO_CNTCORRENTE SET INDINTEGRADOSAP = "+ status
|
||||
+" WHERE FECHAMENTOCNTCORRENTE_ID = " + fechamentocntcorrenteId);
|
||||
|
||||
stmt.executeBatch();
|
||||
}
|
||||
|
||||
return Boolean.TRUE;
|
||||
}
|
||||
|
||||
package com.rjconsultores.ventaboletos.dao.hibernate;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.sql.Connection;
|
||||
import java.sql.Statement;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
|
||||
import org.hibernate.Query;
|
||||
import org.hibernate.SessionFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.stereotype.Repository;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import com.rjconsultores.ventaboletos.dao.SapDAO;
|
||||
import com.rjconsultores.ventaboletos.entidad.Empresa;
|
||||
import com.rjconsultores.ventaboletos.entidad.FechamentoCntcorrente;
|
||||
import com.rjconsultores.ventaboletos.entidad.PuntoVenta;
|
||||
import com.rjconsultores.ventaboletos.enums.StatusIntegracaoSap;
|
||||
import com.rjconsultores.ventaboletos.exception.BusinessRuntimeException;
|
||||
import com.rjconsultores.ventaboletos.utilerias.DateUtil;
|
||||
import com.rjconsultores.ventaboletos.vo.integracao.FechamentoCntCorrenteVO;
|
||||
|
||||
@Repository("sapDAO")
|
||||
public class SapHibernateDAO extends GenericHibernateDAO<FechamentoCntcorrente, Long> implements SapDAO {
|
||||
|
||||
@Autowired
|
||||
public SapHibernateDAO(@Qualifier("sessionFactory") SessionFactory factory) {
|
||||
setSessionFactory(factory);
|
||||
}
|
||||
|
||||
@Autowired
|
||||
@Qualifier("dataSourceWrite")
|
||||
DataSource scoDs;
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public List<FechamentoCntCorrenteVO> obtenerTodosParaRemessa(Empresa empresa, Date dataDe, Date dataAte, String status) {
|
||||
return obtenerTodosParaRemessa(empresa, dataDe, dataAte, status, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public List<FechamentoCntCorrenteVO> obtenerTodosParaRemessa(Empresa empresa, Date dataDe, Date dataAte, String status, PuntoVenta puntoVenta) {
|
||||
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append(" SELECT ");
|
||||
sb.append(" fc.fechamentocntcorrente_id, ");
|
||||
sb.append(" to_char(fc.fecfechamento, 'yyyy-mm-DD'), ");
|
||||
sb.append(" fc.total, ");
|
||||
sb.append(" es.cveestado, ");
|
||||
sb.append(" pv.numpuntoventa, ");
|
||||
sb.append(" pv.numdocpuntoventa, ");
|
||||
sb.append(" pv.nombpuntoventa, ");
|
||||
sb.append(" fc.empresa_id, ");
|
||||
sb.append(" emp.nombempresa, ");
|
||||
sb.append(" fc.indintegradosap, ");
|
||||
sb.append(" to_char(fc.fecfechamento, 'yyyy'), ");
|
||||
sb.append(" to_char(fc.fecfechamento, 'mm'), ");
|
||||
sb.append(" CASE to_char(fc.fecfechamento, 'D') ");
|
||||
sb.append(" WHEN '6' THEN to_char(fc.fecfechamento+3, 'yyyy-mm-DD') ");
|
||||
sb.append(" WHEN '7' THEN to_char(fc.fecfechamento+2, 'yyyy-mm-DD') ");
|
||||
sb.append(" ELSE to_char(fc.fecfechamento+1, 'yyyy-mm-DD') END as feclancamento ");
|
||||
sb.append(" FROM ");
|
||||
sb.append(" fechamento_cntcorrente fc ");
|
||||
sb.append(" INNER JOIN punto_venta pv ON pv.puntoventa_id = fc.puntoventa_id AND pv.activo = 1 ");
|
||||
sb.append(" INNER JOIN empresa emp ON emp.empresa_id = fc.empresa_id AND emp.activo = 1 ");
|
||||
sb.append(" INNER JOIN FECHAMENTO_PARAMPTOVTA fp ON fp.PUNTOVENTA_ID = fc.puntoventa_id AND fp.activo =1 ");
|
||||
sb.append(" AND fp.empresa_id = fc.empresa_id AND fp.TIPOPAGAMENTO = 'B'" );
|
||||
sb.append(" LEFT JOIN ciudad ci ON ci.ciudad_id = emp.ciudad_id AND ci.activo = 1 ");
|
||||
sb.append(" LEFT JOIN plaza pl ON pl.plaza_id = ci.plaza_id AND pl.activo = 1 ");
|
||||
sb.append(" LEFT JOIN estado es ON es.estado_id = ci.estado_id AND es.activo = 1 ");
|
||||
sb.append(" WHERE ");
|
||||
sb.append(" fc.activo = 1 ");
|
||||
sb.append(" AND fc.fecfechamento BETWEEN :dataDe AND :dataAte ");
|
||||
|
||||
if( empresa != null ) {
|
||||
sb.append(" AND fc.EMPRESA_ID = :empresaId ");
|
||||
}
|
||||
|
||||
if( puntoVenta != null ) {
|
||||
sb.append(" AND pv.puntoventa_id = :puntoVentaId ");
|
||||
}
|
||||
|
||||
if(status != null && !status.isEmpty()){
|
||||
sb.append(" AND fc.indintegradosap in ("+status+")");
|
||||
}
|
||||
|
||||
sb.append(" ORDER BY ");
|
||||
sb.append(" pv.nombpuntoventa, fc.fecfechamento ");
|
||||
|
||||
Query query = getSession().createSQLQuery(sb.toString());
|
||||
|
||||
if( empresa != null ) {
|
||||
query.setInteger("empresaId", empresa.getEmpresaId());
|
||||
}
|
||||
|
||||
if( puntoVenta != null ) {
|
||||
query.setInteger("puntoVentaId", puntoVenta.getPuntoventaId());
|
||||
}
|
||||
|
||||
if(dataDe != null && dataAte != null){
|
||||
query.setDate("dataDe", DateUtil.normalizarToFecha(dataDe));
|
||||
query.setDate("dataAte", DateUtil.normalizarToFecha(dataAte));
|
||||
}
|
||||
|
||||
query.setMaxResults(100);
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
List<Object[]> list = query.list();
|
||||
List<FechamentoCntCorrenteVO> retorno = new ArrayList<>();
|
||||
|
||||
for(Object[] tupla : list){
|
||||
|
||||
FechamentoCntCorrenteVO fcc = new FechamentoCntCorrenteVO();
|
||||
fcc.setFechamentocntcorrenteId( Long.valueOf(tupla[0].toString()));
|
||||
fcc.setFecfechamento( tupla[1].toString() );
|
||||
fcc.setTotal( (BigDecimal)tupla[2] );
|
||||
fcc.setUfEmpresa(tupla[3].toString());
|
||||
fcc.setNumPuntoVenta(tupla[4].toString());
|
||||
|
||||
try {
|
||||
String cnpj = tupla[5].toString().replaceAll("\\D", "");
|
||||
fcc.setCnpjPuntoVenta(cnpj);
|
||||
}catch (Exception e) {
|
||||
throw new BusinessRuntimeException( "CNPJ fora do padrao no ponto de venda: %s ", tupla[6] );
|
||||
}
|
||||
fcc.setNombpuntoventa(tupla[6].toString());
|
||||
|
||||
fcc.setEmpresaId( Integer.valueOf( tupla[7].toString() ));
|
||||
fcc.setNombEmpresa( tupla[8].toString());
|
||||
|
||||
fcc.setIntegradoSap( StatusIntegracaoSap.getStatusIntegracaoSap( tupla[9]==null?0:Integer.valueOf(tupla[9].toString()) ));
|
||||
|
||||
fcc.setAnofechamento(tupla[10].toString());
|
||||
fcc.setMesfechamento(tupla[11].toString());
|
||||
fcc.setFeclancamento(tupla[12].toString());
|
||||
|
||||
//empresa enviada nula apenas no processo automatico
|
||||
if(empresa == null) {
|
||||
fcc.setEnviar(true);
|
||||
}
|
||||
|
||||
retorno.add(fcc);
|
||||
}
|
||||
|
||||
return retorno;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public synchronized boolean atualizaFechamento(Long fechamentocntcorrenteId, int status) throws Exception {
|
||||
|
||||
if(fechamentocntcorrenteId == null ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
//é feito update manualmente porque o hibernate utiliza sco_read e nao tem permissao de escrita no banco
|
||||
try(Connection con = scoDs.getConnection();
|
||||
Statement stmt = con.createStatement()){
|
||||
stmt.addBatch("UPDATE FECHAMENTO_CNTCORRENTE SET INDINTEGRADOSAP = "+ status
|
||||
+" WHERE FECHAMENTOCNTCORRENTE_ID = " + fechamentocntcorrenteId);
|
||||
|
||||
stmt.executeBatch();
|
||||
}
|
||||
|
||||
return Boolean.TRUE;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,30 @@
|
|||
package com.rjconsultores.ventaboletos.exception;
|
||||
|
||||
import java.text.MessageFormat;
|
||||
|
||||
import org.zkoss.util.resource.Labels;
|
||||
|
||||
public class BusinessRuntimeException extends RuntimeException {
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = 1L;
|
||||
/**
|
||||
*
|
||||
* @param message
|
||||
* - La clave del archivo de traducción
|
||||
*/
|
||||
public BusinessRuntimeException(String message) {
|
||||
super(Labels.getLabel(message) == null ? message :Labels.getLabel(message));
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param message- La clave del archivo de traducción
|
||||
* @param oMsg - Los parametros de la mensage
|
||||
*/
|
||||
public BusinessRuntimeException(String message,Object oMsg) {
|
||||
super(new MessageFormat(Labels.getLabel(message)).format(oMsg));
|
||||
}
|
||||
}
|
|
@ -16,6 +16,7 @@ import com.rjconsultores.ventaboletos.entidad.Empresa;
|
|||
import com.rjconsultores.ventaboletos.entidad.FechamentoCntcorrente;
|
||||
import com.rjconsultores.ventaboletos.entidad.PuntoVenta;
|
||||
import com.rjconsultores.ventaboletos.enums.StatusIntegracaoSap;
|
||||
import com.rjconsultores.ventaboletos.exception.BusinessRuntimeException;
|
||||
import com.rjconsultores.ventaboletos.rest.IntegracaoSapRest;
|
||||
import com.rjconsultores.ventaboletos.service.SapService;
|
||||
import com.rjconsultores.ventaboletos.utilerias.DateUtil;
|
||||
|
@ -74,43 +75,39 @@ public class SapServiceImpl implements SapService{
|
|||
}
|
||||
|
||||
@Override
|
||||
public int remessa(List<FechamentoCntCorrenteVO> fechamentos, boolean processoManual) throws Exception {
|
||||
try {
|
||||
int contador = 0;
|
||||
IntegracaoSapRest integracaoSapRest = IntegracaoSapRest.getInstance();
|
||||
String credenciais = buscaConstante(INTEGRACAO_SAP_CREDENCIAL);
|
||||
String url = buscaConstante(INTEGRACAO_SAP_URL);
|
||||
public int remessa(List<FechamentoCntCorrenteVO> fechamentos, boolean processoManual) throws BusinessRuntimeException, Exception {
|
||||
int contador = 0;
|
||||
IntegracaoSapRest integracaoSapRest = IntegracaoSapRest.getInstance();
|
||||
String credenciais = buscaConstante(INTEGRACAO_SAP_CREDENCIAL);
|
||||
String url = buscaConstante(INTEGRACAO_SAP_URL);
|
||||
|
||||
for (FechamentoCntCorrenteVO fechamentoCntcorrente : fechamentos) {
|
||||
if( fechamentoCntcorrente.isEnviar()) {
|
||||
log.debug("Enviando fechamento:"+ fechamentoCntcorrente.getFechamentocntcorrenteId());
|
||||
JSONObject integrado = integracaoSapRest.enviarIntegracaoSap(fechamentoCntcorrente, url, credenciais);
|
||||
|
||||
if(integrado == null) {
|
||||
atualizaFechamento(fechamentoCntcorrente.getFechamentocntcorrenteId(), StatusIntegracaoSap.NAO_ENVIADO.ordinal());
|
||||
log.error("Erro no envio/retorno da requisicao para integracao SAP do fechamentoID: "+fechamentoCntcorrente.getFechamentocntcorrenteId());
|
||||
if(processoManual) {
|
||||
throw new RuntimeException("Erro no envio/retorno da requisicao para integracao SAP do fechamentoID: "+fechamentoCntcorrente.getFechamentocntcorrenteId());
|
||||
}
|
||||
}else if(integrado.getString("Integration").equals("S")) {
|
||||
atualizaFechamento(fechamentoCntcorrente.getFechamentocntcorrenteId(), StatusIntegracaoSap.INTEGRADO.ordinal());
|
||||
contador++;
|
||||
}else if(integrado.getString("Integration").equals("E")) {
|
||||
atualizaFechamento(fechamentoCntcorrente.getFechamentocntcorrenteId(), StatusIntegracaoSap.RECUSADO.ordinal());
|
||||
log.warn("Retorno enviado pelo SAP: \r\n"+integrado.getString("Message"));
|
||||
if(processoManual) {
|
||||
throw new RuntimeException("Fechamento: "+fechamentoCntcorrente.getFechamentocntcorrenteId()+"\r\nRetorno enviado pelo SAP: \r\n"+integrado.getString("Message"));
|
||||
}
|
||||
}
|
||||
}
|
||||
for (FechamentoCntCorrenteVO fechamentoCntcorrente : fechamentos) {
|
||||
if( fechamentoCntcorrente.isEnviar()) {
|
||||
log.debug("Enviando fechamento:"+ fechamentoCntcorrente.getFechamentocntcorrenteId());
|
||||
JSONObject integrado = integracaoSapRest.enviarIntegracaoSap(fechamentoCntcorrente, url, credenciais);
|
||||
|
||||
if(integrado == null) {
|
||||
atualizaFechamento(fechamentoCntcorrente.getFechamentocntcorrenteId(), StatusIntegracaoSap.NAO_ENVIADO.ordinal());
|
||||
log.error("Erro no envio/retorno da requisicao para integracao SAP do fechamentoID: "+fechamentoCntcorrente.getFechamentocntcorrenteId());
|
||||
tratarProcessoManual(processoManual, "Erro no envio/retorno da requisicao para integracao SAP do fechamentoID: %s", fechamentoCntcorrente);
|
||||
}else if(integrado.getString("Integration").equals("S")) {
|
||||
atualizaFechamento(fechamentoCntcorrente.getFechamentocntcorrenteId(), StatusIntegracaoSap.INTEGRADO.ordinal());
|
||||
contador++;
|
||||
}else if(integrado.getString("Integration").equals("E")) {
|
||||
atualizaFechamento(fechamentoCntcorrente.getFechamentocntcorrenteId(), StatusIntegracaoSap.RECUSADO.ordinal());
|
||||
log.warn("Retorno enviado pelo SAP: \r\n"+integrado.getString("Message"));
|
||||
tratarProcessoManual(processoManual, "Fechamento: "+fechamentoCntcorrente.getFechamentocntcorrenteId()+"\r\nRetorno enviado pelo SAP: \r\n"+integrado.getString("Message"), fechamentoCntcorrente);
|
||||
}
|
||||
}
|
||||
|
||||
return contador;
|
||||
}catch(RuntimeException re){
|
||||
throw re;
|
||||
}catch(Exception e){
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
return contador;
|
||||
}
|
||||
|
||||
private void tratarProcessoManual(boolean processoManual, String mensagem, FechamentoCntCorrenteVO fechamentoCntcorrente) {
|
||||
if(processoManual) {
|
||||
throw new BusinessRuntimeException( mensagem, fechamentoCntcorrente.getFechamentocntcorrenteId());
|
||||
}
|
||||
}
|
||||
|
||||
private boolean atualizaFechamento(Long fechamentocntcorrenteId, int status) throws Exception {
|
||||
|
@ -121,7 +118,7 @@ public class SapServiceImpl implements SapService{
|
|||
Constante constante = constanteDAO.buscarPorNomeConstante(constanteString);
|
||||
|
||||
if( constante == null || constante.getValorconstante() == null || constante.getValorconstante().isEmpty() ) {
|
||||
throw new RuntimeException("Constante "+constanteString+" n<>o cadastrada");
|
||||
throw new BusinessRuntimeException("Constante %s não cadastrada", constanteString);
|
||||
}
|
||||
|
||||
return constante.getValorconstante();
|
||||
|
|
|
@ -138,7 +138,7 @@ public class FechamentoCntCorrenteVO {
|
|||
this.anofechamento = anofechamento;
|
||||
}
|
||||
|
||||
public Boolean isEnviar() {
|
||||
public boolean isEnviar() {
|
||||
return enviar;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue