Completed
Pull Request — master (#184)
by
unknown
03:18
created

Danfce::pContingencia()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 3
dl 0
loc 11
ccs 0
cts 11
cp 0
crap 2
rs 9.9
c 0
b 0
f 0
1
<?php
2
3
namespace NFePHP\DA\NFe;
4
5
/**
6
 * Classe para a impressão em PDF do Documento Auxiliar de NFe Consumidor
7
 * NOTA: Esta classe não é a indicada para quem faz uso de impressoras térmicas ESCPOS
8
 *
9
 * @category  Library
10
 * @package   nfephp-org/sped-da
11
 * @copyright 2009-2016 NFePHP
12
 * @license   http://www.gnu.org/licenses/lesser.html LGPL v3
13
 * @link      http://github.com/nfephp-org/sped-da for the canonical source repository
14
 * @author    Roberto Spadim <roberto at spadim dot com dot br>
15
 */
16
use Com\Tecnick\Barcode\Barcode;
17
use DateTime;
18
use InvalidArgumentException;
19
use NFePHP\DA\Legacy\Common;
20
use NFePHP\DA\Legacy\Dom;
21
use NFePHP\DA\Legacy\Pdf;
22
23
class Danfce extends Common
24
{
25
    protected $papel;
26
    protected $xml; // string XML NFe
27
    protected $logomarca = ''; // path para logomarca em jpg
28
    protected $formatoChave = "#### #### #### #### #### #### #### #### #### #### ####";
29
    protected $debugMode = 0; //ativa ou desativa o modo de debug
30
    protected $tpImp; //ambiente
31
    protected $tpEmis; //tipo de emissão
32
    protected $fontePadrao = 'Times';
33
    protected $aFontTit;
34
    protected $aFontTex;
35
    protected $nfeProc;
36
    protected $nfe;
37
    protected $infNFe;
38
    protected $ide;
39
    protected $enderDest;
40
    protected $ICMSTot;
41
    protected $imposto;
42
    protected $emit;
43
    protected $enderEmit;
44
    protected $qrCode;
45
    protected $det;
46
    protected $infAdic;
47
    protected $textoAdic;
48
    protected $pag;
49
    protected $vTroco;
50
    protected $dest;
51
    protected $imgQRCode;
52
    protected $urlQR = '';
53
    protected $pdf;
54
    protected $margemInterna = 2;
55
    protected $hMaxLinha = 9;
56
    protected $hBoxLinha = 6;
57
    protected $hLinha = 3;
58
59
    /*
60
     * Retorna a sigla da UF
61
     * @var string
62
     */
63
    protected $UFSigla = [
64
        '12' => 'AC',
65
        '27' => 'AL',
66
        '13' => 'AM',
67
        '16' => 'AP',
68
        '29' => 'BA',
69
        '23' => 'CE',
70
        '53' => 'DF',
71
        '32' => 'ES',
72
        '52' => 'GO',
73
        '31' => 'MG',
74
        '50' => 'MS',
75
        '51' => 'MT',
76
        '21' => 'MA',
77
        '15' => 'PA',
78
        '25' => 'PB',
79
        '26' => 'PE',
80
        '22' => 'PI',
81
        '41' => 'PR',
82
        '33' => 'RJ',
83
        '11' => 'RO',
84
        '24' => 'RN',
85
        '14' => 'RR',
86
        '43' => 'RS',
87
        '42' => 'SC',
88
        '28' => 'SE',
89
        '35' => 'SP',
90
        '17' => 'TO',
91
    ];
92
    /*
93
     * Fonte: http://nfce.encat.org/consumidor/consulte-sua-nota/
94
     * URL referente a pagina de consulta da NFCe pela chave de acesso
95
     * @var string
96
     */
97
    protected $urlConsulta = [
98
        '1' => [
99
            'AC' => 'www.sefaznet.ac.gov.br/nfce/consulta',
100
            'AL' => 'http://nfce.sefaz.al.gov.br/consultaNFCe.htm',
101
            'AP' => 'https://www.sefaz.ap.gov.br/sate/seg/SEGf_AcessarFuncao.jsp?cdFuncao=FIS_1261',
102
            'AM' => 'sistemas.sefaz.am.gov.br/nfceweb/formConsulta.do',
103
            'BA' => 'nfe.sefaz.ba.gov.br/servicos/nfce/default.aspx',
104
            'CE' => '',
105
            'DF' => 'http://dec.fazenda.df.gov.br/NFCE/',
106
            'ES' => 'http://app.sefaz.es.gov.br/ConsultaNFCe',
107
            'GO' => '',
108
            'MA' => 'http://www.nfce.sefaz.ma.gov.br/portal/consultaNFe.do?method=preFilterCupom&',
109
            'MT' => 'http://www.sefaz.mt.gov.br/nfce/consultanfce',
110
            'MS' => 'http://www.dfe.ms.gov.br/nfce',
111
            'MG' => '',
112
            'PA' => 'https://appnfc.sefa.pa.gov.br/portal/view/consultas/nfce/consultanfce.seam',
113
            'PB' => 'www.receita.pb.gov.br/nfce',
114
            'PR' => 'http://www.fazenda.pr.gov.br',
115
            'PE' => '',
116
            'PI' => 'http://webas.sefaz.pi.gov.br/nfceweb/consultarNFCe.jsf',
117
            'RJ' => 'www.nfce.fazenda.rj.gov.br/consulta',
118
            'RN' => 'http://nfce.set.rn.gov.br/consultarNFCe.aspx',
119
            'RS' => 'https://www.sefaz.rs.gov.br/NFCE/NFCE-COM.aspx',
120
            'RO' => 'http://www.nfce.sefin.ro.gov.br',
121
            'RR' => 'https://www.sefaz.rr.gov.br/nfce/servlet/wp_consulta_nfce',
122
            'SC' => '',
123
            'SP' => 'https://www.nfce.fazenda.sp.gov.br/NFCeConsultaPublica/Paginas/ConsultaPublica.aspx',
124
            'SE' => 'http://www.nfce.se.gov.br/portal/portalNoticias.jsp',
125
            'TO' => '',
126
        ],
127
        '2' => [
128
            'AC' => 'http://hml.sefaznet.ac.gov.br/nfce/consulta',
129
            'AL' => 'http://nfce.sefaz.al.gov.br/consultaNFCe.htm',
130
            'AP' => 'https://www.sefaz.ap.gov.br/sate1/seg/SEGf_AcessarFuncao.jsp?cdFuncao=FIS_1261',
131
            'AM' => 'homnfce.sefaz.am.gov.br/nfceweb/formConsulta.do',
132
            'BA' => 'http://hnfe.sefaz.ba.gov.br/servicos/nfce/default.aspx',
133
            'CE' => 'http://nfceh.sefaz.ce.gov.br/pages/consultaNota.jsf',
134
            'DF' => 'http://dec.fazenda.df.gov.br/NFCE/',
135
            'ES' => 'http://homologacao.sefaz.es.gov.br/ConsultaNFCe',
136
            'GO' => '',
137
            'MA' => 'http://www.hom.nfce.sefaz.ma.gov.br/portal/consultarNFCe.jsp',
138
            'MT' => 'http://homologacao.sefaz.mt.gov.br/nfce/consultanfce',
139
            'MS' => 'http://www.dfe.ms.gov.br/nfce',
140
            'MG' => '',
141
            'PA' => 'https://appnfc.sefa.pa.gov.br/portal-homologacao/view/consultas/nfce/consultanfce.seam',
142
            'PB' => '',
143
            'PR' => 'http://www.fazenda.pr.gov.br',
144
            'PE' => '',
145
            'PI' => 'http://webas.sefaz.pi.gov.br/nfceweb-homologacao/consultarNFCe.jsf',
146
            'RJ' => 'www.nfce.fazenda.rj.gov.br/consulta',
147
            'RN' => 'http://nfce.set.rn.gov.br/consultarNFCe.aspx',
148
            'RS' => 'https://www.sefaz.rs.gov.br/NFCE/NFCE-COM.aspx',
149
            'RO' => 'http://www.nfce.sefin.ro.gov.br',
150
            'RR' => 'http://200.174.88.103:8080/nfce/servlet/wp_consulta_nfce',
151
            'SC' => '',
152
            'SP' => 'https://www.homologacao.nfce.fazenda.sp.gov.br/NFCeConsultaPublica/Paginas/ConsultaPublica.aspx',
153
            'SE' => 'http://www.hom.nfe.se.gov.br/portal/portalNoticias.jsp',
154
            'TO' => '',
155
        ],
156
    ];
157
    /**
158
     * __contruct
159
     *
160
     * @param string $docXML
161
     * @param string $sPathLogo
162
     * @param string $mododebug
163
     * @param string $idToken
164
     * @param string $emitToken
165
     * @param string $urlQR
166
     */
167
    public function __construct(
168
        $docXML = '',
169
        $sPathLogo = '',
170
        $mododebug = 0,
171
        // habilita os erros do sistema
172
        $idToken = '',
0 ignored issues
show
Unused Code introduced by
The parameter $idToken is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
173
        $emitToken = '',
0 ignored issues
show
Unused Code introduced by
The parameter $emitToken is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
174
        $urlQR = ''
0 ignored issues
show
Unused Code introduced by
The parameter $urlQR is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
175
    ) {
176
        if (is_numeric($mododebug)) {
177
            $this->debugMode = $mododebug;
0 ignored issues
show
Documentation Bug introduced by
It seems like $mododebug can also be of type double or string. However, the property $debugMode is declared as type integer. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
178
        }
179
        if ($this->debugMode) {
180
            //ativar modo debug
181
            error_reporting(E_ALL);
182
            ini_set('display_errors', 'On');
183
        } else {
184
            //desativar modo debug
185
            error_reporting(0);
186
            ini_set('display_errors', 'Off');
187
        }
188
        $this->xml = $docXML;
189
        $this->logomarca = $sPathLogo;
190
        $this->fontePadrao = empty($fonteDANFE) ? 'Times' : $fonteDANFE;
0 ignored issues
show
Bug introduced by
The variable $fonteDANFE seems to never exist, and therefore empty should always return true. Did you maybe rename this variable?

This check looks for calls to isset(...) or empty() on variables that are yet undefined. These calls will always produce the same result and can be removed.

This is most likely caused by the renaming of a variable or the removal of a function/method parameter.

Loading history...
191
        $this->aFontTit = array('font' => $this->fontePadrao, 'size' => 9, 'style' => 'B');
192
        $this->aFontTex = array('font' => $this->fontePadrao, 'size' => 8, 'style' => '');
193
        if (!empty($this->xml)) {
194
            $this->dom = new Dom();
0 ignored issues
show
Bug introduced by
The property dom does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
195
            $this->dom->loadXML($this->xml);
196
            $this->nfeProc = $this->dom->getElementsByTagName("nfeProc")->item(0);
197
            $this->nfe = $this->dom->getElementsByTagName("NFe")->item(0);
198
            $this->infNFe = $this->dom->getElementsByTagName("infNFe")->item(0);
199
            $this->ide = $this->dom->getElementsByTagName("ide")->item(0);
200
            $this->emit = $this->dom->getElementsByTagName("emit")->item(0);
201
            $this->enderEmit = $this->dom->getElementsByTagName("enderEmit")->item(0);
202
            $this->det = $this->dom->getElementsByTagName("det");
203
            $this->dest = $this->dom->getElementsByTagName("dest")->item(0);
204
            $this->imposto = $this->dom->getElementsByTagName("imposto")->item(0);
205
            $this->ICMSTot = $this->dom->getElementsByTagName("ICMSTot")->item(0);
206
            $this->tpImp = $this->ide->getElementsByTagName("tpImp")->item(0)->nodeValue;
207
            $this->infAdic = $this->dom->getElementsByTagName("infAdic")->item(0);
208
209
            $this->tpEmis = $this->pSimpleGetValue($this->ide, "tpEmis");
210
211
            //se for o layout 4.0 busca pelas tags de detalhe do pagamento
212
            //senao, busca pelas tags de pagamento principal
213
            if ($this->infNFe->getAttribute("versao") == "4.00") {
214
                $this->pag = $this->dom->getElementsByTagName("detPag");
215
216
                $tagPag = $this->dom->getElementsByTagName("pag")->item(0);
217
                $this->vTroco = $this->pSimpleGetValue($tagPag, "vTroco");
218
            } else {
219
                $this->pag = $this->dom->getElementsByTagName("pag");
220
            }
221
        }
222
        $this->qrCode = $this->dom->getElementsByTagName('qrCode')->item(0)->nodeValue;
223
        if ($this->pSimpleGetValue($this->ide, "mod") != '65') {
224
            throw new InvalidArgumentException("O xml do DANFE deve ser uma NFC-e modelo 65");
225
        }
226
    }
227
228
    public function getPapel()
229
    {
230
        return $this->papel;
231
    }
232
233
    public function setPapel($aPap)
234
    {
235
        $this->papel = $aPap;
236
    }
237
238
    public function monta(
239
        $orientacao = 'P',
240
        $papel = '',
241
        $logoAlign = 'C',
242
        $classPdf = false,
243
        $depecNumReg = ''
244
    ) {
245
        $this->montaDANFE($orientacao, $papel, $logoAlign, $classPdf, $depecNumReg);
246
    }
247
248
    public function montaDANFE(
249
        $orientacao = 'P',
250
        $papel = '',
0 ignored issues
show
Unused Code introduced by
The parameter $papel is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
251
        $logoAlign = 'C',
252
        $classPdf = false,
253
        $depecNumReg = ''
254
    ) {
255
        $qtdItens = $this->det->length;
256
        $qtdPgto = $this->pag->length;
257
        $hMaxLinha = $this->hMaxLinha;
258
        $hBoxLinha = $this->hBoxLinha;
0 ignored issues
show
Unused Code introduced by
$hBoxLinha is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
259
        $hLinha = $this->hLinha;
260
        // O 11 são das margins para as linhas
261
        $tamPapelVert = 160 + 16 + 12 + (($qtdItens - 1) * $hMaxLinha) + ($qtdPgto * $hLinha);
262
        // verifica se existe informações adicionais
263
        $this->textoAdic = '';
264
        if (isset($this->infAdic)) {
265
            $this->textoAdic .= !empty($this->infAdic->getElementsByTagName('infCpl')->item(0)->nodeValue) ?
266
            'Inf. Contribuinte: ' .
267
            trim($this->pAnfavea($this->infAdic->getElementsByTagName('infCpl')->item(0)->nodeValue)) : '';
268
            if (!empty($this->textoAdic)) {
269
                $this->textoAdic = str_replace(";", "\n", $this->textoAdic);
270
                $alinhas = explode("\n", $this->textoAdic);
271
                $numlinhasdados = 0;
272
                $tempPDF = new Pdf(); // cria uma instancia temporaria da class pdf
273
                $tempPDF->SetFont('Times', '', '8'); // seta a font do PDF
274
                foreach ($alinhas as $linha) {
275
                    $linha = trim($linha);
276
                    $numlinhasdados += $tempPDF->WordWrap($linha, 76 - 0.2);
0 ignored issues
show
Documentation introduced by
$linha is of type string, but the function expects a object<NFePHP\DA\Legacy\type>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
Documentation introduced by
76 - 0.2 is of type double, but the function expects a object<NFePHP\DA\Legacy\type>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
277
                }
278
                $hdadosadic = round(($numlinhasdados + 1) * $tempPDF->fontSize, 0);
279
                if ($hdadosadic < 5) {
280
                    $hdadosadic = 5;
281
                }
282
                // seta o tamanho do papel
283
                $tamPapelVert += $hdadosadic;
284
            }
285
        }
286
        //se a orientação estiver em branco utilizar o padrão estabelecido na NF
287
        if ($orientacao == '') {
288
            $orientacao = 'P';
289
        }
290
        $this->orientacao = $orientacao;
0 ignored issues
show
Bug introduced by
The property orientacao does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
291
        $this->papel = array(80, $tamPapelVert);
292
        $this->logoAlign = $logoAlign;
0 ignored issues
show
Bug introduced by
The property logoAlign does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
293
        //$this->situacao_externa = $situacaoExterna;
0 ignored issues
show
Unused Code Comprehensibility introduced by
50% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
294
        $this->numero_registro_dpec = $depecNumReg;
0 ignored issues
show
Bug introduced by
The property numero_registro_dpec does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
295
        //instancia a classe pdf
296
        if ($classPdf) {
297
            $this->pdf = $classPdf;
298
        } else {
299
            $this->pdf = new Pdf($this->orientacao, 'mm', $this->papel);
0 ignored issues
show
Documentation introduced by
$this->papel is of type array<integer,integer|do...,"1":"double|integer"}>, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
300
        }
301
        //margens do PDF, em milímetros. Obs.: a margem direita é sempre igual à
302
        //margem esquerda. A margem inferior *não* existe na FPDF, é definida aqui
303
        //apenas para controle se necessário ser maior do que a margem superior
304
        $margSup = 2;
305
        $margEsq = 2;
306
        $margInf = 2;
307
        // posição inicial do conteúdo, a partir do canto superior esquerdo da página
308
        $xInic = $margEsq;
309
        $yInic = $margSup;
310
        $maxW = 80;
311
        $maxH = $tamPapelVert;
312
        //total inicial de paginas
313
        $totPag = 1;
0 ignored issues
show
Unused Code introduced by
$totPag is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
314
        //largura imprimivel em mm: largura da folha menos as margens esq/direita
315
        $this->wPrint = $maxW - ($margEsq * 2);
0 ignored issues
show
Bug introduced by
The property wPrint does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
316
        //comprimento (altura) imprimivel em mm: altura da folha menos as margens
317
        //superior e inferior
318
        $this->hPrint = $maxH - $margSup - $margInf;
0 ignored issues
show
Bug introduced by
The property hPrint does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
319
        // estabelece contagem de paginas
320
        $this->pdf->aliasNbPages();
321
        $this->pdf->setMargins($margEsq, $margSup); // fixa as margens
322
        $this->pdf->setDrawColor(0, 0, 0);
323
        $this->pdf->setFillColor(255, 255, 255);
324
        $this->pdf->open(); // inicia o documento
325
        $this->pdf->addPage($this->orientacao, $this->papel); // adiciona a primeira página
0 ignored issues
show
Documentation introduced by
$this->papel is of type array<integer,integer|do...,"1":"double|integer"}>, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
326
        $this->pdf->setLineWidth(0.1); // define a largura da linha
327
        $this->pdf->setTextColor(0, 0, 0);
328
        $this->pTextBox(0, 0, $maxW, $maxH); // POR QUE PRECISO DESA LINHA?
329
        $hcabecalho = 27; //para cabeçalho (dados emitente mais logomarca)  (FIXO)
330
        $hcabecalhoSecundario = 10 + 3; //para cabeçalho secundário (cabeçalho sefaz) (FIXO)
331
        $hprodutos = $hLinha + ($qtdItens * $hMaxLinha) + 3; //box poduto
332
        $hTotal = 12; //box total (FIXO)
333
        $hpagamentos = $hLinha + ($qtdPgto * $hLinha) + 3; //para pagamentos
334
        if (!empty($this->vTroco)) {
335
            $hpagamentos += $hLinha;
336
        }
337
        $hmsgfiscal = 21 + 2; // para imposto (FIXO)
338
        $hcliente = !isset($this->dest) ? 6 : 12; // para cliente (FIXO)
339
        $hcontingencia = $this->tpEmis == 9 ? 6 : 0; // para contingência (FIXO)
340
        $hQRCode = 50; // para qrcode (FIXO)
341
        $hCabecItens = 4; //cabeçalho dos itens
342
343
        $hUsado = $hCabecItens;
0 ignored issues
show
Unused Code introduced by
$hUsado is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
344
        $w2 = round($this->wPrint * 0.31, 0);
0 ignored issues
show
Unused Code introduced by
$w2 is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
345
        $totPag = 1;
346
        $pag = 1;
347
        $x = $xInic;
348
        // Parametros linha tracejada
349
        $jj;
0 ignored issues
show
Bug introduced by
The variable $jj seems only to be defined at a later point. Did you maybe move this code here without moving the variable definition?

This error can happen if you refactor code and forget to move the variable initialization.

Let’s take a look at a simple example:

function someFunction() {
    $x = 5;
    echo $x;
}

The above code is perfectly fine. Now imagine that we re-order the statements:

function someFunction() {
    echo $x;
    $x = 5;
}

In that case, $x would be read before it is initialized. This was a very basic example, however the principle is the same for the found issue.

Loading history...
350
        //COLOCA CABEÇALHO
351
        $y = $yInic;
352
        $y = $this->pCabecalhoDANFE($x, $y, $hcabecalho, $pag, $totPag);
0 ignored issues
show
Bug introduced by
Are you sure the assignment to $y is correct as $this->pCabecalhoDANFE($...becalho, $pag, $totPag) (which targets NFePHP\DA\NFe\Danfce::pCabecalhoDANFE()) seems to always return null.

This check looks for function or method calls that always return null and whose return value is assigned to a variable.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
$object = $a->getObject();

The method getObject() can return nothing but null, so it makes no sense to assign that value to a variable.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
Unused Code introduced by
$y is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
353
        //COLOCA CABEÇALHO SECUNDÁRIO
354
        $y = $hcabecalho;
355
        $y = $this->pCabecalhoSecundarioDANFE($x, $y, $hcabecalhoSecundario);
0 ignored issues
show
Bug introduced by
Are you sure the assignment to $y is correct as $this->pCabecalhoSecunda... $hcabecalhoSecundario) (which targets NFePHP\DA\NFe\Danfce::pCabecalhoSecundarioDANFE()) seems to always return null.

