Ejemplo n.º 1
0
 /**
  * zMontaMessagem
  *
  * @param string $pathFile
  */
 protected function zMontaMessagem($pathFile)
 {
     $dom = new Dom();
     $dom->loadXMLFile($pathFile);
     $infNFe = $dom->getNode('infNFe', 0);
     $ide = $infNFe->getElementsByTagName('ide')->item(0);
     $dest = $infNFe->getElementsByTagName('dest')->item(0);
     $emit = $infNFe->getElementsByTagName('emit')->item(0);
     $icmsTot = $infNFe->getElementsByTagName('ICMSTot')->item(0);
     $razao = $emit->getElementsByTagName('xNome')->item(0)->nodeValue;
     $nNF = $ide->getElementsByTagName('nNF')->item(0)->nodeValue;
     $serie = $ide->getElementsByTagName('serie')->item(0)->nodeValue;
     $xNome = $dest->getElementsByTagName('xNome')->item(0)->nodeValue;
     $dhEmi = !empty($ide->getElementsByTagName('dhEmi')->item(0)->nodeValue) ? $ide->getElementsByTagName('dhEmi')->item(0)->nodeValue : $ide->getElementsByTagName('dEmi')->item(0)->nodeValue;
     $data = date('d/m/Y', DateTime::convertSefazTimeToTimestamp($dhEmi));
     $vNF = $icmsTot->getElementsByTagName('vNF')->item(0)->nodeValue;
     $this->aMail[] = !empty($dest->getElementsByTagName('email')->item(0)->nodeValue) ? $dest->getElementsByTagName('email')->item(0)->nodeValue : '';
     //pega os emails que existirem em obsCont
     $infAdic = $infNFe->getElementsByTagName('infAdic')->item(0);
     if (!empty($infAdic)) {
         $obsConts = $infAdic->getElementsByTagName('obsCont');
         foreach ($obsConts as $obsCont) {
             if (strtoupper($obsCont->getAttribute('xCampo')) === 'EMAIL') {
                 $this->aMail[] = $obsCont->getElementsByTagName('xTexto')->item(0)->nodeValue;
             }
         }
     }
     $this->msgHtml = $this->zRenderTemplate($xNome, $data, $nNF, $serie, $vNF, $razao);
     $this->msgTxt = utf8_encode(Html2Text::convert(utf8_decode($this->msgHtml)));
     return "NFe n. {$nNF} - {$razao}";
 }
Ejemplo n.º 2
0
 /**
  * zMontaMessagem
  * @param string $pathFile
  */
 protected function zMontaMessagem($pathFile)
 {
     $dom = new Dom();
     $dom->loadXMLFile($pathFile);
     $infMDFe = $dom->getNode('infMDFe', 0);
     $ide = $infMDFe->getElementsByTagName('ide')->item(0);
     $emit = $infMDFe->getElementsByTagName('emit')->item(0);
     $tot = $infMDFe->getElementsByTagName('tot')->item(0);
     $razao = $emit->getElementsByTagName('xNome')->item(0)->nodeValue;
     $nMDF = $ide->getElementsByTagName('nMDF')->item(0)->nodeValue;
     $serie = $ide->getElementsByTagName('serie')->item(0)->nodeValue;
     $dhEmi = !empty($ide->getElementsByTagName('dhEmi')->item(0)->nodeValue) ? $ide->getElementsByTagName('dhEmi')->item(0)->nodeValue : $ide->getElementsByTagName('dEmi')->item(0)->nodeValue;
     $data = date('d/m/Y', DateTime::convertSefazTimeToTimestamp($dhEmi));
     $vCarga = $tot->getElementsByTagName('vCarga')->item(0)->nodeValue;
     $xNome = '';
     $this->msgHtml = $this->zRenderTemplate($xNome, $data, $nMDF, $serie, $vCarga, $razao);
     $this->msgTxt = utf8_encode(Html2Text::convert(utf8_decode($this->msgHtml)));
     return "MDFe n. {$nMDF} - {$razao}";
 }
Ejemplo n.º 3
0
 /**
  * zMontaMessagem
  *
  * @param string $pathFile
  */
 protected function zMontaMessagem($pathFile)
 {
     $dom = new Dom();
     $dom->loadXMLFile($pathFile);
     $infCTe = $dom->getNode('infCte', 0);
     $ide = $infCTe->getElementsByTagName('ide')->item(0);
     $dest = $infCTe->getElementsByTagName('dest')->item(0);
     $emit = $infCTe->getElementsByTagName('emit')->item(0);
     $vPrest = $infCTe->getElementsByTagName('vPrest')->item(0);
     $razao = $emit->getElementsByTagName('xNome')->item(0)->nodeValue;
     $nCT = $ide->getElementsByTagName('nCT')->item(0)->nodeValue;
     $serie = $ide->getElementsByTagName('serie')->item(0)->nodeValue;
     $xNome = $dest->getElementsByTagName('xNome')->item(0)->nodeValue;
     $dhEmi = !empty($ide->getElementsByTagName('dhEmi')->item(0)->nodeValue) ? $ide->getElementsByTagName('dhEmi')->item(0)->nodeValue : $ide->getElementsByTagName('dEmi')->item(0)->nodeValue;
     $data = date('d/m/Y', DateTime::convertSefazTimeToTimestamp($dhEmi));
     $vCT = $vPrest->getElementsByTagName('vTPrest')->item(0)->nodeValue;
     $this->aMail[] = !empty($dest->getElementsByTagName('email')->item(0)->nodeValue) ? $dest->getElementsByTagName('email')->item(0)->nodeValue : '';
     $this->msgHtml = $this->zRenderTemplate($xNome, $data, $nCT, $serie, $vCT, $razao);
     $cHTT = new Html2Text($this->msgHtml);
     $this->msgTxt = $cHTT->getText();
     return "CTe n. {$nCT} - {$razao}";
 }
