Passed
Push — master ( 466b11...b72ed0 )
by Roberto
02:56 queued 11s
created

Danfe::itens()   F

Complexity

Conditions 25
Paths 18

Size

Total Lines 289

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 650

Importance

Changes 0
Metric Value
cc 25
nc 18
nop 7
dl 0
loc 289
ccs 0
cts 238
cp 0
crap 650
rs 3.3333
c 0
b 0
f 0

How to fix   Long Method    Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
namespace NFePHP\DA\NFe;
4
5
use InvalidArgumentException;
6
use NFePHP\DA\Legacy\Dom;
7
use NFePHP\DA\Legacy\Pdf;
8
use NFePHP\DA\Legacy\Common;
9
10
class Danfe extends Common
11
{
12
    const SIT_CANCELADA = 1;
13
    const SIT_DENEGADA = 2;
14
    const SIT_DPEC = 3;
15
    const SIT_NONE = 0;
16
17
    /**
18
     * alinhamento padrão do logo (C-Center)
19
     *
20
     * @var string
21
     */
22
    protected $logoAlign = 'C';
23
    /**
24
     * Posição
25
     * @var float
26
     */
27
    protected $yDados = 0;
28
    /**
29
     * Situação
30
     * @var integer
31
     */
32
    protected $situacaoExterna = 0;
33
    /**
34
     * Numero DPEC
35
     *
36
     * @var string
37
     */
38
    protected $numero_registro_dpec = '';
39
    /**
40
     * quantidade de canhotos a serem montados, geralmente 1 ou 2
41
     *
42
     * @var integer
43
     */
44
    protected $qCanhoto = 1;
45
    /**
46
     * Parâmetro para exibir ou ocultar os valores do PIS/COFINS.
47
     * @var boolean
48
     */
49
    protected $exibirPIS = true;
50
    /**
51
     * Parâmetro para exibir ou ocultar os valores do ICMS Interestadual e Valor Total dos Impostos.
52
     * @var boolean
53
     */
54
    protected $exibirIcmsInterestadual = true;
55
    /**
56
     * Parâmetro para exibir ou ocultar o texto sobre valor aproximado dos tributos.
57
     * @var boolean
58
     */
59
    protected $exibirValorTributos = true;
60
    /**
61
     * Parâmetro para exibir ou ocultar o texto adicional sobre a forma de pagamento
62
     * e as informações de fatura/duplicata.
63
     * @var boolean
64
     */
65
    protected $exibirTextoFatura = false;
66
    /**
67
     * Parâmetro do controle se deve concatenar automaticamente informações complementares
68
     * na descrição do produto, como por exemplo, informações sobre impostos.
69
     * @var boolean
70
     */
71
    protected $descProdInfoComplemento = true;
72
    /**
73
     * Parâmetro do controle se deve gerar quebras de linha com "\n" a partir de ";" na descrição do produto.
74
     * @var boolean
75
     */
76
    protected $descProdQuebraLinha = true;
77
    /**
78
     * objeto fpdf()
79
     * @var object
80
     */
81
    protected $pdf;
82
    /**
83
     * XML NFe
84
     * @var string
85
     */
86
    protected $xml;
87
    /**
88
     * path para logomarca em jpg
89
     * @var string
90
     */
91
    protected $logomarca = '';
92
    /**
93
     * mesagens de erro
94
     * @var string
95
     */
96
    protected $errMsg = '';
97
    /**
98
     * status de erro true um erro ocorreu false sem erros
99
     * @var boolean
100
     */
101
    protected $errStatus = false;
102
    /**
103
     * orientação da DANFE
104
     * P-Retrato ou L-Paisagem
105
     * @var string
106
     */
107
    protected $orientacao = 'P';
108
    /**
109
     * formato do papel
110
     * @var string
111
     */
112
    protected $papel = 'A4';
113
    /**
114
     * Nome da Fonte para gerar o DANFE
115
     * @var string
116
     */
117
    protected $fontePadrao = 'Times';
118
    /**
119
     * Texto
120
     * @var string
121
     */
122
    protected $textoAdic = '';
123
    /**
124
     * Largura
125
     * @var float
126
     */
127
    protected $wAdic = 0;
128
    /**
129
     * largura imprimivel, em milímetros
130
     * @var float
131
     */
132
    protected $wPrint;
133
    /**
134
     * Comprimento (altura) imprimivel, em milímetros
135
     * @var float
136
     */
137
    protected $hPrint;
138
    /**
139
     * largura do canhoto (25mm) apenas para a formatação paisagem
140
     * @var float
141
     */
142
    protected $wCanhoto = 25;
143
    /**
144
     * Formato chave
145
     * @var string
146
     */
147
    protected $formatoChave = "#### #### #### #### #### #### #### #### #### #### ####";
148
    /**
149
     * quantidade de itens já processados na montagem do DANFE
150
     * @var integer
151
     */
152
    protected $qtdeItensProc;
153
    /**
154
     * Document
155
     * @var DOMDocument
156
     */
157
    protected $dom;
158
    /**
159
     * Node
160
     * @var DOMNode
161
     */
162
    protected $infNFe;
163
    /**
164
     * Node
165
     * @var DOMNode
166
     */
167
    protected $ide;
168
    /**
169
     * Node
170
     * @var DOMNode
171
     */
172
    protected $entrega;
173
    /**
174
     * Node
175
     * @var DOMNode
176
     */
177
    protected $retirada;
178
    /**
179
     * Node
180
     * @var DOMNode
181
     */
182
    protected $emit;
183
    /**
184
     * Node
185
     * @var DOMNode
186
     */
187
    protected $dest;
188
    /**
189
     * Node
190
     * @var DOMNode
191
     */
192
    protected $enderEmit;
193
    /**
194
     * Node
195
     * @var DOMNode
196
     */
197
    protected $enderDest;
198
    /**
199
     * Node
200
     * @var DOMNode
201
     */
202
    protected $det;
203
    /**
204
     * Node
205
     * @var DOMNode
206
     */
207
    protected $cobr;
208
    /**
209
     * Node
210
     * @var DOMNode
211
     */
212
    protected $dup;
213
    /**
214
     * Node
215
     * @var DOMNode
216
     */
217
    protected $ICMSTot;
218
    /**
219
     * Node
220
     * @var DOMNode
221
     */
222
    protected $ISSQNtot;
223
    /**
224
     * Node
225
     * @var DOMNode
226
     */
227
    protected $transp;
228
    /**
229
     * Node
230
     * @var DOMNode
231
     */
232
    protected $transporta;
233
    /**
234
     * Node
235
     * @var DOMNode
236
     */
237
    protected $veicTransp;
238
    /**
239
     * Node reboque
240
     * @var DOMNode
241
     */
242
    protected $reboque;
243
    /**
244
     * Node infAdic
245
     * @var DOMNode
246
     */
247
    protected $infAdic;
248
    /**
249
     * Tipo de emissão
250
     * @var integer
251
     */
252
    protected $tpEmis;
253
    /**
254
     * Node infProt
255
     * @var DOMNode
256
     */
257
    protected $infProt;
258
    /**
259
     * 1-Retrato/ 2-Paisagem
260
     * @var integer
261
     */
262
    protected $tpImp;
263
    /**
264
     * Node compra
265
     * @var DOMNode
266
     */
267
    protected $compra;
268
    /**
269
     * ativa ou desativa o modo de debug
270
     * @var integer
271
     */
272
    protected $debugmode = false;
273
    /**
274
     * Creditos para integrador
275
     * @var string
276
     */
277
    protected $creditos = '';
278
279
    /**
280
     * __construct
281
     *
282
     * @name  __construct
283
     * @param string  $docXML      Conteúdo XML da NF-e (com ou sem a tag nfeProc)
0 ignored issues
show
Bug introduced by
There is no parameter named $docXML. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
284
     * @param string  $logoimage   Caminho para o arquivo do logo
0 ignored issues
show
Bug introduced by
There is no parameter named $logoimage. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
285
     */
286
    public function __construct(
287
        $xml
288
    ) {
289
        $this->debugMode();
290
        $this->loadDoc($xml);
291
    }
292
    
293
    /**
294
     * Ativa ou desativa o modo debug
295
     * @param bool $activate
296
     * @return bool
297
     */
298
    public function debugMode($activate = null)
299
    {
300
        if (isset($activate) && is_bool($activate)) {
301
            $this->debugmode = $activate;
0 ignored issues
show
Documentation Bug introduced by
The property $debugmode was declared of type integer, but $activate is of type boolean. Maybe add a type cast?

This check looks for assignments to scalar types that may be of the wrong type.

To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.

$answer = 42;

$correct = false;

$correct = (bool) $answer;
Loading history...
302
        }
303
        if ($this->debugmode) {
304
            //ativar modo debug
305
            error_reporting(E_ALL);
306
            ini_set('display_errors', 'On');
307
        } else {
308
            //desativar modo debug
309
            error_reporting(0);
310
            ini_set('display_errors', 'Off');
311
        }
312
        return $this->debugmode;
313
    }
314
315
    /**
316
     * Add the credits to the integrator in the footer message
317
     * @param string $message
318
     */
319
    public function creditsIntegratorFooter($message = '')
320
    {
321
        $this->creditos = trim($message);
322
    }
323
    
324
    /**
325
     * Dados brutos do PDF
326
     * @return string
327
     */
328
    public function render()
329
    {
330
        if (empty($this->pdf)) {
331
            $this->monta();
332
        }
333
        return $this->pdf->getPdf();
334
    }
335
336
    /**
337
     * monta
338
     * Monta a DANFE conforme as informações fornecidas para a classe durante sua
339
     * construção. Constroi DANFEs com até 3 páginas podendo conter até 56 itens.
340
     * A definição de margens e posições iniciais para a impressão são estabelecidas
341
     * pelo conteúdo da funçao e podem ser modificados.
342
     *
343
     * @param  string $orientacao (Opcional) Estabelece a orientação da impressão
344
     *  (ex. P-retrato), se nada for fornecido será usado o padrão da NFe
345
     * @param  string $papel      (Opcional) Estabelece o tamanho do papel (ex. A4)
346
     * @return string O ID da NFe numero de 44 digitos extraido do arquivo XML
347
     */
348
    public function monta(
349
        $logo = '',
350
        $orientacao = '',
351
        $papel = 'A4',
352
        $logoAlign = 'C',
353
        $depecNumReg = '',
354
        $margSup = 2,
355
        $margEsq = 2,
356
        $margInf = 2
357
    ) {
358
        $this->pdf = '';
0 ignored issues
show
Documentation Bug introduced by
It seems like '' of type string is incompatible with the declared type object of property $pdf.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
359
        $this->logomarca = $logo;
360
        //se a orientação estiver em branco utilizar o padrão estabelecido na NF
361
        if ($orientacao == '') {
362
            if ($this->tpImp == '1') {
363
                $orientacao = 'P';
364
            } else {
365
                $orientacao = 'L';
366
            }
367
        }
368
        $this->orientacao = $orientacao;
369
        $this->papel = $papel;
370
        $this->logoAlign = $logoAlign;
371
        $this->numero_registro_dpec = $depecNumReg;
372
        //instancia a classe pdf
373
        $this->pdf = new Pdf($this->orientacao, 'mm', $this->papel);
374
        //margens do PDF, em milímetros. Obs.: a margem direita é sempre igual à
375
        //margem esquerda. A margem inferior *não* existe na FPDF, é definida aqui
376
        //apenas para controle se necessário ser maior do que a margem superior
377
        // posição inicial do conteúdo, a partir do canto superior esquerdo da página
378
        $xInic = $margEsq;
379
        $yInic = $margSup;
380
        if ($this->orientacao == 'P') {
381
            if ($papel == 'A4') {
382
                $maxW = 210;
383
                $maxH = 297;
384
            }
385
        } else {
386
            if ($papel == 'A4') {
387
                $maxH = 210;
388
                $maxW = 297;
389
                //se paisagem multiplica a largura do canhoto pela quantidade de canhotos
390
                $this->wCanhoto *= $this->qCanhoto;
391
            }
392
        }
393
        //total inicial de paginas
394
        $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...
395
        //largura imprimivel em mm: largura da folha menos as margens esq/direita
396
        $this->wPrint = $maxW-($margEsq * 2);
0 ignored issues
show
Bug introduced by
The variable $maxW 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...
Documentation Bug introduced by
The property $wPrint was declared of type double, but $maxW - $margEsq * 2 is of type integer. Maybe add a type cast?

This check looks for assignments to scalar types that may be of the wrong type.

To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.

$answer = 42;

$correct = false;

$correct = (bool) $answer;
Loading history...
397
        //comprimento (altura) imprimivel em mm: altura da folha menos as margens
398
        //superior e inferior
399
        $this->hPrint = $maxH-$margSup-$margInf;
0 ignored issues
show
Bug introduced by
The variable $maxH 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...
Documentation Bug introduced by
The property $hPrint was declared of type double, but $maxH - $margSup - $margInf is of type integer. Maybe add a type cast?

This check looks for assignments to scalar types that may be of the wrong type.

To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.

$answer = 42;

$correct = false;

$correct = (bool) $answer;
Loading history...
400
        // estabelece contagem de paginas
401
        $this->pdf->aliasNbPages();
402
        // fixa as margens
403
        $this->pdf->setMargins($margEsq, $margSup);
404
        $this->pdf->setDrawColor(0, 0, 0);
405
        $this->pdf->setFillColor(255, 255, 255);
406
        // inicia o documento
407
        $this->pdf->open();
408
        // adiciona a primeira página
409
        $this->pdf->addPage($this->orientacao, $this->papel);
410
        $this->pdf->setLineWidth(0.1);
411
        $this->pdf->setTextColor(0, 0, 0);
412
413
        //##################################################################
414
        // CALCULO DO NUMERO DE PAGINAS A SEREM IMPRESSAS
415
        //##################################################################
416
        //Verificando quantas linhas serão usadas para impressão das duplicatas
417
        $linhasDup = 0;
418
        if (($this->dup->length > 0) && ($this->dup->length <= 7)) {
419
            $linhasDup = 1;
420
        } elseif (($this->dup->length > 7) && ($this->dup->length <= 14)) {
421
            $linhasDup = 2;
422
        } elseif (($this->dup->length > 14) && ($this->dup->length <= 21)) {
423
            $linhasDup = 3;
424
        } elseif ($this->dup->length > 21) {
425
            // chinnonsantos 11/05/2016: Limite máximo de impressão de duplicatas na NFe,
426
            // só vai ser exibito as 21 primeiras duplicatas (parcelas de pagamento),
427
            // se não oculpa espaço d+, cada linha comporta até 7 duplicatas.
428
            $linhasDup = 3;
429
        }
430
        //verifica se será impressa a linha dos serviços ISSQN
431
        $linhaISSQN = 0;
432
        if ((isset($this->ISSQNtot)) && ($this->getTagValue($this->ISSQNtot, 'vServ') > 0)) {
433
            $linhaISSQN = 1;
434
        }
435
        //calcular a altura necessária para os dados adicionais
436
        if ($this->orientacao == 'P') {
437
            $this->wAdic = round($this->wPrint*0.66, 0);
438
        } else {
439
            $this->wAdic = round(($this->wPrint-$this->wCanhoto)*0.5, 0);
440
        }
441
        $fontProduto = ['font'=>$this->fontePadrao, 'size'=>7, 'style'=>''];
442
        $this->textoAdic = '';
443
        if (isset($this->retirada)) {
444
            $txRetCNPJ = $this->getTagValue($this->retirada, "CNPJ");
445
            $txRetxLgr = $this->getTagValue($this->retirada, "xLgr");
446
            $txRetnro = $this->getTagValue($this->retirada, "nro");
447
            $txRetxCpl = $this->getTagValue($this->retirada, "xCpl", " - ");
448
            $txRetxBairro = $this->getTagValue($this->retirada, "xBairro");
449
            $txRetxMun = $this->getTagValue($this->retirada, "xMun");
450
            $txRetUF = $this->getTagValue($this->retirada, "UF");
451
            $this->textoAdic .= "LOCAL DE RETIRADA : ".
452
                    $txRetCNPJ.
453
                    '-' .
454
                    $txRetxLgr .
455
                    ', ' .
456
                    $txRetnro .
457
                    ' ' .
458
                    $txRetxCpl .
459
                    ' - ' .
460
                    $txRetxBairro .
461
                    ' ' .
462
                    $txRetxMun .
463
                    ' - ' .
464
                    $txRetUF .
465
                    "\r\n";
466
        }
467
        //dados do local de entrega da mercadoria
468
        if (isset($this->entrega)) {
469
            $txRetCNPJ = $this->getTagValue($this->entrega, "CNPJ");
470
            $txRetxLgr = $this->getTagValue($this->entrega, "xLgr");
471
            $txRetnro = $this->getTagValue($this->entrega, "nro");
472
            $txRetxCpl = $this->getTagValue($this->entrega, "xCpl", " - ");
473
            $txRetxBairro = $this->getTagValue($this->entrega, "xBairro");
474
            $txRetxMun = $this->getTagValue($this->entrega, "xMun");
475
            $txRetUF = $this->getTagValue($this->entrega, "UF");
476
            if ($this->textoAdic != '') {
477
                $this->textoAdic .= ". \r\n";
478
            }
479
            $this->textoAdic .= "LOCAL DE ENTREGA : ".$txRetCNPJ.'-'.$txRetxLgr.', '.$txRetnro.' '.$txRetxCpl.
480
               ' - '.$txRetxBairro.' '.$txRetxMun.' - '.$txRetUF."\r\n";
481
        }
482
        //informações adicionais
483
        $this->textoAdic .= $this->geraInformacoesDasNotasReferenciadas();
484
        if (isset($this->infAdic)) {
485
            $i = 0;
486
            if ($this->textoAdic != '') {
487
                $this->textoAdic .= ". \r\n";
488
            }
489
            $this->textoAdic .= ! empty($this->getTagValue($this->infAdic, "infCpl")) ?
490
                'Inf. Contribuinte: ' .
491
                $this->anfaveaDANFE($this->getTagValue($this->infAdic, "infCpl")) : '';
492
            $infPedido = $this->geraInformacoesDaTagCompra();
493
            if ($infPedido != "") {
494
                $this->textoAdic .= $infPedido;
495
            }
496
            $this->textoAdic .= $this->getTagValue($this->dest, "email", ' Email do Destinatário: ');
497
            $this->textoAdic .= ! empty($this->getTagValue($this->infAdic, "infAdFisco")) ?
498
                "\r\n Inf. fisco: " .
499
                $this->getTagValue($this->infAdic, "infAdFisco") : '';
500
            $obsCont = $this->infAdic->getElementsByTagName("obsCont");
501
            if (isset($obsCont)) {
502
                foreach ($obsCont as $obs) {
503
                    $campo =  $obsCont->item($i)->getAttribute("xCampo");
504
                    $xTexto = ! empty($obsCont->item($i)->getElementsByTagName("xTexto")->item(0)->nodeValue) ?
505
                        $obsCont->item($i)->getElementsByTagName("xTexto")->item(0)->nodeValue : '';
506
                    $this->textoAdic .= "\r\n" . $campo . ':  ' . trim($xTexto);
507
                    $i++;
508
                }
509
            }
510
        }
511
        //INCLUSO pela NT 2013.003 Lei da Transparência
512
        //verificar se a informação sobre o valor aproximado dos tributos
513
        //já se encontra no campo de informações adicionais
514
        if ($this->exibirValorTributos) {
515
            $flagVTT = strpos(strtolower(trim($this->textoAdic)), 'valor');
516
            $flagVTT = $flagVTT || strpos(strtolower(trim($this->textoAdic)), 'vl');
517
            $flagVTT = $flagVTT && strpos(strtolower(trim($this->textoAdic)), 'aprox');
518
            $flagVTT = $flagVTT && (strpos(strtolower(trim($this->textoAdic)), 'trib') ||
519
                    strpos(strtolower(trim($this->textoAdic)), 'imp'));
520
            $vTotTrib = $this->getTagValue($this->ICMSTot, 'vTotTrib');
521
            if ($vTotTrib != '' && !$flagVTT) {
522
                $this->textoAdic .= "\n Valor Aproximado dos Tributos : R$ " . number_format($vTotTrib, 2, ",", ".");
523
            }
524
        }
525
        //fim da alteração NT 2013.003 Lei da Transparência
526
        $this->textoAdic = str_replace(";", "\n", $this->textoAdic);
527
        $alinhas = explode("\n", $this->textoAdic);
528
        $numlinhasdados = 0;
529
        foreach ($alinhas as $linha) {
530
            $numlinhasdados += $this->pdf->getNumLines($linha, $this->wAdic, $fontProduto);
531
        }
532
        $hdadosadic = round(($numlinhasdados+3) * $this->pdf->fontSize, 0);
533
        if ($hdadosadic < 10) {
534
            $hdadosadic = 10;
535
        }
536
        //altura disponivel para os campos da DANFE
537
        $hcabecalho = 47;//para cabeçalho
538
        $hdestinatario = 25;//para destinatario
539
        $hduplicatas = 12;//para cada grupo de 7 duplicatas
540
        $himposto = 18;// para imposto
541
        $htransporte = 25;// para transporte
542
        $hissqn = 11;// para issqn
543
        $hfooter = 5;// para rodape
544
        $hCabecItens = 4;//cabeçalho dos itens
545
        //alturas disponiveis para os dados
546
        $hDispo1 = $this->hPrint - 10 - ($hcabecalho +
547
            $hdestinatario + ($linhasDup * $hduplicatas) + $himposto + $htransporte +
548
            ($linhaISSQN * $hissqn) + $hdadosadic + $hfooter + $hCabecItens +
549
            $this->sizeExtraTextoFatura());
550
        if ($this->orientacao == 'P') {
551
            $hDispo1 -= 24 * $this->qCanhoto;//para canhoto
552
            $w = $this->wPrint;
553
        } else {
554
            $hcanhoto = $this->hPrint;//para canhoto
0 ignored issues
show
Unused Code introduced by
$hcanhoto 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...
555
            $w = $this->wPrint - $this->wCanhoto;
556
        }
557
        $hDispo2 = $this->hPrint - 10 - ($hcabecalho + $hfooter + $hCabecItens)-4;
558
        //Contagem da altura ocupada para impressão dos itens
559
        $fontProduto = ['font'=>$this->fontePadrao, 'size'=>7, 'style'=>''];
560
        $numlinhas = 0;
0 ignored issues
show
Unused Code introduced by
$numlinhas 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...
561
        $hUsado = $hCabecItens;
562
        $w2 = round($w*0.28, 0);
563
        $hDispo = $hDispo1;
564
        $totPag = 1;
565
        $i = 0;
566
        while ($i < $this->det->length) {
567
            $texto = $this->descricaoProduto($this->det->item($i));
568
            $numlinhas = $this->pdf->getNumLines($texto, $w2, $fontProduto);
569
            $hUsado += round(($numlinhas * $this->pdf->fontSize) + ($numlinhas * 0.5), 2);
570
            if ($hUsado > $hDispo) {
571
                $totPag++;
572
                $hDispo = $hDispo2;
573
                $hUsado = $hCabecItens;
574
                // Remove canhoto para páginas secundárias em modo paisagem ('L')
575
                $w2 = round($this->wPrint*0.28, 0);
576
                $i--; // decrementa para readicionar o item que não coube nessa pagina na outra.
577
            }
578
            $i++;
579
        } //fim da soma das areas de itens usadas
580
        $qtdeItens = $i; //controle da quantidade de itens no DANFE
581
        //montagem da primeira página
582
        $pag = 1;
583
        $x = $xInic;
584
        $y = $yInic;
585
        //coloca o(s) canhoto(s) da NFe
586
        if ($this->orientacao == 'P') {
587
            for ($i = 1; $i <= $this->qCanhoto; $i++) {
588
                $y = $this->canhoto($x, $y);
589
            }
590
        } else {
591
            for ($i = 1; $i <= $this->qCanhoto; $i++) {
592
                $this->canhoto($x, $y);
593
                $x = 25 * $i;
594
            }
595
        }
596
        //coloca o cabeçalho
597
        $y = $this->header($x, $y, $pag, $totPag);
598
        //coloca os dados do destinatário
599
        $y = $this->destinatarioDANFE($x, $y+1);
600
        
601
        
602
        //Verifica as formas de pagamento da nota fiscal
603
        $formaPag = [];
604
        if (isset($this->detPag) && $this->detPag->length > 0) {
605
            foreach ($this->detPag as $k => $d) {
606
                $fPag = !empty($this->detPag->item($k)->getElementsByTagName('tPag')->item(0)->nodeValue) ?
0 ignored issues
show
Bug introduced by
The property detPag 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...
607
                    $this->detPag->item($k)->getElementsByTagName('tPag')->item(0)->nodeValue : '0';
608
                $formaPag[$fPag] = $fPag;
609
            }
610
        }
611
        //caso tenha boleto imprimir fatura
612
        if ($this->dup->length > 0) {
613
            $y = $this->fatura($x, $y+1);
614
        } else {
615
            //Se somente tiver a forma de pagamento sem pagamento ou outros não imprimir nada
616
            if (count($formaPag)=='1' && (isset($formaPag[90]) || isset($formaPag[99]))) {
617
                $y = $y;
0 ignored issues
show
Bug introduced by
Why assign $y to itself?

This checks looks for cases where a variable has been assigned to itself.

This assignement can be removed without consequences.

Loading history...
618
            } else {
619
                //caso tenha mais de uma forma de pagamento ou seja diferente de boleto exibe a
620
                //forma de pagamento e o valor
621
                $y = $this->pagamento($x, $y+1);
622
            }
623
        }
624
        //coloca os dados dos impostos e totais da NFe
625
        $y = $this->imposto($x, $y+1);
626
        //coloca os dados do trasnporte
627
        $y = $this->transporte($x, $y+1);
628
        //itens da DANFE
629
        $nInicial = 0;
630
631
        $y = $this->itens($x, $y+1, $nInicial, $hDispo1, $pag, $totPag, $hCabecItens);
632
633
        //coloca os dados do ISSQN
634
        if ($linhaISSQN == 1) {
635
            $y = $this->issqn($x, $y+4);
636
        } else {
637
            $y += 4;
638
        }
639
        //coloca os dados adicionais da NFe
640
        $y = $this->dadosAdicionais($x, $y, $hdadosadic);
641
        //coloca o rodapé da página
642
        if ($this->orientacao == 'P') {
643
            $this->rodape($xInic, $y-1);
644
        } else {
645
            $this->rodape($xInic, $this->hPrint + 1);
646
        }
647
648
        //loop para páginas seguintes
649
        for ($n = 2; $n <= $totPag; $n++) {
650
            // fixa as margens
651
            $this->pdf->setMargins($margEsq, $margSup);
652
            //adiciona nova página
653
            $this->pdf->addPage($this->orientacao, $this->papel);
654
            //ajusta espessura das linhas
655
            $this->pdf->setLineWidth(0.1);
656
            //seta a cor do texto para petro
657
            $this->pdf->setTextColor(0, 0, 0);
658
            // posição inicial do relatorio
659
            $x = $xInic;
660
            $y = $yInic;
661
            //coloca o cabeçalho na página adicional
662
            $y = $this->header($x, $y, $n, $totPag);
663
            //coloca os itens na página adicional
664
            $y = $this->itens($x, $y+1, $nInicial, $hDispo2, $n, $totPag, $hCabecItens);
665
            //coloca o rodapé da página
666
            if ($this->orientacao == 'P') {
667
                $this->rodape($xInic, $y + 4);
668
            } else {
669
                $this->rodape($xInic, $this->hPrint + 4);
670
            }
671
            //se estiver na última página e ainda restar itens para inserir, adiciona mais uma página
672
            if ($n == $totPag && $this->qtdeItensProc < $qtdeItens) {
673
                $totPag++;
674
            }
675
        }
676
    }
677
678
    /**
679
     * anfavea
680
     * Função para transformar o campo cdata do padrão ANFAVEA para
681
     * texto imprimível
682
     *
683
     * @param  string $cdata campo CDATA
684
     * @return string conteúdo do campo CDATA como string
685
     */
686
    protected function anfaveaDANFE($cdata = '')
687
    {
688
        if ($cdata == '') {
689
            return '';
690
        }
691
        //remove qualquer texto antes ou depois da tag CDATA
692
        $cdata = str_replace('<![CDATA[', '<CDATA>', $cdata);
693
        $cdata = str_replace(']]>', '</CDATA>', $cdata);
694
        $cdata = preg_replace('/\s\s+/', ' ', $cdata);
695
        $cdata = str_replace("> <", "><", $cdata);
696
        $len = strlen($cdata);
697
        $startPos = strpos($cdata, '<');
698
        if ($startPos === false) {
699
            return $cdata;
700
        }
701
        for ($x=$len; $x>0; $x--) {
702
            if (substr($cdata, $x, 1) == '>') {
703
                $endPos = $x;
704
                break;
705
            }
706
        }
707
        if ($startPos > 0) {
708
            $parte1 = substr($cdata, 0, $startPos);
709
        } else {
710
            $parte1 = '';
711
        }
712
        $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...
713
        if ($endPos < $len) {
714
            $parte3 = substr($cdata, $endPos + 1, $len - $endPos - 1);
715
        } else {
716
            $parte3 = '';
717
        }
718
        $texto = trim($parte1).' '.trim($parte3);
719
        if (strpos($parte2, '<CDATA>') === false) {
720
            $cdata = '<CDATA>'.$parte2.'</CDATA>';
721
        } else {
722
            $cdata = $parte2;
723
        }
724
        //Retira a tag <FONTE IBPT> (caso existir) pois não é uma estrutura válida XML
725
        $cdata = str_replace('<FONTE IBPT>', '', $cdata);
726
        //carrega o xml CDATA em um objeto DOM
727
        $dom = new Dom();
728
        $dom->loadXML($cdata, LIBXML_NOBLANKS | LIBXML_NOEMPTYTAG);
729
        //$xml = $dom->saveXML();
730
        //grupo CDATA infADprod
731
        $id = $dom->getElementsByTagName('id')->item(0);
732
        $div = $dom->getElementsByTagName('div')->item(0);
733
        $entg = $dom->getElementsByTagName('entg')->item(0);
734
        $dest = $dom->getElementsByTagName('dest')->item(0);
735
        $ctl = $dom->getElementsByTagName('ctl')->item(0);
736
        $ref = $dom->getElementsByTagName('ref')->item(0);
737
        if (isset($id)) {
738
            if ($id->hasAttributes()) {
739
                foreach ($id->attributes as $attr) {
740
                    $name = $attr->nodeName;
741
                    $value = $attr->nodeValue;
742
                    $texto .= " $name : $value";
743
                }
744
            }
745
        }
746
        if (isset($div)) {
747
            if ($div->hasAttributes()) {
748
                foreach ($div->attributes as $attr) {
749
                    $name = $attr->nodeName;
750
                    $value = $attr->nodeValue;
751
                    $texto .= " $name : $value";
752
                }
753
            }
754
        }
755
        if (isset($entg)) {
756
            if ($entg->hasAttributes()) {
757
                foreach ($entg->attributes as $attr) {
758
                    $name = $attr->nodeName;
759
                    $value = $attr->nodeValue;
760
                    $texto .= " $name : $value";
761
                }
762
            }
763
        }
764
        if (isset($dest)) {
765
            if ($dest->hasAttributes()) {
766
                foreach ($dest->attributes as $attr) {
767
                    $name = $attr->nodeName;
768
                    $value = $attr->nodeValue;
769
                    $texto .= " $name : $value";
770
                }
771
            }
772
        }
773
        if (isset($ctl)) {
774
            if ($ctl->hasAttributes()) {
775
                foreach ($ctl->attributes as $attr) {
776
                    $name = $attr->nodeName;
777
                    $value = $attr->nodeValue;
778
                    $texto .= " $name : $value";
779
                }
780
            }
781
        }
782
        if (isset($ref)) {
783
            if ($ref->hasAttributes()) {
784
                foreach ($ref->attributes as $attr) {
785
                    $name = $attr->nodeName;
786
                    $value = $attr->nodeValue;
787
                    $texto .= " $name : $value";
788
                }
789
            }
790
        }
791
        //grupo CADATA infCpl
792
        $t = $dom->getElementsByTagName('transmissor')->item(0);
793
        $r = $dom->getElementsByTagName('receptor')->item(0);
794
        $versao = ! empty($dom->getElementsByTagName('versao')->item(0)->nodeValue) ?
795
            'Versao:'.$dom->getElementsByTagName('versao')->item(0)->nodeValue.' ' : '';
796
        $especieNF = ! empty($dom->getElementsByTagName('especieNF')->item(0)->nodeValue) ?
797
            'Especie:'.$dom->getElementsByTagName('especieNF')->item(0)->nodeValue.' ' : '';
798
        $fabEntrega = ! empty($dom->getElementsByTagName('fabEntrega')->item(0)->nodeValue) ?
799
            'Entrega:'.$dom->getElementsByTagName('fabEntrega')->item(0)->nodeValue.' ' : '';
800
        $dca = ! empty($dom->getElementsByTagName('dca')->item(0)->nodeValue) ?
801
            'dca:'.$dom->getElementsByTagName('dca')->item(0)->nodeValue.' ' : '';
802
        $texto .= "".$versao.$especieNF.$fabEntrega.$dca;
803
        if (isset($t)) {
804
            if ($t->hasAttributes()) {
805
                $texto .= " Transmissor ";
806
                foreach ($t->attributes as $attr) {
807
                    $name = $attr->nodeName;
808
                    $value = $attr->nodeValue;
809
                    $texto .= " $name : $value";
810
                }
811
            }
812
        }
813
        if (isset($r)) {
814
            if ($r->hasAttributes()) {
815
                $texto .= " Receptor ";
816
                foreach ($r->attributes as $attr) {
817
                    $name = $attr->nodeName;
818
                    $value = $attr->nodeValue;
819
                    $texto .= " $name : $value";
820
                }
821
            }
822
        }
823
        return $texto;
824
    }
825
826
827
828
    protected function statusNFe()
829
    {
830
        if (!isset($this->nfeProc)) {
831
            return ['status' => false, 'message' => 'NFe NÃO PROTOCOLADA'];
832
        }
833
        if ($this->getTagValue($this->ide, "tpAmb") == '2') {
834
            return ['status' => false, 'message' => 'NFe EMITIDA EM HOMOLOGAÇÃO'];
835
        }
836
        $cStat = $this->getTagValue($this->nfeProc, "cStat");
0 ignored issues
show
Bug introduced by
The property nfeProc 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...
837
        if ($cStat == '101'
838
            || $cStat == '151'
839
            || $cStat == '135'
840
            || $cStat == '155'
841
        ) {
842
            return ['status' => false, 'message' => 'NFe CANCELADA'];
843
        }
844
        
845
        if ($cStat == '110' ||
846
               $cStat == '301' ||
847
               $cStat == '302'
848
               
849
        ) {
850
            return ['status' => false, 'message' => 'NFe DENEGADA'];
851
        }
852
    }
853
854
    protected function notaDPEC()
855
    {
856
        return $this->numero_registro_dpec != '';
857
    }
858
859
860
861
    /**
862
     *header
863
     * Monta o cabelhalho da DANFE (retrato e paisagem)
864
     *
865
     * @param  number $x      Posição horizontal inicial, canto esquerdo
866
     * @param  number $y      Posição vertical inicial, canto superior
867
     * @param  number $pag    Número da Página
868
     * @param  number $totPag Total de páginas
869
     * @return number Posição vertical final
870
     */
871
    protected function header($x = 0, $y = 0, $pag = '1', $totPag = '1')
872
    {
873
        $oldX = $x;
874
        $oldY = $y;
875
        if ($this->orientacao == 'P') {
876
              $maxW = $this->wPrint;
877
        } else {
878
            if ($pag == 1) { // primeira página
879
                $maxW = $this->wPrint - $this->wCanhoto;
880
            } else { // páginas seguintes
881
                $maxW = $this->wPrint;
882
            }
883
        }
884
        //####################################################################################
885
        //coluna esquerda identificação do emitente
886
        $w = round($maxW*0.41, 0);
887
        if ($this->orientacao == 'P') {
888
            $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>'I'];
889
        } else {
890
            $aFont = ['font'=>$this->fontePadrao, 'size'=>8, 'style'=>'B'];
891
        }
892
        $w1 = $w;
893
        $h=32;
894
        $oldY += $h;
895
        $this->pdf->textBox($x, $y, $w, $h);
896
        $texto = 'IDENTIFICAÇÃO DO EMITENTE';
897
        $this->pdf->textBox($x, $y, $w, 5, $texto, $aFont, 'T', 'C', 0, '');
898
        //estabelecer o alinhamento
899
        //pode ser left L, center C, right R, full logo L
900
        //se for left separar 1/3 da largura para o tamanho da imagem
901
        //os outros 2/3 serão usados para os dados do emitente
902
        //se for center separar 1/2 da altura para o logo e 1/2 para os dados
903
        //se for right separa 2/3 para os dados e o terço seguinte para o logo
904
        //se não houver logo centraliza dos dados do emitente
905
        // coloca o logo
906
        if (!empty($this->logomarca)) {
907
            $logoInfo = getimagesize($this->logomarca);
908
            $type = strtolower(explode('/', $logoInfo['mime'])[1]);
909
            if ($type == 'png') {
910
                $this->logomarca = $this->imagePNGtoJPG($this->logomarca);
911
                $type == 'jpg';
912
            }
913
            //largura da imagem em mm
914
            $logoWmm = ($logoInfo[0]/72)*25.4;
915
            //altura da imagem em mm
916
            $logoHmm = ($logoInfo[1]/72)*25.4;
917
            if ($this->logoAlign=='L') {
918
                $nImgW = round($w/3, 0);
919
                $nImgH = round($logoHmm * ($nImgW/$logoWmm), 0);
920
                $xImg = $x+1;
921
                $yImg = round(($h-$nImgH)/2, 0)+$y;
922
                //estabelecer posições do texto
923
                $x1 = round($xImg + $nImgW +1, 0);
924
                $y1 = round($h/3+$y, 0);
925
                $tw = round(2*$w/3, 0);
926
            } elseif ($this->logoAlign=='C') {
927
                $nImgH = round($h/3, 0);
928
                $nImgW = round($logoWmm * ($nImgH/$logoHmm), 0);
929
                $xImg = round(($w-$nImgW)/2+$x, 0);
930
                $yImg = $y+3;
931
                $x1 = $x;
932
                $y1 = round($yImg + $nImgH + 1, 0);
933
                $tw = $w;
934
            } elseif ($this->logoAlign=='R') {
935
                $nImgW = round($w/3, 0);
936
                $nImgH = round($logoHmm * ($nImgW/$logoWmm), 0);
937
                $xImg = round($x+($w-(1+$nImgW)), 0);
938
                $yImg = round(($h-$nImgH)/2, 0)+$y;
939
                $x1 = $x;
940
                $y1 = round($h/3+$y, 0);
941
                $tw = round(2*$w/3, 0);
942
            } elseif ($this->logoAlign=='F') {
943
                $nImgH = round($h-5, 0);
944
                $nImgW = round($logoWmm * ($nImgH/$logoHmm), 0);
945
                $xImg = round(($w-$nImgW)/2+$x, 0);
946
                $yImg = $y+3;
947
                $x1 = $x;
948
                $y1 = round($yImg + $nImgH + 1, 0);
949
                $tw = $w;
950
            }
951
            $type = (substr($this->logomarca, 0, 7) === 'data://') ? 'jpg' : null;
952
            $this->pdf->Image($this->logomarca, $xImg, $yImg, $nImgW, $nImgH, $type);
0 ignored issues
show
Bug introduced by
The variable $xImg 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...
Bug introduced by
The variable $yImg 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...
Bug introduced by
The variable $nImgW 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...
Bug introduced by
The variable $nImgH 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...
953
        } else {
954
            $x1 = $x;
955
            $y1 = round($h/3+$y, 0);
956
            $tw = $w;
957
        }
958
        // monta as informações apenas se diferente de full logo
959
        if ($this->logoAlign !== 'F') {
960
            //Nome emitente
961
            $aFont = ['font'=>$this->fontePadrao, 'size'=>12, 'style'=>'B'];
962
            $texto = $this->emit->getElementsByTagName("xNome")->item(0)->nodeValue;
963
            $this->pdf->textBox($x1, $y1, $tw, 8, $texto, $aFont, 'T', 'C', 0, '');
0 ignored issues
show
Bug introduced by
The variable $x1 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...
Bug introduced by
The variable $y1 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...
Bug introduced by
The variable $tw 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...
964
            //endereço
965
            $y1 = $y1+5;
966
            $aFont = ['font'=>$this->fontePadrao, 'size'=>8, 'style'=>''];
967
            $fone = ! empty($this->enderEmit->getElementsByTagName("fone")->item(0)->nodeValue)
968
                 ? $this->enderEmit->getElementsByTagName("fone")->item(0)->nodeValue
969
                 : '';
970
            $lgr = $this->getTagValue($this->enderEmit, "xLgr");
971
            $nro = $this->getTagValue($this->enderEmit, "nro");
972
            $cpl = $this->getTagValue($this->enderEmit, "xCpl", " - ");
973
            $bairro = $this->getTagValue($this->enderEmit, "xBairro");
974
            $CEP = $this->getTagValue($this->enderEmit, "CEP");
975
            $CEP = $this->formatField($CEP, "#####-###");
976
            $mun = $this->getTagValue($this->enderEmit, "xMun");
977
            $UF = $this->getTagValue($this->enderEmit, "UF");
978
            $texto = $lgr . ", " . $nro . $cpl . "\n" . $bairro . " - "
979
                    . $CEP . "\n" . $mun . " - " . $UF . " "
980
                    . "Fone/Fax: " . $fone;
981
            $this->pdf->textBox($x1, $y1, $tw, 8, $texto, $aFont, 'T', 'C', 0, '');
982
        }
983
984
        //####################################################################################
985
        //coluna central Danfe
986
        $x += $w;
987
        $w=round($maxW * 0.17, 0);//35;
988
        $w2 = $w;
989
        $h = 32;
990
        $this->pdf->textBox($x, $y, $w, $h);
991
  
992
        $texto = "DANFE";
993
        $aFont = ['font'=>$this->fontePadrao, 'size'=>14, 'style'=>'B'];
994
        $this->pdf->textBox($x, $y+1, $w, $h, $texto, $aFont, 'T', 'C', 0, '');
995
        $aFont = ['font'=>$this->fontePadrao, 'size'=>8, 'style'=>''];
996
        $texto = 'Documento Auxiliar da Nota Fiscal Eletrônica';
997
        $h = 20;
998
        $this->pdf->textBox($x, $y+6, $w, $h, $texto, $aFont, 'T', 'C', 0, '', false);
999
        
1000
1001
        $aFont = ['font'=>$this->fontePadrao, 'size'=>8, 'style'=>''];
1002
        $texto = '0 - ENTRADA';
1003
        $y1 = $y + 14;
1004
        $h = 8;
1005
        $this->pdf->textBox($x+2, $y1, $w, $h, $texto, $aFont, 'T', 'L', 0, '');
1006
        $texto = '1 - SAÍDA';
1007
        $y1 = $y + 17;
1008
        $this->pdf->textBox($x+2, $y1, $w, $h, $texto, $aFont, 'T', 'L', 0, '');
1009
        //tipo de nF
1010
        $aFont = ['font'=>$this->fontePadrao, 'size'=>12, 'style'=>'B'];
1011
        $y1 = $y + 13;
1012
        $h = 7;
1013
        $texto = $this->ide->getElementsByTagName('tpNF')->item(0)->nodeValue;
1014
        $this->pdf->textBox($x+27, $y1, 5, $h, $texto, $aFont, 'C', 'C', 1, '');
1015
        //numero da NF
1016
        $aFont = ['font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B'];
1017
        $y1 = $y + 20;
1018
        $numNF = str_pad($this->ide->getElementsByTagName('nNF')->item(0)->nodeValue, 9, "0", STR_PAD_LEFT);
1019
        $numNF = $this->formatField($numNF, "###.###.###");
1020
        $texto = "Nº. " . $numNF;
1021
        $this->pdf->textBox($x, $y1, $w, $h, $texto, $aFont, 'C', 'C', 0, '');
1022
        //Série
1023
        $y1 = $y + 23;
1024
        $serie = str_pad($this->ide->getElementsByTagName('serie')->item(0)->nodeValue, 3, "0", STR_PAD_LEFT);
1025
        $texto = "Série " . $serie;
1026
        $this->pdf->textBox($x, $y1, $w, $h, $texto, $aFont, 'C', 'C', 0, '');
1027
        //numero paginas
1028
        $aFont = ['font'=>$this->fontePadrao, 'size'=>8, 'style'=>'I'];
1029
        $y1 = $y + 26;
1030
        $texto = "Folha " . $pag . "/" . $totPag;
1031
        $this->pdf->textBox($x, $y1, $w, $h, $texto, $aFont, 'C', 'C', 0, '');
1032
1033
        //####################################################################################
1034
        //coluna codigo de barras
1035
        $x += $w;
1036
        $w = ($maxW-$w1-$w2);//85;
1037
        $w3 = $w;
1038
        $h = 32;
1039
        $this->pdf->textBox($x, $y, $w, $h);
1040
        $this->pdf->setFillColor(0, 0, 0);
1041
        $chave_acesso = str_replace('NFe', '', $this->infNFe->getAttribute("Id"));
1042
        $bW = 75;
1043
        $bH = 12;
1044
        //codigo de barras
1045
        $this->pdf->code128($x+(($w-$bW)/2), $y+2, $chave_acesso, $bW, $bH);
1046
        //linhas divisorias
1047
        $this->pdf->line($x, $y+4+$bH, $x+$w, $y+4+$bH);
1048
        $this->pdf->line($x, $y+12+$bH, $x+$w, $y+12+$bH);
1049
        $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
1050
        $y1 = $y+4+$bH;
1051
        $h = 7;
1052
        $texto = 'CHAVE DE ACESSO';
1053
        $this->pdf->textBox($x, $y1, $w, $h, $texto, $aFont, 'T', 'L', 0, '');
1054
        $aFont = ['font'=>$this->fontePadrao, 'size'=>8, 'style'=>'B'];
1055
        $y1 = $y+8+$bH;
1056
        $texto = $this->formatField($chave_acesso, $this->formatoChave);
1057
        $this->pdf->textBox($x+2, $y1, $w-2, $h, $texto, $aFont, 'T', 'C', 0, '');
1058
        $y1 = $y+12+$bH;
1059
        $aFont = ['font'=>$this->fontePadrao, 'size'=>8, 'style'=>''];
1060
        $chaveContingencia="";
1061
        if ($this->notaDpec()) {
1062
            $cabecalhoProtoAutorizacao = 'NÚMERO DE REGISTRO DPEC';
1063
        } else {
1064
            $cabecalhoProtoAutorizacao = 'PROTOCOLO DE AUTORIZAÇÃO DE USO';
1065
        }
1066
        if (($this->tpEmis == 2 || $this->tpEmis == 5) && !$this->notaDpec()) {
1067
            $cabecalhoProtoAutorizacao = "DADOS DA NF-E";
1068
            $chaveContingencia = $this->geraChaveAdicionalDeContingencia();
1069
            $this->pdf->setFillColor(0, 0, 0);
1070
            //codigo de barras
1071
            $this->pdf->code128($x+11, $y1+1, $chaveContingencia, $bW*.9, $bH/2);
1072
        } else {
1073
            $texto = 'Consulta de autenticidade no portal nacional da NF-e';
1074
            $this->pdf->textBox($x+2, $y1, $w-2, $h, $texto, $aFont, 'T', 'C', 0, '');
1075
            $y1 = $y+16+$bH;
1076
            $texto = 'www.nfe.fazenda.gov.br/portal ou no site da Sefaz Autorizadora';
1077
            $this->pdf->textBox(
1078
                $x+2,
1079
                $y1,
1080
                $w-2,
1081
                $h,
1082
                $texto,
1083
                $aFont,
1084
                'T',
1085
                'C',
1086
                0,
1087
                'http://www.nfe.fazenda.gov.br/portal ou no site da Sefaz Autorizadora'
1088
            );
1089
        }
1090
1091
        //####################################################################################
1092
        //Dados da NF do cabeçalho
1093
        //natureza da operação
1094
        $texto = 'NATUREZA DA OPERAÇÃO';
1095
        $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
1096
        $w = $w1+$w2;
1097
        $y = $oldY;
1098
        $oldY += $h;
1099
        $x = $oldX;
1100
        $h = 7;
1101
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 1, '');
1102
        $texto = $this->ide->getElementsByTagName("natOp")->item(0)->nodeValue;
