예제 #1
0
 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 infoAction()
 {
     // valor agendamento
     $modelConfig = new Model_DbTable_Config();
     $valor_agendamento = $modelConfig->getBySlug("valor_agendamento");
     $this->view->valor_agendamento = App_Helper_Currency::toCurrency($valor_agendamento->config_valor * -1);
     // qtde de agendamentos gratis
     $agendamentos_gratis = $modelConfig->getBySlug("agendamentos_gratis");
     $this->view->agendamentos_gratis = $agendamentos_gratis->config_valor;
     $this->view->creditos = App_Helper_Currency::toCurrency($valor_agendamento->config_valor * -1 * $agendamentos_gratis->config_valor);
 }
예제 #3
0
 protected function cobranca($agenda)
 {
     // verifica se tera cobranca e ja foi feita a cobranca
     $modelCobrancaLancamento = new Model_DbTable_CobrancaLancamento();
     $where = $modelCobrancaLancamento->getDefaultAdapter()->quoteInto("agenda_id = ?", $agenda->agenda_id);
     $cobranca = $modelCobrancaLancamento->fetchRow($where);
     if (!$agenda->salao_cobranca) {
         return;
     }
     if ($cobranca && $cobranca->cobranca_lancamento_ativo === 0) {
         // atualiza a cobranca
         $modelCobrancaLancamento->updateById(array("cobranca_lancamento_ativo" => 1), $cobranca->cobranca_lancamento_id);
     } else {
         // gera a lancamento da cobranca
         // valor do agendamento
         $modelConfig = new Model_DbTable_Config();
         $valorAgendamento = $modelConfig->getByField("config_slug", "valor_agendamento");
         // dados do lancamento
         $lancamento = array('salao_id' => $agenda->salao_id, 'agenda_id' => $agenda->agenda_id, 'cobranca_lancamento_valor' => (double) $valorAgendamento->config_valor, 'cobranca_lancamento_descricao' => $valorAgendamento->config_nome);
         $modelCobrancaLancamento->insert($lancamento);
     }
     return;
 }