Rev 265 | Rev 274 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
| Rev 265 | Rev 268 | ||
|---|---|---|---|
| Line 28... | Line 28... | ||
| 28 | }
|
28 | }
|
| 29 | 29 | ||
| 30 | @Override |
30 | @Override |
| 31 | public Integer obterQuantidadeDeVendasPorLojaEePeriodo(ParametrosConsultaVendasDTO parametrosConsultaVendasDTO) { |
31 | public Integer obterQuantidadeDeVendasPorLojaEePeriodo(ParametrosConsultaVendasDTO parametrosConsultaVendasDTO) { |
| 32 | StringBuilder sql = new StringBuilder(); |
32 | StringBuilder sql = new StringBuilder(); |
| 33 | sql.append("SELECT COUNT(*) FROM Venda e "); |
- | |
| - | 33 | sql.append("SELECT COUNT(*) FROM Venda v "); |
|
| 34 | sql.append("WHERE 1=1 "); |
34 | sql.append("WHERE 1=1 "); |
| 35 | setarStringParametrosConsulta(sql, parametrosConsultaVendasDTO); |
35 | setarStringParametrosConsulta(sql, parametrosConsultaVendasDTO); |
| 36 | try { |
36 | try { |
| 37 | TypedQuery<Long> query = getEntityManager().createQuery(sql.toString(), Long.class); |
37 | TypedQuery<Long> query = getEntityManager().createQuery(sql.toString(), Long.class); |
| 38 | setarQueryParametrosConsulta(query, parametrosConsultaVendasDTO); |
38 | setarQueryParametrosConsulta(query, parametrosConsultaVendasDTO); |
| Line 44... | Line 44... | ||
| 44 | }
|
44 | }
|
| 45 | 45 | ||
| 46 | @Override |
46 | @Override |
| 47 | public Double obterValorTotalBrutoDeVendasPorLojaEePeriodo(ParametrosConsultaVendasDTO parametrosConsultaVendasDTO) { |
47 | public Double obterValorTotalBrutoDeVendasPorLojaEePeriodo(ParametrosConsultaVendasDTO parametrosConsultaVendasDTO) { |
| 48 | StringBuilder sql = new StringBuilder(); |
48 | StringBuilder sql = new StringBuilder(); |
| 49 | sql.append("SELECT SUM(l.valorVenda) FROM Venda e "); |
- | |
| 50 | sql.append("LEFT JOIN e.listaLancamentos l "); |
- | |
| - | 49 | sql.append("SELECT SUM(l.valorVenda) FROM Venda v "); |
|
| - | 50 | sql.append("LEFT JOIN v.listaLancamentos l "); |
|
| 51 | sql.append("WHERE l.ativo IS TRUE "); |
51 | sql.append("WHERE l.ativo IS TRUE "); |
| 52 | setarStringParametrosConsulta(sql, parametrosConsultaVendasDTO); |
52 | setarStringParametrosConsulta(sql, parametrosConsultaVendasDTO); |
| 53 | try { |
53 | try { |
| 54 | TypedQuery<Double> query = getEntityManager().createQuery(sql.toString(), Double.class); |
54 | TypedQuery<Double> query = getEntityManager().createQuery(sql.toString(), Double.class); |
| 55 | setarQueryParametrosConsulta(query, parametrosConsultaVendasDTO); |
55 | setarQueryParametrosConsulta(query, parametrosConsultaVendasDTO); |
| Line 65... | Line 65... | ||
| 65 | }
|
65 | }
|
| 66 | 66 | ||
| 67 | @Override |
67 | @Override |
| 68 | public Double obterValorDeCuponsUtilizadosPorLojaEePeriodo(ParametrosConsultaVendasDTO parametrosConsultaVendasDTO) { |
68 | public Double obterValorDeCuponsUtilizadosPorLojaEePeriodo(ParametrosConsultaVendasDTO parametrosConsultaVendasDTO) { |
| 69 | StringBuilder sql = new StringBuilder(); |
69 | StringBuilder sql = new StringBuilder(); |
| 70 | sql.append("SELECT SUM(p.valorPagamento) FROM VendaFormaPagamento p "); |
- | |
| 71 | sql.append("LEFT JOIN p.venda e "); |
- | |
| 72 | sql.append("WHERE p.formaPagamento.codigo = 16 "); |
- | |
| - | 70 | sql.append("SELECT SUM(vp.valorPagamento) FROM VendaFormaPagamento vp "); |
|
| - | 71 | sql.append("LEFT JOIN vp.venda v "); |
|
| - | 72 | sql.append("WHERE vp.formaPagamento.codigo = 16 "); |
|
| 73 | setarStringParametrosConsulta(sql, parametrosConsultaVendasDTO); |
73 | setarStringParametrosConsulta(sql, parametrosConsultaVendasDTO); |
| 74 | // parametrosConsulta.setIndicadorComissionado(null);
|
74 | // parametrosConsulta.setIndicadorComissionado(null);
|
| 75 | // parametrosConsulta.setTipoProduto(null);
|
75 | // parametrosConsulta.setTipoProduto(null);
|
| 76 | try { |
76 | try { |
| 77 | TypedQuery<Double> query = getEntityManager().createQuery(sql.toString(), Double.class); |
77 | TypedQuery<Double> query = getEntityManager().createQuery(sql.toString(), Double.class); |
| Line 88... | Line 88... | ||
| 88 | }
|
88 | }
|
| 89 | 89 | ||
| 90 | @Override |
90 | @Override |
| 91 | public Double obterValorDeMaquinetasPorPessoa(Long sequencialPessoaMaquineta, Date dataInicio, Date dataFim) { |
91 | public Double obterValorDeMaquinetasPorPessoa(Long sequencialPessoaMaquineta, Date dataInicio, Date dataFim) { |
| 92 | StringBuilder sql = new StringBuilder(); |
92 | StringBuilder sql = new StringBuilder(); |
| 93 | sql.append("SELECT SUM(p.valorPagamento) FROM VendaFormaPagamento p "); |
- | |
| 94 | sql.append("LEFT JOIN p.venda v "); |
- | |
| 95 | sql.append("WHERE p.formaPagamento.codigo IN :formasDePagamento "); |
- | |
| - | 93 | sql.append("SELECT SUM(vp.valorPagamento) FROM VendaFormaPagamento vp "); |
|
| - | 94 | sql.append("LEFT JOIN vp.venda v "); |
|
| - | 95 | sql.append("WHERE vp.formaPagamento.codigo IN :formasDePagamento "); |
|
| 96 | sql.append("AND v.maquineta.pessoa.sequencial = :sequencialPessoaMaquineta "); |
96 | sql.append("AND v.maquineta.pessoa.sequencial = :sequencialPessoaMaquineta "); |
| 97 | sql.append("AND (v.dataVenda BETWEEN :dataInicial AND :dataFinal OR v.dataVenda = :dataInicial OR v.dataVenda = :dataFinal) "); |
97 | sql.append("AND (v.dataVenda BETWEEN :dataInicial AND :dataFinal OR v.dataVenda = :dataInicial OR v.dataVenda = :dataFinal) "); |
| 98 | try { |
98 | try { |
| 99 | TypedQuery<Double> query = getEntityManager().createQuery(sql.toString(), Double.class); |
99 | TypedQuery<Double> query = getEntityManager().createQuery(sql.toString(), Double.class); |
| 100 | query.setParameter("formasDePagamento", FormaPagamentoDTO.codigosFormasDePagamentoViaCartao()); |
100 | query.setParameter("formasDePagamento", FormaPagamentoDTO.codigosFormasDePagamentoViaCartao()); |
| Line 113... | Line 113... | ||
| 113 | }
|
113 | }
|
| 114 | }
|
114 | }
|
| 115 | 115 | ||
| 116 | private void setarStringParametrosConsulta(StringBuilder sql, ParametrosConsultaVendasDTO parametros) { |
116 | private void setarStringParametrosConsulta(StringBuilder sql, ParametrosConsultaVendasDTO parametros) { |
| 117 | if (VerificadorUtil.naoEstaNuloOuVazio(parametros.getSequencialLoja())) { |
117 | if (VerificadorUtil.naoEstaNuloOuVazio(parametros.getSequencialLoja())) { |
| 118 | sql.append("AND e.loja.sequencial = :sequencialLoja "); |
- | |
| - | 118 | sql.append("AND v.loja.sequencial = :sequencialLoja "); |
|
| 119 | }
|
119 | }
|
| 120 | if (VerificadorUtil.naoEstaNuloOuVazio(parametros.getTipoSituacaoVenda())) { |
120 | if (VerificadorUtil.naoEstaNuloOuVazio(parametros.getTipoSituacaoVenda())) { |
| 121 | sql.append("AND e.tipoSituacao = :tipoSituacao "); |
- | |
| - | 121 | sql.append("AND v.tipoSituacao = :tipoSituacao "); |
|
| 122 | }
|
122 | }
|
| 123 | if (VerificadorUtil.naoEstaNuloOuVazio(parametros.getSequencialVendedor())) { |
123 | if (VerificadorUtil.naoEstaNuloOuVazio(parametros.getSequencialVendedor())) { |
| 124 | sql.append("AND e.vendedor.sequencial = :sequencialVendedor "); |
- | |
| - | 124 | sql.append("AND v.vendedor.sequencial = :sequencialVendedor "); |
|
| 125 | }
|
125 | }
|
| 126 | /*
|
126 | /*
|
| 127 | if (VerificadorUtil.naoEstaNuloOuVazio(parametros.getIndicacao())) {
|
127 | if (VerificadorUtil.naoEstaNuloOuVazio(parametros.getIndicacao())) {
|
| 128 | sql.append("AND e.indicacao.sequencial = :sequencialIndicacao ");
|
128 | sql.append("AND e.indicacao.sequencial = :sequencialIndicacao ");
|
| 129 | }
|
129 | }
|
| Line 154... | Line 154... | ||
| 154 | if (VerificadorUtil.naoEstaNuloOuVazio(parametros.getBandeiraCartao())) {
|
154 | if (VerificadorUtil.naoEstaNuloOuVazio(parametros.getBandeiraCartao())) {
|
| 155 | sql.append("AND (SELECT COUNT(b) FROM VendaFormaPagamento b WHERE b.venda = e AND b.bandeiraCartao.codigo = :codigoBandeiraCartao) > 0 ");
|
155 | sql.append("AND (SELECT COUNT(b) FROM VendaFormaPagamento b WHERE b.venda = e AND b.bandeiraCartao.codigo = :codigoBandeiraCartao) > 0 ");
|
| 156 | }
|
156 | }
|
| 157 | */
|
157 | */
|
| 158 | if (VerificadorUtil.naoEstaNuloOuVazio(parametros.getSequencialVenda())) { |
158 | if (VerificadorUtil.naoEstaNuloOuVazio(parametros.getSequencialVenda())) { |
| 159 | sql.append("AND e.sequencial = :sequencialVenda "); |
- | |
| - | 159 | sql.append("AND v.sequencial = :sequencialVenda "); |
|
| 160 | } else if (VerificadorUtil.naoEstaNuloOuVazio(parametros.getParametrosPeriodoDTO().getDataSelecionada()) |
160 | } else if (VerificadorUtil.naoEstaNuloOuVazio(parametros.getParametrosPeriodoDTO().getDataSelecionada()) |
| 161 | || VerificadorUtil.naoEstaNuloOuVazio(parametros.getParametrosPeriodoDTO().getDataInicial()) |
161 | || VerificadorUtil.naoEstaNuloOuVazio(parametros.getParametrosPeriodoDTO().getDataInicial()) |
| 162 | || VerificadorUtil.naoEstaNuloOuVazio(parametros.getParametrosPeriodoDTO().getDataFinal())) { |
162 | || VerificadorUtil.naoEstaNuloOuVazio(parametros.getParametrosPeriodoDTO().getDataFinal())) { |
| 163 | sql.append("AND e.dataVenda >= :dataInicial "); |
- | |
| 164 | sql.append("AND e.dataVenda <= :dataFinal "); |
- | |
| - | 163 | sql.append("AND v.dataVenda >= :dataInicial "); |
|
| - | 164 | sql.append("AND v.dataVenda <= :dataFinal "); |
|
| 165 | }
|
165 | }
|
| 166 | /*
|
166 | /*
|
| 167 | if (VerificadorUtil.naoEstaNuloOuVazio(parametros.getCodigoCupom())) {
|
167 | if (VerificadorUtil.naoEstaNuloOuVazio(parametros.getCodigoCupom())) {
|
| 168 | sql.append("AND (SELECT COUNT(cl) FROM Lancamento cl WHERE cl.venda = e AND cl.cupom.codigo = :codigoCupom) > 0) ");
|
168 | sql.append("AND (SELECT COUNT(cl) FROM Lancamento cl WHERE cl.venda = e AND cl.cupom.codigo = :codigoCupom) > 0) ");
|
| 169 | }
|
169 | }
|
| Line 479... | Line 479... | ||
| 479 | }
|
479 | }
|
| 480 | */
|
480 | */
|
| 481 | @Override |
481 | @Override |
| 482 | public Double obterValorTotalBrutoDeVendasPorLojaEePeriodoEeFormasDePagamento(ParametrosConsultaVendasDTO parametrosConsultaVendas, List<FormaPagamentoDTO> formasDePagamento) { |
482 | public Double obterValorTotalBrutoDeVendasPorLojaEePeriodoEeFormasDePagamento(ParametrosConsultaVendasDTO parametrosConsultaVendas, List<FormaPagamentoDTO> formasDePagamento) { |
| 483 | StringBuilder sql = new StringBuilder(); |
483 | StringBuilder sql = new StringBuilder(); |
| 484 | sql.append("SELECT SUM(v.valorPagamento) FROM VendaFormaPagamento v "); |
- | |
| 485 | sql.append("LEFT JOIN v.venda e "); |
- | |
| 486 | sql.append("LEFT JOIN v.formaPagamento f "); |
- | |
| 487 | sql.append("WHERE v.formaPagamento.codigo != "); |
- | |
| - | 484 | sql.append("SELECT SUM(vp.valorPagamento) FROM VendaFormaPagamento vp "); |
|
| - | 485 | sql.append("LEFT JOIN vp.venda v "); |
|
| - | 486 | sql.append("LEFT JOIN vp.formaPagamento f "); |
|
| - | 487 | sql.append("WHERE vp.formaPagamento.codigo != "); |
|
| 488 | sql.append(ConstantesSEC.FormasDePagamento.FORMAPAGAMENTO_CUPOM); |
488 | sql.append(ConstantesSEC.FormasDePagamento.FORMAPAGAMENTO_CUPOM); |
| 489 | sql.append(" "); |
489 | sql.append(" "); |
| 490 | try { |
490 | try { |
| 491 | sql = setarParametrosFormasDePagamento(sql, formasDePagamento); |
491 | sql = setarParametrosFormasDePagamento(sql, formasDePagamento); |
| 492 | sql = setarParametrosLojasSelecionadas(sql, parametrosConsultaVendas.getLojasSelecionadasDTO()); |
492 | sql = setarParametrosLojasSelecionadas(sql, parametrosConsultaVendas.getLojasSelecionadasDTO()); |
| - | 493 | if (VerificadorUtil.naoEstaNuloOuVazio(parametrosConsultaVendas.getVendedorSelecionado())) { |
|
| - | 494 | sql.append("AND v.vendedor.sequencial = :sequencialVendedor "); |
|
| - | 495 | }
|
|
| 493 | setarStringParametrosConsulta(sql, parametrosConsultaVendas); |
496 | setarStringParametrosConsulta(sql, parametrosConsultaVendas); |
| 494 | TypedQuery<Double> query = getEntityManager().createQuery(sql.toString(), Double.class); |
497 | TypedQuery<Double> query = getEntityManager().createQuery(sql.toString(), Double.class); |
| 495 | setarQueryParametrosConsulta(query, parametrosConsultaVendas); |
498 | setarQueryParametrosConsulta(query, parametrosConsultaVendas); |
| 496 | - | ||
| - | 499 | if (VerificadorUtil.naoEstaNuloOuVazio(parametrosConsultaVendas.getVendedorSelecionado())) { |
|
| - | 500 | query.setParameter("sequencialVendedor", parametrosConsultaVendas.getVendedorSelecionado().getSequencial()); |
|
| - | 501 | }
|
|
| 497 | Double total = query.getSingleResult(); |
502 | Double total = query.getSingleResult(); |
| 498 | if (VerificadorUtil.estaNulo(total)) { |
503 | if (VerificadorUtil.estaNulo(total)) { |
| 499 | return new Double(0.0); |
504 | return new Double(0.0); |
| 500 | }
|
505 | }
|
| 501 | return total; |
506 | return total; |
| Line 505... | Line 510... | ||
| 505 | }
|
510 | }
|
| 506 | }
|
511 | }
|
| 507 | 512 | ||
| 508 | private StringBuilder setarParametrosFormasDePagamento(StringBuilder sql, List<FormaPagamentoDTO> formasPagamento) { |
513 | private StringBuilder setarParametrosFormasDePagamento(StringBuilder sql, List<FormaPagamentoDTO> formasPagamento) { |
| 509 | if (VerificadorUtil.naoEstaNuloOuVazio(formasPagamento)) { |
514 | if (VerificadorUtil.naoEstaNuloOuVazio(formasPagamento)) { |
| 510 | sql.append("AND v.formaPagamento.codigo IN ("); |
- | |
| - | 515 | sql.append("AND vp.formaPagamento.codigo IN ("); |
|
| 511 | for (FormaPagamentoDTO formaPagamento : formasPagamento) { |
516 | for (FormaPagamentoDTO formaPagamento : formasPagamento) { |
| 512 | if (!formaPagamento.formaPagamentoEhCupom()) { |
517 | if (!formaPagamento.formaPagamentoEhCupom()) { |
| 513 | sql.append(formaPagamento.getCodigo() + ","); |
518 | sql.append(formaPagamento.getCodigo() + ","); |
| 514 | }
|
519 | }
|
| 515 | }
|
520 | }
|
| Line 518... | Line 523... | ||
| 518 | return new StringBuilder(sql.toString().replace(",)", ")")); |
523 | return new StringBuilder(sql.toString().replace(",)", ")")); |
| 519 | }
|
524 | }
|
| 520 | 525 | ||
| 521 | private StringBuilder setarParametrosLojasSelecionadas(StringBuilder sql, List<LojaDTO> lojasSelecionadas) { |
526 | private StringBuilder setarParametrosLojasSelecionadas(StringBuilder sql, List<LojaDTO> lojasSelecionadas) { |
| 522 | if (VerificadorUtil.naoEstaNuloOuVazio(lojasSelecionadas)) { |
527 | if (VerificadorUtil.naoEstaNuloOuVazio(lojasSelecionadas)) { |
| 523 | sql.append("AND v.venda.loja.sequencial IN ("); |
- | |
| - | 528 | sql.append("AND vp.venda.loja.sequencial IN ("); |
|
| 524 | for (LojaDTO loja : lojasSelecionadas) { |
529 | for (LojaDTO loja : lojasSelecionadas) { |
| 525 | sql.append(loja.getSequencial() + ","); |
530 | sql.append(loja.getSequencial() + ","); |
| 526 | }
|
531 | }
|
| 527 | sql.append(") "); |
532 | sql.append(") "); |
| 528 | }
|
533 | }
|