1103
        $aFont = ['font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B'];
1104
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'B', 'C', 0, '');
1105
        $x += $w;
1106
        $w = $w3;
1107
        //PROTOCOLO DE AUTORIZAÇÃO DE USO ou DADOS da NF-E
1108
        $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
1109
        $this->pdf->textBox($x, $y, $w, $h, $cabecalhoProtoAutorizacao, $aFont, 'T', 'L', 1, '');
1110
        // algumas NFe podem estar sem o protocolo de uso portanto sua existencia deve ser
1111
        // testada antes de tentar obter a informação.
1112
        // NOTA : DANFE sem protocolo deve existir somente no caso de contingência !!!
1113
        // Além disso, existem várias NFes em contingência que eu recebo com protocolo de autorização.
1114
        // Na minha opinião, deveríamos mostra-lo, mas o  manual  da NFe v4.01 diz outra coisa...
1115
        if (($this->tpEmis == 2 || $this->tpEmis == 5) && !$this->notaDpec()) {
1116
            $aFont = ['font'=>$this->fontePadrao, 'size'=>8, 'style'=>'B'];
1117
            $texto = $this->formatField($chaveContingencia, "#### #### #### #### #### #### #### #### ####");
1118
            $cStat = '';
0 ignored issues
show
Unused Code introduced by
$cStat 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...
1119
        } else {
1120
            $aFont = ['font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B'];
1121
            if ($this->notaDpec()) {
1122
                $texto = $this->numero_registro_dpec;
1123
                $cStat = '';
0 ignored issues
show
Unused Code introduced by
$cStat 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...
1124
            } else {
1125
                if (isset($this->nfeProc)) {
1126
                    $texto = ! empty($this->nfeProc->getElementsByTagName("nProt")->item(0)->nodeValue) ?
1127
                            $this->nfeProc->getElementsByTagName("nProt")->item(0)->nodeValue : '';
1128
                    $tsHora = $this->convertTime($this->nfeProc->getElementsByTagName("dhRecbto")->item(0)->nodeValue);
1129
                    if ($texto != '') {
1130
                        $texto .= "  -  " . date('d/m/Y H:i:s', $tsHora);
1131
                    }
1132
                    $cStat = $this->nfeProc->getElementsByTagName("cStat")->item(0)->nodeValue;
0 ignored issues
show
Unused Code introduced by
$cStat 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...
1133
                } else {
1134
                    $texto = '';
1135
                    $cStat = '';
0 ignored issues
show
Unused Code introduced by
$cStat 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...
1136
                }
1137
            }
1138
        }
