From 6acaf374b2ef9de37796c875423779ec6cc72f2a Mon Sep 17 00:00:00 2001 From: julio Date: Mon, 27 Apr 2015 20:14:23 +0000 Subject: [PATCH] =?UTF-8?q?Erro=20-=20Modifica=C3=A7=C3=A3o=20Massiva=20de?= =?UTF-8?q?=20Pre=C3=A7os=20(fixes=20bug=20#6227)=20Tempo:=2002=20horas?= 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@43435 d1611594-4594-4d17-8e1d-87c2c4800839 --- .../ModificacionMasivaTarifasController.java | 269 +++++++++--------- 1 file changed, 134 insertions(+), 135 deletions(-) diff --git a/src/java/com/rjconsultores/ventaboletos/web/gui/controladores/tarifas/ModificacionMasivaTarifasController.java b/src/java/com/rjconsultores/ventaboletos/web/gui/controladores/tarifas/ModificacionMasivaTarifasController.java index 17da4a2fe..816e156bf 100644 --- a/src/java/com/rjconsultores/ventaboletos/web/gui/controladores/tarifas/ModificacionMasivaTarifasController.java +++ b/src/java/com/rjconsultores/ventaboletos/web/gui/controladores/tarifas/ModificacionMasivaTarifasController.java @@ -304,7 +304,7 @@ public class ModificacionMasivaTarifasController extends MyGenericForwardCompose } } } catch (Exception e) { - log.error("",e); + log.error("", e); log.debug("Porcentagem Zero"); } @@ -329,167 +329,166 @@ public class ModificacionMasivaTarifasController extends MyGenericForwardCompose String ruta = ""; int contRow = 0; - if(!lsRutaCombinacion.isEmpty()){ + if (!lsRutaCombinacion.isEmpty()) { - for (int i = 0; i < lsRutaCombinacion.size(); i++) { - Object[] obj = (Object[]) lsRutaCombinacion.get(i); + for (int i = 0; i < lsRutaCombinacion.size(); i++) { + Object[] obj = (Object[]) lsRutaCombinacion.get(i); - if (!ruta.equals(obj[4].toString().concat(obj[12].toString()))) { + if (!ruta.equals(obj[4].toString().concat(obj[12].toString()))) { - ruta = obj[4].toString().concat(obj[12].toString()); - String sheetName = ""; - if (obj[4].toString().length() > 26) { - sheetName = (obj[4].toString().substring(0, 26).concat(" (").concat(obj[12].toString()).concat(")")); - } else { - sheetName = (obj[4].toString().concat(" (").concat(obj[12].toString()).concat(")")); + ruta = obj[4].toString().concat(obj[12].toString()); + String sheetName = ""; + if (obj[4].toString().length() > 26) { + sheetName = (obj[12].toString().concat("-").concat(obj[4].toString().substring(0, 26))); + } else { + sheetName = (obj[12].toString().concat("-").concat(obj[4].toString())); + } + sheetName = sheetName.replaceAll("/", "-"); + log.debug("Aba: " + sheetName); + + sheet1 = wb.createSheet(sheetName); + contRow = 1; + + HSSFRow rowCabecalho = sheet1.createRow(0); + + HSSFCell cell = rowCabecalho.createCell(0); + cell.setCellValue( + Labels.getLabel("busquedaTarifaController.lhId.label")); + cell.setCellStyle(estilo); + + HSSFCell cell0 = rowCabecalho.createCell(1); + cell0.setCellValue( + Labels.getLabel("busquedaTarifaController.lhTramo.label")); + cell0.setCellStyle(estilo); + + HSSFCell cell1 = rowCabecalho.createCell(2); + cell1.setCellValue( + Labels.getLabel("busquedaTarifaController.lhOrigen.label")); + cell1.setCellStyle(estilo); + + HSSFCell cell2 = rowCabecalho.createCell(3); + cell2.setCellValue( + Labels.getLabel("busquedaTarifaController.lhDestino.label")); + cell2.setCellStyle(estilo); + + HSSFCell cell3 = rowCabecalho.createCell(4); + cell3.setCellValue( + Labels.getLabel("busquedaTarifaController.lhRuta.label")); + cell3.setCellStyle(estilo); + + HSSFCell cell4 = rowCabecalho.createCell(5); + cell4.setCellValue( + Labels.getLabel("busquedaTarifaController.lhMarca.label")); + cell4.setCellStyle(estilo); + + // Preco original I - 6 + HSSFCell cell5 = rowCabecalho.createCell(6); + cell5.setCellValue( + Labels.getLabel("busquedaTarifaController.lhClaseServicio.label")); + cell5.setCellStyle(estilo); + + // H - 6 + HSSFCell cell6 = rowCabecalho.createCell(7); + cell6.setCellValue( + Labels.getLabel("busquedaTarifaController.lhFeciniciovigencia.label")); + cell6.setCellStyle(estilo); + + // I - 8 + HSSFCell cell7 = rowCabecalho.createCell(8); + cell7.setCellValue( + Labels.getLabel("busquedaTarifaController.lhMoneda.label")); + cell7.setCellStyle(estilo); + + // J - 9 + HSSFCell cell8 = rowCabecalho.createCell(9); + cell8.setCellValue( + Labels.getLabel("busquedaTarifaController.lhPrecioOriginal.label")); + cell8.setCellStyle(estilo); + + // J - 9 + HSSFCell cell9 = rowCabecalho.createCell(10); + cell9.setCellValue( + Labels.getLabel("busquedaTarifaController.lhPrecioExcel.label")); + cell9.setCellStyle(estilo); + + // h - 10 + HSSFCell cell10 = rowCabecalho.createCell(11); + cell10.setCellValue( + Labels.getLabel("busquedaTarifaController.lhPrecioNuevo.label")); + cell10.setCellStyle(estilo); + + HSSFCell cell12 = rowCabecalho.createCell(12); + cell12.setCellValue( + Labels.getLabel("busquedaTarifaController.lhPrecioPedagio.label")); + cell12.setCellStyle(estilo); } - sheetName = sheetName.replaceAll("/", "-"); - log.debug("Aba: " + sheetName); - sheet1 = wb.createSheet(sheetName); - contRow = 1; - HSSFRow rowCabecalho = sheet1.createRow(0); + HSSFRow row = sheet1.createRow(contRow++); - HSSFCell cell = rowCabecalho.createCell(0); - cell.setCellValue( - Labels.getLabel("busquedaTarifaController.lhId.label")); - cell.setCellStyle(estilo); + row.createCell(0).setCellValue(Integer.parseInt(obj[0].toString())); + row.createCell(1).setCellValue(obj[1].toString()); + row.createCell(2).setCellValue(obj[2].toString()); + row.createCell(3).setCellValue(obj[3].toString()); + row.createCell(4).setCellValue(obj[4].toString().concat(" (").concat(obj[12].toString()).concat(")")); + row.createCell(5).setCellValue(obj[5].toString()); + row.createCell(6).setCellValue(obj[6].toString()); - HSSFCell cell0 = rowCabecalho.createCell(1); - cell0.setCellValue( - Labels.getLabel("busquedaTarifaController.lhTramo.label")); - cell0.setCellStyle(estilo); + DateFormat sfFormatada = new SimpleDateFormat("dd/MM/yyyy"); - HSSFCell cell1 = rowCabecalho.createCell(2); - cell1.setCellValue( - Labels.getLabel("busquedaTarifaController.lhOrigen.label")); - cell1.setCellStyle(estilo); + Date dataIni = (Date) obj[7]; + Date dataFim = (Date) obj[8]; - HSSFCell cell2 = rowCabecalho.createCell(3); - cell2.setCellValue( - Labels.getLabel("busquedaTarifaController.lhDestino.label")); - cell2.setCellStyle(estilo); + row.createCell(7).setCellValue(sfFormatada.format(dataIni) + " - " + sfFormatada.format(dataFim)); + row.createCell(8).setCellValue(obj[9].toString()); - HSSFCell cell3 = rowCabecalho.createCell(4); - cell3.setCellValue( - Labels.getLabel("busquedaTarifaController.lhRuta.label")); - cell3.setCellStyle(estilo); + String ori = obj[10].toString(); + BigDecimal original = BigDecimal.valueOf(Double.valueOf(ori)); - HSSFCell cell4 = rowCabecalho.createCell(5); - cell4.setCellValue( - Labels.getLabel("busquedaTarifaController.lhMarca.label")); - cell4.setCellStyle(estilo); + String atu = obj[11].toString(); + BigDecimal atual = BigDecimal.valueOf(Double.valueOf(atu)); - // Preco original I - 6 - HSSFCell cell5 = rowCabecalho.createCell(6); - cell5.setCellValue( - Labels.getLabel("busquedaTarifaController.lhClaseServicio.label")); - cell5.setCellStyle(estilo); + row.createCell(9).setCellValue(original.setScale(2).doubleValue()); + row.createCell(10).setCellValue(atual.setScale(2).doubleValue()); - // H - 6 - HSSFCell cell6 = rowCabecalho.createCell(7); - cell6.setCellValue( - Labels.getLabel("busquedaTarifaController.lhFeciniciovigencia.label")); - cell6.setCellStyle(estilo); + String ped = obj[16] != null ? obj[16].toString() : "0.0"; + BigDecimal pedVal = BigDecimal.valueOf(Double.valueOf(ped)); + row.createCell(12).setCellValue(pedVal.setScale(2).doubleValue()); - // I - 8 - HSSFCell cell7 = rowCabecalho.createCell(8); - cell7.setCellValue( - Labels.getLabel("busquedaTarifaController.lhMoneda.label")); - cell7.setCellStyle(estilo); + // novo preco: + BigDecimal novoPrecio = atual; - // J - 9 - HSSFCell cell8 = rowCabecalho.createCell(9); - cell8.setCellValue( - Labels.getLabel("busquedaTarifaController.lhPrecioOriginal.label")); - cell8.setCellStyle(estilo); + novoPrecio = novoPrecio.multiply(coeficiente).setScale(2, RoundingMode.HALF_UP); - // J - 9 - HSSFCell cell9 = rowCabecalho.createCell(10); - cell9.setCellValue( - Labels.getLabel("busquedaTarifaController.lhPrecioExcel.label")); - cell9.setCellStyle(estilo); - - // h - 10 - HSSFCell cell10 = rowCabecalho.createCell(11); - cell10.setCellValue( - Labels.getLabel("busquedaTarifaController.lhPrecioNuevo.label")); - cell10.setCellStyle(estilo); - - - HSSFCell cell12 = rowCabecalho.createCell(12); - cell12.setCellValue( - Labels.getLabel("busquedaTarifaController.lhPrecioPedagio.label")); - cell12.setCellStyle(estilo); + HSSFCell cellNovoPrecio = row.createCell(11); + cellNovoPrecio.setCellValue(novoPrecio.setScale(2).doubleValue()); + cellNovoPrecio.setCellStyle(estilo); } - HSSFRow row = sheet1.createRow(contRow++); + String nomeArquivo = + UsuarioLogado.getUsuarioLogado().getNombusuario() + + "_" + Calendar.getInstance().getTime().getTime() + + "_" + "modMassivaT"; - row.createCell(0).setCellValue(Integer.parseInt(obj[0].toString())); - row.createCell(1).setCellValue(obj[1].toString()); - row.createCell(2).setCellValue(obj[2].toString()); - row.createCell(3).setCellValue(obj[3].toString()); - row.createCell(4).setCellValue(obj[4].toString().concat(" (").concat(obj[12].toString()).concat(")")); - row.createCell(5).setCellValue(obj[5].toString()); - row.createCell(6).setCellValue(obj[6].toString()); + File fNomeArquivo = File.createTempFile(nomeArquivo, ".tmp"); - DateFormat sfFormatada = new SimpleDateFormat("dd/MM/yyyy"); + FileOutputStream stream = new FileOutputStream(fNomeArquivo); + stream.flush(); + wb.write(stream); + stream.close(); - Date dataIni = (Date) obj[7]; - Date dataFim = (Date) obj[8]; + InputStream is = null; + is = new FileInputStream(fNomeArquivo); + Filedownload.save(is, "application/xls", "modificacionMasivaTarifa.xls"); - row.createCell(7).setCellValue(sfFormatada.format(dataIni) + " - " + sfFormatada.format(dataFim)); - row.createCell(8).setCellValue(obj[9].toString()); + fNomeArquivo.delete(); - String ori = obj[10].toString(); - BigDecimal original = BigDecimal.valueOf(Double.valueOf(ori)); - - String atu = obj[11].toString(); - BigDecimal atual = BigDecimal.valueOf(Double.valueOf(atu)); - - row.createCell(9).setCellValue(original.setScale(2).doubleValue()); - row.createCell(10).setCellValue(atual.setScale(2).doubleValue()); - - String ped = obj[16] != null ? obj[16].toString() : "0.0"; - BigDecimal pedVal = BigDecimal.valueOf(Double.valueOf(ped)); - row.createCell(12).setCellValue(pedVal.setScale(2).doubleValue()); - - // novo preco: - BigDecimal novoPrecio = atual; - - novoPrecio = novoPrecio.multiply(coeficiente).setScale(2, RoundingMode.HALF_UP); - - HSSFCell cellNovoPrecio = row.createCell(11); - cellNovoPrecio.setCellValue(novoPrecio.setScale(2).doubleValue()); - cellNovoPrecio.setCellStyle(estilo); - } - - String nomeArquivo = - UsuarioLogado.getUsuarioLogado().getNombusuario() - + "_" + Calendar.getInstance().getTime().getTime() - + "_" + "modMassivaT"; - - File fNomeArquivo = File.createTempFile(nomeArquivo, ".tmp"); - - FileOutputStream stream = new FileOutputStream(fNomeArquivo); - stream.flush(); - wb.write(stream); - stream.close(); - - - InputStream is = null; - is = new FileInputStream(fNomeArquivo); - Filedownload.save(is, "application/xls", "modificacionMasivaTarifa.xls"); - - fNomeArquivo.delete(); - - }else{ + } else { Messagebox.show(Labels.getLabel("modificacionMasivaTarifasUploadController.MSG.excelVazio"), Labels.getLabel("modificacionMasivaTarifasController.window.title"), Messagebox.OK, Messagebox.INFORMATION); } - + } catch (Exception ex) { - log.error("",ex); + log.error("", ex); } }