This check looks for function or method calls that always return null and whose return value is assigned to a variable.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
$object = $a->getObject();

The method getObject() can return nothing but null, so it makes no sense to assign that value to a variable.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
Unused Code introduced by
$y is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
356
        // linha
357
        $jj = $hcabecalho + $hcabecalhoSecundario;
0 ignored issues
show
Unused Code introduced by
$jj is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
358
        //COLOCA PRODUTOS
359
        $y = $xInic + $hcabecalho + $hcabecalhoSecundario;
360
        $y = $this->pProdutosDANFE($x, $y, $hprodutos);
0 ignored issues
show
Bug introduced by
Are you sure the assignment to $y is correct as $this->pProdutosDANFE($x, $y, $hprodutos) (which targets NFePHP\DA\NFe\Danfce::pProdutosDANFE()) seems to always return null.

This check looks for function or method calls that always return null and whose return value is assigned to a variable.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
$object = $a->getObject();

The method getObject() can return nothing but null, so it makes no sense to assign that value to a variable.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
Unused Code introduced by
$y is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
361
        // linha
362
        $jj = $hcabecalho + $hcabecalhoSecundario + $hprodutos + $dashedLine;
0 ignored issues
show
Bug introduced by
The variable $dashedLine does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
Unused Code introduced by
$jj is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
363
        //COLOCA TOTAL
