rafael 2012-09-04 19:24:28 +00:00
parent 901f0cc92f
commit e8197b170b
4 changed files with 308 additions and 106 deletions

View File

@ -22,12 +22,9 @@ import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.collections.Predicate;
import org.apache.log4j.Logger;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.CellStyle;
import org.apache.poi.ss.usermodel.Font;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.xssf.streaming.SXSSFWorkbook;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
@ -59,12 +56,10 @@ import com.rjconsultores.ventaboletos.service.CategoriaService;
import com.rjconsultores.ventaboletos.service.ClaseServicioService;
import com.rjconsultores.ventaboletos.service.EmpresaService;
import com.rjconsultores.ventaboletos.service.MarcaService;
import com.rjconsultores.ventaboletos.service.MercadoCompetidoService;
import com.rjconsultores.ventaboletos.service.MonedaService;
import com.rjconsultores.ventaboletos.service.RutaCombinacionService;
import com.rjconsultores.ventaboletos.service.RutaService;
import com.rjconsultores.ventaboletos.service.TarifaCategoriaService;
import com.rjconsultores.ventaboletos.service.TarifaService;
import com.rjconsultores.ventaboletos.service.TarifaTipoptovtaService;
import com.rjconsultores.ventaboletos.service.TipoPuntoVentaService;
import com.rjconsultores.ventaboletos.service.VigenciaTarifaService;
import com.rjconsultores.ventaboletos.utilerias.ApplicationProperties;
@ -79,6 +74,15 @@ import com.rjconsultores.ventaboletos.web.utilerias.render.RenderMarca;
import com.rjconsultores.ventaboletos.web.utilerias.render.RenderMoneda;
import com.rjconsultores.ventaboletos.web.utilerias.render.RenderTipoPuntoVenta;
import com.rjconsultores.ventaboletos.web.utilerias.render.RenderVigenciaTarifaModificacionMassivaTarifa;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFCellStyle;
import org.apache.poi.hssf.usermodel.HSSFFont;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
/**
*
@ -89,17 +93,10 @@ import com.rjconsultores.ventaboletos.web.utilerias.render.RenderVigenciaTarifaM
public class ModificacionMasivaTarifasController extends MyGenericForwardComposer {
private final Integer CELL_ID_TARIFA = 0;
private final Integer CELL_NOVO_PRECIO = 8;
private final Integer CELL_ID_CATEGORIA = 10;
private final Integer CELL_NOVO_PRECIO_CATEGORIA = 12;
private final Integer CELL_ID_TIPO_PUNTO = 14;
private final Integer CELL_NOVO_PRECIO_TIPO_PUNTO = 16;
@Autowired
private TarifaService tarifaService;
@Autowired
private TarifaCategoriaService tarifaCategoriaService;
@Autowired
private TarifaTipoptovtaService tarifaTipoptovtaService;
private RutaCombinacionService rutaCombinacionService;
@Autowired
private MarcaService marcaService;
@Autowired
@ -107,8 +104,6 @@ public class ModificacionMasivaTarifasController extends MyGenericForwardCompose
@Autowired
private MonedaService monedaService;
@Autowired
private MercadoCompetidoService mercadoCompetidoService;
@Autowired
private EmpresaService empresaService;
@Autowired
private RutaService rutaService;
@ -156,6 +151,7 @@ public class ModificacionMasivaTarifasController extends MyGenericForwardCompose
private Button btnGerarTarifas;
private Tab tabTipoPuntoVenta;
private Tab tabCategoria;
private Radio rdLinear;
private static Logger log = Logger.getLogger(ModificacionMasivaTarifasController.class);
public List<ClaseServicio> getLsClaseServico() {
@ -344,21 +340,21 @@ public class ModificacionMasivaTarifasController extends MyGenericForwardCompose
// eliminando a opcao TODOS de tipo servicio:
CollectionUtils.filter(lsClaseServico, new Predicate() {
@Override
public boolean evaluate(Object obj) {
return !( ((ClaseServicio)obj).getClaseservicioId().equals(ClaseServicio.TODOS));
}
});
@Override
public boolean evaluate(Object obj) {
return !(((ClaseServicio) obj).getClaseservicioId().equals(ClaseServicio.TODOS));
}
});
// eliminando a opcao TODOS da marca:
CollectionUtils.filter(lsMarcas, new Predicate() {
@Override
public boolean evaluate(Object obj) {
return !( ((Marca)obj).getMarcaId().equals(Marca.TODOS));
}
@Override
public boolean evaluate(Object obj) {
return !(((Marca) obj).getMarcaId().equals(Marca.TODOS));
}
});
//Exibir botão para gerar tarifas automaticas
btnGerarTarifas.setVisible(ApplicationProperties.getInstance().generarTarifasAutomatica());
@ -369,6 +365,14 @@ public class ModificacionMasivaTarifasController extends MyGenericForwardCompose
}
public void onClick$btnGerarExcel(Event ev) {
if (rdLinear.isChecked()) {
onClick$btnGerarExcelLinear(null);
} else {
onClick$btnGerarExcelEscala(null);
}
}
public void onClick$btnGerarExcelLinear(Event ev) {
txtPorcentagem.getValue();
try {
@ -395,6 +399,7 @@ public class ModificacionMasivaTarifasController extends MyGenericForwardCompose
}
}
} catch (Exception e) {
log.error(e);
log.debug("Porcentagem Zero");
}
@ -402,113 +407,151 @@ public class ModificacionMasivaTarifasController extends MyGenericForwardCompose
return;
}
List<Tarifa> lsTarifa = tarifaService.pesquisar(lsAddRmvMonedas, lsAddRmvMarcas,
HSSFWorkbook wb = new HSSFWorkbook();
// fonte em negrito:
HSSFFont fonte = wb.createFont();
fonte.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
HSSFCellStyle estilo = wb.createCellStyle();
estilo.setFont(fonte);
//TESTE:
List<Object> lsRutaCombinacion = rutaCombinacionService.pesquisaTarifaObj(lsAddRmvMonedas, lsAddRmvMarcas,
lsAddRmvClaseServico, lsAddRmvCategoria, lsAddRmvEmpresas, lsAddRmvRutas,
lsAddRmvTipoPuntoVenta, lsAddRmvVigenciaTarifa);
Workbook wb = new SXSSFWorkbook(500);
HSSFSheet sheet1 = null;
String ruta = "";
int contRow = 0;
// fonte em negrito:
Font fonte = wb.createFont();
fonte.setBoldweight(Font.BOLDWEIGHT_BOLD);
CellStyle estilo = wb.createCellStyle();
estilo.setFont(fonte);
for (int i = 0; i < lsRutaCombinacion.size(); i++) {
Object[] obj = (Object[]) lsRutaCombinacion.get(i);
Sheet sheet1 = wb.createSheet(
Labels.getLabel("modificacionMasivaTarifasController.window.title"));
if (!ruta.equals(obj[4].toString().concat(obj[12].toString()))) {
Row rowCabecalho = sheet1.createRow(0);
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(")"));
}
log.debug("Aba: " + sheetName);
sheet1 = wb.createSheet(sheetName);
contRow = 1;
Cell cell = rowCabecalho.createCell(0);
cell.setCellValue(
Labels.getLabel("busquedaTarifaController.lhId.label"));
cell.setCellStyle(estilo);
HSSFRow rowCabecalho = sheet1.createRow(0);
Cell cell0 = rowCabecalho.createCell(1);
cell0.setCellValue(
Labels.getLabel("busquedaTarifaController.lhTramo.label"));
cell0.setCellStyle(estilo);
HSSFCell cell = rowCabecalho.createCell(0);
cell.setCellValue(
Labels.getLabel("busquedaTarifaController.lhId.label"));
cell.setCellStyle(estilo);
Cell cell1 = rowCabecalho.createCell(2);
cell1.setCellValue(
Labels.getLabel("busquedaTarifaController.lhMarca.label"));
cell1.setCellStyle(estilo);
HSSFCell cell0 = rowCabecalho.createCell(1);
cell0.setCellValue(
Labels.getLabel("busquedaTarifaController.lhTramo.label"));
cell0.setCellStyle(estilo);
Cell cell2 = rowCabecalho.createCell(3);
cell2.setCellValue(
Labels.getLabel("busquedaTarifaController.lhClaseServicio.label"));
cell2.setCellStyle(estilo);
HSSFCell cell1 = rowCabecalho.createCell(2);
cell1.setCellValue(
Labels.getLabel("busquedaTarifaController.lhOrigem.label"));
cell1.setCellStyle(estilo);
Cell cell3 = rowCabecalho.createCell(4);
cell3.setCellValue(
Labels.getLabel("busquedaTarifaController.lhFeciniciovigencia.label"));
cell3.setCellStyle(estilo);
HSSFCell cell2 = rowCabecalho.createCell(3);
cell2.setCellValue(
Labels.getLabel("busquedaTarifaController.lhDestino.label"));
cell2.setCellStyle(estilo);
Cell cell4 = rowCabecalho.createCell(5);
cell4.setCellValue(
Labels.getLabel("busquedaTarifaController.lhMoneda.label"));
cell4.setCellStyle(estilo);
HSSFCell cell3 = rowCabecalho.createCell(4);
cell3.setCellValue(
Labels.getLabel("busquedaTarifaController.lhRuta.label"));
cell3.setCellStyle(estilo);
//Preco original I - 6
Cell cell5 = rowCabecalho.createCell(6);
cell5.setCellValue(
Labels.getLabel("busquedaTarifaController.lhPrecioOriginal.label"));
cell5.setCellStyle(estilo);
HSSFCell cell4 = rowCabecalho.createCell(5);
cell4.setCellValue(
Labels.getLabel("busquedaTarifaController.lhMarca.label"));
cell4.setCellStyle(estilo);
// j - 6
Cell cell6 = rowCabecalho.createCell(7);
cell6.setCellValue(
Labels.getLabel("busquedaTarifaController.lhPrecioExcel.label"));
cell6.setCellStyle(estilo);
//Preco original I - 6
HSSFCell cell5 = rowCabecalho.createCell(6);
cell5.setCellValue(
Labels.getLabel("busquedaTarifaController.lhClaseServicio.label"));
cell5.setCellStyle(estilo);
//I - 8
Cell cell7 = rowCabecalho.createCell(8);
cell7.setCellValue(
Labels.getLabel("busquedaTarifaController.lhPrecioNuevo.label"));
cell7.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);
for (int i = 0; i < lsTarifa.size(); i++) {
//J - 9
HSSFCell cell8 = rowCabecalho.createCell(9);
cell8.setCellValue(
Labels.getLabel("busquedaTarifaController.lhPrecioOriginal.label"));
cell8.setCellStyle(estilo);
Tarifa tarifa = lsTarifa.get(i);
//J - 9
HSSFCell cell9 = rowCabecalho.createCell(10);
cell9.setCellValue(
Labels.getLabel("busquedaTarifaController.lhPrecioExcel.label"));
cell9.setCellStyle(estilo);
Row row = sheet1.createRow(i + 1);
//h - 10
HSSFCell cell10 = rowCabecalho.createCell(11);
cell10.setCellValue(
Labels.getLabel("busquedaTarifaController.lhPrecioNuevo.label"));
cell10.setCellStyle(estilo);
}
row.createCell(0).setCellValue(tarifa.getTarifaId());
row.createCell(1).setCellValue(tarifa.getTramo().getDesctramo());
row.createCell(2).setCellValue(tarifa.getMarca().getDescmarca());
row.createCell(3).setCellValue(tarifa.getClaseServicio().getDescclase());
row.createCell(4).setCellValue(tarifa.getVigenciaTarifa().toString());
row.createCell(5).setCellValue(tarifa.getMoneda().getDescmoneda());
row.createCell(6).setCellValue(tarifa.getPreciooriginal().setScale(2).doubleValue());
row.createCell(7).setCellValue(tarifa.getPrecio().setScale(2).doubleValue());
HSSFRow row = sheet1.createRow(contRow++);
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());
DateFormat sfData = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
DateFormat sfFormatada = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss");
Date dataIni = sfData.parse(obj[7].toString());
Date dataFim = sfData.parse(obj[8].toString());
row.createCell(7).setCellValue(sfFormatada.format(dataIni) + " - " + sfFormatada.format(dataFim));
row.createCell(8).setCellValue(obj[9].toString());
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());
// novo preco:
BigDecimal novoPrecio = tarifa.getPrecio();
BigDecimal novoPrecio = atual;
novoPrecio = novoPrecio.multiply(coeficiente).setScale(2, RoundingMode.HALF_UP);
Cell cellNovoPrecio = row.createCell(8);
HSSFCell cellNovoPrecio = row.createCell(11);
cellNovoPrecio.setCellValue(novoPrecio.setScale(2).doubleValue());
cellNovoPrecio.setCellStyle(estilo);
//Tipo de Pasajero
row.createCell(9).setCellValue("");
row.createCell(10).setCellValue("");
row.createCell(11).setCellValue("");
row.createCell(12).setCellValue("");
// novo preco CANAL VENTA:
row.createCell(13).setCellValue("");
row.createCell(14).setCellValue("");
row.createCell(15).setCellValue("");
row.createCell(16).setCellValue("");
}
// }
String nomeArquivo =
UsuarioLogado.getUsuarioLogado().getNombusuario()
+ "_" + Calendar.getInstance().getTime().getTime()
+ "_" + "modMassivaT.xlsx";
+ "_" + "modMassivaT.xls";
FileOutputStream stream = new FileOutputStream(nomeArquivo);
stream.flush();
@ -517,11 +560,73 @@ public class ModificacionMasivaTarifasController extends MyGenericForwardCompose
InputStream is = null;
is = new FileInputStream(nomeArquivo);
Filedownload.save(is, "application/xlsx", "modificacionMasivaTarifa.xlsx");
Filedownload.save(is, "application/xls", "modificacionMasivaTarifa.xls");
boolean success = (new File(nomeArquivo)).delete();
} catch (Exception ex) {
log.error("Erro ao executar a exportação masiva",ex);
log.error(ex);
}
}
//Escala
public void onClick$btnGerarExcelEscala(Event ev) {
txtPorcentagem.getValue();
try {
if (lsAddRmvVigenciaTarifa.isEmpty()) {
Messagebox.show(
Labels.getLabel("modificacionMasivaTarifasController.MSG.SemVigencia"),
Labels.getLabel("modificacionMasivaTarifasController.window.title"),
Messagebox.OK, Messagebox.EXCLAMATION);
return;
}
BigDecimal coeficiente = new BigDecimal(BigInteger.ZERO);
try {
if (txtPorcentagem.getValue() != null) {
BigDecimal porcentage = BigDecimal.valueOf(Double.parseDouble(txtPorcentagem.getValue()));
coeficiente = porcentage.divide(new BigDecimal(100));
if (radIncremento.isChecked()) {
coeficiente = coeficiente.add(BigDecimal.ONE);
} else {
coeficiente = BigDecimal.ONE.subtract(coeficiente);
}
}
} catch (Exception e) {
log.error(e);
log.debug("Porcentagem Zero");
}
if (coeficiente == null) {
return;
}
HSSFWorkbook wb = rutaCombinacionService.gerarTarifaEscala(lsAddRmvMonedas, lsAddRmvMarcas,
lsAddRmvClaseServico, lsAddRmvCategoria, lsAddRmvEmpresas, lsAddRmvRutas,
lsAddRmvTipoPuntoVenta, lsAddRmvVigenciaTarifa);
String nomeArquivo =
UsuarioLogado.getUsuarioLogado().getNombusuario()
+ "_" + Calendar.getInstance().getTime().getTime()
+ "_" + "modMassivaEscala.xls";
FileOutputStream stream = new FileOutputStream(nomeArquivo);
stream.flush();
wb.write(stream);
stream.close();
InputStream is = null;
is = new FileInputStream(nomeArquivo);
Filedownload.save(is, "application/xls", "modificacionMasivaTarifa.xls");
boolean success = (new File(nomeArquivo)).delete();
} catch (Exception ex) {
log.error(ex);
}
}

View File

@ -0,0 +1,37 @@
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package com.rjconsultores.ventaboletos.web.utilerias.render;
import com.rjconsultores.ventaboletos.entidad.SeguroTarifa;
import org.zkoss.zul.Listcell;
import org.zkoss.zul.Listitem;
import org.zkoss.zul.ListitemRenderer;
/**
*
* @author Desenvolvimento
*/
public class RenderSeguroTarifa implements ListitemRenderer {
public void render(Listitem lstm, Object o) throws Exception {
SeguroTarifa taxaTarifa = (SeguroTarifa) o;
Listcell lc = new Listcell(taxaTarifa.getSegurotarifaId()==null?"-":taxaTarifa.getSegurotarifaId().toString());
lc.setParent(lstm);
lc = new Listcell(taxaTarifa.getOrgaoconcedente().getDescOrgao());
lc.setParent(lstm);
lc = new Listcell(taxaTarifa.getValortarifaate().toString());
lc.setParent(lstm);
lc = new Listcell(taxaTarifa.getValortarifa().toString());
lc.setParent(lstm);
lstm.setAttribute("data", taxaTarifa);
}
}

