Passed
Push — master ( e78e20...466b11 )
by Roberto
02:42 queued 10s
created

Danfe::descricaoProdutoHelper()   A

Complexity

Conditions 4
Paths 5

Size

Total Lines 14

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 20

Importance

Changes 0
Metric Value
cc 4
nc 5
nop 3
dl 0
loc 14
ccs 0
cts 13
cp 0
crap 20
rs 9.7998
c 0
b 0
f 0
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->cabecalhoDANFE($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->faturaDANFE($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->pagamentoDANFE($x, $y+1);
622
            }
623
        }
624
        //coloca os dados dos impostos e totais da NFe
625
        $y = $this->impostoDANFE($x, $y+1);
626
        //coloca os dados do trasnporte
627
        $y = $this->transporteDANFE($x, $y+1);
628
        //itens da DANFE
629
        $nInicial = 0;
630
631
        $y = $this->itensDANFE($x, $y+1, $nInicial, $hDispo1, $pag, $totPag, $hCabecItens);
632
633
        //coloca os dados do ISSQN
634
        if ($linhaISSQN == 1) {
635
            $y = $this->issqnDANFE($x, $y+4);
636
        } else {
637
            $y += 4;
638
        }
639
        //coloca os dados adicionais da NFe
640
        $y = $this->dadosAdicionaisDANFE($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->cabecalhoDANFE($x, $y, $n, $totPag);
663
            //coloca os itens na página adicional
664
            $y = $this->itensDANFE($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
     *cabecalhoDANFE
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 cabecalhoDANFE($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 cabecalhoDANFE
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
     * faturaDANFE
1584
     * Monta o campo de duplicatas da DANFE (retrato e paisagem)
1585
     *
1586
     * @name   faturaDANFE
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 faturaDANFE($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;
0 ignored issues
show
Unused Code introduced by
$nFat 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...
1614
            if ($textoFatura !== "" && $this->exibirTextoFatura) {
1615
                $myH=6;
1616
                $myW = $this->wPrint;
1617
                if ($this->orientacao == 'L') {
1618
                    $myW -= $this->wCanhoto;
1619
                }
1620
                $aFont = ['font'=>$this->fontePadrao, 'size'=>8, 'style'=>''];
1621
                $this->pdf->textBox($x, $y, $myW, $myH, $textoFatura, $aFont, 'C', 'L', 1, '');
1622
                $y+=$myH+1;
1623
            }
1624
            if ($this->orientacao == 'P') {
1625
                $w = round($this->wPrint/7.018, 0)-1;
1626
            } else {
1627
                $w = 28;
1628
            }
1629
            $increm = 1;
1630
            foreach ($this->dup as $k => $d) {
1631
                $nDup = ! empty($this->dup->item($k)->getElementsByTagName('nDup')->item(0)->nodeValue) ?
1632
                        $this->dup->item($k)->getElementsByTagName('nDup')->item(0)->nodeValue : '';
1633
                $dDup = ! empty($this->dup->item($k)->getElementsByTagName('dVenc')->item(0)->nodeValue) ?
1634
                        $this->ymdTodmy($this->dup->item($k)->getElementsByTagName('dVenc')->item(0)->nodeValue) : '';
1635
                $vDup = ! empty($this->dup->item($k)->getElementsByTagName('vDup')->item(0)->nodeValue) ?
1636
                        'R$ ' . number_format(
1637
                            $this->dup->item($k)->getElementsByTagName('vDup')->item(0)->nodeValue,
1638
                            2,
1639
                            ",",
1640
                            "."
1641
                        ) : '';
1642
                $h = 8;
1643
                $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...
1644
                if ($nDup!='0' && $nDup!='') {
1645
                    $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
1646
                    $this->pdf->textBox($x, $y, $w, $h, 'Num.', $aFont, 'T', 'L', 1, '');
1647
                    $aFont = ['font'=>$this->fontePadrao, 'size'=>7, 'style'=>'B'];
1648
                    $this->pdf->textBox($x, $y, $w, $h, $nDup, $aFont, 'T', 'R', 0, '');
1649
                } else {
1650
                    $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
1651
                    $this->pdf->textBox($x, $y, $w, $h, ($dupcont+1)."", $aFont, 'T', 'L', 1, '');
1652
                }
1653
                $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
1654
                $this->pdf->textBox($x, $y, $w, $h, 'Venc.', $aFont, 'C', 'L', 0, '');
1655
                $aFont = ['font'=>$this->fontePadrao, 'size'=>7, 'style'=>'B'];
1656
                $this->pdf->textBox($x, $y, $w, $h, $dDup, $aFont, 'C', 'R', 0, '');
1657
                $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
1658
                $this->pdf->textBox($x, $y, $w, $h, 'Valor', $aFont, 'B', 'L', 0, '');
1659
                $aFont = ['font'=>$this->fontePadrao, 'size'=>7, 'style'=>'B'];
1660
                $this->pdf->textBox($x, $y, $w, $h, $vDup, $aFont, 'B', 'R', 0, '');
1661
                $x += $w+$increm;
1662
                $dupcont += 1;
1663
                if ($this->orientacao == 'P') {
1664
                    $maxDupCont = 6;
1665
                } else {
1666
                    $maxDupCont = 8;
1667
                }
1668
                if ($dupcont > $maxDupCont) {
1669
                    $y += 9;
1670
                    $x = $oldx;
1671
                    $dupcont = 0;
1672
                    $linha += 1;
1673
                }
1674
                if ($linha == 5) {
1675
                    $linha = 4;
1676
                    break;
1677
                }
1678
            }
1679
            if ($dupcont == 0) {
1680
                $y -= 9;
1681
                $linha--;
1682
            }
1683
            return ($y+$h);
1684
        } else {
1685
            $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...
1686
            return ($y-2);
1687
        }
1688
    } //fim da função faturaDANFE
1689
1690
    /**
1691
     * pagamentoDANFE
1692
     * Monta o campo de pagamentos da DANFE (retrato e paisagem) (foi baseada na faturaDANFE)
1693
     *
1694
     * @name   pagamentoDANFE
1695
     * @param  number $x Posição horizontal canto esquerdo
1696
     * @param  number $y Posição vertical canto superior
1697
     * @return number Posição vertical final
1698
     */
1699
    protected function pagamentoDANFE($x, $y)
1700
    {
1701
        $linha = 1;
1702
        $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...
1703
        $oldx = $x;
1704
        //verificar se existem cobranças definidas
1705
        if (isset($this->detPag) && $this->detPag->length > 0) {
1706
            //#####################################################################
1707
            //Tipo de pagamento
1708
            $texto = "PAGAMENTO";
1709
            if ($this->orientacao == 'P') {
1710
                $w = $this->wPrint;
1711
            } else {
1712
                $w = 271;
1713
            }
1714
            $h = 8;
1715
            $aFont = ['font'=>$this->fontePadrao, 'size'=>7, 'style'=>'B'];
1716
            $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 0, '');
1717
            $y += 3;
1718
            $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...
1719
            $dupcont = 0;
1720
            if ($this->orientacao == 'P') {
1721
                $w = round($this->wPrint/7.018, 0)-1;
1722
            } else {
1723
                $w = 28;
1724
            }
1725
            if ($this->orientacao == 'P') {
1726
                $maxDupCont = 6;
1727
            } else {
1728
                $maxDupCont = 8;
1729
            }
1730
            $increm = 1;
1731
            $formaPagamento = ['01'=>'Dinheiro','02'=>'Cheque','03'=>'Cartão de Crédito',
1732
                                    '04'=>'Cartão de Débito','05'=>'Crédito Loja','10'=>'Vale Alimentação',
1733
                                    '11'=>'Vale Refeição','12'=>'Vale Presente','13'=>'Vale Combustível',
1734
                                    '14'=>'Duplicata Mercantil','15'=>'Boleto','90'=>'Sem pagamento','99'=>'Outros'];
1735
            $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...
1736
                              '06'=>'Elo','07'=>'Hipercard','08'=>'Aura','09'=>'Cabal','99'=>'Outros'];
1737
            foreach ($this->detPag as $k => $d) {
1738
                $fPag = !empty($this->detPag->item($k)->getElementsByTagName('tPag')->item(0)->nodeValue)
1739
                    ? $this->detPag->item($k)->getElementsByTagName('tPag')->item(0)->nodeValue : '0';
1740
                $vPag = ! empty($this->detPag->item($k)->getElementsByTagName('vPag')->item(0)->nodeValue)
1741
                    ? 'R$ ' . number_format(
1742
                        $this->detPag->item($k)->getElementsByTagName('vPag')->item(0)->nodeValue,
1743
                        2,
1744
                        ",",
1745
                        "."
1746
                    ) : '';
1747
                $h = 6;
1748
                $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...
1749
                if (isset($formaPagamento[$fPag])) {
1750
                    /*Exibir Item sem pagamento ou outros?*/
1751
                    if ($fPag=='90' || $fPag=='99') {
1752
                        continue;
1753
                    }
1754
                    $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
1755
                    $this->pdf->textBox($x, $y, $w, $h, 'Forma', $aFont, 'T', 'L', 1, '');
1756
                    $aFont = ['font'=>$this->fontePadrao, 'size'=>7, 'style'=>'B'];
1757
                    $this->pdf->textBox($x, $y, $w, $h, $formaPagamento[$fPag], $aFont, 'T', 'R', 0, '');
1758
                } else {
1759
                    $aFont = ['font'=>$this->fontePadrao, 'size'=>7, 'style'=>''];
1760
                    $this->pdf->textBox($x, $y, $w, $h, "Forma ".$fPag." não encontrado", $aFont, 'T', 'L', 1, '');
1761
                }
1762
                $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
1763
                $this->pdf->textBox($x, $y, $w, $h, 'Valor', $aFont, 'B', 'L', 0, '');
1764
                $aFont = ['font'=>$this->fontePadrao, 'size'=>7, 'style'=>'B'];
1765
                $this->pdf->textBox($x, $y, $w, $h, $vPag, $aFont, 'B', 'R', 0, '');
1766
                $x += $w+$increm;
1767
                $dupcont += 1;
1768
1769
                if ($dupcont>$maxDupCont) {
1770
                    $y += 9;
1771
                    $x = $oldx;
1772
                    $dupcont = 0;
1773
                    $linha += 1;
1774
                }
1775
                if ($linha == 5) {
1776
                    $linha = 4;
1777
                    break;
1778
                }
1779
            }
1780
            if ($dupcont == 0) {
1781
                $y -= 9;
1782
                $linha--;
1783
            }
1784
            return ($y+$h);
1785
        } else {
1786
            $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...
1787
            return ($y-2);
1788
        }
1789
    } //fim da função pagamentoDANFE
1790
    
1791
    /**
1792
     * impostoDanfeHelper
1793
     * Auxilia a montagem dos campos de impostos e totais da DANFE
1794
     *
1795
     * @name   impostoDanfeHelper
1796
     * @param  float $x Posição horizontal canto esquerdo
1797
     * @param  float $y Posição vertical canto superior
1798
     * @param  float $w Largura do campo
1799
     * @param  float $h Altura do campo
1800
     * @param  float $h Título do campo
1801
     * @param  float $h Valor do imposto
1802
     * @return float Sugestão do $x do próximo imposto
1803
     */
1804
    protected function impostoDanfeHelper($x, $y, $w, $h, $titulo, $campoImposto)
1805
    {
1806
        $valorImposto = '0, 00';
1807
        $the_field = $this->ICMSTot->getElementsByTagName($campoImposto)->item(0);
1808
        if (isset($the_field)) {
1809
            $the_value = $the_field->nodeValue;
1810
            if (!empty($the_value)) {
1811
                $valorImposto = number_format($the_value, 2, ",", ".");
1812
            }
1813
        }
1814
1815
        $fontTitulo = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
1816
        $fontValor = ['font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B'];
1817
        $this->pdf->textBox($x, $y, $w, $h, $titulo, $fontTitulo, 'T', 'L', 1, '');
1818
        $this->pdf->textBox($x, $y, $w, $h, $valorImposto, $fontValor, 'B', 'R', 0, '');
1819
1820
        $next_x = $x + $w;
1821
        return $next_x;
1822
    }