364
        $y = $xInic + $hcabecalho + $hcabecalhoSecundario + $hprodutos;
365
        $y = $this->pTotalDANFE($x, $y, $hTotal);
0 ignored issues
show
Bug introduced by
Are you sure the assignment to $y is correct as $this->pTotalDANFE($x, $y, $hTotal) (which targets NFePHP\DA\NFe\Danfce::pTotalDANFE()) seems to always return null.

This check looks for function or method calls that always return null and whose return value is assigned to a variable.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
$object = $a->getObject();

The method getObject() can return nothing but null, so it makes no sense to assign that value to a variable.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
Unused Code introduced by
$y is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
366
        //COLOCA PAGAMENTOS
367
        $y = $xInic + $hcabecalho + $hcabecalhoSecundario + $hprodutos + $hTotal;
368
        $y = $this->pPagamentosDANFE($x, $y, $hpagamentos);
0 ignored issues
show
Bug introduced by
Are you sure the assignment to $y is correct as $this->pPagamentosDANFE($x, $y, $hpagamentos) (which targets NFePHP\DA\NFe\Danfce::pPagamentosDANFE()) seems to always return null.

This check looks for function or method calls that always return null and whose return value is assigned to a variable.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
$object = $a->getObject();

The method getObject() can return nothing but null, so it makes no sense to assign that value to a variable.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
Unused Code introduced by
$y is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
369
        // linha
370
        $jj = $xInic + $hcabecalho + $hcabecalhoSecundario + $hprodutos + $hTotal + $hpagamentos;
0 ignored issues
show
Unused Code introduced by
$jj is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
371
        //COLOCA MENSAGEM FISCAL
372
        $y = $xInic + $hcabecalho + $hcabecalhoSecundario + $hprodutos + $hTotal + $hpagamentos;
373
        $y = $this->pFiscalDANFE($x, $y, $hmsgfiscal);
0 ignored issues
show
Bug introduced by
Are you sure the assignment to $y is correct as $this->pFiscalDANFE($x, $y, $hmsgfiscal) (which targets NFePHP\DA\NFe\Danfce::pFiscalDANFE()) seems to always return null.

This check looks for function or method calls that always return null and whose return value is assigned to a variable.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
$object = $a->getObject();

The method getObject() can return nothing but null, so it makes no sense to assign that value to a variable.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
Unused Code introduced by
$y is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
374
        //COLOCA CONSUMIDOR
375
        $y = $xInic + $hcabecalho + $hcabecalhoSecundario + $hprodutos + $hTotal + $hpagamentos + $hmsgfiscal;
376
        $jj = $y;
0 ignored issues
show
Unused Code introduced by
$jj is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
377
        $y = $this->pConsumidorDANFE($x, $y, $hcliente);
0 ignored issues
show
Bug introduced by
Are you sure the assignment to $y is correct as $this->pConsumidorDANFE($x, $y, $hcliente) (which targets NFePHP\DA\NFe\Danfce::pConsumidorDANFE()) seems to always return null.

This check looks for function or method calls that always return null and whose return value is assigned to a variable.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
$object = $a->getObject();

The method getObject() can return nothing but null, so it makes no sense to assign that value to a variable.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
Unused Code introduced by
$y is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
378
        //COLOCA Contingência
379
        if ($this->tpEmis == 9) {
380
            $y = $xInic + $hcabecalho + $hcabecalhoSecundario + $hprodutos + $hTotal + $hpagamentos + $hmsgfiscal 
381
                + $hcliente + 1;
382
            $y = $this->pContingencia($x, $y, $hcontingencia);
0 ignored issues
show
Bug introduced by
Are you sure the assignment to $y is correct as $this->pContingencia($x, $y, $hcontingencia) (which targets NFePHP\DA\NFe\Danfce::pContingencia()) seems to always return null.

This check looks for function or method calls that always return null and whose return value is assigned to a variable.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
$object = $a->getObject();

The method getObject() can return nothing but null, so it makes no sense to assign that value to a variable.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
Unused Code introduced by
$y is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
383
        }
384
        //COLOCA QRCODE
385
        $y = $xInic + $hcabecalho + $hcabecalhoSecundario + $hprodutos + $hTotal + $hpagamentos + $hmsgfiscal 
386
            + $hcliente + 1 + $hcontingencia;
387
        $jj = $y + $hQRCode;
0 ignored issues
show
Unused Code introduced by
$jj is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
388
        $y = $this->pQRDANFE($x, $y, $hQRCode);
0 ignored issues
show
Bug introduced by
Are you sure the assignment to $y is correct as $this->pQRDANFE($x, $y, $hQRCode) (which targets NFePHP\DA\NFe\Danfce::pQRDANFE()) seems to always return null.

This check looks for function or method calls that always return null and whose return value is assigned to a variable.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
$object = $a->getObject();

The method getObject() can return nothing but null, so it makes no sense to assign that value to a variable.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
Unused Code introduced by
$y is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
389
390
        //adiciona as informações opcionais
