From 8cace07b182ab2ba4335dafdd343a9a4d172e54b Mon Sep 17 00:00:00 2001 From: alberto Date: Thu, 9 Feb 2017 20:12:49 +0000 Subject: [PATCH] =?UTF-8?q?Exporta=C3=A7=C3=A3o=20Fiscal=20:=20ECF=20e=20R?= =?UTF-8?q?MD=20(issue=208120)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit git-svn-id: http://desenvolvimento.rjconsultores.com.br/repositorio/sco/AdmVenta/Web/trunk/ventaboletos@65802 d1611594-4594-4d17-8e1d-87c2c4800839 --- .../BusquedaExportacaoFiscalController.java | 48 +++++++++++++++---- 1 file changed, 39 insertions(+), 9 deletions(-) diff --git a/src/java/com/rjconsultores/ventaboletos/web/gui/controladores/impressaofiscal/BusquedaExportacaoFiscalController.java b/src/java/com/rjconsultores/ventaboletos/web/gui/controladores/impressaofiscal/BusquedaExportacaoFiscalController.java index da7a24e12..87344e31b 100644 --- a/src/java/com/rjconsultores/ventaboletos/web/gui/controladores/impressaofiscal/BusquedaExportacaoFiscalController.java +++ b/src/java/com/rjconsultores/ventaboletos/web/gui/controladores/impressaofiscal/BusquedaExportacaoFiscalController.java @@ -3,6 +3,8 @@ package com.rjconsultores.ventaboletos.web.gui.controladores.impressaofiscal; import java.io.File; import java.io.FileInputStream; import java.io.InputStream; +import java.text.SimpleDateFormat; +import java.util.Date; import java.util.List; import javax.sql.DataSource; @@ -100,10 +102,12 @@ public class BusquedaExportacaoFiscalController extends MyGenericForwardComposer } if (empresa != null && estado != null) { - File arquivo = fiscalService.buscarArquivoExportacaoECF(datInicial.getValue(), datFinal.getValue(), empresa, estado); + String nomeArquivo = getNomeArquivoExportacaoECF(datInicial.getValue(), estado); + + File arquivo = fiscalService.buscarArquivoExportacaoECF(datInicial.getValue(), datFinal.getValue(), empresa, estado, nomeArquivo); try { - downloadArquivo(arquivo); + downloadArquivo(arquivo, nomeArquivo); } catch (Exception e) { log.error(e.getMessage(), e); @@ -111,6 +115,35 @@ public class BusquedaExportacaoFiscalController extends MyGenericForwardComposer } } + private String getNomeArquivoExportacaoECF(Date dataInicial, Estado estado) { + String[] mesano = new SimpleDateFormat("MM/yyyy").format(dataInicial).split("/"); + + String mes = mesano[0].toString(); + String ano = mesano[1].toString(); + + String nome = ""; + + switch (Integer.valueOf(mes)) { + case 1: nome = "Jan"; break; + case 2: nome = "Fev"; break; + case 3: nome = "Mar"; break; + case 4: nome = "Abr"; break; + case 5: nome = "Mai"; break; + case 6: nome = "Jun"; break; + case 7: nome = "Jul"; break; + case 8: nome = "Ago"; break; + case 9: nome = "Set"; break; + case 10: nome = "Out"; break; + case 11: nome = "Nov"; break; + case 12: nome = "Dez"; break; + default: break; + } + + String nomeArquivo = "TotalBus " + estado.getCveestado() + " ECF " + nome + ano; + + return nomeArquivo; + } + public void onClick$btnExeExportacaoRMD(Event ev) throws InterruptedException { Empresa empresa = null; Estado estado = null; @@ -130,7 +163,7 @@ public class BusquedaExportacaoFiscalController extends MyGenericForwardComposer File arquivo = fiscalService.buscarArquivoExportacaoRMD(datInicial.getValue(), datFinal.getValue(), empresa, estado); try { - downloadArquivo(arquivo); + downloadArquivo(arquivo, null); } catch (Exception e) { log.error(e.getMessage(), e); @@ -138,16 +171,13 @@ public class BusquedaExportacaoFiscalController extends MyGenericForwardComposer } } - private void downloadArquivo(File arquivoTxt) throws Exception { + private void downloadArquivo(File arquivoTxt, String nome) throws Exception { String contentType = "application/notepad"; InputStream isFile = new FileInputStream(arquivoTxt); String nomeArquivo = arquivoTxt.getName(); - if (nomeArquivo.contains(".fs")) { - String nome = nomeArquivo.substring(0, nomeArquivo.length() - 3); - String[] parte = nome.split("-"); - - nomeArquivo = parte[0].toString() + ".fs"; + if (nome != null && !nome.isEmpty()) { + nomeArquivo = nome + ".fs"; } Filedownload.save(isFile, contentType, nomeArquivo);