/**
  * 
  */
 private function hasAvaliacoes()
 {
     $modelAgenda = new Model_DbTable_Agenda();
     $avaliacoes = $modelAgenda->getAvaliacoesPendentes($this->usuario_id);
     if ($avaliacoes->count() > 0) {
         return true;
     }
     return false;
 }
 public function indexAction()
 {
     /**
      * 
      */
     $usuario_id = Zend_Auth::getInstance()->getIdentity()->usuario_id;
     $modelAgenda = new Model_DbTable_Agenda();
     $avaliacoesPendentes = $modelAgenda->getAvaliacoesPendentes($usuario_id);
     //Zend_Debug::dump($avaliacoesPendentes); die();
     $this->view->avaliacoesPendentes = $avaliacoesPendentes;
 }
 public function indexAction()
 {
     // Saloes Cadastrados
     $modelSalao = new Model_DbTable_Salao();
     //$where = $modelSalao->getDefaultAdapter()->quoteInto("salao_pre_cadastro = ?", 0);
     $totalSalao = $modelSalao->getCount();
     $this->view->totalSalao = $totalSalao->count;
     // Clientes Cadastrados
     $modelCliente = new Model_DbTable_Cliente();
     $totalCliente = $modelCliente->getCount();
     $this->view->totalCliente = $totalCliente->count;
     // Consultas CEP (validas)
     $modelBuscaCep = new Model_DbTable_BucaCep();
     $where = $modelBuscaCep->getDefaultAdapter()->quoteInto('busca_valida = ?', 1);
     $totalConsultaCep = $modelBuscaCep->getCount(1, $where);
     $this->view->totalConsultaCep = $totalConsultaCep->count;
     // agendamentos
     $modelAgenda = new Model_DbTable_Agenda();
     $where = $modelAgenda->getDefaultAdapter()->quoteInto("agenda_manual is null", null);
     $totalAgendamentos = $modelAgenda->fetchAll($where);
     $this->view->totalAgendamentos = $totalAgendamentos->count();
 }
 private function checkHasAgendaConfirmar()
 {
     $modelAgenda = new Model_DbTable_Agenda();
     $agenda = $modelAgenda->getAgendaConfirmar($this->identity->salao_id);
     //Zend_Debug::dump($agenda);
     return $agenda->count();
 }
 public function cancelarAction()
 {
     $agenda_id = $this->getRequest()->getParam('id');
     $agenda_id = $this->getRequest()->getParam('id');
     if (!$agenda_id) {
         $this->_helper->flashMessenger->addMessage(array('danger' => "Agendamento não encontrado!"));
         $this->_redirect("cliente/");
     }
     /**
      * busca dados do agendamento
      */
     $modelAgenda = new Model_DbTable_Agenda();
     $agenda = $modelAgenda->getById($agenda_id);
     /**
      * Verifica se o agendamento e do usuario logado
      */
     if ($agenda->usuario_id !== Zend_Auth::getInstance()->getIdentity()->usuario_id) {
         $this->_helper->flashMessenger->addMessage(array('danger' => "<strong>Acesso negado!</strong> Você não pode alterar este agendamento!"));
         $this->_redirect("cliente/");
     }
     /**
      * verifica se pode alterar a data
      */
     $modelConfig = new Model_DbTable_Config();
     $prazoCancelamento = $modelConfig->getBySlug('prazo_alterar_agendamento');
     $zendDateNow = new Zend_Date();
     $zendDateAgenda = new Zend_Date($agenda->agenda_data);
     if (!$zendDateNow->isEarlier($zendDateAgenda->subHour($prazoCancelamento->config_valor))) {
         $this->_helper->flashMessenger->addMessage(array('warning' => "<strong>Atenção!</strong> O prazo para alterar este agendamento já expirou!"));
         $this->_redirect("cliente/");
     }
     $this->view->agenda = $agenda;
     /**
      * form de motivo
      */
     $formMotivo = new Form_Salao_AgendaManualCancelamento();
     $formMotivo->submit->setLabel("Cancelar Agendamento");
     $this->view->formMotivo = $formMotivo;
     if ($this->getRequest()->isPost()) {
         $data = $this->getRequest()->getPost();
         if ($formMotivo->isValid($data)) {
             $agenda_cancelado_motivo = $formMotivo->getValue('agenda_cancelado_motivo');
             try {
                 Zend_Db_Table_Abstract::getDefaultAdapter()->beginTransaction();
                 $update = array('agenda_cancelado' => 1, 'agenda_cancelado_autor' => 'Cliente', 'agenda_cancelado_usuario' => 1, 'agenda_cancelado_motivo' => $agenda_cancelado_motivo, 'agenda_cancelado_data' => Zend_Date::now()->get('YYYY-MM-dd H:m'));
                 $modelAgenda->updateById($update, $agenda_id);
                 /**
                  * envia o email de confirmacao (cliente)
                  */
                 $pluginMail = new Plugin_Mail();
                 $pluginMail->setDataMail('agenda', $agenda);
                 $pluginMail->setDataMail('agenda_cancelado_motivo', $agenda_cancelado_motivo);
                 $pluginMail->send('cliente-agendamento-cancelar.phtml', 'Agendamento Cancelado', Zend_Auth::getInstance()->getIdentity()->usuario_email);
                 /**
                  * envia o email de confirmacao (salao)
                  */
                 $pluginMail2 = new Plugin_Mail();
                 $pluginMail2->setDataMail('agenda', $agenda);
                 $pluginMail2->setDataMail('agenda_cancelado_motivo', $agenda_cancelado_motivo);
                 $pluginMail2->send('salao-agendamento-cancelar.phtml', 'Agendamento Cancelado', $agenda->salao_email);
                 Zend_Db_Table_Abstract::getDefaultAdapter()->commit();
                 // retira a cobranca do salao
                 $pluginCobranca = new Plugin_Cobranca($agenda);
                 $pluginCobranca->retirar();
                 $this->_helper->flashMessenger->addMessage(array('success' => 'Agendamento cancelado com sucesso.'));
                 $this->_redirect("cliente/");
             } catch (Zend_Mail_Exception $ex) {
                 Zend_Db_Table_Abstract::getDefaultAdapter()->commit();
                 $this->_helper->flashMessenger->addMessage(array('success' => 'Agendamento cancelado com sucesso.'));
                 $this->_helper->flashMessenger->addMessage(array('warning' => 'Não foi possível enviar o e-mail de confirmação.'));
                 $this->_redirect("cliente/");
             } catch (Exception $ex) {
                 Zend_Db_Table_Abstract::getDefaultAdapter()->rollBack();
                 $this->_helper->flashMessenger->addMessage(array('danger' => 'Não foi possível cancelar o agendamento. Tente novamente mais tarde. - ' . $ex->getMessage()));
                 $this->_redirect("cliente/");
             }
         }
     }
 }
 public function noshowAction()
 {
     $this->_helper->layout->disableLayout();
     $this->_helper->viewRenderer->setNoRender();
     $agenda_id = $this->getRequest()->getParam("agenda");
     // busca dados do agendamento
     $modelAgenda = new Model_DbTable_Agenda();
     $agenda = $modelAgenda->getById($agenda_id);
     //Zend_Debug::dump($agenda); die();
     // verifica se pode dar no show
     if (!$agenda || $agenda->salao_id !== Zend_Auth::getInstance()->getIdentity()->salao_id) {
         $this->_helper->flashMessenger->addMessage(array("danger" => "Ação não permitida!"));
         $this->_redirect("salao/");
     }
     //caso ja tenha sido dado no-show
     if ($agenda->agenda_noshow) {
         $this->_helper->flashMessenger->addMessage(array("warning" => "No-show já efetuado para este agendamento!"));
         $this->_redirect("salao/");
     }
     try {
         Zend_Db_Table_Abstract::getDefaultAdapter()->beginTransaction();
         // atualizar a tabela
         $modelAgenda->updateById(array("agenda_noshow" => 1), $agenda_id);
         // enviar email para cliente
         $PluginMail = new Plugin_Mail();
         $PluginMail->setDataMail("agenda", $agenda);
         $PluginMail->send("cliente-noshow.phtml", "No-show", $agenda->usuario_email);
         // gravar notificacao
         $insertNotificacao = array("autenticacao_email" => $agenda->usuario_email, "notificacao_mensagem" => "No-show para um agendamento", "notificacao_link" => "#");
         $pluginNotificacao = new Plugin_Notificacao();
         $pluginNotificacao->gravar($insertNotificacao);
         $this->_helper->flashMessenger->addMessage(array("success" => "No-show realizado!"));
         Zend_Db_Table_Abstract::getDefaultAdapter()->commit();
     } catch (Exception $ex) {
         $this->_helper->flashMessenger->addMessage(array("danger" => "Houve um problema - " . $ex->getMessage()));
         Zend_Db_Table_Abstract::getDefaultAdapter()->rollBack();
     }
     $this->_redirect("salao/");
 }
 public function horariosAction()
 {
     $this->_helper->layout->disableLayout();
     $this->_helper->viewRenderer->setNoRender();
     $salao_id = $this->getRequest()->getParam('salao_id');
     $especialidade_id = $this->getRequest()->getParam('especialidade_id');
     $profissional_beleza_id = $this->getRequest()->getParam('profissional_beleza_id', null);
     $agenda_data = App_Helper_Date::getDateDb($this->getRequest()->getParam('agenda_data'));
     try {
         /**
          * Busca os horarios agendados
          */
         $string_horarios = null;
         $modelAgenda = new Model_DbTable_Agenda();
         $horarios = $modelAgenda->getHorariosAgenda($salao_id, $especialidade_id, $agenda_data, $profissional_beleza_id);
         if ($horarios->count() > 0) {
             $array_horarios = array();
             foreach ($horarios as $horario) {
                 $array_horarios[] = "'" . App_Helper_Date::getTime($horario->agenda_data) . "'";
             }
             $string_horarios = implode(', ', $array_horarios);
         }
         /**
          * Busca os horarios do salao para a data
          */
         $zendDate = new Zend_Date($agenda_data);
         $dia_semana = $zendDate->get(Zend_Date::WEEKDAY_DIGIT);
         $modelSalaoHorario = new Model_DbTable_SalaoHorario();
         $horariosLivre = $modelSalaoHorario->getHorariosLivreSalao($salao_id, $dia_semana, $string_horarios);
         if ($horariosLivre->count() > 0) {
             $livres = array();
             foreach ($horariosLivre as $livre) {
                 $livres[] = substr($livre->salao_horario, 0, -3);
             }
             echo Zend_Json::encode($livres);
         } else {
             echo Zend_Json::encode(array('count' => 0));
         }
     } catch (Exception $ex) {
         echo Zend_Json::encode(array('error' => 'Houve um problema - ' . $ex->getMessage()));
     }
 }