예제 #1
0
 /**
  * Retorna os gráficos do dia a partir da unidade informada
  */
 public function today(Context $context)
 {
     $response = new JsonResponse();
     try {
         $ini = DateUtil::now('Y-m-d');
         $fim = DateUtil::nowSQL();
         // full datetime
         $unidade = (int) $context->request()->get('unidade');
         $status = $this->total_atendimentos_status($ini, $fim, $unidade);
         $response->data['legendas'] = AtendimentoService::situacoes();
         $response->data['status'] = $status[$unidade];
         $servicos = $this->total_atendimentos_servico($ini, $fim, $unidade);
         $response->data['servicos'] = $servicos[$unidade];
         $response->success = true;
     } catch (Exception $e) {
         $response->message = $e->getMessage();
     }
     return $response;
 }
예제 #2
0
 /**
  * Move os registros da tabela atendimento para a tabela de historico de atendimentos.
  * Se a unidade não for informada, será acumulado serviços de todas as unidades.
  *
  * @param Unidade|int $unidade
  *
  * @throws Exception
  */
 public function acumularAtendimentos($unidade = 0)
 {
     if ($unidade instanceof Unidade) {
         $unidadeId = $unidade->getId();
     } else {
         $unidadeId = max($unidade, 0);
         $unidade = $unidadeId > 0 ? $this->em->find('Novosga\\Model\\Unidade', $unidadeId) : null;
     }
     AppConfig::getInstance()->hook('attending.pre-reset', $unidade);
     $data = DateUtil::nowSQL();
     $conn = $this->em->getConnection();
     // tables name
     $historicoTable = $this->em->getClassMetadata('Novosga\\Model\\AtendimentoHistorico')->getTableName();
     $historicoCodifTable = $this->em->getClassMetadata('Novosga\\Model\\AtendimentoCodificadoHistorico')->getTableName();
     $atendimentoTable = $this->em->getClassMetadata('Novosga\\Model\\Atendimento')->getTableName();
     $atendimentoCodifTable = $this->em->getClassMetadata('Novosga\\Model\\AtendimentoCodificado')->getTableName();
     $atendimentoMetaTable = $this->em->getClassMetadata('Novosga\\Model\\AtendimentoMeta')->getTableName();
     $historicoMetaTable = $this->em->getClassMetadata('Novosga\\Model\\AtendimentoHistoricoMeta')->getTableName();
     try {
         $conn->beginTransaction();
         // copia os atendimentos para o historico
         $sql = "\n                INSERT INTO {$historicoTable}\n                (\n                    id, unidade_id, usuario_id, servico_id, prioridade_id, status, sigla_senha, num_senha, num_senha_serv,\n                    nm_cli, num_local, dt_cheg, dt_cha, dt_ini, dt_fim, ident_cli, usuario_tri_id, atendimento_id\n                )\n                SELECT\n                    a.id, a.unidade_id, a.usuario_id, a.servico_id, a.prioridade_id, a.status, a.sigla_senha, a.num_senha, a.num_senha_serv,\n                    a.nm_cli, a.num_local, a.dt_cheg, a.dt_cha, a.dt_ini, a.dt_fim, a.ident_cli, a.usuario_tri_id, a.atendimento_id\n                FROM\n                    {$atendimentoTable} a\n                WHERE\n                    a.dt_cheg <= :data AND (a.unidade_id = :unidade OR :unidade = 0)\n            ";
         // atendimentos pais (nao oriundos de redirecionamento)
         $query = $conn->prepare("{$sql} AND a.atendimento_id IS NULL");
         $query->bindValue('data', $data, PDO::PARAM_STR);
         $query->bindValue('unidade', $unidadeId, PDO::PARAM_INT);
         $query->execute();
         // atendimentos filhos (oriundos de redirecionamento)
         $query = $conn->prepare("{$sql} AND a.atendimento_id IS NOT NULL");
         $query->bindValue('data', $data, PDO::PARAM_STR);
         $query->bindValue('unidade', $unidadeId, PDO::PARAM_INT);
         $query->execute();
         // copia os metadados
         $sql = "\n                INSERT INTO {$historicoMetaTable}\n                (\n                    atendimento_id, name, value\n                )\n                SELECT\n                    a.atendimento_id, a.name, a.value\n                FROM\n                    {$atendimentoMetaTable}  a\n                WHERE\n                    a.atendimento_id IN (SELECT b.id FROM {$atendimentoTable} b WHERE b.dt_cheg <= :data AND (b.unidade_id = :unidade OR :unidade = 0))\n            ";
         $query = $conn->prepare($sql);
         $query->bindValue('data', $data, PDO::PARAM_STR);
         $query->bindValue('unidade', $unidadeId, PDO::PARAM_INT);
         $query->execute();
         // copia os atendimentos codificados para o historico
         $query = $conn->prepare("\n                INSERT INTO {$historicoCodifTable}\n                SELECT\n                    ac.atendimento_id, ac.servico_id, ac.valor_peso\n                FROM\n                    {$atendimentoCodifTable} ac\n                WHERE\n                    ac.atendimento_id IN (\n                        SELECT a.id FROM {$atendimentoTable} a WHERE dt_cheg <= :data AND (a.unidade_id = :unidade OR :unidade = 0)\n                    )\n            ");
         $query->bindValue('data', $data, PDO::PARAM_STR);
         $query->bindValue('unidade', $unidadeId, PDO::PARAM_INT);
         $query->execute();
         // limpa atendimentos codificados
         $this->em->createQuery('
                     DELETE Novosga\\Model\\AtendimentoCodificado e WHERE e.atendimento IN (
                         SELECT a.id FROM Novosga\\Model\\Atendimento a WHERE a.dataChegada <= :data AND (a.unidade = :unidade OR :unidade = 0)
                     )
                 ')->setParameter('data', $data)->setParameter('unidade', $unidadeId)->execute();
         // limpa metadata
         $this->em->createQuery('
                     DELETE Novosga\\Model\\AtendimentoMeta e WHERE e.atendimento IN (
                         SELECT a.id FROM Novosga\\Model\\Atendimento a WHERE a.dataChegada <= :data AND (a.unidade = :unidade OR :unidade = 0)
                     )
                 ')->setParameter('data', $data)->setParameter('unidade', $unidadeId)->execute();
         // limpa o auto-relacionamento para poder excluir os atendimento sem dar erro de constraint (#136)
         $this->em->createQuery('UPDATE Novosga\\Model\\Atendimento e SET e.pai = NULL WHERE e.dataChegada <= :data AND (e.unidade = :unidade OR :unidade = 0)')->setParameter('unidade', $unidadeId)->setParameter('data', $data)->execute();
         // limpa atendimentos da unidade
         $this->em->createQuery('DELETE Novosga\\Model\\Atendimento e WHERE e.dataChegada <= :data AND (e.unidade = :unidade OR :unidade = 0)')->setParameter('data', $data)->setParameter('unidade', $unidadeId)->execute();
         // limpa a tabela de senhas a serem exibidas no painel
         $this->em->createQuery('DELETE Novosga\\Model\\PainelSenha e WHERE (e.unidade = :unidade OR :unidade = 0)')->setParameter('unidade', $unidadeId)->execute();
         // zera o contador das senhas
         $this->em->createQuery('UPDATE Novosga\\Model\\Contador e SET e.total = 0 WHERE (e.unidade = :unidade OR :unidade = 0)')->setParameter('unidade', $unidadeId)->execute();
         $conn->commit();
     } catch (Exception $e) {
         try {
             $conn->rollBack();
         } catch (Exception $e2) {
         }
         throw $e;
     }
     AppConfig::getInstance()->hook('attending.reset', $unidade);
 }
예제 #3
0
 /**
  * @param Atendimento $atendimento
  * @param mixed       $statusAtual (array[int] | int)
  * @param int         $novoStatus
  * @param string      $campoData
  *
  * @return bool
  */
 private function mudaStatusAtendimento(Atendimento $atendimento, $statusAtual, $novoStatus, $campoData)
 {
     $cond = '';
     if ($campoData !== null) {
         $cond = ", e.{$campoData} = :data";
     }
     if (!is_array($statusAtual)) {
         $statusAtual = [$statusAtual];
     }
     // atualizando atendimento
     $query = $this->em()->createQuery("\n            UPDATE\n                Novosga\\Model\\Atendimento e\n            SET\n                e.status = :novoStatus {$cond}\n            WHERE\n                e.id = :id AND\n                e.status IN (:statusAtual)\n        ");
     if ($campoData !== null) {
         $query->setParameter('data', DateUtil::nowSQL());
     }
     $query->setParameter('novoStatus', $novoStatus);
     $query->setParameter('id', $atendimento->getId());
     $query->setParameter('statusAtual', $statusAtual);
     return $query->execute() > 0;
 }