Subversion Repositories Integrator Subversion

Rev

Rev 159 | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

package br.com.ec.controller.managedbean;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import javax.inject.Inject;
import javax.inject.Named;

import org.springframework.context.annotation.Scope;

import br.com.ec.core.generic.GenericService;
import br.com.ec.core.util.DataUtils;
import br.com.ec.core.util.VerificadorUtil;
import br.com.ec.domain.dto.LojaDTO;
import br.com.ec.domain.model.AberturaLoja;
import br.com.ec.domain.model.Loja;
import br.com.ec.domain.model.Pessoa;
import br.com.ec.domain.model.Venda;
import br.com.ec.domain.model.VendaVivo;
import br.com.ec.domain.model.tipos.TipoEmitirNotaFiscal;
import br.com.ec.domain.service.aberturaloja.AberturaLojaService;
import br.com.ec.domain.service.loja.LojaService;
import br.com.ec.domain.service.produto.ProdutoService;
import br.com.ec.domain.service.transferencia.TransferenciaService;
import br.com.ec.domain.service.venda.VendaService;
import br.com.ec.domain.service.vendavivo.VendaVivoService;
import br.com.ec.domain.shared.ConstantesSEC;
import br.com.ec.web.exception.VerificadorLancamentoException;
import br.com.ec.web.exception.VerificadorLancamentoException.CommandBean;
import br.com.ec.web.generic.AbstractBean;
import br.com.ec.web.message.LancadorMensagem;

@Named
@Scope("view")
public class LojaBean extends AbstractBean<Loja> implements Serializable {

        private static final long serialVersionUID = 1L;
       
        private LojaService lojaService;
        private VendaService vendaService;
        private VendaVivoService vendaVivoService;
        private ProdutoService produtoService;
        private AberturaLojaService aberturaLojaService;
        private TransferenciaService transferenciaService;
       
        private Loja lojaSelecionada;
        private String senhaUsuarioParaAbertura;
        private List<Loja> centrosDeCustos;
        private List<Loja> listaLojasAtivas;
        private List<Loja> listaLojasAtivasEspacoCase;
        private List<Loja> listaLojas;
        private List<Loja> listaLojasComDetalhes;
        private List<LojaDTO> listaLojasDTOAtivas;
       
        private Integer quantidadeNotificacoes;
        private Integer quantidadeNotificacoesContagem;
        private Integer quantidadeNotificacoesRetirarDoSite;
        private Integer quantidadeTransferenciasParaReceberAbertas;
       
        private Integer quantidadeVendas;
       
        private Boolean consultarComCasaDasCapas = false;
       
        @Inject
        public LojaBean(LojaService lojaService, VendaService vendaService, VendaVivoService vendaVivoService,
                        ProdutoService produtoService, AberturaLojaService aberturaLojaService, TransferenciaService transferenciaService) {
                this.lojaService = lojaService;
                this.vendaService = vendaService;
                this.vendaVivoService = vendaVivoService;
                this.produtoService = produtoService;
                this.aberturaLojaService = aberturaLojaService;
                this.transferenciaService = transferenciaService;
        }
       
        @Override
        public void limparEntidade() {
                setEntidade(new Loja());
        }

        @Override
        public GenericService<Loja> getService() {
                return lojaService;
        }
       
        @Override
        public Loja getEntidade() {
                return entidade;
        }

        @Override
        public Loja getId() {
                return getEntidade();
        }
       
        public Loja getLojaSelecionada() {
                if (VerificadorUtil.estaNulo(lojaSelecionada)) {
                        if (VerificadorUtil.naoEstaNulo(getParametro("sequencialLoja"))) {
                                Loja loja = new Loja();
                                loja.setSequencial(new Long(getParametro("sequencialLoja").toString()));
                                lojaSelecionada = lojaService.consultarPorId(loja);
                        }
                }
                return lojaSelecionada;
        }
        public void setLojaSelecionada(Loja lojaSelecionada) {
                this.lojaSelecionada = lojaSelecionada;
        }
       
