Rev 344 | Rev 686 | Go to most recent revision | 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.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.controller.managedbean.datamodel.ParcelaDataModel; |
||
| 195 | espaco | 12 | import br.com.ec.core.consulta.ParametrosConsulta; |
| 13 | import br.com.ec.core.exception.NegocioException; |
||
| 14 | import br.com.ec.core.generic.GenericService; |
||
| 15 | import br.com.ec.core.util.VerificadorUtil; |
||
| 106 | espaco | 16 | import br.com.ec.domain.dto.ParametrosVendaDTO; |
| 17 | import br.com.ec.domain.model.BandeiraCartao; |
||
| 18 | import br.com.ec.domain.model.Cliente; |
||
| 19 | import br.com.ec.domain.model.Conta; |
||
| 20 | import br.com.ec.domain.model.Cupom; |
||
| 305 | espaco | 21 | import br.com.ec.domain.model.Estampa; |
| 106 | espaco | 22 | import br.com.ec.domain.model.FormaPagamento; |
| 23 | import br.com.ec.domain.model.Lancamento; |
||
| 24 | import br.com.ec.domain.model.Loja; |
||
| 25 | import br.com.ec.domain.model.Modelo; |
||
| 26 | import br.com.ec.domain.model.NotaFiscal; |
||
| 27 | import br.com.ec.domain.model.Pedido; |
||
| 28 | import br.com.ec.domain.model.PedidoProduto; |
||
| 29 | import br.com.ec.domain.model.Produto; |
||
| 30 | import br.com.ec.domain.model.Venda; |
||
| 31 | import br.com.ec.domain.model.VendaFormaPagamento; |
||
| 32 | import br.com.ec.domain.model.Vendedor; |
||
| 33 | import br.com.ec.domain.model.tipos.TipoCupom; |
||
| 34 | import br.com.ec.domain.model.tipos.TipoFrete; |
||
| 305 | espaco | 35 | import br.com.ec.domain.model.tipos.TipoPersonalizacao; |
| 106 | espaco | 36 | import br.com.ec.domain.model.tipos.TipoSituacaoPedido; |
| 37 | import br.com.ec.domain.service.bandeiracartao.BandeiraCartaoService; |
||
| 38 | import br.com.ec.domain.service.cliente.ClienteService; |
||
| 39 | import br.com.ec.domain.service.conta.ContaService; |
||
| 40 | import br.com.ec.domain.service.cupom.CupomService; |
||
| 41 | import br.com.ec.domain.service.email.impl.GerenciadorEmailImpl; |
||
| 305 | espaco | 42 | import br.com.ec.domain.service.estampa.EstampaService; |
| 106 | espaco | 43 | import br.com.ec.domain.service.formapagamento.FormaPagamentoService; |
| 44 | import br.com.ec.domain.service.lancamento.LancamentoService; |
||
| 45 | import br.com.ec.domain.service.loja.LojaService; |
||
| 46 | import br.com.ec.domain.service.modelo.ModeloService; |
||
| 47 | import br.com.ec.domain.service.notafiscal.NotaFiscalService; |
||
| 48 | import br.com.ec.domain.service.parcela.ParcelaService; |
||
| 49 | import br.com.ec.domain.service.pedido.PedidoService; |
||
| 50 | import br.com.ec.domain.service.produto.ProdutoService; |
||
| 51 | import br.com.ec.domain.service.produtodaloja.ProdutoLojaService; |
||
| 52 | import br.com.ec.domain.service.seguranca.ContextoSeguranca; |
||
| 53 | import br.com.ec.domain.service.venda.VendaService; |
||
| 54 | import br.com.ec.domain.service.vendaformapagamento.VendaFormaPagamentoService; |
||
| 55 | import br.com.ec.domain.service.vendedor.VendedorService; |
||
| 56 | import br.com.ec.domain.shared.ConstantesSEC; |
||
| 195 | espaco | 57 | import br.com.ec.web.exception.VerificadorLancamentoException; |
| 58 | import br.com.ec.web.exception.VerificadorLancamentoException.CommandBean; |
||
| 59 | import br.com.ec.web.generic.AbstractBean; |
||
| 60 | import br.com.ec.web.message.LancadorMensagem; |
||
| 106 | espaco | 61 | import net.sf.jasperreports.engine.JasperExportManager; |
| 62 | import net.sf.jasperreports.engine.JasperPrint; |
||
| 63 | |||
| 64 | @Named |
||
| 65 | @Scope("view") |
||
| 66 | public class VendaBean extends AbstractBean<Venda> implements Serializable { |
||
| 67 | |||
| 68 | private static final long serialVersionUID = 1L; |
||
| 69 | |||
| 70 | private LojaService lojaService; |
||
| 71 | private VendaService vendaService; |
||
| 72 | private ProdutoService produtoService; |
||
| 73 | private ProdutoLojaService produtoLojaService; |
||
| 74 | private VendedorService vendedorService; |
||
| 75 | private FormaPagamentoService formaPagamentoService; |
||
| 76 | private VendaFormaPagamentoService vendaFormaPagamentoService; |
||
| 77 | private BandeiraCartaoService bandeiraCartaoService; |
||
| 78 | private ParcelaService parcelaService; |
||
| 79 | private ContaService contaAReceberService; |
||
| 80 | private ClienteService clienteService; |
||
| 81 | private ModeloService modeloService; |
||
| 82 | private NotaFiscalService notaFiscalService; |
||
| 83 | private CupomService cupomService; |
||
| 84 | private LancamentoService lancamentoService; |
||
| 85 | private PedidoService pedidoService; |
||
| 305 | espaco | 86 | private EstampaService estampaService; |
| 106 | espaco | 87 | private ContextoSeguranca contextoSeguranca; |
| 88 | |||
| 89 | private String codigoProduto; |
||
| 90 | private String codigoPedido; |
||
| 91 | private Lancamento lancamento; |
||
| 92 | private String localizacaoNova; |
||
| 93 | private String cpfCnpjCliente; |
||
| 94 | private ParametrosVendaDTO parametrosVenda; |
||
| 95 | private Venda vendaSelecionada; |
||
| 96 | private String observacaoExclusao; |
||
| 97 | private Cupom cupomSelecionado; |
||
| 98 | private Lancamento lancamentoSelecionado; |
||
| 99 | |||
| 100 | private FormaPagamento formaPagamento; |
||
| 101 | private BandeiraCartao bandeiraCartao; |
||
| 102 | private Double valorPagamento; |
||
| 103 | |||
| 104 | private List<FormaPagamento> formasDePagamentoDeCredito; |
||
| 105 | private List<BandeiraCartao> bandeirasDeDebito; |
||
| 106 | private List<BandeiraCartao> bandeirasDeCredito; |
||
| 107 | |||
| 108 | private ParcelaDataModel parcelas; |
||
| 109 | private Boolean emitirCupom = false; |
||
| 110 | private String emailParaEnvio; |
||
| 111 | |||
| 112 | private List<Vendedor> vendedoresColaboradores; |
||
| 113 | private List<Vendedor> vendedoresColaboradoresAtivos; |
||
| 114 | private List<Vendedor> vendedoresExternos; |
||
| 115 | |||
| 305 | espaco | 116 | private List<Estampa> estampas; |
| 117 | |||
| 106 | espaco | 118 | @Inject |
| 119 | public VendaBean(LojaService lojaService, VendaService vendaService, ProdutoService produtoService, ProdutoLojaService produtoLojaService, |
||
| 120 | VendedorService vendedorService, FormaPagamentoService formaPagamentoService, VendaFormaPagamentoService vendaFormaPagamentoService, |
||
| 121 | BandeiraCartaoService bandeiraCartaoService, ParcelaService parcelaService, |
||
| 122 | ContaService contaAReceberService, ClienteService clienteService, ModeloService modeloService, |
||
| 123 | NotaFiscalService notaFiscalService, CupomService cupomService, LancamentoService lancamentoService, PedidoService pedidoService, |
||
| 305 | espaco | 124 | EstampaService estampaService, ContextoSeguranca contextoSeguranca) { |
| 106 | espaco | 125 | this.lojaService = lojaService; |
| 126 | this.vendaService = vendaService; |
||
| 127 | this.produtoService = produtoService; |
||
| 128 | this.produtoLojaService = produtoLojaService; |
||
| 129 | this.vendedorService = vendedorService; |
||
| 130 | this.formaPagamentoService = formaPagamentoService; |
||
| 131 | this.vendaFormaPagamentoService = vendaFormaPagamentoService; |
||
| 132 | this.bandeiraCartaoService = bandeiraCartaoService; |
||
| 133 | this.parcelaService = parcelaService; |
||
| 134 | this.contaAReceberService = contaAReceberService; |
||
| 135 | this.clienteService = clienteService; |
||
| 136 | this.modeloService = modeloService; |
||
| 137 | this.notaFiscalService = notaFiscalService; |
||
| 138 | this.cupomService = cupomService; |
||
| 139 | this.lancamentoService = lancamentoService; |
||
| 140 | this.pedidoService = pedidoService; |
||
| 305 | espaco | 141 | this.estampaService = estampaService; |
| 106 | espaco | 142 | this.contextoSeguranca = contextoSeguranca; |
| 143 | } |
||
| 144 | |||
| 145 | @Override |
||
| 146 | public void preCarregamento() { |
||
| 147 | limparEntidade(); |
||
| 148 | } |
||
| 149 | |||
| 150 | private void setarParametrosDaLoja() { |
||
| 151 | parametrosVenda = new ParametrosVendaDTO(); |
||
| 152 | if (VerificadorUtil.naoEstaNulo(getParametro("sequencialLoja"))) { |
||
| 153 | Loja loja = new Loja(); |
||
| 154 | loja.setSequencial(new Long(getParametro("sequencialLoja").toString())); |
||
| 155 | parametrosVenda.setLoja(lojaService.consultarPorId(loja)); |
||
| 156 | parametrosVenda.setMaquineta(parametrosVenda.getLoja().getMaquineta()); |
||
| 157 | } |
||
| 158 | parametrosVenda.setUsuario(contextoSeguranca.obterUsuario()); |
||
| 159 | } |
||
| 160 | |||
| 161 | @Override |
||
| 162 | public void preDetalhar(Venda venda) { |
||
| 163 | setEntidade(vendaService.detalharVendaCompleta(venda)); |
||
| 164 | } |
||
| 165 | |||
| 166 | @Override |
||
| 167 | public void limparEntidade() { |
||
| 168 | entidade = new Venda(); |
||
| 169 | parametrosConsulta = new ParametrosConsulta<Venda>(); |
||
| 170 | parametrosConsulta.setEntidade(entidade); |
||
| 171 | |||
| 172 | setLancamento(new Lancamento()); |
||
| 173 | setarParametrosDaLoja(); |
||
| 174 | setParcelas(new ParcelaDataModel()); |
||
| 175 | } |
||
| 176 | |||
| 177 | @Override |
||
| 178 | public GenericService<Venda> getService() { |
||
| 179 | return vendaService; |
||
| 180 | } |
||
| 181 | |||
| 182 | @Override |
||
| 183 | public Venda getEntidade() { |
||
| 184 | return entidade; |
||
| 185 | } |
||
| 186 | |||
| 187 | @Override |
||
| 188 | public Venda getId() { |
||
| 189 | return getEntidade(); |
||
| 190 | } |
||
| 191 | |||
| 192 | public String getCodigoProduto() { |
||
| 193 | return codigoProduto; |
||
| 194 | } |
||
| 195 | public void setCodigoProduto(String codigoProduto) { |
||
| 196 | this.codigoProduto = codigoProduto; |
||
| 197 | } |
||
| 198 | |||
| 199 | public String getCodigoPedido() { |
||
| 200 | return codigoPedido; |
||
| 201 | } |
||
| 202 | public void setCodigoPedido(String codigoPedido) { |
||
| 203 | this.codigoPedido = codigoPedido; |
||
| 204 | } |
||
| 205 | |||
| 206 | public Lancamento getLancamento() { |
||
| 207 | return lancamento; |
||
| 208 | } |
||
| 209 | public void setLancamento(Lancamento lancamento) { |
||
| 210 | this.lancamento = lancamento; |
||
| 211 | } |
||
| 212 | |||
| 213 | public String getLocalizacaoNova() { |
||
| 214 | return localizacaoNova; |
||
| 215 | } |
||
| 216 | public void setLocalizacaoNova(String localizacaoNova) { |
||
| 217 | this.localizacaoNova = localizacaoNova; |
||
| 218 | } |
||
| 219 | |||
| 220 | public String getCpfCnpjCliente() { |
||
| 221 | return VerificadorUtil.naoEstaNulo(cpfCnpjCliente)? cpfCnpjCliente.replace(".", "").replace("-", "") : cpfCnpjCliente; |
||
| 222 | } |
||
| 223 | public void setCpfCnpjCliente(String cpfCnpjCliente) { |
||
| 224 | this.cpfCnpjCliente = cpfCnpjCliente; |
||
| 225 | } |
||
| 226 | |||
| 227 | public ParametrosVendaDTO getParametrosVenda() { |
||
| 228 | return parametrosVenda; |
||
| 229 | } |
||
| 230 | public void setParametrosVenda(ParametrosVendaDTO parametrosVenda) { |
||
| 231 | this.parametrosVenda = parametrosVenda; |
||
| 232 | } |
||
| 233 | |||
| 234 | public Venda getVendaSelecionada() { |
||
| 235 | return vendaSelecionada; |
||
| 236 | } |
||
| 237 | public void setVendaSelecionada(Venda vendaSelecionada) { |
||
| 238 | this.vendaSelecionada = vendaSelecionada; |
||
| 239 | } |
||
| 240 | |||
| 241 | public String getObservacaoExclusao() { |
||
| 242 | return observacaoExclusao; |
||
| 243 | } |
||
| 244 | public void setObservacaoExclusao(String observacaoExclusao) { |
||
| 245 | this.observacaoExclusao = observacaoExclusao; |
||
| 246 | } |
||
| 247 | |||
| 248 | public Cupom getCupomSelecionado() { |
||
| 249 | return cupomSelecionado; |
||
| 250 | } |
||
| 251 | public void setCupomSelecionado(Cupom cupomSelecionado) { |
||
| 252 | this.cupomSelecionado = cupomSelecionado; |
||
| 253 | } |
||
| 254 | |||
| 255 | public Lancamento getLancamentoSelecionado() { |
||
| 256 | return lancamentoSelecionado; |
||
| 257 | } |
||
| 258 | public void setLancamentoSelecionado(Lancamento lancamentoSelecionado) { |
||
| 259 | this.lancamentoSelecionado = lancamentoSelecionado; |
||
| 260 | } |
||
| 261 | |||
| 262 | public FormaPagamento getFormaPagamento() { |
||
| 263 | return formaPagamento; |
||
| 264 | } |
||
| 265 | public void setFormaPagamento(FormaPagamento formaPagamento) { |
||
| 266 | this.formaPagamento = formaPagamento; |
||
| 267 | } |
||
| 268 | |||
| 269 | public BandeiraCartao getBandeiraCartao() { |
||
| 270 | return bandeiraCartao; |
||
| 271 | } |
||
| 272 | public void setBandeiraCartao(BandeiraCartao bandeiraCartao) { |
||
| 273 | this.bandeiraCartao = bandeiraCartao; |
||
| 274 | } |
||
| 275 | |||
| 276 | public Double getValorPagamento() { |
||
| 277 | return valorPagamento; |
||
| 278 | } |
||
| 279 | public void setValorPagamento(Double valorPagamento) { |
||
| 280 | this.valorPagamento = valorPagamento; |
||
| 281 | } |
||
| 282 | |||
| 283 | public List<FormaPagamento> getFormasDePagamentoDeCredito() { |
||
| 284 | if (VerificadorUtil.estaNulo(formasDePagamentoDeCredito)) { |
||
| 285 | setFormasDePagamentoDeCredito(formaPagamentoService.consultarFormasDePagamentoDeCredito()); |
||
| 286 | } |
||
| 287 | return formasDePagamentoDeCredito; |
||
| 288 | } |
||
| 289 | public void setFormasDePagamentoDeCredito(List<FormaPagamento> formasDePagamentoDeCredito) { |
||
| 290 | this.formasDePagamentoDeCredito = formasDePagamentoDeCredito; |
||
| 291 | } |
||
| 292 | |||
| 293 | public List<BandeiraCartao> getBandeirasDeDebito() { |
||
| 294 | if (VerificadorUtil.estaNulo(bandeirasDeDebito)) { |
||
| 295 | setBandeirasDeDebito(bandeiraCartaoService.consultarBandeiraCartoesDeDebito()); |
||
| 296 | } |
||
| 297 | return bandeirasDeDebito; |
||
| 298 | } |
||
| 299 | public void setBandeirasDeDebito(List<BandeiraCartao> bandeirasDeDebito) { |
||
| 300 | this.bandeirasDeDebito = bandeirasDeDebito; |
||
| 301 | } |
||
| 302 | |||
| 303 | public List<BandeiraCartao> getBandeirasDeCredito() { |
||
| 304 | if (VerificadorUtil.estaNulo(bandeirasDeCredito)) { |
||
| 305 | setBandeirasDeCredito(bandeiraCartaoService.consultarBandeiraCartoesDeCredito()); |
||
| 306 | } |
||
| 307 | return bandeirasDeCredito; |
||
| 308 | } |
||
| 309 | public void setBandeirasDeCredito(List<BandeiraCartao> bandeirasDeCredito) { |
||
| 310 | this.bandeirasDeCredito = bandeirasDeCredito; |
||
| 311 | } |
||
| 312 | |||
| 313 | public List<Venda> getConsultarTodas() { |
||
| 314 | return vendaService.consultarTodos(new Venda()); |
||
| 315 | } |
||
| 316 | |||
| 317 | public ParcelaDataModel getParcelas() { |
||
| 318 | atualizarParcelas(getParametrosVenda().getVenda()); |
||
| 319 | return parcelas; |
||
| 320 | } |
||
| 321 | public void setParcelas(ParcelaDataModel parcelas) { |
||
| 322 | this.parcelas = parcelas; |
||
| 323 | } |
||
| 324 | public void atualizarParcelas(Venda venda) { |
||
| 325 | if (VerificadorUtil.naoEstaNulo(venda)) { |
||
| 326 | setParcelas(new ParcelaDataModel(parcelaService.consultarParcelasDaVenda(getParametrosVenda().getVenda().getSequencial()))); |
||
| 327 | } |
||
| 328 | } |
||
| 329 | |||
| 330 | public Boolean getEmitirCupom() { |
||
| 331 | return emitirCupom; |
||
| 332 | } |
||
| 333 | public void setEmitirCupom(Boolean emitirCupom) { |
||
| 334 | this.emitirCupom = emitirCupom; |
||
| 335 | } |
||
| 336 | |||
| 337 | public String getEmailParaEnvio() { |
||
| 338 | return emailParaEnvio; |
||
| 339 | } |
||
| 340 | public void setEmailParaEnvio(String emailParaEnvio) { |
||
| 341 | this.emailParaEnvio = emailParaEnvio; |
||
| 342 | } |
||
| 343 | |||
| 344 | public List<Vendedor> getVendedoresColaboradores() { |
||
| 345 | if (VerificadorUtil.estaNulo(vendedoresColaboradores)) { |
||
| 346 | setVendedoresColaboradores(vendedorService.consultarVendedoresColaboradores()); |
||
| 347 | } |
||
| 348 | return vendedoresColaboradores; |
||
| 349 | } |
||
| 350 | public void setVendedoresColaboradores(List<Vendedor> vendedoresColaboradores) { |
||
| 351 | this.vendedoresColaboradores = vendedoresColaboradores; |
||
| 352 | } |
||
| 353 | |||
| 354 | public List<Vendedor> getVendedoresColaboradoresAtivos() { |
||
| 355 | if (VerificadorUtil.estaNulo(vendedoresColaboradoresAtivos)) { |
||
| 356 | setVendedoresColaboradoresAtivos(vendedorService.consultarVendedoresColaboradoresAtivos(null)); |
||
| 357 | } |
||
| 358 | return vendedoresColaboradoresAtivos; |
||
| 359 | } |
||
| 360 | public void setVendedoresColaboradoresAtivos(List<Vendedor> vendedoresColaboradoresAtivos) { |
||
| 361 | this.vendedoresColaboradoresAtivos = vendedoresColaboradoresAtivos; |
||
| 362 | } |
||
| 363 | |||
| 364 | public List<Vendedor> getVendedoresExternos() { |
||
| 365 | if (VerificadorUtil.estaNulo(vendedoresExternos)) { |
||
| 366 | setVendedoresExternos(vendedorService.consultarVendedoresExternosAtivos()); |
||
| 367 | } |
||
| 368 | return vendedoresExternos; |
||
| 369 | } |
||
| 370 | public void setVendedoresExternos(List<Vendedor> vendedoresExternos) { |
||
| 371 | this.vendedoresExternos = vendedoresExternos; |
||
| 372 | } |
||
| 373 | |||
| 305 | espaco | 374 | public List<Estampa> getEstampas() { |
| 375 | if (VerificadorUtil.estaNulo(estampas)) { |
||
| 376 | setEstampas(estampaService.consultarEstampas(null)); |
||
| 377 | } |
||
| 378 | return estampas; |
||
| 379 | } |
||
| 380 | public void setEstampas(List<Estampa> estampas) { |
||
| 381 | this.estampas = estampas; |
||
| 382 | } |
||
| 383 | |||
| 106 | espaco | 384 | public TipoFrete[] getTiposFrete() { |
| 385 | return TipoFrete.values(); |
||
| 386 | } |
||
| 305 | espaco | 387 | |
| 388 | public TipoPersonalizacao[] getTiposPersonalizacao() { |
||
| 389 | return TipoPersonalizacao.values(); |
||
| 390 | } |
||
| 106 | espaco | 391 | |
| 392 | /***************************************************************/ |
||
| 393 | |||
| 394 | public void selecionarCodigoProduto(String codigoProduto) { |
||
| 395 | setCodigoProduto(codigoProduto); |
||
| 396 | } |
||
| 397 | |||
| 398 | public void prepararParaAlterarVenda(final Venda venda) { |
||
| 399 | new VerificadorLancamentoException().tratarIhRelancarExcecaoSemLimparEntidade(new CommandBean() { |
||
| 400 | public void execute() { |
||
| 401 | parametrosVenda = new ParametrosVendaDTO(venda); |
||
| 402 | } |
||
| 403 | }); |
||
| 404 | } |
||
| 405 | |||
| 406 | public void prepararParaAlterarVendaFinanceiro(final Venda venda) { |
||
| 407 | new VerificadorLancamentoException().tratarIhRelancarExcecaoSemLimparEntidade(new CommandBean() { |
||
| 408 | public void execute() { |
||
| 409 | parametrosVenda = new ParametrosVendaDTO(venda); |
||
| 410 | setParcelas(new ParcelaDataModel(parcelaService.consultarParcelasDaVenda(venda.getSequencial()))); |
||
| 411 | } |
||
| 412 | }); |
||
| 413 | } |
||
| 414 | |||
| 415 | public void prepararParaExcluirVenda(final Venda venda) { |
||
| 416 | new VerificadorLancamentoException().tratarIhRelancarExcecaoSemLimparEntidade(new CommandBean() { |
||
| 417 | public void execute() { |
||
| 418 | setVendaSelecionada(venda); |
||
| 419 | List<NotaFiscal> notasFiscais = notaFiscalService.consultarNotasFiscais(venda); |
||
| 420 | if (!notasFiscais.isEmpty()) { |
||
| 421 | String observacao = ""; |
||
| 422 | for (NotaFiscal notaFiscal : notasFiscais) { |
||
| 423 | observacao = notaFiscal.getNumeroNotaFiscal() + "; "; |
||
| 424 | } |
||
| 425 | setObservacaoExclusao("OBS.: NOTAS FISCAIS VINCULADAS: " + observacao); |
||
| 426 | } else { |
||
| 427 | setObservacaoExclusao(""); |
||
| 428 | } |
||
| 429 | } |
||
| 430 | }); |
||
| 431 | } |
||
| 432 | |||
| 433 | public void consultarProduto() { |
||
| 434 | new VerificadorLancamentoException().tratarIhRelancarExcecaoSemLimparEntidade(new CommandBean() { |
||
| 435 | public void execute() { |
||
| 436 | Produto produtoSelecionado = produtoService.consultarProdutoPorCodigoOuCodigoEAN(getCodigoProduto()); |
||
| 437 | if (VerificadorUtil.naoEstaNulo(produtoSelecionado)) { |
||
| 438 | getLancamento().preencher(produtoSelecionado); |
||
| 439 | } |
||
| 440 | getLancamento().setVenda(getEntidade()); |
||
| 441 | getLancamento().setAtivo(true); |
||
| 442 | } |
||
| 443 | }); |
||
| 444 | } |
||
| 445 | |||
| 446 | public void consultarProdutoPrecoPopular() { |
||
| 447 | new VerificadorLancamentoException().tratarIhRelancarExcecaoSemLimparEntidade(new CommandBean() { |
||
| 448 | public void execute() { |
||
| 449 | Produto produtoSelecionado = produtoService.consultarProdutoPorCodigoOuCodigoEAN(getCodigoProduto()); |
||
| 450 | if (VerificadorUtil.naoEstaNulo(produtoSelecionado)) { |
||
| 451 | getLancamento().preencherComPrecoPopular(produtoSelecionado); |
||
| 452 | } |
||
| 453 | getLancamento().setVenda(getEntidade()); |
||
| 454 | getLancamento().setAtivo(true); |
||
| 455 | } |
||
| 456 | }); |
||
| 457 | } |
||
| 458 | |||
| 459 | public void consultarProdutoPrecoAtacado() { |
||
| 460 | new VerificadorLancamentoException().tratarIhRelancarExcecaoSemLimparEntidade(new CommandBean() { |
||
| 461 | public void execute() { |
||
| 462 | Produto produtoSelecionado = produtoService.consultarProdutoPorCodigoOuCodigoEAN(getCodigoProduto()); |
||
| 463 | if (VerificadorUtil.naoEstaNulo(produtoSelecionado)) { |
||
| 464 | getLancamento().preencherComPrecoAtacado(produtoSelecionado); |
||
| 465 | } |
||
| 466 | getLancamento().setVenda(getEntidade()); |
||
| 467 | getLancamento().setAtivo(true); |
||
| 468 | } |
||
| 469 | }); |
||
| 470 | } |
||
| 471 | |||
| 472 | public void consultarProdutoFarma() { |
||
| 473 | new VerificadorLancamentoException().tratarIhRelancarExcecaoSemLimparEntidade(new CommandBean() { |
||
| 474 | public void execute() { |
||
| 475 | Produto produtoSelecionado = produtoService.consultarProdutoPorCodigoRapidoOuCodigoEAN(getCodigoProduto()); |
||
| 476 | if (VerificadorUtil.naoEstaNulo(produtoSelecionado)) { |
||
| 477 | getLancamento().preencher(produtoSelecionado); |
||
| 478 | } |
||
| 479 | getLancamento().setVenda(getEntidade()); |
||
| 480 | getLancamento().setAtivo(true); |
||
| 481 | } |
||
| 482 | }); |
||
| 483 | } |
||
| 484 | |||
| 485 | public void adicionarLancamento() { |
||
| 486 | new VerificadorLancamentoException().tratarIhRelancarExcecaoSemLimparEntidade(new CommandBean() { |
||
| 487 | public void execute() { |
||
| 488 | if (VerificadorUtil.estaNulo(getLancamento().getValorVenda())) { |
||
| 489 | getLancamento().setValorVenda(new Double(0.0)); |
||
| 490 | } |
||
| 491 | for (int i = 1; i <= getLancamento().getQuantidadeLancamento(); i++) { |
||
| 492 | try { |
||
| 493 | getLancamento().setObservacaoNotaFiscal(getLancamento().getObservacaoIMEI1() + " " + getLancamento().getObservacaoIMEI2()); |
||
| 494 | getLancamento().getObservacaoNotaFiscal().trim(); |
||
| 495 | getParametrosVenda().getLancamentos().add((Lancamento)getLancamento().clone()); |
||
| 496 | } catch (CloneNotSupportedException e) { |
||
| 497 | e.printStackTrace(); |
||
| 498 | } |
||
| 499 | } |
||
| 500 | // atualizarValorVendaSeForLojaFarmaciaEProdutoSemValorVenda(getLancamento()); |
||
| 501 | limparLancamento(); |
||
| 502 | LancadorMensagem.lancarSucesso("PRODUTO ADICIONADO COM SUCESSO"); |
||
| 503 | } |
||
| 504 | }); |
||
| 505 | } |
||
| 506 | |||
| 507 | public void adicionarLancamentoRestaurante() { |
||
| 508 | new VerificadorLancamentoException().tratarIhRelancarExcecaoSemLimparEntidade(new CommandBean() { |
||
| 509 | public void execute() { |
||
| 510 | if (VerificadorUtil.estaNulo(getLancamento().getValorVenda())) { |
||
| 511 | getLancamento().setValorVenda(new Double(0.0)); |
||
| 512 | } |
||
| 513 | for (int i = 1; i <= getLancamento().getQuantidadeLancamento(); i++) { |
||
| 514 | try { |
||
| 515 | String opcoes = ""; |
||
| 516 | for (String opcao : getLancamento().getOpcoesRestaurante()) { |
||
| 517 | opcoes = opcoes + opcao + " - "; |
||
| 518 | } |
||
| 519 | String observacoes = ""; |
||
| 520 | if (VerificadorUtil.naoEstaNuloOuVazio(opcoes)) { |
||
| 521 | observacoes = observacoes + opcoes; |
||
| 522 | } |
||
| 523 | if (VerificadorUtil.naoEstaNuloOuVazio(getLancamento().getOpcaoRestaurante())) { |
||
| 524 | observacoes = observacoes + getLancamento().getOpcaoRestaurante(); |
||
| 525 | } |
||
| 526 | if (VerificadorUtil.naoEstaNuloOuVazio(getLancamento().getObservacaoRestaurante())) { |
||
| 527 | observacoes = observacoes + " (" + getLancamento().getObservacaoRestaurante() + ")"; |
||
| 528 | } |
||
| 529 | getLancamento().setObservacao(observacoes); |
||
| 530 | getParametrosVenda().getLancamentos().add((Lancamento)getLancamento().clone()); |
||
| 531 | } catch (CloneNotSupportedException e) { |
||
| 532 | e.printStackTrace(); |
||
| 533 | } |
||
| 534 | } |
||
| 535 | limparLancamento(); |
||
| 536 | LancadorMensagem.lancarSucesso("PRODUTO ADICIONADO COM SUCESSO"); |
||
| 537 | } |
||
| 538 | }); |
||
| 539 | } |
||
| 540 | |||
| 541 | /* |
||
| 542 | * MÉTODO DA FARMÁCIA |
||
| 543 | *//* |
||
| 544 | protected void atualizarValorVendaSeForLojaFarmaciaEProdutoSemValorVenda(Lancamento lancamento) { |
||
| 545 | if (getParametrosVenda().getLoja().getSequencial().equals(ConstantesSEC.SEQUENCIAL_LOJA_FARMACIA_7)) { |
||
| 546 | if (lancamento.getProduto().tipoProdutoEhRemedioOuOutros()) { |
||
| 547 | Produto produto = produtoService.consultarProdutoPorCodigo(lancamento.getProduto().getCodigo()); |
||
| 548 | if (VerificadorUtil.estaNuloOuVazio(produto.getValorVarejo())) { |
||
| 549 | produto.setValorVarejo(lancamento.getValorVenda()); |
||
| 550 | produtoService.alterar(produto); |
||
| 551 | } |
||
| 552 | } |
||
| 553 | } |
||
| 554 | }*/ |
||
| 555 | |||
| 556 | public void removerLancamento(final Lancamento lancamento) { |
||
| 557 | new VerificadorLancamentoException().tratarIhRelancarExcecaoSemLimparEntidade(new CommandBean() { |
||
| 558 | public void execute() { |
||
| 559 | getParametrosVenda().getLancamentos().remove(lancamento); |
||
| 560 | LancadorMensagem.lancarSucesso("PRODUTO REMOVIDO COM SUCESSO"); |
||
| 561 | } |
||
| 562 | }); |
||
| 563 | } |
||
| 564 | |||
| 565 | public void limparLancamento() { |
||
| 566 | setLancamento(new Lancamento()); |
||
| 567 | setCodigoProduto(""); |
||
| 568 | } |
||
| 569 | |||
| 570 | public void limparPagamento() { |
||
| 571 | setBandeiraCartao(null); |
||
| 572 | setValorPagamento(null); |
||
| 573 | } |
||
| 574 | |||
| 575 | public void prepararPagamento() { |
||
| 576 | limparPagamento(); |
||
| 577 | Double subtotal = getParametrosVenda().valorTotalLancamentos() /*+ getParametrosVenda().getValorFrete() */ - getParametrosVenda().valorTotalPago(); |
||
| 578 | if (subtotal > 0) { |
||
| 579 | setValorPagamento(subtotal); |
||
| 580 | } |
||
| 581 | } |
||
| 582 | |||
| 583 | public void prepararPagamentoComCupom() { |
||
| 584 | prepararPagamento(); |
||
| 585 | setCupomSelecionado(new Cupom()); |
||
| 586 | } |
||
| 587 | |||
| 588 | public void adicionarPagamentoEmDinheiro() { |
||
| 589 | new VerificadorLancamentoException().tratarIhRelancarExcecaoSemLimparEntidade(new CommandBean() { |
||
| 590 | public void execute() { |
||
| 591 | adicionarPagamento(new FormaPagamento(ConstantesSEC.FormasDePagamento.FORMAPAGAMENTO_DINHEIRO)); |
||
| 592 | } |
||
| 593 | }); |
||
| 594 | } |
||
| 595 | |||
| 596 | public void adicionarPagamentoEmPix() { |
||
| 597 | new VerificadorLancamentoException().tratarIhRelancarExcecaoSemLimparEntidade(new CommandBean() { |
||
| 598 | public void execute() { |
||
| 599 | adicionarPagamento(new FormaPagamento(ConstantesSEC.FormasDePagamento.FORMAPAGAMENTO_PIX)); |
||
| 600 | } |
||
| 601 | }); |
||
| 602 | } |
||
| 603 | |||
| 344 | espaco | 604 | public void adicionarPagamentoEmTransferencia() { |
| 605 | new VerificadorLancamentoException().tratarIhRelancarExcecaoSemLimparEntidade(new CommandBean() { |
||
| 606 | public void execute() { |
||
| 607 | adicionarPagamento(new FormaPagamento(ConstantesSEC.FormasDePagamento.FORMAPAGAMENTO_TRANSFERENCIA)); |
||
| 608 | } |
||
| 609 | }); |
||
| 610 | } |
||
| 611 | |||
| 106 | espaco | 612 | public void adicionarPagamentoComOutros() { |
| 613 | new VerificadorLancamentoException().tratarIhRelancarExcecaoSemLimparEntidade(new CommandBean() { |
||
| 614 | public void execute() { |
||
| 615 | adicionarPagamento(new FormaPagamento(ConstantesSEC.FormasDePagamento.FORMAPAGAMENTO_OUTROS)); |
||
| 616 | } |
||
| 617 | }); |
||
| 618 | } |
||
| 619 | |||
| 620 | private void adicionarPagamento(FormaPagamento formaPagamento) { |
||
| 621 | VendaFormaPagamento vendaFormaPagamento = new VendaFormaPagamento(getEntidade(), formaPagamentoService.consultarPorId(formaPagamento)); |
||
| 622 | vendaFormaPagamento.setValorPagamento(getValorPagamento()); |
||
| 623 | adicionarPagamento(vendaFormaPagamento); |
||
| 624 | } |
||
| 625 | |||
| 626 | public void adicionarPagamentoEmDebito() { |
||
| 627 | new VerificadorLancamentoException().tratarIhRelancarExcecaoSemLimparEntidade(new CommandBean() { |
||
| 628 | public void execute() { |
||
| 629 | FormaPagamento formaPagamento = formaPagamentoService.consultarPorId(new FormaPagamento(ConstantesSEC.FormasDePagamento.FORMAPAGAMENTO_DEBITO)); |
||
| 630 | VendaFormaPagamento vendaFormaPagamento = new VendaFormaPagamento(getEntidade(), formaPagamento, getBandeiraCartao()); |
||
| 631 | vendaFormaPagamento.setValorPagamento(getValorPagamento()); |
||
| 632 | verificarPagamentoNoCartao(formaPagamento); |
||
| 633 | adicionarPagamento(vendaFormaPagamento); |
||
| 634 | } |
||
| 635 | }); |
||
| 636 | } |
||
| 637 | |||
| 638 | public void adicionarPagamentoEmCredito() { |
||
| 639 | new VerificadorLancamentoException().tratarIhRelancarExcecaoSemLimparEntidade(new CommandBean() { |
||
| 640 | public void execute() { |
||
| 641 | VendaFormaPagamento vendaFormaPagamento = new VendaFormaPagamento(getEntidade(), getFormaPagamento(), getBandeiraCartao()); |
||
| 642 | vendaFormaPagamento.setValorPagamento(getValorPagamento()); |
||
| 643 | verificarPagamentoNoCartao(getFormaPagamento()); |
||
| 644 | adicionarPagamento(vendaFormaPagamento); |
||
| 645 | } |
||
| 646 | }); |
||
| 647 | } |
||
| 648 | |||
| 649 | public void adicionarPagamentoComCupom() { |
||
| 650 | new VerificadorLancamentoException().tratarIhRelancarExcecaoSemLimparEntidade(new CommandBean() { |
||
| 651 | public void execute() { |
||
| 652 | FormaPagamento formaPagamento = formaPagamentoService.consultarPorId(new FormaPagamento(ConstantesSEC.FormasDePagamento.FORMAPAGAMENTO_CUPOM)); |
||
| 653 | VendaFormaPagamento vendaFormaPagamento = new VendaFormaPagamento(getEntidade(), formaPagamento); |
||
| 654 | vendaFormaPagamento.setValorPagamento(getValorPagamento()); |
||
| 655 | vendaFormaPagamento.setCupom(getCupomSelecionado()); |
||
| 656 | adicionarPagamento(vendaFormaPagamento); |
||
| 657 | } |
||
| 658 | }); |
||
| 659 | } |
||
| 660 | |||
| 661 | public void adicionarPagamento(final VendaFormaPagamento vendaFormaPagamento) { |
||
| 662 | new VerificadorLancamentoException().tratarIhRelancarExcecaoSemLimparEntidade(new CommandBean() { |
||
| 663 | public void execute() { |
||
| 664 | verificarPagamento(vendaFormaPagamento); |
||
| 280 | espaco | 665 | // seParcelaAcima12xAlterarMaquineta(getFormaPagamento()); |
| 106 | espaco | 666 | getParametrosVenda().getLancamentosPagamentos().add(vendaFormaPagamento); |
| 667 | setFormaPagamento(null); |
||
| 668 | setValorPagamento(null); |
||
| 669 | setCupomSelecionado(null); |
||
| 670 | LancadorMensagem.lancarSucesso("PAGAMENTO ADICIONADO COM SUCESSO"); |
||
| 671 | } |
||
| 672 | |||
| 673 | private void verificarPagamento(VendaFormaPagamento vendaFormaPagamento) { |
||
| 674 | if (VerificadorUtil.estaNulo(getValorPagamento())) { |
||
| 675 | throw new NegocioException("VALOR DE PAGAMENTO INCORRETO"); |
||
| 676 | } |
||
| 677 | if (getValorPagamento().equals(new Double(0))) { |
||
| 678 | throw new NegocioException("VALOR DE PAGAMENTO INCORRETO"); |
||
| 679 | } |
||
| 680 | /* |
||
| 681 | for (VendaFormaPagamento pagamento : getParametrosVenda().getLancamentosPagamentos()) { |
||
| 682 | if (pagamento.getCodigoDaFormaPagamento().equals(vendaFormaPagamento.getCodigoDaFormaPagamento())) { |
||
| 683 | throw new NegocioException("FORMA DE PAGAMENTO JÁ EXISTE"); |
||
| 684 | } |
||
| 685 | } |
||
| 686 | */ |
||
| 687 | } |
||
| 277 | espaco | 688 | |
| 689 | private void seParcelaAcima12xAlterarMaquineta(FormaPagamento formaPagamento) { |
||
| 690 | if (formaPagamento.formaPagamentoEhCreditoAcima12x()) { |
||
| 691 | getParametrosVenda().setMaquineta(null); |
||
| 692 | } |
||
| 693 | } |
||
| 106 | espaco | 694 | }); |
| 695 | } |
||
| 696 | |||
| 697 | protected void verificarPagamentoNoCartao(FormaPagamento formaPagamento) { |
||
| 698 | if (VerificadorUtil.estaNulo(getBandeiraCartao())) { |
||
| 699 | throw new RuntimeException("É OBRIGATÓRIO INFORMAR A BANDEIRA"); |
||
| 700 | } |
||
| 701 | if (VerificadorUtil.estaNulo(formaPagamento)) { |
||
| 702 | throw new RuntimeException("É OBRIGATÓRIO INFORMAR A BANDEIRA"); |
||
| 703 | } |
||
| 704 | } |
||
| 705 | |||
| 706 | public void removerPagamento(final VendaFormaPagamento pagamento) { |
||
| 707 | new VerificadorLancamentoException().tratarIhRelancarExcecaoSemLimparEntidade(new CommandBean() { |
||
| 708 | public void execute() { |
||
| 709 | getParametrosVenda().getLancamentosPagamentos().remove(pagamento); |
||
| 710 | LancadorMensagem.lancarSucesso("PRODUTO REMOVIDO COM SUCESSO"); |
||
| 711 | } |
||
| 712 | }); |
||
| 713 | } |
||
| 714 | |||
| 715 | public void selecionarCliente(final Cliente cliente) { |
||
| 716 | new VerificadorLancamentoException().tratarIhRelancarExcecaoSemLimparEntidade(new CommandBean() { |
||
| 717 | public void execute() { |
||
| 718 | cliente.setAtivo(true); |
||
| 719 | clienteService.alterar(cliente); |
||
| 720 | getParametrosVenda().setCliente(clienteService.consultarClientePorCpfCnpj(cliente.getCpfCnpj())); |
||
| 721 | setCpfCnpjCliente(null); |
||
| 722 | adicionandoParametroArgsConfirmandoAcao(true); |
||
| 723 | } |
||
| 724 | }); |
||
| 725 | } |
||
| 726 | |||
| 727 | public void retirarCliente() { |
||
| 728 | getParametrosVenda().setCliente(null); |
||
| 729 | } |
||
| 730 | |||
| 731 | public List<Vendedor> consultarVendedoresColaboradores() { |
||
| 732 | return vendedorService.consultarVendedoresColaboradores(); |
||
| 733 | } |
||
| 734 | |||
| 735 | public List<Vendedor> consultarVendedoresColaboradoresAtivos() { |
||
| 736 | return vendedorService.consultarVendedoresColaboradoresAtivos(null); |
||
| 737 | } |
||
| 738 | |||
| 739 | public List<Vendedor> consultarVendedoresExternos() { |
||
| 740 | return vendedorService.consultarVendedoresExternosAtivos(); |
||
| 741 | } |
||
| 742 | |||
| 743 | public void iniciarNovaVenda() { |
||
| 744 | Loja lojaSelecionada = getParametrosVenda().getLoja(); |
||
| 745 | setParametrosVenda(new ParametrosVendaDTO()); |
||
| 746 | getParametrosVenda().setLoja(lojaSelecionada); |
||
| 747 | getParametrosVenda().setMaquineta(lojaSelecionada.getMaquineta()); |
||
| 748 | getParametrosVenda().setUsuario(contextoSeguranca.obterUsuario()); |
||
| 749 | } |
||
| 750 | |||
| 751 | public void iniciarVenda() { |
||
| 752 | new VerificadorLancamentoException().tratarIhRelancarExcecaoSemLimparEntidade(new CommandBean() { |
||
| 753 | public void execute() { |
||
| 754 | LancadorMensagem.lancarSucessoRedirecionandoTela("VENDA REALIZADA COM SUCESSO!", "/sistema/pdv.xhtml?sequencialLoja=" + getParametrosVenda().getLoja().getSequencial()); |
||
| 755 | } |
||
| 756 | }); |
||
| 757 | } |
||
| 758 | |||
| 759 | public void cadastrarVendaSemCupom() { |
||
| 760 | new VerificadorLancamentoException().tratarIhRelancarExcecaoSemLimparEntidade(new CommandBean() { |
||
| 761 | public void execute() { |
||
| 305 | espaco | 762 | Venda vendaCadastrada = vendaService.cadastrarVendaPeloPDV(getParametrosVenda()); |
| 763 | Long sequencialNovoPedido = pedidoService.cadastrarPedidoVendaPersonalizada(vendaCadastrada, getParametrosVenda()); |
||
| 764 | if (VerificadorUtil.naoEstaNulo(sequencialNovoPedido)) { |
||
| 765 | LancadorMensagem.lancarSucesso("Nº PERSONALIZAÇÃO: " + sequencialNovoPedido); |
||
| 766 | } |
||
| 106 | espaco | 767 | iniciarNovaVenda(); |
| 311 | espaco | 768 | LancadorMensagem.lancarSucesso("VENDA REALIZADA COM SUCESSO"); |
| 106 | espaco | 769 | } |
| 770 | }); |
||
| 771 | } |
||
| 772 | |||
| 773 | public void cadastrarVendaComCupom() { |
||
| 774 | new VerificadorLancamentoException().tratarIhRelancarExcecaoSemLimparEntidade(new CommandBean() { |
||
| 775 | public void execute() { |
||
| 776 | setVendaSelecionada(vendaService.cadastrarVendaPeloPDV(getParametrosVenda())); |
||
| 305 | espaco | 777 | Long sequencialNovoPedido = pedidoService.cadastrarPedidoVendaPersonalizada(getVendaSelecionada(), getParametrosVenda()); |
| 778 | if (VerificadorUtil.naoEstaNulo(sequencialNovoPedido)) { |
||
| 779 | LancadorMensagem.lancarSucesso("Nº PERSONALIZAÇÃO: " + sequencialNovoPedido); |
||
| 780 | } |
||
| 106 | espaco | 781 | preCarregamento(); |
| 782 | getParametrosVenda().setLoja(getVendaSelecionada().getLoja()); |
||
| 280 | espaco | 783 | getParametrosVenda().setMaquineta(getVendaSelecionada().getLoja().getMaquineta()); |
| 106 | espaco | 784 | setEmitirCupom(true); |
| 311 | espaco | 785 | LancadorMensagem.lancarSucesso("VENDA REALIZADA COM SUCESSO"); |
| 106 | espaco | 786 | } |
| 787 | }); |
||
| 788 | } |
||
| 789 | |||
| 790 | public void cadastrarVendaFarma() { |
||
| 791 | new VerificadorLancamentoException().tratarIhRelancarExcecaoSemLimparEntidade(new CommandBean() { |
||
| 792 | public void execute() { |
||
| 793 | vendaService.cadastrarVendaPeloPDV(getParametrosVenda()); |
||
| 794 | LancadorMensagem.lancarSucessoRedirecionandoTela("VENDA REALIZADA COM SUCESSO!", "/sistema/pdv.xhtml?sequencialLoja=" + getParametrosVenda().getLoja().getSequencial()); |
||
| 795 | } |
||
| 796 | }); |
||
| 797 | } |
||
| 798 | |||
| 799 | public void cadastrarVendaRestaurante() { |
||
| 800 | new VerificadorLancamentoException().tratarIhRelancarExcecaoSemLimparEntidade(new CommandBean() { |
||
| 801 | public void execute() { |
||
| 802 | setVendaSelecionada(vendaService.cadastrarVendaPeloPDV(getParametrosVenda())); |
||
| 803 | preCarregamento(); |
||
| 804 | getParametrosVenda().setLoja(getVendaSelecionada().getLoja()); |
||
| 280 | espaco | 805 | getParametrosVenda().setMaquineta(getVendaSelecionada().getLoja().getMaquineta()); |
| 106 | espaco | 806 | getVendaSelecionada().setEmitirComanda(true); |
| 807 | setEmitirCupom(true); |
||
| 808 | LancadorMensagem.lancarSucesso("VENDA REALIZADA COM SUCESSO"); |
||
| 809 | } |
||
| 810 | }); |
||
| 811 | } |
||
| 812 | |||
| 813 | public void alterarVenda(final Boolean verificarJustificativa) { |
||
| 814 | new VerificadorLancamentoException().tratarIhRelancarExcecaoSemLimparEntidade(new CommandBean() { |
||
| 815 | public void execute() { |
||
| 816 | if (verificarJustificativa) { |
||
| 817 | if (VerificadorUtil.estaNuloOuVazio(getParametrosVenda().getVenda().getJustificativaParaExcluir())) { |
||
| 818 | throw new NegocioException("JUSTIFICATIVA OBRIGATÓRIA"); |
||
| 819 | } |
||
| 820 | } |
||
| 821 | vendaService.alterarVenda(getParametrosVenda(), contextoSeguranca.obterUsuario(), verificarJustificativa); |
||
| 822 | adicionandoParametroArgsConfirmandoAcao(true); |
||
| 823 | LancadorMensagem.lancarSucesso("VENDA ALTERADA COM SUCESSO"); |
||
| 824 | } |
||
| 825 | }); |
||
| 826 | } |
||
| 827 | |||
| 828 | public void excluirVendaSelecionada() { |
||
| 829 | new VerificadorLancamentoException().tratarIhRelancarExcecaoSemLimparEntidade(new CommandBean() { |
||
| 830 | public void execute() { |
||
| 831 | if (VerificadorUtil.estaNuloOuVazio(getVendaSelecionada().getJustificativaParaExcluir())) { |
||
| 832 | throw new RuntimeException("É OBRIGATÓRIO JUSTIFICAR"); |
||
| 833 | } |
||
| 834 | vendaService.excluirVenda(getVendaSelecionada(), contextoSeguranca.obterUsuario()); |
||
| 835 | adicionandoParametroArgsConfirmandoAcao(true); |
||
| 836 | LancadorMensagem.lancarSucesso("VENDA EXCLUÍDA COM SUCESSO"); |
||
| 837 | } |
||
| 838 | }); |
||
| 839 | } |
||
| 840 | |||
| 841 | public void excluirVenda(final Venda venda) { |
||
| 842 | new VerificadorLancamentoException().tratarIhRelancarExcecaoSemLimparEntidade(new CommandBean() { |
||
| 843 | public void execute() { |
||
| 844 | vendaService.excluirVenda(venda, contextoSeguranca.obterUsuario()); |
||
| 845 | adicionandoParametroArgsConfirmandoAcao(true); |
||
| 846 | LancadorMensagem.lancarSucesso("VENDA EXCLUÍDA COM SUCESSO"); |
||
| 847 | } |
||
| 848 | }); |
||
| 849 | } |
||
| 850 | |||
| 851 | public String verificarFinanceiro(Venda venda) { |
||
| 852 | Conta contaAReceber = new Conta(); |
||
| 853 | contaAReceber.setVenda(venda); |
||
| 854 | contaAReceber.setIndicadorAtivo(true); |
||
| 855 | if (contaAReceberService.obterQuantidadeDeRegistrosPassandoEntidade(contaAReceber) == 0) { |
||
| 856 | return "NENHUMA"; |
||
| 857 | } |
||
| 858 | return parcelaService.verificarPossuiParcelaAberta(venda) ? "PENDENTE" : "QUITADO"; |
||
| 859 | } |
||
| 860 | |||
| 861 | public void prepararEnvioCupomEmail() { |
||
| 862 | setEmailParaEnvio(getVendaSelecionada().getEmailDoCliente()); |
||
| 863 | } |
||
| 864 | |||
| 865 | public void enviarCupomPorEmail() { |
||
| 866 | new VerificadorLancamentoException().tratarIhRelancarExcecaoSemLimparEntidade(new CommandBean() { |
||
| 867 | public void execute() { |
||
| 868 | lancarExcecaoCasoEmailNaoInformado(); |
||
| 869 | try { |
||
| 870 | JasperPrint relatorio = notaFiscalService.retornarRelatorio(getVendaSelecionada()); |
||
| 871 | byte[] arquivo = JasperExportManager.exportReportToPdf(relatorio); |
||
| 872 | new GerenciadorEmailImpl() |
||
| 873 | .comEmailsDestino(getEmailParaEnvio()) |
||
| 874 | .comAssunto("CUPOM EMITIDO POR ESPAÇO CASE") |
||
| 875 | .comConteudoHtml("OBRIGADO PELA PREFERÊNCIA!") |
||
| 876 | .adicionarAnexo("CUPOM.pdf", arquivo, "pdf") |
||
| 877 | .enviar(); |
||
| 878 | LancadorMensagem.lancarSucesso("Cupom enviado por email."); |
||
| 879 | } catch (Exception e) { |
||
| 880 | e.printStackTrace(); |
||
| 881 | } |
||
| 882 | } |
||
| 883 | |||
| 884 | private void lancarExcecaoCasoEmailNaoInformado() { |
||
| 885 | if (VerificadorUtil.estaNuloOuVazio(getEmailParaEnvio())) { |
||
| 886 | throw new NegocioException("Obrigatório informar o email de destino"); |
||
| 887 | } |
||
| 888 | } |
||
| 889 | }); |
||
| 890 | } |
||
| 891 | |||
| 892 | /*************************************************/ |
||
| 893 | |||
| 894 | public void informarEtico() { |
||
| 895 | new VerificadorLancamentoException().tratarIhRelancarExcecaoSemLimparEntidade(new CommandBean() { |
||
| 896 | public void execute() { |
||
| 897 | alterarCategoria(new Long(343), "ÉTICO"); |
||
| 898 | } |
||
| 899 | }); |
||
| 900 | } |
||
| 901 | |||
| 902 | public void informarGenerico() { |
||
| 903 | new VerificadorLancamentoException().tratarIhRelancarExcecaoSemLimparEntidade(new CommandBean() { |
||
| 904 | public void execute() { |
||
| 905 | alterarCategoria(new Long(340), "GENÉRICO"); |
||
| 906 | } |
||
| 907 | }); |
||
| 908 | } |
||
| 909 | |||
| 910 | public void informarSimilar() { |
||
| 911 | new VerificadorLancamentoException().tratarIhRelancarExcecaoSemLimparEntidade(new CommandBean() { |
||
| 912 | public void execute() { |
||
| 913 | alterarCategoria(new Long(338), "SIMILAR"); |
||
| 914 | } |
||
| 915 | }); |
||
| 916 | } |
||
| 917 | |||
| 918 | public void informarOutros() { |
||
| 919 | new VerificadorLancamentoException().tratarIhRelancarExcecaoSemLimparEntidade(new CommandBean() { |
||
| 920 | public void execute() { |
||
| 921 | alterarCategoria(new Long(339), "OUTROS"); |
||
| 922 | } |
||
| 923 | }); |
||
| 924 | } |
||
| 925 | |||
| 926 | public void alterarCategoria(final Long sequencialModelo, final String modelo) { |
||
| 927 | Modelo modeloNovo = new Modelo(); |
||
| 928 | modeloNovo.setSequencial(sequencialModelo); |
||
| 929 | modeloService.consultarPorId(modeloNovo); |
||
| 930 | getLancamento().getProduto().setModelo(modeloNovo); |
||
| 931 | produtoService.alterar(getLancamento().getProduto()); |
||
| 932 | setCodigoProduto(""); |
||
| 933 | LancadorMensagem.lancarSucesso("CATEGORIA ALTERADA PARA " + modelo); |
||
| 934 | } |
||
| 935 | |||
| 936 | public void informarLocalizacao() { |
||
| 937 | new VerificadorLancamentoException().tratarIhRelancarExcecaoSemLimparEntidade(new CommandBean() { |
||
| 938 | public void execute() { |
||
| 939 | produtoLojaService.alterarLocalizacao(getLocalizacaoNova(), getLancamento().getProduto(), getParametrosVenda().getLoja()); |
||
| 940 | LancadorMensagem.lancarSucesso("LOCALIZAÇÃO ALTERADA PARA " + getLocalizacaoNova()); |
||
| 941 | setCodigoProduto(""); |
||
| 942 | setLocalizacaoNova(""); |
||
| 943 | } |
||
| 944 | }); |
||
| 945 | } |
||
| 946 | |||
| 947 | public void prepararAdicionarCupom(Lancamento lancamento) { |
||
| 948 | setLancamentoSelecionado(lancamento); |
||
| 949 | setCupomSelecionado(new Cupom()); |
||
| 950 | } |
||
| 951 | |||
| 952 | public void consultarCupom(final String tipoCupom) { |
||
| 953 | new VerificadorLancamentoException().tratarIhRelancarExcecaoSemLimparEntidade(new CommandBean() { |
||
| 954 | public void execute() { |
||
| 955 | setCupomSelecionado(cupomService.consultarCupomPorCodigo(getCupomSelecionado().getCodigo())); |
||
| 956 | verificarCupomValido(); |
||
| 957 | verificarInclusaoDoCupom(getCupomSelecionado(), tipoCupom); |
||
| 958 | getCupomSelecionado().setLancamento(getLancamentoSelecionado()); |
||
| 959 | |||
| 960 | if (VerificadorUtil.naoEstaNulo(getCupomSelecionado().getValor())) { |
||
| 961 | setValorPagamento(getCupomSelecionado().getValor()); |
||
| 962 | } else if (VerificadorUtil.naoEstaNulo(getCupomSelecionado().getPercentual())) { |
||
| 963 | setValorPagamento(getCupomSelecionado().getLancamento().getValorVenda() * getCupomSelecionado().getPercentual() / 100); |
||
| 964 | } |
||
| 965 | } |
||
| 966 | |||
| 967 | private void verificarCupomValido() { |
||
| 968 | if (VerificadorUtil.estaNulo(getCupomSelecionado())) { |
||
| 969 | setCupomSelecionado(new Cupom()); |
||
| 970 | throw new NegocioException("CUPOM NÃO LOCALIZADO"); |
||
| 971 | } else { |
||
| 972 | if (!getCupomSelecionado().valido() || !getCupomSelecionado().getAtivo()) { |
||
| 973 | setCupomSelecionado(new Cupom()); |
||
| 974 | throw new NegocioException("CUPOM INVÁLIDO"); |
||
| 975 | } |
||
| 976 | if (getCupomSelecionado().getLimiteUtilizacao()) { |
||
| 977 | Integer vendasComCupom = lancamentoService.obterQuantidadeVendasComCupom(getCupomSelecionado()); |
||
| 978 | vendasComCupom += vendaFormaPagamentoService.obterQuantidadePagamentosComCupom(getCupomSelecionado()); |
||
| 979 | if (vendasComCupom > 0) { |
||
| 980 | setCupomSelecionado(new Cupom()); |
||
| 981 | throw new NegocioException("CUPOM JÁ UTILIZADO ANTERIORMENTE"); |
||
| 982 | } |
||
| 983 | } |
||
| 984 | } |
||
| 985 | } |
||
| 986 | |||
| 987 | private void verificarInclusaoDoCupom(Cupom cupom, String tipoCupom) { |
||
| 988 | if (TipoCupom.PROMOCIONAL.getValor().equals(tipoCupom)) { |
||
| 989 | if (!cupom.getTipoCupom().equals(TipoCupom.PROMOCIONAL.getValor())) { |
||
| 990 | setCupomSelecionado(new Cupom()); |
||
| 991 | throw new NegocioException("PERMITIDO APENAS PARA CUPONS PROMOCIONAIS"); |
||
| 992 | } |
||
| 993 | if (getLancamentoSelecionado().getProduto().getProdutoEmPromocao()) { |
||
| 994 | setCupomSelecionado(new Cupom()); |
||
| 995 | throw new NegocioException("AÇÃO NÃO PERMITIDA: PRODUTO JÁ EM PROMOÇÃO"); |
||
| 996 | } |
||
| 997 | } else if (TipoCupom.REEMBOLSO.getValor().equals(tipoCupom)) { |
||
| 998 | if (!cupom.getTipoCupom().equals(TipoCupom.REEMBOLSO.getValor())) { |
||
| 999 | setCupomSelecionado(new Cupom()); |
||
| 1000 | throw new NegocioException("PERMITIDO APENAS PARA CUPONS DE REEMBOLSO"); |
||
| 1001 | } |
||
| 1002 | } |
||
| 1003 | } |
||
| 1004 | }); |
||
| 1005 | } |
||
| 1006 | |||
| 1007 | public void adicionarCupom() { |
||
| 1008 | new VerificadorLancamentoException().tratarIhRelancarExcecaoSemLimparEntidade(new CommandBean() { |
||
| 1009 | public void execute() { |
||
| 1010 | verificarSeValorMaiorDesconto(getValorPagamento()); |
||
| 1011 | verificarSeCupomJaFoiAdicionado(getCupomSelecionado(), getParametrosVenda().getLancamentos()); |
||
| 1012 | for (Lancamento lancamento : getParametrosVenda().getLancamentos()) { |
||
| 1013 | if (lancamento.equals(getCupomSelecionado().getLancamento())) { |
||
| 1014 | lancamento.setCupom(getCupomSelecionado()); |
||
| 1015 | lancamento.setValorVarejo(lancamento.getValorVarejo() - getValorPagamento()); |
||
| 1016 | lancamento.setValorVenda(lancamento.getValorVenda() - getValorPagamento()); |
||
| 1017 | break; |
||
| 1018 | } |
||
| 1019 | } |
||
| 1020 | LancadorMensagem.lancarSucesso("CUPOM ADICIONADO COM SUCESSO"); |
||
| 1021 | } |
||
| 1022 | |||
| 1023 | private void verificarSeCupomJaFoiAdicionado(Cupom cupomSelecionado, List<Lancamento> lancamentos) { |
||
| 1024 | if (cupomSelecionado.getLimiteUtilizacao()) { |
||
| 1025 | for (Lancamento lancamento : getParametrosVenda().getLancamentos()) { |
||
| 1026 | if (VerificadorUtil.naoEstaNulo(lancamento.getCupom())) { |
||
| 1027 | if (lancamento.getCupom().equals(cupomSelecionado)) { |
||
| 1028 | throw new RuntimeException("CUPOM JÁ FOI UTILIZADO"); |
||
| 1029 | } |
||
| 1030 | } |
||
| 1031 | } |
||
| 1032 | } |
||
| 1033 | } |
||
| 1034 | |||
| 1035 | private void verificarSeValorMaiorDesconto(Double valorPagamento) { |
||
| 1036 | if (VerificadorUtil.naoEstaNulo(getCupomSelecionado().getValor())) { |
||
| 1037 | if (valorPagamento > getCupomSelecionado().getValor()) { |
||
| 1038 | throw new RuntimeException("VALOR DO DESCONTO ACIMA DO PERMITIDO"); |
||
| 1039 | } |
||
| 1040 | } else if (VerificadorUtil.naoEstaNulo(getCupomSelecionado().getPercentual())) { |
||
| 1041 | if (valorPagamento > getCupomSelecionado().getLancamento().getValorVenda() * getCupomSelecionado().getPercentual() / 100) { |
||
| 1042 | throw new RuntimeException("VALOR DO DESCONTO ACIMA DO PERMITIDO"); |
||
| 1043 | } |
||
| 1044 | } |
||
| 1045 | } |
||
| 1046 | }); |
||
| 1047 | } |
||
| 1048 | |||
| 1049 | public void removerCupom(Lancamento lancamento) { |
||
| 1050 | for (Lancamento lancamentoVendas : getParametrosVenda().getLancamentos()) { |
||
| 1051 | if (lancamentoVendas.equals(lancamento)) { |
||
| 1052 | lancamentoVendas.setCupom(null); |
||
| 1053 | lancamentoVendas.setValorVarejo(lancamento.getValorVarejo() + getValorPagamento()); |
||
| 1054 | lancamentoVendas.setValorVenda(lancamento.getValorVenda() + getValorPagamento()); |
||
| 1055 | break; |
||
| 1056 | } |
||
| 1057 | } |
||
| 1058 | LancadorMensagem.lancarSucesso("CUPOM REMOVIDO COM SUCESSO"); |
||
| 1059 | } |
||
| 1060 | |||
| 1061 | public void vincularPedido() { |
||
| 1062 | new VerificadorLancamentoException().tratarIhRelancarExcecaoSemLimparEntidade(new CommandBean() { |
||
| 1063 | public void execute() { |
||
| 1064 | Pedido pedido = new Pedido(); |
||
| 1065 | pedido.setSequencial(new Long(getCodigoPedido())); |
||
| 1066 | getParametrosVenda().setPedidoVinculado(pedidoService.consultarPedidoCompleto(pedido)); |
||
| 1067 | if (VerificadorUtil.naoEstaNulo(getParametrosVenda().getPedidoVinculado())) { |
||
| 330 | espaco | 1068 | verificarSePedidoEhValido(getParametrosVenda().getPedidoVinculado()); |
| 106 | espaco | 1069 | getParametrosVenda().setObservacao("PEDIDO VINCULADO: " + getParametrosVenda().getPedidoVinculado().getSequencial() + ". " + getParametrosVenda().getObservacao()); |
| 1070 | Vendedor vendedorPedido = vendedorService.consultarVendedorPorPessoa(getParametrosVenda().getPedidoVinculado().getUsuarioPedido().getPessoa()); |
||
| 1071 | if (VerificadorUtil.naoEstaNulo(vendedorPedido)) { |
||
| 1072 | getParametrosVenda().setVendedor(vendedorPedido); |
||
| 1073 | } |
||
| 1074 | |||
| 1075 | for (PedidoProduto pedidoProduto : getParametrosVenda().getPedidoVinculado().getProdutos()) { |
||
| 1076 | Integer quantidadeProduto = 1; |
||
| 1077 | while (quantidadeProduto <= pedidoProduto.getQuantidade()) { |
||
| 1078 | Lancamento lancamento = new Lancamento(); |
||
| 1079 | lancamento.preencher(pedidoProduto.getProduto()); |
||
| 1080 | lancamento.setValorVenda(pedidoProduto.getValor()); |
||
| 1081 | lancamento.setObservacao(pedidoProduto.getObservacao()); |
||
| 1082 | getParametrosVenda().getLancamentos().add(lancamento); |
||
| 1083 | quantidadeProduto++; |
||
| 1084 | } |
||
| 1085 | } |
||
| 1086 | |||
| 1087 | if (VerificadorUtil.naoEstaNulo(getParametrosVenda().getPedidoVinculado().getCliente())) { |
||
| 1088 | getParametrosVenda().setCliente(getParametrosVenda().getPedidoVinculado().getCliente()); |
||
| 1089 | } |
||
| 1090 | setCodigoPedido(""); |
||
| 1091 | LancadorMensagem.lancarSucesso("PEDIDO " + getParametrosVenda().getPedidoVinculado().getSequencial() + " VINCULADO"); |
||
| 1092 | } else { |
||
| 1093 | LancadorMensagem.lancarErro("PEDIDO NÃO ENCONTRADO"); |
||
| 1094 | } |
||
| 1095 | } |
||
| 330 | espaco | 1096 | |
| 1097 | private void verificarSePedidoEhValido(Pedido pedidoVinculado) { |
||
| 1098 | if (getParametrosVenda().getPedidoVinculado().getTipoSituacao().equals(TipoSituacaoPedido.FINALIZADO.getValor()) || |
||
| 1099 | getParametrosVenda().getPedidoVinculado().getTipoSituacao().equals(TipoSituacaoPedido.FINALIZADO_COM_VENDAS.getValor())) { |
||
| 1100 | throw new NegocioException("VÍNCULO NÃO REALIZADO: PEDIDO JÁ FINALIZADO"); |
||
| 1101 | } |
||
| 1102 | if (getParametrosVenda().getPedidoVinculado().getTipoSituacao().equals(TipoSituacaoPedido.INVALIDO.getValor())) { |
||
| 1103 | throw new NegocioException("VÍNCULO NÃO REALIZADO: PEDIDO INVÁLIDO"); |
||
| 1104 | } |
||
| 1105 | } |
||
| 106 | espaco | 1106 | }); |
| 1107 | } |
||
| 1108 | |||
| 1109 | } |