コード例 #1
0
ファイル: ToolsNFe.php プロジェクト: eliasdanielmelo/nfephp
 /**
  * zPutQRTag
  * Monta a URI para o QRCode e coloca a tag 
  * no xml já assinado
  * @param Dom $dom
  * @return string
  * NOTA: O Campo QRCode está habilitado para uso a partir de 
  *       01/10/2015 homologação
  *       03/11/2015 Produção
  */
 protected function zPutQRTag(Dom $dom, $saveFile)
 {
     //pega os dados necessários para a montagem da URI a partir do xml
     $nfe = $dom->getNode('NFe');
     $ide = $dom->getNode('ide');
     $dest = $dom->getNode('dest');
     $icmsTot = $dom->getNode('ICMSTot');
     $signedInfo = $dom->getNode('SignedInfo');
     $chNFe = $dom->getChave('infNFe');
     $cUF = $dom->getValue($ide, 'cUF');
     $tpAmb = $dom->getValue($ide, 'tpAmb');
     $dhEmi = $dom->getValue($ide, 'dhEmi');
     $cDest = '';
     if (!empty($dest)) {
         //pode ser CNPJ , CPF ou idEstrageiro
         $cDest = $dom->getValue($dest, 'CNPJ');
         if ($cDest == '') {
             $cDest = $dom->getValue($dest, 'CPF');
             if ($cDest == '') {
                 $cDest = $dom->getValue($dest, 'idEstrangeiro');
             }
         }
     }
     $vNF = $dom->getValue($icmsTot, 'vNF');
     $vICMS = $dom->getValue($icmsTot, 'vICMS');
     $digVal = $dom->getValue($signedInfo, 'DigestValue');
     $token = $this->aConfig['tokenNFCe'];
     $idToken = $this->aConfig['tokenNFCeId'];
     $versao = '100';
     //pega a URL para consulta do QRCode do estado emissor
     //essa url está em nfe_ws3_mode65.xml
     //carrega serviço
     $servico = 'NfeConsultaQR';
     $siglaUF = $this->zGetSigla($cUF);
     $this->zLoadServico('nfe', $servico, $siglaUF, $tpAmb);
     if ($this->urlService == '') {
         $this->errors[] = "A consulta por QRCode não está disponível na SEFAZ {$siglaUF}!!!";
         return $dom->saveXML();
     }
     $url = $this->urlService;
     //usa a função zMakeQRCode para gerar a string da URI
     $qrcode = $this->zMakeQRCode($chNFe, $url, $tpAmb, $dhEmi, $vNF, $vICMS, $digVal, $token, $cDest, $idToken, $versao);
     if ($qrcode == '') {
         return $dom->saveXML();
     }
     //inclui a TAG NFe/infNFeSupl com o qrcode
     $infNFeSupl = $dom->createElement("infNFeSupl");
     $nodeqr = $infNFeSupl->appendChild($dom->createElement('qrCode'));
     $nodeqr->appendChild($dom->createCDATASection($qrcode));
     $signature = $dom->getElementsByTagName('Signature')->item(0);
     $nfe->insertBefore($infNFeSupl, $signature);
     $dom->formatOutput = false;
     $xmlSigned = $dom->saveXML();
     //salva novamente o xml assinado e agora com o QRCode
     if ($saveFile) {
         $anomes = date('Ym', DateTime::convertSefazTimeToTimestamp($dhEmi));
         $filename = "{$chNFe}-nfe.xml";
         $this->zGravaFile('nfe', $tpAmb, $filename, $xmlSigned, 'assinadas', $anomes);
     }
     //retorna a string com o xml assinado e com o QRCode
     return $xmlSigned;
 }
