wilian 2016-01-20 19:05:57 +00:00
parent ad6c83353d
commit 9e951fa5ee
8 changed files with 232 additions and 1 deletions

View File

@ -1,11 +1,13 @@
package com.rjconsultores.ventaboletos.dao; package com.rjconsultores.ventaboletos.dao;
import java.sql.SQLException;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
import com.rjconsultores.ventaboletos.entidad.EsquemaCorrida; import com.rjconsultores.ventaboletos.entidad.EsquemaCorrida;
import com.rjconsultores.ventaboletos.vo.impressaofiscal.ImportacionFiscalReducaoZVO; import com.rjconsultores.ventaboletos.vo.impressaofiscal.ImportacionFiscalReducaoZVO;
import com.rjconsultores.ventaboletos.vo.impressaofiscal.ImportacionManualFiscalVO; import com.rjconsultores.ventaboletos.vo.impressaofiscal.ImportacionManualFiscalVO;
import com.rjconsultores.ventaboletos.vo.impressaofiscal.ImportacionNaoFiscalVO;
public interface FiscalDAO { public interface FiscalDAO {
@ -17,4 +19,6 @@ public interface FiscalDAO {
public List<ImportacionManualFiscalVO> buscaDatosFiscaisECFManual(Date inicio, Date fim, Integer empresaId); public List<ImportacionManualFiscalVO> buscaDatosFiscaisECFManual(Date inicio, Date fim, Integer empresaId);
public List<ImportacionNaoFiscalVO> buscaDatosNaoFiscais(Date inicio, Date fim, Integer empresaId) throws SQLException;
} }

View File

@ -1,8 +1,15 @@
package com.rjconsultores.ventaboletos.dao.hibernate; package com.rjconsultores.ventaboletos.dao.hibernate;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
import javax.sql.DataSource;
import org.hibernate.Query; import org.hibernate.Query;
import org.hibernate.SessionFactory; import org.hibernate.SessionFactory;
import org.hibernate.transform.AliasToBeanResultTransformer; import org.hibernate.transform.AliasToBeanResultTransformer;
@ -19,12 +26,16 @@ import com.rjconsultores.ventaboletos.entidad.EsquemaCorrida;
import com.rjconsultores.ventaboletos.utilerias.DateUtil; import com.rjconsultores.ventaboletos.utilerias.DateUtil;
import com.rjconsultores.ventaboletos.vo.impressaofiscal.ImportacionFiscalReducaoZVO; import com.rjconsultores.ventaboletos.vo.impressaofiscal.ImportacionFiscalReducaoZVO;
import com.rjconsultores.ventaboletos.vo.impressaofiscal.ImportacionManualFiscalVO; import com.rjconsultores.ventaboletos.vo.impressaofiscal.ImportacionManualFiscalVO;
import com.rjconsultores.ventaboletos.vo.impressaofiscal.ImportacionNaoFiscalVO;
import com.rjconsultores.ventaboletos.vo.impressaofiscal.SituacaoTributaria; import com.rjconsultores.ventaboletos.vo.impressaofiscal.SituacaoTributaria;
@Repository("fiscalDAO") @Repository("fiscalDAO")
public class FiscalHibernateDAO extends GenericHibernateDAO<String, String> implements FiscalDAO { public class FiscalHibernateDAO extends GenericHibernateDAO<String, String> implements FiscalDAO {
public static final String DATE_FORMAT_FISCAL = "yyyyMMdd"; public static final String DATE_FORMAT_FISCAL = "yyyyMMdd";
@Autowired
private DataSource dataSourceRead;
@Autowired @Autowired
public FiscalHibernateDAO(@Qualifier("sessionFactory") SessionFactory factory) { public FiscalHibernateDAO(@Qualifier("sessionFactory") SessionFactory factory) {
@ -434,4 +445,44 @@ public class FiscalHibernateDAO extends GenericHibernateDAO<String, String> impl
int gerarRegistroF2 = this.gerarRegistroF2(lsEsquemaCorrida, dataDe, dataAte); int gerarRegistroF2 = this.gerarRegistroF2(lsEsquemaCorrida, dataDe, dataAte);
return gerarRegistroP2 + gerarRegistroF2; return gerarRegistroP2 + gerarRegistroF2;
} }
@Override
public List<ImportacionNaoFiscalVO> buscaDatosNaoFiscais(Date inicio, Date fim, Integer empresaId) throws SQLException {
StringBuilder sQuery = new StringBuilder();
sQuery.append("SELECT TEE.TIPOEVENTOEXTRA_ID AS TIPOEVENTOEXTRAID, TEE.DESCTIPOEVENTO AS DESCTIPOEVENTO, TRUNC(CD.FECHORVTA) AS FECHORVTA, SUM(CD.PRECIO) AS TOTAL ")
.append("FROM TIPO_EVENTO_EXTRA TEE ")
.append("LEFT JOIN EVENTO_EXTRA EE ON TEE.TIPOEVENTOEXTRA_ID = EE.TIPOEVENTOEXTRA_ID ")
.append("LEFT JOIN CAJA_DIVERSOS CD ON EE.EVENTOEXTRA_ID = CD.EVENTOEXTRA_ID ")
.append("WHERE TEE.ACTIVO = 1 ")
.append("AND EE.EMPRESA_ID = ? ")
.append("AND TRUNC(CD.FECHORVTA) BETWEEN ? AND ? ")
.append("GROUP BY TEE.TIPOEVENTOEXTRA_ID, TEE.DESCTIPOEVENTO, TRUNC(CD.FECHORVTA) ")
.append("ORDER BY TRUNC(CD.FECHORVTA), TEE.DESCTIPOEVENTO ");
PreparedStatement stmt = getConexao().prepareStatement(sQuery.toString());
stmt.setInt(1, empresaId);
stmt.setDate(2, new java.sql.Date(inicio.getTime()));
stmt.setDate(3, new java.sql.Date(fim.getTime()));
ResultSet rset = stmt.executeQuery();
List<ImportacionNaoFiscalVO> importacionNaoFiscalVOs = new ArrayList<ImportacionNaoFiscalVO>();
while (rset.next()) {
ImportacionNaoFiscalVO importacionNaoFiscal = new ImportacionNaoFiscalVO();
importacionNaoFiscal.setTipoeventoextraId(rset.getInt("TIPOEVENTOEXTRAID"));
importacionNaoFiscal.setDesctipoevento(rset.getString("DESCTIPOEVENTO"));
importacionNaoFiscal.setFechorvta(rset.getDate("FECHORVTA"));
importacionNaoFiscal.setTotal(rset.getBigDecimal("TOTAL"));
importacionNaoFiscalVOs.add(importacionNaoFiscal);
}
return importacionNaoFiscalVOs;
}
public Connection getConexao() throws SQLException {
return dataSourceRead.getConnection();
}
} }

View File

@ -7,6 +7,7 @@ import java.util.List;
import com.rjconsultores.ventaboletos.entidad.Empresa; import com.rjconsultores.ventaboletos.entidad.Empresa;
import com.rjconsultores.ventaboletos.entidad.EsquemaCorrida; import com.rjconsultores.ventaboletos.entidad.EsquemaCorrida;
import com.rjconsultores.ventaboletos.vo.impressaofiscal.ImportacionNaoFiscalVO;
public interface FiscalService { public interface FiscalService {
@ -17,5 +18,7 @@ public interface FiscalService {
public File importacionFiscalReducaoZ(Date inicio, Date fim, Empresa empresa); public File importacionFiscalReducaoZ(Date inicio, Date fim, Empresa empresa);
public File importacionFiscalECFManual(Date inicio, Date fim, Empresa empresa); public File importacionFiscalECFManual(Date inicio, Date fim, Empresa empresa);
public File importacionNaoFiscal(Date inicio, Date fim, Empresa empresa);
} }

View File

@ -31,9 +31,11 @@ import com.rjconsultores.ventaboletos.utilerias.DateUtil;
import com.rjconsultores.ventaboletos.utilerias.StringHelper; import com.rjconsultores.ventaboletos.utilerias.StringHelper;
import com.rjconsultores.ventaboletos.utilerias.UsuarioLogado; import com.rjconsultores.ventaboletos.utilerias.UsuarioLogado;
import com.rjconsultores.ventaboletos.utilerias.UtileriasFiscal; import com.rjconsultores.ventaboletos.utilerias.UtileriasFiscal;
import com.rjconsultores.ventaboletos.utilerias.archivointegracion.ArchivoIntegracionNaoFiscal;
import com.rjconsultores.ventaboletos.vo.impressaofiscal.ImportacionFiscalReducaoZVO; import com.rjconsultores.ventaboletos.vo.impressaofiscal.ImportacionFiscalReducaoZVO;
import com.rjconsultores.ventaboletos.vo.impressaofiscal.ImportacionFiscalVO; import com.rjconsultores.ventaboletos.vo.impressaofiscal.ImportacionFiscalVO;
import com.rjconsultores.ventaboletos.vo.impressaofiscal.ImportacionManualFiscalVO; import com.rjconsultores.ventaboletos.vo.impressaofiscal.ImportacionManualFiscalVO;
import com.rjconsultores.ventaboletos.vo.impressaofiscal.ImportacionNaoFiscalVO;
import com.rjconsultores.ventaboletos.vo.impressaofiscal.ItemFiscalVO; import com.rjconsultores.ventaboletos.vo.impressaofiscal.ItemFiscalVO;
import com.rjconsultores.ventaboletos.vo.impressaofiscal.SituacaoTributaria; import com.rjconsultores.ventaboletos.vo.impressaofiscal.SituacaoTributaria;
import com.rjconsultores.ventaboletos.vo.impressaofiscal.SubItens; import com.rjconsultores.ventaboletos.vo.impressaofiscal.SubItens;
@ -949,4 +951,15 @@ public class FiscalServiceImpl implements FiscalService {
return fechamento.toString(); return fechamento.toString();
} }
@Override
public File importacionNaoFiscal(Date inicio, Date fim, Empresa empresa) {
try {
List<ImportacionNaoFiscalVO> importacionNaoFiscalVOs = fiscalDAO.buscaDatosNaoFiscais(inicio, fim, empresa.getEmpresaId());
return new ArchivoIntegracionNaoFiscal().gerarArquivo(empresa.getCnpj(), importacionNaoFiscalVOs);
} catch (Exception e) {
log.error(e.getMessage(), e);
}
return null;
}
} }

