Rev 159 | Details | Compare with Previous | Last modification | View Log | RSS feed
| Rev | Author | Line No. | Line |
|---|---|---|---|
| 106 | espaco | 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 | |||
| 195 | espaco | 13 | import br.com.ec.core.consulta.ParametrosConsulta; |
| 14 | import br.com.ec.core.generic.GenericService; |
||
| 15 | import br.com.ec.core.util.DataUtils; |
||
| 16 | import br.com.ec.core.util.VerificadorUtil; |
||
| 106 | espaco | 17 | import br.com.ec.domain.dto.FluxoDeCaixaDTO; |
| 18 | import br.com.ec.domain.dto.QuadroResumosDTO; |
||
| 121 | espaco | 19 | import br.com.ec.domain.dto.RankingLojaDTO; |
| 106 | espaco | 20 | import br.com.ec.domain.model.AvaliacaoLoja; |
| 21 | import br.com.ec.domain.model.Loja; |
||
| 22 | import br.com.ec.domain.service.acompanhamento.AcompanhamentoService; |
||
| 23 | import br.com.ec.domain.service.avaliacaoloja.AvaliacaoLojaService; |
||
| 24 | import br.com.ec.domain.service.loja.LojaService; |
||
| 121 | espaco | 25 | import br.com.ec.domain.service.venda.VendaService; |
| 195 | espaco | 26 | import br.com.ec.web.generic.AbstractBean; |
| 106 | espaco | 27 | |
| 28 | @Named |
||
| 29 | @Scope("view") |
||
| 30 | public class QuadroResumoBean extends AbstractBean<QuadroResumosDTO> implements Serializable { |
||
| 31 | |||
| 32 | private static final long serialVersionUID = 1L; |
||
| 33 | |||
| 34 | private Date dataInicial; |
||
| 35 | private Date dataFinal; |
||
| 36 | |||
| 121 | espaco | 37 | private List<RankingLojaDTO> rankingLojas; |
| 38 | |||
| 106 | espaco | 39 | private FluxoDeCaixaDTO fluxoMatriz; |
| 40 | private List<FluxoDeCaixaDTO> fluxosDeCaixa; |
||
| 41 | |||
| 121 | espaco | 42 | private VendaService vendaService; |
| 43 | |||
| 106 | espaco | 44 | private LojaService lojaService; |
| 45 | private AcompanhamentoService acompanhamentoService; |
||
| 46 | private AvaliacaoLojaService avaliacaoLojaService; |
||
| 47 | |||
| 48 | @Inject |
||
| 121 | espaco | 49 | public QuadroResumoBean(VendaService vendaService, LojaService lojaService, AcompanhamentoService acompanhamentoService, |
| 50 | AvaliacaoLojaService avaliacaoLojaService) { |
||
| 51 | this.vendaService = vendaService; |
||
| 106 | espaco | 52 | this.lojaService = lojaService; |
| 53 | this.acompanhamentoService = acompanhamentoService; |
||
| 54 | this.avaliacaoLojaService = avaliacaoLojaService; |
||
| 55 | } |
||
| 56 | |||
| 57 | @Override |
||
| 58 | public void preCarregamento() { |
||
| 59 | try { |
||
| 60 | if (VerificadorUtil.estaNulo(parametrosConsulta)) { |
||
| 61 | entidade = new QuadroResumosDTO(); |
||
| 62 | parametrosConsulta = new ParametrosConsulta<QuadroResumosDTO>(); |
||
| 63 | parametrosConsulta.setEntidade(entidade); |
||
| 64 | } |
||
| 65 | setDataInicial(DataUtils.getPrimeiroDiaDoMesAtual()); |
||
| 66 | setDataFinal(DataUtils.getUltimoDiaDoMesAtual()); |
||
| 67 | consultarQuadroResumos(); |
||
| 68 | } catch (Exception e) { |
||
| 69 | e.printStackTrace(); |
||
| 70 | } |
||
| 71 | } |
||
| 72 | |||
| 73 | @Override |
||
| 74 | public GenericService<QuadroResumosDTO> getService() { |
||
| 75 | return null; |
||
| 76 | } |
||
| 77 | |||
| 78 | @Override |
||
| 79 | public void limparEntidade() { |
||
| 80 | setEntidade(new QuadroResumosDTO()); |
||
| 81 | } |
||
| 82 | |||
| 83 | @Override |
||
| 84 | public QuadroResumosDTO getEntidade() { |
||
| 85 | return entidade; |
||
| 86 | } |
||
| 87 | |||
| 88 | @Override |
||
| 89 | public QuadroResumosDTO getId() { |
||
| 90 | return getEntidade(); |
||
| 91 | } |
||
| 92 | |||
| 93 | public Date getDataInicial() { |
||
| 94 | return dataInicial; |
||
| 95 | } |
||
| 96 | public void setDataInicial(Date dataInicial) { |
||
| 97 | this.dataInicial = dataInicial; |
||
| 98 | } |
||
| 99 | |||
| 100 | public Date getDataFinal() { |
||
| 101 | return dataFinal; |
||
| 102 | } |
||
| 103 | public void setDataFinal(Date dataFinal) { |
||
| 104 | this.dataFinal = dataFinal; |
||
| 105 | } |
||
| 106 | |||
| 121 | espaco | 107 | public List<RankingLojaDTO> getRankingLojas() { |
| 108 | return rankingLojas; |
||
| 109 | } |
||
| 110 | public void setRankingLojas(List<RankingLojaDTO> rankingLojas) { |
||
| 111 | this.rankingLojas = rankingLojas; |
||
| 112 | } |
||
| 113 | |||
| 106 | espaco | 114 | public FluxoDeCaixaDTO getFluxoMatriz() { |
| 115 | return fluxoMatriz; |
||
| 116 | } |
||
| 117 | public void setFluxoMatriz(FluxoDeCaixaDTO fluxoMatriz) { |
||
| 118 | this.fluxoMatriz = fluxoMatriz; |
||
| 119 | } |
||
| 120 | |||
| 121 | public List<FluxoDeCaixaDTO> getFluxosDeCaixa() { |
||
| 122 | return fluxosDeCaixa; |
||
| 123 | } |
||
| 124 | public void setFluxosDeCaixa(List<FluxoDeCaixaDTO> fluxosDeCaixa) { |
||
| 125 | this.fluxosDeCaixa = fluxosDeCaixa; |
||
| 126 | } |
||
| 127 | |||
| 128 | /********************************************************************/ |
||
| 129 | |||
| 130 | public void consultarQuadroResumos() { |
||
| 121 | espaco | 131 | setRankingLojas(vendaService.consultarRankingLojasCompleto(getDataInicial(), getDataFinal())); |
| 132 | } |
||
| 133 | |||
| 134 | public Double valorTotalVendas() { |
||
| 135 | Double valorTotal = 0.0; |
||
| 136 | for (RankingLojaDTO rankingLoja : getRankingLojas()) { |
||
| 137 | if (VerificadorUtil.naoEstaNulo(rankingLoja.getValorTotalVendido())) { |
||
| 138 | if (rankingLoja.getValorTotalVendido() > 0.0) { |
||
| 139 | valorTotal = valorTotal + rankingLoja.getValorTotalVendido(); |
||
| 140 | } |
||
| 141 | } |
||
| 142 | } |
||
| 143 | return valorTotal; |
||
| 144 | } |
||
| 145 | |||
| 146 | public Double valorTotalMetas() { |
||
| 147 | Double valorTotal = 0.0; |
||
| 148 | for (RankingLojaDTO rankingLoja : getRankingLojas()) { |
||
| 149 | if (VerificadorUtil.naoEstaNulo(rankingLoja.getValorMetaMensal())) { |
||
| 150 | if (rankingLoja.getValorMetaMensal() > 0.0) { |
||
| 151 | valorTotal = valorTotal + rankingLoja.getValorMetaMensal(); |
||
| 152 | } |
||
| 153 | } |
||
| 154 | } |
||
| 155 | return valorTotal; |
||
| 156 | } |
||
| 157 | |||
| 158 | public Double valorMedioTicketMedio() { |
||
| 159 | Double valorTotal = 0.0; |
||
| 160 | Integer quantidadeSomas = 0; |
||
| 161 | for (RankingLojaDTO rankingLoja : getRankingLojas()) { |
||
| 162 | if (VerificadorUtil.naoEstaNulo(rankingLoja.valorTicketMedio())) { |
||
| 163 | if (rankingLoja.valorTicketMedio() > 0.0) { |
||
| 164 | quantidadeSomas++; |
||
| 165 | valorTotal = valorTotal + rankingLoja.valorTicketMedio(); |
||
| 166 | } |
||
| 167 | } |
||
| 168 | } |
||
| 169 | return valorTotal / quantidadeSomas; |
||
| 170 | } |
||
| 171 | |||
| 172 | public Integer quantidadeTotalAtendimentos() { |
||
| 173 | Integer valorTotal = 0; |
||
| 174 | for (RankingLojaDTO rankingLoja : getRankingLojas()) { |
||
| 175 | if (VerificadorUtil.naoEstaNulo(rankingLoja.getQuantidadeAtendimentos())) { |
||
| 176 | if (rankingLoja.getQuantidadeAtendimentos() > 0.0) { |
||
| 177 | valorTotal = valorTotal + rankingLoja.getQuantidadeAtendimentos(); |
||
| 178 | } |
||
| 179 | } |
||
| 180 | } |
||
| 181 | return valorTotal; |
||
| 182 | } |
||
| 183 | |||
| 184 | public Integer quantidadeTotalPedidos() { |
||
| 185 | Integer valorTotal = 0; |
||
| 186 | for (RankingLojaDTO rankingLoja : getRankingLojas()) { |
||
| 187 | if (VerificadorUtil.naoEstaNulo(rankingLoja.getQuantidadePedidos())) { |
||
| 188 | if (rankingLoja.getQuantidadePedidos() > 0.0) { |
||
| 189 | valorTotal = valorTotal + rankingLoja.getQuantidadePedidos(); |
||
| 190 | } |
||
| 191 | } |
||
| 192 | } |
||
| 193 | return valorTotal; |
||
| 194 | } |
||
| 195 | |||
| 196 | public Integer quantidadeTotalPedidosInvalidos() { |
||
| 197 | Integer valorTotal = 0; |
||
| 198 | for (RankingLojaDTO rankingLoja : getRankingLojas()) { |
||
| 199 | if (VerificadorUtil.naoEstaNulo(rankingLoja.getQuantidadePedidosInvalidos())) { |
||
| 200 | if (rankingLoja.getQuantidadePedidosInvalidos() > 0.0) { |
||
| 201 | valorTotal = valorTotal + rankingLoja.getQuantidadePedidosInvalidos(); |
||
| 202 | } |
||
| 203 | } |
||
| 204 | } |
||
| 205 | return valorTotal; |
||
| 206 | } |
||
| 207 | |||
| 208 | public Integer quantidadeTotalAvarias() { |
||
| 209 | Integer valorTotal = 0; |
||
| 210 | for (RankingLojaDTO rankingLoja : getRankingLojas()) { |
||
| 211 | if (VerificadorUtil.naoEstaNulo(rankingLoja.getQuantidadeAvarias())) { |
||
| 212 | if (rankingLoja.getQuantidadeAvarias() > 0.0) { |
||
| 213 | valorTotal = valorTotal + rankingLoja.getQuantidadeAvarias(); |
||
| 214 | } |
||
| 215 | } |
||
| 216 | } |
||
| 217 | return valorTotal; |
||
| 218 | } |
||
| 219 | |||
| 220 | public Integer quantidadeTotalTrocas() { |
||
| 221 | Integer valorTotal = 0; |
||
| 222 | for (RankingLojaDTO rankingLoja : getRankingLojas()) { |
||
| 223 | if (VerificadorUtil.naoEstaNulo(rankingLoja.getQuantidadeTrocas())) { |
||
| 224 | if (rankingLoja.getQuantidadeTrocas() > 0.0) { |
||
| 225 | valorTotal = valorTotal + rankingLoja.getQuantidadeTrocas(); |
||
| 226 | } |
||
| 227 | } |
||
| 228 | } |
||
| 229 | return valorTotal; |
||
| 230 | } |
||
| 231 | |||
| 232 | public Double valorTotalPercentualDescontos() { |
||
| 233 | Double valorTotal = valorTotalDescontos(); |
||
| 234 | if (valorTotal > 0.0) { |
||
| 235 | return (valorTotal * 100) / valorTotalVendas(); |
||
| 236 | } |
||
| 237 | return 0.0; |
||
| 238 | } |
||
| 239 | |||
| 240 | public Double valorTotalDescontos() { |
||
| 241 | Double valorTotal = 0.0; |
||
| 242 | for (RankingLojaDTO rankingLoja : getRankingLojas()) { |
||
| 243 | if (VerificadorUtil.naoEstaNulo(rankingLoja.getValorTotalDescontos())) { |
||
| 244 | if (rankingLoja.getValorTotalDescontos() > 0.0) { |
||
| 245 | valorTotal = valorTotal + rankingLoja.getValorTotalDescontos(); |
||
| 246 | } |
||
| 247 | } |
||
| 248 | } |
||
| 249 | return valorTotal; |
||
| 250 | } |
||
| 251 | |||
| 252 | public Double valorTotalCustoProdutosVendidos() { |
||
| 253 | Double valorTotal = 0.0; |
||
| 254 | for (RankingLojaDTO rankingLoja : getRankingLojas()) { |
||
| 255 | if (VerificadorUtil.naoEstaNulo(rankingLoja.getCustoProdutosVendidos())) { |
||
| 256 | if (rankingLoja.getCustoProdutosVendidos() > 0.0) { |
||
| 257 | valorTotal = valorTotal + rankingLoja.getCustoProdutosVendidos(); |
||
| 258 | } |
||
| 259 | } |
||
| 260 | } |
||
| 261 | return valorTotal; |
||
| 262 | } |
||
| 263 | |||
| 122 | espaco | 264 | public Integer quantidadeTotalPatrimonioAtual() { |
| 265 | Integer valorTotal = 0; |
||
| 266 | for (RankingLojaDTO rankingLoja : getRankingLojas()) { |
||
| 267 | if (VerificadorUtil.naoEstaNulo(rankingLoja.getQuantidadeTotalEstoque())) { |
||
| 268 | if (rankingLoja.getQuantidadeTotalEstoque() > 0.0) { |
||
| 269 | valorTotal = valorTotal + rankingLoja.getQuantidadeTotalEstoque(); |
||
| 270 | } |
||
| 271 | } |
||
| 272 | } |
||
| 273 | return valorTotal; |
||
| 274 | } |
||
| 275 | |||
| 121 | espaco | 276 | public Double valorTotalPatrimonioAtual() { |
| 277 | Double valorTotal = 0.0; |
||
| 278 | for (RankingLojaDTO rankingLoja : getRankingLojas()) { |
||
| 279 | if (VerificadorUtil.naoEstaNulo(rankingLoja.getValorTotalEstoque())) { |
||
| 280 | if (rankingLoja.getValorTotalEstoque() > 0.0) { |
||
| 281 | valorTotal = valorTotal + rankingLoja.getValorTotalEstoque(); |
||
| 282 | } |
||
| 283 | } |
||
| 284 | } |
||
| 285 | return valorTotal; |
||
| 286 | } |
||
| 287 | |||
| 288 | public void consultarQuadroResumosOld() { |
||
| 106 | espaco | 289 | fluxoMatriz = new FluxoDeCaixaDTO(); |
| 290 | fluxoMatriz.setDataInicial(getDataInicial()); |
||
| 291 | fluxoMatriz.setDataFinal(getDataFinal()); |
||
| 292 | fluxoMatriz = acompanhamentoService.consultarFluxoDeCaixa(fluxoMatriz); |
||
| 293 | |||
| 294 | fluxosDeCaixa = new ArrayList<FluxoDeCaixaDTO>(); |
||
| 295 | List<Loja> lojasAtivas = lojaService.listarLojasAtivas(); |
||
| 296 | for (Loja lojaAtiva : lojasAtivas) { |
||
| 297 | FluxoDeCaixaDTO fluxoCaixa = new FluxoDeCaixaDTO(); |
||
| 298 | fluxoCaixa.setCentroDeCustos(lojaAtiva); |
||
| 299 | fluxoCaixa.setDataInicial(getDataInicial()); |
||
| 300 | fluxoCaixa.setDataFinal(getDataFinal()); |
||
| 301 | fluxoCaixa.setValorMetaMensal(0.0); |
||
| 302 | fluxoCaixa.setValorMargemContribuicao(0.0); |
||
| 303 | |||
| 304 | AvaliacaoLoja avaliacaoLoja = avaliacaoLojaService.consultarAvaliacaoLojaPelaData(lojaAtiva, getDataFinal()); |
||
| 305 | if (VerificadorUtil.naoEstaNulo(avaliacaoLoja)) { |
||
| 306 | if (VerificadorUtil.naoEstaNulo(avaliacaoLoja.getValorMetaMensal())) { |
||
| 307 | fluxoCaixa.setValorMetaMensal(avaliacaoLoja.getValorMetaMensal()); |
||
| 308 | } |
||
| 309 | if (VerificadorUtil.naoEstaNulo(avaliacaoLoja.getValorMargemContribuicao())) { |
||
| 310 | fluxoCaixa.setValorMargemContribuicao(avaliacaoLoja.getValorMargemContribuicao()); |
||
| 311 | } |
||
| 312 | } |
||
| 313 | fluxoCaixa = acompanhamentoService.consultarFluxoDeCaixa(fluxoCaixa); |
||
| 314 | fluxosDeCaixa.add(fluxoCaixa); |
||
| 315 | } |
||
| 316 | } |
||
| 317 | |||
| 318 | public Double getValorTotalFluxo() { |
||
| 319 | Double totalFluxo = new Double(0); |
||
| 320 | for (FluxoDeCaixaDTO fluxoCaixa : fluxosDeCaixa) { |
||
| 321 | if (VerificadorUtil.naoEstaNulo(fluxoCaixa.getValorTotalFluxo())) { |
||
| 322 | totalFluxo = totalFluxo + fluxoCaixa.getValorTotalFluxo(); |
||
| 323 | } |
||
| 324 | } |
||
| 325 | return totalFluxo; |
||
| 326 | } |
||
| 327 | |||
| 328 | public Double getValorTotalMargemContribuicao() { |
||
| 329 | Double totalMargemContribuicao = new Double(0); |
||
| 330 | for (FluxoDeCaixaDTO fluxoCaixa : fluxosDeCaixa) { |
||
| 331 | if (VerificadorUtil.naoEstaNulo(fluxoCaixa.getCentroDeCustos())) { |
||
| 332 | totalMargemContribuicao = totalMargemContribuicao + fluxoCaixa.getValorMargemContribuicao(); |
||
| 333 | } |
||
| 334 | } |
||
| 335 | return totalMargemContribuicao; |
||
| 336 | } |
||
| 337 | |||
| 338 | public Double calcularValorTotalMargemContribuicao() { |
||
| 339 | Double totalMargemContribuicao = new Double(0); |
||
| 340 | for (FluxoDeCaixaDTO fluxoCaixa : fluxosDeCaixa) { |
||
| 341 | totalMargemContribuicao = totalMargemContribuicao + fluxoCaixa.calcularValorMargemContribuicao(fluxoMatriz.getValorTotalFluxo()); |
||
| 342 | } |
||
| 343 | return totalMargemContribuicao; |
||
| 344 | } |
||
| 345 | |||
| 346 | public Double calcularValorTotalFluxoComMargemContribuicao() { |
||
| 347 | Double totalFluxoComMargemContribuicao = new Double(0); |
||
| 348 | for (FluxoDeCaixaDTO fluxoCaixa : fluxosDeCaixa) { |
||
| 349 | totalFluxoComMargemContribuicao = totalFluxoComMargemContribuicao + fluxoCaixa.calcularValorFluxoComMargemContribuicao(fluxoMatriz.getValorTotalFluxo()); |
||
| 350 | } |
||
| 351 | return totalFluxoComMargemContribuicao; |
||
| 352 | } |
||
| 353 | |||
| 354 | public Double getValorTotalProdutosUtilizados() { |
||
| 355 | Double totalProdutosUtilizados = new Double(0); |
||
| 356 | for (FluxoDeCaixaDTO fluxoCaixa : fluxosDeCaixa) { |
||
| 357 | if (VerificadorUtil.naoEstaNulo(fluxoCaixa.getValorTotalProdutosUtilizados())) { |
||
| 358 | totalProdutosUtilizados = totalProdutosUtilizados + fluxoCaixa.getValorTotalProdutosUtilizados(); |
||
| 359 | } |
||
| 360 | } |
||
| 361 | return totalProdutosUtilizados; |
||
| 362 | } |
||
| 363 | |||
| 364 | } |