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