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