1823
1824
    /**
1825
     * impostoDANFE
1826
     * Monta o campo de impostos e totais da DANFE (retrato e paisagem)
1827
     *
1828
     * @param  number $x Posição horizontal canto esquerdo
1829
     * @param  number $y Posição vertical canto superior
1830
     * @return number Posição vertical final
1831
     */
1832
    protected function impostoDANFE($x, $y)
1833
    {
1834
        $x_inicial = $x;
1835
        //#####################################################################
1836
1837
1838
        $campos_por_linha = 9;
1839
        if (!$this->exibirPIS) {
1840
            $campos_por_linha--;
1841
        }
1842
        if (!$this->exibirIcmsInterestadual) {
1843
            $campos_por_linha -= 2;
1844
        }
1845
1846
        if ($this->orientacao == 'P') {
1847
            $maxW = $this->wPrint;
1848
            $title_size = 31;
1849
        } else {
1850
            $maxW = $this->wPrint - $this->wCanhoto;
1851
            $title_size = 40;
1852
        }
1853
        $w = $maxW / $campos_por_linha;
1854
1855
        $aFont = ['font'=>$this->fontePadrao, 'size'=>7, 'style'=>'B'];
1856
        $texto = "CÁLCULO DO IMPOSTO";
1857
        $this->pdf->textBox($x, $y, $title_size, 8, $texto, $aFont, 'T', 'L', 0, '');
1858
        $y += 3;
1859
        $h = 7;
1860
1861
        $x = $this->impostoDanfeHelper($x, $y, $w, $h, "BASE DE CÁLC. DO ICMS", "vBC");
1862
        $x = $this->impostoDanfeHelper($x, $y, $w, $h, "VALOR DO ICMS", "vICMS");
1863
        $x = $this->impostoDanfeHelper($x, $y, $w, $h, "BASE DE CÁLC. ICMS S.T.", "vBCST");
1864
        $x = $this->impostoDanfeHelper($x, $y, $w, $h, "VALOR DO ICMS SUBST.", "vST");
1865
        $x = $this->impostoDanfeHelper($x, $y, $w, $h, "V. IMP. IMPORTAÇÃO", "vII");
1866
1867
        if ($this->exibirIcmsInterestadual) {
1868
            $x = $this->impostoDanfeHelper($x, $y, $w, $h, "V. ICMS UF REMET.", "vICMSUFRemet");
1869
            $x = $this->impostoDanfeHelper($x, $y, $w, $h, "V. FCP UF DEST.", "vFCPUFDest");
1870
        }
1871
1872
        if ($this->exibirPIS) {
1873
            $x = $this->impostoDanfeHelper($x, $y, $w, $h, "VALOR DO PIS", "vPIS");
1874
        }
1875
1876
        $x = $this->impostoDanfeHelper($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...
1877
1878
        //
1879
1880
        $y += $h;
1881
        $x = $x_inicial;
1882
1883
        $x = $this->impostoDanfeHelper($x, $y, $w, $h, "VALOR DO FRETE", "vFrete");
1884
        $x = $this->impostoDanfeHelper($x, $y, $w, $h, "VALOR DO SEGURO", "vSeg");
1885
        $x = $this->impostoDanfeHelper($x, $y, $w, $h, "DESCONTO", "vDesc");
1886
        $x = $this->impostoDanfeHelper($x, $y, $w, $h, "OUTRAS DESPESAS", "vOutro");
1887
        $x = $this->impostoDanfeHelper($x, $y, $w, $h, "VALOR TOTAL IPI", "vIPI");
1888
1889
        if ($this->exibirIcmsInterestadual) {
1890
            $x = $this->impostoDanfeHelper($x, $y, $w, $h, "V. ICMS UF DEST.", "vICMSUFDest");
1891
            $x = $this->impostoDanfeHelper($x, $y, $w, $h, "V. TOT. TRIB.", "vTotTrib");
1892
        }
1893
1894
        if ($this->exibirPIS) {
1895
            $x = $this->impostoDanfeHelper($x, $y, $w, $h, "VALOR DA COFINS", "vCOFINS");
1896
        }
1897
        $x = $this->impostoDanfeHelper($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...
1898
1899
        return ($y+$h);
1900
    } //fim impostoDANFE
1901
1902
    /**
1903
     * transporteDANFE
1904
     * Monta o campo de transportes da DANFE (retrato e paisagem)
1905
     *
1906
     * @name   transporteDANFE
1907
     * @param  float $x Posição horizontal canto esquerdo
1908
     * @param  float $y Posição vertical canto superior
1909
     * @return float Posição vertical final
1910
     */
1911
    protected function transporteDANFE($x, $y)
1912
    {
1913
        $oldX = $x;
1914
        if ($this->orientacao == 'P') {
1915
            $maxW = $this->wPrint;
1916
        } else {
1917
            $maxW = $this->wPrint - $this->wCanhoto;
1918
        }
1919
        //#####################################################################
1920
        //TRANSPORTADOR / VOLUMES TRANSPORTADOS
1921
        $texto = "TRANSPORTADOR / VOLUMES TRANSPORTADOS";
1922
        $w = $maxW;
1923
        $h = 7;
1924
        $aFont = ['font'=>$this->fontePadrao, 'size'=>7, 'style'=>'B'];
1925
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 0, '');
1926
        //NOME / RAZÃO SOCIAL
1927
        $w1 = $maxW*0.29;
1928
        $y += 3;
1929
        $texto = 'NOME / RAZÃO SOCIAL';
1930
        $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
1931
        $this->pdf->textBox($x, $y, $w1, $h, $texto, $aFont, 'T', 'L', 1, '');
1932
        if (isset($this->transporta)) {
1933
            $texto = ! empty($this->transporta->getElementsByTagName("xNome")->item(0)->nodeValue) ?
1934
                    $this->transporta->getElementsByTagName("xNome")->item(0)->nodeValue : '';
1935
        } else {
1936
            $texto = '';
1937
        }
1938
        $aFont = ['font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B'];
1939
        $this->pdf->textBox($x, $y, $w1, $h, $texto, $aFont, 'B', 'L', 0, '');
1940
        //FRETE POR CONTA
1941
        $x += $w1;
1942
        $w2 = $maxW*0.15;
1943
        $texto = 'FRETE';
1944
        $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
1945
        $this->pdf->textBox($x, $y, $w2, $h, $texto, $aFont, 'T', 'L', 1, '');
1946
        $tipoFrete = ! empty($this->transp->getElementsByTagName("modFrete")->item(0)->nodeValue) ?
1947
                $this->transp->getElementsByTagName("modFrete")->item(0)->nodeValue : '0';
1948
        switch ($tipoFrete) {
1949
            case 0:
1950
                $texto = "0-Por conta do Rem";
1951
                break;
1952
            case 1:
1953
                $texto = "1-Por conta do Dest";
1954
                break;
1955
            case 2:
1956
                $texto = "2-Por conta de Terceiros";
1957
                break;
1958
            case 3:
1959
                $texto = "3-Próprio por conta do Rem";
1960
                break;
1961
            case 4:
1962
                $texto = "4-Próprio por conta do Dest";
1963
                break;
1964
            case 9:
1965
                $texto = "9-Sem Transporte";
1966
                break;
1967
        }
1968
        $aFont = ['font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B'];
1969
        $this->pdf->textBox($x, $y, $w2, $h, $texto, $aFont, 'C', 'C', 1, '');
1970
        //CÓDIGO ANTT
1971
        $x += $w2;
1972
        $texto = 'CÓDIGO ANTT';
1973
        $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
1974
        $this->pdf->textBox($x, $y, $w2, $h, $texto, $aFont, 'T', 'L', 1, '');
1975
        if (isset($this->veicTransp)) {
1976
            $texto = ! empty($this->veicTransp->getElementsByTagName("RNTC")->item(0)->nodeValue) ?
1977
                    $this->veicTransp->getElementsByTagName("RNTC")->item(0)->nodeValue : '';
1978
        } else {
1979
            $texto = '';
1980
        }
1981
        $aFont = ['font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B'];
1982
        $this->pdf->textBox($x, $y, $w2, $h, $texto, $aFont, 'B', 'C', 0, '');
1983
        //PLACA DO VEÍC
1984
        $x += $w2;
1985
        $texto = 'PLACA DO VEÍCULO';
1986
        $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
1987
        $this->pdf->textBox($x, $y, $w2, $h, $texto, $aFont, 'T', 'L', 1, '');
1988
        if (isset($this->veicTransp)) {
1989
            $texto = ! empty($this->veicTransp->getElementsByTagName("placa")->item(0)->nodeValue) ?
1990
                    $this->veicTransp->getElementsByTagName("placa")->item(0)->nodeValue : '';
1991
        } elseif (isset($this->reboque)) {
1992
            $texto = ! empty($this->reboque->getElementsByTagName("placa")->item(0)->nodeValue) ?
1993
                    $this->reboque->getElementsByTagName("placa")->item(0)->nodeValue : '';
1994
        } else {
1995
            $texto = '';
1996
        }
1997
        $aFont = ['font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B'];
1998
        $this->pdf->textBox($x, $y, $w2, $h, $texto, $aFont, 'B', 'C', 0, '');
1999
        //UF
2000
        $x += $w2;
2001
        $w3 = round($maxW*0.04, 0);
2002
        $texto = 'UF';
2003
        $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
2004
        $this->pdf->textBox($x, $y, $w3, $h, $texto, $aFont, 'T', 'L', 1, '');
2005
        if (isset($this->veicTransp)) {
2006
            $texto = ! empty($this->veicTransp->getElementsByTagName("UF")->item(0)->nodeValue) ?
2007
                    $this->veicTransp->getElementsByTagName("UF")->item(0)->nodeValue : '';
2008
        } elseif (isset($this->reboque)) {
2009
            $texto = ! empty($this->reboque->getElementsByTagName("UF")->item(0)->nodeValue) ?
2010
                    $this->reboque->getElementsByTagName("UF")->item(0)->nodeValue : '';
2011
        } else {
2012
            $texto = '';
2013
        }
2014
        $aFont = ['font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B'];
2015
        $this->pdf->textBox($x, $y, $w3, $h, $texto, $aFont, 'B', 'C', 0, '');
2016
        //CNPJ / CPF
2017
        $x += $w3;
2018
        $w = $maxW-($w1+3*$w2+$w3);
2019
        $texto = 'CNPJ / CPF';
2020
        $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
2021
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 1, '');
2022
        if (isset($this->transporta)) {
2023
            $texto = ! empty($this->transporta->getElementsByTagName("CNPJ")->item(0)->nodeValue) ?
2024
                    $this->formatField(
2025
                        $this->transporta->getElementsByTagName("CNPJ")->item(0)->nodeValue,
2026
                        "##.###.###/####-##"
2027
                    ) : '';
2028
            if ($texto == '') {
2029
                $texto = ! empty($this->transporta->getElementsByTagName("CPF")->item(0)->nodeValue) ?
2030
                        $this->formatField(
2031
                            $this->transporta->getElementsByTagName("CPF")->item(0)->nodeValue,
2032
                            "###.###.###-##"
2033
                        ) : '';
2034
            }
2035
        } else {
2036
            $texto = '';
2037
        }
2038
        $aFont = ['font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B'];
2039
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'B', 'C', 0, '');
2040
        //#####################################################################
2041
        //ENDEREÇO
2042
        $y += $h;
2043
        $x = $oldX;
2044
        $h = 7;
2045
        $w1 = $maxW*0.44;
2046
        $texto = 'ENDEREÇO';
2047
        $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
2048
        $this->pdf->textBox($x, $y, $w1, $h, $texto, $aFont, 'T', 'L', 1, '');
2049
        if (isset($this->transporta)) {
2050
            $texto = ! empty($this->transporta->getElementsByTagName("xEnder")->item(0)->nodeValue) ?
2051
                    $this->transporta->getElementsByTagName("xEnder")->item(0)->nodeValue : '';
2052
        } else {
2053
            $texto = '';
2054
        }
