Details | Last modification | View Log | RSS feed
| Rev | Author | Line No. | Line |
|---|---|---|---|
| 598 | blopes | 1 | package br.com.ec.controller.managedbean; |
| 2 | |||
| 3 | import java.io.Serializable; |
||
| 4 | import java.util.ArrayList; |
||
| 5 | import java.util.Date; |
||
| 6 | import java.util.List; |
||
| 7 | |||
| 8 | import javax.inject.Inject; |
||
| 9 | import javax.inject.Named; |
||
| 10 | |||
| 11 | import org.springframework.context.annotation.Scope; |
||
| 12 | |||
| 13 | import br.com.ec.controller.util.UtilBean; |
||
| 14 | import br.com.ec.core.generic.GenericService; |
||
| 15 | import br.com.ec.core.util.DataUtils; |
||
| 16 | import br.com.ec.core.util.VerificadorUtil; |
||
| 17 | import br.com.ec.domain.dto.CockpitDTO; |
||
| 18 | import br.com.ec.domain.dto.RankingLojaDTO; |
||
| 19 | import br.com.ec.domain.dto.RankingVendedorDTO; |
||
| 20 | import br.com.ec.domain.model.Loja; |
||
| 21 | import br.com.ec.domain.service.loja.LojaService; |
||
| 22 | import br.com.ec.domain.service.perfil.PerfilService; |
||
| 23 | import br.com.ec.domain.service.usuario.UsuarioService; |
||
| 24 | import br.com.ec.domain.service.venda.VendaService; |
||
| 25 | import br.com.ec.domain.service.vendedor.VendedorService; |
||
| 26 | import br.com.ec.web.exception.VerificadorLancamentoException; |
||
| 27 | import br.com.ec.web.exception.VerificadorLancamentoException.CommandBean; |
||
| 28 | import br.com.ec.web.generic.AbstractBean; |
||
| 29 | |||
| 30 | @Named |
||
| 31 | @Scope("view") |
||
| 32 | public class RankingAcompanhamentoBean extends AbstractBean<CockpitDTO> implements Serializable { |
||
| 33 | |||
| 34 | private static final long serialVersionUID = 1L; |
||
| 35 | |||
| 36 | private VendaService vendaService; |
||
| 37 | private VendedorService vendedorService; |
||
| 38 | private LojaService lojaService; |
||
| 39 | private PerfilService perfilService; |
||
| 40 | private UsuarioService usuarioService; |
||
| 41 | private Date dataInicial; |
||
| 42 | private Date dataFinal; |
||
| 43 | |||
| 44 | private Double percentualVendidoMesAtual; |
||
| 45 | private Double percentualPercorridoMesAtual; |
||
| 46 | |||
| 47 | private Loja lojaParcial; |
||
| 48 | private Loja lojaVendedores; |
||
| 49 | private String parcialEmTexto; |
||
| 50 | |||
| 51 | @Inject |
||
| 52 | public RankingAcompanhamentoBean(VendaService vendaService, VendedorService vendedorService, LojaService lojaService, PerfilService perfilService, |
||
| 53 | UsuarioService usuarioService) { |
||
| 54 | this.vendaService = vendaService; |
||
| 55 | this.vendedorService = vendedorService; |
||
| 56 | this.lojaService = lojaService; |
||
| 57 | this.perfilService = perfilService; |
||
| 58 | this.usuarioService = usuarioService; |
||
| 59 | } |
||
| 60 | |||
| 61 | @Override |
||
| 62 | public void preCarregamento() { |
||
| 63 | setDataInicial(DataUtils.getPrimeiroDiaDoMesAtual()); |
||
| 64 | setDataFinal(DataUtils.getUltimoDiaDoMesAtual()); |
||
| 65 | preencherPercentuais(); |
||
| 66 | |||
| 67 | consultarRankings(); |
||
| 68 | } |
||
| 69 | |||
| 70 | @Override |
||
| 71 | public void limparEntidade() { |
||
| 72 | setEntidade(new CockpitDTO()); |
||
| 73 | } |
||
| 74 | |||
| 75 | @Override |
||
| 76 | public GenericService<CockpitDTO> getService() { |
||
| 77 | return null; |
||
| 78 | } |
||
| 79 | |||
| 80 | @Override |
||
| 81 | public CockpitDTO getEntidade() { |
||
| 82 | return entidade; |
||
| 83 | } |
||
| 84 | |||
| 85 | @Override |
||
| 86 | public CockpitDTO getId() { |
||
| 87 | return getEntidade(); |
||
| 88 | } |
||
| 89 | |||
| 90 | public String estiloValor(Double valor) { |
||
| 91 | return UtilBean.estiloValor(valor); |
||
| 92 | } |
||
| 93 | |||
| 94 | public Date getDataInicial() { |
||
| 95 | return dataInicial; |
||
| 96 | } |
||
| 97 | public void setDataInicial(Date dataInicial) { |
||
| 98 | this.dataInicial = dataInicial; |
||
| 99 | } |
||
| 100 | |||
| 101 | public Date getDataFinal() { |
||
| 102 | return dataFinal; |
||
| 103 | } |
||
| 104 | public void setDataFinal(Date dataFinal) { |
||
| 105 | this.dataFinal = dataFinal; |
||
| 106 | } |
||
| 107 | |||
| 108 | public Double getPercentualVendidoMesAtual() { |
||
| 109 | return percentualVendidoMesAtual; |
||
| 110 | } |
||
| 111 | public void setPercentualVendidoMesAtual(Double percentualVendidoMesAtual) { |
||
| 112 | this.percentualVendidoMesAtual = percentualVendidoMesAtual; |
||
| 113 | } |
||
| 114 | |||
| 115 | public Double getPercentualPercorridoMesAtual() { |
||
| 116 | return percentualPercorridoMesAtual; |
||
| 117 | } |
||
| 118 | public void setPercentualPercorridoMesAtual(Double percentualPercorridoMesAtual) { |
||
| 119 | this.percentualPercorridoMesAtual = percentualPercorridoMesAtual; |
||
| 120 | } |
||
| 121 | |||
| 122 | public Loja getLojaParcial() { |
||
| 123 | return lojaParcial; |
||
| 124 | } |
||
| 125 | public void setLojaParcial(Loja lojaParcial) { |
||
| 126 | this.lojaParcial = lojaParcial; |
||
| 127 | } |
||
| 128 | |||
| 129 | public Loja getLojaVendedores() { |
||
| 130 | return lojaVendedores; |
||
| 131 | } |
||
| 132 | public void setLojaVendedores(Loja lojaVendedores) { |
||
| 133 | this.lojaVendedores = lojaVendedores; |
||
| 134 | } |
||
| 135 | |||
| 136 | public String getParcialEmTexto() { |
||
| 137 | return parcialEmTexto; |
||
| 138 | } |
||
| 139 | public void setParcialEmTexto(String parcialEmTexto) { |
||
| 140 | this.parcialEmTexto = parcialEmTexto; |
||
| 141 | } |
||
| 142 | |||
| 143 | public void consultarRankingVendedores() { |
||
| 144 | if (VerificadorUtil.estaNulo(getEntidade())) { |
||
| 145 | entidade = new CockpitDTO(); |
||
| 146 | } |
||
| 147 | List<RankingVendedorDTO> rankingVendedor = new ArrayList<RankingVendedorDTO>(); |
||
| 148 | List<RankingVendedorDTO> ranking = vendaService.consultarRankingVendedores(dataInicial, dataFinal, true, getLojaVendedores()); |
||
| 149 | for (RankingVendedorDTO vendedor : ranking) { |
||
| 150 | if (vendedor.getValorTotalVendido() > new Double(0.0)) { |
||
| 151 | rankingVendedor.add(vendedor); |
||
| 152 | } |
||
| 153 | } |
||
| 154 | entidade.setRankingVendedores(rankingVendedor); |
||
| 155 | } |
||
| 156 | |||
| 157 | public void consultarRankingLojas() { |
||
| 158 | if (VerificadorUtil.estaNulo(getEntidade())) { |
||
| 159 | entidade = new CockpitDTO(); |
||
| 160 | } |
||
| 161 | entidade.setRankingLojas(vendaService.consultarRankingLojas(getDataInicial(), getDataFinal())); |
||
| 162 | Double valorTotalVendido = new Double(0.0); |
||
| 163 | for (RankingLojaDTO rankingLoja : entidade.getRankingLojas()) { |
||
| 164 | valorTotalVendido = valorTotalVendido + rankingLoja.getValorTotalVendido(); |
||
| 165 | } |
||
| 166 | setPercentualVendidoMesAtual(new Double(valorTotalVendido/entidade.getValorTotalMeta())); |
||
| 167 | } |
||
| 168 | |||
| 169 | private void preencherPercentuais() { |
||
| 170 | Integer ultimoDiaDoMes = DataUtils.getUltimoDiaDoMesAtual().getDate(); |
||
| 171 | Integer diaAtual = DataUtils.getDataAtual().getDate(); |
||
| 172 | setPercentualPercorridoMesAtual(new Double(100*diaAtual/ultimoDiaDoMes)); |
||
| 173 | } |
||
| 174 | |||
| 175 | public void consultarRankings() { |
||
| 176 | new VerificadorLancamentoException().tratarIhRelancarExcecaoSemLimparEntidade(new CommandBean() { |
||
| 177 | public void execute() { |
||
| 178 | consultarRankingVendedores(); |
||
| 179 | consultarRankingLojas(); |
||
| 180 | } |
||
| 181 | }); |
||
| 182 | } |
||
| 183 | |||
| 184 | public RankingVendedorDTO retornarVendedorPelaColocacao(Integer colocacaoVendedor) { |
||
| 185 | Integer colocacao = 1; |
||
| 186 | for (RankingVendedorDTO rankingVendedorDTO : entidade.getRankingVendedores()) { |
||
| 187 | if (colocacao.equals(colocacaoVendedor)) { |
||
| 188 | rankingVendedorDTO.setUsuario(usuarioService.consultarUsuarioPorPessoa(rankingVendedorDTO.getVendedor().getPessoa())); |
||
| 189 | return rankingVendedorDTO; |
||
| 190 | } |
||
| 191 | colocacao++; |
||
| 192 | } |
||
| 193 | return null; |
||
| 194 | } |
||
| 195 | |||
| 196 | public RankingLojaDTO retornarLojaPelaColocacao(Integer colocacaoLoja) { |
||
| 197 | Integer colocacao = 1; |
||
| 198 | for (RankingLojaDTO rankingLojaDTO : entidade.getRankingLojas()) { |
||
| 199 | if (colocacao.equals(colocacaoLoja)) { |
||
| 200 | return rankingLojaDTO; |
||
| 201 | } |
||
| 202 | colocacao++; |
||
| 203 | } |
||
| 204 | return null; |
||
| 205 | } |
||
| 206 | |||
| 207 | } |