Subversion Repositories Integrator Subversion

Rev

Rev 106 | Rev 572 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

package br.com.ec.controller.managedbean;

import java.io.Serializable;

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.domain.model.Ponto;
import br.com.ec.domain.service.ponto.PontoService;
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 PontoBean extends AbstractBean<Ponto> implements Serializable {

        private static final long serialVersionUID = 1L;
       
        private String senhaUsuario;
       
        private PontoService pontoService;
       
        @Inject
        public PontoBean(PontoService pontoService) {
                this.pontoService = pontoService;
        }
       
        @Override
        public void preCarregamento() {
                limparEntidade();
        }
       
        @Override
        public void limparEntidade() {
                entidade = new Ponto();
                setSenhaUsuario("");
        }

        @Override
        public GenericService<Ponto> getService() {
                return pontoService;
        }
       
        @Override
        public Ponto getEntidade() {
                return entidade;
        }

        @Override
        public Ponto getId() {
                return getEntidade();
        }
       
        public String getSenhaUsuario() {
                return senhaUsuario;
        }
        public void setSenhaUsuario(String senhaUsuario) {
                this.senhaUsuario = senhaUsuario;
        }
       
        /***************************************************************/
       
        public void iniciarPonto(final Long lojaSequencial) {
                new VerificadorLancamentoException().tratarIhRelancarExcecaoSemLimparEntidade(new CommandBean() {
                        public void execute() {
                                setEntidade(pontoService.consultarPonto(DataUtils.getDataAtual(), senhaUsuario, lojaSequencial));
                        }
                });
        }
       
        public void baterPontoInicio() {
                new VerificadorLancamentoException().tratarIhRelancarExcecaoSemLimparEntidade(new CommandBean() {
                        public void execute() {
                                getEntidade().setDataHoraPontoInicio(DataUtils.getDataAtual());
                                baterPonto();
                        }
                });
        }
       
        public void excluirPontoInicio() {
                new VerificadorLancamentoException().tratarIhRelancarExcecaoSemLimparEntidade(new CommandBean() {
                        public void execute() {
                                getEntidade().setDataHoraPontoInicio(null);
                                baterPonto();
                        }
                });
        }
       
        public void baterPontoFim() {
                new VerificadorLancamentoException().tratarIhRelancarExcecaoSemLimparEntidade(new CommandBean() {
                        public void execute() {
                                getEntidade().setDataHoraPontoFim(DataUtils.getDataAtual());
                                baterPonto();
                        }
                });
        }
       
        public void excluirPontoFim() {
                new VerificadorLancamentoException().tratarIhRelancarExcecaoSemLimparEntidade(new CommandBean() {
                        public void execute() {
                                getEntidade().setDataHoraPontoFim(null);
                                baterPonto();
                        }
                });
        }
       
        public void baterIntervaloInicio() {
                new VerificadorLancamentoException().tratarIhRelancarExcecaoSemLimparEntidade(new CommandBean() {
                        public void execute() {
                                getEntidade().setDataHoraIntervaloInicio(DataUtils.getDataAtual());
                                baterPonto();
                        }
                });
        }
       
        public void excluirIntervaloInicio() {
                new VerificadorLancamentoException().tratarIhRelancarExcecaoSemLimparEntidade(new CommandBean() {
                        public void execute() {
                                getEntidade().setDataHoraIntervaloInicio(null);
                                baterPonto();
                        }
                });
        }
       
        public void baterIntervaloFim() {
                new VerificadorLancamentoException().tratarIhRelancarExcecaoSemLimparEntidade(new CommandBean() {
                        public void execute() {
                                getEntidade().setDataHoraIntervaloFim(DataUtils.getDataAtual());
                                baterPonto();
                        }
                });
        }
       
        public void excluirIntervaloFim() {
                new VerificadorLancamentoException().tratarIhRelancarExcecaoSemLimparEntidade(new CommandBean() {
                        public void execute() {
                                getEntidade().setDataHoraIntervaloFim(null);
                                baterPonto();
                        }
                });
        }
       
        private void baterPonto() {
                pontoService.alterar(getEntidade());
                limparEntidade();
                LancadorMensagem.lancarSucesso("PONTO ALTERADO COM SUCESSO!");
        }
       
}