|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace NFePHP\MDFe\Factories; |
|
4
|
|
|
|
|
5
|
|
|
/** |
|
6
|
|
|
* Class QRCode create a string to make a QRCode string |
|
7
|
|
|
* |
|
8
|
|
|
* @author Cleiton Perin <cperin20 at gmail dot com> |
|
9
|
|
|
* @package NFePHP\MDFe\Factories\QRCode |
|
10
|
|
|
* @copyright NFePHP Copyright (c) 2008-2019 |
|
11
|
|
|
* @license http://www.gnu.org/licenses/lgpl.txt LGPLv3+ |
|
12
|
|
|
* @license https://opensource.org/licenses/MIT MIT |
|
13
|
|
|
* @license http://www.gnu.org/licenses/gpl.txt GPLv3+ |
|
14
|
|
|
* @category NFePHP |
|
15
|
|
|
* @link http://github.com/nfephp-org/sped-mdfe for the canonical source repository |
|
16
|
|
|
*/ |
|
17
|
|
|
|
|
18
|
|
|
use DOMDocument; |
|
19
|
|
|
use NFePHP\MDFe\Exception\DocumentsException; |
|
20
|
|
|
|
|
21
|
|
|
class QRCode |
|
22
|
|
|
{ |
|
23
|
|
|
/** |
|
24
|
|
|
* putQRTag |
|
25
|
|
|
* @param DOMDocument $dom MDFe |
|
26
|
|
|
* @return string |
|
27
|
|
|
* @throws DocumentsException |
|
28
|
|
|
*/ |
|
29
|
|
|
public static function putQRTag( |
|
30
|
|
|
\DOMDocument $dom |
|
31
|
|
|
) { |
|
32
|
|
|
|
|
33
|
|
|
$mdfe = $dom->getElementsByTagName('MDFe')->item(0); |
|
34
|
|
|
$infMDFe = $dom->getElementsByTagName('infMDFe')->item(0); |
|
35
|
|
|
$ide = $dom->getElementsByTagName('ide')->item(0); |
|
36
|
|
|
$chMDFe = preg_replace('/[^0-9]/', '', $infMDFe->getAttribute("Id")); |
|
37
|
|
|
$tpAmb = $ide->getElementsByTagName('tpAmb')->item(0)->nodeValue; |
|
38
|
|
|
$urlQRCode = "https://dfe-portal.svrs.rs.gov.br/mdfe/qrCode?chMDFe=$chMDFe&tpAmb=$tpAmb"; |
|
39
|
|
|
$infMDFeSupl = $dom->createElement("infMDFeSupl"); |
|
40
|
|
|
$qrCode = $infMDFeSupl->appendChild($dom->createElement('qrCodMDFe')); |
|
41
|
|
|
$qrCode->appendChild($dom->createCDATASection($urlQRCode)); |
|
42
|
|
|
$signature = $dom->getElementsByTagName('Signature')->item(0); |
|
43
|
|
|
$mdfe->insertBefore($infMDFeSupl, $signature); |
|
44
|
|
|
$dom->formatOutput = false; |
|
45
|
|
|
return $dom->saveXML(); |
|
46
|
|
|
} |
|
47
|
|
|
} |
|
48
|
|
|
|