Exemplo n.º 1
0
 /**
  * método para persistencia  - Grau de Acesso
  * @param \Core_Dto_Search $dto
  */
 public function alterarArtefato($dto)
 {
     $sqTipoDocumento = $this->_getRepository('app:TipoDocumento')->find($dto->getSqTipoDocumento());
     $criteria = array('sqAssunto' => $dto->getSqAssunto(), 'sqTipoArtefato' => \Core_Configuration::getSgdoceTipoArtefatoDossie());
     $sqTipoArtefatoAssunto = $this->_getRepository('app:TipoArtefatoAssunto')->findBy($criteria);
     $entity = $this->_getRepository('app:Artefato')->find($dto->getSqArtefato());
     $entity->setNuArtefato($dto->getNuArtefato());
     $entity->setSqTipoDocumento($sqTipoDocumento);
     $entity->setTxAssuntoComplementar($dto->getTxAssuntoComplementar());
     $entity->setSqTipoArtefatoAssunto($this->_getRepository('app:TipoArtefatoAssunto')->find($sqTipoArtefatoAssunto[0]->getSqTipoArtefatoAssunto()));
     $entityArtefatoDossie = $this->_getRepository('app:ArtefatoDossie')->find($dto->getSqArtefato());
     if (!$entityArtefatoDossie) {
         $entityArtefatoDossie = new \Sgdoce\Model\Entity\ArtefatoDossie();
     }
     $entityArtefatoDossie->setNoTitulo($dto->getNoTitulo());
     $entityArtefatoDossie->setTxObservacao($dto->getTxObservacao());
     $entityArtefatoDossie->setSqArtefato($entity);
     $this->getEntityManager()->persist($entityArtefatoDossie);
     $this->getEntityManager()->flush($entityArtefatoDossie);
     //Persistir PessoaAssinanteArtefato
     $this->persistPessoaAssinanteArtefato($entity, $dto);
     self::_salvaOrigem($entity, $dto);
     // RN - Caso não exista Grau de Acesso ao Artefato sera por default publico(1)
     if (!$dto->getSqGrauAcesso()) {
         $data = array('sqGrauAcesso' => \Core_Configuration::getSgdoceGrauAcessoPublico());
         $dto = new \Core_Dto_Mapping($data, array_keys($data));
         $sqGrauAcesso = $this->_getRepository('app:GrauAcesso')->find($dto->getSqGrauAcesso());
     } else {
         $sqGrauAcesso = $this->_getRepository('app:GrauAcesso')->find($dto->getSqGrauAcesso());
     }
     // realizando a persistencia do Grau de Acesso
     $test = $this->persistGrauAcessoArtefato($entity, $sqGrauAcesso);
     $this->getEntityManager()->persist($entity);
     $this->getEntityManager()->flush($entity);
 }
