Details | Last modification | View Log | RSS feed
| Rev | Author | Line No. | Line |
|---|---|---|---|
| 200 | 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.core.consulta.ParametrosConsulta; |
||
| 12 | import br.com.ec.core.exception.NegocioException; |
||
| 13 | import br.com.ec.core.generic.GenericService; |
||
| 14 | import br.com.ec.core.util.VerificadorUtil; |
||
| 15 | import br.com.ec.domain.model.Cliente; |
||
| 16 | import br.com.ec.domain.model.EstoqueAuditoria; |
||
| 17 | import br.com.ec.domain.model.Loja; |
||
| 18 | import br.com.ec.domain.model.Pedido; |
||
| 19 | import br.com.ec.domain.model.Venda; |
||
| 20 | import br.com.ec.domain.model.tipos.TipoDevolucao; |
||
| 21 | import br.com.ec.domain.service.cliente.ClienteService; |
||
| 22 | import br.com.ec.domain.service.estoqueauditoria.EstoqueAuditoriaService; |
||
| 23 | import br.com.ec.domain.service.loja.LojaService; |
||
| 24 | import br.com.ec.domain.service.pedido.PedidoService; |
||
| 25 | import br.com.ec.domain.service.venda.VendaService; |
||
| 26 | import br.com.ec.web.exception.VerificadorLancamentoException; |
||
| 27 | import br.com.ec.web.exception.VerificadorLancamentoException.CommandBean; |
||
| 28 | import br.com.ec.web.generic.AbstractBean; |
||
| 29 | |||
| 30 | @Named |
||
| 31 | @Scope("view") |
||
| 32 | public class InformarTrocaBean extends AbstractBean<EstoqueAuditoria> implements Serializable { |
||
| 33 | |||
| 34 | private static final long serialVersionUID = 1L; |
||
| 35 | |||
| 36 | private Loja lojaSelecionada; |
||
| 37 | private String cpfCliente; |
||
| 38 | |||
| 39 | private List<EstoqueAuditoria> listaTrocasDoDia; |
||
| 40 | private List<EstoqueAuditoria> listaDevolucoesDoDia; |
||
| 41 | |||
| 42 | private EstoqueAuditoriaService estoqueAuditoriaService; |
||
| 43 | private LojaService lojaService; |
||
| 44 | private ClienteService clienteService; |
||
| 45 | private VendaService vendaService; |
||
| 46 | private PedidoService pedidoService; |
||
| 47 | |||
| 48 | @Inject |
||
| 49 | public InformarTrocaBean(EstoqueAuditoriaService estoqueAuditoriaService, LojaService lojaService, ClienteService clienteService, VendaService vendaService, |
||
| 50 | PedidoService pedidoService) { |
||
| 51 | this.estoqueAuditoriaService = estoqueAuditoriaService; |
||
| 52 | this.lojaService = lojaService; |
||
| 53 | this.clienteService = clienteService; |
||
| 54 | this.vendaService = vendaService; |
||
| 55 | this.pedidoService = pedidoService; |
||
| 56 | } |
||
| 57 | |||
| 58 | @Override |
||
| 59 | public void preCarregamento() { |
||
| 60 | if (VerificadorUtil.estaNulo(parametrosConsulta)) { |
||
| 61 | entidade = new EstoqueAuditoria(); |
||
| 62 | parametrosConsulta = new ParametrosConsulta<EstoqueAuditoria>(); |
||
| 63 | parametrosConsulta.setEntidade(entidade); |
||
| 64 | setListaTrocasDoDia(estoqueAuditoriaService.consultarTrocasDoDia(getLojaSelecionada())); |
||
| 65 | setListaDevolucoesDoDia(estoqueAuditoriaService.consultarDevolucoesDoDia(getLojaSelecionada())); |
||
| 66 | } |
||
| 67 | } |
||
| 68 | |||
| 69 | @Override |
||
| 70 | public void limparEntidade() { |
||
| 71 | setEntidade(new EstoqueAuditoria()); |
||
| 72 | } |
||
| 73 | |||
| 74 | @Override |
||
| 75 | public GenericService<EstoqueAuditoria> getService() { |
||
| 76 | return estoqueAuditoriaService; |
||
| 77 | } |
||
| 78 | |||
| 79 | @Override |
||
| 80 | public EstoqueAuditoria getEntidade() { |
||
| 81 | return entidade; |
||
| 82 | } |
||
| 83 | |||
| 84 | @Override |
||
| 85 | public EstoqueAuditoria getId() { |
||
| 86 | return getEntidade(); |
||
| 87 | } |
||
| 88 | |||
| 89 | public TipoDevolucao[] getTiposDevolucao() { |
||
| 90 | return TipoDevolucao.values(); |
||
| 91 | } |
||
| 92 | |||
| 93 | public Loja getLojaSelecionada() { |
||
| 94 | if (VerificadorUtil.estaNulo(lojaSelecionada)) { |
||
| 95 | Loja loja = new Loja(); |
||
| 96 | loja.setSequencial(new Long(getParametro("sequencialLoja").toString())); |
||
| 97 | lojaSelecionada = lojaService.consultarPorId(loja); |
||
| 98 | } |
||
| 99 | return lojaSelecionada; |
||
| 100 | } |
||
| 101 | public void setLojaSelecionada(Loja lojaSelecionada) { |
||
| 102 | this.lojaSelecionada = lojaSelecionada; |
||
| 103 | } |
||
| 104 | |||
| 105 | public String getCpfCliente() { |
||
| 106 | return VerificadorUtil.naoEstaNulo(cpfCliente)? cpfCliente.replace(".", "").replace("-", "") : cpfCliente; |
||
| 107 | } |
||
| 108 | public void setCpfCliente(String cpfCliente) { |
||
| 109 | this.cpfCliente = cpfCliente; |
||
| 110 | } |
||
| 111 | |||
| 112 | public List<EstoqueAuditoria> getListaTrocasDoDia() { |
||
| 113 | return listaTrocasDoDia; |
||
| 114 | } |
||
| 115 | public void setListaTrocasDoDia(List<EstoqueAuditoria> listaTrocasDoDia) { |
||
| 116 | this.listaTrocasDoDia = listaTrocasDoDia; |
||
| 117 | } |
||
| 118 | |||
| 119 | public List<EstoqueAuditoria> getListaDevolucoesDoDia() { |
||
| 120 | return listaDevolucoesDoDia; |
||
| 121 | } |
||
| 122 | public void setListaDevolucoesDoDia(List<EstoqueAuditoria> listaDevolucoesDoDia) { |
||
| 123 | this.listaDevolucoesDoDia = listaDevolucoesDoDia; |
||
| 124 | } |
||
| 125 | |||
| 126 | public void selecionarCliente(final Cliente cliente) { |
||
| 127 | new VerificadorLancamentoException().tratarIhRelancarExcecaoSemLimparEntidade(new CommandBean() { |
||
| 128 | public void execute() { |
||
| 129 | cliente.setAtivo(true); |
||
| 130 | clienteService.alterar(cliente); |
||
| 131 | getEntidade().setCliente(clienteService.consultarClientePorCpfCnpj(cliente.getCpfCnpj())); |
||
| 132 | setCpfCliente(null); |
||
| 133 | adicionandoParametroArgsConfirmandoAcao(true); |
||
| 134 | } |
||
| 135 | }); |
||
| 136 | } |
||
| 137 | |||
| 138 | public void retirarCliente() { |
||
| 139 | getEntidade().setCliente(null); |
||
| 140 | } |
||
| 141 | |||
| 142 | public void consultarInformacoesVenda() { |
||
| 143 | new VerificadorLancamentoException().tratarIhRelancarExcecaoSemLimparEntidade(new CommandBean() { |
||
| 144 | public void execute() { |
||
| 145 | if (VerificadorUtil.estaNulo(getEntidade().getSequencialVenda())) { |
||
| 146 | throw new NegocioException("ID não informado corretamente"); |
||
| 147 | } |
||
| 148 | Venda vendaConsulta = new Venda(); |
||
| 149 | vendaConsulta.setSequencial(getEntidade().getSequencialVenda()); |
||
| 150 | vendaConsulta = vendaService.consultarPorId(vendaConsulta); |
||
| 151 | if (VerificadorUtil.estaNulo(vendaConsulta)) { |
||
| 152 | throw new NegocioException("Venda informada não existente"); |
||
| 153 | } |
||
| 154 | getEntidade().setDataVenda(vendaConsulta.getDataVenda()); |
||
| 155 | getEntidade().setLojaVenda(vendaConsulta.getLoja()); |
||
| 156 | } |
||
| 157 | }); |
||
| 158 | } |
||
| 159 | |||
| 160 | public void consultarInformacoesPedido() { |
||
| 161 | new VerificadorLancamentoException().tratarIhRelancarExcecaoSemLimparEntidade(new CommandBean() { |
||
| 162 | public void execute() { |
||
| 163 | if (VerificadorUtil.estaNulo(getEntidade().getSequencialPedido())) { |
||
| 164 | throw new NegocioException("ID do pedido não informado corretamente"); |
||
| 165 | } |
||
| 166 | Pedido pedidoConsultado = new Pedido(); |
||
| 167 | pedidoConsultado.setSequencial(getEntidade().getSequencialPedido()); |
||
| 168 | pedidoConsultado = pedidoService.consultarPedidoCompleto(pedidoConsultado); |
||
| 169 | if (VerificadorUtil.estaNulo(pedidoConsultado)) { |
||
| 170 | throw new NegocioException("Pedido informado não existente"); |
||
| 171 | } |
||
| 172 | if (!pedidoConsultado.pedidoEhTroca()) { |
||
| 173 | throw new NegocioException("Pedido não é do tipo TROCA"); |
||
| 174 | } |
||
| 175 | if (pedidoConsultado.foiAtendido()) { |
||
| 176 | throw new NegocioException("Pedido informado já finalizado"); |
||
| 177 | } |
||
| 178 | if (VerificadorUtil.naoEstaNulo(pedidoConsultado.getCliente())) { |
||
| 179 | getEntidade().setCliente(pedidoConsultado.getCliente()); |
||
| 180 | } |
||
| 181 | getEntidade().setObservacao("PEDIDO VINCULADO: ID " + getEntidade().getSequencialPedido() + "\n" + getEntidade().getObservacao()); |
||
| 182 | getEntidade().setPedidoParaVincular(pedidoConsultado); |
||
| 183 | } |
||
| 184 | }); |
||
| 185 | } |
||
| 186 | |||
| 187 | public void desvincularPedido() { |
||
| 188 | new VerificadorLancamentoException().tratarIhRelancarExcecaoSemLimparEntidade(new CommandBean() { |
||
| 189 | public void execute() { |
||
| 190 | getEntidade().setObservacao(getEntidade().getObservacao().replace("PEDIDO VINCULADO: ID " + getEntidade().getSequencialPedido(), "")); |
||
| 191 | getEntidade().setSequencialPedido(null); |
||
| 192 | getEntidade().setPedidoParaVincular(null); |
||
| 193 | } |
||
| 194 | }); |
||
| 195 | } |
||
| 196 | |||
| 197 | } |