diff --git a/src/com/rjconsultores/ventaboletos/dao/hibernate/FiscalHibernateDAO.java b/src/com/rjconsultores/ventaboletos/dao/hibernate/FiscalHibernateDAO.java index fb4097a9f..64d464aef 100644 --- a/src/com/rjconsultores/ventaboletos/dao/hibernate/FiscalHibernateDAO.java +++ b/src/com/rjconsultores/ventaboletos/dao/hibernate/FiscalHibernateDAO.java @@ -8,6 +8,7 @@ import java.sql.ResultSetMetaData; import java.sql.SQLException; import java.text.SimpleDateFormat; import java.util.ArrayList; +import java.util.Arrays; import java.util.Collections; import java.util.Date; import java.util.HashMap; @@ -3671,11 +3672,13 @@ public class FiscalHibernateDAO extends HibernateDaoSupport implements FiscalDAO List list = new ArrayList(); try { + boolean isDif = validaConstanteCustom(empresaId.toString(), "IMPORT_FISCAL_DIF"); + String sql = null; if (isECF && !isCancelamento) { sql = getSqlImpressaoRMDTipoECF(); } else if (isManual && !isCancelamento) { - sql = getSqlImpressaoRMDTipoBPR(); + sql = getSqlImpressaoRMDTipoBPR(isDif); } else if (isCancelamento) { sql = getSqlImpressaoRMDCancelados(); } @@ -3754,8 +3757,20 @@ public class FiscalHibernateDAO extends HibernateDaoSupport implements FiscalDAO return list; } + + public boolean validaConstanteCustom(String valor, String nomeConstante) { + ConstanteService constanteService = (ConstanteService) AppContext.getApplicationContext().getBean("constanteService"); + String value = constanteService.buscarPorNomeConstante(nomeConstante).getValorconstante(); + + if (StringUtils.isBlank(value)) + return false; + + List valuesList = Arrays.asList(value.split(",", -1)); + return valuesList.contains(valor); + } + + private String getSqlImpressaoRMDTipoBPR(boolean isDif) { - private String getSqlImpressaoRMDTipoBPR() { StringBuilder sql = new StringBuilder(); sql.append("select distinct "); sql.append(" b.caja_id as cajaId, "); @@ -3828,8 +3843,17 @@ public class FiscalHibernateDAO extends HibernateDaoSupport implements FiscalDAO sql.append(" left join estado eie on eie.estado_id = cie.estado_id "); sql.append(" left join empresa_imposto ei on ei.empresa_id = b.empresacorrida_id "); sql.append(" and ei.estado_id = coalesce(ae.estado_id, e_ag.estado_id, eos.estado_id, eo.estado_id) and ei.activo = 1 "); - sql.append("where ((b.tipoventa_id = 3 and b.indstatusboleto = 'V' and b.indreimpresion = 0) "); - sql.append(" or (b.tipoventa_id in (12,18) and b.indstatusboleto = 'E' and b.numfoliosistema = b.numfoliopreimpreso)) "); + sql.append("where "); + + if (isDif) { + sql.append(" ((b.tipoventa_id not in (5,12,18,81,82,49,41) and b.indstatusboleto = 'V' and b.indreimpresion = 0) "); + sql.append(" or (b.tipoventa_id in (5,12,18,81,82,49,41) and b.indstatusboleto = 'E' and b.numfoliosistema = b.numfoliopreimpreso)) "); + sql.append(" and a.aidf_id is not null "); + } else { + sql.append(" ((b.tipoventa_id = 3 and b.indstatusboleto = 'V' and b.indreimpresion = 0) "); + sql.append(" or (b.tipoventa_id in (12,18) and b.indstatusboleto = 'E' and b.numfoliosistema = b.numfoliopreimpreso)) "); + } + sql.append(" and (b.motivocancelacion_id is null or b.motivocancelacion_id <> 35) "); sql.append(" and b.indcancelacion = 0 "); sql.append(" and b.empresacorrida_id = :EMPRESA_ID ");