Exemplo n.º 2
0
 /**
  * Metódo que realiza o post Save.
  * @param Object $entity
  * @param Object $dto
  */
 public function postSave($entity, $dto = NULL)
 {
     try {
         // RN - Caso não exista Grau de Acesso ao Artefato sera por default publico(1)
         if (!$dto->getSqGrauAcesso()) {
             $data = array('sqGrauAcesso' => \Core_Configuration::getSgdoceGrauAcessoPublico());
             $dtoAcesso = new \Core_Dto_Mapping($data, array_keys($data));
             $sqGrauAcesso = $this->_getRepository('app:GrauAcesso')->find($dtoAcesso->getSqGrauAcesso());
         } else {
             $sqGrauAcesso = $this->_getRepository('app:GrauAcesso')->find($dto->getSqGrauAcesso());
         }
         // realizando a persistencia do Grau de Acesso
         $this->getServiceLocator()->getService('Dossie')->persistGrauAcessoArtefato($entity, $sqGrauAcesso);
         $strMessage = NULL;
         if ($this->_firstTramite) {
             $strMessage = $this->getServiceLocator()->getService('HistoricoArtefato')->getMessage('MH005', $entity->getDtCadastro()->get(\Zend_Date::DATETIME_MEDIUM), \Core_Integration_Sica_User::getUserName());
             $nuOcorrencia = \Core_Configuration::getSgdoceSqOcorrenciaCadastrar();
         } else {
             $strMessage = $this->getServiceLocator()->getService('HistoricoArtefato')->getMessage('MH006', \Zend_Date::now()->get(\Zend_Date::DATETIME_MEDIUM), \Core_Integration_Sica_User::getUserName());
             $nuOcorrencia = \Core_Configuration::getSgdoceSqOcorrenciaAlterar();
         }
         $this->getServiceLocator()->getService('HistoricoArtefato')->registrar($entity->getSqArtefato(), $nuOcorrencia, $strMessage);
         // verificando atributo
         // noResponsavelAssinatura vem o sqPessoa selecionado no autocomplete
         if ($dto->getNoResponsavelAssinatura() != NULL) {
             /**
              * em caso de update de documento de origem externa ou com tipo de documento sem assinatura e que não tiver assinante
              * efetua a exclusão caso ja tenha sido preenchido
              * anteriormente
              */
             if ($entity->getSqArtefato() && !$dto->getNoResponsavelAssinatura()) {
                 $this->_checkExcluirAssinante($entity, $dto);
             } else {
                 $sqPessoaResponsavelAssinatura = $dto->getNoResponsavelAssinatura_hidden() ? $dto->getNoResponsavelAssinatura_hidden() : $dto->getNoResponsavelAssinatura();
                 $noPessoaResponsavelAssinatura = $dto->getNoResponsavelAssinatura_autocomplete() ? $dto->getNoResponsavelAssinatura_autocomplete() : $dto->getNoResponsavelAssinatura();
                 if (!is_numeric($sqPessoaResponsavelAssinatura)) {
                     throw new \Core_Exception_ServiceLayer_Verification('Ocorreu um erro na identificação do assintante do documento. ' . "Preencha o campo <b>Assinatura</b> novamente.");
                 }
                 $entityPessoa = $this->pessoaCorporativoSgdoce($sqPessoaResponsavelAssinatura, $noPessoaResponsavelAssinatura);
                 $pessoaArtefato = $this->getServiceLocator()->getService('Artefato')->cadastrarPessoaArtefato($entity, $entityPessoa, \Core_Configuration::getSgdocePessoaFuncaoAssinatura());
                 $this->getEntityManager()->persist($pessoaArtefato);
                 $this->getEntityManager()->flush($pessoaArtefato);
                 // verificando se existe registro em PessoaAssinanteArtefato
                 if ($dto->getProcedenciaInterno() != 'externo') {
                     //só quando é unidade
                     if ($dto->getSqPessoaOrigem() != '') {
                         $sqPessoaOrigem = NULL;
                     } else {
                         $sqPessoaOrigem = $dto->getSqPessoaIcmbio();
                     }
                     $pessoaUnidadeOrg = $this->hasPessoaUnidadeOrg($entityPessoa, $dto->getNoPessoaFuncaoAssinante(), $sqPessoaOrigem);
                     $criteria = array('sqArtefato' => $entity->getSqArtefato());
                     $entPessoaAssinante = $this->_getRepository('app:PessoaAssinanteArtefato')->findOneBy($criteria);
                     // verificando se existe registro
                     if (count($entPessoaAssinante)) {
                         // atualizando PessoaAssinanteArtefato
                         $entPessoaAssinante->setSqPessoaUnidadeOrg($pessoaUnidadeOrg);
                         if ($dto->getNoPessoaFuncaoAssinante() != $entPessoaAssinante->getNoCargoAssinante()) {
                             $entPessoaAssinante->setNoCargoAssinante($dto->getNoPessoaFuncaoAssinante());
                         }
                     } else {
                         // Preparando Entidade para salvar
                         /** @var PessoaAssinanteArtefato $resPessoaAssinante */
                         $entPessoaAssinante = $this->_newEntity('app:PessoaAssinanteArtefato');
                         //                            $entPessoaAssinante->setSqArtefato($this->_getRepository('app:Artefato')->find($entity->getSqArtefato()));
                         $entPessoaAssinante->setSqArtefato($entity);
                         $entPessoaAssinante->setSqPessoaUnidadeOrg($pessoaUnidadeOrg);
                         $entPessoaAssinante->setNoCargoAssinante($dto->getNoPessoaFuncaoAssinante());
                     }
                     // salvando PessoaAssinanteArtefato
                     $this->getEntityManager()->persist($entPessoaAssinante);
                     $this->getEntityManager()->flush($entPessoaAssinante);
                 }
             }
         } else {
             /**
              * em caso de update de documento de origem externa e não tiver assinante efetua a exclusão caso ja tenha sido preenchido
              * anteriormente
              */
             $this->_checkExcluirAssinante($entity, $dto);
         }
         //sqPrazo = 1 (data) e sqPrazo = 2 (dias)
         $entity->setDtPrazo($dto->getSqPrazo() == 2 ? NULL : $dto->getDtPrazo() != '' ? $dto->getDtPrazo() : NULL);
         $entity->setNuDiasPrazo($dto->getNuDiasPrazo() == '' ? NULL : $dto->getNuDiasPrazo());
         //Tira os Espaços do 'enter' para salvar com 250 caracteres
         $txAssuntoComplementar = $this->getServiceLocator()->getService('MinutaEletronica')->fixNewlines($entity->getTxAssuntoComplementar());
         $entity->setTxAssuntoComplementar(!$txAssuntoComplementar ? NULL : $txAssuntoComplementar);
         // salvando Origem e Destino
         self::salvaOrigemDestino($entity, $dto);
         if ($entity->getNuDigital() && !$entity->getNuDigital() instanceof \Sgdoce\Model\Entity\EtiquetaNupSiorg) {
             $entityEtiquetaNupSiorg = $this->getEntityManager()->getPartialReference('app:EtiquetaNupSiorg', $entity->getNuDigital());
             $entity->setNuDigital($entityEtiquetaNupSiorg);
         }
         // persistindo informacao
         $this->getEntityManager()->persist($entity);
         $this->getEntityManager()->flush($entity);
         /*
          * ##### INTERESSADO #####
          *
          * só é postado no create, em caso de edit os interessados são
          * manutenidos no proprio formulario
          *
          */
         if ($dto->getDataInteressado()) {
             $dataIntessado = $dto->getDataInteressado();
             foreach ($dataIntessado->getApi() as $method) {
                 $line = $dataIntessado->{$method}();
                 //metodo foi copiado e adaptado de Artefato_PessoaController::addInteressadoAction()
                 $add = $this->addInteressado(array('noPessoa' => $line->getNoPessoa(), 'unidFuncionario' => $line->getUnidFuncionario(), 'sqPessoaCorporativo' => $line->getSqPessoaCorporativo(), 'sqTipoPessoa' => $line->getSqTipoPessoa(), 'sqPessoaFuncao' => $line->getSqPessoaFuncao(), 'sqArtefato' => $entity->getSqArtefato()));
                 if (!$add) {
                     throw new \Core_Exception_ServiceLayer($line->getNoPessoa() . ' já é um interessado deste documento.');
                 }
             }
         }
         /*
          * ##### REFERÊNCIA (VINCULO) #####
          *
          * só é postado no create, em caso de edit os vinculos são
          * manutenidos no proprio formulario
          *
          */
         if ($dto->getDataVinculo()) {
             //só é postado no create
             $dataVinculo = $dto->getDataVinculo();
             foreach ($dataVinculo->getApi() as $method) {
                 $gridLine = $dataVinculo->{$method}();
                 //metodo foi copiado e adaptado de Artefato_DocumentoController::addDocumentoEletronicoAction()
                 $add = $this->addVinculo(array('nuDigital' => $gridLine->getNuDigital(), 'nuArtefatoVinculacao' => $gridLine->getNuArtefatoVinculacao(), 'sqTipoArtefato' => $gridLine->getSqTipoArtefato(), 'sqArtefato' => $entity->getSqArtefato(), 'tipoVinculo' => \Core_Configuration::getSgdoceTipoVinculoArtefatoReferencia(), 'inOriginal' => $gridLine->getInOriginal()));
                 if (!$add) {
                     $msg = "A digital <b>{$gridLine->getNuDigital()}</b> já esta vinculada a este documento";
                     if ($gridLine->getSqTipoArtefato() == \Core_Configuration::getSgdoceTipoArtefatoProcesso()) {
                         $msg = "O processo <b>{$gridLine->getNuArtefatoVinculacao()}</b> já esta vinculado a este documento";
                     }
                     throw new \Core_Exception_ServiceLayer($msg);
                 }
             }
         }
         #processar anexos para SIC
         if (true === (bool) $dto->getIsSic() && (int) $dto->getUploader_count() > 0) {
             $this->_processaAnexoSIC($entity, $dto);
         }
         if ($this->_firstTramite) {
             $this->getServiceLocator()->getService('TramiteArtefato')->insertFirstTramite($entity->getSqArtefato());
         }
     } catch (\Exception $e) {
         $this->getEntityManager()->getConnection()->rollback();
         throw $e;
     }
 }
