Rev 583 | Rev 588 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
| Rev | Author | Line No. | Line |
|---|---|---|---|
| 229 | espaco | 1 | package br.com.ec.domain.service.impl; |
| 2 | |||
| 561 | blopes | 3 | import java.util.ArrayList; |
| 229 | espaco | 4 | import java.util.Date; |
| 261 | espaco | 5 | import java.util.List; |
| 229 | espaco | 6 | |
| 7 | import org.springframework.stereotype.Service; |
||
| 8 | |||
| 452 | blopes | 9 | import br.com.ec.core.exception.NegocioException; |
| 229 | espaco | 10 | import br.com.ec.core.generic.AbstractService; |
| 11 | import br.com.ec.core.generic.GenericRepository; |
||
| 452 | blopes | 12 | import br.com.ec.core.util.DataUtils; |
| 13 | import br.com.ec.core.util.VerificadorUtil; |
||
| 229 | espaco | 14 | import br.com.ec.core.validador.Validador; |
| 450 | blopes | 15 | import br.com.ec.domain.dto.AuditoriaVendaDTO; |
| 261 | espaco | 16 | import br.com.ec.domain.dto.FormaPagamentoDTO; |
| 561 | blopes | 17 | import br.com.ec.domain.dto.LojaDTO; |
| 566 | blopes | 18 | import br.com.ec.domain.dto.ModeloDTO; |
| 561 | blopes | 19 | import br.com.ec.domain.dto.RankingComprasTransferenciasDTO; |
| 20 | import br.com.ec.domain.dto.RankingComprasTransferenciasEstiloDTO; |
||
| 21 | import br.com.ec.domain.dto.RankingComprasTransferenciasEstiloPorLojaDTO; |
||
| 22 | import br.com.ec.domain.dto.RankingModeloDTO; |
||
| 582 | blopes | 23 | import br.com.ec.domain.dto.RankingProdutoDTO; |
| 583 | blopes | 24 | import br.com.ec.domain.dto.RankingProdutoDTONovo; |
| 561 | blopes | 25 | import br.com.ec.domain.dto.consulta.ParametrosConsultaModelosMaisVendidosDTO; |
| 26 | import br.com.ec.domain.dto.consulta.ParametrosConsultaPorPeriodoDTO; |
||
| 582 | blopes | 27 | import br.com.ec.domain.dto.consulta.ParametrosConsultaProdutosVendidosDTO; |
| 230 | espaco | 28 | import br.com.ec.domain.dto.consulta.ParametrosConsultaVendasDTO; |
| 259 | espaco | 29 | import br.com.ec.domain.model.Venda; |
| 566 | blopes | 30 | import br.com.ec.domain.model.tipos.TipoEstiloProduto; |
| 259 | espaco | 31 | import br.com.ec.domain.model.tipos.TipoSituacaoVenda; |
| 561 | blopes | 32 | import br.com.ec.domain.service.LojaService; |
| 566 | blopes | 33 | import br.com.ec.domain.service.ModeloService; |
| 229 | espaco | 34 | import br.com.ec.domain.service.VendaService; |
| 35 | import br.com.ec.repository.VendaRepository; |
||
| 36 | |||
| 37 | @Service |
||
| 38 | public class VendaServiceImpl extends AbstractService<Venda> implements VendaService { |
||
| 39 | |||
| 561 | blopes | 40 | private LojaService lojaService; |
| 566 | blopes | 41 | private ModeloService modeloService; |
| 229 | espaco | 42 | private VendaRepository vendaRepository; |
| 43 | |||
| 566 | blopes | 44 | public VendaServiceImpl(Validador validador, LojaService lojaService, ModeloService modeloService, VendaRepository vendaRepository) { |
| 229 | espaco | 45 | super(validador); |
| 561 | blopes | 46 | this.lojaService = lojaService; |
| 566 | blopes | 47 | this.modeloService = modeloService; |
| 229 | espaco | 48 | this.vendaRepository = vendaRepository; |
| 49 | } |
||
| 50 | |||
| 51 | @Override |
||
| 52 | protected GenericRepository<Venda> getRepository() { |
||
| 53 | return vendaRepository; |
||
| 54 | } |
||
| 55 | |||
| 56 | @Override |
||
| 296 | espaco | 57 | public Double obterValorTotalBrutoDeVendas(ParametrosConsultaVendasDTO parametrosConsultaVendasDTO) { |
| 58 | Double valorTotal = vendaRepository.obterValorTotalBrutoDeVendas(parametrosConsultaVendasDTO); |
||
| 59 | valorTotal = valorTotal - vendaRepository.obterValorDeCuponsUtilizadosPorLojaEePeriodo(parametrosConsultaVendasDTO); |
||
| 60 | return valorTotal; |
||
| 61 | } |
||
| 62 | |||
| 63 | @Override |
||
| 229 | espaco | 64 | public Integer obterQuantidadeDeVendasPorLojaEePeriodo(Long sequencialLoja, Date dataInicial, Date dataFinal) { |
| 296 | espaco | 65 | return vendaRepository.obterQuantidadeDeVendas(new ParametrosConsultaVendasDTO(sequencialLoja, dataInicial, dataFinal)); |
| 229 | espaco | 66 | } |
| 230 | espaco | 67 | |
| 68 | @Override |
||
| 253 | espaco | 69 | public Integer obterQuantidadeDeVendasNovasPorLojaEePeriodo(Long sequencialLoja, Date dataInicial, Date dataFinal) { |
| 70 | ParametrosConsultaVendasDTO parametrosConsulta = new ParametrosConsultaVendasDTO(sequencialLoja, dataInicial, dataFinal); |
||
| 71 | parametrosConsulta.setTipoSituacaoVenda(TipoSituacaoVenda.NOVO.getValor()); |
||
| 296 | espaco | 72 | return vendaRepository.obterQuantidadeDeVendas(parametrosConsulta); |
| 253 | espaco | 73 | } |
| 74 | |||
| 75 | @Override |
||
| 296 | espaco | 76 | public Double obterValorTotalBrutoDeVendasPorLojaEePeriodoEeFormasDePagamento(ParametrosConsultaVendasDTO parametrosConsultaVendas, List<FormaPagamentoDTO> formasDePagamento) { |
| 77 | return vendaRepository.obterValorTotalBrutoDeVendasPorParametrosEeFormasDePagamento(parametrosConsultaVendas, formasDePagamento); |
||
| 230 | espaco | 78 | } |
| 261 | espaco | 79 | |
| 80 | @Override |
||
| 296 | espaco | 81 | public Double obterValorDeMaquinetasPorPessoa(Long sequencialPessoaMaquineta, Date dataInicio, Date dataFim) { |
| 82 | return vendaRepository.obterValorDeMaquinetasPorPessoa(sequencialPessoaMaquineta, dataInicio, dataFim); |
||
| 261 | espaco | 83 | } |
| 84 | |||
| 265 | espaco | 85 | @Override |
| 296 | espaco | 86 | public Double obterValorTotalLiquidoDeVendas(ParametrosConsultaVendasDTO parametrosConsultaVendas) { |
| 87 | return vendaRepository.obterValorTotalLiquidoDeVendas(parametrosConsultaVendas); |
||
| 265 | espaco | 88 | } |
| 89 | |||
| 296 | espaco | 90 | @Override |
| 91 | public Double obterValorProdutosUtilizadosEmVendas(ParametrosConsultaVendasDTO parametrosConsultaVendas) { |
||
| 92 | return vendaRepository.obterValorProdutosUtilizadosEmVendas(parametrosConsultaVendas); |
||
| 93 | } |
||
| 94 | |||
| 450 | blopes | 95 | @Override |
| 96 | public List<AuditoriaVendaDTO> consultarAuditoriaVenda(Date dataSelecionada, Long sequencialLojaSelecionada) { |
||
| 452 | blopes | 97 | if (VerificadorUtil.estaNulo(sequencialLojaSelecionada)) { |
| 98 | throw new NegocioException("Selecione a loja"); |
||
| 99 | } |
||
| 100 | Integer diferencaDiasEntreDatas = DataUtils.calcularDiferenceEmDiasEntreDuasDatas(DataUtils.getDataAtual(), dataSelecionada); |
||
| 101 | if (diferencaDiasEntreDatas > 60) { |
||
| 102 | throw new NegocioException("Consulta indisponível"); |
||
| 103 | } |
||
| 450 | blopes | 104 | return vendaRepository.consultarAuditoriaVenda(dataSelecionada, sequencialLojaSelecionada); |
| 105 | } |
||
| 106 | |||
| 561 | blopes | 107 | @Override |
| 567 | blopes | 108 | public List<RankingComprasTransferenciasDTO> consultarRankingComprasTransferencias(Integer quantidadeDiasVendas, Integer quantidadeDiasParaAlerta, List<RankingModeloDTO> modelosMaisVendidos, Boolean consultarPorLoja) { |
| 561 | blopes | 109 | List<RankingComprasTransferenciasDTO> ranking = new ArrayList<RankingComprasTransferenciasDTO>(); |
| 110 | |||
| 111 | ParametrosConsultaPorPeriodoDTO parametrosConsultaPorPeriodoDTO = new ParametrosConsultaPorPeriodoDTO(); |
||
| 112 | parametrosConsultaPorPeriodoDTO.setDataFinal(DataUtils.getDataAtual()); |
||
| 567 | blopes | 113 | parametrosConsultaPorPeriodoDTO.setDataInicial(DataUtils.acrescentarDias(DataUtils.getDataAtual(), quantidadeDiasVendas*-1)); |
| 561 | blopes | 114 | |
| 115 | for (RankingModeloDTO rankingModelo : modelosMaisVendidos) { |
||
| 586 | blopes | 116 | if (rankingModelo.getModelo().getSequencial().equals(new Long(946))) { |
| 117 | System.out.println("TESTAR"); |
||
| 118 | } |
||
| 561 | blopes | 119 | RankingComprasTransferenciasDTO rankingComprasTransferenciasDTO = new RankingComprasTransferenciasDTO(); |
| 120 | rankingComprasTransferenciasDTO.setRankingModelo(rankingModelo); |
||
| 121 | |||
| 122 | // CONSULTAR POR ESTILO |
||
| 566 | blopes | 123 | List<RankingComprasTransferenciasEstiloDTO> rankEstiloDTO = new ArrayList<RankingComprasTransferenciasEstiloDTO>(); |
| 124 | rankEstiloDTO.addAll(consultarRankingPorEstilo(rankingModelo.getModelo().getSequencial(), parametrosConsultaPorPeriodoDTO)); |
||
| 125 | |||
| 126 | // PREENCHER COM ESTILOS QUE NÃO FORAM CONSULTADOS |
||
| 561 | blopes | 127 | List<RankingComprasTransferenciasEstiloDTO> rankingEstiloDTO = new ArrayList<RankingComprasTransferenciasEstiloDTO>(); |
| 566 | blopes | 128 | for (TipoEstiloProduto tipoEstilo : TipoEstiloProduto.values()) { |
| 129 | Boolean adicionarEstilo = true; |
||
| 130 | for (RankingComprasTransferenciasEstiloDTO rankingEstilo : rankEstiloDTO) { |
||
| 131 | if (rankingEstilo.getEstilo().equals(tipoEstilo)) { |
||
| 132 | rankingEstiloDTO.add(rankingEstilo); |
||
| 133 | adicionarEstilo = false; |
||
| 134 | break; |
||
| 135 | } |
||
| 136 | } |
||
| 137 | if (adicionarEstilo) { |
||
| 138 | RankingComprasTransferenciasEstiloDTO rankingEstilo = new RankingComprasTransferenciasEstiloDTO(); |
||
| 139 | rankingEstilo.setEstilo(tipoEstilo); |
||
| 140 | rankingEstiloDTO.add(rankingEstilo); |
||
| 141 | } |
||
| 142 | } |
||
| 561 | blopes | 143 | |
| 568 | blopes | 144 | Double quantidadeMinimaTransferirComprar = new Double(quantidadeDiasParaAlerta) / new Double(quantidadeDiasVendas); |
| 145 | |||
| 561 | blopes | 146 | // CONSULTAR ESTILO POR LOJA |
| 567 | blopes | 147 | if (consultarPorLoja) { |
| 148 | for (RankingComprasTransferenciasEstiloDTO rankingEstilo : rankingEstiloDTO) { |
||
| 149 | List<RankingComprasTransferenciasEstiloPorLojaDTO> rankingPorLoja = new ArrayList<RankingComprasTransferenciasEstiloPorLojaDTO>(); |
||
| 150 | rankingPorLoja.addAll(consultarRankingPorEstiloPorLoja(rankingModelo.getModelo().getSequencial(), rankingEstilo.getEstilo().getValor(), parametrosConsultaPorPeriodoDTO)); |
||
| 151 | |||
| 152 | // PREENCHER COM LOJAS ATIVAS |
||
| 153 | List<RankingComprasTransferenciasEstiloPorLojaDTO> rankingEstiloPorLoja = new ArrayList<RankingComprasTransferenciasEstiloPorLojaDTO>(); |
||
| 154 | List<LojaDTO> lojasDTO = lojaService.consultarLojasAtivas(); |
||
| 155 | for (LojaDTO lojaDTO : lojasDTO) { |
||
| 156 | Boolean adicionarRankingLoja = true; |
||
| 157 | for (RankingComprasTransferenciasEstiloPorLojaDTO rk : rankingPorLoja) { |
||
| 158 | if (rk.getLojaDTO().equals(lojaDTO)) { |
||
| 159 | rankingEstiloPorLoja.add(rk); |
||
| 160 | adicionarRankingLoja = false; |
||
| 161 | break; |
||
| 162 | } |
||
| 566 | blopes | 163 | } |
| 567 | blopes | 164 | if (adicionarRankingLoja) { |
| 165 | RankingComprasTransferenciasEstiloPorLojaDTO rank = new RankingComprasTransferenciasEstiloPorLojaDTO(); |
||
| 166 | rank.setLojaDTO(lojaDTO); |
||
| 167 | rankingEstiloPorLoja.add(rank); |
||
| 168 | } |
||
| 566 | blopes | 169 | } |
| 567 | blopes | 170 | rankingEstilo.setRankingsPorLoja(rankingEstiloPorLoja); |
| 171 | rankingComprasTransferenciasDTO.getEstilos().add(rankingEstilo); |
||
| 566 | blopes | 172 | } |
| 568 | blopes | 173 | rankingComprasTransferenciasDTO.setAlertas(rankingComprasTransferenciasDTO.verificarAlertasLogistica(quantidadeMinimaTransferirComprar)); |
| 174 | } else { |
||
| 175 | rankingComprasTransferenciasDTO.setEstilos(rankingEstiloDTO); |
||
| 176 | rankingComprasTransferenciasDTO.setAlertas(rankingComprasTransferenciasDTO.verificarAlertasCompras(quantidadeMinimaTransferirComprar)); |
||
| 561 | blopes | 177 | } |
| 178 | ranking.add(rankingComprasTransferenciasDTO); |
||
| 179 | } |
||
| 180 | |||
| 568 | blopes | 181 | List<RankingComprasTransferenciasDTO> rankingComAlertas = retirarModelosSemAlertas(ranking); |
| 182 | return rankingComAlertas; |
||
| 183 | } |
||
| 184 | |||
| 185 | private List<RankingComprasTransferenciasDTO> retirarModelosSemAlertas(List<RankingComprasTransferenciasDTO> ranking) { |
||
| 564 | blopes | 186 | List<RankingComprasTransferenciasDTO> rankingComAlertas = new ArrayList<RankingComprasTransferenciasDTO>(); |
| 187 | for (RankingComprasTransferenciasDTO rank : ranking) { |
||
| 188 | if (!rank.getAlertas().isEmpty()) { |
||
| 189 | rankingComAlertas.add(rank); |
||
| 190 | } |
||
| 191 | } |
||
| 192 | return rankingComAlertas; |
||
| 561 | blopes | 193 | } |
| 194 | |||
| 195 | @Override |
||
| 196 | public List<RankingComprasTransferenciasEstiloPorLojaDTO> consultarRankingPorEstiloPorLoja(Long sequencialModelo, String tipoEstilo, ParametrosConsultaPorPeriodoDTO parametrosConsultaPorPeriodoDTO) { |
||
| 197 | return vendaRepository.consultarRankingPorEstiloPorLoja(sequencialModelo, tipoEstilo, parametrosConsultaPorPeriodoDTO); |
||
| 198 | } |
||
| 199 | |||
| 200 | @Override |
||
| 566 | blopes | 201 | public List<RankingModeloDTO> consultarRankingModelos(ParametrosConsultaModelosMaisVendidosDTO parametrosConsulta, Boolean adicionarTodosModelosFavoritos) { |
| 202 | List<RankingModeloDTO> rankingModelosMaisVendidos = new ArrayList<RankingModeloDTO>(); |
||
| 203 | rankingModelosMaisVendidos.addAll(vendaRepository.consultarModelosMaisVendidos(parametrosConsulta)); |
||
| 204 | |||
| 205 | if (adicionarTodosModelosFavoritos) { |
||
| 206 | // PREENCHER COM MODELOS FAVORITOS SEM VENDAS |
||
| 207 | ModeloDTO modeloDTO = new ModeloDTO(); |
||
| 208 | modeloDTO.setAtivo(true); |
||
| 209 | modeloDTO.setIndicadorFavorito(true); |
||
| 210 | List<ModeloDTO> modelosFavoritos = modeloService.consultarModelos(modeloDTO); |
||
| 211 | List<RankingModeloDTO> modelosFavoritosSemVendas = new ArrayList<RankingModeloDTO>(); |
||
| 212 | for (ModeloDTO modeloFavorito : modelosFavoritos) { |
||
| 213 | Boolean adicionarModelo = true; |
||
| 214 | for (RankingModeloDTO ranking : rankingModelosMaisVendidos) { |
||
| 215 | if (ranking.getModelo().equals(modeloFavorito)) { |
||
| 216 | adicionarModelo = false; |
||
| 217 | break; |
||
| 218 | } |
||
| 219 | } |
||
| 220 | if (adicionarModelo) { |
||
| 221 | RankingModeloDTO rankingModeloDTO = new RankingModeloDTO(); |
||
| 222 | rankingModeloDTO.setModelo(modeloFavorito); |
||
| 223 | modelosFavoritosSemVendas.add(rankingModeloDTO); |
||
| 224 | } |
||
| 225 | } |
||
| 226 | rankingModelosMaisVendidos.addAll(modelosFavoritosSemVendas); |
||
| 227 | } |
||
| 228 | |||
| 229 | return rankingModelosMaisVendidos; |
||
| 561 | blopes | 230 | } |
| 231 | |||
| 232 | @Override |
||
| 233 | public List<RankingComprasTransferenciasEstiloDTO> consultarRankingPorEstilo(Long sequencialModelo, ParametrosConsultaPorPeriodoDTO parametrosConsultaPorPeriodoDTO) { |
||
| 234 | return vendaRepository.consultarRankingPorEstilo(sequencialModelo, parametrosConsultaPorPeriodoDTO); |
||
| 235 | } |
||
| 236 | |||
| 582 | blopes | 237 | @Override |
| 238 | public List<RankingProdutoDTO> consultarProdutosVendidos(ParametrosConsultaProdutosVendidosDTO parametrosConsulta) { |
||
| 239 | List<RankingProdutoDTO> produtosVendidosConsultados = vendaRepository.consultarProdutosVendidos(parametrosConsulta); |
||
| 240 | for (RankingProdutoDTO produtoVendido : produtosVendidosConsultados) { |
||
| 241 | produtoVendido.atualizarTempoEstoque(parametrosConsulta.getDataInicial(), parametrosConsulta.getDataFinal()); |
||
| 242 | } |
||
| 243 | return produtosVendidosConsultados; |
||
| 244 | } |
||
| 245 | |||
| 583 | blopes | 246 | @Override |
| 247 | public List<RankingProdutoDTONovo> consultarProdutosDTOVendidos(ParametrosConsultaProdutosVendidosDTO parametrosConsulta) { |
||
| 248 | List<RankingProdutoDTONovo> produtosVendidosConsultados = vendaRepository.consultarProdutosVendidosDTO(parametrosConsulta); |
||
| 249 | for (RankingProdutoDTONovo produtoVendido : produtosVendidosConsultados) { |
||
| 250 | produtoVendido.atualizarTempoEstoque(parametrosConsulta.getDataInicial(), parametrosConsulta.getDataFinal()); |
||
| 251 | } |
||
| 252 | return produtosVendidosConsultados; |
||
| 253 | } |
||
| 254 | |||
| 229 | espaco | 255 | /* |
| 256 | private LancamentoService lancamentoService; |
||
| 257 | private VendaFormaPagamentoService vendaFormaPagamentoService; |
||
| 258 | private ProdutoService produtoService; |
||
| 259 | private ProdutoLojaService produtoLojaService; |
||
| 260 | private VendedorService vendedorService; |
||
| 261 | private FuncionarioService funcionarioService; |
||
| 262 | private LojaService lojaService; |
||
| 263 | private PedidoService pedidoService; |
||
| 264 | private ParcelaService parcelaService; |
||
| 265 | private AvaliacaoService avaliacaoService; |
||
| 266 | private AvaliacaoFuncionarioService avaliacaoFuncionarioService; |
||
| 267 | private AvaliacaoLojaService avaliacaoLojaService; |
||
| 268 | private VendaVivoService vendaVivoService; |
||
| 269 | private ModeloService modeloService; |
||
| 270 | private CupomService cupomService; |
||
| 271 | private BancoHorasService bancoHorasService; |
||
| 272 | private EstoqueAuditoriaService estoqueAuditoriaService; |
||
| 273 | |||
| 274 | private Ordenador ordenador; |
||
| 275 | private NotaFiscalRepository notaFiscalRepository; |
||
| 276 | |||
| 277 | @Autowired |
||
| 278 | public VendaServiceImpl(Validador validador, VendaRepository vendaRepository, LancamentoService lancamentoService, |
||
| 279 | VendaFormaPagamentoService vendaFormaPagamentoService, ProdutoService produtoService, ProdutoLojaService produtoLojaService, |
||
| 280 | VendedorService vendedorService, FuncionarioService funcionarioService, LojaService lojaService, PedidoService pedidoService, |
||
| 281 | ParcelaService parcelaService, AvaliacaoService avaliacaoService, AvaliacaoFuncionarioService avaliacaoFuncionarioService, |
||
| 282 | AvaliacaoLojaService avaliacaoLojaService, VendaVivoService vendaVivoService, ModeloService modeloService, CupomService cupomService, |
||
| 283 | BancoHorasService bancoHorasService, EstoqueAuditoriaService estoqueAuditoriaService, NotaFiscalRepository notaFiscalRepository) { |
||
| 284 | super(validador); |
||
| 285 | this.vendaRepository = vendaRepository; |
||
| 286 | this.funcionarioService = funcionarioService; |
||
| 287 | this.lancamentoService = lancamentoService; |
||
| 288 | this.vendaFormaPagamentoService = vendaFormaPagamentoService; |
||
| 289 | this.produtoService = produtoService; |
||
| 290 | this.produtoLojaService = produtoLojaService; |
||
| 291 | this.vendedorService = vendedorService; |
||
| 292 | this.lojaService = lojaService; |
||
| 293 | this.pedidoService = pedidoService; |
||
| 294 | this.parcelaService = parcelaService; |
||
| 295 | this.avaliacaoService = avaliacaoService; |
||
| 296 | this.avaliacaoFuncionarioService = avaliacaoFuncionarioService; |
||
| 297 | this.avaliacaoLojaService = avaliacaoLojaService; |
||
| 298 | this.vendaVivoService = vendaVivoService; |
||
| 299 | this.modeloService = modeloService; |
||
| 300 | this.cupomService = cupomService; |
||
| 301 | this.bancoHorasService = bancoHorasService; |
||
| 302 | this.estoqueAuditoriaService = estoqueAuditoriaService; |
||
| 303 | this.ordenador = new OrdenadorImpl(); |
||
| 304 | this.notaFiscalRepository = notaFiscalRepository; |
||
| 305 | } |
||
| 306 | |||
| 307 | @Override |
||
| 308 | protected GenericRepository<Venda> getRepository() { |
||
| 309 | return vendaRepository; |
||
| 310 | } |
||
| 311 | |||
| 312 | @Override |
||
| 313 | protected void regrasNegocioCadastrar(Venda venda) { |
||
| 314 | if (VerificadorUtil.estaNulo(venda.getVendedor())) { |
||
| 315 | throw new NegocioException("Obrigatório informar o vendedor."); |
||
| 316 | } |
||
| 317 | venda.setDataVenda(DataUtils.getDataAtual()); |
||
| 318 | venda.setTipoSituacao(TipoSituacaoVenda.NOVO.getValor()); |
||
| 319 | } |
||
| 320 | */ |
||
| 321 | /***************************************************************/ |
||
| 322 | /* |
||
| 323 | @Override |
||
| 324 | public Venda detalharVenda(Venda venda) { |
||
| 325 | return vendaRepository.detalharVenda(venda); |
||
| 326 | } |
||
| 327 | |||
| 328 | @Override |
||
| 329 | public Venda detalharVendaCompleta(Venda venda) { |
||
| 330 | return vendaRepository.detalharVendaCompleta(venda); |
||
| 331 | } |
||
| 332 | |||
| 333 | public void excluirVenda(Venda venda, Usuario usuario) { |
||
| 334 | List<NotaFiscal> notasVinculadas = desvincularNotaFiscalEmitida(venda, usuario); |
||
| 335 | verificarSeExisteLancamentoFinanceiro(venda); |
||
| 336 | reporEstoqueAoExcluirVenda(venda); |
||
| 337 | excluirPagamentos(venda); |
||
| 338 | super.excluir(venda); |
||
| 339 | enviarEmail(venda, usuario, notasVinculadas); |
||
| 340 | } |
||
| 341 | |||
| 342 | private List<NotaFiscal> desvincularNotaFiscalEmitida(Venda venda, Usuario usuario) { |
||
| 343 | List<NotaFiscal> notasFiscais = notaFiscalRepository.consultarNotasFiscais(venda); |
||
| 344 | for (NotaFiscal nf : notasFiscais) { |
||
| 345 | nf.setObservacaoVenda("VENDA ID: " + venda.getSequencial() + " em " + |
||
| 346 | DataUtils.converterDataComHorarioParaString(venda.getDataVenda()) + ". " + |
||
| 347 | venda.getJustificativaParaExcluir()); |
||
| 348 | notaFiscalRepository.desvincularVenda(nf); |
||
| 349 | } |
||
| 350 | return notasFiscais; |
||
| 351 | } |
||
| 352 | |||
| 353 | private void verificarSeExisteLancamentoFinanceiro(Venda venda) { |
||
| 354 | if (parcelaService.verificarPossuiParcela(venda)) { |
||
| 355 | throw new NegocioException("Não é permitido excluir uma venda com lançamentos financeiros."); |
||
| 356 | } |
||
| 357 | } |
||
| 358 | |||
| 359 | public void reporEstoqueAoExcluirVenda(Venda venda) { |
||
| 360 | for (Lancamento lancamento : venda.getLancamentos()) { |
||
| 361 | alterarEstoqueProduto(1, venda.getLoja(), lancamento.getProduto().getCodigo()); |
||
| 362 | } |
||
| 363 | } |
||
| 364 | |||
| 365 | private void excluirPagamentos(Venda venda) { |
||
| 366 | for (VendaFormaPagamento vendaFormaPagamento : venda.getListaVendaFormaPagamentos()) { |
||
| 367 | // vendaFormaPagamentoService.excluirPorId(vendaFormaPagamento); |
||
| 368 | vendaFormaPagamentoService.excluir(vendaFormaPagamento); |
||
| 369 | } |
||
| 370 | } |
||
| 371 | |||
| 372 | private void enviarEmail(Venda venda, Usuario usuario, List<NotaFiscal> notasFiscaisVinculadas) { |
||
| 373 | String diaAtual = DataUtils.converterDataParaString(DataUtils.getDataAtual()); |
||
| 374 | StringBuilder conteudo = new StringBuilder(); |
||
| 375 | conteudo.append(montarDadosDaVenda(venda, usuario, venda.getLancamentos(), venda.getVendaFormaPagamentos())); |
||
| 376 | if (!notasFiscaisVinculadas.isEmpty()) { |
||
| 377 | conteudo.append("--------------------------------------------------\n\n"); |
||
| 378 | conteudo.append("NOTAS FISCAIS DESVINCULADAS:\n"); |
||
| 379 | for (NotaFiscal nota : notasFiscaisVinculadas) { |
||
| 380 | conteudo.append("NÚMERO: " + nota.getNumeroNotaFiscal() + "\n"); |
||
| 381 | } |
||
| 382 | } |
||
| 383 | new GerenciadorEmailImpl() |
||
| 384 | .comEmailsDestino(ConstantesSEC.DESTINATARIOS_EMAIL_DIRECAO) |
||
| 385 | .comAssunto("ESPAÇO CASE - OPERAÇÃO DE EXCLUSÃO DE VENDA: " + diaAtual) |
||
| 386 | .comConteudo(conteudo.toString()) |
||
| 387 | .enviar(); |
||
| 388 | } |
||
| 389 | |||
| 390 | @Override |
||
| 391 | public Venda cadastrarVendaPeloPDV(ParametrosVendaDTO parametrosVenda) { |
||
| 392 | verificarLancamentos(parametrosVenda.getLancamentos()); |
||
| 393 | // lancarExcecaoCasoFreteContraditorio(parametrosVenda); |
||
| 394 | lancarExcecaoCasoNaoSejaInformadoCamposObrigatorios(parametrosVenda); |
||
| 395 | lancarExcecaoSeValoresNaoSaoIguais(parametrosVenda); |
||
| 396 | Venda venda = new Venda(parametrosVenda); |
||
| 397 | cadastrar(venda); |
||
| 398 | cadastrarLancamentos(parametrosVenda, venda); |
||
| 399 | cadastrarPagamentos(parametrosVenda, venda); |
||
| 400 | alterarSituacaoPedido(parametrosVenda.getPedidoVinculado(), venda); |
||
| 401 | enviarAlertasPorEmail(parametrosVenda, venda); |
||
| 402 | venda.verificarSePermiteEmissaoNotaFiscal(); |
||
| 403 | venda.setEmitirNotaFiscal(verificarEmissaoNotaFiscal(parametrosVenda, venda)); |
||
| 404 | return venda; |
||
| 405 | } |
||
| 406 | |||
| 407 | private Boolean verificarEmissaoNotaFiscal(ParametrosVendaDTO parametrosVenda, Venda venda) { |
||
| 408 | if (venda.getPermitirEmissaoNotaFiscal() == false) {return false;} |
||
| 409 | Boolean emitir = null; |
||
| 410 | emitir = naoEmitirLojaSemPermissao(parametrosVenda); |
||
| 411 | if (VerificadorUtil.naoEstaNulo(emitir)) {return emitir;} |
||
| 412 | |||
| 413 | emitir = naoEmitirCpfCnpjInvalido(parametrosVenda); |
||
| 414 | if (VerificadorUtil.naoEstaNulo(emitir)) {return emitir;} |
||
| 415 | |||
| 416 | emitir = emitirLojaComEmissaoObrigatoria(parametrosVenda); |
||
| 417 | if (VerificadorUtil.naoEstaNulo(emitir)) {return emitir;} |
||
| 418 | |||
| 419 | emitir = emitirProdutoComEmissaoObrigatoria(parametrosVenda); |
||
| 420 | if (VerificadorUtil.naoEstaNulo(emitir)) {return emitir;} |
||
| 421 | |||
| 422 | emitir = emitirVendasAcimaQuinhetosReais(parametrosVenda); |
||
| 423 | if (VerificadorUtil.naoEstaNulo(emitir)) {return emitir;} |
||
| 424 | |||
| 425 | emitir = emitirVendaPagamentoCartao(parametrosVenda); |
||
| 426 | if (VerificadorUtil.naoEstaNulo(emitir)) {return emitir;} |
||
| 427 | return false; |
||
| 428 | } |
||
| 429 | |||
| 430 | private Boolean naoEmitirLojaSemPermissao(ParametrosVendaDTO parametrosVenda) { |
||
| 431 | if (parametrosVenda.getLoja().getTipoEmitirNotaFiscal().equals(TipoEmitirNotaFiscal.NAO_PERMITIR_EMISSAO.getValor()) || |
||
| 432 | parametrosVenda.getLoja().getTipoEmitirNotaFiscal().equals(TipoEmitirNotaFiscal.NAO_EMITIR.getValor())) { |
||
| 433 | return false; |
||
| 434 | } |
||
| 435 | return null; |
||
| 436 | } |
||
| 437 | |||
| 438 | private Boolean naoEmitirCpfCnpjInvalido(ParametrosVendaDTO parametrosVenda) { |
||
| 439 | if (VerificadorUtil.naoEstaNulo(parametrosVenda.getCliente())) { |
||
| 440 | if (!parametrosVenda.getCliente().cpfCnpjEhValido()) { |
||
| 441 | return false; |
||
| 442 | } |
||
| 443 | } |
||
| 444 | return null; |
||
| 445 | } |
||
| 446 | |||
| 447 | private Boolean emitirLojaComEmissaoObrigatoria(ParametrosVendaDTO parametrosVenda) { |
||
| 448 | if (parametrosVenda.getLoja().getTipoEmitirNotaFiscal().equals(TipoEmitirNotaFiscal.TODAS_VENDAS.getValor())) { |
||
| 449 | return true; |
||
| 450 | } |
||
| 451 | return null; |
||
| 452 | } |
||
| 453 | |||
| 454 | |||
| 455 | |||
| 456 | private Boolean emitirProdutoComEmissaoObrigatoria(ParametrosVendaDTO parametrosVenda) { |
||
| 457 | for (Lancamento lancamento : parametrosVenda.getLancamentos()) { |
||
| 458 | if (lancamento.getProduto().getIndicadorEmissaoNotaFiscal()) { |
||
| 459 | return true; |
||
| 460 | } |
||
| 461 | } |
||
| 462 | return null; |
||
| 463 | } |
||
| 464 | |||
| 465 | private Boolean emitirVendasAcimaQuinhetosReais(ParametrosVendaDTO parametrosVenda) { |
||
| 466 | Double valorVenda = new Double(0.0); |
||
| 467 | for (Lancamento lancamento : parametrosVenda.getLancamentos()) { |
||
| 468 | valorVenda = valorVenda + lancamento.getValorVenda(); |
||
| 469 | } |
||
| 470 | if (valorVenda > 499.9) { |
||
| 471 | return true; |
||
| 472 | } |
||
| 473 | return null; |
||
| 474 | } |
||
| 475 | |||
| 476 | private Boolean emitirVendaPagamentoCartao(ParametrosVendaDTO parametrosVenda) { |
||
| 477 | if (parametrosVenda.getLoja().getTipoEmitirNotaFiscal().equals(TipoEmitirNotaFiscal.VENDAS_OBRIGATORIAS.getValor())) { |
||
| 478 | for (VendaFormaPagamento pagamento : parametrosVenda.getLancamentosPagamentos()) { |
||
| 479 | if (pagamento.getFormaPagamento().formaPagamentoEhCredito() || |
||
| 480 | pagamento.getFormaPagamento().formaPagamentoEhDebito() || |
||
| 481 | pagamento.getFormaPagamento().formaPagamentoEhPagseguro()) { |
||
| 482 | return true; |
||
| 483 | } |
||
| 484 | } |
||
| 485 | } |
||
| 486 | return null; |
||
| 487 | } |
||
| 488 | |||
| 489 | private void alterarSituacaoPedido(Pedido pedidoVinculado, Venda venda) { |
||
| 490 | if (VerificadorUtil.naoEstaNulo(pedidoVinculado)) { |
||
| 491 | PedidoHistorico pedidoHistorico = new PedidoHistorico(); |
||
| 492 | pedidoHistorico.setDataHistorico(DataUtils.getDataAtual()); |
||
| 493 | pedidoHistorico.setObservacao("VENDA: " + venda.getSequencial()); |
||
| 494 | pedidoHistorico.setTipoSituacao(TipoSituacaoPedido.FINALIZADO_COM_VENDAS.getValor()); |
||
| 495 | pedidoHistorico.setUsuario(venda.getUsuario()); |
||
| 496 | pedidoHistorico.setPedido(pedidoVinculado); |
||
| 497 | if (VerificadorUtil.estaNulo(pedidoVinculado.getHistorico())) { |
||
| 498 | pedidoVinculado.setHistorico(new ArrayList<PedidoHistorico>()); |
||
| 499 | } |
||
| 500 | pedidoVinculado.getHistorico().add(pedidoHistorico); |
||
| 501 | pedidoVinculado.setTipoSituacao(TipoSituacaoPedido.FINALIZADO_COM_VENDAS.getValor()); |
||
| 502 | pedidoVinculado.setDataUltimaAlteracaoSituacao(DataUtils.getDataAtual()); |
||
| 503 | pedidoVinculado.setVenda(venda); |
||
| 504 | pedidoService.alterar(pedidoVinculado); |
||
| 505 | } |
||
| 506 | } |
||
| 507 | |||
| 508 | private void enviarAlertasPorEmail(ParametrosVendaDTO parametrosVenda, Venda venda) { |
||
| 509 | if (descontosEmProdutosSuperiores(parametrosVenda)) { |
||
| 510 | new GerenciadorEmailImpl() |
||
| 511 | .comEmailsDestino(ConstantesSEC.DESTINATARIOS_EMAIL_SUPERVISAO) |
||
| 512 | .comAssunto("ESPAÇO CASE - VENDA COM DESCONTO SUPERIOR : " + DataUtils.converterDataParaString(DataUtils.getDataAtual())) |
||
| 513 | .comConteudo(montarDadosDaVenda(venda, venda.getUsuario(), parametrosVenda.getLancamentos(), parametrosVenda.getLancamentosPagamentos())) |
||
| 514 | .enviar(); |
||
| 515 | } |
||
| 516 | if (produtosComDescontoECupom(parametrosVenda)) { |
||
| 517 | new GerenciadorEmailImpl() |
||
| 518 | .comEmailsDestino(ConstantesSEC.DESTINATARIOS_EMAIL_SUPERVISAO) |
||
| 519 | .comAssunto("ESPAÇO CASE - VENDA COM PRODUTO COM DESCONTO E CUPOM PROMOCIONAL : " + DataUtils.converterDataParaString(DataUtils.getDataAtual())) |
||
| 520 | .comConteudo(montarDadosDaVenda(venda, venda.getUsuario(), parametrosVenda.getLancamentos(), parametrosVenda.getLancamentosPagamentos())) |
||
| 521 | .enviar(); |
||
| 522 | } |
||
| 523 | } |
||
| 524 | */ |
||
| 525 | /* |
||
| 526 | private void enviarAlertasPorEmail(ParametrosVendaDTO parametrosVenda, Venda venda) { |
||
| 527 | if (pagamentoDividido(parametrosVenda)) { |
||
| 528 | if (descontoEmProdutos(parametrosVenda)) { |
||
| 529 | String diaAtual = DataUtils.converterDataParaString(DataUtils.getDataAtual()); |
||
| 530 | new GerenciadorEmailImpl() |
||
| 531 | .comEmailsDestino(ConstantesSEC.DESTINATARIOS_EMAIL_DIRECAO) |
||
| 532 | .comAssunto("ESPAÇO CASE - VENDA DIVIDIDA E COM DESCONTO : " + diaAtual) |
||
| 533 | .comConteudo(montarDadosDaVenda(venda, venda.getUsuario(), parametrosVenda.getLancamentos(), parametrosVenda.getLancamentosPagamentos())) |
||
| 534 | .enviar(); |
||
| 535 | } |
||
| 536 | } |
||
| 537 | } |
||
| 538 | */ |
||
| 539 | /* |
||
| 540 | private Boolean pagamentoDividido(ParametrosVendaDTO parametrosVenda) { |
||
| 541 | for (VendaFormaPagamento pagamento : parametrosVenda.getLancamentosPagamentos()) { |
||
| 542 | if (pagamento.getFormaPagamento().formaPagamentoEhCreditoDividido()) { |
||
| 543 | return true; |
||
| 544 | } |
||
| 545 | } |
||
| 546 | return false; |
||
| 547 | } |
||
| 548 | |||
| 549 | private boolean descontoEmProdutos(ParametrosVendaDTO parametrosVenda) { |
||
| 550 | for (Lancamento lancamento : parametrosVenda.getLancamentos()) { |
||
| 551 | if (lancamento.comDescontos()) { |
||
| 552 | return true; |
||
| 553 | } |
||
| 554 | } |
||
| 555 | return false; |
||
| 556 | } |
||
| 557 | |||
| 558 | private boolean descontosEmProdutosSuperiores(ParametrosVendaDTO parametrosVenda) { |
||
| 559 | for (Lancamento lancamento : parametrosVenda.getLancamentos()) { |
||
| 560 | if (lancamento.comDescontosAcimaDoPermitido()) { |
||
| 561 | return true; |
||
| 562 | } |
||
| 563 | } |
||
| 564 | return false; |
||
| 565 | } |
||
| 566 | |||
| 567 | private boolean produtosComDescontoECupom(ParametrosVendaDTO parametrosVenda) { |
||
| 568 | for (Lancamento lancamento : parametrosVenda.getLancamentos()) { |
||
| 569 | if (VerificadorUtil.naoEstaNulo(lancamento.getCupom()) && lancamento.comDescontos()) { |
||
| 570 | return true; |
||
| 571 | } |
||
| 572 | } |
||
| 573 | return false; |
||
| 574 | } |
||
| 575 | |||
| 576 | @Override |
||
| 577 | public void alterarVenda(ParametrosVendaDTO parametrosVenda, Usuario usuario, Boolean verificarJustificativa) { |
||
| 578 | verificarLancamentos(parametrosVenda.getLancamentos()); |
||
| 579 | lancarExcecaoCasoNaoSejaInformadoCamposObrigatorios(parametrosVenda); |
||
| 580 | lancarExcecaoSeValoresNaoSaoIguais(parametrosVenda); |
||
| 581 | if (verificarJustificativa) {enviarEmailAlteracoes(parametrosVenda, usuario);} |
||
| 582 | atualizarDadosDaVenda(parametrosVenda); |
||
| 583 | alterarLancamentos(parametrosVenda); |
||
| 584 | alterarPagamentos(parametrosVenda); |
||
| 585 | alterar(parametrosVenda.getVenda()); |
||
| 586 | alterarSituacaoPedido(parametrosVenda.getPedidoVinculado(), parametrosVenda.getVenda()); |
||
| 587 | } |
||
| 588 | |||
| 589 | private void enviarEmailAlteracoes(ParametrosVendaDTO parametrosVenda, Usuario usuario) { |
||
| 590 | String diaAtual = DataUtils.converterDataParaString(DataUtils.getDataAtual()); |
||
| 591 | StringBuilder conteudo = new StringBuilder(); |
||
| 592 | conteudo.append("OPERAÇÃO REALIZADA POR: " + usuario.getNome() + "\n"); |
||
| 593 | conteudo.append("ID: " + parametrosVenda.getVenda().getSequencial() + "\n"); |
||
| 594 | conteudo.append("DATA DA VENDA: " + DataUtils.converterDataComHorarioParaString(parametrosVenda.getVenda().getDataVenda()) + "\n"); |
||
| 595 | conteudo.append("ALTERAÇÕES:\n"); |
||
| 596 | if (!parametrosVenda.getLoja().equals(parametrosVenda.getVenda().getLoja())) { |
||
| 597 | conteudo.append("LOJA: " + parametrosVenda.getVenda().getLoja().getDescricao() + " -> " + parametrosVenda.getLoja().getDescricao() + "\n"); |
||
| 598 | } |
||
| 599 | if (!parametrosVenda.getVendedor().equals(parametrosVenda.getVenda().getVendedor())) { |
||
| 600 | conteudo.append("VENDEDOR: " + parametrosVenda.getVenda().getVendedor().getNomeDaPessoa() + " -> " + parametrosVenda.getVendedor().getNomeDaPessoa() + "\n"); |
||
| 601 | } |
||
| 602 | |||
| 603 | String indicacao = "NÃO INFORMADO"; |
||
| 604 | String novaIndicacao = "NÃO INFORMADO"; |
||
| 605 | if (VerificadorUtil.naoEstaNulo(parametrosVenda.getVenda().getIndicacao())) { |
||
| 606 | indicacao = parametrosVenda.getVenda().getIndicacao().getNome(); |
||
| 607 | } |
||
| 608 | if (VerificadorUtil.naoEstaNulo(parametrosVenda.getIndicacao())) { |
||
| 609 | novaIndicacao = parametrosVenda.getIndicacao().getNome(); |
||
| 610 | } |
||
| 611 | if (!indicacao.equals(novaIndicacao)) { |
||
| 612 | conteudo.append("INDICAÇÃO: " + indicacao + " -> " + novaIndicacao + "\n"); |
||
| 613 | } |
||
| 614 | |||
| 615 | String cliente = "NÃO INFORMADO"; |
||
| 616 | String novoCliente = "NÃO INFORMADO"; |
||
| 617 | if (VerificadorUtil.naoEstaNulo(parametrosVenda.getVenda().getCliente())) { |
||
| 618 | cliente = parametrosVenda.getVenda().getCliente().getNome(); |
||
| 619 | } |
||
| 620 | if (VerificadorUtil.naoEstaNulo(parametrosVenda.getCliente())) { |
||
| 621 | novoCliente = parametrosVenda.getCliente().getNome(); |
||
| 622 | } |
||
| 623 | if (!cliente.equals(novoCliente)) { |
||
| 624 | conteudo.append("CLIENTE: " + cliente + " -> " + novoCliente + "\n"); |
||
| 625 | } |
||
| 626 | |||
| 627 | if (!parametrosVenda.getObservacao().equals(parametrosVenda.getVenda().getObservacao())) { |
||
| 628 | conteudo.append("OBS: " + parametrosVenda.getVenda().getObservacao() + " -> " + parametrosVenda.getObservacao() + "\n"); |
||
| 629 | } |
||
| 630 | |||
| 631 | String formasPagamento = ""; |
||
| 632 | String novasFormasPagamento = ""; |
||
| 633 | List<VendaFormaPagamento> pagamentosAnteriores = consultarPagamentosCadastrados(parametrosVenda); |
||
| 634 | if (!VerificadorUtil.isListaNulaOuVazia(pagamentosAnteriores)) { |
||
| 635 | for (VendaFormaPagamento pagamento : pagamentosAnteriores) { |
||
| 636 | formasPagamento = formasPagamento + " R$" + pagamento.getValorPagamento() + " (" + pagamento.getFormaPagamento().getDescricao(); |
||
| 637 | if (VerificadorUtil.naoEstaNulo(pagamento.getBandeiraCartao())) { |
||
| 638 | formasPagamento = formasPagamento + " - " + pagamento.getBandeiraCartao().getTipoCartaoDescricao() + " - " + pagamento.getDescricaoDaBandeiraCartao(); |
||
| 639 | } |
||
| 640 | formasPagamento = formasPagamento + "); "; |
||
| 641 | } |
||
| 642 | } |
||
| 643 | if (!VerificadorUtil.isListaNulaOuVazia(parametrosVenda.getLancamentosPagamentos())) { |
||
| 644 | for (VendaFormaPagamento pagamento : parametrosVenda.getLancamentosPagamentos()) { |
||
| 645 | novasFormasPagamento = novasFormasPagamento + " R$" + pagamento.getValorPagamento() + " (" + pagamento.getFormaPagamento().getDescricao(); |
||
| 646 | if (VerificadorUtil.naoEstaNulo(pagamento.getBandeiraCartao())) { |
||
| 647 | novasFormasPagamento = novasFormasPagamento + " - " + pagamento.getBandeiraCartao().getTipoCartaoDescricao() + " - " + pagamento.getDescricaoDaBandeiraCartao(); |
||
| 648 | } |
||
| 649 | novasFormasPagamento = novasFormasPagamento + "); "; |
||
| 650 | } |
||
| 651 | } |
||
| 652 | if (!formasPagamento.equals(novasFormasPagamento)) { |
||
| 653 | conteudo.append("FORMAS DE PAGAMENTO: " + formasPagamento + " -> " + novasFormasPagamento + "\n"); |
||
| 654 | } |
||
| 655 | |||
| 656 | conteudo.append("\n"); |
||
| 657 | conteudo.append("JUSTIFICATIVA: " + parametrosVenda.getVenda().getJustificativaParaExcluir() + "\n"); |
||
| 658 | new GerenciadorEmailImpl() |
||
| 659 | .comEmailsDestino(ConstantesSEC.DESTINATARIOS_EMAIL_SUPERVISAO) |
||
| 660 | .comAssunto("ESPAÇO CASE - ALTERAÇÃO DE VENDA: " + diaAtual) |
||
| 661 | .comConteudo(conteudo.toString()) |
||
| 662 | .enviar(); |
||
| 663 | } |
||
| 664 | |||
| 665 | private String montarDadosDaVenda(Venda venda, Usuario usuario, List<Lancamento> lancamentos, List<VendaFormaPagamento> pagamentos) { |
||
| 666 | StringBuilder conteudo = new StringBuilder(); |
||
| 667 | conteudo.append("OPERAÇÃO REALIZADA POR: " + usuario.getNome() + "\n"); |
||
| 668 | conteudo.append("ID: " + venda.getSequencial() + "\n"); |
||
| 669 | conteudo.append("DATA DA VENDA: " + DataUtils.converterDataComHorarioParaString(venda.getDataVenda()) + "\n"); |
||
| 670 | conteudo.append("LOJA: " + venda.getLoja().getDescricao() + "\n"); |
||
| 671 | conteudo.append("VENDEDOR: " + venda.getVendedor().getNomeDaPessoa() + "\n"); |
||
| 672 | conteudo.append("TOTAL: " + valorTotalVenda(lancamentos) + "\n"); |
||
| 673 | conteudo.append("OBS.: " + venda.getObservacao() + "\n"); |
||
| 674 | if (VerificadorUtil.naoEstaNuloOuVazio(venda.getJustificativaParaExcluir())) { |
||
| 675 | conteudo.append("JUSTIFICATIVA: " + venda.getJustificativaParaExcluir() + "\n"); |
||
| 676 | } else { |
||
| 677 | conteudo.append("SEM JUSTIFICATIVA\n"); |
||
| 678 | } |
||
| 679 | conteudo.append("--------------------------------------------------\n"); |
||
| 680 | for (Lancamento lancamento : lancamentos) { |
||
| 681 | conteudo.append(lancamento.getProduto().getCodigoProdutoPadrao() + " | "); |
||
| 682 | conteudo.append(lancamento.getProduto().getDescricaoComModeloCompleta() + ", "); |
||
| 683 | conteudo.append("R$" + lancamento.getValorVenda()); |
||
| 684 | if (lancamento.comDescontos()) { |
||
| 685 | conteudo.append(" (COM DESCONTO DE R$" + lancamento.valorDescontos()); |
||
| 686 | conteudo.append(" [" + lancamento.valorPercentualDescontos() + "])"); |
||
| 687 | } |
||
| 688 | if (VerificadorUtil.naoEstaNuloOuVazio(lancamento.getObservacao())) { |
||
| 689 | conteudo.append(" (OBS.: " + lancamento.getObservacao() + ")"); |
||
| 690 | } |
||
| 691 | if (VerificadorUtil.naoEstaNulo(lancamento.getCupom())) { |
||
| 692 | String descricaoCupom = lancamento.getCupom().getCodigo(); |
||
| 693 | if (VerificadorUtil.naoEstaNulo(lancamento.getCupom().getDescricao())) { |
||
| 694 | descricaoCupom = descricaoCupom + " - " + lancamento.getCupom().getDescricao(); |
||
| 695 | } |
||
| 696 | conteudo.append(" (CUPOM: " + descricaoCupom + ")"); |
||
| 697 | } |
||
| 698 | conteudo.append("\n"); |
||
| 699 | } |
||
| 700 | conteudo.append("--------------------------------------------------\n"); |
||
| 701 | for (VendaFormaPagamento pagamento : pagamentos) { |
||
| 702 | if (VerificadorUtil.naoEstaNulo(pagamento.getBandeiraCartao())) { |
||
| 703 | conteudo.append(pagamento.getFormaPagamento().getDescricao() + " - " + pagamento.getBandeiraCartao().getDescricao() + ": R$" + pagamento.getValorPagamento() + "\n"); |
||
| 704 | } else { |
||
| 705 | conteudo.append(pagamento.getFormaPagamento().getDescricao() + ": R$" + pagamento.getValorPagamento() + "\n"); |
||
| 706 | } |
||
| 707 | conteudo.append("\n"); |
||
| 708 | } |
||
| 709 | conteudo.append("--------------------------------------------------\n"); |
||
| 710 | if (VerificadorUtil.naoEstaNulo(venda.getCliente())) { |
||
| 711 | conteudo.append("DADOS DO CLIENTE:\n"); |
||
| 712 | conteudo.append(venda.getCliente().getNome() + "\n"); |
||
| 713 | conteudo.append(venda.getCliente().getCpfCnpjFormatado() + "\n"); |
||
| 714 | } |
||
| 715 | return conteudo.toString(); |
||
| 716 | } |
||
| 717 | |||
| 718 | private Double valorTotalVenda(List<Lancamento> lancamentos) { |
||
| 719 | Double total = new Double(0.0); |
||
| 720 | for (Lancamento lancamento : lancamentos) { |
||
| 721 | if (lancamento.getAtivo()) { |
||
| 722 | total = total + lancamento.getValorVenda(); |
||
| 723 | } |
||
| 724 | } |
||
| 725 | return total; |
||
| 726 | } |
||
| 727 | |||
| 728 | private void atualizarDadosDaVenda(ParametrosVendaDTO parametrosVenda) { |
||
| 729 | parametrosVenda.getVenda().setVendedor(parametrosVenda.getVendedor()); |
||
| 730 | parametrosVenda.getVenda().setIndicacao(parametrosVenda.getIndicacao()); |
||
| 731 | parametrosVenda.getVenda().setCliente(parametrosVenda.getCliente()); |
||
| 732 | parametrosVenda.getVenda().setObservacao(parametrosVenda.getObservacao()); |
||
| 733 | parametrosVenda.getVenda().setNotaFiscal(parametrosVenda.getNotaFiscal()); |
||
| 734 | parametrosVenda.getVenda().setMaquineta(parametrosVenda.getMaquineta()); |
||
| 735 | if (!parametrosVenda.getVenda().getLoja().equals(parametrosVenda.getLoja())) { |
||
| 736 | for (Lancamento lancamento : parametrosVenda.getVenda().getLancamentos()) { |
||
| 737 | alterarEstoqueProduto(1, parametrosVenda.getVenda().getLoja(), lancamento.getProduto().getCodigo()); |
||
| 738 | alterarEstoqueProduto(-1, parametrosVenda.getLoja(), lancamento.getProduto().getCodigo()); |
||
| 739 | } |
||
| 740 | parametrosVenda.getVenda().setLoja(parametrosVenda.getLoja()); |
||
| 741 | parametrosVenda.getVenda().setMaquineta(parametrosVenda.getLoja().getMaquineta()); |
||
| 742 | } |
||
| 743 | parametrosVenda.getVenda().setTipoSituacao(parametrosVenda.getTipoSituacao()); |
||
| 744 | parametrosVenda.getVenda().setDataVenda(parametrosVenda.getDataVenda()); |
||
| 745 | } |
||
| 746 | |||
| 747 | @Override |
||
| 748 | public List<Venda> consultarVendasDoDia(Long sequencialLoja, Date dataVendas) { |
||
| 749 | return vendaRepository.consultarVendasDoDia(sequencialLoja, dataVendas); |
||
| 750 | } |
||
| 751 | |||
| 752 | @Override |
||
| 753 | public Integer obterQuantidadeDeVendasPorLojaEePeriodo(Venda venda, Date dataInicial, Date dataFinal) { |
||
| 754 | return vendaRepository.obterQuantidadeDeVendasPorLojaEePeriodo(venda, dataInicial, dataFinal); |
||
| 755 | } |
||
| 756 | |||
| 757 | @Override |
||
| 758 | public Double obterValorTotalBrutoDeVendasPorLojaEePeriodo(ParametrosConsultaVendasDTO parametrosConsulta) { |
||
| 759 | Double valorTotal = vendaRepository.obterValorTotalBrutoDeVendasPorLojaEePeriodo(parametrosConsulta); |
||
| 760 | valorTotal = valorTotal - vendaRepository.obterValorDeCuponsUtilizadosPorLojaEePeriodo(parametrosConsulta); |
||
| 761 | return valorTotal; |
||
| 762 | } |
||
| 763 | |||
| 764 | @Override |
||
| 765 | public Double obterValorTotalDeDescontosPorLojaEePeriodo(ParametrosConsultaVendasDTO parametrosConsulta) { |
||
| 766 | return vendaRepository.obterValorTotalDeDescontosPorLojaEePeriodo(parametrosConsulta); |
||
| 767 | } |
||
| 768 | |||
| 769 | @Override |
||
| 770 | public Double obterValorTotalBrutoDeVendasPorLojaEePeriodoEeFormasDePagamento(ParametrosConsultaVendasDTO parametrosConsultaVendas, List<FormaPagamento> formasDePagamento) { |
||
| 771 | return vendaRepository.obterValorTotalBrutoDeVendasPorLojaEePeriodoEeFormasDePagamento(parametrosConsultaVendas, formasDePagamento); |
||
| 772 | } |
||
| 773 | |||
| 774 | @Override |
||
| 775 | public Integer obterQuantidadeProdutosVendidosPorLojaEePeriodo(ParametrosConsultaVendasDTO parametrosConsultaVendas) { |
||
| 776 | return vendaRepository.obterQuantidadeProdutosVendidosPorLojaEePeriodo(parametrosConsultaVendas); |
||
| 777 | } |
||
| 778 | |||
| 779 | @Override |
||
| 780 | public Integer obterQuantidadeProdutosVendidosPorLojaEePeriodoNaoVivo(ParametrosConsultaVendasDTO parametrosConsultaVendas) { |
||
| 781 | return vendaRepository.obterQuantidadeProdutosVendidosPorLojaEePeriodoNaoVivo(parametrosConsultaVendas); |
||
| 782 | } |
||
| 783 | |||
| 784 | @Override |
||
| 785 | public Integer obterQuantidadeProdutosVendidosPorEstiloEeGenero(Date dataInicial, Date dataFinal, Long sequencialLoja, Long sequencialModelo, String tipoProduto, String estiloProduto, String tipoGenero) { |
||
| 786 | return vendaRepository.obterQuantidadeProdutosVendidosPorEstiloEeGenero(dataInicial, dataFinal, sequencialLoja, sequencialModelo, tipoProduto, estiloProduto, tipoGenero); |
||
| 787 | } |
||
| 788 | |||
| 789 | private void verificarLancamentos(List<Lancamento> lancamentos) { |
||
| 790 | if (lancamentos.isEmpty()) { |
||
| 791 | throw new NegocioException("Obrigatório informar ao menos um produto"); |
||
| 792 | } |
||
| 793 | } |
||
| 794 | */ |
||
| 795 | // TODO: EM DESENVOLVIMENTO |
||
| 796 | /* |
||
| 797 | private void lancarExcecaoCasoFreteContraditorio(ParametrosVendaDTO parametrosVenda) { |
||
| 798 | if (VerificadorUtil.naoEstaNulo(parametrosVenda.getTipoFrete())) { |
||
| 799 | if (parametrosVenda.getTipoFrete().equals(ConstantesSEC.NotaFiscal.Transporte.SEM_OCORRENCIA_TRANSPORTE_9) |
||
| 800 | && parametrosVenda.getValorFrete() > 0.0) { |
||
| 801 | throw new NegocioException("Não é possível informar o frete sem a ocorrência."); |
||
| 802 | } |
||
| 803 | if (parametrosVenda.getTipoFrete().equals(ConstantesSEC.NotaFiscal.Transporte.FRETE_POR_CONTA_REMETENTE_TRANSPORTE_PROPRIO_3) |
||
| 804 | && parametrosVenda.getValorFrete() == 0.0) { |
||
| 805 | throw new NegocioException("É necessário informar o valor do frete."); |
||
| 806 | } |
||
| 807 | |||
| 808 | } |
||
| 809 | // CASO TENHA VALOR E: FRETE CIF, FRETE DE TERCEIROS, FRETE REMETENTE (TP) OU SEM OCORRÊNCIA |
||
| 810 | // CASO NÃO TENHA VALOR E: FRETE FOB. |
||
| 811 | } |
||
| 812 | */ |
||
| 813 | /* |
||
| 814 | private void lancarExcecaoCasoNaoSejaInformadoCamposObrigatorios(ParametrosVendaDTO parametrosVenda) { |
||
| 815 | if (VerificadorUtil.isListaNulaOuVazia(parametrosVenda.getLancamentosPagamentos()) && VerificadorUtil.estaNuloOuVazio(parametrosVenda.getObservacao())) { |
||
| 816 | throw new NegocioException("Obrigatório informar as observações em vendas sem pagamentos"); |
||
| 817 | } |
||
| 818 | if (VerificadorUtil.estaNulo(parametrosVenda.getLoja())) { |
||
| 819 | throw new NegocioException("Informe a loja"); |
||
| 820 | } |
||
| 821 | } |
||
| 822 | */ |
||
| 823 | // private void lancarExcecaoSeValoresNaoSaoIguais(ParametrosVendaDTO parametrosVenda) { |
||
| 824 | // final double TOLERANCE = 0.01; |
||
| 825 | // if(Math.abs(parametrosVenda.valorTotalLancamentos() /*+ parametrosVenda.getValorFrete() */- parametrosVenda.valorTotalPago()) > TOLERANCE) { |
||
| 826 | // throw new NegocioException("Valores pagos não corresponde ao valor vendido."); |
||
| 827 | // } |
||
| 828 | // } |
||
| 829 | /* |
||
| 830 | private void cadastrarLancamentos(ParametrosVendaDTO parametrosVenda, Venda venda) { |
||
| 831 | for (Lancamento lancamento : parametrosVenda.getLancamentos()) { |
||
| 832 | cadastrarLancamento(parametrosVenda.getLoja(), venda, lancamento); |
||
| 833 | } |
||
| 834 | } |
||
| 835 | |||
| 836 | private void alterarLancamentos(ParametrosVendaDTO parametrosVenda) { |
||
| 837 | excluirLancamentosRetiradosDaLista(parametrosVenda, consultarLancamentosCadastrados(parametrosVenda)); |
||
| 838 | cadastrarNovosLancamentos(parametrosVenda); |
||
| 839 | } |
||
| 840 | |||
| 841 | private void excluirLancamentosRetiradosDaLista(ParametrosVendaDTO parametrosVenda, List<Lancamento> lancamentosAntigos) { |
||
| 842 | for (Lancamento lancamentoAntigo : lancamentosAntigos) { |
||
| 843 | if (!parametrosVenda.getLancamentos().contains(lancamentoAntigo)) { |
||
| 844 | lancamentoService.excluir(lancamentoAntigo); |
||
| 845 | alterarEstoqueProduto(1, parametrosVenda.getLoja(), lancamentoAntigo.getProduto().getCodigo()); |
||
| 846 | } |
||
| 847 | } |
||
| 848 | } |
||
| 849 | |||
| 850 | private void cadastrarNovosLancamentos(ParametrosVendaDTO parametrosVenda) { |
||
| 851 | for (Lancamento lancamento : parametrosVenda.getLancamentos()) { |
||
| 852 | if (VerificadorUtil.estaNulo(lancamento.getSequencial())) { |
||
| 853 | cadastrarLancamento(parametrosVenda.getLoja(), parametrosVenda.getVenda(), lancamento); |
||
| 854 | } |
||
| 855 | } |
||
| 856 | } |
||
| 857 | |||
| 858 | private List<Lancamento> consultarLancamentosCadastrados(ParametrosVendaDTO parametrosVenda) { |
||
| 859 | Lancamento lancamentoDaVenda = new Lancamento(); |
||
| 860 | lancamentoDaVenda.setVenda(parametrosVenda.getVenda()); |
||
| 861 | return lancamentoService.consultarPassandoEntidade(lancamentoDaVenda, 0, lancamentoService.obterQuantidadeDeRegistrosPassandoEntidade(lancamentoDaVenda)); |
||
| 862 | } |
||
| 863 | |||
| 864 | private void cadastrarLancamento(Loja loja, Venda venda, Lancamento lancamento) { |
||
| 865 | lancamento.setVenda(venda); |
||
| 866 | igualarValorVarejoComCompraSeProdutoForPadrao(lancamento); |
||
| 867 | acrescentarValorIPISeHouver(lancamento); |
||
| 868 | lancamentoService.cadastrar(lancamento); |
||
| 869 | alterarEstoqueProduto(-1, loja, lancamento.getProduto().getCodigo()); |
||
| 870 | utilizarCupom(lancamento.getCupom()); |
||
| 871 | |||
| 872 | } |
||
| 873 | |||
| 874 | private void igualarValorVarejoComCompraSeProdutoForPadrao(Lancamento lancamento) { |
||
| 875 | if (VerificadorUtil.naoEstaNulo(lancamento.getProduto())) { |
||
| 876 | if (lancamento.getProduto().getCodigo().equals(ConstantesSEC.CODIGO_PRODUTO_PADRAO_000000)) { |
||
| 877 | lancamento.setValorVarejo(lancamento.getValorVenda()); |
||
| 878 | } |
||
| 879 | } |
||
| 880 | } |
||
| 881 | |||
| 882 | private void acrescentarValorIPISeHouver(Lancamento lancamento) { |
||
| 883 | if (VerificadorUtil.naoEstaNulo(lancamento.getProduto())) { |
||
| 884 | lancamento.setValorCompra(lancamento.getProduto().getValorCompra()); |
||
| 885 | // lancamento.setValorCompra(lancamento.getProduto().calculoOperacao()); |
||
| 886 | } |
||
| 887 | } |
||
| 888 | |||
| 889 | private void cadastrarPagamentos(ParametrosVendaDTO parametrosVenda, Venda venda) { |
||
| 890 | for (VendaFormaPagamento vendaFormaPagamento : parametrosVenda.getLancamentosPagamentos()) { |
||
| 891 | adicionarMaquineta(vendaFormaPagamento, parametrosVenda, venda); |
||
| 892 | vendaFormaPagamento.setVenda(venda); |
||
| 893 | vendaFormaPagamentoService.cadastrar(vendaFormaPagamento); |
||
| 894 | utilizarCupom(vendaFormaPagamento.getCupom()); |
||
| 895 | } |
||
| 896 | } |
||
| 897 | |||
| 898 | private void adicionarMaquineta(VendaFormaPagamento vendaFormaPagamento, ParametrosVendaDTO parametrosVenda, Venda venda) { |
||
| 899 | if (vendaFormaPagamento.getFormaPagamento().formaPagamentoEhCartao()) { |
||
| 900 | if (VerificadorUtil.estaNulo(parametrosVenda.getMaquineta())) { |
||
| 901 | parametrosVenda.setMaquineta(parametrosVenda.getLoja().getMaquineta()); |
||
| 902 | } |
||
| 903 | venda.setMaquineta(parametrosVenda.getMaquineta()); |
||
| 904 | } |
||
| 905 | } |
||
| 906 | |||
| 907 | private void alterarPagamentos(ParametrosVendaDTO parametrosVenda) { |
||
| 908 | excluirPagamentosRetiradosDaLista(parametrosVenda, consultarPagamentosCadastrados(parametrosVenda)); |
||
| 909 | cadastrarNovosPagamentos(parametrosVenda); |
||
| 910 | } |
||
| 911 | |||
| 912 | private void excluirPagamentosRetiradosDaLista(ParametrosVendaDTO parametrosVenda, List<VendaFormaPagamento> pagamentosAntigos) { |
||
| 913 | for (VendaFormaPagamento pagamentoAntigo : pagamentosAntigos) { |
||
| 914 | if (!parametrosVenda.getLancamentosPagamentos().contains(pagamentoAntigo)) { |
||
| 915 | vendaFormaPagamentoService.excluir(pagamentoAntigo); |
||
| 916 | } |
||
| 917 | // if (verificarSePagamentoFoiRetiradoDaLista(parametrosVenda.getLancamentosPagamentos(), pagamentoAntigo)) { |
||
| 918 | // vendaFormaPagamentoService.excluirPorId(pagamentoAntigo); |
||
| 919 | // } |
||
| 920 | } |
||
| 921 | } |
||
| 922 | |||
| 923 | private boolean verificarSePagamentoFoiRetiradoDaLista(List<VendaFormaPagamento> pagamentos, VendaFormaPagamento pagamentoAntigo) { |
||
| 924 | boolean pagamentoRetirado = true; |
||
| 925 | for (VendaFormaPagamento pagamento : pagamentos) { |
||
| 926 | if (pagamento.getCodigoDaFormaPagamento().equals(pagamentoAntigo.getCodigoDaFormaPagamento())) { |
||
| 927 | if (verificarSeBandeiraCartaoEhIgual(pagamento.getCodigoDaBandeiraCartao(), pagamentoAntigo.getCodigoDaBandeiraCartao()) && |
||
| 928 | pagamento.getValorPagamento().equals(pagamentoAntigo.getValorPagamento())) { |
||
| 929 | return false; |
||
| 930 | } else { |
||
| 931 | pagamento.setVenda(pagamentoAntigo.getVenda()); |
||
| 932 | vendaFormaPagamentoService.alterar(pagamento); |
||
| 933 | return false; |
||
| 934 | } |
||
| 935 | } |
||
| 936 | } |
||
| 937 | return pagamentoRetirado; |
||
| 938 | } |
||
| 939 | |||
| 940 | private boolean verificarSeBandeiraCartaoEhIgual(Long codigoDaBandeiraCartao, Long codigoDaBandeiraCartaoSegundo) { |
||
| 941 | if (VerificadorUtil.naoEstaNulo(codigoDaBandeiraCartao) && VerificadorUtil.naoEstaNulo(codigoDaBandeiraCartaoSegundo)) { |
||
| 942 | return codigoDaBandeiraCartao.equals(codigoDaBandeiraCartaoSegundo); |
||
| 943 | } |
||
| 944 | if ((VerificadorUtil.estaNulo(codigoDaBandeiraCartao) && VerificadorUtil.naoEstaNulo(codigoDaBandeiraCartaoSegundo)) || |
||
| 945 | (VerificadorUtil.naoEstaNulo(codigoDaBandeiraCartao) && VerificadorUtil.estaNulo(codigoDaBandeiraCartaoSegundo))) { |
||
| 946 | return false; |
||
| 947 | } |
||
| 948 | return true; |
||
| 949 | } |
||
| 950 | |||
| 951 | private void cadastrarNovosPagamentos(ParametrosVendaDTO parametrosVenda) { |
||
| 952 | for (VendaFormaPagamento pagamento : parametrosVenda.getLancamentosPagamentos()) { |
||
| 953 | if (VerificadorUtil.estaNulo(pagamento.getSequencial())) { |
||
| 954 | adicionarMaquineta(pagamento, parametrosVenda, parametrosVenda.getVenda()); |
||
| 955 | pagamento.setVenda(parametrosVenda.getVenda()); |
||
| 956 | vendaFormaPagamentoService.cadastrar(pagamento); |
||
| 957 | utilizarCupom(pagamento.getCupom()); |
||
| 958 | } |
||
| 959 | } |
||
| 960 | } |
||
| 961 | |||
| 962 | private List<VendaFormaPagamento> consultarPagamentosCadastrados(ParametrosVendaDTO parametrosVenda) { |
||
| 963 | VendaFormaPagamento pagamentoDaVenda = new VendaFormaPagamento(); |
||
| 964 | pagamentoDaVenda.setVenda(parametrosVenda.getVenda()); |
||
| 965 | return vendaFormaPagamentoService.consultarPassandoEntidade(pagamentoDaVenda, 0, vendaFormaPagamentoService.obterQuantidadeDeRegistrosPassandoEntidade(pagamentoDaVenda)); |
||
| 966 | } |
||
| 967 | |||
| 968 | private void alterarEstoqueProduto(Integer quantidadeAlterar, Loja loja, String codigoProduto) { |
||
| 969 | if (VerificadorUtil.naoEstaNulo(codigoProduto)) { |
||
| 970 | Produto produto = produtoService.consultarProdutoPorCodigo(codigoProduto); |
||
| 971 | produtoLojaService.alterarEstoqueAcrescentandoQuantidadeInformada(quantidadeAlterar, produto, loja); |
||
| 972 | } |
||
| 973 | } |
||
| 974 | |||
| 975 | private void utilizarCupom(Cupom cupom) { |
||
| 976 | if (VerificadorUtil.naoEstaNulo(cupom)) { |
||
| 977 | Cupom cupomUtilizado = cupomService.consultarPorId(cupom); |
||
| 978 | cupomUtilizado.setDataHoraUtilizado(DataUtils.getDataAtual()); |
||
| 979 | if (VerificadorUtil.estaNulo(cupomUtilizado.getQuantidadeUtilizada())) { |
||
| 980 | cupomUtilizado.setQuantidadeUtilizada(0); |
||
| 981 | } |
||
| 982 | cupomUtilizado.setQuantidadeUtilizada(cupomUtilizado.getQuantidadeUtilizada() + 1); |
||
| 983 | cupomService.alterar(cupomUtilizado); |
||
| 984 | } |
||
| 985 | } |
||
| 986 | |||
| 987 | @Override |
||
| 988 | public List<Venda> consultarVendasPorDemanda(ParametrosConsulta<Venda> parametrosConsulta, Integer primeiroRegistro, |
||
| 989 | Integer tamanhoPagina, String sortField, String orderSort, Map<String, Object> filters) { |
||
| 990 | return vendaRepository.consultarVendasPorDemanda(parametrosConsulta, primeiroRegistro, tamanhoPagina, sortField, orderSort, filters); |
||
| 991 | } |
||
| 992 | |||
| 993 | @Override |
||
| 994 | public List<Venda> consultarVendaPorParametros(ParametrosConsultaVendasDTO parametrosConsultaVendas) { |
||
| 995 | return vendaRepository.consultarVendaPorParametros(parametrosConsultaVendas); |
||
| 996 | } |
||
| 997 | |||
| 998 | @Override |
||
| 999 | public GraficoAcumuladoDTO consultarGrafico(String mes, String ano) { |
||
| 1000 | return vendaRepository.consultarGrafico(mes, ano); |
||
| 1001 | } |
||
| 1002 | |||
| 1003 | @Override |
||
| 1004 | public List<RankingVendedorDTO> consultarRankingVendedores(Date dataInicial, Date dataFinal, Boolean produtosComissionados, Loja lojaSelecionada) { |
||
| 1005 | List<RankingVendedorDTO> rankingVendedores = new ArrayList<RankingVendedorDTO>(); |
||
| 1006 | List<Vendedor> vendedores = vendedorService.consultarVendedoresColaboradoresAtivos(lojaSelecionada); |
||
| 1007 | for (Vendedor vendedor : vendedores) { |
||
| 1008 | RankingVendedorDTO vendedorConsultado = consultarRankingVendedor(vendedor, dataInicial, dataFinal, produtosComissionados); |
||
| 1009 | rankingVendedores.add(vendedorConsultado); |
||
| 1010 | } |
||
| 1011 | return (List<RankingVendedorDTO>) ordenador.ordenar(rankingVendedores); |
||
| 1012 | } |
||
| 1013 | |||
| 1014 | @Override |
||
| 1015 | public RankingVendedorDTO consultarRankingVendedor(Vendedor vendedor, Vigencia vigencia, Boolean produtosComissionados) { |
||
| 1016 | Avaliacao avaliacao = avaliacaoService.consultarAvaliacaoDaVigencia(vigencia); |
||
| 1017 | RankingVendedorDTO rankingVendedor = consultarRankingVendedor(vendedor, vigencia.getDataInicio(), vigencia.getDataFim(), produtosComissionados); |
||
| 1018 | rankingVendedor.setFuncionario(funcionarioService.consultarFuncionarioPorPessoa(vendedor.getPessoa())); |
||
| 1019 | rankingVendedor.setQuantidadeBancoHoras(bancoHorasService.consultarQuantidadeHoras(rankingVendedor.getFuncionario())); |
||
| 1020 | AvaliacaoFuncionario avaliacaoFuncionario = avaliacaoFuncionarioService.detalhar(vendedor.getPessoa(), avaliacao); |
||
| 1021 | if (VerificadorUtil.naoEstaNuloOuVazio(avaliacaoFuncionario)) { |
||
| 1022 | rankingVendedor.setAvaliacaoFuncionario(avaliacaoFuncionario); |
||
| 1023 | if (VerificadorUtil.naoEstaNulo(avaliacaoFuncionario.getPorcentagemComissao())) { |
||
| 1024 | rankingVendedor.setComissao(calcularComissao(rankingVendedor.getValorTotalVendido(), avaliacaoFuncionario.getPorcentagemComissao()/100)); |
||
| 1025 | } else { |
||
| 1026 | rankingVendedor.setComissao(calcularComissao(rankingVendedor.getValorTotalVendido(), avaliacaoFuncionario.retornarFaixaComissao(rankingVendedor.getValorTotalVendido(), rankingVendedor.getFuncionario().getTipoComissionamento()))); |
||
| 1027 | } |
||
| 1028 | } |
||
| 1029 | return rankingVendedor; |
||
| 1030 | } |
||
| 1031 | |||
| 1032 | public Double calcularComissao(Double valorTotalVendido, Double porcentagemComissao) { |
||
| 1033 | if (VerificadorUtil.naoEstaNuloOuVazio(porcentagemComissao)) { |
||
| 1034 | return valorTotalVendido * porcentagemComissao; |
||
| 1035 | } |
||
| 1036 | return 0.0; |
||
| 1037 | } |
||
| 1038 | |||
| 1039 | @Override |
||
| 1040 | public RankingVendedorDTO consultarRankingVendedor(Vendedor vendedor, Date dataInicial, Date dataFinal, Boolean produtosComissionados) { |
||
| 1041 | ParametrosConsultaVendasDTO parametrosConsultaVendas = new ParametrosConsultaVendasDTO(); |
||
| 1042 | parametrosConsultaVendas.setDataInicial(DataUtils.getDataComHorarioMinimo(dataInicial)); |
||
| 1043 | parametrosConsultaVendas.setDataFinal(DataUtils.getDataComHorarioMaximo(dataFinal)); |
||
| 1044 | parametrosConsultaVendas.setVendedor(vendedor); |
||
| 1045 | if (VerificadorUtil.naoEstaNulo(produtosComissionados)) { |
||
| 1046 | parametrosConsultaVendas.setIndicadorComissionado(produtosComissionados); |
||
| 1047 | } |
||
| 1048 | |||
| 1049 | RankingVendedorDTO rankingVendedor = new RankingVendedorDTO(); |
||
| 1050 | rankingVendedor.setVendedor(vendedor); |
||
| 1051 | try { |
||
| 1052 | rankingVendedor.setFuncionario(funcionarioService.consultarFuncionarioPorPessoa(vendedor.getPessoa())); |
||
| 1053 | rankingVendedor.setQuantidadeBancoHoras(bancoHorasService.consultarQuantidadeHoras(rankingVendedor.getFuncionario())); |
||
| 1054 | } catch (RuntimeException e) { |
||
| 1055 | rankingVendedor.setFuncionario(null); |
||
| 1056 | } |
||
| 1057 | |||
| 1058 | rankingVendedor.setValorTotalVendido(obterValorTotalBrutoDeVendasPorLojaEePeriodo(parametrosConsultaVendas)); |
||
| 1059 | rankingVendedor.setValorTotalDescontos(obterValorTotalDeDescontosPorLojaEePeriodo(parametrosConsultaVendas)); |
||
| 1060 | rankingVendedor.setQuantidadeTotalProdutosVendidos(obterQuantidadeProdutosVendidosPorLojaEePeriodo(parametrosConsultaVendas)); |
||
| 1061 | |||
| 1062 | Venda venda = new Venda(); |
||
| 1063 | venda.setVendedor(vendedor); |
||
| 1064 | rankingVendedor.setQuantidadeVendas(obterQuantidadeDeVendasPorLojaEePeriodo(venda, dataInicial, dataFinal)); |
||
| 1065 | rankingVendedor.setQuantidadePedidos(obterQuantidadePedidosValidos(vendedor, null, dataInicial, dataFinal)); |
||
| 1066 | rankingVendedor.setQuantidadePedidosInvalidos(obterQuantidadePedidos(vendedor, null, dataInicial, dataFinal, TipoSituacaoPedido.INVALIDO.getValor())); |
||
| 1067 | rankingVendedor.setQuantidadeContagens(obterQuantidadeDeContagens(vendedor, dataInicial, dataFinal)); |
||
| 1068 | rankingVendedor.setQuantidadeAtendimentos(obterQuantidadeDeAtendimentos(vendedor, dataInicial, dataFinal)); |
||
| 1069 | rankingVendedor.setValorTotalVendidoVivo(obterValorTotalBrutoDeVendasVivoPorLojaEePeriodo(parametrosConsultaVendas)); |
||
| 1070 | |||
| 1071 | rankingVendedor.setAvaliacaoFuncionario(avaliacaoFuncionarioService.consultarAvaliacaoFuncionarioPelaData(vendedor, DataUtils.getDataComHorarioMinimo(dataFinal))); |
||
| 1072 | if (VerificadorUtil.naoEstaNulo(rankingVendedor.getAvaliacaoFuncionario())) { |
||
| 1073 | rankingVendedor.setPercentualDescontos(rankingVendedor.getAvaliacaoFuncionario().retornarPercentual(rankingVendedor.getValorTotalDescontos(), rankingVendedor.getValorTotalVendido())); |
||
| 1074 | rankingVendedor.setPercentualMetaMensal(rankingVendedor.getAvaliacaoFuncionario().retornarPercentualRealizado(rankingVendedor.getValorTotalVendido())); |
||
| 1075 | rankingVendedor.setPercentualMetaMensalVivo(rankingVendedor.getAvaliacaoFuncionario().retornarPercentualVivoRealizado(rankingVendedor.getValorTotalVendidoVivo())); |
||
| 1076 | } |
||
| 1077 | |||
| 1078 | ParametrosConsultaVendasDTO parametrosConsultaVendasDoDia = new ParametrosConsultaVendasDTO(); |
||
| 1079 | parametrosConsultaVendasDoDia.setDataInicial(DataUtils.getDataComHorarioMinimo(DataUtils.getDataAtual())); |
||
| 1080 | parametrosConsultaVendasDoDia.setDataFinal(DataUtils.getDataComHorarioMaximo(DataUtils.getDataAtual())); |
||
| 1081 | parametrosConsultaVendasDoDia.setVendedor(vendedor); |
||
| 1082 | if (VerificadorUtil.naoEstaNulo(produtosComissionados)) { |
||
| 1083 | parametrosConsultaVendasDoDia.setIndicadorComissionado(produtosComissionados); |
||
| 1084 | } |
||
| 1085 | rankingVendedor.setValorTotalVendidoDoDia(obterValorTotalBrutoDeVendasPorLojaEePeriodo(parametrosConsultaVendasDoDia)); |
||
| 1086 | |||
| 1087 | return rankingVendedor; |
||
| 1088 | } |
||
| 1089 | |||
| 1090 | private Integer obterQuantidadePedidos(Vendedor vendedor, Loja loja, Date dataInicial, Date dataFinal, String tipoSituacao) { |
||
| 1091 | if (VerificadorUtil.naoEstaNulo(vendedor)) { |
||
| 1092 | if (VerificadorUtil.estaNulo(vendedor.getPessoa())) { |
||
| 1093 | return 0; |
||
| 1094 | } |
||
| 1095 | } |
||
| 1096 | ParametrosConsultaPedidoDTO parametrosPedidos = new ParametrosConsultaPedidoDTO(); |
||
| 1097 | if (VerificadorUtil.naoEstaNulo(vendedor)) { |
||
| 1098 | parametrosPedidos.setPessoa(vendedor.getPessoa()); |
||
| 1099 | } |
||
| 1100 | parametrosPedidos.setEntidade(new Pedido()); |
||
| 1101 | parametrosPedidos.getEntidade().setTipoSituacao(tipoSituacao); |
||
| 1102 | parametrosPedidos.getEntidade().setLoja(loja); |
||
| 1103 | parametrosPedidos.setDataInicial(dataInicial); |
||
| 1104 | parametrosPedidos.setDataFinal(dataFinal); |
||
| 1105 | return pedidoService.obterQuantidadeDeRegistrosParametrosConsulta(parametrosPedidos); |
||
| 1106 | } |
||
| 1107 | |||
| 1108 | private Integer obterQuantidadePedidosValidos(Vendedor vendedor, Loja loja, Date dataInicial, Date dataFinal) { |
||
| 1109 | if (VerificadorUtil.naoEstaNulo(vendedor)) { |
||
| 1110 | if (VerificadorUtil.estaNulo(vendedor.getPessoa())) { |
||
| 1111 | return 0; |
||
| 1112 | } |
||
| 1113 | } |
||
| 1114 | ParametrosConsultaPedidoDTO parametrosPedidos = new ParametrosConsultaPedidoDTO(); |
||
| 1115 | if (VerificadorUtil.naoEstaNulo(vendedor)) { |
||
| 1116 | parametrosPedidos.setPessoa(vendedor.getPessoa()); |
||
| 1117 | } |
||
| 1118 | parametrosPedidos.setEntidade(new Pedido()); |
||
| 1119 | parametrosPedidos.getEntidade().setLoja(loja); |
||
| 1120 | parametrosPedidos.setDataInicial(dataInicial); |
||
| 1121 | parametrosPedidos.setDataFinal(dataFinal); |
||
| 1122 | parametrosPedidos.setValidos(true); |
||
| 1123 | return pedidoService.obterQuantidadeDeRegistrosParametrosConsulta(parametrosPedidos); |
||
| 1124 | } |
||
| 1125 | |||
| 1126 | private Integer obterQuantidadeDeContagens(Vendedor vendedor, Date dataInicial, Date dataFinal) { |
||
| 1127 | if (VerificadorUtil.naoEstaNulo(vendedor)) { |
||
| 1128 | if (VerificadorUtil.estaNulo(vendedor.getPessoa())) { |
||
| 1129 | return 0; |
||
| 1130 | } |
||
| 1131 | } |
||
| 1132 | return produtoLojaService.obterQuantidadeDeContagens(vendedor.getPessoa(), dataInicial, dataFinal); |
||
| 1133 | } |
||
| 1134 | |||
| 1135 | private Integer obterQuantidadeDeAtendimentos(Vendedor vendedor, Date dataInicial, Date dataFinal) { |
||
| 1136 | if (VerificadorUtil.estaNulo(vendedor.getPessoa())) { |
||
| 1137 | return 0; |
||
| 1138 | } |
||
| 1139 | return produtoLojaService.obterQuantidadeDeAtendimentos(vendedor.getPessoa(), dataInicial, dataFinal); |
||
| 1140 | } |
||
| 1141 | |||
| 1142 | private Integer obterQuantidadeDeAtendimentos(Loja loja, Date dataInicial, Date dataFinal) { |
||
| 1143 | return produtoLojaService.obterQuantidadeDeAtendimentos(loja, dataInicial, dataFinal); |
||
| 1144 | } |
||
| 1145 | |||
| 1146 | private Double obterValorTotalBrutoDeVendasVivoPorLojaEePeriodo(ParametrosConsultaVendasDTO parametrosConsultaVendas) { |
||
| 1147 | ParametrosConsultaVendasVivoDTO parametrosConsultaVendasVivo = new ParametrosConsultaVendasVivoDTO(); |
||
| 1148 | parametrosConsultaVendasVivo.setVendedor(parametrosConsultaVendas.getVendedor()); |
||
| 1149 | parametrosConsultaVendasVivo.setDataInicial(parametrosConsultaVendas.getDataInicial()); |
||
| 1150 | parametrosConsultaVendasVivo.setDataFinal(parametrosConsultaVendas.getDataFinal()); |
||
| 1151 | return vendaVivoService.obterValorTotalBrutoDeVendasPorLojaEePeriodo(parametrosConsultaVendasVivo); |
||
| 1152 | } |
||
| 1153 | |||
| 1154 | @Override |
||
| 1155 | public List<RankingLojaDTO> consultarRankingLojas(Date dataInicial, Date dataFinal) { |
||
| 1156 | List<RankingLojaDTO> rankingLojas = new ArrayList<RankingLojaDTO>(); |
||
| 1157 | List<Loja> lojas = lojaService.listarLojasAtivas(); |
||
| 1158 | ParametrosConsultaVendasDTO parametrosConsultaVendas = new ParametrosConsultaVendasDTO(); |
||
| 1159 | parametrosConsultaVendas.setDataInicial(DataUtils.getDataComHorarioMinimo(dataInicial)); |
||
| 1160 | parametrosConsultaVendas.setDataFinal(DataUtils.getDataComHorarioMaximo(dataFinal)); |
||
| 1161 | for (Loja loja : lojas) { |
||
| 1162 | if (!loja.getSequencial().equals(ConstantesSEC.SEQUENCIAL_LOJA_FARMACIA_7) |
||
| 1163 | && !loja.getSequencial().equals(ConstantesSEC.SEQUENCIAL_RESTAURANTE_16)) { |
||
| 1164 | parametrosConsultaVendas.setLoja(loja); |
||
| 1165 | |||
| 1166 | RankingLojaDTO rankingLoja = new RankingLojaDTO(); |
||
| 1167 | rankingLoja.setLoja(loja); |
||
| 1168 | rankingLoja.setValorTotalVendido(obterValorTotalBrutoDeVendasPorLojaEePeriodo(parametrosConsultaVendas) |
||
| 1169 | - obterValorTotalBrutoDeVendasPorLojaEePeriodoServicos(parametrosConsultaVendas)); |
||
| 1170 | rankingLoja.setAvaliacaoLoja(avaliacaoLojaService.consultarAvaliacaoLojaPelaData(loja, DataUtils.getDataComHorarioMinimo(dataFinal))); |
||
| 1171 | if (VerificadorUtil.naoEstaNulo(rankingLoja.getAvaliacaoLoja())) { |
||
| 1172 | rankingLoja.setValorMetaMensal(rankingLoja.getAvaliacaoLoja().getValorMetaMensal()); |
||
| 1173 | } |
||
| 1174 | rankingLojas.add(rankingLoja); |
||
| 1175 | } |
||
| 1176 | } |
||
| 1177 | return (List<RankingLojaDTO>) ordenador.ordenar(rankingLojas); |
||
| 1178 | } |
||
| 1179 | |||
| 1180 | @Override |
||
| 1181 | public List<RankingLojaDTO> consultarRankingLojasCompleto(Date dataInicial, Date dataFinal) { |
||
| 1182 | List<RankingLojaDTO> rankingLojasCompleto = new ArrayList<RankingLojaDTO>(); |
||
| 1183 | List<RankingLojaDTO> rankingLojas = consultarRankingLojas(dataInicial, dataFinal); |
||
| 1184 | for (RankingLojaDTO rankingLoja : rankingLojas) { |
||
| 1185 | rankingLoja.setQuantidadeVendas(obterQuantidadeDeVendasPorLojaEePeriodo(new Venda(rankingLoja.getLoja(), null), dataInicial, dataFinal)); |
||
| 1186 | rankingLoja.setQuantidadeAtendimentos(obterQuantidadeDeAtendimentos(rankingLoja.getLoja(), dataInicial, dataFinal)); |
||
| 1187 | rankingLoja.setQuantidadePedidos(obterQuantidadePedidosValidos(null, rankingLoja.getLoja(), dataInicial, dataFinal)); |
||
| 1188 | rankingLoja.setQuantidadePedidosInvalidos(obterQuantidadePedidos(null, rankingLoja.getLoja(), dataInicial, dataFinal, TipoSituacaoPedido.INVALIDO.getValor())); |
||
| 1189 | |||
| 1190 | ParametrosConsultaPorPeriodoDTO parametrosConsulta = new ParametrosConsultaPorPeriodoDTO(); |
||
| 1191 | ((ParametrosConsultaPorPeriodoDTO)parametrosConsulta).setDataInicial(dataInicial); |
||
| 1192 | ((ParametrosConsultaPorPeriodoDTO)parametrosConsulta).setDataFinal(dataFinal); |
||
| 1193 | EstoqueAuditoria estoqueAuditoria = new EstoqueAuditoria(); |
||
| 1194 | estoqueAuditoria.setLoja(rankingLoja.getLoja()); |
||
| 1195 | estoqueAuditoria.setTipoEstoqueAuditoria(TipoEstoqueAuditoria.AVARIA.getValor()); |
||
| 1196 | parametrosConsulta.setEntidade(estoqueAuditoria); |
||
| 1197 | rankingLoja.setQuantidadeAvarias(estoqueAuditoriaService.obterQuantidadeTotalAuditoria(parametrosConsulta)); |
||
| 1198 | |||
| 1199 | estoqueAuditoria.setTipoEstoqueAuditoria(TipoEstoqueAuditoria.TROCA.getValor()); |
||
| 1200 | parametrosConsulta.setEntidade(estoqueAuditoria); |
||
| 1201 | rankingLoja.setQuantidadeTrocas(estoqueAuditoriaService.obterQuantidadeTotalAuditoria(parametrosConsulta)); |
||
| 1202 | |||
| 1203 | ParametrosConsultaVendasDTO parametrosConsultaVendas = new ParametrosConsultaVendasDTO(); |
||
| 1204 | parametrosConsultaVendas.setDataInicial(DataUtils.getDataComHorarioMinimo(dataInicial)); |
||
| 1205 | parametrosConsultaVendas.setDataFinal(DataUtils.getDataComHorarioMaximo(dataFinal)); |
||
| 1206 | parametrosConsultaVendas.setLoja(rankingLoja.getLoja()); |
||
| 1207 | rankingLoja.setValorTotalDescontos(obterValorTotalDeDescontosPorLojaEePeriodo(parametrosConsultaVendas)); |
||
| 1208 | rankingLoja.setCustoProdutosVendidos(obterValorProdutosUtilizadosEmVendasPorLojaEePeriodo(parametrosConsultaVendas)); |
||
| 1209 | rankingLoja.setValorTotalEstoque(produtoService.valorTotalEstoque(rankingLoja.getLoja(), null)); |
||
| 1210 | rankingLoja.setQuantidadeTotalEstoque(produtoService.quantidadeTotalEstoque(rankingLoja.getLoja())); |
||
| 1211 | |||
| 1212 | ParametrosConsultaLancamentosDTO parametros = new ParametrosConsultaLancamentosDTO(); |
||
| 1213 | parametros.setCategoria(new Categoria(ConstantesSEC.Categoria.SEQUENCIAL_CATEGORIA_ALUGUEL_11)); |
||
| 1214 | parametros.setCentroDeCustos(rankingLoja.getLoja()); |
||
| 1215 | parametros.setPagamentoRealizado(true); |
||
| 1216 | parametros.setDataInicial(dataInicial); |
||
| 1217 | parametros.setDataFinal(dataFinal); |
||
| 1218 | Double valorCac = 0.0; |
||
| 1219 | |||
| 1220 | valorCac = somarValor(valorCac, parcelaService.obterValorPassandoParametrosConsulta(parametros)); |
||
| 1221 | parametros.setCategoria(new Categoria(ConstantesSEC.Categoria.SEQUENCIAL_CATEGORIA_HORA_EXTRA_2)); |
||
| 1222 | valorCac = somarValor(valorCac, parcelaService.obterValorPassandoParametrosConsulta(parametros)); |
||
| 1223 | parametros.setCategoria(new Categoria(ConstantesSEC.Categoria.SEQUENCIAL_CATEGORIA_SALARIO_9)); |
||
| 1224 | valorCac = somarValor(valorCac, parcelaService.obterValorPassandoParametrosConsulta(parametros)); |
||
| 1225 | parametros.setCategoria(new Categoria(ConstantesSEC.Categoria.SEQUENCIAL_CATEGORIA_FERIAS_12)); |
||
| 1226 | valorCac = somarValor(valorCac, parcelaService.obterValorPassandoParametrosConsulta(parametros)); |
||
| 1227 | parametros.setCategoria(new Categoria(ConstantesSEC.Categoria.SEQUENCIAL_CATEGORIA_COMISSOES_8)); |
||
| 1228 | valorCac = somarValor(valorCac, parcelaService.obterValorPassandoParametrosConsulta(parametros)); |
||
| 1229 | parametros.setCategoria(new Categoria(ConstantesSEC.Categoria.SEQUENCIAL_CATEGORIA_VALE_TRANSPORTE_46)); |
||
| 1230 | valorCac = somarValor(valorCac, parcelaService.obterValorPassandoParametrosConsulta(parametros)); |
||
| 1231 | valorCac = valorCac / rankingLoja.getQuantidadeVendas(); |
||
| 1232 | rankingLoja.setValorCac(valorCac); |
||
| 1233 | |||
| 1234 | rankingLojasCompleto.add(rankingLoja); |
||
| 1235 | } |
||
| 1236 | return (List<RankingLojaDTO>) ordenador.ordenar(rankingLojasCompleto); |
||
| 1237 | } |
||
| 1238 | |||
| 1239 | private Double somarValor(Double valor, Double valorAcrescentar) { |
||
| 1240 | if (VerificadorUtil.naoEstaNulo(valorAcrescentar)) { |
||
| 1241 | return valor + valorAcrescentar; |
||
| 1242 | } |
||
| 1243 | return valor; |
||
| 1244 | } |
||
| 1245 | |||
| 1246 | @Override |
||
| 1247 | public List<RankingLojaDTO> consultarRankingLojasExtras(Date dataInicial, Date dataFinal) { |
||
| 1248 | List<RankingLojaDTO> rankingLojas = new ArrayList<RankingLojaDTO>(); |
||
| 1249 | |||
| 1250 | ParametrosConsultaVendasDTO parametrosConsultaVendas = new ParametrosConsultaVendasDTO(); |
||
| 1251 | parametrosConsultaVendas.setDataInicial(DataUtils.getDataComHorarioMinimo(dataInicial)); |
||
| 1252 | parametrosConsultaVendas.setDataFinal(DataUtils.getDataComHorarioMaximo(dataFinal)); |
||
| 1253 | // rankingLojas.addAll(preenchendoLojasExtras(parametrosConsultaVendas)); |
||
| 1254 | |||
| 1255 | parametrosConsultaVendas.setLoja(null); |
||
| 1256 | // rankingLojas.add(preencherLojaAssistencia(parametrosConsultaVendas)); |
||
| 1257 | |||
| 1258 | return (List<RankingLojaDTO>) ordenador.ordenar(rankingLojas); |
||
| 1259 | } |
||
| 1260 | |||
| 1261 | private RankingLojaDTO preencherLojaAssistencia(ParametrosConsultaVendasDTO parametrosConsultaVendas) { |
||
| 1262 | RankingLojaDTO rankingLojaServico = new RankingLojaDTO(); |
||
| 1263 | Loja lojaServico = new Loja(); |
||
| 1264 | lojaServico.setDescricao("ASSISTÊNCIA"); |
||
| 1265 | rankingLojaServico.setValorMetaMensal(new Double(0.0)); |
||
| 1266 | rankingLojaServico.setLoja(lojaServico); |
||
| 1267 | rankingLojaServico.setValorTotalVendido(obterValorTotalBrutoDeVendasPorLojaEePeriodoServicos(parametrosConsultaVendas)); |
||
| 1268 | return rankingLojaServico; |
||
| 1269 | } |
||
| 1270 | |||
| 1271 | private RankingLojaDTO preencherVendasComPedidos(ParametrosConsultaVendasDTO parametrosConsultaVendas) { |
||
| 1272 | RankingLojaDTO rankingLojaServico = new RankingLojaDTO(); |
||
| 1273 | Loja lojaServico = new Loja(); |
||
| 1274 | lojaServico.setDescricao("E-COMMERCE"); |
||
| 1275 | rankingLojaServico.setValorMetaMensal(new Double(0.0)); |
||
| 1276 | rankingLojaServico.setLoja(lojaServico); |
||
| 1277 | rankingLojaServico.setValorTotalVendido(obterValorTotalBrutoDeVendasPorLojaEePeriodoServicos(parametrosConsultaVendas)); |
||
| 1278 | return rankingLojaServico; |
||
| 1279 | } |
||
| 1280 | |||
| 1281 | private List<RankingLojaDTO> preenchendoLojasExtras(ParametrosConsultaVendasDTO parametrosConsultaVendas) { |
||
| 1282 | List<RankingLojaDTO> rankingLojas = new ArrayList<RankingLojaDTO>(); |
||
| 1283 | List<Loja> lojas = lojaService.listarLojasAtivas(); |
||
| 1284 | for (Loja loja : lojas) { |
||
| 1285 | if (loja.getSequencial().equals(ConstantesSEC.SEQUENCIAL_LOJA_FARMACIA_7) |
||
| 1286 | || loja.getSequencial().equals(ConstantesSEC.SEQUENCIAL_RESTAURANTE_16)) { |
||
| 1287 | parametrosConsultaVendas.setLoja(loja); |
||
| 1288 | |||
| 1289 | RankingLojaDTO rankingLoja = new RankingLojaDTO(); |
||
| 1290 | rankingLoja.setLoja(loja); |
||
| 1291 | rankingLoja.setValorTotalVendido(obterValorTotalBrutoDeVendasPorLojaEePeriodo(parametrosConsultaVendas) |
||
| 1292 | - obterValorTotalBrutoDeVendasPorLojaEePeriodoServicos(parametrosConsultaVendas)); |
||
| 1293 | rankingLoja.setAvaliacaoLoja(avaliacaoLojaService.consultarAvaliacaoLojaPelaData(loja, DataUtils.getDataComHorarioMinimo(parametrosConsultaVendas.getDataFinal()))); |
||
| 1294 | if (VerificadorUtil.naoEstaNulo(rankingLoja.getAvaliacaoLoja())) { |
||
| 1295 | rankingLoja.setValorMetaMensal(rankingLoja.getAvaliacaoLoja().getValorMetaMensal()); |
||
| 1296 | } |
||
| 1297 | rankingLojas.add(rankingLoja); |
||
| 1298 | } |
||
| 1299 | } |
||
| 1300 | return rankingLojas; |
||
| 1301 | } |
||
| 1302 | |||
| 1303 | @Override |
||
| 1304 | public Double obterValorTotalBrutoDeVendasPorLojaEePeriodoServicos(ParametrosConsultaVendasDTO parametrosConsultaVendas) { |
||
| 1305 | parametrosConsultaVendas.setTipoProduto(TipoProduto.SERVICO.getValor()); |
||
| 1306 | Double valorTotal = vendaRepository.obterValorTotalBrutoDeVendasPorLojaEePeriodo(parametrosConsultaVendas); |
||
| 1307 | parametrosConsultaVendas.setTipoProduto(null); |
||
| 1308 | return VerificadorUtil.estaNulo(valorTotal)? new Double(0.0) : valorTotal; |
||
| 1309 | } |
||
| 1310 | |||
| 1311 | @Override |
||
| 1312 | public List<RankingProdutoDTO> consultarProdutosVendidosResumido(ParametrosConsultaProdutosVendidosDTO parametrosConsulta) { |
||
| 1313 | return vendaRepository.consultarProdutosVendidosResumido(parametrosConsulta); |
||
| 1314 | } |
||
| 1315 | |||
| 1316 | @Override |
||
| 1317 | public List<RankingProdutoDTO> consultarProdutosParaTransferir(ParametrosConsultaProdutosVendidosDTO parametrosConsulta) { |
||
| 1318 | return vendaRepository.consultarProdutosParaTransferir(parametrosConsulta); |
||
| 1319 | } |
||
| 1320 | |||
| 1321 | @Override |
||
| 1322 | public List<RankingProdutoDTO> consultarRankingProdutos(Date dataInicial, Date dataFinal, Integer quantidadeProdutos, String tipoOrdenacao, Long sequencialLoja, String tipoProduto, Produto produto, Marca marca) { |
||
| 1323 | return vendaRepository.consultarProdutosMaisVendidos(dataInicial, dataFinal, quantidadeProdutos, tipoOrdenacao, sequencialLoja, tipoProduto, produto, marca); |
||
| 1324 | } |
||
| 1325 | |||
| 1326 | @Override |
||
| 1327 | public List<RankingModeloDTO> consultarRankingModelos(Date dataInicial, Date dataFinal, Integer quantidadeModelos, String tipoOrdenacao, String tipoProduto, Long sequencialLoja) { |
||
| 1328 | ParametrosConsultaModelosMaisVendidosDTO parametros = new ParametrosConsultaModelosMaisVendidosDTO(dataInicial, dataFinal, quantidadeModelos, tipoOrdenacao, tipoProduto, sequencialLoja); |
||
| 1329 | return this.consultarRankingModelos(parametros); |
||
| 1330 | } |
||
| 1331 | |||
| 1332 | @Override |
||
| 1333 | public List<RankingComprasTransferenciasDTO> consultarPlanejamentoParaCompras(ParametrosConsultaParaComprasTransferenciasDTO parametrosParaConsulta) { |
||
| 1334 | Integer limite = parametrosParaConsulta.getQuantidadeModelos(); |
||
| 1335 | if (parametrosParaConsulta.getIndicadorConsultarTodosModelos()) { |
||
| 1336 | limite = null; |
||
| 1337 | } |
||
| 1338 | List<RankingComprasTransferenciasDTO> planejamentos = new ArrayList<RankingComprasTransferenciasDTO>(); |
||
| 1339 | ParametrosConsultaModelosMaisVendidosDTO parametrosConsulta = new ParametrosConsultaModelosMaisVendidosDTO(parametrosParaConsulta.getDataInicial(), parametrosParaConsulta.getDataFinal(), limite, |
||
| 1340 | parametrosParaConsulta.getTipoOrdenacao(), parametrosParaConsulta.getTipoProduto(), parametrosParaConsulta.getSequencialLoja(), parametrosParaConsulta.getModelo(), parametrosParaConsulta.getEstilo()); |
||
| 1341 | List<RankingModeloDTO> modelos = vendaRepository.consultarModelosMaisVendidos(parametrosConsulta); |
||
| 1342 | for (RankingModeloDTO modelo : modelos) { |
||
| 1343 | RankingComprasTransferenciasDTO planejamento = new RankingComprasTransferenciasDTO(); |
||
| 1344 | planejamento.setModelo(modelo.getModelo()); |
||
| 1345 | planejamento.setValorTotalVendido(modelo.getValorTotalVendido()); |
||
| 1346 | planejamento.setValorTotalComprado(modelo.getValorTotalComprado()); |
||
| 1347 | planejamento.setQuantidadeVendas(modelo.getQuantidadeVendas()); |
||
| 1348 | planejamento.setQuantidadeMinimaComprar(parametrosParaConsulta.getQuantidadeMinimaComprar()); |
||
| 1349 | if (VerificadorUtil.naoEstaNuloOuVazio(modelo.getQuantidadeEstoqueLocal())) { |
||
| 1350 | planejamento.setQuantidadeEstoqueLocal(modelo.getQuantidadeEstoqueLocal().intValue()); |
||
| 1351 | } |
||
| 1352 | planejamento.setQuantidadeEstoqueGeral(modelo.getQuantidadeEstoqueGeral().intValue()); |
||
| 1353 | planejamentos.add(planejamento); |
||
| 1354 | } |
||
| 1355 | |||
| 1356 | if (parametrosParaConsulta.getIndicadorConsultarTodosModelos()) { |
||
| 1357 | List<Modelo> modelosAtivos = new ArrayList<Modelo>(); |
||
| 1358 | if (VerificadorUtil.estaNulo(parametrosParaConsulta.getModelo())) { |
||
| 1359 | modelosAtivos = modeloService.consultarTodosAtivos(); |
||
| 1360 | } else { |
||
| 1361 | modelosAtivos = modeloService.consultarPassandoEntidade(parametrosParaConsulta.getModelo(), 0, modeloService.obterQuantidadeDeRegistrosPassandoEntidade(parametrosParaConsulta.getModelo())); |
||
| 1362 | } |
||
| 1363 | for (Modelo modeloAtivo : modelosAtivos) { |
||
| 1364 | if (modeloNaoEstaPresenteNaLista(modelos, modeloAtivo)) { |
||
| 1365 | RankingComprasTransferenciasDTO planejamento = new RankingComprasTransferenciasDTO(); |
||
| 1366 | planejamento.setModelo(modeloAtivo); |
||
| 1367 | planejamento.setValorTotalVendido(new Double(0.0)); |
||
| 1368 | planejamento.setValorTotalComprado(new Double(0.0)); |
||
| 1369 | planejamento.setQuantidadeVendas(new Long(0)); |
||
| 1370 | planejamento.setQuantidadeMinimaComprar(parametrosParaConsulta.getQuantidadeMinimaComprar()); |
||
| 1371 | if (VerificadorUtil.naoEstaNuloOuVazio(parametrosParaConsulta.getSequencialLoja())) { |
||
| 1372 | planejamento.setQuantidadeEstoqueLocal(produtoLojaService.consultarEstoqueModeloEeLoja(modeloAtivo, parametrosParaConsulta.getSequencialLoja(), null, parametrosParaConsulta.getTipoProduto(), null, null)); |
||
| 1373 | } |
||
| 1374 | planejamento.setQuantidadeEstoqueGeral(produtoLojaService.consultarEstoqueModeloEeLoja(modeloAtivo, null, null, parametrosParaConsulta.getTipoProduto(), null, null)); |
||
| 1375 | if (planejamento.getQuantidadeEstoqueGeral() > 0) { |
||
| 1376 | planejamentos.add(planejamento); |
||
| 1377 | } |
||
| 1378 | } |
||
| 1379 | } |
||
| 1380 | } |
||
| 1381 | |||
| 1382 | if (parametrosParaConsulta.getTipoOrdenacao().equals(TipoOrdenacaoPlanejamentoCompras.QUANTIDADE_COMPRAR.getValor())) { |
||
| 1383 | return new ArrayList<RankingComprasTransferenciasDTO>(ordenador.ordenar(planejamentos)); |
||
| 1384 | } |
||
| 1385 | return planejamentos; |
||
| 1386 | } |
||
| 1387 | |||
| 1388 | private Boolean modeloNaoEstaPresenteNaLista(List<RankingModeloDTO> rankingModelos, Modelo modeloAtivo) { |
||
| 1389 | for (RankingModeloDTO rankingModelo : rankingModelos) { |
||
| 1390 | if (rankingModelo.getModelo().getSequencial().equals(modeloAtivo.getSequencial())) { |
||
| 1391 | return false; |
||
| 1392 | } |
||
| 1393 | } |
||
| 1394 | return true; |
||
| 1395 | } |
||
| 1396 | |||
| 1397 | @Override |
||
| 1398 | public List<RankingComprasTransferenciasEstiloDTO> consultarDetalhamentoPlanejamentoParaCompras(ParametrosConsultaParaComprasTransferenciasDTO parametrosParaConsulta, Modelo modelo) { |
||
| 1399 | List<RankingComprasTransferenciasEstiloDTO> estilos = new ArrayList<RankingComprasTransferenciasEstiloDTO>(); |
||
| 1400 | for (TipoEstiloProduto estiloProduto : TipoEstiloProduto.values()) { |
||
| 1401 | parametrosParaConsulta.setEstilo(StringUtil.setarUpperCase(estiloProduto.getValor())); |
||
| 1402 | RankingComprasTransferenciasEstiloDTO estilo = vendaRepository.consultarEstoqueEeVendasPorEstilo(parametrosParaConsulta, modelo); |
||
| 1403 | estilo.setRankingsPorLoja(vendaRepository.consultarEstoqueEeVendasEstiloPorLoja(parametrosParaConsulta, modelo)); |
||
| 1404 | estilo.setQuantidadeMinimaComprar(parametrosParaConsulta.getQuantidadeMinimaComprar()); |
||
| 1405 | estilos.add(estilo); |
||
| 1406 | } |
||
| 1407 | return estilos; |
||
| 1408 | } |
||
| 1409 | |||
| 1410 | @Override |
||
| 1411 | public List<RankingVendedorDTO> consultarRankingPromocaoInterna(Date dataInicial, Date dataFinal) { |
||
| 1412 | List<RankingVendedorDTO> rankingVendedores = new ArrayList<RankingVendedorDTO>(); |
||
| 1413 | List<Vendedor> vendedores = vendedorService.consultarVendedoresColaboradoresAtivos(null); |
||
| 1414 | for (Vendedor vendedor : vendedores) { |
||
| 1415 | RankingVendedorDTO ranking = consultarRankingPromocaoInternaDoVendedor(vendedor, dataInicial, dataFinal); |
||
| 1416 | if (ranking.getValorTotalVendido() > new Double(0.0)) { |
||
| 1417 | rankingVendedores.add(ranking); |
||
| 1418 | } |
||
| 1419 | } |
||
| 1420 | return (List<RankingVendedorDTO>) ordenador.ordenar(rankingVendedores); |
||
| 1421 | } |
||
| 1422 | |||
| 1423 | @Override |
||
| 1424 | public RankingVendedorDTO consultarRankingPromocaoInternaDoVendedor(Vendedor vendedor, Date dataInicial, Date dataFinal) { |
||
| 1425 | ParametrosConsultaVendasDTO parametrosConsultaVendas = new ParametrosConsultaVendasDTO(); |
||
| 1426 | parametrosConsultaVendas.setDataInicial(DataUtils.getDataComHorarioMinimo(dataInicial)); |
||
| 1427 | parametrosConsultaVendas.setDataFinal(DataUtils.getDataComHorarioMaximo(dataFinal)); |
||
| 1428 | parametrosConsultaVendas.setVendedor(vendedor); |
||
| 1429 | RankingVendedorDTO rankingVendedor = new RankingVendedorDTO(); |
||
| 1430 | rankingVendedor.setVendedor(vendedor); |
||
| 1431 | |||
| 1432 | rankingVendedor.setQuantidadePedidos(lancamentoService.obterQuantidadeVendasDosProdutosDaPromocaoInterna(parametrosConsultaVendas)); |
||
| 1433 | // if (rankingVendedor.getQuantidadePedidos() >= ConstantesSEC.ProdutosPromocaoInterna.QUANTIDADE_MINIMA_RECEBIMENTO) { |
||
| 1434 | rankingVendedor.setValorTotalVendido(lancamentoService.obterValorTotalVendidoDosProdutosDaPromocaoInterna(parametrosConsultaVendas) * ConstantesSEC.ProdutosPromocaoInterna.PERCENTUAL); |
||
| 1435 | // } else { |
||
| 1436 | // rankingVendedor.setValorTotalVendido(new Double(0.0)); |
||
| 1437 | // } |
||
| 1438 | |||
| 1439 | ParametrosConsultaVendasDTO parametrosConsultaVendasDoDia = new ParametrosConsultaVendasDTO(); |
||
| 1440 | parametrosConsultaVendasDoDia.setDataInicial(DataUtils.getDataComHorarioMinimo(DataUtils.getDataAtual())); |
||
| 1441 | parametrosConsultaVendasDoDia.setDataFinal(DataUtils.getDataComHorarioMaximo(DataUtils.getDataAtual())); |
||
| 1442 | parametrosConsultaVendasDoDia.setVendedor(vendedor); |
||
| 1443 | rankingVendedor.setValorTotalVendidoDoDia(lancamentoService.obterValorTotalVendidoDosProdutosDaPromocaoInterna(parametrosConsultaVendasDoDia)); |
||
| 1444 | return rankingVendedor; |
||
| 1445 | } |
||
| 1446 | |||
| 1447 | @Override |
||
| 1448 | public List<VendasDTO> consultarVendas(ParametrosConsultaVendasDTO parametrosConsultaVendasDTO) { |
||
| 1449 | return vendaRepository.consultarVendas(parametrosConsultaVendasDTO); |
||
| 1450 | } |
||
| 1451 | */ |
||
| 1452 | /* |
||
| 1453 | @Override |
||
| 1454 | public List<RankingVendedorDTO> consultarRankingVendedores(Date dataInicial, Date dataFinal) { |
||
| 1455 | List<RankingVendedorDTO> rankingVendedores = new ArrayList<RankingVendedorDTO>(); |
||
| 1456 | List<Vendedor> vendedores = vendedorService.consultarVendedoresColaboradores(); |
||
| 1457 | for (Vendedor vendedor : vendedores) { |
||
| 1458 | ParametrosConsultaVendasDTO parametrosConsultaVendas = new ParametrosConsultaVendasDTO(); |
||
| 1459 | parametrosConsultaVendas.setDataInicial(DataUtils.getDataComHorarioMinimo(dataInicial)); |
||
| 1460 | parametrosConsultaVendas.setDataFinal(DataUtils.getDataComHorarioMaximo(dataFinal)); |
||
| 1461 | parametrosConsultaVendas.setVendedor(vendedor); |
||
| 1462 | RankingVendedorDTO rankingVendedor = new RankingVendedorDTO(); |
||
| 1463 | rankingVendedor.setVendedor(vendedor); |
||
| 1464 | rankingVendedor.setValorTotalVendido(obterValorTotalBrutoDeVendasPorLojaEePeriodo(parametrosConsultaVendas)); |
||
| 1465 | rankingVendedor.setQuantidadePedidos(obterQuantidadePedidos(vendedor, dataInicial, dataFinal)); |
||
| 1466 | rankingVendedores.add(rankingVendedor); |
||
| 1467 | } |
||
| 1468 | return (List<RankingVendedorDTO>) ordenador.ordenar(rankingVendedores); |
||
| 1469 | } |
||
| 1470 | */ |
||
| 1471 | |||
| 1472 | } |