package com.rjconsultores.ventaboletos.web.gui.controladores.gestaopricing;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.commons.lang.BooleanUtils;
import org.apache.logging.log4j.Level;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
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.WrongValueException;
import org.zkoss.zk.ui.event.CheckEvent;
import org.zkoss.zk.ui.event.Event;
import org.zkoss.zk.ui.event.EventListener;
import org.zkoss.zk.ui.event.ForwardEvent;
import org.zkoss.zul.Button;
import org.zkoss.zul.Checkbox;
import org.zkoss.zul.Combobox;
import org.zkoss.zul.Comboitem;
import org.zkoss.zul.Intbox;
import org.zkoss.zul.Radio;
import org.zkoss.zul.Tab;
import org.zkoss.zul.Tabbox;
import org.zkoss.zul.Tabpanel;
import org.zkoss.zul.Textbox;
import org.zkoss.zul.Window;

import com.rjconsultores.ventaboletos.entidad.Categoria;
import com.rjconsultores.ventaboletos.entidad.ClaseServicio;
import com.rjconsultores.ventaboletos.entidad.Empresa;
import com.rjconsultores.ventaboletos.entidad.EsquemaCorrida;
import com.rjconsultores.ventaboletos.entidad.GP_Pricing;
import com.rjconsultores.ventaboletos.entidad.GP_PricingAsiento;
import com.rjconsultores.ventaboletos.entidad.GP_PricingCategoria;
import com.rjconsultores.ventaboletos.entidad.GP_PricingClase;
import com.rjconsultores.ventaboletos.entidad.GP_PricingCorrida;
import com.rjconsultores.ventaboletos.entidad.GP_PricingDia;
import com.rjconsultores.ventaboletos.entidad.GP_PricingFormapago;
import com.rjconsultores.ventaboletos.entidad.GP_PricingImporte;
import com.rjconsultores.ventaboletos.entidad.GP_PricingMarca;
import com.rjconsultores.ventaboletos.entidad.GP_PricingMercado;
import com.rjconsultores.ventaboletos.entidad.GP_PricingOcupaAntecipa;
import com.rjconsultores.ventaboletos.entidad.GP_PricingPuntoVenta;
import com.rjconsultores.ventaboletos.entidad.GP_PricingRuta;
import com.rjconsultores.ventaboletos.entidad.GP_PricingTipoPtoVta;
import com.rjconsultores.ventaboletos.entidad.GP_PricingTipoServicio;
import com.rjconsultores.ventaboletos.entidad.GP_PricingVigencia;
import com.rjconsultores.ventaboletos.entidad.Marca;
import com.rjconsultores.ventaboletos.entidad.Parada;
import com.rjconsultores.ventaboletos.entidad.PuntoVenta;
import com.rjconsultores.ventaboletos.entidad.Ruta;
import com.rjconsultores.ventaboletos.entidad.TipoPuntoVenta;
import com.rjconsultores.ventaboletos.service.CategoriaService;
import com.rjconsultores.ventaboletos.service.ClaseServicioService;
import com.rjconsultores.ventaboletos.service.GP_PricingAsientoService;
import com.rjconsultores.ventaboletos.service.GP_PricingCategoriaService;
import com.rjconsultores.ventaboletos.service.GP_PricingClaseService;
import com.rjconsultores.ventaboletos.service.GP_PricingCorridaService;
import com.rjconsultores.ventaboletos.service.GP_PricingDiaService;
import com.rjconsultores.ventaboletos.service.GP_PricingFormapagoService;
import com.rjconsultores.ventaboletos.service.GP_PricingHistoricoService;
import com.rjconsultores.ventaboletos.service.GP_PricingImporteService;
import com.rjconsultores.ventaboletos.service.GP_PricingMarcaService;
import com.rjconsultores.ventaboletos.service.GP_PricingMercadoService;
import com.rjconsultores.ventaboletos.service.GP_PricingOcupaAntecipaService;
import com.rjconsultores.ventaboletos.service.GP_PricingPuntoVentaService;
import com.rjconsultores.ventaboletos.service.GP_PricingRevisaoValoresService;
import com.rjconsultores.ventaboletos.service.GP_PricingRutaService;
import com.rjconsultores.ventaboletos.service.GP_PricingService;
import com.rjconsultores.ventaboletos.service.GP_PricingTipoPtoVtaService;
import com.rjconsultores.ventaboletos.service.GP_PricingTipoServicioService;
import com.rjconsultores.ventaboletos.service.GP_PricingVigenciaService;
import com.rjconsultores.ventaboletos.service.MarcaService;
import com.rjconsultores.ventaboletos.service.ParadaService;
import com.rjconsultores.ventaboletos.service.PuntoVentaService;
import com.rjconsultores.ventaboletos.service.RutaService;
import com.rjconsultores.ventaboletos.service.TipoPuntoVentaService;
import com.rjconsultores.ventaboletos.utilerias.ApplicationProperties;
import com.rjconsultores.ventaboletos.utilerias.CustomEnum;
import com.rjconsultores.ventaboletos.utilerias.UsuarioLogado;
import com.rjconsultores.ventaboletos.vo.pricing.GP_PricingOcupaAntecipaLegendaVO;
import com.rjconsultores.ventaboletos.vo.pricing.GP_PricingOcupaAntecipaPoltronasVO;
import com.rjconsultores.ventaboletos.vo.pricing.GP_PricingOcupaAntecipaVO;
import com.rjconsultores.ventaboletos.vo.pricing.GP_PricingRevisaoValoresVO;
import com.rjconsultores.ventaboletos.web.gui.controladores.pricing.PricingController;
import com.rjconsultores.ventaboletos.web.utilerias.MyListbox;
import com.rjconsultores.ventaboletos.web.utilerias.MyTextboxDecimal;
import com.rjconsultores.ventaboletos.web.utilerias.render.RenderPricingAsiento;
import com.rjconsultores.ventaboletos.web.utilerias.render.RenderPricingCategoria;
import com.rjconsultores.ventaboletos.web.utilerias.render.RenderPricingClase;
import com.rjconsultores.ventaboletos.web.utilerias.render.RenderPricingCorrida;
import com.rjconsultores.ventaboletos.web.utilerias.render.RenderPricingDia;
import com.rjconsultores.ventaboletos.web.utilerias.render.RenderPricingFormaPago;
import com.rjconsultores.ventaboletos.web.utilerias.render.RenderPricingImporte;
import com.rjconsultores.ventaboletos.web.utilerias.render.RenderPricingMarca;
import com.rjconsultores.ventaboletos.web.utilerias.render.RenderPricingMercado;
import com.rjconsultores.ventaboletos.web.utilerias.render.RenderPricingOcupaAntecipaLegenda;
import com.rjconsultores.ventaboletos.web.utilerias.render.RenderPricingOcupacao;
import com.rjconsultores.ventaboletos.web.utilerias.render.RenderPricingPuntoVenta;
import com.rjconsultores.ventaboletos.web.utilerias.render.RenderPricingRevisaoValores;
import com.rjconsultores.ventaboletos.web.utilerias.render.RenderPricingRuta;
import com.rjconsultores.ventaboletos.web.utilerias.render.RenderPricingTipoPtoVta;
import com.rjconsultores.ventaboletos.web.utilerias.render.RenderPricingTipoServicio;
import com.rjconsultores.ventaboletos.web.utilerias.render.RenderPricingVigencia;

import ch.stfo.zk.component.Colorbox;

@Controller("editarGP_PricingController")
@Scope("prototype")
@SuppressWarnings("unused")
public class EditarGP_PricingController extends PricingController {

	private static final long serialVersionUID = 1L;
	private static Logger log = LogManager.getLogger(EditarGP_PricingController.class);
	@Autowired
	private GP_PricingService pricingService;
	@Autowired
	private GP_PricingMarcaService pricingMarcaService;
	@Autowired
	private GP_PricingClaseService pricingClaseService;
	@Autowired
	private GP_PricingCorridaService pricingCorridaService;
	@Autowired
	private GP_PricingDiaService pricingDiaService;
	@Autowired
	private GP_PricingPuntoVentaService pricingPuntoVentaService;
	@Autowired
	private GP_PricingTipoPtoVtaService pricingTipoPtoVtaService;
	@Autowired
	private GP_PricingTipoServicioService pricingTipoServicioService;
	@Autowired
	private GP_PricingVigenciaService pricingVigenciaService;
	@Autowired
	private GP_PricingRutaService pricingRutaService;
	@Autowired
	private GP_PricingCategoriaService pricingCategoriaService;
	@Autowired
	private GP_PricingMercadoService pricingMercadoService;
	@Autowired
	private GP_PricingImporteService pricingImporteService;
	@Autowired
	private GP_PricingFormapagoService pricingFormapagoService;
	@Autowired
	private GP_PricingOcupaAntecipaService pricingOcupaAntecipaService;
	@Autowired
	private GP_PricingRevisaoValoresService pricingRevisaoValoresService;
	@Autowired
	private MarcaService marcaService;
	@Autowired
	private ClaseServicioService claseServicioService;
	@Autowired
	private PuntoVentaService puntoVentaService;
	@Autowired
	private TipoPuntoVentaService tipoPuntoVentaService;
	@Autowired
	private RutaService rutaService;
	@Autowired
	private CategoriaService categoriaService;
	@Autowired
	private ParadaService paradaService;
	@Autowired
	private GP_PricingAsientoService pricingAsientoService;
	
	@Autowired
	private GP_PricingHistoricoService pricingHistoricoService;

	private GP_Pricing pricing;
	private GP_Pricing pricingOriginal;
	private MyListbox pricingList;
	private MyListbox pricingVigenciaList;
	private MyListbox pricingImporteList;
	private MyListbox pricingMarcaList;
	private MyListbox pricingClaseList;
	private MyListbox pricingPuntoVentaList;
	private MyListbox pricingTipoPtoVtaList;
	private MyListbox pricingRutaList;
	private MyListbox pricingMercadoList;
	private MyListbox pricingCategoriaList;
	private MyListbox pricingDiaList;
	private MyListbox pricingCorridaList;
	private MyListbox pricingAsientoList;
	private MyListbox pricingTipoServicioList;
	private MyListbox pricingFormapagoList;
	private MyListbox pricingRevisaoValores;
	private List<Empresa> lsEmpresa;
	private List<GP_PricingVigencia> lsPricingVigencia;
	private List<GP_PricingImporte> lsPricingImporte;
	private List<GP_PricingClase> lsPricingClase;
	private List<GP_PricingTipoPtoVta> lsPricingTipoPtoVta;
	private List<GP_PricingPuntoVenta> lsPricingPuntoVenta;
	private List<GP_PricingMarca> lsPricingMarca;
	private List<GP_PricingMercado> lsPricingMercado;
	private List<GP_PricingDia> lsPricingDia;
	private List<GP_PricingCorrida> lsPricingCorrida;
	private List<GP_PricingCategoria> lsPricingCategoria;
	private List<GP_PricingAsiento> lsPricingAsiento;
	private List<GP_PricingOcupaAntecipa> lsPricingOcupaAntecipa;
	private List<GP_PricingRuta> lsPricingRuta;
	private List<GP_PricingTipoServicio> lsPricingTipoServicio;
	private List<GP_PricingFormapago> lsPricingFormapago;
	private Combobox cmbEmpresa;
	private Radio rdTransSi;
	private Radio rdTransNo;
	private Radio rdExibirVendaSi;
	private Radio rdExibirVendaNo;
	private Radio rdCanceSi;
	private Radio rdCanceNo;
	private Radio rdReserSi;
	private Radio rdReserNo;
	private Radio radioImp;
	private Radio radioPor;
	private MyTextboxDecimal descuentoporcredondo;
	private MyTextboxDecimal descuentoporcsen;
	private Button btnSalvar;
	private Button btnCopiar;
	private Button btnNovoImporte;
	private Button btnApagarImporte;
	private Button btnModificarImporte;
	private Button btnApagar;
	private Button btnInativar;
	private Button btnAtivar;
	private Button btnNovoVigencia;
	private Button btnApagarVigencia;
	private Button btnModificarVigencia;
	private Button btnNovoMarca;
	private Button btnApagarMarca;
	private Button btnModificarMarca;
	private Button btnNovoClase;
	private Button btnApagarClase;
	private Button btnModificarClase;
	private Button btnNovoPuntoVenta;
	private Button btnApagarPuntoVenta;
	private Button btnModificarPuntoVenta;
	private Button btnNovoRuta;
	private Button btnApagarRuta;
	private Button btnModificarRuta;
	private Button btnNovoTipoPtoVta;
	private Button btnApagarTipoPtoVta;
	private Button btnModificarTipoPtoVta;
	private Button btnNovoMercado;
	private Button btnApagarMercado;
	private Button btnModificarMercado;
	private Button btnNovoDia;
	private Button btnApagarDia;
	private Button btnNovoCorrida;
	private Button btnApagarCorrida;
	private Button btnNovoAsiento;
	private Button btnApagarAsiento;
	private Button btnModificarAsiento;
	private Button btnNovoOcupaAntecipa;
	private Button btnApagarOcupaAntecipa;
	private Button btnModificarOcupaAntecipa;
	private Button btnNovoTipoServicio;
	private Button btnApagarTipoServicio;
	private Button btnModificarTipoServicio;
	private Button btnNovoFormaPago;
	private Button btnApagarFormaPago;
	private Button btnNovoCategoria;
	private Button btnApagarCategoria;
	private Button btnModificarCategoria;
	private Button btnModificarFormaPago;
	private boolean salvo = false;
	private Boolean gravarNovo = Boolean.TRUE;
	private Textbox nombrePricing;
	private Intbox itxCantboleto;
	private Intbox cantdiasanticipacion;
	private Combobox cmbIndGeneraFeriadoFechaVenta;
	private Combobox cmbIndGeneraFeriadoFechaViaje;
	private Integer buscarPricingInativosAtivos;
	private Colorbox colorChoose;
	private MyListbox pricingOcupaAntecipaList;
	private MyListbox pricingOcupaAntecipaLegendaList;
	private Tabbox tb;
	private Tabpanel tabPanelOcupaAntecipa;
	private Window winEditarGP_Pricing;
	private Tab tabOcupaAntecipa;
	private Checkbox chkAgruparDia;
	private Checkbox chkAgruparServico;
	
	private List<String> columns;
	private List<GP_PricingOcupaAntecipaVO> lsPricingOcupacaoAntecipas;
	private List<GP_PricingOcupaAntecipaLegendaVO> lsPricingOcupaAntecipaLegendas;
	private List<GP_PricingRevisaoValoresVO> lsPricingRevisaoValores;
	