コード例 #2
0
 /**
  * addCancelamento
  * Adiciona a tga de cancelamento a uma MDFe já autorizada
  * NOTA: não é requisito da SEFAZ, mas auxilia na identificação das MDFe que foram canceladas
  * @param string $pathMDFefile
  * @param string $pathCancfile
  * @param bool $saveFile
  * @return string
  * @throws Exception\RuntimeException
  */
 public function addCancelamento($pathMDFefile = '', $pathCancfile = '', $saveFile = false)
 {
     $procXML = '';
     //carrega a NFe
     $docmdfe = new Dom();
     $docmdfe->loadXMLFile($pathMDFefile);
     $nodemdfe = $docmdfe->getNode('MDFe', 0);
     if ($nodemdfe == '') {
         $msg = "O arquivo indicado como MDFe não é um xml de MDFe!";
         throw new Exception\RuntimeException($msg);
     }
     $proMDFe = $docmdfe->getNode('protMDFe');
     if ($proMDFe == '') {
         $msg = "O MDFe não está protocolado ainda!!";
         throw new Exception\RuntimeException($msg);
     }
     $chaveMDFe = $proMDFe->getElementsByTagName('chMDFe')->item(0)->nodeValue;
     //$nProtNFe = $proNFe->getElementsByTagName('nProt')->item(0)->nodeValue;
     $tpAmb = $docmdfe->getNodeValue('tpAmb');
     $anomes = date('Ym', DateTime::convertSefazTimeToTimestamp($docmdfe->getNodeValue('dhEmi')));
     //carrega o cancelamento
     //pode ser um evento ou resultado de uma consulta com multiplos eventos
     $doccanc = new Dom();
     $doccanc->loadXMLFile($pathCancfile);
     $eventos = $doccanc->getElementsByTagName('infEvento');
     foreach ($eventos as $evento) {
         //evento
         $cStat = $evento->getElementsByTagName('cStat')->item(0)->nodeValue;
         $tpAmb = $evento->getElementsByTagName('tpAmb')->item(0)->nodeValue;
         $chaveEvento = $evento->getElementsByTagName('chNFe')->item(0)->nodeValue;
         $tpEvento = $evento->getElementsByTagName('tpEvento')->item(0)->nodeValue;
         //$nProtEvento = $evento->getElementsByTagName('nProt')->item(0)->nodeValue;
         //verifica se conferem os dados
         //cStat = 135 ==> evento homologado
         //tpEvento = 110111 ==> Cancelamento
         //chave do evento == chave da NFe
         //protocolo do evneto ==  protocolo da NFe
         if ($cStat == '135' && $tpEvento == '110111' && $chaveEvento == $chaveMDFe) {
             $proMDFe->getElementsByTagName('cStat')->item(0)->nodeValue = '101';
             $proMDFe->getElementsByTagName('xMotivo')->item(0)->nodeValue = 'Cancelamento de NF-e homologado';
             $procXML = $docmdfe->saveXML();
             //remove as informações indesejadas
             $procXML = Strings::clearProt($procXML);
             if ($saveFile) {
                 $filename = "{$chaveMDFe}-protMDFe.xml";
                 $this->zGravaFile('mdfe', $tpAmb, $filename, $procXML, 'enviadas' . DIRECTORY_SEPARATOR . 'aprovadas', $anomes);
             }
             break;
         }
     }
     return (string) $procXML;
 }
