Subversion Repositories Integrator Subversion

Rev

Rev 195 | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

package br.com.ec.controller.util;

import java.util.Date;

import javax.faces.bean.ManagedBean;

import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

import br.com.ec.core.util.DataUtils;
import br.com.ec.core.util.VerificadorUtil;
import br.com.ec.domain.shared.ConstantesSEC;
import br.com.ec.domain.shared.TipoCor;

@Component
@ManagedBean
@Scope("view")
public class UtilBean {

        public static String padraoCodigoProduto(String codigoProduto) {
                try {
                        return !codigoProduto.isEmpty() ? String.format("%06d", new Long(codigoProduto)) : "";
                } catch (Exception e) {
                        return "";
                }
        }
       
        public static String statusContagem(Date dataVerificar, Date dataContagemSolicitada) {
                if (dataVerificar != null) {
                        if (VerificadorUtil.naoEstaNulo(dataContagemSolicitada)) {
                                if (dataContagemSolicitada.before(dataVerificar)) {
                                        return "green";
                                } else {
                                        Integer quantidadeDias = DataUtils.calcularDiferenceEmDiasEntreDuasDatas(DataUtils.getDataAtual(), dataVerificar);
                                        if (quantidadeDias > ConstantesSEC.StatusContagem.CONTAGEM_VERMELHO_60_DIAS) return "pink";
                                        if (quantidadeDias > ConstantesSEC.StatusContagem.CONTAGEM_AMARELO_30_DIAS) return "orange";
                                }
                        }
                }
                return "black";
        }
       
        public static String statusContagemAnterior(Date dataVerificar) {
                if (dataVerificar != null) {
                        Integer quantidadeDias = DataUtils.calcularDiferenceEmDiasEntreDuasDatas(DataUtils.getDataAtual(), dataVerificar);
                        if (quantidadeDias <= ConstantesSEC.StatusContagem.CONTAGEM_AMARELO_30_DIAS) return "green";
                        if (quantidadeDias <= ConstantesSEC.StatusContagem.CONTAGEM_VERMELHO_60_DIAS) return "orange";
                        if (quantidadeDias <= ConstantesSEC.StatusContagem.CONTAGEM_VERMELHO_CHEIO_90_DIAS) return "black";
                }
                return "black";
        }
       
        public static String estiloVendas(Double valor) {
                if (VerificadorUtil.naoEstaNulo(valor)) {
                        if (valor > new Double(1999)) return TipoCor.VERDE_PADRAO.getDescricao();
                        if (valor > new Double(999)) return TipoCor.AZUL_PADRAO.getDescricao();
                        if (valor > new Double(499)) return "orange";
                }
                return "black";
        }
       
        public static String estiloValor(Double valor) {
                if (valor >= 0) return TipoCor.VERDE_PADRAO.getDescricao();
                if (valor < 0) return TipoCor.VERMELHO_PADRAO.getDescricao();
                return TipoCor.AZUL_PADRAO.getDescricao();
        }
       
        public static Boolean dataEstaVencida(Date data) {
                Date dataVerificar = DataUtils.acrescentarDias(DataUtils.getDataAtual(), -1);
                return data.before(DataUtils.getDataComHorarioMaximo(dataVerificar));
        }

        public static String estiloVendasPorMeta(Double valorTotalVendasDoDia, Double valorMetaDiaria) {
                if (VerificadorUtil.naoEstaNulo(valorTotalVendasDoDia) && VerificadorUtil.naoEstaNulo(valorMetaDiaria)) {
                        if (valorTotalVendasDoDia >= valorMetaDiaria) return TipoCor.VERDE_PADRAO.getDescricao();
                        if (valorTotalVendasDoDia >= valorMetaDiaria * 0.8) return TipoCor.AZUL_PADRAO.getDescricao();
                        if (valorTotalVendasDoDia >= valorMetaDiaria * 0.5) return "orange";
                }
                return TipoCor.VERMELHO_PADRAO.getDescricao();
        }
       
        public static TipoCor corPorValor(Double valor) {
                if (valor >= 0) return TipoCor.VERDE_PADRAO;
                return TipoCor.VERMELHO_PADRAO;
        }
       
}