        public String getSenhaUsuarioParaAbertura() {
                return senhaUsuarioParaAbertura;
        }
        public void setSenhaUsuarioParaAbertura(String senhaUsuarioParaAbertura) {
                this.senhaUsuarioParaAbertura = senhaUsuarioParaAbertura;
        }
       
        public List<Loja> getCentrosDeCustos() {
                if (VerificadorUtil.estaNuloOuVazio(centrosDeCustos)) {
                        List<Loja> lojasAtivas = new ArrayList<Loja>();
                        lojasAtivas.add(new Loja(new Long(-1), "SEM CENTRO DE CUSTOS"));
                        lojasAtivas.addAll(getListaLojasAtivas());
                        setCentrosDeCustos(lojasAtivas);
                }
                return centrosDeCustos;
        }
        public void setCentrosDeCustos(List<Loja> centrosDeCustos) {
                this.centrosDeCustos = centrosDeCustos;
        }
       
        public List<Loja> getListaLojasAtivas() {
                if (VerificadorUtil.estaNulo(listaLojasAtivas)) {
                        setListaLojasAtivas(lojaService.listarLojasAtivas());
                }
                return listaLojasAtivas;
        }
        public void setListaLojasAtivas(List<Loja> listaLojasAtivas) {
                this.listaLojasAtivas = listaLojasAtivas;
        }
       
        public List<Loja> getListaLojasAtivasEspacoCase() {
                if (VerificadorUtil.estaNulo(listaLojasAtivasEspacoCase)) {
                        setListaLojasAtivasEspacoCase(lojaService.listarLojasAtivasEspacoCase());
                }
                return listaLojasAtivasEspacoCase;
        }
        public void setListaLojasAtivasEspacoCase(List<Loja> listaLojasAtivasEspacoCase) {
                this.listaLojasAtivasEspacoCase = listaLojasAtivasEspacoCase;
        }
        public List<Loja> listaLojasAtivasEspacoCase(Boolean comCasaDasCapas) {
                Loja lojaCasaDasCapas = new Loja(ConstantesSEC.SEQUENCIAL_CASA_DAS_CAPAS_17);
                if (comCasaDasCapas) {
                        if (!getListaLojasAtivasEspacoCase().contains(lojaCasaDasCapas)) {
                                setListaLojasAtivasEspacoCase(lojaService.listarLojasAtivasEspacoCaseEeCasaDasCapas());
                        }
                } else {
                        getListaLojasAtivasEspacoCase().remove(lojaCasaDasCapas);
                }
                return getListaLojasAtivasEspacoCase();
        }
       
        public List<Loja> getListaLojas() {
                if (VerificadorUtil.estaNulo(listaLojas)) {
                        setListaLojas(lojaService.consultarTodos(new Loja()));
                }
                return listaLojas;
        }
        public void setListaLojas(List<Loja> listaLojas) {
                this.listaLojas = listaLojas;
        }
       
        public List<Loja> getListaLojasComDetalhes() {
                if (VerificadorUtil.estaNulo(listaLojasComDetalhes)) {
                        setListaLojasComDetalhes(lojaService.listarLojasComDetalhe());
                }
                return listaLojasComDetalhes;
        }
        public void setListaLojasComDetalhes(List<Loja> listaLojasComDetalhes) {
                this.listaLojasComDetalhes = listaLojasComDetalhes;
        }
       
        public List<LojaDTO> getListaLojasDTOAtivas() {
                if (VerificadorUtil.estaNulo(listaLojasDTOAtivas)) {
                        setListaLojasDTOAtivas(lojaService.listarLojasDTOAtivas());
                }
                return listaLojasDTOAtivas;
        }
        public void setListaLojasDTOAtivas(List<LojaDTO> listaLojasDTOAtivas) {
                this.listaLojasDTOAtivas = listaLojasDTOAtivas;
        }
       
