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 | |||
| 5 | import javax.inject.Inject; |
||
| 6 | import javax.inject.Named; |
||
| 7 | |||
| 8 | import org.springframework.context.annotation.Scope; |
||
| 9 | |||
| 10 | import br.com.ec.domain.model.Cliente; |
||
| 11 | import br.com.ec.domain.model.Loja; |
||
| 12 | import br.com.ec.domain.model.Pedido; |
||
| 13 | import br.com.ec.domain.model.Produto; |
||
| 14 | import br.com.ec.domain.service.cliente.ClienteService; |
||
| 15 | import br.com.ec.domain.service.loja.LojaService; |
||
| 16 | import br.com.ec.domain.service.pedido.PedidoService; |
||
| 17 | import br.com.ec.domain.service.produto.ProdutoService; |
||
| 18 | import br.com.ec.domain.shared.ConstantesSEC; |
||
| 19 | import br.edu.cesmac.core.generic.GenericService; |
||
| 20 | import br.edu.cesmac.core.util.DataUtils; |
||
| 21 | import br.edu.cesmac.core.util.VerificadorUtil; |
||
| 22 | import br.edu.cesmac.web.exception.VerificadorLancamentoException; |
||
| 23 | import br.edu.cesmac.web.exception.VerificadorLancamentoException.CommandBean; |
||
| 24 | import br.edu.cesmac.web.generic.AbstractBean; |
||
| 25 | import br.edu.cesmac.web.message.LancadorMensagem; |
||
| 26 | |||
| 27 | @Named |
||
| 28 | @Scope("view") |
||
| 29 | public class InformarPedidoBean extends AbstractBean<Pedido> implements Serializable { |
||
| 30 | |||
| 31 | private static final long serialVersionUID = 1L; |
||
| 32 | |||
| 33 | private Loja lojaSelecionada; |
||
| 34 | private String senhaUsuario; |
||
| 35 | private String cpfCliente; |
||
| 36 | private String codigoProduto; |
||
| 37 | private Produto produtoSelecionado; |
||
| 38 | |||
| 39 | private PedidoService pedidoService; |
||
| 40 | private ClienteService clienteService; |
||
| 41 | private ProdutoService produtoService; |
||
| 42 | private LojaService lojaService; |
||
| 43 | |||
| 44 | @Inject |
||
| 45 | public InformarPedidoBean(PedidoService pedidoService, ClienteService clienteService, ProdutoService produtoService, |
||
| 46 | LojaService lojaService) { |
||
| 47 | this.pedidoService = pedidoService; |
||
| 48 | this.clienteService = clienteService; |
||
| 49 | this.produtoService = produtoService; |
||
| 50 | this.lojaService = lojaService; |
||
| 51 | } |
||
| 52 | |||
| 53 | @Override |
||
| 54 | public void preCarregamento() { |
||
| 55 | limparEntidade(); |
||
| 56 | } |
||
| 57 | |||
| 58 | @Override |
||
| 59 | public void limparEntidade() { |
||
| 60 | entidade = new Pedido(); |
||
| 61 | entidade.setLoja(new Loja(ConstantesSEC.SEQUENCIAL_MATRIZ_ESTOQUE_9)); |
||
| 62 | setSenhaUsuario(""); |
||
| 63 | } |
||
| 64 | |||
| 65 | @Override |
||
| 66 | public GenericService<Pedido> getService() { |
||
| 67 | return pedidoService; |
||
| 68 | } |
||
| 69 | |||
| 70 | @Override |
||
| 71 | public Pedido getEntidade() { |
||
| 72 | return entidade; |
||
| 73 | } |
||
| 74 | |||
| 75 | @Override |
||
| 76 | public Pedido getId() { |
||
| 77 | return getEntidade(); |
||
| 78 | } |
||
| 79 | |||
| 80 | public Loja getLojaSelecionada() { |
||
| 81 | if (VerificadorUtil.estaNulo(lojaSelecionada)) { |
||
| 82 | Loja loja = new Loja(); |
||
| 83 | loja.setSequencial(new Long(getParametro("sequencialLoja").toString())); |
||
| 84 | lojaSelecionada = lojaService.consultarPorId(loja); |
||
| 85 | } |
||
| 86 | return lojaSelecionada; |
||
| 87 | } |
||
| 88 | public void setLojaSelecionada(Loja lojaSelecionada) { |
||
| 89 | this.lojaSelecionada = lojaSelecionada; |
||
| 90 | } |
||
| 91 | |||
| 92 | public String getSenhaUsuario() { |
||
| 93 | return senhaUsuario; |
||
| 94 | } |
||
| 95 | public void setSenhaUsuario(String senhaUsuario) { |
||
| 96 | this.senhaUsuario = senhaUsuario; |
||
| 97 | } |
||
| 98 | |||
| 99 | public String getCpfCliente() { |
||
| 100 | return VerificadorUtil.naoEstaNulo(cpfCliente)? cpfCliente.replace(".", "").replace("-", "") : cpfCliente; |
||
| 101 | } |
||
| 102 | public void setCpfCliente(String cpfCliente) { |
||
| 103 | this.cpfCliente = cpfCliente; |
||
| 104 | } |
||
| 105 | |||
| 106 | public String getCodigoProduto() { |
||
| 107 | return codigoProduto; |
||
| 108 | } |
||
| 109 | public void setCodigoProduto(String codigoProduto) { |
||
| 110 | this.codigoProduto = codigoProduto; |
||
| 111 | } |
||
| 112 | |||
| 113 | public Produto getProdutoSelecionado() { |
||
| 114 | return produtoSelecionado; |
||
| 115 | } |
||
| 116 | public void setProdutoSelecionado(Produto produtoSelecionado) { |
||
| 117 | this.produtoSelecionado = produtoSelecionado; |
||
| 118 | } |
||
| 119 | |||
| 120 | /***************************************************************/ |
||
| 121 | |||
| 122 | @Override |
||
| 123 | public void cadastrar() { |
||
| 124 | new VerificadorLancamentoException().tratarIhRelancarExcecaoSemLimparEntidade(new CommandBean() { |
||
| 125 | public void execute() { |
||
| 126 | pedidoService.adicionarPedido(getEntidade(), senhaUsuario); |
||
| 127 | limparEntidade(); |
||
| 128 | LancadorMensagem.lancarSucesso("PEDIDO ADICIONADO COM SUCESSO!"); |
||
| 129 | } |
||
| 130 | }); |
||
| 131 | } |
||
| 132 | |||
| 133 | public void atenderPedido(final Pedido pedido) { |
||
| 134 | new VerificadorLancamentoException().tratarIhRelancarExcecaoSemLimparEntidade(new CommandBean() { |
||
| 135 | public void execute() { |
||
| 136 | pedido.setDataUltimaAlteracaoSituacao(DataUtils.getDataAtual()); |
||
| 137 | pedidoService.alterar(pedido); |
||
| 138 | LancadorMensagem.lancarSucesso("PEDIDO ATENDIDO COM SUCESSO!"); |
||
| 139 | } |
||
| 140 | }); |
||
| 141 | } |
||
| 142 | |||
| 143 | public void excluirPedido(final Pedido pedido) { |
||
| 144 | new VerificadorLancamentoException().tratarIhRelancarExcecaoSemLimparEntidade(new CommandBean() { |
||
| 145 | public void execute() { |
||
| 146 | pedidoService.excluir(pedido); |
||
| 147 | LancadorMensagem.lancarSucesso("PEDIDO EXCLUĂDO COM SUCESSO!"); |
||
| 148 | } |
||
| 149 | }); |
||
| 150 | } |
||
| 151 | |||
| 152 | public void selecionarCliente(final Cliente cliente) { |
||
| 153 | new VerificadorLancamentoException().tratarIhRelancarExcecaoSemLimparEntidade(new CommandBean() { |
||
| 154 | public void execute() { |
||
| 155 | cliente.setAtivo(true); |
||
| 156 | clienteService.alterar(cliente); |
||
| 157 | getEntidade().setCliente(clienteService.consultarClientePorCpfCnpj(cliente.getCpfCnpj())); |
||
| 158 | setCpfCliente(null); |
||
| 159 | adicionandoParametroArgsConfirmandoAcao(true); |
||
| 160 | } |
||
| 161 | }); |
||
| 162 | } |
||
| 163 | |||
| 164 | public void retirarCliente() { |
||
| 165 | getEntidade().setCliente(null); |
||
| 166 | } |
||
| 167 | |||
| 168 | public void consultarProduto() { |
||
| 169 | new VerificadorLancamentoException().tratarIhRelancarExcecaoSemLimparEntidade(new CommandBean() { |
||
| 170 | public void execute() { |
||
| 171 | Produto produtoSelecionado = produtoService.consultarProdutoPorCodigoOuCodigoEAN(getCodigoProduto()); |
||
| 172 | if (VerificadorUtil.naoEstaNulo(produtoSelecionado)) { |
||
| 173 | setProdutoSelecionado(produtoSelecionado); |
||
| 174 | } |
||
| 175 | } |
||
| 176 | }); |
||
| 177 | } |
||
| 178 | |||
| 179 | public void selecionarProduto() { |
||
| 180 | new VerificadorLancamentoException().tratarIhRelancarExcecaoSemLimparEntidade(new CommandBean() { |
||
| 181 | public void execute() { |
||
| 182 | // getEntidade().setProduto(getProdutoSelecionado()); |
||
| 183 | setCodigoProduto(null); |
||
| 184 | getEntidade().setModelo(null); |
||
| 185 | getEntidade().setGenero(null); |
||
| 186 | adicionandoParametroArgsConfirmandoAcao(true); |
||
| 187 | } |
||
| 188 | }); |
||
| 189 | } |
||
| 190 | |||
| 191 | public void retirarProduto() { |
||
| 192 | // entidade.setProduto(null); |
||
| 193 | } |
||
| 194 | |||
| 195 | /***************************************************************/ |
||
| 196 | |||
| 197 | public void adicionarPedido(final Loja loja) { |
||
| 198 | new VerificadorLancamentoException().tratarIhRelancarExcecaoSemLimparEntidade(new CommandBean() { |
||
| 199 | public void execute() { |
||
| 200 | getEntidade().setLoja(loja); |
||
| 201 | pedidoService.adicionarPedido(getEntidade(), senhaUsuario); |
||
| 202 | limparEntidade(); |
||
| 203 | LancadorMensagem.lancarSucesso("PEDIDO ADICIONADO COM SUCESSO!"); |
||
| 204 | } |
||
| 205 | }); |
||
| 206 | } |
||
| 207 | |||
| 208 | } |