	private Intbox cantdiasEstadiaminima;
	private Radio rdEstadiaMinimaSi;
	private Radio rdEstadiaMinimaNo;
	private Checkbox chkIndLunEstadiaminima;
	private Checkbox chkIndMarEstadiaminima;
	private Checkbox chkIndMieEstadiaminima;
	private Checkbox chkIndJueEstadiaminima;
	private Checkbox chkIndVieEstadiaminima;
	private Checkbox chkIndSabEstadiaminima;
	private Checkbox chkIndDomEstadiaminima;
	
	private void clearCombobox(Combobox combobox) {
		int size = combobox.getItemCount();

		for (int i = size - 1; i >= 0; i--) {
			combobox.removeItemAt(i);
		}
	}

	private void popularCombobox(Combobox cmb) throws Exception {
		clearCombobox(cmb);
		for (EsquemaCorrida.GerarFeriado p : EsquemaCorrida.GerarFeriado.values()) {
			Comboitem comboItem = new Comboitem(p.descricao());
			comboItem.setValue(p.valor());
			comboItem.setParent(cmb);
		}

		cmb.setSelectedIndex(0);
	}

	@Override
	public void doAfterCompose(Component comp) throws Exception {
		lsEmpresa = UsuarioLogado.getUsuarioLogado().getEmpresa();

		pricing = (GP_Pricing) Executions.getCurrent().getArg().get("pricing");
		pricingList = (MyListbox) Executions.getCurrent().getArg().get("pricingList");
		buscarPricingInativosAtivos = (Integer) Executions.getCurrent().getArg().get("buscarPricingInativosAtivos");
		gravarNovo = (Boolean) Executions.getCurrent().getArg().get("gravarNovo");
		Boolean isSelecionarTabOcupaAntecipa = (Boolean) Executions.getCurrent().getArg().get("isSelecionarTabOcupaAntecipa");

		super.doAfterCompose(comp);
		
		if(BooleanUtils.toBoolean(isSelecionarTabOcupaAntecipa)) {
			winEditarGP_Pricing.focus();
			tb.setSelectedPanel(tabPanelOcupaAntecipa);
		}
				
		pricingCategoriaList.setDisabled(Boolean.TRUE);
		btnNovoCategoria.setDisabled(Boolean.TRUE);
		btnApagarCategoria.setDisabled(Boolean.TRUE);
		btnModificarCategoria.setDisabled(Boolean.TRUE);

		popularCombobox(cmbIndGeneraFeriadoFechaVenta);
		popularCombobox(cmbIndGeneraFeriadoFechaViaje);
		
		carregarTabOcupaAntecipa();
		
		if (pricing.getIndAgrupadoDia() != null && pricing.getIndAgrupadoDia()) {
			chkAgruparDia.setChecked(Boolean.TRUE);
		} else {
			chkAgruparDia.setChecked(Boolean.FALSE);
		}

		if (pricing.getIndAgrupadoServico() != null && pricing.getIndAgrupadoServico()) {
			chkAgruparServico.setChecked(Boolean.TRUE);
		} else {
			chkAgruparServico.setChecked(Boolean.FALSE);
		}
		
		if (pricing.getColor() != null) {
			colorChoose.setStyle(" background: #FFFFFF; font-style: oblique;");
			colorChoose.setValue(pricing.getColor());
		}


		if (pricing.getIndGeneraFeriadoVenta() != null) {
			if (pricing.getIndGeneraFeriadoVenta().equals("S")) {
				cmbIndGeneraFeriadoFechaVenta.setSelectedIndex(0);
			} else if (pricing.getIndGeneraFeriadoVenta().equals("F")) {
				cmbIndGeneraFeriadoFechaVenta.setSelectedIndex(1);
			} else if (pricing.getIndGeneraFeriadoVenta().equals("N")) {
				cmbIndGeneraFeriadoFechaVenta.setSelectedIndex(2);
			}
		}

		if (pricing.getIndGeneraFeriadoViaje() != null) {
			if (pricing.getIndGeneraFeriadoViaje().equals("S")) {
				cmbIndGeneraFeriadoFechaViaje.setSelectedIndex(0);
			} else if (pricing.getIndGeneraFeriadoViaje().equals("F")) {
				cmbIndGeneraFeriadoFechaViaje.setSelectedIndex(1);
			} else if (pricing.getIndGeneraFeriadoViaje().equals("N")) {
				cmbIndGeneraFeriadoFechaViaje.setSelectedIndex(2);
			}
		}

		// Vigencia
		pricingVigenciaList.setItemRenderer(new RenderPricingVigencia());
		lsPricingVigencia = new ArrayList<GP_PricingVigencia>();
		pricingVigenciaList.setData(lsPricingVigencia);

		// Importe
		pricingImporteList.setItemRenderer(new RenderPricingImporte());
		lsPricingImporte = new ArrayList<GP_PricingImporte>();
		pricingImporteList.setData(lsPricingImporte);

		// Marca
		pricingMarcaList.setItemRenderer(new RenderPricingMarca());
		lsPricingMarca = new ArrayList<GP_PricingMarca>();
		pricingMarcaList.addEventListener("onDoubleClick", new EventListener() {

			@Override
			public void onEvent(Event event) throws Exception {
				GP_PricingMarca pMarca = (GP_PricingMarca) pricingMarcaList.getSelected();
				verPricingMarca(pMarca);
			}
		});

		// Clase
		pricingClaseList.setItemRenderer(new RenderPricingClase());
		lsPricingClase = new ArrayList<GP_PricingClase>();
		pricingClaseList.addEventListener("onDoubleClick", new EventListener() {

			@Override
			public void onEvent(Event event) throws Exception {
				GP_PricingClase pClase = (GP_PricingClase) pricingClaseList.getSelected();
				verPricingClase(pClase);
			}
		});

		// Punto Venta
		pricingPuntoVentaList.setItemRenderer(new RenderPricingPuntoVenta());
		lsPricingPuntoVenta = new ArrayList<GP_PricingPuntoVenta>();
		pricingPuntoVentaList.addEventListener("onDoubleClick", new EventListener() {

			@Override
			public void onEvent(Event event) throws Exception {
				GP_PricingPuntoVenta pPuntoVenta = (GP_PricingPuntoVenta) pricingPuntoVentaList.getSelected();
				verPricingPuntoVenta(pPuntoVenta);
			}
		});

		// Canal Venta
		pricingTipoPtoVtaList.setItemRenderer(new RenderPricingTipoPtoVta());
		lsPricingTipoPtoVta = new ArrayList<GP_PricingTipoPtoVta>();
		pricingTipoPtoVtaList.addEventListener("onDoubleClick", new EventListener() {

			@Override
			public void onEvent(Event event) throws Exception {
				GP_PricingTipoPtoVta pTipoPtoVta = (GP_PricingTipoPtoVta) pricingTipoPtoVtaList.getSelected();
				verPricingTipoPtoVta(pTipoPtoVta);
			}
		});

		// Rutas
		pricingRutaList.setItemRenderer(new RenderPricingRuta());
		lsPricingRuta = new ArrayList<GP_PricingRuta>();
		pricingRutaList.addEventListener("onDoubleClick", new EventListener() {

			@Override
			public void onEvent(Event event) throws Exception {
				GP_PricingRuta pRuta = (GP_PricingRuta) pricingRutaList.getSelected();
				verPricingRuta(pRuta);
			}
		});

		// Categoria
		pricingCategoriaList.setItemRenderer(new RenderPricingCategoria());
		lsPricingCategoria = new ArrayList<GP_PricingCategoria>();

		// Mercado
		pricingMercadoList.setItemRenderer(new RenderPricingMercado());
		lsPricingMercado = new ArrayList<GP_PricingMercado>();
		pricingMercadoList.addEventListener("onDoubleClick", new EventListener() {

			@Override
			public void onEvent(Event event) throws Exception {
				GP_PricingMercado pMercado = (GP_PricingMercado) pricingMercadoList.getSelected();
				verPricingMercado(pMercado);
			}
		});

		// Dia
		pricingDiaList.setItemRenderer(new RenderPricingDia());
		lsPricingDia = new ArrayList<GP_PricingDia>();
		pricingDiaList.addEventListener("onDoubleClick", new EventListener() {

			@Override
			public void onEvent(Event event) throws Exception {
				GP_PricingDia pDia = (GP_PricingDia) pricingDiaList.getSelected();
				verPricingDia(pDia);
			}
		});

		// Corrida
		pricingCorridaList.setItemRenderer(new RenderPricingCorrida());
		lsPricingCorrida = new ArrayList<GP_PricingCorrida>();

		// Asiento
		pricingAsientoList.setItemRenderer(new RenderPricingAsiento());
		lsPricingAsiento = new ArrayList<GP_PricingAsiento>();
		pricingAsientoList.addEventListener("onDoubleClick", new EventListener() {

			@Override
			public void onEvent(Event event) throws Exception {
				GP_PricingAsiento pAsiento = (GP_PricingAsiento) pricingAsientoList.getSelected();
				verPricingAsiento(pAsiento);
			}
		});

		// TipoServicio
		pricingTipoServicioList.setItemRenderer(new RenderPricingTipoServicio());
		lsPricingTipoServicio = new ArrayList<GP_PricingTipoServicio>();
		pricingTipoServicioList.addEventListener("onDoubleClick", new EventListener() {

			@Override
			public void onEvent(Event event) throws Exception {
				GP_PricingTipoServicio pTipoServicio = (GP_PricingTipoServicio) pricingTipoServicioList.getSelected();
				verPricingTipoServicio(pTipoServicio);
			}
		});

		// FormaPago
		pricingFormapagoList.setItemRenderer(new RenderPricingFormaPago());
		lsPricingFormapago = new ArrayList<GP_PricingFormapago>();
		pricingFormapagoList.addEventListener("onDoubleClick", new EventListener() {

			@Override
			public void onEvent(Event event) throws Exception {
				GP_PricingFormapago pFormapago = (GP_PricingFormapago) pricingFormapagoList.getSelected();
				verPricingFormapago(pFormapago);
			}
		});
		
		// Tipo Pasajero - Categoria
		if (ApplicationProperties.getInstance().isCustomHabilitado(CustomEnum.HABILITAR_PRICING_CATEGORIA.getDescricao())) {
			pricingCategoriaList.setDisabled(Boolean.FALSE);
			btnNovoCategoria.setDisabled(Boolean.FALSE);
			btnApagarCategoria.setDisabled(Boolean.FALSE);
			btnModificarCategoria.setDisabled(Boolean.FALSE);
		} 
		
		if (pricing.getPricingId() != null) {
			pricing = pricingService.obtenerID(pricing.getPricingId());

			lsPricingVigencia = pricing.getPricingVigenciaList();
			pricingVigenciaList.setData(lsPricingVigencia);
			if (lsPricingVigencia.size() > 0) {
				pricingVigenciaList.setSelectedIndex(0);
			}

			lsPricingImporte = pricing.getPricingImporteList();
			pricingImporteList.setData(lsPricingImporte);
			if (lsPricingImporte.size() > 0) {
				pricingImporteList.setSelectedIndex(0);
			}

			lsPricingMarca = pricing.getPricingMarcaList();
			pricingMarcaList.setData(lsPricingMarca);
			if (lsPricingMarca.size() > 0) {
				pricingMarcaList.setSelectedIndex(0);
			}

			lsPricingClase = pricing.getPricingClaseList();
			pricingClaseList.setData(lsPricingClase);
			if (lsPricingClase.size() > 0) {
				pricingClaseList.setSelectedIndex(0);
			}

			lsPricingTipoServicio = pricing.getPricingTipoServicioList();
			pricingTipoServicioList.setData(lsPricingTipoServicio);
			if (lsPricingTipoServicio.size() > 0) {
				pricingTipoServicioList.setSelectedIndex(0);
			}

			lsPricingFormapago = pricing.getPricingFormapagoList();
			pricingFormapagoList.setData(lsPricingFormapago);
			if (lsPricingFormapago.size() > 0) {
				pricingFormapagoList.setSelectedIndex(0);
			}

			lsPricingPuntoVenta = pricing.getPricingPuntoventaList();
			pricingPuntoVentaList.setData(lsPricingPuntoVenta);
			if (lsPricingPuntoVenta.size() > 0) {
				pricingPuntoVentaList.setSelectedIndex(0);
			}

			lsPricingCategoria = pricing.getPricingCategoriaList();
			pricingCategoriaList.setData(lsPricingCategoria);
			if (lsPricingCategoria.size() > 0) {
				pricingCategoriaList.setSelectedIndex(0);
			}

			lsPricingRuta = pricing.getPricingRutaList();
			pricingRutaList.setData(lsPricingRuta);
			if (lsPricingRuta.size() > 0) {
				pricingRutaList.setSelectedIndex(0);
			}

			lsPricingMercado = pricing.getPricingMercadoList();
			pricingMercadoList.setData(lsPricingMercado);

			lsPricingTipoPtoVta = pricing.getPricingTipoptovtaList();
			pricingTipoPtoVtaList.setData(lsPricingTipoPtoVta);
			if (lsPricingTipoPtoVta.size() > 0) {
				pricingTipoPtoVtaList.setSelectedIndex(0);
			}

			lsPricingCorrida = pricing.getPricingCorridaList();
			pricingCorridaList.setData(lsPricingCorrida);

			lsPricingDia = pricing.getPricingDiaList();
			pricingDiaList.setData(lsPricingDia);

			lsPricingAsiento = pricing.getPricingAsientoList();
			pricingAsientoList.setData(lsPricingAsiento);

			lsPricingTipoServicio = pricing.getPricingTipoServicioList();
			pricingTipoServicioList.setData(lsPricingTipoServicio);

			lsPricingFormapago = pricing.getPricingFormapagoList();
			pricingFormapagoList.setData(lsPricingFormapago);

			if (pricing.getIndtransferible() == Boolean.FALSE) {
				rdTransNo.setChecked(true);
			}
			if (pricing.getIndcancelable() == Boolean.FALSE) {
				rdCanceNo.setChecked(true);
			}
			if (pricing.getIndreservable() == Boolean.FALSE) {
				rdReserNo.setChecked(true);
			}
			if (pricing.getDescuentoporcentaje() != null) {
				radioPor.setChecked(true);
			}
			if (!lsPricingImporte.isEmpty()) {
				radioImp.setChecked(true);
				onClick$radioImp(null);
			} else {

				btnNovoImporte.setVisible(false);
				btnApagarImporte.setVisible(false);
				btnModificarImporte.setVisible(false);
			}

			// BUG-1202 não permitir alterar a empresa.
			cmbEmpresa.setDisabled(true);
			
			rdEstadiaMinimaSi.setChecked(pricing.getIndestadiaminima() != null ? pricing.getIndestadiaminima() : false);
			rdEstadiaMinimaNo.setChecked(!rdEstadiaMinimaSi.isChecked());
			
			chkIndLunEstadiaminima.setChecked(pricing.getIndLunEstadiaminima() != null ? pricing.getIndLunEstadiaminima() : false);
			chkIndMarEstadiaminima.setChecked(pricing.getIndMarEstadiaminima() != null ? pricing.getIndMarEstadiaminima() : false);
			chkIndMieEstadiaminima.setChecked(pricing.getIndMieEstadiaminima() != null ? pricing.getIndMieEstadiaminima() : false);
			chkIndJueEstadiaminima.setChecked(pricing.getIndJueEstadiaminima() != null ? pricing.getIndJueEstadiaminima() : false);
			chkIndVieEstadiaminima.setChecked(pricing.getIndVieEstadiaminima() != null ? pricing.getIndVieEstadiaminima() : false);
			chkIndSabEstadiaminima.setChecked(pricing.getIndSabEstadiaminima() != null ? pricing.getIndSabEstadiaminima() : false);
			chkIndDomEstadiaminima.setChecked(pricing.getIndDomEstadiaminima() != null ? pricing.getIndDomEstadiaminima() : false);

			salvo = true;
			
			ativarDesativarCamposEstadiaMinima(pricing.getDescuentoporcredondo() == null);
			
			pricingOriginal = pricing.clonar();
			
		} else {

			btnNovoImporte.setVisible(false);
			btnApagarImporte.setVisible(false);
			btnModificarImporte.setVisible(false);
			descuentoporcredondo.setDisabled(false);

			pricingService.suscribir(pricing);
			// Marca - Preenchendo com o Objeto TODOS caso exista.
			Short id = -1;
			GP_PricingMarca pm = new GP_PricingMarca();
			Marca m = marcaService.obtenerID(id);
			if (m != null) {
				pm.setMarca(m);
				pm.setPricing(pricing);
				pm.setActivo(GP_Pricing.ATIVO);
				pm.setUsuarioId(UsuarioLogado.getUsuarioLogado().getUsuarioId());
				pm.setFecmodif(Calendar.getInstance().getTime());
				lsPricingMarca.add(pm);
				pricingMarcaList.setData(lsPricingMarca);
				pricingMarcaService.suscribir(pm);
			}

			// Tipo de Servicio
			GP_PricingClase pts = new GP_PricingClase();
			ClaseServicio cs = claseServicioService.obtenerID((int)id);
			if (cs != null) {
				pts.setClaseServicio(cs);
				pts.setPricing(pricing);
				pts.setActivo(GP_Pricing.ATIVO);
				pts.setUsuarioId(UsuarioLogado.getUsuarioLogado().getUsuarioId());
				pts.setFecmodif(Calendar.getInstance().getTime());
				lsPricingClase.add(pts);
				pricingClaseList.setData(lsPricingClase);
				pricingClaseService.suscribir(pts);
			}

			// Punto de Venta
			GP_PricingPuntoVenta ppv = new GP_PricingPuntoVenta();
			PuntoVenta pv = puntoVentaService.obtenerID(-1);
			if (pv != null) {
				ppv.setPuntoVenta(pv);
				ppv.setPricing(pricing);
				ppv.setActivo(GP_Pricing.ATIVO);
				ppv.setUsuarioId(UsuarioLogado.getUsuarioLogado().getUsuarioId());
				ppv.setFecmodif(Calendar.getInstance().getTime());
				lsPricingPuntoVenta.add(ppv);
				pricingPuntoVentaList.setData(lsPricingPuntoVenta);
				pricingPuntoVentaService.suscribir(ppv);
			}
			// Punto de Venta
			GP_PricingTipoPtoVta ptpv = new GP_PricingTipoPtoVta();
			TipoPuntoVenta tpv = tipoPuntoVentaService.obtenerID((short) -1);
			if (tpv != null) {
				ptpv.setTipoPtovta(tpv);
				ptpv.setPricing(pricing);
				ptpv.setActivo(GP_Pricing.ATIVO);
				ptpv.setUsuarioId(UsuarioLogado.getUsuarioLogado().getUsuarioId());
				ptpv.setFecmodif(Calendar.getInstance().getTime());
				lsPricingTipoPtoVta.add(ptpv);
				pricingTipoPtoVtaList.setData(lsPricingTipoPtoVta);
				pricingTipoPtoVtaService.suscribir(ptpv);
			}

			// Ruta
			GP_PricingRuta pr = new GP_PricingRuta();
			Ruta r = rutaService.obtenerID(-1);
			if (r != null) {
				pr.setRuta(r);
				pr.setPricing(pricing);
				pr.setActivo(GP_Pricing.ATIVO);
				pr.setUsuarioId(UsuarioLogado.getUsuarioLogado().getUsuarioId());
				pr.setFecmodif(Calendar.getInstance().getTime());
				lsPricingRuta.add(pr);
				pricingRutaList.setData(lsPricingRuta);
				pricingRutaService.suscribir(pr);
			}

			// Mercado
			GP_PricingMercado pme = new GP_PricingMercado();
			Parada p1 = paradaService.obtenerID(-1);
			if (p1 != null) {
				pme.setActivo(GP_Pricing.ATIVO);
				pme.setPricing(pricing);
				pme.setUsuarioId(UsuarioLogado.getUsuarioLogado().getUsuarioId());
				pme.setFecmodif(Calendar.getInstance().getTime());
				pme.setOrigen(p1);
				pme.setDestino(p1);

				lsPricingMercado.add(pme);
				pricingMercadoList.setData(lsPricingMercado);
				pricingMercadoService.suscribir(pme);
			}
			
			incluirCategoria(categoriaService.obtenerID(1));

			incluirCategoriasPadroes();

			btnApagar.setVisible(Boolean.FALSE);
			btnInativar.setVisible(Boolean.FALSE);
			btnAtivar.setVisible(Boolean.FALSE);
		}
	}