Exemplo n.º 3
0
 /**
  *
  * @param ArtefatoEntity $entArtefato
  * @return boolean
  * @throws \Exception
  */
 private function _migraDocumento(ArtefatoEntity $entArtefato)
 {
     //fecha a conexão com banco
     $this->_closeConnection();
     //        tb_documentos_imagem.flg_publico = [0=>confidencial, 1=publico, 2=>excluido]
     //        tb_documentos_imagem.img_type = [7=>TIF, 8=>PNG, 9=>PDF]
     //        todos o PNG esta excluido (2)
     $sqArtefato = $entArtefato->getSqArtefato();
     $this->_nuDigital = $entArtefato->getNuDigital()->getNuEtiqueta();
     $this->_txDigital = str_pad($this->_nuDigital, 7, '0', STR_PAD_LEFT);
     $arrImagem = $this->_getRepository('app:VwImagemSgdocFisico')->findBy(array('sqArtefato' => $sqArtefato), array('dtInclusao' => 'ASC', 'nuOrdem' => 'ASC'));
     if (!$arrImagem) {
         self::_debug('Sem imagem para processar');
         throw new \Exception("Nenhuma imagem encontrada para a digital {$this->_txDigital}", self::CODE_IMG_NOT_FOUND);
     }
     $this->_setImagePathIn($entArtefato)->_setImagePathOut();
     $this->_arrPdf = array();
     $arrTif = array();
     $sigiloso = false;
     $arrFileNotFound = array();
     self::_debug('Iniciando conversão das imagems caso necessário');
     foreach ($arrImagem as $imagem) {
         $typeFile = $imagem->getInTipoArquivo();
         $filename = $imagem->getTxNomeArquivo() . $this->_extension[$typeFile];
         $fullFilename = $this->_imagePathOut . $filename;
         $stPublico = $imagem->getStPublico();
         $this->_pageCount += $imagem->getInQtdePagina();
         //verifica se alguma imagem é confidencial para setar o grau acesso do artefato
         if ($stPublico === self::ACESSO_CONFIDENCIAL && false === $sigiloso) {
             $sigiloso = true;
         }
         //se o arquivo da imagem não existir no file system registra o nome do arquivo
         if (!file_exists($fullFilename)) {
             $arrFileNotFound[] = $filename;
             continue;
         }
         //adicion tif na stack de conversão
         if ($typeFile == self::ARQUIVO_TIF) {
             $arrTif[] = $fullFilename;
             if (!filesize($fullFilename)) {
                 self::_debug("Digital {$this->_txDigital} com imagem corrompida");
                 throw new \Exception("A digital {$this->_txDigital} possui uma ou mais imagens corrompidas", self::CODE_IMG_CORRUPTED);
             }
         }
         if ($typeFile == self::ARQUIVO_PDF) {
             //se for pdf e possui tif na stack
             //processa os tifs para transformar em pdf
             //antes de adicionar a proxima imagem pdf na stack
             if ($arrTif) {
                 $this->_convertTifToPdf($arrTif, $this->_arrPdf);
                 //limpa a fila de tif após a conversão
                 $arrTif = array();
             }
             $this->_arrPdf[] = $fullFilename;
         }
     }
     if ($arrFileNotFound) {
         self::_debug("O(s) arquivo(s) " . implode(', ', $arrFileNotFound) . " não foi(ram) localizado(s) no diretório de origem ({$this->_imagePathOut}) para digital {$this->_txDigital}");
         //para o processo do artefato da vez
         $this->_unlinkTmpFile();
         throw new \Exception("O(s) arquivo(s) " . implode(', ', $arrFileNotFound) . " não foi(ram) localizado(s) no diretório de origem ({$this->_imagePathOut}) para digital {$this->_txDigital}");
     }
     //por fim se sobrou tif na stack processa novamente
     if ($arrTif) {
         $this->_convertTifToPdf($arrTif);
         //limpa a fila de tif
         $arrTif = array();
     }
     //setar grau de acesso para o artefato
     $sqGrauAcesso = \Core_Configuration::getSgdoceGrauAcessoPublico();
     if ($sigiloso) {
         $sqGrauAcesso = \Core_Configuration::getSgdoceGrauAcessoSigiloso();
     }
     self::_debug('Conversões finalizadas');
     $this->_processMergePdf($entArtefato)->_grauAcesso($entArtefato, $sqGrauAcesso)->_unlinkTmpFile();
 }
