Rev 267 | Rev 274 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
| Rev 267 | Rev 268 | ||
|---|---|---|---|
| Line 18... | Line 18... | ||
| 18 | import org.primefaces.model.charts.optionconfig.title.Title; |
18 | import org.primefaces.model.charts.optionconfig.title.Title; |
| 19 | import org.primefaces.model.charts.pie.PieChartDataSet; |
19 | import org.primefaces.model.charts.pie.PieChartDataSet; |
| 20 | import org.primefaces.model.charts.pie.PieChartModel; |
20 | import org.primefaces.model.charts.pie.PieChartModel; |
| 21 | import org.springframework.beans.factory.annotation.Autowired; |
21 | import org.springframework.beans.factory.annotation.Autowired; |
| 22 | import org.springframework.stereotype.Service; |
22 | import org.springframework.stereotype.Service; |
| - | 23 | ||
| - | 24 | import com.mchange.lang.DoubleUtils; |
|
| 23 | 25 | ||
| 24 | import br.com.ec.core.generic.AbstractService; |
26 | import br.com.ec.core.generic.AbstractService; |
| 25 | import br.com.ec.core.generic.GenericRepository; |
27 | import br.com.ec.core.generic.GenericRepository; |
| 26 | import br.com.ec.core.util.DataUtils; |
28 | import br.com.ec.core.util.DataUtils; |
| - | 29 | import br.com.ec.core.util.StringUtil; |
|
| 27 | import br.com.ec.core.util.VerificadorUtil; |
30 | import br.com.ec.core.util.VerificadorUtil; |
| 28 | import br.com.ec.core.validador.Validador; |
31 | import br.com.ec.core.validador.Validador; |
| - | 32 | import br.com.ec.domain.dto.AvaliacaoFuncionarioDTO; |
|
| 29 | import br.com.ec.domain.dto.consulta.ParametrosConsultaVendasDTO; |
33 | import br.com.ec.domain.dto.consulta.ParametrosConsultaVendasDTO; |
| 30 | import br.com.ec.domain.dto.grafico.GraficoBarraDTO; |
34 | import br.com.ec.domain.dto.grafico.GraficoBarraDTO; |
| 31 | import br.com.ec.domain.dto.grafico.GraficoDTO; |
35 | import br.com.ec.domain.dto.grafico.GraficoDTO; |
| 32 | import br.com.ec.domain.dto.grafico.GraficoDadoDTO; |
36 | import br.com.ec.domain.dto.grafico.GraficoDadoDTO; |
| 33 | import br.com.ec.domain.dto.grafico.GraficoPizzaDTO; |
37 | import br.com.ec.domain.dto.grafico.GraficoPizzaDTO; |
| - | 38 | import br.com.ec.domain.service.AvaliacaoFuncionarioService; |
|
| 34 | import br.com.ec.domain.service.GraficoService; |
39 | import br.com.ec.domain.service.GraficoService; |
| 35 | import br.com.ec.domain.service.VendaService; |
40 | import br.com.ec.domain.service.VendaService; |
| 36 | 41 | ||
| 37 | @Service |
42 | @Service |
| 38 | public class GraficoServiceImpl extends AbstractService<GraficoDTO> implements GraficoService { |
43 | public class GraficoServiceImpl extends AbstractService<GraficoDTO> implements GraficoService { |
| 39 | 44 | ||
| 40 | private VendaService vendaService; |
45 | private VendaService vendaService; |
| - | 46 | private AvaliacaoFuncionarioService avaliacaoFuncionarioService; |
|
| 41 | 47 | ||
| 42 | @Autowired |
48 | @Autowired |
| 43 | public GraficoServiceImpl(Validador validador, VendaService vendaService) { |
- | |
| - | 49 | public GraficoServiceImpl(Validador validador, VendaService vendaService, AvaliacaoFuncionarioService avaliacaoFuncionarioService) { |
|
| 44 | super(validador); |
50 | super(validador); |
| 45 | this.vendaService = vendaService; |
51 | this.vendaService = vendaService; |
| - | 52 | this.avaliacaoFuncionarioService = avaliacaoFuncionarioService; |
|
| 46 | }
|
53 | }
|
| 47 | 54 | ||
| 48 | @Override |
55 | @Override |
| 49 | protected GenericRepository<GraficoDTO> getRepository() { |
56 | protected GenericRepository<GraficoDTO> getRepository() { |
| 50 | return null; |
57 | return null; |
| 51 | }
|
58 | }
|
| 52 | 59 | ||
| 53 | @Override |
60 | @Override |
| 54 | public GraficoBarraDTO gerarGraficoVendas(ParametrosConsultaVendasDTO parametrosConsulta, ParametrosConsultaVendasDTO parametrosConsultaComparativo) { |
61 | public GraficoBarraDTO gerarGraficoVendas(ParametrosConsultaVendasDTO parametrosConsulta, ParametrosConsultaVendasDTO parametrosConsultaComparativo) { |
| 55 | GraficoBarraDTO graficoDTO = new GraficoBarraDTO(); |
62 | GraficoBarraDTO graficoDTO = new GraficoBarraDTO(); |
| - | 63 | graficoDTO.setParametrosConsulta(parametrosConsulta); |
|
| 56 | if (parametrosConsulta.getParametrosPeriodoDTO().tipoPeriodoEhPorDia()) { |
64 | if (parametrosConsulta.getParametrosPeriodoDTO().tipoPeriodoEhPorDia()) { |
| 57 | graficoDTO.setDados(preencherDadosComPeriodoEhPorDia(parametrosConsulta, "rgba(75, 192, 192, 0.2)", "rgb(75, 192, 192)")); |
65 | graficoDTO.setDados(preencherDadosComPeriodoEhPorDia(parametrosConsulta, "rgba(75, 192, 192, 0.2)", "rgb(75, 192, 192)")); |
| 58 | graficoDTO.setTitulo("VENDAS POR DIA"); |
66 | graficoDTO.setTitulo("VENDAS POR DIA"); |
| 59 | }
|
67 | }
|
| 60 | if (parametrosConsulta.getParametrosPeriodoDTO().tipoPeriodoEhPorMes()) { |
68 | if (parametrosConsulta.getParametrosPeriodoDTO().tipoPeriodoEhPorMes()) { |
| Line 67... | Line 75... | ||
| 67 | }
|
75 | }
|
| 68 | if (parametrosConsulta.getParametrosPeriodoDTO().tipoPeriodoEhUltimosSeisMeses() || |
76 | if (parametrosConsulta.getParametrosPeriodoDTO().tipoPeriodoEhUltimosSeisMeses() || |
| 69 | parametrosConsulta.getParametrosPeriodoDTO().tipoPeriodoEhUltimosDozeMeses()) { |
77 | parametrosConsulta.getParametrosPeriodoDTO().tipoPeriodoEhUltimosDozeMeses()) { |
| 70 | graficoDTO.setDados(preencherDadosComPeriodoEhUltimosSeisOuDozeMeses(parametrosConsulta, "rgba(75, 192, 192, 0.2)", "rgb(75, 192, 192)")); |
78 | graficoDTO.setDados(preencherDadosComPeriodoEhUltimosSeisOuDozeMeses(parametrosConsulta, "rgba(75, 192, 192, 0.2)", "rgb(75, 192, 192)")); |
| 71 | graficoDTO.setTitulo("VENDAS PELOS ÚLTIMOS MESES"); |
79 | graficoDTO.setTitulo("VENDAS PELOS ÚLTIMOS MESES"); |
| 72 | /*
|
- | |
| 73 | if (VerificadorUtil.naoEstaNulo(parametrosRelatorioVendas.getVendedor())) {
|
- | |
| 74 | consultarHistoricoPercentual(parametrosRelatorioVendas);
|
- | |
| 75 | }
|
- | |
| 76 | */
|
- | |
| 77 | }
|
80 | }
|
| 78 | 81 | ||
| 79 | BarChartDataSet barDataSet = new BarChartDataSet(); |
82 | BarChartDataSet barDataSet = new BarChartDataSet(); |
| 80 | barDataSet.setLabel(""); |
83 | barDataSet.setLabel(""); |
| 81 | barDataSet.setData(graficoDTO.getDados().getValores()); |
84 | barDataSet.setData(graficoDTO.getDados().getValores()); |
| Line 235... | Line 238... | ||
| 235 | String descricaoLinha = mesAtual.toString() + "/" + anoAtual; |
238 | String descricaoLinha = mesAtual.toString() + "/" + anoAtual; |
| 236 | mesAtual++;
|
239 | mesAtual++;
|
| 237 | dados.adicionarDados(valorAcumulado, cor, corBorda, "" + descricaoLinha); |
240 | dados.adicionarDados(valorAcumulado, cor, corBorda, "" + descricaoLinha); |
| 238 | }
|
241 | }
|
| 239 | return dados; |
242 | return dados; |
| - | 243 | }
|
|
| - | 244 | ||
| - | 245 | @Override |
|
| - | 246 | public GraficoBarraDTO gerarGraficoPercentuaisMeta(ParametrosConsultaVendasDTO parametrosConsulta) { |
|
| - | 247 | GraficoBarraDTO graficoDTO = new GraficoBarraDTO(); |
|
| - | 248 | graficoDTO.setParametrosConsulta(parametrosConsulta); |
|
| - | 249 | if (parametrosConsulta.getParametrosPeriodoDTO().tipoPeriodoEhPorMes()) { |
|
| - | 250 | GraficoDadoDTO dados = new GraficoDadoDTO(); |
|
| - | 251 | for (int mes = 1; mes <= 12; mes++) { |
|
| - | 252 | Double valorAcumulado = new Double(0.0); |
|
| - | 253 | Calendar dataInicial = DataUtils.obterCalendario(DataUtils.obterData(1, new Integer(mes)-1, new Integer(parametrosConsulta.getParametrosPeriodoDTO().getAno()))); |
|
| - | 254 | int qntMaximaDias = dataInicial.getActualMaximum(Calendar.DAY_OF_MONTH); |
|
| - | 255 | Calendar dataFinal = DataUtils.obterCalendario(DataUtils.obterData(qntMaximaDias, new Integer(mes)-1, new Integer(parametrosConsulta.getParametrosPeriodoDTO().getAno()))); |
|
| - | 256 | parametrosConsulta.getParametrosPeriodoDTO().setDataInicial(dataInicial.getTime()); |
|
| - | 257 | parametrosConsulta.getParametrosPeriodoDTO().setDataFinal(dataFinal.getTime()); |
|
| - | 258 | valorAcumulado = vendaService.obterValorTotalBrutoDeVendasPorLojaEePeriodoEeFormasDePagamento(parametrosConsulta, null); |
|
| - | 259 | ||
| - | 260 | AvaliacaoFuncionarioDTO avaliacaoFuncionarioDTO = new AvaliacaoFuncionarioDTO(); |
|
| - | 261 | avaliacaoFuncionarioDTO.setValorTotalVendido(valorAcumulado); |
|
| - | 262 | avaliacaoFuncionarioDTO.setValorMetaMensal(avaliacaoFuncionarioService.consultarMetaMensalPelaData(parametrosConsulta.getVendedorSelecionado().getSequencialPessoa(), DataUtils.getDataComHorarioMinimo(parametrosConsulta.getParametrosPeriodoDTO().getDataFinal()))); |
|
| - | 263 | Double valorParaFormatar = avaliacaoFuncionarioDTO.retornarPercentualRealizado() * 100; |
|
| - | 264 | dados.adicionarDados(valorParaFormatar.intValue(), "rgba(75, 192, 192, 0.2)", "rgb(75, 192, 192)", "" + mes); |
|
| - | 265 | }
|
|
| - | 266 | ||
| - | 267 | graficoDTO.setDados(dados); |
|
| - | 268 | graficoDTO.setTitulo("PERCENTUAIS DA META POR MÊS"); |
|
| - | 269 | }
|
|
| - | 270 | if (parametrosConsulta.getParametrosPeriodoDTO().tipoPeriodoEhUltimosSeisMeses() || |
|
| - | 271 | parametrosConsulta.getParametrosPeriodoDTO().tipoPeriodoEhUltimosDozeMeses()) { |
|
| - | 272 | GraficoDadoDTO dados = new GraficoDadoDTO(); |
|
| - | 273 | Integer mesAtual = new Integer(parametrosConsulta.getParametrosPeriodoDTO().getMes()); |
|
| - | 274 | Integer anoAtual = new Integer(parametrosConsulta.getParametrosPeriodoDTO().getAno()); |
|
| - | 275 | Integer quantidadeMesesAnteriores = 0; |
|
| - | 276 | if (parametrosConsulta.getParametrosPeriodoDTO().tipoPeriodoEhUltimosSeisMeses()) { |
|
| - | 277 | quantidadeMesesAnteriores = 7; |
|
| - | 278 | }
|
|
| - | 279 | if (parametrosConsulta.getParametrosPeriodoDTO().tipoPeriodoEhUltimosDozeMeses()) { |
|
| - | 280 | quantidadeMesesAnteriores = 13; |
|
| - | 281 | }
|
|
| - | 282 | ||
| - | 283 | mesAtual = mesAtual - quantidadeMesesAnteriores + 1; |
|
| - | 284 | if (mesAtual <= 0) { |
|
| - | 285 | mesAtual = mesAtual + 12; |
|
| - | 286 | anoAtual--;
|
|
| - | 287 | }
|
|
| - | 288 | for (int mes = 1; mes <= quantidadeMesesAnteriores; quantidadeMesesAnteriores--) { |
|
| - | 289 | if (mesAtual == 13) { |
|
| - | 290 | mesAtual = 1; |
|
| - | 291 | anoAtual++;
|
|
| - | 292 | }
|
|
| - | 293 | Double valorAcumulado = new Double(0.0); |
|
| - | 294 | Calendar dataInicial = DataUtils.obterCalendario(DataUtils.obterData(1, mesAtual - 1, anoAtual)); |
|
| - | 295 | parametrosConsulta.getParametrosPeriodoDTO().setDataInicial(dataInicial.getTime()); |
|
| - | 296 | int qntMaximaDias = dataInicial.getActualMaximum(Calendar.DAY_OF_MONTH); |
|
| - | 297 | parametrosConsulta.getParametrosPeriodoDTO().setDataFinal(DataUtils.obterCalendario(DataUtils.obterData(qntMaximaDias, mesAtual - 1, anoAtual)).getTime()); |
|
| - | 298 | valorAcumulado = vendaService.obterValorTotalBrutoDeVendasPorLojaEePeriodoEeFormasDePagamento(parametrosConsulta, Arrays.asList(parametrosConsulta.getFormasDePagamentoDTO())); |
|
| - | 299 | String descricaoLinha = mesAtual.toString() + "/" + anoAtual; |
|
| - | 300 | mesAtual++;
|
|
| - | 301 | ||
| - | 302 | AvaliacaoFuncionarioDTO avaliacaoFuncionarioDTO = new AvaliacaoFuncionarioDTO(); |
|
| - | 303 | avaliacaoFuncionarioDTO.setValorTotalVendido(valorAcumulado); |
|
| - | 304 | avaliacaoFuncionarioDTO.setValorMetaMensal(avaliacaoFuncionarioService.consultarMetaMensalPelaData(parametrosConsulta.getVendedorSelecionado().getSequencialPessoa(), DataUtils.getDataComHorarioMinimo(parametrosConsulta.getParametrosPeriodoDTO().getDataFinal()))); |
|
| - | 305 | Double valorParaFormatar = avaliacaoFuncionarioDTO.retornarPercentualRealizado() * 100; |
|
| - | 306 | dados.adicionarDados(valorParaFormatar.intValue(), "rgba(75, 192, 192, 0.2)", "rgb(75, 192, 192)", "" + descricaoLinha); |
|
| - | 307 | }
|
|
| - | 308 | ||
| - | 309 | graficoDTO.setDados(dados); |
|
| - | 310 | graficoDTO.setTitulo("PERCENTUAIS DA META PELOS ÚLTIMOS MESES"); |
|
| - | 311 | }
|
|
| - | 312 | ||
| - | 313 | BarChartDataSet barDataSet = new BarChartDataSet(); |
|
| - | 314 | barDataSet.setLabel(""); |
|
| - | 315 | barDataSet.setData(graficoDTO.getDados().getValores()); |
|
| - | 316 | barDataSet.setBackgroundColor(graficoDTO.getDados().getCores()); |
|
| - | 317 | barDataSet.setBorderColor(graficoDTO.getDados().getBordas()); |
|
| - | 318 | barDataSet.setBorderWidth(1); |
|
| - | 319 | ||
| - | 320 | ChartData dados = new ChartData(); |
|
| - | 321 | dados.setLabels(graficoDTO.getDados().getMarcadores()); |
|
| - | 322 | dados.addChartDataSet(barDataSet); |
|
| - | 323 | ||
| - | 324 | BarChartOptions options = new BarChartOptions(); |
|
| - | 325 | CartesianScales cScales = new CartesianScales(); |
|
| - | 326 | CartesianLinearAxes linearAxes = new CartesianLinearAxes(); |
|
| - | 327 | linearAxes.setOffset(true); |
|
| - | 328 | CartesianLinearTicks ticks = new CartesianLinearTicks(); |
|
| - | 329 | ticks.setBeginAtZero(true); |
|
| - | 330 | linearAxes.setTicks(ticks); |
|
| - | 331 | cScales.setDisplay(true); |
|
| - | 332 | cScales.addYAxesData(linearAxes); |
|
| - | 333 | options.setScales(cScales); |
|
| - | 334 | ||
| - | 335 | if (VerificadorUtil.naoEstaNuloOuVazio(graficoDTO.getTitulo())) { |
|
| - | 336 | Title title = new Title(); |
|
| - | 337 | title.setDisplay(true); |
|
| - | 338 | title.setText(graficoDTO.getTitulo()); |
|
| - | 339 | options.setTitle(title); |
|
| - | 340 | }
|
|
| - | 341 | ||
| - | 342 | Legend legend = new Legend(); |
|
| - | 343 | legend.setDisplay(true); |
|
| - | 344 | legend.setPosition("top"); |
|
| - | 345 | ||
| - | 346 | LegendLabel legendLabels = new LegendLabel(); |
|
| - | 347 | legendLabels.setFontStyle("bold"); |
|
| - | 348 | legendLabels.setFontColor("#2980B9"); |
|
| - | 349 | legendLabels.setFontSize(24); |
|
| - | 350 | legend.setLabels(legendLabels); |
|
| - | 351 | options.setLegend(legend); |
|
| - | 352 | ||
| - | 353 | BarChartModel graficoBarra = new BarChartModel(); |
|
| - | 354 | graficoBarra.setData(dados); |
|
| - | 355 | graficoBarra.setOptions(options); |
|
| - | 356 | graficoBarra.setExtender("barraPercentuais"); |
|
| - | 357 | ||
| - | 358 | graficoDTO.setGraficoBarra(graficoBarra); |
|
| - | 359 | return graficoDTO; |
|
| 240 | }
|
360 | }
|
| 241 | 361 | ||
| 242 | @Override |
362 | @Override |
| 243 | public GraficoPizzaDTO gerarGraficoVendasPorFormasDePagamento(ParametrosConsultaVendasDTO parametrosConsulta) { |
363 | public GraficoPizzaDTO gerarGraficoVendasPorFormasDePagamento(ParametrosConsultaVendasDTO parametrosConsulta) { |
| 244 | GraficoBarraDTO graficoDTO = new GraficoBarraDTO(); |
364 | GraficoBarraDTO graficoDTO = new GraficoBarraDTO(); |
| - | 365 | graficoDTO.setParametrosConsulta(parametrosConsulta); |
|
| 245 | if (parametrosConsulta.getParametrosPeriodoDTO().tipoPeriodoEhPorDia()) { |
366 | if (parametrosConsulta.getParametrosPeriodoDTO().tipoPeriodoEhPorDia()) { |
| 246 | graficoDTO.setDados(preencherDadosComPeriodoEhPorDia(parametrosConsulta, "rgba(75, 192, 192, 0.2)", "rgb(75, 192, 192)")); |
367 | graficoDTO.setDados(preencherDadosComPeriodoEhPorDia(parametrosConsulta, "rgba(75, 192, 192, 0.2)", "rgb(75, 192, 192)")); |
| 247 | graficoDTO.setTitulo("VENDAS POR DIA"); |
368 | graficoDTO.setTitulo("VENDAS POR DIA"); |
| 248 | }
|
369 | }
|
| 249 | if (parametrosConsulta.getParametrosPeriodoDTO().tipoPeriodoEhPorMes()) { |
370 | if (parametrosConsulta.getParametrosPeriodoDTO().tipoPeriodoEhPorMes()) { |