コード例 #3
0
ファイル: Make.php プロジェクト: nfephp-org/sped-cte
 /**
  * Monta o arquivo XML usando as tag's já preenchidas
  *
  * @return bool
  */
 public function montaCTe()
 {
     if (count($this->erros) > 0) {
         return false;
     }
     $this->zCTeTag();
     if ($this->toma03 != '') {
         $this->dom->appChild($this->ide, $this->toma03, 'Falta tag "ide"');
     } else {
         $this->dom->appChild($this->toma4, $this->enderToma, 'Falta tag "toma4"');
         $this->dom->appChild($this->ide, $this->toma4, 'Falta tag "ide"');
     }
     $this->dom->appChild($this->infCte, $this->ide, 'Falta tag "infCte"');
     if ($this->compl != '') {
         if ($this->fluxo != '') {
             foreach ($this->pass as $pass) {
                 $this->dom->appChild($this->fluxo, $pass, 'Falta tag "fluxo"');
             }
             $this->dom->appChild($this->compl, $this->fluxo, 'Falta tag "infCte"');
         }
         if ($this->semData != '') {
             $this->zEntregaTag();
             $this->dom->appChild($this->entrega, $this->semData, 'Falta tag "Entrega"');
         } elseif ($this->comData != '') {
             $this->zEntregaTag();
             $this->dom->appChild($this->entrega, $this->comData, 'Falta tag "Entrega"');
         } elseif ($this->noPeriodo != '') {
             $this->zEntregaTag();
             $this->dom->appChild($this->entrega, $this->noPeriodo, 'Falta tag "Entrega"');
         } elseif ($this->semHora != '') {
             $this->zEntregaTag();
             $this->dom->appChild($this->entrega, $this->semHora, 'Falta tag "Entrega"');
         } elseif ($this->comHora != '') {
             $this->zEntregaTag();
             $this->dom->appChild($this->entrega, $this->comHora, 'Falta tag "Entrega"');
         } elseif ($this->noInter != '') {
             $this->zEntregaTag();
             $this->dom->appChild($this->entrega, $this->noInter, 'Falta tag "Entrega"');
         }
         foreach ($this->obsCont as $obsCont) {
             $this->dom->appChild($this->compl, $obsCont, 'Falta tag "compl"');
         }
         foreach ($this->obsFisco as $obsFisco) {
             $this->dom->appChild($this->compl, $obsFisco, 'Falta tag "compl"');
         }
         $this->dom->appChild($this->infCte, $this->compl, 'Falta tag "infCte"');
     }
     $this->dom->appChild($this->emit, $this->enderEmit, 'Falta tag "emit"');
     $this->dom->appChild($this->infCte, $this->emit, 'Falta tag "infCte"');
     if ($this->rem != '') {
         //    $this->dom->appChild($this->rem, $this->enderReme, 'Falta tag "rem"');
         $this->dom->appChild($this->infCte, $this->rem, 'Falta tag "infCte"');
     }
     if ($this->exped != '') {
         //            $this->dom->appChild($this->exped, $this->enderExped, 'Falta tag "exped"');
         $this->dom->appChild($this->infCte, $this->exped, 'Falta tag "infCte"');
     }
     if ($this->receb != '') {
         //            $this->dom->appChild($this->receb, $this->enderReceb, 'Falta tag "receb"');
         $this->dom->appChild($this->infCte, $this->receb, 'Falta tag "infCte"');
     }
     if ($this->dest != '') {
         //    $this->dom->appChild($this->dest, $this->enderDest, 'Falta tag "dest"');
         $this->dom->appChild($this->infCte, $this->dest, 'Falta tag "infCte"');
     }
     foreach ($this->comp as $comp) {
         $this->dom->appChild($this->vPrest, $comp, 'Falta tag "vPrest"');
     }
     $this->dom->appChild($this->infCte, $this->vPrest, 'Falta tag "infCte"');
     $this->dom->appChild($this->infCte, $this->imp, 'Falta tag "imp"');
     $this->dom->appChild($this->infCte, $this->infCTeNorm, 'Falta tag "infCTeNorm"');
     $this->dom->appChild($this->infCTeNorm, $this->infCarga, 'Falta tag "infCarga"');
     $this->dom->appChild($this->infCarga, $this->infQ, 'Falta tag "infQ"');
     $this->dom->appChild($this->infCTeNorm, $this->infDoc, 'Falta tag "infDoc"');
     foreach ($this->infNFe as $infNFe) {
         $this->dom->appChild($this->infDoc, $infNFe, 'Falta tag "infNFe"');
     }
     foreach ($this->infOutros as $infOutros) {
         $this->dom->appChild($this->infDoc, $infOutros, 'Falta tag "infOutros"');
     }
     $this->dom->appChild($this->infCTeNorm, $this->seg, 'Falta tag "seg"');
     $this->dom->appChild($this->infCTeNorm, $this->infModal, 'Falta tag "infModal"');
     $this->dom->appChild($this->infModal, $this->rodo, 'Falta tag "rodo"');
     $this->dom->appChild($this->CTe, $this->infCte, 'Falta tag "CTe"');
     $this->dom->appChild($this->dom, $this->CTe, 'Falta tag "DOMDocument"');
     $this->xml = $this->dom->saveXML();
     return true;
 }
コード例 #4
0
ファイル: DFe.php プロジェクト: jhonleandres/teste
 /**
  * zTrataProcEvent
  * @param array $resp
  */
 private static function zTrataProcEvent($resp = array())
 {
     $aResp = array();
     $content = $resp['doc'];
     $dom = new Dom();
     $dom->loadXMLString($content);
     $xmldata = $dom->saveXML();
     $xmldata = str_replace('<?xml version="1.0"?>', '<?xml version="1.0" encoding="utf-8"?>', $xmldata);
     $data = $dom->getNodeValue('dhEvento');
     $tsdhevento = DateTime::convertSefazTimeToTimestamp($data);
     $anomes = date('Ym', $tsdhevento);
     $tpEvento = $dom->getNodeValue('tpEvento');
     $chave = $dom->getNodeValue('chNFe');
     if ($tpEvento == '110111') {
         //confirmado cancelamento, localizar o xml da NFe recebida
         //na pasta anomes
         $path = $this->pathNFe . DIRECTORY_SEPARATOR . $this->ambiente . DIRECTORY_SEPARATOR . "recebidas" . DIRECTORY_SEPARATOR . $anomes;
         $pathFile = $path . DIRECTORY_SEPARATOR . $chave . '-nfe.xml';
         self::zCancela($pathFile);
         $aResp[] = array('tipo' => '-cancNFe.xml', 'chave' => $chave, 'anomes' => $anomes, 'xml' => $xmldata);
     } elseif ($tpEvento == '110110') {
         //evento Carta de Correção
         $aResp[] = array('tipo' => '-cce.xml', 'chave' => $chave, 'anomes' => $anomes, 'xml' => $xmldata);
     }
     return $aResp;
 }