Ejemplo n.º 4
0
 /**
  * verificaValidade
  * Verifica a validade de uma NFe recebida
  * @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, 'infNFe');
     //obtem o chave da NFe
     $docnfe = new Dom();
     $docnfe->loadXMLFile($pathXmlFile);
     $tpAmb = $docnfe->getNodeValue('tpAmb');
     $chNFe = $docnfe->getChave('infNFe');
     $this->sefazConsultaChave($chNFe, $tpAmb, $aRetorno);
     if ($aRetorno['cStat'] != '100' && $aRetorno['cStat'] != '150') {
         return false;
     }
     return true;
 }
Ejemplo n.º 5
0
 public static function extrai($aList, $cnpj = '')
 {
     $aResp = array();
     $totFat = 0;
     $totPeso = 0;
     $totIcms = 0;
     foreach ($aList as $file) {
         $dom = null;
         $ide = null;
         $emit = null;
         $dest = null;
         try {
             $dom = new Dom();
             $dom->loadXMLFile($file);
             $ide = $dom->getNode('ide');
             $emit = $dom->getNode('emit');
             $dest = $dom->getNode('dest');
             $icmsTot = $dom->getNode('ICMSTot');
             $vol = $dom->getNode('vol');
             $cStat = $dom->getNodeValue('cStat');
             if ($cStat != '100') {
                 self::$nCanc++;
             }
             $dhEmi = $dom->getValue($ide, 'dhEmi');
             if (empty($dhEmi)) {
                 $dhEmi = $dom->getValue($ide, 'dEmi');
             }
             //echo $file.'___'.$dhEmi.'<br>';
             $tsEmi = DateTime::convertSefazTimeToTimestamp($dhEmi);
             $data = '';
             if (is_numeric($tsEmi)) {
                 $data = date('d/m/Y', $tsEmi);
             }
             $emitCNPJ = $dom->getValue($emit, 'CNPJ');
             $emitRazao = $dom->getValue($emit, 'xNome');
             $destRazao = $dom->getValue($dest, 'xNome');
             $vNF = $dom->getValue($icmsTot, 'vNF');
             $vNFtext = $vNF;
             if (is_numeric($vNF)) {
                 $vNFtext = 'R$ ' . number_format($vNF, '2', ',', '.');
             }
             $serie = $dom->getNodeValue('serie');
             $nProt = $dom->getNodeValue('nProt');
             $nome = $emitRazao;
             if ($emitCNPJ == $cnpj) {
                 $nome = $destRazao;
             }
             $email = $dom->getValue($dest, 'email');
             $aObscont = $dom->getElementsByTagName('obsCont');
             if (count($aObscont) > 0) {
                 foreach ($aObscont as $obsCont) {
                     $xCampo = $obsCont->getAttribute('xCampo');
                     if ($xCampo == 'email') {
                         $email .= ";" . $dom->getValue($obsCont, 'xTexto');
                     }
                 }
             }
             if (substr($email, 0, 1) == ';') {
                 $email = substr($email, 1, strlen($email) - 1);
             }
             $vICMS = $dom->getValue($icmsTot, 'vICMS');
             $totIcms += $vICMS;
             $valorFat = 0;
             if ($vICMS != 0 && $cStat == '100') {
                 $valorFat = $vNF;
             }
             $totFat += $valorFat;
             $pesoL = $dom->getValue($vol, 'pesoL');
             if ($pesoL != '') {
                 $totPeso += $pesoL;
             }
             $aResp[] = array('nNF' => $dom->getValue($ide, 'nNF'), 'serie' => $serie, 'data' => $data, 'nome' => $nome, 'natureza' => $dom->getValue($ide, 'natOp'), 'cStat' => $cStat, 'vNF' => $vNFtext, 'nProt' => $nProt, 'email' => $email);
         } catch (RuntimeException $e) {
             $aResp[] = array('nNF' => '000000', 'serie' => '000', 'data' => '000', 'nome' => 'FALHA', 'natureza' => "{$file}", 'cStat' => '', 'vNF' => 0, 'nProt' => '', 'email' => '');
         }
     }
     return array('totFat' => $totFat, 'totPeso' => $totPeso, 'totIcms' => $totIcms, 'aNF' => $aResp);
 }
Ejemplo n.º 6
0
 /**
  * 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;
 }