2055
        $aFont = ['font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B'];
2056
        $this->pdf->textBox($x, $y, $w1, $h, $texto, $aFont, 'B', 'L', 0, '');
2057
        //MUNICÍPIO
2058
        $x += $w1;
2059
        $w2 = round($maxW*0.30, 0);
2060
        $texto = 'MUNICÍPIO';
2061
        $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
2062
        $this->pdf->textBox($x, $y, $w2, $h, $texto, $aFont, 'T', 'L', 1, '');
2063
        if (isset($this->transporta)) {
2064
            $texto = ! empty($this->transporta->getElementsByTagName("xMun")->item(0)->nodeValue) ?
2065
                    $this->transporta->getElementsByTagName("xMun")->item(0)->nodeValue : '';
2066
        } else {
2067
            $texto = '';
2068
        }
2069
        $aFont = ['font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B'];
2070
        $this->pdf->textBox($x, $y, $w2, $h, $texto, $aFont, 'B', 'C', 0, '');
2071
        //UF
2072
        $x += $w2;
2073
        $w3 = round($maxW*0.04, 0);
2074
        $texto = 'UF';
2075
        $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
2076
        $this->pdf->textBox($x, $y, $w3, $h, $texto, $aFont, 'T', 'L', 1, '');
2077
        if (isset($this->transporta)) {
2078
            $texto = ! empty($this->transporta->getElementsByTagName("UF")->item(0)->nodeValue) ?
2079
                    $this->transporta->getElementsByTagName("UF")->item(0)->nodeValue : '';
2080
        } else {
2081
            $texto = '';
2082
        }
2083
        $aFont = ['font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B'];
2084
        $this->pdf->textBox($x, $y, $w3, $h, $texto, $aFont, 'B', 'C', 0, '');
2085
        //INSCRIÇÃO ESTADUAL
2086
        $x += $w3;
2087
        $w = $maxW-($w1+$w2+$w3);
2088
        $texto = 'INSCRIÇÃO ESTADUAL';
2089
        $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
2090
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 1, '');
2091
        $texto = '';
2092
        if (isset($this->transporta)) {
2093
            if (! empty($this->transporta->getElementsByTagName("IE")->item(0)->nodeValue)) {
2094
                $texto = $this->transporta->getElementsByTagName("IE")->item(0)->nodeValue;
2095
            }
2096
        }
2097
        $aFont = ['font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B'];
2098
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'B', 'C', 0, '');
2099
        //Tratar Multiplos volumes
2100
        $volumes = $this->transp->getElementsByTagName('vol');
2101
        $quantidade = 0;
2102
        $especie = '';
2103
        $marca = '';
2104
        $numero = '';
2105
        $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...
2106
        $pesoBruto=0;
2107
        $pesoLiquido=0;
2108
        foreach ($volumes as $volume) {
2109
            $quantidade += ! empty($volume->getElementsByTagName("qVol")->item(0)->nodeValue) ?
2110
                    $volume->getElementsByTagName("qVol")->item(0)->nodeValue : 0;
2111
            $pesoBruto += ! empty($volume->getElementsByTagName("pesoB")->item(0)->nodeValue) ?
2112
                    $volume->getElementsByTagName("pesoB")->item(0)->nodeValue : 0;
2113
            $pesoLiquido += ! empty($volume->getElementsByTagName("pesoL")->item(0)->nodeValue) ?
2114
                    $volume->getElementsByTagName("pesoL")->item(0)->nodeValue : 0;
2115
            $texto = ! empty($this->transp->getElementsByTagName("esp")->item(0)->nodeValue) ?
2116
                    $this->transp->getElementsByTagName("esp")->item(0)->nodeValue : '';
2117
            if ($texto != $especie && $especie != '') {
2118
                //tem várias especies
2119
                $especie = 'VARIAS';
2120
            } else {
2121
                $especie = $texto;
2122
            }
2123
            $texto = ! empty($this->transp->getElementsByTagName("marca")->item(0)->nodeValue) ?
2124
                    $this->transp->getElementsByTagName("marca")->item(0)->nodeValue : '';
2125
            if ($texto != $marca && $marca != '') {
2126
                //tem várias especies
2127
                $marca = 'VARIAS';
2128
            } else {
2129
                $marca = $texto;
2130
            }
2131
            $texto = ! empty($this->transp->getElementsByTagName("nVol")->item(0)->nodeValue) ?
2132
                    $this->transp->getElementsByTagName("nVol")->item(0)->nodeValue : '';
2133
            if ($texto != $numero && $numero != '') {
2134
                //tem várias especies
2135
                $numero = 'VARIOS';
2136
            } else {
2137
                $numero = $texto;
2138
            }
2139
        }
2140
2141
        //#####################################################################
2142
        //QUANTIDADE
2143
        $y += $h;
2144
        $x = $oldX;
2145
        $h = 7;
2146
        $w1 = round($maxW*0.10, 0);
2147
        $texto = 'QUANTIDADE';
2148
        $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
2149
        $this->pdf->textBox($x, $y, $w1, $h, $texto, $aFont, 'T', 'L', 1, '');
2150
        if (!empty($quantidade)) {
2151
            $texto = $quantidade;
2152
            $aFont = ['font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B'];
2153
            $this->pdf->textBox($x, $y, $w1, $h, $texto, $aFont, 'B', 'C', 0, '');
2154
        }
2155
        //ESPÉCIE
2156
        $x += $w1;
2157
        $w2 = round($maxW*0.17, 0);
2158
        $texto = 'ESPÉCIE';
2159
        $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
2160
        $this->pdf->textBox($x, $y, $w2, $h, $texto, $aFont, 'T', 'L', 1, '');
2161
        $texto = $especie;
2162
        $aFont = ['font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B'];
2163
        $this->pdf->textBox($x, $y, $w2, $h, $texto, $aFont, 'B', 'C', 0, '');
2164
        //MARCA
2165
        $x += $w2;
2166
        $texto = 'MARCA';
2167
        $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
2168
        $this->pdf->textBox($x, $y, $w2, $h, $texto, $aFont, 'T', 'L', 1, '');
2169
        $texto = ! empty($this->transp->getElementsByTagName("marca")->item(0)->nodeValue) ?
2170
                $this->transp->getElementsByTagName("marca")->item(0)->nodeValue : '';
2171
        $aFont = ['font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B'];
2172
        $this->pdf->textBox($x, $y, $w2, $h, $texto, $aFont, 'B', 'C', 0, '');
2173
        //NUMERAÇÃO
2174
        $x += $w2;
2175
        $texto = 'NUMERAÇÃO';
2176
        $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
2177
        $this->pdf->textBox($x, $y, $w2, $h, $texto, $aFont, 'T', 'L', 1, '');
2178
        $texto = $numero;
2179
        $aFont = ['font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B'];
2180
        $this->pdf->textBox($x, $y, $w2, $h, $texto, $aFont, 'B', 'C', 0, '');
2181
        //PESO BRUTO
2182
        $x += $w2;
2183
        $w3 = round($maxW*0.20, 0);
2184
        $texto = 'PESO BRUTO';
2185
        $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
2186
        $this->pdf->textBox($x, $y, $w3, $h, $texto, $aFont, 'T', 'L', 1, '');
2187
        if (is_numeric($pesoBruto) && $pesoBruto > 0) {
2188
            $texto = number_format($pesoBruto, 3, ",", ".");
2189
        } else {
2190
            $texto = '';
2191
        }
2192
        $aFont = ['font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B'];
2193
        $this->pdf->textBox($x, $y, $w3, $h, $texto, $aFont, 'B', 'R', 0, '');
2194
        //PESO LÍQUIDO
2195
        $x += $w3;
2196
        $w = $maxW -($w1+3*$w2+$w3);
2197
        $texto = 'PESO LÍQUIDO';
2198
        $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
2199
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 1, '');
2200
        if (is_numeric($pesoLiquido) && $pesoLiquido > 0) {
2201
            $texto = number_format($pesoLiquido, 3, ",", ".");
2202
        } else {
2203
            $texto = '';
2204
        }
2205
        $aFont = ['font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B'];
2206
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'B', 'R', 0, '');
2207
        return ($y+$h);
2208
    } //fim transporteDANFE
2209
2210
2211
2212
    protected function descricaoProdutoHelper($origem, $campo, $formato)
2213
    {
2214
        $valor_original = $origem->getElementsByTagName($campo)->item(0);
2215
        if (!isset($valor_original)) {
2216
            return "";
2217
        }
2218
        $valor_original = $valor_original->nodeValue;
2219
        $valor = ! empty($valor_original) ? number_format($valor_original, 2, ",", ".") : '';
2220
2221
        if ($valor != "") {
2222
            return sprintf($formato, $valor);
2223
        }
2224
        return "";
2225
    }
2226
2227
    /**
2228
     * descricaoProduto
2229
     * Monta a string de descrição de cada Produto
2230
     *
2231
     * @name   descricaoProduto
2232
     * @param  DOMNode itemProd
2233
     * @return string descricao do produto
2234
     */
2235
    protected function descricaoProduto($itemProd)
2236
    {
2237
        $prod = $itemProd->getElementsByTagName('prod')->item(0);
2238
        $ICMS = $itemProd->getElementsByTagName("ICMS")->item(0);
2239
        $ICMSUFDest = $itemProd->getElementsByTagName("ICMSUFDest")->item(0);
2240
        $impostos = '';
2241
2242
        if (!empty($ICMS)) {
2243
            $impostos .= $this->descricaoProdutoHelper($ICMS, "vBCFCP", " BcFcp=%s");
2244
            $impostos .= $this->descricaoProdutoHelper($ICMS, "pFCP", " pFcp=%s%%");
2245
            $impostos .= $this->descricaoProdutoHelper($ICMS, "vFCP", " vFcp=%s");
2246
            $impostos .= $this->descricaoProdutoHelper($ICMS, "pRedBC", " pRedBC=%s%%");
2247
            $impostos .= $this->descricaoProdutoHelper($ICMS, "pMVAST", " IVA/MVA=%s%%");
2248
            $impostos .= $this->descricaoProdutoHelper($ICMS, "pICMSST", " pIcmsSt=%s%%");
2249
            $impostos .= $this->descricaoProdutoHelper($ICMS, "vBCST", " BcIcmsSt=%s");
2250
            $impostos .= $this->descricaoProdutoHelper($ICMS, "vICMSST", " vIcmsSt=%s");
2251
            $impostos .= $this->descricaoProdutoHelper($ICMS, "vBCFCPST", " BcFcpSt=%s");
2252
            $impostos .= $this->descricaoProdutoHelper($ICMS, "pFCPST", " pFcpSt=%s%%");
2253
            $impostos .= $this->descricaoProdutoHelper($ICMS, "vFCPST", " vFcpSt=%s");
2254
            $impostos .= $this->descricaoProdutoHelper($ICMS, "vBCSTRet", " vBcStRet=%s");
2255
            $impostos .= $this->descricaoProdutoHelper($ICMS, "pST", " pSt=%s");
2256
            $impostos .= $this->descricaoProdutoHelper($ICMS, "vICMSSTRet", " vIcmsStRet=%s");
2257
        }
2258
        if (!empty($ICMSUFDest)) {
2259
            $impostos .= $this->descricaoProdutoHelper($ICMSUFDest, "pFCPUFDest", " pFCPUFDest=%s%%");
2260
            $impostos .= $this->descricaoProdutoHelper($ICMSUFDest, "pICMSUFDest", " pICMSUFDest=%s%%");
2261
            $impostos .= $this->descricaoProdutoHelper($ICMSUFDest, "pICMSInterPart", " pICMSInterPart=%s%%");
2262
            $impostos .= $this->descricaoProdutoHelper($ICMSUFDest, "vFCPUFDest", " vFCPUFDest=%s");
2263
            $impostos .= $this->descricaoProdutoHelper($ICMSUFDest, "vICMSUFDest", " vICMSUFDest=%s");
2264
            $impostos .= $this->descricaoProdutoHelper($ICMSUFDest, "vICMSUFRemet", " vICMSUFRemet=%s");
2265
        }
2266
        $infAdProd = ! empty($itemProd->getElementsByTagName('infAdProd')->item(0)->nodeValue)
2267
            ? substr(
2268
                $this->anfaveaDANFE($itemProd->getElementsByTagName('infAdProd')->item(0)->nodeValue),
2269
                0,
2270
                500
2271
            )
2272
            : '';
2273
        if (! empty($infAdProd)) {
2274
            $infAdProd = trim($infAdProd);
2275
            $infAdProd .= ' ';
2276
        }
2277
        $loteTxt ='';
2278
        $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...
2279
        if (!empty($prod->getElementsByTagName("rastro"))) {
2280
            $rastro = $prod->getElementsByTagName("rastro");
2281
            $i = 0;
2282
            while ($i < $rastro->length) {
2283
                $loteTxt .= $this->getTagValue($rastro->item($i), 'nLote', ' Lote: ');
2284
                $loteTxt .= $this->getTagValue($rastro->item($i), 'qLote', ' Quant: ');
2285
                $loteTxt .= $this->getTagDate($rastro->item($i), 'dFab', ' Fab: ');
2286
                $loteTxt .= $this->getTagDate($rastro->item($i), 'dVal', ' Val: ');
2287
                $loteTxt .= $this->getTagValue($rastro->item($i), 'vPMC', ' PMC: ');
2288
                $i++;
2289
            }
2290
            if ($loteTxt != '') {
2291
                $loteTxt.= ' ';
2292
            }
2293
        }
2294
        //NT2013.006 FCI
2295
        $nFCI = (! empty($itemProd->getElementsByTagName('nFCI')->item(0)->nodeValue)) ?
2296
                ' FCI:'.$itemProd->getElementsByTagName('nFCI')->item(0)->nodeValue : '';
2297
        $tmp_ad=$infAdProd . ($this->descProdInfoComplemento ? $loteTxt . $impostos . $nFCI : '');
2298
        $texto = $prod->getElementsByTagName("xProd")->item(0)->nodeValue . (strlen($tmp_ad)!=0?"\n    ".$tmp_ad:'');
2299
        //decodifica os caracteres html no xml
2300
        $texto = html_entity_decode($texto);
2301
        if ($this->descProdQuebraLinha) {
2302
            $texto = str_replace(";", "\n", $texto);
2303
        }
2304
        return $texto;
2305
    }
