diff --git a/src/java/com/rjconsultores/ventaboletos/web/gui/controladores/pricing/CopiarPricingController.java b/src/java/com/rjconsultores/ventaboletos/web/gui/controladores/pricing/CopiarPricingController.java index f9a8c89c7..57c05b1a1 100644 --- a/src/java/com/rjconsultores/ventaboletos/web/gui/controladores/pricing/CopiarPricingController.java +++ b/src/java/com/rjconsultores/ventaboletos/web/gui/controladores/pricing/CopiarPricingController.java @@ -1,12 +1,9 @@ package com.rjconsultores.ventaboletos.web.gui.controladores.pricing; -import java.util.List; - +import org.apache.commons.lang.StringUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Scope; import org.springframework.stereotype.Controller; -import org.zkoss.util.resource.Labels; -import org.zkoss.zhtml.Messagebox; import org.zkoss.zk.ui.Component; import org.zkoss.zk.ui.Executions; import org.zkoss.zk.ui.event.Event; @@ -14,6 +11,8 @@ import org.zkoss.zul.Textbox; import com.rjconsultores.ventaboletos.entidad.Pricing; import com.rjconsultores.ventaboletos.service.PricingService; +import com.rjconsultores.ventaboletos.utilerias.ApplicationProperties; +import com.rjconsultores.ventaboletos.web.utilerias.MensagensUtils; import com.rjconsultores.ventaboletos.web.utilerias.MyGenericForwardComposer; import com.rjconsultores.ventaboletos.web.utilerias.MyListbox; @@ -21,6 +20,8 @@ import com.rjconsultores.ventaboletos.web.utilerias.MyListbox; @Scope("prototype") public class CopiarPricingController extends MyGenericForwardComposer { + private static final String CONTROLLER_WINDOW_TITLE = "copiarPricingController.window.title"; + private static final long serialVersionUID = 1L; @Autowired @@ -38,42 +39,30 @@ public class CopiarPricingController extends MyGenericForwardComposer { } public void onClick$btnSalvarCopia(Event ev) throws InterruptedException { - if (!nombrePricing.getText().equals("") && nombrePricing.getText() != null) { - - List lsPricing = - pricingService.buscarPorNombre(nombrePricing.getText()); - - if (lsPricing.isEmpty()) { - - Boolean resp = pricingService.clonarPricing(pricing.getPricingId(), nombrePricing.getText()); - - if (resp) { - - closeWindow(); - Messagebox.show( - Labels.getLabel("copiarPricingController.MSG.suscribirOK"), - Labels.getLabel("copiarPricingController.window.title"), - Messagebox.OK, Messagebox.INFORMATION); - - } else { - Messagebox.show( - Labels.getLabel("copiarPricingController.MSG.ERRO"), - Labels.getLabel("copiarPricingController.window.title"), - Messagebox.OK, Messagebox.INFORMATION); - } - - } else { - Messagebox.show( - Labels.getLabel("copiarPricingController.MSG.Registro.Existe"), - Labels.getLabel("copiarPricingController.window.title"), - Messagebox.OK, Messagebox.EXCLAMATION); - } - } else { - Messagebox.show( - Labels.getLabel("copiarPricingController.MSG.sem.nome"), - Labels.getLabel("copiarPricingController.window.title"), - Messagebox.OK, Messagebox.EXCLAMATION); + if (StringUtils.isBlank(nombrePricing.getText())) { + MensagensUtils.showMessageExclamation("copiarPricingController.MSG.sem.nome",CONTROLLER_WINDOW_TITLE); + return; } + + if (existePricingComMesmoNome()) { + MensagensUtils.showMessageExclamation("copiarPricingController.MSG.Registro.Existe", CONTROLLER_WINDOW_TITLE); + return; + } + + Boolean clonou = pricingService.clonarPricing(pricing.getPricingId(), nombrePricing.getText(), + ApplicationProperties.getInstance().usaPadraoPricingTipoPassagemPET()); + + if (clonou) { + closeWindow(); + MensagensUtils.showMessageInformation("copiarPricingController.MSG.suscribirOK", CONTROLLER_WINDOW_TITLE); + } else { + MensagensUtils.showMessageInformation("copiarPricingController.MSG.ERRO", CONTROLLER_WINDOW_TITLE); + } + + } + + protected boolean existePricingComMesmoNome() { + return pricingService.buscarPorNombre(nombrePricing.getText()).size() > 0; } public void onClose$winCopiarPricing(Event ev) { diff --git a/src/java/com/rjconsultores/ventaboletos/web/gui/controladores/pricing/EditarPricingController.java b/src/java/com/rjconsultores/ventaboletos/web/gui/controladores/pricing/EditarPricingController.java index 4366f7a58..e7c899c2a 100644 --- a/src/java/com/rjconsultores/ventaboletos/web/gui/controladores/pricing/EditarPricingController.java +++ b/src/java/com/rjconsultores/ventaboletos/web/gui/controladores/pricing/EditarPricingController.java @@ -100,7 +100,7 @@ import com.rjconsultores.ventaboletos.web.utilerias.render.RenderPricingVigencia @Controller("editarPricingController") @Scope("prototype") @SuppressWarnings("unused") -public class EditarPricingController extends MyGenericForwardComposer { +public class EditarPricingController extends PricingController { private static final long serialVersionUID = 1L; private static Logger log = Logger.getLogger(EditarPricingController.class); @@ -266,7 +266,6 @@ public class EditarPricingController extends MyGenericForwardComposer { @Override public void doAfterCompose(Component comp) throws Exception { lsEmpresa = UsuarioLogado.getUsuarioLogado().getEmpresa(); -// lsEmpresa.add(empresaService.obtenerID(-1)); pricing = (Pricing) Executions.getCurrent().getArg().get("pricing"); pricingList = (MyListbox) Executions.getCurrent().getArg().get("pricingList"); @@ -663,29 +662,27 @@ public class EditarPricingController extends MyGenericForwardComposer { pricingMercadoService.suscribir(pme); } - // Empresa -// Empresa emp = empresaService.obtenerID(-1); -// if (emp != null) { -// pricing.setEmpresa(emp); -// cmbEmpresa.setText(emp.getNombempresa()); -// } + // Tipo Pasajero - Categoria + if (ApplicationProperties.getInstance().habilitarPricingCategoria()) { + pricingCategoriaList.setDisabled(Boolean.FALSE); + btnNovoCategoria.setDisabled(Boolean.FALSE); + btnApagarCategoria.setDisabled(Boolean.FALSE); + btnModificarCategoria.setDisabled(Boolean.FALSE); + } else { + incluirCategoria(categoriaService.obtenerID(1)); + } + + incluirCategoriasPadroes(); + + btnApagar.setVisible(Boolean.FALSE); + btnInativar.setVisible(Boolean.FALSE); + btnAtivar.setVisible(Boolean.FALSE); } - - // Tipo Pasajero - Categoria - PricingCategoria pc = new PricingCategoria(); - Categoria categoria = null; - - if (ApplicationProperties.getInstance().habilitarPricingCategoria()) { - pricingCategoriaList.setDisabled(Boolean.FALSE); - btnNovoCategoria.setDisabled(Boolean.FALSE); - btnApagarCategoria.setDisabled(Boolean.FALSE); - btnModificarCategoria.setDisabled(Boolean.FALSE); - - }else{ - categoria = categoriaService.obtenerID(1); - } - + } + + private void incluirCategoria(Categoria categoria) { if (categoria != null && verificarCategoriaNaoAdicionada(categoria)) { + PricingCategoria pc = new PricingCategoria(); pc.setCategoria(categoria); pc.setPricing(pricing); pc.setActivo(Pricing.ATIVO); @@ -699,12 +696,6 @@ public class EditarPricingController extends MyGenericForwardComposer { pricingCategoriaList.setData(lsPricingCategoria); pricingCategoriaService.suscribir(pc); } - - if (pricing.getPricingId() == null) { - btnApagar.setVisible(Boolean.FALSE); - btnInativar.setVisible(Boolean.FALSE); - btnAtivar.setVisible(Boolean.FALSE); - } } /** Valida se a categoria não foi adicionada */ @@ -720,6 +711,16 @@ public class EditarPricingController extends MyGenericForwardComposer { return true; } + @Override + protected void incluirCategoriaNormal(Categoria categoriaNormal) { + incluirCategoria(categoriaNormal); + } + + @Override + protected void incluirCategoriaPet(Categoria categoriaPET) { + incluirCategoria(categoriaPET); + } + public void onClick$radioImp(Event ev) { btnNovoImporte.setVisible(true); btnApagarImporte.setVisible(true); diff --git a/src/java/com/rjconsultores/ventaboletos/web/gui/controladores/pricing/EditarPricingEspecificoController.java b/src/java/com/rjconsultores/ventaboletos/web/gui/controladores/pricing/EditarPricingEspecificoController.java index 61306f145..751b7b716 100644 --- a/src/java/com/rjconsultores/ventaboletos/web/gui/controladores/pricing/EditarPricingEspecificoController.java +++ b/src/java/com/rjconsultores/ventaboletos/web/gui/controladores/pricing/EditarPricingEspecificoController.java @@ -43,7 +43,6 @@ import com.rjconsultores.ventaboletos.entidad.PricingEspecificoCategoria; import com.rjconsultores.ventaboletos.entidad.PricingEspecificoOcupacion; import com.rjconsultores.ventaboletos.entidad.PuntoVenta; import com.rjconsultores.ventaboletos.entidad.TipoPuntoVenta; -import com.rjconsultores.ventaboletos.service.CategoriaService; import com.rjconsultores.ventaboletos.service.ClaseServicioService; import com.rjconsultores.ventaboletos.service.CorridaCtrlService; import com.rjconsultores.ventaboletos.service.MarcaService; @@ -73,7 +72,7 @@ import com.rjconsultores.ventaboletos.web.utilerias.render.RenderPricingEspecifi @Controller("editarPricingEspecificoController") @Scope("prototype") @SuppressWarnings({ "unchecked", "rawtypes", "unused" }) -public class EditarPricingEspecificoController extends MyGenericForwardComposer { +public class EditarPricingEspecificoController extends PricingController { private static final long serialVersionUID = 1L; private static Logger log = Logger.getLogger(EditarPricingController.class); @@ -83,8 +82,6 @@ public class EditarPricingEspecificoController extends MyGenericForwardComposer @Autowired private TipoPuntoVentaService puntoVentaService; @Autowired - private CategoriaService categoriaService; - @Autowired private ClaseServicioService claseServicioService; @Autowired private MarcaService marcaService; @@ -141,7 +138,7 @@ public class EditarPricingEspecificoController extends MyGenericForwardComposer @Override public void doAfterCompose(Component comp) throws Exception { - lsCategoria = categoriaService.obtenerTodos(); + lsCategoria = getCategoriaService().obtenerTodos(); lsMarca = marcaService.buscarMarcaPorEmpresa(UsuarioLogado.getUsuarioLogado().getEmpresa()); lsMoneda = monedaService.obtenerTodos(); lsPtovata = puntoVentaService.obtenerTodos(); @@ -161,7 +158,7 @@ public class EditarPricingEspecificoController extends MyGenericForwardComposer if (pricingEspecifico.getPricingespecificoId() == null) { btnApagar.setVisible(Boolean.FALSE); - setTipoPassagemPadrao(); + incluirCategoriasPadroes(); } else { Parada origem = pricingEspecifico.getParada(); if (origem != null) { @@ -193,33 +190,6 @@ public class EditarPricingEspecificoController extends MyGenericForwardComposer fechaInicio.focus(); } - - private void setTipoPassagemPadrao() { - if (ApplicationProperties.getInstance().usaPadroPricingEspecificoTipoPassagemPET()) { - Categoria categoriaNormal = buscarCategoria("NORMAL"); - Categoria categoriaPET = buscarCategoria("PET"); - - if (categoriaNormal != null) { - PricingEspecificoCategoria pcNormal = new PricingEspecificoCategoria(categoriaNormal, pricingEspecifico, UsuarioLogado.getUsuarioLogado().getUsuarioId()); - pricingListEspCategoria.addItemNovo(pcNormal); - pricingEspecifico.getPricingEspecificoCategoriaList().add(pcNormal); - } - - if (categoriaPET != null) { - PricingEspecificoCategoria pcPET = new PricingEspecificoCategoria(categoriaPET, pricingEspecifico, UsuarioLogado.getUsuarioLogado().getUsuarioId()); - pricingListEspCategoria.addItemNovo(pcPET); - pricingEspecifico.getPricingEspecificoCategoriaList().add(pcPET); - } - } - } - - private Categoria buscarCategoria(String categoria) { - List categoriaList = categoriaService.buscar(categoria); - if(categoriaList.isEmpty()){ - return null; - } - return categoriaList.get(0); - } public void verPricingEspecificoOcupacion(PricingEspecificoOcupacion especificoOcupacion, Boolean isEdicao) { @@ -1082,21 +1052,6 @@ public class EditarPricingEspecificoController extends MyGenericForwardComposer this.puntoVentaService = puntoVentaService; } - /** - * @return the categoriaService - */ - public CategoriaService getCategoriaService() { - return categoriaService; - } - - /** - * @param categoriaService - * the categoriaService to set - */ - public void setCategoriaService(CategoriaService categoriaService) { - this.categoriaService = categoriaService; - } - /** * @return the claseServicioService */ @@ -1199,4 +1154,18 @@ public class EditarPricingEspecificoController extends MyGenericForwardComposer } + @Override + protected void incluirCategoriaNormal(Categoria categoriaNormal) { + PricingEspecificoCategoria pcNormal = new PricingEspecificoCategoria(categoriaNormal, pricingEspecifico, UsuarioLogado.getUsuarioLogado().getUsuarioId()); + pricingListEspCategoria.addItemNovo(pcNormal); + pricingEspecifico.getPricingEspecificoCategoriaList().add(pcNormal); + } + + @Override + protected void incluirCategoriaPet(Categoria categoriaPET) { + PricingEspecificoCategoria pcPET = new PricingEspecificoCategoria(categoriaPET, pricingEspecifico, UsuarioLogado.getUsuarioLogado().getUsuarioId()); + pricingListEspCategoria.addItemNovo(pcPET); + pricingEspecifico.getPricingEspecificoCategoriaList().add(pcPET); + } + } diff --git a/src/java/com/rjconsultores/ventaboletos/web/gui/controladores/pricing/PricingController.java b/src/java/com/rjconsultores/ventaboletos/web/gui/controladores/pricing/PricingController.java new file mode 100644 index 000000000..de969101b --- /dev/null +++ b/src/java/com/rjconsultores/ventaboletos/web/gui/controladores/pricing/PricingController.java @@ -0,0 +1,51 @@ +package com.rjconsultores.ventaboletos.web.gui.controladores.pricing; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.Scope; +import org.springframework.stereotype.Controller; + +import com.rjconsultores.ventaboletos.entidad.Categoria; +import com.rjconsultores.ventaboletos.service.CategoriaService; +import com.rjconsultores.ventaboletos.utilerias.ApplicationProperties; +import com.rjconsultores.ventaboletos.web.utilerias.MyGenericForwardComposer; + +@Controller("pricingController") +@Scope("prototype") +public abstract class PricingController extends MyGenericForwardComposer { + + private static final long serialVersionUID = -63691911293429900L; + + @Autowired + private CategoriaService categoriaService; + + protected void incluirCategoriasPadroes() { + if (ApplicationProperties.getInstance().usaPadraoPricingTipoPassagemPET()) { + Categoria categoriaNormal = getCategoriaNormal(); + Categoria categoriaPET = getCategoriaPET(); + + if (categoriaNormal != null) { + incluirCategoriaNormal(categoriaNormal); + } + + if (categoriaPET != null) { + incluirCategoriaPet(categoriaPET); + } + } + } + + protected Categoria getCategoriaPET() { + return getCategoriaService().buscarUmaCategoria("PET"); + } + + protected Categoria getCategoriaNormal() { + return getCategoriaService().buscarUmaCategoria("NORMAL"); + } + + protected abstract void incluirCategoriaNormal(Categoria categoriaNormal); + protected abstract void incluirCategoriaPet(Categoria categoriaPET); + + public CategoriaService getCategoriaService() { + return categoriaService; + } + +} diff --git a/src/java/com/rjconsultores/ventaboletos/web/utilerias/MensagensUtils.java b/src/java/com/rjconsultores/ventaboletos/web/utilerias/MensagensUtils.java index c6428aea7..34663a6d9 100644 --- a/src/java/com/rjconsultores/ventaboletos/web/utilerias/MensagensUtils.java +++ b/src/java/com/rjconsultores/ventaboletos/web/utilerias/MensagensUtils.java @@ -7,13 +7,25 @@ public class MensagensUtils { private MensagensUtils() { } - + public static void showMessageInformation(String labelMensagem, String tituloMenssagem) { + showMessage(labelMensagem, tituloMenssagem, Messagebox.INFORMATION); + } + + public static void showMessageExclamation(String labelMensagem, String tituloMenssagem) { + showMessage(labelMensagem, tituloMenssagem, Messagebox.EXCLAMATION); + } + + public static void showMessageError(String labelMensagem, String tituloMenssagem) { + showMessage(labelMensagem, tituloMenssagem, Messagebox.ERROR); + } + + private static void showMessage(String labelMensagem, String tituloMenssagem, String tipoMenssagem) { try { Messagebox.show( Labels.getLabel(labelMensagem), Labels.getLabel(tituloMenssagem), - Messagebox.OK, Messagebox.INFORMATION); + Messagebox.OK, tipoMenssagem); } catch (InterruptedException e) { Thread.currentThread().interrupt(); }