fixes bug #7399
git-svn-id: http://desenvolvimento.rjconsultores.com.br/repositorio/sco/AdmVenta/Model/trunk/modelWeb@55382 d1611594-4594-4d17-8e1d-87c2c4800839master
parent
c700a213db
commit
0986ad50fb
|
@ -30,7 +30,9 @@ import com.rjconsultores.ventaboletos.constantes.Constantes;
|
||||||
import com.rjconsultores.ventaboletos.dao.FiscalDAO;
|
import com.rjconsultores.ventaboletos.dao.FiscalDAO;
|
||||||
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.entidad.TipoEventoExtra;
|
||||||
import com.rjconsultores.ventaboletos.service.FiscalService;
|
import com.rjconsultores.ventaboletos.service.FiscalService;
|
||||||
|
import com.rjconsultores.ventaboletos.service.TipoEventoExtraService;
|
||||||
import com.rjconsultores.ventaboletos.utilerias.BigDecimalUtil;
|
import com.rjconsultores.ventaboletos.utilerias.BigDecimalUtil;
|
||||||
import com.rjconsultores.ventaboletos.utilerias.DateUtil;
|
import com.rjconsultores.ventaboletos.utilerias.DateUtil;
|
||||||
import com.rjconsultores.ventaboletos.utilerias.LocaleUtil;
|
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.LeitorFiscalReducaoZVO;
|
||||||
import com.rjconsultores.ventaboletos.vo.impressaofiscal.LeitorFiscalVO;
|
import com.rjconsultores.ventaboletos.vo.impressaofiscal.LeitorFiscalVO;
|
||||||
import com.rjconsultores.ventaboletos.vo.impressaofiscal.LeitorManualFiscalVO;
|
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.SiglaMotivoCancelacion;
|
||||||
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;
|
||||||
|
@ -57,6 +60,11 @@ public class FiscalServiceImpl implements FiscalService {
|
||||||
public static final BigDecimal CEM = BigDecimal.valueOf(100);
|
public static final BigDecimal CEM = BigDecimal.valueOf(100);
|
||||||
public static final String QUEBRA_LINHA = "\r\n";
|
public static final String QUEBRA_LINHA = "\r\n";
|
||||||
|
|
||||||
|
private List<TipoEventoExtra> lsTipoEventoExtra;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private TipoEventoExtraService tipoEventoExtraService;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private FiscalDAO fiscalDAO;
|
private FiscalDAO fiscalDAO;
|
||||||
|
|
||||||
|
@ -1033,7 +1041,7 @@ public class FiscalServiceImpl implements FiscalService {
|
||||||
leitorFiscalReducaoZ.setCnpj(linha.substring(9, 23).trim());
|
leitorFiscalReducaoZ.setCnpj(linha.substring(9, 23).trim());
|
||||||
leitorFiscalReducaoZ.setAliquota(BigDecimalUtil.getStringToBigDecimal(linha.substring(196, 210).trim(), 2, LocaleUtil.getLocale()));
|
leitorFiscalReducaoZ.setAliquota(BigDecimalUtil.getStringToBigDecimal(linha.substring(196, 210).trim(), 2, LocaleUtil.getLocale()));
|
||||||
|
|
||||||
if(registros.contains(leitorFiscalReducaoZ)) {
|
if (registros.contains(leitorFiscalReducaoZ)) {
|
||||||
indice = registros.indexOf(leitorFiscalReducaoZ);
|
indice = registros.indexOf(leitorFiscalReducaoZ);
|
||||||
leitorFiscalReducaoZ = registros.get(indice);
|
leitorFiscalReducaoZ = registros.get(indice);
|
||||||
}
|
}
|
||||||
|
@ -1047,14 +1055,13 @@ public class FiscalServiceImpl implements FiscalService {
|
||||||
linha = br.readLine();
|
linha = br.readLine();
|
||||||
}
|
}
|
||||||
|
|
||||||
if(leitorFiscalReducaoZ != null && indice > -1) {
|
if (leitorFiscalReducaoZ != null && indice > -1) {
|
||||||
registros.set(indice, leitorFiscalReducaoZ);
|
registros.set(indice, leitorFiscalReducaoZ);
|
||||||
} else if (leitorFiscalReducaoZ != null) {
|
} else if (leitorFiscalReducaoZ != null) {
|
||||||
registros.add(leitorFiscalReducaoZ);
|
registros.add(leitorFiscalReducaoZ);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
br.close();
|
br.close();
|
||||||
|
|
||||||
Collections.sort(registros);
|
Collections.sort(registros);
|
||||||
|
@ -1169,7 +1176,7 @@ public class FiscalServiceImpl implements FiscalService {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public File importacionNaoFiscalXls(Empresa empresa, File arquivoTxt) {
|
public File importacionNaoFiscalXls(Empresa empresa, File arquivoTxt) {
|
||||||
return null;
|
return gerarArquivoNaoFiscalXls(empresa, arquivoTxt);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -1177,6 +1184,16 @@ public class FiscalServiceImpl implements FiscalService {
|
||||||
return gerarArquivoEcfXlsGenerico(empresa, 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) {
|
private File gerarArquivoEcfXlsGenerico(Empresa empresa, File arquivoTxt) {
|
||||||
try {
|
try {
|
||||||
List<LeitorFiscalVO> registros = carregarRegistrosEcf(empresa, arquivoTxt);
|
List<LeitorFiscalVO> registros = carregarRegistrosEcf(empresa, arquivoTxt);
|
||||||
|
@ -1262,7 +1279,7 @@ public class FiscalServiceImpl implements FiscalService {
|
||||||
leitorFiscal.setDescmotivocancelamento(linha.substring(192, 212).trim());
|
leitorFiscal.setDescmotivocancelamento(linha.substring(192, 212).trim());
|
||||||
leitorFiscal.setAliquota(BigDecimalUtil.getStringToBigDecimal(linha.substring(79, 93).trim(), 2, LocaleUtil.getLocale()));
|
leitorFiscal.setAliquota(BigDecimalUtil.getStringToBigDecimal(linha.substring(79, 93).trim(), 2, LocaleUtil.getLocale()));
|
||||||
|
|
||||||
if(registros.contains(leitorFiscal)) {
|
if (registros.contains(leitorFiscal)) {
|
||||||
indice = registros.indexOf(leitorFiscal);
|
indice = registros.indexOf(leitorFiscal);
|
||||||
leitorFiscal = registros.get(indice);
|
leitorFiscal = registros.get(indice);
|
||||||
}
|
}
|
||||||
|
@ -1292,7 +1309,7 @@ public class FiscalServiceImpl implements FiscalService {
|
||||||
linha = br.readLine();
|
linha = br.readLine();
|
||||||
}
|
}
|
||||||
|
|
||||||
if(leitorFiscal != null && indice > -1) {
|
if (leitorFiscal != null && indice > -1) {
|
||||||
registros.set(indice, leitorFiscal);
|
registros.set(indice, leitorFiscal);
|
||||||
} else if (leitorFiscal != null) {
|
} else if (leitorFiscal != null) {
|
||||||
registros.add(leitorFiscal);
|
registros.add(leitorFiscal);
|
||||||
|
@ -1324,7 +1341,7 @@ public class FiscalServiceImpl implements FiscalService {
|
||||||
leitorManualFiscal.setStatus(linha.substring(223, 224).trim());
|
leitorManualFiscal.setStatus(linha.substring(223, 224).trim());
|
||||||
leitorManualFiscal.setIcms(BigDecimalUtil.getStringToBigDecimal(linha.substring(79, 93).trim(), 2, LocaleUtil.getLocale()));
|
leitorManualFiscal.setIcms(BigDecimalUtil.getStringToBigDecimal(linha.substring(79, 93).trim(), 2, LocaleUtil.getLocale()));
|
||||||
|
|
||||||
if(registros.contains(leitorManualFiscal)) {
|
if (registros.contains(leitorManualFiscal)) {
|
||||||
indice = registros.indexOf(leitorManualFiscal);
|
indice = registros.indexOf(leitorManualFiscal);
|
||||||
leitorManualFiscal = registros.get(indice);
|
leitorManualFiscal = registros.get(indice);
|
||||||
}
|
}
|
||||||
|
@ -1357,7 +1374,7 @@ public class FiscalServiceImpl implements FiscalService {
|
||||||
linha = br.readLine();
|
linha = br.readLine();
|
||||||
}
|
}
|
||||||
|
|
||||||
if(leitorManualFiscal != null && indice > -1) {
|
if (leitorManualFiscal != null && indice > -1) {
|
||||||
registros.set(indice, leitorManualFiscal);
|
registros.set(indice, leitorManualFiscal);
|
||||||
} else if (leitorManualFiscal != null) {
|
} else if (leitorManualFiscal != null) {
|
||||||
registros.add(leitorManualFiscal);
|
registros.add(leitorManualFiscal);
|
||||||
|
@ -1371,4 +1388,101 @@ public class FiscalServiceImpl implements FiscalService {
|
||||||
return 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;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue