Details | Last modification | View Log | RSS feed
| Rev | Author | Line No. | Line |
|---|---|---|---|
| 1 | espaco | 1 | package br.com.ec.controller.managedbean; |
| 2 | |||
| 3 | import java.io.Serializable; |
||
| 4 | |||
| 5 | import javax.inject.Inject; |
||
| 6 | import javax.inject.Named; |
||
| 7 | |||
| 8 | import org.springframework.context.annotation.Scope; |
||
| 9 | |||
| 10 | import br.com.ec.controller.managedbean.consultademanda.ProdutoConsultaPorDemanda; |
||
| 11 | import br.com.ec.domain.dto.ParametrosConsultaProdutoDTO; |
||
| 12 | import br.com.ec.domain.model.Loja; |
||
| 13 | import br.com.ec.domain.model.Produto; |
||
| 14 | import br.com.ec.domain.model.Usuario; |
||
| 15 | import br.com.ec.domain.service.loja.LojaService; |
||
| 16 | import br.com.ec.domain.service.produto.ProdutoService; |
||
| 17 | import br.com.ec.domain.service.seguranca.ContextoSeguranca; |
||
| 18 | import br.edu.cesmac.core.generic.GenericService; |
||
| 19 | import br.edu.cesmac.core.util.VerificadorUtil; |
||
| 20 | import br.edu.cesmac.web.exception.VerificadorLancamentoException; |
||
| 21 | import br.edu.cesmac.web.exception.VerificadorLancamentoException.CommandBean; |
||
| 22 | import br.edu.cesmac.web.generic.AbstractBean; |
||
| 23 | import br.edu.cesmac.web.message.LancadorMensagem; |
||
| 24 | |||
| 25 | @Named |
||
| 26 | @Scope("view") |
||
| 27 | public class ContagemConsultaBean extends AbstractBean<Produto> implements Serializable { |
||
| 28 | |||
| 29 | private static final long serialVersionUID = 1L; |
||
| 30 | |||
| 31 | private ProdutoConsultaPorDemanda lazy; |
||
| 32 | private ContextoSeguranca contextoSeguranca; |
||
| 33 | private Loja lojaSelecionada; |
||
| 34 | private Usuario usuarioParaContagem; |
||
| 35 | |||
| 36 | private LojaService lojaService; |
||
| 37 | private ProdutoService produtoService; |
||
| 38 | |||
| 39 | @Inject |
||
| 40 | public ContagemConsultaBean(ProdutoConsultaPorDemanda lazy, ContextoSeguranca contextoSeguranca, LojaService lojaService, |
||
| 41 | ProdutoService produtoService) { |
||
| 42 | this.lazy = lazy; |
||
| 43 | this.contextoSeguranca = contextoSeguranca; |
||
| 44 | this.lojaService = lojaService; |
||
| 45 | this.produtoService = produtoService; |
||
| 46 | } |
||
| 47 | |||
| 48 | @Override |
||
| 49 | public void preCarregamento() { |
||
| 50 | entidade = new Produto(); |
||
| 51 | parametrosConsulta = new ParametrosConsultaProdutoDTO(); |
||
| 52 | parametrosConsulta.setEntidade(new Produto()); |
||
| 53 | prepararConsultaDemanda(); |
||
| 54 | } |
||
| 55 | |||
| 56 | @Override |
||
| 57 | public void limparEntidade() {} |
||
| 58 | |||
| 59 | @Override |
||
| 60 | public GenericService<Produto> getService() { |
||
| 61 | return null; |
||
| 62 | } |
||
| 63 | |||
| 64 | @Override |
||
| 65 | public Produto getEntidade() { |
||
| 66 | return entidade; |
||
| 67 | } |
||
| 68 | |||
| 69 | @Override |
||
| 70 | public Produto getId() { |
||
| 71 | return getEntidade(); |
||
| 72 | } |
||
| 73 | |||
| 74 | public ProdutoConsultaPorDemanda getLazy() { |
||
| 75 | prepararConsultaDemanda(); |
||
| 76 | return lazy; |
||
| 77 | } |
||
| 78 | public void setLazy(ProdutoConsultaPorDemanda lazy) { |
||
| 79 | this.lazy = lazy; |
||
| 80 | } |
||
| 81 | public void prepararConsultaDemanda() { |
||
| 82 | ((ParametrosConsultaProdutoDTO)parametrosConsulta).setLojaSelecionadaParaContagem(getLojaSelecionada()); |
||
| 83 | ((ParametrosConsultaProdutoDTO)parametrosConsulta).setConsultarAtivo(1); |
||
| 84 | ((ParametrosConsultaProdutoDTO)parametrosConsulta).setUsuarioParaContagem(getUsuarioParaContagem()); |
||
| 85 | lazy.setarParametrosConsulta(getParametrosConsulta()); |
||
| 86 | } |
||
| 87 | |||
| 88 | public Loja getLojaSelecionada() { |
||
| 89 | if (VerificadorUtil.estaNulo(lojaSelecionada)) { |
||
| 90 | if (VerificadorUtil.naoEstaNulo(getParametro("sequencialLoja"))) { |
||
| 91 | Loja loja = new Loja(); |
||
| 92 | loja.setSequencial(new Long(getParametro("sequencialLoja").toString())); |
||
| 93 | lojaSelecionada = lojaService.consultarPorId(loja); |
||
| 94 | } |
||
| 95 | } |
||
| 96 | return lojaSelecionada; |
||
| 97 | } |
||
| 98 | public void setLojaSelecionada(Loja lojaSelecionada) { |
||
| 99 | this.lojaSelecionada = lojaSelecionada; |
||
| 100 | } |
||
| 101 | |||
| 102 | public Usuario getUsuarioParaContagem() { |
||
| 103 | return usuarioParaContagem; |
||
| 104 | } |
||
| 105 | public void setUsuarioParaContagem(Usuario usuarioParaContagem) { |
||
| 106 | this.usuarioParaContagem = usuarioParaContagem; |
||
| 107 | } |
||
| 108 | |||
| 109 | public void cancelarContagem() { |
||
| 110 | new VerificadorLancamentoException().tratarIhRelancarExcecaoSemLimparEntidade(new CommandBean() { |
||
| 111 | public void execute() { |
||
| 112 | produtoService.cancelarContagem((ParametrosConsultaProdutoDTO)getParametrosConsulta()); |
||
| 113 | LancadorMensagem.lancarSucesso("CONTAGEM CANCELADA COM SUCESSO!"); |
||
| 114 | } |
||
| 115 | }); |
||
| 116 | } |
||
| 117 | |||
| 118 | public void zerarEstoque() { |
||
| 119 | new VerificadorLancamentoException().tratarIhRelancarExcecaoSemLimparEntidade(new CommandBean() { |
||
| 120 | public void execute() { |
||
| 121 | produtoService.zerarEstoque((ParametrosConsultaProdutoDTO)getParametrosConsulta(), contextoSeguranca.obterUsuario()); |
||
| 122 | LancadorMensagem.lancarSucesso("ESTOQUE ZERADO COM SUCESSO!"); |
||
| 123 | } |
||
| 124 | }); |
||
| 125 | } |
||
| 126 | |||
| 127 | } |