2306
2307
    /**
2308
     * itensDANFE
2309
     * Monta o campo de itens da DANFE (retrato e paisagem)
2310
     *
2311
     * @name   itensDANFE
2312
     * @param  float $x       Posição horizontal canto esquerdo
2313
     * @param  float $y       Posição vertical canto superior
2314
     * @param  float $nInicio Número do item inicial
2315
     * @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...
2316
     * @param  float $hmax    Altura máxima do campo de itens em mm
2317
     * @return float Posição vertical final
2318
     */
2319
    protected function itensDANFE($x, $y, &$nInicio, $hmax, $pag = 0, $totpag = 0, $hCabecItens = 7)
2320
    {
2321
        $oldX = $x;
2322
        $oldY = $y;
2323
        $totItens = $this->det->length;
2324
        //#####################################################################
2325
        //DADOS DOS PRODUTOS / SERVIÇOS
2326
        $texto = "DADOS DOS PRODUTOS / SERVIÇOS ";
2327
        if ($this->orientacao == 'P') {
2328
            $w = $this->wPrint;
2329
        } else {
2330
            if ($nInicio < 2) { // primeira página
2331
                $w = $this->wPrint - $this->wCanhoto;
2332
            } else { // páginas seguintes
2333
                $w = $this->wPrint;
2334
            }
2335
        }
2336
        $h = 4;
2337
        $aFont = ['font'=>$this->fontePadrao, 'size'=>7, 'style'=>'B'];
2338
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 0, '');
2339
        $y += 3;
2340
        //desenha a caixa dos dados dos itens da NF
2341
        $hmax += 1;
2342
        $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...
2343
        $this->pdf->textBox($x, $y, $w, $hmax);
2344
        //##################################################################################
2345
        // cabecalho LOOP COM OS DADOS DOS PRODUTOS
2346
        //CÓDIGO PRODUTO
2347
        $texto = "CÓDIGO PRODUTO";
2348
        $w1 = round($w*0.09, 0);
2349
        $h = 4;
2350
        $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
2351
        $this->pdf->textBox($x, $y, $w1, $h, $texto, $aFont, 'C', 'C', 0, '', false);
2352
        $this->pdf->line($x+$w1, $y, $x+$w1, $y+$hmax);
2353
        //DESCRIÇÃO DO PRODUTO / SERVIÇO
2354
        $x += $w1;
2355
        $w2 = round($w*0.28, 0);
2356
        $texto = 'DESCRIÇÃO DO PRODUTO / SERVIÇO';
2357
        $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
2358
        $this->pdf->textBox($x, $y, $w2, $h, $texto, $aFont, 'C', 'C', 0, '', false);
2359
        $this->pdf->line($x+$w2, $y, $x+$w2, $y+$hmax);
2360
        //NCM/SH
2361
        $x += $w2;
2362
        $w3 = round($w*0.06, 0);
2363
        $texto = 'NCM/SH';
2364
        $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
2365
        $this->pdf->textBox($x, $y, $w3, $h, $texto, $aFont, 'C', 'C', 0, '', false);
2366
        $this->pdf->line($x+$w3, $y, $x+$w3, $y+$hmax);
2367
        //O/CST ou O/CSOSN
2368
        $x += $w3;
2369
        $w4 = round($w*0.05, 0);
2370
        $texto = 'O/CSOSN';//Regime do Simples CRT = 1 ou CRT = 2
2371
        if ($this->getTagValue($this->emit, 'CRT') == '3') {
2372
             $texto = 'O/CST';//Regime Normal
2373
        }
2374
        $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
2375
        $this->pdf->textBox($x, $y, $w4, $h, $texto, $aFont, 'C', 'C', 0, '', false);
2376
        $this->pdf->line($x+$w4, $y, $x+$w4, $y+$hmax);
2377
        //CFOP
2378
        $x += $w4;
2379
        $w5 = round($w*0.04, 0);
2380
        $texto = 'CFOP';
2381
        $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
2382
        $this->pdf->textBox($x, $y, $w5, $h, $texto, $aFont, 'C', 'C', 0, '', false);
2383
        $this->pdf->line($x+$w5, $y, $x+$w5, $y+$hmax);
2384
        //UN
2385
        $x += $w5;
2386
        $w6 = round($w*0.03, 0);
2387
        $texto = 'UN';
2388
        $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
2389
        $this->pdf->textBox($x, $y, $w6, $h, $texto, $aFont, 'C', 'C', 0, '', false);
2390
        $this->pdf->line($x+$w6, $y, $x+$w6, $y+$hmax);
2391
        //QUANT
2392
        $x += $w6;
2393
        $w7 = round($w*0.07, 0);
2394
        $texto = 'QUANT';
2395
        $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
2396
        $this->pdf->textBox($x, $y, $w7, $h, $texto, $aFont, 'C', 'C', 0, '', false);
2397
        $this->pdf->line($x+$w7, $y, $x+$w7, $y+$hmax);
2398
        //VALOR UNIT
2399
        $x += $w7;
2400
        $w8 = round($w*0.06, 0);
2401
        $texto = 'VALOR UNIT';
2402
        $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
2403
        $this->pdf->textBox($x, $y, $w8, $h, $texto, $aFont, 'C', 'C', 0, '', false);
2404
        $this->pdf->line($x+$w8, $y, $x+$w8, $y+$hmax);
2405
        //VALOR TOTAL
2406
        $x += $w8;
2407
        $w9 = round($w*0.06, 0);
2408
        $texto = 'VALOR TOTAL';
2409
        $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
2410
        $this->pdf->textBox($x, $y, $w9, $h, $texto, $aFont, 'C', 'C', 0, '', false);
2411
        $this->pdf->line($x+$w9, $y, $x+$w9, $y+$hmax);
2412
        //B.CÁLC ICMS
2413
        $x += $w9;
2414
        $w10 = round($w*0.06, 0);
2415
        $texto = 'B.CÁLC ICMS';
2416
        $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
2417
        $this->pdf->textBox($x, $y, $w10, $h, $texto, $aFont, 'C', 'C', 0, '', false);
2418
        $this->pdf->line($x+$w10, $y, $x+$w10, $y+$hmax);
2419
        //VALOR ICMS
2420
        $x += $w10;
2421
        $w11 = round($w*0.06, 0);
2422
        $texto = 'VALOR ICMS';
2423
        $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
2424
        $this->pdf->textBox($x, $y, $w11, $h, $texto, $aFont, 'C', 'C', 0, '', false);
2425
        $this->pdf->line($x+$w11, $y, $x+$w11, $y+$hmax);
2426
        //VALOR IPI
2427
        $x += $w11;
2428
        $w12 = round($w*0.05, 0);
2429
        $texto = 'VALOR IPI';
2430
        $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
2431
        $this->pdf->textBox($x, $y, $w12, $h, $texto, $aFont, 'C', 'C', 0, '', false);
2432
        $this->pdf->line($x+$w12, $y, $x+$w12, $y+$hmax);
2433
        //ALÍQ. ICMS
2434
        $x += $w12;
2435
        $w13 = round($w*0.035, 0);
2436
        $texto = 'ALÍQ. ICMS';
2437
        $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
2438
        $this->pdf->textBox($x, $y, $w13, $h, $texto, $aFont, 'C', 'C', 0, '', false);
2439
        $this->pdf->line($x+$w13, $y, $x+$w13, $y+$hmax);
2440
        //ALÍQ. IPI
2441
        $x += $w13;
2442
        $w14 = $w-($w1+$w2+$w3+$w4+$w5+$w6+$w7+$w8+$w9+$w10+$w11+$w12+$w13);
2443
        $texto = 'ALÍQ. IPI';
2444
        $this->pdf->textBox($x, $y, $w14, $h, $texto, $aFont, 'C', 'C', 0, '', false);
2445
        $this->pdf->line($oldX, $y+$h+1, $oldX + $w, $y+$h+1);
2446
        $y += 5;
2447
        //##################################################################################
2448
        // LOOP COM OS DADOS DOS PRODUTOS
2449
        $i = 0;
2450
        $hUsado = $hCabecItens;
2451
        $aFont = ['font'=>$this->fontePadrao, 'size'=>7, 'style'=>''];