	private void carregarTabOcupaAntecipa() {
		lsPricingOcupaAntecipa = pricingOcupaAntecipaService.carregarPricingOcupaAntecipa(pricing.getPricingId());
		lsPricingOcupacaoAntecipas = pricingOcupaAntecipaService.carregarPricingOcupaAntecipaVO(pricing.getPricingId());
		
		pricingOcupaAntecipaList.setItemRenderer(new RenderPricingOcupacao());
		pricingOcupaAntecipaList.setData(lsPricingOcupacaoAntecipas);
		pricingOcupaAntecipaList.addEventListener("onDoubleClick", new EventListener() {
			@Override
			public void onEvent(Event event) throws Exception {
				if(event instanceof ForwardEvent) {
					ForwardEvent forwardEvent = (ForwardEvent) event;
					String vet[] = forwardEvent.getOrigin().getTarget().getId().split("-");
					Integer pricingocupaantecipaId = Integer.valueOf(vet[0]);
					verPricingOcupaAntecipa(pricingocupaantecipaId);
				}
			}
		});
		
		lsPricingOcupaAntecipaLegendas = pricingOcupaAntecipaService.carregarPricingOcupaAntecipaLegenda(pricing.getPricingId());
		pricingOcupaAntecipaLegendaList.setItemRenderer(new RenderPricingOcupaAntecipaLegenda());
		pricingOcupaAntecipaLegendaList.setData(lsPricingOcupaAntecipaLegendas);
	}

	private void incluirCategoria(Categoria categoria) {
		if (categoria != null && verificarCategoriaNaoAdicionada(categoria)) {
			GP_PricingCategoria pc = new GP_PricingCategoria();
			pc.setCategoria(categoria);
			pc.setPricing(pricing);
			pc.setActivo(GP_Pricing.ATIVO);
			pc.setUsuarioId(UsuarioLogado.getUsuarioLogado().getUsuarioId());
			pc.setFecmodif(Calendar.getInstance().getTime());
			
			if(lsPricingCategoria == null) {
				lsPricingCategoria = new ArrayList<GP_PricingCategoria>();
			}
			lsPricingCategoria.add(pc);
			pricingCategoriaList.setData(lsPricingCategoria);
			pricingCategoriaService.suscribir(pc);
		}
	}

	/** Valida se a categoria não foi adicionada */
	private boolean verificarCategoriaNaoAdicionada(Categoria categoria) {
		if(lsPricingCategoria == null || lsPricingCategoria.isEmpty()) {
			return true;
		}
		for (GP_PricingCategoria pricingCategoria : lsPricingCategoria) {
			if(pricingCategoria.getCategoria() != null && pricingCategoria.getCategoria().equals(categoria)) {
				return false;
			}
		}
		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);
		btnModificarImporte.setVisible(true);

		descuentoporcsen.setConstraint("");
		descuentoporcsen.setDisabled(true);
		descuentoporcsen.setValue(null);
		pricing.setDescuentoporcentaje(null);

