Exemplo n.º 1
0
 /**
  * Metódo que realiza o save do Artefato
  * @param Object $dtoSearch
  * @return \Sgdoce\Model\Entity\Artefato
  */
 public function saveArtefato(\Core_Dto_Search $dtoSearch)
 {
     $date = new \Zend_Date();
     $this->getEntityManager()->getConnection()->beginTransaction();
     try {
         $sqPessoaSgdoce = $this->_getRepository('app:PessoaSgdoce')->findBySqPessoaCorporativo(\Core_Integration_Sica_User::getPersonId());
         if (empty($sqPessoaSgdoce)) {
             $filter = new \Zend_Filter_Digits();
             $sqPessoaCorporativo = \Core_Integration_Sica_User::getPersonId();
             $data['sqPessoaCorporativo'] = $this->_getRepository('app:VwPessoa')->find($sqPessoaCorporativo);
             $dtoPessoaSearch = \Core_Dto::factoryFromData($data, 'search');
             $cpfCnpjPassaportUnfiltered = $this->getServiceLocator()->getService('VwPessoa')->returnCpfCnpjPassaporte($dtoPessoaSearch);
             $cpfCnpjPassaport = $filter->filter($cpfCnpjPassaportUnfiltered);
             $noPessoaCorporativo = $data['sqPessoaCorporativo']->getNoPessoa();
             $this->addPessoaSgdoce($sqPessoaCorporativo, $noPessoaCorporativo, $cpfCnpjPassaport);
             $sqPessoaSgdoce = $this->_getRepository('app:PessoaSgdoce')->findBySqPessoaCorporativo(\Core_Integration_Sica_User::getPersonId());
         }
         /** @var \Sgdoce\Model\Entity\Artefato $entityArtefato */
         $entityArtefato = $this->_newEntity('app:Artefato');
         //só seta o numero da digital se for documento tipo físico
         if (!$dtoSearch->getInEletronico()) {
             $entityLoteEtiqueta = $this->getEntityManager()->getPartialReference('app:LoteEtiqueta', $dtoSearch->getSqLoteEtiqueta());
             /** @var \Sgdoce\Model\Entity\EtiquetasUso $entityEtiquetasUso */
             $entityEtiquetasUso = $this->_newEntity('app:EtiquetasUso');
             $entityEtiquetasUso->setNuEtiqueta($dtoSearch->getNuDigital());
             $entityEtiquetasUso->setSqLoteEtiqueta($entityLoteEtiqueta);
             //persist Etiquetas Uso
             $this->getEntityManager()->persist($entityEtiquetasUso);
             $this->getEntityManager()->flush($entityEtiquetasUso);
             $entityArtefato->setNuDigital($entityEtiquetasUso);
             $entityArtefato->setSqLoteEtiqueta($entityEtiquetasUso);
         }
         $entityArtefato->setDtPrazo(NULL);
         $entityArtefato->setDtArtefato($date);
         $entityArtefato->setInEletronico($dtoSearch->getInEletronico());
         //persist artefato
         $this->getEntityManager()->persist($entityArtefato);
         $this->getEntityManager()->flush($entityArtefato);
         $sqPessoaFuncao = $this->getEntityManager()->getPartialReference('app:PessoaFuncao', \Core_Configuration::getSgdocePessoaFuncaoAutor());
         /** @var \Sgdoce\Model\Entity\PessoaArtefato $entityPessoaArtefato */
         $entityPessoaArtefato = $this->_newEntity('app:PessoaArtefato');
         $entityPessoaArtefato->setSqArtefato($entityArtefato);
         $entityPessoaArtefato->setSqPessoaSgdoce($sqPessoaSgdoce[0]);
         $entityPessoaArtefato->setSqPessoaFuncao($sqPessoaFuncao);
         $this->getEntityManager()->persist($entityPessoaArtefato);
         $this->getEntityManager()->flush($entityPessoaArtefato);
         // salva o historico do artefato
         $arrDto = array('sqPessoa' => \Core_Integration_Sica_User::getPersonId(), 'sqUnidade' => \Core_Integration_Sica_User::getUserUnit());
         // #HistoricoArtefato::save();
         $strMessage = $this->getServiceLocator()->getService('HistoricoArtefato')->getMessage('MH005');
         $this->getServiceLocator()->getService('HistoricoArtefato')->registrar($entityArtefato->getSqArtefato(), \Core_COnfiguration::getSgdoceSqOcorrenciaCadastrar(), $strMessage);
         $this->getEntityManager()->getConnection()->commit();
     } catch (\Exception $e) {
         $this->getEntityManager()->getConnection()->rollback();
         throw $e;
     }
     return $entityArtefato;
 }