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