コード例 #5
0
ファイル: Tools.php プロジェクト: nfephp-org/sped-cte
 /**
  * addCancelamento
  * Adiciona a tga de cancelamento a uma CTe já autorizada
  * NOTA: não é requisito da SEFAZ, mas auxilia na identificação das CTe que foram canceladas
  * @param string $pathCTefile
  * @param string $pathCancfile
  * @param bool $saveFile
  * @return string
  * @throws Exception\RuntimeException
  */
 public function addCancelamento($pathCTefile = '', $pathCancfile = '', $saveFile = false)
 {
     $procXML = '';
     //carrega a CTe
     $docCTe = new Dom();
     if (file_exists($pathCTefile)) {
         //carrega o XML pelo caminho do arquivo informado
         $docCTe->loadXMLFile($pathCTefile);
     } else {
         //carrega o XML pelo conteúdo
         $docCTe->loadXMLString($pathCTefile);
     }
     $nodeCTe = $docCTe->getNode('CTe', 0);
     if ($nodeCTe == '') {
         $msg = "O arquivo indicado como CTe não é um xml de CTe!";
         throw new Exception\RuntimeException($msg);
     }
     $proCTe = $docCTe->getNode('protCTe');
     if ($proCTe == '') {
         $msg = "A CTe não está protocolada ainda!!";
         throw new Exception\RuntimeException($msg);
     }
     $chaveCTe = $proCTe->getElementsByTagName('chCTe')->item(0)->nodeValue;
     //$nProtCTe = $proCTe->getElementsByTagName('nProt')->item(0)->nodeValue;
     $tpAmb = $docCTe->getNodeValue('tpAmb');
     $anomes = date('Ym', DateTime::convertSefazTimeToTimestamp($docCTe->getNodeValue('dhEmi')));
     //carrega o cancelamento
     //pode ser um evento ou resultado de uma consulta com multiplos eventos
     $doccanc = new Dom();
     if (file_exists($pathCancfile)) {
         //carrega o XML pelo caminho do arquivo informado
         $doccanc->loadXMLFile($pathCancfile);
     } else {
         //carrega o XML pelo conteúdo
         $doccanc->loadXMLString($pathCancfile);
     }
     $retEvento = $doccanc->getElementsByTagName('retEventoCTe')->item(0);
     $eventos = $retEvento->getElementsByTagName('infEvento');
     foreach ($eventos as $evento) {
         //evento
         $cStat = $evento->getElementsByTagName('cStat')->item(0)->nodeValue;
         $tpAmb = $evento->getElementsByTagName('tpAmb')->item(0)->nodeValue;
         $chaveEvento = $evento->getElementsByTagName('chCTe')->item(0)->nodeValue;
         $tpEvento = $evento->getElementsByTagName('tpEvento')->item(0)->nodeValue;
         //$nProtEvento = $evento->getElementsByTagName('nProt')->item(0)->nodeValue;
         //verifica se conferem os dados
         //cStat = 135 ==> evento homologado
         //cStat = 136 ==> vinculação do evento à respectiva NF-e prejudicada
         //cStat = 155 ==> Cancelamento homologado fora de prazo
         //tpEvento = 110111 ==> Cancelamento
         //chave do evento == chave da CTe
         //protocolo do evneto ==  protocolo da CTe
         if (($cStat == '135' || $cStat == '136' || $cStat == '155') && $tpEvento == '110111' && $chaveEvento == $chaveCTe) {
             $proCTe->getElementsByTagName('cStat')->item(0)->nodeValue = '101';
             $proCTe->getElementsByTagName('xMotivo')->item(0)->nodeValue = 'Cancelamento de CT-e homologado';
             $procXML = $docCTe->saveXML();
             //remove as informações indesejadas
             $procXML = Strings::clearProt($procXML);
             if ($saveFile) {
                 $filename = "{$chaveCTe}-protCTe.xml";
                 $this->zGravaFile('cte', $tpAmb, $filename, $procXML, 'canceladas', $anomes);
             }
             break;
         }
     }
     return (string) $procXML;
 }