1139
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'B', 'C', 0, '');
1140
        //####################################################################################
1141
        //INSCRIÇÃO ESTADUAL
1142
        $w = round($maxW * 0.333, 0);
1143
        $y += $h;
1144
        $oldY += $h;
1145
        $x = $oldX;
1146
        $texto = 'INSCRIÇÃO ESTADUAL';
1147
        $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
1148
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 1, '');
1149
        $texto = $this->getTagValue($this->emit, "IE");
1150
        $aFont = ['font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B'];
1151
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'B', 'C', 0, '');
1152
        //INSCRIÇÃO ESTADUAL DO SUBST. TRIBUT.
1153
        $x += $w;
1154
        $texto = 'INSCRIÇÃO ESTADUAL DO SUBST. TRIBUT.';
1155
        $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
1156
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 1, '');
1157
        $texto = ! empty($this->emit->getElementsByTagName("IEST")->item(0)->nodeValue)
1158
             ? $this->emit->getElementsByTagName("IEST")->item(0)->nodeValue
1159
             : '';
1160
        $aFont = ['font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B'];
1161
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'B', 'C', 0, '');
1162
        //CNPJ
1163
        $x += $w;
1164
        $w = ($maxW-(2*$w));
1165
        $texto = 'CNPJ / CPF';
1166
        $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
1167
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 1, '');
1168
        //Pegando valor do CPF/CNPJ
1169
        if (! empty($this->emit->getElementsByTagName("CNPJ")->item(0)->nodeValue)) {
1170
            $texto = $this->formatField(
1171
                $this->emit->getElementsByTagName("CNPJ")->item(0)->nodeValue,
1172
                "###.###.###/####-##"
1173
            );
1174
        } else {
1175
            $texto = ! empty($this->emit->getElementsByTagName("CPF")->item(0)->nodeValue) ?
1176
                $this->formatField(
1177
                    $this->emit->getElementsByTagName("CPF")->item(0)->nodeValue,
1178
                    "###.###.###-##"
1179
                ) : '';
1180
        }
1181
        $aFont = ['font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B'];
1182
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'B', 'C', 0, '');
1183
1184
        //####################################################################################
1185
        //Indicação de NF Homologação, cancelamento e falta de protocolo
1186
        $tpAmb = $this->ide->getElementsByTagName('tpAmb')->item(0)->nodeValue;
0 ignored issues
show
Unused Code introduced by
$tpAmb 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...
1187
        //indicar cancelamento
1188
        $resp = $this->statusNFe();
1189
        if (!$resp['status']) {
1190
            $x = 10;
1191
            $y = $this->hPrint-130;
1192
            $h = 25;
1193
            $w = $maxW-(2*$x);
1194
            $this->pdf->setTextColor(90, 90, 90);
1195
            $texto = $resp['message'];
1196
            $aFont = ['font'=>$this->fontePadrao, 'size'=>48, 'style'=>'B'];
1197
            $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'C', 'C', 0, '');
1198
            $y += $h;
1199
            $h = 5;
1200
            $w = $maxW-(2*$x);
1201
            if (isset($this->infProt) && $resp['status']) {
1202
                $xMotivo = $this->infProt->getElementsByTagName("xMotivo")->item(0)->nodeValue;
1203
            } else {
1204
                $xMotivo = '';
1205
            }
1206
            $texto = "SEM VALOR FISCAL\n".$xMotivo;
1207
            $aFont = ['font'=>$this->fontePadrao, 'size'=>48, 'style'=>'B'];
1208
            $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'C', 'C', 0, '');
1209
            $this->pdf->setTextColor(0, 0, 0);
1210
        }
1211
        
1212
        /*
1213
        if ($this->pNotaCancelada()) {
1214
            //101 Cancelamento
1215
            $x = 10;
1216
            $y = $this->hPrint-130;
1217
            $h = 25;
1218
            $w = $maxW-(2*$x);
1219
            $this->pdf->SetTextColor(90, 90, 90);
1220
            $texto = "NFe CANCELADA";
1221
            $aFont = ['font'=>$this->fontePadrao, 'size'=>48, 'style'=>'B'];
1222
            $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'C', 'C', 0, '');
1223
            $this->pdf->SetTextColor(0, 0, 0);
1224
        }*/
1225
1226
        if ($this->notaDpec() || $this->tpEmis == 4) {
1227
            //DPEC
1228
            $x = 10;
1229
            $y = $this->hPrint-130;
1230
            $h = 25;
1231
            $w = $maxW-(2*$x);
1232
            $this->pdf->SetTextColor(200, 200, 200);
1233
            $texto = "DANFE impresso em contingência -\n".
1234
                     "DPEC regularmente recebido pela Receita\n".
1235
                     "Federal do Brasil";
1236
            $aFont = ['font'=>$this->fontePadrao, 'size'=>48, 'style'=>'B'];
1237
            $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'C', 'C', 0, '');
1238
            $this->pdf->SetTextColor(0, 0, 0);
1239
        }
1240
        /*
1241
        if ($this->pNotaDenegada()) {
1242
            //110 301 302 Denegada
1243
            $x = 10;
1244
            $y = $this->hPrint-130;
1245
            $h = 25;
1246
            $w = $maxW-(2*$x);
1247
            $this->pdf->SetTextColor(90, 90, 90);
1248
            $texto = "NFe USO DENEGADO";
1249
            $aFont = ['font'=>$this->fontePadrao, 'size'=>48, 'style'=>'B'];
1250
            $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'C', 'C', 0, '');
1251
            $y += $h;
1252
            $h = 5;
1253
            $w = $maxW-(2*$x);
1254
            if (isset($this->infProt)) {
1255
                $xMotivo = $this->infProt->getElementsByTagName("xMotivo")->item(0)->nodeValue;
1256
            } else {
1257
                $xMotivo = '';
1258
            }
1259
            $texto = "SEM VALOR FISCAL\n".$xMotivo;
1260
            $aFont = ['font'=>$this->fontePadrao, 'size'=>48, 'style'=>'B'];
1261
            $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'C', 'C', 0, '');
1262
            $this->pdf->SetTextColor(0, 0, 0);
1263
        }
1264
         *
1265
         */
1266
        //indicar sem valor
1267
        /*
1268
        if ($tpAmb != 1) {
1269
            $x = 10;
1270
            if ($this->orientacao == 'P') {
1271
                $y = round($this->hPrint*2/3, 0);
1272
            } else {
1273
                $y = round($this->hPrint/2, 0);
1274
            }
1275
            $h = 5;
1276
            $w = $maxW-(2*$x);
1277
            $this->pdf->SetTextColor(90, 90, 90);
1278
            $texto = "SEM VALOR FISCAL";
1279
            $aFont = ['font'=>$this->fontePadrao, 'size'=>48, 'style'=>'B'];
1280
            $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'C', 'C', 0, '');
1281
            $aFont = ['font'=>$this->fontePadrao, 'size'=>30, 'style'=>'B'];
1282
            $texto = "AMBIENTE DE HOMOLOGAÇÃO";
1283
            $this->pdf->textBox($x, $y+14, $w, $h, $texto, $aFont, 'C', 'C', 0, '');
1284
            $this->pdf->SetTextColor(0, 0, 0);
1285
        } else {
1286
            $x = 10;
1287
            if ($this->orientacao == 'P') {
1288
                $y = round($this->hPrint*2/3, 0);
1289
            } else {
1290
                $y = round($this->hPrint/2, 0);
1291
            }//fim orientacao
1292
            $h = 5;
1293
            $w = $maxW-(2*$x);
1294
            $this->pdf->SetTextColor(90, 90, 90);
1295
            //indicar FALTA DO PROTOCOLO se NFe não for em contingência
1296
            if (($this->tpEmis == 2 || $this->tpEmis == 5) && !$this->notaDpec()) {
1297
                //Contingência
1298
                $texto = "DANFE Emitido em Contingência";
1299
                $aFont = ['font'=>$this->fontePadrao, 'size'=>48, 'style'=>'B'];
1300
                $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'C', 'C', 0, '');
1301
                $aFont = ['font'=>$this->fontePadrao, 'size'=>30, 'style'=>'B'];
1302
                $texto = "devido à problemas técnicos";
1303
                $this->pdf->textBox($x, $y+12, $w, $h, $texto, $aFont, 'C', 'C', 0, '');
1304
            } else {
1305
                if (!isset($this->nfeProc)) {
1306
                    if (!$this->notaDpec()) {
1307
                        $texto = "SEM VALOR FISCAL";
1308
                        $aFont = ['font'=>$this->fontePadrao, 'size'=>48, 'style'=>'B'];
1309
                        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'C', 'C', 0, '');
1310
                    }
1311
                    $aFont = ['font'=>$this->fontePadrao, 'size'=>30, 'style'=>'B'];
1312
                    $texto = "FALTA PROTOCOLO DE APROVAÇÃO DA SEFAZ";
1313
                    if (!$this->notaDpec()) {
1314
                        $this->pdf->textBox($x, $y+12, $w, $h, $texto, $aFont, 'C', 'C', 0, '');
1315
                    } else {
1316
                        $this->pdf->textBox($x, $y+25, $w, $h, $texto, $aFont, 'C', 'C', 0, '');
1317
                    }
1318
                }//fim nefProc
1319
            }//fim tpEmis
1320
            $this->pdf->SetTextColor(0, 0, 0);
1321
        }
1322
         *
1323
         */
1324
        return $oldY;
1325
    } //fim header
1326
1327
    /**
1328
     * destinatarioDANFE
1329
     * Monta o campo com os dados do destinatário na DANFE. (retrato e paisagem)
1330
     *
1331
     * @name   destinatarioDANFE
1332
     * @param  number $x Posição horizontal canto esquerdo
1333
     * @param  number $y Posição vertical canto superior
1334
     * @return number Posição vertical final
1335
     */
1336
    protected function destinatarioDANFE($x = 0, $y = 0)
1337
    {
1338
        //####################################################################################
1339
        //DESTINATÁRIO / REMETENTE
1340
        $oldX = $x;
1341
        $oldY = $y;
0 ignored issues
show
Unused Code introduced by
$oldY 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...
1342
        if ($this->orientacao == 'P') {
1343
            $maxW = $this->wPrint;
1344
        } else {
1345
            $maxW = $this->wPrint - $this->wCanhoto;
1346
        }
1347
        $w = $maxW;
1348
        $h = 7;
1349
        $texto = 'DESTINATÁRIO / REMETENTE';
1350
        $aFont = ['font'=>$this->fontePadrao, 'size'=>7, 'style'=>'B'];
1351
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 0, '');
1352
        //NOME / RAZÃO SOCIAL
1353
        $w = round($maxW*0.61, 0);
1354
        $w1 = $w;
1355
        $y += 3;
1356
        $texto = 'NOME / RAZÃO SOCIAL';
1357
        $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
1358
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 1, '');
1359
        $texto = $this->dest->getElementsByTagName("xNome")->item(0)->nodeValue;
1360
        $aFont = ['font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B'];
1361
        if ($this->orientacao == 'P') {
1362
            $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'B', 'L', 0, '');
1363
        } else {
1364
            $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'B', 'L', 1, '');
1365
        }
1366
        //CNPJ / CPF
1367
        $x += $w;
1368
        $w = round($maxW*0.23, 0);
1369
        $w2 = $w;
1370
        $texto = 'CNPJ / CPF';
1371
        $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
1372
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 1, '');
1373
        //Pegando valor do CPF/CNPJ
1374
        if (! empty($this->dest->getElementsByTagName("CNPJ")->item(0)->nodeValue)) {
1375
            $texto = $this->formatField(
1376
                $this->dest->getElementsByTagName("CNPJ")->item(0)->nodeValue,
1377
                "###.###.###/####-##"
1378
            );
1379
        } else {
1380
            $texto = ! empty($this->dest->getElementsByTagName("CPF")->item(0)->nodeValue) ?
1381
                    $this->formatField(
1382
                        $this->dest->getElementsByTagName("CPF")->item(0)->nodeValue,
1383
                        "###.###.###-##"
1384
                    ) : '';
1385
        }
1386
        $aFont = ['font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B'];
1387
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'B', 'C', 0, '');
1388
        //DATA DA EMISSÃO
1389
        $x += $w;
1390
        $w = $maxW-($w1+$w2);
1391
        $wx = $w;
1392
        $texto = 'DATA DA EMISSÃO';
1393
        $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
1394
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 1, '');
1395
        $dEmi = ! empty($this->ide->getElementsByTagName("dEmi")->item(0)->nodeValue) ?
1396
                $this->ide->getElementsByTagName("dEmi")->item(0)->nodeValue : '';
1397
        if ($dEmi == '') {
1398
            $dEmi = ! empty($this->ide->getElementsByTagName("dhEmi")->item(0)->nodeValue) ?
1399
                    $this->ide->getElementsByTagName("dhEmi")->item(0)->nodeValue : '';
1400
            $aDemi = explode('T', $dEmi);
1401
            $dEmi = $aDemi[0];
1402
        }
1403
        $texto = $this->ymdTodmy($dEmi);
1404
        $aFont = ['font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B'];
1405
        if ($this->orientacao == 'P') {
1406
            $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'B', 'C', 0, '');
1407
        } else {
1408
            $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'B', 'C', 1, '');
1409
        }
1410
        //ENDEREÇO
1411
        $w = round($maxW*0.47, 0);
1412
        $w1 = $w;
1413
        $y += $h;
1414
        $x = $oldX;
1415
        $texto = 'ENDEREÇO';
1416
        $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
1417
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 1, '');
1418
        $texto = $this->dest->getElementsByTagName("xLgr")->item(0)->nodeValue;
1419
        $texto .= ', ' . $this->dest->getElementsByTagName("nro")->item(0)->nodeValue;
1420
        $texto .= $this->getTagValue($this->dest, "xCpl", " - ");
1421
1422
        $aFont = ['font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B'];
1423
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'B', 'L', 0, '', true);
1424
        //BAIRRO / DISTRITO
1425
        $x += $w;
1426
        $w = round($maxW*0.21, 0);
1427
        $w2 = $w;
1428
        $texto = 'BAIRRO / DISTRITO';
1429
        $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
1430
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 1, '');
1431
        $texto = $this->dest->getElementsByTagName("xBairro")->item(0)->nodeValue;
1432
        $aFont = ['font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B'];
1433
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'B', 'C', 0, '');
1434
        //CEP
1435
        $x += $w;
1436
        $w = $maxW-$w1-$w2-$wx;
1437
        $w2 = $w;
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...
1438
        $texto = 'CEP';
1439
        $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
1440
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 1, '');
1441
        $texto = ! empty($this->dest->getElementsByTagName("CEP")->item(0)->nodeValue) ?
1442
                $this->dest->getElementsByTagName("CEP")->item(0)->nodeValue : '';
1443
        $texto = $this->formatField($texto, "#####-###");
1444
        $aFont = ['font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B'];
1445
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'B', 'C', 0, '');
1446
        //DATA DA SAÍDA
1447
        $x += $w;
1448
        $w = $wx;
1449
        $texto = 'DATA DA SAÍDA/ENTRADA';
1450
        $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
