コード例 #1
0
 /**
  * Prepara os dados para o cancelamento da nota
  * @param string $sParametroArquivo
  */
 public function preparaDados($sParametroArquivo)
 {
     $this->oDadosXML = $this->validaXML($sParametroArquivo);
     /**
      * Verifica se existe inconsistencias
      */
     if (count($this->aInconsistencias) == 0) {
         $sCnpj = (string) $this->oDadosXML->IdentificacaoNfse->Cnpj;
         $sNumero = (string) $this->oDadosXML->IdentificacaoNfse->Numero;
         $iInscricaoMunicipal = (string) $this->oDadosXML->IdentificacaoNfse->InscricaoMunicipal;
         $iNumero = (int) substr($sNumero, 4, 11);
         $aAtributosContriobuinte = array("cnpj_cpf" => $sCnpj, "im" => $iInscricaoMunicipal);
         $sAmbiente = Zend_Controller_Front::getInstance()->getRequest()->getActionName();
         if (DBSeller_Plugin_Auth::checkPermissionWebservice($sCnpj, "webservice/{$sAmbiente}/recepcionar-lote-rps")) {
             $aContribuinte = Administrativo_Model_UsuarioContribuinte::getByAttributes($aAtributosContriobuinte);
             foreach ($aContribuinte as $oContribuinte) {
                 $this->oContribuinte = $oContribuinte;
             }
             /**
              * Verifica se existe contribuinte com o CNPJ e Inscrição Municipal informado
              */
             if (empty($this->oContribuinte)) {
                 $this->adicionarInconsistencia('E44');
                 $this->adicionarInconsistencia('E50');
             } else {
                 $iIdContribuinte = $this->oContribuinte->getId();
                 $aAtributosNota = array("id_contribuinte" => $iIdContribuinte, "nota" => $iNumero);
                 /**
                  * Retornar a entidade do array de notas
                  */
                 $aNotas = Contribuinte_Model_Nota::getByAttributes($aAtributosNota);
                 foreach ($aNotas as $oNota) {
                     $this->oNota = $oNota;
                 }
                 /**
                  * Verifica se existe nota
                  */
                 if (empty($this->oNota)) {
                     $this->adicionarInconsistencia('E78');
                 } else {
                     $bNotaCancelada = $this->oNota->getCancelada();
                     /**
                      * Verifica se a nota já está cancelada
                      */
                     if ($bNotaCancelada) {
                         $this->adicionarInconsistencia('E79');
                     }
                 }
             }
         } else {
             $this->adicionarInconsistencia('E157');
             $this->adicionarInconsistencia('Usuário sem permissão!');
         }
     }
 }