From 0a05c5917e0db7f54d55751f757ef7037a4f9680 Mon Sep 17 00:00:00 2001 From: julio Date: Wed, 25 May 2016 19:32:31 +0000 Subject: [PATCH] bug #7500 git-svn-id: http://desenvolvimento.rjconsultores.com.br/repositorio/sco/AdmVenta/Model/trunk/modelWeb@56388 d1611594-4594-4d17-8e1d-87c2c4800839 --- .../dao/hibernate/FiscalHibernateDAO.java | 30 +++++----- .../service/impl/FiscalServiceImpl.java | 29 +++++++++- .../ImportacionFiscalReducaoZVO.java | 58 +++++++++++++++++++ .../impressaofiscal/ImportacionFiscalVO.java | 9 +++ .../impressaofiscal/SituacaoTributaria.java | 2 +- 5 files changed, 112 insertions(+), 16 deletions(-) diff --git a/src/com/rjconsultores/ventaboletos/dao/hibernate/FiscalHibernateDAO.java b/src/com/rjconsultores/ventaboletos/dao/hibernate/FiscalHibernateDAO.java index 8f48323a4..9319751af 100644 --- a/src/com/rjconsultores/ventaboletos/dao/hibernate/FiscalHibernateDAO.java +++ b/src/com/rjconsultores/ventaboletos/dao/hibernate/FiscalHibernateDAO.java @@ -193,11 +193,11 @@ public class FiscalHibernateDAO implements FiscalDAO { } @Override - public List buscaDatosFiscaisReducaoZ(Date inicio, Date fim, Integer empresaId,Connection connection) throws SQLException { + public List buscaDatosFiscaisReducaoZ(Date inicio, Date fim, Integer empresaId, Connection connection) throws SQLException { PreparedStatement stmt = null; ResultSet rset = null; - + StringBuilder sql = new StringBuilder(); sql.append("SELECT r2.datamov AS datamov, "); sql.append(" r2.numreducoes AS numreducoes, "); @@ -212,7 +212,7 @@ public class FiscalHibernateDAO implements FiscalDAO { sql.append(" r3.totparcial AS aliquota, "); sql.append(" r3.valoracumulado AS imposto, "); sql.append(" ifi.numserie AS numpdv, "); - sql.append(" e.cnpj AS cnpj, "); + sql.append(" TRANSLATE(t2.cnpj, ' / - . ', ' ') AS cnpj,"); sql.append(" r2.totgeral AS gtFinal, "); sql.append(" anterior.totgeral AS gtInicial "); sql.append("FROM fiscal_r2 r2 "); @@ -225,18 +225,16 @@ public class FiscalHibernateDAO implements FiscalDAO { sql.append(" AND r3.fiscalimpressora_id = ifi.fiscalimpressora_id "); sql.append(" inner join fiscal_t2 t2 "); sql.append(" ON ifi.fiscalimpressora_id = t2.fiscalimpressora_id "); - sql.append(" inner join empresa e ON TRANSLATE(t2.cnpj, ' / - . ', ' ') "); - sql.append(" in (TRANSLATE(e.cnpj, ' / - . ', ' '), "); - sql.append(" (select TRANSLATE(cnpj, ' / - . ', ' ') from inscricao_estadual where empresa_id = ? )),"); + sql.append(" inner join empresa e ON (TRANSLATE(t2.cnpj, ' / - . ', ' ') = (TRANSLATE(e.cnpj, ' / - . ', ' ')) ) or "); + sql.append(" (TRANSLATE(t2.cnpj, ' / - . ', ' ') in "); + sql.append(" (select TRANSLATE(cnpj, ' / - . ', ' ') from inscricao_estadual where empresa_id = ? and activo = 1 )), "); sql.append(" (SELECT numserie20, crz, totgeral "); sql.append(" FROM fiscal_r2) anterior "); sql.append("WHERE r2.datamov BETWEEN ? AND ? "); sql.append(" AND r2.activo = 1 "); sql.append(" AND e.empresa_id = ? "); sql.append(" AND r3.totparcial not in ("); - sql.append("'" + SituacaoTributaria.CANCELADO.getValue() + "'").append(", "); - sql.append("'" + SituacaoTributaria.DESCRITIVO.getValue() + "'").append(", "); - sql.append("'" + SituacaoTributaria.OPCIONAL.getValue() + "'").append(")"); + sql.append("'" + SituacaoTributaria.NAO_FISCAL.getValue() + "'").append(")"); sql.append(" AND anterior.numserie20 = r2.numserie20 "); sql.append(" AND anterior.crz = r2.crz - 1 "); sql.append("GROUP BY r2.datamov, "); @@ -252,7 +250,7 @@ public class FiscalHibernateDAO implements FiscalDAO { sql.append(" r3.totparcial, "); sql.append(" r3.valoracumulado, "); sql.append(" ifi.numserie, "); - sql.append(" e.cnpj, "); + sql.append(" t2.cnpj, "); sql.append(" r2.totgeral, "); sql.append(" anterior.totgeral "); sql.append("ORDER BY r2.datamov, "); @@ -329,7 +327,8 @@ public class FiscalHibernateDAO implements FiscalDAO { sql.append(" 'C' as status, "); sql.append(" b.motivocancelacion_id as motivocancelacion, "); sql.append(" ee.impingreso as valorMulta, "); - sql.append(" cs.descclase as claseServicio "); + sql.append(" cs.descclase as claseServicio, "); + sql.append(" translate(fi.numcnpj, ' / - . ', ' ') as cnpjEcf "); sql.append(" FROM fiscal_r4 r4 "); sql.append(" INNER JOIN fiscal_r5 r5 ON r4.numserie20 = r5.numserie20 AND r4.coo = r5.coo "); sql.append(" AND r4.datamov = r5.datamov AND r4.contador = r5.contador "); @@ -349,6 +348,7 @@ public class FiscalHibernateDAO implements FiscalDAO { sql.append(" WHERE r4.datamov BETWEEN ? AND ? "); sql.append(" AND b.marca_id = ? "); sql.append(" AND b.motivocancelacion_id in (31, 32, 10) "); + sql.append(" AND r4.indcancelamento = 'N' "); sql.append(" GROUP BY r4.numserie20, "); sql.append(" r4.coo, "); sql.append(" r4.datainicialemissao, "); @@ -376,7 +376,8 @@ public class FiscalHibernateDAO implements FiscalDAO { sql.append(" b.importetaxaembarque, "); sql.append(" b.importepedagio, "); sql.append(" b.importeseguro, "); - sql.append(" cs.descclase "); + sql.append(" cs.descclase, "); + sql.append(" fi.numcnpj "); sql.append(" ORDER BY r4.datainicialemissao, "); sql.append(" r4.numserie20, "); sql.append(" r4.coo, "); @@ -413,6 +414,7 @@ public class FiscalHibernateDAO implements FiscalDAO { sql.append(" b.importepedagio as importepedagio, "); sql.append(" b.importeseguro as importeseguro, "); sql.append(" cs.descclase as claseServicio, "); + sql.append(" translate(fi.numcnpj, ' / - . ', ' ') as cnpjEcf, "); sql.append(" 'N' as status "); sql.append(" FROM fiscal_r4 r4 "); sql.append(" INNER JOIN fiscal_r5 r5 ON r4.numserie20 = r5.numserie20 AND r4.coo = r5.coo "); @@ -431,6 +433,7 @@ public class FiscalHibernateDAO implements FiscalDAO { sql.append(" INNER JOIN estado ed ON ed.estado_id = cd.estado_id "); sql.append(" WHERE r4.datamov BETWEEN ? AND ? "); sql.append(" AND b.marca_id = ? "); + sql.append(" AND r4.indcancelamento = 'N' "); sql.append(" GROUP BY r4.numserie20, "); sql.append(" r4.coo, "); sql.append(" r4.datainicialemissao, "); @@ -456,7 +459,8 @@ public class FiscalHibernateDAO implements FiscalDAO { sql.append(" b.importetaxaembarque, "); sql.append(" b.importepedagio, "); sql.append(" b.importeseguro, "); - sql.append(" cs.descclase "); + sql.append(" cs.descclase, "); + sql.append(" fi.numcnpj "); sql.append(" ORDER BY r4.datainicialemissao, "); sql.append(" r4.numserie20, "); sql.append(" r4.coo, "); diff --git a/src/com/rjconsultores/ventaboletos/service/impl/FiscalServiceImpl.java b/src/com/rjconsultores/ventaboletos/service/impl/FiscalServiceImpl.java index 8af2b117f..33272d6ef 100644 --- a/src/com/rjconsultores/ventaboletos/service/impl/FiscalServiceImpl.java +++ b/src/com/rjconsultores/ventaboletos/service/impl/FiscalServiceImpl.java @@ -457,12 +457,36 @@ public class FiscalServiceImpl implements FiscalService { List aux = new ArrayList(); BigDecimal valorNaoTributado = null; + BigDecimal valorNaoIncluido = BigDecimal.ZERO; + + ImportacionFiscalReducaoZVO item = null; + for (ImportacionFiscalReducaoZVO ifr : list) { - if (ifr.getAliquota().equals(SituacaoTributaria.NAO_TRIBUTADO.getValue())) { + + if (!ifr.equals(item)) { + valorNaoIncluido = BigDecimal.ZERO; + item = ifr; + } + + String tipoMovimento = ifr.getAliquota(); + if (tipoMovimento.equals(SituacaoTributaria.CANCELADO.getValue()) || + tipoMovimento.equals(SituacaoTributaria.DESCONTO.getValue())) { + + valorNaoIncluido = valorNaoIncluido.add(ifr.getImposto()); + ifr.setValorNaoIncluido(valorNaoIncluido); + + } else if (tipoMovimento.equals(SituacaoTributaria.NAO_TRIBUTADO.getValue())) { valorNaoTributado = ifr.getImposto(); } else { + ifr.setValorNaoTributado(valorNaoTributado); + ifr.setValorNaoIncluido(valorNaoIncluido); + + BigDecimal valorReducaoZ = ifr.getVendabrutadiaria().subtract(valorNaoIncluido); + ifr.setVendabrutadiaria(valorReducaoZ); + aux.add(ifr); + } } @@ -516,6 +540,7 @@ public class FiscalServiceImpl implements FiscalService { String data = item.getDataEmissao(); String brancos = StringHelper.preencherStringEspacoEsquerda(null, 202); + String cnpjEcf = item.getCnpjEcf() == null ? cnpjFilial : item.getCnpjEcf(); String serie = item.getNumImpressora(); if (serie.length() >= 20) { @@ -579,7 +604,7 @@ public class FiscalServiceImpl implements FiscalService { String claseServicio = StringHelper.preencherStringEspacoDireita(item.getClaseServicio(), 30); String seqHeader = StringHelper.preencherZeroEsquerda(Integer.valueOf(seq).toString(), 6); - header = headerDocumentoFiscal("1", data, cnpjFilial, coo, serie, especie, codigoCliente, + header = headerDocumentoFiscal("1", data, cnpjEcf, coo, serie, especie, codigoCliente, filialCliente, condicaoPagamento, valorTotalDocumanto, valorItens, aliquota, imposto, valorPIS, valorCofins, valorCSLL, totalICMSIsento, totalICMSNaotributado, origenUf, origen, destinoUf, destino, null, null, status, motivocancelacion, valorMulta, brancos, claseServicio, seqHeader); diff --git a/src/com/rjconsultores/ventaboletos/vo/impressaofiscal/ImportacionFiscalReducaoZVO.java b/src/com/rjconsultores/ventaboletos/vo/impressaofiscal/ImportacionFiscalReducaoZVO.java index fe0f0bdc7..9caca4d85 100644 --- a/src/com/rjconsultores/ventaboletos/vo/impressaofiscal/ImportacionFiscalReducaoZVO.java +++ b/src/com/rjconsultores/ventaboletos/vo/impressaofiscal/ImportacionFiscalReducaoZVO.java @@ -21,6 +21,7 @@ public class ImportacionFiscalReducaoZVO { private String numpdv; private BigDecimal gtFinal; private BigDecimal gtInicial; + private BigDecimal valorNaoIncluido; public String getDatamov() { return datamov; @@ -158,4 +159,61 @@ public class ImportacionFiscalReducaoZVO { this.gtInicial = gtInicial; } + public BigDecimal getValorNaoIncluido() { + return valorNaoIncluido; + } + + public void setValorNaoIncluido(BigDecimal valorNaoIncluido) { + this.valorNaoIncluido = valorNaoIncluido; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((coofinal == null) ? 0 : coofinal.hashCode()); + result = prime * result + ((cooinicial == null) ? 0 : cooinicial.hashCode()); + result = prime * result + ((datamov == null) ? 0 : datamov.hashCode()); + result = prime * result + ((datareducao == null) ? 0 : datareducao.hashCode()); + result = prime * result + ((numserie20 == null) ? 0 : numserie20.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + ImportacionFiscalReducaoZVO other = (ImportacionFiscalReducaoZVO) obj; + if (coofinal == null) { + if (other.coofinal != null) + return false; + } else if (!coofinal.equals(other.coofinal)) + return false; + if (cooinicial == null) { + if (other.cooinicial != null) + return false; + } else if (!cooinicial.equals(other.cooinicial)) + return false; + if (datamov == null) { + if (other.datamov != null) + return false; + } else if (!datamov.equals(other.datamov)) + return false; + if (datareducao == null) { + if (other.datareducao != null) + return false; + } else if (!datareducao.equals(other.datareducao)) + return false; + if (numserie20 == null) { + if (other.numserie20 != null) + return false; + } else if (!numserie20.equals(other.numserie20)) + return false; + return true; + } + } diff --git a/src/com/rjconsultores/ventaboletos/vo/impressaofiscal/ImportacionFiscalVO.java b/src/com/rjconsultores/ventaboletos/vo/impressaofiscal/ImportacionFiscalVO.java index d77e641aa..50eb661b9 100644 --- a/src/com/rjconsultores/ventaboletos/vo/impressaofiscal/ImportacionFiscalVO.java +++ b/src/com/rjconsultores/ventaboletos/vo/impressaofiscal/ImportacionFiscalVO.java @@ -29,6 +29,7 @@ public class ImportacionFiscalVO { private BigDecimal valorPedagio; private BigDecimal valorEmbarque; private BigDecimal valorSeguro; + private String cnpjEcf; private List itensFiscais; @@ -294,4 +295,12 @@ public class ImportacionFiscalVO { this.descmotivocancelamento = descmotivocancelamento; } + public String getCnpjEcf() { + return cnpjEcf; + } + + public void setCnpjEcf(String cnpjEcf) { + this.cnpjEcf = cnpjEcf; + } + } diff --git a/src/com/rjconsultores/ventaboletos/vo/impressaofiscal/SituacaoTributaria.java b/src/com/rjconsultores/ventaboletos/vo/impressaofiscal/SituacaoTributaria.java index b3eb6ee41..db836e0ec 100644 --- a/src/com/rjconsultores/ventaboletos/vo/impressaofiscal/SituacaoTributaria.java +++ b/src/com/rjconsultores/ventaboletos/vo/impressaofiscal/SituacaoTributaria.java @@ -1,7 +1,7 @@ package com.rjconsultores.ventaboletos.vo.impressaofiscal; public enum SituacaoTributaria { - TRIBUTADO("T"), NAO_TRIBUTADO("N1"), CANCELADO("Can-T"), DESCRITIVO("DT"), OPCIONAL("OPNF"); + TRIBUTADO("T"), NAO_TRIBUTADO("N1"), CANCELADO("Can-T"), DESCONTO("DT"), NAO_FISCAL("OPNF"); private String value;