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

import java.text.DecimalFormat;
import java.text.SimpleDateFormat;

import org.zkoss.zul.Listcell;
import org.zkoss.zul.Listitem;
import org.zkoss.zul.ListitemRenderer;

import com.rjconsultores.ventaboletos.entidad.TarifaEmbarcada;
import com.rjconsultores.ventaboletos.utilerias.ApplicationProperties;
import com.rjconsultores.ventaboletos.utilerias.CustomEnum;

public class RenderTarifaEmbarcada implements ListitemRenderer {

    public void render(Listitem lstm, Object o) throws Exception {
        TarifaEmbarcada t = (TarifaEmbarcada) o;
        SimpleDateFormat formatoData = new SimpleDateFormat("dd/MM/yyyy");
        DecimalFormat df = new DecimalFormat("###,###,##0.00", new java.text.DecimalFormatSymbols(java.util.Locale.US));

        Listcell lc = new Listcell(t.getTarifaembarcadaId().toString());
        lc.setParent(lstm);

        if (t.getPrecio() != null) {
            lc = new Listcell(df.format(t.getPrecio()));
        } else {
            lc = new Listcell("");
        }
        lc.setParent(lstm);

        if (t.getPreciooriginal() != null) {
            lc = new Listcell(df.format(t.getPreciooriginal()));
        } else {
            lc = new Listcell("");
        }
        lc.setParent(lstm);

        lc = new Listcell(t.getImportepedagio() == null ? "" : df.format(t.getImportepedagio()));
        lc.setParent(lstm);
        lc = new Listcell(t.getImportetaxaembarque() == null ? "" : df.format(t.getImportetaxaembarque()));
        lc.setParent(lstm);
        lc = new Listcell(t.getImporteseguro() == null ? "" : df.format(t.getImporteseguro()));
        lc.setParent(lstm);

        if (ApplicationProperties.getInstance().isCustomHabilitado(CustomEnum.EXIBE_TPP.getDescricao())) {
	        lc = new Listcell(t.getImporteTPP() == null ? "" : df.format(t.getImporteTPP()));
	        lc.setParent(lstm);
        } else {
        	lc = new Listcell(""); 
	        lc.setParent(lstm);
        }
        
        lc = new Listcell(t.getImporteoutros() == null ? "" : df.format(t.getImporteoutros()));
        lc.setParent(lstm);
        
        if (t.getStatustarifa() != null) {
            String status;
            if (t.getStatustarifa().equals("A")) {
                status = "Autorizado";
            } else {
                status = "Latente";
            }
            lc = new Listcell(status);
        } else {
            lc = new Listcell("");
        }
        lc.setParent(lstm);


        if (t.getTramo() != null) {
            lc = new Listcell(t.getTramo().getOrigem().getDescparada());
            lc.setParent(lstm);
            lc = new Listcell(t.getTramo().getDestino().getDescparada());
            lc.setParent(lstm);
            lc = new Listcell(t.getTramo().getVia().getNombvia());
            lc.setParent(lstm);
        } else {
            lc = new Listcell("");
            lc.setParent(lstm);
            lc = new Listcell("");
            lc.setParent(lstm);
            lc = new Listcell("");
            lc.setParent(lstm);
        }



        if (t.getMarca() != null) {
            lc = new Listcell(t.getMarca().getDescmarca());
        } else {
            lc = new Listcell("");
        }
        lc.setParent(lstm);

        if (t.getVigenciaTarifa() != null) {
            String vigencia = formatoData.format(t.getVigenciaTarifa().getFeciniciovigencia()) + " - "
                    + formatoData.format(t.getVigenciaTarifa().getFecfinvigencia());
            lc = new Listcell(vigencia);
        } else {
            lc = new Listcell("");
        }
        lc.setParent(lstm);

        if (t.getClaseServicio() != null) {
            lc = new Listcell(t.getClaseServicio().getDescclase());
        } else {
            lc = new Listcell("");
        }
        lc.setParent(lstm);
        
        if (t.getOrgaoConcedente() != null){
            lc = new Listcell(t.getOrgaoConcedente().getDescOrgao());
        } else {
            lc = new Listcell("");
        }
        lc.setParent(lstm);

        if (t.getRuta() != null) {
            lc = new Listcell(t.getRuta().getPrefixo());
        } else {
            lc = new Listcell("");
        }
        lc.setParent(lstm);

        if (t.getRuta() != null) {
            lc = new Listcell(t.getRuta().getNumRuta());
        } else {
            lc = new Listcell("");
        }
        lc.setParent(lstm);

        lstm.setAttribute("data", t);
    }
}