2452
        foreach ($this->det as $d) {
2453
            if ($i >= $nInicio) {
2454
                $thisItem = $this->det->item($i);
2455
                //carrega as tags do item
2456
                $prod = $thisItem->getElementsByTagName("prod")->item(0);
2457
                $imposto = $this->det->item($i)->getElementsByTagName("imposto")->item(0);
2458
                $ICMS = $imposto->getElementsByTagName("ICMS")->item(0);
2459
                $IPI  = $imposto->getElementsByTagName("IPI")->item(0);
2460
                $textoProduto = trim($this->descricaoProduto($thisItem));
2461
2462
                $linhaDescr = $this->pdf->getNumLines($textoProduto, $w2, $aFont);
2463
                $h = round(($linhaDescr * $this->pdf->fontSize)+ ($linhaDescr * 0.5), 2);
2464
                $hUsado += $h;
2465
2466
                $diffH = $hmax - $hUsado;
2467
2468
                if ($pag != $totpag) {
2469
                    if (1 > $diffH && $i < $totItens) {
2470
                        //ultrapassa a capacidade para uma única página
2471
                        //o restante dos dados serão usados nas proximas paginas
2472
                        $nInicio = $i;
2473
                        break;
2474
                    }
2475
                }
2476
                $y_linha=$y+$h;
2477
                // linha entre itens
2478
                $this->pdf->dashedHLine($oldX, $y_linha, $w, 0.1, 120);
2479
                //corrige o x
2480
                $x=$oldX;
2481
                //codigo do produto
2482
                $texto = $prod->getElementsByTagName("cProd")->item(0)->nodeValue;
2483
                $this->pdf->textBox($x, $y, $w1, $h, $texto, $aFont, 'T', 'C', 0, '');
2484
                $x += $w1;
2485
                //DESCRIÇÃO
2486
                if ($this->orientacao == 'P') {
2487
                    $this->pdf->textBox($x, $y, $w2, $h, $textoProduto, $aFont, 'T', 'L', 0, '', false);
2488
                } else {
2489
                    $this->pdf->textBox($x, $y, $w2, $h, $textoProduto, $aFont, 'T', 'L', 0, '', false);
2490
                }
2491
                $x += $w2;
2492
                //NCM
2493
                $texto = ! empty($prod->getElementsByTagName("NCM")->item(0)->nodeValue) ?
2494
                        $prod->getElementsByTagName("NCM")->item(0)->nodeValue : '';
2495
                $this->pdf->textBox($x, $y, $w3, $h, $texto, $aFont, 'T', 'C', 0, '');
2496
                $x += $w3;
2497
                //CST
2498
                if (isset($ICMS)) {
2499
                    $origem =  $this->getTagValue($ICMS, "orig");
2500
                    $cst =  $this->getTagValue($ICMS, "CST");
2501
                    $csosn =  $this->getTagValue($ICMS, "CSOSN");
2502
                    $texto = $origem.$cst.$csosn;
2503
                    $this->pdf->textBox($x, $y, $w4, $h, $texto, $aFont, 'T', 'C', 0, '');
2504
                }
2505
                //CFOP
2506
                $x += $w4;
2507
                $texto = $prod->getElementsByTagName("CFOP")->item(0)->nodeValue;
2508
                $this->pdf->textBox($x, $y, $w5, $h, $texto, $aFont, 'T', 'C', 0, '');
2509
                //Unidade
2510
                $x += $w5;
2511
                $texto = $prod->getElementsByTagName("uCom")->item(0)->nodeValue;
2512
                $this->pdf->textBox($x, $y, $w6, $h, $texto, $aFont, 'T', 'C', 0, '');
2513
                $x += $w6;
2514
                if ($this->orientacao == 'P') {
2515
                    $alinhamento = 'R';
2516
                } else {
2517
                    $alinhamento = 'R';
2518
                }
2519
                // QTDADE
2520
                $texto = number_format($prod->getElementsByTagName("qCom")->item(0)->nodeValue, 4, ",", ".");
2521
                $this->pdf->textBox($x, $y, $w7, $h, $texto, $aFont, 'T', $alinhamento, 0, '');
2522
                $x += $w7;
2523
                // Valor Unitário
2524
                $texto = number_format($prod->getElementsByTagName("vUnCom")->item(0)->nodeValue, 4, ",", ".");
2525
                $this->pdf->textBox($x, $y, $w8, $h, $texto, $aFont, 'T', $alinhamento, 0, '');
2526
                $x += $w8;
2527
                // Valor do Produto
2528
                $texto = "";
2529
                if (is_numeric($prod->getElementsByTagName("vProd")->item(0)->nodeValue)) {
2530
                    $texto = number_format($prod->getElementsByTagName("vProd")->item(0)->nodeValue, 2, ",", ".");
2531
                }
2532
                $this->pdf->textBox($x, $y, $w9, $h, $texto, $aFont, 'T', $alinhamento, 0, '');
2533
                //Valor da Base de calculo
2534
                $x += $w9;
2535
                if (isset($ICMS)) {
2536
                    $texto = ! empty($ICMS->getElementsByTagName("vBC")->item(0)->nodeValue) ?
2537
                            number_format(
2538
                                $ICMS->getElementsByTagName("vBC")->item(0)->nodeValue,
2539
                                2,
2540
                                ",",
2541
                                "."
2542
                            ) : '0, 00';
2543
                    $this->pdf->textBox($x, $y, $w10, $h, $texto, $aFont, 'T', $alinhamento, 0, '');
2544
                }
2545
                //Valor do ICMS
2546
                $x += $w10;
2547
                if (isset($ICMS)) {
2548
                    $texto = ! empty($ICMS->getElementsByTagName("vICMS")->item(0)->nodeValue) ?
2549
                            number_format(
2550
                                $ICMS->getElementsByTagName("vICMS")->item(0)->nodeValue,
2551
                                2,
2552
                                ",",
2553
                                "."
2554
                            ) : '0, 00';
2555
                    $this->pdf->textBox($x, $y, $w11, $h, $texto, $aFont, 'T', $alinhamento, 0, '');
2556
                }
2557
                //Valor do IPI
2558
                $x += $w11;
2559
                if (isset($IPI)) {
2560
                    $texto = ! empty($IPI->getElementsByTagName("vIPI")->item(0)->nodeValue) ?
2561
                            number_format($IPI->getElementsByTagName("vIPI")->item(0)->nodeValue, 2, ",", ".") :'';
2562
                } else {
2563
                    $texto = '';
2564
                }
2565
                $this->pdf->textBox($x, $y, $w12, $h, $texto, $aFont, 'T', $alinhamento, 0, '');
2566
                // %ICMS
2567
                $x += $w12;
2568
                if (isset($ICMS)) {
2569
                    $texto = ! empty($ICMS->getElementsByTagName("pICMS")->item(0)->nodeValue) ?
2570
                            number_format(
2571
                                $ICMS->getElementsByTagName("pICMS")->item(0)->nodeValue,
2572
                                2,
2573
                                ",",
2574
                                "."
2575
                            ) : '0, 00';
2576
                    $this->pdf->textBox($x, $y, $w13, $h, $texto, $aFont, 'T', 'C', 0, '');
2577
                }
2578
                //%IPI
2579
                $x += $w13;
2580
                if (isset($IPI)) {
2581
                    $texto = ! empty($IPI->getElementsByTagName("pIPI")->item(0)->nodeValue) ?
2582
                            number_format($IPI->getElementsByTagName("pIPI")->item(0)->nodeValue, 2, ",", ".") : '';
2583
                } else {
2584
                    $texto = '';
2585
                }
2586
                $this->pdf->textBox($x, $y, $w14, $h, $texto, $aFont, 'T', 'C', 0, '');
2587
2588
2589
                // Dados do Veiculo Somente para veiculo 0 Km
2590
                $veicProd = $prod->getElementsByTagName("veicProd")->item(0);
2591
                // Tag somente é gerada para veiculo 0k, e só é permitido um veiculo por NF-e por conta do detran
2592
                // Verifica se a Tag existe
2593
                if (!empty($veicProd)) {
2594
                    $this->dadosItenVeiculoDANFE($oldX, $y, $nInicio, $h, $prod);
2595
                }
2596
2597
2598
                $y += $h;
2599
                $i++;
2600
                //incrementa o controle dos itens processados.
2601
                $this->qtdeItensProc++;
2602
            } else {
2603
                $i++;
2604
            }
2605
        }
2606
        return $oldY+$hmax;
2607
    }
2608
2609
2610
    /**
2611
     * dadosItenVeiculoDANFE
2612
     * Coloca os dados do veiculo abaixo do item da NFe. (retrato e paisagem)
2613
     *
2614
     * @param float  $x    Posição horizontal
2615
     *                     canto esquerdo
2616
     * @param float  $y    Posição vertical
2617
     *                     canto superior
2618
     * @param        $nInicio
2619
     * @param float  $h    altura do campo
2620
     * @param object $prod Contendo todos os dados do item
2621
     */
2622
2623
    protected function dadosItenVeiculoDANFE($x, $y, &$nInicio, $h, $prod)
2624
    {
2625
        $oldX = $x;
2626
        $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...
2627
2628
        if ($this->orientacao == 'P') {
2629
            $w = $this->wPrint;
2630
        } else {
2631
            if ($nInicio < 2) { // primeira página
2632
                $w = $this->wPrint - $this->wCanhoto;
2633
            } else { // páginas seguintes
2634
                $w = $this->wPrint;
2635
            }
2636
        }
2637
2638
        $aFont = ['font'=>$this->fontePadrao, 'size'=>7, 'style'=>''];
2639
2640
        $w1 = round($w*0.09, 0);
2641
2642
        // Tabela Renavam Combustivel
2643
        $renavamCombustivel = [
2644
            1=>'ALCOOL',
2645
            2=>'GASOLINA',
2646
            3=>'DIESEL',
2647
            4=>'GASOGENIO',
2648
            5=>'GAS METANO',
2649
            6=>'ELETRICO/FONTE INTERNA',
2650
            7=>'ELETRICO/FONTE EXTERNA',
2651
            8=>'GASOL/GAS NATURAL COMBUSTIVEL',
2652
            9=>'ALCOOL/GAS NATURAL COMBUSTIVEL',
2653
            10=>'DIESEL/GAS NATURAL COMBUSTIVEL',
2654
            11=>'VIDE/CAMPO/OBSERVACAO',
2655
            12=>'ALCOOL/GAS NATURAL VEICULAR',
2656
            13=>'GASOLINA/GAS NATURAL VEICULAR',
2657
            14=>'DIESEL/GAS NATURAL VEICULAR',
2658
            15=>'GAS NATURAL VEICULAR',
2659
            16=>'ALCOOL/GASOLINA',
2660
            17=>'GASOLINA/ALCOOL/GAS NATURAL',
2661
            18=>'GASOLINA/ELETRICO'
2662
        ];
2663
2664
        $renavamEspecie = [
2665
            1=>'PASSAGEIRO',
2666
            2=>'CARGA',
2667
            3=>'MISTO',
2668
            4=>'CORRIDA',
2669
            5=>'TRACAO',
2670
            6=>'ESPECIAL',
2671
            7=>'COLECAO'
2672
        ];
2673
2674
        $renavamTiposVeiculos = [
2675
            1=>'BICICLETA',
2676
            2=>'CICLOMOTOR',
2677
            3=>'MOTONETA',
2678
            4=>'MOTOCICLETA',
2679
            5=>'TRICICLO',
2680
            6=>'AUTOMOVEL',
2681
            7=>'MICROONIBUS',
2682
            8=>'ONIBUS',
2683
            9=>'BONDE',
2684
            10=>'REBOQUE',
2685
            11=>'SEMI-REBOQUE',
2686
            12=>'CHARRETE',
2687
            13=>'CAMIONETA',
2688
            14=>'CAMINHAO',
2689
            15=>'CARROCA',
2690
            16=>'CARRO DE MAO',
2691
            17=>'CAMINHAO TRATOR',
2692
            18=>'TRATOR DE RODAS',
2693
            19=>'TRATOR DE ESTEIRAS',
2694
            20=>'TRATOR MISTO',
2695
            21=>'QUADRICICLO',
2696
            22=>'CHASSI/PLATAFORMA',
2697
            23=>'CAMINHONETE',
2698
            24=>'SIDE-CAR',
2699
            25=>'UTILITARIO',
2700
            26=>'MOTOR-CASA'
2701
        ];
2702
2703
        $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...
2704
            'F'=>'FOSCA',
2705
            'S'=>'SÓLIDA',
2706
            'P'=>'PEROLIZADA',
2707
            'M'=>'METALICA',
2708
        ];
2709
2710
        $veicProd = $prod->getElementsByTagName("veicProd")->item(0);
2711
2712
        $veiculoChassi = $veicProd->getElementsByTagName("chassi")->item(0)->nodeValue;
2713
        $veiculoCor = $veicProd->getElementsByTagName("xCor")->item(0)->nodeValue;
2714
        $veiculoCilindrada = $veicProd->getElementsByTagName("cilin")->item(0)->nodeValue;
2715
        $veiculoCmkg = $veicProd->getElementsByTagName("CMT")->item(0)->nodeValue;
2716
        $veiculoTipo = $veicProd->getElementsByTagName("tpVeic")->item(0)->nodeValue;
2717
2718
        $veiculoMotor = $veicProd->getElementsByTagName("nMotor")->item(0)->nodeValue;