View File

@ -0,0 +1,53 @@
<?xml version="1.0" encoding="UTF-8"?>
<?page contentType="text/html;charset=UTF-8"?>
<?variable-resolver class="org.zkoss.zkplus.spring.DelegatingVariableResolver"?>
<?init class="org.zkoss.zkplus.databind.AnnotateDataBinderInit" arg0="winBusquedaSeguroTarifa"?>
<?taglib uri="http://www.zkoss.org/dsp/web/core" prefix="c"?>
<zk xmlns="http://www.zkoss.org/2005/zul">
<window id="winBusquedaSeguroTarifa" title="${c:l('busquedaSeguroTarifaController.window.title')}"
apply="${busquedaSeguroTarifaController}" contentStyle="overflow:auto"
height="500px" width="750px" border="normal" >
<toolbar>
<button id="btnRefresh" image="/gui/img/refresh.png" width="35px"
tooltiptext="${c:l('busquedaSeguroTarifaController.btnRefresh.tooltiptext')}" />
<separator orient="vertical" />
<button id="btnNovo" image="/gui/img/add.png" width="35px"
tooltiptext="${c:l('busquedaSeguroTarifaController.btnNovo.tooltiptext')}" />
<separator orient="vertical" />
<button id="btnCerrar" onClick="winBusquedaSeguroTarifa.detach()" image="/gui/img/exit.png" width="35px"
tooltiptext="${c:l('busquedaSeguroTarifaController.btnCerrar.tooltiptext')}"/>
</toolbar>
<grid fixedLayout="true">
<columns>
<column width="30%" />
<column width="70%" />
</columns>
<rows>
<row>
<label value="${c:l('busquedaSeguroTarifaController.orgao')}"/>
<textbox id="txtOrgao" width="200px" use="com.rjconsultores.ventaboletos.web.utilerias.MyTextbox"/>
</row>
</rows>
</grid>
<toolbar>
<button id="btnPesquisa" image="/gui/img/find.png"
label="${c:l('tooltiptext.btnPesquisa')}"/>
</toolbar>
<paging id="pagingSeguroTarifa" pageSize="15"/>
<listbox id="seguroTarifaList" use="com.rjconsultores.ventaboletos.web.utilerias.MyListbox"
multiple="false">
<listhead sizable="true">
<listheader width="50px" image="/gui/img/builder.gif"
label="${c:l('lb.id')}"
sort="auto(taxaembarqueTarifaId)"/>
<listheader image="/gui/img/builder.gif"
label="${c:l('busquedaSeguroTarifaController.orgao')}"
sort="auto(descOrgao)"/>
</listhead>
</listbox>
</window>
</zk>

View File

@ -45,6 +45,13 @@
<textbox id="txtPorcentagem" maxValue="100.00" constraint="no empty" value="0.00"
use="com.rjconsultores.ventaboletos.web.utilerias.MyTextboxDecimal"/>
</row>
<row>
<label value="${c:l('modificacionMasivaTarifasController.formato')}"/>
<radiogroup id="rdFormato" >
<radio id="rdLinear" label="${c:l('modificacionMasivaTarifasController.linear')}" checked="true"/>
<radio id="rdEscala" label="${c:l('modificacionMasivaTarifasController.escala')}"/>
</radiogroup>
</row>
</rows>
</grid>
@ -92,7 +99,7 @@
sort="auto(descclase)"/>
</listhead>
</listbox>
</tabpanel>
</tabpanel>
<tabpanel height="300px">
<grid fixedLayout="true">