julio 2016-04-29 13:11:47 +00:00
parent c700a213db
commit 0986ad50fb
2 changed files with 282 additions and 52 deletions

View File

@ -30,7 +30,9 @@ import com.rjconsultores.ventaboletos.constantes.Constantes;
import com.rjconsultores.ventaboletos.dao.FiscalDAO;
import com.rjconsultores.ventaboletos.entidad.Empresa;
import com.rjconsultores.ventaboletos.entidad.EsquemaCorrida;
import com.rjconsultores.ventaboletos.entidad.TipoEventoExtra;
import com.rjconsultores.ventaboletos.service.FiscalService;
import com.rjconsultores.ventaboletos.service.TipoEventoExtraService;
import com.rjconsultores.ventaboletos.utilerias.BigDecimalUtil;
import com.rjconsultores.ventaboletos.utilerias.DateUtil;
import com.rjconsultores.ventaboletos.utilerias.LocaleUtil;
@ -45,6 +47,7 @@ import com.rjconsultores.ventaboletos.vo.impressaofiscal.ItemFiscalVO;
import com.rjconsultores.ventaboletos.vo.impressaofiscal.LeitorFiscalReducaoZVO;
import com.rjconsultores.ventaboletos.vo.impressaofiscal.LeitorFiscalVO;
import com.rjconsultores.ventaboletos.vo.impressaofiscal.LeitorManualFiscalVO;
import com.rjconsultores.ventaboletos.vo.impressaofiscal.LeitorNaoFiscalVO;
import com.rjconsultores.ventaboletos.vo.impressaofiscal.SiglaMotivoCancelacion;
import com.rjconsultores.ventaboletos.vo.impressaofiscal.SituacaoTributaria;
import com.rjconsultores.ventaboletos.vo.impressaofiscal.SubItens;
@ -57,6 +60,11 @@ public class FiscalServiceImpl implements FiscalService {
public static final BigDecimal CEM = BigDecimal.valueOf(100);
public static final String QUEBRA_LINHA = "\r\n";
private List<TipoEventoExtra> lsTipoEventoExtra;
@Autowired
private TipoEventoExtraService tipoEventoExtraService;
@Autowired
private FiscalDAO fiscalDAO;
@ -468,7 +476,7 @@ public class FiscalServiceImpl implements FiscalService {
List<ImportacionFiscalVO> list = fiscalDAO.buscaDatosFiscaisECF(inicio, fim, empresa.getEmpresaId(), isCancelados);
for (ImportacionFiscalVO item : list) {
qtdDoc++;
header = null;
itensDocs = new ArrayList<String>();
@ -641,7 +649,7 @@ public class FiscalServiceImpl implements FiscalService {
// PEDAGIO
} else if (codProduto.indexOf("PE") >= 0) {
valorItem = item.getValorPedagio() == null ? valorItem : item.getValorPedagio();
// SEGURO
} else if (codProduto.indexOf("SE") >= 0) {
valorItem = item.getValorSeguro() == null ? valorItem : item.getValorSeguro();
@ -761,7 +769,7 @@ public class FiscalServiceImpl implements FiscalService {
// PEDAGIO
} else if (codProduto.indexOf("PE") >= 0) {
valorItem = item.getValorPedagio() == null ? valorItem : item.getValorPedagio();
// SEGURO
} else if (codProduto.indexOf("SE") >= 0) {
valorItem = item.getValorSeguro() == null ? valorItem : item.getValorSeguro();
@ -929,7 +937,7 @@ public class FiscalServiceImpl implements FiscalService {
header.append(valorMulta == null ? "" : valorMulta);
header.append(brancos);
header.replace(226, 256, claseServicio);
header.append(sequencial);
return header.toString();
@ -1032,8 +1040,8 @@ public class FiscalServiceImpl implements FiscalService {
leitorFiscalReducaoZ.setDatamov(linha.substring(1, 9).trim());
leitorFiscalReducaoZ.setCnpj(linha.substring(9, 23).trim());
leitorFiscalReducaoZ.setAliquota(BigDecimalUtil.getStringToBigDecimal(linha.substring(196, 210).trim(), 2, LocaleUtil.getLocale()));
if(registros.contains(leitorFiscalReducaoZ)) {
if (registros.contains(leitorFiscalReducaoZ)) {
indice = registros.indexOf(leitorFiscalReducaoZ);
leitorFiscalReducaoZ = registros.get(indice);
}
@ -1041,31 +1049,30 @@ public class FiscalServiceImpl implements FiscalService {
leitorFiscalReducaoZ.setImposto(leitorFiscalReducaoZ.getImposto().add(BigDecimalUtil.getStringToBigDecimal(linha.substring(272, 285).trim(), 2, LocaleUtil.getLocale())));
leitorFiscalReducaoZ.setValorNaoTributado(leitorFiscalReducaoZ.getValorNaoTributado().add(BigDecimalUtil.getStringToBigDecimal(linha.substring(182, 196).trim(), 2, LocaleUtil.getLocale())));
leitorFiscalReducaoZ.setVendabrutadiaria(leitorFiscalReducaoZ.getVendabrutadiaria().add(BigDecimalUtil.getStringToBigDecimal(linha.substring(126, 140).trim(), 2, LocaleUtil.getLocale())));
linha = br.readLine();
} else {
linha = br.readLine();
}
if(leitorFiscalReducaoZ != null && indice > -1) {
if (leitorFiscalReducaoZ != null && indice > -1) {
registros.set(indice, leitorFiscalReducaoZ);
} else if (leitorFiscalReducaoZ != null) {
registros.add(leitorFiscalReducaoZ);
}
}
br.close();
Collections.sort(registros);
return registros;
}
private File gerarArquivoReducaoZXls(List<LeitorFiscalReducaoZVO> registros, String nomeArquivo) throws IOException {
HSSFWorkbook workbook = new HSSFWorkbook();
HSSFSheet firstSheet = workbook.createSheet();
int linha = 0;
// Cabecalho
@ -1077,7 +1084,7 @@ public class FiscalServiceImpl implements FiscalService {
row.createCell(4).setCellValue("VALOR_NAO_TRIBUTADO");
row.createCell(5).setCellValue("ALIQUOTA");
row.createCell(6).setCellValue("VALOR_ICMS");
for (LeitorFiscalReducaoZVO leitorFiscal : registros) {
row = firstSheet.createRow(linha++);
row.createCell(0).setCellValue(leitorFiscal.getDatamov());
@ -1088,13 +1095,13 @@ public class FiscalServiceImpl implements FiscalService {
row.createCell(5).setCellValue(leitorFiscal.getAliquota().doubleValue());
row.createCell(6).setCellValue(leitorFiscal.getImposto().doubleValue());
}
ByteArrayOutputStream bos = new ByteArrayOutputStream();
workbook.write(bos);
nomeArquivo = "consolidado_" + nomeArquivo.split("\\.")[0];
File arquivo = File.createTempFile(nomeArquivo, ".xls");
FileOutputStream fos = new FileOutputStream(arquivo);
fos.write(bos.toByteArray());
fos.close();
@ -1116,7 +1123,7 @@ public class FiscalServiceImpl implements FiscalService {
private File gerarArquivoEcfManualXls(List<LeitorManualFiscalVO> registros, String nomeArquivo) throws Exception {
HSSFWorkbook workbook = new HSSFWorkbook();
HSSFSheet firstSheet = workbook.createSheet();
int linha = 0;
// Cabecalho
@ -1135,7 +1142,7 @@ public class FiscalServiceImpl implements FiscalService {
row.createCell(11).setCellValue("ALIQUOTA");
row.createCell(12).setCellValue("VALOR_ICMS");
row.createCell(13).setCellValue("QTDE");
for (LeitorManualFiscalVO leitorFiscal : registros) {
row = firstSheet.createRow(linha++);
row.createCell(0).setCellValue(leitorFiscal.getDataEmissao());
@ -1153,13 +1160,13 @@ public class FiscalServiceImpl implements FiscalService {
row.createCell(12).setCellValue(leitorFiscal.getValorIcms().doubleValue());
row.createCell(13).setCellValue(leitorFiscal.getQtdeItens());
}
ByteArrayOutputStream bos = new ByteArrayOutputStream();
workbook.write(bos);
nomeArquivo = "consolidado_" + nomeArquivo.split("\\.")[0];
File arquivo = File.createTempFile(nomeArquivo, ".xls");
FileOutputStream fos = new FileOutputStream(arquivo);
fos.write(bos.toByteArray());
fos.close();
@ -1169,14 +1176,24 @@ public class FiscalServiceImpl implements FiscalService {
@Override
public File importacionNaoFiscalXls(Empresa empresa, File arquivoTxt) {
return null;
return gerarArquivoNaoFiscalXls(empresa, arquivoTxt);
}
@Override
public File importacionFiscalECFCanceladosXls(Empresa empresa, File arquivoTxt) {
return gerarArquivoEcfXlsGenerico(empresa, arquivoTxt);
}
private File gerarArquivoNaoFiscalXls(Empresa empresa, File arquivoTxt) {
try {
List<LeitorNaoFiscalVO> registros = carregarRegistrosNaoFiscais(empresa, arquivoTxt);
return gerarArquivoNaoFiscaisXls(registros, arquivoTxt.getName());
} catch (Exception e) {
log.error(e.getMessage(), e);
}
return null;
}
private File gerarArquivoEcfXlsGenerico(Empresa empresa, File arquivoTxt) {
try {
List<LeitorFiscalVO> registros = carregarRegistrosEcf(empresa, arquivoTxt);
@ -1190,7 +1207,7 @@ public class FiscalServiceImpl implements FiscalService {
private File gerarArquivoEcfXls(List<LeitorFiscalVO> registros, String nomeArquivo) throws IOException {
HSSFWorkbook workbook = new HSSFWorkbook();
HSSFSheet firstSheet = workbook.createSheet();
int linha = 0;
// Cabecalho
@ -1210,7 +1227,7 @@ public class FiscalServiceImpl implements FiscalService {
row.createCell(12).setCellValue("ALIQUOTA_ICMS");
row.createCell(13).setCellValue("VALOR_ICMS");
row.createCell(14).setCellValue("QTDE");
for (LeitorFiscalVO leitorFiscal : registros) {
row = firstSheet.createRow(linha++);
row.createCell(0).setCellValue(leitorFiscal.getDataEmissao());
@ -1229,19 +1246,19 @@ public class FiscalServiceImpl implements FiscalService {
row.createCell(13).setCellValue(leitorFiscal.getValorIcms().doubleValue());
row.createCell(14).setCellValue(leitorFiscal.getQtdeItens());
}
ByteArrayOutputStream bos = new ByteArrayOutputStream();
workbook.write(bos);
nomeArquivo = "consolidado_" + nomeArquivo.split("\\.")[0];
File arquivo = File.createTempFile(nomeArquivo, ".xls");
FileOutputStream fos = new FileOutputStream(arquivo);
fos.write(bos.toByteArray());
fos.close();
return arquivo;
}
private List<LeitorFiscalVO> carregarRegistrosEcf(Empresa empresa, File arquivoTxt) throws Exception {
@ -1261,8 +1278,8 @@ public class FiscalServiceImpl implements FiscalService {
leitorFiscal.setClaseServicio(linha.substring(226, 256).trim());
leitorFiscal.setDescmotivocancelamento(linha.substring(192, 212).trim());
leitorFiscal.setAliquota(BigDecimalUtil.getStringToBigDecimal(linha.substring(79, 93).trim(), 2, LocaleUtil.getLocale()));
if(registros.contains(leitorFiscal)) {
if (registros.contains(leitorFiscal)) {
indice = registros.indexOf(leitorFiscal);
leitorFiscal = registros.get(indice);
}
@ -1281,31 +1298,31 @@ public class FiscalServiceImpl implements FiscalService {
if (linha.indexOf("PE") >= 0) {
leitorFiscal.setValorPedagio(leitorFiscal.getValorPedagio().add(BigDecimalUtil.getStringToBigDecimal(linha.substring(47, 62).trim(), 2, LocaleUtil.getLocale())));
}
if (linha.indexOf("SE") >= 0) {
leitorFiscal.setValorSeguro(leitorFiscal.getValorSeguro().add(BigDecimalUtil.getStringToBigDecimal(linha.substring(47, 62).trim(), 2, LocaleUtil.getLocale())));
}
linha = br.readLine();
}
} else {
linha = br.readLine();
}
if(leitorFiscal != null && indice > -1) {
if (leitorFiscal != null && indice > -1) {
registros.set(indice, leitorFiscal);
} else if (leitorFiscal != null) {
registros.add(leitorFiscal);
}
}
br.close();
Collections.sort(registros);
return registros;
}
private List<LeitorManualFiscalVO> carregarRegistrosManualFiscal(Empresa empresa, File arquivoTxt) throws Exception {
List<LeitorManualFiscalVO> registros = new ArrayList<LeitorManualFiscalVO>();
BufferedReader br = new BufferedReader(new FileReader(arquivoTxt));
@ -1323,52 +1340,149 @@ public class FiscalServiceImpl implements FiscalService {
leitorManualFiscal.setClaseServicio(linha.substring(226, 256).trim());
leitorManualFiscal.setStatus(linha.substring(223, 224).trim());
leitorManualFiscal.setIcms(BigDecimalUtil.getStringToBigDecimal(linha.substring(79, 93).trim(), 2, LocaleUtil.getLocale()));
if(registros.contains(leitorManualFiscal)) {
if (registros.contains(leitorManualFiscal)) {
indice = registros.indexOf(leitorManualFiscal);
leitorManualFiscal = registros.get(indice);
}
leitorManualFiscal.setValorIcms(leitorManualFiscal.getValorIcms().add(BigDecimalUtil.getStringToBigDecimal(linha.substring(93, 107).trim(), 2, LocaleUtil.getLocale())));
leitorManualFiscal.setValorTotal(leitorManualFiscal.getValorTotal().add(BigDecimalUtil.getStringToBigDecimal(linha.substring(51, 65).trim(), 2, LocaleUtil.getLocale())));
leitorManualFiscal.setQtdeItens(leitorManualFiscal.getQtdeItens() + 1);
linha = br.readLine();
while (linha != null && linha.startsWith("2")) {
if (linha.indexOf("TA") >= 0) {
leitorManualFiscal.setValorItem(leitorManualFiscal.getValorItem().add(BigDecimalUtil.getStringToBigDecimal(linha.substring(47, 62).trim(), 2, LocaleUtil.getLocale())));
}
if (linha.indexOf("TX") >= 0) {
leitorManualFiscal.setImportetaxaembarque(leitorManualFiscal.getImportetaxaembarque().add(BigDecimalUtil.getStringToBigDecimal(linha.substring(47, 62).trim(), 2, LocaleUtil.getLocale())));
}
if (linha.indexOf("PE") >= 0) {
leitorManualFiscal.setImportepedagio(leitorManualFiscal.getImportepedagio().add(BigDecimalUtil.getStringToBigDecimal(linha.substring(47, 62).trim(), 2, LocaleUtil.getLocale())));
}
if (linha.indexOf("SE") >= 0) {
leitorManualFiscal.setImporteseguro(leitorManualFiscal.getImporteseguro().add(BigDecimalUtil.getStringToBigDecimal(linha.substring(47, 62).trim(), 2, LocaleUtil.getLocale())));
}
linha = br.readLine();
}
} else {
linha = br.readLine();
}
if(leitorManualFiscal != null && indice > -1) {
if (leitorManualFiscal != null && indice > -1) {
registros.set(indice, leitorManualFiscal);
} else if (leitorManualFiscal != null) {
registros.add(leitorManualFiscal);
}
}
br.close();
Collections.sort(registros);
return registros;
}
private List<LeitorNaoFiscalVO> carregarRegistrosNaoFiscais(Empresa empresa, File arquivoTxt) throws Exception {
List<LeitorNaoFiscalVO> registros = new ArrayList<LeitorNaoFiscalVO>();
BufferedReader br = new BufferedReader(new FileReader(arquivoTxt));
String linha = br.readLine();
while (linha != null) {
LeitorNaoFiscalVO naoFiscais = null;
int indice = -1;
if (linha.startsWith("1")) {
naoFiscais = new LeitorNaoFiscalVO();
naoFiscais.setEmpresaId(empresa.getEmpresaId());
naoFiscais.setNombempresa(empresa.getNombempresa());
naoFiscais.setDatamov(linha.substring(1, 9).trim());
Integer tipoEventoExtraId = Integer.valueOf(linha.substring(69, 78).trim());
TipoEventoExtra tipoEvento = getTipoEventoExtra(tipoEventoExtraId);
naoFiscais.setTipoeventoextraId(tipoEvento.getTipoeventoextraId());
naoFiscais.setDesctipoevento(tipoEvento.getDescTipoEvento());
if (registros.contains(naoFiscais)) {
indice = registros.indexOf(naoFiscais);
naoFiscais = registros.get(indice);
}
naoFiscais.setValorTotal(naoFiscais.getValorTotal().add(BigDecimalUtil.getStringToBigDecimal(linha.substring(52, 65).trim(), 2, LocaleUtil.getLocale())));
linha = br.readLine();
} else {
linha = br.readLine();
}
if (naoFiscais != null && indice > -1) {
registros.set(indice, naoFiscais);
} else if (naoFiscais != null) {
registros.add(naoFiscais);
}
}
br.close();
Collections.sort(registros);
return registros;
}
private File gerarArquivoNaoFiscaisXls(List<LeitorNaoFiscalVO> registros, String nomeArquivo) throws IOException {
HSSFWorkbook workbook = new HSSFWorkbook();
HSSFSheet firstSheet = workbook.createSheet();
int linha = 0;
// Cabecalho
HSSFRow row = firstSheet.createRow(linha++);
row.createCell(0).setCellValue("DATA_EMISSAO");
row.createCell(1).setCellValue("EMPRESA");
row.createCell(2).setCellValue("CODIGO_NATUREZA");
row.createCell(3).setCellValue("DESCRICAO_NATUREZA");
row.createCell(4).setCellValue("VALOR_TOTAL");
for (LeitorNaoFiscalVO leitorNaoFiscal : registros) {
row = firstSheet.createRow(linha++);
row.createCell(0).setCellValue(leitorNaoFiscal.getDatamov());
row.createCell(1).setCellValue(leitorNaoFiscal.getNombempresa());
row.createCell(2).setCellValue(leitorNaoFiscal.getTipoeventoextraId());
row.createCell(3).setCellValue(leitorNaoFiscal.getDesctipoevento());
row.createCell(4).setCellValue(leitorNaoFiscal.getValorTotal().doubleValue());
}
ByteArrayOutputStream bos = new ByteArrayOutputStream();
workbook.write(bos);
nomeArquivo = "consolidado_" + nomeArquivo.split("\\.")[0];
File arquivo = File.createTempFile(nomeArquivo, ".xls");
FileOutputStream fos = new FileOutputStream(arquivo);
fos.write(bos.toByteArray());
fos.close();
return arquivo;
}
private TipoEventoExtra getTipoEventoExtra(Integer tipoEventoExtraId) {
for (TipoEventoExtra tipoEvento : getListTipoEventoExtra()) {
if (tipoEventoExtraId.equals(tipoEvento.getTipoeventoextraId()))
return tipoEvento;
}
return null;
}
private List<TipoEventoExtra> getListTipoEventoExtra() {
if (lsTipoEventoExtra == null) {
lsTipoEventoExtra = tipoEventoExtraService.obtenerTodos();
}
return lsTipoEventoExtra;
}
}

View File

@ -0,0 +1,116 @@
package com.rjconsultores.ventaboletos.vo.impressaofiscal;
import java.math.BigDecimal;
public class LeitorNaoFiscalVO implements Comparable<LeitorNaoFiscalVO> {
private Integer empresaId;
private String nombempresa;
private String datamov;
private Integer tipoeventoextraId;
private String desctipoevento;
private BigDecimal valorTotal;
public LeitorNaoFiscalVO() {
super();
setValorTotal(BigDecimal.ZERO);
}
public Integer getEmpresaId() {
return empresaId;
}
public void setEmpresaId(Integer empresaId) {
this.empresaId = empresaId;
}
public String getNombempresa() {
return nombempresa;
}
public void setNombempresa(String nombempresa) {
this.nombempresa = nombempresa;
}
public String getDatamov() {
return datamov;
}
public void setDatamov(String datamov) {
this.datamov = datamov;
}
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 getValorTotal() {
return valorTotal;
}
public void setValorTotal(BigDecimal valorTotal) {
this.valorTotal = valorTotal;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((datamov == null) ? 0 : datamov.hashCode());
result = prime * result + ((empresaId == null) ? 0 : empresaId.hashCode());
result = prime * result + ((tipoeventoextraId == null) ? 0 : tipoeventoextraId.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;
LeitorNaoFiscalVO other = (LeitorNaoFiscalVO) obj;
if (datamov == null) {
if (other.datamov != null)
return false;
} else if (!datamov.equals(other.datamov))
return false;
if (empresaId == null) {
if (other.empresaId != null)
return false;
} else if (!empresaId.equals(other.empresaId))
return false;
if (tipoeventoextraId == null) {
if (other.tipoeventoextraId != null)
return false;
} else if (!tipoeventoextraId.equals(other.tipoeventoextraId))
return false;
return true;
}
@Override
public int compareTo(LeitorNaoFiscalVO o) {
int retorno = getDatamov().compareTo(o.getDatamov());
if (retorno == 0) {
retorno = getNombempresa().compareTo(o.getNombempresa());
}
if (retorno == 0) {
retorno = getDesctipoevento().compareTo(o.getDesctipoevento());
}
return retorno;
}
}