/** * Página inicial do módulo padrão */ public function indexAction() { // Verifica se o usuário está logado parent::checkIdentity(); // Zera as permissões do contribuinte $oSessao = new Zend_Session_Namespace('nfse'); $oSessao->contribuinte = NULL; $this->view->contribuinte = NULL; $this->_session->id = NULL; $this->view->iUsuarioEscolhido = $oSessao->iUsuarioEscolhido; $aAuth = Zend_Session::namespaceGet('Zend_Auth'); $oUsuario = Administrativo_Model_Usuario::getById($aAuth['storage']['id']); if ($oUsuario->getTipo() == 3) { $oBaseUrl = new Zend_View_Helper_BaseUrl(); // Verifica se possui cadastros eventuais $aCadastrosEventuais = Contribuinte_Model_CadastroPessoa::getCadastrosParaLiberacao(); if (count($aCadastrosEventuais) > 0) { $sMensagem = "Hà " . count($aCadastrosEventuais) . " Cadastros Eventuais Pendentes <br/>"; $sMensagem .= " <a href=" . $oBaseUrl->baseUrl("/fiscal/usuario-eventual/listar-novos-cadastros") . "> Verificar </a>"; DBSeller_Plugin_Notificacao::addAviso('F001', $sMensagem); } // Verifica se possui solicitações de cancelamento $aSolicitacoesCancelamento = Contribuinte_Model_SolicitacaoCancelamento::getAll(); if (count($aSolicitacoesCancelamento) > 0) { $sMensagem = "Hà " . count($aSolicitacoesCancelamento) . " Solicitações de cancelamento de NFS-e <br/>"; $sMensagem .= " <a href=" . $oBaseUrl->baseUrl("/fiscal/cancelamento-nfse/consultar") . "> Verificar </a>"; DBSeller_Plugin_Notificacao::addAviso('F002', $sMensagem); } } // Tiver apenas um módulo redireciona para a default/index if (isset($this->view->user) && count($this->view->user->getModulos()) == 1) { $aModulos = each($this->view->user->getModulos()); $sModulo = strtolower($aModulos['value']->getNome()); $this->_redirector->gotoSimple('index', 'index', $sModulo); } // Recria as permissões do usuário new DBSeller_Acl_Setup(TRUE); }
/** * Tela inicial do módulo fiscal * * @return void */ public function indexAction() { $aAuth = Zend_Session::namespaceGet('Zend_Auth'); $oUsuario = Administrativo_Model_Usuario::getById($aAuth['storage']['id']); if ($oUsuario->getTipo() == 3) { $oBaseUrl = new Zend_View_Helper_BaseUrl(); // Verifica se possui cadastros eventuais $aCadastrosEventuais = Contribuinte_Model_CadastroPessoa::getCadastrosParaLiberacao(); if (count($aCadastrosEventuais) > 0) { $sMensagem = "Hà " . count($aCadastrosEventuais) . " Cadastros Eventuais Pendentes <br/>"; $sMensagem .= " <a href=" . $oBaseUrl->baseUrl("/fiscal/usuario-eventual/listar-novos-cadastros") . "> Verificar </a>"; DBSeller_Plugin_Notificacao::addAviso('F001', $sMensagem); } // Verifica se possui solicitações de cancelamento $aSolicitacoesCancelamento = Contribuinte_Model_SolicitacaoCancelamento::getAll(); if (count($aSolicitacoesCancelamento) > 0) { $sMensagem = "Hà " . count($aSolicitacoesCancelamento) . " Solicitações de cancelamento de NFS-e <br/>"; $sMensagem .= " <a href=" . $oBaseUrl->baseUrl("/fiscal/cancelamento-nfse/consultar") . "> Verificar </a>"; DBSeller_Plugin_Notificacao::addAviso('F002', $sMensagem); } } $this->view->oculta_breadcrumbs = TRUE; }
/** * Verifica se o cadastro está apto a ser liberado/bloqueado * * @param Contribuinte_Model_CadastroPessoa $oCadastroPessoa * @throws Exception * @return void */ protected function validarLiberacaoUsuario(Contribuinte_Model_CadastroPessoa $oCadastroPessoa) { if ($oCadastroPessoa->getEntity()->getTipoLiberacao() != '') { $sTextoLiberacao = ''; switch ($oCadastroPessoa->getEntity()->getTipoLiberacao()) { case Contribuinte_Model_CadastroPessoa::TIPO_LIBERACAO_USUARIO: case Contribuinte_Model_CadastroPessoa::TIPO_LIBERACAO_USUARIO_CGM: $sTextoLiberacao = ' já consta como liberado. Procedimento cancelado'; break; case Contribuinte_Model_CadastroPessoa::TIPO_LIBERACAO_USUARIO_BLOQUEADO: $sTextoLiberacao = ' já consta como bloqueado. Procedimento cancelado'; break; } $sErroMensagem = "Cadastro do Contribuinte {$oCadastroPessoa->getEntity()->getNome()} {$sTextoLiberacao}"; throw new Exception($sErroMensagem); } }
/** * 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); }