diff --git a/src/java/com/rjconsultores/ventaboletos/web/gui/controladores/tarifas/ModificacionMasivaEmbarcadaController.java b/src/java/com/rjconsultores/ventaboletos/web/gui/controladores/tarifas/ModificacionMasivaEmbarcadaController.java new file mode 100644 index 000000000..373742948 --- /dev/null +++ b/src/java/com/rjconsultores/ventaboletos/web/gui/controladores/tarifas/ModificacionMasivaEmbarcadaController.java @@ -0,0 +1,993 @@ +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ +package com.rjconsultores.ventaboletos.web.gui.controladores.tarifas; + +import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.math.BigDecimal; +import java.math.BigInteger; +import java.math.RoundingMode; +import java.text.DateFormat; +import java.text.SimpleDateFormat; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Calendar; +import java.util.Date; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.apache.commons.collections.CollectionUtils; +import org.apache.commons.collections.Predicate; +import org.apache.log4j.Logger; +import org.apache.poi.hssf.usermodel.HSSFFont; +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.SXSSFCell; +import org.apache.poi.xssf.streaming.SXSSFRow; +import org.apache.poi.xssf.streaming.SXSSFSheet; +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; +import org.springframework.stereotype.Controller; +import org.zkoss.util.media.Media; +import org.zkoss.util.resource.Labels; +import org.zkoss.zhtml.Filedownload; +import org.zkoss.zhtml.Fileupload; +import org.zkoss.zhtml.Messagebox; +import org.zkoss.zk.ui.Component; +import org.zkoss.zk.ui.event.Event; +import org.zkoss.zul.Button; +import org.zkoss.zul.Combobox; +import org.zkoss.zul.Comboitem; +import org.zkoss.zul.Radio; +import org.zkoss.zul.Tab; +import org.zkoss.zul.Textbox; + +import com.rjconsultores.ventaboletos.entidad.Categoria; +import com.rjconsultores.ventaboletos.entidad.ClaseServicio; +import com.rjconsultores.ventaboletos.entidad.Empresa; +import com.rjconsultores.ventaboletos.entidad.Marca; +import com.rjconsultores.ventaboletos.entidad.Moneda; +import com.rjconsultores.ventaboletos.entidad.OrgaoConcedente; +import com.rjconsultores.ventaboletos.entidad.Ruta; +import com.rjconsultores.ventaboletos.entidad.TarifaEmbarcada; +import com.rjconsultores.ventaboletos.entidad.TipoPuntoVenta; +import com.rjconsultores.ventaboletos.entidad.VigenciaTarifa; +import com.rjconsultores.ventaboletos.service.CategoriaService; +import com.rjconsultores.ventaboletos.service.ClaseServicioService; +import com.rjconsultores.ventaboletos.service.MarcaService; +import com.rjconsultores.ventaboletos.service.MonedaService; +import com.rjconsultores.ventaboletos.service.OrgaoConcedenteService; +import com.rjconsultores.ventaboletos.service.RutaCombinacionService; +import com.rjconsultores.ventaboletos.service.RutaService; +import com.rjconsultores.ventaboletos.service.TarifaEmbarcadaService; +import com.rjconsultores.ventaboletos.service.TipoPuntoVentaService; +import com.rjconsultores.ventaboletos.service.VigenciaTarifaService; +import com.rjconsultores.ventaboletos.utilerias.UsuarioLogado; +import com.rjconsultores.ventaboletos.web.utilerias.MyGenericForwardComposer; +import com.rjconsultores.ventaboletos.web.utilerias.MyListbox; +import com.rjconsultores.ventaboletos.web.utilerias.render.RenderCatalogoDeRutas; +import com.rjconsultores.ventaboletos.web.utilerias.render.RenderClaseServicio; +import com.rjconsultores.ventaboletos.web.utilerias.render.RenderEmpresaModificacionMassivaEmbarcada; +import com.rjconsultores.ventaboletos.web.utilerias.render.RenderMarca; +import com.rjconsultores.ventaboletos.web.utilerias.render.RenderMoneda; +import com.rjconsultores.ventaboletos.web.utilerias.render.RenderOrgaoConcedenteModifMassEmb; +import com.rjconsultores.ventaboletos.web.utilerias.render.RenderPersonalizado; +import com.rjconsultores.ventaboletos.web.utilerias.render.RenderTipoPuntoVenta; +import com.rjconsultores.ventaboletos.web.utilerias.render.RenderVigenciaTarifaModificacionMassivaEmbarcada; + + +@Controller("modificacionMasivaEmbarcadaController") +@Scope("prototype") +public class ModificacionMasivaEmbarcadaController extends MyGenericForwardComposer { + + private static final long serialVersionUID = 1L; + private final Integer CELL_ID_TARIFA = 0; + @Autowired + private TarifaEmbarcadaService tarifaEmbarcadaService; + @Autowired + private RutaCombinacionService rutaCombinacionService; + @Autowired + private MarcaService marcaService; + @Autowired + private ClaseServicioService claseServicioService; + @Autowired + private MonedaService monedaService; + @Autowired + private RutaService rutaService; + @Autowired + private TipoPuntoVentaService tipoPuntoVentaService; + @Autowired + private CategoriaService categoriaService; + @Autowired + private VigenciaTarifaService vigenciaTarifaService; + @Autowired + private OrgaoConcedenteService orgaoConcedenteService; + private List lsMarcas; + private List lsClaseServico; + private List lsMonedas; + private List lsEmpresas; + private List lsRutas; + private List lsOrgaoConcedente; + private List lsTipoPuntoVenta; + private List lsCategoria; + private List lsVigenciaTarifa; + private List lsAddRmvMarcas; + private List lsAddRmvClaseServico; + private List lsAddRmvMonedas; + private List lsAddRmvEmpresas; + private List lsAddRmvRutas; + private List lsAddRmvOrgaoConcedente; + private List lsAddRmvTipoPuntoVenta; + private List lsAddRmvCategoria; + private List lsAddRmvVigenciaTarifa; + private List lsComponentePreco; + + private Combobox cmbMarca; + private Combobox cmbMoneda; + private Combobox cmbClaseServicio; + private Combobox cmbEmpresa; + private Combobox cmbRuta; + private Combobox cmbOrgaoConcedente; + private Combobox cmbTipoPuntoVenta; + private Combobox cmbCategoria; + private Combobox cmbVigenciaTarifaEmb; + private Combobox cmbComponentePreco; + private MyListbox claseServicioList; + private MyListbox marcaList; + private MyListbox monedaList; + private MyListbox empresaList; + private MyListbox rutaList; + private MyListbox orgaoConcedenteList; + private MyListbox tipoPuntoVentaList; + private MyListbox categoriaList; + private MyListbox vigenciaTarifaEmbList; + private Textbox txtPorcentagem; + private Radio radIncremento; + private Radio radAgrupamentoLinhasSim; + private Button btnGerarTarifasEmb; + private Tab tabTipoPuntoVenta; + private Tab tabCategoria; + + private final int ROW_CABECALHO = 0; + + //INDICES PLANILHA + private final int IDX_CELL_ID = 0; + private final int IDX_CELL_MARCA = 1; + private final int IDX_CELL_NUMLINHA = 2; + private final int IDX_CELL_DESCLINHA = 3; + private final int IDX_CELL_TIPOCLASSE = 4; + private final int IDX_CELL_TRECHO = 5; + private final int IDX_CELL_ORIGEM = 6; + private final int IDX_CELL_DESTINO = 7; + private final int IDX_CELL_TARIFAORIGINAL = 8; + private final int IDX_CELL_TARIFAATUAL = 9; + private final int IDX_CELL_TARIFA_SIMULADA = 10; + private final int IDX_CELL_PEDAGIOATUAL = 11; + private final int IDX_CELL_PEDAGIOSIMULADO = 12; + private final int IDX_CELL_TXEMBARQUEATUAL = 13; + private final int IDX_CELL_TXEMBARQUESIMULADO = 14; + private final int IDX_CELL_SEGUROATUAL = 15; + private final int IDX_CELL_SEGUROSIMULADO = 16; + private final int IDX_CELL_TPPATUAL = 17; + private final int IDX_CELL_TPPSIMULADO = 18; + private final int IDX_CELL_ORGAOCONCEDENTE = 19; + private final int IDX_CELL_PREFIXO = 20; + private final int IDX_CELL_VIGENCIA = 21; + private final int IDX_CELL_MOEDA = 22; + private final int IDX_CELL_SENTIDO = 23; + private final int IDX_CELL_VENDE = 24; + private final int IDX_CELL_CHAVEPORDEMANDA = 25; + + private static Logger log = Logger.getLogger(ModificacionMasivaEmbarcadaController.class); + + public List getLsClaseServico() { + return lsClaseServico; + } + + public void setLsClaseServico(List lsClaseServico) { + this.lsClaseServico = lsClaseServico; + } + + public List getLsMarcas() { + return lsMarcas; + } + + public void setLsMarcas(List lsMarcas) { + this.lsMarcas = lsMarcas; + } + + public List getLsMonedas() { + return lsMonedas; + } + + public void setLsMonedas(List lsMonedas) { + this.lsMonedas = lsMonedas; + } + + public List getLsEmpresas() { + return lsEmpresas; + } + + public void setLsEmpresas(List lsEmpresas) { + this.lsEmpresas = lsEmpresas; + } + + public List getLsRutas() { + return lsRutas; + } + + public void setLsRutas(List lsRutas) { + this.lsRutas = lsRutas; + } + + public List getLsCategoria() { + return lsCategoria; + } + + public void setLsCategoria(List lsCategoria) { + this.lsCategoria = lsCategoria; + } + + public List getLsTipoPuntoVenta() { + return lsTipoPuntoVenta; + } + + public void setLsTipoPuntoVenta(List lsTipoPuntoVenta) { + this.lsTipoPuntoVenta = lsTipoPuntoVenta; + } + + public List getLsVigenciaTarifa() { + return lsVigenciaTarifa; + } + + public void setLsVigenciaTarifa(List lsVigenciaTarifa) { + this.lsVigenciaTarifa = lsVigenciaTarifa; + } + + public List getLsComponentePreco() { + return lsComponentePreco; + } + + public void setLstComponentePreco(List lsComponentePreco) { + this.lsComponentePreco = lsComponentePreco; + } + + @Override + public void doAfterCompose(Component comp) throws Exception { + + super.doAfterCompose(comp); + + + lsOrgaoConcedente = orgaoConcedenteService.obtenerTodos(); + lsMarcas = marcaService.buscarMarcaPorEmpresa(UsuarioLogado.getUsuarioLogado().getEmpresa()); + lsClaseServico = claseServicioService.obtenerTodos(); + lsMonedas = monedaService.obtenerTodos(); + lsEmpresas = UsuarioLogado.getUsuarioLogado().getEmpresa(); + lsRutas = rutaService.buscarRutasPorEmpresas(lsEmpresas); + lsTipoPuntoVenta = tipoPuntoVentaService.obtenerTodos(); + lsCategoria = categoriaService.obtenerTodos(); + lsVigenciaTarifa = vigenciaTarifaService.obtenerTodos(); + + setLstComponentePreco(EnumTarifaPedagio.obterBundleValues()); + + claseServicioList.setItemRenderer(new RenderClaseServicio()); + marcaList.setItemRenderer(new RenderMarca()); + monedaList.setItemRenderer(new RenderMoneda()); + empresaList.setItemRenderer(new RenderEmpresaModificacionMassivaEmbarcada()); + rutaList.setItemRenderer(new RenderCatalogoDeRutas()); + orgaoConcedenteList.setItemRenderer(new RenderOrgaoConcedenteModifMassEmb()); + tipoPuntoVentaList.setItemRenderer(new RenderTipoPuntoVenta()); + categoriaList.setItemRenderer(new RenderPersonalizado(Arrays.asList("categoriaId", "desccategoria"))); + vigenciaTarifaEmbList.setItemRenderer(new RenderVigenciaTarifaModificacionMassivaEmbarcada()); + + + lsAddRmvMarcas = new ArrayList(); + lsAddRmvClaseServico = new ArrayList(); + lsAddRmvMonedas = new ArrayList(); + lsAddRmvEmpresas = new ArrayList(); + lsAddRmvRutas = new ArrayList(); + lsAddRmvOrgaoConcedente = new ArrayList(); + lsAddRmvTipoPuntoVenta = new ArrayList(); + lsAddRmvCategoria = new ArrayList(); + lsAddRmvVigenciaTarifa = new ArrayList(); + + // 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)); + } + }); + + // eliminando a opcao TODOS da marca: + CollectionUtils.filter(lsMarcas, new Predicate() { + + @Override + public boolean evaluate(Object obj) { + return !(((Marca) obj).getMarcaId().equals(Marca.TODOS)); + } + }); + + // Exibir botão para gerar tarifas automaticas + //btnGerarTarifas.setVisible(ApplicationProperties.getInstance().isCustomHabilitado(CustomEnum.GENERAR_TARIFAS_AUTOMATICA.getDescricao())); + btnGerarTarifasEmb.setVisible(false); + + // Abas desativadas no SCIA + tabCategoria.setVisible(Boolean.FALSE); + tabTipoPuntoVenta.setVisible(Boolean.FALSE); + } + + public void onClick$btnGerarExcel(Event ev) { + onClick$btnGerarExcelLinear(null); + } + + public void onClick$btnGerarExcelLinear(Event ev) { + + try { + if (lsAddRmvVigenciaTarifa.isEmpty()) { + Messagebox.show( + Labels.getLabel("modificacionMasivaEmbarcadaController.MSG.SemVigencia"), + Labels.getLabel("modificacionMasivaEmbarcadaController.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().replace(",", "."))); + + 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; + } + + //Estilo padrão para os dois tipos de relatórios + SXSSFWorkbook wb = new SXSSFWorkbook (); + + // fonte em negrito: + Font fonte = wb.createFont(); + fonte.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD); + CellStyle estilo = wb.createCellStyle(); + estilo.setFont(fonte); + + List lsRutaCombinacion = rutaCombinacionService.pesquisaTarifaEmbObj(lsAddRmvMonedas, lsAddRmvMarcas, + lsAddRmvClaseServico, lsAddRmvCategoria, lsAddRmvEmpresas, lsAddRmvRutas, + lsAddRmvTipoPuntoVenta, lsAddRmvVigenciaTarifa, lsAddRmvOrgaoConcedente); + + if (!lsRutaCombinacion.isEmpty()) { + if (radAgrupamentoLinhasSim.isChecked()){ + gerarExcelComAgrupamento(lsRutaCombinacion, wb, estilo, coeficiente); + } else { + gerarExcelSemAgrupamento(lsRutaCombinacion, wb, estilo, coeficiente); + } + + 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", "modificacionMasivaTarifaEmbarcada.xls"); + + fNomeArquivo.delete(); + + } else { + Messagebox.show(Labels.getLabel("modificacionMasivaEmbarcadaUploadController.MSG.excelVazio"), + Labels.getLabel("modificacionMasivaEmbarcadaController.window.title"), Messagebox.OK, Messagebox.INFORMATION); + } + + } catch (Exception ex) { + log.error("", ex); + } + } + + private String getStringImporteSafe(Object o) { + return ((o == null)?"0.0":o.toString()); + } + + // Escala + public VigenciaTarifa vigenciaTarifa(Media mExcel) throws IOException { + InputStream isMExcel = mExcel.getStreamData(); + Workbook wb = new XSSFWorkbook(isMExcel); + + VigenciaTarifa v = new VigenciaTarifa(); + + for (int k = 0; k < wb.getNumberOfSheets(); k++) { + Sheet sheet = wb.getSheetAt(k); + int rows = sheet.getPhysicalNumberOfRows(); + + // pula o row 0 pq eh o cabecalho: + for (int r = 1; r < rows; r++) { + Row row = sheet.getRow(r); + if (row == null) { + continue; + } + + Cell cellIdTarifa = row.getCell(CELL_ID_TARIFA); + BigDecimal bdId = new BigDecimal(cellIdTarifa.getNumericCellValue()); + Integer idTarifa = bdId.intValue(); + + TarifaEmbarcada tarifaEmbarcada = tarifaEmbarcadaService.obtenerID(idTarifa); + + v = tarifaEmbarcada.getVigenciaTarifa(); + + break; + } + } + + return v; + } + + @SuppressWarnings({ "rawtypes", "unchecked" }) + public void onClick$btnUpLoadExcel(Event ev) throws InterruptedException, IOException { + Media mExcel = Fileupload.get(); + + if (mExcel != null) { + Map args = new HashMap(); + args.put("mExcel", mExcel); + + openWindow("/gui/tarifas/modificacionMasivaEmbarcadaUpload.zul", + Labels.getLabel("modificacionMasivaEmbarcadaController.window.title"), args, MODAL); + } + } + + public void onClick$btnAdicionarClaseServicio(Event ev) { + Comboitem cbiClaseServicio = cmbClaseServicio.getSelectedItem(); + if (cbiClaseServicio != null) { + ClaseServicio claseServicio = (ClaseServicio) cbiClaseServicio.getValue(); + + lsAddRmvClaseServico.add(claseServicio); + claseServicioList.setData(lsAddRmvClaseServico); + + cmbClaseServicio.setSelectedItem(null); + } + } + + public void onClick$btnRemoverClaseServicio(Event ev) { + ClaseServicio claseServicio = (ClaseServicio) claseServicioList.getSelected(); + if (claseServicio != null) { + lsAddRmvClaseServico.remove(claseServicio); + claseServicioList.setData(lsAddRmvClaseServico); + } + } + + public void onClick$btnAdicionarMarca(Event ev) { + Comboitem cbimarca = cmbMarca.getSelectedItem(); + if (cbimarca != null) { + Marca marca = (Marca) cbimarca.getValue(); + + lsAddRmvMarcas.add(marca); + marcaList.setData(lsAddRmvMarcas); + + cmbMarca.setSelectedItem(null); + } + } + + public void onClick$btnRemoverMarca(Event ev) { + Marca marca = (Marca) marcaList.getSelected(); + if (marca != null) { + lsAddRmvMarcas.remove(marca); + marcaList.setData(lsAddRmvMarcas); + } + } + + public void onClick$btnAdicionarMoneda(Event ev) { + Comboitem cbiMoneda = cmbMoneda.getSelectedItem(); + if (cbiMoneda != null) { + Moneda moneda = (Moneda) cbiMoneda.getValue(); + + lsAddRmvMonedas.add(moneda); + monedaList.setData(lsAddRmvMonedas); + + cmbMoneda.setSelectedItem(null); + } + } + + public void onClick$btnRemoverMoneda(Event ev) { + Moneda moneda = (Moneda) monedaList.getSelected(); + if (moneda != null) { + lsAddRmvMonedas.remove(moneda); + monedaList.setData(lsAddRmvMonedas); + } + } + + public void onClick$btnAdicionarEmpresa(Event ev) { + Comboitem cbiEmpresa = cmbEmpresa.getSelectedItem(); + if (cbiEmpresa != null) { + Empresa empresa = (Empresa) cbiEmpresa.getValue(); + + lsAddRmvEmpresas.add(empresa); + empresaList.setData(lsAddRmvEmpresas); + + cmbEmpresa.setSelectedItem(null); + } + } + + public void onClick$btnRemoverEmpresa(Event ev) { + Empresa empresa = (Empresa) empresaList.getSelected(); + if (empresa != null) { + lsAddRmvEmpresas.remove(empresa); + empresaList.setData(lsAddRmvEmpresas); + } + } + + public void onClick$btnAdicionarRuta(Event ev) { + Comboitem cbiRuta = cmbRuta.getSelectedItem(); + if (cbiRuta != null) { + Ruta ruta = (Ruta) cbiRuta.getValue(); + + lsAddRmvRutas.add(ruta); + rutaList.setData(lsAddRmvRutas); + + cmbRuta.setSelectedItem(null); + } + } + + public void onClick$btnRemoverRuta(Event ev) { + Ruta ruta = (Ruta) rutaList.getSelected(); + if (ruta != null) { + lsAddRmvRutas.remove(ruta); + rutaList.setData(lsAddRmvRutas); + } + } + + public void onClick$btnAdicionarOrgao(Event ev) { + Comboitem cbiOrgao = cmbOrgaoConcedente.getSelectedItem(); + if (cbiOrgao != null) { + OrgaoConcedente orgao = (OrgaoConcedente) cbiOrgao.getValue(); + + lsAddRmvOrgaoConcedente.add(orgao); + orgaoConcedenteList.setData(lsAddRmvOrgaoConcedente); + + cmbOrgaoConcedente.setSelectedItem(null); + } + } + + public void onClick$btnRemoverOrgao(Event ev) { + OrgaoConcedente orgao = (OrgaoConcedente) orgaoConcedenteList.getSelected(); + if (orgao != null) { + lsAddRmvOrgaoConcedente.remove(orgao); + orgaoConcedenteList.setData(lsAddRmvOrgaoConcedente); + } + } + + public void onClick$btnAdicionarTipoPuntoVenta(Event ev) { + Comboitem cbiTipoPuntoVenta = cmbTipoPuntoVenta.getSelectedItem(); + if (cbiTipoPuntoVenta != null) { + TipoPuntoVenta tipoPuntoVenta = (TipoPuntoVenta) cbiTipoPuntoVenta.getValue(); + + lsAddRmvTipoPuntoVenta.add(tipoPuntoVenta); + tipoPuntoVentaList.setData(lsAddRmvTipoPuntoVenta); + + cmbTipoPuntoVenta.setSelectedItem(null); + } + } + + public void onClick$btnRemoverTipoPuntoVenta(Event ev) { + TipoPuntoVenta tipoPuntoVenta = (TipoPuntoVenta) tipoPuntoVentaList.getSelected(); + if (tipoPuntoVenta != null) { + lsAddRmvTipoPuntoVenta.remove(tipoPuntoVenta); + tipoPuntoVentaList.setData(lsAddRmvTipoPuntoVenta); + } + } + + public void onClick$btnAdicionarCategoria(Event ev) { + Comboitem cbiCategoria = cmbCategoria.getSelectedItem(); + if (cbiCategoria != null) { + Categoria categoria = (Categoria) cbiCategoria.getValue(); + + lsAddRmvCategoria.add(categoria); + categoriaList.setData(lsAddRmvCategoria); + + cmbCategoria.setSelectedItem(null); + } + } + + public void onClick$btnRemoverCategoria(Event ev) { + Categoria categoria = (Categoria) categoriaList.getSelected(); + if (categoria != null) { + lsAddRmvCategoria.remove(categoria); + categoriaList.setData(lsAddRmvCategoria); + } + } + + public void onClick$btnAdicionarVigenciaTarifaEmb(Event ev) throws InterruptedException { + Comboitem cbiVigenciaTarifa = cmbVigenciaTarifaEmb.getSelectedItem(); + + if (lsAddRmvVigenciaTarifa.size() > 0 ){ + Messagebox.show(Labels.getLabel("modificacionMasivaEmbarcadaUploadController.MSG.nomaximoumavigencia"), + Labels.getLabel("modificacionMasivaEmbarcadaController.window.title"), Messagebox.OK, Messagebox.INFORMATION); + + return; + } + + if (cbiVigenciaTarifa != null) { + VigenciaTarifa vigenciaTarifa = (VigenciaTarifa) cbiVigenciaTarifa.getValue(); + + lsAddRmvVigenciaTarifa.add(vigenciaTarifa); + vigenciaTarifaEmbList.setData(lsAddRmvVigenciaTarifa); + + cmbVigenciaTarifaEmb.setSelectedItem(null); + } + } + + public void onClick$btnRemoverVigenciaTarifaEmb(Event ev) { + VigenciaTarifa vigenciaTarifa = (VigenciaTarifa) vigenciaTarifaEmbList.getSelected(); + if (vigenciaTarifa != null) { + lsAddRmvVigenciaTarifa.remove(vigenciaTarifa); + vigenciaTarifaEmbList.setData(lsAddRmvVigenciaTarifa); + } + } + + public List getLsOrgaoConcedente() { + return lsOrgaoConcedente; + } + + public void setLsOrgaoConcedente(List lsOrgaoConcedente) { + this.lsOrgaoConcedente = lsOrgaoConcedente; + } + + private void gerarExcelSemAgrupamento(List lsRutaCombinacion, SXSSFWorkbook wb, CellStyle estilo, BigDecimal coeficiente){ + SXSSFSheet sheet1 = null; + String ruta = ""; + int contRow = 0; + + for (int i = 0; i < lsRutaCombinacion.size(); i++) { + Object[] obj = (Object[]) lsRutaCombinacion.get(i); + + String sheetName = ""; + + try{ + if (!ruta.equals(obj[4].toString().concat(obj[12].toString()))) { + + ruta = obj[4].toString().concat(obj[12].toString()); + String sentido = (obj[22].toString().equals("1"))?"IDA":"VOLTA"; + + if (obj[4].toString().length() > 26) { + sheetName = (obj[12].toString().concat("-").concat(obj[4].toString().substring(0, obj[4].toString().length()).concat(" - ").concat(sentido))); + } else { + sheetName = (obj[12].toString().concat("-").concat(obj[4].toString()).concat(" - ").concat(sentido)); + } + sheetName = sheetName.replaceAll("/", "-"); + + log.debug("Aba: " + sheetName); + sheet1 = (SXSSFSheet) wb.createSheet(sheetName); + contRow = 1; + + criarCabecalhoExcel(sheet1, estilo); + } + } catch(Exception exception){ + log.error("",exception); + System.err.println(sheetName); + continue; + } + + + popularPlanilha(sheet1, obj, estilo, coeficiente, contRow++); + } + } + + private void gerarExcelComAgrupamento(List lsRutaCombinacion, SXSSFWorkbook wb, CellStyle estilo, BigDecimal coeficiente) { + + SXSSFSheet sheet1 = null; + String ruta = ""; + int contRow = 0; + + for (int i = 0; i < lsRutaCombinacion.size(); i++) { + + Object[] obj = (Object[]) lsRutaCombinacion.get(i); + + if (!ruta.equals(obj[4].toString().concat(obj[12].toString()))) { + + ruta = obj[4].toString().concat(obj[12].toString()); + String linha = ""; + if (obj[4].toString().length() > 26) { + linha = (obj[12].toString().concat("-").concat(obj[4].toString().substring(0, 26))); + } else { + linha = (obj[12].toString().concat("-").concat(obj[4].toString())); + } + linha = "Linha: ".concat(linha.replaceAll("/", "-")); + log.debug("Linha: " + linha); + + if (sheet1 == null){ + sheet1 = (SXSSFSheet) wb.createSheet("Agrupado por Linha"); + contRow = 0; + } + + if (contRow == 0){ + criarCabecalhoExcel(sheet1, estilo); + ++contRow; + } + } + + popularPlanilha(sheet1, obj, estilo, coeficiente, contRow++); + } + } + + private boolean validarComponente(Object[] obj, int rowNum) { + if (obj[rowNum] == null) { + return false; + } + + return true; + } + + private void criarCabecalhoExcel(SXSSFSheet sheet1, CellStyle estilo) { + + Row rowCabecalho = sheet1.createRow(ROW_CABECALHO); + + Cell cellId = rowCabecalho.createCell(IDX_CELL_ID); + cellId.setCellValue(Labels.getLabel("busquedaTarifaController.lhId.label")); + cellId.setCellStyle(estilo); + + Cell cellMarca = rowCabecalho.createCell(IDX_CELL_MARCA); + cellMarca.setCellValue(Labels.getLabel("busquedaTarifaController.lhMarca.label")); + cellMarca.setCellStyle(estilo); + + Cell cellNumLinha = rowCabecalho.createCell(IDX_CELL_NUMLINHA); + cellNumLinha.setCellValue(Labels.getLabel("busquedaTarifaController.lhNumLinha.label")); + cellNumLinha.setCellStyle(estilo); + + Cell cellDescLinha = rowCabecalho.createCell(IDX_CELL_DESCLINHA); + cellDescLinha.setCellValue(Labels.getLabel("busquedaTarifaController.lhDescLinha.label")); + cellDescLinha.setCellStyle(estilo); + + Cell cellTipoClasse = rowCabecalho.createCell(IDX_CELL_TIPOCLASSE); + cellTipoClasse.setCellValue(Labels.getLabel("busquedaTarifaController.lhClaseServicio.label")); + cellTipoClasse.setCellStyle(estilo); + + Cell cellTrecho = rowCabecalho.createCell(IDX_CELL_TRECHO); + cellTrecho.setCellValue(Labels.getLabel("busquedaTarifaController.lhTramo.label")); + cellTrecho.setCellStyle(estilo); + + Cell cellOrigem = rowCabecalho.createCell(IDX_CELL_ORIGEM); + cellOrigem.setCellValue(Labels.getLabel("busquedaTarifaController.lhOrigen.label")); + cellOrigem.setCellStyle(estilo); + + Cell cellDestino = rowCabecalho.createCell(IDX_CELL_DESTINO); + cellDestino.setCellValue(Labels.getLabel("busquedaTarifaController.lhDestino.label")); + cellDestino.setCellStyle(estilo); + + Cell cellTarifaOriginal = rowCabecalho.createCell(IDX_CELL_TARIFAORIGINAL); + cellTarifaOriginal.setCellValue(Labels.getLabel("busquedaTarifaController.lhPrecioOriginal.label")); + cellTarifaOriginal.setCellStyle(estilo); + + Cell cellTarifaAtual = rowCabecalho.createCell(IDX_CELL_TARIFAATUAL); + cellTarifaAtual.setCellValue(Labels.getLabel("busquedaTarifaController.lhPrecioExcel.label")); + cellTarifaAtual.setCellStyle(estilo); + + Cell cellTarifaSimulada = rowCabecalho.createCell(IDX_CELL_TARIFA_SIMULADA); + cellTarifaSimulada.setCellValue(Labels.getLabel("busquedaTarifaController.lhPrecioNuevo.label")); + cellTarifaSimulada.setCellStyle(estilo); + + Cell cellPedagioAtual = rowCabecalho.createCell(IDX_CELL_PEDAGIOATUAL); + cellPedagioAtual.setCellValue(Labels.getLabel("busquedaTarifaController.lhPrecioPedagio.label")); + cellPedagioAtual.setCellStyle(estilo); + + Cell cellPedagioSimulado = rowCabecalho.createCell(IDX_CELL_PEDAGIOSIMULADO); + cellPedagioSimulado.setCellValue(Labels.getLabel("busquedaTarifaController.lhPrecioPedagioNuevo.label")); + cellPedagioSimulado.setCellStyle(estilo); + + Cell cellTxEmbarqueAtual = rowCabecalho.createCell(IDX_CELL_TXEMBARQUEATUAL); + cellTxEmbarqueAtual.setCellValue(Labels.getLabel("busquedaTarifaController.lhPrecioTxEmbarque.label")); + cellTxEmbarqueAtual.setCellStyle(estilo); + + Cell cellTxEmbarqueSimulado = rowCabecalho.createCell(IDX_CELL_TXEMBARQUESIMULADO); + cellTxEmbarqueSimulado.setCellValue(Labels.getLabel("busquedaTarifaController.lhPrecioTxEmbarqueSimulado.label")); + cellTxEmbarqueSimulado.setCellStyle(estilo); + + Cell cellSeguroAtual = rowCabecalho.createCell(IDX_CELL_SEGUROATUAL); + cellSeguroAtual.setCellValue(Labels.getLabel("busquedaTarifaController.lhPrecioSeguroAtual.label")); + cellSeguroAtual.setCellStyle(estilo); + + Cell cellSeguroSimulado = rowCabecalho.createCell(IDX_CELL_SEGUROSIMULADO); + cellSeguroSimulado.setCellValue(Labels.getLabel("busquedaTarifaController.lhPrecioSeguroSimulado.label")); + cellSeguroSimulado.setCellStyle(estilo); + + Cell cellTPPAtual = rowCabecalho.createCell(IDX_CELL_TPPATUAL); + cellTPPAtual.setCellValue(Labels.getLabel("busquedaTarifaController.lhPrecioTPPAtual.label")); + cellTPPAtual.setCellStyle(estilo); + + Cell cellTPPSimulado = rowCabecalho.createCell(IDX_CELL_TPPSIMULADO); + cellTPPSimulado.setCellValue(Labels.getLabel("busquedaTarifaController.lhPrecioTPPSimulado.label")); + cellTPPSimulado.setCellStyle(estilo); + + Cell cellOrgaoConcedente = rowCabecalho.createCell(IDX_CELL_ORGAOCONCEDENTE); + cellOrgaoConcedente.setCellValue(Labels.getLabel("busquedaTarifaController.lhOrgaoLabel.label")); + cellOrgaoConcedente.setCellStyle(estilo); + + Cell cellPrefixo = rowCabecalho.createCell(IDX_CELL_PREFIXO); + cellPrefixo.setCellValue(Labels.getLabel("busquedaTarifaController.lhPrefixo.label")); + cellPrefixo.setCellStyle(estilo); + + Cell cellVigencia = rowCabecalho.createCell(IDX_CELL_VIGENCIA); + cellVigencia.setCellValue(Labels.getLabel("busquedaTarifaController.lhFeciniciovigencia.label")); + cellVigencia.setCellStyle(estilo); + + Cell cellMoeda = rowCabecalho.createCell(IDX_CELL_MOEDA); + cellMoeda.setCellValue(Labels.getLabel("busquedaTarifaController.lhMoneda.label")); + cellMoeda.setCellStyle(estilo); + + Cell cellSentido = rowCabecalho.createCell(IDX_CELL_SENTIDO); + cellSentido.setCellValue(Labels.getLabel("busquedaTarifaController.lhSentido.label")); + cellSentido.setCellStyle(estilo); + + Cell cellVende = rowCabecalho.createCell(IDX_CELL_VENDE); + cellVende.setCellValue(Labels.getLabel("busquedaTarifaController.lhVende.label")); + cellVende.setCellStyle(estilo); + + Cell cellChavePorDemanda = rowCabecalho.createCell(IDX_CELL_CHAVEPORDEMANDA); + cellChavePorDemanda.setCellValue(Labels.getLabel("busquedaTarifaController.lhChavePorDemanda.label")); + cellChavePorDemanda.setCellStyle(estilo); + } + + private boolean popularPlanilha(SXSSFSheet sheet1,Object[] obj, CellStyle estilo, BigDecimal coeficiente, int rowNum){ + SXSSFRow row = (SXSSFRow) sheet1.createRow(rowNum); + + //IDXs das coluna diferente dos IDXs do obj + row.createCell(IDX_CELL_ID).setCellValue(Integer.parseInt(obj[0].toString())); + row.createCell(IDX_CELL_TRECHO).setCellValue(obj[1].toString()); + row.createCell(IDX_CELL_ORIGEM).setCellValue(obj[2].toString()); + row.createCell(IDX_CELL_DESTINO).setCellValue(obj[3].toString()); + row.createCell(IDX_CELL_DESCLINHA).setCellValue(obj[4].toString().concat(" (").concat(obj[12].toString()).concat(")")); + row.createCell(IDX_CELL_MARCA).setCellValue(obj[5].toString()); + row.createCell(IDX_CELL_TIPOCLASSE).setCellValue(obj[6].toString()); + + DateFormat sfFormatada = new SimpleDateFormat("dd/MM/yyyy"); + + Date dataIni = (Date) obj[7]; + Date dataFim = (Date) obj[8]; + + row.createCell(IDX_CELL_VIGENCIA).setCellValue(sfFormatada.format(dataIni) + " - " + sfFormatada.format(dataFim)); + row.createCell(IDX_CELL_MOEDA).setCellValue(obj[9].toString()); + + String ori = getStringImporteSafe(obj[10]); + BigDecimal original = BigDecimal.valueOf(Double.valueOf(ori)); + + String atu = getStringImporteSafe(obj[11]); + BigDecimal atual = BigDecimal.valueOf(Double.valueOf(atu)); + + row.createCell(IDX_CELL_TARIFAORIGINAL).setCellValue(original.setScale(2).doubleValue()); + row.createCell(IDX_CELL_TARIFAATUAL).setCellValue(atual.setScale(2).doubleValue()); + + String ped = getStringImporteSafe(obj[16]); + BigDecimal pedVal = BigDecimal.valueOf(Double.valueOf(ped)); + row.createCell(IDX_CELL_PEDAGIOATUAL).setCellValue(pedVal.setScale(2).doubleValue()); + + String txEmbarque = getStringImporteSafe(obj[18]); + BigDecimal txEmbarqueVal = BigDecimal.valueOf(Double.valueOf(txEmbarque)); + row.createCell(IDX_CELL_TXEMBARQUEATUAL).setCellValue(txEmbarqueVal.setScale(2).doubleValue()); + + String seguro = getStringImporteSafe(obj[19]); + BigDecimal seguroVal = BigDecimal.valueOf(Double.valueOf(seguro)); + row.createCell(IDX_CELL_SEGUROATUAL).setCellValue(seguroVal.setScale(2).doubleValue()); + + String tpp = getStringImporteSafe(obj[20]); + BigDecimal tppVal = BigDecimal.valueOf(Double.valueOf(tpp)); + row.createCell(IDX_CELL_TPPATUAL).setCellValue(tppVal.setScale(2).doubleValue()); + + row.createCell(IDX_CELL_ORGAOCONCEDENTE).setCellValue(obj[17].toString()); + + row.createCell(IDX_CELL_NUMLINHA).setCellValue(obj[21] == null?"":obj[21].toString()); + row.createCell(IDX_CELL_PREFIXO).setCellValue(obj[22] == null?"":obj[22].toString()); + + String sentido = obj[23].toString(); + row.createCell(IDX_CELL_SENTIDO).setCellValue(sentido.equals("1") ? "IDA" : "VOLTA"); + + row.createCell(IDX_CELL_VENDE).setCellValue(obj[24] == null ? "" : (Integer.parseInt(obj[24].toString()) == 1 ?"SIM" : "NAO")); + if(obj[26] == null?false:((BigDecimal)obj[26]).intValue() == 1? true : false){ + row.createCell(IDX_CELL_CHAVEPORDEMANDA).setCellValue(obj[25] == null?"":obj[25].toString()); + } + + + // novo preco: + BigDecimal novoPrecio = null; + + if (cmbComponentePreco.getSelectedItem().getValue().equals(EnumTarifaPedagio.TARIFA.getDescricao()) || + cmbComponentePreco.getSelectedItem().getValue().equals(EnumTarifaPedagio.TODOS.getDescricao())){ + + novoPrecio = atual; + novoPrecio = novoPrecio.multiply(coeficiente).setScale(2, RoundingMode.HALF_UP); + + SXSSFCell cellNovoPrecio = (SXSSFCell) row.createCell(IDX_CELL_TARIFA_SIMULADA);//celula alterada + cellNovoPrecio.setCellValue(novoPrecio.setScale(2).doubleValue()); + cellNovoPrecio.setCellStyle(estilo); + } + + if (cmbComponentePreco.getSelectedItem().getValue().equals(EnumTarifaPedagio.PEDAGIO.getDescricao())|| + cmbComponentePreco.getSelectedItem().getValue().equals(EnumTarifaPedagio.TODOS.getDescricao())){ + + if (!validarComponente(obj, IDX_CELL_PEDAGIOATUAL)){ + return false; + } + + novoPrecio = BigDecimal.valueOf(Double.valueOf(getStringImporteSafe(obj[16]))); + novoPrecio = novoPrecio.multiply(coeficiente).setScale(2, RoundingMode.HALF_UP); + + Cell cellNovoPrecio = row.createCell(IDX_CELL_PEDAGIOSIMULADO); //celula alterada + cellNovoPrecio.setCellValue(novoPrecio.setScale(2).doubleValue()); + cellNovoPrecio.setCellStyle(estilo); + } + + if (cmbComponentePreco.getSelectedItem().getValue().equals(EnumTarifaPedagio.TX_EMBARQUE.getDescricao())|| + cmbComponentePreco.getSelectedItem().getValue().equals(EnumTarifaPedagio.TODOS.getDescricao())){ + + if (!validarComponente(obj, IDX_CELL_TXEMBARQUEATUAL)){ + return false; + } + + novoPrecio = BigDecimal.valueOf(Double.valueOf(getStringImporteSafe(obj[18]))); + novoPrecio = novoPrecio.multiply(coeficiente).setScale(2, RoundingMode.HALF_UP); + + Cell cellNovoPrecio = row.createCell(IDX_CELL_TXEMBARQUESIMULADO); //celula alterada + cellNovoPrecio.setCellValue(novoPrecio.setScale(2).doubleValue()); + cellNovoPrecio.setCellStyle(estilo); + } + + if (cmbComponentePreco.getSelectedItem().getValue().equals(EnumTarifaPedagio.SEGURO.getDescricao())|| + cmbComponentePreco.getSelectedItem().getValue().equals(EnumTarifaPedagio.TODOS.getDescricao())){ + + if (!validarComponente(obj, IDX_CELL_SEGUROATUAL)){ + return false; + } + + novoPrecio = BigDecimal.valueOf(Double.valueOf(getStringImporteSafe(obj[19]))); + novoPrecio = novoPrecio.multiply(coeficiente).setScale(2, RoundingMode.HALF_UP); + + Cell cellNovoPrecio = row.createCell(IDX_CELL_SEGUROSIMULADO); //celula alterada + cellNovoPrecio.setCellValue(novoPrecio.setScale(2).doubleValue()); + cellNovoPrecio.setCellStyle(estilo); + } + + if (cmbComponentePreco.getSelectedItem().getValue().equals(EnumTarifaPedagio.TPP.getDescricao())|| + cmbComponentePreco.getSelectedItem().getValue().equals(EnumTarifaPedagio.TODOS.getDescricao())){ + + if (!validarComponente(obj, IDX_CELL_TPPATUAL)){ + return false; + } + + novoPrecio = BigDecimal.valueOf(Double.valueOf(getStringImporteSafe(obj[20]))); + novoPrecio = novoPrecio.multiply(coeficiente).setScale(2, RoundingMode.HALF_UP); + + Cell cellNovoPrecio = row.createCell(IDX_CELL_TPPSIMULADO); //celula alterada + cellNovoPrecio.setCellValue(novoPrecio.setScale(2).doubleValue()); + cellNovoPrecio.setCellStyle(estilo); + } + return true; + } +} diff --git a/src/java/com/rjconsultores/ventaboletos/web/gui/controladores/tarifas/ModificacionMasivaEmbarcadaUploadController.java b/src/java/com/rjconsultores/ventaboletos/web/gui/controladores/tarifas/ModificacionMasivaEmbarcadaUploadController.java new file mode 100644 index 000000000..67d800590 --- /dev/null +++ b/src/java/com/rjconsultores/ventaboletos/web/gui/controladores/tarifas/ModificacionMasivaEmbarcadaUploadController.java @@ -0,0 +1,661 @@ +/* + + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ +package com.rjconsultores.ventaboletos.web.gui.controladores.tarifas; + +import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.math.BigDecimal; +import java.math.RoundingMode; +import java.text.SimpleDateFormat; +import java.util.Calendar; +import java.util.List; + +import org.apache.commons.lang.StringUtils; +import org.apache.log4j.Logger; +import org.apache.poi.ss.usermodel.Cell; +import org.apache.poi.ss.usermodel.Row; +import org.apache.poi.ss.usermodel.Sheet; +import org.apache.poi.xssf.usermodel.XSSFWorkbook; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.Scope; +import org.springframework.stereotype.Controller; +import org.zkoss.util.media.Media; +import org.zkoss.util.resource.Labels; +import org.zkoss.zk.ui.Component; +import org.zkoss.zk.ui.Executions; +import org.zkoss.zk.ui.event.Event; +import org.zkoss.zul.Combobox; +import org.zkoss.zul.Comboitem; +import org.zkoss.zul.Filedownload; +import org.zkoss.zul.Label; +import org.zkoss.zul.Messagebox; +import org.zkoss.zul.Radio; + +import com.rjconsultores.ventaboletos.entidad.Ciudad; +import com.rjconsultores.ventaboletos.entidad.ClaseServicio; +import com.rjconsultores.ventaboletos.entidad.Moneda; +import com.rjconsultores.ventaboletos.entidad.Parada; +import com.rjconsultores.ventaboletos.entidad.Plaza; +import com.rjconsultores.ventaboletos.entidad.TarifaEmbarcada; +import com.rjconsultores.ventaboletos.entidad.Tramo; +import com.rjconsultores.ventaboletos.entidad.VigenciaTarifa; +import com.rjconsultores.ventaboletos.service.MercadoCompetidoService; +import com.rjconsultores.ventaboletos.service.MonedaService; +import com.rjconsultores.ventaboletos.service.TarifaEmbarcadaService; +import com.rjconsultores.ventaboletos.service.VigenciaTarifaService; +import com.rjconsultores.ventaboletos.utilerias.UsuarioLogado; +import com.rjconsultores.ventaboletos.web.utilerias.MyGenericForwardComposer; + +@Controller("modificacionMasivaEmbarcadaUploadController") +@Scope("prototype") +public class ModificacionMasivaEmbarcadaUploadController extends MyGenericForwardComposer { + + private static final long serialVersionUID = 1L; + + private final Integer CELL_ID_TARIFAEMBARCADA = 0; + private final Integer CELL_NOVO_PRECIO = 10; + // private final Integer CELL_PEAJE = 12; + private final Integer CELL_NOVO_PEAJE = 12; + private final Integer CELL_NOVO_TX_EMBARQUE = 14; + private final Integer CELL_NOVO_SEGURO = 16; + private final Integer CELL_NOVO_TPP = 18; + private final Integer CELL_NOVO_MONEDA = 22; + private final Integer CELL_ORIGINAL_PRECIO = 8; + + @Autowired + private TarifaEmbarcadaService tarifaEmbarcadaService; + @Autowired + private VigenciaTarifaService vigenciaTarifaService; + @Autowired + private MercadoCompetidoService mercadoCompetidoService; + @Autowired + private MonedaService monedaService; + private List lsVigenciaTarifa; + private VigenciaTarifa vigenciaTarifaArquivoExcel; + private Media mExcel; + + private Radio rdVigenciaAtual; + private Radio rdVigenciaNueva; + + private Combobox cmbVigenciaTarifa; + private Label lbVigencia; + private String componentePreco; + private Combobox cmbComponentePreco; + private List lsComponentePreco; + private Radio radAlterarPrecoOriginalSim; + private static Logger log = Logger.getLogger(ModificacionMasivaEmbarcadaUploadController.class); + + @Override + public void doAfterCompose(Component comp) throws Exception { + + super.doAfterCompose(comp); + + mExcel = (Media) Executions.getCurrent().getArg().get("mExcel"); + + lsVigenciaTarifa = vigenciaTarifaService.obtenerTodos(); + lbVigencia.setVisible(Boolean.FALSE); + cmbVigenciaTarifa.setVisible(Boolean.FALSE); + setLsComponentePreco(EnumTarifaPedagio.obterBundleValues()); + + carregarVigenciaTarifaArquivoExcel(); + + } + + public void onClick$rdVigenciaNueva(Event ev) { + lbVigencia.setVisible(Boolean.TRUE); + cmbVigenciaTarifa.setVisible(Boolean.TRUE); + cmbVigenciaTarifa.setConstraint("no empty"); + } + + public void onClick$rdVigenciaAtual(Event ev) { + lbVigencia.setVisible(Boolean.FALSE); + cmbVigenciaTarifa.setVisible(Boolean.FALSE); + cmbVigenciaTarifa.setConstraint(""); + } + + public void onClick$btnSalvar(Event ev) throws IOException, InterruptedException { + componentePreco = cmbComponentePreco.getValue(); + + salvarNuevos(rdVigenciaNueva.isChecked()); + } + + /** + * Indica se a operação será de alteração das tarifas do arquivo excel ou de inserção de novas tarifas em uma nova vigência + * + * @param salvarNuevos + * @throws IOException + * @throws InterruptedException + */ + public void salvarNuevos(Boolean salvarNuevos) throws IOException, InterruptedException { + + log.debug("MotificacionMasica:Salvar nuevos"); + + String strErrorTarifa = ""; + String strMercadoCompetido = ""; + String strTarifaMinima = ""; + String strDuplicidade = ""; + + Integer contador = 0; + + Integer opcao = Messagebox.show( + Labels.getLabel("modificacionMasivaEmbarcadaController.MSGAplicar"), + Labels.getLabel("modificacionMasivaEmbarcadaController.window.title"), + Messagebox.YES | Messagebox.NO, Messagebox.QUESTION); + + if (opcao.equals(Messagebox.YES)) { + + InputStream isMExcel = mExcel.getStreamData(); + XSSFWorkbook wb = new XSSFWorkbook(isMExcel); + + for (int k = 0; k < wb.getNumberOfSheets(); k++) { + + Sheet sheet = wb.getSheetAt(k); + int rows = sheet.getPhysicalNumberOfRows(); + + for (int r = 0; r < rows ; r++) { + + Row row = sheet.getRow(r); + + if (row == null || row.getCell(0) == null || (row.getCell(0).getCellType() == Cell.CELL_TYPE_STRING && (row.getCell(0).getStringCellValue().startsWith("Linha") || row.getCell(0).getStringCellValue().isEmpty()))) { + continue; + } + + if (row.getCell(0).getCellType() == Cell.CELL_TYPE_STRING && row.getCell(0).getStringCellValue().equalsIgnoreCase("id")) { + continue; + } + + if (row.getCell(0).getCellType() == Cell.CELL_TYPE_BLANK) { + continue; + } + + boolean retorno = true; + + if (!componentePreco.equals(EnumTarifaPedagio.TODOS.getDescricao())){ + retorno = validarComponenteEspecifico(row); + } + + if (!retorno){ + continue; + } + + Cell cellIdTarifa = row.getCell(CELL_ID_TARIFAEMBARCADA); + BigDecimal bdId = new BigDecimal(cellIdTarifa.getNumericCellValue()); + Integer idTarifa = bdId.intValue(); + + TarifaEmbarcada tarifa = tarifaEmbarcadaService.obtenerID(idTarifa); + + if (tarifa != null) { + alterarDescricaoTelaAuditoria(tarifa); + contador = gerarComponeneteTarifa(tarifa, row, salvarNuevos, contador, strDuplicidade, strTarifaMinima, strErrorTarifa, strMercadoCompetido); + } + } + } + } + + if (opcao.equals(Messagebox.YES)) { + Messagebox.show( + Labels.getLabel("modificacionMasivaEmbarcadaController.MSGAplicadoSucesso"), + Labels.getLabel("modificacionMasivaEmbarcadaController.window.title"), + Messagebox.OK, Messagebox.INFORMATION); + + String nomeArquivo = UsuarioLogado.getUsuarioLogado().getNombusuario() + + "_" + Calendar.getInstance().getTime().getTime() + + "_" + "retorno"; + + // Gravando no arquivo de retorno + File fNomeArquivo = File.createTempFile(nomeArquivo, ".tmp"); + FileOutputStream fos = new FileOutputStream(fNomeArquivo); + + String texto = "" + contador + " " + + Labels.getLabel("modificacionMasivaEmbarcadaController.MSG.RegistroSalvos") + "\n"; + + if (!strTarifaMinima.isEmpty()) { + texto = texto + + "---------- TARIFAS MINIMAS ----------\n" + + strTarifaMinima + + "\n-------------------------------------\n"; + } + + if (!strMercadoCompetido.isEmpty()) { + texto = texto + + "--------- MERCADO COMPETIDO -----------\n" + + strMercadoCompetido + + "\n---------------------------------------\n"; + } + + if (!strErrorTarifa.isEmpty()) { + texto = texto + + "--------------- ERRORS ----------------\n" + + strErrorTarifa + + "\n---------------------------------------"; + } + if (!strDuplicidade.toString().isEmpty()) { + log.debug(strDuplicidade); + texto = texto + + "--------------- DUPLICADO ----------------\n" + + strDuplicidade + + "\n---------------------------------------"; + } + + fos.write(texto.getBytes()); + fos.close(); + + InputStream is = null; + is = new FileInputStream(fNomeArquivo); + Filedownload.save(is, "application/txt", "RetornoModMasivaTarifasEmbarcada.txt"); + + fNomeArquivo.delete(); + + closeWindow(); + } + + } + + /** + * O arquivo excel gerado tem uma vigência apenas. Ou seja, basta buscar a primeira vigência da primeira tarifa. + * + * Carregar essa vigência em uma variável + * + * @throws IOException + * @throws InterruptedException + */ + public void carregarVigenciaTarifaArquivoExcel() throws IOException, InterruptedException { + try { + InputStream isMExcel = mExcel.getStreamData(); + XSSFWorkbook wb = null; + try { + wb = new XSSFWorkbook(isMExcel); + } catch (Exception e) { + Messagebox.show( + Labels.getLabel("modificacionMasivaEmbarcadaUploadController.MSG.excel .old"), + Labels.getLabel("modificacionMasivaEmbarcadaController.window.title"), + Messagebox.OK, Messagebox.ERROR); + closeWindow(); + return; + } + vigenciaTarifaArquivoExcel = null; + + for (int k = 0; ( (k < wb.getNumberOfSheets()) && (vigenciaTarifaArquivoExcel == null)); k++) { + Sheet sheet = wb.getSheetAt(k); + int rows = sheet.getPhysicalNumberOfRows(); + + for (int r = 0; ( (r < rows) && (vigenciaTarifaArquivoExcel == null)) ; r++) { + Row row = sheet.getRow(r); + + if (row == null || (row.getCell(0).getCellType() == Cell.CELL_TYPE_STRING && (row.getCell(0).getStringCellValue().startsWith("Linha") || row.getCell(0).getStringCellValue().isEmpty()))) { + continue; + } + + if (row.getCell(0).getCellType() == Cell.CELL_TYPE_STRING && row.getCell(0).getStringCellValue().equalsIgnoreCase("id")) { + continue; + } + + if (row.getCell(0).getCellType() == Cell.CELL_TYPE_BLANK) { + continue; + } + + Cell cellIdTarifa = row.getCell(CELL_ID_TARIFAEMBARCADA); + + BigDecimal bdId = new BigDecimal(cellIdTarifa.getNumericCellValue()); + Integer idTarifa = bdId.intValue(); + + TarifaEmbarcada tarifa = tarifaEmbarcadaService.obtenerID(idTarifa); + + if (tarifa != null) { + + vigenciaTarifaArquivoExcel = tarifa.getVigenciaTarifa(); + lsVigenciaTarifa.remove(vigenciaTarifaArquivoExcel); + + SimpleDateFormat sf = new SimpleDateFormat("dd/MM/yyyy HH:mm"); + + log.debug("Vigencia De: " + sf.format(vigenciaTarifaArquivoExcel.getFeciniciovigencia()) + " até: " + sf.format(vigenciaTarifaArquivoExcel.getFecfinvigencia())); + + rdVigenciaAtual.setLabel(Labels.getLabel("modificacionMasivaEmbarcadaUploadController.MSG.radioUno", + new Object[] { sf.format(vigenciaTarifaArquivoExcel.getFeciniciovigencia()).concat(" ").concat(sf.format(vigenciaTarifaArquivoExcel.getFecfinvigencia())) })); + } + break; + } + } + } catch (Exception e) { + log.error("Error ao inportar tarifas Excell", e); + Messagebox.show( + Labels.getLabel("modificacionMasivaEmbarcadaUploadController.MSG.excel "), + Labels.getLabel("modificacionMasivaEmbarcadaController.window.title"), + Messagebox.OK, Messagebox.ERROR); + closeWindow(); + } + } + + public List getLsVigenciaTarifa() { + return lsVigenciaTarifa; + } + + public void setLsVigenciaTarifa(List lsVigenciaTarifa) { + this.lsVigenciaTarifa = lsVigenciaTarifa; + } + + public Media getmExcel() { + return mExcel; + } + + public void setmExcel(Media mExcel) { + this.mExcel = mExcel; + } + + public Radio getRdVigenciaAtual() { + return rdVigenciaAtual; + } + + public void setRdVigenciaAtual(Radio rdVigenciaAtual) { + this.rdVigenciaAtual = rdVigenciaAtual; + } + + public Radio getRdVigenciaNueva() { + return rdVigenciaNueva; + } + + public void setRdVigenciaNueva(Radio rdVigenciaNueva) { + this.rdVigenciaNueva = rdVigenciaNueva; + } + + public Combobox getCmbVigenciaTarifa() { + return cmbVigenciaTarifa; + } + + public void setCmbVigenciaTarifa(Combobox cmbVigenciaTarifa) { + this.cmbVigenciaTarifa = cmbVigenciaTarifa; + } + + public Label getLbVigencia() { + return lbVigencia; + } + + public void setLbVigencia(Label lbVigencia) { + this.lbVigencia = lbVigencia; + } + + public Combobox getCmbComponentePreco() { + return cmbComponentePreco; + } + + public void setCmbComponentePreco(Combobox cmbComponentePreco) { + this.cmbComponentePreco = cmbComponentePreco; + } + + public List getLsComponentePreco() { + return lsComponentePreco; + } + + public void setLsComponentePreco(List lsComponentePreco) { + this.lsComponentePreco = lsComponentePreco; + } + + private Integer gerarComponeneteTarifa(TarifaEmbarcada tarifa, Row row, boolean salvarNuevos, Integer contador, String strDuplicidade, String strTarifaMinima, + String strErrorTarifa, String strMercadoCompetido){ + Tramo tramo = tarifa.getTramo(); + + if (tramo != null) { + + Parada origem = tarifa.getTramo().getOrigem(); + Ciudad ciudad = origem.getCiudad(); + Plaza plaza = null; + + if (ciudad != null) { + plaza = ciudad.getPlaza(); + } + + Parada destino = tarifa.getTramo().getDestino(); + ClaseServicio claseServicio = tarifa.getClaseServicio(); + Moneda moneda = tarifa.getMoneda(); + + // verificando se a tarifa eh de um mercado competido: + boolean existeMercadoCompetido = mercadoCompetidoService.existe(claseServicio, origem, destino); + if (!existeMercadoCompetido) { + try { + Cell cellNovoPrecio = null; + Cell cellOriginalPrecio = null; + + Boolean podeSalvarTarifaMinima = tarifaEmbarcadaService.podeAlterarTarifaMinima(tarifa, tarifa.getMarca(), + origem, destino, claseServicio, plaza, moneda); + + if (podeSalvarTarifaMinima) { + + if (salvarNuevos) { + + Comboitem cbiVt = cmbVigenciaTarifa.getSelectedItem(); + VigenciaTarifa nuevaVigencia; + + nuevaVigencia = (VigenciaTarifa) cbiVt.getValue(); + + TarifaEmbarcada tarifaNueva= tarifaEmbarcadaService.buscar(tarifa.getTramo(), tarifa.getMarca(), tarifa.getClaseServicio(), nuevaVigencia, tarifa.getMoneda(), tarifa.getRuta()); + tarifaNueva.clonar(); + alterarDescricaoTelaAuditoria(tarifaNueva); + + boolean existeTarifa = tarifaNueva != null && tarifaNueva.getTarifaembarcadaId() != null; + if(!existeTarifa) { + tarifaNueva = new TarifaEmbarcada(); + } + tarifaNueva.setVigenciaTarifa(nuevaVigencia); + + tarifaNueva.setClaseServicio(tarifa.getClaseServicio()); + tarifaNueva.setMarca(tarifa.getMarca()); + tarifaNueva.setMoneda(verificaMonedaASerInserida((row.getCell(CELL_NOVO_MONEDA) != null? row.getCell(CELL_NOVO_MONEDA).getStringCellValue():null), tarifa.getMoneda())); + tarifaNueva.setPreciooriginal(tarifa.getPreciooriginal()); + + if (componentePreco.equals(EnumTarifaPedagio.TARIFA.getDescricao()) || + (componentePreco.equals(EnumTarifaPedagio.TODOS.getDescricao()) && (row.getCell(CELL_NOVO_PRECIO) != null))) { + cellNovoPrecio = row.getCell(CELL_NOVO_PRECIO); + BigDecimal novoPrecio = new BigDecimal(cellNovoPrecio.getNumericCellValue()); + novoPrecio = novoPrecio.setScale(2, RoundingMode.HALF_UP); + + //mantis 7621 + if (radAlterarPrecoOriginalSim.isChecked() && row.getCell(CELL_ORIGINAL_PRECIO) != null){ + cellOriginalPrecio = row.getCell(CELL_ORIGINAL_PRECIO); + tarifaNueva.setPreciooriginal(new BigDecimal(cellOriginalPrecio.getNumericCellValue())); + } + + tarifaNueva.setPrecio(novoPrecio); + } + + if (componentePreco.equals(EnumTarifaPedagio.PEDAGIO.getDescricao()) || + (componentePreco.equals(EnumTarifaPedagio.TODOS.getDescricao()) && row.getCell(CELL_NOVO_PEAJE) != null)) { + cellNovoPrecio = row.getCell(CELL_NOVO_PEAJE); + BigDecimal novoPrecio = new BigDecimal(cellNovoPrecio.getNumericCellValue()); + novoPrecio = novoPrecio.setScale(2, RoundingMode.HALF_UP); + + tarifaNueva.setImportepedagio(novoPrecio); + } + + if (componentePreco.equals(EnumTarifaPedagio.TX_EMBARQUE.getDescricao()) || + (componentePreco.equals(EnumTarifaPedagio.TODOS.getDescricao()) && row.getCell(CELL_NOVO_TX_EMBARQUE) != null)) { + cellNovoPrecio = row.getCell(CELL_NOVO_TX_EMBARQUE); + BigDecimal novoPrecio = new BigDecimal(cellNovoPrecio.getNumericCellValue()); + novoPrecio = novoPrecio.setScale(2, RoundingMode.HALF_UP); + + tarifaNueva.setImportetaxaembarque(novoPrecio); + } + + if (componentePreco.equals(EnumTarifaPedagio.SEGURO.getDescricao()) || + (componentePreco.equals(EnumTarifaPedagio.TODOS.getDescricao()) && row.getCell(CELL_NOVO_SEGURO) != null)){ + cellNovoPrecio = row.getCell(CELL_NOVO_SEGURO); + BigDecimal novoPrecio = new BigDecimal(cellNovoPrecio.getNumericCellValue()); + novoPrecio = novoPrecio.setScale(2, RoundingMode.HALF_UP); + + tarifaNueva.setImporteseguro(novoPrecio); + } + + if (componentePreco.equals(EnumTarifaPedagio.TPP.getDescricao()) || + (componentePreco.equals(EnumTarifaPedagio.TODOS.getDescricao()) && row.getCell(CELL_NOVO_TPP) != null)){ + cellNovoPrecio = row.getCell(CELL_NOVO_TPP); + BigDecimal novoPrecio = new BigDecimal(cellNovoPrecio.getNumericCellValue()); + novoPrecio = novoPrecio.setScale(2, RoundingMode.HALF_UP); + + tarifaNueva.setImporteTPP(novoPrecio); + } + + tarifaNueva.setPrecioredabierto(tarifa.getPrecioredabierto()); + tarifaNueva.setStatustarifa("A"); + tarifaNueva.setTramo(tarifa.getTramo()); + tarifaNueva.setRuta(tarifa.getRuta()); + tarifaNueva.setOrgaoConcedente(tarifa.getOrgaoConcedente()); + tarifaNueva.setOrigen(tarifa.getOrigen()); + tarifaNueva.setDestino(tarifa.getDestino()); + + + + if (existeTarifa) { + tarifaEmbarcadaService.actualizacion(tarifaNueva); + } else { + tarifaNueva = tarifaEmbarcadaService.suscribir(tarifaNueva); + } + + } else { + + tarifa.setMoneda(verificaMonedaASerInserida((row.getCell(CELL_NOVO_MONEDA) != null? row.getCell(CELL_NOVO_MONEDA).getStringCellValue():null), tarifa.getMoneda())); + if (componentePreco.equals(EnumTarifaPedagio.TARIFA.getDescricao()) || + (componentePreco.equals(EnumTarifaPedagio.TODOS.getDescricao()) && row.getCell(CELL_NOVO_PRECIO) != null)) { + cellNovoPrecio = row.getCell(CELL_NOVO_PRECIO); + BigDecimal novoPrecio = new BigDecimal(cellNovoPrecio.getNumericCellValue()); + novoPrecio = novoPrecio.setScale(2, RoundingMode.HALF_UP); + + cellOriginalPrecio = row.getCell(CELL_ORIGINAL_PRECIO); + BigDecimal originalPrecio = new BigDecimal(cellOriginalPrecio.getNumericCellValue()); + originalPrecio = originalPrecio.setScale(2, RoundingMode.HALF_UP); + + //mantis 7621 + if (radAlterarPrecoOriginalSim.isChecked()){ + tarifa.setPreciooriginal(originalPrecio); + } + + tarifa.setPrecio(novoPrecio); + } + + if (componentePreco.equals(EnumTarifaPedagio.PEDAGIO.getDescricao()) || + (componentePreco.equals(EnumTarifaPedagio.TODOS.getDescricao()) && row.getCell(CELL_NOVO_PEAJE) != null)) { + cellNovoPrecio = row.getCell(CELL_NOVO_PEAJE); + BigDecimal novoPrecio = new BigDecimal(cellNovoPrecio.getNumericCellValue()); + novoPrecio = novoPrecio.setScale(2, RoundingMode.HALF_UP); + + tarifa.setImportepedagio(novoPrecio); + } + + if (componentePreco.equals(EnumTarifaPedagio.TX_EMBARQUE.getDescricao()) || + (componentePreco.equals(EnumTarifaPedagio.TODOS.getDescricao()) && row.getCell(CELL_NOVO_TX_EMBARQUE) != null)) { + cellNovoPrecio = row.getCell(CELL_NOVO_TX_EMBARQUE); + BigDecimal novoPrecio = new BigDecimal(cellNovoPrecio.getNumericCellValue()); + novoPrecio = novoPrecio.setScale(2, RoundingMode.HALF_UP); + + tarifa.setImportetaxaembarque(novoPrecio); + } + + if (componentePreco.equals(EnumTarifaPedagio.SEGURO.getDescricao()) || + (componentePreco.equals(EnumTarifaPedagio.TODOS.getDescricao()) && row.getCell(CELL_NOVO_SEGURO) != null)) { + cellNovoPrecio = row.getCell(CELL_NOVO_SEGURO); + BigDecimal novoPrecio = new BigDecimal(cellNovoPrecio.getNumericCellValue()); + novoPrecio = novoPrecio.setScale(2, RoundingMode.HALF_UP); + + tarifa.setImporteseguro(novoPrecio); + } + + if (componentePreco.equals(EnumTarifaPedagio.TPP.getDescricao()) || + (componentePreco.equals(EnumTarifaPedagio.TODOS.getDescricao()) && row.getCell(CELL_NOVO_TPP) != null)) { + cellNovoPrecio = row.getCell(CELL_NOVO_TPP); + BigDecimal novoPrecio = new BigDecimal(cellNovoPrecio.getNumericCellValue()); + novoPrecio = novoPrecio.setScale(2, RoundingMode.HALF_UP); + + tarifa.setImporteTPP(novoPrecio); + } + + tarifa.setStatustarifa("A"); + + tarifa = tarifaEmbarcadaService.actualizacion(tarifa); + } + + contador = contador + 1; + } else { + String strTmpTarifaMinima = "TARIFA MINIMA: \n" + + "Tarifa: " + tarifa.getTarifaembarcadaId() + "; \n" + + "Tramo: " + tramo.getDesctramo() + "; \n" + + "Via: " + tramo.getVia() + "; \n" + + "Clase Servicio: " + claseServicio + "; \n" + + "Precio: " + tarifa.getPrecio().setScale(2).toString() + "\n"; + + log.info(strTmpTarifaMinima); + + strTarifaMinima = strTarifaMinima + strTmpTarifaMinima; + } + } catch (Exception ex) { + String strTmpErrorTarifa = "ERROR: formato nuevo precio." + ex + "\n" + + "Tarifa: " + tarifa.getTarifaembarcadaId() + "; \n" + + "Tramo: " + tramo.getDesctramo() + "; \n" + + "Via: " + tramo.getVia() + "; \n" + + "Clase Servicio: " + claseServicio + "; \n" + + "Precio: " + tarifa.getPrecio().setScale(2).toString() + "\n"; + + log.error(strTmpErrorTarifa); + + strErrorTarifa = strErrorTarifa + strTmpErrorTarifa; + } + } else { + String strTmpMercadoCompetido = "MERCADO COMPETIDO: \n" + + "Tarifa: " + tarifa.getTarifaembarcadaId() + "; \n" + + "Tramo: " + tramo.getDesctramo() + "; \n" + + "Via: " + tramo.getVia() + "; \n" + + "Clase Servicio: " + claseServicio + "; \n" + + "Precio: " + tarifa.getPrecio().setScale(2).toString() + "\n"; + + log.info(strTmpMercadoCompetido); + + strMercadoCompetido = strMercadoCompetido + strTmpMercadoCompetido; + } + } + + return contador; + } + + private void alterarDescricaoTelaAuditoria(TarifaEmbarcada tarifa) { + tarifa.setTelaAlternativa("Modificação Massiva de Preços Embarcada"); + } + + private boolean validarComponenteEspecifico(Row row) { + if (componentePreco.equals(EnumTarifaPedagio.TARIFA.getDescricao())){ + if (row.getCell(CELL_NOVO_PRECIO) == null) { + return false; + } + } else if (componentePreco.equals(EnumTarifaPedagio.PEDAGIO.getDescricao())){ + if (row.getCell(CELL_NOVO_PEAJE) == null) { + return false; + } + } else if (componentePreco.equals(EnumTarifaPedagio.SEGURO.getDescricao())){ + if (row.getCell(CELL_NOVO_SEGURO) == null) { + return false; + } + } else if (componentePreco.equals(EnumTarifaPedagio.TX_EMBARQUE.getDescricao())){ + if (row.getCell(CELL_NOVO_TX_EMBARQUE) == null) { + return false; + } + } + + return true; + } + + private Moneda verificaMonedaASerInserida(String descMoedaNova, Moneda atual ) { + Moneda nova = atual; + if (!StringUtils.isBlank(descMoedaNova)) { + if(!descMoedaNova.equals(atual.getDescmoneda())) { + List monedas = monedaService.buscar(descMoedaNova); + if(monedas !=null && !monedas.isEmpty()){ + nova = monedas.get(0); + } + return nova; + } + } + return nova; + } +} diff --git a/src/java/com/rjconsultores/ventaboletos/web/utilerias/menu/item/tarifas/ItemMenuModificacionMasivaEmbarcada.java b/src/java/com/rjconsultores/ventaboletos/web/utilerias/menu/item/tarifas/ItemMenuModificacionMasivaEmbarcada.java new file mode 100644 index 000000000..e290a7e2b --- /dev/null +++ b/src/java/com/rjconsultores/ventaboletos/web/utilerias/menu/item/tarifas/ItemMenuModificacionMasivaEmbarcada.java @@ -0,0 +1,27 @@ +package com.rjconsultores.ventaboletos.web.utilerias.menu.item.tarifas; + +import org.zkoss.util.resource.Labels; + +import com.rjconsultores.ventaboletos.constantes.ConstantesFuncionSistema; +import com.rjconsultores.ventaboletos.web.utilerias.PantallaUtileria; +import com.rjconsultores.ventaboletos.web.utilerias.menu.DefaultItemMenuSistema; + +public class ItemMenuModificacionMasivaEmbarcada extends DefaultItemMenuSistema { + + public ItemMenuModificacionMasivaEmbarcada() { + super("indexController.mniModificacionMasivaEmbarcada.label"); + } + + @Override + public String getClaveMenu() { + return ConstantesFuncionSistema.CLAVE_MODIFICACAO_EMBARCADA; + } + + @Override + public void ejecutar() { + PantallaUtileria.openWindow("/gui/tarifas/modificacionMasivaEmbarcada.zul", + Labels.getLabel("indexController.mniModificacionMasivaEmbarcada.label"), getArgs(), desktop); + + } + +} diff --git a/src/java/com/rjconsultores/ventaboletos/web/utilerias/menu/menu_original.properties b/src/java/com/rjconsultores/ventaboletos/web/utilerias/menu/menu_original.properties index 44890cb04..634a64152 100644 --- a/src/java/com/rjconsultores/ventaboletos/web/utilerias/menu/menu_original.properties +++ b/src/java/com/rjconsultores/ventaboletos/web/utilerias/menu/menu_original.properties @@ -125,6 +125,7 @@ tarifas.modificacionMasiva=com.rjconsultores.ventaboletos.web.utilerias.menu.ite tarifas.modificacionMasivaAlias=com.rjconsultores.ventaboletos.web.utilerias.menu.item.tarifas.ItemMenuModificacionMasivaAlias tarifas.tarifas=com.rjconsultores.ventaboletos.web.utilerias.menu.item.tarifas.ItemMenuTarifas tarifas.tarifaembarcada=com.rjconsultores.ventaboletos.web.utilerias.menu.item.tarifas.ItemMenuTarifaEmbarcada +tarifas.modificacionMasivaEmbarcada=com.rjconsultores.ventaboletos.web.utilerias.menu.item.tarifas.ItemMenuModificacionMasivaEmbarcada tarifas.tarifaEscala=com.rjconsultores.ventaboletos.web.utilerias.menu.item.tarifas.ItemMenuTarifaEscala tarifas.segopcional=com.rjconsultores.ventaboletos.web.utilerias.menu.item.tarifas.segopcional.SubMenuSegOpcional tarifas.segopcional.seguradoraEmpresa=com.rjconsultores.ventaboletos.web.utilerias.menu.item.tarifasOficial.ItemMenuSeguradoraEmpresa diff --git a/src/java/com/rjconsultores/ventaboletos/web/utilerias/render/RenderEmpresaModificacionMassivaEmbarcada.java b/src/java/com/rjconsultores/ventaboletos/web/utilerias/render/RenderEmpresaModificacionMassivaEmbarcada.java new file mode 100644 index 000000000..5b038d028 --- /dev/null +++ b/src/java/com/rjconsultores/ventaboletos/web/utilerias/render/RenderEmpresaModificacionMassivaEmbarcada.java @@ -0,0 +1,29 @@ +/* + * 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.Empresa; +import org.zkoss.zul.Listcell; +import org.zkoss.zul.Listitem; +import org.zkoss.zul.ListitemRenderer; + +/** + * + * @author Administrador + */ +public class RenderEmpresaModificacionMassivaEmbarcada implements ListitemRenderer { + + public void render(Listitem lstm, Object o) throws Exception { + Empresa empresa = (Empresa) o; + + Listcell lc = new Listcell(empresa.getEmpresaId().toString()); + lc.setParent(lstm); + + lc = new Listcell(empresa.getNombempresa()); + lc.setParent(lstm); + + lstm.setAttribute("data", empresa); + } +} diff --git a/src/java/com/rjconsultores/ventaboletos/web/utilerias/render/RenderOrgaoConcedenteModifMassEmb.java b/src/java/com/rjconsultores/ventaboletos/web/utilerias/render/RenderOrgaoConcedenteModifMassEmb.java new file mode 100644 index 000000000..cb6c658c3 --- /dev/null +++ b/src/java/com/rjconsultores/ventaboletos/web/utilerias/render/RenderOrgaoConcedenteModifMassEmb.java @@ -0,0 +1,24 @@ +package com.rjconsultores.ventaboletos.web.utilerias.render; + +import org.zkoss.zul.Listcell; +import org.zkoss.zul.Listitem; +import org.zkoss.zul.ListitemRenderer; + +import com.rjconsultores.ventaboletos.entidad.OrgaoConcedente; + +public class RenderOrgaoConcedenteModifMassEmb implements ListitemRenderer { + + public void render(Listitem lstm, Object o) throws Exception { + OrgaoConcedente orgaoConcedente = (OrgaoConcedente) o; + + Listcell lc = new Listcell(orgaoConcedente.getOrgaoConcedenteId().toString()); + lc.setParent(lstm); + + lc = new Listcell(orgaoConcedente.getDescOrgao()); + lc.setParent(lstm); + + lc.setParent(lstm); + + lstm.setAttribute("data", orgaoConcedente); + } +} diff --git a/src/java/com/rjconsultores/ventaboletos/web/utilerias/render/RenderVigenciaTarifaModificacionMassivaEmbarcada.java b/src/java/com/rjconsultores/ventaboletos/web/utilerias/render/RenderVigenciaTarifaModificacionMassivaEmbarcada.java new file mode 100644 index 000000000..4f5f0a675 --- /dev/null +++ b/src/java/com/rjconsultores/ventaboletos/web/utilerias/render/RenderVigenciaTarifaModificacionMassivaEmbarcada.java @@ -0,0 +1,42 @@ +/* + * 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.VigenciaTarifa; +import java.text.SimpleDateFormat; +import org.zkoss.zul.Listcell; +import org.zkoss.zul.Listitem; +import org.zkoss.zul.ListitemRenderer; + +/** + * + * @author Administrador + */ +public class RenderVigenciaTarifaModificacionMassivaEmbarcada implements ListitemRenderer { + + public void render(Listitem lstm, Object o) throws Exception { + VigenciaTarifa vigenciaTarifa = (VigenciaTarifa) o; + SimpleDateFormat f = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss"); + + Listcell lc = new Listcell(vigenciaTarifa.getVigenciatarifaId().toString()); + lc.setParent(lstm); + + if (vigenciaTarifa.getFeciniciovigencia() != null) { + lc = new Listcell(f.format(vigenciaTarifa.getFeciniciovigencia())); + } else { + lc = new Listcell(""); + } + lc.setParent(lstm); + + if (vigenciaTarifa.getFecfinvigencia() != null) { + lc = new Listcell(f.format(vigenciaTarifa.getFecfinvigencia())); + } else { + lc = new Listcell(""); + } + lc.setParent(lstm); + + lstm.setAttribute("data", vigenciaTarifa); + } +} diff --git a/web/WEB-INF/i3-label_en.label b/web/WEB-INF/i3-label_en.label index d320ae5ed..fe03f4741 100644 --- a/web/WEB-INF/i3-label_en.label +++ b/web/WEB-INF/i3-label_en.label @@ -3500,6 +3500,48 @@ modificacionMasivaTarifasController.agrupamentoLinha.radioNao=Não modificacionMasivaTarifasController.alterarPrecoOriginal=Alterar Preço Original modificacionMasivaTarifasController.alterarPrecoOriginal.radioNao=Não modificacionMasivaTarifasController.alterarPrecoOriginal.radioSim=Sim + +# Modificacion Massiva Embarcada +editarEmbarcadaController.window.title = Shipped Fare +editarEmbarcadaController.lhPrecio.label = Select... +modificacionMasivaEmbarcadaController.window.title = Onboard Mass Modification +modificacionMasivaEmbarcadaController.porcentagem.label = % (0-100) +modificacionMasivaEmbarcadaController.MSGAplicar = Apply modification? +modificacionMasivaEmbarcadaController.MSGAplicadoSucesso = Modification successfully applied. Wait for the results file. +modificacionMasivaEmbarcadaController.radIncremento = increment +modificacionMasivaEmbarcadaController.radDecremento = Decrement +modificacionMasivaEmbarcadaController.formato = Format +modificacionMasivaEmbarcadaController.linear = Linear +modificacionMasivaEmbarcadaController.escala = Scale +modificacionMasivaEmbarcadaController.salvarNuevos =Operation +modificacionMasivaEmbarcadaController.salvarNuevos.si = Yes +modificacionMasivaEmbarcadaController.salvarNuevos.no = No +modificacionMasivaEmbarcadaController.tipoModificacion = Type Moddification +modificacionMasivaEmbarcadaController.btnUpLoadExcel.tooltiptext = Import Excel authorized. +modificacionMasivaEmbarcadaController.btnUpLoadExcel.label = Importa Excel authorized +modificacionMasgeracionCorridaController.MSG.ForaVigenciaivaEmbarcadaController.btnUpLoadExcel.label = Import Excel authorized +modificacionMasivaEmbarcadaController.btnGerarExcel.label = Generate Excel with simulation +modificacionMasivaEmbarcadaController.btnGerarExcel.tooltiptext = Generate Excel with simulation. +modificacionMasivaEmbarcadaController.MSG.SemVigencia = Select a validity . +modificacionMasivaEmbarcadaUploadController.MSG.pergunta = Select the term for which the modification will be applied: +modificacionMasivaEmbarcadaUploadController.MSG.radioUno = Update Onboard Fares Selected term: {0} +modificacionMasivaEmbarcadaUploadController.MSG.radioDos = Insert Charges Embedded in Another Term: +modificacionMasivaEmbarcadaUploadController.MSG.salvar = Apply changes +modificacionMasivaEmbarcadaUploadController.MSG.excel = Error importing Excel file . +modificacionMasivaEmbarcadaUploadController.MSG.excel.old = Only excel files in xlsx format can be imported. +modificacionMasivaEmbarcadaUploadController.MSG.excelVazio = No Embedded Rates found for excel generation +modificacionMasivaEmbarcadaUploadController.MSG.nomaximoumavigencia= select only one term +modificacionMasivaEmbarcadaController.componentePreco.label = Price Component +modificacionMasivaEmbarcadaController.orgaoConcedente.label = Granting Agency +modificacionMasivaEmbarcadaController.lhNombOrgao.label = Name of Granting Agency +modificacionMasivaEmbarcadaController.lhId.label = ID +modificacionMasivaEmbarcadaController.agrupamentoLinha.label = Grouping by Line +modificacionMasivaEmbarcadaController.agrupamentoLinha.radioSim = Yes +modificacionMasivaEmbarcadaController.agrupamentoLinha.radioNao = No +modificacionMasivaEmbarcadaController.alterarPrecoOriginal = Change Original Price +modificacionMasivaEmbarcadaController.alterarPrecoOriginal.radioNao = No +modificacionMasivaEmbarcadaController.alterarPrecoOriginal.radioSim = Yes +modificacionMasivaEmbarcadaController.MSG.RegistroSalvos = Record(s) successfully processed. # Modificação Massiva Alias modificacionMasivaAliasTarifasController.window.title=Modificação Massiva Alias diff --git a/web/WEB-INF/i3-label_es_MX.label b/web/WEB-INF/i3-label_es_MX.label index 16edafa45..362a8e53a 100644 --- a/web/WEB-INF/i3-label_es_MX.label +++ b/web/WEB-INF/i3-label_es_MX.label @@ -3445,6 +3445,47 @@ modificacionMasivaTarifasController.agrupamentoLinha.label = Línea de Agrupaci modificacionMasivaTarifasController.agrupamentoLinha.radioSim = Sí modificacionMasivaTarifasController.agrupamentoLinha.radioNao = No +# Modificacion Massiva Embarcada +editarEmbarcadaController.window.title = Tarifa Embarcada +editarEmbarcadaController.lhPrecio.label = Selecione... +modificacionMasivaEmbarcadaController.window.title = Modificação Massiva Embarcada +modificacionMasivaEmbarcadaController.porcentagem.label = % (0-100) +modificacionMasivaEmbarcadaController.MSGAplicar = Aplicar modificação? +modificacionMasivaEmbarcadaController.MSGAplicadoSucesso = Modificação aplicada com Sucesso. Esperar o arquivo de resultados. +modificacionMasivaEmbarcadaController.radIncremento = Incremento +modificacionMasivaEmbarcadaController.radDecremento = Decremento +modificacionMasivaEmbarcadaController.formato = Formato +modificacionMasivaEmbarcadaController.linear = Lineal +modificacionMasivaEmbarcadaController.escala = Escala +modificacionMasivaEmbarcadaController.salvarNuevos =Operação +modificacionMasivaEmbarcadaController.salvarNuevos.si = Sim +modificacionMasivaEmbarcadaController.salvarNuevos.no = Não +modificacionMasivaEmbarcadaController.tipoModificacion = Tipo Modificação +modificacionMasivaEmbarcadaController.btnUpLoadExcel.tooltiptext = Importar Excel autorizado. +modificacionMasivaEmbarcadaController.btnUpLoadExcel.label = Importar Excel autorizado +modificacionMasgeracionCorridaController.MSG.ForaVigenciaivaEmbarcadaController.btnUpLoadExcel.label = Importar Excel autorizado +modificacionMasivaEmbarcadaController.btnGerarExcel.label = Gerar Excel com simulação +modificacionMasivaEmbarcadaController.btnGerarExcel.tooltiptext = Gerar Excel com simulação. +modificacionMasivaEmbarcadaController.MSG.SemVigencia = Selecione uma vigência. +modificacionMasivaEmbarcadaUploadController.MSG.pergunta = Selecione a vigência a qual será aplicada a modificação: +modificacionMasivaEmbarcadaUploadController.MSG.radioUno = Atualizar Tarifas Embarcada Vigência seleccionada: {0} +modificacionMasivaEmbarcadaUploadController.MSG.radioDos = Inserir Tarifas Embarcada em Outra vigência: +modificacionMasivaEmbarcadaUploadController.MSG.salvar = Aplicar modificações +modificacionMasivaEmbarcadaUploadController.MSG.excel = Erro ao importar arquivo Excel. +modificacionMasivaEmbarcadaUploadController.MSG.excel.old = Somente podem ser importados arquivos do excel no formato xlsx. +modificacionMasivaEmbarcadaUploadController.MSG.excelVazio = Não foram encontradas Tarifas Embarcada para geração do excel +modificacionMasivaEmbarcadaUploadController.MSG.nomaximoumavigencia= É possível selecionar apenas uma vigência +modificacionMasivaEmbarcadaController.componentePreco.label = Componente do Preço +modificacionMasivaEmbarcadaController.orgaoConcedente.label = Órgão Concedente +modificacionMasivaEmbarcadaController.lhNombOrgao.label = Nome Órgão Concedente +modificacionMasivaEmbarcadaController.lhId.label = ID +modificacionMasivaEmbarcadaController.agrupamentoLinha.label = Agrupamento por Linha +modificacionMasivaEmbarcadaController.agrupamentoLinha.radioSim = Sim +modificacionMasivaEmbarcadaController.agrupamentoLinha.radioNao = Não +modificacionMasivaEmbarcadaController.alterarPrecoOriginal = Alterar Preço Original +modificacionMasivaEmbarcadaController.alterarPrecoOriginal.radioNao = Não +modificacionMasivaEmbarcadaController.alterarPrecoOriginal.radioSim = Sim +modificacionMasivaEmbarcadaController.MSG.RegistroSalvos = Registro(s) processado(s) com Sucesso. # Modificação Massiva Alias modificacionMasivaAliasTarifasController.window.title = Modificación Masiva Alias diff --git a/web/WEB-INF/i3-label_pt_BR.label b/web/WEB-INF/i3-label_pt_BR.label index a91ef72b7..043453330 100644 --- a/web/WEB-INF/i3-label_pt_BR.label +++ b/web/WEB-INF/i3-label_pt_BR.label @@ -191,6 +191,7 @@ indexController.mniParamAcumulacionMasivo.label = Configuração Acumulação Ma indexController.mniParamCompraPunto.label = Configuração Compra de Pontos indexController.mniParamCostoTarjeta.label = Configuração Custo Cartão indexController.mniModificacionMasiva.label = Modificação Massiva de Preços +indexController.mniModificacionMasivaEmbarcada.label = Modificação Massiva - Embarcada indexController.mniModificacionMasivaAlias.label = Modificação Massiva Alias indexController.mniCambioVigencia.label = Mudar/Copiar Vigência indexController.mnAjuda.label = Ajuda @@ -3798,6 +3799,48 @@ modificacionMasivaPricingEspecificoController.msg.registroSalvos = registro(s) m modificacionMasivaPricingEspecificoController.msg.registrosCancelados1 = Sendo destes : modificacionMasivaPricingEspecificoController.msg.registrosCancelados2 = registros cancelados. +# Modificacion Massiva Embarcada +editarEmbarcadaController.window.title = Tarifa Embarcada +editarEmbarcadaController.lhPrecio.label = Selecione... +modificacionMasivaEmbarcadaController.window.title = Modificação Massiva Embarcada +modificacionMasivaEmbarcadaController.porcentagem.label = % (0-100) +modificacionMasivaEmbarcadaController.MSGAplicar = Aplicar modificação? +modificacionMasivaEmbarcadaController.MSGAplicadoSucesso = Modificação aplicada com Sucesso. Esperar o arquivo de resultados. +modificacionMasivaEmbarcadaController.radIncremento = Incremento +modificacionMasivaEmbarcadaController.radDecremento = Decremento +modificacionMasivaEmbarcadaController.formato = Formato +modificacionMasivaEmbarcadaController.linear = Lineal +modificacionMasivaEmbarcadaController.escala = Escala +modificacionMasivaEmbarcadaController.salvarNuevos =Operação +modificacionMasivaEmbarcadaController.salvarNuevos.si = Sim +modificacionMasivaEmbarcadaController.salvarNuevos.no = Não +modificacionMasivaEmbarcadaController.tipoModificacion = Tipo Modificação +modificacionMasivaEmbarcadaController.btnUpLoadExcel.tooltiptext = Importar Excel autorizado. +modificacionMasivaEmbarcadaController.btnUpLoadExcel.label = Importar Excel autorizado +modificacionMasgeracionCorridaController.MSG.ForaVigenciaivaEmbarcadaController.btnUpLoadExcel.label = Importar Excel autorizado +modificacionMasivaEmbarcadaController.btnGerarExcel.label = Gerar Excel com simulação +modificacionMasivaEmbarcadaController.btnGerarExcel.tooltiptext = Gerar Excel com simulação. +modificacionMasivaEmbarcadaController.MSG.SemVigencia = Selecione uma vigência. +modificacionMasivaEmbarcadaUploadController.MSG.pergunta = Selecione a vigência a qual será aplicada a modificação: +modificacionMasivaEmbarcadaUploadController.MSG.radioUno = Atualizar Tarifas Embarcada Vigência seleccionada: {0} +modificacionMasivaEmbarcadaUploadController.MSG.radioDos = Inserir Tarifas Embarcada em Outra vigência: +modificacionMasivaEmbarcadaUploadController.MSG.salvar = Aplicar modificações +modificacionMasivaEmbarcadaUploadController.MSG.excel = Erro ao importar arquivo Excel. +modificacionMasivaEmbarcadaUploadController.MSG.excel.old = Somente podem ser importados arquivos do excel no formato xlsx. +modificacionMasivaEmbarcadaUploadController.MSG.excelVazio = Não foram encontradas Tarifas Embarcada para geração do excel +modificacionMasivaEmbarcadaUploadController.MSG.nomaximoumavigencia= É possível selecionar apenas uma vigência +modificacionMasivaEmbarcadaController.componentePreco.label = Componente do Preço +modificacionMasivaEmbarcadaController.orgaoConcedente.label = Órgão Concedente +modificacionMasivaEmbarcadaController.lhNombOrgao.label = Nome Órgão Concedente +modificacionMasivaEmbarcadaController.lhId.label = ID +modificacionMasivaEmbarcadaController.agrupamentoLinha.label = Agrupamento por Linha +modificacionMasivaEmbarcadaController.agrupamentoLinha.radioSim = Sim +modificacionMasivaEmbarcadaController.agrupamentoLinha.radioNao = Não +modificacionMasivaEmbarcadaController.alterarPrecoOriginal = Alterar Preço Original +modificacionMasivaEmbarcadaController.alterarPrecoOriginal.radioNao = Não +modificacionMasivaEmbarcadaController.alterarPrecoOriginal.radioSim = Sim +modificacionMasivaEmbarcadaController.MSG.RegistroSalvos = Registro(s) processado(s) com Sucesso. + #Geracion de Serviço geracionCorridaController.window.title = Geração de Serviços geracionCorridaController.lhGerar.label = Gerar serviços diff --git a/web/gui/tarifas/modificacionMasivaEmbarcada.zul b/web/gui/tarifas/modificacionMasivaEmbarcada.zul new file mode 100644 index 000000000..a45121f66 --- /dev/null +++ b/web/gui/tarifas/modificacionMasivaEmbarcada.zul @@ -0,0 +1,386 @@ + + + + + + + + + + +