391
        if (!empty($this->textoAdic)) {
392
            $y = $xInic + $hcabecalho + $hcabecalhoSecundario + $hprodutos
393
                 + $hTotal + $hpagamentos + $hmsgfiscal + $hcliente + $hQRCode;
394
            $hInfAdic = 0;
395
            $y = $this->pInfAdic($x, $y, $hInfAdic);
0 ignored issues
show
Bug introduced by
Are you sure the assignment to $y is correct as $this->pInfAdic($x, $y, $hInfAdic) (which targets NFePHP\DA\NFe\Danfce::pInfAdic()) seems to always return null.

This check looks for function or method calls that always return null and whose return value is assigned to a variable.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
$object = $a->getObject();

The method getObject() can return nothing but null, so it makes no sense to assign that value to a variable.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
Unused Code introduced by
$y is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
396
        }
397
398
        //retorna o ID na NFe
399
        if ($classPdf !== false) {
400
            $aR = [
401
                'id' => str_replace('NFe', '', $this->infNFe->getAttribute("Id")),
402
                'classe_PDF' => $this->pdf,
403
            ];
404
            return $aR;
405
        } else {
406
            return str_replace('NFe', '', $this->infNFe->getAttribute("Id"));
407
        }
408
    }
409
410
    protected function pCabecalhoDANFE($x = 0, $y = 0, $h = 0, $pag = '1', $totPag = '1')
0 ignored issues
show
Unused Code introduced by
The parameter $x is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $pag is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $totPag is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
411
    {
412
        $emitRazao = $this->pSimpleGetValue($this->emit, "xNome");
413
        $emitCnpj = $this->pSimpleGetValue($this->emit, "CNPJ");
414
        $emitCnpj = $this->pFormat($emitCnpj, "##.###.###/####-##");
415
        $emitIE = $this->pSimpleGetValue($this->emit, "IE");
416
        $emitIM = $this->pSimpleGetValue($this->emit, "IM");
417
        $emitFone = $this->pSimpleGetValue($this->enderEmit, "fone");
418
        $foneLen = strlen($emitFone);
419
        if ($foneLen > 0) {
420
            $ddd = substr($emitFone, 0, 2);
421
            $fone1 = substr($emitFone, -8);
422
            $digito9 = ' ';
423
            if ($foneLen == 11) {
424
                $digito9 = substr($emitFone, 2, 1);
425
            }
426
            $emitFone = ' - (' . $ddd . ') ' . $digito9 . ' ' . substr($fone1, 0, 4) . '-' . substr($fone1, -4);
427
        } else {
428
            $emitFone = '';
429
        }
430
        $emitLgr = $this->pSimpleGetValue($this->enderEmit, "xLgr");
431
        $emitNro = $this->pSimpleGetValue($this->enderEmit, "nro");
432
        $emitCpl = $this->pSimpleGetValue($this->enderEmit, "xCpl", "");
433
        $emitBairro = $this->pSimpleGetValue($this->enderEmit, "xBairro");
434
        $emitCEP = $this->pFormat($this->pSimpleGetValue($this->enderEmit, "CEP"), "#####-###");
435
        $emitMun = $this->pSimpleGetValue($this->enderEmit, "xMun");
436
        $emitUF = $this->pSimpleGetValue($this->enderEmit, "UF");
437
        // CONFIGURAÇÃO DE POSIÇÃO
438
        $margemInterna = $this->margemInterna;
439
        $maxW = $this->wPrint;
440
        $h = $h - ($margemInterna);
441
        //COLOCA LOGOMARCA
442
        if (is_file($this->logomarca)) {
443
            $xImg = $margemInterna;
444
            $yImg = $margemInterna + 1;
445
            $this->pdf->Image($this->logomarca, $xImg, $yImg, 30, 22.5);
446
            $xRs = ($maxW * 0.4) + $margemInterna;
447
            $wRs = ($maxW * 0.6);
448
            $alignEmit = 'L';
449
        } else {
450
            $xRs = $margemInterna;
451
            $wRs = ($maxW * 1);
452
            $alignEmit = 'L';
453
        }
454
        //COLOCA RAZÃO SOCIAL
455
        $texto = $emitRazao;
456
        $texto = $texto . "\nCNPJ:" . $emitCnpj;
457
        $texto = $texto . "\nIE:" . $emitIE;
458
        if (!empty($emitIM)) {
459
            $texto = $texto . " - IM:" . $emitIM;
460
        }
461
        $texto = $texto . "\n" . $emitLgr . "," . $emitNro . " " . $emitCpl . "," . $emitBairro
462
            . ". CEP:" . $emitCEP . ". " . $emitMun . "-" . $emitUF . $emitFone;
463
        $this->pTextBox($xRs, $y, $wRs, $h, $texto, $this->aFontTex, 'C', $alignEmit, 0, '', false);
464
    }
465
466
    protected function pCabecalhoSecundarioDANFE($x = 0, $y = 0, $h = 0)
0 ignored issues
show
Unused Code introduced by
The parameter $h is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
467
    {
468
        $margemInterna = $this->margemInterna;
0 ignored issues
show
Unused Code introduced by
$margemInterna is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
469
        $maxW = $this->wPrint;
470
        $w = ($maxW * 1);
471
        $hBox1 = 7;
472
        $texto = $this->tpEmis == 9 ? 
473
            "EMITIDA EM CONTINGÊNCIA" : 
474
            "DANFE NFC-e\nDocumento Auxiliar da Nota Fiscal de Consumidor Eletrônica";
475
        $this->pTextBox($x, $y, $w, $hBox1, $texto, $this->aFontTit, 'C', 'C', 0, '', false);
476
        $hBox2 = 4;
477
        $yBox2 = $y + $hBox1;
478
        $texto = $this->tpEmis == 9 ? 
479
            "\nPendente de autorização" : 
480
            "\nNFC-e não permite aproveitamento de crédito de ICMS";
481
        $aFont = array('font' => $this->fontePadrao, 'size' => 7, 'style' => '');
482
        $this->pTextBox($x, $yBox2, $w, $hBox2, $texto, $aFont, 'C', 'C', 0, '', false);
483
    }
484
485
    protected function pProdutosDANFE($x = 0, $y = 0, $h = 0)
