/**
  * Retorna os dados do cadastro da pessoa e do CGM para avaliacao dos dados
  * 
  * @return void
  */
 public function compararAction()
 {
     parent::noTemplate();
     $oDadosRequisicao = $this->getRequest();
     if ($oDadosRequisicao->getParam('id') != '') {
         $oCadastroPessoa = new Contribuinte_Model_CadastroPessoa($oDadosRequisicao->getParam('id'));
         $oCgm = Contribuinte_Model_Cgm::getDadosCgm($oCadastroPessoa->getCpfcnpj());
         $this->view->oCadastroPessoa = $oCadastroPessoa;
         $this->view->oCGM = $oCgm ? $oCgm : new Contribuinte_Model_Cgm();
     }
 }
Ejemplo n.º 2
0
 /**
  * Retorna os dados do CGM vindos atravez do webservice
  * @param $sCpfCnpj
  * @return object
  */
 public static function getDadosCgm($sCpfCnpj)
 {
     if (empty($sCpfCnpj)) {
         throw new Exception('CPF/CNPJ não informado.');
     }
     $oRetornoCgm = WebService_Model_Ecidade::processar('pesquisaCgmByCpfCnpj', array('cpfcnpj' => $sCpfCnpj));
     if ($oRetornoCgm == NULL) {
         return NULL;
     }
     $oCgm = new Contribuinte_Model_Cgm();
     $oCgm->setCodigoCgm($oRetornoCgm->iCodigoCgm);
     $oCgm->setNome($oRetornoCgm->sNome);
     $oCgm->setJuridico($oRetornoCgm->lJuridico);
     $oCgm->setCNPJ(isset($oRetornoCgm->iCnpj) ? $oRetornoCgm->iCnpj : NULL);
     $oCgm->setCPF(isset($oRetornoCgm->iCpf) ? $oRetornoCgm->iCpf : NULL);
     $oCgm->setNumeroLogradouro($oRetornoCgm->sNumero);
     $oCgm->setComplemento($oRetornoCgm->sComplemento);
     $oCgm->setDescricaoMunicipio($oRetornoCgm->sMunicipio);
     $oCgm->setEstado($oRetornoCgm->sUf);
     $oCgm->setEmail($oRetornoCgm->sEmail);
     $oCgm->setCep($oRetornoCgm->sCep);
     $oCgm->setDescricaoLogradouro($oRetornoCgm->sLogradouro);
     $oCgm->setDescricaoBairro($oRetornoCgm->sBairro);
     return $oCgm;
 }
 /**
  * Método para confirmação do usuário eventual [json]
  *
  * @throws Exception
  * @return void
  */
 public function confirmarAction()
 {
     $oFiltro = new Zend_Filter_Digits();
     $aDados = $this->getRequest()->getParams();
     $sCpfCnpj = DBSeller_Helper_Number_Format::unmaskCPF_CNPJ($aDados['cnpjcpf']);
     // Popula o formulario
     $oForm = new Default_Form_LiberacaoCadastro();
     $oForm->populate($aDados);
     // Valida o formulario
     if ($oForm->isValid($aDados)) {
         if ($aDados['hash'] == NULL || $sCpfCnpj == NULL) {
             throw new Exception($this->translate->_('Campo(s) obrigatório(s) não informado(s).'));
         }
         $oDoctrine = Zend_Registry::get('em');
         $oDoctrine->getConnection()->beginTransaction();
         try {
             $oCadastroPessoa = Contribuinte_Model_CadastroPessoa::getByAttribute('hash', $aDados['hash']);
             if ($oCadastroPessoa == NULL) {
                 $sMensagemErro = 'Dados informados não encontrados. Favor entrar em contato com o suporte da prefeitura.';
                 throw new Exception($this->translate->_($sMensagemErro));
             }
             $iTipoLiberacaoUsuarioBloqueado = Contribuinte_Model_CadastroPessoa::TIPO_LIBERACAO_USUARIO_BLOQUEADO;
             if ($oCadastroPessoa->getTipoLiberacao() == $iTipoLiberacaoUsuarioBloqueado) {
                 $sMensagemErro = 'Cadastro foi recusado. Favor entrar em contato com o setor de fiscalização.';
                 throw new Exception($this->translate->_($sMensagemErro));
             }
             if ($sCpfCnpj != $oCadastroPessoa->getCpfcnpj()) {
                 throw new Exception($this->translate->_('CNPJ/CPF informado não é o mesmo informado no cadastro.'));
             }
             $oUsuarioCadastrado = Administrativo_Model_Usuario::getByAttribute('email', $oCadastroPessoa->getEmail());
             if ($oUsuarioCadastrado instanceof Administrativo_Model_Usuario) {
                 $sLink = '<a href="' . $this->view->serverUrl('/auth/login/esqueci-minha-senha/') . '">Clique Aqui</a>';
                 $sMensagemErro = "Já encontramos um cadastro com este email.<br>Caso tenha esquecido sua senha. {$sLink}";
                 throw new Exception($this->translate->_($sMensagemErro));
             }
             $oCgm = Contribuinte_Model_Cgm::getDadosCgm($sCpfCnpj);
             if ($oCadastroPessoa->getTipoLiberacao() == Contribuinte_Model_CadastroPessoa::TIPO_LIBERACAO_USUARIO && $oCgm == NULL) {
                 $sErro = $this->translate->_('Parametros estão inválidos (CGM não existe), ');
                 $sErro .= $this->translate->_('favor entrar em contato com o setor de fiscalização.');
                 throw new Exception($sErro);
             }
             if ($oCadastroPessoa->getTipoLiberacao() == Contribuinte_Model_CadastroPessoa::TIPO_LIBERACAO_USUARIO_CGM && $oCgm == NULL) {
                 $oNovoCgm = new Contribuinte_Model_Cgm();
                 if (strlen($oCadastroPessoa->getCpfCnpj()) >= 14) {
                     $oNovoCgm->setJuridico(TRUE);
                     $oNovoCgm->setCNPJ($oCadastroPessoa->getCpfCnpj());
                 } else {
                     $oNovoCgm->setJuridico(FALSE);
                     $oNovoCgm->setCPF($oCadastroPessoa->getCpfCnpj());
                 }
                 $sDescricaoMunicipio = Default_Model_Cadendermunicipio::getById($oCadastroPessoa->getCidade())->getNome();
                 $oNovoCgm->setNome($oCadastroPessoa->getNome());
                 $oNovoCgm->setEmail($oCadastroPessoa->getEmail());
                 $oNovoCgm->setCodigoIbgeCidade($oCadastroPessoa->getCidade());
                 $oNovoCgm->setDescricaoMunicipio($sDescricaoMunicipio);
                 $oNovoCgm->setEstado($oCadastroPessoa->getEstado());
                 $oNovoCgm->setTelefone($oFiltro->filter($oCadastroPessoa->getTelefone()));
                 $oNovoCgm->setCep($oFiltro->filter($oCadastroPessoa->getCep()));
                 $oNovoCgm->setEnderecoEcidade(FALSE);
                 if ($oCadastroPessoa->getCodBairro()) {
                     $oNovoCgm->setEnderecoEcidade(TRUE);
                 }
                 $oNovoCgm->setCodigoBairro($oCadastroPessoa->getCodBairro());
                 $oNovoCgm->setCodigoLogradouro($oCadastroPessoa->getCodEndereco());
                 $oNovoCgm->setDescricaoBairro($oCadastroPessoa->getBairro());
                 $oNovoCgm->setDescricaoLogradouro($oCadastroPessoa->getEndereco());
                 $oNovoCgm->setNumeroLogradouro($oCadastroPessoa->getNumero());
                 $oNovoCgm->setComplemento($oCadastroPessoa->getComplemento());
                 $oCodigoCgm = $oNovoCgm->persist();
                 $iCodigoCgm = $oCodigoCgm->codigo_cgm;
             } else {
                 $iCodigoCgm = $oCgm->getCodigoCgm();
             }
             $aArraTipoLiberacao = array(Contribuinte_Model_CadastroPessoa::TIPO_LIBERACAO_USUARIO_CGM, Contribuinte_Model_CadastroPessoa::TIPO_LIBERACAO_USUARIO);
             if (in_array($oCadastroPessoa->getTipoLiberacao(), $aArraTipoLiberacao)) {
                 // Usuário do sistema
                 $oUsuarioSistema = new Administrativo_Model_Usuario();
                 $oUsuarioSistema->setNome($oCadastroPessoa->getNome());
                 $oUsuarioSistema->setTelefone($oFiltro->filter($oCadastroPessoa->getTelefone()));
                 $oUsuarioSistema->setLogin($oCadastroPessoa->getCpfCnpj());
                 $oUsuarioSistema->setSenha($aDados['senha']);
                 $oUsuarioSistema->setEmail($oCadastroPessoa->getEmail());
                 $oUsuarioSistema->setHabilitado(TRUE);
                 $oUsuarioSistema->setAdministrativo(FALSE);
                 $oUsuarioSistema->setTipo(Administrativo_Model_TipoUsuario::$CONTRIBUINTE);
                 $oUsuarioSistema->setCgm($iCodigoCgm);
                 $oUsuarioSistema->setCnpj($oCadastroPessoa->getCpfCnpj());
                 $oUsuarioSistema->setPerfil($oCadastroPessoa->getPerfil()->getEntity());
                 $oUsuarioSistema->adicionaAcoes($oCadastroPessoa->getPerfil()->getAcoes());
                 $oUsuarioSistema->persist();
                 // Criamos o usuario eventual;
                 $oUsuarioEventual = new Administrativo_Model_UsuarioContribuinte();
                 $oUsuarioEventual->setCGM($iCodigoCgm);
                 $oUsuarioEventual->setHabilitado(TRUE);
                 $oUsuarioEventual->setTipoContribuinte(2);
                 $oUsuarioEventual->setCnpjCpf($oCadastroPessoa->getCpfCnpj());
                 $oUsuarioEventual->setUsuario($oUsuarioSistema->getEntity());
                 $oUsuarioEventual->copiaPerfilAcoes($oCadastroPessoa->getPerfil());
                 $oUsuarioEventual->persist();
                 // Cadastro de Pessoa
                 $oCadastroPessoa->setHash(NULL);
                 $oCadastroPessoa->persist();
             }
             $oDoctrine->getConnection()->commit();
             $aRetornoJson['status'] = TRUE;
             $aRetornoJson['success'] = $this->translate->_('Cadastro efetuado com sucesso.');
             $aRetornoJson['url'] = $this->view->serverUrl();
         } catch (Exception $oErro) {
             $oDoctrine->getConnection()->rollback();
             if (isset($oCodigoCgm) && isset($oCodigoCgm->codigo_cgm) && Contribuinte_Model_Cgm::removerCgm($oCodigoCgm->codigo_cgm)) {
                 $oLog = Zend_Registry::get('logger');
                 $oLog->log("Erro ao excluir o CGM: {$oCodigoCgm->codigo_cgm}", Zend_Log::INFO, ' ');
             }
             $aRetornoJson['status'] = FALSE;
             $aRetornoJson['error'][] = $oErro->getMessage();
         }
     } else {
         $aRetornoJson['status'] = FALSE;
         $aRetornoJson['fields'] = array_keys($oForm->getMessages());
         $aRetornoJson['error'][] = $this->translate->_('Preencha os dados corretamente.');
     }
     echo $this->getHelper('json')->sendJson($aRetornoJson);
 }