View File

@ -9,6 +9,8 @@ import java.util.regex.Pattern;
import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.StringUtils;
public class StringHelper { public class StringHelper {
public static final String QUEBRA_LINHA = "\r\n";
private static String[] REPLACES = { "a", "e", "i", "o", "u", "c", "A", "E", "I", "O", "U", "C" }; private static String[] REPLACES = { "a", "e", "i", "o", "u", "c", "A", "E", "I", "O", "U", "C" };
private static Pattern[] PATTERNS = null; private static Pattern[] PATTERNS = null;

View File

@ -1,6 +1,8 @@
package com.rjconsultores.ventaboletos.utilerias; package com.rjconsultores.ventaboletos.utilerias;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.text.DecimalFormat;
import java.text.NumberFormat;
import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.StringUtils;
@ -30,7 +32,7 @@ public class UtileriasFiscal {
} }
public static void main(String args[]) { public static void main(String args[]) {
System.out.println(defineCodigoProduto(5611, 14199, 4212)); System.out.println(formataZeroDecimal(new BigDecimal(2d), 2, 14));
} }
public static String formataNumerico(final String valor, final int tamanho) { public static String formataNumerico(final String valor, final int tamanho) {
@ -82,4 +84,15 @@ public class UtileriasFiscal {
public static BigDecimal arredondar(BigDecimal aNumber) { public static BigDecimal arredondar(BigDecimal aNumber) {
return aNumber.setScale(DECIMALS, ROUNDING_MODE); return aNumber.setScale(DECIMALS, ROUNDING_MODE);
} }
public static String formataZeroDecimal(final BigDecimal valor, final int casasDecimais, final int tamanho) {
NumberFormat df = DecimalFormat.getInstance();
df.setMinimumFractionDigits(casasDecimais);
df.setMaximumFractionDigits(casasDecimais);
String valorFommat = valor == null ? "" : df.format(valor).replaceAll("[^0-9]", "");
valorFommat = formataNumerico(valorFommat, tamanho);
return valorFommat;
}
} }

View File

@ -0,0 +1,94 @@
package com.rjconsultores.ventaboletos.utilerias.archivointegracion;
import java.io.File;
import java.io.FileOutputStream;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.util.Calendar;
import java.util.List;
import org.apache.log4j.Logger;
import com.rjconsultores.ventaboletos.constantes.Constantes;
import com.rjconsultores.ventaboletos.exception.BusinessException;
import com.rjconsultores.ventaboletos.utilerias.DateUtil;
import com.rjconsultores.ventaboletos.utilerias.StringHelper;
import com.rjconsultores.ventaboletos.utilerias.UsuarioLogado;
import com.rjconsultores.ventaboletos.utilerias.UtileriasFiscal;
import com.rjconsultores.ventaboletos.vo.impressaofiscal.ImportacionNaoFiscalVO;
public class ArchivoIntegracionNaoFiscal {
private static Logger log = Logger.getLogger(ArchivoIntegracionNaoFiscal.class);
private String cnpjFilial;
private Integer sequencial = 0;
private List<ImportacionNaoFiscalVO> importacionNaoFiscalVOs;
private StringBuilder getAberturaArquivo() {
StringBuilder aberturaArquivo = new StringBuilder();
aberturaArquivo.append("0") //Identificador Registro = "0"
.append(DateUtil.getStringCurrentDate("yyyyMMdd")) //Data geração arquivo
.append(StringHelper.preencherStringEspacoEsquerda(cnpjFilial.replace("[^0-9]", ""), 14)) //Cnpj filial
.append(StringHelper.preencherStringEspacoEsquerda(null, 371)) //Brancos
.append(StringHelper.preencherZeroEsquerda((++sequencial).toString(), 6)) //Sequencial
.append(StringHelper.QUEBRA_LINHA);
return aberturaArquivo;
}
private StringBuilder getHeaderArquivo() {
StringBuilder headerArquivo = new StringBuilder();
for (ImportacionNaoFiscalVO importacionNaoFiscalVO : importacionNaoFiscalVOs) {
headerArquivo.append("1") //Identificador Registro = "1"
.append(DateUtil.getStringDate(importacionNaoFiscalVO.getFechorvta(),"yyyyMMdd")) //Data emissão documento
.append(StringHelper.preencherStringEspacoEsquerda(cnpjFilial.replace("[^0-9]", ""), 14)) //Cnpj filial
.append(StringHelper.preencherStringEspacoEsquerda(importacionNaoFiscalVO.getNumeroDocumento(), 9)) //Numero do Documento
.append(StringHelper.preencherStringEspacoEsquerda(null, 3)) //Série
.append(StringHelper.preencherStringEspacoEsquerda("SVP", 5)) //Prefixo = "SVP"
.append(StringHelper.preencherStringEsquerda(null, 6, "9")) //Codigo Cliente "999999"
.append(StringHelper.preencherStringEsquerda(null, 2, "9")) //Filial cliente="99"
.append(StringHelper.preencherStringEsquerda(null, 3, "9")) //Condição pagamento = "999"
.append(UtileriasFiscal.formataZeroDecimal(importacionNaoFiscalVO.getTotal(), 2, 14)) //Valor Total documento
.append(StringHelper.preencherStringEspacoEsquerda("REC", 3)) //Tipo = "REC"
.append(StringHelper.preencherStringEspacoEsquerda(importacionNaoFiscalVO.getTipoeventoextraId()+"", 10)) //Natureza
.append(StringHelper.preencherStringEspacoEsquerda(null, 316)) //Brancos
.append(StringHelper.preencherZeroEsquerda((++sequencial).toString(), 6)) //Sequencial
.append(StringHelper.QUEBRA_LINHA);
}
return headerArquivo;
}
private StringBuilder getFechamentoArquivo() {
StringBuilder fechamentoArquivo = new StringBuilder();
fechamentoArquivo.append("3") //Identificador Registro = "3"
.append(StringHelper.preencherZeroEsquerda((importacionNaoFiscalVOs.size())+"", 6)) //Qtde de Documentos gerados = 1
.append(StringHelper.preencherZeroEsquerda((importacionNaoFiscalVOs.size())+"", 6)) //Qtde de Itens Documentos gerados = 2
.append(StringHelper.preencherStringEspacoEsquerda(null, 381)) //Brancos
.append(StringHelper.preencherZeroEsquerda((++sequencial).toString(), 6)); //Sequencial
return fechamentoArquivo;
}
public File gerarArquivo(String cnpjFilial, List<ImportacionNaoFiscalVO> importacionNaoFiscalVOs) throws BusinessException {
try {
String nomeArquivo = UsuarioLogado.getUsuarioLogado().getNombusuario() + "_" + Calendar.getInstance().getTime().getTime() + "_" + "naofiscal";
File arquivo = File.createTempFile(nomeArquivo, ".tmp");
PrintWriter gravarArq = new PrintWriter(new OutputStreamWriter(new FileOutputStream(arquivo), Constantes.UTF_8));
/* Gerando arquivo */
this.cnpjFilial = cnpjFilial;
this.importacionNaoFiscalVOs = importacionNaoFiscalVOs;
gravarArq.print(getAberturaArquivo());
gravarArq.print(getHeaderArquivo());
gravarArq.print(getFechamentoArquivo());
gravarArq.close();
return arquivo;
} catch (Exception e) {
log.error(e.getMessage(), e);
throw new BusinessException(e.getMessage(), e);
}
}
}

View File

@ -0,0 +1,51 @@
package com.rjconsultores.ventaboletos.vo.impressaofiscal;
import java.math.BigDecimal;
import java.util.Date;
import com.rjconsultores.ventaboletos.utilerias.DateUtil;
public class ImportacionNaoFiscalVO {
private Integer tipoeventoextraId;
private String desctipoevento;
private BigDecimal total;
private Date fechorvta;
public Integer getTipoeventoextraId() {
return tipoeventoextraId;
}
public void setTipoeventoextraId(Integer tipoeventoextraId) {
this.tipoeventoextraId = tipoeventoextraId;
}
public String getDesctipoevento() {
return desctipoevento;
}
public void setDesctipoevento(String desctipoevento) {
this.desctipoevento = desctipoevento;
}
public BigDecimal getTotal() {
return total;
}
public void setTotal(BigDecimal total) {
this.total = total;
}
public Date getFechorvta() {
return fechorvta;
}
public void setFechorvta(Date fechorvta) {
this.fechorvta = fechorvta;
}
public String getNumeroDocumento() {
return getTipoeventoextraId() + DateUtil.getStringDate(getFechorvta(), "ddMMyy");
}
}