        public Integer getQuantidadeNotificacoes() {
                if (VerificadorUtil.naoEstaNulo(getLojaSelecionada())) {
                        if (VerificadorUtil.estaNulo(quantidadeNotificacoes)) {
                                setQuantidadeNotificacoes(quantidadeNotificacoes());
                        }
                }
                return quantidadeNotificacoes;
        }
        public void setQuantidadeNotificacoes(Integer quantidadeNotificacoes) {
                this.quantidadeNotificacoes = quantidadeNotificacoes;
        }
       
        public Integer getQuantidadeNotificacoesContagem() {
                if (VerificadorUtil.naoEstaNulo(getLojaSelecionada())) {
                        if (VerificadorUtil.estaNulo(quantidadeNotificacoesContagem)) {
                                setQuantidadeNotificacoesContagem(quantidadeNotificacoesContagem(getLojaSelecionada()));
                        }
                }
                return quantidadeNotificacoesContagem;
        }
        public void setQuantidadeNotificacoesContagem(Integer quantidadeNotificacoesContagem) {
                this.quantidadeNotificacoesContagem = quantidadeNotificacoesContagem;
        }
       
        public Integer getQuantidadeNotificacoesRetirarDoSite() {
                if (VerificadorUtil.naoEstaNulo(getLojaSelecionada())) {
                        if (VerificadorUtil.estaNulo(quantidadeNotificacoesRetirarDoSite)) {
                                setQuantidadeNotificacoesRetirarDoSite(quantidadeNotificacoesRetirarDoSite(getLojaSelecionada()));
                        }
                }
                return quantidadeNotificacoesRetirarDoSite;
        }
        public void setQuantidadeNotificacoesRetirarDoSite(Integer quantidadeNotificacoesRetirarDoSite) {
                this.quantidadeNotificacoesRetirarDoSite = quantidadeNotificacoesRetirarDoSite;
        }
       
        public Integer getQuantidadeTransferenciasParaReceberAbertas() {
                if (VerificadorUtil.naoEstaNulo(getLojaSelecionada())) {
                        if (VerificadorUtil.estaNulo(quantidadeTransferenciasParaReceberAbertas)) {
                                setQuantidadeTransferenciasParaReceberAbertas(quantidadeTransferenciasAbertasParaReceber(getLojaSelecionada()));
                        }
                }
                return quantidadeTransferenciasParaReceberAbertas;
        }
        public void setQuantidadeTransferenciasParaReceberAbertas(Integer quantidadeTransferenciasParaReceberAbertas) {
                this.quantidadeTransferenciasParaReceberAbertas = quantidadeTransferenciasParaReceberAbertas;
        }
       
        /***************************************************************/
       
        public TipoEmitirNotaFiscal[] getTiposEmitirNotaFiscal() {
                return TipoEmitirNotaFiscal.values();
        }
       
        public boolean lojaEstaAberta(Loja loja) {
                return VerificadorUtil.naoEstaNulo(aberturaLojaService.consultarAberturaLoja(DataUtils.getDataAtual(), loja));
        }
       
        public AberturaLoja consultarAberturaLoja(Long sequencialLoja) {
                return aberturaLojaService.consultarAberturaLoja(DataUtils.getDataAtual(), new Loja(sequencialLoja));
        }
       
        public void abrirLoja() {
                new VerificadorLancamentoException().tratarIhRelancarExcecaoSemLimparEntidade(new CommandBean() {
                        public void execute() {
                                aberturaLojaService.abrirLoja(getSenhaUsuarioParaAbertura(), getLojaSelecionada());
                                LancadorMensagem.lancarSucessoRedirecionandoTela("ABERTURA DE LOJA REALIZADA COM SUCESSO!", "/sistema/loja.xhtml?sequencialLoja=" + getLojaSelecionada().getSequencial());
                        }
                });
        }
       
