/**
  * Ação inicial de Modelos de Minutas
  */
 public function createAction()
 {
     parent::createAction();
     $this->view->arrTipoEtiqueta = $this->getService('TipoEtiqueta')->listItems();
     $this->view->sqTipoEtiquetaEletronica = Core_Configuration::getSgdoceTipoEtiquetaEletronica();
     $this->view->arrQtdeEtiqueta = $this->getService('QuantidadeEtiqueta')->listItems();
 }
Esempio n. 2
0
 /**
  * Obtém os dados da pessoa
  * @return array
  */
 public function searchPessoaInterna(\Core_Dto_Abstract $dto, $limit = NULL)
 {
     $search = mb_strtolower($dto->getQuery(), 'UTF-8');
     $queryBuilder = $this->_em->createQueryBuilder();
     $where = NULL;
     if ($dto->getProcedencia() == 'interna' && !is_null($dto->getSqPessoaOrigem())) {
         $where = $queryBuilder->andWhere('vf.sqUnidadeExercicio = :unidadeExercicio');
         if ($dto->getTipoPessoa() == \Core_Configuration::getCorpTipoPessoaFisica()) {
             $pessoaOrigem = $this->getEntityManager()->getRepository('app:VwProfissional')->find($dto->getSqPessoaOrigem());
             $queryBuilder->setParameter('unidadeExercicio', $pessoaOrigem->getSqUnidadeExercicio()->getSqUnidadeOrg());
         } else {
             if ($dto->getTipoPessoa() == \Core_Configuration::getCorpTipoPessoaUnidadeOrg()) {
                 $queryBuilder->setParameter('unidadeExercicio', $dto->getSqPessoaOrigem());
             }
         }
     }
     $field = $queryBuilder->expr()->lower($queryBuilder->expr()->trim('p.noPessoa'));
     $query = $queryBuilder->select('p.sqPessoa,p.noPessoa')->distinct()->from('app:VwProfissional', 'vf')->innerJoin('vf.sqPessoa', 'p')->andWhere($queryBuilder->expr()->like('clear_accentuation(' . $field . ')', $queryBuilder->expr()->literal($this->removeAccent('%' . $search . '%'))));
     if ($where) {
         $where;
     }
     if ($limit) {
         $query->setMaxResults($limit);
     }
     $query->orderBy('p.noPessoa');
     $res = $query->getQuery()->execute();
     $out = array();
     foreach ($res as $item) {
         $out[$item['sqPessoa']] = $item['noPessoa'];
     }
     return $out;
 }
 /**
  *
  * @param \Core_Dto_Search $dto
  * @return \Doctrine\DBAL\Query\QueryBuilder
  */
 public function listGrid(\Core_Dto_Search $dto)
 {
     $rsm = new \Doctrine\ORM\Query\ResultSetMapping();
     $rsm->addScalarResult('total_record', 'totalRecord', 'integer');
     $rsm->addScalarResult('sq_artefato', 'sqArtefato', 'integer');
     $rsm->addScalarResult('digital_numero', 'digitalNumero', 'string');
     $rsm->addScalarResult('dt_arquivamento', 'dtArquivamento', 'zenddate');
     $rsm->addScalarResult('no_pessoa_arquivamento', 'noPessoaArquivamento', 'string');
     $rsm->addScalarResult('tx_assunto', 'txAssunto', 'string');
     $rsm->addScalarResult('no_tipo_documento', 'noTipoDocumento', 'string');
     $rsm->addScalarResult('no_pessoa_origem', 'noPessoaOrigem', 'string');
     $caseNuDigital = "sgdoce.formata_numero_digital(a.nu_digital)";
     $sql = "\n               SELECT DISTINCT\n                      COUNT(a.sq_artefato) OVER() AS total_record\n                      ,a.sq_artefato\n                      ,COALESCE({$caseNuDigital}, formata_numero_artefato(a.nu_artefato,ap.co_ambito_processo)) AS digital_numero\n                      ,dt_arquivamento\n                      ,p.no_pessoa as no_pessoa_arquivamento\n                      ,ass.tx_assunto\n                      ,td.no_tipo_documento\n                      ,ps.no_pessoa AS no_pessoa_origem\n                 FROM artefato_arquivo_setorial aas\n                 JOIN vw_pessoa p ON aas.sq_pessoa_arquivamento = p.sq_pessoa\n                 JOIN artefato a USING(sq_artefato)\n                 JOIN sgdoce.tipo_artefato_assunto taa USING(sq_tipo_artefato_assunto)\n                 JOIN sgdoce.assunto ass ON ass.sq_assunto = taa.sq_assunto\n                 JOIN sgdoce.pessoa_artefato pa ON pa.sq_artefato = a.sq_artefato and pa.sq_pessoa_funcao = %1\$d\n                 JOIN sgdoce.pessoa_sgdoce ps ON ps.sq_pessoa_sgdoce = pa.sq_pessoa_sgdoce\n            LEFT JOIN artefato_processo ap ON a.sq_artefato = ap.sq_artefato\n            LEFT JOIN tipo_documento td USING(sq_tipo_documento)\n                WHERE dt_desarquivamento IS NULL\n                  AND sq_unidade_arquivamento = %2\$d\n                  AND sq_tipo_artefato = %3\$d\n                  %4\$s\n             ORDER BY dt_arquivamento DESC";
     $optionalCondition = '';
     $search = mb_strtolower($dto->getSearch(), 'UTF-8');
     if ($search) {
         $queryBuild = $this->_em->createQueryBuilder();
         if ($dto->getSqTipoArtefato() == \Core_Configuration::getSgdoceTipoArtefatoProcesso()) {
             $nuArtefato = $this->_em->createQueryBuilder()->expr()->lower("TRANSLATE(a.nu_artefato, './-', '')")->__toString();
             $optionalCondition = " AND (" . $queryBuild->expr()->eq('a.nu_artefato', $queryBuild->expr()->literal($search))->__toString() . " OR " . $queryBuild->expr()->eq($nuArtefato, $queryBuild->expr()->literal(str_replace(array('.', '/', '-'), '', $search)))->__toString() . ")";
         } else {
             $optionalCondition = " AND " . $queryBuild->expr()->eq('a.nu_digital', $search)->__toString();
         }
     }
     $strSql = sprintf($sql, \Core_Configuration::getSgdocePessoaFuncaoOrigem(), \Core_Integration_Sica_User::getUserUnit(), $dto->getSqTipoArtefato(), $optionalCondition);
     return $this->_em->createNativeQuery($strSql, $rsm)->useResultCache(false);
 }
Esempio n. 4
0
 public function indexAction()
 {
     $user = Zend_Auth::getInstance()->getIdentity();
     if ((int) $user->sqSistema !== (int) \Core_Configuration::getSicaeSqSistema()) {
         $this->_redirect('/index/home');
     }
 }
