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