public function testIdentificacao() { $aList = array('consReciNFe' => 'consReciNFe', 'consSitNFe' => 'consSitNFe', 'consStatServ' => 'consStatServ', 'distDFeInt' => 'distDFeInt', 'enviNFe' => 'enviNFe', 'inutNFe' => 'inutNFe', 'NFe' => 'nfe', 'procInutNFe' => 'procInutNFe', 'procNFe' => 'procNFe', 'resEvento' => 'resEvento', 'resNFe' => 'resNFe', 'retConsReciNFe' => 'retConsReciNFe', 'retConsSitNFe' => 'retConsSitNFe', 'retConsStatServ' => 'retConsStatServ', 'retDistDFeInt' => 'retDistDFeInt', 'retEnviNFe' => 'retEnviNFe', 'retInutNFe' => 'retInutNFe'); $aResp = array(); Identify::setListSchemesId($aList); $xml = dirname(dirname(dirname(__FILE__))) . '/fixtures/xml/NFe/35150158716523000119550010000000071000000076-protNFe.xml'; $schem = Identify::identificacao($xml, $aResp); $this->assertEquals($schem, 'nfe'); }
public static function identificar($xml = '', &$aResp = array()) { $aList = array('consReciNFe' => 'consReciNFe', 'consSitNFe' => 'consSitNFe', 'consStatServ' => 'consStatServ', 'distDFeInt' => 'distDFeInt', 'enviNFe' => 'enviNFe', 'inutNFe' => 'inutNFe', 'NFe' => 'nfe', 'procInutNFe' => 'procInutNFe', 'procNFe' => 'procNFe', 'resEvento' => 'resEvento', 'resNFe' => 'resNFe', 'retConsReciNFe' => 'retConsReciNFe', 'retConsSitNFe' => 'retConsSitNFe', 'retConsStatServ' => 'retConsStatServ', 'retDistDFeInt' => 'retDistDFeInt', 'retEnviNFe' => 'retEnviNFe', 'retInutNFe' => 'retInutNFe'); Identify::setListSchemesId($aList); $schem = Identify::identificacao($xml, $aResp); $dom = $aResp['dom']; $node = $dom->getElementsByTagName($aResp['tag'])->item(0); if ($schem == 'nfe') { //se for um nfe então é necessário pegar a versão // em outro node infNFe $node1 = $dom->getElementsByTagName('infNFe')->item(0); $versao = $node1->getAttribute('versao'); } else { $versao = $node->getAttribute('versao'); } $aResp['versao'] = $versao; $aResp['xml'] = $dom->saveXML($node); return $schem; }
public static function identificar($xml = '', &$aResp = array()) { $aList = array('consReciCTe' => 'consReciCTe', 'consSitCTe' => 'consSitCTe', 'consStatServCTe' => 'consStatServCTe', 'enviCTe' => 'enviCTe', 'evCancCTe' => 'evCancCTe', 'evEncCTe' => 'evEncCTe', 'CTe' => 'cte', 'eventoCTe' => 'eventoCTe', 'procEventoCTe' => 'procEventoCTe', 'mdfeProc' => 'procCTe', 'retConsReciCTe' => 'retConsReciCTe', 'retConsSitCTe' => 'retConsSitCTe', 'retConsStatServCTe' => 'retConsStatServCTe', 'retEnviCTe' => 'retEnviCTe', 'retEventoCTe' => 'retEventoCTe'); Identify::setListSchemesId($aList); $schem = Identify::identificacao($xml, $aResp); $dom = $aResp['dom']; $node = $dom->getElementsByTagName($aResp['tag'])->item(0); if ($schem == 'cte') { //se for um nfe então é necessário pegar a versão // em outro node infNFe $node1 = $dom->getElementsByTagName('infCte')->item(0); $versao = $node1->getAttribute('versao'); } else { $versao = $node->getAttribute('versao'); } $aResp['versao'] = $versao; $aResp['xml'] = $dom->saveXML($node); return $schem; }
/** * gravaXML * grava o xml do documento fiscal na estrutura de pastas * em path indicar por exemplo /var/www/nfe ou /dados/cte ou /arquivo/mdfe * ou seja as pastas principais onde guardar os arquivos * Esse método itá colocar na subpastas [producao] ou [homologacao] * na subpasta [entradas] e na subpasta [ANOMES] * * @param string $path * @return boolean */ public function gravaXML($path = '') { //pode ser NFe, CTe, MDFe e pode ser homologação ou produção //essas informações estão dentro do xml if ($path == '') { return false; } if (!is_dir($path)) { return false; } if (substr($path, -1) == DIRECTORY_SEPARATOR) { $path = substr($path, 0, strlen($path) - 1); } $aResp = array(); $aList = array('NFe' => 'nfe', 'CTe' => 'cte', 'MDFe' => 'mdfe'); Identify::setListSchemesId($aList); $schem = Identify::identificacao($this->xml, $aResp); if ($aResp['chave'] == '') { return false; } $filename = $aResp['chave'] . '-' . $schem . '.xml'; $dirBase = 'homologacao'; if ($aResp['tpAmb'] == '1') { $dirBase = 'producao'; } $aDh = explode('-', $aResp['dhEmi']); $anomes = date('Ym'); if (count($aDh) > 1) { $anomes = $aDh[0] . $aDh[1]; } $completePath = $path . DIRECTORY_SEPARATOR . $dirBase . DIRECTORY_SEPARATOR . 'entradas' . DIRECTORY_SEPARATOR . $anomes; $content = $this->xml; if (!FilesFolders::saveFile($completePath, $filename, $content)) { return false; } return true; }