Skip to content

Commit

Permalink
Merge pull request #99 from realfabecker/adiciona-zAddProtMsg-Tools
Browse files Browse the repository at this point in the history
adicionado metodo zAddProtMsg para uso em sefazInutiliza
  • Loading branch information
maisonsakamoto authored Mar 31, 2017
2 parents 1af7606 + 15c630a commit e374c36
Showing 1 changed file with 51 additions and 7 deletions.
58 changes: 51 additions & 7 deletions src/Tools.php
Original file line number Diff line number Diff line change
Expand Up @@ -434,18 +434,62 @@ public function sefazInutiliza(
}
//tratar dados de retorno
$aRetorno = Response::readReturnSefaz($servico, $retorno);
//Comentado por não ter implementada a função de zAddProtMsg
// if ($aRetorno['cStat'] == '102') {
// $retorno = $this->zAddProtMsg('ProcInutCTe', 'inutCTe', $signedMsg, 'retInutCTe', $retorno);
if ($salvarMensagens) {
$filename = "$sAno-$this->modelo-$sSerie-".$sInicio."_".$sFinal."-procInutCTe.xml";
$this->zGravaFile('cte', $tpAmb, $filename, $retorno, 'inutilizadas');
if ($aRetorno['cStat'] == '102') {
$retorno = $this->zAddProtMsg('ProcInutCTe', 'inutCTe', $signedMsg, 'retInutCTe', $retorno);
if ($salvarMensagens) {
$filename = "$sAno-$this->modelo-$sSerie-".$sInicio."_".$sFinal."-procInutCTe.xml";
$this->zGravaFile('cte', $tpAmb, $filename, $retorno, 'inutilizadas');
}
}
// }
return (string) $retorno;
}

/**
* zAddProtMsg
*
* @param string $tagproc
* @param string $tagmsg
* @param string $xmlmsg
* @param string $tagretorno
* @param string $xmlretorno
* @return string
*/
protected function zAddProtMsg($tagproc, $tagmsg, $xmlmsg, $tagretorno, $xmlretorno)
{
$doc = new Dom();
$doc->loadXMLString($xmlmsg);
$nodedoc = $doc->getNode($tagmsg, 0);
$procver = $nodedoc->getAttribute("versao");
$procns = $nodedoc->getAttribute("xmlns");
$doc1 = new Dom();
$doc1->loadXMLString($xmlretorno);
$nodedoc1 = $doc1->getNode($tagretorno, 0);
$proc = new \DOMDocument('1.0', 'utf-8');
$proc->formatOutput = false;
$proc->preserveWhiteSpace = false;
//cria a tag nfeProc
$procNode = $proc->createElement($tagproc);
$proc->appendChild($procNode);
//estabele o atributo de versão
$procNodeAtt1 = $procNode->appendChild($proc->createAttribute('versao'));
$procNodeAtt1->appendChild($proc->createTextNode($procver));
//estabelece o atributo xmlns
$procNodeAtt2 = $procNode->appendChild($proc->createAttribute('xmlns'));
$procNodeAtt2->appendChild($proc->createTextNode($procns));
//inclui a tag inutNFe
$node = $proc->importNode($nodedoc, true);
$procNode->appendChild($node);
//inclui a tag retInutNFe
$node = $proc->importNode($nodedoc1, true);
$procNode->appendChild($node);
//salva o xml como string em uma variável
$procXML = $proc->saveXML();
//remove as informações indesejadas
$procXML = Strings::clearProt($procXML);
return $procXML;
}

/*
* zValidParamInut
*
* @param string $xJust
Expand Down

0 comments on commit e374c36

Please sign in to comment.