2719
        $veiculoRenavam = $veicProd->getElementsByTagName("cMod")->item(0)->nodeValue;
2720
        $veiculoHp = $veicProd->getElementsByTagName("pot")->item(0)->nodeValue;
2721
        $veiculoPlaca = ''; //$veiculo->getElementsByTagName("CMT")->item(0)->nodeValue;
2722
        $veiculoTipoPintura = $veicProd->getElementsByTagName("tpPint")->item(0)->nodeValue;
2723
        $veiculoMarcaModelo = $prod->getElementsByTagName("xProd")->item(0)->nodeValue;
2724
        $veiculoEspecie = $veicProd->getElementsByTagName("espVeic")->item(0)->nodeValue;
2725
        $veiculoCombustivel = $veicProd->getElementsByTagName("tpComb")->item(0)->nodeValue;
2726
        $veiculoSerial = $veicProd->getElementsByTagName("nSerie")->item(0)->nodeValue;
2727
        $veiculoFabricacao = $veicProd->getElementsByTagName("anoFab")->item(0)->nodeValue;
2728
        $veiculoModelo = $veicProd->getElementsByTagName("anoMod")->item(0)->nodeValue;
2729
        $veiculoDistancia = $veicProd->getElementsByTagName("dist")->item(0)->nodeValue;
2730
2731
        $x = $oldX;
2732
2733
        $yVeic = $y + $h;
2734
        $texto = 'Chassi: ............: ' . $veiculoChassi;
2735
        $this->pdf->textBox($x, $yVeic, $w1+40, $h, $texto, $aFont, 'T', 'L', 0, '');
2736
        $yVeic += $h;
2737
        $texto = 'Cor...................: ' . $veiculoCor;
2738
        $this->pdf->textBox($x, $yVeic, $w1+40, $h, $texto, $aFont, 'T', 'L', 0, '');
2739
        $yVeic += $h;
2740
        $texto = 'Cilindrada........: ' . $veiculoCilindrada;
2741
        $this->pdf->textBox($x, $yVeic, $w1+40, $h, $texto, $aFont, 'T', 'L', 0, '');
2742
        $yVeic += $h;
2743
        $texto = 'Cmkg...............: ' . $veiculoCmkg;
2744
        $this->pdf->textBox($x, $yVeic, $w1+40, $h, $texto, $aFont, 'T', 'L', 0, '');
2745
        $yVeic += $h;
2746
        $texto = 'Tipo.................: ' . ($renavamTiposVeiculos[intval($veiculoTipo)] ?? $veiculoTipo);
2747
         $this->pdf->textBox($x, $yVeic, $w1+40, $h, $texto, $aFont, 'T', 'L', 0, '');
2748
        $yVeic = $y + $h;
2749
        $xVeic = $x + 65;
2750
        $texto = 'Nº Motor: .........: ' . $veiculoMotor;
2751
        $this->pdf->textBox($xVeic, $yVeic, $w1+50, $h, $texto, $aFont, 'T', 'L', 0, '');
2752
        $yVeic += $h;
2753
        $texto = 'Renavam...........: ' . $veiculoRenavam;
2754
        $this->pdf->textBox($xVeic, $yVeic, $w1+50, $h, $texto, $aFont, 'T', 'L', 0, '');
2755
        $yVeic += $h;
2756
        $texto = 'HP.....................: ' . $veiculoHp;
2757
        $this->pdf->textBox($xVeic, $yVeic, $w1+50, $h, $texto, $aFont, 'T', 'L', 0, '');
2758
        $yVeic += $h;
2759
        $texto = 'Placa.................: ' . $veiculoPlaca;
2760
        $this->pdf->textBox($xVeic, $yVeic, $w1+50, $h, $texto, $aFont, 'T', 'L', 0, '');
2761
        $yVeic += $h;
2762
        $texto = 'Tipo Pintura......: ' . ($renavamEspecie[intval($veiculoTipoPintura)] ?? $veiculoTipoPintura);
2763
        $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...
2764
        $yVeic = $y + $h;
2765
        $xVeic = $xVeic + 55;
2766
        $texto = 'Marca / Modelo.....: ' . $veiculoMarcaModelo;
2767
        $this->pdf->textBox($xVeic, $yVeic, $w1+50, $h, $texto, $aFont, 'T', 'L', 0, '');
2768
        $yVeic += $h;
2769
        $texto = 'Especie..................: ' . ($renavamEspecie[intval($veiculoEspecie)] ?? $veiculoEspecie);
2770
        $this->pdf->textBox($xVeic, $yVeic, $w1+50, $h, $texto, $aFont, 'T', 'L', 0, '');
2771
        $yVeic += $h;
2772
        $texto = 'Combustivel..........: ' . ($renavamCombustivel[intval($veiculoCombustivel)] ?? $veiculoCombustivel);
2773
        $this->pdf->textBox($xVeic, $yVeic, $w1+50, $h, $texto, $aFont, 'T', 'L', 0, '');
2774
        $yVeic += $h;
2775
        $texto = 'Serial.....................: ' . $veiculoSerial;
2776
        $this->pdf->textBox($xVeic, $yVeic, $w1+50, $h, $texto, $aFont, 'T', 'L', 0, '');
2777
        $yVeic += $h;
2778
        $texto = 'Ano Fab/Mod........: '. $veiculoFabricacao . '/' . $veiculoModelo;
2779
        $this->pdf->textBox($xVeic, $yVeic, $w1+50, $h, $texto, $aFont, 'T', 'L', 0, '');
2780
        $yVeic += $h;
2781
        $texto = 'Distancia Entre Eixos(mm)..: '. $veiculoDistancia;
2782
        $this->pdf->textBox($xVeic, $yVeic, $w1+50, $h, $texto, $aFont, 'T', 'L', 0, '');
2783
    }
2784
2785
    /**
2786
     * issqnDANFE
2787
     * Monta o campo de serviços do DANFE
2788
     *
2789
     * @name   issqnDANFE (retrato e paisagem)
2790
     * @param  float $x Posição horizontal canto esquerdo
2791
     * @param  float $y Posição vertical canto superior
2792
     * @return float Posição vertical final
2793
     */
2794
    protected function issqnDANFE($x, $y)
2795
    {
2796
        $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...
2797
        //#####################################################################
2798
        //CÁLCULO DO ISSQN
2799
        $texto = "CÁLCULO DO ISSQN";
2800
        $w = $this->wPrint;
2801
        $h = 7;
2802
        $aFont = ['font'=>$this->fontePadrao, 'size'=>7, 'style'=>'B'];
2803
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 0, '');
2804
        //INSCRIÇÃO MUNICIPAL
2805
        $y += 3;
2806
        $w = round($this->wPrint*0.23, 0);
2807
        $texto = 'INSCRIÇÃO MUNICIPAL';
2808
        $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
2809
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 1, '');
2810
        //inscrição municipal
2811
        $texto = ! empty($this->emit->getElementsByTagName("IM")->item(0)->nodeValue) ?
2812
                $this->emit->getElementsByTagName("IM")->item(0)->nodeValue : '';
2813
        $aFont = ['font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B'];
2814
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'B', 'L', 0, '');
2815
        //VALOR TOTAL DOS SERVIÇOS
2816
        $x += $w;
2817
        $texto = 'VALOR TOTAL DOS SERVIÇOS';
2818
        $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
2819
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 1, '');
2820
        if (isset($this->ISSQNtot)) {
2821
            $texto = ! empty($this->ISSQNtot->getElementsByTagName("vServ")->item(0)->nodeValue) ?
2822
                    $this->ISSQNtot->getElementsByTagName("vServ")->item(0)->nodeValue : '';
2823
            $texto = number_format($texto, 2, ",", ".");
2824
        } else {
2825
            $texto = '';
2826
        }
2827
        $aFont = ['font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B'];
2828
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'B', 'R', 0, '');
2829
        //BASE DE CÁLCULO DO ISSQN
2830
        $x += $w;
2831
        $texto = 'BASE DE CÁLCULO DO ISSQN';
2832
        $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
2833
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 1, '');
2834
        if (isset($this->ISSQNtot)) {
2835
            $texto = ! empty($this->ISSQNtot->getElementsByTagName("vBC")->item(0)->nodeValue) ?
2836
                    $this->ISSQNtot->getElementsByTagName("vBC")->item(0)->nodeValue : '';
2837
            $texto = ! empty($texto) ? number_format($texto, 2, ",", ".") : '';
2838
        } else {
2839
            $texto = '';
2840
        }
2841
        $aFont = ['font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B'];
2842
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'B', 'R', 0, '');
2843
        //VALOR TOTAL DO ISSQN
2844
        $x += $w;
2845
        if ($this->orientacao == 'P') {
2846
            $w = $this->wPrint - (3 * $w);
2847
        } else {
2848
            $w = $this->wPrint - (3 * $w)-$this->wCanhoto;
2849
        }
2850
        $texto = 'VALOR TOTAL DO ISSQN';
2851
        $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
2852
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 1, '');
2853
        if (isset($this->ISSQNtot)) {
2854
            $texto = ! empty($this->ISSQNtot->getElementsByTagName("vISS")->item(0)->nodeValue) ?
2855
                    $this->ISSQNtot->getElementsByTagName("vISS")->item(0)->nodeValue : '';
2856
            $texto = ! empty($texto) ? number_format($texto, 2, ",", ".") : '';
2857
        } else {
2858
            $texto = '';
2859
        }
2860
        $aFont = ['font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B'];
2861
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'B', 'R', 0, '');
2862
        return ($y+$h+1);
2863
    }
2864
2865
    /**
2866
     *dadosAdicionaisDANFE
2867
     * Coloca o grupo de dados adicionais da NFe. (retrato e paisagem)
2868
     *
2869
     * @name   dadosAdicionaisDANFE
2870
     * @param  float $x Posição horizontal canto esquerdo
2871
     * @param  float $y Posição vertical canto superior
2872
     * @param  float $h altura do campo
2873
     * @return float Posição vertical final (eixo Y)
2874
     */
2875
    protected function dadosAdicionaisDANFE($x, $y, $h)
2876
    {
2877
        //##################################################################################
2878
        //DADOS ADICIONAIS
2879
        $texto = "DADOS ADICIONAIS";
2880
        if ($this->orientacao == 'P') {
2881
              $w = $this->wPrint;
2882
        } else {
2883
              $w = $this->wPrint-$this->wCanhoto;
2884
        }
2885
        $aFont = ['font'=>$this->fontePadrao, 'size'=>7, 'style'=>'B'];
2886
        $this->pdf->textBox($x, $y, $w, 8, $texto, $aFont, 'T', 'L', 0, '');
2887
        //INFORMAÇÕES COMPLEMENTARES
2888
        $texto = "INFORMAÇÕES COMPLEMENTARES";
2889
        $y += 3;
2890
        $w = $this->wAdic;
2891
        $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>'B'];
2892
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 1, '');
2893
        //o texto com os dados adicionais foi obtido na função montaDANFE
2894
        //e carregado em uma propriedade privada da classe
2895
        //$this->wAdic com a largura do campo
2896
        //$this->textoAdic com o texto completo do campo
2897
        $y += 1;
2898
        $aFont = ['font'=>$this->fontePadrao, 'size'=>7, 'style'=>''];
2899
        $this->pdf->textBox($x, $y+2, $w-2, $h-3, $this->textoAdic, $aFont, 'T', 'L', 0, '', false);
2900
        //RESERVADO AO FISCO
2901
        $texto = "RESERVADO AO FISCO";
2902
        $x += $w;
2903
        $y -= 1;
2904
        if ($this->orientacao == 'P') {
2905
            $w = $this->wPrint-$w;
2906
        } else {
2907
            $w = $this->wPrint-$w-$this->wCanhoto;
2908
        }
2909
        $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>'B'];
2910
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 1, '');
2911
        //inserir texto informando caso de contingência
2912
        // 1 - Normal - emissão normal;
2913
        // 2 - Contingência FS - emissão em contingência com impressão do DANFE em Formulário de Segurança;
