package br.com.ec.controller;
import java.io.Serializable;
import javax.inject.Inject;
import javax.inject.Named;
import org.springframework.context.annotation.Scope;
import br.com.ec.controller.consultademanda.NotaFiscalConsultaPorDemanda;
import br.com.ec.core.generic.GenericService;
import br.com.ec.domain.dto.consulta.ParametrosConsultaNotaFiscal;
import br.com.ec.domain.model.NotaFiscal;
import br.com.ec.domain.model.Papel;
import br.com.ec.domain.model.nfe.TipoNotaFiscal;
import br.com.ec.domain.service.NotaFiscalService;
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;
import br.com.ec.web.util.TipoOperacao;
@Named
@Scope
("view")
public class NotaFiscalBean
extends AbstractBean
<NotaFiscal
> implements Serializable {
private static final long serialVersionUID = 1L
;
private NotaFiscalService notaFiscalService
;
private ParametrosConsultaNotaFiscal parametrosConsultaNotaFiscal
;
private NotaFiscalConsultaPorDemanda lazy
;
private Long sequencialVendaParaVinculo
;
@Inject
public NotaFiscalBean
(NotaFiscalConsultaPorDemanda lazy, NotaFiscalService notaFiscalService
) {
this.
lazy = lazy
;
this.
notaFiscalService = notaFiscalService
;
}
@
Override
public void preCarregamento
() {
parametrosConsultaNotaFiscal =
new ParametrosConsultaNotaFiscal
();
prepararConsultaDemanda
();
limparEntidade
();
}
@
Override
public void limparEntidade
() {
setEntidade
(new NotaFiscal
());
}
@
Override
public GenericService
<NotaFiscal
> getService
() {
return notaFiscalService
;
}
@
Override
public NotaFiscal getEntidade
() {
return entidade
;
}
@
Override
public void preConsultar
() {
setTipoOperacao
(TipoOperacao.
CONSULTAR);
}
@
Override
public NotaFiscal getId
() {
return getEntidade
();
}
public ParametrosConsultaNotaFiscal getParametrosConsultaNotaFiscal
() {
return parametrosConsultaNotaFiscal
;
}
public void setParametrosConsultaNotaFiscal
(ParametrosConsultaNotaFiscal parametrosConsultaNotaFiscal
) {
this.
parametrosConsultaNotaFiscal = parametrosConsultaNotaFiscal
;
}
public NotaFiscalConsultaPorDemanda getLazy
() {
return lazy
;
}
public void setLazy
(NotaFiscalConsultaPorDemanda lazy
) {
this.
lazy = lazy
;
}
public void prepararConsultaDemanda
() {
lazy.
setarParametrosConsulta(getParametrosConsultaNotaFiscal
());
}
public TipoNotaFiscal
[] getTiposNotaFiscal
() {
return TipoNotaFiscal.
values();
}
public Long getSequencialVendaParaVinculo
() {
return sequencialVendaParaVinculo
;
}
public void setSequencialVendaParaVinculo
(Long sequencialVendaParaVinculo
) {
this.
sequencialVendaParaVinculo = sequencialVendaParaVinculo
;
}
/**************************************************/
public void desvincularVenda
() {
new VerificadorLancamentoException
().
tratarIhRelancarExcecaoSemLimparEntidade(new CommandBean
() {
public void execute
() {
// pessoaPapelService.adicionarPapel(getEntidade().getPessoa(), new Papel(getPessoaPapelDTO().getCodigoPapel()));
// getEntidadeDTO().setPapeisDTO(pessoaPapelService.consultarPapeisDaPessoa(getPessoaPapelDTO().getSequencialPessoa()));
LancadorMensagem.
lancarSucesso("VENDA DESVINCULADA COM SUCESSO");
}
});
}
public void vincularVenda
() {
new VerificadorLancamentoException
().
tratarIhRelancarExcecaoSemLimparEntidade(new CommandBean
() {
public void execute
() {
// pessoaPapelService.adicionarPapel(getEntidade().getPessoa(), new Papel(getPessoaPapelDTO().getCodigoPapel()));
// getEntidadeDTO().setPapeisDTO(pessoaPapelService.consultarPapeisDaPessoa(getPessoaPapelDTO().getSequencialPessoa()));
LancadorMensagem.
lancarSucesso("VENDA VINCULADA COM SUCESSO");
}
});
}
}