		descuentoporcredondo.setConstraint("");
		descuentoporcredondo.setValue(null);
		descuentoporcredondo.setDisabled(true);
		pricing.setDescuentoporcredondo(null);
	}

	public void onClick$radioPor(Event ev) {
		btnNovoImporte.setVisible(false);
		btnApagarImporte.setVisible(false);
		btnModificarImporte.setVisible(false);

		descuentoporcsen.setDisabled(false);
		descuentoporcredondo.setDisabled(false);

		Object[] listPImporte = pricingImporteList.getData();
		if (listPImporte != null) {
			for (Object o : listPImporte) {
				GP_PricingImporte pImporte = (GP_PricingImporte) o;
				lsPricingImporte.remove(pImporte);

				pImporte.setUsuarioId(UsuarioLogado.getUsuarioLogado().getUsuarioId());
				pImporte.setFecmodif(Calendar.getInstance().getTime());
				pImporte.setActivo(GP_Pricing.INATIVO);

				lsPricingImporte.add(pImporte);
				pricingImporteList.removeItem(pImporte);
			}

			pricingImporteList.clearSelection();
			pricing.setPricingImporteList(lsPricingImporte);
		}
	}

	private boolean validarNome() throws InterruptedException {
		try {
			nombrePricing.getValue();
		} catch (WrongValueException e) {

			Messagebox.show(
					Labels.getLabel("editarPricingController.MSG.nomPricingVazio"),
					Labels.getLabel("editarPricingController.window.title"),
					Messagebox.OK, Messagebox.INFORMATION);

			return false;
		}

		return true;
	}

	private boolean validarObligatorios() throws InterruptedException {
		try {
			nombrePricing.getValue();
		} catch (WrongValueException e) {

			Messagebox.show(
					Labels.getLabel("editarPricingController.MSG.nomPricingVazio"),
					Labels.getLabel("editarPricingController.window.title"),
					Messagebox.OK, Messagebox.INFORMATION);

			return false;
		}

		try {
			if (pricing.getEmpresa() == null) {
				Messagebox.show(
						Labels.getLabel("editarPricingController.MSG.empresaVazio"),
						Labels.getLabel("editarPricingController.window.title"),
						Messagebox.OK, Messagebox.INFORMATION);

				return false;
			}
			cmbEmpresa.getValue();
		} catch (WrongValueException e) {
			Messagebox.show(
					Labels.getLabel("editarPricingController.MSG.empresaVazio"),
					Labels.getLabel("editarPricingController.window.title"),
					Messagebox.OK, Messagebox.INFORMATION);

			return false;
		}

		try {
			itxCantboleto.getValue();
		} catch (WrongValueException e) {
			Messagebox.show(
					Labels.getLabel("editarPricingController.MSG.cantAsientosCorridasVazio"),
					Labels.getLabel("editarPricingController.window.title"),
					Messagebox.OK, Messagebox.INFORMATION);
			return false;
		}

		if (pricingVigenciaList.getModel().getSize() == 0) {
			Messagebox.show(
					Labels.getLabel("editarPricingController.MSG.vigenciasVazio"),
					Labels.getLabel("editarPricingController.window.title"),
					Messagebox.OK, Messagebox.INFORMATION);
			return false;
		}

		try {
			cantdiasanticipacion.getValue();
		} catch (WrongValueException e) {
			Messagebox.show(
					Labels.getLabel("editarPricingController.MSG.cantDiasAntecipacionVazio"),
					Labels.getLabel("editarPricingController.window.title"),
					Messagebox.OK, Messagebox.INFORMATION);
			return false;
		}

		if (pricingMarcaList.getModel().getSize() == 0) {
			Messagebox.show(
					Labels.getLabel("editarPricingController.MSG.marcaVazio"),
					Labels.getLabel("editarPricingController.window.title"),
					Messagebox.OK, Messagebox.INFORMATION);
			return false;
		}
		if (pricingClaseList.getModel().getSize() == 0) {
			Messagebox.show(
					Labels.getLabel("editarPricingController.MSG.claseVazio"),
					Labels.getLabel("editarPricingController.window.title"),
					Messagebox.OK, Messagebox.INFORMATION);
			return false;
		}
		if (pricingPuntoVentaList.getModel().getSize() == 0) {
			Messagebox.show(
					Labels.getLabel("editarPricingController.MSG.puntoVazio"),
					Labels.getLabel("editarPricingController.window.title"),
					Messagebox.OK, Messagebox.INFORMATION);
			return false;
		}
		
		if (pricingRutaList.getModel().getSize() == 0) {		
			Messagebox.show(
					Labels.getLabel("editarPricingController.MSG.rutaVazio"),
					Labels.getLabel("editarPricingController.window.title"),
					Messagebox.OK, Messagebox.INFORMATION);
			return false;
		}
				
		if (verificarContemTodasRuta() && verificarContemTodas()) {		
			Messagebox.show(
					Labels.getLabel("editarPricingController.MSG.noRutaTodasYTrechosTodos"),
					Labels.getLabel("editarPricingController.window.title"),
					Messagebox.OK, Messagebox.INFORMATION);
			return false;
		}
		if (pricingTipoPtoVtaList.getModel().getSize() == 0) {
			Messagebox.show(
					Labels.getLabel("editarPricingController.MSG.tipoPtoVtaVazio"),
					Labels.getLabel("editarPricingController.window.title"),
					Messagebox.OK, Messagebox.INFORMATION);
			return false;
		}

		if (pricingCategoriaList.getModel().getSize() == 0) {
			Messagebox.show(
					Labels.getLabel("editarPricingController.MSG.categoriaVazio"),
					Labels.getLabel("editarPricingController.window.title"),
					Messagebox.OK, Messagebox.INFORMATION);
			return false;
		}

		if (pricingMercadoList.getModel().getSize() == 0 && verificarContemTodasRuta()) {
			Messagebox.show(
					Labels.getLabel("editarPricingController.MSG.mercadoVazio"),
					Labels.getLabel("editarPricingController.window.title"),
					Messagebox.OK, Messagebox.INFORMATION);
			return false;
		}
		
		if(!rdEstadiaMinimaSi.isDisabled() && rdEstadiaMinimaSi.isChecked() && cantdiasEstadiaminima.getValue() == null) {
			Messagebox.show(
					Labels.getLabel("editarPricingController.MSG.cantestadiaminima"),
					Labels.getLabel("editarPricingController.window.title"),
					Messagebox.OK, Messagebox.EXCLAMATION);
			return false;
		}

		return true;
	}

	private boolean verificarContemTodasRuta() {
		Integer rutaIdTodas = -1;	
		for(int i = 0; i < pricingRutaList.getModel().getSize(); i++ ){
			GP_PricingRuta princingRuta = (GP_PricingRuta) pricingRutaList.getModel().getElementAt(i);
			if(princingRuta.getRuta().getRutaId() == rutaIdTodas){
				return true;
			}					
		}		
		return false;
	}

	private Boolean verificarContemTodas() {
		String TODAS = "TODAS";		
		for(int i = 0; i < pricingMercadoList.getModel().getSize(); i++ ){
			GP_PricingMercado princingMercado  = (GP_PricingMercado) pricingMercadoList.getModel().getElementAt(i);
			if(princingMercado.getOrigen().getDescparada().equals(TODAS) || princingMercado.getDestino().getDescparada().equals(TODAS)){
				return true;
			}					
		}		
		return false;
	}

	@SuppressWarnings("unchecked")
	public void onClick$btnSalvar(Event ev) throws InterruptedException {
		if (!validarObligatorios()) {
			return;
		}
		
		if(!pricingCorridaList.getListData().isEmpty()){
			pricing.setPricingCorridaList((List<GP_PricingCorrida>)pricingCorridaList.getListData());
		}

		BigDecimal vlrdescuentoporcsen = descuentoporcsen.getValueDecimal();
		BigDecimal vlrdescuentoporcredondo = descuentoporcredondo.getValueDecimal();

		if (cmbIndGeneraFeriadoFechaVenta.getSelectedItem() != null) {
			pricing.setIndGeneraFeriadoVenta((String) cmbIndGeneraFeriadoFechaVenta.getSelectedItem().getValue());
		}

		if (cmbIndGeneraFeriadoFechaViaje.getSelectedItem() != null) {
			pricing.setIndGeneraFeriadoViaje((String) cmbIndGeneraFeriadoFechaViaje.getSelectedItem().getValue());
		}
		
		if (chkAgruparDia.isChecked()) {
			pricing.setIndAgrupadoDia(Boolean.TRUE);
		} else {
			pricing.setIndAgrupadoDia(Boolean.FALSE);
		}
		
		if (chkAgruparServico.isChecked()) {
			pricing.setIndAgrupadoServico(Boolean.TRUE);
		} else {
			pricing.setIndAgrupadoServico(Boolean.FALSE);
		}

		try {
			try {
				if (radioPor.isChecked()) {

					if ((vlrdescuentoporcsen != null) && (vlrdescuentoporcsen.intValue() < -100 || vlrdescuentoporcsen.intValue() >= 1000)) {
						Messagebox.show(
								Labels.getLabel("editarPricingController.msgSencillo.title"),
								Labels.getLabel("editarPricingController.window.title"),
								Messagebox.OK, Messagebox.INFORMATION);
						return;
					}

					if ((vlrdescuentoporcredondo != null) && (vlrdescuentoporcredondo.intValue() < -100 || vlrdescuentoporcredondo.intValue() >= 1000)) {
						Messagebox.show(
								Labels.getLabel("editarPricingController.msgRedondo.title"),
								Labels.getLabel("editarPricingController.window.title"),
								Messagebox.OK, Messagebox.INFORMATION);
						return;

					}
				}
			} catch (Exception ex) {
				log.error("PrincigController - descuentoporcsen.getValue() // descuentoporcredondo.getValue() : " + ex);
				Messagebox.show(
						Labels.getLabel("MSG.Error"),
						Labels.getLabel("editarPricingController.window.title"),
						Messagebox.OK, Messagebox.EXCLAMATION);

			}

			pricing.setEmpresa((Empresa) cmbEmpresa.getSelectedItem().getValue());
			
			if (colorChoose.getValue() != null) {
				pricing.setColor(colorChoose.getValue());
			}

			if (rdTransSi.isChecked()) {
				pricing.setIndtransferible(Boolean.TRUE);
			} else {
				pricing.setIndtransferible(Boolean.FALSE);
			}
			if (rdCanceSi.isChecked()) {
				pricing.setIndcancelable(Boolean.TRUE);
			} else {
				pricing.setIndcancelable(Boolean.FALSE);
			}
			if (rdReserSi.isChecked()) {
				pricing.setIndreservable(Boolean.TRUE);
			} else {
				pricing.setIndreservable(Boolean.FALSE);
			}
			if (rdExibirVendaSi.isChecked()) {
				pricing.setExibeVenda(Boolean.TRUE);
			} else {
				pricing.setExibeVenda(Boolean.FALSE);
			}
			
			definirCamposEstadiaMinima();
			
			if (gravarNovo) {
				List<GP_Pricing> lsPricing =
						pricingService.buscarPorNombre(pricing.getNombPricing());

				if (lsPricing.size() == 0) {
					pricing = pricingService.actualizacion(pricing);
					pricingList.addItemNovo(pricing);
					
					compararAlteracoesESalvarHistorico();

					Messagebox.show(
							Labels.getLabel("editarPricingController.MSG.suscribirOK"),
							Labels.getLabel("editarPricingController.window.title"),
							Messagebox.OK, Messagebox.INFORMATION);

					salvo = true;

				} else {
					Messagebox.show(
							Labels.getLabel("MSG.Registro.Existe"),
							Labels.getLabel("editarPricingController.window.title"),
							Messagebox.OK, Messagebox.EXCLAMATION);
				}
			} else {
				
				if(!lsPricingOcupaAntecipa.isEmpty()){
					pricing.setPricingOcupaAntecipaList(lsPricingOcupaAntecipa);			
				}
				
				pricing = pricingService.actualizacion(pricing);
				pricingList.updateItem(pricing);

				if (buscarPricingInativosAtivos.equals(GP_Pricing.INATIVO)) {
					pricingService.inativar(pricing);
				}
				
				compararAlteracoesESalvarHistorico();

				Messagebox.show(
						Labels.getLabel("editarPricingController.MSG.suscribirOK"),
						Labels.getLabel("editarPricingController.window.title"),
						Messagebox.OK, Messagebox.INFORMATION);

				salvo = true;

			}

			// Se for por porcentage eu desativo todos os importes
			if (radioPor.isChecked()) {
				pricing = pricingService.obtenerID(pricing.getPricingId());
				for (GP_PricingImporte pi : pricing.getPricingImporteList()) {
					pricingImporteService.borrar(pi);
				}
			}
		} catch (Exception ex) {
			log.error("Error salvar pricing : " + ex);
			Messagebox.show(
					Labels.getLabel("MSG.Error"),
					Labels.getLabel("editarPricingController.window.title"),
					Messagebox.OK, Messagebox.EXCLAMATION);
		}
	}
	
	private void compararAlteracoesESalvarHistorico() {
		try {
			// Busca todas as listas novamente pq nao encontrava novos registros
			pricing.setPricingAsientoList(pricingAsientoService.obtenerTodoPorPricing(pricing));
			pricing.setPricingOcupaAntecipaList(pricingOcupaAntecipaService.obtenerTodoPorPricing(pricing));
			pricing.setPricingCategoriaList(pricingCategoriaService.obtenerTodoPorPricing(pricing));
			pricing.setPricingClaseList(pricingClaseService.obtenerTodoPorPricing(pricing));
			pricing.setPricingCorridaList(pricingCorridaService.obtenerTodoPorPricing(pricing));
			pricing.setPricingDiaList(pricingDiaService.obtenerTodoPorPricing(pricing));
			pricing.setPricingFormapagoList(pricingFormapagoService.obtenerTodoPorPricing(pricing));
			pricing.setPricingImporteList(pricingImporteService.obtenerTodoPorPricing(pricing));
			pricing.setPricingMarcaList(pricingMarcaService.obtenerTodoPorPricing(pricing));
			pricing.setPricingMercadoList(pricingMercadoService.obtenerTodoPorPricing(pricing));
			pricing.setPricingPuntoventaList(pricingPuntoVentaService.obtenerTodoPorPricing(pricing));
			pricing.setPricingRutaList(pricingRutaService.obtenerTodoPorPricing(pricing));
			pricing.setPricingTipoptovtaList(pricingTipoPtoVtaService.obtenerTodoPorPricing(pricing));
			pricing.setPricingTipoServicioList(pricingTipoServicioService.obtenerTodoPorPricing(pricing));
			pricing.setPricingVigenciaList(pricingVigenciaService.obtenerTodoPorPricing(pricing));
			
			pricingHistoricoService.compararESalvar(pricingOriginal, pricing);
			pricingOriginal = new GP_Pricing();
			pricingOriginal = pricing.clonar();			
		} catch (Exception e) {
			log.error("Erro ao salvar historico do Pricing Rapido: ", e);
		}
	}

	private void definirCamposEstadiaMinima() {
		chkIndLunEstadiaminima.getValue();
		chkIndMarEstadiaminima.getValue();
		chkIndMieEstadiaminima.getValue();
		chkIndJueEstadiaminima.getValue();
		chkIndVieEstadiaminima.getValue();
		chkIndSabEstadiaminima.getValue();
		chkIndDomEstadiaminima.getValue();
		cantdiasEstadiaminima.getValue();
		
		/*
		 * Caso não exista percentual de desconto informado, limpar as configurações de estadia minima
		 * Mantis #14990
		 */
		if(pricing.getDescuentoporcredondo() != null && rdEstadiaMinimaSi.isChecked()) {
			pricing.setIndestadiaminima(Boolean.TRUE);
			pricing.setCantdiasEstadiaminima(cantdiasEstadiaminima.getValue());
			pricing.setIndLunEstadiaminima(chkIndLunEstadiaminima.isChecked());
			pricing.setIndMarEstadiaminima(chkIndMarEstadiaminima.isChecked());
			pricing.setIndMieEstadiaminima(chkIndMieEstadiaminima.isChecked());
			pricing.setIndJueEstadiaminima(chkIndJueEstadiaminima.isChecked());
			pricing.setIndVieEstadiaminima(chkIndVieEstadiaminima.isChecked());
			pricing.setIndSabEstadiaminima(chkIndSabEstadiaminima.isChecked());
			pricing.setIndDomEstadiaminima(chkIndDomEstadiaminima.isChecked());
		} else {
			cantdiasEstadiaminima.setValue(null);
			rdEstadiaMinimaSi.setChecked(false);
			rdEstadiaMinimaNo.setChecked(true);
			chkIndLunEstadiaminima.setChecked(false);
			chkIndMarEstadiaminima.setChecked(false);
			chkIndMieEstadiaminima.setChecked(false);
			chkIndJueEstadiaminima.setChecked(false);
			chkIndVieEstadiaminima.setChecked(false);
			chkIndSabEstadiaminima.setChecked(false);
			chkIndDomEstadiaminima.setChecked(false);
		}
	}

	@SuppressWarnings({ "rawtypes", "unchecked" })
	public void onClick$btnCopiar(Event ev) throws InterruptedException {

		Map args = new HashMap();
		args.put("pricing", pricing);

		openWindow("/gui/gestao_pricing/copiarGP_Pricing.zul",
				Labels.getLabel("copiarPricingController.window.title"), args, MODAL);

	}
	

	@SuppressWarnings({ "unchecked" })
	public void onCheck$chkAgruparDia(CheckEvent ev) throws InterruptedException {
		
		if (ev.isChecked()) {
			List<GP_PricingDia> list = pricingDiaList.getListData();
			Checkbox chk = (Checkbox) ev.getTarget();

			if (list.isEmpty()) {
				Messagebox.show(
						"Adicione os registros para habilitar agrupação. ",
						Labels.getLabel("editarPricingController.window.title"),
						Messagebox.OK, Messagebox.INFORMATION);

				chk.setChecked(false);
				ev.stopPropagation();
			}

			for (GP_PricingDia gp_PricingDia : list) {

				if (gp_PricingDia.getIndfecviaje() != null && !gp_PricingDia.getIndfecviaje()) {

					Messagebox.show(
							"Para agrupar é necessário escolher somente Data da Viagem. ",
							Labels.getLabel("editarPricingController.window.title"),
							Messagebox.OK, Messagebox.INFORMATION);

					chk.setChecked(false);
					ev.stopPropagation();
				}
			}
		}
	}
	
	// O tratamento para deletar o Pricing (made by Monteiro) quando sair sem
	// salvar foi mudado para o evento onClose da janela.
	public void onClick$btnFechar(Event ev) {
		onClose$winEditarPricing(null);
	}

	public void onClose$winEditarPricing(Event ev) {
		if (!salvo) {
			if (pricing.getPricingId() != null) {
				pricingService.borrarFisico(pricing);
			}
		}

		closeWindow();
	}

	public void onClick$btnApagar(Event ev) throws InterruptedException {
		try {
			int resp = Messagebox.show(
					Labels.getLabel("editarPricingController.MSG.borrarPergunta"),
					Labels.getLabel("editarPricingController.window.title"),
					Messagebox.YES | Messagebox.NO, Messagebox.QUESTION);

			if (resp == Messagebox.YES) {
				pricingService.borrar(pricing);
				Messagebox.show(
						Labels.getLabel("editarPricingController.MSG.borrarOK"),
						Labels.getLabel("editarPricingController.window.title"),
						Messagebox.OK, Messagebox.INFORMATION);

				pricingList.removeItem(pricing);

				closeWindow();
			}
		} catch (Exception ex) {
			log.error("Erro apagar pricing : " + ex);
			Messagebox.show(
					Labels.getLabel("MSG.Error"),
					Labels.getLabel("editarPricingController.window.title"),
					Messagebox.OK, Messagebox.EXCLAMATION);
		}
	}

	public void onClick$btnModificarVigencia(Event ev) {
		GP_PricingVigencia pVigencia = (GP_PricingVigencia) pricingVigenciaList.getSelected();

		if (pVigencia != null) {
			verPricingVigencia(pVigencia);
		} else {
			try {
				Messagebox.show(Labels.getLabel("editarPricingController.MSG.selectItem"), Labels.getLabel("editarPricingController.windowVigencia.title"), Messagebox.OK, Messagebox.EXCLAMATION);
			} catch (InterruptedException ex) {
				LogManager.getLogger(EditarGP_PricingController.class).log(Level.FATAL, "", ex);
			}
		}
	}

	public void onClick$btnApagarVigencia(Event ev) throws Exception {
		List<Object> listPVigencia = pricingVigenciaList.getSelectedsItens();
		if (listPVigencia != null) {
			int resp = Messagebox.show(
					Labels.getLabel("editarPricingController.MSG.borrarPerguntaVigencia"),
					Labels.getLabel("editarPricingController.windowVigencia.title"),
					Messagebox.YES | Messagebox.NO, Messagebox.QUESTION);
			if (resp == Messagebox.YES) {
				for (Object o : listPVigencia) {

					pricing = pricingService.obtenerID(pricing.getPricingId());
					lsPricingVigencia = pricing.getPricingVigenciaList();

					GP_PricingVigencia pVigencia = (GP_PricingVigencia) o;
					lsPricingVigencia.remove(pVigencia);

					pVigencia.setUsuarioId(UsuarioLogado.getUsuarioLogado().getUsuarioId());
					pVigencia.setFecmodif(Calendar.getInstance().getTime());
					pVigencia.setActivo(GP_Pricing.EXCLUIDO);

					lsPricingVigencia.add(pVigencia);
					pricingVigenciaList.removeItem(pVigencia);

					pricing.setPricingVigenciaList(lsPricingVigencia);

					pricingService.actualizacion(pricing);
					lsPricingVigencia.clear();
				}
			}
		} else {
			Messagebox.show(Labels.getLabel("editarPricingController.MSG.selectItem"), Labels.getLabel("editarPricingController.window.title"), Messagebox.OK, Messagebox.EXCLAMATION);
		}
	}

	public void onClick$btnNovoVigencia(Event ev) throws InterruptedException {
		if (!validarNome()) {
			return;
		}
		GP_PricingVigencia pVigencia = new GP_PricingVigencia();
		pVigencia.setPricing(pricing);

		verPricingVigencia(pVigencia);
	}

	@SuppressWarnings({ "rawtypes", "unchecked" })
	private void verPricingVigencia(GP_PricingVigencia pVigencia) {
		if (pricing.getPricingId() == null) {
			pricingService.suscribir(pricing);
		}

		Map args = new HashMap();
		args.put("pricingVigencia", pVigencia);
		args.put("pricing", pricing);
		args.put("pricingVigenciaList", pricingVigenciaList);

		openWindow("/gui/gestao_pricing/editarGP_PricingVigencia.zul",
				Labels.getLabel("editarPricingController.vigencia.value"), args, MODAL);
	}

	public void onClick$btnApagarImporte(Event ev) throws Exception {
		List<Object> listPImporte = pricingImporteList.getSelectedsItens();
		if (listPImporte != null) {
			int resp = Messagebox.show(
					Labels.getLabel("editarPricingController.MSG.borrarPerguntaImporte"),
					Labels.getLabel("editarPricingController.windowImporte.title"),
					Messagebox.YES | Messagebox.NO, Messagebox.QUESTION);
			if (resp == Messagebox.YES) {
				for (Object o : listPImporte) {
					GP_PricingImporte pImporte = (GP_PricingImporte) o;
					lsPricingImporte.remove(pImporte);

					pImporte.setUsuarioId(UsuarioLogado.getUsuarioLogado().getUsuarioId());
					pImporte.setFecmodif(Calendar.getInstance().getTime());
					pImporte.setActivo(GP_Pricing.EXCLUIDO);

					lsPricingImporte.add(pImporte);
					pricingImporteList.removeItem(pImporte);
				}

				pricingImporteList.clearSelection();
				pricing.setPricingImporteList(lsPricingImporte);
				pricingService.actualizacion(pricing);
			}
		} else {
			Messagebox.show(Labels.getLabel("editarPricingController.MSG.selectItem"), Labels.getLabel("editarPricingController.windowImporte.title"), Messagebox.OK, Messagebox.EXCLAMATION);
		}
	}

	public void onClick$btnNovoImporte(Event ev) throws InterruptedException {
		if (!validarNome()) {
			return;
		}

		GP_PricingImporte pImporte = new GP_PricingImporte();
		pImporte.setPricing(pricing);
		verPricingImporte(pImporte);
	}

	@SuppressWarnings({ "rawtypes", "unchecked" })
	private void verPricingImporte(GP_PricingImporte pImporte) {
		if (pricing.getPricingId() == null) {
			pricingService.suscribir(pricing);
		}

		Map args = new HashMap();
		args.put("pricingImporte", pImporte);
		args.put("pricingImporteList", pricingImporteList);

		openWindow("/gui/gestao_pricing/editarGP_PricingImporte.zul",
				Labels.getLabel("editarPricingController.windowImporte.title"), args, MODAL);
	}

	public void onClick$btnModificarImporte(Event ev) throws InterruptedException {
		GP_PricingImporte pImporte = (GP_PricingImporte) pricingImporteList.getSelected();

		if (pImporte != null) {
			verPricingImporte(pImporte);
		} else {
			Messagebox.show(Labels.getLabel("editarPricingController.MSG.selectItem"), Labels.getLabel("editarPricingController.windowImporte.title"), Messagebox.OK, Messagebox.EXCLAMATION);
		}
	}

	public void onClick$btnApagarMarca(Event ev) throws Exception {
		List<Object> listPMarca = pricingMarcaList.getSelectedsItens();
		if (listPMarca != null) {
			int resp = Messagebox.show(
					Labels.getLabel("editarPricingController.MSG.borrarPerguntaMarca"),
					Labels.getLabel("editarPricingController.windowMarca.title"),
					Messagebox.YES | Messagebox.NO, Messagebox.QUESTION);
			if (resp == Messagebox.YES) {
				for (Object o : listPMarca) {
					GP_PricingMarca pMarca = (GP_PricingMarca) o;

					lsPricingMarca.remove(pMarca);

					pMarca.setUsuarioId(UsuarioLogado.getUsuarioLogado().getUsuarioId());
					pMarca.setFecmodif(Calendar.getInstance().getTime());
					pMarca.setActivo(GP_Pricing.EXCLUIDO);

					lsPricingMarca.add(pMarca);
					pricingMarcaList.removeItem(pMarca);
					pricingMarcaList.clearSelection();

					pricing.setPricingMarcaList(lsPricingMarca);
					pricingService.actualizacion(pricing);
				}
			}
		} else {
			Messagebox.show(Labels.getLabel("editarPricingController.MSG.selectItem"), Labels.getLabel("editarPricingController.window.title"), Messagebox.OK, Messagebox.EXCLAMATION);
		}
	}

	public void onClick$btnNovoMarca(Event ev) throws InterruptedException {
		if (!validarNome()) {
			return;
		}

		GP_PricingMarca pMarca = new GP_PricingMarca();
		pMarca.setPricing(pricing);
		verPricingMarca(pMarca);
	}

	@SuppressWarnings({ "rawtypes", "unchecked" })
	private void verPricingMarca(GP_PricingMarca pMarca) {
		if (pricing.getPricingId() == null) {
			pricingService.suscribir(pricing);
		}

		Map args = new HashMap();
		args.put("pricingMarca", pMarca);
		args.put("pricingMarcaList", pricingMarcaList);

		openWindow("/gui/gestao_pricing/editarGP_PricingMarca.zul",
				Labels.getLabel("editarPricingController.windowMarca.title"), args, MODAL);
	}

	public void onClick$btnModificarMarca(Event ev) {
		GP_PricingMarca pMarca = (GP_PricingMarca) pricingMarcaList.getSelected();

		if (pMarca != null) {
			verPricingMarca(pMarca);
		} else {
			try {
				Messagebox.show(Labels.getLabel("editarPricingController.MSG.selectItem"), Labels.getLabel("editarPricingController.window.title"), Messagebox.OK, Messagebox.EXCLAMATION);
			} catch (InterruptedException ex) {
				LogManager.getLogger(EditarGP_PricingController.class).log(Level.FATAL, "", ex);
			}
		}
	}

	public void onClick$btnApagarClase(Event ev) throws Exception {
		List<Object> listPClase = pricingClaseList.getSelectedsItens();

		if (listPClase != null) {
			int resp = Messagebox.show(
					Labels.getLabel("editarPricingController.MSG.borrarPerguntaClase"),
					Labels.getLabel("editarPricingController.windowClase.title"),
					Messagebox.YES | Messagebox.NO, Messagebox.QUESTION);
			if (resp == Messagebox.YES) {
				for (Object o : listPClase) {

					GP_PricingClase pClase = (GP_PricingClase) o;

					lsPricingClase.remove(pClase);

					pClase.setUsuarioId(UsuarioLogado.getUsuarioLogado().getUsuarioId());
					pClase.setFecmodif(Calendar.getInstance().getTime());
					pClase.setActivo(GP_Pricing.EXCLUIDO);

					lsPricingClase.add(pClase);
					pricingClaseList.removeItem(pClase);
					pricingClaseList.clearSelection();

					pricing.setPricingClaseList(lsPricingClase);
					pricingService.actualizacion(pricing);
				}
			}
		} else {
			Messagebox.show(Labels.getLabel("editarPricingController.MSG.selectItem"), Labels.getLabel("editarPricingController.window.title"), Messagebox.OK, Messagebox.EXCLAMATION);
		}
	}

	public void onClick$btnNovoClase(Event ev) throws InterruptedException {
		if (!validarNome()) {
			return;
		}

		GP_PricingClase pClase = new GP_PricingClase();
		pClase.setPricing(pricing);
		verPricingClase(pClase);
	}

	@SuppressWarnings({ "rawtypes", "unchecked" })
	private void verPricingClase(GP_PricingClase pClase) {
		if (pricing.getPricingId() == null) {
			pricingService.suscribir(pricing);
		}

		Map args = new HashMap();
		args.put("pricingClase", pClase);
		args.put("pricingClaseList", pricingClaseList);

		openWindow("/gui/gestao_pricing/editarGP_PricingClase.zul",
				Labels.getLabel("editarPricingController.windowTipoServicio.title"), args, MODAL);
	}

	public void onClick$btnModificarClase(Event ev) {
		GP_PricingClase pClase = (GP_PricingClase) pricingClaseList.getSelected();

		if (pClase != null) {
			verPricingClase(pClase);
		} else {
			try {
				Messagebox.show(Labels.getLabel("editarPricingController.MSG.selectItem"), Labels.getLabel("editarPricingController.window.title"), Messagebox.OK, Messagebox.EXCLAMATION);
			} catch (InterruptedException ex) {
				LogManager.getLogger(EditarGP_PricingController.class).log(Level.FATAL, "", ex);
			}
		}
	}

	public void onClick$btnApagarPuntoVenta(Event ev) throws Exception {
		List<Object> listPuntoVenta = pricingPuntoVentaList.getSelectedsItens();
		if (listPuntoVenta != null) {
			int resp = Messagebox.show(
					Labels.getLabel("editarPricingController.MSG.borrarPerguntaPuntoVenta"),
					Labels.getLabel("editarPricingController.windowPuntoVenta.title"),
					Messagebox.YES | Messagebox.NO, Messagebox.QUESTION);
			if (resp == Messagebox.YES) {

				for (Object o : listPuntoVenta) {

					GP_PricingPuntoVenta pPuntoVenta = (GP_PricingPuntoVenta) o;
					lsPricingPuntoVenta.remove(pPuntoVenta);

					pPuntoVenta.setUsuarioId(UsuarioLogado.getUsuarioLogado().getUsuarioId());
					pPuntoVenta.setFecmodif(Calendar.getInstance().getTime());
					pPuntoVenta.setActivo(GP_Pricing.EXCLUIDO);

					lsPricingPuntoVenta.add(pPuntoVenta);
					pricingPuntoVentaList.removeItem(pPuntoVenta);
					pricingPuntoVentaList.clearSelection();

					pricing.setPricingPuntoventaList(lsPricingPuntoVenta);
					pricingService.actualizacion(pricing);
				}
			}
		} else {
			Messagebox.show(Labels.getLabel("editarPricingController.MSG.selectItem"), Labels.getLabel("editarPricingController.window.title"), Messagebox.OK, Messagebox.EXCLAMATION);
		}
	}

	public void onClick$btnNovoPuntoVenta(Event ev) throws InterruptedException {
		if (!validarNome()) {
			return;
		}

		GP_PricingPuntoVenta pPuntoVenta = new GP_PricingPuntoVenta();
		pPuntoVenta.setPricing(pricing);
		verPricingPuntoVenta(pPuntoVenta);
	}

	@SuppressWarnings({ "rawtypes", "unchecked" })
	private void verPricingPuntoVenta(GP_PricingPuntoVenta pPuntoVenta) {
		if (pricing.getPricingId() == null) {
			pricingService.suscribir(pricing);
		}

		Map args = new HashMap();
		args.put("pricingPuntoVenta", pPuntoVenta);
		args.put("pricingPuntoVentaList", pricingPuntoVentaList);

		openWindow("/gui/gestao_pricing/editarGP_PricingPuntoVenta.zul",
				Labels.getLabel("editarPricingController.windowPuntoVenta.title"), args, MODAL);
	}

	public void onClick$btnModificarPuntoVenta(Event ev) {
		GP_PricingPuntoVenta pPuntoVenta = (GP_PricingPuntoVenta) pricingPuntoVentaList.getSelected();

		if (pPuntoVenta != null) {
			verPricingPuntoVenta(pPuntoVenta);
		} else {
			try {
				Messagebox.show(Labels.getLabel("editarPricingController.MSG.selectItem"), Labels.getLabel("editarPricingController.window.title"), Messagebox.OK, Messagebox.EXCLAMATION);
			} catch (InterruptedException ex) {
				LogManager.getLogger(EditarGP_PricingController.class).log(Level.FATAL, "", ex);
			}
		}
	}

	public void onClick$btnApagarTipoPtoVta(Event ev) throws Exception {
		List<Object> listTipoPtoVta = pricingTipoPtoVtaList.getSelectedsItens();
		if (listTipoPtoVta != null) {
			int resp = Messagebox.show(
					Labels.getLabel("editarPricingController.MSG.borrarPerguntaTipoPtoVta"),
					Labels.getLabel("editarPricingController.windowTipoPtoVta.title"),
					Messagebox.YES | Messagebox.NO, Messagebox.QUESTION);
			if (resp == Messagebox.YES) {
				for (Object r : listTipoPtoVta) {
					GP_PricingTipoPtoVta pTipoPtoVta = (GP_PricingTipoPtoVta) r;

					lsPricingTipoPtoVta.remove(pTipoPtoVta);
					pTipoPtoVta.setUsuarioId(UsuarioLogado.getUsuarioLogado().getUsuarioId());
					pTipoPtoVta.setFecmodif(Calendar.getInstance().getTime());
					pTipoPtoVta.setActivo(GP_Pricing.EXCLUIDO);

					lsPricingTipoPtoVta.add(pTipoPtoVta);
					pricingTipoPtoVtaList.removeItem(pTipoPtoVta);
					pricingTipoPtoVtaList.clearSelection();

					pricing.setPricingTipoptovtaList(lsPricingTipoPtoVta);
					pricingService.actualizacion(pricing);
				}
			}
		} else {
			Messagebox.show(Labels.getLabel("editarPricingController.MSG.selectItem"), Labels.getLabel("editarPricingController.window.title"), Messagebox.OK, Messagebox.EXCLAMATION);
		}
	}

	public void onClick$btnNovoTipoPtoVta(Event ev) throws InterruptedException {
		if (!validarNome()) {
			return;
		}

		GP_PricingTipoPtoVta pTipoPtoVta = new GP_PricingTipoPtoVta();
		pTipoPtoVta.setPricing(pricing);
		verPricingTipoPtoVta(pTipoPtoVta);
	}

	@SuppressWarnings({ "rawtypes", "unchecked" })
	private void verPricingTipoPtoVta(GP_PricingTipoPtoVta pTipoPtoVta) {
		if (pricing.getPricingId() == null) {
			pricingService.suscribir(pricing);
		}

		Map args = new HashMap();
		args.put("pricingTipoPtoVta", pTipoPtoVta);
		args.put("pricingTipoPtoVtaList", pricingTipoPtoVtaList);

		openWindow("/gui/gestao_pricing/editarGP_PricingTipoPtoVta.zul",
				Labels.getLabel("editarPricingController.windowTipoPtoVta.title"), args, MODAL);
	}

	public void onClick$btnModificarTipoPtoVta(Event ev) {
		GP_PricingTipoPtoVta pTipoPtoVta = (GP_PricingTipoPtoVta) pricingTipoPtoVtaList.getSelected();

		if (pTipoPtoVta != null) {
			verPricingTipoPtoVta(pTipoPtoVta);
		} else {
			try {
				Messagebox.show(Labels.getLabel("editarPricingController.MSG.selectItem"), Labels.getLabel("editarPricingController.window.title"), Messagebox.OK, Messagebox.EXCLAMATION);
			} catch (InterruptedException ex) {
				LogManager.getLogger(EditarGP_PricingController.class).log(Level.FATAL, "", ex);
			}
		}
	}

	public void onClick$btnApagarCategoria(Event ev) throws Exception {
		List<Object> listPCategoria = pricingCategoriaList.getSelectedsItens();
		if (listPCategoria != null) {
			int resp = Messagebox.show(
					Labels.getLabel("editarPricingController.MSG.borrarPerguntaCategoria"),
					Labels.getLabel("editarPricingController.windowCategoria.title"),
					Messagebox.YES | Messagebox.NO, Messagebox.QUESTION);
			if (resp == Messagebox.YES) {
				for (Object o : listPCategoria) {
					GP_PricingCategoria pCategoria = (GP_PricingCategoria) o;
					lsPricingCategoria.remove(pCategoria);

					pCategoria.setUsuarioId(UsuarioLogado.getUsuarioLogado().getUsuarioId());
					pCategoria.setFecmodif(Calendar.getInstance().getTime());
					pCategoria.setActivo(GP_Pricing.EXCLUIDO);

					lsPricingCategoria.add(pCategoria);
					pricingCategoriaList.removeItem(pCategoria);
					pricingCategoriaList.clearSelection();

					pricing.setPricingCategoriaList(lsPricingCategoria);
					pricingService.actualizacion(pricing);
				}
			}
		} else {
			Messagebox.show(Labels.getLabel("editarPricingController.MSG.selectItem"), Labels.getLabel("editarPricingController.window.title"), Messagebox.OK, Messagebox.EXCLAMATION);
		}
	}

	public void onClick$btnNovoCategoria(Event ev) throws InterruptedException {
		if (!validarNome()) {
			return;
		}

		GP_PricingCategoria pCategoria = new GP_PricingCategoria();
		pCategoria.setPricing(pricing);
		verPricingCategoria(pCategoria);
	}

	@SuppressWarnings({ "rawtypes", "unchecked" })
	private void verPricingCategoria(GP_PricingCategoria pCategoria) {
		if (pricing.getPricingId() == null) {
			pricingService.suscribir(pricing);
		}

		Map args = new HashMap();
		args.put("pricingCategoria", pCategoria);
		args.put("pricingCategoriaList", pricingCategoriaList);

		openWindow("/gui/gestao_pricing/editarGP_PricingCategoria.zul",
				Labels.getLabel("editarPricingController.windowCategoria.title"), args, MODAL);
	}

	public void onClick$btnModificarCategoria(Event ev) {
		GP_PricingCategoria pCategoria = (GP_PricingCategoria) pricingCategoriaList.getSelected();

		if (pCategoria != null) {
			verPricingCategoria(pCategoria);
		} else {
			try {
				Messagebox.show(Labels.getLabel("editarPricingController.MSG.selectItem"), Labels.getLabel("editarPricingController.window.title"), Messagebox.OK, Messagebox.EXCLAMATION);
			} catch (InterruptedException ex) {
				LogManager.getLogger(EditarGP_PricingController.class).log(Level.FATAL, "", ex);
			}
		}
	}

	public void onClick$btnApagarRuta(Event ev) throws Exception {
		List<Object> listRuta = pricingRutaList.getSelectedsItens();
		if (listRuta != null) {
			int resp = Messagebox.show(
					Labels.getLabel("editarPricingController.MSG.borrarPerguntaRuta"),
					Labels.getLabel("editarPricingController.windowRuta.title"),
					Messagebox.YES | Messagebox.NO, Messagebox.QUESTION);
			if (resp == Messagebox.YES) {
				for (Object r : listRuta) {
					GP_PricingRuta pRuta = (GP_PricingRuta) r;

					lsPricingRuta.remove(pRuta);

					pRuta.setUsuarioId(UsuarioLogado.getUsuarioLogado().getUsuarioId());
					pRuta.setFecmodif(Calendar.getInstance().getTime());
					pRuta.setActivo(GP_Pricing.EXCLUIDO);

					lsPricingRuta.add(pRuta);
					pricingRutaList.removeItem(pRuta);

				}
				pricingRutaList.clearSelection();
				pricing.setPricingRutaList(lsPricingRuta);
			}
		} else {
			Messagebox.show(Labels.getLabel("editarPricingController.MSG.selectItem"), Labels.getLabel("editarPricingController.window.title"), Messagebox.OK, Messagebox.EXCLAMATION);
		}
	}

	
	public void onChange$colorChoose(Event ev) throws InterruptedException {
		colorChoose.setStyle(" background: #FFFFFF; font-style: oblique;");
	}
	
	public void onClick$btnNovoRuta(Event ev) throws InterruptedException {
		if (!validarNome()) {
			return;
		}

		GP_PricingRuta pRuta = new GP_PricingRuta();
		pRuta.setPricing(pricing);
		verPricingRuta(pRuta);
	}

	@SuppressWarnings({ "rawtypes", "unchecked" })
	private void verPricingRuta(GP_PricingRuta pRuta) throws InterruptedException {
		if (pricing.getPricingId() == null) {
			pricingService.suscribir(pricing);
		}

			if(pricing.getEmpresa() != null){
				Map args = new HashMap();
				args.put("pricingRuta", pRuta);
				args.put("pricingRutaList", pricingRutaList);
		
				openWindow("/gui/gestao_pricing/editarGP_PricingRuta.zul",
						Labels.getLabel("editarPricingController.windowRuta.title"), args, MODAL);

			}else{
				Messagebox.show(
						Labels.getLabel("editarPuntoVentaController.MSG.empresa"),
						Labels.getLabel("editarPricingController.windowRuta.title"),
						Messagebox.OK, Messagebox.EXCLAMATION);
			}
	}

	public void onClick$btnModificarRuta(Event ev) throws InterruptedException {
		GP_PricingRuta pRuta = (GP_PricingRuta) pricingRutaList.getSelected();

		if (pRuta != null) {
			verPricingRuta(pRuta);
		} else {
			try {
				Messagebox.show(Labels.getLabel("editarPricingController.MSG.selectItem"), Labels.getLabel("editarPricingController.window.title"), Messagebox.OK, Messagebox.EXCLAMATION);
			} catch (InterruptedException ex) {
				LogManager.getLogger(EditarGP_PricingController.class).log(Level.FATAL, "", ex);
			}
		}
	}

	public void onClick$btnApagarMercado(Event ev) throws Exception {
		GP_PricingMercado pMercado = (GP_PricingMercado) pricingMercadoList.getSelected();
		if (pMercado != null) {
			int resp = Messagebox.show(
					Labels.getLabel("editarPricingController.MSG.borrarPerguntaMercado"),
					Labels.getLabel("editarPricingController.windowMercado.title"),
					Messagebox.YES | Messagebox.NO, Messagebox.QUESTION);
			if (resp == Messagebox.YES) {
				lsPricingMercado.remove(pMercado);

				pMercado.setUsuarioId(UsuarioLogado.getUsuarioLogado().getUsuarioId());
				pMercado.setFecmodif(Calendar.getInstance().getTime());
				pMercado.setActivo(GP_Pricing.EXCLUIDO);

				lsPricingMercado.add(pMercado);
				pricingMercadoList.removeItem(pMercado);
				pricingMercadoList.clearSelection();

				pricing.setPricingMercadoList(lsPricingMercado);
				pricingService.actualizacion(pricing);
			}
		} else {
			Messagebox.show(Labels.getLabel("editarPricingController.MSG.selectItem"), Labels.getLabel("editarPricingController.window.title"), Messagebox.OK, Messagebox.EXCLAMATION);
		}
	}

	public void onClick$btnNovoMercado(Event ev) throws InterruptedException {
		if (!validarNome()) {
			return;
		}

		GP_PricingMercado pMercado = new GP_PricingMercado();
		pMercado.setPricing(pricing);

		verPricingMercado(pMercado);
	}

	@SuppressWarnings({ "rawtypes", "unchecked" })
	private void verPricingMercado(GP_PricingMercado pMercado) {
		if (pricing.getPricingId() == null) {
			pricingService.suscribir(pricing);
		}

		Map args = new HashMap();
		args.put("pricingMercado", pMercado);
		args.put("pricingMercadoList", pricingMercadoList);

		openWindowPosi("/gui/gestao_pricing/editarGP_PricingMercado.zul",
				Labels.getLabel("editarPricingController.windowMercado.title"), args, MODAL, "center,top");
	}

	public void onClick$btnModificarMercado(Event ev) {
		GP_PricingMercado pMercado = (GP_PricingMercado) pricingMercadoList.getSelected();

		if (pMercado != null) {
			verPricingMercado(pMercado);
		} else {
			try {
				Messagebox.show(Labels.getLabel("editarPricingController.MSG.selectItem"), Labels.getLabel("editarPricingController.window.title"), Messagebox.OK, Messagebox.EXCLAMATION);
			} catch (InterruptedException ex) {
				LogManager.getLogger(EditarGP_PricingController.class).log(Level.FATAL, "", ex);
			}
		}
	}

	public void onClick$btnApagarCorrida(Event ev) throws Exception {
		GP_PricingCorrida pCorrida = (GP_PricingCorrida) pricingCorridaList.getSelected();
		if (pCorrida != null) {
			int resp = Messagebox.show(
					Labels.getLabel("editarPricingController.MSG.borrarPerguntaCorrida"),
					Labels.getLabel("editarPricingController.windowCorrida.title"),
					Messagebox.YES | Messagebox.NO, Messagebox.QUESTION);

			if (resp == Messagebox.YES) {
				pCorrida.setUsuarioId(UsuarioLogado.getUsuarioLogado().getUsuarioId());
				pCorrida.setFecmodif(Calendar.getInstance().getTime());
				pCorrida.setActivo(GP_Pricing.EXCLUIDO);

				pricing.setPricingCorridaList(lsPricingCorrida);
				pricingService.actualizacion(pricing);

				lsPricingCorrida.remove(pCorrida);
				pricingCorridaList.removeItem(pCorrida);
				pricingCorridaList.clearSelection();
			}
		} else {
			Messagebox.show(Labels.getLabel("editarPricingController.MSG.selectItem"),
					Labels.getLabel("editarPricingController.window.title"),
					Messagebox.OK, Messagebox.EXCLAMATION);
		}
	}

	public void onClick$btnNovoCorrida(Event ev) throws InterruptedException {
		if (!validarNome()) {
			return;
		}

		verPricingCorrida();
	}

	@SuppressWarnings({ "rawtypes", "unchecked" })
	private void verPricingCorrida() {
		if (pricing.getPricingId() == null) {
			pricingService.suscribir(pricing);
		}

		List<GP_PricingCorrida> lsCorridas = (List<GP_PricingCorrida>) pricingCorridaList.getListData();

		Map args = new HashMap();
		args.put("pricing", pricing);
		args.put("lsCorridas", lsCorridas);
		args.put("pricingCorridaList", pricingCorridaList);

		openWindow("/gui/gestao_pricing/editarGP_PricingCorrida.zul",
				Labels.getLabel("editarPricingController.windowCorrida.title"), args, MODAL);
	}

	public void onClick$btnModificarCorrida(Event ev) {
		GP_PricingCorrida pCorrida = (GP_PricingCorrida) pricingCorridaList.getSelected();

		if (pCorrida != null) {
			verPricingCorrida();
		} else {
			try {
				Messagebox.show(Labels.getLabel("editarPricingController.MSG.selectItem"),
						Labels.getLabel("editarPricingController.window.title"),
						Messagebox.OK, Messagebox.EXCLAMATION);
			} catch (InterruptedException ex) {
				LogManager.getLogger(EditarGP_PricingController.class).log(Level.FATAL, "", ex);
			}
		}
	}

	public void onClick$btnApagarDia(Event ev) throws Exception {
		GP_PricingDia pDia = (GP_PricingDia) pricingDiaList.getSelected();
		if (pDia != null) {
			int resp = Messagebox.show(
					Labels.getLabel("editarPricingController.MSG.borrarPerguntaDia"),
					Labels.getLabel("editarPricingController.windowDia.title"),
					Messagebox.YES | Messagebox.NO, Messagebox.QUESTION);
			if (resp == Messagebox.YES) {
				lsPricingDia.remove(pDia);

				pDia.setUsuarioId(UsuarioLogado.getUsuarioLogado().getUsuarioId());
				pDia.setFecmodif(Calendar.getInstance().getTime());
				pDia.setActivo(GP_Pricing.EXCLUIDO);

				lsPricingDia.add(pDia);
				pricingDiaList.removeItem(pDia);
				pricingDiaList.clearSelection();

				pricing.setPricingDiaList(lsPricingDia);
				pricingService.actualizacion(pricing);
			}
		} else {
			Messagebox.show(Labels.getLabel("editarPricingController.MSG.selectItem"), Labels.getLabel("editarPricingController.window.title"), Messagebox.OK, Messagebox.EXCLAMATION);
		}
	}

	public void onClick$btnNovoDia(Event ev) throws InterruptedException {
		if (!validarNome()) {
			return;
		}

		GP_PricingDia pDia = new GP_PricingDia();
		pDia.setPricing(pricing);
		verPricingDia(pDia);
	}

	@SuppressWarnings({ "rawtypes", "unchecked" })
	private void verPricingDia(GP_PricingDia pDia) {
		if (pricing.getPricingId() == null) {
			pricingService.suscribir(pricing);
		}

		Map args = new HashMap();
		args.put("pricingDia", pDia);
		args.put("pricingDiaList", pricingDiaList);

		openWindow("/gui/gestao_pricing/editarGP_PricingDia.zul",
				Labels.getLabel("editarPricingController.windowDia.title"), args, MODAL);
	}

	public void onClick$btnModificarDia(Event ev) {
		GP_PricingDia pDia = (GP_PricingDia) pricingDiaList.getSelected();

		if (pDia != null) {
			verPricingDia(pDia);
		} else {
			try {
				Messagebox.show(Labels.getLabel("editarPricingController.MSG.selectItem"), Labels.getLabel("editarPricingController.window.title"), Messagebox.OK, Messagebox.EXCLAMATION);
			} catch (InterruptedException ex) {
				LogManager.getLogger(EditarGP_PricingController.class).log(Level.FATAL, "", ex);
			}
		}
	}

	public void onClick$btnApagarOcupaAntecipa(Event ev) throws Exception {
		GP_PricingOcupaAntecipaVO pOcupaAntecipaVO = (GP_PricingOcupaAntecipaVO) pricingOcupaAntecipaList.getSelected();
		
		GP_PricingOcupaAntecipa pOcupaAntecipa = pricingOcupaAntecipaService.obtenerID(pOcupaAntecipaVO.getPricingocupaantecipaId());

		if (pOcupaAntecipa != null) {
			int resp = Messagebox.show(
					Labels.getLabel("editarPricingController.MSG.borrarPerguntaOcupacion"),
					Labels.getLabel("editarPricingController.windowOcupacion.title"),
					Messagebox.YES | Messagebox.NO, Messagebox.QUESTION);
			if (resp == Messagebox.YES) {
				lsPricingOcupaAntecipa.remove(pOcupaAntecipa);

				pOcupaAntecipa.setUsuarioId(UsuarioLogado.getUsuarioLogado().getUsuarioId());
				pOcupaAntecipa.setFecmodif(Calendar.getInstance().getTime());
				pOcupaAntecipa.setActivo(GP_Pricing.EXCLUIDO);

				lsPricingOcupaAntecipa.add(pOcupaAntecipa);
				pricing.setPricingOcupaAntecipaList(lsPricingOcupaAntecipa);
				pricingService.actualizacion(pricing);
				
				lsPricingOcupacaoAntecipas = pricingOcupaAntecipaService.carregarPricingOcupaAntecipaVO(pricing.getPricingId());
				pricingOcupaAntecipaList.setData(lsPricingOcupacaoAntecipas);
				
			}
		} else {
			Messagebox.show(Labels.getLabel("editarPricingController.MSG.selectItem"), Labels.getLabel("editarPricingController.window.title"), Messagebox.OK, Messagebox.EXCLAMATION);
		}
	}

	public void onClick$btnNovoOcupaAntecipa(Event ev) throws InterruptedException {
		if (!validarNome()) {
			return;
		}
		verPricingOcupaAntecipa(null);
	}

	@SuppressWarnings({ "rawtypes", "unchecked" })
	private void verPricingOcupaAntecipa(Integer pricingocupaantecipaId) {
		Map args = new HashMap();
		try {
			if (pricing.getPricingId() == null) {
				pricingService.suscribir(pricing);
			}
			
			GP_PricingOcupaAntecipa pOcupaAntecipa = null;
			if(pricingocupaantecipaId != null) {
				pOcupaAntecipa = pricingOcupaAntecipaService.obtenerID(pricingocupaantecipaId);
			} else {
				pOcupaAntecipa = new GP_PricingOcupaAntecipa();
				pOcupaAntecipa.setPricing(pricing);
			}

			args.put("pricingOcupaAntecipa", pOcupaAntecipa);
			args.put("pricingOcupaAntecipaListVO", pricingOcupaAntecipaList);
			args.put("pricingOcupaAntecipaLegendaList", pricingOcupaAntecipaLegendaList);
			args.put("lsPricingOcupaAntecipa", lsPricingOcupaAntecipa);
			args.put("parentWindow", this);
			args.put("argParentWindow", arg);
		} catch (Exception e) {
			log.error(e.getMessage(), e);
		}
		
		openWindow("/gui/gestao_pricing/editarGP_PricingOcupaAntecipa.zul",
				Labels.getLabel("editarPricingController.windowOcupacion.title"), args, MODAL);
		
	}

	@SuppressWarnings({ "rawtypes", "unchecked" })
	private void verPricingOcupaAntecipaAutomatico() {

		Map args = new HashMap();
		args.put("pricing", pricing);
        args.put("clasePricingOcupaAntecipaList", lsPricingOcupaAntecipa);
        args.put("pricingOcupaAntecipaList", pricingOcupaAntecipaList);
        args.put("clasePricingOcupaAntecipaLegendasList", lsPricingOcupaAntecipaLegendas);
        args.put("pricingOcupaAntecipaLegendasList", pricingOcupaAntecipaLegendaList);
        
        openWindow("/gui/gestao_pricing/editarGP_PricingOcupaAntecipaAutomatico.zul",
				Labels.getLabel("editarPricingAutomaticoController.windowOcupacion.title"), args, MODAL);
        
        
	}
	
	public void onClick$btnModificarOcupaAntecipa(Event ev) {
		GP_PricingOcupaAntecipaVO pOcupaAntecipa = (GP_PricingOcupaAntecipaVO) pricingOcupaAntecipaList.getSelected();

		if (pOcupaAntecipa != null) {
			verPricingOcupaAntecipa(pOcupaAntecipa.getPricingocupaantecipaId());
		} else {
			try {
				Messagebox.show(Labels.getLabel("editarPricingController.MSG.selectItem"), Labels.getLabel("editarPricingController.window.title"), Messagebox.OK, Messagebox.EXCLAMATION);
			} catch (InterruptedException ex) {
				LogManager.getLogger(EditarGP_PricingController.class).log(Level.FATAL, "", ex);
			}
		}
	}
	
	public void onClick$btnOcupaAntecipaAutomatico(Event ev) {
		verPricingOcupaAntecipaAutomatico();
	}

	public void onClick$btnApagarAsiento(Event ev) throws Exception {
		GP_PricingAsiento pAsiento = (GP_PricingAsiento) pricingAsientoList.getSelected();

		if (pAsiento != null) {
			int resp = Messagebox.show(
					Labels.getLabel("editarPricingController.MSG.borrarPerguntaAsiento"),
					Labels.getLabel("editarPricingController.windowAsiento.title"),
					Messagebox.YES | Messagebox.NO, Messagebox.QUESTION);
			if (resp == Messagebox.YES) {
				lsPricingAsiento.remove(pAsiento);

				pAsiento.setUsuarioId(UsuarioLogado.getUsuarioLogado().getUsuarioId());
				pAsiento.setFecmodif(Calendar.getInstance().getTime());
				pAsiento.setActivo(GP_Pricing.EXCLUIDO);

				lsPricingAsiento.add(pAsiento);
				pricingAsientoList.removeItem(pAsiento);
				pricingAsientoList.clearSelection();

				pricing.setPricingAsientoList(lsPricingAsiento);
				pricingService.actualizacion(pricing);
			}
		} else {
			Messagebox.show(Labels.getLabel("editarPricingController.MSG.selectItem"), Labels.getLabel("editarPricingController.window.title"), Messagebox.OK, Messagebox.EXCLAMATION);
		}
	}

	public void onClick$btnNovoAsiento(Event ev) throws InterruptedException {
		if (!validarNome()) {
			return;
		}

		GP_PricingAsiento pAsiento = new GP_PricingAsiento();
		pAsiento.setPricing(pricing);
		verPricingAsiento(pAsiento);
	}

	@SuppressWarnings({ "rawtypes", "unchecked" })
	private void verPricingAsiento(GP_PricingAsiento pAsiento) {
		if (pricing.getPricingId() == null) {
			pricingService.suscribir(pricing);
		}

		Map args = new HashMap();
		args.put("pricingAsiento", pAsiento);
		args.put("pricingAsientoList", pricingAsientoList);

		openWindow("/gui/gestao_pricing/editarGP_PricingAsiento.zul",
				Labels.getLabel("editarPricingController.windowAsiento.title"), args, MODAL);
	}

	public void onClick$btnModificarAsiento(Event ev) {
		GP_PricingAsiento pAsiento = (GP_PricingAsiento) pricingAsientoList.getSelected();

		if (pAsiento != null) {
			verPricingAsiento(pAsiento);
		} else {
			try {
				Messagebox.show(Labels.getLabel("editarPricingController.MSG.selectItem"), Labels.getLabel("editarPricingController.window.title"), Messagebox.OK, Messagebox.EXCLAMATION);
			} catch (InterruptedException ex) {
				LogManager.getLogger(EditarGP_PricingController.class).log(Level.FATAL, "", ex);
			}
		}
	}

	public void onClick$btnApagarTipoServicio(Event ev) throws Exception {
		GP_PricingTipoServicio pTipoServicio = (GP_PricingTipoServicio) pricingTipoServicioList.getSelected();

		if (pTipoServicio != null) {
			int resp = Messagebox.show(
					Labels.getLabel("editarPricingController.MSG.borrarPerguntaTipoServicio"),
					Labels.getLabel("editarPricingController.windowTipoServicio.title"),
					Messagebox.YES | Messagebox.NO, Messagebox.QUESTION);
			if (resp == Messagebox.YES) {
				lsPricingTipoServicio.remove(pTipoServicio);

				pTipoServicio.setUsuarioId(UsuarioLogado.getUsuarioLogado().getUsuarioId());
				pTipoServicio.setFecmodif(Calendar.getInstance().getTime());
				pTipoServicio.setActivo(GP_Pricing.EXCLUIDO);

				lsPricingTipoServicio.add(pTipoServicio);
				pricingTipoServicioList.removeItem(pTipoServicio);
				pricingTipoServicioList.clearSelection();

				pricing.setPricingTipoServicioList(lsPricingTipoServicio);
				pricingService.actualizacion(pricing);
			}
		} else {
			Messagebox.show(Labels.getLabel("editarPricingController.MSG.selectItem"), Labels.getLabel("editarPricingController.window.title"), Messagebox.OK, Messagebox.EXCLAMATION);
		}
	}

	public void onClick$btnNovoTipoServicio(Event ev) throws InterruptedException {
		if (!validarNome()) {
			return;
		}

		GP_PricingTipoServicio pTipoServicio = new GP_PricingTipoServicio();
		pTipoServicio.setPricing(pricing);
		verPricingTipoServicio(pTipoServicio);
	}

	@SuppressWarnings({ "rawtypes", "unchecked" })
	private void verPricingTipoServicio(GP_PricingTipoServicio pTipoServicio) {
		if (pricing.getPricingId() == null) {
			pricingService.suscribir(pricing);
		}

		Map args = new HashMap();
		args.put("pricingTipoServicio", pTipoServicio);
		args.put("pricingTipoServicioList", pricingTipoServicioList);

		openWindow("/gui/gestao_pricing/editarGP_PricingTipoServicio.zul",
				Labels.getLabel("editarPricingController.windowTipoServicio.title"), args, MODAL);
	}

	public void onClick$btnModificarTipoServicio(Event ev) {
		GP_PricingTipoServicio pTipoServicio = (GP_PricingTipoServicio) pricingTipoServicioList.getSelected();

		if (pTipoServicio != null) {
			verPricingTipoServicio(pTipoServicio);
		} else {
			try {
				Messagebox.show(Labels.getLabel("editarPricingController.MSG.selectItem"),
						Labels.getLabel("editarPricingController.window.title"), Messagebox.OK, Messagebox.EXCLAMATION);
			} catch (InterruptedException ex) {
				log.error(ex.getMessage());
			}
		}
	}

	public void onClick$btnApagarFormaPago(Event ev) throws Exception {
		GP_PricingFormapago pFormapago = (GP_PricingFormapago) pricingFormapagoList.getSelected();

		if (pFormapago != null) {
			int resp = Messagebox.show(
					Labels.getLabel("editarPricingController.MSG.borrarPerguntaFormaPago"),
					Labels.getLabel("editarPricingController.windowFormaPago.title"),
					Messagebox.YES | Messagebox.NO, Messagebox.QUESTION);
			if (resp == Messagebox.YES) {
				lsPricingFormapago.remove(pFormapago);

				pFormapago.setUsuarioId(UsuarioLogado.getUsuarioLogado().getUsuarioId());
				pFormapago.setFecmodif(Calendar.getInstance().getTime());
				pFormapago.setActivo(GP_Pricing.EXCLUIDO);

				lsPricingFormapago.add(pFormapago);
				pricingFormapagoList.removeItem(pFormapago);

				pricingFormapagoList.clearSelection();

				pricing.setPricingFormapagoList(lsPricingFormapago);
				pricingService.actualizacion(pricing);

				lsPricingFormapago = pricing.getPricingFormapagoList();
				pricingFormapagoList.setData(lsPricingFormapago);

			}
		} else {
			Messagebox.show(Labels.getLabel("editarPricingController.MSG.selectItem"),
					Labels.getLabel("editarPricingController.window.title"), Messagebox.OK, Messagebox.EXCLAMATION);
		}
	}

	public void onClick$btnNovoFormaPago(Event ev) throws InterruptedException {
		if (!validarNome()) {
			return;
		}

		GP_PricingFormapago pFormapago = new GP_PricingFormapago();
		pFormapago.setPricing(pricing);
		verPricingFormapago(pFormapago);
	}

	public void onClick$btnModificarFormaPago(Event ev) {
		GP_PricingFormapago pFormapago = (GP_PricingFormapago) pricingFormapagoList.getSelected();

		if (pFormapago != null) {
			verPricingFormapago(pFormapago);

		} else {
			try {
				Messagebox.show(Labels.getLabel("editarPricingController.MSG.selectItem"),
						Labels.getLabel("editarPricingController.window.title"), Messagebox.OK, Messagebox.EXCLAMATION);
			} catch (InterruptedException ex) {
				LogManager.getLogger(EditarGP_PricingController.class).log(Level.FATAL, "", ex);
			}
		}
	}

	@SuppressWarnings({ "rawtypes", "unchecked" })
	private void verPricingFormapago(GP_PricingFormapago pFormapago) {
		if (pricing.getPricingId() == null) {
			pricingService.suscribir(pricing);
		}

		Map args = new HashMap();
		args.put("pricingFormapago", pFormapago);
		args.put("pricingFormapagoList", pricingFormapagoList);

		openWindow("/gui/gestao_pricing/editarGP_PricingFormapago.zul",
				Labels.getLabel("editarPricingController.windowFormaPago.title"), args, MODAL);
	}

	public void onClick$btnInativar(Event ev) throws InterruptedException {
		try {
			int resp = Messagebox.show(
					Labels.getLabel("editarPricingController.MSG.inativarPergunta"),
					Labels.getLabel("editarPricingController.window.title"),
					Messagebox.YES | Messagebox.NO, Messagebox.QUESTION);

			if (resp == Messagebox.YES) {
				pricingService.inativar(pricing);
				Messagebox.show(
						Labels.getLabel("editarPricingController.MSG.inativarOK"),
						Labels.getLabel("editarPricingController.window.title"),
						Messagebox.OK, Messagebox.INFORMATION);

				pricingList.removeItem(pricing);

				closeWindow();
			}
		} catch (Exception ex) {
			log.error("Erro inativar pricing : " + ex);
			Messagebox.show(
					Labels.getLabel("MSG.Error"),
					Labels.getLabel("editarPricingController.window.title"),
					Messagebox.OK, Messagebox.EXCLAMATION);
		}
	}

	public void onClick$btnAtivar(Event ev) throws InterruptedException {
		try {
			int resp = Messagebox.show(
					Labels.getLabel("editarPricingController.MSG.ativarPergunta"),
					Labels.getLabel("editarPricingController.window.title"),
					Messagebox.YES | Messagebox.NO, Messagebox.QUESTION);

			if (resp == Messagebox.YES) {
				pricingService.ativar(pricing);
				Messagebox.show(
						Labels.getLabel("editarPricingController.MSG.ativarOK"),
						Labels.getLabel("editarPricingController.window.title"),
						Messagebox.OK, Messagebox.INFORMATION);

				ativarInativarComponentes(Boolean.FALSE);

				pricingList.removeItem(pricing);
				closeWindow();
			}
		} catch (Exception ex) {
			log.error("Erro ativar pricing : ", ex);
			Messagebox.show(
					Labels.getLabel("MSG.Error"),
					Labels.getLabel("editarPricingController.window.title"),
					Messagebox.OK, Messagebox.EXCLAMATION);
		}
	}

	private void ativarInativarComponentes(Boolean desativar) {
		pricingVigenciaList.setDisabled(desativar);
		pricingImporteList.setDisabled(desativar);
		pricingMarcaList.setDisabled(desativar);
		pricingClaseList.setDisabled(desativar);
		pricingPuntoVentaList.setDisabled(desativar);
		pricingTipoPtoVtaList.setDisabled(desativar);
		pricingRutaList.setDisabled(desativar);
		pricingMercadoList.setDisabled(desativar);
		pricingDiaList.setDisabled(desativar);
		pricingCorridaList.setDisabled(desativar);
		pricingAsientoList.setDisabled(desativar);
		pricingOcupaAntecipaList.setDisabled(desativar);
		pricingTipoServicioList.setDisabled(desativar);
		pricingFormapagoList.setDisabled(desativar);
		btnNovoVigencia.setDisabled(desativar);
		btnApagarVigencia.setDisabled(desativar);
		btnModificarVigencia.setDisabled(desativar);
		btnNovoImporte.setDisabled(desativar);
		btnApagarImporte.setDisabled(desativar);
		btnModificarImporte.setDisabled(desativar);
		btnNovoMarca.setDisabled(desativar);
		btnApagarMarca.setDisabled(desativar);
		btnModificarMarca.setDisabled(desativar);
		btnNovoClase.setDisabled(desativar);
		btnApagarClase.setDisabled(desativar);
		btnModificarClase.setDisabled(desativar);
		btnNovoPuntoVenta.setDisabled(desativar);
		btnApagarPuntoVenta.setDisabled(desativar);
		btnModificarPuntoVenta.setDisabled(desativar);
		btnNovoRuta.setDisabled(desativar);
		btnApagarRuta.setDisabled(desativar);
		btnModificarRuta.setDisabled(desativar);
		btnNovoTipoPtoVta.setDisabled(desativar);
		btnApagarTipoPtoVta.setDisabled(desativar);
		btnModificarTipoPtoVta.setDisabled(desativar);
		btnNovoMercado.setDisabled(desativar);
		btnApagarMercado.setDisabled(desativar);
		btnModificarMercado.setDisabled(desativar);
		btnNovoDia.setDisabled(desativar);
		btnApagarDia.setDisabled(desativar);
		btnNovoCorrida.setDisabled(desativar);
		btnApagarCorrida.setDisabled(desativar);
		btnNovoAsiento.setDisabled(desativar);
		btnApagarAsiento.setDisabled(desativar);
		btnModificarAsiento.setDisabled(desativar);
		btnNovoTipoServicio.setDisabled(desativar);
		btnApagarTipoServicio.setDisabled(desativar);
		btnModificarTipoServicio.setDisabled(desativar);
		btnNovoFormaPago.setDisabled(desativar);
		btnApagarFormaPago.setDisabled(desativar);
		btnModificarFormaPago.setDisabled(desativar);
		
		btnCopiar.setDisabled(desativar);
		btnSalvar.setDisabled(desativar);
	}

	public List<Empresa> getLsEmpresa() {
		return lsEmpresa;
	}

	public void setLsEmpresa(List<Empresa> lsEmpresa) {
		this.lsEmpresa = lsEmpresa;
	}

	public GP_Pricing getPricing() {
		return pricing;
	}

	public void setPricing(GP_Pricing pricing) {
		this.pricing = pricing;
	}

	public MyListbox getPricingList() {
		return pricingList;
	}

	public void setPricingList(MyListbox pricingList) {
		this.pricingList = pricingList;
	}

	public GP_PricingService getPricingService() {
		return pricingService;
	}

	public void setPricingService(GP_PricingService pricingService) {
		this.pricingService = pricingService;
	}

	public List<GP_PricingVigencia> getLsPricingVigencia() {
		return lsPricingVigencia;
	}

	public void setLsPricingVigencia(List<GP_PricingVigencia> lsPricingVigencia) {
		this.lsPricingVigencia = lsPricingVigencia;
	}

	public Combobox getCmbEmpresa() {
		return cmbEmpresa;
	}

	public void setCmbEmpresa(Combobox cmbEmpresa) {
		this.cmbEmpresa = cmbEmpresa;
	}

	public List<GP_PricingAsiento> getLsPricingAsiento() {
		return lsPricingAsiento;
	}

	public void setLsPricingAsiento(List<GP_PricingAsiento> lsPricingAsiento) {
		this.lsPricingAsiento = lsPricingAsiento;
	}

	public List<GP_PricingCategoria> getLsPricingCategoria() {
		return lsPricingCategoria;
	}

	public void setLsPricingCategoria(List<GP_PricingCategoria> lsPricingCategoria) {
		this.lsPricingCategoria = lsPricingCategoria;
	}

	public List<GP_PricingClase> getLsPricingClase() {
		return lsPricingClase;
	}

	public void setLsPricingClase(List<GP_PricingClase> lsPricingClase) {
		this.lsPricingClase = lsPricingClase;
	}

	public List<GP_PricingDia> getLsPricingDia() {
		return lsPricingDia;
	}

	public void setLsPricingDia(List<GP_PricingDia> lsPricingDia) {
		this.lsPricingDia = lsPricingDia;
	}

	public List<GP_PricingImporte> getLsPricingImporte() {
		return lsPricingImporte;
	}

	public void setLsPricingImporte(List<GP_PricingImporte> lsPricingImporte) {
		this.lsPricingImporte = lsPricingImporte;
	}

	public List<GP_PricingMarca> getLsPricingMarca() {
		return lsPricingMarca;
	}

	public void setLsPricingMarca(List<GP_PricingMarca> lsPricingMarca) {
		this.lsPricingMarca = lsPricingMarca;
	}

	public List<GP_PricingMercado> getLsPricingMercado() {
		return lsPricingMercado;
	}

	public void setLsPricingMercado(List<GP_PricingMercado> lsPricingMercado) {
		this.lsPricingMercado = lsPricingMercado;
	}

	public List<GP_PricingRuta> getLsPricingRuta() {
		return lsPricingRuta;
	}

	public void setLsPricingRuta(List<GP_PricingRuta> lsPricingRuta) {
		this.lsPricingRuta = lsPricingRuta;
	}

	public MyListbox getPricingImporteList() {
		return pricingImporteList;
	}

	public void setPricingImporteList(MyListbox pricingImporteList) {
		this.pricingImporteList = pricingImporteList;
	}

	public MyListbox getPricingVigenciaList() {
		return pricingVigenciaList;
	}

	public void setPricingVigenciaList(MyListbox pricingVigenciaList) {
		this.pricingVigenciaList = pricingVigenciaList;
	}

	public Radio getRdCanceNo() {
		return rdCanceNo;
	}

	public void setRdCanceNo(Radio rdCanceNo) {
		this.rdCanceNo = rdCanceNo;
	}

	public Radio getRdCanceSi() {
		return rdCanceSi;
	}

	public void setRdCanceSi(Radio rdCanceSi) {
		this.rdCanceSi = rdCanceSi;
	}

	public Radio getRdReserNo() {
		return rdReserNo;
	}

	public void setRdReserNo(Radio rdReserNo) {
		this.rdReserNo = rdReserNo;
	}

	public Radio getRdReserSi() {
		return rdReserSi;
	}

	public void setRdReserSi(Radio rdReserSi) {
		this.rdReserSi = rdReserSi;
	}

	public Radio getRdTransNo() {
		return rdTransNo;
	}

	public void setRdTransNo(Radio rdTransNo) {
		this.rdTransNo = rdTransNo;
	}

	public Radio getRdTransSi() {
		return rdTransSi;
	}

	public void setRdTransSi(Radio rdTransSi) {
		this.rdTransSi = rdTransSi;
	}

	public Button getBtnApagar() {
		return btnApagar;
	}

	public void setBtnApagar(Button btnApagar) {
		this.btnApagar = btnApagar;
	}

	public Button getBtnApagarImporte() {
		return btnApagarImporte;
	}

	public void setBtnApagarImporte(Button btnApagarImporte) {
		this.btnApagarImporte = btnApagarImporte;
	}

	public Button getBtnModificarImporte() {
		return btnModificarImporte;
	}

	public void setBtnModificarImporte(Button btnModificarImporte) {
		this.btnModificarImporte = btnModificarImporte;
	}

	public Button getBtnNovoImporte() {
		return btnNovoImporte;
	}

	public void setBtnNovoImporte(Button btnNovoImporte) {
		this.btnNovoImporte = btnNovoImporte;
	}

	public Radio getRadioImp() {
		return radioImp;
	}

	public void setRadioImp(Radio radioImp) {
		this.radioImp = radioImp;
	}

	public Radio getRadioPor() {
		return radioPor;
	}

	public void setRadioPor(Radio radioPor) {
		this.radioPor = radioPor;
	}

	public Radio getRdExibirVendaSi() {
		return rdExibirVendaSi;
	}

	public void setRdExibirVendaSi(Radio rdExibirVendaSi) {
		this.rdExibirVendaSi = rdExibirVendaSi;
	}

	public Radio getRdExibirVendaNo() {
		return rdExibirVendaNo;
	}

	public void setRdExibirVendaNo(Radio rdExibirVendaNo) {
		this.rdExibirVendaNo = rdExibirVendaNo;
	}

	public boolean isFormaPagoPricingInativo(){
		return ApplicationProperties.getInstance().isCustomHabilitado(CustomEnum.IS_FORMAPAGO_PRICING_INATIVO.getDescricao(), "1");
	}
	
	public Checkbox getChkAgruparDia() {
		return chkAgruparDia;
	}

	public void setChkAgruparDia(Checkbox chkAgruparDia) {
		this.chkAgruparDia = chkAgruparDia;
	}

	public Checkbox getChkAgruparServico() {
		return chkAgruparServico;
	}

	public void setChkAgruparServico(Checkbox chkAgruparServico) {
		this.chkAgruparServico = chkAgruparServico;
	}

	public List<String> getColumns() {
		if (columns == null) {
			carregarColunas();
		}
		return columns;
	}

	private void carregarColunas() {
		columns = new ArrayList<String>();
		for (int i = 1; i <= GP_PricingOcupaAntecipaPoltronasVO.MAXPOLTRONAS; i++) {
			columns.add(i+"");
		}
	}
	
	public void onClick$tabOcupaAntecipa(Event ev) {
		carregarTabOcupaAntecipa();
	}
	
	public void onClick$tabRevisaoValor(Event ev) {
		carregarListaRevisaoValoresPricing();
		
	}
	
	@SuppressWarnings("unchecked")
	private void carregarListaRevisaoValoresPricing() {
		List<GP_PricingCorrida> lsPricingCorrida = new ArrayList<GP_PricingCorrida>();
		if(pricingCorridaList.getListData()!= null && !pricingCorridaList.getListData().isEmpty()) {
			lsPricingCorrida = (List<GP_PricingCorrida>)pricingCorridaList.getListData();
		}
		lsPricingRevisaoValores = pricingRevisaoValoresService.buscarPricingRevisaoValoresVO(lsPricingVigencia,lsPricingClase,
				lsPricingMarca,lsPricingMercado, lsPricingOcupaAntecipa,lsPricingCorrida, lsPricingRuta);
		
		pricingRevisaoValores.setItemRenderer(new RenderPricingRevisaoValores());
		pricingRevisaoValores.setData(lsPricingRevisaoValores);
		
	}

	public void onBlur$descuentoporcredondo(Event ev) {
		descuentoporcredondo.getValue();
		ativarDesativarCamposEstadiaMinima(descuentoporcredondo.getValueDecimal() == null);
	}

	private void ativarDesativarCamposEstadiaMinima(Boolean desativar) {
		rdEstadiaMinimaSi.setDisabled(desativar);
		rdEstadiaMinimaNo.setDisabled(desativar);
		cantdiasEstadiaminima.setDisabled(desativar);
		chkIndLunEstadiaminima.setDisabled(desativar);
		chkIndMarEstadiaminima.setDisabled(desativar);
		chkIndMieEstadiaminima.setDisabled(desativar);
		chkIndJueEstadiaminima.setDisabled(desativar);
		chkIndVieEstadiaminima.setDisabled(desativar);
		chkIndSabEstadiaminima.setDisabled(desativar);
		chkIndDomEstadiaminima.setDisabled(desativar);
	}
	
	public void onClick$rdEstadiaMinimaNo(Event ev) {
		cantdiasEstadiaminima.setValue(null);
		chkIndLunEstadiaminima.setChecked(false);
		chkIndMarEstadiaminima.setChecked(false);
		chkIndMieEstadiaminima.setChecked(false);
		chkIndJueEstadiaminima.setChecked(false);
		chkIndVieEstadiaminima.setChecked(false);
		chkIndSabEstadiaminima.setChecked(false);
		chkIndDomEstadiaminima.setChecked(false);
	}

}