0 ignored issues
show
Unused Code introduced by
The parameter $h is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
486
    {
487
        $margemInterna = $this->margemInterna;
0 ignored issues
show
Unused Code introduced by
$margemInterna is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
488
        $maxW = $this->wPrint;
489
        $qtdItens = $this->det->length;
490
        $w = ($maxW * 1);
491
        $hLinha = $this->hLinha;
492
        $aFontCabProdutos = array('font' => $this->fontePadrao, 'size' => 7, 'style' => 'B');
493
        $wBoxCod = $w * 0.17;
494
        $texto = "CÓDIGO";
495
        $this->pTextBox($x, $y, $wBoxCod, $hLinha, $texto, $aFontCabProdutos, 'T', 'L', 0, '', false);
496
        $wBoxDescricao = $w * 0.43;
497
        $xBoxDescricao = $wBoxCod + $x;
498
        $texto = "DESCRICÃO";
499
        $this->pTextBox(
500
            $xBoxDescricao,
501
            $y,
502
            $wBoxDescricao,
503
            $hLinha,
504
            $texto,
505
            $aFontCabProdutos,
506
            'T',
507
            'L',
508
            0,
509
            '',
510
            false
511
        );
512
        $wBoxQt = $w * 0.08;
513
        $xBoxQt = $wBoxDescricao + $xBoxDescricao;
514
        $texto = "QT";
515
        $this->pTextBox($xBoxQt, $y, $wBoxQt, $hLinha, $texto, $aFontCabProdutos, 'T', 'L', 0, '', false);
516
        $wBoxUn = $w * 0.06;
517
        $xBoxUn = $wBoxQt + $xBoxQt;
518
        $texto = "UN";
519
        $this->pTextBox($xBoxUn, $y, $wBoxUn, $hLinha, $texto, $aFontCabProdutos, 'T', 'L', 0, '', false);
520
        $wBoxVl = $w * 0.13;
521
        $xBoxVl = $wBoxUn + $xBoxUn;
522
        $texto = "VALOR";
523
        $this->pTextBox($xBoxVl, $y, $wBoxVl, $hLinha, $texto, $aFontCabProdutos, 'T', 'L', 0, '', false);
524
        $wBoxTotal = $w * 0.13;
525
        $xBoxTotal = $wBoxVl + $xBoxVl;
526
        $texto = "TOTAL";
527
        $this->pTextBox($xBoxTotal, $y, $wBoxTotal, $hLinha, $texto, $aFontCabProdutos, 'T', 'L', 0, '', false);
528
        $hBoxLinha = $this->hBoxLinha;
0 ignored issues
show
Unused Code introduced by
$hBoxLinha is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
529
        $hMaxLinha = $this->hMaxLinha;
530
        $cont = 0;
531
        $aFontProdutos = array('font' => $this->fontePadrao, 'size' => 7, 'style' => '');
532
        if ($qtdItens > 0) {
533
            foreach ($this->det as $detI) {
534
                $thisItem = $detI;
535
                $prod = $thisItem->getElementsByTagName("prod")->item(0);
536
                $nitem = $thisItem->getAttribute("nItem");
0 ignored issues
show
Unused Code introduced by
$nitem is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
537
                $cProd = $this->pSimpleGetValue($prod, "cProd");
538
                $xProd = $this->pSimpleGetValue($prod, "xProd");
539
                $qCom = number_format($this->pSimpleGetValue($prod, "qCom"), 2, ",", ".");
540
                $uCom = $this->pSimpleGetValue($prod, "uCom");
541
                $vUnCom = number_format($this->pSimpleGetValue($prod, "vUnCom"), 2, ",", ".");
542
                $vProd = number_format($this->pSimpleGetValue($prod, "vProd"), 2, ",", ".");
543
                //COLOCA PRODUTO
544
                $yBoxProd = $y + $hLinha + ($cont * $hMaxLinha);
545
                //COLOCA PRODUTO CÓDIGO
546
                $wBoxCod = $w * 0.17;
547
                $texto = $cProd;
548
                $this->pTextBox($x, $yBoxProd, $wBoxCod, $hMaxLinha, $texto, $aFontProdutos, 'C', 'C', 0, '', false);
549
                //COLOCA PRODUTO DESCRIÇÃO
550
                $wBoxDescricao = $w * 0.43;
551
                $xBoxDescricao = $wBoxCod + $x;
552
                $texto = $xProd;
553
                $this->pTextBox(
554
                    $xBoxDescricao,
555
                    $yBoxProd,
556
                    $wBoxDescricao,
557
                    $hMaxLinha,
558
                    $texto,
559
                    $aFontProdutos,
560
                    'C',
561
                    'L',
562
                    0,
563
                    '',
564
                    false
565
                );
566
                //COLOCA PRODUTO QUANTIDADE
567
                $wBoxQt = $w * 0.08;
568
                $xBoxQt = $wBoxDescricao + $xBoxDescricao;
569
                $texto = $qCom;
570
                $this->pTextBox(
571
                    $xBoxQt,
572
                    $yBoxProd,
573
                    $wBoxQt,
574
                    $hMaxLinha,
575
                    $texto,
576
                    $aFontProdutos,
577
                    'C',
578
                    'C',
579
                    0,
580
                    '',
581
                    false
582
                );
583
                //COLOCA PRODUTO UNIDADE
584
                $wBoxUn = $w * 0.06;
585
                $xBoxUn = $wBoxQt + $xBoxQt;
586
                $texto = $uCom;
587
                $this->pTextBox(
588
                    $xBoxUn,
589
                    $yBoxProd,
590
                    $wBoxUn,
591
                    $hMaxLinha,
592
                    $texto,
593
                    $aFontProdutos,
594
                    'C',
595
                    'C',
596
                    0,
597
                    '',
598
                    false
599
                );
600
                //COLOCA PRODUTO VL UNITÁRIO
601
                $wBoxVl = $w * 0.13;
602
                $xBoxVl = $wBoxUn + $xBoxUn;
603
                $texto = $vUnCom;
604
                $this->pTextBox(
605
                    $xBoxVl,
606
                    $yBoxProd,
607
                    $wBoxVl,
608
                    $hMaxLinha,
609
                    $texto,
610
                    $aFontProdutos,
611
                    'C',
612
                    'R',
613
                    0,
614
                    '',
615
                    false
616
                );
617
                //COLOCA PRODUTO VL TOTAL
618
                $wBoxTotal = $w * 0.13;
619
                $xBoxTotal = $wBoxVl + $xBoxVl;
620
                $texto = $vProd;
621
                $this->pTextBox(
622
                    $xBoxTotal,
623
                    $yBoxProd,
624
                    $wBoxTotal,
625
                    $hMaxLinha,
626
                    $texto,
627
                    $aFontProdutos,
628
                    'C',
629
                    'R',
630
                    0,
631
                    '',
632
                    false
633
                );
634
635
                $cont++;
636
            }
637
        }
638
    }
639
640
    protected function pTotalDANFE($x = 0, $y = 0, $h = 0)
0 ignored issues
show
Unused Code introduced by
The parameter $h is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
641
    {
642
        $margemInterna = $this->margemInterna;
0 ignored issues
show
Unused Code introduced by
$margemInterna is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
643
        $maxW = $this->wPrint;
644
        $hLinha = 3;
645
        $wColEsq = ($maxW * 0.7);
646
        $wColDir = ($maxW * 0.3);
647
        $xValor = $x + $wColEsq;
648
        $qtdItens = $this->det->length;
649
        $vProd = $this->pSimpleGetValue($this->ICMSTot, "vProd");
650
        $vNF = $this->pSimpleGetValue($this->ICMSTot, "vNF");
651
        $vDesc = $this->pSimpleGetValue($this->ICMSTot, "vDesc");
652
        $vFrete = $this->pSimpleGetValue($this->ICMSTot, "vFrete");
653
        $vTotTrib = $this->pSimpleGetValue($this->ICMSTot, "vTotTrib");
654
        $texto = "Qtd. Total de Itens";
655
        $aFont = array('font' => $this->fontePadrao, 'size' => 7, 'style' => 'B');
656
        $this->pTextBox($x, $y, $wColEsq, $hLinha, $texto, $aFont, 'T', 'L', 0, '', false);
657
        $texto = $qtdItens;
658
        $aFont = array('font' => $this->fontePadrao, 'size' => 7, 'style' => 'B');
659
        $this->pTextBox($xValor, $y, $wColDir, $hLinha, $texto, $aFont, 'T', 'R', 0, '', false);
660
        $yTotal = $y + ($hLinha);
661
        $texto = "Total de Produtos";
662
        $aFont = array('font' => $this->fontePadrao, 'size' => 7, 'style' => 'B');
663
        $this->pTextBox($x, $yTotal, $wColEsq, $hLinha, $texto, $aFont, 'T', 'L', 0, '', false);
664
        $texto = "R$ " . number_format($vProd, 2, ",", ".");
665
        $aFont = array('font' => $this->fontePadrao, 'size' => 7, 'style' => 'B');
666
        $this->pTextBox($xValor, $yTotal, $wColDir, $hLinha, $texto, $aFont, 'T', 'R', 0, '', false);
667
        $yDesconto = $y + ($hLinha * 2);
668
        $texto = "Descontos";
669
        $aFont = array('font' => $this->fontePadrao, 'size' => 7, 'style' => 'B');
670
        $this->pTextBox($x, $yDesconto, $wColEsq, $hLinha, $texto, $aFont, 'T', 'L', 0, '', false);
671
        $texto = "R$ " . $vDesc;
672
        $aFont = array('font' => $this->fontePadrao, 'size' => 7, 'style' => 'B');
673
        $this->pTextBox($xValor, $yDesconto, $wColDir, $hLinha, $texto, $aFont, 'T', 'R', 0, '', false);
674
        $yFrete = $y + ($hLinha * 3);
675
        $texto = "Frete";
676
        $aFont = array('font' => $this->fontePadrao, 'size' => 7, 'style' => 'B');
677
        $this->pTextBox($x, $yFrete, $wColEsq, $hLinha, $texto, $aFont, 'T', 'L', 0, '', false);
678
        $texto = "R$ " . $vFrete;
679
        $aFont = array('font' => $this->fontePadrao, 'size' => 7, 'style' => 'B');
680
        $this->pTextBox($xValor, $yFrete, $wColDir, $hLinha, $texto, $aFont, 'T', 'R', 0, '', false);
681
        $yTotalFinal = $y + ($hLinha * 4);
682
        $texto = "Total";
683
        $aFont = array('font' => $this->fontePadrao, 'size' => 7, 'style' => 'B');
684
        $this->pTextBox($x, $yTotalFinal, $wColEsq, $hLinha, $texto, $aFont, 'T', 'L', 0, '', false);
685
        $texto = "R$ " . $vNF;
686
        $aFont = array('font' => $this->fontePadrao, 'size' => 7, 'style' => 'B');
687
        $this->pTextBox($xValor, $yTotalFinal, $wColDir, $hLinha, $texto, $aFont, 'T', 'R', 0, '', false);
688
        $yTotalFinal = $y + ($hLinha * 5);
689
        $texto = "Informação dos Tributos Totais Incidentes";
690
        $aFont = array('font' => $this->fontePadrao, 'size' => 7, 'style' => '');
691
        $this->pTextBox($x, $yTotalFinal, $wColEsq, $hLinha, $texto, $aFont, 'T', 'L', 0, '', false);
692
        $texto = "R$ " . $vTotTrib;
693
        $aFont = array('font' => $this->fontePadrao, 'size' => 7, 'style' => 'B');
694
        $this->pTextBox($xValor, $yTotalFinal, $wColDir, $hLinha, $texto, $aFont, 'T', 'R', 0, '', false);
695
    }
696
697
    protected function pPagamentosDANFE($x = 0, $y = 0, $h = 0)
