Subversion Repositories Integrator Subversion

Rev

Rev 106 | 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.controller.managedbean.consultademanda.VendaConsultaPorDemanda;
import br.com.ec.core.generic.GenericService;
import br.com.ec.core.util.VerificadorUtil;
import br.com.ec.domain.dto.ParametrosConsultaVendasDTO;
import br.com.ec.domain.dto.VendasDTO;
import br.com.ec.domain.model.BandeiraCartao;
import br.com.ec.domain.model.FormaPagamento;
import br.com.ec.domain.model.Lancamento;
import br.com.ec.domain.model.Loja;
import br.com.ec.domain.model.Venda;
import br.com.ec.domain.service.bandeiracartao.BandeiraCartaoService;
import br.com.ec.domain.service.formapagamento.FormaPagamentoService;
import br.com.ec.domain.service.lancamento.LancamentoService;
import br.com.ec.domain.service.loja.LojaService;
import br.com.ec.domain.service.venda.VendaService;
import br.com.ec.web.generic.AbstractBean;

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

        private static final long serialVersionUID = 1L;
       
        private ParametrosConsultaVendasDTO parametrosConsultaVendasDTO;
       
        private VendaConsultaPorDemanda lazy;
        private List<VendasDTO> vendas;
        private List<Lancamento> lancamentosComDesconto;
        private List<FormaPagamento> formasDePagamento;
        private List<BandeiraCartao> bandeirasDeCartao;
       
        private VendaService vendaService;
        private LancamentoService lancamentoService;
        private LojaService lojaService;
        private FormaPagamentoService formaPagamentoService;
        private BandeiraCartaoService bandeiraCartaoService;
       
        @Inject
        public VendasConsultaBean(VendaConsultaPorDemanda lazy, VendaService vendaService, LancamentoService lancamentoService, LojaService lojaService,
                        FormaPagamentoService formaPagamentoService, BandeiraCartaoService bandeiraCartaoService) {
                this.lazy = lazy;
                this.vendaService = vendaService;
                this.lancamentoService = lancamentoService;
                this.lojaService = lojaService;
                this.formaPagamentoService = formaPagamentoService;
                this.bandeiraCartaoService = bandeiraCartaoService;
        }
       
        @Override
        public void preCarregamento() {
                entidade = new Venda();
                parametrosConsultaVendasDTO = new ParametrosConsultaVendasDTO();
                parametrosConsultaVendasDTO.setEntidade(entidade);
               
                if (VerificadorUtil.naoEstaNulo(getParametro("sequencialLoja"))) {
                        Loja loja = new Loja();
                        loja.setSequencial(new Long(getParametro("sequencialLoja").toString()));
                        parametrosConsultaVendasDTO.setLoja(lojaService.consultarPorId(loja));
                }
               
                prepararConsultaDemanda();
                setVendas(new ArrayList<VendasDTO>());
//              setLancamentosComDesconto(lancamentoService.consultarLancamentosComDescontos(DataUtils.getDataAtual(), DataUtils.getDataAtual()));
        }
       
        @Override
        public void limparEntidade() {
                setEntidade(new Venda());
        }

        @Override
        public GenericService<Venda> getService() {
                return vendaService;
        }
       
        @Override
        public Venda getEntidade() {
                return entidade;
        }

        @Override
        public Venda getId() {
                return getEntidade();
        }
       
        public ParametrosConsultaVendasDTO getParametrosConsultaVendasDTO() {
                return parametrosConsultaVendasDTO;
        }
        public void setParametrosConsultaVendasDTO(ParametrosConsultaVendasDTO parametrosConsultaVendasDTO) {
                this.parametrosConsultaVendasDTO = parametrosConsultaVendasDTO;
        }
       
        public VendaConsultaPorDemanda getLazy() {
                return lazy;
        }
        public void setLazy(VendaConsultaPorDemanda lazy) {
                this.lazy = lazy;
        }
        public void prepararConsultaDemanda() {
                lazy.setarParametrosConsulta(getParametrosConsultaVendasDTO());
        }
       
        public List<Lancamento> getLancamentosComDesconto() {
                return lancamentosComDesconto;
        }
        public void setLancamentosComDesconto(List<Lancamento> lancamentosComDesconto) {
                this.lancamentosComDesconto = lancamentosComDesconto;
        }
       
        public List<FormaPagamento> getFormasDePagamento() {
                if (VerificadorUtil.estaNulo(formasDePagamento)) {
                        setFormasDePagamento(formaPagamentoService.listarFormasPagamentoAtivas());
                }
                return formasDePagamento;
        }
        public void setFormasDePagamento(List<FormaPagamento> formasDePagamento) {
                this.formasDePagamento = formasDePagamento;
        }
       
        public List<BandeiraCartao> getBandeirasDeCartao() {
                if (VerificadorUtil.estaNulo(bandeirasDeCartao)) {
                        List<BandeiraCartao> bandeiras = new ArrayList<BandeiraCartao>();
                        bandeiras.addAll(bandeiraCartaoService.consultarBandeiraCartoesDeDebito());
                        bandeiras.addAll(bandeiraCartaoService.consultarBandeiraCartoesDeCredito());
                        setBandeirasDeCartao(bandeiras);
                }
                return bandeirasDeCartao;
        }
        public void setBandeirasDeCartao(List<BandeiraCartao> bandeirasDeCartao) {
                this.bandeirasDeCartao = bandeirasDeCartao;
        }
       
        public Double getTotalVendas() {
                return vendaService.obterValorTotalBrutoDeVendasPorLojaEePeriodo(getParametrosConsultaVendasDTO());
        }
       
        public List<VendasDTO> getVendas() {
                return vendas;
        }
        public void setVendas(List<VendasDTO> vendas) {
                this.vendas = vendas;
        }
       
        /***************************************************************/
       
        public void consultarVendas() {
                setVendas(vendaService.consultarVendas(getParametrosConsultaVendasDTO()));
        }
       
}