        public Integer getQuantidadeVendas() {
                return quantidadeVendas;
        }
        public void setQuantidadeVendas(Integer quantidadeVendas) {
                this.quantidadeVendas = quantidadeVendas;
        }
        public Integer quantidadeVendas(Loja loja) {
                if (VerificadorUtil.estaNulo(getQuantidadeVendas())) {
                        Venda venda = new Venda();
                        venda.setLoja(loja);
                        setQuantidadeVendas(vendaService.obterQuantidadeDeVendasPorLojaEePeriodo(venda, DataUtils.getDataAtual(), DataUtils.getDataAtual()));
                }
                return getQuantidadeVendas();
        }
       
        public Boolean getConsultarComCasaDasCapas() {
                return consultarComCasaDasCapas;
        }
        public void setConsultarComCasaDasCapas(Boolean consultarComCasaDasCapas) {
                this.consultarComCasaDasCapas = consultarComCasaDasCapas;
        }
       
        public Integer quantidadeVendasVivo(Loja loja) {
                VendaVivo venda = new VendaVivo();
                venda.setLoja(loja);
                return vendaVivoService.obterQuantidadeDeVendasPorLojaEePeriodo(venda, DataUtils.getDataAtual(), DataUtils.getDataAtual());
        }
       
        public Integer quantidadeNotificacoes(Loja loja) {
                Integer notificacoes = 0;
                if (VerificadorUtil.naoEstaNulo(loja)) {
                        if (quantidadeNotificacoesContagem(loja) > 0) {notificacoes++;}
                }
                return notificacoes;
        }
       
        public Integer quantidadeNotificacoes(Integer quantidadeNotificacoesContagem) {
                Integer notificacoes = 0;
                if (VerificadorUtil.naoEstaNulo(quantidadeNotificacoesContagem)) {
                        if (quantidadeNotificacoesContagem > 0) {notificacoes++;}
                }
                return notificacoes;
        }
       
        public Integer quantidadeNotificacoes() {
                Integer notificacoes = 0;
                if (VerificadorUtil.naoEstaNulo(getQuantidadeNotificacoesContagem())) {
                        if (getQuantidadeNotificacoesContagem() > 0) {notificacoes++;}
                }
                return notificacoes;
        }
       
        public Integer quantidadeNotificacoesContagem(Loja loja) {
                return produtoService.quantidadeParaContagem(loja);
        }
       
        public Integer quantidadeNotificacoesRetirarDoSite(Loja loja) {
                return produtoService.quantidadeProdutosParaRetirarDoOnline(loja);
        }
       
        public Integer quantidadeTransferenciasAbertasParaReceber(Loja loja) {
                return transferenciaService.obterQuantidadeDeTransferenciasParaReceberAbertas(loja, null, null);
        }
       
        public void selecionarPessoaJuridica(final Pessoa pessoa) {
                new VerificadorLancamentoException().tratarIhRelancarExcecaoSemLimparEntidade(new CommandBean() {
                        public void execute() {
                                getEntidade().setPessoaJuridica(pessoa);
                                adicionandoParametroArgsConfirmandoAcao(true);
                        }
                });
        }
       
        public void retirarPessoaJuridica() {
                getEntidade().setPessoaJuridica(null);
        }
       
        /***************************************************************/
       
        public Long getSequencialQuiosqueExtra() {
                return ConstantesSEC.SEQUENCIAL_QUIOSQUE_EXTRA_2;
        }
       
        public Long getSequencialLojaVivo() {
                return ConstantesSEC.SEQUENCIAL_LOJA_VIVO_4;
        }
       
        public Long getSequencialMatrizEstoque() {
                return ConstantesSEC.SEQUENCIAL_MATRIZ_ESTOQUE_9;
        }
       
        public Long getSequencialLojaFarmacia() {
                return ConstantesSEC.SEQUENCIAL_LOJA_FARMACIA_7;
        }
       
        public Long getSequencialRestaurante() {
                return ConstantesSEC.SEQUENCIAL_RESTAURANTE_16;
        }
       
        public Long getSequencialCasaDasCapas() {
                return ConstantesSEC.SEQUENCIAL_CASA_DAS_CAPAS_17;
        }
       
}