Rev 259 | Rev 264 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
| Rev 259 | Rev 261 | ||
|---|---|---|---|
| Line 2... | Line 2... | ||
| 2 | 2 | ||
| 3 | import java.util.Date; |
3 | import java.util.Date; |
| - | 4 | import java.util.List; |
|
| 4 | 5 | ||
| 5 | import javax.persistence.Query; |
6 | import javax.persistence.Query; |
| 6 | import javax.persistence.TypedQuery; |
7 | import javax.persistence.TypedQuery; |
| 7 | 8 | ||
| 8 | import org.springframework.stereotype.Repository; |
9 | import org.springframework.stereotype.Repository; |
| 9 | 10 | ||
| 10 | import br.com.ec.core.util.DataUtils; |
11 | import br.com.ec.core.util.DataUtils; |
| 11 | import br.com.ec.core.util.VerificadorUtil; |
12 | import br.com.ec.core.util.VerificadorUtil; |
| - | 13 | import br.com.ec.domain.dto.FormaPagamentoDTO; |
|
| 12 | import br.com.ec.domain.dto.consulta.ParametrosConsultaVendasDTO; |
14 | import br.com.ec.domain.dto.consulta.ParametrosConsultaVendasDTO; |
| 13 | import br.com.ec.domain.model.Venda; |
15 | import br.com.ec.domain.model.Venda; |
| - | 16 | import br.com.ec.domain.shared.ConstantesSEC; |
|
| 14 | import br.com.ec.repository.SistemaAbstractRepository; |
17 | import br.com.ec.repository.SistemaAbstractRepository; |
| 15 | import br.com.ec.repository.VendaRepository; |
18 | import br.com.ec.repository.VendaRepository; |
| 16 | 19 | ||
| 17 | @Repository |
20 | @Repository |
| 18 | public class VendaRepositoryJpaImpl extends SistemaAbstractRepository<Venda> implements VendaRepository { |
21 | public class VendaRepositoryJpaImpl extends SistemaAbstractRepository<Venda> implements VendaRepository { |
| Line 124... | Line 127... | ||
| 124 | sql.append("AND (SELECT COUNT(b) FROM VendaFormaPagamento b WHERE b.venda = e AND b.bandeiraCartao.codigo = :codigoBandeiraCartao) > 0 ");
|
127 | sql.append("AND (SELECT COUNT(b) FROM VendaFormaPagamento b WHERE b.venda = e AND b.bandeiraCartao.codigo = :codigoBandeiraCartao) > 0 ");
|
| 125 | }
|
128 | }
|
| 126 | */
|
129 | */
|
| 127 | if (VerificadorUtil.naoEstaNuloOuVazio(parametros.getSequencialVenda())) { |
130 | if (VerificadorUtil.naoEstaNuloOuVazio(parametros.getSequencialVenda())) { |
| 128 | sql.append("AND e.sequencial = :sequencialVenda "); |
131 | sql.append("AND e.sequencial = :sequencialVenda "); |
| 129 | } else if (VerificadorUtil.naoEstaNuloOuVazio(parametros.getDataVendas()) |
- | |
| 130 | || VerificadorUtil.naoEstaNuloOuVazio(parametros.getDataInicial()) |
- | |
| 131 | || VerificadorUtil.naoEstaNuloOuVazio(parametros.getDataFinal())) { |
- | |
| - | 132 | } else if (VerificadorUtil.naoEstaNuloOuVazio(parametros.getParametrosPeriodoDTO().getDataSelecionada()) |
|
| - | 133 | || VerificadorUtil.naoEstaNuloOuVazio(parametros.getParametrosPeriodoDTO().getDataInicial()) |
|
| - | 134 | || VerificadorUtil.naoEstaNuloOuVazio(parametros.getParametrosPeriodoDTO().getDataFinal())) { |
|
| 132 | sql.append("AND e.dataVenda >= :dataInicial "); |
135 | sql.append("AND e.dataVenda >= :dataInicial "); |
| 133 | sql.append("AND e.dataVenda <= :dataFinal "); |
136 | sql.append("AND e.dataVenda <= :dataFinal "); |
| 134 | }
|
137 | }
|
| 135 | /*
|
138 | /*
|
| 136 | if (VerificadorUtil.naoEstaNuloOuVazio(parametros.getCodigoCupom())) {
|
139 | if (VerificadorUtil.naoEstaNuloOuVazio(parametros.getCodigoCupom())) {
|
| Line 166... | Line 169... | ||
| 166 | query.setParameter("codigoBandeiraCartao", parametros.getBandeiraCartao().getCodigo());
|
169 | query.setParameter("codigoBandeiraCartao", parametros.getBandeiraCartao().getCodigo());
|
| 167 | }
|
170 | }
|
| 168 | */
|
171 | */
|
| 169 | if (VerificadorUtil.naoEstaNuloOuVazio(parametros.getSequencialVenda())) { |
172 | if (VerificadorUtil.naoEstaNuloOuVazio(parametros.getSequencialVenda())) { |
| 170 | query.setParameter("sequencialVenda", parametros.getSequencialVenda()); |
173 | query.setParameter("sequencialVenda", parametros.getSequencialVenda()); |
| 171 | } else if (VerificadorUtil.naoEstaNuloOuVazio(parametros.getDataInicial()) |
- | |
| 172 | && VerificadorUtil.naoEstaNuloOuVazio(parametros.getDataFinal())) { |
- | |
| 173 | Date dataInicial = DataUtils.getDataComHorarioMinimo(parametros.getDataInicial()); |
- | |
| 174 | Date dataFinal = DataUtils.getDataComHorarioMaximo(parametros.getDataFinal()); |
- | |
| - | 174 | } else if (VerificadorUtil.naoEstaNuloOuVazio(parametros.getParametrosPeriodoDTO().getDataInicial()) |
|
| - | 175 | && VerificadorUtil.naoEstaNuloOuVazio(parametros.getParametrosPeriodoDTO().getDataFinal())) { |
|
| - | 176 | Date dataInicial = DataUtils.getDataComHorarioMinimo(parametros.getParametrosPeriodoDTO().getDataInicial()); |
|
| - | 177 | Date dataFinal = DataUtils.getDataComHorarioMaximo(parametros.getParametrosPeriodoDTO().getDataFinal()); |
|
| 175 | query.setParameter("dataInicial", dataInicial); |
178 | query.setParameter("dataInicial", dataInicial); |
| 176 | query.setParameter("dataFinal", dataFinal); |
179 | query.setParameter("dataFinal", dataFinal); |
| 177 | } else if (VerificadorUtil.naoEstaNuloOuVazio(parametros.getDataVendas())) { |
- | |
| 178 | Date dataInicial = DataUtils.getDataComHorarioMinimo(parametros.getDataVendas()); |
- | |
| 179 | Date dataFinal = DataUtils.getDataComHorarioMaximo(parametros.getDataVendas()); |
- | |
| - | 180 | } else if (VerificadorUtil.naoEstaNuloOuVazio(parametros.getParametrosPeriodoDTO().getDataSelecionada())) { |
|
| - | 181 | Date dataInicial = DataUtils.getDataComHorarioMinimo(parametros.getParametrosPeriodoDTO().getDataSelecionada()); |
|
| - | 182 | Date dataFinal = DataUtils.getDataComHorarioMaximo(parametros.getParametrosPeriodoDTO().getDataSelecionada()); |
|
| 180 | query.setParameter("dataInicial", dataInicial); |
183 | query.setParameter("dataInicial", dataInicial); |
| 181 | query.setParameter("dataFinal", dataFinal); |
184 | query.setParameter("dataFinal", dataFinal); |
| 182 | }
|
185 | }
|
| 183 | /*
|
186 | /*
|
| 184 | if (VerificadorUtil.naoEstaNuloOuVazio(parametros.getCodigoCupom())) {
|
187 | if (VerificadorUtil.naoEstaNuloOuVazio(parametros.getCodigoCupom())) {
|
| Line 444... | Line 447... | ||
| 444 | } catch(Exception ex) {
|
447 | } catch(Exception ex) {
|
| 445 | ex.printStackTrace();
|
448 | ex.printStackTrace();
|
| 446 | return null;
|
449 | return null;
|
| 447 | }
|
450 | }
|
| 448 | }
|
451 | }
|
| 449 |
|
- | |
| - | 452 | */
|
|
| 450 | @Override
|
453 | @Override |
| 451 | public Double obterValorTotalBrutoDeVendasPorLojaEePeriodoEeFormasDePagamento(ParametrosConsultaVendasDTO parametrosConsultaVendas, List<FormaPagamento> formasDePagamento) {
|
- | |
| - | 454 | public Double obterValorTotalBrutoDeVendasPorLojaEePeriodoEeFormasDePagamento(ParametrosConsultaVendasDTO parametrosConsultaVendas, List<FormaPagamentoDTO> formasDePagamento) { |
|
| 452 | StringBuilder sql = new StringBuilder();
|
455 | StringBuilder sql = new StringBuilder(); |
| 453 | sql.append("SELECT SUM(v.valorPagamento) FROM VendaFormaPagamento v ");
|
456 | sql.append("SELECT SUM(v.valorPagamento) FROM VendaFormaPagamento v "); |
| 454 | sql.append("LEFT JOIN v.venda e ");
|
457 | sql.append("LEFT JOIN v.venda e "); |
| 455 | sql.append("LEFT JOIN v.formaPagamento f ");
|
458 | sql.append("LEFT JOIN v.formaPagamento f "); |
| 456 | sql.append("WHERE 1=1 ");
|
- | |
| - | 459 | sql.append("WHERE v.formaPagamento.codigo != "); |
|
| - | 460 | sql.append(ConstantesSEC.FormasDePagamento.FORMAPAGAMENTO_CUPOM); |
|
| - | 461 | sql.append(" "); |
|
| 457 | try {
|
462 | try { |
| 458 | sql = setarParametrosFormasDePagamento(sql, formasDePagamento);
|
463 | sql = setarParametrosFormasDePagamento(sql, formasDePagamento); |
| 459 | setarStringParametrosConsulta(sql, parametrosConsultaVendas);
|
464 | setarStringParametrosConsulta(sql, parametrosConsultaVendas); |
| 460 | TypedQuery<Double> query = getEntityManager().createQuery(sql.toString(), Double.class);
|
465 | TypedQuery<Double> query = getEntityManager().createQuery(sql.toString(), Double.class); |
| 461 | setarQueryParametrosConsulta(query, parametrosConsultaVendas);
|
466 | setarQueryParametrosConsulta(query, parametrosConsultaVendas); |
| Line 469... | Line 474... | ||
| 469 | ex.printStackTrace();
|
474 | ex.printStackTrace(); |
| 470 | return null;
|
475 | return null; |
| 471 | }
|
476 | }
|
| 472 | }
|
477 | }
|
| 473 |
|
478 | |
| 474 | private StringBuilder setarParametrosFormasDePagamento(StringBuilder sql, List<FormaPagamento> formasPagamento) {
|
- | |
| 475 | if (VerificadorUtil.isListaComElementos(formasPagamento)) {
|
- | |
| - | 479 | private StringBuilder setarParametrosFormasDePagamento(StringBuilder sql, List<FormaPagamentoDTO> formasPagamento) { |
|
| - | 480 | // if (VerificadorUtil.isListaComElementos(formasPagamento)) {
|
|
| - | 481 | if (VerificadorUtil.naoEstaNuloOuVazio(formasPagamento)) { |
|
| 476 | sql.append("AND v.formaPagamento.codigo IN (");
|
482 | sql.append("AND v.formaPagamento.codigo IN ("); |
| 477 | for (FormaPagamento formaPagamento : formasPagamento) {
|
- | |
| 478 | sql.append(formaPagamento.getCodigo() + ",");
|
- | |
| - | 483 | for (FormaPagamentoDTO formaPagamento : formasPagamento) { |
|
| - | 484 | if (!formaPagamento.formaPagamentoEhCupom()) { |
|
| - | 485 | sql.append(formaPagamento.getCodigo() + ","); |
|
| - | 486 | }
|
|
| 479 | }
|
487 | }
|
| 480 | sql.append(") ");
|
488 | sql.append(") "); |
| 481 | }
|
489 | }
|
| 482 | return new StringBuilder(sql.toString().replace(",)", ")"));
|
490 | return new StringBuilder(sql.toString().replace(",)", ")")); |
| 483 | }
|
491 | }
|
| 484 |
|
- | |
| - | 492 | /*
|
|
| 485 | @Override
|
493 | @Override
|
| 486 | public Double obterValorTotalLiquidoDeVendasPorLojaEePeriodo(ParametrosConsultaVendasDTO parametrosConsulta) {
|
494 | public Double obterValorTotalLiquidoDeVendasPorLojaEePeriodo(ParametrosConsultaVendasDTO parametrosConsulta) {
|
| 487 | StringBuilder sql = new StringBuilder();
|
495 | StringBuilder sql = new StringBuilder();
|
| 488 | sql.append("SELECT SUM(e.valor) FROM Parcela e ");
|
496 | sql.append("SELECT SUM(e.valor) FROM Parcela e ");
|
| 489 | sql.append("INNER JOIN e.conta c ");
|
497 | sql.append("INNER JOIN e.conta c ");
|