0 ignored issues
show
Unused Code introduced by
The parameter $h is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
698
    {
699
        $y += 6;
700
        $margemInterna = $this->margemInterna;
0 ignored issues
show
Unused Code introduced by
$margemInterna is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
701
        $maxW = $this->wPrint;
702
        $qtdPgto = $this->pag->length;
703
        $w = ($maxW * 1);
704
        $hLinha = $this->hLinha;
705
        $wColEsq = ($maxW * 0.7);
706
        $wColDir = ($maxW * 0.3);
0 ignored issues
show
Unused Code introduced by
$wColDir is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
707
        $xValor = $x + $wColEsq;
0 ignored issues
show
Unused Code introduced by
$xValor is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
708
        $aFontPgto = array('font' => $this->fontePadrao, 'size' => 7, 'style' => 'B');
709
        $wBoxEsq = $w * 0.7;
710
        $texto = "FORMA DE PAGAMENTO";
711
        $this->pTextBox($x, $y, $wBoxEsq, $hLinha, $texto, $aFontPgto, 'T', 'L', 0, '', false);
712
        $wBoxDir = $w * 0.3;
713
        $xBoxDescricao = $x + $wBoxEsq;
714
        $texto = "VALOR PAGO";
715
        $this->pTextBox($xBoxDescricao, $y, $wBoxDir, $hLinha, $texto, $aFontPgto, 'T', 'R', 0, '', false);
716
        $cont = 0;
717
        if ($qtdPgto > 0) {
718
            foreach ($this->pag as $pagI) {
719
                $tPag = $this->pSimpleGetValue($pagI, "tPag");
720
                $tPagNome = $this->tipoPag($tPag);
721
                $tPnome = $tPagNome;
0 ignored issues
show
Unused Code introduced by
$tPnome is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
722
                $vPag = number_format($this->pSimpleGetValue($pagI, "vPag"), 2, ",", ".");
723
                $card = $pagI->getElementsByTagName("card")->item(0);
724
                $cardCNPJ = '';
0 ignored issues
show
Unused Code introduced by
$cardCNPJ is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
725
                $tBand = '';
0 ignored issues
show
Unused Code introduced by
$tBand is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
726
                $tBandNome = '';
0 ignored issues
show
Unused Code introduced by
$tBandNome is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
727
                if (isset($card)) {
728
                    $cardCNPJ = $this->pSimpleGetValue($card, "CNPJ");
0 ignored issues
show
Unused Code introduced by
$cardCNPJ is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
729
                    $tBand = $this->pSimpleGetValue($card, "tBand");
730
                    $cAut = $this->pSimpleGetValue($card, "cAut");
0 ignored issues
show
Unused Code introduced by
$cAut is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
731
                    $tBandNome = self::getCardName($tBand);
0 ignored issues
show
Unused Code introduced by
$tBandNome is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
732
                }
733
                //COLOCA PRODUTO
734
                $yBoxProd = $y + $hLinha + ($cont * $hLinha);
735
                //COLOCA PRODUTO CÓDIGO
736
                $texto = $tPagNome;
737
                $this->pTextBox($x, $yBoxProd, $wBoxEsq, $hLinha, $texto, $aFontPgto, 'T', 'L', 0, '', false);
738
                //COLOCA PRODUTO DESCRIÇÃO
739
                $xBoxDescricao = $wBoxEsq + $x;
740
                $texto = "R$ " . $vPag;
741
                $this->pTextBox(
742
                    $xBoxDescricao,
743
                    $yBoxProd,
744
                    $wBoxDir,
745
                    $hLinha,
746
                    $texto,
747
                    $aFontPgto,
748
                    'C',
749
                    'R',
750
                    0,
751
                    '',
752
                    false
753
                );
754
                $cont++;
755
            }
756
757
            if (!empty($this->vTroco)) {
758
                $yBoxProd = $y + $hLinha + ($cont * $hLinha);
759
                //COLOCA PRODUTO CÓDIGO
760
                $texto = 'Troco';
761
                $this->pTextBox($x, $yBoxProd, $wBoxEsq, $hLinha, $texto, $aFontPgto, 'T', 'L', 0, '', false);
762
                //COLOCA PRODUTO DESCRIÇÃO
763
                $xBoxDescricao = $wBoxEsq + $x;
764
                $texto = "R$ " . number_format($this->vTroco, 2, ",", ".");
765
                $this->pTextBox(
766
                    $xBoxDescricao,
767
                    $yBoxProd,
768
                    $wBoxDir,
769
                    $hLinha,
770
                    $texto,
771
                    $aFontPgto,
772
                    'C',
773
                    'R',
774
                    0,
775
                    '',
776
                    false
777
                );
778
            }
779
        }
780
    }
781
782
    protected function pFiscalDANFE($x = 0, $y = 0, $h = 0)
783
    {
784
        $y += 6;
785
        $margemInterna = $this->margemInterna;
0 ignored issues
show
Unused Code introduced by
$margemInterna is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
786
        $maxW = $this->wPrint;
787
        $w = ($maxW * 1);
788
        $hLinha = $this->hLinha;
789
        $digVal = $this->pSimpleGetValue($this->nfe, "DigestValue");
0 ignored issues
show
Unused Code introduced by
$digVal is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
790
        $chNFe = str_replace('NFe', '', $this->infNFe->getAttribute("Id"));
791
        $tpAmb = $this->pSimpleGetValue($this->ide, 'tpAmb');
792
793
        if ($this->pNotaCancelada()) {
794
            //101 Cancelamento
795
            $this->pdf->SetTextColor(255, 0, 0);
796
            $texto = "NFCe CANCELADA";
797
            $this->pTextBox($x, $y - 30, $w, $h, $texto, $this->aFontTit, 'C', 'C', 0, '');
798
            $this->pdf->SetTextColor(0, 0, 0);
799
        }
800
801
        if ($this->pNotaDenegada()) {
802
            //uso denegado
803
            $this->pdf->SetTextColor(255, 0, 0);
804
            $texto = "NFCe CANCELADA";
805
            $this->pTextBox($x, $y - 30, $w, $h, $texto, $this->aFontTit, 'C', 'C', 0, '');
806
            $this->pdf->SetTextColor(0, 0, 0);
807
        }
808
809
        $cUF = $this->pSimpleGetValue($this->ide, 'cUF');
810
        $nNF = $this->pSimpleGetValue($this->ide, 'nNF');
811
        $serieNF = str_pad($this->pSimpleGetValue($this->ide, "serie"), 3, "0", STR_PAD_LEFT);
812
        $dhEmi = $this->pSimpleGetValue($this->ide, "dhEmi");
813
        $urlChave = $this->urlConsulta[$tpAmb][$this->UFSigla[$cUF]];
814
        $texto = "ÁREA DE MENSAGEM FISCAL";
815
        $this->pTextBox($x, $y, $w, $hLinha, $texto, $this->aFontTit, 'C', 'C', 0, '', false);
816
        $yTex1 = $y + ($hLinha * 1);
817
        $hTex1 = $hLinha * 2;
818
        $texto = "Número " . $nNF . " Série " . $serieNF . " " . $dhEmi . " - Via Consumidor";
819
        $this->pTextBox($x, $yTex1, $w, $hTex1, $texto, $this->aFontTex, 'C', 'C', 0, '', false);
820
        $yTex2 = $y + ($hLinha * 3);
821
        $hTex2 = $hLinha * 2;
822
        $texto = "Consulte pela Chave de Acesso em " . $urlChave;
823
        $this->pTextBox($x, $yTex2, $w, $hTex2, $texto, $this->aFontTex, 'C', 'C', 0, '', false);
824
        $texto = "CHAVE DE ACESSO";
825
        $yTit2 = $y + ($hLinha * 5);
826
        $this->pTextBox($x, $yTit2, $w, $hLinha, $texto, $this->aFontTit, 'C', 'C', 0, '', false);
827
        $yTex3 = $y + ($hLinha * 6);
828
        $texto = $chNFe;
829
        $this->pTextBox($x, $yTex3, $w, $hLinha, $texto, $this->aFontTex, 'C', 'C', 0, '', false);
830
    }
831
832
    protected function pContingencia($x = 0, $y = 0, $h = 0)
0 ignored issues
show
Unused Code introduced by
The parameter $h is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
833
    {
834
        $y += 7;
835
        $margemInterna = $this->margemInterna;
0 ignored issues
show
Unused Code introduced by
$margemInterna is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
836
        $maxW = $this->wPrint;
837
        $w = ($maxW * 1);
838
        $hLinha = $this->hLinha;
839
        $texto = "EMITIDA EM CONTINGÊNCIA";
840
        $this->pTextBox($x, $y, $w, $hLinha, $texto, $this->aFontTit, 'C', 'C', 0, '', false);
841
        $this->pTextBox($x, $y + 3, $w, $hLinha, "Pendente de autorização", $this->aFontTex, 'C', 'C', 0, '', false);
842
    }
843
844
    protected function pConsumidorDANFE($x = 0, $y = 0, $h = 0)
