/** * verifica * Verifica o status da SEFAZ com o webservice e retorna tags html com o resultado * @param string $config json do arquivo de configuração * @return string */ public static function verifica($config = '') { $aRetorno = array(); if (empty($config)) { return ''; } self::$config = $config; if (is_file(APP_ROOT . '/base/status.json')) { $aRetorno = (array) json_decode(FilesFolders::readFile(APP_ROOT . '/base/status.json')); } $tstmp = DateTime::convertSefazTimeToTimestamp($aRetorno['dhRecbto']); $tsnow = time(); $dif = $tsnow - $tstmp; //caso tenha passado mais de uma hora desde a ultima verificação if ($dif > 3600) { self::$nfe = new ToolsNFe($config); self::$certTS = self::$nfe->certExpireTimestamp; self::$nfe->sefazStatus('', '', $aRetorno); $retJson = json_encode($aRetorno); FilesFolders::saveFile(APP_ROOT . '/base', 'status.json', $retJson); } $tstmp = DateTime::convertSefazTimeToTimestamp($aRetorno['dhRecbto']); $dhora = date('d/m/Y H:i:s', $tstmp); $htmlStatus = "<p class=\"smallred\">OFF-LINE</p>\n<p class=\"smallred\">{$dhora}</p>"; if ($aRetorno['cStat'] == '107') { $htmlStatus = "<p class=\"smallgreen\">SEFAZ On-Line</p>\n<p class=\"smallgreen\">{$dhora}</p>"; } return $htmlStatus; }
public function __construct($configJson = '') { if ($configJson == '') { $configJson = Files\FilesFolders::readFile('../config/config.json'); } $aConfig = (array) json_decode($configJson); $this->aMailConf = (array) $aConfig['aMailConf']; }
/** * Executa a leitura do arquivo de configuração e * carrega o certificado * * @param string $config * @param bool $ignore */ protected function loadConfig($config = '', $ignore = false) { if (is_file($config)) { $config = FilesFolders::readFile($config); } $result = json_decode($config); if (json_last_error() === JSON_ERROR_NONE) { $this->objConfig = $result; } if (!is_object($this->objConfig)) { throw new InvalidArgumentException("Uma configuração valida deve ser passada!"); } $this->pkcs = new Pkcs12($this->objConfig->pathCertsFiles, $this->objConfig->cnpj, '', '', '', $ignore); $this->pkcs->loadPfxFile($this->objConfig->pathCertsFiles . $this->objConfig->certPfxName, $this->objConfig->certPassword, true, $ignore, false); }
/** * identificacao * Identifica o documento * @param type $xml * @return string */ public static function identificacao($xml = '', &$aResp = array()) { if ($xml == '') { return ''; } elseif (is_file($xml)) { $xml = FilesFolders::readFile($xml); } $dom = new Dom('1.0', 'utf-8'); $dom->loadXMLString($xml); $key = ''; $schId = (string) self::zSearchNode($dom, $key); if ($schId == '') { return ''; } $chave = ''; $tpAmb = ''; $dhEmi = ''; if ($schId == 'nfe' || $schId == 'cte' || $schId == 'mdfe') { switch ($schId) { case 'nfe': $tag = 'infNFe'; break; case 'cte': $tag = 'infCte'; break; case 'mdfe': $tag = 'infMDFe'; break; } $chave = $dom->getChave($tag); $tpAmb = $dom->getNodeValue('tpAmb'); $dhEmi = $dom->getNodeValue('dhEmi'); } $aResp['Id'] = $schId; $aResp['tag'] = $key; $aResp['dom'] = $dom; $aResp['chave'] = $chave; $aResp['tpAmb'] = $tpAmb; $aResp['dhEmi'] = $dhEmi; return $schId; }
* Rotina para apresentar uma lista das NFe a serem manifestadas * gravadas na pasta indicada recebidas/resumos * Após serem manifestadas essas notas não aparecerão mais * * @category Application * @package robmachado\teste * @copyright Copyright (c) 2008-2015 * @license http://www.gnu.org/licenses/lesser.html LGPL v3 * @author Roberto L. Machado <linux.rlm at gmail dot com> * @link http://github.com/robmachado/teste for the canonical source repository */ use App\Dados; use NFePHP\Common\Files\FilesFolders; use NFePHP\Common\Exception\InvalidArgumentException; //carrega os dados de configuração $configJson = FilesFolders::readFile('../config/config.json'); $objConfig = json_decode($configJson); //estabelece o ambiente $ambiente = 'homologacao'; if ($objConfig->tpAmb == '1') { $ambiente = 'producao'; } //cria uma lista vazia $aList = array(); $caminho = 'recebidas' . DIRECTORY_SEPARATOR . 'resumo'; $path = $objConfig->pathNFeFiles . DIRECTORY_SEPARATOR . $ambiente . DIRECTORY_SEPARATOR . $caminho; try { $aList = FilesFolders::listDir($path, '*.xml', true); } catch (InvalidArgumentException $exc) { $mensagem = $exc->getMessage(); }
/** * 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; }
/** * 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; }
<?php /** * ATENÇÃO : Esse exemplo usa classe PROVISÓRIA que será removida assim que * a nova classe DANFE estiver refatorada e a pasta EXTRAS será removida. */ error_reporting(E_ALL); ini_set('display_errors', 'On'); include_once '../../bootstrap.php'; use NFePHP\Extras\Danfe; use NFePHP\Common\Files\FilesFolders; $chaveNotaFiscal = $_GET['chaveNotaFiscal']; $logoLoja = $_GET['logoLoja']; //var_dump($logoLoja); //exit(); $xml = '../xml/' . $chaveNotaFiscal . '-nfe.xml'; $docxml = FilesFolders::readFile($xml); $danfe = new Danfe($docxml, 'P', 'A4', '../../../../logos/' . $logoLoja, 'I', ''); $id = $danfe->montaDANFE(); $teste = $danfe->printDANFE($id . '.pdf', 'I');
/** * setTemplate * Carrega o arquivo html do template do email em um parametro da classe * @param type $pathFile */ public function setTemplate($pathFile = '') { if (is_file($pathFile)) { $this->template = Files\FilesFolders::readFile($pathFile); } }
<?php error_reporting(E_ALL); ini_set('display_errors', 'On'); require_once '../../bootstrap.php'; use NFePHP\NFe\ToolsNFe; use NFePHP\Extras\Danfce; use NFePHP\Common\Files\FilesFolders; $nfe = new ToolsNFe('../../config/config.json'); //$nfe->aConfig['aDocFormat']->pathLogoFile // Logo em config $saida = isset($_REQUEST['o']) ? $_REQUEST['o'] : 'pdf'; //pdf ou html $ecoNFCe = false; //false = Não (NFC-e Completa); true = Sim (NFC-e Simplificada) $chave = '52160522234907000158650010000002001000002009'; $xmlProt = "D:/xampp/htdocs/GIT-nfephp-org/nfephp/xmls/NF-e/homologacao/enviadas/aprovadas/201605/{$chave}-protNFe.xml"; // Uso da nomeclatura '-danfce.pdf' para facilitar a diferenciação entre PDFs DANFE e DANFCE salvos na mesma pasta... $pdfDanfe = "D:/xampp/htdocs/GIT-nfephp-org/nfephp/xmls/NF-e/homologacao/pdf/201605/{$chave}-danfce.pdf"; $docxml = FilesFolders::readFile($xmlProt); $danfce = new Danfce($docxml, '', 2); $id = $danfce->montaDANFCE($ecoNFCe); $salva = $danfce->printDANFCE('pdf', $pdfDanfe, 'F'); //Salva na pasta pdf $abre = $danfce->printDANFCE($saida, $pdfDanfe, 'I'); //Abre na tela
public function loadXMLFile($pathXmlFile = '') { $data = FilesFolders::readFile($pathXmlFile); $this->loadXMLString($data); }
/** * __construct * * @param string $configJson * @param bool $ignore default false usado para testes apenas * @throws InvalidArgumentException * @throws RuntimeException */ public function __construct($configJson = '', $ignore = false) { if ($configJson == '') { $msg = 'O arquivo de configuração no formato JSON deve ser passado para a classe.'; throw new InvalidArgumentException($msg); } if (is_file($configJson)) { $configJson = Files\FilesFolders::readFile($configJson); } //carrega os dados de configuração $this->aConfig = (array) json_decode($configJson, true); $this->aProxyConf = (array) $this->aConfig['aProxyConf']; $this->verAplic = $this->aConfig['verAplic']; //seta o timezone DateTime::tzdBR($this->aConfig['siglaUF']); //carrega os certificados $this->oCertificate = new Pkcs12($this->aConfig['pathCertsFiles'], $this->aConfig['cnpj'], '', '', '', $ignore); $timestampnow = gmmktime(0, 0, 0, date("m"), date("d"), date("Y")); if ($this->oCertificate->expireTimestamp == 0 || $this->oCertificate->expireTimestamp < $timestampnow) { //tentar carregar novo certificado $this->atualizaCertificado($this->aConfig['pathCertsFiles'] . $this->aConfig['certPfxName'], $this->aConfig['certPassword']); if ($this->oCertificate->expireTimestamp == 0 || $this->oCertificate->expireTimestamp < $timestampnow) { $msg = 'Não existe certificado válido disponível. Atualize o Certificado.'; throw new RuntimeException($msg); } } $this->setAmbiente($this->aConfig['tpAmb']); $this->certExpireTimestamp = $this->oCertificate->expireTimestamp; $this->certExpireDate = date('d/m/Y', $this->certExpireTimestamp); $this->loadSoapClass(); }
/** * zCancela * Edita a NFe recebida de terceiros indicando o cancelamento * @param string $pathFile */ private static function zCancela($pathFile) { if (is_file($pathFile)) { //o arquivo foi localizado, então indicar o cancelamento //editando o xml da NFe e substituindo o cStat do protocolo por //135 ou 101 $xml = FilesFolders::readFile($pathFile); $nfe = new \DOMDocument(); $nfe->loadXML($xml); $infProt = $nfe->getElementsByTagName('infProt')->item(0); $infProt->getElementsByTagName('cStat')->item(0)->nodeValue = '101'; $nfe->save($pathFile); } }
/** *Método que faz o download da DANFE * * @name gerarDANFE * @access public * @author Roberson Faria * @param Numeric $customer_id * @param String $arquivo Caminho para o arquivo xml * @param Char $tipoDownload Defini o tipo do download do arquivo "I" - abre o pdf no browser "D" - faz o download do PDF para a maquina do cliente. */ public function printDanfe($arquivo, $tipoDownload = "I") { $dxml = base64_decode($arquivo); $logo = 'images/logo.jpg'; if (strpos($arquivo, 'recebidas')) { $logo = ''; } $docxml = FilesFolders::readFile($arquivo); $danfe = new Danfe($docxml, 'P', 'A4', $logo, $tipoDownload, ''); $id = $danfe->montaDANFE(); $danfe->printDANFE($id . '.pdf', $tipoDownload); }
$mailReplayToMail = ''; $mailReplayToName = ''; $mailImapHost = ''; $mailImapPort = ''; $mailImapSecurity = ''; $mailImapNocerts = ''; $mailImapBox = ''; $proxyIp = ''; $proxyPort = ''; $proxyUser = ''; $proxyPass = ''; $configfolder = PATH_NFEPHP . DIRECTORY_SEPARATOR . 'config'; $pathConfig = $configfolder . DIRECTORY_SEPARATOR . 'config.json'; $configureVer = '4.0'; if (is_file($pathConfig)) { $configJson = FilesFolders::readFile($pathConfig); $installConfig = json_decode($configJson); $tpAmb = isset($installConfig->tpAmb) ? $installConfig->tpAmb : '2'; $pathXmlUrlFileNFe = isset($installConfig->pathXmlUrlFileNFe) ? $installConfig->pathXmlUrlFileNFe : ''; $pathXmlUrlFileCTe = isset($installConfig->pathXmlUrlFileCTe) ? $installConfig->pathXmlUrlFileCTe : ''; $pathXmlUrlFileMDFe = isset($installConfig->pathXmlUrlFileMDFe) ? $installConfig->pathXmlUrlFileMDFe : ''; $pathXmlUrlFileCLe = isset($installConfig->pathXmlUrlFileCLe) ? $installConfig->pathXmlUrlFileCLe : ''; $pathXmlUrlFileNFSe = isset($installConfig->pathXmlUrlFileNFSe) ? $installConfig->pathXmlUrlFileNFSe : ''; $pathNFeFiles = isset($installConfig->pathNFeFiles) ? $installConfig->pathNFeFiles : ''; $pathCTeFiles = isset($installConfig->pathCTeFiles) ? $installConfig->pathCTeFiles : ''; $pathMDFeFiles = isset($installConfig->pathMDFeFiles) ? $installConfig->pathMDFeFiles : ''; $pathCLeFiles = isset($installConfig->pathCLeFiles) ? $installConfig->pathCLeFiles : ''; $pathNFSeFiles = isset($installConfig->pathNFSeFiles) ? $installConfig->pathNFSeFiles : ''; $pathCertsFiles = isset($installConfig->pathCertsFiles) ? $installConfig->pathCertsFiles : ''; $siteUrl = isset($installConfig->siteUrl) ? $installConfig->siteUrl : $siteUrl; $schemesNFe = isset($installConfig->schemesNFe) ? $installConfig->schemesNFe : '';