Ejemplo n.º 1
0
 /**
  * zGetInfo
  * Busca informações do XML
  * para uso no sefazEPEC
  * @param string $xml
  * @return array
  */
 protected function zGetInfo($xml)
 {
     $dom = new Dom();
     $dom->loadXMLString($xml);
     $ide = $dom->getNode('ide');
     $emit = $dom->getNode('emit');
     $dest = $dom->getNode('dest');
     $enderDest = $dest->getElementsByTagName('enderDest')->item(0);
     $icmsTot = $dom->getNode('ICMSTot');
     $resp = array('chave' => $dom->getChave('infNFe'), 'dhCont' => $dom->getValue($ide, 'dhCont'), 'xJust' => $dom->getValue($ide, 'xJust'), 'cOrgaoAutor' => $dom->getValue($ide, 'cUF'), 'tpAutor' => '1', 'dhEmi' => $dom->getValue($ide, 'dhEmi'), 'tpNF' => $dom->getValue($ide, 'tpNF'), 'IE' => $dom->getValue($emit, 'IE'), 'UF' => $dom->getValue($enderDest, 'UF'), 'CNPJ' => $dom->getValue($dest, 'CNPJ'), 'CPF' => $dom->getValue($dest, 'CPF'), 'idEstrangeiro' => $dom->getValue($dest, 'idEstrangeiro'), 'IEdest' => $dom->getValue($dest, 'IE'), 'vNF' => $dom->getValue($icmsTot, 'vNF'), 'vICMS' => $dom->getValue($icmsTot, 'vICMS'), 'vST' => $dom->getValue($icmsTot, 'vST'));
     return $resp;
 }
Ejemplo n.º 2
0
 /**
  * verificaValidade
  * @param string $pathXmlFile
  * @param array $aRetorno
  * @return boolean
  * @throws Exception\InvalidArgumentException
  */
 public function verificaValidade($pathXmlFile = '', &$aRetorno = array())
 {
     $aRetorno = array();
     if (!file_exists($pathXmlFile)) {
         $msg = "Arquivo não localizado!!";
         throw new Exception\InvalidArgumentException($msg);
     }
     //carrega a NFe
     $xml = Files\FilesFolders::readFile($pathXmlFile);
     $this->oCertificate->verifySignature($xml, 'infMDFe');
     //obtem o chave da NFe
     $docnfe = new Dom();
     $docnfe->loadXMLFile($pathXmlFile);
     $tpAmb = $docnfe->getNodeValue('tpAmb');
     $chMDFe = $docnfe->getChave('infMDFe');
     $this->sefazConsultaChave($chMDFe, $tpAmb, $aRetorno);
     if ($aRetorno['cStat'] != '100') {
         return false;
     }
     return true;
 }
Ejemplo n.º 3
0
 /**
  * assinaDoc
  * @param string $xml
  * @param string $tipo nfe, cte, ou mdfe
  * @param string $tag Nome da tag a ser assinada 
  * @param boolean $saveFile APENAS para salvar NFe, CTe ou MDFe
  * @return string
  * @throws Exception\InvalidArgumentException
  * @throws Exception\RuntimeException
  */
 public function assinaDoc($xml = '', $tipo = '', $tag = '', $saveFile = false)
 {
     if ($tag == '') {
         $msg = 'Deve ser indicada uma tag a ser assinada';
         throw new Exception\InvalidArgumentException($msg);
     }
     if (is_file($xml)) {
         $xml = Files\FilesFolders::readFile($xml);
     }
     $sxml = $this->oCertificate->signXML($xml, $tag);
     $dom = new Dom();
     $dom->loadXMLString($sxml);
     //$versao = $dom->getElementsByTagName($tag)->item(0)->getAttribute('versao');
     //if (! $this->zValidMessage($sxml, $tipo, $versao)) {
     //$msg = "Falha na validação do $tipo. ".$this->error;
     //  throw new Exception\RuntimeException($msg);
     //}
     if ($saveFile && $tipo != '') {
         $dom = new Dom();
         $dom->loadXMLString($sxml);
         $tpAmb = $dom->getElementsByTagName('tpAmb')->item(0)->nodeValue;
         $anomes = date('Ym', DateTime::convertSefazTimeToTimestamp($dom->getElementsByTagName('dhEmi')->item(0)->nodeValue));
         $chave = $dom->getChave($tag);
         $filename = "{$chave}-{$tipo}.xml";
         $this->zGravaFile($tipo, $tpAmb, $filename, $sxml, 'assinadas', $anomes);
     }
     return $sxml;
 }
Ejemplo n.º 4
0
 /**
  * zTrataProcNFe
  * @param array $resp
  * @return array
  */
 private static function zTrataProcNFe($resp = array())
 {
     $content = $resp['doc'];
     $dom = new Dom();
     $dom->loadXMLString($content);
     $chave = $dom->getChave();
     $data = $dom->getNodeValue('dhEmi');
     if ($data == '') {
         $data = $dom->getNodeValue('dEmi');
     }
     $tsdhemi = DateTime::convertSefazTimeToTimestamp($data);
     $anomes = date('Ym', $tsdhemi);
     $xmldata = $dom->saveXML();
     $xmldata = str_replace('<?xml version="1.0"?>', '<?xml version="1.0" encoding="utf-8"?>', $xmldata);
     $aResp[] = array('tipo' => '-nfe.xml', 'chave' => $chave, 'anomes' => $anomes, 'xml' => $xmldata);
     return $aResp;
 }