/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.rjconsultores.ventaboletos.web.utilerias.render;

import java.text.SimpleDateFormat;

import org.zkoss.zkplus.spring.SpringUtil;
import org.zkoss.zul.Listcell;
import org.zkoss.zul.Listitem;
import org.zkoss.zul.ListitemRenderer;

import com.rjconsultores.ventaboletos.entidad.Pricing;
import com.rjconsultores.ventaboletos.entidad.PricingVigencia;
import com.rjconsultores.ventaboletos.service.PricingService;

/**
 * 
 * @author Rafius
 */
public class RenderPricing implements ListitemRenderer {

	private PricingService pricingService = (PricingService) SpringUtil.getBean("pricingService");

	public void render(Listitem lstm, Object o) throws Exception {
		Pricing p = (Pricing) o;
		p = pricingService.obtenerID(p.getPricingId());

		Listcell lc = new Listcell();

		if (p.getNombPricing() != null) {

			if (p.getPricingId() != null) {
				lc = new Listcell(p.getPricingId().toString());
			} else {
				lc = new Listcell("-");
			}
			lc.setParent(lstm);

			if (p.getNombPricing() != null) {
				lc = new Listcell(p.getNombPricing());
			} else {
				lc = new Listcell("-");
			}
			lc.setParent(lstm);

			if (p.getEmpresa() != null) {
				lc = new Listcell(p.getEmpresa().getNombempresa());
			} else {
				lc = new Listcell("-");
			}
			lc.setParent(lstm);

			Integer pricingInativoAtivo = p.getActivo();
			SimpleDateFormat dt = new SimpleDateFormat("dd/MM/yyyy HH:mm");
			if (!p.getPricingVigenciaList().isEmpty()) {
				String data = "";
				for (PricingVigencia pv : p.getPricingVigenciaList()) {
					data = data + dt.format(pv.getFecinicioviaje()) + " a " + dt.format(pv.getFecfinviaje()) + " ou ";
				}
				data = data.substring(0, data.length() - 3);
				lc = new Listcell(data);
			} else {
				lc = new Listcell("-");
			}
			lc.setParent(lstm);
		}
		lstm.setAttribute("data", p);
	}
}