Esempio n. 5
0
 /**
  * Consulta de processos.
  *
  * @return QueryBuilder
  */
 public function listGridProcesso($dto)
 {
     $listCondition = array('getInteressado' => array("ilike" => array("OR" => array("trim(pse.no_pessoa)", "trim(vue.sg_unidade_org || ' - ' || pse.no_pessoa)"), 'tlp' => array('trim(%s)', 'trim(%s)'))), 'getNuArtefato' => array("regex" => array("AND" => array('art.nu_artefato'), 'tlp' => array('%s'))), 'getSqAssunto' => array("=" => array("AND" => 'ass.sq_assunto')), 'getTxAssuntoComplementar' => array("ilike" => array("AND" => 'art.tx_assunto_complementar')), 'getOrigem' => array("ilike" => array('OR' => array('trim(pfo.no_pessoa)', "trim(pfo.no_pessoa)"), 'tlp' => array('trim(%s)', 'trim(%s)'))), 'getNuDigital' => array("ilike" => array("AND" => 'cast(ard.nu_digital as text)')));
     $listPeriodo = array('dtCadastro' => 'art.dt_cadastro', 'dtAutuacao' => 'art.dt_artefato', 'dtPrazo' => 'art.dt_prazo');
     $sqPeriodo = $dto->getSqPeriodo();
     $periodoColumn = null;
     if (isset($listPeriodo[$sqPeriodo])) {
         $periodoColumn = $listPeriodo[$sqPeriodo];
     }
     $where = $this->getEntityManager()->getRepository('app:Artefato')->getCriteriaText($listCondition, $dto, $periodoColumn);
     $rsm = new \Doctrine\ORM\Query\ResultSetMapping($this->_em);
     $rsm->addScalarResult('total_record', 'totalRecord', 'integer');
     $rsm->addScalarResult('sq_artefato', 'sqArtefato', 'integer');
     $rsm->addScalarResult('nu_artefato', 'nuArtefato', 'string');
     $rsm->addScalarResult('tx_assunto', 'txAssunto', 'string');
     $rsm->addScalarResult('origem', 'noPessoaOrigem', 'string');
     $rsm->addScalarResult('interessados', 'noPessoaInteressados', 'string');
     $rsm->addScalarResult('tx_movimentacao', 'txMovimentacao', 'string');
     $sql = "SELECT\n                       COUNT(art.sq_artefato) OVER() AS total_record,\n                       art.sq_artefato,\n                       formata_numero_artefato(art.nu_artefato, atp.co_ambito_processo) AS nu_artefato,\n                       ass.sq_assunto,\n                       ass.tx_assunto,\n                       art.tx_assunto_complementar,\n                       string_agg(pse.no_pessoa, ', ') as interessados,\n                       pfo.sq_pessoa_corporativo as origem_id,\n                       pfo.no_pessoa as origem,\n                       art.dt_artefato,\n                       art.dt_prazo,\n                       art.dt_cadastro,\n                       ard.nu_digital,\n                       sgdoce.ultima_movimentacao_artefato(art.sq_artefato) as tx_movimentacao,\n                       vuo.sg_unidade_org\n                  FROM sgdoce.artefato art\n                  JOIN sgdoce.artefato_processo atp\n                    ON art.sq_artefato = atp.sq_artefato\n                  JOIN sgdoce.tipo_artefato_assunto taa\n                    ON art.sq_tipo_artefato_assunto = taa.sq_tipo_artefato_assunto\n                  JOIN sgdoce.assunto ass\n                    ON taa.sq_assunto = ass.sq_assunto\n                  JOIN sgdoce.pessoa_artefato pao\n                    ON art.sq_artefato = pao.sq_artefato AND pao.sq_pessoa_funcao = " . \Core_Configuration::getSgdocePessoaFuncaoOrigem() . "\n                  JOIN sgdoce.pessoa_sgdoce pfo\n                    ON pao.sq_pessoa_sgdoce = pfo.sq_pessoa_sgdoce\n             LEFT JOIN corporativo.vw_unidade_org vuo\n                    ON pfo.sq_pessoa_corporativo = vuo.sq_pessoa\n             LEFT JOIN sgdoce.pessoa_interessada_artefato pai\n                    ON art.sq_artefato = pai.sq_artefato\n             LEFT JOIN sgdoce.pessoa_sgdoce pse\n                    ON pai.sq_pessoa_sgdoce = pse.sq_pessoa_sgdoce\n             LEFT JOIN corporativo.vw_unidade_org vue\n                    ON pse.sq_pessoa_corporativo = vue.sq_pessoa\n             LEFT JOIN sgdoce.artefato_vinculo arv\n                    ON art.sq_artefato = arv.sq_artefato_pai AND arv.sq_tipo_vinculo_artefato = " . \Core_Configuration::getSgdoceTipoVinculoArtefatoAutuacao() . "\n             LEFT JOIN sgdoce.artefato ard\n                    ON ard.sq_artefato = arv.sq_artefato_filho\n                %s\n              GROUP BY art.sq_artefato,\n                       art.nu_artefato,\n                       atp.co_ambito_processo,\n                       ass.sq_assunto,\n                       ass.tx_assunto,\n                       art.tx_assunto_complementar,\n                       pfo.sq_pessoa_corporativo,\n                       pfo.no_pessoa,\n                       art.dt_artefato,\n                       art.dt_prazo,\n                       art.dt_cadastro,\n                       ard.nu_digital,\n                       tx_movimentacao,\n                       vuo.sg_unidade_org";
     if ($where != "") {
         $where = "WHERE " . $where;
     } else {
         $where = "WHERE 1 <> 1";
     }
     $sql = sprintf($sql, $where);
     return $this->_em->createNativeQuery($sql, $rsm);
 }
