@PostConstruct
 public void init() {
   agendamento = new Agendamento();
   agendamentoEdit = new Agendamento();
   listAgendamento = new ArrayList<>();
   listAgendamentoConsulta = new ArrayList<>();
   listFotos = new ArrayList<>();
   contrato = new Contrato();
   data = new String[2];
   data[0] = DataHoje.data();
   data[1] = DataHoje.data();
   index = new Integer[4];
   index[0] = null;
   index[1] = null;
   index[2] = null;
   index[3] = null;
   listSelectItem = new ArrayList[2];
   listSelectItem[0] = new ArrayList<>();
   listSelectItem[1] = new ArrayList<>();
   horaAgenda = DataHoje.livre(new Date(), "HH:mm");
   by = "hoje";
   description = "";
   startFinish = "";
   actives = false;
   visibleCadastrarFoto = false;
 }
 public List<Agendamento> getListAgendamentoConsulta() {
   if (listAgendamentoConsulta.isEmpty()) {
     AgendamentoDao agendamentoDao = new AgendamentoDao();
     getListSelectItem();
     Integer idEvento = null;
     switch (by) {
       case "evento":
         if (index[1] != null) {
           idEvento = Integer.parseInt(listSelectItem[0].get(index[1]).getDescription());
         }
         break;
       case "hoje":
         data[0] = DataHoje.data();
         data[1] = "";
         break;
     }
     listAgendamentoConsulta =
         agendamentoDao.findAll(
             startFinish,
             by,
             description,
             data[0],
             data[1],
             SessaoCliente.get().getId(),
             idEvento);
   }
   return listAgendamentoConsulta;
 }
 public void setHoraAgenda(String horaAgenda) {
   if (!horaAgenda.isEmpty()) {
     this.horaAgenda = DataHoje.validaHora(horaAgenda);
   } else {
     this.horaAgenda = horaAgenda;
   }
 }
 public void clear(int tCase) {
   // CASO 0 - BOTÃO SALVAR / EXCLUIR
   if (tCase == 0 || tCase == 1) {
     agendamento = new Agendamento();
     index[0] = null;
     horaAgenda = DataHoje.livre(new Date(), "HH:mm");
     listAgendamento.clear();
   }
   // CASO 1 - BOTÃO NOVO
   if (tCase == 1) {
     Sessions.remove("agendamentoBean");
   }
 }
 public String editConsulta(Agendamento o) {
   Dao dao = new Dao();
   agendamentoEdit = (Agendamento) dao.rebind(o);
   agendamentoEdit.setHoraAgenda(DataHoje.livre(new Date(), "HH:mm"));
   agendamentoEdit.setDataAgenda(new Date());
   for (int i = 0; i < listSelectItem[0].size(); i++) {
     if (o.getEvento().getId() == Integer.parseInt(listSelectItem[0].get(i).getDescription())) {
       index[0] = i;
       break;
     }
   }
   return null;
 }
 public void selectedDataAtendimento(SelectEvent event) {
   SimpleDateFormat format = new SimpleDateFormat("d/M/yyyy");
   this.dataAtendimento = DataHoje.converte(format.format(event.getObject()));
 }
 public void setDataAtendimentoString(String dataAtendimentoString) {
   this.dataAtendimento = DataHoje.converte(dataAtendimentoString);
 }
 public String getDataAtendimentoString() {
   return DataHoje.converteData(dataAtendimento);
 }
 public void setDataAgendaString(String agendaString) {
   this.dataAgenda = DataHoje.converte(agendaString);
 }
 public String getDataAgendaString() {
   return DataHoje.converteData(dataAgenda);
 }
 public void setDataLancamentoString(String lancamentoString) {
   this.dataLancamento = DataHoje.converte(lancamentoString);
 }
 public String getDataLancamentoString() {
   return DataHoje.converteData(dataLancamento);
 }
 public void setEntradaString(String entradaString) {
   this.entrada = DataHoje.converte(entradaString);
 }
 public String getEntradaString() {
   return DataHoje.converteData(entrada);
 }
  public void save() {
    ConfiguracaoCoordenacao cc =
        new ConfiguracaoCoordenacaoDao().findByCliente(SessaoCliente.get().getId());
    if (cc == null) {
      Messages.warn("Sistema", "Configurar Coordernação! Segurança > Configuração > Coordenação");
      return;
    }
    Dao dao = new Dao();
    Logger logger = new Logger();
    if (index[0] == null) {
      Messages.warn("Validação", "Selecionar evento!");
      return;
    }
    List list = new FotosDao().findFotosByContrato(contrato.getId());
    if (list.isEmpty()) {
      Messages.warn("Validação", "Cadastrar nova foto de evolução para realizar agendamento!");
      return;
    }
    list = new FotosDao().findFotosByContrato(contrato.getId(), 30);
    if (list.isEmpty()) {
      Messages.warn("Validação", "Cadastrar nova foto de evolução para realizar agendamento!");
      return;
    }
    visibleCadastrarFoto = false;
    agendamento.setEvento(
        (Evento)
            dao.find(
                new Evento(), Integer.parseInt(listSelectItem[0].get(index[0]).getDescription())));
    if (getHabilitaFuncaoEquipe()) {
      if (listSelectItem[1].isEmpty()) {
        Messages.warn("Validação", "Nenhuma função encontrada!");
        return;
      }
      if (index[3] == null) {
        Messages.warn("Validação", "Selecionar função equipe!");
        return;
      }
      agendamento.setFuncaoEquipe(
          (FuncaoEquipe)
              dao.find(
                  new FuncaoEquipe(),
                  Integer.parseInt(listSelectItem[1].get(index[3]).getDescription())));
    }
    if (contrato.getId() == null) {
      Messages.warn("Validação", "Pesquisar contrato!");
      return;
    }
    if (agendamento.getDataAgendaString().isEmpty()) {
      Messages.warn("Validação", "Informar data do agendamento!");
      return;
    }

    // INICIA - CONFIGURAÇÃO > COORDENAÇÃO
    DataHoje dataHoje = new DataHoje();
    Integer dt1 = DataHoje.converteDataParaInteger(DataHoje.data());
    Integer dt2 = DataHoje.converteDataParaInteger(agendamento.getDataAgendaString());
    Integer dt3 = dt2;
    Integer dt4 =
        DataHoje.converteDataParaInteger(
            dataHoje.incrementarMeses(cc.getAgendamentoMaxMesesAgenda(), DataHoje.data()));
    // VERIFICA SE PERMITE AGENDAMENTO RETROATIVO
    if (cc.getAgendamentoDataRetroativo() != null) {
      dt2 =
          DataHoje.converteDataParaInteger(
              DataHoje.converteData(cc.getAgendamentoDataRetroativo()));
      if (dt2 < dt1) {
        dt2 = dt3;
      }
    }
    if (dt2 <= dt1) {
      Messages.warn("Validação", "A data do agendamento deve ser superior a data de hoje!");
      return;
    }
    // VERIFICA PERÍODO MÁXIMO DE MESES PARA AGENDAMENTO FUTURO
    if (dt3 > dt4) {
      Messages.warn(
          "Validação",
          "A data do agendamento não deve ser superior a "
              + cc.getAgendamentoMaxMesesAgenda()
              + " mese(s)");
      return;
    }
    // TERMINA - CONFIGURAÇÃO > COORDENAÇÃO
    if (horaAgenda.isEmpty()) {
      Messages.warn("Validação", "Informar horário válido!");
      return;
    }
    agendamento.setHoraAgenda(horaAgenda);
    if (agendamento.getId() == -1) {
      agendamento.setStatus((Status) dao.find(new Status(), 1));
      agendamento.setAgendador((Usuario) Sessions.getObject("sessaoUsuario"));
      agendamento.setContrato(contrato);
      AgendamentoDao agendamentoDao = new AgendamentoDao();
      if (agendamentoDao.exists(
          contrato.getId(), agendamento.getDataAgenda(), agendamento.getHoraAgenda())) {
        Messages.warn("Validação", "Agendamento já cadastrado!");
        return;
      }
      if (dao.save(agendamento, true)) {
        Messages.info("Sucesso", "Registro adicionado");
        logger.save(
            "ID: "
                + agendamento.getId()
                + "]"
                + " - Contrato: ["
                + agendamento.getContrato()
                + " - Agenda: "
                + agendamento.getDataAgendaString()
                + " - Hora: "
                + agendamento.getHoraAgenda());
        clear(0);
      } else {
        Messages.warn("Erro", "Ao adicionar registro!");
      }
    } else {
      Agendamento a = (Agendamento) dao.find(agendamento);
      String beforeUpdate =
          "ID: "
              + a.getId()
              + "]"
              + " - Contrato: ["
              + a.getContrato()
              + " - Agenda: "
              + a.getDataAgendaString()
              + " - Hora: "
              + a.getHoraAgenda();
      if (dao.update(agendamento, true)) {
        Messages.info("Sucesso", "Registro atualizado");
        logger.update(
            beforeUpdate,
            "ID: "
                + agendamento.getId()
                + "]"
                + " - Contrato: ["
                + agendamento.getContrato()
                + " - Agenda: "
                + agendamento.getDataAgendaString()
                + " - Hora: "
                + agendamento.getHoraAgenda());
        clear(0);
      } else {
        Messages.warn("Erro", "Ao atualizar registro!");
      }
    }
  }