2914
        // 3 - Contingência SCAN - emissão em contingência no Sistema de Contingência do Ambiente Nacional;
2915
        // 4 - Contingência DPEC - emissão em contingência com envio da Declaração
2916
        //     Prévia de Emissão em Contingência;
2917
        // 5 - Contingência FS-DA - emissão em contingência com impressão do DANFE em Formulário de
2918
        //     Segurança para Impressão de Documento Auxiliar de Documento Fiscal Eletrônico (FS-DA);
2919
        // 6 - Contingência SVC-AN
2920
        // 7 - Contingência SVC-RS
2921
        $xJust = $this->getTagValue($this->ide, 'xJust', 'Justificativa: ');
2922
        $dhCont = $this->getTagValue($this->ide, 'dhCont', ' Entrada em contingência : ');
2923
        $texto = '';
2924
        switch ($this->tpEmis) {
2925
            case 2:
2926
                $texto = 'CONTINGÊNCIA FS' . $dhCont . $xJust;
2927
                break;
2928
            case 3:
2929
                $texto = 'CONTINGÊNCIA SCAN' . $dhCont . $xJust;
2930
                break;
2931
            case 4:
2932
                $texto = 'CONTINGÊNCIA DPEC' . $dhCont . $xJust;
2933
                break;
2934
            case 5:
2935
                $texto = 'CONTINGÊNCIA FSDA' . $dhCont . $xJust;
2936
                break;
2937
            case 6:
2938
                $texto = 'CONTINGÊNCIA SVC-AN' . $dhCont . $xJust;
2939
                break;
2940
            case 7:
2941
                $texto = 'CONTINGÊNCIA SVC-RS' . $dhCont . $xJust;
2942
                break;
2943
        }
2944
        $y += 2;
2945
        $aFont = ['font'=>$this->fontePadrao, 'size'=>7, 'style'=>''];
2946
        $this->pdf->textBox($x, $y, $w-2, $h-3, $texto, $aFont, 'T', 'L', 0, '', false);
2947
        return $y+$h;
2948
    }
2949
2950
    /**
2951
     * rodape
2952
     * Monta o rodapé no final da DANFE com a data/hora de impressão e informações
2953
     * sobre a API NfePHP
2954
     *
2955
     * @name   rodape
2956
     * @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...
2957
     * @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...
2958
     * @return void
2959
     */
2960
    protected function rodape($x, $y)
2961
    {
2962
        if ($this->orientacao == 'P') {
2963
              $w = $this->wPrint;
2964
        } else {
2965
              $w = $this->wPrint-$this->wCanhoto;
2966
              $x = $this->wCanhoto;
2967
        }
2968
        $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>'I'];
2969
        $texto = "Impresso em ". date('d/m/Y') . " as " . date('H:i:s');
2970
        $this->pdf->textBox($x, $y, $w, 0, $texto, $aFont, 'T', 'L', false);
2971
        $texto = $this->creditos .  "  Powered by NFePHP®";
2972
        $this->pdf->textBox($x, $y, $w, 0, $texto, $aFont, 'T', 'R', false, '');
2973
    }
2974
2975
    /**
2976
     * pCcanhotoDANFE
2977
     * Monta o canhoto da DANFE (retrato e paisagem)
2978
     *
2979
     * @name   canhotoDANFE
2980
     * @param  number $x Posição horizontal canto esquerdo
2981
     * @param  number $y Posição vertical canto superior
2982
     * @return number Posição vertical final
2983
     *
2984
     * TODO 21/07/14 fmertins: quando orientação L-paisagem, o canhoto está sendo gerado incorretamente
2985
     */
2986
    protected function canhoto($x, $y)
2987
    {
2988
        $oldX = $x;
2989
        $oldY = $y;
2990
        //#################################################################################
2991
        //canhoto
2992
        //identificação do tipo de nf entrada ou saida
2993
        $tpNF = $this->ide->getElementsByTagName('tpNF')->item(0)->nodeValue;
2994
        if ($tpNF == '0') {
2995
            //NFe de Entrada
2996
            $emitente = '';
2997
            $emitente .= $this->dest->getElementsByTagName("xNome")->item(0)->nodeValue . " - ";
2998
            $emitente .= $this->enderDest->getElementsByTagName("xLgr")->item(0)->nodeValue . ", ";
2999
            $emitente .= $this->enderDest->getElementsByTagName("nro")->item(0)->nodeValue . " - ";
3000
            $emitente .= $this->getTagValue($this->enderDest, "xCpl", " - ", " ");
3001
            $emitente .= $this->enderDest->getElementsByTagName("xBairro")->item(0)->nodeValue . " ";
3002
            $emitente .= $this->enderDest->getElementsByTagName("xMun")->item(0)->nodeValue . "-";
3003
            $emitente .= $this->enderDest->getElementsByTagName("UF")->item(0)->nodeValue . "";
3004
            $destinatario = $this->emit->getElementsByTagName("xNome")->item(0)->nodeValue . " ";
3005
        } else {
3006
            //NFe de Saída
3007
            $emitente = $this->emit->getElementsByTagName("xNome")->item(0)->nodeValue . " ";
3008
            $destinatario = '';
3009
            $destinatario .= $this->dest->getElementsByTagName("xNome")->item(0)->nodeValue . " - ";
3010
            $destinatario .= $this->enderDest->getElementsByTagName("xLgr")->item(0)->nodeValue . ", ";
3011
            $destinatario .= $this->enderDest->getElementsByTagName("nro")->item(0)->nodeValue . " ";
3012
            $destinatario .= $this->getTagValue($this->enderDest, "xCpl", " - ", " ");
3013
            $destinatario .= $this->enderDest->getElementsByTagName("xBairro")->item(0)->nodeValue . " ";
3014
            $destinatario .= $this->enderDest->getElementsByTagName("xMun")->item(0)->nodeValue . "-";
3015
            $destinatario .= $this->enderDest->getElementsByTagName("UF")->item(0)->nodeValue . " ";
3016
        }
3017
        //identificação do sistema emissor
3018
        //linha separadora do canhoto
3019
        if ($this->orientacao == 'P') {
3020
            $w = round($this->wPrint * 0.81, 0);
3021
        } else {
3022
            //linha separadora do canhoto - 238
3023
            //posicao altura
3024
            $y = $this->wPrint-85;
3025
            //altura
3026
            $w = $this->wPrint-85-24;
3027
        }
3028
        $h = 10;
3029
        //desenha caixa
3030
        $texto = '';
3031
        $aFont = ['font'=>$this->fontePadrao, 'size'=>7, 'style'=>''];
3032
        $aFontSmall = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
3033
        if ($this->orientacao == 'P') {
3034
            $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'C', 'L', 1, '', false);
3035
        } else {
3036
            $this->pdf->textBox90($x, $y, $w, $h, $texto, $aFont, 'C', 'L', 1, '', false);
3037
        }
3038
        $numNF = str_pad($this->ide->getElementsByTagName('nNF')->item(0)->nodeValue, 9, "0", STR_PAD_LEFT);
3039
        $serie = str_pad($this->ide->getElementsByTagName('serie')->item(0)->nodeValue, 3, "0", STR_PAD_LEFT);
3040
        $texto = "RECEBEMOS DE ";
3041
        $texto .= $emitente;
3042
        $texto .= " OS PRODUTOS E/OU SERVIÇOS CONSTANTES DA NOTA FISCAL ELETRÔNICA INDICADA ";
3043
        if ($this->orientacao == 'P') {
3044
            $texto .= "ABAIXO";
3045
        } else {
3046
            $texto .= "AO LADO";
3047
        }
3048
        $texto .= ". EMISSÃO: ";
3049
        $dEmi = ! empty($this->ide->getElementsByTagName("dEmi")->item(0)->nodeValue) ?
3050
                $this->ide->getElementsByTagName("dEmi")->item(0)->nodeValue : '';
3051
        if ($dEmi == '') {
3052
            $dEmi = ! empty($this->ide->getElementsByTagName("dhEmi")->item(0)->nodeValue) ?
3053
                    $this->ide->getElementsByTagName("dhEmi")->item(0)->nodeValue : '';
3054
            $aDemi = explode('T', $dEmi);
3055
            $dEmi = $aDemi[0];
3056
        }
3057
        $texto .= $this->ymdTodmy($dEmi) ." ";
3058
        $texto .= "VALOR TOTAL: R$ ";
3059
        $texto .= number_format($this->ICMSTot->getElementsByTagName("vNF")->item(0)->nodeValue, 2, ",", ".") . " ";
3060
        $texto .= "DESTINATÁRIO: ";
3061
        $texto .= $destinatario;
3062
        if ($this->orientacao == 'P') {
3063
            $this->pdf->textBox($x, $y, $w-1, $h, $texto, $aFont, 'C', 'L', 0, '', false);
3064
            $x1 = $x + $w;
3065
            $w1 = $this->wPrint - $w;
3066
            $texto = "NF-e";
3067
            $aFont = ['font'=>$this->fontePadrao, 'size'=>14, 'style'=>'B'];
3068
            $this->pdf->textBox($x1, $y, $w1, 18, $texto, $aFont, 'T', 'C', 0, '');
3069
            $texto = "Nº. " . $this->formatField($numNF, "###.###.###") . " \n";
3070
            $texto .= "Série $serie";
3071
            $aFont = ['font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B'];
3072
            $this->pdf->textBox($x1, $y, $w1, 18, $texto, $aFont, 'C', 'C', 1, '');
3073
            //DATA DE RECEBIMENTO
3074
            $texto = "DATA DE RECEBIMENTO";
3075
            $y += $h;
3076
            $w2 = round($this->wPrint*0.17, 0); //35;
3077
            $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
3078
            $this->pdf->textBox($x, $y, $w2, 8, $texto, $aFont, 'T', 'L', 1, '');
3079
            //IDENTIFICAÇÃO E ASSINATURA DO RECEBEDOR
3080
            $x += $w2;
3081
            $w3 = $w-$w2;
3082
            $texto = "IDENTIFICAÇÃO E ASSINATURA DO RECEBEDOR";
3083
            $this->pdf->textBox($x, $y, $w3, 8, $texto, $aFont, 'T', 'L', 1, '');
3084
            $x = $oldX;
3085
            $y += 9;
3086
            $this->pdf->dashedHLine($x, $y, $this->wPrint, 0.1, 80);
3087
            $y += 2;
3088
            return $y;
3089
        } else {
3090
            $x--;
3091
            $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...
3092
            //NUMERO DA NOTA FISCAL LOGO NFE
3093
            $w1 = 18;
3094
            $x1 = $oldX;
3095
            $y = $oldY;
3096
            $texto = "NF-e";
3097
            $aFont = ['font'=>$this->fontePadrao, 'size'=>14, 'style'=>'B'];
3098
            $this->pdf->textBox($x1, $y, $w1, 18, $texto, $aFont, 'T', 'C', 0, '');
3099
            $texto = "Nº.\n" . $this->formatField($numNF, "###.###.###") . " \n";
3100
            $texto .= "Série $serie";
3101
            $aFont = ['font'=>$this->fontePadrao, 'size'=>8, 'style'=>'B'];
3102
            $this->pdf->textBox($x1, $y, $w1, 18, $texto, $aFont, 'C', 'C', 1, '');
3103
            //DATA DO RECEBIMENTO
3104
            $texto = "DATA DO RECEBIMENTO";
3105
            $y = $this->wPrint-85;
3106
            $x = 12;
3107
            $w2 = round($this->wPrint*0.17, 0); //35;
3108
            $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
3109
            $this->pdf->textBox90($x, $y, $w2, 8, $texto, $aFont, 'T', 'L', 1, '');
3110
            //IDENTIFICAÇÃO E ASSINATURA DO RECEBEDOR
3111
            $y -= $w2;
3112
            $w3 = $w-$w2;
3113
            $texto = "IDENTIFICAÇÃO E ASSINATURA DO RECEBEDOR";
3114
            $aFont = ['font'=>$this->fontePadrao, 'size'=>5.7, 'style'=>''];
3115
            $x = $this->pdf->textBox90($x, $y, $w3, 8, $texto, $aFont, 'T', 'L', 1, '');
3116
            $this->pdf->DashedVLine(23, $oldY, 0.1, $this->wPrint-20, 67);
3117
            return $x;
3118
        }
