Rev 200 | Details | Compare with Previous | 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.ArrayList; |
||
| 5 | import java.util.List; |
||
| 6 | |||
| 7 | import javax.inject.Inject; |
||
| 8 | import javax.inject.Named; |
||
| 9 | |||
| 204 | espaco | 10 | import org.primefaces.PrimeFaces; |
| 200 | espaco | 11 | import org.springframework.context.annotation.Scope; |
| 12 | |||
| 13 | import br.com.ec.core.exception.NegocioException; |
||
| 14 | import br.com.ec.core.generic.GenericService; |
||
| 15 | import br.com.ec.core.util.DataUtils; |
||
| 16 | import br.com.ec.core.util.VerificadorUtil; |
||
| 17 | import br.com.ec.domain.dto.TransferenciaProdutoDTO; |
||
| 18 | import br.com.ec.domain.model.Fornecedor; |
||
| 19 | import br.com.ec.domain.model.Loja; |
||
| 20 | import br.com.ec.domain.model.NotaFiscal; |
||
| 21 | import br.com.ec.domain.model.NotaFiscalProduto; |
||
| 22 | import br.com.ec.domain.model.Produto; |
||
| 23 | import br.com.ec.domain.model.Transferencia; |
||
| 24 | import br.com.ec.domain.model.TransferenciaProduto; |
||
| 25 | import br.com.ec.domain.model.Usuario; |
||
| 26 | import br.com.ec.domain.model.tipos.nfe.TipoModeloNotaFiscal; |
||
| 27 | import br.com.ec.domain.model.tipos.nfe.TipoNotaFiscal; |
||
| 28 | import br.com.ec.domain.service.email.impl.GerenciadorEmailImpl; |
||
| 29 | import br.com.ec.domain.service.fornecedor.FornecedorService; |
||
| 30 | import br.com.ec.domain.service.loja.LojaService; |
||
| 31 | import br.com.ec.domain.service.notafiscal.NotaFiscalProdutoService; |
||
| 32 | import br.com.ec.domain.service.notafiscal.NotaFiscalService; |
||
| 33 | import br.com.ec.domain.service.produto.ProdutoService; |
||
| 34 | import br.com.ec.domain.service.produtodaloja.ProdutoLojaService; |
||
| 35 | import br.com.ec.domain.service.transferencia.TransferenciaService; |
||
| 36 | import br.com.ec.domain.service.transferenciaproduto.TransferenciaProdutoService; |
||
| 37 | import br.com.ec.domain.service.usuario.UsuarioService; |
||
| 38 | import br.com.ec.domain.shared.ConstantesSEC; |
||
| 39 | import br.com.ec.web.exception.VerificadorLancamentoException; |
||
| 40 | import br.com.ec.web.exception.VerificadorLancamentoException.CommandBean; |
||
| 41 | import br.com.ec.web.generic.AbstractBean; |
||
| 42 | import br.com.ec.web.message.LancadorMensagem; |
||
| 43 | import br.com.ec.web.util.TipoOperacao; |
||
| 44 | |||
| 45 | @Named |
||
| 46 | @Scope("view") |
||
| 47 | public class TransferirProdutoBean extends AbstractBean<Transferencia> implements Serializable { |
||
| 48 | |||
| 49 | private static final long serialVersionUID = 1L; |
||
| 50 | |||
| 51 | private Loja lojaSelecionada; |
||
| 52 | private Long sequencialLojaSelecionada; |
||
| 53 | private String senhaUsuarioTransferencia; |
||
| 54 | private Usuario usuarioTransferencia; |
||
| 55 | |||
| 56 | private String codigoProduto; |
||
| 57 | private Produto produtoSelecionado; |
||
| 58 | private TransferenciaProdutoDTO transferenciaProdutoSelecionadoDTO; |
||
| 59 | private Integer quantidadeProdutoSelecionado; |
||
| 60 | |||
| 61 | private TransferenciaService transferenciaService; |
||
| 62 | private TransferenciaProdutoService transferenciaProdutoService; |
||
| 63 | private LojaService lojaService; |
||
| 64 | private UsuarioService usuarioService; |
||
| 65 | private ProdutoService produtoService; |
||
| 66 | private ProdutoLojaService produtoLojaService; |
||
| 67 | private NotaFiscalService notaFiscalService; |
||
| 68 | private NotaFiscalProdutoService notaFiscalProdutoService; |
||
| 69 | private FornecedorService fornecedorService; |
||
| 70 | |||
| 71 | @Inject |
||
| 72 | public TransferirProdutoBean(TransferenciaService transferenciaService, TransferenciaProdutoService transferenciaProdutoService, |
||
| 73 | LojaService lojaService, UsuarioService usuarioService, ProdutoService produtoService, ProdutoLojaService produtoLojaService, |
||
| 74 | NotaFiscalService notaFiscalService, NotaFiscalProdutoService notaFiscalProdutoService, FornecedorService fornecedorService) { |
||
| 75 | this.transferenciaService = transferenciaService; |
||
| 76 | this.transferenciaProdutoService = transferenciaProdutoService; |
||
| 77 | this.lojaService = lojaService; |
||
| 78 | this.usuarioService = usuarioService; |
||
| 79 | this.produtoService = produtoService; |
||
| 80 | this.produtoLojaService = produtoLojaService; |
||
| 81 | this.notaFiscalService = notaFiscalService; |
||
| 82 | this.notaFiscalProdutoService = notaFiscalProdutoService; |
||
| 83 | this.fornecedorService = fornecedorService; |
||
| 84 | } |
||
| 85 | |||
| 86 | @Override |
||
| 87 | public void preCarregamento() { |
||
| 88 | entidade = new Transferencia(); |
||
| 89 | entidade.setLojaEntrada(getLojaSelecionada()); |
||
| 90 | entidade.setLojaSaida(getLojaSelecionada()); |
||
| 91 | setSenhaUsuarioTransferencia(""); |
||
| 92 | } |
||
| 93 | |||
| 94 | @Override |
||
| 95 | public void limparEntidade() { |
||
| 96 | setEntidade(new Transferencia()); |
||
| 97 | setSenhaUsuarioTransferencia(""); |
||
| 98 | setUsuarioTransferencia(null); |
||
| 99 | setLojaSelecionada(null); |
||
| 100 | setCodigoProduto(""); |
||
| 101 | } |
||
| 102 | |||
| 103 | @Override |
||
| 104 | public GenericService<Transferencia> getService() { |
||
| 105 | return transferenciaService; |
||
| 106 | } |
||
| 107 | |||
| 108 | @Override |
||
| 109 | public Transferencia getEntidade() { |
||
| 110 | return entidade; |
||
| 111 | } |
||
| 112 | |||
| 113 | @Override |
||
| 114 | public Transferencia getId() { |
||
| 115 | return getEntidade(); |
||
| 116 | } |
||
| 117 | |||
| 118 | public Loja getLojaSelecionada() { |
||
| 119 | if (VerificadorUtil.estaNulo(lojaSelecionada)) { |
||
| 120 | if (VerificadorUtil.naoEstaNulo(getSequencialLojaSelecionada())) { |
||
| 121 | Loja loja = new Loja(); |
||
| 122 | loja.setSequencial(getSequencialLojaSelecionada()); |
||
| 123 | lojaSelecionada = lojaService.consultarPorId(loja); |
||
| 124 | } |
||
| 125 | } |
||
| 126 | return lojaSelecionada; |
||
| 127 | } |
||
| 128 | public void setLojaSelecionada(Loja lojaSelecionada) { |
||
| 129 | this.lojaSelecionada = lojaSelecionada; |
||
| 130 | } |
||
| 131 | |||
| 132 | public Long getSequencialLojaSelecionada() { |
||
| 133 | if (VerificadorUtil.naoEstaNulo(getParametro("sequencialLoja"))) { |
||
| 134 | setSequencialLojaSelecionada(new Long(getParametro("sequencialLoja").toString())); |
||
| 135 | } |
||
| 136 | return sequencialLojaSelecionada; |
||
| 137 | } |
||
| 138 | public void setSequencialLojaSelecionada(Long sequencialLojaSelecionada) { |
||
| 139 | this.sequencialLojaSelecionada = sequencialLojaSelecionada; |
||
| 140 | } |
||
| 141 | |||
| 142 | public String getSenhaUsuarioTransferencia() { |
||
| 143 | return senhaUsuarioTransferencia; |
||
| 144 | } |
||
| 145 | public void setSenhaUsuarioTransferencia(String senhaUsuarioTransferencia) { |
||
| 146 | this.senhaUsuarioTransferencia = senhaUsuarioTransferencia; |
||
| 147 | } |
||
| 148 | |||
| 149 | public Usuario getUsuarioTransferencia() { |
||
| 150 | return usuarioTransferencia; |
||
| 151 | } |
||
| 152 | public void setUsuarioTransferencia(Usuario usuarioTransferencia) { |
||
| 153 | this.usuarioTransferencia = usuarioTransferencia; |
||
| 154 | } |
||
| 155 | public Boolean possuiUsuarioTransferencia() { |
||
| 156 | return VerificadorUtil.naoEstaNulo(getUsuarioTransferencia()); |
||
| 157 | } |
||
| 158 | |||
| 159 | public String getCodigoProduto() { |
||
| 160 | return codigoProduto; |
||
| 161 | } |
||
| 162 | public void setCodigoProduto(String codigoProduto) { |
||
| 163 | this.codigoProduto = codigoProduto; |
||
| 164 | } |
||
| 165 | |||
| 166 | public Produto getProdutoSelecionado() { |
||
| 167 | return produtoSelecionado; |
||
| 168 | } |
||
| 169 | public void setProdutoSelecionado(Produto produtoSelecionado) { |
||
| 170 | this.produtoSelecionado = produtoSelecionado; |
||
| 171 | } |
||
| 172 | |||
| 173 | public TransferenciaProdutoDTO getTransferenciaProdutoSelecionadoDTO() { |
||
| 174 | return transferenciaProdutoSelecionadoDTO; |
||
| 175 | } |
||
| 176 | public void setTransferenciaProdutoSelecionadoDTO(TransferenciaProdutoDTO transferenciaProdutoSelecionadoDTO) { |
||
| 177 | this.transferenciaProdutoSelecionadoDTO = transferenciaProdutoSelecionadoDTO; |
||
| 178 | } |
||
| 179 | |||
| 180 | public Integer getQuantidadeProdutoSelecionado() { |
||
| 181 | return quantidadeProdutoSelecionado; |
||
| 182 | } |
||
| 183 | public void setQuantidadeProdutoSelecionado(Integer quantidadeProdutoSelecionado) { |
||
| 184 | this.quantidadeProdutoSelecionado = quantidadeProdutoSelecionado; |
||
| 185 | } |
||
| 186 | |||
| 187 | /***************************************************************/ |
||
| 188 | |||
| 189 | public Integer quantidadeTransferencias(Loja loja) { |
||
| 190 | return transferenciaService.obterQuantidadeDeTransferenciasAbertas(loja); |
||
| 191 | } |
||
| 192 | |||
| 193 | @Override |
||
| 194 | public void preAlterar(Transferencia transferencia) { |
||
| 195 | limparEntidade(); |
||
| 196 | transferencia.setProdutosDTO(transferenciaService.consultarProdutos(transferencia)); |
||
| 197 | super.preAlterar(transferencia); |
||
| 198 | } |
||
| 199 | |||
| 200 | @Override |
||
| 201 | public void preDetalhar(Transferencia transferencia) { |
||
| 202 | limparEntidade(); |
||
| 203 | transferencia.setProdutosDTO(transferenciaService.consultarProdutos(transferencia)); |
||
| 204 | super.preDetalhar(transferencia); |
||
| 205 | } |
||
| 206 | |||
| 207 | public Boolean todosProdutosRecebidos() { |
||
| 208 | for (TransferenciaProdutoDTO produto : getEntidade().getProdutosDTO()) { |
||
| 209 | if (!produto.getRecebido()) { |
||
| 210 | return false; |
||
| 211 | } |
||
| 212 | } |
||
| 213 | return true; |
||
| 214 | } |
||
| 215 | |||
| 216 | public void retirarVerificacaoProdutos() { |
||
| 217 | for (TransferenciaProdutoDTO produto : getEntidade().getProdutosDTO()) { |
||
| 218 | produto.setRecebido(false); |
||
| 219 | } |
||
| 220 | } |
||
| 221 | |||
| 222 | public void escolherProduto() { |
||
| 223 | new VerificadorLancamentoException().tratarIhRelancarExcecaoSemLimparEntidade(new CommandBean() { |
||
| 224 | public void execute() { |
||
| 225 | Produto produtoConsultado = produtoService.consultarProdutoPorCodigoOuCodigoEAN(getCodigoProduto()); |
||
| 226 | if (VerificadorUtil.estaNulo(produtoConsultado)) { |
||
| 227 | LancadorMensagem.lancarErro("Produto não encontrado!"); |
||
| 228 | } else { |
||
| 229 | setProdutoSelecionado(produtoConsultado); |
||
| 230 | setQuantidadeProdutoSelecionado(1); |
||
| 204 | espaco | 231 | PrimeFaces.current().ajax().addCallbackParam("confirmado", true); |
| 200 | espaco | 232 | } |
| 233 | } |
||
| 234 | }); |
||
| 235 | } |
||
| 236 | |||
| 237 | public void escolherProduto(Produto produto) { |
||
| 238 | setProdutoSelecionado(produto); |
||
| 239 | setQuantidadeProdutoSelecionado(1); |
||
| 240 | } |
||
| 241 | |||
| 242 | public void adicionarProduto() { |
||
| 243 | new VerificadorLancamentoException().tratarIhRelancarExcecaoSemLimparEntidade(new CommandBean() { |
||
| 244 | public void execute() { |
||
| 245 | Usuario usuarioTransferencia = getUsuarioTransferencia(); |
||
| 246 | TransferenciaProduto transferenciaProduto = new TransferenciaProduto(); |
||
| 247 | transferenciaProduto.setProduto(getProdutoSelecionado()); |
||
| 248 | transferenciaProduto.setQuantidadeTransferir(getQuantidadeProdutoSelecionado()); |
||
| 249 | transferenciaProduto.setIndicadorRecebido(false); |
||
| 250 | transferenciaProduto.setTransferencia(getEntidade()); |
||
| 251 | transferenciaProduto.setUsuarioSaida(usuarioTransferencia); |
||
| 252 | verificarParametros(transferenciaProduto); |
||
| 253 | verificarAlertas(transferenciaProduto); |
||
| 254 | transferenciaProdutoService.alterar(transferenciaProduto); |
||
| 255 | preAlterar(getEntidade()); |
||
| 256 | setCodigoProduto(null); |
||
| 257 | setUsuarioTransferencia(usuarioTransferencia); |
||
| 258 | LancadorMensagem.lancarSucesso("Produto adicionado, código: " + getProdutoSelecionado().getCodigoProdutoPadrao()); |
||
| 259 | } |
||
| 260 | }); |
||
| 261 | } |
||
| 262 | |||
| 263 | private void verificarAlertas(TransferenciaProduto transferenciaProduto) { |
||
| 264 | Integer estoqueProdutoLojaSaida = produtoLojaService.consultarEstoqueProdutoEeLoja(transferenciaProduto.getProduto(), transferenciaProduto.getTransferencia().getLojaSaida()); |
||
| 265 | if (estoqueProdutoLojaSaida < transferenciaProduto.getQuantidadeTransferir()) { |
||
| 266 | transferenciaProduto.setObservacao("QUANTIDADE SUPERIOR AO ESTOQUE"); |
||
| 267 | } |
||
| 268 | if (estoqueProdutoLojaSaida < 0) { |
||
| 269 | transferenciaProduto.setObservacao("QUANTIDADE SUPERIOR AO ESTOQUE (ESTOQUE NEGATIVO)"); |
||
| 270 | } |
||
| 271 | } |
||
| 272 | |||
| 273 | private void verificarParametros(TransferenciaProduto transferenciaProduto) { |
||
| 274 | if (VerificadorUtil.estaNulo(transferenciaProduto.getQuantidadeTransferir()) || transferenciaProduto.getQuantidadeTransferir().equals(0)) { |
||
| 275 | throw new NegocioException("Obrigatório informar a quantidade para transferência."); |
||
| 276 | } |
||
| 277 | verificarSeProdutoJaFoiAdicionado(transferenciaProduto.getSequencialDoProduto()); |
||
| 278 | } |
||
| 279 | |||
| 280 | protected void verificarSeProdutoJaFoiAdicionado(Long sequencialProduto) { |
||
| 281 | if (getEntidade().verificarSeProdutoJaConstaNaLista(sequencialProduto)) { |
||
| 282 | throw new NegocioException("Produto já foi adicionando anteriormente!"); |
||
| 283 | } |
||
| 284 | } |
||
| 285 | |||
| 286 | public void removerProduto(final TransferenciaProdutoDTO transferenciaProdutoDTO) { |
||
| 287 | new VerificadorLancamentoException().tratarIhRelancarExcecaoSemLimparEntidade(new CommandBean() { |
||
| 288 | public void execute() { |
||
| 289 | Usuario usuarioTransferencia = getUsuarioTransferencia(); |
||
| 290 | transferenciaProdutoService.excluirTransferenciaProduto(transferenciaProdutoDTO); |
||
| 291 | preAlterar(getEntidade()); |
||
| 292 | setUsuarioTransferencia(usuarioTransferencia); |
||
| 293 | LancadorMensagem.lancarSucesso("Produto removido, código: " + transferenciaProdutoDTO.getCodigoProdutoPadrao()); |
||
| 294 | } |
||
| 295 | }); |
||
| 296 | } |
||
| 297 | |||
| 298 | public void escolherTransferenciaProduto() { |
||
| 299 | new VerificadorLancamentoException().tratarIhRelancarExcecaoSemLimparEntidade(new CommandBean() { |
||
| 300 | public void execute() { |
||
| 301 | if (VerificadorUtil.estaNuloOuVazio(getCodigoProduto())) { |
||
| 302 | LancadorMensagem.lancarErro("Informe o código do produto!"); |
||
| 303 | } else { |
||
| 304 | boolean produtoLocalizado = false; |
||
| 305 | for (TransferenciaProdutoDTO transferenciaProdutoDTO : getEntidade().getProdutosDTO()) { |
||
| 306 | if (transferenciaProdutoDTO.verificarSeCodigoEhIgual(getCodigoProduto())) { |
||
| 307 | setTransferenciaProdutoSelecionadoDTO(transferenciaProdutoDTO); |
||
| 308 | produtoLocalizado = true; |
||
| 309 | break; |
||
| 310 | } |
||
| 311 | } |
||
| 312 | if (produtoLocalizado) { |
||
| 204 | espaco | 313 | PrimeFaces.current().ajax().addCallbackParam("confirmado", true); |
| 200 | espaco | 314 | } else { |
| 315 | LancadorMensagem.lancarErro("Produto não localizado!"); |
||
| 316 | } |
||
| 317 | } |
||
| 318 | } |
||
| 319 | }); |
||
| 320 | } |
||
| 321 | |||
| 322 | public void receberProduto() { |
||
| 323 | new VerificadorLancamentoException().tratarIhRelancarExcecaoSemLimparEntidade(new CommandBean() { |
||
| 324 | public void execute() { |
||
| 325 | for (TransferenciaProdutoDTO transferenciaProdutoDTO : getEntidade().getProdutosDTO()) { |
||
| 326 | if (transferenciaProdutoDTO.verificarSeCodigoEhIgual(getCodigoProduto())) { |
||
| 327 | if (transferenciaProdutoDTO.getRecebido()) { |
||
| 328 | LancadorMensagem.lancarErro("Produto já foi recebido anteriormente!"); |
||
| 329 | break; |
||
| 330 | } |
||
| 331 | transferenciaProdutoDTO.setRecebido(true); |
||
| 332 | receberProduto(transferenciaProdutoDTO); |
||
| 333 | setCodigoProduto(null); |
||
| 334 | LancadorMensagem.lancarSucesso("Produto recebido com sucesso!"); |
||
| 335 | break; |
||
| 336 | } |
||
| 337 | } |
||
| 338 | } |
||
| 339 | }); |
||
| 340 | } |
||
| 341 | |||
| 342 | public void receberProduto(final TransferenciaProdutoDTO transferenciaProdutoDTO) { |
||
| 343 | new VerificadorLancamentoException().tratarIhRelancarExcecaoSemLimparEntidade(new CommandBean() { |
||
| 344 | public void execute() { |
||
| 345 | Usuario usuarioTransferencia = getUsuarioTransferencia(); |
||
| 346 | transferenciaProdutoDTO.setUsuarioEntrada(usuarioTransferencia); |
||
| 347 | transferenciaProdutoService.receberProduto(transferenciaProdutoDTO, transferenciaProdutoDTO.getRecebido()); |
||
| 348 | preDetalhar(getEntidade()); |
||
| 349 | setUsuarioTransferencia(usuarioTransferencia); |
||
| 350 | } |
||
| 351 | }); |
||
| 352 | } |
||
| 353 | |||
| 354 | public void verificarTodasTransferenciaProduto() { |
||
| 355 | new VerificadorLancamentoException().tratarIhRelancarExcecaoSemLimparEntidade(new CommandBean() { |
||
| 356 | public void execute() { |
||
| 357 | Usuario usuarioTransferencia = getUsuarioTransferencia(); |
||
| 358 | setEntidade(transferenciaService.detalharTransferencia(getEntidade())); |
||
| 359 | List<TransferenciaProduto> produtosRecebidosPosteriormente = new ArrayList<TransferenciaProduto>(); |
||
| 360 | for (TransferenciaProduto transferenciaProduto : getEntidade().getListaProdutos()) { |
||
| 361 | if (!transferenciaProduto.getIndicadorRecebido()) { |
||
| 362 | produtosRecebidosPosteriormente.add(transferenciaProduto); |
||
| 363 | transferenciaProduto.setUsuarioEntrada(usuarioTransferencia); |
||
| 364 | transferenciaProduto.setIndicadorRecebido(true); |
||
| 365 | } |
||
| 366 | } |
||
| 367 | getService().alterar(getEntidade()); |
||
| 368 | preDetalhar(getEntidade()); |
||
| 369 | setUsuarioTransferencia(usuarioTransferencia); |
||
| 370 | enviarEmailProcedimentoVerificarTudo(getEntidade(), usuarioTransferencia, produtosRecebidosPosteriormente); |
||
| 371 | } |
||
| 372 | |||
| 373 | private void enviarEmailProcedimentoVerificarTudo(Transferencia tranferencia, Usuario usuarioTransferencia, List<TransferenciaProduto> produtosRecebidosPosteriormente) { |
||
| 374 | String diaAtual = DataUtils.converterDataParaString(DataUtils.getDataAtual()); |
||
| 375 | new GerenciadorEmailImpl() |
||
| 376 | .comEmailsDestino(ConstantesSEC.DESTINATARIOS_EMAIL_SUPERVISAO) |
||
| 377 | .comAssunto("ESPAÇO CASE - RECEBIMENTO VERIFICANDO TUDO : " + diaAtual) |
||
| 378 | .comConteudo(montarDadosDaTransferencia(tranferencia, usuarioTransferencia, produtosRecebidosPosteriormente)) |
||
| 379 | .enviar(); |
||
| 380 | } |
||
| 381 | |||
| 382 | private String montarDadosDaTransferencia(Transferencia tranferencia, Usuario usuarioTransferencia, List<TransferenciaProduto> produtosRecebidosPosteriormente) { |
||
| 383 | StringBuilder conteudo = new StringBuilder(); |
||
| 384 | conteudo.append("OPERAÇÃO REALIZADA POR: " + usuarioTransferencia.getNome() + "\n"); |
||
| 385 | conteudo.append("LOJA ORIGEM: " + tranferencia.getLojaSaida().getDescricao() + "\n"); |
||
| 386 | conteudo.append("LOJA DESTINO: " + tranferencia.getLojaEntrada().getDescricao() + "\n"); |
||
| 387 | conteudo.append("DATA DA SOLICITAÇÃO: " + DataUtils.converterDataComHorarioParaString(tranferencia.getDataSolicitacao()) + "\n"); |
||
| 388 | conteudo.append("__________________________________________________\n\n"); |
||
| 389 | conteudo.append("ITENS RECEBIDOS VERIFICANDO TUDO: " + produtosRecebidosPosteriormente.size() + "\n"); |
||
| 390 | conteudo.append("__________________________________________________\n"); |
||
| 391 | for (TransferenciaProduto produtoRecebido : produtosRecebidosPosteriormente) { |
||
| 392 | conteudo.append(produtoRecebido.getProduto().getCodigoProdutoPadrao() + " | "); |
||
| 393 | conteudo.append(produtoRecebido.getProduto().getDescricaoComModeloCompleta() + ", "); |
||
| 394 | conteudo.append("QUANTIDADE: " + produtoRecebido.getQuantidadeTransferir()); |
||
| 395 | conteudo.append("\n"); |
||
| 396 | } |
||
| 397 | conteudo.append("__________________________________________________\n\n"); |
||
| 398 | conteudo.append("TRANSFERÊNCIA:\n"); |
||
| 399 | conteudo.append("__________________________________________________\n"); |
||
| 400 | for (TransferenciaProduto transferenciaProduto : tranferencia.getListaProdutos()) { |
||
| 401 | conteudo.append(transferenciaProduto.getProduto().getCodigoProdutoPadrao() + " | "); |
||
| 402 | conteudo.append(transferenciaProduto.getProduto().getDescricaoComModeloCompleta() + ", "); |
||
| 403 | conteudo.append("QUANTIDADE: " + transferenciaProduto.getQuantidadeTransferir()); |
||
| 404 | conteudo.append("\n"); |
||
| 405 | } |
||
| 406 | conteudo.append("__________________________________________________\n\n"); |
||
| 407 | return conteudo.toString(); |
||
| 408 | } |
||
| 409 | }); |
||
| 410 | } |
||
| 411 | |||
| 412 | public void solicitarTransferencia() { |
||
| 413 | new VerificadorLancamentoException().tratarIhRelancarExcecaoSemLimparEntidade(new CommandBean() { |
||
| 414 | public void execute() { |
||
| 415 | getEntidade().setConferido(false); |
||
| 416 | cadastrar(); |
||
| 417 | } |
||
| 418 | }); |
||
| 419 | } |
||
| 420 | |||
| 421 | public void cadastrarTransferencia() { |
||
| 422 | new VerificadorLancamentoException().tratarIhRelancarExcecaoSemLimparEntidade(new CommandBean() { |
||
| 423 | public void execute() { |
||
| 424 | getEntidade().setConferido(true); |
||
| 425 | cadastrar(); |
||
| 426 | } |
||
| 427 | }); |
||
| 428 | } |
||
| 429 | |||
| 430 | public void cadastrar() { |
||
| 431 | new VerificadorLancamentoException().tratarIhRelancarExcecaoSemLimparEntidade(new CommandBean() { |
||
| 432 | public void execute() { |
||
| 433 | Usuario usuarioTransferencia = verificarSenhaUsuario(getSenhaUsuarioTransferencia()); |
||
| 434 | getEntidade().setLojaSaida(getLojaSelecionada()); |
||
| 435 | getService().cadastrar(getEntidade()); |
||
| 436 | preAlterar(getEntidade()); |
||
| 437 | setLojaSelecionada(getEntidade().getLojaSaida()); |
||
| 438 | setUsuarioTransferencia(usuarioTransferencia); |
||
| 439 | LancadorMensagem.lancarSucesso("TRANSFERÊNCIA INICIADA"); |
||
| 440 | } |
||
| 441 | }); |
||
| 442 | } |
||
| 443 | |||
| 444 | public void alterarSolicitacaoTransferencia() { |
||
| 445 | new VerificadorLancamentoException().tratarIhRelancarExcecaoSemLimparEntidade(new CommandBean() { |
||
| 446 | public void execute() { |
||
| 447 | setUsuarioTransferencia(verificarSenhaUsuario(getSenhaUsuarioTransferencia())); |
||
| 448 | } |
||
| 449 | }); |
||
| 450 | } |
||
| 451 | |||
| 452 | public void iniciarTransferencia() { |
||
| 453 | new VerificadorLancamentoException().tratarIhRelancarExcecaoSemLimparEntidade(new CommandBean() { |
||
| 454 | public void execute() { |
||
| 455 | getEntidade().setConferido(true); |
||
| 456 | retirarVerificacaoProdutos(); |
||
| 457 | alterar(); |
||
| 458 | LancadorMensagem.lancarSucesso("TRANSFERÊNCIA INICIADA"); |
||
| 459 | } |
||
| 460 | }); |
||
| 461 | } |
||
| 462 | |||
| 463 | public void solicitarNovamenteTransferencia() { |
||
| 464 | new VerificadorLancamentoException().tratarIhRelancarExcecaoSemLimparEntidade(new CommandBean() { |
||
| 465 | public void execute() { |
||
| 466 | getEntidade().setConferido(false); |
||
| 467 | retirarVerificacaoProdutos(); |
||
| 468 | alterar(); |
||
| 469 | LancadorMensagem.lancarSucesso("SOLICITAÇÃO DE TRANSFERÊNCIA INICIADA"); |
||
| 470 | } |
||
| 471 | }); |
||
| 472 | } |
||
| 473 | |||
| 474 | private Usuario verificarSenhaUsuario(String senha) { |
||
| 475 | return usuarioService.consultarUsuarioPorSenha(senha); |
||
| 476 | } |
||
| 477 | |||
| 478 | public void receberProdutos() { |
||
| 479 | new VerificadorLancamentoException().tratarIhRelancarExcecaoSemLimparEntidade(new CommandBean() { |
||
| 480 | public void execute() { |
||
| 481 | transferenciaService.receberProdutos(getEntidade()); |
||
| 482 | setTipoOperacao(TipoOperacao.CONSULTAR); |
||
| 483 | LancadorMensagem.lancarSucesso("TRANSFERÊNCIA CONCLUÍDA COM SUCESSO"); |
||
| 484 | Transferencia transferencia = transferenciaService.detalharTransferencia(getEntidade()); |
||
| 485 | gerarNotaFiscalRemessa(transferencia); |
||
| 486 | limparEntidade(); |
||
| 487 | } |
||
| 488 | }); |
||
| 489 | } |
||
| 490 | |||
| 491 | public void excluirTransferencia(final Transferencia transferencia) { |
||
| 492 | new VerificadorLancamentoException().tratarIhRelancarExcecaoSemLimparEntidade(new CommandBean() { |
||
| 493 | public void execute() { |
||
| 494 | excluir(transferencia); |
||
| 495 | LancadorMensagem.lancarSucesso("RANSFERÊNCIA EXCLUÍDA COM SUCESSO"); |
||
| 496 | } |
||
| 497 | }); |
||
| 498 | } |
||
| 499 | |||
| 500 | public void verificarTodosProdutos() { |
||
| 501 | new VerificadorLancamentoException().tratarIhRelancarExcecaoSemLimparEntidade(new CommandBean() { |
||
| 502 | public void execute() { |
||
| 503 | for (TransferenciaProdutoDTO transferenciaProdutoDTO : getEntidade().getProdutosDTO()) { |
||
| 504 | transferenciaProdutoDTO.setRecebido(true); |
||
| 505 | } |
||
| 506 | LancadorMensagem.lancarSucesso("Produtos verificados com sucesso!"); |
||
| 507 | } |
||
| 508 | }); |
||
| 509 | } |
||
| 510 | |||
| 511 | public void gerarNotaFiscalRemessa(final Transferencia transferencia) { |
||
| 512 | new VerificadorLancamentoException().tratarIhRelancarExcecaoSemLimparEntidade(new CommandBean() { |
||
| 513 | public void execute() { |
||
| 514 | if (sePermitidoEnvio(transferencia)) { |
||
| 515 | String numeroNota = "" + notaFiscalService.consultarProximoNumeroNotaFiscal(TipoNotaFiscal.NFE_REMESSA.getValor(), transferencia.getLojaSaida().getPessoaJuridica()); |
||
| 516 | NotaFiscal notaFiscal = new NotaFiscal(); |
||
| 517 | notaFiscal.setNumeroNotaFiscal(new Long(numeroNota)); |
||
| 518 | notaFiscal.setTipoModeloNotaFiscal(TipoModeloNotaFiscal.MODELO_NFE_55.getValor()); |
||
| 519 | notaFiscal.setTipoNotaFiscal(TipoNotaFiscal.NFE_REMESSA.getValor()); |
||
| 520 | notaFiscal.setSerie(TipoNotaFiscal.NFE_REMESSA.getSerie()); |
||
| 521 | notaFiscal.setDataHoraEmissao(DataUtils.getDataAtual()); |
||
| 522 | notaFiscal.setPessoaEmitente(transferencia.getLojaSaida().getPessoaJuridica()); |
||
| 523 | notaFiscal.setPessoaDestinatario(transferencia.getLojaEntrada().getPessoaJuridica()); |
||
| 524 | notaFiscalService.cadastrar(notaFiscal); |
||
| 525 | |||
| 526 | // ADICIONAR PRODUTOS COM FORNECEDORES APTOS |
||
| 527 | NotaFiscal notaFiscalRemessa = notaFiscalService.consultarPeloNumeroEeTipo(notaFiscal.getNumeroNotaFiscal(), notaFiscal.getTipoNotaFiscal()); |
||
| 528 | List<Fornecedor> fornecedoresEmitemNota = fornecedorService.consultarFornecedoresComEmissaoNota(); |
||
| 529 | List<TransferenciaProduto> transferenciaProdutos = transferenciaService.consultarProdutosVerificandoFornecedores(transferencia, fornecedoresEmitemNota); |
||
| 530 | for (TransferenciaProduto transferenciaProduto : transferenciaProdutos) { |
||
| 531 | NotaFiscalProduto notaFiscalProduto = new NotaFiscalProduto(); |
||
| 532 | notaFiscalProduto.setNotaFiscal(notaFiscalRemessa); |
||
| 533 | notaFiscalProduto.setProduto(transferenciaProduto.getProduto()); |
||
| 534 | notaFiscalProduto.setQuantidade(transferenciaProduto.getQuantidadeTransferir()); |
||
| 535 | notaFiscalProdutoService.cadastrar(notaFiscalProduto); |
||
| 536 | } |
||
| 537 | transferencia.setNotaFiscalRemessa(notaFiscalRemessa); |
||
| 538 | transferenciaService.alterar(transferencia); |
||
| 539 | |||
| 540 | LancadorMensagem.lancarSucesso("NOTA DE REMESSA: INICIADA COM SUCESSO"); |
||
| 541 | } |
||
| 542 | } |
||
| 543 | |||
| 544 | private boolean sePermitidoEnvio(Transferencia transferencia) { |
||
| 545 | if (VerificadorUtil.estaNulo(transferencia.getLojaEntrada().getPessoaJuridica()) |
||
| 546 | || VerificadorUtil.estaNulo(transferencia.getLojaSaida().getPessoaJuridica())) { |
||
| 547 | return false; |
||
| 548 | } |
||
| 549 | return seEmitenteForMatriz(transferencia) && transferencia.getLojaEntrada().getReceberNotaFiscalRemessa() && !seCnpjsIguais(transferencia); |
||
| 550 | } |
||
| 551 | |||
| 552 | private boolean seEmitenteForMatriz(final Transferencia transferencia) { |
||
| 553 | return transferencia.getLojaSaida().getPessoaJuridica().getCpfCnpj().equals(ConstantesSEC.Empresa.CNPJ_21494821000100); |
||
| 554 | } |
||
| 555 | |||
| 556 | private boolean seCnpjsIguais(final Transferencia transferencia) { |
||
| 557 | return transferencia.getLojaSaida().getPessoaJuridica().getCpfCnpj().equals(transferencia.getLojaEntrada().getPessoaJuridica().getCpfCnpj()); |
||
| 558 | } |
||
| 559 | |||
| 560 | }); |
||
| 561 | } |
||
| 562 | |||
| 563 | } |