Go to most recent revision | Details | Last modification | View Log | RSS feed
| Rev | Author | Line No. | Line |
|---|---|---|---|
| 106 | espaco | 1 | package br.com.ec.controller.managedbean; |
| 2 | |||
| 3 | import java.io.Serializable; |
||
| 4 | import java.util.List; |
||
| 5 | |||
| 6 | import javax.inject.Inject; |
||
| 7 | import javax.inject.Named; |
||
| 8 | |||
| 9 | import org.springframework.context.annotation.Scope; |
||
| 10 | |||
| 11 | import br.com.ec.domain.dto.ParametrosVendaVivoDTO; |
||
| 12 | import br.com.ec.domain.model.Cliente; |
||
| 13 | import br.com.ec.domain.model.LinhaVivo; |
||
| 14 | import br.com.ec.domain.model.Loja; |
||
| 15 | import br.com.ec.domain.model.VendaVivo; |
||
| 16 | import br.com.ec.domain.model.Vendedor; |
||
| 17 | import br.com.ec.domain.model.tipos.TipoStatusDigitalizacao; |
||
| 18 | import br.com.ec.domain.service.cliente.ClienteService; |
||
| 19 | import br.com.ec.domain.service.linhavivo.LinhaVivoService; |
||
| 20 | import br.com.ec.domain.service.loja.LojaService; |
||
| 21 | import br.com.ec.domain.service.seguranca.ContextoSeguranca; |
||
| 22 | import br.com.ec.domain.service.vendavivo.VendaVivoService; |
||
| 23 | import br.com.ec.domain.service.vendedor.VendedorService; |
||
| 24 | import br.edu.cesmac.core.consulta.ParametrosConsulta; |
||
| 25 | import br.edu.cesmac.core.generic.GenericService; |
||
| 26 | import br.edu.cesmac.core.util.DataUtils; |
||
| 27 | import br.edu.cesmac.core.util.StringUtil; |
||
| 28 | import br.edu.cesmac.core.util.VerificadorUtil; |
||
| 29 | import br.edu.cesmac.web.exception.VerificadorLancamentoException; |
||
| 30 | import br.edu.cesmac.web.exception.VerificadorLancamentoException.CommandBean; |
||
| 31 | import br.edu.cesmac.web.generic.AbstractBean; |
||
| 32 | import br.edu.cesmac.web.message.LancadorMensagem; |
||
| 33 | |||
| 34 | @Named |
||
| 35 | @Scope("view") |
||
| 36 | public class VendaVivoBean extends AbstractBean<VendaVivo> implements Serializable { |
||
| 37 | |||
| 38 | private static final long serialVersionUID = 1L; |
||
| 39 | |||
| 40 | private LojaService lojaService; |
||
| 41 | private VendaVivoService vendaVivoService; |
||
| 42 | private LinhaVivoService linhaVivoService; |
||
| 43 | private VendedorService vendedorService; |
||
| 44 | private ClienteService clienteService; |
||
| 45 | private ContextoSeguranca contextoSeguranca; |
||
| 46 | |||
| 47 | private String cpfCliente; |
||
| 48 | private ParametrosVendaVivoDTO parametrosVenda; |
||
| 49 | private Boolean numeroVerificado; |
||
| 50 | private VendaVivo vendaSelecionada; |
||
| 51 | private List<Vendedor> vendedoresColaboradores; |
||
| 52 | |||
| 53 | @Inject |
||
| 54 | public VendaVivoBean(LojaService lojaService, VendaVivoService vendaVivoService, LinhaVivoService linhaVivoService, |
||
| 55 | VendedorService vendedorService, ClienteService clienteService, ContextoSeguranca contextoSeguranca) { |
||
| 56 | this.lojaService = lojaService; |
||
| 57 | this.vendaVivoService = vendaVivoService; |
||
| 58 | this.linhaVivoService = linhaVivoService; |
||
| 59 | this.vendedorService = vendedorService; |
||
| 60 | this.clienteService = clienteService; |
||
| 61 | this.contextoSeguranca = contextoSeguranca; |
||
| 62 | } |
||
| 63 | |||
| 64 | @Override |
||
| 65 | public void preCarregamento() { |
||
| 66 | entidade = new VendaVivo(); |
||
| 67 | entidade.setIndicadorPortabilidade(false); |
||
| 68 | entidade.setIndicadorMigracao(false); |
||
| 69 | entidade.setIndicadorCadastradoVivoGo(false); |
||
| 70 | numeroVerificado = false; |
||
| 71 | parametrosConsulta = new ParametrosConsulta<VendaVivo>(); |
||
| 72 | parametrosConsulta.setEntidade(entidade); |
||
| 73 | parametrosVenda = new ParametrosVendaVivoDTO(); |
||
| 74 | setarParametrosDaLoja(); |
||
| 75 | } |
||
| 76 | |||
| 77 | private void setarParametrosDaLoja() { |
||
| 78 | if (VerificadorUtil.estaNulo(entidade)) { |
||
| 79 | entidade = new VendaVivo(); |
||
| 80 | entidade.setDataVenda(DataUtils.getDataAtual()); |
||
| 81 | parametrosVenda.setUsuario(contextoSeguranca.obterUsuario()); |
||
| 82 | } |
||
| 83 | if (VerificadorUtil.naoEstaNulo(getParametro("sequencialLoja"))) { |
||
| 84 | Loja loja = new Loja(); |
||
| 85 | loja.setSequencial(new Long(getParametro("sequencialLoja").toString())); |
||
| 86 | entidade.setLoja(lojaService.consultarPorId(loja)); |
||
| 87 | } |
||
| 88 | } |
||
| 89 | |||
| 90 | @Override |
||
| 91 | public void limparEntidade() { |
||
| 92 | setEntidade(new VendaVivo()); |
||
| 93 | setNumeroVerificado(false); |
||
| 94 | } |
||
| 95 | |||
| 96 | @Override |
||
| 97 | public GenericService<VendaVivo> getService() { |
||
| 98 | return vendaVivoService; |
||
| 99 | } |
||
| 100 | |||
| 101 | @Override |
||
| 102 | public VendaVivo getEntidade() { |
||
| 103 | return entidade; |
||
| 104 | } |
||
| 105 | |||
| 106 | @Override |
||
| 107 | public VendaVivo getId() { |
||
| 108 | return getEntidade(); |
||
| 109 | } |
||
| 110 | |||
| 111 | public String getCpfCliente() { |
||
| 112 | return VerificadorUtil.naoEstaNulo(cpfCliente)? cpfCliente.replace(".", "").replace("-", "") : cpfCliente; |
||
| 113 | } |
||
| 114 | public void setCpfCliente(String cpfCliente) { |
||
| 115 | this.cpfCliente = cpfCliente; |
||
| 116 | } |
||
| 117 | |||
| 118 | public ParametrosVendaVivoDTO getParametrosVenda() { |
||
| 119 | return parametrosVenda; |
||
| 120 | } |
||
| 121 | public void setParametrosVenda(ParametrosVendaVivoDTO parametrosVenda) { |
||
| 122 | this.parametrosVenda = parametrosVenda; |
||
| 123 | } |
||
| 124 | |||
| 125 | public Boolean getNumeroVerificado() { |
||
| 126 | return numeroVerificado; |
||
| 127 | } |
||
| 128 | public void setNumeroVerificado(Boolean numeroVerificado) { |
||
| 129 | this.numeroVerificado = numeroVerificado; |
||
| 130 | } |
||
| 131 | |||
| 132 | public VendaVivo getVendaSelecionada() { |
||
| 133 | return vendaSelecionada; |
||
| 134 | } |
||
| 135 | public void setVendaSelecionada(VendaVivo vendaSelecionada) { |
||
| 136 | this.vendaSelecionada = vendaSelecionada; |
||
| 137 | } |
||
| 138 | |||
| 139 | public List<Vendedor> getVendedoresColaboradores() { |
||
| 140 | if (VerificadorUtil.estaNulo(vendedoresColaboradores)) { |
||
| 141 | setVendedoresColaboradores(vendedorService.consultarVendedoresColaboradores()); |
||
| 142 | } |
||
| 143 | return vendedoresColaboradores; |
||
| 144 | } |
||
| 145 | public void setVendedoresColaboradores(List<Vendedor> vendedoresColaboradores) { |
||
| 146 | this.vendedoresColaboradores = vendedoresColaboradores; |
||
| 147 | } |
||
| 148 | |||
| 149 | public List<VendaVivo> getConsultarTodas() { |
||
| 150 | return vendaVivoService.consultarTodos(new VendaVivo()); |
||
| 151 | } |
||
| 152 | |||
| 153 | /***************************************************************/ |
||
| 154 | |||
| 155 | public void retirarProduto() { |
||
| 156 | getEntidade().setProdutoVivo(null); |
||
| 157 | } |
||
| 158 | |||
| 159 | public void prepararParaAlterarVenda(final VendaVivo vendaVivo) { |
||
| 160 | new VerificadorLancamentoException().tratarIhRelancarExcecaoSemLimparEntidade(new CommandBean() { |
||
| 161 | public void execute() { |
||
| 162 | setEntidade(vendaVivo); |
||
| 163 | } |
||
| 164 | }); |
||
| 165 | } |
||
| 166 | |||
| 167 | public void iniciarNovaVenda() { |
||
| 168 | limparEntidade(); |
||
| 169 | } |
||
| 170 | |||
| 171 | public void verificarNumero() { |
||
| 172 | new VerificadorLancamentoException().tratarIhRelancarExcecaoSemLimparEntidade(new CommandBean() { |
||
| 173 | public void execute() { |
||
| 174 | getEntidade().setNumeroDaLinha(StringUtil.retornarApenasNumeros(getEntidade().getNumeroDaLinha())); |
||
| 175 | LinhaVivo linhaConsultada = linhaVivoService.consultarPorNumero(getEntidade().getNumeroDaLinha()); |
||
| 176 | if (VerificadorUtil.naoEstaNulo(linhaConsultada)) { |
||
| 177 | getEntidade().setLinhaVivo(linhaConsultada); |
||
| 178 | LancadorMensagem.lancarSucesso("LINHA JÁ EXISTENTE"); |
||
| 179 | } |
||
| 180 | setNumeroVerificado(true); |
||
| 181 | getEntidade().setDataVenda(DataUtils.getDataAtual()); |
||
| 182 | } |
||
| 183 | }); |
||
| 184 | } |
||
| 185 | |||
| 186 | public void cadastrarVendaVivo() { |
||
| 187 | new VerificadorLancamentoException().tratarIhRelancarExcecaoSemLimparEntidade(new CommandBean() { |
||
| 188 | public void execute() { |
||
| 189 | setarParametrosDaLoja(); |
||
| 190 | vendaVivoService.cadastrarVendaVivoPeloPDV(getEntidade()); |
||
| 191 | LancadorMensagem.lancarSucessoRedirecionandoTela("VENDA REALIZADA COM SUCESSO!", "/sistema/pdv_vivo.xhtml?sequencialLoja=" + getEntidade().getLoja().getSequencial()); |
||
| 192 | iniciarNovaVenda(); |
||
| 193 | } |
||
| 194 | }); |
||
| 195 | } |
||
| 196 | |||
| 197 | public void alterarVendaVivo() { |
||
| 198 | new VerificadorLancamentoException().tratarIhRelancarExcecaoSemLimparEntidade(new CommandBean() { |
||
| 199 | public void execute() { |
||
| 200 | vendaVivoService.alterarVendaVivoPeloPDV(getEntidade()); |
||
| 201 | adicionandoParametroArgsConfirmandoAcao(true); |
||
| 202 | LancadorMensagem.lancarSucesso("VENDA ALTERADA COM SUCESSO"); |
||
| 203 | } |
||
| 204 | }); |
||
| 205 | } |
||
| 206 | |||
| 207 | public void excluirVendaVivo(final VendaVivo vendaVivo) { |
||
| 208 | new VerificadorLancamentoException().tratarIhRelancarExcecaoSemLimparEntidade(new CommandBean() { |
||
| 209 | public void execute() { |
||
| 210 | vendaVivoService.excluirVendaVivo(vendaVivo, contextoSeguranca.obterUsuario()); |
||
| 211 | adicionandoParametroArgsConfirmandoAcao(true); |
||
| 212 | LancadorMensagem.lancarSucesso("VENDA EXCLUÍDA COM SUCESSO"); |
||
| 213 | } |
||
| 214 | }); |
||
| 215 | } |
||
| 216 | |||
| 217 | public void selecionarCliente(final Cliente cliente) { |
||
| 218 | new VerificadorLancamentoException().tratarIhRelancarExcecaoSemLimparEntidade(new CommandBean() { |
||
| 219 | public void execute() { |
||
| 220 | cliente.setAtivo(true); |
||
| 221 | clienteService.alterar(cliente); |
||
| 222 | getEntidade().getLinhaVivo().setCliente(clienteService.consultarClientePorCpfCnpj(cliente.getCpfCnpj())); |
||
| 223 | setCpfCliente(null); |
||
| 224 | adicionandoParametroArgsConfirmandoAcao(true); |
||
| 225 | } |
||
| 226 | }); |
||
| 227 | } |
||
| 228 | |||
| 229 | public void retirarCliente() { |
||
| 230 | getEntidade().getLinhaVivo().setCliente(null); |
||
| 231 | } |
||
| 232 | |||
| 233 | public void selecionarDigitalizacao() { |
||
| 234 | new VerificadorLancamentoException().tratarIhRelancarExcecaoSemLimparEntidade(new CommandBean() { |
||
| 235 | public void execute() { |
||
| 236 | if (VerificadorUtil.naoEstaNuloOuVazio(getEntidade().getProtocoloGED())) { |
||
| 237 | getEntidade().setTipoStatusDigitalizacao(TipoStatusDigitalizacao.CONFERINDO.getValor()); |
||
| 238 | getEntidade().setDataStatus(DataUtils.getDataAtual()); |
||
| 239 | getEntidade().setDataDigitalizacao(DataUtils.getDataAtual()); |
||
| 240 | } |
||
| 241 | adicionandoParametroArgsConfirmandoAcao(true); |
||
| 242 | } |
||
| 243 | }); |
||
| 244 | } |
||
| 245 | |||
| 246 | public void retirarDigitalizacao() { |
||
| 247 | getEntidade().setProtocoloGED(""); |
||
| 248 | getEntidade().setTipoStatusDigitalizacao(""); |
||
| 249 | getEntidade().setDataDigitalizacao(null); |
||
| 250 | getEntidade().setDataStatus(null); |
||
| 251 | } |
||
| 252 | |||
| 253 | public void prepararParaExcluirVenda(final VendaVivo vendaVivo) { |
||
| 254 | new VerificadorLancamentoException().tratarIhRelancarExcecaoSemLimparEntidade(new CommandBean() { |
||
| 255 | public void execute() { |
||
| 256 | setVendaSelecionada(vendaVivo); |
||
| 257 | } |
||
| 258 | }); |
||
| 259 | } |
||
| 260 | |||
| 261 | public void excluirVendaSelecionada() { |
||
| 262 | new VerificadorLancamentoException().tratarIhRelancarExcecaoSemLimparEntidade(new CommandBean() { |
||
| 263 | public void execute() { |
||
| 264 | if (VerificadorUtil.estaNuloOuVazio(getVendaSelecionada().getJustificativaParaExcluir())) { |
||
| 265 | throw new RuntimeException("É OBRIGATÓRIO JUSTIFICAR"); |
||
| 266 | } |
||
| 267 | vendaVivoService.excluirVendaVivo(getVendaSelecionada(), contextoSeguranca.obterUsuario()); |
||
| 268 | adicionandoParametroArgsConfirmandoAcao(true); |
||
| 269 | LancadorMensagem.lancarSucesso("VENDA EXCLUÍDA COM SUCESSO"); |
||
| 270 | } |
||
| 271 | }); |
||
| 272 | } |
||
| 273 | |||
| 274 | } |