3119
    }
3120
3121
    /**
3122
     * geraInformacoesDaTagCompra
3123
     * Devolve uma string contendo informação sobre as tag <compra><xNEmp>, <xPed> e <xCont> ou string vazia.
3124
     * Aviso: Esta função não leva em consideração dados na tag xPed do item.
3125
     *
3126
     * @name   pGeraInformacoesDaTagCompra
3127
     * @return string com as informacoes dos pedidos.
3128
     */
3129
    protected function geraInformacoesDaTagCompra()
3130
    {
3131
        $saida = "";
3132
        if (isset($this->compra)) {
3133
            if (! empty($this->compra->getElementsByTagName("xNEmp")->item(0)->nodeValue)) {
3134
                $saida .= " Nota de Empenho: " . $this->compra->getElementsByTagName("xNEmp")->item(0)->nodeValue;
3135
            }
3136
            if (! empty($this->compra->getElementsByTagName("xPed")->item(0)->nodeValue)) {
3137
                $saida .= " Pedido: " . $this->compra->getElementsByTagName("xPed")->item(0)->nodeValue;
3138
            }
3139
            if (! empty($this->compra->getElementsByTagName("xCont")->item(0)->nodeValue)) {
3140
                $saida .= " Contrato: " . $this->compra->getElementsByTagName("xCont")->item(0)->nodeValue;
3141
            }
3142
        }
3143
        return $saida;
3144
    }
3145
3146
    /**
3147
     * geraChaveAdicionalDeContingencia
3148
     *
3149
     * @name   geraChaveAdicionalDeContingencia
3150
     * @return string chave
3151
     */
3152
    protected function geraChaveAdicionalDeContingencia()
3153
    {
3154
        //cUF tpEmis CNPJ vNF ICMSp ICMSs DD  DV
3155
        // Quantidade de caracteres  02   01      14  14    01    01  02 01
3156
        $forma  = "%02d%d%s%014d%01d%01d%02d";
3157
        $cUF    = $this->ide->getElementsByTagName('cUF')->item(0)->nodeValue;
3158
        $CNPJ   = "00000000000000" . $this->emit->getElementsByTagName('CNPJ')->item(0)->nodeValue;
3159
        $CNPJ   = substr($CNPJ, -14);
3160
        $vNF    = $this->ICMSTot->getElementsByTagName("vNF")->item(0)->nodeValue * 100;
3161
        $vICMS  = $this->ICMSTot->getElementsByTagName("vICMS")->item(0)->nodeValue;
3162
        if ($vICMS > 0) {
3163
            $vICMS = 1;
3164
        }
3165
        $icmss  = $this->ICMSTot->getElementsByTagName("vBC")->item(0)->nodeValue;
3166
        if ($icmss > 0) {
3167
            $icmss = 1;
3168
        }
3169
        $dEmi = ! empty($this->ide->getElementsByTagName("dEmi")->item(0)->nodeValue) ?
3170
                $this->ide->getElementsByTagName("dEmi")->item(0)->nodeValue : '';
3171
        if ($dEmi == '') {
3172
            $dEmi = ! empty($this->ide->getElementsByTagName("dhEmi")->item(0)->nodeValue) ?
3173
                    $this->ide->getElementsByTagName("dhEmi")->item(0)->nodeValue : '';
3174
            $aDemi = explode('T', $dEmi);
3175
            $dEmi = $aDemi[0];
3176
        }
3177
        $dd  = $dEmi;
3178
        $rpos = strrpos($dd, '-');
3179
        $dd  = substr($dd, $rpos +1);
3180
        $chave = sprintf($forma, $cUF, $this->tpEmis, $CNPJ, $vNF, $vICMS, $icmss, $dd);
3181
        $chave = $chave . $this->modulo11($chave);
3182
        return $chave;
3183
    }
3184
3185
    /**
3186
     *  geraInformacoesDasNotasReferenciadas
3187
     * Devolve uma string contendo informação sobre as notas referenciadas. Suporta N notas, eletrônicas ou não
3188
     * Exemplo: NFe Ref.: série: 01 número: 01 emit: 11.111.111/0001-01
3189
     * em 10/2010 [0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000]
3190
     *
3191
     * @return string Informacoes a serem adicionadas no rodapé sobre notas referenciadas.
3192
     */
3193
    protected function geraInformacoesDasNotasReferenciadas()
3194
    {
3195
        $formaNfeRef = "\r\nNFe Ref.: série:%d número:%d emit:%s em %s [%s]";
3196
        $formaCTeRef = "\r\nCTe Ref.: série:%d número:%d emit:%s em %s [%s]";
3197
        $formaNfRef = "\r\nNF  Ref.: série:%d numero:%d emit:%s em %s modelo: %d";
3198
        $formaECFRef = "\r\nECF Ref.: modelo: %s ECF:%d COO:%d";
3199
        $formaNfpRef = "\r\nNFP Ref.: série:%d número:%d emit:%s em %s modelo: %d IE:%s";
3200
        $saida='';
3201
        $nfRefs = $this->ide->getElementsByTagName('NFref');
3202
        if (0 === $nfRefs->length) {
3203
            return $saida;
3204
        }
3205
        if ($nfRefs->length > 2) {
3206
            return 'Existem mais de 2 NF/NFe/ECF/NFP/CTe referenciadas, não serão exibidas na DANFE.';
3207
        }
3208
        foreach ($nfRefs as $nfRef) {
3209
            if (empty($nfRef)) {
3210
                continue;
3211
            }
3212
            $refNFe = $nfRef->getElementsByTagName('refNFe');
3213
            foreach ($refNFe as $chave_acessoRef) {
3214
                $chave_acesso = $chave_acessoRef->nodeValue;
3215
                $chave_acessoF = $this->formatField($chave_acesso, $this->formatoChave);
3216
                $data = substr($chave_acesso, 4, 2)."/20".substr($chave_acesso, 2, 2);
3217
                $cnpj = $this->formatField(substr($chave_acesso, 6, 14), "##.###.###/####-##");
3218
                $serie  = substr($chave_acesso, 22, 3);
3219
                $numero = substr($chave_acesso, 25, 9);
3220
                $saida .= sprintf($formaNfeRef, $serie, $numero, $cnpj, $data, $chave_acessoF);
3221
            }
3222
            $refNF = $nfRef->getElementsByTagName('refNF');
3223
            foreach ($refNF as $umaRefNFe) {
3224
                $data = $umaRefNFe->getElementsByTagName('AAMM')->item(0)->nodeValue;
3225
                $cnpj = $umaRefNFe->getElementsByTagName('CNPJ')->item(0)->nodeValue;
3226
                $mod = $umaRefNFe->getElementsByTagName('mod')->item(0)->nodeValue;
3227
                $serie = $umaRefNFe->getElementsByTagName('serie')->item(0)->nodeValue;
3228
                $numero = $umaRefNFe->getElementsByTagName('nNF')->item(0)->nodeValue;
3229
                $data = substr($data, 2, 2) . "/20" . substr($data, 0, 2);
3230
                $cnpj = $this->formatField($cnpj, "##.###.###/####-##");
3231
                $saida .= sprintf($formaNfRef, $serie, $numero, $cnpj, $data, $mod);
3232
            }
3233
            $refCTe = $nfRef->getElementsByTagName('refCTe');
3234
            foreach ($refCTe as $chave_acessoRef) {
3235
                $chave_acesso = $chave_acessoRef->nodeValue;
3236
                $chave_acessoF = $this->formatField($chave_acesso, $this->formatoChave);
3237
                $data = substr($chave_acesso, 4, 2)."/20".substr($chave_acesso, 2, 2);
3238
                $cnpj = $this->formatField(substr($chave_acesso, 6, 14), "##.###.###/####-##");
3239
                $serie  = substr($chave_acesso, 22, 3);
3240
                $numero = substr($chave_acesso, 25, 9);
3241
                $saida .= sprintf($formaCTeRef, $serie, $numero, $cnpj, $data, $chave_acessoF);
3242
            }
3243
            $refECF = $nfRef->getElementsByTagName('refECF');
3244
            foreach ($refECF as $umaRefNFe) {
3245
                $mod    = $umaRefNFe->getElementsByTagName('mod')->item(0)->nodeValue;
3246
                $nECF   = $umaRefNFe->getElementsByTagName('nECF')->item(0)->nodeValue;
3247
                $nCOO   = $umaRefNFe->getElementsByTagName('nCOO')->item(0)->nodeValue;
3248
                $saida .= sprintf($formaECFRef, $mod, $nECF, $nCOO);
3249
            }
3250
            $refNFP = $nfRef->getElementsByTagName('refNFP');
3251
            foreach ($refNFP as $umaRefNFe) {
3252
                $data = $umaRefNFe->getElementsByTagName('AAMM')->item(0)->nodeValue;
3253
                $cnpj = ! empty($umaRefNFe->getElementsByTagName('CNPJ')->item(0)->nodeValue) ?
3254
                    $umaRefNFe->getElementsByTagName('CNPJ')->item(0)->nodeValue :
3255
                    '';
3256
                $cpf = ! empty($umaRefNFe->getElementsByTagName('CPF')->item(0)->nodeValue) ?
3257
                        $umaRefNFe->getElementsByTagName('CPF')->item(0)->nodeValue : '';
3258
                $mod = $umaRefNFe->getElementsByTagName('mod')->item(0)->nodeValue;
3259
                $serie = $umaRefNFe->getElementsByTagName('serie')->item(0)->nodeValue;
3260
                $numero = $umaRefNFe->getElementsByTagName('nNF')->item(0)->nodeValue;
3261
                $ie = $umaRefNFe->getElementsByTagName('IE')->item(0)->nodeValue;
3262
                $data = substr($data, 2, 2) . "/20" . substr($data, 0, 2);
3263
                if ($cnpj == '') {
3264
                    $cpf_cnpj = $this->formatField($cpf, "###.###.###-##");
3265
                } else {
3266
                    $cpf_cnpj = $this->formatField($cnpj, "##.###.###/####-##");
3267
                }
3268
                $saida .= sprintf($formaNfpRef, $serie, $numero, $cpf_cnpj, $data, $mod, $ie);
3269
            }
3270
        }
3271
        return $saida;
3272
    }
3273
    
3274
    private function loadDoc($xml)
3275
    {
3276
        $this->xml = $xml;
3277
        if (!empty($xml)) {
3278
            $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...
3279
            $this->dom->loadXML($this->xml);
3280
            if (empty($this->dom->getElementsByTagName("infNFe")->item(0))) {
3281
                throw new \Exception('Isso não é um NFe.');
3282
            }
3283
            $this->nfeProc = $this->dom->getElementsByTagName("nfeProc")->item(0);
3284
            $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...
3285
            $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...
3286
            if ($this->getTagValue($this->ide, "mod") != '55') {
3287
                throw new \Exception("O xml deve ser NF-e modelo 55.");
3288
            }
3289
            $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...
3290
            $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...
3291
            $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...
3292
            $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...
3293
            $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...
3294
            $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...
3295
            $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...
3296
            $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...
3297
            $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...
3298
            $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...
3299
            $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...
3300
            $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...
3301
            $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...
3302
            $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...
3303
            $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...
3304
            $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...
3305
            $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...
3306
            $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...
3307
            $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...
3308
            $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...
3309
        }
3310
    }
3311
    
3312
    private function imagePNGtoJPG($original)
3313
    {
3314
        $image = imagecreatefrompng($original);
3315
        ob_start();
3316
        imagejpeg($image, null, 100);
3317
        imagedestroy($image);
3318
        $stringdata = ob_get_contents(); // read from buffer
3319
        ob_end_clean();
3320
        return 'data://text/plain;base64,'.base64_encode($stringdata);
3321
    }
3322
}
3323