0 ignored issues
show
Unused Code introduced by
The parameter $h is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
845
    {
846
        $y += 6;
847
        $margemInterna = $this->margemInterna;
0 ignored issues
show
Unused Code introduced by
$margemInterna is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
848
        $maxW = $this->wPrint;
849
        $w = ($maxW * 1);
850
        $hLinha = $this->hLinha;
851
        $texto = "CONSUMIDOR";
852
        $this->pTextBox($x, $y, $w, $hLinha, $texto, $this->aFontTit, 'C', 'C', 0, '', false);
853
        if (isset($this->dest)) {
854
            $considEstrangeiro = !empty($this->dest->getElementsByTagName("idEstrangeiro")->item(0)->nodeValue)
855
            ? $this->dest->getElementsByTagName("idEstrangeiro")->item(0)->nodeValue
856
            : '';
857
            $consCPF = !empty($this->dest->getElementsByTagName("CPF")->item(0)->nodeValue)
858
            ? $this->dest->getElementsByTagName("CPF")->item(0)->nodeValue
859
            : '';
860
            $consCNPJ = !empty($this->dest->getElementsByTagName("CNPJ")->item(0)->nodeValue)
861
            ? $this->dest->getElementsByTagName("CNPJ")->item(0)->nodeValue
862
            : '';
863
            $cDest = $consCPF . $consCNPJ . $considEstrangeiro; //documentos do consumidor
0 ignored issues
show
Unused Code introduced by
$cDest is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
864
            $enderDest = $this->dest->getElementsByTagName("enderDest")->item(0);
865
            $consNome = $this->pSimpleGetValue($this->dest, "xNome");
866
            $consLgr = $this->pSimpleGetValue($enderDest, "xLgr");
867
            $consNro = $this->pSimpleGetValue($enderDest, "nro");
868
            $consCpl = $this->pSimpleGetValue($enderDest, "xCpl", " - ");
869
            $consBairro = $this->pSimpleGetValue($enderDest, "xBairro");
870
            $consCEP = $this->pFormat($this->pSimpleGetValue($enderDest, "CEP"));
871
            $consMun = $this->pSimpleGetValue($enderDest, "xMun");
872
            $consUF = $this->pSimpleGetValue($enderDest, "UF");
873
            $considEstrangeiro = $this->pSimpleGetValue($this->dest, "idEstrangeiro");
874
            $consCPF = $this->pSimpleGetValue($this->dest, "CPF");
875
            $consCNPJ = $this->pSimpleGetValue($this->dest, "CNPJ");
876
            $consDoc = "";
877
            if (!empty($consCNPJ)) {
878
                $consDoc = "CNPJ: $consCNPJ";
879
            } elseif (!empty($consCPF)) {
880
                $consDoc = "CPF: $consCPF";
881
            } elseif (!empty($considEstrangeiro)) {
882
                $consDoc = "id: $considEstrangeiro";
883
            }
884
            $consEnd = "";
885
            if (!empty($consLgr)) {
886
                $consEnd = $consLgr
887
                    . ","
888
                    . $consNro
889
                    . " "
890
                    . $consCpl
891
                    . ","
892
                    . $consBairro
893
                    . ". CEP:"
894
                    . $consCEP
895
                    . ". "
896
                    . $consMun
897
                    . "-"
898
                    . $consUF;
899
            }
900
            $yTex1 = $y + $hLinha;
901
            $texto = $consNome;
902
            if (!empty($consDoc)) {
903
                $texto .= " - " . $consDoc . "\n" . $consEnd;
904
                $this->pTextBox($x, $yTex1, $w, $hLinha * 3, $texto, $this->aFontTex, 'C', 'C', 0, '', false);
905
            }
906
        } else {
907
            $yTex1 = $y + $hLinha;
908
            $texto = "Consumidor não identificado";
909
            $this->pTextBox($x, $yTex1, $w, $hLinha, $texto, $this->aFontTex, 'C', 'C', 0, '', false);
910
        }
911
    }
912
913
    protected function pQRDANFE($x = 0, $y = 0, $h = 0)
0 ignored issues
show
Unused Code introduced by
The parameter $h is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
914
    {
915
        $y += 6;
916
        $margemInterna = $this->margemInterna;
917
        $maxW = $this->wPrint;
918
        $w = ($maxW * 1) + 4;
919
        $hLinha = $this->hLinha;
0 ignored issues
show
Unused Code introduced by
$hLinha is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
920
        $hBoxLinha = $this->hBoxLinha;
921
        $dhRecbto = '';
922
        $nProt = '';
923
        if (isset($this->nfeProc)) {
924
            $nProt = $this->pSimpleGetValue($this->nfeProc, "nProt");
925
            $dhRecbto = $this->pSimpleGetValue($this->nfeProc, "dhRecbto");
926
        }
927
        $barcode = new Barcode();
928
        $bobj = $barcode->getBarcodeObj(
929
            'QRCODE,M',
930
            $this->qrCode,
931
            -4,
932
            -4,
933
            'black',
934
            array(-2, -2, -2, -2)
935
        )->setBackgroundColor('white');
936
        $qrcode = $bobj->getPngData();
937
        $wQr = 50;
938
        $hQr = 50;
939
        $yQr = ($y + $margemInterna);
940
        $xQr = ($w / 2) - ($wQr / 2);
941
        // prepare a base64 encoded "data url"
942
        $pic = 'data://text/plain;base64,' . base64_encode($qrcode);
943
        $info = getimagesize($pic);
0 ignored issues
show
Unused Code introduced by
$info is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
944
        $this->pdf->image($pic, $xQr, $yQr, $wQr, $hQr, 'PNG');
945
        $dt = new DateTime($dhRecbto);
946
        $yQr = ($yQr + $hQr + $margemInterna);
947
        if (trim($nProt) != "") {
948
            $this->pTextBox($x, $yQr, $w - 4, $hBoxLinha, "Protocolo de Autorização: " . $nProt . "\n"
949
                . $dt->format('d/m/Y H:i:s'), $this->aFontTex, 'C', 'C', 0, '', false);
950
        }
951
    }
952
953
    protected function pInfAdic($x = 0, $y = 0, $h = 0)
0 ignored issues
show
Unused Code introduced by
The parameter $h is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
954
    {
955
        $y += 17;
956
        $margemInterna = $this->margemInterna;
0 ignored issues
show
Unused Code introduced by
$margemInterna is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
957
        $maxW = $this->wPrint;
958
        $w = ($maxW * 1);
959
        $hLinha = $this->hLinha;
960
        // seta o textbox do titulo
961
        $texto = "INFORMAÇÃO ADICIONAL";
962
        $heigthText = $this->pTextBox($x, $y, $w, $hLinha, $texto, $this->aFontTit, 'C', 'C', 0, '', false);
0 ignored issues
show
Unused Code introduced by
$heigthText is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
963
964
        // seta o textbox do texto adicional
965
        $this->pTextBox($x, $y + 3, $w - 2, $hLinha - 3, $this->textoAdic, $this->aFontTex, 'T', 'L', 0, '', false);
966
    }
967
968
    /**
969
     * printDANFE
970
     * Esta função envia a DANFE em PDF criada para o dispositivo informado.
971
     * O destino da impressão pode ser :
972
     * I-browser
973
     * D-browser com download
974
     * F-salva em um arquivo local com o nome informado
975
     * S-retorna o documento como uma string e o nome é ignorado.
976
     * Para enviar o pdf diretamente para uma impressora indique o
977
     * nome da impressora e o destino deve ser 'S'.
978
     *
979
     * @param  string $nome    Path completo com o nome do arquivo pdf
980
     * @param  string $destino Direção do envio do PDF
981
     * @param  string $printer Identificação da impressora no sistema
982
     * @return string Caso o destino seja S o pdf é retornado como uma string
983
     * @todo   Rotina de impressão direta do arquivo pdf criado
984
     */
985
    public function printDANFE($nome = '', $destino = 'I', $printer = '')
0 ignored issues
show
Unused Code introduced by
The parameter $printer is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
986
    {
987
        $arq = $this->pdf->Output($nome, $destino);
988
        if ($destino == 'S') {
0 ignored issues
show
Unused Code introduced by
This if statement is empty and can be removed.

This check looks for the bodies of if statements that have no statements or where all statements have been commented out. This may be the result of changes for debugging or the code may simply be obsolete.

These if bodies can be removed. If you have an empty if but statements in the else branch, consider inverting the condition.

if (rand(1, 6) > 3) {
//print "Check failed";
} else {
    print "Check succeeded";
}

could be turned into

if (rand(1, 6) <= 3) {
    print "Check succeeded";
}

This is much more concise to read.

Loading history...
989
            //aqui pode entrar a rotina de impressão direta
990
        }
991
        return $arq;
992
    }
993
    /**
994
     * Dados brutos do PDF
995
     * @return string
996
     */
997
    public function render()
998
    {
999
        return $this->pdf->getPdf();
1000
    }
1001
1002
    /**
1003
     * anfavea
1004
     * Função para transformar o campo cdata do padrão ANFAVEA para
1005
     * texto imprimível
1006
     *
1007
     * @param  string $cdata campo CDATA
1008
     * @return string conteúdo do campo CDATA como string
1009
     */
1010
    protected function pAnfavea($cdata = '')