1451
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 1, '');
1452
        $dSaiEnt = ! empty($this->ide->getElementsByTagName("dSaiEnt")->item(0)->nodeValue) ?
1453
                $this->ide->getElementsByTagName("dSaiEnt")->item(0)->nodeValue : '';
1454
        if ($dSaiEnt == '') {
1455
            $dSaiEnt = ! empty($this->ide->getElementsByTagName("dhSaiEnt")->item(0)->nodeValue) ?
1456
                    $this->ide->getElementsByTagName("dhSaiEnt")->item(0)->nodeValue : '';
1457
            $aDsaient = explode('T', $dSaiEnt);
1458
            $dSaiEnt = $aDsaient[0];
1459
        }
1460
        $texto = $this->ymdTodmy($dSaiEnt);
1461
        $aFont = ['font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B'];
1462
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'B', 'C', 0, '');
1463
        //MUNICÍPIO
1464
        $w = $w1;
1465
        $y += $h;
1466
        $x = $oldX;
1467
        $texto = 'MUNICÍPIO';
1468
        $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
1469
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 1, '');
1470
        $texto = $this->dest->getElementsByTagName("xMun")->item(0)->nodeValue;
1471
        if (strtoupper(trim($texto)) == "EXTERIOR" && $this->dest->getElementsByTagName("xPais")->length > 0) {
1472
            $texto .= " - " .  $this->dest->getElementsByTagName("xPais")->item(0)->nodeValue;
1473
        }
1474
        $aFont = ['font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B'];
1475
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'B', 'L', 0, '');
1476
        //UF
1477
        $x += $w;
1478
        $w = 8;
1479
        $texto = 'UF';
1480
        $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
1481
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 1, '');
1482
        $texto = $this->dest->getElementsByTagName("UF")->item(0)->nodeValue;
1483
        $aFont = ['font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B'];
1484
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'B', 'C', 0, '');
1485
        //FONE / FAX
1486
        $x += $w;
1487
        $w = round(($maxW -$w1-$wx-8)/2, 0);
1488
        $w3 = $w;
1489
        $texto = 'FONE / FAX';
1490
        $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
1491
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 1, '');
1492
        $texto = ! empty($this->dest->getElementsByTagName("fone")->item(0)->nodeValue) ?
1493
                $this->dest->getElementsByTagName("fone")->item(0)->nodeValue : '';
1494
        $aFont = ['font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B'];
1495
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'B', 'C', 0, '');
1496
        //INSCRIÇÃO ESTADUAL
1497
        $x += $w;
1498
        $w = $maxW -$w1-$wx-8-$w3;
1499
        $texto = 'INSCRIÇÃO ESTADUAL';
1500
        $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
1501
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 1, '');
1502
        $IE = $this->dest->getElementsByTagName("IE");
1503
        $texto = ($IE && $IE->length > 0) ? $IE->item(0)->nodeValue : '';
1504
        $aFont = ['font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B'];
1505
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'B', 'C', 0, '');
1506
        //HORA DA SAÍDA
1507
        $x += $w;
1508
        $w = $wx;
1509
        $texto = 'HORA DA SAÍDA/ENTRADA';
1510
        $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
1511
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 1, '');
1512
        $hSaiEnt = ! empty($this->ide->getElementsByTagName("hSaiEnt")->item(0)->nodeValue) ?
1513
                $this->ide->getElementsByTagName("hSaiEnt")->item(0)->nodeValue : '';
1514
        if ($hSaiEnt == '') {
1515
            $dhSaiEnt = ! empty($this->ide->getElementsByTagName("dhSaiEnt")->item(0)->nodeValue) ?
1516
                    $this->ide->getElementsByTagName("dhSaiEnt")->item(0)->nodeValue : '';
1517
            $tsDhSaiEnt = $this->convertTime($dhSaiEnt);
1518
            if ($tsDhSaiEnt != '') {
1519
                $hSaiEnt = date('H:i:s', $tsDhSaiEnt);
1520
            }
1521
        }
1522
        $texto = $hSaiEnt;
1523
        $aFont = ['font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B'];
1524
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'B', 'C', 0, '');
1525
        return ($y + $h);
1526
    } //fim da função destinatarioDANFE
1527
1528
     /**
1529
     * getTextoFatura
1530
     * Gera a String do Texto da Fatura
1531
      *
1532
     * @name   getTextoFatura
1533
     * @return uma String com o texto ou "";
1534
     */
1535
    protected function getTextoFatura()
1536
    {
1537
        if (isset($this->cobr)) {
1538
            $fat = $this->cobr->getElementsByTagName("fat")->item(0);
1539
            if (isset($fat)) {
1540
                if (!empty($this->getTagValue($this->ide, "indPag"))) {
1541
                    $textoIndPag = "";
1542
                    $indPag = $this->getTagValue($this->ide, "indPag");
1543
                    if ($indPag === "0") {
1544
                        $textoIndPag = "Pagamento à Vista - ";
1545
                    } elseif ($indPag === "1") {
1546
                        $textoIndPag = "Pagamento à Prazo - ";
1547
                    }
1548
                    $nFat = $this->getTagValue($fat, "nFat", "Fatura: ");
1549
                    $vOrig = $this->getTagValue($fat, "vOrig", " Valor Original: ");
1550
                    $vDesc = $this->getTagValue($fat, "vDesc", " Desconto: ");
1551
                    $vLiq = $this->getTagValue($fat, "vLiq", " Valor Líquido: ");
1552
                    $texto = $textoIndPag . $nFat . $vOrig . $vDesc . $vLiq;
1553
                    return $texto;
1554
                } else {
1555
                    $pag = $this->dom->getElementsByTagName("pag");
1556
                    if ($tPag = $this->getTagValue($pag->item(0), "tPag")) {
1557
                        return $this->tipoPag($tPag);
1558
                    }
1559
                }
1560
            }
1561
        }
1562
        return "";
1563
    }
1564
1565
     /**
1566
     * sizeExtraTextoFatura
1567
     * Calcula o espaço ocupado pelo texto da fatura. Este espaço só é utilizado quando não houver duplicata.
1568
      *
1569
     * @name   sizeExtraTextoFatura
1570
     * @return integer
1571
     */
1572
    protected function sizeExtraTextoFatura()
1573
    {
1574
        $textoFatura = $this->getTextoFatura();
1575
        //verificar se existem duplicatas
1576
        if ($this->dup->length == 0 && $textoFatura !== "") {
1577
            return 10;
1578
        }
1579
        return 0;
1580
    }
1581
1582
    /**
1583
     * fatura
1584
     * Monta o campo de duplicatas da DANFE (retrato e paisagem)
1585
     *
1586
     * @name   fatura
1587
     * @param  number $x Posição horizontal canto esquerdo
1588
     * @param  number $y Posição vertical canto superior
1589
     * @return number Posição vertical final
1590
     */
1591
    protected function fatura($x, $y)
1592
    {
1593
        $linha = 1;
1594
        $h = 8+3;
0 ignored issues
show
Unused Code introduced by
$h 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...
1595
        $oldx = $x;
1596
        $textoFatura = $this->getTextoFatura();
1597
        //verificar se existem duplicatas
1598
        if ($this->dup->length > 0 || $textoFatura !== "") {
1599
            //#####################################################################
1600
            //FATURA / DUPLICATA
1601
            $texto = "FATURA / DUPLICATA";
1602
            if ($this->orientacao == 'P') {
1603
                $w = $this->wPrint;
1604
            } else {
1605
                $w = 271;
1606
            }
1607
            $h = 8;
1608
            $aFont = ['font'=>$this->fontePadrao, 'size'=>7, 'style'=>'B'];
1609
            $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 0, '');
1610
            $y += 3;
1611
            $dups = "";
0 ignored issues
show
Unused Code introduced by
$dups 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...
1612
            $dupcont = 0;
1613
            $nFat = $this->dup->length;
1614
            if ($nFat > 7) {
1615
                $myH = 6;
1616
                $myW = $this->wPrint;
1617
                if ($this->orientacao == 'L') {
1618
                    $myW -= $this->wCanhoto;
1619
                }
1620
                $aFont = ['font' => $this->fontePadrao, 'size' => 9, 'style' => ''];
1621
                $texto = "Existem mais de 7 duplicatas registradas, portanto não "
1622
                    . "serão exibidas, confira diretamente pelo XML.";
1623
                $this->pdf->textBox($x, $y, $myW, $myH, $texto, $aFont, 'C', 'C', 1, '');
1624
                return ($y + $h - 3);
1625
            }
1626
            if ($textoFatura !== "" && $this->exibirTextoFatura) {
1627
                $myH=6;
1628
                $myW = $this->wPrint;
1629
                if ($this->orientacao == 'L') {
1630
                    $myW -= $this->wCanhoto;
1631
                }
1632
                $aFont = ['font'=>$this->fontePadrao, 'size'=>8, 'style'=>''];
1633
                $this->pdf->textBox($x, $y, $myW, $myH, $textoFatura, $aFont, 'C', 'L', 1, '');
1634
                $y+=$myH+1;
1635
            }
1636
            if ($this->orientacao == 'P') {
1637
                $w = round($this->wPrint/7.018, 0)-1;
1638
            } else {
1639
                $w = 28;
1640
            }
1641
            $increm = 1;
1642
            foreach ($this->dup as $k => $d) {
1643
                $nDup = ! empty($this->dup->item($k)->getElementsByTagName('nDup')->item(0)->nodeValue) ?
1644
                        $this->dup->item($k)->getElementsByTagName('nDup')->item(0)->nodeValue : '';
1645
                $dDup = ! empty($this->dup->item($k)->getElementsByTagName('dVenc')->item(0)->nodeValue) ?
1646
                        $this->ymdTodmy($this->dup->item($k)->getElementsByTagName('dVenc')->item(0)->nodeValue) : '';
1647
                $vDup = ! empty($this->dup->item($k)->getElementsByTagName('vDup')->item(0)->nodeValue) ?
1648
                        'R$ ' . number_format(
1649
                            $this->dup->item($k)->getElementsByTagName('vDup')->item(0)->nodeValue,
1650
                            2,
1651
                            ",",
1652
                            "."
1653
                        ) : '';
1654
                $h = 8;
1655
                $texto = '';
0 ignored issues
show
Unused Code introduced by
$texto 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...
1656
                if ($nDup!='0' && $nDup!='') {
1657
                    $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
1658
                    $this->pdf->textBox($x, $y, $w, $h, 'Num.', $aFont, 'T', 'L', 1, '');
1659
                    $aFont = ['font'=>$this->fontePadrao, 'size'=>7, 'style'=>'B'];
1660
                    $this->pdf->textBox($x, $y, $w, $h, $nDup, $aFont, 'T', 'R', 0, '');
1661
                } else {
1662
                    $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
1663
                    $this->pdf->textBox($x, $y, $w, $h, ($dupcont+1)."", $aFont, 'T', 'L', 1, '');
1664
                }
1665
                $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
1666
                $this->pdf->textBox($x, $y, $w, $h, 'Venc.', $aFont, 'C', 'L', 0, '');
1667
                $aFont = ['font'=>$this->fontePadrao, 'size'=>7, 'style'=>'B'];
1668
                $this->pdf->textBox($x, $y, $w, $h, $dDup, $aFont, 'C', 'R', 0, '');
1669
                $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
1670
                $this->pdf->textBox($x, $y, $w, $h, 'Valor', $aFont, 'B', 'L', 0, '');
1671
                $aFont = ['font'=>$this->fontePadrao, 'size'=>7, 'style'=>'B'];
1672
                $this->pdf->textBox($x, $y, $w, $h, $vDup, $aFont, 'B', 'R', 0, '');
1673
                $x += $w+$increm;
1674
                $dupcont += 1;
1675
                if ($this->orientacao == 'P') {
1676
                    $maxDupCont = 6;
1677
                } else {
1678
                    $maxDupCont = 8;
1679
                }
1680
                if ($dupcont > $maxDupCont) {
1681
                    $y += 9;
1682
                    $x = $oldx;
1683
                    $dupcont = 0;
1684
                    $linha += 1;
1685
                }
1686
                if ($linha == 5) {
1687
                    $linha = 4;
1688
                    break;
1689
                }
1690
            }
1691
            if ($dupcont == 0) {
1692
                $y -= 9;
1693
                $linha--;
1694
            }
1695
            return ($y+$h);
1696
        } else {
1697
            $linha = 0;
0 ignored issues
show
Unused Code introduced by
$linha 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...
1698
            return ($y-2);
1699
        }
1700
    }
1701
1702
    /**
1703
     * pagamento
1704
     * Monta o campo de pagamentos da DANFE (retrato e paisagem) (foi baseada na fatura)
1705
     *
1706
     * @name   pagamento
1707
     * @param  number $x Posição horizontal canto esquerdo
1708
     * @param  number $y Posição vertical canto superior
1709
     * @return number Posição vertical final
1710
     */
1711
    protected function pagamento($x, $y)
1712
    {
1713
        $linha = 1;
1714
        $h = 8+3;
0 ignored issues
show
Unused Code introduced by
$h 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...
1715
        $oldx = $x;
1716
        //verificar se existem cobranças definidas
1717
        if (isset($this->detPag) && $this->detPag->length > 0) {
1718
            //#####################################################################
1719
            //Tipo de pagamento
1720
            $texto = "PAGAMENTO";
1721
            if ($this->orientacao == 'P') {
1722
                $w = $this->wPrint;
1723
            } else {
1724
                $w = 271;
1725
            }
1726
            $h = 8;
1727
            $aFont = ['font'=>$this->fontePadrao, 'size'=>7, 'style'=>'B'];
1728
            $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 0, '');
1729
            $y += 3;
1730
            $dups = "";
0 ignored issues
show
Unused Code introduced by
$dups 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...
1731
            $dupcont = 0;
1732
            if ($this->orientacao == 'P') {
1733
                $w = round($this->wPrint/7.018, 0)-1;
1734
            } else {
1735
                $w = 28;
1736
            }
1737
            if ($this->orientacao == 'P') {
1738
                $maxDupCont = 6;
1739
            } else {
1740
                $maxDupCont = 8;
1741
            }
1742
            $increm = 1;
1743
            $formaPagamento = ['01'=>'Dinheiro','02'=>'Cheque','03'=>'Cartão de Crédito',
1744
                                    '04'=>'Cartão de Débito','05'=>'Crédito Loja','10'=>'Vale Alimentação',
1745
                                    '11'=>'Vale Refeição','12'=>'Vale Presente','13'=>'Vale Combustível',
1746
                                    '14'=>'Duplicata Mercantil','15'=>'Boleto','90'=>'Sem pagamento','99'=>'Outros'];
1747
            $bandeira = ['01'=>'Visa','02'=>'Mastercard','03'=>'American','04'=>'Sorocred','05'=>'Diners',
0 ignored issues
show
Unused Code introduced by
$bandeira 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...
1748
                              '06'=>'Elo','07'=>'Hipercard','08'=>'Aura','09'=>'Cabal','99'=>'Outros'];
1749
            foreach ($this->detPag as $k => $d) {
1750
                $fPag = !empty($this->detPag->item($k)->getElementsByTagName('tPag')->item(0)->nodeValue)
1751
                    ? $this->detPag->item($k)->getElementsByTagName('tPag')->item(0)->nodeValue : '0';
1752
                $vPag = ! empty($this->detPag->item($k)->getElementsByTagName('vPag')->item(0)->nodeValue)
1753
                    ? 'R$ ' . number_format(
1754
                        $this->detPag->item($k)->getElementsByTagName('vPag')->item(0)->nodeValue,
1755
                        2,
1756
                        ",",
1757
                        "."
1758
                    ) : '';
1759
                $h = 6;
1760
                $texto = '';
0 ignored issues
show
Unused Code introduced by
$texto 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...
1761
                if (isset($formaPagamento[$fPag])) {
1762
                    /*Exibir Item sem pagamento ou outros?*/
1763
                    if ($fPag=='90' || $fPag=='99') {
1764
                        continue;
1765
                    }
1766
                    $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
1767
                    $this->pdf->textBox($x, $y, $w, $h, 'Forma', $aFont, 'T', 'L', 1, '');
1768
                    $aFont = ['font'=>$this->fontePadrao, 'size'=>7, 'style'=>'B'];
1769
                    $this->pdf->textBox($x, $y, $w, $h, $formaPagamento[$fPag], $aFont, 'T', 'R', 0, '');
1770
                } else {
1771
                    $aFont = ['font'=>$this->fontePadrao, 'size'=>7, 'style'=>''];
1772
                    $this->pdf->textBox($x, $y, $w, $h, "Forma ".$fPag." não encontrado", $aFont, 'T', 'L', 1, '');
1773
                }
1774
                $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
1775
                $this->pdf->textBox($x, $y, $w, $h, 'Valor', $aFont, 'B', 'L', 0, '');
1776
                $aFont = ['font'=>$this->fontePadrao, 'size'=>7, 'style'=>'B'];
1777
                $this->pdf->textBox($x, $y, $w, $h, $vPag, $aFont, 'B', 'R', 0, '');
1778
                $x += $w+$increm;
1779
                $dupcont += 1;
1780
1781
                if ($dupcont>$maxDupCont) {
1782
                    $y += 9;
1783
                    $x = $oldx;
1784
                    $dupcont = 0;
1785
                    $linha += 1;
1786
                }
1787
                if ($linha == 5) {
1788
                    $linha = 4;
1789
                    break;
1790
                }
1791
            }
1792
            if ($dupcont == 0) {
1793
                $y -= 9;
1794
                $linha--;
1795
            }
1796
            return ($y+$h);
1797
        } else {
1798
            $linha = 0;
0 ignored issues
show
Unused Code introduced by
$linha 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...
1799
            return ($y-2);
1800
        }
1801
    } //fim da função pagamento
1802
    
1803
    /**
1804
     * impostoHelper
1805
     * Auxilia a montagem dos campos de impostos e totais da DANFE
1806
     *
1807
     * @name   impostoHelper
1808
     * @param  float $x Posição horizontal canto esquerdo
1809
     * @param  float $y Posição vertical canto superior
1810
     * @param  float $w Largura do campo
1811
     * @param  float $h Altura do campo
1812
     * @param  float $h Título do campo
1813
     * @param  float $h Valor do imposto
1814
     * @return float Sugestão do $x do próximo imposto
1815
     */
1816
    protected function impostoHelper($x, $y, $w, $h, $titulo, $campoImposto)
1817
    {
1818
        $valorImposto = '0, 00';
1819
        $the_field = $this->ICMSTot->getElementsByTagName($campoImposto)->item(0);
1820
        if (isset($the_field)) {
1821
            $the_value = $the_field->nodeValue;
1822
            if (!empty($the_value)) {
1823
                $valorImposto = number_format($the_value, 2, ",", ".");
1824
            }
1825
        }
1826
1827
        $fontTitulo = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
1828
        $fontValor = ['font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B'];
1829
        $this->pdf->textBox($x, $y, $w, $h, $titulo, $fontTitulo, 'T', 'L', 1, '');
1830
        $this->pdf->textBox($x, $y, $w, $h, $valorImposto, $fontValor, 'B', 'R', 0, '');
1831
1832
        $next_x = $x + $w;
1833
        return $next_x;
1834
    }
1835
1836
    /**
1837
     * imposto
1838
     * Monta o campo de impostos e totais da DANFE (retrato e paisagem)
1839
     *
1840
     * @param  number $x Posição horizontal canto esquerdo
1841
     * @param  number $y Posição vertical canto superior
1842
     * @return number Posição vertical final
1843
     */
1844
    protected function imposto($x, $y)
1845
    {
1846
        $x_inicial = $x;
1847
        //#####################################################################
1848
1849
1850
        $campos_por_linha = 9;
1851
        if (!$this->exibirPIS) {
1852
            $campos_por_linha--;
1853
        }
1854
        if (!$this->exibirIcmsInterestadual) {
1855
            $campos_por_linha -= 2;
1856
        }
1857
1858
        if ($this->orientacao == 'P') {
1859
            $maxW = $this->wPrint;
1860
            $title_size = 31;
1861
        } else {
1862
            $maxW = $this->wPrint - $this->wCanhoto;
1863
            $title_size = 40;
1864
        }
1865
        $w = $maxW / $campos_por_linha;
1866
1867
        $aFont = ['font'=>$this->fontePadrao, 'size'=>7, 'style'=>'B'];
1868
        $texto = "CÁLCULO DO IMPOSTO";
1869
        $this->pdf->textBox($x, $y, $title_size, 8, $texto, $aFont, 'T', 'L', 0, '');
1870
        $y += 3;
1871
        $h = 7;
1872
1873
        $x = $this->impostoHelper($x, $y, $w, $h, "BASE DE CÁLC. DO ICMS", "vBC");
1874
        $x = $this->impostoHelper($x, $y, $w, $h, "VALOR DO ICMS", "vICMS");
1875
        $x = $this->impostoHelper($x, $y, $w, $h, "BASE DE CÁLC. ICMS S.T.", "vBCST");
1876
        $x = $this->impostoHelper($x, $y, $w, $h, "VALOR DO ICMS SUBST.", "vST");
1877
        $x = $this->impostoHelper($x, $y, $w, $h, "V. IMP. IMPORTAÇÃO", "vII");
1878
1879
        if ($this->exibirIcmsInterestadual) {
1880
            $x = $this->impostoHelper($x, $y, $w, $h, "V. ICMS UF REMET.", "vICMSUFRemet");
1881
            $x = $this->impostoHelper($x, $y, $w, $h, "V. FCP UF DEST.", "vFCPUFDest");
1882
        }
1883
1884
        if ($this->exibirPIS) {
1885
            $x = $this->impostoHelper($x, $y, $w, $h, "VALOR DO PIS", "vPIS");
1886
        }
1887
1888
        $x = $this->impostoHelper($x, $y, $w, $h, "V. TOTAL PRODUTOS", "vProd");
0 ignored issues
show
Unused Code introduced by
$x 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...
1889
1890
        //
1891
1892
        $y += $h;
1893
        $x = $x_inicial;
1894
1895
        $x = $this->impostoHelper($x, $y, $w, $h, "VALOR DO FRETE", "vFrete");
1896
        $x = $this->impostoHelper($x, $y, $w, $h, "VALOR DO SEGURO", "vSeg");
1897
        $x = $this->impostoHelper($x, $y, $w, $h, "DESCONTO", "vDesc");
1898
        $x = $this->impostoHelper($x, $y, $w, $h, "OUTRAS DESPESAS", "vOutro");
1899
        $x = $this->impostoHelper($x, $y, $w, $h, "VALOR TOTAL IPI", "vIPI");
1900
1901
        if ($this->exibirIcmsInterestadual) {
1902
            $x = $this->impostoHelper($x, $y, $w, $h, "V. ICMS UF DEST.", "vICMSUFDest");
1903
            $x = $this->impostoHelper($x, $y, $w, $h, "V. TOT. TRIB.", "vTotTrib");
1904
        }
1905
1906
        if ($this->exibirPIS) {
1907
            $x = $this->impostoHelper($x, $y, $w, $h, "VALOR DA COFINS", "vCOFINS");
1908
        }
1909
        $x = $this->impostoHelper($x, $y, $w, $h, "V. TOTAL DA NOTA", "vNF");
0 ignored issues
show
Unused Code introduced by
$x 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...
1910
1911
        return ($y+$h);
1912
    } //fim imposto