Exemplo n.º 4
0
 /**
  *retorna dados da grid
  */
 protected function _factoryParamsExtrasSave($data)
 {
     if (!$data['sqGrauAcesso']) {
         $data['sqGrauAcesso'] = \Core_Configuration::getSgdoceGrauAcessoPublico();
     }
     $entityGrauArtefato = Core_Dto::factoryFromData($data, 'entity', array('entity' => 'Sgdoce\\Model\\Entity\\GrauAcessoArtefato', 'mapping' => array('sqGrauAcesso' => 'Sgdoce\\Model\\Entity\\GrauAcesso', 'sqArtefato' => 'Sgdoce\\Model\\Entity\\Artefato')));
     $sqAssunto = new Core_Dto_Mapping($data, array_keys($data));
     return array($sqAssunto, $entityGrauArtefato);
 }
Exemplo n.º 5
0
 /**
  * @param Core_Model_Entity_Abstract $entity
  * @param type $dto
  */
 public function postInsert($entity, $dto = null, $artefatoProcesso = null, $digital = null)
 {
     $retorno = false;
     $this->getEntityManager()->beginTransaction();
     try {
         // salva o artefato_processo
         $artefatoProcesso->setSqArtefato($entity);
         // Ao autuar um documento sempre vai abrir um volume, iniciando pela página um.
         // Adicionando um volume na linha 148 deste arquivo.
         $artefatoProcesso->setNuVolume(1);
         $artefatoProcesso->setNuPaginaProcesso(1);
         $this->getServiceLocator()->getService('ProcessoEletronico')->saveArtefatoProcesso($artefatoProcesso);
         $arrPesArtDto = array('entity' => 'Sgdoce\\Model\\Entity\\PessoaArtefato', 'mapping' => array('sqPessoaFuncao' => 'Sgdoce\\Model\\Entity\\PessoaFuncao', 'sqPessoaSgdoce' => 'Sgdoce\\Model\\Entity\\PessoaSgdoce', 'sqArtefato' => 'Sgdoce\\Model\\Entity\\Artefato'));
         $arrParams = array();
         $arrParams['sqArtefato'] = $entity->getSqArtefato();
         $arrParams['sqPessoaFuncao'] = \Core_Configuration::getSgdocePessoaFuncaoAutor();
         $arrParams['sqPessoaSgdoce'] = current($this->getServiceLocator()->getService('PessoaSgdoce')->findBy(array('sqPessoaCorporativo' => \Core_Integration_Sica_User::getPersonId())))->getSqPessoaSgdoce();
         $objPessoaArtefatoDto = \Core_Dto::factoryFromData($arrParams, 'entity', $arrPesArtDto);
         $this->getServiceLocator()->getService('PessoaArtefato')->savePessoaArtefato($objPessoaArtefatoDto);
         $this->_salvaOrigem($entity, $dto);
         // RN - Caso não exista Grau de Acesso ao Artefato sera por default publico(1)
         if (!$dto->getSqGrauAcesso()) {
             $data = array('sqGrauAcesso' => \Core_Configuration::getSgdoceGrauAcessoPublico());
             $dtoAcesso = new \Core_Dto_Mapping($data, array_keys($data));
             $sqGrauAcesso = $this->_getRepository('app:GrauAcesso')->find($dtoAcesso->getSqGrauAcesso());
         } else {
             $sqGrauAcesso = $this->_getRepository('app:GrauAcesso')->find($dto->getSqGrauAcesso());
         }
         // realizando a persistencia do Grau de Acesso
         $this->getServiceLocator()->getService('Dossie')->persistGrauAcessoArtefato($entity, $sqGrauAcesso);
         /*
          * ##### INTERESSADO #####
          *
          * só é postado no create, em caso de edit os interessados são
          * manutenidos no proprio formulario
          *
          */
         if ($dto->getDataInteressado()) {
             $dataIntessado = $dto->getDataInteressado();
             foreach ($dataIntessado->getApi() as $method) {
                 $line = $dataIntessado->{$method}();
                 //metodo foi copiado e adaptado de Artefato_PessoaController::addInteressadoAction()
                 $add = $this->getServiceLocator()->getService('Documento')->addInteressado(array('noPessoa' => $line->getNoPessoa(), 'unidFuncionario' => $line->getUnidFuncionario(), 'sqPessoaCorporativo' => $line->getSqPessoaCorporativo(), 'sqTipoPessoa' => $line->getSqTipoPessoa(), 'sqPessoaFuncao' => $line->getSqPessoaFuncao(), 'sqArtefato' => $entity->getSqArtefato()));
                 if (!$add) {
                     throw new \Core_Exception_ServiceLayer($line->getNoPessoa() . ' já é um interessado deste documento.');
                 }
             }
         }
         /**
          * #### VOLUME ####
          */
         $sqPessoaAbertura = \Core_Integration_Sica_User::getPersonId();
         $sqUnidadeOrgAbertura = \Core_Integration_Sica_User::getUserUnit();
         $entPessoaAbertura = $this->getEntityManager()->getPartialReference('app:VwPessoa', $sqPessoaAbertura);
         $entUnidadeOrgAbertura = $this->getEntityManager()->getPartialReference('app:VwUnidadeOrg', $sqUnidadeOrgAbertura);
         $entVolume = $this->_newEntity('app:ProcessoVolume');
         $entVolume->setSqArtefato($entity);
         $entVolume->setNuVolume(1);
         $entVolume->setNuFolhaInicial(1);
         $entVolume->setDtAbertura(\Zend_Date::now());
         $entVolume->setSqPessoaAbertura($entPessoaAbertura);
         $entVolume->setSqUnidadeOrgAbertura($entUnidadeOrgAbertura);
         $this->getEntityManager()->persist($entVolume);
         /*
          * ##### (PEÇA) #####
          */
         $this->getServiceLocator()->getService('ArtefatoVinculo')->inserirPeca(array('parent' => $entity, 'child' => $digital), \Core_Configuration::getSgdoceTipoVinculoArtefatoAutuacao());
         // #HistoricoArtefato::save();
         $nuDigital = $digital->getNuDigital()->getNuEtiqueta();
         $dataAtual = new \Zend_Date(\Zend_Date::now());
         $nuProcesso = $this->getServiceLocator()->getService("Processo")->formataProcessoAmbitoFederal($entity);
         $strMessage = $this->getServiceLocator()->getService('HistoricoArtefato')->getMessage('MH012', $dataAtual->get("dd/MM/yyyy HH:mm:ss"), $nuProcesso);
         $this->getServiceLocator()->getService('HistoricoArtefato')->registrar($entity->getSqArtefato(), \Core_Configuration::getSgdoceSqOcorrenciaCadastrar(), $strMessage);
         // insere tramite
         $this->getServiceLocator()->getService('TramiteArtefato')->insertFirstTramite($entity->getSqArtefato());
         $this->getMessaging()->addSuccessMessage("Documento autuado gerando o processo " . $nuProcesso, "User");
         $retorno = $this->getEntityManager()->commit();
     } catch (\Exception $objException) {
         $this->getEntityManager()->rollback();
         $this->getMessaging()->addErrorMessage("[" . $objException->getCode() . "] " . $objException->getMessage(), "User");
         $retorno = $objException;
     }
     $this->getMessaging()->dispatchPackets();
     return $retorno;
 }