1011
    {
1012
        if ($cdata == '') {
1013
            return '';
1014
        }
1015
        //remove qualquer texto antes ou depois da tag CDATA
1016
        $cdata = str_replace('<![CDATA[', '<CDATA>', $cdata);
1017
        $cdata = str_replace(']]>', '</CDATA>', $cdata);
1018
        $cdata = preg_replace('/\s\s+/', ' ', $cdata);
1019
        $cdata = str_replace("> <", "><", $cdata);
1020
        $len = strlen($cdata);
1021
        $startPos = strpos($cdata, '<');
1022
        if ($startPos === false) {
1023
            return $cdata;
1024
        }
1025
        for ($x = $len; $x > 0; $x--) {
1026
            if (substr($cdata, $x, 1) == '>') {
1027
                $endPos = $x;
1028
                break;
1029
            }
1030
        }
1031
        if ($startPos > 0) {
1032
            $parte1 = substr($cdata, 0, $startPos);
1033
        } else {
1034
            $parte1 = '';
1035
        }
1036
        $parte2 = substr($cdata, $startPos, $endPos - $startPos + 1);
0 ignored issues
show
Bug introduced by
The variable $endPos does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
1037
        if ($endPos < $len) {
1038
            $parte3 = substr($cdata, $endPos + 1, $len - $endPos - 1);
1039
        } else {
1040
            $parte3 = '';
1041
        }
1042
        $texto = trim($parte1) . ' ' . trim($parte3);
1043
        if (strpos($parte2, '<CDATA>') === false) {
1044
            $cdata = '<CDATA>' . $parte2 . '</CDATA>';
1045
        } else {
1046
            $cdata = $parte2;
1047
        }
1048
        //carrega o xml CDATA em um objeto DOM
1049
        $dom = new Dom();
1050
        $dom->loadXML($cdata, LIBXML_NOBLANKS | LIBXML_NOEMPTYTAG);
1051
        //$xml = $dom->saveXML();
0 ignored issues
show
Unused Code Comprehensibility introduced by
60% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
1052
        //grupo CDATA infADprod
1053
        $id = $dom->getElementsByTagName('id')->item(0);
1054
        $div = $dom->getElementsByTagName('div')->item(0);
1055
        $entg = $dom->getElementsByTagName('entg')->item(0);
1056
        $dest = $dom->getElementsByTagName('dest')->item(0);
1057
        $ctl = $dom->getElementsByTagName('ctl')->item(0);
1058
        $ref = $dom->getElementsByTagName('ref')->item(0);
1059
        if (isset($id)) {
1060
            if ($id->hasAttributes()) {
1061
                foreach ($id->attributes as $attr) {
1062
                    $name = $attr->nodeName;
1063
                    $value = $attr->nodeValue;
1064
                    $texto .= " $name : $value";
1065
                }
1066
            }
1067
        }
1068
        if (isset($div)) {
1069
            if ($div->hasAttributes()) {
1070
                foreach ($div->attributes as $attr) {
1071
                    $name = $attr->nodeName;
1072
                    $value = $attr->nodeValue;
1073
                    $texto .= " $name : $value";
1074
                }
1075
            }
1076
        }
1077
        if (isset($entg)) {
1078
            if ($entg->hasAttributes()) {
1079
                foreach ($entg->attributes as $attr) {
1080
                    $name = $attr->nodeName;
1081
                    $value = $attr->nodeValue;
1082
                    $texto .= " $name : $value";
1083
                }
1084
            }
1085
        }
1086
        if (isset($dest)) {
1087
            if ($dest->hasAttributes()) {
1088
                foreach ($dest->attributes as $attr) {
1089
                    $name = $attr->nodeName;
1090
                    $value = $attr->nodeValue;
1091
                    $texto .= " $name : $value";
1092
                }
1093
            }
1094
        }
1095
        if (isset($ctl)) {
1096
            if ($ctl->hasAttributes()) {
1097
                foreach ($ctl->attributes as $attr) {
1098
                    $name = $attr->nodeName;
1099
                    $value = $attr->nodeValue;
1100
                    $texto .= " $name : $value";
1101
                }
1102
            }
1103
        }
1104
        if (isset($ref)) {
1105
            if ($ref->hasAttributes()) {
1106
                foreach ($ref->attributes as $attr) {
1107
                    $name = $attr->nodeName;
1108
                    $value = $attr->nodeValue;
1109
                    $texto .= " $name : $value";
1110
                }
1111
            }
1112
        }
1113
        //grupo CADATA infCpl
1114
        $t = $dom->getElementsByTagName('transmissor')->item(0);
1115
        $r = $dom->getElementsByTagName('receptor')->item(0);
1116
        $versao = !empty($dom->getElementsByTagName('versao')->item(0)->nodeValue) ?
1117
        'Versao:' . $dom->getElementsByTagName('versao')->item(0)->nodeValue . ' ' : '';
1118
        $especieNF = !empty($dom->getElementsByTagName('especieNF')->item(0)->nodeValue) ?
1119
        'Especie:' . $dom->getElementsByTagName('especieNF')->item(0)->nodeValue . ' ' : '';
1120
        $fabEntrega = !empty($dom->getElementsByTagName('fabEntrega')->item(0)->nodeValue) ?
1121
        'Entrega:' . $dom->getElementsByTagName('fabEntrega')->item(0)->nodeValue . ' ' : '';
1122
        $dca = !empty($dom->getElementsByTagName('dca')->item(0)->nodeValue) ?
1123
        'dca:' . $dom->getElementsByTagName('dca')->item(0)->nodeValue . ' ' : '';
1124
        $texto .= "" . $versao . $especieNF . $fabEntrega . $dca;
1125
        if (isset($t)) {
1126
            if ($t->hasAttributes()) {
1127
                $texto .= " Transmissor ";
1128
                foreach ($t->attributes as $attr) {
1129
                    $name = $attr->nodeName;
1130
                    $value = $attr->nodeValue;
1131
                    $texto .= " $name : $value";
1132
                }
1133
            }
1134
        }
1135
        if (isset($r)) {
1136
            if ($r->hasAttributes()) {
1137
                $texto .= " Receptor ";
1138
                foreach ($r->attributes as $attr) {
1139
                    $name = $attr->nodeName;
1140
                    $value = $attr->nodeValue;
1141
                    $texto .= " $name : $value";
1142
                }
1143
            }
1144
        }
1145
        return $texto;
1146
    }
1147
1148
    /**
1149
     * str2Hex
1150
     * Converte string para haxadecimal ASCII
1151
     *
1152
     * @param  string $str
1153
     * @return string
1154
     */
1155
    protected static function str2Hex($str)
1156
    {
1157
        if ($str == '') {
1158
            return '';
1159
        }
1160
        $hex = "";
1161
        $iCount = 0;
1162
        do {
1163
            $hex .= sprintf("%02x", ord($str{$iCount}));
1164
            $iCount++;
1165
        } while ($iCount < strlen($str));
1166
        return $hex;
1167
    } //fim str2Hex
1168
1169
    protected static function getCardName($tBand)
1170
    {
1171
        switch ($tBand) {
1172
            case '01':
1173
                $tBandNome = 'VISA';
1174
                break;
1175
            case '02':
1176
                $tBandNome = 'MASTERCARD';
1177
                break;
1178
            case '03':
1179
                $tBandNome = 'AMERICAM EXPRESS';
1180
                break;
1181
            case '04':
1182
                $tBandNome = 'SOROCRED';
1183
                break;
1184
            case '99':
1185
                $tBandNome = 'OUTROS';
1186
                break;
1187
            default:
1188
                $tBandNome = '';
1189
        }
1190
        return $tBandNome;
1191
    }
1192
1193
    /**
1194
     * hex2Str
1195
     * Converte hexadecimal ASCII para string
1196
     *
1197
     * @param  string $str
1198
     * @return string
1199
     */
1200
    protected static function hex2Str($str)
1201
    {
1202
        if ($str == '') {
1203
            return '';
1204
        }
1205
        $bin = "";
1206
        $iCount = 0;
1207
        do {
1208
            $bin .= chr(hexdec($str{$iCount} . $str{($iCount + 1)}));
1209
            $iCount += 2;
1210
        } while ($iCount < strlen($str));
1211
        return $bin;
1212
    }
1213
1214
    protected function makeQRCode(
1215
        $chNFe,
1216
        $url,
1217
        $tpAmb,
1218
        $cDest = '',
1219
        $dhEmi = '',
1220
        $vNF = '',
1221
        $vICMS = '',
1222
        $digVal = '',
1223
        $idToken = '000001',
1224
        $token = ''
1225
    ) {
1226
        $nVersao = '100';
1227
        $dhHex = self::str2Hex($dhEmi);
1228
        $digHex = self::str2Hex($digVal);
1229
        $seq = '';
1230
        $seq .= 'chNFe=' . $chNFe;
1231
        $seq .= '&nVersao=' . $nVersao;
1232
        $seq .= '&tpAmb=' . $tpAmb;
1233
        if ($cDest != '') {
1234
            $seq .= '&cDest=' . $cDest;
1235
        }
1236
        $seq .= '&dhEmi=' . strtolower($dhHex);
1237
        $seq .= '&vNF=' . $vNF;
1238
        $seq .= '&vICMS=' . $vICMS;
1239
        $seq .= '&digVal=' . strtolower($digHex);
1240
        $seq .= '&cIdToken=' . $idToken;
1241
        //o hash code é calculado com o Token incluso
1242
        $hash = sha1($seq . $token);
1243
        $seq .= '&cHashQRCode=' . strtoupper($hash);
1244
        if (strpos($url, '?') === false) {
1245
            $seq = $url . '?' . $seq;
1246
        } else {
1247
            $seq = $url . '' . $seq;
1248
        }
1249
        return $seq;
1250
    }
1251
1252
    protected function pNotaCancelada()
1253
    {
1254
        if (!isset($this->nfeProc)) {
1255
            return false;
1256
        }
1257
        $cStat = $this->pSimpleGetValue($this->nfeProc, "cStat");
1258
        return $cStat == '101' ||
1259
            $cStat == '151' ||
1260
            $cStat == '135' ||
1261
            $cStat == '155';
1262
    }
1263
1264
    protected function pNotaDenegada()
1265
    {
1266
        if (!isset($this->nfeProc)) {
1267
            return false;
1268
        }
1269
        //NÃO ERA NECESSÁRIO ESSA FUNÇÃO POIS SÓ SE USA
1270
        //1 VEZ NO ARQUIVO INTEIRO
1271
        $cStat = $this->pSimpleGetValue($this->nfeProc, "cStat");
1272
        return $cStat == '110' ||
1273
            $cStat == '301' ||
1274
            $cStat == '302';
1275
    }
1276
}
1277