1913
1914
    /**
1915
     * transporte
1916
     * Monta o campo de transportes da DANFE (retrato e paisagem)
1917
     *
1918
     * @name   transporte
1919
     * @param  float $x Posição horizontal canto esquerdo
1920
     * @param  float $y Posição vertical canto superior
1921
     * @return float Posição vertical final
1922
     */
1923
    protected function transporte($x, $y)
1924
    {
1925
        $oldX = $x;
1926
        if ($this->orientacao == 'P') {
1927
            $maxW = $this->wPrint;
1928
        } else {
1929
            $maxW = $this->wPrint - $this->wCanhoto;
1930
        }
1931
        //#####################################################################
1932
        //TRANSPORTADOR / VOLUMES TRANSPORTADOS
1933
        $texto = "TRANSPORTADOR / VOLUMES TRANSPORTADOS";
1934
        $w = $maxW;
1935
        $h = 7;
1936
        $aFont = ['font'=>$this->fontePadrao, 'size'=>7, 'style'=>'B'];
1937
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 0, '');
1938
        //NOME / RAZÃO SOCIAL
1939
        $w1 = $maxW*0.29;
1940
        $y += 3;
1941
        $texto = 'NOME / RAZÃO SOCIAL';
1942
        $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
1943
        $this->pdf->textBox($x, $y, $w1, $h, $texto, $aFont, 'T', 'L', 1, '');
1944
        if (isset($this->transporta)) {
1945
            $texto = ! empty($this->transporta->getElementsByTagName("xNome")->item(0)->nodeValue) ?
1946
                    $this->transporta->getElementsByTagName("xNome")->item(0)->nodeValue : '';
1947
        } else {
1948
            $texto = '';
1949
        }
1950
        $aFont = ['font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B'];
1951
        $this->pdf->textBox($x, $y, $w1, $h, $texto, $aFont, 'B', 'L', 0, '');
1952
        //FRETE POR CONTA
1953
        $x += $w1;
1954
        $w2 = $maxW*0.15;
1955
        $texto = 'FRETE';
1956
        $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
1957
        $this->pdf->textBox($x, $y, $w2, $h, $texto, $aFont, 'T', 'L', 1, '');
1958
        $tipoFrete = ! empty($this->transp->getElementsByTagName("modFrete")->item(0)->nodeValue) ?
1959
                $this->transp->getElementsByTagName("modFrete")->item(0)->nodeValue : '0';
1960
        switch ($tipoFrete) {
1961
            case 0:
1962
                $texto = "0-Por conta do Rem";
1963
                break;
1964
            case 1:
1965
                $texto = "1-Por conta do Dest";
1966
                break;
1967
            case 2:
1968
                $texto = "2-Por conta de Terceiros";
1969
                break;
1970
            case 3:
1971
                $texto = "3-Próprio por conta do Rem";
1972
                break;
1973
            case 4:
1974
                $texto = "4-Próprio por conta do Dest";
1975
                break;
1976
            case 9:
1977
                $texto = "9-Sem Transporte";
1978
                break;
1979
        }
1980
        $aFont = ['font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B'];
1981
        $this->pdf->textBox($x, $y, $w2, $h, $texto, $aFont, 'C', 'C', 1, '');
1982
        //CÓDIGO ANTT
1983
        $x += $w2;
1984
        $texto = 'CÓDIGO ANTT';
1985
        $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
1986
        $this->pdf->textBox($x, $y, $w2, $h, $texto, $aFont, 'T', 'L', 1, '');
1987
        if (isset($this->veicTransp)) {
1988
            $texto = ! empty($this->veicTransp->getElementsByTagName("RNTC")->item(0)->nodeValue) ?
1989
                    $this->veicTransp->getElementsByTagName("RNTC")->item(0)->nodeValue : '';
1990
        } else {
1991
            $texto = '';
1992
        }
1993
        $aFont = ['font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B'];
1994
        $this->pdf->textBox($x, $y, $w2, $h, $texto, $aFont, 'B', 'C', 0, '');
1995
        //PLACA DO VEÍC
1996
        $x += $w2;
1997
        $texto = 'PLACA DO VEÍCULO';
1998
        $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
1999
        $this->pdf->textBox($x, $y, $w2, $h, $texto, $aFont, 'T', 'L', 1, '');
2000
        if (isset($this->veicTransp)) {
2001
            $texto = ! empty($this->veicTransp->getElementsByTagName("placa")->item(0)->nodeValue) ?
2002
                    $this->veicTransp->getElementsByTagName("placa")->item(0)->nodeValue : '';
2003
        } elseif (isset($this->reboque)) {
2004
            $texto = ! empty($this->reboque->getElementsByTagName("placa")->item(0)->nodeValue) ?
2005
                    $this->reboque->getElementsByTagName("placa")->item(0)->nodeValue : '';
2006
        } else {
2007
            $texto = '';
2008
        }
2009
        $aFont = ['font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B'];
2010
        $this->pdf->textBox($x, $y, $w2, $h, $texto, $aFont, 'B', 'C', 0, '');
2011
        //UF
2012
        $x += $w2;
2013
        $w3 = round($maxW*0.04, 0);
2014
        $texto = 'UF';
2015
        $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
2016
        $this->pdf->textBox($x, $y, $w3, $h, $texto, $aFont, 'T', 'L', 1, '');
2017
        if (isset($this->veicTransp)) {
2018
            $texto = ! empty($this->veicTransp->getElementsByTagName("UF")->item(0)->nodeValue) ?
2019
                    $this->veicTransp->getElementsByTagName("UF")->item(0)->nodeValue : '';
2020
        } elseif (isset($this->reboque)) {
2021
            $texto = ! empty($this->reboque->getElementsByTagName("UF")->item(0)->nodeValue) ?
2022
                    $this->reboque->getElementsByTagName("UF")->item(0)->nodeValue : '';
2023
        } else {
2024
            $texto = '';
2025
        }
2026
        $aFont = ['font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B'];
2027
        $this->pdf->textBox($x, $y, $w3, $h, $texto, $aFont, 'B', 'C', 0, '');
2028
        //CNPJ / CPF
2029
        $x += $w3;
2030
        $w = $maxW-($w1+3*$w2+$w3);
2031
        $texto = 'CNPJ / CPF';
2032
        $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
2033
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 1, '');
2034
        if (isset($this->transporta)) {
2035
            $texto = ! empty($this->transporta->getElementsByTagName("CNPJ")->item(0)->nodeValue) ?
2036
                    $this->formatField(
2037
                        $this->transporta->getElementsByTagName("CNPJ")->item(0)->nodeValue,
2038
                        "##.###.###/####-##"
2039
                    ) : '';
2040
            if ($texto == '') {
2041
                $texto = ! empty($this->transporta->getElementsByTagName("CPF")->item(0)->nodeValue) ?
2042
                        $this->formatField(
2043
                            $this->transporta->getElementsByTagName("CPF")->item(0)->nodeValue,
2044
                            "###.###.###-##"
2045
                        ) : '';
2046
            }
2047
        } else {
2048
            $texto = '';
2049
        }
2050
        $aFont = ['font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B'];
2051
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'B', 'C', 0, '');
2052
        //#####################################################################
2053
        //ENDEREÇO
2054
        $y += $h;
2055
        $x = $oldX;
2056
        $h = 7;
2057
        $w1 = $maxW*0.44;
2058
        $texto = 'ENDEREÇO';
2059
        $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
2060
        $this->pdf->textBox($x, $y, $w1, $h, $texto, $aFont, 'T', 'L', 1, '');
2061
        if (isset($this->transporta)) {
2062
            $texto = ! empty($this->transporta->getElementsByTagName("xEnder")->item(0)->nodeValue) ?
2063
                    $this->transporta->getElementsByTagName("xEnder")->item(0)->nodeValue : '';
2064
        } else {
2065
            $texto = '';
2066
        }
2067
        $aFont = ['font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B'];
2068
        $this->pdf->textBox($x, $y, $w1, $h, $texto, $aFont, 'B', 'L', 0, '');
2069
        //MUNICÍPIO
2070
        $x += $w1;
2071
        $w2 = round($maxW*0.30, 0);
2072
        $texto = 'MUNICÍPIO';
2073
        $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
2074
        $this->pdf->textBox($x, $y, $w2, $h, $texto, $aFont, 'T', 'L', 1, '');
2075
        if (isset($this->transporta)) {
2076
            $texto = ! empty($this->transporta->getElementsByTagName("xMun")->item(0)->nodeValue) ?
2077
                    $this->transporta->getElementsByTagName("xMun")->item(0)->nodeValue : '';
2078
        } else {
2079
            $texto = '';
2080
        }
2081
        $aFont = ['font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B'];
2082
        $this->pdf->textBox($x, $y, $w2, $h, $texto, $aFont, 'B', 'C', 0, '');
2083
        //UF
2084
        $x += $w2;
2085
        $w3 = round($maxW*0.04, 0);
2086
        $texto = 'UF';
2087
        $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
2088
        $this->pdf->textBox($x, $y, $w3, $h, $texto, $aFont, 'T', 'L', 1, '');
2089
        if (isset($this->transporta)) {
2090
            $texto = ! empty($this->transporta->getElementsByTagName("UF")->item(0)->nodeValue) ?
2091
                    $this->transporta->getElementsByTagName("UF")->item(0)->nodeValue : '';
2092
        } else {
2093
            $texto = '';
2094
        }
2095
        $aFont = ['font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B'];
2096
        $this->pdf->textBox($x, $y, $w3, $h, $texto, $aFont, 'B', 'C', 0, '');
2097
        //INSCRIÇÃO ESTADUAL
2098
        $x += $w3;
2099
        $w = $maxW-($w1+$w2+$w3);
2100
        $texto = 'INSCRIÇÃO ESTADUAL';
2101
        $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
2102
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 1, '');
2103
        $texto = '';
2104
        if (isset($this->transporta)) {
2105
            if (! empty($this->transporta->getElementsByTagName("IE")->item(0)->nodeValue)) {
2106
                $texto = $this->transporta->getElementsByTagName("IE")->item(0)->nodeValue;
2107
            }
2108
        }
2109
        $aFont = ['font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B'];
2110
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'B', 'C', 0, '');
2111
        //Tratar Multiplos volumes
2112
        $volumes = $this->transp->getElementsByTagName('vol');
2113
        $quantidade = 0;
2114
        $especie = '';
2115
        $marca = '';
2116
        $numero = '';
2117
        $texto = '';
0 ignored issues
show
Unused Code introduced by
$texto 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...
2118
        $pesoBruto=0;
2119
        $pesoLiquido=0;
2120
        foreach ($volumes as $volume) {
2121
            $quantidade += ! empty($volume->getElementsByTagName("qVol")->item(0)->nodeValue) ?
2122
                    $volume->getElementsByTagName("qVol")->item(0)->nodeValue : 0;
2123
            $pesoBruto += ! empty($volume->getElementsByTagName("pesoB")->item(0)->nodeValue) ?
2124
                    $volume->getElementsByTagName("pesoB")->item(0)->nodeValue : 0;
2125
            $pesoLiquido += ! empty($volume->getElementsByTagName("pesoL")->item(0)->nodeValue) ?
2126
                    $volume->getElementsByTagName("pesoL")->item(0)->nodeValue : 0;
2127
            $texto = ! empty($this->transp->getElementsByTagName("esp")->item(0)->nodeValue) ?
2128
                    $this->transp->getElementsByTagName("esp")->item(0)->nodeValue : '';
2129
            if ($texto != $especie && $especie != '') {
2130
                //tem várias especies
2131
                $especie = 'VARIAS';
2132
            } else {
2133
                $especie = $texto;
2134
            }
2135
            $texto = ! empty($this->transp->getElementsByTagName("marca")->item(0)->nodeValue) ?
2136
                    $this->transp->getElementsByTagName("marca")->item(0)->nodeValue : '';
2137
            if ($texto != $marca && $marca != '') {
2138
                //tem várias especies
2139
                $marca = 'VARIAS';
2140
            } else {
2141
                $marca = $texto;
2142
            }
2143
            $texto = ! empty($this->transp->getElementsByTagName("nVol")->item(0)->nodeValue) ?
2144
                    $this->transp->getElementsByTagName("nVol")->item(0)->nodeValue : '';
2145
            if ($texto != $numero && $numero != '') {
2146
                //tem várias especies
2147
                $numero = 'VARIOS';
2148
            } else {
2149
                $numero = $texto;
2150
            }
2151
        }
2152
2153
        //#####################################################################
2154
        //QUANTIDADE
2155
        $y += $h;
2156
        $x = $oldX;
2157
        $h = 7;
2158
        $w1 = round($maxW*0.10, 0);
2159
        $texto = 'QUANTIDADE';
2160
        $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
2161
        $this->pdf->textBox($x, $y, $w1, $h, $texto, $aFont, 'T', 'L', 1, '');
2162
        if (!empty($quantidade)) {
2163
            $texto = $quantidade;
2164
            $aFont = ['font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B'];
2165
            $this->pdf->textBox($x, $y, $w1, $h, $texto, $aFont, 'B', 'C', 0, '');
2166
        }
2167
        //ESPÉCIE
2168
        $x += $w1;
2169
        $w2 = round($maxW*0.17, 0);
2170
        $texto = 'ESPÉCIE';
2171
        $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
2172
        $this->pdf->textBox($x, $y, $w2, $h, $texto, $aFont, 'T', 'L', 1, '');
2173
        $texto = $especie;
2174
        $aFont = ['font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B'];
2175
        $this->pdf->textBox($x, $y, $w2, $h, $texto, $aFont, 'B', 'C', 0, '');
2176
        //MARCA
2177
        $x += $w2;
2178
        $texto = 'MARCA';
2179
        $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
2180
        $this->pdf->textBox($x, $y, $w2, $h, $texto, $aFont, 'T', 'L', 1, '');
2181
        $texto = ! empty($this->transp->getElementsByTagName("marca")->item(0)->nodeValue) ?
2182
                $this->transp->getElementsByTagName("marca")->item(0)->nodeValue : '';
2183
        $aFont = ['font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B'];
2184
        $this->pdf->textBox($x, $y, $w2, $h, $texto, $aFont, 'B', 'C', 0, '');
2185
        //NUMERAÇÃO
2186
        $x += $w2;
2187
        $texto = 'NUMERAÇÃO';
2188
        $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
2189
        $this->pdf->textBox($x, $y, $w2, $h, $texto, $aFont, 'T', 'L', 1, '');
2190
        $texto = $numero;
2191
        $aFont = ['font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B'];
2192
        $this->pdf->textBox($x, $y, $w2, $h, $texto, $aFont, 'B', 'C', 0, '');
2193
        //PESO BRUTO
2194
        $x += $w2;
2195
        $w3 = round($maxW*0.20, 0);
2196
        $texto = 'PESO BRUTO';
2197
        $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
2198
        $this->pdf->textBox($x, $y, $w3, $h, $texto, $aFont, 'T', 'L', 1, '');
2199
        if (is_numeric($pesoBruto) && $pesoBruto > 0) {
2200
            $texto = number_format($pesoBruto, 3, ",", ".");
2201
        } else {
2202
            $texto = '';
2203
        }
2204
        $aFont = ['font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B'];
2205
        $this->pdf->textBox($x, $y, $w3, $h, $texto, $aFont, 'B', 'R', 0, '');
2206
        //PESO LÍQUIDO
2207
        $x += $w3;
2208
        $w = $maxW -($w1+3*$w2+$w3);
2209
        $texto = 'PESO LÍQUIDO';
2210
        $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
2211
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 1, '');
2212
        if (is_numeric($pesoLiquido) && $pesoLiquido > 0) {
2213
            $texto = number_format($pesoLiquido, 3, ",", ".");
2214
        } else {
2215
            $texto = '';
2216
        }
2217
        $aFont = ['font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B'];
2218
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'B', 'R', 0, '');
2219
        return ($y+$h);
2220
    } //fim transporte
2221
2222
2223
2224
    protected function descricaoProdutoHelper($origem, $campo, $formato)
2225
    {
2226
        $valor_original = $origem->getElementsByTagName($campo)->item(0);
2227
        if (!isset($valor_original)) {
2228
            return "";
2229
        }
2230
        $valor_original = $valor_original->nodeValue;
2231
        $valor = ! empty($valor_original) ? number_format($valor_original, 2, ",", ".") : '';
2232
2233
        if ($valor != "") {
2234
            return sprintf($formato, $valor);
2235
        }
2236
        return "";
2237
    }
2238
2239
    /**
2240
     * descricaoProduto
2241
     * Monta a string de descrição de cada Produto
2242
     *
2243
     * @name   descricaoProduto
2244
     * @param  DOMNode itemProd
2245
     * @return string descricao do produto
2246
     */
2247
    protected function descricaoProduto($itemProd)
2248
    {
2249
        $prod = $itemProd->getElementsByTagName('prod')->item(0);
2250
        $ICMS = $itemProd->getElementsByTagName("ICMS")->item(0);
2251
        $ICMSUFDest = $itemProd->getElementsByTagName("ICMSUFDest")->item(0);
2252
        $impostos = '';
2253
2254
        if (!empty($ICMS)) {
2255
            $impostos .= $this->descricaoProdutoHelper($ICMS, "vBCFCP", " BcFcp=%s");
2256
            $impostos .= $this->descricaoProdutoHelper($ICMS, "pFCP", " pFcp=%s%%");
2257
            $impostos .= $this->descricaoProdutoHelper($ICMS, "vFCP", " vFcp=%s");
2258
            $impostos .= $this->descricaoProdutoHelper($ICMS, "pRedBC", " pRedBC=%s%%");
2259
            $impostos .= $this->descricaoProdutoHelper($ICMS, "pMVAST", " IVA/MVA=%s%%");
2260
            $impostos .= $this->descricaoProdutoHelper($ICMS, "pICMSST", " pIcmsSt=%s%%");
2261
            $impostos .= $this->descricaoProdutoHelper($ICMS, "vBCST", " BcIcmsSt=%s");
2262
            $impostos .= $this->descricaoProdutoHelper($ICMS, "vICMSST", " vIcmsSt=%s");
2263
            $impostos .= $this->descricaoProdutoHelper($ICMS, "vBCFCPST", " BcFcpSt=%s");
2264
            $impostos .= $this->descricaoProdutoHelper($ICMS, "pFCPST", " pFcpSt=%s%%");
2265
            $impostos .= $this->descricaoProdutoHelper($ICMS, "vFCPST", " vFcpSt=%s");
2266
            $impostos .= $this->descricaoProdutoHelper($ICMS, "vBCSTRet", " vBcStRet=%s");
2267
            $impostos .= $this->descricaoProdutoHelper($ICMS, "pST", " pSt=%s");
2268
            $impostos .= $this->descricaoProdutoHelper($ICMS, "vICMSSTRet", " vIcmsStRet=%s");
2269
        }
2270
        if (!empty($ICMSUFDest)) {
2271
            $impostos .= $this->descricaoProdutoHelper($ICMSUFDest, "pFCPUFDest", " pFCPUFDest=%s%%");
2272
            $impostos .= $this->descricaoProdutoHelper($ICMSUFDest, "pICMSUFDest", " pICMSUFDest=%s%%");
2273
            $impostos .= $this->descricaoProdutoHelper($ICMSUFDest, "pICMSInterPart", " pICMSInterPart=%s%%");
2274
            $impostos .= $this->descricaoProdutoHelper($ICMSUFDest, "vFCPUFDest", " vFCPUFDest=%s");
2275
            $impostos .= $this->descricaoProdutoHelper($ICMSUFDest, "vICMSUFDest", " vICMSUFDest=%s");
2276
            $impostos .= $this->descricaoProdutoHelper($ICMSUFDest, "vICMSUFRemet", " vICMSUFRemet=%s");
2277
        }
2278
        $infAdProd = ! empty($itemProd->getElementsByTagName('infAdProd')->item(0)->nodeValue)
2279
            ? substr(
2280
                $this->anfaveaDANFE($itemProd->getElementsByTagName('infAdProd')->item(0)->nodeValue),
2281
                0,
2282
                500
2283
            )
2284
            : '';
2285
        if (! empty($infAdProd)) {
2286
            $infAdProd = trim($infAdProd);
2287
            $infAdProd .= ' ';
2288
        }
2289
        $loteTxt ='';
2290
        $rastro = $prod->getElementsByTagName("med");
0 ignored issues
show
Unused Code introduced by
$rastro 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...
2291
        if (!empty($prod->getElementsByTagName("rastro"))) {
2292
            $rastro = $prod->getElementsByTagName("rastro");
2293
            $i = 0;
2294
            while ($i < $rastro->length) {
2295
                $loteTxt .= $this->getTagValue($rastro->item($i), 'nLote', ' Lote: ');
2296
                $loteTxt .= $this->getTagValue($rastro->item($i), 'qLote', ' Quant: ');
2297
                $loteTxt .= $this->getTagDate($rastro->item($i), 'dFab', ' Fab: ');
2298
                $loteTxt .= $this->getTagDate($rastro->item($i), 'dVal', ' Val: ');
2299
                $loteTxt .= $this->getTagValue($rastro->item($i), 'vPMC', ' PMC: ');
2300
                $i++;
2301
            }
2302
            if ($loteTxt != '') {
2303
                $loteTxt.= ' ';
2304
            }
2305
        }
2306
        //NT2013.006 FCI
2307
        $nFCI = (! empty($itemProd->getElementsByTagName('nFCI')->item(0)->nodeValue)) ?
2308
                ' FCI:'.$itemProd->getElementsByTagName('nFCI')->item(0)->nodeValue : '';
2309
        $tmp_ad=$infAdProd . ($this->descProdInfoComplemento ? $loteTxt . $impostos . $nFCI : '');
2310
        $texto = $prod->getElementsByTagName("xProd")->item(0)->nodeValue . (strlen($tmp_ad)!=0?"\n    ".$tmp_ad:'');
2311
        //decodifica os caracteres html no xml
2312
        $texto = html_entity_decode($texto);
2313
        if ($this->descProdQuebraLinha) {
2314
            $texto = str_replace(";", "\n", $texto);
2315
        }
2316
        return $texto;
2317
    }
