diff --git a/src/java/com/rjconsultores/ventaboletos/web/gui/controladores/relatorios/RelatorioEmbarqueLocalidadeController.java b/src/java/com/rjconsultores/ventaboletos/web/gui/controladores/relatorios/RelatorioEmbarqueLocalidadeController.java index c2ef9f3d8..cdfe5c306 100644 --- a/src/java/com/rjconsultores/ventaboletos/web/gui/controladores/relatorios/RelatorioEmbarqueLocalidadeController.java +++ b/src/java/com/rjconsultores/ventaboletos/web/gui/controladores/relatorios/RelatorioEmbarqueLocalidadeController.java @@ -10,6 +10,7 @@ import java.sql.SQLException; import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Calendar; +import java.util.Date; import java.util.HashMap; import java.util.LinkedHashMap; import java.util.List; @@ -52,6 +53,7 @@ import com.rjconsultores.ventaboletos.service.EmpresaService; import com.rjconsultores.ventaboletos.service.OrgaoConcedenteService; import com.rjconsultores.ventaboletos.service.ParadaService; import com.rjconsultores.ventaboletos.service.RutaService; +import com.rjconsultores.ventaboletos.utilerias.DateUtil; import com.rjconsultores.ventaboletos.utilerias.UsuarioLogado; import com.rjconsultores.ventaboletos.web.utilerias.MyComboboxEstandar; import com.rjconsultores.ventaboletos.web.utilerias.MyGenericForwardComposer; @@ -204,9 +206,9 @@ public class RelatorioEmbarqueLocalidadeController extends MyGenericForwardCompo int linha = NUM_LINHA_INICIO; HSSFRow row = null; - - sheet1 = wb.createSheet("07-08-19"); - geraCabecalho(sheet1, "07-08-19", wb); + String dataAtual = DateUtil.getStringDate(new Date(),"dd-MM-yy"); + sheet1 = wb.createSheet(dataAtual); + geraCabecalho(sheet1, dataAtual, wb); Map linhas = new HashMap(); int totalGeral = 0; @@ -281,25 +283,8 @@ public class RelatorioEmbarqueLocalidadeController extends MyGenericForwardCompo Messagebox.OK, Messagebox.INFORMATION); return; } - - String nomeArquivo = UsuarioLogado.getUsuarioLogado().getNombusuario() - + "_" + Calendar.getInstance().getTime().getTime() - + "_" + "EmbarqueLocalidade"; - - File fNomeArquivo = File.createTempFile(nomeArquivo, ".tmp"); - - FileOutputStream stream = new FileOutputStream(fNomeArquivo); - - wb.write(stream); - - InputStream is = null; - is = new FileInputStream(fNomeArquivo); - Filedownload.save(is, "application/xls", "EmbarqueLocalidade.xls"); - fNomeArquivo.delete(); - stream.flush(); - stream.close(); - //is.close(); - + + downloadArquivo(wb); } catch (Exception e) { e.printStackTrace(); @@ -307,6 +292,29 @@ public class RelatorioEmbarqueLocalidadeController extends MyGenericForwardCompo } } + + private void downloadArquivo(HSSFWorkbook wb) throws Exception { + + + String nomeArquivo = UsuarioLogado.getUsuarioLogado().getNombusuario() + "_" + Calendar.getInstance().getTime().getTime() + "_" + "EmbarqueLocalidade.xls"; + File fNomeArquivo = File.createTempFile(nomeArquivo, ".tmp"); + String contentType = "application/vnd.ms-excel"; + + InputStream isFile = new FileInputStream(fNomeArquivo); + Filedownload.save(isFile, contentType, nomeArquivo); + FileOutputStream stream = new FileOutputStream(fNomeArquivo); + + wb.write(stream); + + InputStream is = new FileInputStream(fNomeArquivo); + Filedownload.save(is, contentType, nomeArquivo); + stream.flush(); + stream.close(); + + if (fNomeArquivo != null) { + fNomeArquivo.delete(); + } + } private void geraCabecalhoTitulo(HSSFSheet sheet1, HSSFWorkbook wb) { HSSFRow titulo = sheet1.createRow(NUM_LINHA_TITULO); @@ -422,7 +430,7 @@ public class RelatorioEmbarqueLocalidadeController extends MyGenericForwardCompo lsEmpresas = empresaService.obtenerTodos(); lsOrgaosConcedentes = orgaoConcedenteService.obtenerTodos(); lsOrigens = paradaService.obtenerTodos(); - // lsRutas = rutaService.obtenerTodos(); + lsRutas = rutaService.obtenerTodos(); } public void onChange$cmbOrgaoConcedente(Event ev) throws Exception {