Esempio n. 6
0
 public function findDocumentoSemImagem($limit = 100)
 {
     $rsm = new \Doctrine\ORM\Query\ResultSetMapping($this->_em);
     $rsm->addScalarResult('sq_artefato', 'sqArtefato', 'integer');
     /**
      * somente documento que não possua vinculo com ninguem
      */
     $strQuery = sprintf('SELECT DISTINCT t.*
                            FROM(SELECT a.sq_artefato
                                   FROM artefato AS a
                              LEFT JOIN (
                                         SELECT DISTINCT ON (ai.sq_artefato)
                                                ai.sq_artefato,
                                                ai.sq_artefato_imagem
                                           FROM artefato_imagem ai
                                          ORDER BY ai.sq_artefato, ai.dt_operacao DESC, ai.sq_artefato_imagem DESC
                              ) uia ON a.sq_artefato = uia.sq_artefato
                              LEFT JOIN tipo_artefato_assunto     AS taa USING(sq_tipo_artefato_assunto)
                              LEFT JOIN artefato_processo         AS ap  ON a.sq_artefato = ap.sq_artefato
                              LEFT JOIN tmp_artefato_migration    as tmp ON a.sq_artefato = tmp.sq_artefato
                                  WHERE taa.sq_tipo_artefato = %1$d
                                    AND ap.sq_artefato         IS NULL
                                    AND uia.sq_artefato_imagem IS NULL
                                    AND tmp.sq_artefato        IS NULL
                                ) t
                            JOIN vw_imagem_sgdoc_fisico AS isf USING(sq_artefato)
                        ORDER BY sq_artefato DESC
                        LIMIT %2$d', \Core_Configuration::getSgdoceTipoArtefatoDocumento(), $limit);
     return $this->_em->createNativeQuery($strQuery, $rsm)->useResultCache(false)->getArrayResult();
 }
Esempio n. 7
0
 /**
  * Obtém pessoa artefato assinatura
  * @param  $dto
  * @return array
  */
 public function getPessoaArtefatoAssinatura($dto)
 {
     $query = $this->_em->createQueryBuilder()->select('p.noPessoa, p.noProfissao, p.noUnidadeOrg, tm.noTipoMotivacao, tm.sqTipoMotivacao,
                             m.deMotivacao')->from('app:Motivacao', 'm')->innerJoin('m.sqTipoMotivacao', 'tm')->innerJoin('m.sqPessoa', 'p')->innerJoin('p.sqPessoaFuncao', 'pf')->leftJoin('p.sqTratamentoVocativo', 'tv')->leftJoin('tv.sqTratamento', 't')->leftJoin('tv.sqVocativo', 'v')->leftJoin('p.sqPessoaCorporativo', 'pc')->leftJoin('p.sqMunicipioEndereco', 'cid')->leftJoin('cid.sqEstado', 'est')->andWhere('p.sqArtefato = :sqArtefato')->setParameter('sqArtefato', $dto->getSqArtefato())->andWhere('p.sqPessoaFuncao = :sqPessoaFuncao')->setParameter('sqPessoaFuncao', \Core_Configuration::getSgdocePessoaFuncaoAssinatura())->getQuery()->execute();
     if (empty($query)) {
         return NULL;
     }
     return $query;
 }
 /**
  * Metodo iniciais
  */
 public function init()
 {
     parent::init();
     $sqPessoa = $this->_getParam('sqPessoa');
     $criteria = array('sqTipoVinculo' => array(\Core_Configuration::getCorpTipoVinculoSocio(), \Core_Configuration::getCorpTipoVinculoRepreLegal()));
     $cmb['sqTipoVinculo'] = $this->getService('TipoVinculo')->getComboDefault($criteria);
     $this->view->cmb = $cmb;
     $this->view->sqPessoa = $sqPessoa;
     $this->_helper->layout()->disableLayout();
 }
Esempio n. 9
0
 /**
  * Realiza a pesquisa da grid
  * @param \Core_Dto_Abstract $dto
  */
 public function listGrid(\Core_Dto_Abstract $dto)
 {
     return $this->_em->createQueryBuilder()->select('
                         d.sqDocumento, 
                         d.txValor, 
                         td.sqTipoDocumento, 
                         td.noTipoDocumento,
                         atd.sqAtributoTipoDocumento, 
                         p.sqPessoa')->from('app:Documento', 'd')->innerJoin('d.sqAtributoTipoDocumento', 'atd')->innerJoin('atd.sqAtributoDocumento', 'ad')->innerJoin('atd.sqTipoDocumento', 'td')->innerJoin('d.sqPessoa', 'p')->where('p.sqPessoa = :sqPessoa')->setParameter('sqPessoa', $dto->getSqPessoa())->andWhere($this->_em->createQueryBuilder()->expr()->in('ad.sqAtributoDocumento', ':sqAtributoDocumento'))->setParameter('sqAtributoDocumento', array(\Core_Configuration::getCorpAtributoDocumentoNumero(), \Core_Configuration::getCorpAtributoDocumentoPisPasep()));
 }
Esempio n. 10
0
 public function isGestor(\Core_Dto_Search $dtoSearch)
 {
     $sql = "SELECT count(*) > 0 as is_gestor\n                  FROM sicae.vw_perfil p\n                 WHERE p.sq_perfil = :sqPerfil\n                   AND p.sq_tipo_perfil = :sqTipoPerfil";
     $rsm = new \Doctrine\ORM\Query\ResultSetMapping();
     $rsm->addScalarResult('is_gestor', 'isGestor');
     $query = $this->_em->createNativeQuery($sql, $rsm);
     $query->setParameter('sqTipoPerfil', \Core_Configuration::getSicaeTipoPerfilGestor());
     $query->setParameter('sqPerfil', $dtoSearch->getSqPerfil());
     return $query->useResultCache(TRUE, NULL, __METHOD__)->getSingleResult(AbstractQuery::HYDRATE_SINGLE_SCALAR);
 }
 /**
  *
  * @param \Core_Dto_Search $dto
  * @return boolean
  */
 public function isFirstTramite(\Core_Dto_Search $dto)
 {
     $entityTramite = $this->find($dto->getSqArtefato());
     if ($entityTramite->getNuTramite() == 2 && $entityTramite->getSqStatusTramite()->getSqStatusTramite() == \Core_Configuration::getSgdoceStatusTramiteCancelado()) {
         return true;
     }
     if ($entityTramite->getNuTramite() > 1) {
         return false;
     }
     return true;
 }
Esempio n. 12
0
 public function listItemsVinculoArtefatoAction(array $tipos = NULL)
 {
     $tipoDocumento = \Core_Configuration::getSgdoceTipoArtefatoDocumento();
     $tipoProcesso = \Core_Configuration::getSgdoceTipoArtefatoProcesso();
     $queryBuilder = $this->_em->createQueryBuilder()->select('ta.sqTipoArtefato,ta.noTipoArtefato')->from('app:TipoArtefato', 'ta')->orderBy('ta.noTipoArtefato', 'ASC');
     $queryBuilder->andWhere('ta.sqTipoArtefato in(:tipoDocumento,:tipoProcesso)')->setParameters(array('tipoDocumento' => $tipoDocumento, 'tipoProcesso' => $tipoProcesso));
     $out = array();
     $res = $queryBuilder->getQuery()->getArrayResult();
     foreach ($res as $item) {
         $out[$item['sqTipoArtefato']] = $item['noTipoArtefato'];
     }
     return $out;
 }
Esempio n. 13
0
 /**
  * Implementa as regras de negócio
  * @param object $entity
  * @param object $dto
  * @return string/NULL
  */
 public function preSave($entity, $dto = NULL)
 {
     $entity->setInAtivo(TRUE);
     if (!$entity->getSqPosicaoTipoDocumento()->getSqPosicaoTipoDocumento()) {
         $entityPosicao = $this->_getRepository('app:PosicaoTipoDocumento')->find(\Core_Configuration::getSgdoceSqPosicaoTipoDocEsquerda());
         $entity->setSqPosicaoTipoDocumento($entityPosicao);
     }
     if (!$entity->getSqPosicaoData()->getSqPosicaoData()) {
         $entityData = $this->_getRepository('app:PosicaoData')->find(\Core_Configuration::getSgdoceSqPosicaoDataLadoDoTipo());
         $entity->setSqPosicaoData($entityData);
     }
     $entity->getSqPosicaoTipoDocumento();
     $this->updateExistente($entity);
 }
Esempio n. 14
0
 /**
  * método que pesquisa assinatura para preencher autocomplete
  * @param string $term
  * @return multitype:NULL
  */
 public function searchUnidadeInterna($term)
 {
     $search = mb_strtolower($term, 'UTF-8');
     $queryBuilder = $this->_em->createQueryBuilder();
     $field = $queryBuilder->expr()->lower($queryBuilder->expr()->trim('u.noPessoa'));
     $term = mb_strtolower($term, 'UTF-8');
     $query = $queryBuilder->select('u.sqPessoa', 'u.noPessoa')->from('app:VwUnidadeOrgInterna', 'vw')->join('vw.sqPessoa', 'u')->andWhere($queryBuilder->expr()->like('clear_accentuation(' . $field . ')', $queryBuilder->expr()->literal($this->removeAccent('%' . $search . '%'))))->andWhere($queryBuilder->expr()->eq('u.sqTipoPessoa', \Core_Configuration::getCorpTipoPessoaUnidadeOrg()))->orderBy('u.noPessoa');
     $res = $query->getQuery()->execute();
     $out = array();
     foreach ($res as $item) {
         $out[$item['sqPessoa']] = $item['noPessoa'];
     }
     return $out;
 }
Esempio n. 15
0
 /**
  *
  * @param \Core_Dto_Abstract $dto
  * @return array
  */
 public function listGridAnexos(\Core_Dto_Search $dto)
 {
     $queryBuilder = $this->_em->createQueryBuilder();
     $queryBuilder->select('af.sqArtefato')->from('app:ArtefatoVinculo', 'av')->innerJoin('av.sqArtefatoFilho', 'af')->andWhere('av.sqTipoVinculoArtefato != :tipoVinculo')->andWhere('av.sqArtefatoPai = :sqArtefatoPai')->andWhere('av.dtRemocaoVinculo is null')->setParameters(array('tipoVinculo' => \Core_Configuration::getSgdoceTipoVinculoArtefatoReferencia(), 'sqArtefatoPai' => $dto->getSqArtefato()));
     $arrSqArtefatoVinculo = $queryBuilder->getQuery()->execute();
     $arrSqArtefato = array((int) $dto->getSqArtefato());
     if (!empty($arrSqArtefatoVinculo)) {
         foreach ($arrSqArtefatoVinculo as $artefatoVinculo) {
             $arrSqArtefato[] = $artefatoVinculo['sqArtefato'];
         }
     }
     $queryBuilder = $this->_em->createQueryBuilder();
     $queryBuilder->select('aa,a')->from('app:AnexoArtefato', 'aa')->innerJoin('aa.sqArtefato', 'a')->andWhere('aa.sqArtefato in(:sqArtefato)')->setParameters(array('sqArtefato' => $arrSqArtefato))->orderBy('aa.nuPagina');
     return $queryBuilder->getQuery()->getArrayResult();
 }
Esempio n. 16
0
 public function findDataInstitucional($codigo)
 {
     if (NULL === $codigo) {
         return array('sqPessoa' => NULL, 'noPessoa' => NULL, 'nuCpf' => NULL, 'nuDdd' => NULL, 'nuTelefone' => NULL, 'txEmail' => NULL);
     }
     $query = $this->_em->createQueryBuilder();
     $tipoTelefoneInstituicional = \Core_Configuration::getCorpTipoTelefoneInstitucional();
     $tipoEmailInstituicional = \Core_Configuration::getCorpTipoEmailInstitucional();
     $query->select('p.sqPessoa', 'p.noPessoa', 'pf.nuCpf', 't.nuDdd, t.nuTelefone', 'e.txEmail')->from('app:PessoaFisica', 'pf')->innerJoin('pf.sqPessoa', 'p')->leftJoin('p.telefone', 't', 'WITH', $query->expr()->eq('t.sqTipoTelefone', ':tipoTelefone'))->leftJoin('p.email', 'e', 'WITH', $query->expr()->eq('e.sqTipoEmail', ':tipoEmail'))->where($query->expr()->eq('p.sqPessoa', ':sqPessoa'))->andWhere($query->expr()->eq('pf.sqPessoa', ':sqPessoa'))->setParameter('tipoTelefone', $tipoTelefoneInstituicional, 'integer')->setParameter('tipoEmail', $tipoEmailInstituicional, 'integer')->setParameter('sqPessoa', $codigo, 'integer');
     $data = $query->getQuery()->execute(array(), \Doctrine\ORM\AbstractQuery::HYDRATE_ARRAY);
     if (!$data) {
         return array('sqPessoa' => NULL, 'noPessoa' => NULL, 'nuCpf' => NULL, 'nuDdd' => NULL, 'nuTelefone' => NULL, 'txEmail' => NULL);
     }
     return $data[0];
 }
Esempio n. 17
0
 public function listGrid(\Core_Dto_Abstract $dto)
 {
     $_qb = $this->_em->createQueryBuilder();
     $query = $_qb->select('
         d.sqDocumento,
         d.txValor,
         td.sqTipoDocumento,
         td.noTipoDocumento,
         atd.sqAtributoTipoDocumento,
         p.sqPessoa,
         ps.sqPessoaSgdoce,
         acd.sqAnexoComprovanteDocumento,
         acd.deCaminhoImagem
     ')->from($this->_entityName, 'd')->innerJoin('d.sqAtributoTipoDocumento', 'atd')->innerJoin('atd.sqAtributoDocumento', 'ad')->innerJoin('atd.sqTipoDocumento', 'td')->innerJoin('d.sqPessoa', 'p')->leftJoin('p.sqPessoaCorporativo', 'ps', 'WITH', $_qb->expr()->andX()->add($_qb->expr()->eq('ps.sqPessoaCorporativo', 'p.sqPessoa')))->leftJoin('ps.sqAnexoComprovanteDocumento', 'acd', 'WITH', $_qb->expr()->andX()->add($_qb->expr()->eq('acd.sqTipoDocumento', 'td.sqTipoDocumento'))->add($_qb->expr()->eq('acd.sqPessoaSgdoce', ':sqPessoaSgdoce')))->where('p.sqPessoa = :sqPessoa')->andWhere($_qb->expr()->in('ad.sqAtributoDocumento', ':sqAtributoDocumento'))->setParameter('sqPessoa', $dto->getSqPessoaFisica() ?: null)->setParameter('sqPessoaSgdoce', $dto->getSqPessoaSgdoce() ?: null)->setParameter('sqAtributoDocumento', array(\Core_Configuration::getCorpAtributoDocumentoNumero()));
     return $query;
 }
Esempio n. 18
0
 public function saveEmailPessoaRodape($dto, $entityAux)
 {
     $criteria = array('sqPessoaSgdoce' => $entityAux->getSqPessoaSgdoce());
     $entityEmailArtefato = $this->_getRepository('app:EmailSgdoce')->findOneBy($criteria);
     if (!$entityEmailArtefato) {
         $entityEmailArtefato = $this->_newEntity('app:EmailSgdoce');
         $entityEmailArtefato->setSqPessoaSgdoce($entityAux);
     }
     $tipoEmail = $this->getEntityManager()->getPartialReference('app:VwTipoEmail', \Core_Configuration::getSgdoceTipoEmailParticular());
     $entityEmailArtefato->setDtCadastro(new \Zend_Date());
     $entityEmailArtefato->setSqTipoEmail($tipoEmail);
     $entityEmailArtefato->setTxEmail($dto->getTxEmailRodape());
     $this->getEntityManager()->persist($entityEmailArtefato);
     $this->getEntityManager()->flush($entityEmailArtefato);
     return $entityEmailArtefato;
 }
Esempio n. 19
0
 /**
  *
  * @param \Core_Dto_Search $dto
  * @return array
  */
 public function listGrid(\Core_Dto_Search $dto)
 {
     $rsm = new \Doctrine\ORM\Query\ResultSetMapping($this->_em);
     $rsm->addScalarResult('sq_caixa', 'sqCaixa', 'integer');
     $rsm->addScalarResult('sq_artefato', 'sqArtefato', 'integer');
     $rsm->addScalarResult('sq_tipo_artefato', 'sqTipoArtefato', 'integer');
     $rsm->addScalarResult('nu_artefato', 'nuArtefato', 'string');
     $rsm->addScalarResult('no_tipo_documento', 'noTipoDocumento', 'string');
     $rsm->addScalarResult('tx_classificacao', 'txClassificacao', 'string');
     $rsm->addScalarResult('nu_classificacao', 'nuClassificacao', 'string');
     $rsm->addScalarResult('no_pessoa_origem', 'noPessoaOrigem', 'string');
     $rsm->addScalarResult('tx_assunto', 'txAssunto', 'string');
     $strQuery = sprintf("SELECT ca.sq_caixa\n                        ,art.sq_artefato\n                        ,CASE WHEN (taa.sq_tipo_artefato = %d) THEN art.nu_artefato ELSE art.nu_digital::TEXT END AS nu_artefato\n                        ,td.no_tipo_documento\n                        ,taa.sq_tipo_artefato\n                        ,cl.nu_classificacao || ' - ' ||cl.tx_classificacao as tx_classificacao\n\n                        ,ps.no_pessoa AS no_pessoa_origem\n                        ,ass.tx_assunto\n                   FROM caixa_artefato ca\n             INNER JOIN caixa cx                    using(sq_caixa)\n             INNER JOIN artefato art                 using(sq_artefato)\n             INNER JOIN tipo_documento td            using(sq_tipo_documento)\n             INNER JOIN tipo_artefato_assunto taa    using(sq_tipo_artefato_assunto)\n             INNER JOIN assunto ass                  using(sq_assunto)\n             INNER JOIN artefato_classificacao ac    using(sq_artefato)\n             INNER JOIN classificacao cl             ON ac.sq_classificacao = cl.sq_classificacao\n             INNER JOIN pessoa_artefato pa           using(sq_artefato)\n             INNER JOIN pessoa_sgdoce ps             using(sq_pessoa_sgdoce)\n                  WHERE ca.sq_caixa = %d\n                    AND pa.sq_pessoa_funcao = %d", \Core_Configuration::getSgdoceTipoArtefatoProcesso(), $dto->getSqCaixa(), \Core_Configuration::getSgdocePessoaFuncaoOrigem());
     $nativeQuery = $this->_em->createNativeQuery($strQuery, $rsm);
     return $nativeQuery;
 }
 /**
  * Método que obtém os dados para grid
  * @param \Core_Dto_Search $dtoSearch
  * @return array
  */
 public function getResultList(\Core_Dto_Search $dtoSearch)
 {
     $this->view->perfil = Core_Integration_Sica_User::getUserProfile();
     $dtoSearch->sqPessoa = Core_Integration_Sica_User::getPersonId();
     $dtoSearch->sqUnidadeOrg = Core_Integration_Sica_User::getUserUnit();
     $dtoSearch->sqTipoArtefato = $this->getRequest()->getParam('tipoArtefato') ? $this->getRequest()->getParam('tipoArtefato') : 1;
     $dtoSearch->search = $this->getRequest()->getParam('search') ? $this->getRequest()->getParam('search') : null;
     $this->view->isUserSgi = $this->_isUserSgi();
     $this->view->isUserPro = $this->view->perfil == \Core_Configuration::getSgdocePerfilProtocolo();
     $dtoUnidadeOrg = Core_Dto::factoryFromData(array('sqUnidadeOrg' => $dtoSearch->sqUnidadeOrg), 'search');
     $dtoSearch->currentUnitHasNUP = $this->getService('VwUnidadeOrg')->hasNUP($dtoUnidadeOrg);
     $caixa = $this->_getParam('migration_box');
     $dtoSearch->caixa = $caixa;
     $res = $this->getService()->getGrid($dtoSearch);
     return $res;
 }
 public function modalClassificacaoAction()
 {
     $this->getHelper('layout')->disableLayout();
     $params = $this->_getAllParams();
     $entityArtefato = $this->getService('Artefato')->find($params['sqArtefato']);
     $sqTipoArtefato = $entityArtefato->getSqTipoArtefatoAssunto()->getSqTipoArtefato()->getSqTipoArtefato();
     if ($sqTipoArtefato == \Core_Configuration::getSgdoceTipoArtefatoProcesso()) {
         $nuArtefato = $this->getService('Processo')->formataProcessoAmbitoFederal($entityArtefato);
     } else {
         $nuArtefato = $entityArtefato->getNuDigital()->getNuEtiqueta();
     }
     $this->view->nuArtefato = $nuArtefato;
     $this->view->entityArtefato = $entityArtefato;
     if (isset($params['back'])) {
         $this->view->backUrl = str_replace('.', '/', $params['back']);
     }
 }
Esempio n. 22
0
 public function saveEnderecoPessoaRodape($dto, $entityAux)
 {
     $filter = new \Zend_Filter();
     $criteria = array('sqPessoaSgdoce' => $entityAux->getSqPessoaSgdoce());
     $entityEnderecoArtefato = $this->_getRepository('app:EnderecoSgdoce')->findOneBy($criteria);
     if (!$entityEnderecoArtefato) {
         $entityEnderecoArtefato = $this->_newEntity('app:EnderecoSgdoce');
         $entityEnderecoArtefato->setSqPessoaSgdoce($entityAux);
     }
     $tipoEndereco = $this->getEntityManager()->getPartialReference('app:VwTipoEndereco', \Core_Configuration::getSgdoceTipoEnderecoResidencial());
     $entityEnderecoArtefato->setSqTipoEndereco($tipoEndereco);
     $entityEnderecoArtefato->setTxEndereco($dto->getTxEnderecoRodape());
     $entityEnderecoArtefato->setCoCep($filter->filterStatic($dto->getCoCepRodape(), 'Digits'));
     $this->getEntityManager()->persist($entityEnderecoArtefato);
     $this->getEntityManager()->flush($entityEnderecoArtefato);
     return $entityEnderecoArtefato;
 }
Esempio n. 23
0
 public function saveTelefoneSgdoce($entity, $entityAux1)
 {
     $telefone = $this->getServiceLocator()->getService('VwTelefone')->findTelefone($entity->getSqPessoa());
     $entityTelefoneArtefato = NULL;
     $filter = new \Zend_Filter();
     if ($telefone->getSqTelefone()) {
         $entityTelefoneArtefato = $this->_newEntity('app:TelefoneSgdoce');
         $tipoTelefone = $this->getEntityManager()->getPartialReference('app:VwTipoTelefone', \Core_Configuration::getSgdoceTipoTelefoneResidencial());
         $entityTelefoneArtefato->setSqPessoaSgdoce($entityAux1);
         $entityTelefoneArtefato->setSqTipoTelefone($tipoTelefone);
         $entityTelefoneArtefato->setDtCadastro(new \Zend_Date());
         $entityTelefoneArtefato->setNuDdd($filter->filterStatic($telefone->getNuDdd(), 'Digits'));
         $entityTelefoneArtefato->setNuTelefone($filter->filterStatic($telefone->getNuTelefone(), 'Digits'));
         $this->getEntityManager()->persist($entityTelefoneArtefato);
     }
     $this->getEntityManager()->flush($entityTelefoneArtefato);
     return $entityTelefoneArtefato;
 }
Esempio n. 24
0
 /**
  * @param integer $sqSolicitacao
  */
 public function getStatusPorTipo($sqSolicitacao, $sqTipoStatusSolicitacao)
 {
     $sql = "SELECT  row_number() over() as rownum,\n                        s.sq_solicitacao,\n                        ss.sq_pessoa_triagem,\n                        ss.sq_pessoa_responsavel,\n                        ss.tx_comentario,\n                        to_char(ss.dt_operacao, 'DD/MM/YYYY') as dt_operacao,\n                        pt.no_pessoa as no_pessoa_triagem,\n                        pr.no_pessoa as no_pessoa_responsavel,\n                        ps.no_pessoa as no_pessoa_solicitacao,\n                        ss.sq_tipo_status_solicitacao,\n                        em.tx_email\n                FROM sgdoce.solicitacao s\n                JOIN sgdoce.status_solicitacao ss USING(sq_solicitacao)\n                JOIN corporativo.vw_pessoa ps ON s.sq_pessoa = ps.sq_pessoa\n                LEFT JOIN corporativo.vw_pessoa pt ON ss.sq_pessoa_triagem = pt.sq_pessoa\n                LEFT JOIN corporativo.vw_pessoa pr ON ss.sq_pessoa_responsavel = pr.sq_pessoa\n                LEFT JOIN corporativo.vw_email em\n                ON em.sq_pessoa = s.sq_pessoa AND em.sq_tipo_email = " . \Core_Configuration::getCorpTipoEmailInstitucional() . "\n                WHERE ss.sq_solicitacao = :sqSolicitacao AND ss.sq_tipo_status_solicitacao = :sqTipoStatusSolicitacao\n                ORDER BY ss.dt_operacao DESC, rownum ASC";
     $rsm = new \Doctrine\ORM\Query\ResultSetMapping();
     $rsm->addScalarResult('rownum', 'rownum');
     $rsm->addScalarResult('sq_solicitacao', 'sqSolicitacao');
     $rsm->addScalarResult('sq_pessoa_triagem', 'sqPessoaTriagem');
     $rsm->addScalarResult('sq_pessoa_responsavel', 'sqPessoaResponsavel');
     $rsm->addScalarResult('tx_comentario', 'txComentario');
     $rsm->addScalarResult('dt_operacao', 'dtOperacao');
     $rsm->addScalarResult('no_pessoa_triagem', 'noPessoaTriagem');
     $rsm->addScalarResult('no_pessoa_responsavel', 'noPessoaResponsavel');
     $rsm->addScalarResult('no_pessoa_solicitacao', 'noPessoaSolicitacao');
     $rsm->addScalarResult('tx_email', 'txEmail');
     $query = $this->_em->createNativeQuery($sql, $rsm);
     $query->setParameter('sqSolicitacao', $sqSolicitacao)->setParameter('sqTipoStatusSolicitacao', $sqTipoStatusSolicitacao);
     return $query->getScalarResult();
 }
 /**
  * @param type $entity
  * @param type $dto
  */
 public function postInsert($entity, $dto = NULL)
 {
     // Salvando histórico.
     $txNumeroPecas = $entity->getTxNumeroPecas();
     $sqArtefato = $entity->getSqArtefato()->getSqArtefato();
     $artefatoEnt = $this->getServiceLocator()->getService('Artefato')->find($sqArtefato);
     $nuArtefato = $artefatoEnt->getNuArtefato();
     if ($entity->getStDesmembramento()) {
         $sqArtefatoDestino = $entity->getSqArtefatoDestino()->getSqArtefato();
         $artefatoDestinoEnt = $this->getServiceLocator()->getService('Artefato')->find($sqArtefatoDestino);
         $nuArtefatoDestino = $artefatoDestinoEnt->getNuArtefato();
         // #HistoricoArtefato::save();
         $strMessage = $this->getServiceLocator()->getService('HistoricoArtefato')->getMessage('MH010', $txNumeroPecas, $nuArtefato, $nuArtefatoDestino);
     } else {
         // #HistoricoArtefato::save();
         $strMessage = $this->getServiceLocator()->getService('HistoricoArtefato')->getMessage('MH011', $txNumeroPecas, $nuArtefato);
     }
     $this->getServiceLocator()->getService('HistoricoArtefato')->registrar($sqArtefato, \Core_Configuration::getSgdoceSqOcorrenciaCadastrar(), $strMessage);
 }
 public function listItemsVinculoArtefatoAction()
 {
     $this->_helper->layout->disableLayout();
     $this->_helper->viewRenderer->setNoRender(TRUE);
     $data = array();
     # filtra o tipo de retorno conforme o tipo do documento base
     # Atentar para o tipo do documento base
     #          BASE -> Recupera
     # Regra-1: DOC  +  DOC
     # Regra-2: PROC +  PROC
     # Regra-3: PROC +  DOC
     $tipoArtefatoFiltro = array(\Core_Configuration::getSgdoceTipoArtefatoDocumento() => array(\Core_Configuration::getSgdoceTipoArtefatoDocumento()), \Core_Configuration::getSgdoceTipoArtefatoProcesso() => array(\Core_Configuration::getSgdoceTipoArtefatoDocumento(), \Core_Configuration::getSgdoceTipoArtefatoProcesso()));
     $arrTipoArtefatoAceito = $tipoArtefatoFiltro[$this->getRequest()->getParam('sqTipoArtefatoParent')];
     foreach ($this->getService()->listItemsVinculoArtefatoAction() as $key => $value) {
         if (in_array($key, $arrTipoArtefatoAceito)) {
             $data[] = array('value' => $key, 'text' => $value);
         }
     }
     $this->_helper->json($data);
 }
Esempio n. 27
0
 public function desarquivar(\Core_Dto_Search $dto)
 {
     try {
         $serviceHA = $this->getServiceLocator()->getService('HistoricoArtefato');
         foreach ($dto->getSqArtefato()->getApi() as $method) {
             $entityArtefato = $this->_getRepository('app:Artefato')->find($dto->getSqArtefato()->{$method}());
             $this->_checkArtefatoEmprestado($entityArtefato);
             $entityCaixaArtefato = $this->_getRepository()->findOneBy(array('sqArtefato' => $entityArtefato->getSqArtefato()));
             if (NULL === $entityCaixaArtefato) {
                 throw new \Core_Exception_ServiceLayer_Verification('Artefato não localizado no arquivo. Já deve ter sido desarquivado');
             }
             //remove 1 segundo para garantir que o historico a ser salvo em seguida seja a ultima movimentação
             $date = \Zend_Date::now()->subSecond(1);
             $sqTipoHistorico = \Core_Configuration::getSgdoceTipoHistoricoArquivoDesarquivado();
             # persiste o historico do arquivo
             $this->_doInsertHistorico($entityCaixaArtefato, $date, $sqTipoHistorico);
             # persiste um tramite para quem faz o desarquivamento
             $dtoSearchArtefato = \Core_Dto::factoryFromData(array('sqArtefato' => $entityArtefato->getSqArtefato()), 'search');
             $tramiteArtefatoService = $this->getServiceLocator()->getService('TramiteArtefato');
             $entityTramiteArtefato = $this->_newEntity('app:TramiteArtefato');
             $entityTramiteArtefato->setDtTramite($date)->setDtRecebimento($date)->setSqArtefato($entityArtefato)->setSqPessoaTramite($this->_getUserOperation())->setSqUnidadeOrgTramite($this->_getUnitOperation())->setNuTramite($tramiteArtefatoService->getNextTramiteNumber($dtoSearchArtefato))->setSqPessoaDestinoInterno($this->_getUserOperation())->setInImpresso(true)->setSqPessoaRecebimento($this->_getUserOperation())->setSqStatusTramite($this->getEntityManager()->getPartialReference('app:StatusTramite', \Core_Configuration::getSgdoceStatusTramiteRecebido()))->setSqPessoaDestino($this->getEntityManager()->getPartialReference('app:VwPessoa', $this->_getUnitOperation()->getSqUnidadeOrg()));
             $this->getEntityManager()->persist($entityTramiteArtefato);
             # persiste o historico no artefato
             $sqOcorrencia = \Core_Configuration::getSgdoceSqOcorrenciaDesarquivar();
             $pessoaOperacao = $this->_getUserOperation()->getNoPessoa();
             $strMessage = $serviceHA->getMessage('MH020', \Zend_Date::now()->toString('dd/MM/YYYY HH:mm:ss'), $pessoaOperacao);
             $serviceHA->registrar($entityArtefato->getSqArtefato(), $sqOcorrencia, $strMessage);
             /**
              * remove registro da caixa de artefato
              *
              * a remoção do artefato da caixa deve ser feita no final devido ao relacionamento reverso
              * de sqCaixaArtefato existem em Artefato
              */
             $this->getEntityManager()->remove($entityCaixaArtefato);
             $this->getEntityManager()->flush();
         }
     } catch (\Exception $e) {
         throw $e;
     }
 }
 /**
  * LISTA DE TIPO DE ASSUNTO DE SOLICITAÇÃO.
  *
  * @param \Core_Dto_Search $dto
  * @param string $sort
  * @param string $order
  * @return array
  */
 public function listTipoAssuntoSolicitacao($dto, $sort = 'a.noTipoAssuntoSolicitacao', $order = 'ASC')
 {
     $queryBuilder = $this->_em->createQueryBuilder()->select('a.sqTipoAssuntoSolicitacao, a.noTipoAssuntoSolicitacao, a.inTipoParaArtefato')->from('app:TipoAssuntoSolicitacao', 'a')->orderBy($sort, $order);
     if ($dto->getQuery() != "") {
         $search = mb_strtolower($dto->getQuery(), 'UTF-8');
         $noTipoAssuntoSolicitacao = $queryBuilder->expr()->lower($queryBuilder->expr()->trim('a.noTipoAssuntoSolicitacao'));
         $queryBuilder->where($queryBuilder->expr()->like('clear_accentuation(' . $noTipoAssuntoSolicitacao . ')', $queryBuilder->expr()->literal($this->removeAccent('%' . $search . '%'))));
     }
     $inTipoParaArtefato = $dto->getInTipoParaArtefato();
     if (!is_null($inTipoParaArtefato)) {
         $paraArtefato = $dto->getInTipoParaArtefato() > 0 ? '1' : '0';
         $queryBuilder->andWhere("a.inTipoParaArtefato = :inTipoParaArtefato")->setParameter(":inTipoParaArtefato", $paraArtefato);
         if ($paraArtefato) {
             $arrAssuntoProcesso = array(\Core_Configuration::getSgdoceTipoAssuntoSolicitacaoComentario(), \Core_Configuration::getSgdoceTipoAssuntoSolicitacaoDespacho(), \Core_Configuration::getSgdoceTipoAssuntoSolicitacaoAlterarCadastro(), \Core_Configuration::getSgdoceTipoAssuntoSolicitacaoVolumeDeProcesso(), \Core_Configuration::getSgdoceTipoAssuntoSolicitacaoDesanexaProcesso(), \Core_Configuration::getSgdoceTipoAssuntoSolicitacaoDesmembraPecas(), \Core_Configuration::getSgdoceTipoAssuntoSolicitacaoRemoverPeca());
             $arrAssuntoDocumento = array(\Core_Configuration::getSgdoceTipoAssuntoSolicitacaoComentario(), \Core_Configuration::getSgdoceTipoAssuntoSolicitacaoAlterarCadastro(), \Core_Configuration::getSgdoceTipoAssuntoSolicitacaoDespacho(), \Core_Configuration::getSgdoceTipoAssuntoSolicitacaoDesanexaDigital(), \Core_Configuration::getSgdoceTipoAssuntoSolicitacaoExcluirImagem());
             $arrAssunto = $inTipoParaArtefato == \Core_Configuration::getSgdoceTipoArtefatoProcesso() ? $arrAssuntoProcesso : $arrAssuntoDocumento;
             $queryBuilder->andWhere("a.sqTipoAssuntoSolicitacao IN(:sqTipoAssuntoSolicitacaoiIn)")->setParameter(":sqTipoAssuntoSolicitacaoiIn", $arrAssunto);
         }
     }
     $queryBuilder->andWhere("a.stRegistroAtivo = :stRegistroAtivo")->setParameter(":stRegistroAtivo", TRUE);
     return $queryBuilder->getQuery()->useResultCache(TRUE, NULL, __METHOD__)->execute();
 }
Esempio n. 29
0
 /**
  * @param  array  $data
  * @param  int    $selected
  * @param  array  $config
  * @return string
  */
 public function nuArtefato(Artefato $entArtefato, $sqTipoArtefato = null)
 {
     $return = NULL;
     $coAmbitoProcesso = Processo::T_TIPO_AMBITO_PROCESSO_FEDERAL;
     if (is_null($sqTipoArtefato)) {
         $sqTipoArtefato = $entArtefato->getSqTipoArtefatoAssunto()->getSqTipoArtefato()->getSqTipoArtefato();
     }
     // PROCESSO
     if ($sqTipoArtefato == \Core_Configuration::getSgdoceTipoArtefatoProcesso()) {
         $nuArtefato = $entArtefato->getNuArtefato();
         if (method_exists($entArtefato, 'getSqArtefatoProcesso') && $entArtefato->getSqArtefatoProcesso()) {
             $coAmbitoProcesso = $entArtefato->getSqArtefatoProcesso()->getCoAmbitoProcesso();
         }
         // SE AMBITO FEDERAL APLICA MÁSCARA
         if ($coAmbitoProcesso == Processo::T_TIPO_AMBITO_PROCESSO_FEDERAL) {
             $nuArtefato = $this->mask($nuArtefato);
         }
         return $nuArtefato;
     } else {
         return $entArtefato->getNuDigital()->getNuEtiqueta(TRUE);
     }
     return $return;
 }
Esempio n. 30
0
 /**
  *
  * @param \Sgdoce\Model\Entity\Artefato $entityArtefato
  * @return \Arquivo\Service\ArquivamentoSetorial
  */
 private function _processTramite(\Sgdoce\Model\Entity\Artefato $entityArtefato)
 {
     $sqArtefato = $entityArtefato->getSqArtefato();
     $entityUltimoTramite = $this->_getRepository('app:VwUltimoTramiteArtefato')->find($sqArtefato);
     $sqPessoaLogada = (int) \Core_Integration_Sica_User::getPersonId();
     $sqUnidadeLogada = (int) \Core_Integration_Sica_User::getUserUnit();
     $serviceTramite = $this->getServiceLocator()->getService('TramiteArtefato');
     $dtoSearchArtefato = \Core_Dto::factoryFromData(array('sqArtefato' => $sqArtefato), 'search');
     /**
      * Se não tem ultimo Tramite é porque o artefato ainda não foi corrigido.
      * Verificar, mesmo assim, se tem tramite pois a view de ultimo tramite faz join
      * que pode não retornar registro caso documento não tenha sido corrido
      */
     if (!$entityUltimoTramite) {
         $objZendDate = \Zend_Date::now();
         $dataTramite = array('sqArtefato' => $sqArtefato, 'sqPessoaDestino' => $sqUnidadeLogada, 'sqPessoaDestinoInterno' => $sqPessoaLogada, 'sqUnidadeOrgTramite' => $sqUnidadeLogada, 'sqStatusTramite' => \Core_Configuration::getSgdoceStatusTramiteRecebido(), 'dtTramite' => $objZendDate, 'sqPessoaTramite' => $sqPessoaLogada, 'inImpresso' => TRUE, 'nuTramite' => $serviceTramite->getNextTramiteNumber($dtoSearchArtefato));
         $entityDtoTramite = $serviceTramite->montaEntidateTramite($dataTramite);
         $entityPessoaRecebimento = $this->getEntityManager()->getPartialReference('app:VwPessoa', $sqPessoaLogada);
         $entityDtoTramite->getEntity()->setSqPessoaRecebimento($entityPessoaRecebimento);
         $objZendDateRecebimento = clone $objZendDate;
         $entityDtoTramite->getEntity()->setDtRecebimento($objZendDateRecebimento->addSecond(1));
         $entityTramite = $serviceTramite->save($entityDtoTramite);
     } else {
         $sqPessoaRecebimento = $entityUltimoTramite->getSqPessoaRecebimento()->getSqPessoa();
         $sqPessoaDestino = $entityUltimoTramite->getSqPessoaDestino()->getSqPessoa();
         /**
          * caso o ultimo tramite do artefato não for da pessoa logada
          * deve-se registrar um tramite para pessoa logada (SGI) para que este
          * possa encaminhar para quem solicitou a desanexação
          */
         if ($sqPessoaRecebimento != $sqPessoaLogada || $sqPessoaDestino != $sqUnidadeLogada) {
             $dtoSearchArtefato = \Core_Dto::factoryFromData(array('sqArtefato' => $sqArtefato), 'search');
             $objZendDate = \Zend_Date::now();
             $dataTramite = array('sqArtefato' => $sqArtefato, 'sqPessoaDestino' => $sqUnidadeLogada, 'sqPessoaDestinoInterno' => $sqPessoaLogada, 'sqUnidadeOrgTramite' => $sqUnidadeLogada, 'sqStatusTramite' => \Core_Configuration::getSgdoceStatusTramiteRecebido(), 'dtTramite' => $objZendDate, 'sqPessoaTramite' => $sqPessoaLogada, 'inImpresso' => TRUE, 'nuTramite' => $serviceTramite->getNextTramiteNumber($dtoSearchArtefato));
             $entityDtoTramite = $serviceTramite->montaEntidateTramite($dataTramite);
             $entityPessoaRecebimento = $this->getEntityManager()->getPartialReference('app:VwPessoa', $sqPessoaLogada);
             $entityDtoTramite->getEntity()->setSqPessoaRecebimento($entityPessoaRecebimento);
             $objZendDateRecebimento = clone $objZendDate;
             $entityDtoTramite->getEntity()->setDtRecebimento($objZendDateRecebimento->addSecond(1));
             $entityTramite = $serviceTramite->save($entityDtoTramite);
         }
     }
     return $this;
 }