2318
2319
    /**
2320
     * itens
2321
     * Monta o campo de itens da DANFE (retrato e paisagem)
2322
     *
2323
     * @name   itens
2324
     * @param  float $x       Posição horizontal canto esquerdo
2325
     * @param  float $y       Posição vertical canto superior
2326
     * @param  float $nInicio Número do item inicial
2327
     * @param  float $max     Número do item final
0 ignored issues
show
Bug introduced by
There is no parameter named $max. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
2328
     * @param  float $hmax    Altura máxima do campo de itens em mm
2329
     * @return float Posição vertical final
2330
     */
2331
    protected function itens($x, $y, &$nInicio, $hmax, $pag = 0, $totpag = 0, $hCabecItens = 7)
2332
    {
2333
        $oldX = $x;
2334
        $oldY = $y;
2335
        $totItens = $this->det->length;
2336
        //#####################################################################
2337
        //DADOS DOS PRODUTOS / SERVIÇOS
2338
        $texto = "DADOS DOS PRODUTOS / SERVIÇOS ";
2339
        if ($this->orientacao == 'P') {
2340
            $w = $this->wPrint;
2341
        } else {
2342
            if ($nInicio < 2) { // primeira página
2343
                $w = $this->wPrint - $this->wCanhoto;
2344
            } else { // páginas seguintes
2345
                $w = $this->wPrint;
2346
            }
2347
        }
2348
        $h = 4;
2349
        $aFont = ['font'=>$this->fontePadrao, 'size'=>7, 'style'=>'B'];
2350
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 0, '');
2351
        $y += 3;
2352
        //desenha a caixa dos dados dos itens da NF
2353
        $hmax += 1;
2354
        $texto = '';
0 ignored issues
show
Unused Code introduced by
$texto 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...
2355
        $this->pdf->textBox($x, $y, $w, $hmax);
2356
        //##################################################################################
2357
        // cabecalho LOOP COM OS DADOS DOS PRODUTOS
2358
        //CÓDIGO PRODUTO
2359
        $texto = "CÓDIGO PRODUTO";
2360
        $w1 = round($w*0.09, 0);
2361
        $h = 4;
2362
        $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
2363
        $this->pdf->textBox($x, $y, $w1, $h, $texto, $aFont, 'C', 'C', 0, '', false);
2364
        $this->pdf->line($x+$w1, $y, $x+$w1, $y+$hmax);
2365
        //DESCRIÇÃO DO PRODUTO / SERVIÇO
2366
        $x += $w1;
2367
        $w2 = round($w*0.28, 0);
2368
        $texto = 'DESCRIÇÃO DO PRODUTO / SERVIÇO';
2369
        $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
2370
        $this->pdf->textBox($x, $y, $w2, $h, $texto, $aFont, 'C', 'C', 0, '', false);
2371
        $this->pdf->line($x+$w2, $y, $x+$w2, $y+$hmax);
2372
        //NCM/SH
2373
        $x += $w2;
2374
        $w3 = round($w*0.06, 0);
2375
        $texto = 'NCM/SH';
2376
        $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
2377
        $this->pdf->textBox($x, $y, $w3, $h, $texto, $aFont, 'C', 'C', 0, '', false);
2378
        $this->pdf->line($x+$w3, $y, $x+$w3, $y+$hmax);
2379
        //O/CST ou O/CSOSN
2380
        $x += $w3;
2381
        $w4 = round($w*0.05, 0);
2382
        $texto = 'O/CSOSN';//Regime do Simples CRT = 1 ou CRT = 2
2383
        if ($this->getTagValue($this->emit, 'CRT') == '3') {
2384
             $texto = 'O/CST';//Regime Normal
2385
        }
2386
        $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
2387
        $this->pdf->textBox($x, $y, $w4, $h, $texto, $aFont, 'C', 'C', 0, '', false);
2388
        $this->pdf->line($x+$w4, $y, $x+$w4, $y+$hmax);
2389
        //CFOP
2390
        $x += $w4;
2391
        $w5 = round($w*0.04, 0);
2392
        $texto = 'CFOP';
2393
        $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
2394
        $this->pdf->textBox($x, $y, $w5, $h, $texto, $aFont, 'C', 'C', 0, '', false);
2395
        $this->pdf->line($x+$w5, $y, $x+$w5, $y+$hmax);
2396
        //UN
2397
        $x += $w5;
2398
        $w6 = round($w*0.03, 0);
2399
        $texto = 'UN';
2400
        $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
2401
        $this->pdf->textBox($x, $y, $w6, $h, $texto, $aFont, 'C', 'C', 0, '', false);
2402
        $this->pdf->line($x+$w6, $y, $x+$w6, $y+$hmax);
2403
        //QUANT
2404
        $x += $w6;
2405
        $w7 = round($w*0.07, 0);
2406
        $texto = 'QUANT';
2407
        $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
2408
        $this->pdf->textBox($x, $y, $w7, $h, $texto, $aFont, 'C', 'C', 0, '', false);
2409
        $this->pdf->line($x+$w7, $y, $x+$w7, $y+$hmax);
2410
        //VALOR UNIT
2411
        $x += $w7;
2412
        $w8 = round($w*0.06, 0);
2413
        $texto = 'VALOR UNIT';
2414
        $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
2415
        $this->pdf->textBox($x, $y, $w8, $h, $texto, $aFont, 'C', 'C', 0, '', false);
2416
        $this->pdf->line($x+$w8, $y, $x+$w8, $y+$hmax);
2417
        //VALOR TOTAL
2418
        $x += $w8;
2419
        $w9 = round($w*0.06, 0);
2420
        $texto = 'VALOR TOTAL';
2421
        $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
2422
        $this->pdf->textBox($x, $y, $w9, $h, $texto, $aFont, 'C', 'C', 0, '', false);
2423
        $this->pdf->line($x+$w9, $y, $x+$w9, $y+$hmax);
2424
        //B.CÁLC ICMS
2425
        $x += $w9;
2426
        $w10 = round($w*0.06, 0);
2427
        $texto = 'B.CÁLC ICMS';
2428
        $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
2429
        $this->pdf->textBox($x, $y, $w10, $h, $texto, $aFont, 'C', 'C', 0, '', false);
2430
        $this->pdf->line($x+$w10, $y, $x+$w10, $y+$hmax);
2431
        //VALOR ICMS
2432
        $x += $w10;
2433
        $w11 = round($w*0.06, 0);
2434
        $texto = 'VALOR ICMS';
2435
        $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
2436
        $this->pdf->textBox($x, $y, $w11, $h, $texto, $aFont, 'C', 'C', 0, '', false);
2437
        $this->pdf->line($x+$w11, $y, $x+$w11, $y+$hmax);
2438
        //VALOR IPI
2439
        $x += $w11;
2440
        $w12 = round($w*0.05, 0);
2441
        $texto = 'VALOR IPI';
2442
        $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
2443
        $this->pdf->textBox($x, $y, $w12, $h, $texto, $aFont, 'C', 'C', 0, '', false);
2444
        $this->pdf->line($x+$w12, $y, $x+$w12, $y+$hmax);
2445
        //ALÍQ. ICMS
2446
        $x += $w12;
2447
        $w13 = round($w*0.035, 0);
2448
        $texto = 'ALÍQ. ICMS';
2449
        $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
2450
        $this->pdf->textBox($x, $y, $w13, $h, $texto, $aFont, 'C', 'C', 0, '', false);
2451
        $this->pdf->line($x+$w13, $y, $x+$w13, $y+$hmax);
2452
        //ALÍQ. IPI
2453
        $x += $w13;
2454
        $w14 = $w-($w1+$w2+$w3+$w4+$w5+$w6+$w7+$w8+$w9+$w10+$w11+$w12+$w13);
2455
        $texto = 'ALÍQ. IPI';
2456
        $this->pdf->textBox($x, $y, $w14, $h, $texto, $aFont, 'C', 'C', 0, '', false);
2457
        $this->pdf->line($oldX, $y+$h+1, $oldX + $w, $y+$h+1);
2458
        $y += 5;
2459
        //##################################################################################
2460
        // LOOP COM OS DADOS DOS PRODUTOS
2461
        $i = 0;
2462
        $hUsado = $hCabecItens;
2463
        $aFont = ['font'=>$this->fontePadrao, 'size'=>7, 'style'=>''];
2464
        foreach ($this->det as $d) {
2465
            if ($i >= $nInicio) {
2466
                $thisItem = $this->det->item($i);
2467
                //carrega as tags do item
2468
                $prod = $thisItem->getElementsByTagName("prod")->item(0);
2469
                $imposto = $this->det->item($i)->getElementsByTagName("imposto")->item(0);
2470
                $ICMS = $imposto->getElementsByTagName("ICMS")->item(0);
2471
                $IPI  = $imposto->getElementsByTagName("IPI")->item(0);
2472
                $textoProduto = trim($this->descricaoProduto($thisItem));
2473
2474
                $linhaDescr = $this->pdf->getNumLines($textoProduto, $w2, $aFont);
2475
                $h = round(($linhaDescr * $this->pdf->fontSize)+ ($linhaDescr * 0.5), 2);
2476
                $hUsado += $h;
2477
2478
                $diffH = $hmax - $hUsado;
2479
2480
                if ($pag != $totpag) {
2481
                    if (1 > $diffH && $i < $totItens) {
2482
                        //ultrapassa a capacidade para uma única página
2483
                        //o restante dos dados serão usados nas proximas paginas
2484
                        $nInicio = $i;
2485
                        break;
2486
                    }
2487
                }
2488
                $y_linha=$y+$h;
2489
                // linha entre itens
2490
                $this->pdf->dashedHLine($oldX, $y_linha, $w, 0.1, 120);
2491
                //corrige o x
2492
                $x=$oldX;
2493
                //codigo do produto
2494
                $texto = $prod->getElementsByTagName("cProd")->item(0)->nodeValue;
2495
                $this->pdf->textBox($x, $y, $w1, $h, $texto, $aFont, 'T', 'C', 0, '');
2496
                $x += $w1;
2497
                //DESCRIÇÃO
2498
                if ($this->orientacao == 'P') {
2499
                    $this->pdf->textBox($x, $y, $w2, $h, $textoProduto, $aFont, 'T', 'L', 0, '', false);
2500
                } else {
2501
                    $this->pdf->textBox($x, $y, $w2, $h, $textoProduto, $aFont, 'T', 'L', 0, '', false);
2502
                }
2503
                $x += $w2;
2504
                //NCM
2505
                $texto = ! empty($prod->getElementsByTagName("NCM")->item(0)->nodeValue) ?
2506
                        $prod->getElementsByTagName("NCM")->item(0)->nodeValue : '';
2507
                $this->pdf->textBox($x, $y, $w3, $h, $texto, $aFont, 'T', 'C', 0, '');
2508
                $x += $w3;
2509
                //CST
2510
                if (isset($ICMS)) {
2511
                    $origem =  $this->getTagValue($ICMS, "orig");
2512
                    $cst =  $this->getTagValue($ICMS, "CST");
2513
                    $csosn =  $this->getTagValue($ICMS, "CSOSN");
2514
                    $texto = $origem.$cst.$csosn;
2515
                    $this->pdf->textBox($x, $y, $w4, $h, $texto, $aFont, 'T', 'C', 0, '');
2516
                }
2517
                //CFOP
2518
                $x += $w4;
2519
                $texto = $prod->getElementsByTagName("CFOP")->item(0)->nodeValue;
2520
                $this->pdf->textBox($x, $y, $w5, $h, $texto, $aFont, 'T', 'C', 0, '');
2521
                //Unidade
2522
                $x += $w5;
2523
                $texto = $prod->getElementsByTagName("uCom")->item(0)->nodeValue;
2524
                $this->pdf->textBox($x, $y, $w6, $h, $texto, $aFont, 'T', 'C', 0, '');
2525
                $x += $w6;
2526
                if ($this->orientacao == 'P') {
2527
                    $alinhamento = 'R';
2528
                } else {
2529
                    $alinhamento = 'R';
2530
                }
2531
                // QTDADE
2532
                $texto = number_format($prod->getElementsByTagName("qCom")->item(0)->nodeValue, 4, ",", ".");
2533
                $this->pdf->textBox($x, $y, $w7, $h, $texto, $aFont, 'T', $alinhamento, 0, '');
2534
                $x += $w7;
2535
                // Valor Unitário
2536
                $texto = number_format($prod->getElementsByTagName("vUnCom")->item(0)->nodeValue, 4, ",", ".");
2537
                $this->pdf->textBox($x, $y, $w8, $h, $texto, $aFont, 'T', $alinhamento, 0, '');
2538
                $x += $w8;
2539
                // Valor do Produto
2540
                $texto = "";
2541
                if (is_numeric($prod->getElementsByTagName("vProd")->item(0)->nodeValue)) {
2542
                    $texto = number_format($prod->getElementsByTagName("vProd")->item(0)->nodeValue, 2, ",", ".");
2543
                }
2544
                $this->pdf->textBox($x, $y, $w9, $h, $texto, $aFont, 'T', $alinhamento, 0, '');
2545
                //Valor da Base de calculo
2546
                $x += $w9;
2547
                if (isset($ICMS)) {
2548
                    $texto = ! empty($ICMS->getElementsByTagName("vBC")->item(0)->nodeValue) ?
2549
                            number_format(
2550
                                $ICMS->getElementsByTagName("vBC")->item(0)->nodeValue,
2551
                                2,
2552
                                ",",
2553
                                "."
2554
                            ) : '0, 00';
2555
                    $this->pdf->textBox($x, $y, $w10, $h, $texto, $aFont, 'T', $alinhamento, 0, '');
2556
                }
2557
                //Valor do ICMS
2558
                $x += $w10;
2559
                if (isset($ICMS)) {
2560
                    $texto = ! empty($ICMS->getElementsByTagName("vICMS")->item(0)->nodeValue) ?
2561
                            number_format(
2562
                                $ICMS->getElementsByTagName("vICMS")->item(0)->nodeValue,
2563
                                2,
2564
                                ",",
2565
                                "."
2566
                            ) : '0, 00';
2567
                    $this->pdf->textBox($x, $y, $w11, $h, $texto, $aFont, 'T', $alinhamento, 0, '');
2568
                }
2569
                //Valor do IPI
2570
                $x += $w11;
2571
                if (isset($IPI)) {
2572
                    $texto = ! empty($IPI->getElementsByTagName("vIPI")->item(0)->nodeValue) ?
2573
                            number_format($IPI->getElementsByTagName("vIPI")->item(0)->nodeValue, 2, ",", ".") :'';
2574
                } else {
2575
                    $texto = '';
2576
                }
2577
                $this->pdf->textBox($x, $y, $w12, $h, $texto, $aFont, 'T', $alinhamento, 0, '');
2578
                // %ICMS
2579
                $x += $w12;
2580
                if (isset($ICMS)) {
2581
                    $texto = ! empty($ICMS->getElementsByTagName("pICMS")->item(0)->nodeValue) ?
2582
                            number_format(
2583
                                $ICMS->getElementsByTagName("pICMS")->item(0)->nodeValue,
2584
                                2,
2585
                                ",",
2586
                                "."
2587
                            ) : '0, 00';
2588
                    $this->pdf->textBox($x, $y, $w13, $h, $texto, $aFont, 'T', 'C', 0, '');
2589
                }
2590
                //%IPI
2591
                $x += $w13;
2592
                if (isset($IPI)) {
2593
                    $texto = ! empty($IPI->getElementsByTagName("pIPI")->item(0)->nodeValue) ?
2594
                            number_format($IPI->getElementsByTagName("pIPI")->item(0)->nodeValue, 2, ",", ".") : '';
2595
                } else {
2596
                    $texto = '';
2597
                }
2598
                $this->pdf->textBox($x, $y, $w14, $h, $texto, $aFont, 'T', 'C', 0, '');
2599
2600
2601
                // Dados do Veiculo Somente para veiculo 0 Km
2602
                $veicProd = $prod->getElementsByTagName("veicProd")->item(0);
2603
                // Tag somente é gerada para veiculo 0k, e só é permitido um veiculo por NF-e por conta do detran
2604
                // Verifica se a Tag existe
2605
                if (!empty($veicProd)) {
2606
                    $this->dadosItenVeiculoDANFE($oldX, $y, $nInicio, $h, $prod);
2607
                }
2608
2609
2610
                $y += $h;
2611
                $i++;
2612
                //incrementa o controle dos itens processados.
2613
                $this->qtdeItensProc++;
2614
            } else {
2615
                $i++;
2616
            }
2617
        }
2618
        return $oldY+$hmax;
2619
    }
2620
2621
2622
    /**
2623
     * dadosItenVeiculoDANFE
2624
     * Coloca os dados do veiculo abaixo do item da NFe. (retrato e paisagem)
2625
     *
2626
     * @param float  $x    Posição horizontal
2627
     *                     canto esquerdo
2628
     * @param float  $y    Posição vertical
2629
     *                     canto superior
2630
     * @param        $nInicio
2631
     * @param float  $h    altura do campo
2632
     * @param object $prod Contendo todos os dados do item
2633
     */
2634
2635
    protected function dadosItenVeiculoDANFE($x, $y, &$nInicio, $h, $prod)
2636
    {
2637
        $oldX = $x;
2638
        $oldY = $y;
0 ignored issues
show
Unused Code introduced by
$oldY 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...
2639
2640
        if ($this->orientacao == 'P') {
2641
            $w = $this->wPrint;
2642
        } else {
2643
            if ($nInicio < 2) { // primeira página
2644
                $w = $this->wPrint - $this->wCanhoto;
2645
            } else { // páginas seguintes
2646
                $w = $this->wPrint;
2647
            }
2648
        }
2649
2650
        $aFont = ['font'=>$this->fontePadrao, 'size'=>7, 'style'=>''];
2651
2652
        $w1 = round($w*0.09, 0);
2653
2654
        // Tabela Renavam Combustivel
2655
        $renavamCombustivel = [
2656
            1=>'ALCOOL',
2657
            2=>'GASOLINA',
2658
            3=>'DIESEL',
2659
            4=>'GASOGENIO',
2660
            5=>'GAS METANO',
2661
            6=>'ELETRICO/FONTE INTERNA',
2662
            7=>'ELETRICO/FONTE EXTERNA',
2663
            8=>'GASOL/GAS NATURAL COMBUSTIVEL',
2664
            9=>'ALCOOL/GAS NATURAL COMBUSTIVEL',
2665
            10=>'DIESEL/GAS NATURAL COMBUSTIVEL',
2666
            11=>'VIDE/CAMPO/OBSERVACAO',
2667
            12=>'ALCOOL/GAS NATURAL VEICULAR',
2668
            13=>'GASOLINA/GAS NATURAL VEICULAR',
2669
            14=>'DIESEL/GAS NATURAL VEICULAR',
2670
            15=>'GAS NATURAL VEICULAR',
2671
            16=>'ALCOOL/GASOLINA',
2672
            17=>'GASOLINA/ALCOOL/GAS NATURAL',
2673
            18=>'GASOLINA/ELETRICO'
2674
        ];
2675
2676
        $renavamEspecie = [
2677
            1=>'PASSAGEIRO',
2678
            2=>'CARGA',
2679
            3=>'MISTO',
2680
            4=>'CORRIDA',
2681
            5=>'TRACAO',
2682
            6=>'ESPECIAL',
2683
            7=>'COLECAO'
2684
        ];
2685
2686
        $renavamTiposVeiculos = [
2687
            1=>'BICICLETA',
2688
            2=>'CICLOMOTOR',
2689
            3=>'MOTONETA',
2690
            4=>'MOTOCICLETA',
2691
            5=>'TRICICLO',
2692
            6=>'AUTOMOVEL',
2693
            7=>'MICROONIBUS',
2694
            8=>'ONIBUS',
2695
            9=>'BONDE',
2696
            10=>'REBOQUE',
2697
            11=>'SEMI-REBOQUE',
2698
            12=>'CHARRETE',
2699
            13=>'CAMIONETA',
2700
            14=>'CAMINHAO',
2701
            15=>'CARROCA',
2702
            16=>'CARRO DE MAO',
2703
            17=>'CAMINHAO TRATOR',
2704
            18=>'TRATOR DE RODAS',
2705
            19=>'TRATOR DE ESTEIRAS',
2706
            20=>'TRATOR MISTO',
2707
            21=>'QUADRICICLO',
2708
            22=>'CHASSI/PLATAFORMA',
2709
            23=>'CAMINHONETE',
2710
            24=>'SIDE-CAR',
2711
            25=>'UTILITARIO',
2712
            26=>'MOTOR-CASA'
2713
        ];
2714
2715
        $renavamTipoPintura = [
0 ignored issues
show
Unused Code introduced by
$renavamTipoPintura 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...
2716
            'F'=>'FOSCA',
2717
            'S'=>'SÓLIDA',
2718
            'P'=>'PEROLIZADA',
2719
            'M'=>'METALICA',
2720
        ];
2721
2722
        $veicProd = $prod->getElementsByTagName("veicProd")->item(0);
2723
2724
        $veiculoChassi = $veicProd->getElementsByTagName("chassi")->item(0)->nodeValue;
2725
        $veiculoCor = $veicProd->getElementsByTagName("xCor")->item(0)->nodeValue;
2726
        $veiculoCilindrada = $veicProd->getElementsByTagName("cilin")->item(0)->nodeValue;
2727
        $veiculoCmkg = $veicProd->getElementsByTagName("CMT")->item(0)->nodeValue;
2728
        $veiculoTipo = $veicProd->getElementsByTagName("tpVeic")->item(0)->nodeValue;
2729
2730
        $veiculoMotor = $veicProd->getElementsByTagName("nMotor")->item(0)->nodeValue;
2731
        $veiculoRenavam = $veicProd->getElementsByTagName("cMod")->item(0)->nodeValue;
2732
        $veiculoHp = $veicProd->getElementsByTagName("pot")->item(0)->nodeValue;
2733
        $veiculoPlaca = ''; //$veiculo->getElementsByTagName("CMT")->item(0)->nodeValue;
2734
        $veiculoTipoPintura = $veicProd->getElementsByTagName("tpPint")->item(0)->nodeValue;
2735
        $veiculoMarcaModelo = $prod->getElementsByTagName("xProd")->item(0)->nodeValue;
2736
        $veiculoEspecie = $veicProd->getElementsByTagName("espVeic")->item(0)->nodeValue;
2737
        $veiculoCombustivel = $veicProd->getElementsByTagName("tpComb")->item(0)->nodeValue;
2738
        $veiculoSerial = $veicProd->getElementsByTagName("nSerie")->item(0)->nodeValue;
2739
        $veiculoFabricacao = $veicProd->getElementsByTagName("anoFab")->item(0)->nodeValue;
2740
        $veiculoModelo = $veicProd->getElementsByTagName("anoMod")->item(0)->nodeValue;
2741
        $veiculoDistancia = $veicProd->getElementsByTagName("dist")->item(0)->nodeValue;
2742
2743
        $x = $oldX;
2744
2745
        $yVeic = $y + $h;
2746
        $texto = 'Chassi: ............: ' . $veiculoChassi;
2747
        $this->pdf->textBox($x, $yVeic, $w1+40, $h, $texto, $aFont, 'T', 'L', 0, '');
2748
        $yVeic += $h;
2749
        $texto = 'Cor...................: ' . $veiculoCor;
2750
        $this->pdf->textBox($x, $yVeic, $w1+40, $h, $texto, $aFont, 'T', 'L', 0, '');
2751
        $yVeic += $h;
2752
        $texto = 'Cilindrada........: ' . $veiculoCilindrada;
2753
        $this->pdf->textBox($x, $yVeic, $w1+40, $h, $texto, $aFont, 'T', 'L', 0, '');
2754
        $yVeic += $h;
2755
        $texto = 'Cmkg...............: ' . $veiculoCmkg;
2756
        $this->pdf->textBox($x, $yVeic, $w1+40, $h, $texto, $aFont, 'T', 'L', 0, '');
2757
        $yVeic += $h;
2758
        $texto = 'Tipo.................: ' . ($renavamTiposVeiculos[intval($veiculoTipo)] ?? $veiculoTipo);
2759
         $this->pdf->textBox($x, $yVeic, $w1+40, $h, $texto, $aFont, 'T', 'L', 0, '');
2760
        $yVeic = $y + $h;
2761
        $xVeic = $x + 65;
2762
        $texto = 'Nº Motor: .........: ' . $veiculoMotor;
2763
        $this->pdf->textBox($xVeic, $yVeic, $w1+50, $h, $texto, $aFont, 'T', 'L', 0, '');
2764
        $yVeic += $h;
2765
        $texto = 'Renavam...........: ' . $veiculoRenavam;
2766
        $this->pdf->textBox($xVeic, $yVeic, $w1+50, $h, $texto, $aFont, 'T', 'L', 0, '');
2767
        $yVeic += $h;
2768
        $texto = 'HP.....................: ' . $veiculoHp;
2769
        $this->pdf->textBox($xVeic, $yVeic, $w1+50, $h, $texto, $aFont, 'T', 'L', 0, '');
2770
        $yVeic += $h;
2771
        $texto = 'Placa.................: ' . $veiculoPlaca;
2772
        $this->pdf->textBox($xVeic, $yVeic, $w1+50, $h, $texto, $aFont, 'T', 'L', 0, '');
2773
        $yVeic += $h;
2774
        $texto = 'Tipo Pintura......: ' . ($renavamEspecie[intval($veiculoTipoPintura)] ?? $veiculoTipoPintura);
2775
        $this->pTextBox($xVeic, $yVeic, $w1+50, $h, $texto, $aFont, 'T', 'L', 0, '');
0 ignored issues
show
Bug introduced by
The method pTextBox() does not seem to exist on object<NFePHP\DA\NFe\Danfe>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
2776
        $yVeic = $y + $h;
2777
        $xVeic = $xVeic + 55;
2778
        $texto = 'Marca / Modelo.....: ' . $veiculoMarcaModelo;
2779
        $this->pdf->textBox($xVeic, $yVeic, $w1+50, $h, $texto, $aFont, 'T', 'L', 0, '');
2780
        $yVeic += $h;
2781
        $texto = 'Especie..................: ' . ($renavamEspecie[intval($veiculoEspecie)] ?? $veiculoEspecie);
2782
        $this->pdf->textBox($xVeic, $yVeic, $w1+50, $h, $texto, $aFont, 'T', 'L', 0, '');
2783
        $yVeic += $h;
2784
        $texto = 'Combustivel..........: ' . ($renavamCombustivel[intval($veiculoCombustivel)] ?? $veiculoCombustivel);
2785
        $this->pdf->textBox($xVeic, $yVeic, $w1+50, $h, $texto, $aFont, 'T', 'L', 0, '');
2786
        $yVeic += $h;
2787
        $texto = 'Serial.....................: ' . $veiculoSerial;
2788
        $this->pdf->textBox($xVeic, $yVeic, $w1+50, $h, $texto, $aFont, 'T', 'L', 0, '');
2789
        $yVeic += $h;
2790
        $texto = 'Ano Fab/Mod........: '. $veiculoFabricacao . '/' . $veiculoModelo;
2791
        $this->pdf->textBox($xVeic, $yVeic, $w1+50, $h, $texto, $aFont, 'T', 'L', 0, '');
2792
        $yVeic += $h;
2793
        $texto = 'Distancia Entre Eixos(mm)..: '. $veiculoDistancia;
2794
        $this->pdf->textBox($xVeic, $yVeic, $w1+50, $h, $texto, $aFont, 'T', 'L', 0, '');
2795
    }
2796
2797
    /**
2798
     * issqn
2799
     * Monta o campo de serviços do DANFE
2800
     *
2801
     * @name   issqn (retrato e paisagem)
2802
     * @param  float $x Posição horizontal canto esquerdo
2803
     * @param  float $y Posição vertical canto superior
2804
     * @return float Posição vertical final
2805
     */
2806
    protected function issqn($x, $y)
2807
    {
2808
        $oldX = $x;
0 ignored issues
show
Unused Code introduced by
$oldX 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...
2809
        //#####################################################################
2810
        //CÁLCULO DO ISSQN
2811
        $texto = "CÁLCULO DO ISSQN";
2812
        $w = $this->wPrint;
2813
        $h = 7;
2814
        $aFont = ['font'=>$this->fontePadrao, 'size'=>7, 'style'=>'B'];
2815
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 0, '');
2816
        //INSCRIÇÃO MUNICIPAL
2817
        $y += 3;
2818
        $w = round($this->wPrint*0.23, 0);
2819
        $texto = 'INSCRIÇÃO MUNICIPAL';
2820
        $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
2821
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 1, '');
2822
        //inscrição municipal
2823
        $texto = ! empty($this->emit->getElementsByTagName("IM")->item(0)->nodeValue) ?
2824
                $this->emit->getElementsByTagName("IM")->item(0)->nodeValue : '';
2825
        $aFont = ['font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B'];
2826
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'B', 'L', 0, '');
2827
        //VALOR TOTAL DOS SERVIÇOS
2828
        $x += $w;
2829
        $texto = 'VALOR TOTAL DOS SERVIÇOS';
2830
        $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
2831
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 1, '');
2832
        if (isset($this->ISSQNtot)) {
2833
            $texto = ! empty($this->ISSQNtot->getElementsByTagName("vServ")->item(0)->nodeValue) ?
2834
                    $this->ISSQNtot->getElementsByTagName("vServ")->item(0)->nodeValue : '';
2835
            $texto = number_format($texto, 2, ",", ".");
2836
        } else {
2837
            $texto = '';
2838
        }
2839
        $aFont = ['font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B'];
2840
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'B', 'R', 0, '');
2841
        //BASE DE CÁLCULO DO ISSQN
2842
        $x += $w;
2843
        $texto = 'BASE DE CÁLCULO DO ISSQN';
2844
        $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
2845
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 1, '');
2846
        if (isset($this->ISSQNtot)) {
2847
            $texto = ! empty($this->ISSQNtot->getElementsByTagName("vBC")->item(0)->nodeValue) ?
2848
                    $this->ISSQNtot->getElementsByTagName("vBC")->item(0)->nodeValue : '';
2849
            $texto = ! empty($texto) ? number_format($texto, 2, ",", ".") : '';
2850
        } else {
2851
            $texto = '';
2852
        }
2853
        $aFont = ['font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B'];
2854
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'B', 'R', 0, '');
2855
        //VALOR TOTAL DO ISSQN
2856
        $x += $w;
2857
        if ($this->orientacao == 'P') {
2858
            $w = $this->wPrint - (3 * $w);
2859
        } else {
2860
            $w = $this->wPrint - (3 * $w)-$this->wCanhoto;
2861
        }
2862
        $texto = 'VALOR TOTAL DO ISSQN';
2863
        $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
2864
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 1, '');
2865
        if (isset($this->ISSQNtot)) {
2866
            $texto = ! empty($this->ISSQNtot->getElementsByTagName("vISS")->item(0)->nodeValue) ?
2867
                    $this->ISSQNtot->getElementsByTagName("vISS")->item(0)->nodeValue : '';
2868
            $texto = ! empty($texto) ? number_format($texto, 2, ",", ".") : '';
2869
        } else {
2870
            $texto = '';
2871
        }
2872
        $aFont = ['font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B'];
2873
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'B', 'R', 0, '');
2874
        return ($y+$h+1);
2875
    }
2876
2877
    /**
2878
     *dadosAdicionais
2879
     * Coloca o grupo de dados adicionais da NFe. (retrato e paisagem)
2880
     *
2881
     * @name   dadosAdicionais
2882
     * @param  float $x Posição horizontal canto esquerdo
2883
     * @param  float $y Posição vertical canto superior
2884
     * @param  float $h altura do campo
2885
     * @return float Posição vertical final (eixo Y)
2886
     */
2887
    protected function dadosAdicionais($x, $y, $h)
2888
    {
2889
        //##################################################################################
2890
        //DADOS ADICIONAIS
2891
        $texto = "DADOS ADICIONAIS";
2892
        if ($this->orientacao == 'P') {
2893
              $w = $this->wPrint;
2894
        } else {
2895
              $w = $this->wPrint-$this->wCanhoto;
2896
        }
2897
        $aFont = ['font'=>$this->fontePadrao, 'size'=>7, 'style'=>'B'];
2898
        $this->pdf->textBox($x, $y, $w, 8, $texto, $aFont, 'T', 'L', 0, '');
2899
        //INFORMAÇÕES COMPLEMENTARES
2900
        $texto = "INFORMAÇÕES COMPLEMENTARES";
2901
        $y += 3;
2902
        $w = $this->wAdic;
2903
        $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>'B'];
2904
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 1, '');
2905
        //o texto com os dados adicionais foi obtido na função montaDANFE
2906
        //e carregado em uma propriedade privada da classe
2907
        //$this->wAdic com a largura do campo
2908
        //$this->textoAdic com o texto completo do campo
2909
        $y += 1;
2910
        $aFont = ['font'=>$this->fontePadrao, 'size'=>7, 'style'=>''];
2911
        $this->pdf->textBox($x, $y+2, $w-2, $h-3, $this->textoAdic, $aFont, 'T', 'L', 0, '', false);
2912
        //RESERVADO AO FISCO
2913
        $texto = "RESERVADO AO FISCO";
2914
        $x += $w;
2915
        $y -= 1;
2916
        if ($this->orientacao == 'P') {
2917
            $w = $this->wPrint-$w;
2918
        } else {
2919
            $w = $this->wPrint-$w-$this->wCanhoto;
2920
        }
2921
        $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>'B'];
2922
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 1, '');
2923
        //inserir texto informando caso de contingência
2924
        // 1 - Normal - emissão normal;
2925
        // 2 - Contingência FS - emissão em contingência com impressão do DANFE em Formulário de Segurança;
2926
        // 3 - Contingência SCAN - emissão em contingência no Sistema de Contingência do Ambiente Nacional;
2927
        // 4 - Contingência DPEC - emissão em contingência com envio da Declaração
2928
        //     Prévia de Emissão em Contingência;
2929
        // 5 - Contingência FS-DA - emissão em contingência com impressão do DANFE em Formulário de
2930
        //     Segurança para Impressão de Documento Auxiliar de Documento Fiscal Eletrônico (FS-DA);
2931
        // 6 - Contingência SVC-AN
2932
        // 7 - Contingência SVC-RS
2933
        $xJust = $this->getTagValue($this->ide, 'xJust', 'Justificativa: ');
2934
        $dhCont = $this->getTagValue($this->ide, 'dhCont', ' Entrada em contingência : ');
2935
        $texto = '';
2936
        switch ($this->tpEmis) {
2937
            case 2:
2938
                $texto = 'CONTINGÊNCIA FS' . $dhCont . $xJust;
2939
                break;
2940
            case 3:
2941
                $texto = 'CONTINGÊNCIA SCAN' . $dhCont . $xJust;
2942
                break;
2943
            case 4:
2944
                $texto = 'CONTINGÊNCIA DPEC' . $dhCont . $xJust;
2945
                break;
2946
            case 5:
2947
                $texto = 'CONTINGÊNCIA FSDA' . $dhCont . $xJust;
2948
                break;
2949
            case 6:
2950
                $texto = 'CONTINGÊNCIA SVC-AN' . $dhCont . $xJust;
2951
                break;
2952
            case 7:
2953
                $texto = 'CONTINGÊNCIA SVC-RS' . $dhCont . $xJust;
2954
                break;
2955
        }
2956
        $y += 2;
2957
        $aFont = ['font'=>$this->fontePadrao, 'size'=>7, 'style'=>''];
2958
        $this->pdf->textBox($x, $y, $w-2, $h-3, $texto, $aFont, 'T', 'L', 0, '', false);
2959
        return $y+$h;
2960
    }
2961
2962
    /**
2963
     * rodape
2964
     * Monta o rodapé no final da DANFE com a data/hora de impressão e informações
2965
     * sobre a API NfePHP
2966
     *
2967
     * @name   rodape
2968
     * @param  float $xInic  Posição horizontal canto esquerdo
0 ignored issues
show
Bug introduced by
There is no parameter named $xInic. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
2969
     * @param  float $yFinal Posição vertical final para impressão
0 ignored issues
show
Bug introduced by
There is no parameter named $yFinal. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
2970
     * @return void
2971
     */
2972
    protected function rodape($x, $y)
2973
    {
2974
        if ($this->orientacao == 'P') {
2975
              $w = $this->wPrint;
2976
        } else {
2977
              $w = $this->wPrint-$this->wCanhoto;
2978
              $x = $this->wCanhoto;
2979
        }
2980
        $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>'I'];
2981
        $texto = "Impresso em ". date('d/m/Y') . " as " . date('H:i:s');
2982
        $this->pdf->textBox($x, $y, $w, 0, $texto, $aFont, 'T', 'L', false);
2983
        $texto = $this->creditos .  "  Powered by NFePHP®";
2984
        $this->pdf->textBox($x, $y, $w, 0, $texto, $aFont, 'T', 'R', false, '');
2985
    }
2986
2987
    /**
2988
     * pCcanhotoDANFE
2989
     * Monta o canhoto da DANFE (retrato e paisagem)
2990
     *
2991
     * @name   canhotoDANFE
2992
     * @param  number $x Posição horizontal canto esquerdo
2993
     * @param  number $y Posição vertical canto superior
2994
     * @return number Posição vertical final
2995
     *
2996
     * TODO 21/07/14 fmertins: quando orientação L-paisagem, o canhoto está sendo gerado incorretamente
2997
     */
2998
    protected function canhoto($x, $y)
2999
    {
3000
        $oldX = $x;
3001
        $oldY = $y;
3002
        //#################################################################################
3003
        //canhoto
3004
        //identificação do tipo de nf entrada ou saida
3005
        $tpNF = $this->ide->getElementsByTagName('tpNF')->item(0)->nodeValue;
3006
        if ($tpNF == '0') {
3007
            //NFe de Entrada
3008
            $emitente = '';
3009
            $emitente .= $this->dest->getElementsByTagName("xNome")->item(0)->nodeValue . " - ";
3010
            $emitente .= $this->enderDest->getElementsByTagName("xLgr")->item(0)->nodeValue . ", ";
3011
            $emitente .= $this->enderDest->getElementsByTagName("nro")->item(0)->nodeValue . " - ";
3012
            $emitente .= $this->getTagValue($this->enderDest, "xCpl", " - ", " ");
3013
            $emitente .= $this->enderDest->getElementsByTagName("xBairro")->item(0)->nodeValue . " ";
3014
            $emitente .= $this->enderDest->getElementsByTagName("xMun")->item(0)->nodeValue . "-";
3015
            $emitente .= $this->enderDest->getElementsByTagName("UF")->item(0)->nodeValue . "";
3016
            $destinatario = $this->emit->getElementsByTagName("xNome")->item(0)->nodeValue . " ";
3017
        } else {
3018
            //NFe de Saída
3019
            $emitente = $this->emit->getElementsByTagName("xNome")->item(0)->nodeValue . " ";
3020
            $destinatario = '';
3021
            $destinatario .= $this->dest->getElementsByTagName("xNome")->item(0)->nodeValue . " - ";
3022
            $destinatario .= $this->enderDest->getElementsByTagName("xLgr")->item(0)->nodeValue . ", ";
3023
            $destinatario .= $this->enderDest->getElementsByTagName("nro")->item(0)->nodeValue . " ";
3024
            $destinatario .= $this->getTagValue($this->enderDest, "xCpl", " - ", " ");
3025
            $destinatario .= $this->enderDest->getElementsByTagName("xBairro")->item(0)->nodeValue . " ";
3026
            $destinatario .= $this->enderDest->getElementsByTagName("xMun")->item(0)->nodeValue . "-";
3027
            $destinatario .= $this->enderDest->getElementsByTagName("UF")->item(0)->nodeValue . " ";
3028
        }
3029
        //identificação do sistema emissor
3030
        //linha separadora do canhoto
3031
        if ($this->orientacao == 'P') {
3032
            $w = round($this->wPrint * 0.81, 0);
3033
        } else {
3034
            //linha separadora do canhoto - 238
3035
            //posicao altura
3036
            $y = $this->wPrint-85;
3037
            //altura
3038
            $w = $this->wPrint-85-24;
3039
        }
3040
        $h = 10;
3041
        //desenha caixa
3042
        $texto = '';
3043
        $aFont = ['font'=>$this->fontePadrao, 'size'=>7, 'style'=>''];
3044
        $aFontSmall = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
3045
        if ($this->orientacao == 'P') {
3046
            $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'C', 'L', 1, '', false);
3047
        } else {
3048
            $this->pdf->textBox90($x, $y, $w, $h, $texto, $aFont, 'C', 'L', 1, '', false);
3049
        }
3050
        $numNF = str_pad($this->ide->getElementsByTagName('nNF')->item(0)->nodeValue, 9, "0", STR_PAD_LEFT);
3051
        $serie = str_pad($this->ide->getElementsByTagName('serie')->item(0)->nodeValue, 3, "0", STR_PAD_LEFT);
3052
        $texto = "RECEBEMOS DE ";
3053
        $texto .= $emitente;
3054
        $texto .= " OS PRODUTOS E/OU SERVIÇOS CONSTANTES DA NOTA FISCAL ELETRÔNICA INDICADA ";
3055
        if ($this->orientacao == 'P') {
3056
            $texto .= "ABAIXO";
3057
        } else {
3058
            $texto .= "AO LADO";
3059
        }
3060
        $texto .= ". EMISSÃO: ";
3061
        $dEmi = ! empty($this->ide->getElementsByTagName("dEmi")->item(0)->nodeValue) ?
3062
                $this->ide->getElementsByTagName("dEmi")->item(0)->nodeValue : '';
3063
        if ($dEmi == '') {
3064
            $dEmi = ! empty($this->ide->getElementsByTagName("dhEmi")->item(0)->nodeValue) ?
3065
                    $this->ide->getElementsByTagName("dhEmi")->item(0)->nodeValue : '';
3066
            $aDemi = explode('T', $dEmi);
3067
            $dEmi = $aDemi[0];
3068
        }
3069
        $texto .= $this->ymdTodmy($dEmi) ." ";
3070
        $texto .= "VALOR TOTAL: R$ ";
3071
        $texto .= number_format($this->ICMSTot->getElementsByTagName("vNF")->item(0)->nodeValue, 2, ",", ".") . " ";
3072
        $texto .= "DESTINATÁRIO: ";
3073
        $texto .= $destinatario;
3074
        if ($this->orientacao == 'P') {
3075
            $this->pdf->textBox($x, $y, $w-1, $h, $texto, $aFont, 'C', 'L', 0, '', false);
3076
            $x1 = $x + $w;
3077
            $w1 = $this->wPrint - $w;
3078
            $texto = "NF-e";
3079
            $aFont = ['font'=>$this->fontePadrao, 'size'=>14, 'style'=>'B'];
3080
            $this->pdf->textBox($x1, $y, $w1, 18, $texto, $aFont, 'T', 'C', 0, '');
3081
            $texto = "Nº. " . $this->formatField($numNF, "###.###.###") . " \n";
3082
            $texto .= "Série $serie";
3083
            $aFont = ['font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B'];
3084
            $this->pdf->textBox($x1, $y, $w1, 18, $texto, $aFont, 'C', 'C', 1, '');
3085
            //DATA DE RECEBIMENTO
3086
            $texto = "DATA DE RECEBIMENTO";
3087
            $y += $h;
3088
            $w2 = round($this->wPrint*0.17, 0); //35;
3089
            $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
3090
            $this->pdf->textBox($x, $y, $w2, 8, $texto, $aFont, 'T', 'L', 1, '');
3091
            //IDENTIFICAÇÃO E ASSINATURA DO RECEBEDOR
3092
            $x += $w2;
3093
            $w3 = $w-$w2;
3094
            $texto = "IDENTIFICAÇÃO E ASSINATURA DO RECEBEDOR";
3095
            $this->pdf->textBox($x, $y, $w3, 8, $texto, $aFont, 'T', 'L', 1, '');
3096
            $x = $oldX;
3097
            $y += 9;
3098
            $this->pdf->dashedHLine($x, $y, $this->wPrint, 0.1, 80);
3099
            $y += 2;
3100
            return $y;
3101
        } else {
3102
            $x--;
3103
            $x = $this->pdf->textBox90($x, $y, $w-1, $h, $texto, $aFontSmall, 'C', 'L', 0, '', false);
0 ignored issues
show
Unused Code introduced by
$x 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...
3104
            //NUMERO DA NOTA FISCAL LOGO NFE
3105
            $w1 = 18;
3106
            $x1 = $oldX;
3107
            $y = $oldY;
3108
            $texto = "NF-e";
3109
            $aFont = ['font'=>$this->fontePadrao, 'size'=>14, 'style'=>'B'];
3110
            $this->pdf->textBox($x1, $y, $w1, 18, $texto, $aFont, 'T', 'C', 0, '');
3111
            $texto = "Nº.\n" . $this->formatField($numNF, "###.###.###") . " \n";
3112
            $texto .= "Série $serie";
3113
            $aFont = ['font'=>$this->fontePadrao, 'size'=>8, 'style'=>'B'];
3114
            $this->pdf->textBox($x1, $y, $w1, 18, $texto, $aFont, 'C', 'C', 1, '');
3115
            //DATA DO RECEBIMENTO
3116
            $texto = "DATA DO RECEBIMENTO";
3117
            $y = $this->wPrint-85;
3118
            $x = 12;
3119
            $w2 = round($this->wPrint*0.17, 0); //35;
3120
            $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
3121
            $this->pdf->textBox90($x, $y, $w2, 8, $texto, $aFont, 'T', 'L', 1, '');
3122
            //IDENTIFICAÇÃO E ASSINATURA DO RECEBEDOR
3123
            $y -= $w2;
3124
            $w3 = $w-$w2;
3125
            $texto = "IDENTIFICAÇÃO E ASSINATURA DO RECEBEDOR";
3126
            $aFont = ['font'=>$this->fontePadrao, 'size'=>5.7, 'style'=>''];
3127
            $x = $this->pdf->textBox90($x, $y, $w3, 8, $texto, $aFont, 'T', 'L', 1, '');
3128
            $this->pdf->DashedVLine(23, $oldY, 0.1, $this->wPrint-20, 67);
3129
            return $x;
3130
        }
3131
    }
3132
3133
    /**
3134
     * geraInformacoesDaTagCompra
3135
     * Devolve uma string contendo informação sobre as tag <compra><xNEmp>, <xPed> e <xCont> ou string vazia.
3136
     * Aviso: Esta função não leva em consideração dados na tag xPed do item.
3137
     *
3138
     * @name   pGeraInformacoesDaTagCompra
3139
     * @return string com as informacoes dos pedidos.
3140
     */
3141
    protected function geraInformacoesDaTagCompra()
3142
    {
3143
        $saida = "";
3144
        if (isset($this->compra)) {
3145
            if (! empty($this->compra->getElementsByTagName("xNEmp")->item(0)->nodeValue)) {
3146
                $saida .= " Nota de Empenho: " . $this->compra->getElementsByTagName("xNEmp")->item(0)->nodeValue;
3147
            }
3148
            if (! empty($this->compra->getElementsByTagName("xPed")->item(0)->nodeValue)) {
3149
                $saida .= " Pedido: " . $this->compra->getElementsByTagName("xPed")->item(0)->nodeValue;
3150
            }
3151
            if (! empty($this->compra->getElementsByTagName("xCont")->item(0)->nodeValue)) {
3152
                $saida .= " Contrato: " . $this->compra->getElementsByTagName("xCont")->item(0)->nodeValue;
3153
            }
3154
        }
3155
        return $saida;
3156
    }
3157
3158
    /**
3159
     * geraChaveAdicionalDeContingencia
3160
     *
3161
     * @name   geraChaveAdicionalDeContingencia
3162
     * @return string chave
3163
     */
3164
    protected function geraChaveAdicionalDeContingencia()
3165
    {
3166
        //cUF tpEmis CNPJ vNF ICMSp ICMSs DD  DV
3167
        // Quantidade de caracteres  02   01      14  14    01    01  02 01
3168
        $forma  = "%02d%d%s%014d%01d%01d%02d";
3169
        $cUF    = $this->ide->getElementsByTagName('cUF')->item(0)->nodeValue;
3170
        $CNPJ   = "00000000000000" . $this->emit->getElementsByTagName('CNPJ')->item(0)->nodeValue;
3171
        $CNPJ   = substr($CNPJ, -14);
3172
        $vNF    = $this->ICMSTot->getElementsByTagName("vNF")->item(0)->nodeValue * 100;
3173
        $vICMS  = $this->ICMSTot->getElementsByTagName("vICMS")->item(0)->nodeValue;
3174
        if ($vICMS > 0) {
3175
            $vICMS = 1;
3176
        }
3177
        $icmss  = $this->ICMSTot->getElementsByTagName("vBC")->item(0)->nodeValue;
3178
        if ($icmss > 0) {
3179
            $icmss = 1;
3180
        }
3181
        $dEmi = ! empty($this->ide->getElementsByTagName("dEmi")->item(0)->nodeValue) ?
3182
                $this->ide->getElementsByTagName("dEmi")->item(0)->nodeValue : '';
3183
        if ($dEmi == '') {
3184
            $dEmi = ! empty($this->ide->getElementsByTagName("dhEmi")->item(0)->nodeValue) ?
3185
                    $this->ide->getElementsByTagName("dhEmi")->item(0)->nodeValue : '';
3186
            $aDemi = explode('T', $dEmi);
3187
            $dEmi = $aDemi[0];
3188
        }
3189
        $dd  = $dEmi;
3190
        $rpos = strrpos($dd, '-');
3191
        $dd  = substr($dd, $rpos +1);
3192
        $chave = sprintf($forma, $cUF, $this->tpEmis, $CNPJ, $vNF, $vICMS, $icmss, $dd);
3193
        $chave = $chave . $this->modulo11($chave);
3194
        return $chave;
3195
    }
3196
3197
    /**
3198
     *  geraInformacoesDasNotasReferenciadas
3199
     * Devolve uma string contendo informação sobre as notas referenciadas. Suporta N notas, eletrônicas ou não
3200
     * Exemplo: NFe Ref.: série: 01 número: 01 emit: 11.111.111/0001-01
3201
     * em 10/2010 [0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000]
3202
     *
3203
     * @return string Informacoes a serem adicionadas no rodapé sobre notas referenciadas.
3204
     */
3205
    protected function geraInformacoesDasNotasReferenciadas()
3206
    {
3207
        $formaNfeRef = "\r\nNFe Ref.: série:%d número:%d emit:%s em %s [%s]";
3208
        $formaCTeRef = "\r\nCTe Ref.: série:%d número:%d emit:%s em %s [%s]";
3209
        $formaNfRef = "\r\nNF  Ref.: série:%d numero:%d emit:%s em %s modelo: %d";
3210
        $formaECFRef = "\r\nECF Ref.: modelo: %s ECF:%d COO:%d";
3211
        $formaNfpRef = "\r\nNFP Ref.: série:%d número:%d emit:%s em %s modelo: %d IE:%s";
3212
        $saida='';
3213
        $nfRefs = $this->ide->getElementsByTagName('NFref');
3214
        if (0 === $nfRefs->length) {
3215
            return $saida;
3216
        }
3217
        if ($nfRefs->length > 2) {
3218
            return 'Existem mais de 2 NF/NFe/ECF/NFP/CTe referenciadas, não serão exibidas na DANFE.';
3219
        }
3220
        foreach ($nfRefs as $nfRef) {
3221
            if (empty($nfRef)) {
3222
                continue;
3223
            }
3224
            $refNFe = $nfRef->getElementsByTagName('refNFe');
3225
            foreach ($refNFe as $chave_acessoRef) {
3226
                $chave_acesso = $chave_acessoRef->nodeValue;
3227
                $chave_acessoF = $this->formatField($chave_acesso, $this->formatoChave);
3228
                $data = substr($chave_acesso, 4, 2)."/20".substr($chave_acesso, 2, 2);
3229
                $cnpj = $this->formatField(substr($chave_acesso, 6, 14), "##.###.###/####-##");
3230
                $serie  = substr($chave_acesso, 22, 3);
3231
                $numero = substr($chave_acesso, 25, 9);
3232
                $saida .= sprintf($formaNfeRef, $serie, $numero, $cnpj, $data, $chave_acessoF);
3233
            }
3234
            $refNF = $nfRef->getElementsByTagName('refNF');
3235
            foreach ($refNF as $umaRefNFe) {
3236
                $data = $umaRefNFe->getElementsByTagName('AAMM')->item(0)->nodeValue;
3237
                $cnpj = $umaRefNFe->getElementsByTagName('CNPJ')->item(0)->nodeValue;
3238
                $mod = $umaRefNFe->getElementsByTagName('mod')->item(0)->nodeValue;
3239
                $serie = $umaRefNFe->getElementsByTagName('serie')->item(0)->nodeValue;
3240
                $numero = $umaRefNFe->getElementsByTagName('nNF')->item(0)->nodeValue;
3241
                $data = substr($data, 2, 2) . "/20" . substr($data, 0, 2);
3242
                $cnpj = $this->formatField($cnpj, "##.###.###/####-##");
3243
                $saida .= sprintf($formaNfRef, $serie, $numero, $cnpj, $data, $mod);
3244
            }
3245
            $refCTe = $nfRef->getElementsByTagName('refCTe');
3246
            foreach ($refCTe as $chave_acessoRef) {
3247
                $chave_acesso = $chave_acessoRef->nodeValue;
3248
                $chave_acessoF = $this->formatField($chave_acesso, $this->formatoChave);
3249
                $data = substr($chave_acesso, 4, 2)."/20".substr($chave_acesso, 2, 2);
3250
                $cnpj = $this->formatField(substr($chave_acesso, 6, 14), "##.###.###/####-##");
3251
                $serie  = substr($chave_acesso, 22, 3);
3252
                $numero = substr($chave_acesso, 25, 9);
3253
                $saida .= sprintf($formaCTeRef, $serie, $numero, $cnpj, $data, $chave_acessoF);
3254
            }
3255
            $refECF = $nfRef->getElementsByTagName('refECF');
3256
            foreach ($refECF as $umaRefNFe) {
3257
                $mod    = $umaRefNFe->getElementsByTagName('mod')->item(0)->nodeValue;
3258
                $nECF   = $umaRefNFe->getElementsByTagName('nECF')->item(0)->nodeValue;
3259
                $nCOO   = $umaRefNFe->getElementsByTagName('nCOO')->item(0)->nodeValue;
3260
                $saida .= sprintf($formaECFRef, $mod, $nECF, $nCOO);
3261
            }
3262
            $refNFP = $nfRef->getElementsByTagName('refNFP');
3263
            foreach ($refNFP as $umaRefNFe) {
3264
                $data = $umaRefNFe->getElementsByTagName('AAMM')->item(0)->nodeValue;
3265
                $cnpj = ! empty($umaRefNFe->getElementsByTagName('CNPJ')->item(0)->nodeValue) ?
3266
                    $umaRefNFe->getElementsByTagName('CNPJ')->item(0)->nodeValue :
3267
                    '';
3268
                $cpf = ! empty($umaRefNFe->getElementsByTagName('CPF')->item(0)->nodeValue) ?
3269
                        $umaRefNFe->getElementsByTagName('CPF')->item(0)->nodeValue : '';
3270
                $mod = $umaRefNFe->getElementsByTagName('mod')->item(0)->nodeValue;
3271
                $serie = $umaRefNFe->getElementsByTagName('serie')->item(0)->nodeValue;
3272
                $numero = $umaRefNFe->getElementsByTagName('nNF')->item(0)->nodeValue;
3273
                $ie = $umaRefNFe->getElementsByTagName('IE')->item(0)->nodeValue;
3274
                $data = substr($data, 2, 2) . "/20" . substr($data, 0, 2);
3275
                if ($cnpj == '') {
3276
                    $cpf_cnpj = $this->formatField($cpf, "###.###.###-##");
3277
                } else {
3278
                    $cpf_cnpj = $this->formatField($cnpj, "##.###.###/####-##");
3279
                }
3280
                $saida .= sprintf($formaNfpRef, $serie, $numero, $cpf_cnpj, $data, $mod, $ie);
3281
            }
3282
        }
3283
        return $saida;
3284
    }
3285
    
3286
    private function loadDoc($xml)
3287
    {
3288
        $this->xml = $xml;
3289
        if (!empty($xml)) {
3290
            $this->dom = new Dom();
0 ignored issues
show
Documentation Bug introduced by
It seems like new \NFePHP\DA\Legacy\Dom() of type object<NFePHP\DA\Legacy\Dom> is incompatible with the declared type object<NFePHP\DA\NFe\DOMDocument> of property $dom.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
3291
            $this->dom->loadXML($this->xml);
3292
            if (empty($this->dom->getElementsByTagName("infNFe")->item(0))) {
3293
                throw new \Exception('Isso não é um NFe.');
3294
            }
3295
            $this->nfeProc = $this->dom->getElementsByTagName("nfeProc")->item(0);
3296
            $this->infNFe = $this->dom->getElementsByTagName("infNFe")->item(0);
0 ignored issues
show
Documentation Bug introduced by
It seems like $this->dom->getElementsB...Name('infNFe')->item(0) of type object<DOMNode> is incompatible with the declared type object<NFePHP\DA\NFe\DOMNode> of property $infNFe.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
3297
            $this->ide = $this->dom->getElementsByTagName("ide")->item(0);
0 ignored issues
show
Documentation Bug introduced by
It seems like $this->dom->getElementsByTagName('ide')->item(0) of type object<DOMNode> is incompatible with the declared type object<NFePHP\DA\NFe\DOMNode> of property $ide.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
3298
            if ($this->getTagValue($this->ide, "mod") != '55') {
3299
                throw new \Exception("O xml deve ser NF-e modelo 55.");
3300
            }
3301
            $this->entrega = $this->dom->getElementsByTagName("entrega")->item(0);
0 ignored issues
show
Documentation Bug introduced by
It seems like $this->dom->getElementsB...ame('entrega')->item(0) of type object<DOMNode> is incompatible with the declared type object<NFePHP\DA\NFe\DOMNode> of property $entrega.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
3302
            $this->retirada = $this->dom->getElementsByTagName("retirada")->item(0);
0 ignored issues
show
Documentation Bug introduced by
It seems like $this->dom->getElementsB...me('retirada')->item(0) of type object<DOMNode> is incompatible with the declared type object<NFePHP\DA\NFe\DOMNode> of property $retirada.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
3303
            $this->emit = $this->dom->getElementsByTagName("emit")->item(0);
0 ignored issues
show
Documentation Bug introduced by
It seems like $this->dom->getElementsByTagName('emit')->item(0) of type object<DOMNode> is incompatible with the declared type object<NFePHP\DA\NFe\DOMNode> of property $emit.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
3304
            $this->dest = $this->dom->getElementsByTagName("dest")->item(0);
0 ignored issues
show
Documentation Bug introduced by
It seems like $this->dom->getElementsByTagName('dest')->item(0) of type object<DOMNode> is incompatible with the declared type object<NFePHP\DA\NFe\DOMNode> of property $dest.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
3305
            $this->enderEmit = $this->dom->getElementsByTagName("enderEmit")->item(0);
0 ignored issues
show
Documentation Bug introduced by
It seems like $this->dom->getElementsB...e('enderEmit')->item(0) of type object<DOMNode> is incompatible with the declared type object<NFePHP\DA\NFe\DOMNode> of property $enderEmit.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
3306
            $this->enderDest = $this->dom->getElementsByTagName("enderDest")->item(0);
0 ignored issues
show
Documentation Bug introduced by
It seems like $this->dom->getElementsB...e('enderDest')->item(0) of type object<DOMNode> is incompatible with the declared type object<NFePHP\DA\NFe\DOMNode> of property $enderDest.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
3307
            $this->det = $this->dom->getElementsByTagName("det");
0 ignored issues
show
Documentation Bug introduced by
It seems like $this->dom->getElementsByTagName('det') of type object<DOMNodeList> is incompatible with the declared type object<NFePHP\DA\NFe\DOMNode> of property $det.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
3308
            $this->cobr = $this->dom->getElementsByTagName("cobr")->item(0);
0 ignored issues
show
Documentation Bug introduced by
It seems like $this->dom->getElementsByTagName('cobr')->item(0) of type object<DOMNode> is incompatible with the declared type object<NFePHP\DA\NFe\DOMNode> of property $cobr.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
3309
            $this->dup = $this->dom->getElementsByTagName('dup');
0 ignored issues
show
Documentation Bug introduced by
It seems like $this->dom->getElementsByTagName('dup') of type object<DOMNodeList> is incompatible with the declared type object<NFePHP\DA\NFe\DOMNode> of property $dup.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
3310
            $this->ICMSTot = $this->dom->getElementsByTagName("ICMSTot")->item(0);
0 ignored issues
show
Documentation Bug introduced by
It seems like $this->dom->getElementsB...ame('ICMSTot')->item(0) of type object<DOMNode> is incompatible with the declared type object<NFePHP\DA\NFe\DOMNode> of property $ICMSTot.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
3311
            $this->ISSQNtot = $this->dom->getElementsByTagName("ISSQNtot")->item(0);
0 ignored issues
show
Documentation Bug introduced by
It seems like $this->dom->getElementsB...me('ISSQNtot')->item(0) of type object<DOMNode> is incompatible with the declared type object<NFePHP\DA\NFe\DOMNode> of property $ISSQNtot.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
3312
            $this->transp = $this->dom->getElementsByTagName("transp")->item(0);
0 ignored issues
show
Documentation Bug introduced by
It seems like $this->dom->getElementsB...Name('transp')->item(0) of type object<DOMNode> is incompatible with the declared type object<NFePHP\DA\NFe\DOMNode> of property $transp.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
3313
            $this->transporta = $this->dom->getElementsByTagName("transporta")->item(0);
0 ignored issues
show
Documentation Bug introduced by
It seems like $this->dom->getElementsB...('transporta')->item(0) of type object<DOMNode> is incompatible with the declared type object<NFePHP\DA\NFe\DOMNode> of property $transporta.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
3314
            $this->veicTransp = $this->dom->getElementsByTagName("veicTransp")->item(0);
0 ignored issues
show
Documentation Bug introduced by
It seems like $this->dom->getElementsB...('veicTransp')->item(0) of type object<DOMNode> is incompatible with the declared type object<NFePHP\DA\NFe\DOMNode> of property $veicTransp.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
3315
            $this->reboque = $this->dom->getElementsByTagName("reboque")->item(0);
0 ignored issues
show
Documentation Bug introduced by
It seems like $this->dom->getElementsB...ame('reboque')->item(0) of type object<DOMNode> is incompatible with the declared type object<NFePHP\DA\NFe\DOMNode> of property $reboque.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
3316
            $this->infAdic = $this->dom->getElementsByTagName("infAdic")->item(0);
0 ignored issues
show
Documentation Bug introduced by
It seems like $this->dom->getElementsB...ame('infAdic')->item(0) of type object<DOMNode> is incompatible with the declared type object<NFePHP\DA\NFe\DOMNode> of property $infAdic.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
3317
            $this->compra = $this->dom->getElementsByTagName("compra")->item(0);
0 ignored issues
show
Documentation Bug introduced by
It seems like $this->dom->getElementsB...Name('compra')->item(0) of type object<DOMNode> is incompatible with the declared type object<NFePHP\DA\NFe\DOMNode> of property $compra.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
3318
            $this->tpEmis = $this->getTagValue($this->ide, "tpEmis");
0 ignored issues
show
Documentation Bug introduced by
The property $tpEmis was declared of type integer, but $this->getTagValue($this->ide, 'tpEmis') is of type string. Maybe add a type cast?

This check looks for assignments to scalar types that may be of the wrong type.

To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.

$answer = 42;

$correct = false;

$correct = (bool) $answer;
Loading history...
3319
            $this->tpImp = $this->getTagValue($this->ide, "tpImp");
0 ignored issues
show
Documentation Bug introduced by
The property $tpImp was declared of type integer, but $this->getTagValue($this->ide, 'tpImp') is of type string. Maybe add a type cast?

This check looks for assignments to scalar types that may be of the wrong type.

To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.

$answer = 42;

$correct = false;

$correct = (bool) $answer;
Loading history...
3320
            $this->infProt = $this->dom->getElementsByTagName("infProt")->item(0);
0 ignored issues
show
Documentation Bug introduced by
It seems like $this->dom->getElementsB...ame('infProt')->item(0) of type object<DOMNode> is incompatible with the declared type object<NFePHP\DA\NFe\DOMNode> of property $infProt.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
3321
        }
3322
    }
3323
    
3324
    private function imagePNGtoJPG($original)
3325
    {
3326
        $image = imagecreatefrompng($original);
3327
        ob_start();
3328
        imagejpeg($image, null, 100);
3329
        imagedestroy($image);
3330
        $stringdata = ob_get_contents(); // read from buffer
3331
        ob_end_clean();
3332
        return 'data://text/plain;base64,'.base64_encode($stringdata);
3333
    }
3334
}
3335