Completed
Pull Request — master (#299)
by
unknown
02:51 queued 24s
created

Danfe::pNotaCancelada()   A

Complexity

Conditions 6
Paths 6

Size

Total Lines 12

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 42

Importance

Changes 0
Metric Value
cc 6
nc 6
nop 0
dl 0
loc 12
ccs 0
cts 12
cp 0
crap 42
rs 9.2222
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
13
    /**
14
     * alinhamento padrão do logo (C-Center)
15
     *
16
     * @var string
17
     */
18
    protected $logoAlign = 'C';
19
    /**
20
     * Posição
21
     * @var float
22
     */
23
    protected $yDados = 0;
24
    /**
25
     * Numero DPEC
26
     *
27
     * @var string
28
     */
29
    protected $numero_registro_dpec = '';
30
     /**
31
     * Parâmetro para exibir ou ocultar os valores do PIS/COFINS.
32
     * @var boolean
33
     */
34
    protected $qCanhoto = 1;
35
    /**
36
     * Define a exbição dos valores de PIS e Cofins
37
     * @var bool
38
     */
39
    protected $exibirPIS = true;
40
    /**
41
     * Parâmetro para exibir ou ocultar os valores do ICMS Interestadual e Valor Total dos Impostos.
42
     * @var boolean
43
     */
44
    protected $exibirIcmsInterestadual = true;
45
    /**
46
     * Parâmetro para exibir ou ocultar o texto sobre valor aproximado dos tributos.
47
     * @var boolean
48
     */
49
    protected $exibirValorTributos = true;
50
    /**
51
     * Parâmetro para exibir ou ocultar o texto adicional sobre a forma de pagamento
52
     * e as informações de fatura/duplicata.
53
     * @var boolean
54
     */
55
    protected $exibirTextoFatura = false;
56
    /**
57
     * Parâmetro do controle se deve concatenar automaticamente informações complementares
58
     * na descrição do produto, como por exemplo, informações sobre impostos.
59
     * @var boolean
60
     */
61
    public $descProdInfoComplemento = true;
62
    /**
63
     * Parâmetro do controle se deve gerar quebras de linha com "\n" a partir de ";" na descrição do produto.
64
     * @var boolean
65
     */
66
    protected $descProdQuebraLinha = true;
67
    /**
68
     * objeto fpdf()
69
     * @var \NFePHP\DA\Legacy\Pdf
70
     */
71
    protected $pdf;
72
    /**
73
     * XML NFe
74
     * @var string
75
     */
76
    protected $xml;
77
    /**
78
     * path para logomarca em jpg
79
     * @var string
80
     */
81
    protected $logomarca = '';
82
    /**
83
     * mesagens de erro
84
     * @var string
85
     */
86
    protected $errMsg = '';
87
    /**
88
     * status de erro true um erro ocorreu false sem erros
89
     * @var boolean
90
     */
91
    protected $errStatus = false;
92
    /**
93
     * orientação da DANFE
94
     * P-Retrato ou L-Paisagem
95
     * @var string
96
     */
97
    protected $orientacao = 'P';
98
    /**
99
     * formato do papel
100
     * @var string
101
     */
102
    protected $papel = 'A4';
103
    /**
104
     * Nome da Fonte para gerar o DANFE
105
     * @var string
106
     */
107
    protected $fontePadrao = 'Times';
108
    /**
109
     * Texto adicional da DANFE
110
     * @var string
111
     */
112
    protected $textoAdic = '';
113
    /**
114
     * Largura
115
     * @var float
116
     */
117
    protected $wAdic = 0;
118
    /**
119
     * largura imprimivel, em milímetros
120
     * @var float
121
     */
122
    protected $wPrint;
123
    /**
124
     * Comprimento (altura) imprimivel, em milímetros
125
     * @var float
126
     */
127
    protected $hPrint;
128
    /**
129
     * Altura maxima
130
     * @var float
131
     */
132
    protected $maxH;
133
    /**
134
     * Largura maxima
135
     * @var float
136
     */
137
    protected $maxW;
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
     * Dom Document
155
     * @var \NFePHP\DA\Legacy\Dom
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  $xml Conteúdo XML da NF-e (com ou sem a tag nfeProc)
284
     */
285
    public function __construct($xml)
286
    {
287
        $this->debugMode();
288
        $this->loadDoc($xml);
289
    }
290
    
291
    /**
292
     * Ativa ou desativa o modo debug
293
     * @param bool $activate
294
     * @return bool
295
     */
296
    public function debugMode($activate = null)
297
    {
298
        if (isset($activate) && is_bool($activate)) {
299
            $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...
300
        }
301
        if ($this->debugmode) {
302
            //ativar modo debug
303
            error_reporting(E_ALL);
304
            ini_set('display_errors', 'On');
305
        } else {
306
            //desativar modo debug
307
            error_reporting(0);
308
            ini_set('display_errors', 'Off');
309
        }
310
        return $this->debugmode;
311
    }
312
313
    /**
314
     * Add the credits to the integrator in the footer message
315
     * @param string $message
316
     */
317
    public function creditsIntegratorFooter($message = '')
318
    {
319
        $this->creditos = trim($message);
320
    }
321
    
322
    /**
323
     * Dados brutos do PDF
324
     * @return string
325
     */
326
    public function render()
327
    {
328
        if (empty($this->pdf)) {
329
            $this->monta();
330
        }
331
        return $this->pdf->getPdf();
332
    }
333
    protected function pNotaCancelada()
334
    {
335
        if (!isset($this->nfeProc)) {
336
            return false;
337
        }
338
        $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...
339
        return $cStat == '101' ||
340
                $cStat == '151' ||
341
                $cStat == '135' ||
342
                $cStat == '155' ||
343
                $this->situacao_externa == self::SIT_CANCELADA;
0 ignored issues
show
Bug introduced by
The property situacao_externa 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...
344
    }
345
    /**
346
     * monta
347
     * Monta a DANFE conforme as informações fornecidas para a classe durante sua
348
     * construção. Constroi DANFEs com até 3 páginas podendo conter até 56 itens.
349
     * A definição de margens e posições iniciais para a impressão são estabelecidas
350
     * pelo conteúdo da funçao e podem ser modificados.
351
     *
352
     * @param  string $orientacao (Opcional) Estabelece a orientação da impressão
353
     *  (ex. P-retrato), se nada for fornecido será usado o padrão da NFe
354
     * @param  string $papel      (Opcional) Estabelece o tamanho do papel (ex. A4)
355
     * @return string O ID da NFe numero de 44 digitos extraido do arquivo XML
356
     */
357
    public function monta(
358
        $logo = '',
359
        $orientacao = '',
360
        $papel = 'A4',
361
        $logoAlign = 'C',
362
        $depecNumReg = '',
363
        $margSup = 2,
364
        $margEsq = 2,
365
        $margInf = 2
366
    ) {
367
        $this->pdf = '';
0 ignored issues
show
Documentation Bug introduced by
It seems like '' of type string is incompatible with the declared type object<NFePHP\DA\Legacy\Pdf> 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...
368
        $this->logomarca = $logo;
369
        //se a orientação estiver em branco utilizar o padrão estabelecido na NF
370
        if ($orientacao == '') {
371
            if ($this->tpImp == '2') {
372
                $orientacao = 'L';
373
            } else {
374
                $orientacao = 'P';
375
            }
376
        }
377
        $this->orientacao = $orientacao;
378
        $this->papel = $papel;
379
        $this->logoAlign = $logoAlign;
380
        $this->numero_registro_dpec = $depecNumReg;
381
        //instancia a classe pdf
382
        $this->pdf = new Pdf($this->orientacao, 'mm', $this->papel);
383
        //margens do PDF, em milímetros. Obs.: a margem direita é sempre igual à
384
        //margem esquerda. A margem inferior *não* existe na FPDF, é definida aqui
385
        //apenas para controle se necessário ser maior do que a margem superior
386
        // posição inicial do conteúdo, a partir do canto superior esquerdo da página
387
        $xInic = $margEsq;
388
        if ($this->orientacao == 'P') {
389
            if ($papel == 'A4') {
390
                $this->maxW = 210;
0 ignored issues
show
Documentation Bug introduced by
The property $maxW was declared of type double, but 210 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...
391
                $this->maxH = 297;
0 ignored issues
show
Documentation Bug introduced by
The property $maxH was declared of type double, but 297 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...
392
            }
393
        } else {
394
            if ($papel == 'A4') {
395
                $this->maxW = 297;
0 ignored issues
show
Documentation Bug introduced by
The property $maxW was declared of type double, but 297 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...
396
                $this->maxH = 210;
0 ignored issues
show
Documentation Bug introduced by
The property $maxH was declared of type double, but 210 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
                $xInic = $margEsq+10;
398
                //se paisagem multiplica a largura do canhoto pela quantidade de canhotos
399
                //$this->wCanhoto *= $this->qCanhoto;
400
            }
401
        }
402
        //total inicial de paginas
403
        $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...
404
        //largura imprimivel em mm: largura da folha menos as margens esq/direita
405
        $this->wPrint = $this->maxW-($margEsq * 2);
0 ignored issues
show
Documentation Bug introduced by
It seems like $this->maxW - $margEsq * 2 can also be of type integer. However, the property $wPrint is declared as type double. Maybe add an additional type check?

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

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

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

class Id
{
    public $id;

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

}

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

$account_id = false;

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

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
406
        //comprimento (altura) imprimivel em mm: altura da folha menos as margens
407
        //superior e inferior
408
        $this->hPrint = $this->maxH-$margSup-$margInf;
0 ignored issues
show
Documentation Bug introduced by
It seems like $this->maxH - $margSup - $margInf can also be of type integer. However, the property $hPrint is declared as type double. Maybe add an additional type check?

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

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

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

class Id
{
    public $id;

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

}

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

$account_id = false;

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

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
409
        // estabelece contagem de paginas
410
        $this->pdf->aliasNbPages();
411
        // fixa as margens
412
        $this->pdf->setMargins($margEsq, $margSup);
413
        $this->pdf->setDrawColor(0, 0, 0);
414
        $this->pdf->setFillColor(255, 255, 255);
415
        // inicia o documento
416
        $this->pdf->open();
417
        // adiciona a primeira página
418
        $this->pdf->addPage($this->orientacao, $this->papel);
419
        $this->pdf->setLineWidth(0.1);
420
        $this->pdf->settextcolor(0, 0, 0);
421
422
        //##################################################################
423
        // CALCULO DO NUMERO DE PAGINAS A SEREM IMPRESSAS
424
        //##################################################################
425
        //Verificando quantas linhas serão usadas para impressão das duplicatas
426
        $linhasDup = 0;
427
        $qtdPag = 0;
428
        if (isset($this->dup) && $this->dup->length > 0) {
429
            $qtdPag = $this->dup->length;
0 ignored issues
show
Bug introduced by
The property length does not seem to exist in DOMNode.

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
430
        } elseif (isset($this->detPag) && $this->detPag->length > 0) {
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...
431
            $qtdPag = $this->detPag->length;
432
        }
433
        if (($qtdPag > 0) && ($qtdPag <= 7)) {
434
            $linhasDup = 1;
435
        } elseif (($qtdPag > 7) && ($qtdPag <= 14)) {
436
            $linhasDup = 2;
437
        } elseif (($qtdPag > 14) && ($qtdPag <= 21)) {
438
            $linhasDup = 3;
439
        } elseif ($qtdPag > 21) {
440
            // chinnonsantos 11/05/2016: Limite máximo de impressão de duplicatas na NFe,
441
            // só vai ser exibito as 21 primeiras duplicatas (parcelas de pagamento),
442
            // se não oculpa espaço d+, cada linha comporta até 7 duplicatas.
443
            $linhasDup = 3;
444
        }
445
        //verifica se será impressa a linha dos serviços ISSQN
446
        $linhaISSQN = 0;
447
        if ((isset($this->ISSQNtot)) && ($this->getTagValue($this->ISSQNtot, 'vServ') > 0)) {
448
            $linhaISSQN = 1;
449
        }
450
        //calcular a altura necessária para os dados adicionais
451
        if ($this->orientacao == 'P') {
452
            $this->wAdic = round($this->wPrint*0.66, 0);
453
        } else {
454
            $this->wAdic = round(($this->wPrint-$this->wCanhoto)*0.5, 0);
455
        }
456
        $fontProduto = ['font'=>$this->fontePadrao, 'size'=>7, 'style'=>''];
457
        $this->textoAdic = '';
458
        if (isset($this->retirada)) {
459
            $txRetCNPJ = $this->getTagValue($this->retirada, "CNPJ");
460
            $txRetxLgr = $this->getTagValue($this->retirada, "xLgr");
461
            $txRetnro = $this->getTagValue($this->retirada, "nro");
462
            $txRetxCpl = $this->getTagValue($this->retirada, "xCpl", " - ");
463
            $txRetxBairro = $this->getTagValue($this->retirada, "xBairro");
464
            $txRetxMun = $this->getTagValue($this->retirada, "xMun");
465
            $txRetUF = $this->getTagValue($this->retirada, "UF");
466
            $this->textoAdic .= "LOCAL DE RETIRADA : ".
467
                    $txRetCNPJ.
468
                    '-' .
469
                    $txRetxLgr .
470
                    ', ' .
471
                    $txRetnro .
472
                    ' ' .
473
                    $txRetxCpl .
474
                    ' - ' .
475
                    $txRetxBairro .
476
                    ' ' .
477
                    $txRetxMun .
478
                    ' - ' .
479
                    $txRetUF .
480
                    "\r\n";
481
        }
482
        //dados do local de entrega da mercadoria
483
        if (isset($this->entrega)) {
484
            $txRetCNPJ = $this->getTagValue($this->entrega, "CNPJ");
485
            $txRetxLgr = $this->getTagValue($this->entrega, "xLgr");
486
            $txRetnro = $this->getTagValue($this->entrega, "nro");
487
            $txRetxCpl = $this->getTagValue($this->entrega, "xCpl", " - ");
488
            $txRetxBairro = $this->getTagValue($this->entrega, "xBairro");
489
            $txRetxMun = $this->getTagValue($this->entrega, "xMun");
490
            $txRetUF = $this->getTagValue($this->entrega, "UF");
491
            if ($this->textoAdic != '') {
492
                $this->textoAdic .= ". \r\n";
493
            }
494
            $this->textoAdic .= "LOCAL DE ENTREGA : ".$txRetCNPJ.'-'.$txRetxLgr.', '.$txRetnro.' '.$txRetxCpl.
495
               ' - '.$txRetxBairro.' '.$txRetxMun.' - '.$txRetUF."\r\n";
496
        }
497
        //informações adicionais
498
        $this->textoAdic .= $this->geraInformacoesDasNotasReferenciadas();
499
        if (isset($this->infAdic)) {
500
            $i = 0;
501
            if ($this->textoAdic != '') {
502
                $this->textoAdic .= ". \r\n";
503
            }
504
            $this->textoAdic .= ! empty($this->getTagValue($this->infAdic, "infCpl"))
505
            ? 'Inf. Contribuinte: ' . $this->anfaveaDANFE($this->getTagValue($this->infAdic, "infCpl"))
506
            : '';
507
            $infPedido = $this->geraInformacoesDaTagCompra();
508
            if ($infPedido != "") {
509
                $this->textoAdic .= $infPedido;
510
            }
511
            $this->textoAdic .= $this->getTagValue($this->dest, "email", ' Email do Destinatário: ');
512
            $this->textoAdic .= ! empty($this->getTagValue($this->infAdic, "infAdFisco"))
513
            ? "\r\n Inf. fisco: " . $this->getTagValue($this->infAdic, "infAdFisco")
514
            : '';
515
            $obsCont = $this->infAdic->getElementsByTagName("obsCont");
516
            if (isset($obsCont)) {
517
                foreach ($obsCont as $obs) {
518
                    $campo =  $obsCont->item($i)->getAttribute("xCampo");
519
                    $xTexto = ! empty($obsCont->item($i)->getElementsByTagName("xTexto")->item(0)->nodeValue)
520
                    ? $obsCont->item($i)->getElementsByTagName("xTexto")->item(0)->nodeValue
521
                    : '';
522
                    $this->textoAdic .= "\r\n" . $campo . ':  ' . trim($xTexto);
523
                    $i++;
524
                }
525
            }
526
        }
527
        //INCLUSO pela NT 2013.003 Lei da Transparência
528
        //verificar se a informação sobre o valor aproximado dos tributos
529
        //já se encontra no campo de informações adicionais
530
        if ($this->exibirValorTributos) {
531
            $flagVTT = strpos(strtolower(trim($this->textoAdic)), 'valor');
532
            $flagVTT = $flagVTT || strpos(strtolower(trim($this->textoAdic)), 'vl');
533
            $flagVTT = $flagVTT && strpos(strtolower(trim($this->textoAdic)), 'aprox');
534
            $flagVTT = $flagVTT && (strpos(strtolower(trim($this->textoAdic)), 'trib') ||
535
                    strpos(strtolower(trim($this->textoAdic)), 'imp'));
536
            $vTotTrib = $this->getTagValue($this->ICMSTot, 'vTotTrib');
537
            if ($vTotTrib != '' && !$flagVTT) {
538
                $this->textoAdic .= "\n Valor Aproximado dos Tributos : R$ "
539
                    . number_format($vTotTrib, 2, ",", ".");
540
            }
541
        }
542
        //fim da alteração NT 2013.003 Lei da Transparência
543
        $this->textoAdic = str_replace(";", "\n", $this->textoAdic);
544
        $alinhas = explode("\n", $this->textoAdic);
545
        $numlinhasdados = 0;
546
        foreach ($alinhas as $linha) {
547
            $numlinhasdados += $this->pdf->getNumLines($linha, $this->wAdic, $fontProduto);
548
        }
549
        $hdadosadic = round(($numlinhasdados+3) * $this->pdf->fontSize, 0);
550
        if ($hdadosadic < 10) {
551
            $hdadosadic = 10;
552
        }
553
        //altura disponivel para os campos da DANFE
554
        $hcabecalho = 47;//para cabeçalho
555
        $hdestinatario = 25;//para destinatario
556
        $hduplicatas = 12;//para cada grupo de 7 duplicatas
557
        if (isset($this->entrega)) {
558
            $hlocalentrega = 25;
559
        } else {
560
            $hlocalentrega = 0;
561
        }
562
        if (isset($this->retirada)) {
563
            $hlocalretirada = 25;
564
        } else {
565
            $hlocalretirada = 0;
566
        }
567
        $himposto = 18;// para imposto
568
        $htransporte = 25;// para transporte
569
        $hissqn = 11;// para issqn
570
        $hfooter = 5;// para rodape
571
        $hCabecItens = 4;//cabeçalho dos itens
572
        //alturas disponiveis para os dados
573
        $hDispo1 = $this->hPrint - 10 - ($hcabecalho +
574
            //$hdestinatario + ($linhasDup * $hduplicatas) + $himposto + $htransporte +
575
            $hdestinatario + $hlocalentrega + $hlocalretirada +
576
            ($linhasDup * $hduplicatas) + $himposto + $htransporte +
577
            ($linhaISSQN * $hissqn) + $hdadosadic + $hfooter + $hCabecItens +
578
            $this->sizeExtraTextoFatura());
579
        if ($this->orientacao == 'P') {
580
            $hDispo1 -= 24 * $this->qCanhoto;//para canhoto
581
            $w = $this->wPrint;
582
        } else {
583
            $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...
584
            $w = $this->wPrint - $this->wCanhoto;
585
        }
586
        $hDispo2 = $this->hPrint - 10 - ($hcabecalho + $hfooter + $hCabecItens)-4;
587
        //Contagem da altura ocupada para impressão dos itens
588
        $fontProduto = ['font'=>$this->fontePadrao, 'size'=>7, 'style'=>''];
589
        $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...
590
        $hUsado = $hCabecItens;
591
        $w2 = round($w*0.28, 0);
592
        $hDispo = $hDispo1;
593
        $totPag = 1;
594
        $i = 0;
595
        while ($i < $this->det->length) {
596
            $texto = $this->descricaoProduto($this->det->item($i));
597
            $numlinhas = $this->pdf->getNumLines($texto, $w2, $fontProduto);
598
            $hUsado += round(($numlinhas * $this->pdf->fontSize) + ($numlinhas * 0.5), 2);
599
            if ($hUsado > $hDispo) {
600
                $totPag++;
601
                $hDispo = $hDispo2;
602
                $hUsado = $hCabecItens;
603
                // Remove canhoto para páginas secundárias em modo paisagem ('L')
604
                $w2 = round($this->wPrint*0.28, 0);
605
                $i--; // decrementa para readicionar o item que não coube nessa pagina na outra.
606
            }
607
            $i++;
608
        } //fim da soma das areas de itens usadas
609
        $qtdeItens = $i; //controle da quantidade de itens no DANFE
610
        //montagem da primeira página
611
        $pag = 1;
612
        
613
        $x = $margEsq;
614
        $y = $margSup;
615
        //coloca o(s) canhoto(s) da NFe
616
        if ($this->orientacao == 'P') {
617
            $y = $this->canhoto($margEsq, $margSup);
618
        } else {
619
            $this->canhoto($margEsq, $margSup);
620
            $x = 25;
621
        }
622
        //$x = $xInic;
623
        //$y = $yInic;
624
        
625
        //coloca o cabeçalho
626
        $y = $this->header($x, $y, $pag, $totPag);
627
        //coloca os dados do destinatário
628
        $y = $this->destinatarioDANFE($x, $y+1);
629
        
630
        //coloca os dados do local de retirada
631
        if (isset($this->retirada)) {
632
            $y = $this->localRetiradaDANFE($x, $y+1);
633
        }
634
        //coloca os dados do local de entrega
635
        if (isset($this->entrega)) {
636
            $y = $this->localEntregaDANFE($x, $y+1);
637
        }
638
        
639
        //Verifica as formas de pagamento da nota fiscal
640
        $formaPag = [];
641
        if (isset($this->detPag) && $this->detPag->length > 0) {
642
            foreach ($this->detPag as $k => $d) {
643
                $fPag = !empty($this->detPag->item($k)->getElementsByTagName('tPag')->item(0)->nodeValue)
644
                ? $this->detPag->item($k)->getElementsByTagName('tPag')->item(0)->nodeValue
645
                : '0';
646
                $formaPag[$fPag] = $fPag;
647
            }
648
        }
649
        //caso tenha boleto imprimir fatura
650
        if ($this->dup->length > 0) {
651
            $y = $this->fatura($x, $y+1);
652
        } else {
653
            //Se somente tiver a forma de pagamento sem pagamento ou outros não imprimir nada
654
            if (count($formaPag)=='1' && (isset($formaPag[90]) || isset($formaPag[99]))) {
655
                $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...
656
            } else {
657
                //caso tenha mais de uma forma de pagamento ou seja diferente de boleto exibe a
658
                //forma de pagamento e o valor
659
                $y = $this->pagamento($x, $y+1);
660
            }
661
        }
662
        //coloca os dados dos impostos e totais da NFe
663
        $y = $this->imposto($x, $y+1);
664
        //coloca os dados do trasnporte
665
        $y = $this->transporte($x, $y+1);
666
        //itens da DANFE
667
        $nInicial = 0;
668
669
        $y = $this->itens($x, $y+1, $nInicial, $hDispo1, $pag, $totPag, $hCabecItens);
670
671
        //coloca os dados do ISSQN
672
        if ($linhaISSQN == 1) {
673
            $y = $this->issqn($x, $y+4);
674
        } else {
675
            $y += 4;
676
        }
677
        //coloca os dados adicionais da NFe
678
        $y = $this->dadosAdicionais($x, $y, $hdadosadic);
0 ignored issues
show
Unused Code introduced by
$y is not used, you could remove the assignment.

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

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

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

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

Loading history...
679
        //coloca o rodapé da página
680
        if ($this->orientacao == 'P') {
681
            $this->rodape($xInic);
682
        } else {
683
            $this->rodape($xInic);
684
        }
685
686
        //loop para páginas seguintes
687
        for ($n = 2; $n <= $totPag; $n++) {
688
            // fixa as margens
689
            $this->pdf->setMargins($margEsq, $margSup);
690
            //adiciona nova página
691
            $this->pdf->addPage($this->orientacao, $this->papel);
692
            //ajusta espessura das linhas
693
            $this->pdf->setLineWidth(0.1);
694
            //seta a cor do texto para petro
695
            $this->pdf->settextcolor(0, 0, 0);
696
            // posição inicial do relatorio
697
            $x = $margEsq;
698
            $y = $margSup;
699
            //coloca o cabeçalho na página adicional
700
            $y = $this->header($x, $y, $n, $totPag);
701
            //coloca os itens na página adicional
702
            $y = $this->itens($x, $y+1, $nInicial, $hDispo2, $n, $totPag, $hCabecItens);
0 ignored issues
show
Unused Code introduced by
$y is not used, you could remove the assignment.

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

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

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

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

Loading history...
703
            //coloca o rodapé da página
704
            if ($this->orientacao == 'P') {
705
                $this->rodape($margEsq);
706
            } else {
707
                $this->rodape($margEsq);
708
            }
709
            //se estiver na última página e ainda restar itens para inserir, adiciona mais uma página
710
            if ($n == $totPag && $this->qtdeItensProc < $qtdeItens) {
711
                $totPag++;
712
            }
713
        }
714
        //retorna o ID na NFe
715
        return str_replace('NFe', '', $this->infNFe->getAttribute("Id"));
716
    }
717
718
    /**
719
     * anfavea
720
     * Função para transformar o campo cdata do padrão ANFAVEA para
721
     * texto imprimível
722
     *
723
     * @param  string $cdata campo CDATA
724
     * @return string conteúdo do campo CDATA como string
725
     */
726
    protected function anfaveaDANFE($cdata = '')
727
    {
728
        if ($cdata == '') {
729
            return '';
730
        }
731
        //remove qualquer texto antes ou depois da tag CDATA
732
        $cdata = str_replace('<![CDATA[', '<CDATA>', $cdata);
733
        $cdata = str_replace(']]>', '</CDATA>', $cdata);
734
        $cdata = preg_replace('/\s\s+/', ' ', $cdata);
735
        $cdata = str_replace("> <", "><", $cdata);
736
        $len = strlen($cdata);
737
        $startPos = strpos($cdata, '<');
738
        if ($startPos === false) {
739
            return $cdata;
740
        }
741
        for ($x=$len; $x>0; $x--) {
742
            if (substr($cdata, $x, 1) == '>') {
743
                $endPos = $x;
744
                break;
745
            }
746
        }
747
        if ($startPos > 0) {
748
            $parte1 = substr($cdata, 0, $startPos);
749
        } else {
750
            $parte1 = '';
751
        }
752
        $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...
753
        if ($endPos < $len) {
754
            $parte3 = substr($cdata, $endPos + 1, $len - $endPos - 1);
755
        } else {
756
            $parte3 = '';
757
        }
758
        $texto = trim($parte1).' '.trim($parte3);
759
        if (strpos($parte2, '<CDATA>') === false) {
760
            $cdata = '<CDATA>'.$parte2.'</CDATA>';
761
        } else {
762
            $cdata = $parte2;
763
        }
764
        //Retira a tag <FONTE IBPT> (caso existir) pois não é uma estrutura válida XML
765
        $cdata = str_replace('<FONTE IBPT>', '', $cdata);
766
        //carrega o xml CDATA em um objeto DOM
767
        $dom = new Dom();
768
        $dom->loadXML($cdata, LIBXML_NOBLANKS | LIBXML_NOEMPTYTAG);
769
        //$xml = $dom->saveXML();
770
        //grupo CDATA infADprod
771
        $id = $dom->getElementsByTagName('id')->item(0);
772
        $div = $dom->getElementsByTagName('div')->item(0);
773
        $entg = $dom->getElementsByTagName('entg')->item(0);
774
        $dest = $dom->getElementsByTagName('dest')->item(0);
775
        $ctl = $dom->getElementsByTagName('ctl')->item(0);
776
        $ref = $dom->getElementsByTagName('ref')->item(0);
777
        if (isset($id)) {
778
            if ($id->hasAttributes()) {
779
                foreach ($id->attributes as $attr) {
780
                    $name = $attr->nodeName;
781
                    $value = $attr->nodeValue;
782
                    $texto .= " $name : $value";
783
                }
784
            }
785
        }
786
        if (isset($div)) {
787
            if ($div->hasAttributes()) {
788
                foreach ($div->attributes as $attr) {
789
                    $name = $attr->nodeName;
790
                    $value = $attr->nodeValue;
791
                    $texto .= " $name : $value";
792
                }
793
            }
794
        }
795
        if (isset($entg)) {
796
            if ($entg->hasAttributes()) {
797
                foreach ($entg->attributes as $attr) {
798
                    $name = $attr->nodeName;
799
                    $value = $attr->nodeValue;
800
                    $texto .= " $name : $value";
801
                }
802
            }
803
        }
804
        if (isset($dest)) {
805
            if ($dest->hasAttributes()) {
806
                foreach ($dest->attributes as $attr) {
807
                    $name = $attr->nodeName;
808
                    $value = $attr->nodeValue;
809
                    $texto .= " $name : $value";
810
                }
811
            }
812
        }
813
        if (isset($ctl)) {
814
            if ($ctl->hasAttributes()) {
815
                foreach ($ctl->attributes as $attr) {
816
                    $name = $attr->nodeName;
817
                    $value = $attr->nodeValue;
818
                    $texto .= " $name : $value";
819
                }
820
            }
821
        }
822
        if (isset($ref)) {
823
            if ($ref->hasAttributes()) {
824
                foreach ($ref->attributes as $attr) {
825
                    $name = $attr->nodeName;
826
                    $value = $attr->nodeValue;
827
                    $texto .= " $name : $value";
828
                }
829
            }
830
        }
831
        //grupo CADATA infCpl
832
        $t = $dom->getElementsByTagName('transmissor')->item(0);
833
        $r = $dom->getElementsByTagName('receptor')->item(0);
834
        $versao = ! empty($dom->getElementsByTagName('versao')->item(0)->nodeValue) ?
835
            'Versao:'.$dom->getElementsByTagName('versao')->item(0)->nodeValue.' ' : '';
836
        $especieNF = ! empty($dom->getElementsByTagName('especieNF')->item(0)->nodeValue) ?
837
            'Especie:'.$dom->getElementsByTagName('especieNF')->item(0)->nodeValue.' ' : '';
838
        $fabEntrega = ! empty($dom->getElementsByTagName('fabEntrega')->item(0)->nodeValue) ?
839
            'Entrega:'.$dom->getElementsByTagName('fabEntrega')->item(0)->nodeValue.' ' : '';
840
        $dca = ! empty($dom->getElementsByTagName('dca')->item(0)->nodeValue) ?
841
            'dca:'.$dom->getElementsByTagName('dca')->item(0)->nodeValue.' ' : '';
842
        $texto .= "".$versao.$especieNF.$fabEntrega.$dca;
843
        if (isset($t)) {
844
            if ($t->hasAttributes()) {
845
                $texto .= " Transmissor ";
846
                foreach ($t->attributes as $attr) {
847
                    $name = $attr->nodeName;
848
                    $value = $attr->nodeValue;
849
                    $texto .= " $name : $value";
850
                }
851
            }
852
        }
853
        if (isset($r)) {
854
            if ($r->hasAttributes()) {
855
                $texto .= " Receptor ";
856
                foreach ($r->attributes as $attr) {
857
                    $name = $attr->nodeName;
858
                    $value = $attr->nodeValue;
859
                    $texto .= " $name : $value";
860
                }
861
            }
862
        }
863
        return $texto;
864
    }
865
866
    /**
867
     * Verifica o status da NFe
868
     *
869
     * @return array
870
     */
871
    protected function statusNFe()
872
    {
873
        if (!isset($this->nfeProc)) {
874
            return ['status' => false, 'message' => 'NFe NÃO PROTOCOLADA'];
875
        }
876
        if ($this->getTagValue($this->ide, "tpAmb") == '2') {
877
            return ['status' => false, 'message' => 'NFe EMITIDA EM HOMOLOGAÇÃO'];
878
        }
879
        $cStat = $this->getTagValue($this->nfeProc, "cStat");
880
        if ($cStat == '101'
881
            || $cStat == '151'
882
            || $cStat == '135'
883
            || $cStat == '155'
884
        ) {
885
            return ['status' => false, 'message' => 'NFe CANCELADA'];
886
        }
887
        
888
        if ($cStat == '110' ||
889
               $cStat == '301' ||
890
               $cStat == '302'
891
               
892
        ) {
893
            return ['status' => false, 'message' => 'NFe DENEGADA'];
894
        }
895
        return ['status' => true, 'message' => ''];
896
    }
897
898
    protected function notaDPEC()
899
    {
900
        return $this->numero_registro_dpec != '';
901
    }
902
903
    /**
904
     *header
905
     * Monta o cabelhalho da DANFE (retrato e paisagem)
906
     *
907
     * @param  number $x      Posição horizontal inicial, canto esquerdo
908
     * @param  number $y      Posição vertical inicial, canto superior
909
     * @param  number $pag    Número da Página
910
     * @param  number $totPag Total de páginas
911
     * @return number Posição vertical final
912
     */
913
    protected function header($x = 0, $y = 0, $pag = '1', $totPag = '1')
914
    {
915
        $oldX = $x;
916
        $oldY = $y;
917
        if ($this->orientacao == 'P') {
918
              $maxW = $this->wPrint;
919
        } else {
920
            if ($pag == 1) { // primeira página
921
                $maxW = $this->wPrint - $this->wCanhoto;
922
            } else { // páginas seguintes
923
                $maxW = $this->wPrint;
924
            }
925
        }
926
        //####################################################################################
927
        //coluna esquerda identificação do emitente
928
        $w = round($maxW*0.41, 0);
929
        if ($this->orientacao == 'P') {
930
            $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>'I'];
931
        } else {
932
            $aFont = ['font'=>$this->fontePadrao, 'size'=>8, 'style'=>'B'];
933
        }
934
        $w1 = $w;
935
        $h=32;
936
        $oldY += $h;
937
        $this->pdf->textBox($x, $y, $w, $h);
938
        $texto = 'IDENTIFICAÇÃO DO EMITENTE';
939
        $this->pdf->textBox($x, $y, $w, 5, $texto, $aFont, 'T', 'C', 0, '');
940
        //estabelecer o alinhamento
941
        //pode ser left L, center C, right R, full logo L
942
        //se for left separar 1/3 da largura para o tamanho da imagem
943
        //os outros 2/3 serão usados para os dados do emitente
944
        //se for center separar 1/2 da altura para o logo e 1/2 para os dados
945
        //se for right separa 2/3 para os dados e o terço seguinte para o logo
946
        //se não houver logo centraliza dos dados do emitente
947
        // coloca o logo
948
        if (!empty($this->logomarca)) {
949
            $logoInfo = getimagesize($this->logomarca);
950
            $type = strtolower(explode('/', $logoInfo['mime'])[1]);
951
            if ($type == 'png') {
952
                $this->logomarca = $this->imagePNGtoJPG($this->logomarca);
953
                $type == 'jpg';
954
            }
955
            //largura da imagem em mm
956
            $logoWmm = ($logoInfo[0]/72)*25.4;
957
            //altura da imagem em mm
958
            $logoHmm = ($logoInfo[1]/72)*25.4;
959
            if ($this->logoAlign=='L') {
960
                $nImgW = round($w/3, 0);
961
                $nImgH = round($logoHmm * ($nImgW/$logoWmm), 0);
962
                $xImg = $x+1;
963
                $yImg = round(($h-$nImgH)/2, 0)+$y;
964
                //estabelecer posições do texto
965
                $x1 = round($xImg + $nImgW +1, 0);
966
                $y1 = round($h/3+$y, 0);
967
                $tw = round(2*$w/3, 0);
968
            } elseif ($this->logoAlign=='C') {
969
                $nImgH = round($h/3, 0);
970
                $nImgW = round($logoWmm * ($nImgH/$logoHmm), 0);
971
                $xImg = round(($w-$nImgW)/2+$x, 0);
972
                $yImg = $y+3;
973
                $x1 = $x;
974
                $y1 = round($yImg + $nImgH + 1, 0);
975
                $tw = $w;
976
            } elseif ($this->logoAlign=='R') {
977
                $nImgW = round($w/3, 0);
978
                $nImgH = round($logoHmm * ($nImgW/$logoWmm), 0);
979
                $xImg = round($x+($w-(1+$nImgW)), 0);
980
                $yImg = round(($h-$nImgH)/2, 0)+$y;
981
                $x1 = $x;
982
                $y1 = round($h/3+$y, 0);
983
                $tw = round(2*$w/3, 0);
984
            } elseif ($this->logoAlign=='F') {
985
                $nImgH = round($h-5, 0);
986
                $nImgW = round($logoWmm * ($nImgH/$logoHmm), 0);
987
                $xImg = round(($w-$nImgW)/2+$x, 0);
988
                $yImg = $y+3;
989
                $x1 = $x;
990
                $y1 = round($yImg + $nImgH + 1, 0);
991
                $tw = $w;
992
            }
993
            $type = (substr($this->logomarca, 0, 7) === 'data://') ? 'jpg' : null;
994
            $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...
995
        } else {
996
            $x1 = $x;
997
            $y1 = round($h/3+$y, 0);
998
            $tw = $w;
999
        }
1000
        // monta as informações apenas se diferente de full logo
1001
        if ($this->logoAlign !== 'F') {
1002
            //Nome emitente
1003
            $aFont = ['font'=>$this->fontePadrao, 'size'=>12, 'style'=>'B'];
1004
            $texto = $this->emit->getElementsByTagName("xNome")->item(0)->nodeValue;
1005
            $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...
1006
            //endereço
1007
            $y1 = $y1+5;
1008
            $aFont = ['font'=>$this->fontePadrao, 'size'=>8, 'style'=>''];
1009
            $fone = ! empty($this->enderEmit->getElementsByTagName("fone")->item(0)->nodeValue)
1010
            ? $this->enderEmit->getElementsByTagName("fone")->item(0)->nodeValue
1011
            : '';
1012
            $lgr = $this->getTagValue($this->enderEmit, "xLgr");
1013
            $nro = $this->getTagValue($this->enderEmit, "nro");
1014
            $cpl = $this->getTagValue($this->enderEmit, "xCpl", " - ");
1015
            $bairro = $this->getTagValue($this->enderEmit, "xBairro");
1016
            $CEP = $this->getTagValue($this->enderEmit, "CEP");
1017
            $CEP = $this->formatField($CEP, "#####-###");
1018
            $mun = $this->getTagValue($this->enderEmit, "xMun");
1019
            $UF = $this->getTagValue($this->enderEmit, "UF");
1020
            $texto = $lgr . ", " . $nro . $cpl . "\n" . $bairro . " - "
1021
                . $CEP . "\n" . $mun . " - " . $UF . " "
1022
                . "Fone/Fax: " . $fone;
1023
            $this->pdf->textBox($x1, $y1, $tw, 8, $texto, $aFont, 'T', 'C', 0, '');
1024
        }
1025
1026
        //####################################################################################
1027
        //coluna central Danfe
1028
        $x += $w;
1029
        $w=round($maxW * 0.17, 0);//35;
1030
        $w2 = $w;
1031
        $h = 32;
1032
        $this->pdf->textBox($x, $y, $w, $h);
1033
  
1034
        $texto = "DANFE";
1035
        $aFont = ['font'=>$this->fontePadrao, 'size'=>14, 'style'=>'B'];
1036
        $this->pdf->textBox($x, $y+1, $w, $h, $texto, $aFont, 'T', 'C', 0, '');
1037
        $aFont = ['font'=>$this->fontePadrao, 'size'=>8, 'style'=>''];
1038
        $texto = 'Documento Auxiliar da Nota Fiscal Eletrônica';
1039
        $h = 20;
1040
        $this->pdf->textBox($x, $y+6, $w, $h, $texto, $aFont, 'T', 'C', 0, '', false);
1041
1042
        $aFont = ['font'=>$this->fontePadrao, 'size'=>8, 'style'=>''];
1043
        $texto = '0 - ENTRADA';
1044
        $y1 = $y + 14;
1045
        $h = 8;
1046
        $this->pdf->textBox($x+2, $y1, $w, $h, $texto, $aFont, 'T', 'L', 0, '');
1047
        $texto = '1 - SAÍDA';
1048
        $y1 = $y + 17;
1049
        $this->pdf->textBox($x+2, $y1, $w, $h, $texto, $aFont, 'T', 'L', 0, '');
1050
        //tipo de nF
1051
        $aFont = ['font'=>$this->fontePadrao, 'size'=>12, 'style'=>'B'];
1052
        $y1 = $y + 13;
1053
        $h = 7;
1054
        $texto = $this->ide->getElementsByTagName('tpNF')->item(0)->nodeValue;
1055
        $this->pdf->textBox($x+27, $y1, 5, $h, $texto, $aFont, 'C', 'C', 1, '');
1056
        //numero da NF
1057
        $aFont = ['font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B'];
1058
        $y1 = $y + 20;
1059
        $numNF = str_pad(
1060
            $this->ide->getElementsByTagName('nNF')->item(0)->nodeValue,
1061
            9,
1062
            "0",
1063
            STR_PAD_LEFT
1064
        );
1065
        $numNF = $this->formatField($numNF, "###.###.###");
1066
        $texto = "Nº. " . $numNF;
1067
        $this->pdf->textBox($x, $y1, $w, $h, $texto, $aFont, 'C', 'C', 0, '');
1068
        //Série
1069
        $y1 = $y + 23;
1070
        $serie = str_pad(
1071
            $this->ide->getElementsByTagName('serie')->item(0)->nodeValue,
1072
            3,
1073
            "0",
1074
            STR_PAD_LEFT
1075
        );
1076
        $texto = "Série " . $serie;
1077
        $this->pdf->textBox($x, $y1, $w, $h, $texto, $aFont, 'C', 'C', 0, '');
1078
        //numero paginas
1079
        $aFont = ['font'=>$this->fontePadrao, 'size'=>8, 'style'=>'I'];
1080
        $y1 = $y + 26;
1081
        $texto = "Folha " . $pag . "/" . $totPag;
1082
        $this->pdf->textBox($x, $y1, $w, $h, $texto, $aFont, 'C', 'C', 0, '');
1083
1084
        //####################################################################################
1085
        //coluna codigo de barras
1086
        $x += $w;
1087
        $w = ($maxW-$w1-$w2);//85;
1088
        $w3 = $w;
1089
        $h = 32;
1090
        $this->pdf->textBox($x, $y, $w, $h);
1091
        $this->pdf->setFillColor(0, 0, 0);
1092
        $chave_acesso = str_replace('NFe', '', $this->infNFe->getAttribute("Id"));
1093
        $bW = 75;
1094
        $bH = 12;
1095
        //codigo de barras
1096
        $this->pdf->code128($x+(($w-$bW)/2), $y+2, $chave_acesso, $bW, $bH);
1097
        //linhas divisorias
1098
        $this->pdf->line($x, $y+4+$bH, $x+$w, $y+4+$bH);
1099
        $this->pdf->line($x, $y+12+$bH, $x+$w, $y+12+$bH);
1100
        $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
1101
        $y1 = $y+4+$bH;
1102
        $h = 7;
1103
        $texto = 'CHAVE DE ACESSO';
1104
        $this->pdf->textBox($x, $y1, $w, $h, $texto, $aFont, 'T', 'L', 0, '');
1105
        $aFont = ['font'=>$this->fontePadrao, 'size'=>8, 'style'=>'B'];
1106
        $y1 = $y+8+$bH;
1107
        $texto = $this->formatField($chave_acesso, $this->formatoChave);
1108
        $this->pdf->textBox($x+2, $y1, $w-2, $h, $texto, $aFont, 'T', 'C', 0, '');
1109
        $y1 = $y+12+$bH;
1110
        $aFont = ['font'=>$this->fontePadrao, 'size'=>8, 'style'=>''];
1111
        $chaveContingencia="";
1112
        if ($this->notaDpec()) {
1113
            $cabecalhoProtoAutorizacao = 'NÚMERO DE REGISTRO DPEC';
1114
        } else {
1115
            $cabecalhoProtoAutorizacao = 'PROTOCOLO DE AUTORIZAÇÃO DE USO';
1116
        }
1117
        if (($this->tpEmis == 2 || $this->tpEmis == 5) && !$this->notaDpec()) {
1118
            $cabecalhoProtoAutorizacao = "DADOS DA NF-E";
1119
            $chaveContingencia = $this->geraChaveAdicionalDeContingencia();
1120
            $this->pdf->setFillColor(0, 0, 0);
1121
            //codigo de barras
1122
            $this->pdf->code128($x+11, $y1+1, $chaveContingencia, $bW*.9, $bH/2);
1123
        } else {
1124
            $texto = 'Consulta de autenticidade no portal nacional da NF-e';
1125
            $this->pdf->textBox($x+2, $y1, $w-2, $h, $texto, $aFont, 'T', 'C', 0, '');
1126
            $y1 = $y+16+$bH;
1127
            $texto = 'www.nfe.fazenda.gov.br/portal ou no site da Sefaz Autorizadora';
1128
            $this->pdf->textBox(
1129
                $x+2,
1130
                $y1,
1131
                $w-2,
1132
                $h,
1133
                $texto,
1134
                $aFont,
1135
                'T',
1136
                'C',
1137
                0,
1138
                'http://www.nfe.fazenda.gov.br/portal ou no site da Sefaz Autorizadora'
1139
            );
1140
        }
1141
1142
        //####################################################################################
1143
        //Dados da NF do cabeçalho
1144
        //natureza da operação
1145
        $texto = 'NATUREZA DA OPERAÇÃO';
1146
        $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
1147
        $w = $w1+$w2;
1148
        $y = $oldY;
1149
        $oldY += $h;
1150
        $x = $oldX;
1151
        $h = 7;
1152
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 1, '');
1153
        $texto = $this->ide->getElementsByTagName("natOp")->item(0)->nodeValue;
1154
        $aFont = ['font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B'];
1155
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'B', 'C', 0, '');
1156
        $x += $w;
1157
        $w = $w3;
1158
        //PROTOCOLO DE AUTORIZAÇÃO DE USO ou DADOS da NF-E
1159
        $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
1160
        $this->pdf->textBox($x, $y, $w, $h, $cabecalhoProtoAutorizacao, $aFont, 'T', 'L', 1, '');
1161
        // algumas NFe podem estar sem o protocolo de uso portanto sua existencia deve ser
1162
        // testada antes de tentar obter a informação.
1163
        // NOTA : DANFE sem protocolo deve existir somente no caso de contingência !!!
1164
        // Além disso, existem várias NFes em contingência que eu recebo com protocolo de autorização.
1165
        // Na minha opinião, deveríamos mostra-lo, mas o  manual  da NFe v4.01 diz outra coisa...
1166
        if (($this->tpEmis == 2 || $this->tpEmis == 5) && !$this->notaDpec()) {
1167
            $aFont = ['font'=>$this->fontePadrao, 'size'=>8, 'style'=>'B'];
1168
            $texto = $this->formatField(
1169
                $chaveContingencia,
1170
                "#### #### #### #### #### #### #### #### ####"
1171
            );
1172
            $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...
1173
        } else {
1174
            $aFont = ['font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B'];
1175
            if ($this->notaDpec()) {
1176
                $texto = $this->numero_registro_dpec;
1177
                $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...
1178
            } else {
1179
                if (isset($this->nfeProc)) {
1180
                    $texto = ! empty($this->nfeProc->getElementsByTagName("nProt")->item(0)->nodeValue)
1181
                    ? $this->nfeProc->getElementsByTagName("nProt")->item(0)->nodeValue
1182
                    : '';
1183
                    $tsHora = $this->toTimestamp(
1184
                        $this->nfeProc->getElementsByTagName("dhRecbto")->item(0)->nodeValue
1185
                    );
1186
                    if ($texto != '') {
1187
                        $texto .= "  -  " . date('d/m/Y H:i:s', $tsHora);
1188
                    }
1189
                    $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...
1190
                } else {
1191
                    $texto = '';
1192
                    $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...
1193
                }
1194
            }
1195
        }
1196
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'B', 'C', 0, '');
1197
        //####################################################################################
1198
        //INSCRIÇÃO ESTADUAL
1199
        $w = round($maxW * 0.333, 0);
1200
        $y += $h;
1201
        $oldY += $h;
1202
        $x = $oldX;
1203
        $texto = 'INSCRIÇÃO ESTADUAL';
1204
        $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
1205
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 1, '');
1206
        $texto = $this->getTagValue($this->emit, "IE");
1207
        $aFont = ['font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B'];
1208
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'B', 'C', 0, '');
1209
        //INSCRIÇÃO ESTADUAL DO SUBST. TRIBUT.
1210
        $x += $w;
1211
        $texto = 'INSCRIÇÃO ESTADUAL DO SUBST. TRIBUT.';
1212
        $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
1213
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 1, '');
1214
        $texto = ! empty($this->emit->getElementsByTagName("IEST")->item(0)->nodeValue)
1215
        ? $this->emit->getElementsByTagName("IEST")->item(0)->nodeValue
1216
        : '';
1217
        $aFont = ['font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B'];
1218
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'B', 'C', 0, '');
1219
        //CNPJ
1220
        $x += $w;
1221
        $w = ($maxW-(2*$w));
1222
        $texto = 'CNPJ / CPF';
1223
        $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
1224
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 1, '');
1225
        //Pegando valor do CPF/CNPJ
1226
        if (! empty($this->emit->getElementsByTagName("CNPJ")->item(0)->nodeValue)) {
1227
            $texto = $this->formatField(
1228
                $this->emit->getElementsByTagName("CNPJ")->item(0)->nodeValue,
1229
                "###.###.###/####-##"
1230
            );
1231
        } else {
1232
            $texto = ! empty($this->emit->getElementsByTagName("CPF")->item(0)->nodeValue)
1233
            ? $this->formatField(
1234
                $this->emit->getElementsByTagName("CPF")->item(0)->nodeValue,
1235
                "###.###.###-##"
1236
            )
1237
            : '';
1238
        }
1239
        $aFont = ['font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B'];
1240
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'B', 'C', 0, '');
1241
1242
        //####################################################################################
1243
        //Indicação de NF Homologação, cancelamento e falta de protocolo
1244
        $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...
1245
        //indicar cancelamento
1246
        $resp = $this->statusNFe();
1247
        if (!$resp['status']) {
1248
            $x = 10;
1249
            $y = $this->hPrint-130;
1250
            $h = 25;
1251
            $w = $maxW-(2*$x);
1252
            $this->pdf->settextcolor(90, 90, 90);
1253
            $texto = $resp['message'];
1254
            $aFont = ['font'=>$this->fontePadrao, 'size'=>48, 'style'=>'B'];
1255
            $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'C', 'C', 0, '');
1256
            $y += $h;
1257
            $h = 5;
1258
            $w = $maxW-(2*$x);
1259
            if (isset($this->infProt) && $resp['status']) {
1260
                $xMotivo = $this->infProt->getElementsByTagName("xMotivo")->item(0)->nodeValue;
1261
            } else {
1262
                $xMotivo = '';
1263
            }
1264
            $texto = "SEM VALOR FISCAL\n".$xMotivo;
1265
            $aFont = ['font'=>$this->fontePadrao, 'size'=>48, 'style'=>'B'];
1266
            $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'C', 'C', 0, '');
1267
            $this->pdf->settextcolor(0, 0, 0);
1268
        }
1269
        
1270
        if ($this->pNotaCancelada()) {
1271
            //101 Cancelamento
1272
            $x = 10;
1273
            $y = $this->hPrint-140;
1274
            $h = 25;
1275
            $w = $maxW-(2*$x);
1276
            $this->pdf->SetTextColor(90, 90, 90);
1277
            $texto = "NFe CANCELADA";
1278
            $aFont = ['font'=>$this->fontePadrao, 'size'=>48, 'style'=>'B'];
1279
            $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'C', 'C', 0, '');
1280
            $this->pdf->SetTextColor(0, 0, 0);
1281
        }
1282
1283
        if ($this->notaDpec() || $this->tpEmis == 4) {
1284
            //DPEC
1285
            $x = 10;
1286
            $y = $this->hPrint-130;
1287
            $h = 25;
1288
            $w = $maxW-(2*$x);
1289
            $this->pdf->SetTextColor(200, 200, 200);
1290
            $texto = "DANFE impresso em contingência -\n".
1291
                     "DPEC regularmente recebido pela Receita\n".
1292
                     "Federal do Brasil";
1293
            $aFont = ['font'=>$this->fontePadrao, 'size'=>48, 'style'=>'B'];
1294
            $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'C', 'C', 0, '');
1295
            $this->pdf->SetTextColor(0, 0, 0);
1296
        }
1297
        /*
1298
        if ($this->pNotaDenegada()) {
1299
            //110 301 302 Denegada
1300
            $x = 10;
1301
            $y = $this->hPrint-130;
1302
            $h = 25;
1303
            $w = $maxW-(2*$x);
1304
            $this->pdf->SetTextColor(90, 90, 90);
1305
            $texto = "NFe USO DENEGADO";
1306
            $aFont = ['font'=>$this->fontePadrao, 'size'=>48, 'style'=>'B'];
1307
            $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'C', 'C', 0, '');
1308
            $y += $h;
1309
            $h = 5;
1310
            $w = $maxW-(2*$x);
1311
            if (isset($this->infProt)) {
1312
                $xMotivo = $this->infProt->getElementsByTagName("xMotivo")->item(0)->nodeValue;
1313
            } else {
1314
                $xMotivo = '';
1315
            }
1316
            $texto = "SEM VALOR FISCAL\n".$xMotivo;
1317
            $aFont = ['font'=>$this->fontePadrao, 'size'=>48, 'style'=>'B'];
1318
            $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'C', 'C', 0, '');
1319
            $this->pdf->SetTextColor(0, 0, 0);
1320
        }
1321
         *
1322
         */
1323
        //indicar sem valor
1324
        /*
1325
        if ($tpAmb != 1) {
1326
            $x = 10;
1327
            if ($this->orientacao == 'P') {
1328
                $y = round($this->hPrint*2/3, 0);
1329
            } else {
1330
                $y = round($this->hPrint/2, 0);
1331
            }
1332
            $h = 5;
1333
            $w = $maxW-(2*$x);
1334
            $this->pdf->SetTextColor(90, 90, 90);
1335
            $texto = "SEM VALOR FISCAL";
1336
            $aFont = ['font'=>$this->fontePadrao, 'size'=>48, 'style'=>'B'];
1337
            $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'C', 'C', 0, '');
1338
            $aFont = ['font'=>$this->fontePadrao, 'size'=>30, 'style'=>'B'];
1339
            $texto = "AMBIENTE DE HOMOLOGAÇÃO";
1340
            $this->pdf->textBox($x, $y+14, $w, $h, $texto, $aFont, 'C', 'C', 0, '');
1341
            $this->pdf->SetTextColor(0, 0, 0);
1342
        } else {
1343
            $x = 10;
1344
            if ($this->orientacao == 'P') {
1345
                $y = round($this->hPrint*2/3, 0);
1346
            } else {
1347
                $y = round($this->hPrint/2, 0);
1348
            }//fim orientacao
1349
            $h = 5;
1350
            $w = $maxW-(2*$x);
1351
            $this->pdf->SetTextColor(90, 90, 90);
1352
            //indicar FALTA DO PROTOCOLO se NFe não for em contingência
1353
            if (($this->tpEmis == 2 || $this->tpEmis == 5) && !$this->notaDpec()) {
1354
                //Contingência
1355
                $texto = "DANFE Emitido em Contingência";
1356
                $aFont = ['font'=>$this->fontePadrao, 'size'=>48, 'style'=>'B'];
1357
                $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'C', 'C', 0, '');
1358
                $aFont = ['font'=>$this->fontePadrao, 'size'=>30, 'style'=>'B'];
1359
                $texto = "devido à problemas técnicos";
1360
                $this->pdf->textBox($x, $y+12, $w, $h, $texto, $aFont, 'C', 'C', 0, '');
1361
            } else {
1362
                if (!isset($this->nfeProc)) {
1363
                    if (!$this->notaDpec()) {
1364
                        $texto = "SEM VALOR FISCAL";
1365
                        $aFont = ['font'=>$this->fontePadrao, 'size'=>48, 'style'=>'B'];
1366
                        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'C', 'C', 0, '');
1367
                    }
1368
                    $aFont = ['font'=>$this->fontePadrao, 'size'=>30, 'style'=>'B'];
1369
                    $texto = "FALTA PROTOCOLO DE APROVAÇÃO DA SEFAZ";
1370
                    if (!$this->notaDpec()) {
1371
                        $this->pdf->textBox($x, $y+12, $w, $h, $texto, $aFont, 'C', 'C', 0, '');
1372
                    } else {
1373
                        $this->pdf->textBox($x, $y+25, $w, $h, $texto, $aFont, 'C', 'C', 0, '');
1374
                    }
1375
                }//fim nefProc
1376
            }//fim tpEmis
1377
            $this->pdf->SetTextColor(0, 0, 0);
1378
        }
1379
         *
1380
         */
1381
        return $oldY;
1382
    } //fim header
1383
1384
    /**
1385
     * destinatarioDANFE
1386
     * Monta o campo com os dados do destinatário na DANFE. (retrato e paisagem)
1387
     *
1388
     * @name   destinatarioDANFE
1389
     * @param  number $x Posição horizontal canto esquerdo
1390
     * @param  number $y Posição vertical canto superior
1391
     * @return number Posição vertical final
1392
     */
1393
    protected function destinatarioDANFE($x = 0, $y = 0)
1394
    {
1395
        //####################################################################################
1396
        //DESTINATÁRIO / REMETENTE
1397
        $oldX = $x;
1398
        $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...
1399
        if ($this->orientacao == 'P') {
1400
            $maxW = $this->wPrint;
1401
        } else {
1402
            $maxW = $this->wPrint - $this->wCanhoto;
1403
        }
1404
        $w = $maxW;
1405
        $h = 7;
1406
        $texto = 'DESTINATÁRIO / REMETENTE';
1407
        $aFont = ['font'=>$this->fontePadrao, 'size'=>7, 'style'=>'B'];
1408
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 0, '');
1409
        //NOME / RAZÃO SOCIAL
1410
        $w = round($maxW*0.61, 0);
1411
        $w1 = $w;
1412
        $y += 3;
1413
        $texto = 'NOME / RAZÃO SOCIAL';
1414
        $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
1415
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 1, '');
1416
        $texto = $this->dest->getElementsByTagName("xNome")->item(0)->nodeValue;
1417
        $aFont = ['font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B'];
1418
        if ($this->orientacao == 'P') {
1419
            $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'B', 'L', 0, '');
1420
        } else {
1421
            $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'B', 'L', 1, '');
1422
        }
1423
        //CNPJ / CPF
1424
        $x += $w;
1425
        $w = round($maxW*0.23, 0);
1426
        $w2 = $w;
1427
        $texto = 'CNPJ / CPF';
1428
        $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
1429
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 1, '');
1430
        //Pegando valor do CPF/CNPJ
1431
        if (! empty($this->dest->getElementsByTagName("CNPJ")->item(0)->nodeValue)) {
1432
            $texto = $this->formatField(
1433
                $this->dest->getElementsByTagName("CNPJ")->item(0)->nodeValue,
1434
                "###.###.###/####-##"
1435
            );
1436
        } else {
1437
            $texto = ! empty($this->dest->getElementsByTagName("CPF")->item(0)->nodeValue)
1438
            ? $this->formatField(
1439
                $this->dest->getElementsByTagName("CPF")->item(0)->nodeValue,
1440
                "###.###.###-##"
1441
            )
1442
            : '';
1443
        }
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 EMISSÃO
1447
        $x += $w;
1448
        $w = $maxW-($w1+$w2);
1449
        $wx = $w;
1450
        $texto = 'DATA DA EMISSÃO';
1451
        $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
1452
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 1, '');
1453
        $dEmi = ! empty($this->ide->getElementsByTagName("dEmi")->item(0)->nodeValue)
1454
        ? $this->ide->getElementsByTagName("dEmi")->item(0)->nodeValue
1455
        : '';
1456
        if ($dEmi == '') {
1457
            $dEmi = ! empty($this->ide->getElementsByTagName("dhEmi")->item(0)->nodeValue)
1458
            ? $this->ide->getElementsByTagName("dhEmi")->item(0)->nodeValue
1459
            : '';
1460
            $aDemi = explode('T', $dEmi);
1461
            $dEmi = $aDemi[0];
1462
        }
1463
        $texto = $this->ymdTodmy($dEmi);
1464
        $aFont = ['font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B'];
1465
        if ($this->orientacao == 'P') {
1466
            $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'B', 'C', 0, '');
1467
        } else {
1468
            $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'B', 'C', 1, '');
1469
        }
1470
        //ENDEREÇO
1471
        $w = round($maxW*0.47, 0);
1472
        $w1 = $w;
1473
        $y += $h;
1474
        $x = $oldX;
1475
        $texto = 'ENDEREÇO';
1476
        $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
1477
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 1, '');
1478
        $texto = $this->dest->getElementsByTagName("xLgr")->item(0)->nodeValue;
1479
        $texto .= ', ' . $this->dest->getElementsByTagName("nro")->item(0)->nodeValue;
1480
        $texto .= $this->getTagValue($this->dest, "xCpl", " - ");
1481
1482
        $aFont = ['font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B'];
1483
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'B', 'L', 0, '', true);
1484
        //BAIRRO / DISTRITO
1485
        $x += $w;
1486
        $w = round($maxW*0.21, 0);
1487
        $w2 = $w;
1488
        $texto = 'BAIRRO / DISTRITO';
1489
        $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
1490
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 1, '');
1491
        $texto = $this->dest->getElementsByTagName("xBairro")->item(0)->nodeValue;
1492
        $aFont = ['font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B'];
1493
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'B', 'C', 0, '');
1494
        //CEP
1495
        $x += $w;
1496
        $w = $maxW-$w1-$w2-$wx;
1497
        $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...
1498
        $texto = 'CEP';
1499
        $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
1500
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 1, '');
1501
        $texto = ! empty($this->dest->getElementsByTagName("CEP")->item(0)->nodeValue)
1502
        ? $this->dest->getElementsByTagName("CEP")->item(0)->nodeValue
1503
        : '';
1504
        $texto = $this->formatField($texto, "#####-###");
1505
        $aFont = ['font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B'];
1506
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'B', 'C', 0, '');
1507
        //DATA DA SAÍDA
1508
        $x += $w;
1509
        $w = $wx;
1510
        $texto = 'DATA DA SAÍDA/ENTRADA';
1511
        $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
1512
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 1, '');
1513
        $dSaiEnt = ! empty($this->ide->getElementsByTagName("dSaiEnt")->item(0)->nodeValue)
1514
            ? $this->ide->getElementsByTagName("dSaiEnt")->item(0)->nodeValue
1515
            : '';
1516
        if ($dSaiEnt == '') {
1517
            $dSaiEnt = ! empty($this->ide->getElementsByTagName("dhSaiEnt")->item(0)->nodeValue)
1518
                ? $this->ide->getElementsByTagName("dhSaiEnt")->item(0)->nodeValue
1519
                : '';
1520
            $aDsaient = explode('T', $dSaiEnt);
1521
            $dSaiEnt = $aDsaient[0];
1522
        }
1523
        $texto = $this->ymdTodmy($dSaiEnt);
1524
        $aFont = ['font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B'];
1525
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'B', 'C', 0, '');
1526
        //MUNICÍPIO
1527
        $w = $w1;
1528
        $y += $h;
1529
        $x = $oldX;
1530
        $texto = 'MUNICÍPIO';
1531
        $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
1532
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 1, '');
1533
        $texto = $this->dest->getElementsByTagName("xMun")->item(0)->nodeValue;
1534
        if (strtoupper(trim($texto)) == "EXTERIOR"
1535
            && $this->dest->getElementsByTagName("xPais")->length > 0
1536
        ) {
1537
            $texto .= " - " .  $this->dest->getElementsByTagName("xPais")->item(0)->nodeValue;
1538
        }
1539
        $aFont = ['font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B'];
1540
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'B', 'L', 0, '');
1541
        //UF
1542
        $x += $w;
1543
        $w = 8;
1544
        $texto = 'UF';
1545
        $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
1546
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 1, '');
1547
        $texto = $this->dest->getElementsByTagName("UF")->item(0)->nodeValue;
1548
        $aFont = ['font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B'];
1549
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'B', 'C', 0, '');
1550
        //FONE / FAX
1551
        $x += $w;
1552
        $w = round(($maxW -$w1-$wx-8)/2, 0);
1553
        $w3 = $w;
1554
        $texto = 'FONE / FAX';
1555
        $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
1556
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 1, '');
1557
        $texto = ! empty($this->dest->getElementsByTagName("fone")->item(0)->nodeValue)
1558
        ? $this->dest->getElementsByTagName("fone")->item(0)->nodeValue
1559
        : '';
1560
        $aFont = ['font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B'];
1561
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'B', 'C', 0, '');
1562
        //INSCRIÇÃO ESTADUAL
1563
        $x += $w;
1564
        $w = $maxW -$w1-$wx-8-$w3;
1565
        $texto = 'INSCRIÇÃO ESTADUAL';
1566
        $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
1567
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 1, '');
1568
        $IE = $this->dest->getElementsByTagName("IE");
1569
        $texto = ($IE && $IE->length > 0) ? $IE->item(0)->nodeValue : '';
1570
        $aFont = ['font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B'];
1571
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'B', 'C', 0, '');
1572
        //HORA DA SAÍDA
1573
        $x += $w;
1574
        $w = $wx;
1575
        $texto = 'HORA DA SAÍDA/ENTRADA';
1576
        $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
1577
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 1, '');
1578
        $hSaiEnt = ! empty($this->ide->getElementsByTagName("hSaiEnt")->item(0)->nodeValue)
1579
        ? $this->ide->getElementsByTagName("hSaiEnt")->item(0)->nodeValue
1580
        : '';
1581
        if ($hSaiEnt == '') {
1582
            $dhSaiEnt = ! empty($this->ide->getElementsByTagName("dhSaiEnt")->item(0)->nodeValue)
1583
            ? $this->ide->getElementsByTagName("dhSaiEnt")->item(0)->nodeValue
1584
            : '';
1585
            $tsDhSaiEnt = $this->toTimestamp($dhSaiEnt);
1586
            if ($tsDhSaiEnt != '') {
1587
                $hSaiEnt = date('H:i:s', $tsDhSaiEnt);
1588
            }
1589
        }
1590
        $texto = $hSaiEnt;
1591
        $aFont = ['font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B'];
1592
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'B', 'C', 0, '');
1593
        return ($y + $h);
1594
    } //fim da função destinatarioDANFE
1595
1596
    /**
1597
     * localEntregaDANFE
1598
     * Monta o campo com os dados do local de entrega na DANFE. (retrato e paisagem)
1599
     *
1600
     * @name   localEntregaDANFE
1601
     * @param  number $x Posição horizontal canto esquerdo
1602
     * @param  number $y Posição vertical canto superior
1603
     * @return number Posição vertical final
1604
     */
1605
    protected function localEntregaDANFE($x = 0, $y = 0)
1606
    {
1607
        //####################################################################################
1608
        //LOCAL DE ENTREGA
1609
        $oldX = $x;
1610
        if ($this->orientacao == 'P') {
1611
            $maxW = $this->wPrint;
1612
        } else {
1613
            $maxW = $this->wPrint - $this->wCanhoto;
1614
        }
1615
        $w = $maxW;
1616
        $h = 7;
1617
        $texto = 'INFORMAÇÕES DO LOCAL DE ENTREGA';
1618
        $aFont = array('font'=>$this->fontePadrao, 'size'=>7, 'style'=>'B');
1619
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 0, '');
1620
        //NOME / RAZÃO SOCIAL
1621
        $w = round($maxW*0.61, 0);
1622
        $w1 = $w;
1623
        $y += 3;
1624
        $texto = 'NOME / RAZÃO SOCIAL';
1625
        $aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>'');
1626
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 1, '');
1627
        $texto = '';
1628
        if ($this->entrega->getElementsByTagName("xNome")->item(0)) {
1629
            $texto = $this->entrega->getElementsByTagName("xNome")->item(0)->nodeValue;
1630
        }
1631
        $aFont = array('font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B');
1632
        if ($this->orientacao == 'P') {
1633
            $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'B', 'L', 0, '');
1634
        } else {
1635
            $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'B', 'L', 1, '');
1636
        }
1637
        //CNPJ / CPF
1638
        $x += $w;
1639
        $w = round($maxW*0.23, 0);
1640
        $w2 = $w;
1641
        $texto = 'CNPJ / CPF';
1642
        $aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>'');
1643
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 1, '');
1644
        //Pegando valor do CPF/CNPJ
1645
        if (! empty($this->entrega->getElementsByTagName("CNPJ")->item(0)->nodeValue)) {
1646
            $texto = $this->formatField(
1647
                $this->entrega->getElementsByTagName("CNPJ")->item(0)->nodeValue,
1648
                "###.###.###/####-##"
1649
            );
1650
        } else {
1651
            $texto = ! empty($this->entrega->getElementsByTagName("CPF")->item(0)->nodeValue) ?
1652
                    $this->formatField(
1653
                        $this->entrega->getElementsByTagName("CPF")->item(0)->nodeValue,
1654
                        "###.###.###-##"
1655
                    ) : '';
1656
        }
1657
        $aFont = array('font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B');
1658
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'B', 'C', 0, '');
1659
        //INSCRIÇÃO ESTADUAL
1660
        $x += $w;
1661
        $w = $maxW-($w1+$w2);
1662
        $wx = $w;
1663
        $texto = 'INSCRIÇÃO ESTADUAL';
1664
        $aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>'');
1665
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 1, '');
1666
        $texto = '';
1667
        if ($this->entrega->getElementsByTagName("IE")->item(0)) {
1668
            $texto = $this->entrega->getElementsByTagName("IE")->item(0)->nodeValue;
1669
        }
1670
        $aFont = array('font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B');
1671
        if ($this->orientacao == 'P') {
1672
            $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'B', 'C', 0, '');
1673
        } else {
1674
            $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'B', 'C', 1, '');
1675
        }
1676
        //ENDEREÇO
1677
        $w = round($maxW*0.355, 0) + $wx;
1678
        $w1 = $w;
1679
        $y += $h;
1680
        $x = $oldX;
1681
        $texto = 'ENDEREÇO';
1682
        $aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>'');
1683
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 1, '');
1684
        $texto = $this->entrega->getElementsByTagName("xLgr")->item(0)->nodeValue;
1685
        $texto .= ', ' . $this->entrega->getElementsByTagName("nro")->item(0)->nodeValue;
1686
        $texto .= $this->getTagValue($this->entrega, "xCpl", " - ");
1687
        $aFont = array('font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B');
1688
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'B', 'L', 0, '', true);
1689
        //BAIRRO / DISTRITO
1690
        $x += $w;
1691
        $w = round($maxW*0.335, 0);
1692
        $w2 = $w;
1693
        $texto = 'BAIRRO / DISTRITO';
1694
        $aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>'');
1695
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 1, '');
1696
        $texto = $this->entrega->getElementsByTagName("xBairro")->item(0)->nodeValue;
1697
        $aFont = array('font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B');
1698
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'B', 'C', 0, '');
1699
        //CEP
1700
        $x += $w;
1701
        $w = $maxW-($w1+$w2);
1702
        $texto = 'CEP';
1703
        $aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>'');
1704
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 1, '');
1705
        $texto = ! empty($this->entrega->getElementsByTagName("CEP")->item(0)->nodeValue) ?
1706
                $this->entrega->getElementsByTagName("CEP")->item(0)->nodeValue : '';
1707
        $texto = $this->formatField($texto, "#####-###");
1708
        $aFont = array('font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B');
1709
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'B', 'C', 0, '');
1710
        //MUNICÍPIO
1711
        $w = round($maxW*0.805, 0);
1712
        $w1 = $w;
1713
        $y += $h;
1714
        $x = $oldX;
1715
        $texto = 'MUNICÍPIO';
1716
        $aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>'');
1717
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 1, '');
1718
        $texto = $this->entrega->getElementsByTagName("xMun")->item(0)->nodeValue;
1719
        if (strtoupper(trim($texto)) == "EXTERIOR" && $this->entrega->getElementsByTagName("xPais")->length > 0) {
1720
            $texto .= " - " .  $this->entrega->getElementsByTagName("xPais")->item(0)->nodeValue;
1721
        }
1722
        $aFont = array('font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B');
1723
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'B', 'L', 0, '');
1724
        //UF
1725
        $x += $w;
1726
        $w = 8;
1727
        $texto = 'UF';
1728
        $aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>'');
1729
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 1, '');
1730
        $texto = $this->entrega->getElementsByTagName("UF")->item(0)->nodeValue;
1731
        $aFont = array('font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B');
1732
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'B', 'C', 0, '');
1733
        //FONE / FAX
1734
        $x += $w;
1735
        $w = $maxW-$w-$w1;
1736
        $texto = 'FONE / FAX';
1737
        $aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>'');
1738
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 1, '');
1739
        $texto = ! empty($this->entrega->getElementsByTagName("fone")->item(0)->nodeValue) ?
1740
                $this->entrega->getElementsByTagName("fone")->item(0)->nodeValue : '';
1741
        $aFont = array('font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B');
1742
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'B', 'C', 0, '');
1743
        return ($y + $h);
1744
    } //fim da função localEntregaDANFE
1745
    
1746
    /**
1747
     * localretiradaDANFE
1748
     * Monta o campo com os dados do local de entrega na DANFE. (retrato e paisagem)
1749
     *
1750
     * @name   localretiradaDANFE
1751
     * @param  number $x Posição horizontal canto esquerdo
1752
     * @param  number $y Posição vertical canto superior
1753
     * @return number Posição vertical final
1754
     */
1755
    protected function localRetiradaDANFE($x = 0, $y = 0)
1756
    {
1757
        //####################################################################################
1758
        //LOCAL DE RETIRADA
1759
        $oldX = $x;
1760
        if ($this->orientacao == 'P') {
1761
            $maxW = $this->wPrint;
1762
        } else {
1763
            $maxW = $this->wPrint - $this->wCanhoto;
1764
        }
1765
        $w = $maxW;
1766
        $h = 7;
1767
        $texto = 'INFORMAÇÕES DO LOCAL DE RETIRADA';
1768
        $aFont = array('font'=>$this->fontePadrao, 'size'=>7, 'style'=>'B');
1769
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 0, '');
1770
        //NOME / RAZÃO SOCIAL
1771
        $w = round($maxW*0.61, 0);
1772
        $w1 = $w;
1773
        $y += 3;
1774
        $texto = 'NOME / RAZÃO SOCIAL';
1775
        $aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>'');
1776
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 1, '');
1777
        $texto = '';
1778
        if ($this->retirada->getElementsByTagName("xNome")->item(0)) {
1779
            $texto = $this->retirada->getElementsByTagName("xNome")->item(0)->nodeValue;
1780
        }
1781
        $aFont = array('font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B');
1782
        if ($this->orientacao == 'P') {
1783
            $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'B', 'L', 0, '');
1784
        } else {
1785
            $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'B', 'L', 1, '');
1786
        }
1787
        //CNPJ / CPF
1788
        $x += $w;
1789
        $w = round($maxW*0.23, 0);
1790
        $w2 = $w;
1791
        $texto = 'CNPJ / CPF';
1792
        $aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>'');
1793
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 1, '');
1794
        //Pegando valor do CPF/CNPJ
1795
        if (! empty($this->retirada->getElementsByTagName("CNPJ")->item(0)->nodeValue)) {
1796
            $texto = $this->formatField(
1797
                $this->retirada->getElementsByTagName("CNPJ")->item(0)->nodeValue,
1798
                "###.###.###/####-##"
1799
            );
1800
        } else {
1801
            $texto = ! empty($this->retirada->getElementsByTagName("CPF")->item(0)->nodeValue) ?
1802
                    $this->formatField(
1803
                        $this->retirada->getElementsByTagName("CPF")->item(0)->nodeValue,
1804
                        "###.###.###-##"
1805
                    ) : '';
1806
        }
1807
        $aFont = array('font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B');
1808
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'B', 'C', 0, '');
1809
        //INSCRIÇÃO ESTADUAL
1810
        $x += $w;
1811
        $w = $maxW-($w1+$w2);
1812
        $wx = $w;
1813
        $texto = 'INSCRIÇÃO ESTADUAL';
1814
        $aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>'');
1815
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 1, '');
1816
        $texto = '';
1817
        if ($this->retirada->getElementsByTagName("IE")->item(0)) {
1818
            $texto = $this->retirada->getElementsByTagName("IE")->item(0)->nodeValue;
1819
        }
1820
        $aFont = array('font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B');
1821
        if ($this->orientacao == 'P') {
1822
            $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'B', 'C', 0, '');
1823
        } else {
1824
            $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'B', 'C', 1, '');
1825
        }
1826
        //ENDEREÇO
1827
        $w = round($maxW*0.355, 0) + $wx;
1828
        $w1 = $w;
1829
        $y += $h;
1830
        $x = $oldX;
1831
        $texto = 'ENDEREÇO';
1832
        $aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>'');
1833
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 1, '');
1834
        $texto = $this->retirada->getElementsByTagName("xLgr")->item(0)->nodeValue;
1835
        $texto .= ', ' . $this->retirada->getElementsByTagName("nro")->item(0)->nodeValue;
1836
        $texto .= $this->getTagValue($this->retirada, "xCpl", " - ");
1837
        $aFont = array('font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B');
1838
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'B', 'L', 0, '', true);
1839
        //BAIRRO / DISTRITO
1840
        $x += $w;
1841
        $w = round($maxW*0.335, 0);
1842
        $w2 = $w;
1843
        $texto = 'BAIRRO / DISTRITO';
1844
        $aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>'');
1845
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 1, '');
1846
        $texto = $this->retirada->getElementsByTagName("xBairro")->item(0)->nodeValue;
1847
        $aFont = array('font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B');
1848
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'B', 'C', 0, '');
1849
        //CEP
1850
        $x += $w;
1851
        $w = $maxW-($w1+$w2);
1852
        $texto = 'CEP';
1853
        $aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>'');
1854
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 1, '');
1855
        $texto = ! empty($this->retirada->getElementsByTagName("CEP")->item(0)->nodeValue) ?
1856
                $this->retirada->getElementsByTagName("CEP")->item(0)->nodeValue : '';
1857
        $texto = $this->formatField($texto, "#####-###");
1858
        $aFont = array('font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B');
1859
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'B', 'C', 0, '');
1860
        //MUNICÍPIO
1861
        $w = round($maxW*0.805, 0);
1862
        $w1 = $w;
1863
        $y += $h;
1864
        $x = $oldX;
1865
        $texto = 'MUNICÍPIO';
1866
        $aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>'');
1867
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 1, '');
1868
        $texto = $this->retirada->getElementsByTagName("xMun")->item(0)->nodeValue;
1869
        if (strtoupper(trim($texto)) == "EXTERIOR" && $this->retirada->getElementsByTagName("xPais")->length > 0) {
1870
            $texto .= " - " .  $this->retirada->getElementsByTagName("xPais")->item(0)->nodeValue;
1871
        }
1872
        $aFont = array('font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B');
1873
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'B', 'L', 0, '');
1874
        //UF
1875
        $x += $w;
1876
        $w = 8;
1877
        $texto = 'UF';
1878
        $aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>'');
1879
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 1, '');
1880
        $texto = $this->retirada->getElementsByTagName("UF")->item(0)->nodeValue;
1881
        $aFont = array('font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B');
1882
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'B', 'C', 0, '');
1883
        //FONE / FAX
1884
        $x += $w;
1885
        $w = $maxW-$w-$w1;
1886
        $texto = 'FONE / FAX';
1887
        $aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>'');
1888
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 1, '');
1889
        $texto = ! empty($this->retirada->getElementsByTagName("fone")->item(0)->nodeValue) ?
1890
                $this->retirada->getElementsByTagName("fone")->item(0)->nodeValue : '';
1891
        $aFont = array('font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B');
1892
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'B', 'C', 0, '');
1893
        return ($y + $h);
1894
    } //fim da função localRetiradaDANFE
1895
    
1896
     /**
1897
     * getTextoFatura
1898
     * Gera a String do Texto da Fatura
1899
      *
1900
     * @name   getTextoFatura
1901
     * @return uma String com o texto ou "";
1902
     */
1903
    protected function getTextoFatura()
1904
    {
1905
        if (isset($this->cobr)) {
1906
            $fat = $this->cobr->getElementsByTagName("fat")->item(0);
1907
            if (isset($fat)) {
1908
                if (!empty($this->getTagValue($this->ide, "indPag"))) {
1909
                    $textoIndPag = "";
1910
                    $indPag = $this->getTagValue($this->ide, "indPag");
1911
                    if ($indPag === "0") {
1912
                        $textoIndPag = "Pagamento à Vista - ";
1913
                    } elseif ($indPag === "1") {
1914
                        $textoIndPag = "Pagamento à Prazo - ";
1915
                    }
1916
                    $nFat = $this->getTagValue($fat, "nFat", "Fatura: ");
1917
                    $vOrig = $this->getTagValue($fat, "vOrig", " Valor Original: ");
1918
                    $vDesc = $this->getTagValue($fat, "vDesc", " Desconto: ");
1919
                    $vLiq = $this->getTagValue($fat, "vLiq", " Valor Líquido: ");
1920
                    $texto = $textoIndPag . $nFat . $vOrig . $vDesc . $vLiq;
1921
                    return $texto;
1922
                } else {
1923
                    $pag = $this->dom->getElementsByTagName("pag");
1924
                    if ($tPag = $this->getTagValue($pag->item(0), "tPag")) {
1925
                        return $this->tipoPag($tPag);
1926
                    }
1927
                }
1928
            }
1929
        }
1930
        return "";
1931
    }
1932
1933
     /**
1934
     * sizeExtraTextoFatura
1935
     * Calcula o espaço ocupado pelo texto da fatura. Este espaço só é utilizado quando não houver duplicata.
1936
      *
1937
     * @name   sizeExtraTextoFatura
1938
     * @return integer
1939
     */
1940
    protected function sizeExtraTextoFatura()
1941
    {
1942
        $textoFatura = $this->getTextoFatura();
1943
        //verificar se existem duplicatas
1944
        if ($this->dup->length == 0 && $textoFatura !== "") {
0 ignored issues
show
Bug introduced by
The property length does not seem to exist in DOMNode.

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
1945
            return 10;
1946
        }
1947
        return 0;
1948
    }
1949
1950
    /**
1951
     * fatura
1952
     * Monta o campo de duplicatas da DANFE (retrato e paisagem)
1953
     *
1954
     * @name   fatura
1955
     * @param  number $x Posição horizontal canto esquerdo
1956
     * @param  number $y Posição vertical canto superior
1957
     * @return number Posição vertical final
1958
     */
1959
    protected function fatura($x, $y)
1960
    {
1961
        $linha = 1;
1962
        $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...
1963
        $oldx = $x;
1964
        $textoFatura = $this->getTextoFatura();
1965
        //verificar se existem duplicatas
1966
        if ($this->dup->length > 0 || $textoFatura !== "") {
1967
            //#####################################################################
1968
            //FATURA / DUPLICATA
1969
            $texto = "FATURA / DUPLICATA";
1970
            if ($this->orientacao == 'P') {
1971
                $w = $this->wPrint;
1972
            } else {
1973
                $w = 271;
1974
            }
1975
            $h = 8;
1976
            $aFont = ['font'=>$this->fontePadrao, 'size'=>7, 'style'=>'B'];
1977
            $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 0, '');
1978
            $y += 3;
1979
            $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...
1980
            $dupcont = 0;
1981
            $nFat = $this->dup->length;
0 ignored issues
show
Bug introduced by
The property length does not seem to exist in DOMNode.

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
1982
            if ($nFat > 7) {
1983
                $myH = 6;
1984
                $myW = $this->wPrint;
1985
                if ($this->orientacao == 'L') {
1986
                    $myW -= $this->wCanhoto;
1987
                }
1988
                $aFont = ['font' => $this->fontePadrao, 'size' => 9, 'style' => ''];
1989
                $texto = "Existem mais de 7 duplicatas registradas, portanto não "
1990
                    . "serão exibidas, confira diretamente pelo XML.";
1991
                $this->pdf->textBox($x, $y, $myW, $myH, $texto, $aFont, 'C', 'C', 1, '');
1992
                return ($y + $h - 3);
1993
            }
1994
            if ($textoFatura !== "" && $this->exibirTextoFatura) {
1995
                $myH=6;
1996
                $myW = $this->wPrint;
1997
                if ($this->orientacao == 'L') {
1998
                    $myW -= $this->wCanhoto;
1999
                }
2000
                $aFont = ['font'=>$this->fontePadrao, 'size'=>8, 'style'=>''];
2001
                $this->pdf->textBox($x, $y, $myW, $myH, $textoFatura, $aFont, 'C', 'L', 1, '');
2002
                $y+=$myH+1;
2003
            }
2004
            if ($this->orientacao == 'P') {
2005
                $w = round($this->wPrint/7.018, 0)-1;
2006
            } else {
2007
                $w = 28;
2008
            }
2009
            $increm = 1;
2010
            foreach ($this->dup as $k => $d) {
0 ignored issues
show
Bug introduced by
The expression $this->dup of type object<DOMNode> is not traversable.
Loading history...
2011
                $nDup = ! empty($this->dup->item($k)->getElementsByTagName('nDup')->item(0)->nodeValue)
2012
                ? $this->dup->item($k)->getElementsByTagName('nDup')->item(0)->nodeValue
2013
                : '';
2014
                $dDup = ! empty($this->dup->item($k)->getElementsByTagName('dVenc')->item(0)->nodeValue)
2015
                ? $this->ymdTodmy($this->dup->item($k)->getElementsByTagName('dVenc')->item(0)->nodeValue)
2016
                : '';
2017
                $vDup = ! empty($this->dup->item($k)->getElementsByTagName('vDup')->item(0)->nodeValue)
2018
                ? 'R$ ' . number_format(
2019
                    $this->dup->item($k)->getElementsByTagName('vDup')->item(0)->nodeValue,
2020
                    2,
2021
                    ",",
2022
                    "."
2023
                )
2024
                : '';
2025
                $h = 8;
2026
                $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...
2027
                if ($nDup!='0' && $nDup!='') {
2028
                    $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
2029
                    $this->pdf->textBox($x, $y, $w, $h, 'Num.', $aFont, 'T', 'L', 1, '');
2030
                    $aFont = ['font'=>$this->fontePadrao, 'size'=>7, 'style'=>'B'];
2031
                    $this->pdf->textBox($x, $y, $w, $h, $nDup, $aFont, 'T', 'R', 0, '');
2032
                } else {
2033
                    $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
2034
                    $this->pdf->textBox($x, $y, $w, $h, ($dupcont+1)."", $aFont, 'T', 'L', 1, '');
2035
                }
2036
                $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
2037
                $this->pdf->textBox($x, $y, $w, $h, 'Venc.', $aFont, 'C', 'L', 0, '');
2038
                $aFont = ['font'=>$this->fontePadrao, 'size'=>7, 'style'=>'B'];
2039
                $this->pdf->textBox($x, $y, $w, $h, $dDup, $aFont, 'C', 'R', 0, '');
2040
                $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
2041
                $this->pdf->textBox($x, $y, $w, $h, 'Valor', $aFont, 'B', 'L', 0, '');
2042
                $aFont = ['font'=>$this->fontePadrao, 'size'=>7, 'style'=>'B'];
2043
                $this->pdf->textBox($x, $y, $w, $h, $vDup, $aFont, 'B', 'R', 0, '');
2044
                $x += $w+$increm;
2045
                $dupcont += 1;
2046
                if ($this->orientacao == 'P') {
2047
                    $maxDupCont = 6;
2048
                } else {
2049
                    $maxDupCont = 8;
2050
                }
2051
                if ($dupcont > $maxDupCont) {
2052
                    $y += 9;
2053
                    $x = $oldx;
2054
                    $dupcont = 0;
2055
                    $linha += 1;
2056
                }
2057
                if ($linha == 5) {
2058
                    $linha = 4;
2059
                    break;
2060
                }
2061
            }
2062
            if ($dupcont == 0) {
2063
                $y -= 9;
2064
                $linha--;
2065
            }
2066
            return ($y+$h);
2067
        } else {
2068
            $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...
2069
            return ($y-2);
2070
        }
2071
    }
2072
2073
    /**
2074
     * pagamento
2075
     * Monta o campo de pagamentos da DANFE (retrato e paisagem) (foi baseada na fatura)
2076
     *
2077
     * @name   pagamento
2078
     * @param  number $x Posição horizontal canto esquerdo
2079
     * @param  number $y Posição vertical canto superior
2080
     * @return number Posição vertical final
2081
     */
2082
    protected function pagamento($x, $y)
2083
    {
2084
        $linha = 1;
2085
        $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...
2086
        $oldx = $x;
2087
        //verificar se existem cobranças definidas
2088
        if (isset($this->detPag) && $this->detPag->length > 0) {
2089
            //#####################################################################
2090
            //Tipo de pagamento
2091
            $texto = "PAGAMENTO";
2092
            if ($this->orientacao == 'P') {
2093
                $w = $this->wPrint;
2094
            } else {
2095
                $w = 271;
2096
            }
2097
            $h = 8;
2098
            $aFont = ['font'=>$this->fontePadrao, 'size'=>7, 'style'=>'B'];
2099
            $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 0, '');
2100
            $y += 3;
2101
            $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...
2102
            $dupcont = 0;
2103
            if ($this->orientacao == 'P') {
2104
                $w = round($this->wPrint/7.018, 0)-1;
2105
            } else {
2106
                $w = 28;
2107
            }
2108
            if ($this->orientacao == 'P') {
2109
                $maxDupCont = 6;
2110
            } else {
2111
                $maxDupCont = 8;
2112
            }
2113
            $increm = 1;
2114
            $formaPagamento = ['01'=>'Dinheiro','02'=>'Cheque','03'=>'Cartão de Crédito',
2115
                                    '04'=>'Cartão de Débito','05'=>'Crédito Loja','10'=>'Vale Alimentação',
2116
                                    '11'=>'Vale Refeição','12'=>'Vale Presente','13'=>'Vale Combustível',
2117
                                    '14'=>'Duplicata Mercantil','15'=>'Boleto','90'=>'Sem pagamento','99'=>'Outros'];
2118
            $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...
2119
                              '06'=>'Elo','07'=>'Hipercard','08'=>'Aura','09'=>'Cabal','99'=>'Outros'];
2120
            foreach ($this->detPag as $k => $d) {
2121
                $fPag = !empty($this->detPag->item($k)->getElementsByTagName('tPag')->item(0)->nodeValue)
2122
                ? $this->detPag->item($k)->getElementsByTagName('tPag')->item(0)->nodeValue
2123
                : '0';
2124
                $vPag = ! empty($this->detPag->item($k)->getElementsByTagName('vPag')->item(0)->nodeValue)
2125
                ? 'R$ ' . number_format(
2126
                    $this->detPag->item($k)->getElementsByTagName('vPag')->item(0)->nodeValue,
2127
                    2,
2128
                    ",",
2129
                    "."
2130
                )
2131
                : '';
2132
                $h = 6;
2133
                $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...
2134
                if (isset($formaPagamento[$fPag])) {
2135
                    /*Exibir Item sem pagamento ou outros?*/
2136
                    if ($fPag=='90' || $fPag=='99') {
2137
                        continue;
2138
                    }
2139
                    $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
2140
                    $this->pdf->textBox($x, $y, $w, $h, 'Forma', $aFont, 'T', 'L', 1, '');
2141
                    $aFont = ['font'=>$this->fontePadrao, 'size'=>7, 'style'=>'B'];
2142
                    $this->pdf->textBox($x, $y, $w, $h, $formaPagamento[$fPag], $aFont, 'T', 'R', 0, '');
2143
                } else {
2144
                    $aFont = ['font'=>$this->fontePadrao, 'size'=>7, 'style'=>''];
2145
                    $this->pdf->textBox($x, $y, $w, $h, "Forma ".$fPag." não encontrado", $aFont, 'T', 'L', 1, '');
2146
                }
2147
                $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
2148
                $this->pdf->textBox($x, $y, $w, $h, 'Valor', $aFont, 'B', 'L', 0, '');
2149
                $aFont = ['font'=>$this->fontePadrao, 'size'=>7, 'style'=>'B'];
2150
                $this->pdf->textBox($x, $y, $w, $h, $vPag, $aFont, 'B', 'R', 0, '');
2151
                $x += $w+$increm;
2152
                $dupcont += 1;
2153
2154
                if ($dupcont>$maxDupCont) {
2155
                    $y += 9;
2156
                    $x = $oldx;
2157
                    $dupcont = 0;
2158
                    $linha += 1;
2159
                }
2160
                if ($linha == 5) {
2161
                    $linha = 4;
2162
                    break;
2163
                }
2164
            }
2165
            if ($dupcont == 0) {
2166
                $y -= 9;
2167
                $linha--;
2168
            }
2169
            return ($y+$h);
2170
        } else {
2171
            $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...
2172
            return ($y-2);
2173
        }
2174
    } //fim da função pagamento
2175
    
2176
    /**
2177
     * impostoHelper
2178
     * Auxilia a montagem dos campos de impostos e totais da DANFE
2179
     *
2180
     * @name   impostoHelper
2181
     * @param  float $x Posição horizontal canto esquerdo
2182
     * @param  float $y Posição vertical canto superior
2183
     * @param  float $w Largura do campo
2184
     * @param  float $h Altura do campo
2185
     * @param  float $h Título do campo
2186
     * @param  float $h Valor do imposto
2187
     * @return float Sugestão do $x do próximo imposto
2188
     */
2189
    protected function impostoHelper($x, $y, $w, $h, $titulo, $campoImposto)
2190
    {
2191
        $valorImposto = '0, 00';
2192
        $the_field = $this->ICMSTot->getElementsByTagName($campoImposto)->item(0);
2193
        if (isset($the_field)) {
2194
            $the_value = $the_field->nodeValue;
2195
            if (!empty($the_value)) {
2196
                $valorImposto = number_format($the_value, 2, ",", ".");
2197
            }
2198
        }
2199
2200
        $fontTitulo = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
2201
        $fontValor = ['font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B'];
2202
        $this->pdf->textBox($x, $y, $w, $h, $titulo, $fontTitulo, 'T', 'L', 1, '');
2203
        $this->pdf->textBox($x, $y, $w, $h, $valorImposto, $fontValor, 'B', 'R', 0, '');
2204
2205
        $next_x = $x + $w;
2206
        return $next_x;
2207
    }
2208
2209
    /**
2210
     * imposto
2211
     * Monta o campo de impostos e totais da DANFE (retrato e paisagem)
2212
     *
2213
     * @param  number $x Posição horizontal canto esquerdo
2214
     * @param  number $y Posição vertical canto superior
2215
     * @return number Posição vertical final
2216
     */
2217
    protected function imposto($x, $y)
2218
    {
2219
        $x_inicial = $x;
2220
        //#####################################################################
2221
2222
2223
        $campos_por_linha = 9;
2224
        if (!$this->exibirPIS) {
2225
            $campos_por_linha--;
2226
        }
2227
        if (!$this->exibirIcmsInterestadual) {
2228
            $campos_por_linha -= 2;
2229
        }
2230
2231
        if ($this->orientacao == 'P') {
2232
            $maxW = $this->wPrint;
2233
            $title_size = 31;
2234
        } else {
2235
            $maxW = $this->wPrint - $this->wCanhoto;
2236
            $title_size = 40;
2237
        }
2238
        $w = $maxW / $campos_por_linha;
2239
2240
        $aFont = ['font'=>$this->fontePadrao, 'size'=>7, 'style'=>'B'];
2241
        $texto = "CÁLCULO DO IMPOSTO";
2242
        $this->pdf->textBox($x, $y, $title_size, 8, $texto, $aFont, 'T', 'L', 0, '');
2243
        $y += 3;
2244
        $h = 7;
2245
2246
        $x = $this->impostoHelper($x, $y, $w, $h, "BASE DE CÁLC. DO ICMS", "vBC");
2247
        $x = $this->impostoHelper($x, $y, $w, $h, "VALOR DO ICMS", "vICMS");
2248
        $x = $this->impostoHelper($x, $y, $w, $h, "BASE DE CÁLC. ICMS S.T.", "vBCST");
2249
        $x = $this->impostoHelper($x, $y, $w, $h, "VALOR DO ICMS SUBST.", "vST");
2250
        $x = $this->impostoHelper($x, $y, $w, $h, "V. IMP. IMPORTAÇÃO", "vII");
2251
2252
        if ($this->exibirIcmsInterestadual) {
2253
            $x = $this->impostoHelper($x, $y, $w, $h, "V. ICMS UF REMET.", "vICMSUFRemet");
2254
            $x = $this->impostoHelper($x, $y, $w, $h, "V. FCP UF DEST.", "vFCPUFDest");
2255
        }
2256
2257
        if ($this->exibirPIS) {
2258
            $x = $this->impostoHelper($x, $y, $w, $h, "VALOR DO PIS", "vPIS");
2259
        }
2260
2261
        $x = $this->impostoHelper($x, $y, $w, $h, "V. TOTAL PRODUTOS", "vProd");
0 ignored issues
show
Unused Code introduced by
$x is not used, you could remove the assignment.

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

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

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

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

Loading history...
2262
2263
        //
2264
2265
        $y += $h;
2266
        $x = $x_inicial;
2267
2268
        $x = $this->impostoHelper($x, $y, $w, $h, "VALOR DO FRETE", "vFrete");
2269
        $x = $this->impostoHelper($x, $y, $w, $h, "VALOR DO SEGURO", "vSeg");
2270
        $x = $this->impostoHelper($x, $y, $w, $h, "DESCONTO", "vDesc");
2271
        $x = $this->impostoHelper($x, $y, $w, $h, "OUTRAS DESPESAS", "vOutro");
2272
        $x = $this->impostoHelper($x, $y, $w, $h, "VALOR TOTAL IPI", "vIPI");
2273
2274
        if ($this->exibirIcmsInterestadual) {
2275
            $x = $this->impostoHelper($x, $y, $w, $h, "V. ICMS UF DEST.", "vICMSUFDest");
2276
            $x = $this->impostoHelper($x, $y, $w, $h, "V. TOT. TRIB.", "vTotTrib");
2277
        }
2278
2279
        if ($this->exibirPIS) {
2280
            $x = $this->impostoHelper($x, $y, $w, $h, "VALOR DA COFINS", "vCOFINS");
2281
        }
2282
        $x = $this->impostoHelper($x, $y, $w, $h, "V. TOTAL DA NOTA", "vNF");
0 ignored issues
show
Unused Code introduced by
$x is not used, you could remove the assignment.

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

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

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

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

Loading history...
2283
2284
        return ($y+$h);
2285
    } //fim imposto
2286
2287
    /**
2288
     * transporte
2289
     * Monta o campo de transportes da DANFE (retrato e paisagem)
2290
     *
2291
     * @name   transporte
2292
     * @param  float $x Posição horizontal canto esquerdo
2293
     * @param  float $y Posição vertical canto superior
2294
     * @return float Posição vertical final
2295
     */
2296
    protected function transporte($x, $y)
2297
    {
2298
        $oldX = $x;
2299
        if ($this->orientacao == 'P') {
2300
            $maxW = $this->wPrint;
2301
        } else {
2302
            $maxW = $this->wPrint - $this->wCanhoto;
2303
        }
2304
        //#####################################################################
2305
        //TRANSPORTADOR / VOLUMES TRANSPORTADOS
2306
        $texto = "TRANSPORTADOR / VOLUMES TRANSPORTADOS";
2307
        $w = $maxW;
2308
        $h = 7;
2309
        $aFont = ['font'=>$this->fontePadrao, 'size'=>7, 'style'=>'B'];
2310
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 0, '');
2311
        //NOME / RAZÃO SOCIAL
2312
        $w1 = $maxW*0.29;
2313
        $y += 3;
2314
        $texto = 'NOME / RAZÃO SOCIAL';
2315
        $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
2316
        $this->pdf->textBox($x, $y, $w1, $h, $texto, $aFont, 'T', 'L', 1, '');
2317
        if (isset($this->transporta)) {
2318
            $texto = ! empty($this->transporta->getElementsByTagName("xNome")->item(0)->nodeValue)
2319
            ? $this->transporta->getElementsByTagName("xNome")->item(0)->nodeValue
2320
            : '';
2321
        } else {
2322
            $texto = '';
2323
        }
2324
        $aFont = ['font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B'];
2325
        $this->pdf->textBox($x, $y, $w1, $h, $texto, $aFont, 'B', 'L', 0, '');
2326
        //FRETE POR CONTA
2327
        $x += $w1;
2328
        $w2 = $maxW*0.15;
2329
        $texto = 'FRETE';
2330
        $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
2331
        $this->pdf->textBox($x, $y, $w2, $h, $texto, $aFont, 'T', 'L', 1, '');
2332
        $tipoFrete = ! empty($this->transp->getElementsByTagName("modFrete")->item(0)->nodeValue)
2333
        ? $this->transp->getElementsByTagName("modFrete")->item(0)->nodeValue
2334
        : '0';
2335
        switch ($tipoFrete) {
2336
            case 0:
2337
                $texto = "0-Por conta do Rem";
2338
                break;
2339
            case 1:
2340
                $texto = "1-Por conta do Dest";
2341
                break;
2342
            case 2:
2343
                $texto = "2-Por conta de Terceiros";
2344
                break;
2345
            case 3:
2346
                $texto = "3-Próprio por conta do Rem";
2347
                break;
2348
            case 4:
2349
                $texto = "4-Próprio por conta do Dest";
2350
                break;
2351
            case 9:
2352
                $texto = "9-Sem Transporte";
2353
                break;
2354
        }
2355
        $aFont = ['font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B'];
2356
        $this->pdf->textBox($x, $y, $w2, $h, $texto, $aFont, 'C', 'C', 1, '');
2357
        //CÓDIGO ANTT
2358
        $x += $w2;
2359
        $texto = 'CÓDIGO ANTT';
2360
        $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
2361
        $this->pdf->textBox($x, $y, $w2, $h, $texto, $aFont, 'T', 'L', 1, '');
2362
        if (isset($this->veicTransp)) {
2363
            $texto = ! empty($this->veicTransp->getElementsByTagName("RNTC")->item(0)->nodeValue)
2364
            ? $this->veicTransp->getElementsByTagName("RNTC")->item(0)->nodeValue
2365
            : '';
2366
        } else {
2367
            $texto = '';
2368
        }
2369
        $aFont = ['font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B'];
2370
        $this->pdf->textBox($x, $y, $w2, $h, $texto, $aFont, 'B', 'C', 0, '');
2371
        //PLACA DO VEÍC
2372
        $x += $w2;
2373
        $texto = 'PLACA DO VEÍCULO';
2374
        $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
2375
        $this->pdf->textBox($x, $y, $w2, $h, $texto, $aFont, 'T', 'L', 1, '');
2376
        if (isset($this->veicTransp)) {
2377
            $texto = ! empty($this->veicTransp->getElementsByTagName("placa")->item(0)->nodeValue)
2378
            ? $this->veicTransp->getElementsByTagName("placa")->item(0)->nodeValue
2379
            : '';
2380
        } elseif (isset($this->reboque)) {
2381
            $texto = ! empty($this->reboque->getElementsByTagName("placa")->item(0)->nodeValue)
2382
            ? $this->reboque->getElementsByTagName("placa")->item(0)->nodeValue
2383
            : '';
2384
        } else {
2385
            $texto = '';
2386
        }
2387
        $aFont = ['font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B'];
2388
        $this->pdf->textBox($x, $y, $w2, $h, $texto, $aFont, 'B', 'C', 0, '');
2389
        //UF
2390
        $x += $w2;
2391
        $w3 = round($maxW*0.04, 0);
2392
        $texto = 'UF';
2393
        $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
2394
        $this->pdf->textBox($x, $y, $w3, $h, $texto, $aFont, 'T', 'L', 1, '');
2395
        if (isset($this->veicTransp)) {
2396
            $texto = ! empty($this->veicTransp->getElementsByTagName("UF")->item(0)->nodeValue)
2397
            ? $this->veicTransp->getElementsByTagName("UF")->item(0)->nodeValue
2398
            : '';
2399
        } elseif (isset($this->reboque)) {
2400
            $texto = ! empty($this->reboque->getElementsByTagName("UF")->item(0)->nodeValue)
2401
            ? $this->reboque->getElementsByTagName("UF")->item(0)->nodeValue
2402
            : '';
2403
        } else {
2404
            $texto = '';
2405
        }
2406
        $aFont = ['font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B'];
2407
        $this->pdf->textBox($x, $y, $w3, $h, $texto, $aFont, 'B', 'C', 0, '');
2408
        //CNPJ / CPF
2409
        $x += $w3;
2410
        $w = $maxW-($w1+3*$w2+$w3);
2411
        $texto = 'CNPJ / CPF';
2412
        $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
2413
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 1, '');
2414
        if (isset($this->transporta)) {
2415
            $texto = ! empty($this->transporta->getElementsByTagName("CNPJ")->item(0)->nodeValue)
2416
            ? $this->formatField(
2417
                $this->transporta->getElementsByTagName("CNPJ")->item(0)->nodeValue,
2418
                "##.###.###/####-##"
2419
            )
2420
            : '';
2421
            if ($texto == '') {
2422
                $texto = ! empty($this->transporta->getElementsByTagName("CPF")->item(0)->nodeValue)
2423
                ? $this->formatField(
2424
                    $this->transporta->getElementsByTagName("CPF")->item(0)->nodeValue,
2425
                    "###.###.###-##"
2426
                )
2427
                : '';
2428
            }
2429
        } else {
2430
            $texto = '';
2431
        }
2432
        $aFont = ['font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B'];
2433
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'B', 'C', 0, '');
2434
        //#####################################################################
2435
        //ENDEREÇO
2436
        $y += $h;
2437
        $x = $oldX;
2438
        $h = 7;
2439
        $w1 = $maxW*0.44;
2440
        $texto = 'ENDEREÇO';
2441
        $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
2442
        $this->pdf->textBox($x, $y, $w1, $h, $texto, $aFont, 'T', 'L', 1, '');
2443
        if (isset($this->transporta)) {
2444
            $texto = ! empty($this->transporta->getElementsByTagName("xEnder")->item(0)->nodeValue)
2445
                ? $this->transporta->getElementsByTagName("xEnder")->item(0)->nodeValue
2446
                : '';
2447
        } else {
2448
            $texto = '';
2449
        }
2450
        $aFont = ['font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B'];
2451
        $this->pdf->textBox($x, $y, $w1, $h, $texto, $aFont, 'B', 'L', 0, '');
2452
        //MUNICÍPIO
2453
        $x += $w1;
2454
        $w2 = round($maxW*0.30, 0);
2455
        $texto = 'MUNICÍPIO';
2456
        $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
2457
        $this->pdf->textBox($x, $y, $w2, $h, $texto, $aFont, 'T', 'L', 1, '');
2458
        if (isset($this->transporta)) {
2459
            $texto = ! empty($this->transporta->getElementsByTagName("xMun")->item(0)->nodeValue)
2460
                ? $this->transporta->getElementsByTagName("xMun")->item(0)->nodeValue
2461
                : '';
2462
        } else {
2463
            $texto = '';
2464
        }
2465
        $aFont = ['font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B'];
2466
        $this->pdf->textBox($x, $y, $w2, $h, $texto, $aFont, 'B', 'C', 0, '');
2467
        //UF
2468
        $x += $w2;
2469
        $w3 = round($maxW*0.04, 0);
2470
        $texto = 'UF';
2471
        $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
2472
        $this->pdf->textBox($x, $y, $w3, $h, $texto, $aFont, 'T', 'L', 1, '');
2473
        if (isset($this->transporta)) {
2474
            $texto = ! empty($this->transporta->getElementsByTagName("UF")->item(0)->nodeValue)
2475
                ? $this->transporta->getElementsByTagName("UF")->item(0)->nodeValue
2476
                : '';
2477
        } else {
2478
            $texto = '';
2479
        }
2480
        $aFont = ['font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B'];
2481
        $this->pdf->textBox($x, $y, $w3, $h, $texto, $aFont, 'B', 'C', 0, '');
2482
        //INSCRIÇÃO ESTADUAL
2483
        $x += $w3;
2484
        $w = $maxW-($w1+$w2+$w3);
2485
        $texto = 'INSCRIÇÃO ESTADUAL';
2486
        $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
2487
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 1, '');
2488
        $texto = '';
2489
        if (isset($this->transporta)) {
2490
            if (! empty($this->transporta->getElementsByTagName("IE")->item(0)->nodeValue)) {
2491
                $texto = $this->transporta->getElementsByTagName("IE")->item(0)->nodeValue;
2492
            }
2493
        }
2494
        $aFont = ['font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B'];
2495
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'B', 'C', 0, '');
2496
        //Tratar Multiplos volumes
2497
        $volumes = $this->transp->getElementsByTagName('vol');
2498
        $quantidade = 0;
2499
        $especie = '';
2500
        $marca = '';
2501
        $numero = '';
2502
        $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...
2503
        $pesoBruto=0;
2504
        $pesoLiquido=0;
2505
        foreach ($volumes as $volume) {
2506
            $quantidade += ! empty($volume->getElementsByTagName("qVol")->item(0)->nodeValue) ?
2507
                    $volume->getElementsByTagName("qVol")->item(0)->nodeValue : 0;
2508
            $pesoBruto += ! empty($volume->getElementsByTagName("pesoB")->item(0)->nodeValue) ?
2509
                    $volume->getElementsByTagName("pesoB")->item(0)->nodeValue : 0;
2510
            $pesoLiquido += ! empty($volume->getElementsByTagName("pesoL")->item(0)->nodeValue) ?
2511
                    $volume->getElementsByTagName("pesoL")->item(0)->nodeValue : 0;
2512
            $texto = ! empty($this->transp->getElementsByTagName("esp")->item(0)->nodeValue) ?
2513
                    $this->transp->getElementsByTagName("esp")->item(0)->nodeValue : '';
2514
            if ($texto != $especie && $especie != '') {
2515
                //tem várias especies
2516
                $especie = 'VARIAS';
2517
            } else {
2518
                $especie = $texto;
2519
            }
2520
            $texto = ! empty($this->transp->getElementsByTagName("marca")->item(0)->nodeValue)
2521
                ? $this->transp->getElementsByTagName("marca")->item(0)->nodeValue
2522
                : '';
2523
            if ($texto != $marca && $marca != '') {
2524
                //tem várias especies
2525
                $marca = 'VARIAS';
2526
            } else {
2527
                $marca = $texto;
2528
            }
2529
            $texto = ! empty($this->transp->getElementsByTagName("nVol")->item(0)->nodeValue)
2530
                ? $this->transp->getElementsByTagName("nVol")->item(0)->nodeValue
2531
                : '';
2532
            if ($texto != $numero && $numero != '') {
2533
                //tem várias especies
2534
                $numero = 'VARIOS';
2535
            } else {
2536
                $numero = $texto;
2537
            }
2538
        }
2539
2540
        //#####################################################################
2541
        //QUANTIDADE
2542
        $y += $h;
2543
        $x = $oldX;
2544
        $h = 7;
2545
        $w1 = round($maxW*0.10, 0);
2546
        $texto = 'QUANTIDADE';
2547
        $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
2548
        $this->pdf->textBox($x, $y, $w1, $h, $texto, $aFont, 'T', 'L', 1, '');
2549
        if (!empty($quantidade)) {
2550
            $texto = $quantidade;
2551
            $aFont = ['font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B'];
2552
            $this->pdf->textBox($x, $y, $w1, $h, $texto, $aFont, 'B', 'C', 0, '');
2553
        }
2554
        //ESPÉCIE
2555
        $x += $w1;
2556
        $w2 = round($maxW*0.17, 0);
2557
        $texto = 'ESPÉCIE';
2558
        $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
2559
        $this->pdf->textBox($x, $y, $w2, $h, $texto, $aFont, 'T', 'L', 1, '');
2560
        $texto = $especie;
2561
        $aFont = ['font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B'];
2562
        $this->pdf->textBox($x, $y, $w2, $h, $texto, $aFont, 'B', 'C', 0, '');
2563
        //MARCA
2564
        $x += $w2;
2565
        $texto = 'MARCA';
2566
        $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
2567
        $this->pdf->textBox($x, $y, $w2, $h, $texto, $aFont, 'T', 'L', 1, '');
2568
        $texto = ! empty($this->transp->getElementsByTagName("marca")->item(0)->nodeValue) ?
2569
                $this->transp->getElementsByTagName("marca")->item(0)->nodeValue : '';
2570
        $aFont = ['font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B'];
2571
        $this->pdf->textBox($x, $y, $w2, $h, $texto, $aFont, 'B', 'C', 0, '');
2572
        //NUMERAÇÃO
2573
        $x += $w2;
2574
        $texto = 'NUMERAÇÃO';
2575
        $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
2576
        $this->pdf->textBox($x, $y, $w2, $h, $texto, $aFont, 'T', 'L', 1, '');
2577
        $texto = $numero;
2578
        $aFont = ['font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B'];
2579
        $this->pdf->textBox($x, $y, $w2, $h, $texto, $aFont, 'B', 'C', 0, '');
2580
        //PESO BRUTO
2581
        $x += $w2;
2582
        $w3 = round($maxW*0.20, 0);
2583
        $texto = 'PESO BRUTO';
2584
        $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
2585
        $this->pdf->textBox($x, $y, $w3, $h, $texto, $aFont, 'T', 'L', 1, '');
2586
        if (is_numeric($pesoBruto) && $pesoBruto > 0) {
2587
            $texto = number_format($pesoBruto, 3, ",", ".");
2588
        } else {
2589
            $texto = '';
2590
        }
2591
        $aFont = ['font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B'];
2592
        $this->pdf->textBox($x, $y, $w3, $h, $texto, $aFont, 'B', 'R', 0, '');
2593
        //PESO LÍQUIDO
2594
        $x += $w3;
2595
        $w = $maxW -($w1+3*$w2+$w3);
2596
        $texto = 'PESO LÍQUIDO';
2597
        $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
2598
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 1, '');
2599
        if (is_numeric($pesoLiquido) && $pesoLiquido > 0) {
2600
            $texto = number_format($pesoLiquido, 3, ",", ".");
2601
        } else {
2602
            $texto = '';
2603
        }
2604
        $aFont = ['font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B'];
2605
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'B', 'R', 0, '');
2606
        return ($y+$h);
2607
    } //fim transporte
2608
2609
2610
2611
    protected function descricaoProdutoHelper($origem, $campo, $formato)
2612
    {
2613
        $valor_original = $origem->getElementsByTagName($campo)->item(0);
2614
        if (!isset($valor_original)) {
2615
            return "";
2616
        }
2617
        $valor_original = $valor_original->nodeValue;
2618
        $valor = ! empty($valor_original) ? number_format($valor_original, 2, ",", ".") : '';
2619
2620
        if ($valor != "") {
2621
            return sprintf($formato, $valor);
2622
        }
2623
        return "";
2624
    }
2625
2626
    /**
2627
     * descricaoProduto
2628
     * Monta a string de descrição de cada Produto
2629
     *
2630
     * @name   descricaoProduto
2631
     * @param  DOMNode itemProd
2632
     * @return string descricao do produto
2633
     */
2634
    protected function descricaoProduto($itemProd)
2635
    {
2636
        $prod = $itemProd->getElementsByTagName('prod')->item(0);
2637
        $ICMS = $itemProd->getElementsByTagName("ICMS")->item(0);
2638
        $ICMSUFDest = $itemProd->getElementsByTagName("ICMSUFDest")->item(0);
2639
        $impostos = '';
2640
2641
        if (!empty($ICMS)) {
2642
            $impostos .= $this->descricaoProdutoHelper($ICMS, "vBCFCP", " BcFcp=%s");
2643
            $impostos .= $this->descricaoProdutoHelper($ICMS, "pFCP", " pFcp=%s%%");
2644
            $impostos .= $this->descricaoProdutoHelper($ICMS, "vFCP", " vFcp=%s");
2645
            $impostos .= $this->descricaoProdutoHelper($ICMS, "pRedBC", " pRedBC=%s%%");
2646
            $impostos .= $this->descricaoProdutoHelper($ICMS, "pMVAST", " IVA/MVA=%s%%");
2647
            $impostos .= $this->descricaoProdutoHelper($ICMS, "pICMSST", " pIcmsSt=%s%%");
2648
            $impostos .= $this->descricaoProdutoHelper($ICMS, "vBCST", " BcIcmsSt=%s");
2649
            $impostos .= $this->descricaoProdutoHelper($ICMS, "vICMSST", " vIcmsSt=%s");
2650
            $impostos .= $this->descricaoProdutoHelper($ICMS, "vBCFCPST", " BcFcpSt=%s");
2651
            $impostos .= $this->descricaoProdutoHelper($ICMS, "pFCPST", " pFcpSt=%s%%");
2652
            $impostos .= $this->descricaoProdutoHelper($ICMS, "vFCPST", " vFcpSt=%s");
2653
            $impostos .= $this->descricaoProdutoHelper($ICMS, "vBCSTRet", " vBcStRet=%s");
2654
            $impostos .= $this->descricaoProdutoHelper($ICMS, "pST", " pSt=%s");
2655
            $impostos .= $this->descricaoProdutoHelper($ICMS, "vICMSSTRet", " vIcmsStRet=%s");
2656
        }
2657
        if (!empty($ICMSUFDest)) {
2658
            $impostos .= $this->descricaoProdutoHelper($ICMSUFDest, "pFCPUFDest", " pFCPUFDest=%s%%");
2659
            $impostos .= $this->descricaoProdutoHelper($ICMSUFDest, "pICMSUFDest", " pICMSUFDest=%s%%");
2660
            $impostos .= $this->descricaoProdutoHelper($ICMSUFDest, "pICMSInterPart", " pICMSInterPart=%s%%");
2661
            $impostos .= $this->descricaoProdutoHelper($ICMSUFDest, "vFCPUFDest", " vFCPUFDest=%s");
2662
            $impostos .= $this->descricaoProdutoHelper($ICMSUFDest, "vICMSUFDest", " vICMSUFDest=%s");
2663
            $impostos .= $this->descricaoProdutoHelper($ICMSUFDest, "vICMSUFRemet", " vICMSUFRemet=%s");
2664
        }
2665
        $infAdProd = ! empty($itemProd->getElementsByTagName('infAdProd')->item(0)->nodeValue)
2666
        ? substr(
2667
            $this->anfaveaDANFE($itemProd->getElementsByTagName('infAdProd')->item(0)->nodeValue),
2668
            0,
2669
            500
2670
        )
2671
        : '';
2672
        if (! empty($infAdProd)) {
2673
            $infAdProd = trim($infAdProd);
2674
            $infAdProd .= ' ';
2675
        }
2676
        $loteTxt ='';
2677
        $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...
2678
        if (!empty($prod->getElementsByTagName("rastro"))) {
2679
            $rastro = $prod->getElementsByTagName("rastro");
2680
            $i = 0;
2681
            while ($i < $rastro->length) {
2682
                $loteTxt .= $this->getTagValue($rastro->item($i), 'nLote', ' Lote: ');
2683
                $loteTxt .= $this->getTagValue($rastro->item($i), 'qLote', ' Quant: ');
2684
                $loteTxt .= $this->getTagDate($rastro->item($i), 'dFab', ' Fab: ');
2685
                $loteTxt .= $this->getTagDate($rastro->item($i), 'dVal', ' Val: ');
2686
                $loteTxt .= $this->getTagValue($rastro->item($i), 'vPMC', ' PMC: ');
2687
                $i++;
2688
            }
2689
            if ($loteTxt != '') {
2690
                $loteTxt.= ' ';
2691
            }
2692
        }
2693
        //NT2013.006 FCI
2694
        $nFCI = (! empty($itemProd->getElementsByTagName('nFCI')->item(0)->nodeValue)) ?
2695
                ' FCI:'.$itemProd->getElementsByTagName('nFCI')->item(0)->nodeValue : '';
2696
        $tmp_ad=$infAdProd . ($this->descProdInfoComplemento ? $loteTxt . $impostos . $nFCI : '');
2697
        $texto = $prod->getElementsByTagName("xProd")->item(0)->nodeValue
2698
            . (strlen($tmp_ad)!=0?"\n    ".$tmp_ad:'');
2699
        //decodifica os caracteres html no xml
2700
        $texto = html_entity_decode($texto);
2701
        if ($this->descProdQuebraLinha) {
2702
            $texto = str_replace(";", "\n", $texto);
2703
        }
2704
        return $texto;
2705
    }
2706
2707
    /**
2708
     * itens
2709
     * Monta o campo de itens da DANFE (retrato e paisagem)
2710
     *
2711
     * @name   itens
2712
     * @param  float $x       Posição horizontal canto esquerdo
2713
     * @param  float $y       Posição vertical canto superior
2714
     * @param  float $nInicio Número do item inicial
2715
     * @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...
2716
     * @param  float $hmax    Altura máxima do campo de itens em mm
2717
     * @return float Posição vertical final
2718
     */
2719
    protected function itens($x, $y, &$nInicio, $hmax, $pag = 0, $totpag = 0, $hCabecItens = 7)
2720
    {
2721
        $oldX = $x;
2722
        $oldY = $y;
2723
        $totItens = $this->det->length;
0 ignored issues
show
Bug introduced by
The property length does not seem to exist in DOMNode.

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
2724
        //#####################################################################
2725
        //DADOS DOS PRODUTOS / SERVIÇOS
2726
        $texto = "DADOS DOS PRODUTOS / SERVIÇOS ";
2727
        if ($this->orientacao == 'P') {
2728
            $w = $this->wPrint;
2729
        } else {
2730
            if ($nInicio < 2) { // primeira página
2731
                $w = $this->wPrint - $this->wCanhoto;
2732
            } else { // páginas seguintes
2733
                $w = $this->wPrint;
2734
            }
2735
        }
2736
        $h = 4;
2737
        $aFont = ['font'=>$this->fontePadrao, 'size'=>7, 'style'=>'B'];
2738
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 0, '');
2739
        $y += 3;
2740
        //desenha a caixa dos dados dos itens da NF
2741
        $hmax += 1;
2742
        $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...
2743
        $this->pdf->textBox($x, $y, $w, $hmax);
2744
        //##################################################################################
2745
        // cabecalho LOOP COM OS DADOS DOS PRODUTOS
2746
        //CÓDIGO PRODUTO
2747
        $texto = "CÓDIGO PRODUTO";
2748
        $w1 = round($w*0.09, 0);
2749
        $h = 4;
2750
        $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
2751
        $this->pdf->textBox($x, $y, $w1, $h, $texto, $aFont, 'C', 'C', 0, '', false);
2752
        $this->pdf->line($x+$w1, $y, $x+$w1, $y+$hmax);
2753
        //DESCRIÇÃO DO PRODUTO / SERVIÇO
2754
        $x += $w1;
2755
        $w2 = round($w*0.28, 0);
2756
        $texto = 'DESCRIÇÃO DO PRODUTO / SERVIÇO';
2757
        $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
2758
        $this->pdf->textBox($x, $y, $w2, $h, $texto, $aFont, 'C', 'C', 0, '', false);
2759
        $this->pdf->line($x+$w2, $y, $x+$w2, $y+$hmax);
2760
        //NCM/SH
2761
        $x += $w2;
2762
        $w3 = round($w*0.06, 0);
2763
        $texto = 'NCM/SH';
2764
        $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
2765
        $this->pdf->textBox($x, $y, $w3, $h, $texto, $aFont, 'C', 'C', 0, '', false);
2766
        $this->pdf->line($x+$w3, $y, $x+$w3, $y+$hmax);
2767
        //O/CST ou O/CSOSN
2768
        $x += $w3;
2769
        $w4 = round($w*0.05, 0);
2770
        $texto = 'O/CSOSN';//Regime do Simples CRT = 1 ou CRT = 2
2771
        if ($this->getTagValue($this->emit, 'CRT') == '3') {
2772
             $texto = 'O/CST';//Regime Normal
2773
        }
2774
        $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
2775
        $this->pdf->textBox($x, $y, $w4, $h, $texto, $aFont, 'C', 'C', 0, '', false);
2776
        $this->pdf->line($x+$w4, $y, $x+$w4, $y+$hmax);
2777
        //CFOP
2778
        $x += $w4;
2779
        $w5 = round($w*0.04, 0);
2780
        $texto = 'CFOP';
2781
        $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
2782
        $this->pdf->textBox($x, $y, $w5, $h, $texto, $aFont, 'C', 'C', 0, '', false);
2783
        $this->pdf->line($x+$w5, $y, $x+$w5, $y+$hmax);
2784
        //UN
2785
        $x += $w5;
2786
        $w6 = round($w*0.03, 0);
2787
        $texto = 'UN';
2788
        $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
2789
        $this->pdf->textBox($x, $y, $w6, $h, $texto, $aFont, 'C', 'C', 0, '', false);
2790
        $this->pdf->line($x+$w6, $y, $x+$w6, $y+$hmax);
2791
        //QUANT
2792
        $x += $w6;
2793
        $w7 = round($w*0.07, 0);
2794
        $texto = 'QUANT';
2795
        $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
2796
        $this->pdf->textBox($x, $y, $w7, $h, $texto, $aFont, 'C', 'C', 0, '', false);
2797
        $this->pdf->line($x+$w7, $y, $x+$w7, $y+$hmax);
2798
        //VALOR UNIT
2799
        $x += $w7;
2800
        $w8 = round($w*0.06, 0);
2801
        $texto = 'VALOR UNIT';
2802
        $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
2803
        $this->pdf->textBox($x, $y, $w8, $h, $texto, $aFont, 'C', 'C', 0, '', false);
2804
        $this->pdf->line($x+$w8, $y, $x+$w8, $y+$hmax);
2805
        //VALOR TOTAL
2806
        $x += $w8;
2807
        $w9 = round($w*0.06, 0);
2808
        $texto = 'VALOR TOTAL';
2809
        $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
2810
        $this->pdf->textBox($x, $y, $w9, $h, $texto, $aFont, 'C', 'C', 0, '', false);
2811
        $this->pdf->line($x+$w9, $y, $x+$w9, $y+$hmax);
2812
        //B.CÁLC ICMS
2813
        $x += $w9;
2814
        $w10 = round($w*0.06, 0);
2815
        $texto = 'B.CÁLC ICMS';
2816
        $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
2817
        $this->pdf->textBox($x, $y, $w10, $h, $texto, $aFont, 'C', 'C', 0, '', false);
2818
        $this->pdf->line($x+$w10, $y, $x+$w10, $y+$hmax);
2819
        //VALOR ICMS
2820
        $x += $w10;
2821
        $w11 = round($w*0.06, 0);
2822
        $texto = 'VALOR ICMS';
2823
        $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
2824
        $this->pdf->textBox($x, $y, $w11, $h, $texto, $aFont, 'C', 'C', 0, '', false);
2825
        $this->pdf->line($x+$w11, $y, $x+$w11, $y+$hmax);
2826
        //VALOR IPI
2827
        $x += $w11;
2828
        $w12 = round($w*0.05, 0);
2829
        $texto = 'VALOR IPI';
2830
        $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
2831
        $this->pdf->textBox($x, $y, $w12, $h, $texto, $aFont, 'C', 'C', 0, '', false);
2832
        $this->pdf->line($x+$w12, $y, $x+$w12, $y+$hmax);
2833
        //ALÍQ. ICMS
2834
        $x += $w12;
2835
        $w13 = round($w*0.035, 0);
2836
        $texto = 'ALÍQ. ICMS';
2837
        $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
2838
        $this->pdf->textBox($x, $y, $w13, $h, $texto, $aFont, 'C', 'C', 0, '', false);
2839
        $this->pdf->line($x+$w13, $y, $x+$w13, $y+$hmax);
2840
        //ALÍQ. IPI
2841
        $x += $w13;
2842
        $w14 = $w-($w1+$w2+$w3+$w4+$w5+$w6+$w7+$w8+$w9+$w10+$w11+$w12+$w13);
2843
        $texto = 'ALÍQ. IPI';
2844
        $this->pdf->textBox($x, $y, $w14, $h, $texto, $aFont, 'C', 'C', 0, '', false);
2845
        $this->pdf->line($oldX, $y+$h+1, $oldX + $w, $y+$h+1);
2846
        $y += 5;
2847
        //##################################################################################
2848
        // LOOP COM OS DADOS DOS PRODUTOS
2849
        $i = 0;
2850
        $hUsado = $hCabecItens;
2851
        $aFont = ['font'=>$this->fontePadrao, 'size'=>7, 'style'=>''];
2852
        foreach ($this->det as $d) {
0 ignored issues
show
Bug introduced by
The expression $this->det of type object<DOMNode> is not traversable.
Loading history...
2853
            if ($i >= $nInicio) {
2854
                $thisItem = $this->det->item($i);
2855
                //carrega as tags do item
2856
                $prod = $thisItem->getElementsByTagName("prod")->item(0);
2857
                $imposto = $this->det->item($i)->getElementsByTagName("imposto")->item(0);
2858
                $ICMS = $imposto->getElementsByTagName("ICMS")->item(0);
2859
                $IPI  = $imposto->getElementsByTagName("IPI")->item(0);
2860
                $textoProduto = trim($this->descricaoProduto($thisItem));
2861
2862
                $linhaDescr = $this->pdf->getNumLines($textoProduto, $w2, $aFont);
2863
                $h = round(($linhaDescr * $this->pdf->fontSize)+ ($linhaDescr * 0.5), 2);
2864
                $hUsado += $h;
2865
2866
                $diffH = $hmax - $hUsado;
2867
2868
                if ($pag != $totpag) {
2869
                    if (1 > $diffH && $i < $totItens) {
2870
                        //ultrapassa a capacidade para uma única página
2871
                        //o restante dos dados serão usados nas proximas paginas
2872
                        $nInicio = $i;
2873
                        break;
2874
                    }
2875
                }
2876
                $y_linha=$y+$h;
2877
                // linha entre itens
2878
                $this->pdf->dashedHLine($oldX, $y_linha, $w, 0.1, 120);
2879
                //corrige o x
2880
                $x=$oldX;
2881
                //codigo do produto
2882
                $texto = $prod->getElementsByTagName("cProd")->item(0)->nodeValue;
2883
                $this->pdf->textBox($x, $y, $w1, $h, $texto, $aFont, 'T', 'C', 0, '');
2884
                $x += $w1;
2885
                //DESCRIÇÃO
2886
                if ($this->orientacao == 'P') {
2887
                    $this->pdf->textBox($x, $y, $w2, $h, $textoProduto, $aFont, 'T', 'L', 0, '', false);
2888
                } else {
2889
                    $this->pdf->textBox($x, $y, $w2, $h, $textoProduto, $aFont, 'T', 'L', 0, '', false);
2890
                }
2891
                $x += $w2;
2892
                //NCM
2893
                $texto = ! empty($prod->getElementsByTagName("NCM")->item(0)->nodeValue) ?
2894
                        $prod->getElementsByTagName("NCM")->item(0)->nodeValue : '';
2895
                $this->pdf->textBox($x, $y, $w3, $h, $texto, $aFont, 'T', 'C', 0, '');
2896
                $x += $w3;
2897
                //CST
2898
                if (isset($ICMS)) {
2899
                    $origem =  $this->getTagValue($ICMS, "orig");
2900
                    $cst =  $this->getTagValue($ICMS, "CST");
2901
                    $csosn =  $this->getTagValue($ICMS, "CSOSN");
2902
                    $texto = $origem.$cst.$csosn;
2903
                    $this->pdf->textBox($x, $y, $w4, $h, $texto, $aFont, 'T', 'C', 0, '');
2904
                }
2905
                //CFOP
2906
                $x += $w4;
2907
                $texto = $prod->getElementsByTagName("CFOP")->item(0)->nodeValue;
2908
                $this->pdf->textBox($x, $y, $w5, $h, $texto, $aFont, 'T', 'C', 0, '');
2909
                //Unidade
2910
                $x += $w5;
2911
                $texto = $prod->getElementsByTagName("uCom")->item(0)->nodeValue;
2912
                $this->pdf->textBox($x, $y, $w6, $h, $texto, $aFont, 'T', 'C', 0, '');
2913
                $x += $w6;
2914
                if ($this->orientacao == 'P') {
2915
                    $alinhamento = 'R';
2916
                } else {
2917
                    $alinhamento = 'R';
2918
                }
2919
                // QTDADE
2920
                $texto = number_format($prod->getElementsByTagName("qCom")->item(0)->nodeValue, 4, ",", ".");
2921
                $this->pdf->textBox($x, $y, $w7, $h, $texto, $aFont, 'T', $alinhamento, 0, '');
2922
                $x += $w7;
2923
                // Valor Unitário
2924
                $texto = number_format($prod->getElementsByTagName("vUnCom")->item(0)->nodeValue, 4, ",", ".");
2925
                $this->pdf->textBox($x, $y, $w8, $h, $texto, $aFont, 'T', $alinhamento, 0, '');
2926
                $x += $w8;
2927
                // Valor do Produto
2928
                $texto = "";
2929
                if (is_numeric($prod->getElementsByTagName("vProd")->item(0)->nodeValue)) {
2930
                    $texto = number_format($prod->getElementsByTagName("vProd")->item(0)->nodeValue, 2, ",", ".");
2931
                }
2932
                $this->pdf->textBox($x, $y, $w9, $h, $texto, $aFont, 'T', $alinhamento, 0, '');
2933
                //Valor da Base de calculo
2934
                $x += $w9;
2935
                if (isset($ICMS)) {
2936
                    $texto = ! empty($ICMS->getElementsByTagName("vBC")->item(0)->nodeValue)
2937
                    ? number_format(
2938
                        $ICMS->getElementsByTagName("vBC")->item(0)->nodeValue,
2939
                        2,
2940
                        ",",
2941
                        "."
2942
                    )
2943
                    : '0, 00';
2944
                    $this->pdf->textBox($x, $y, $w10, $h, $texto, $aFont, 'T', $alinhamento, 0, '');
2945
                }
2946
                //Valor do ICMS
2947
                $x += $w10;
2948
                if (isset($ICMS)) {
2949
                    $texto = ! empty($ICMS->getElementsByTagName("vICMS")->item(0)->nodeValue)
2950
                    ? number_format(
2951
                        $ICMS->getElementsByTagName("vICMS")->item(0)->nodeValue,
2952
                        2,
2953
                        ",",
2954
                        "."
2955
                    )
2956
                    : '0, 00';
2957
                    $this->pdf->textBox($x, $y, $w11, $h, $texto, $aFont, 'T', $alinhamento, 0, '');
2958
                }
2959
                //Valor do IPI
2960
                $x += $w11;
2961
                if (isset($IPI)) {
2962
                    $texto = ! empty($IPI->getElementsByTagName("vIPI")->item(0)->nodeValue)
2963
                    ? number_format(
2964
                        $IPI->getElementsByTagName("vIPI")->item(0)->nodeValue,
2965
                        2,
2966
                        ",",
2967
                        "."
2968
                    )
2969
                    :'';
2970
                } else {
2971
                    $texto = '';
2972
                }
2973
                $this->pdf->textBox($x, $y, $w12, $h, $texto, $aFont, 'T', $alinhamento, 0, '');
2974
                // %ICMS
2975
                $x += $w12;
2976
                if (isset($ICMS)) {
2977
                    $texto = ! empty($ICMS->getElementsByTagName("pICMS")->item(0)->nodeValue)
2978
                    ? number_format(
2979
                        $ICMS->getElementsByTagName("pICMS")->item(0)->nodeValue,
2980
                        2,
2981
                        ",",
2982
                        "."
2983
                    )
2984
                    : '0, 00';
2985
                    $this->pdf->textBox($x, $y, $w13, $h, $texto, $aFont, 'T', 'C', 0, '');
2986
                }
2987
                //%IPI
2988
                $x += $w13;
2989
                if (isset($IPI)) {
2990
                    $texto = ! empty($IPI->getElementsByTagName("pIPI")->item(0)->nodeValue)
2991
                    ? number_format(
2992
                        $IPI->getElementsByTagName("pIPI")->item(0)->nodeValue,
2993
                        2,
2994
                        ",",
2995
                        "."
2996
                    )
2997
                    : '';
2998
                } else {
2999
                    $texto = '';
3000
                }
3001
                $this->pdf->textBox($x, $y, $w14, $h, $texto, $aFont, 'T', 'C', 0, '');
3002
3003
3004
                // Dados do Veiculo Somente para veiculo 0 Km
3005
                $veicProd = $prod->getElementsByTagName("veicProd")->item(0);
3006
                // Tag somente é gerada para veiculo 0k, e só é permitido um veiculo por NF-e por conta do detran
3007
                // Verifica se a Tag existe
3008
                if (!empty($veicProd)) {
3009
                    $this->dadosItenVeiculoDANFE($oldX, $y, $nInicio, $h, $prod);
3010
                }
3011
3012
3013
                $y += $h;
3014
                $i++;
3015
                //incrementa o controle dos itens processados.
3016
                $this->qtdeItensProc++;
3017
            } else {
3018
                $i++;
3019
            }
3020
        }
3021
        return $oldY+$hmax;
3022
    }
3023
3024
3025
    /**
3026
     * dadosItenVeiculoDANFE
3027
     * Coloca os dados do veiculo abaixo do item da NFe. (retrato e paisagem)
3028
     *
3029
     * @param float  $x    Posição horizontal
3030
     *                     canto esquerdo
3031
     * @param float  $y    Posição vertical
3032
     *                     canto superior
3033
     * @param        $nInicio
3034
     * @param float  $h    altura do campo
3035
     * @param object $prod Contendo todos os dados do item
3036
     */
3037
3038
    protected function dadosItenVeiculoDANFE($x, $y, &$nInicio, $h, $prod)
3039
    {
3040
        $oldX = $x;
3041
        $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...
3042
3043
        if ($this->orientacao == 'P') {
3044
            $w = $this->wPrint;
3045
        } else {
3046
            if ($nInicio < 2) { // primeira página
3047
                $w = $this->wPrint - $this->wCanhoto;
3048
            } else { // páginas seguintes
3049
                $w = $this->wPrint;
3050
            }
3051
        }
3052
3053
        $aFont = ['font'=>$this->fontePadrao, 'size'=>7, 'style'=>''];
3054
3055
        $w1 = round($w*0.09, 0);
3056
3057
        // Tabela Renavam Combustivel
3058
        $renavamCombustivel = [
3059
            1=>'ALCOOL',
3060
            2=>'GASOLINA',
3061
            3=>'DIESEL',
3062
            4=>'GASOGENIO',
3063
            5=>'GAS METANO',
3064
            6=>'ELETRICO/FONTE INTERNA',
3065
            7=>'ELETRICO/FONTE EXTERNA',
3066
            8=>'GASOL/GAS NATURAL COMBUSTIVEL',
3067
            9=>'ALCOOL/GAS NATURAL COMBUSTIVEL',
3068
            10=>'DIESEL/GAS NATURAL COMBUSTIVEL',
3069
            11=>'VIDE/CAMPO/OBSERVACAO',
3070
            12=>'ALCOOL/GAS NATURAL VEICULAR',
3071
            13=>'GASOLINA/GAS NATURAL VEICULAR',
3072
            14=>'DIESEL/GAS NATURAL VEICULAR',
3073
            15=>'GAS NATURAL VEICULAR',
3074
            16=>'ALCOOL/GASOLINA',
3075
            17=>'GASOLINA/ALCOOL/GAS NATURAL',
3076
            18=>'GASOLINA/ELETRICO'
3077
        ];
3078
3079
        $renavamEspecie = [
3080
            1=>'PASSAGEIRO',
3081
            2=>'CARGA',
3082
            3=>'MISTO',
3083
            4=>'CORRIDA',
3084
            5=>'TRACAO',
3085
            6=>'ESPECIAL',
3086
            7=>'COLECAO'
3087
        ];
3088
3089
        $renavamTiposVeiculos = [
3090
            1=>'BICICLETA',
3091
            2=>'CICLOMOTOR',
3092
            3=>'MOTONETA',
3093
            4=>'MOTOCICLETA',
3094
            5=>'TRICICLO',
3095
            6=>'AUTOMOVEL',
3096
            7=>'MICROONIBUS',
3097
            8=>'ONIBUS',
3098
            9=>'BONDE',
3099
            10=>'REBOQUE',
3100
            11=>'SEMI-REBOQUE',
3101
            12=>'CHARRETE',
3102
            13=>'CAMIONETA',
3103
            14=>'CAMINHAO',
3104
            15=>'CARROCA',
3105
            16=>'CARRO DE MAO',
3106
            17=>'CAMINHAO TRATOR',
3107
            18=>'TRATOR DE RODAS',
3108
            19=>'TRATOR DE ESTEIRAS',
3109
            20=>'TRATOR MISTO',
3110
            21=>'QUADRICICLO',
3111
            22=>'CHASSI/PLATAFORMA',
3112
            23=>'CAMINHONETE',
3113
            24=>'SIDE-CAR',
3114
            25=>'UTILITARIO',
3115
            26=>'MOTOR-CASA'
3116
        ];
3117
3118
        $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...
3119
            'F'=>'FOSCA',
3120
            'S'=>'SÓLIDA',
3121
            'P'=>'PEROLIZADA',
3122
            'M'=>'METALICA',
3123
        ];
3124
3125
        $veicProd = $prod->getElementsByTagName("veicProd")->item(0);
3126
3127
        $veiculoChassi = $veicProd->getElementsByTagName("chassi")->item(0)->nodeValue;
3128
        $veiculoCor = $veicProd->getElementsByTagName("xCor")->item(0)->nodeValue;
3129
        $veiculoCilindrada = $veicProd->getElementsByTagName("cilin")->item(0)->nodeValue;
3130
        $veiculoCmkg = $veicProd->getElementsByTagName("CMT")->item(0)->nodeValue;
3131
        $veiculoTipo = $veicProd->getElementsByTagName("tpVeic")->item(0)->nodeValue;
3132
3133
        $veiculoMotor = $veicProd->getElementsByTagName("nMotor")->item(0)->nodeValue;
3134
        $veiculoRenavam = $veicProd->getElementsByTagName("cMod")->item(0)->nodeValue;
3135
        $veiculoHp = $veicProd->getElementsByTagName("pot")->item(0)->nodeValue;
3136
        $veiculoPlaca = ''; //$veiculo->getElementsByTagName("CMT")->item(0)->nodeValue;
3137
        $veiculoTipoPintura = $veicProd->getElementsByTagName("tpPint")->item(0)->nodeValue;
3138
        $veiculoMarcaModelo = $prod->getElementsByTagName("xProd")->item(0)->nodeValue;
3139
        $veiculoEspecie = $veicProd->getElementsByTagName("espVeic")->item(0)->nodeValue;
3140
        $veiculoCombustivel = $veicProd->getElementsByTagName("tpComb")->item(0)->nodeValue;
3141
        $veiculoSerial = $veicProd->getElementsByTagName("nSerie")->item(0)->nodeValue;
3142
        $veiculoFabricacao = $veicProd->getElementsByTagName("anoFab")->item(0)->nodeValue;
3143
        $veiculoModelo = $veicProd->getElementsByTagName("anoMod")->item(0)->nodeValue;
3144
        $veiculoDistancia = $veicProd->getElementsByTagName("dist")->item(0)->nodeValue;
3145
3146
        $x = $oldX;
3147
3148
        $yVeic = $y + $h;
3149
        $texto = 'Chassi: ............: ' . $veiculoChassi;
3150
        $this->pdf->textBox($x, $yVeic, $w1+40, $h, $texto, $aFont, 'T', 'L', 0, '');
3151
        $yVeic += $h;
3152
        $texto = 'Cor...................: ' . $veiculoCor;
3153
        $this->pdf->textBox($x, $yVeic, $w1+40, $h, $texto, $aFont, 'T', 'L', 0, '');
3154
        $yVeic += $h;
3155
        $texto = 'Cilindrada........: ' . $veiculoCilindrada;
3156
        $this->pdf->textBox($x, $yVeic, $w1+40, $h, $texto, $aFont, 'T', 'L', 0, '');
3157
        $yVeic += $h;
3158
        $texto = 'Cmkg...............: ' . $veiculoCmkg;
3159
        $this->pdf->textBox($x, $yVeic, $w1+40, $h, $texto, $aFont, 'T', 'L', 0, '');
3160
        $yVeic += $h;
3161
        $texto = 'Tipo.................: ' . ($renavamTiposVeiculos[intval($veiculoTipo)] ?? $veiculoTipo);
3162
         $this->pdf->textBox($x, $yVeic, $w1+40, $h, $texto, $aFont, 'T', 'L', 0, '');
3163
        $yVeic = $y + $h;
3164
        $xVeic = $x + 65;
3165
        $texto = 'Nº Motor: .........: ' . $veiculoMotor;
3166
        $this->pdf->textBox($xVeic, $yVeic, $w1+50, $h, $texto, $aFont, 'T', 'L', 0, '');
3167
        $yVeic += $h;
3168
        $texto = 'Renavam...........: ' . $veiculoRenavam;
3169
        $this->pdf->textBox($xVeic, $yVeic, $w1+50, $h, $texto, $aFont, 'T', 'L', 0, '');
3170
        $yVeic += $h;
3171
        $texto = 'HP.....................: ' . $veiculoHp;
3172
        $this->pdf->textBox($xVeic, $yVeic, $w1+50, $h, $texto, $aFont, 'T', 'L', 0, '');
3173
        $yVeic += $h;
3174
        $texto = 'Placa.................: ' . $veiculoPlaca;
3175
        $this->pdf->textBox($xVeic, $yVeic, $w1+50, $h, $texto, $aFont, 'T', 'L', 0, '');
3176
        $yVeic += $h;
3177
        $texto = 'Tipo Pintura......: ' . ($renavamEspecie[intval($veiculoTipoPintura)] ?? $veiculoTipoPintura);
3178
        $this->pdf->textBox($xVeic, $yVeic, $w1+50, $h, $texto, $aFont, 'T', 'L', 0, '');
3179
        $yVeic = $y + $h;
3180
        $xVeic = $xVeic + 55;
3181
        $texto = 'Marca / Modelo.....: ' . $veiculoMarcaModelo;
3182
        $this->pdf->textBox($xVeic, $yVeic, $w1+50, $h, $texto, $aFont, 'T', 'L', 0, '');
3183
        $yVeic += $h;
3184
        $texto = 'Especie..................: ' . ($renavamEspecie[intval($veiculoEspecie)] ?? $veiculoEspecie);
3185
        $this->pdf->textBox($xVeic, $yVeic, $w1+50, $h, $texto, $aFont, 'T', 'L', 0, '');
3186
        $yVeic += $h;
3187
        $texto = 'Combustivel..........: ' . ($renavamCombustivel[intval($veiculoCombustivel)] ?? $veiculoCombustivel);
3188
        $this->pdf->textBox($xVeic, $yVeic, $w1+50, $h, $texto, $aFont, 'T', 'L', 0, '');
3189
        $yVeic += $h;
3190
        $texto = 'Serial.....................: ' . $veiculoSerial;
3191
        $this->pdf->textBox($xVeic, $yVeic, $w1+50, $h, $texto, $aFont, 'T', 'L', 0, '');
3192
        $yVeic += $h;
3193
        $texto = 'Ano Fab/Mod........: '. $veiculoFabricacao . '/' . $veiculoModelo;
3194
        $this->pdf->textBox($xVeic, $yVeic, $w1+50, $h, $texto, $aFont, 'T', 'L', 0, '');
3195
        $yVeic += $h;
3196
        $texto = 'Distancia Entre Eixos(mm)..: '. $veiculoDistancia;
3197
        $this->pdf->textBox($xVeic, $yVeic, $w1+50, $h, $texto, $aFont, 'T', 'L', 0, '');
3198
    }
3199
3200
    /**
3201
     * issqn
3202
     * Monta o campo de serviços do DANFE
3203
     *
3204
     * @name   issqn (retrato e paisagem)
3205
     * @param  float $x Posição horizontal canto esquerdo
3206
     * @param  float $y Posição vertical canto superior
3207
     * @return float Posição vertical final
3208
     */
3209
    protected function issqn($x, $y)
3210
    {
3211
        $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...
3212
        //#####################################################################
3213
        //CÁLCULO DO ISSQN
3214
        $texto = "CÁLCULO DO ISSQN";
3215
        $w = $this->wPrint;
3216
        $h = 7;
3217
        $aFont = ['font'=>$this->fontePadrao, 'size'=>7, 'style'=>'B'];
3218
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 0, '');
3219
        //INSCRIÇÃO MUNICIPAL
3220
        $y += 3;
3221
        $w = round($this->wPrint*0.23, 0);
3222
        $texto = 'INSCRIÇÃO MUNICIPAL';
3223
        $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
3224
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 1, '');
3225
        //inscrição municipal
3226
        $texto = ! empty($this->emit->getElementsByTagName("IM")->item(0)->nodeValue) ?
3227
                $this->emit->getElementsByTagName("IM")->item(0)->nodeValue : '';
3228
        $aFont = ['font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B'];
3229
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'B', 'L', 0, '');
3230
        //VALOR TOTAL DOS SERVIÇOS
3231
        $x += $w;
3232
        $texto = 'VALOR TOTAL DOS SERVIÇOS';
3233
        $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
3234
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 1, '');
3235
        if (isset($this->ISSQNtot)) {
3236
            $texto = ! empty($this->ISSQNtot->getElementsByTagName("vServ")->item(0)->nodeValue) ?
3237
                    $this->ISSQNtot->getElementsByTagName("vServ")->item(0)->nodeValue : '';
3238
            $texto = number_format($texto, 2, ",", ".");
3239
        } else {
3240
            $texto = '';
3241
        }
3242
        $aFont = ['font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B'];
3243
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'B', 'R', 0, '');
3244
        //BASE DE CÁLCULO DO ISSQN
3245
        $x += $w;
3246
        $texto = 'BASE DE CÁLCULO DO ISSQN';
3247
        $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
3248
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 1, '');
3249
        if (isset($this->ISSQNtot)) {
3250
            $texto = ! empty($this->ISSQNtot->getElementsByTagName("vBC")->item(0)->nodeValue) ?
3251
                    $this->ISSQNtot->getElementsByTagName("vBC")->item(0)->nodeValue : '';
3252
            $texto = ! empty($texto) ? number_format($texto, 2, ",", ".") : '';
3253
        } else {
3254
            $texto = '';
3255
        }
3256
        $aFont = ['font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B'];
3257
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'B', 'R', 0, '');
3258
        //VALOR TOTAL DO ISSQN
3259
        $x += $w;
3260
        if ($this->orientacao == 'P') {
3261
            $w = $this->wPrint - (3 * $w);
3262
        } else {
3263
            $w = $this->wPrint - (3 * $w)-$this->wCanhoto;
3264
        }
3265
        $texto = 'VALOR TOTAL DO ISSQN';
3266
        $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
3267
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 1, '');
3268
        if (isset($this->ISSQNtot)) {
3269
            $texto = ! empty($this->ISSQNtot->getElementsByTagName("vISS")->item(0)->nodeValue) ?
3270
                    $this->ISSQNtot->getElementsByTagName("vISS")->item(0)->nodeValue : '';
3271
            $texto = ! empty($texto) ? number_format($texto, 2, ",", ".") : '';
3272
        } else {
3273
            $texto = '';
3274
        }
3275
        $aFont = ['font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B'];
3276
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'B', 'R', 0, '');
3277
        return ($y+$h+1);
3278
    }
3279
3280
    /**
3281
     *dadosAdicionais
3282
     * Coloca o grupo de dados adicionais da NFe. (retrato e paisagem)
3283
     *
3284
     * @name   dadosAdicionais
3285
     * @param  float $x Posição horizontal canto esquerdo
3286
     * @param  float $y Posição vertical canto superior
3287
     * @param  float $h altura do campo
3288
     * @return float Posição vertical final (eixo Y)
3289
     */
3290
    protected function dadosAdicionais($x, $y, $h)
3291
    {
3292
        //##################################################################################
3293
        //DADOS ADICIONAIS
3294
        $texto = "DADOS ADICIONAIS";
3295
        if ($this->orientacao == 'P') {
3296
              $w = $this->wPrint;
3297
        } else {
3298
              $w = $this->wPrint-$this->wCanhoto;
3299
        }
3300
        $aFont = ['font'=>$this->fontePadrao, 'size'=>7, 'style'=>'B'];
3301
        $this->pdf->textBox($x, $y, $w, 8, $texto, $aFont, 'T', 'L', 0, '');
3302
        //INFORMAÇÕES COMPLEMENTARES
3303
        $texto = "INFORMAÇÕES COMPLEMENTARES";
3304
        $y += 3;
3305
        $w = $this->wAdic;
3306
        $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>'B'];
3307
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 1, '');
3308
        //o texto com os dados adicionais foi obtido na função montaDANFE
3309
        //e carregado em uma propriedade privada da classe
3310
        //$this->wAdic com a largura do campo
3311
        //$this->textoAdic com o texto completo do campo
3312
        $y += 1;
3313
        $aFont = ['font'=>$this->fontePadrao, 'size'=>7, 'style'=>''];
3314
        $this->pdf->textBox($x, $y+2, $w-2, $h-3, $this->textoAdic, $aFont, 'T', 'L', 0, '', false);
3315
        //RESERVADO AO FISCO
3316
        $texto = "RESERVADO AO FISCO";
3317
        if ($this->nfeProc->getElementsByTagName("xMsg")) {
3318
            $texto = $texto . ' ' . $this->nfeProc->getElementsByTagName("xMsg")->item(0)->nodeValue;
3319
        }
3320
        $x += $w;
3321
        $y -= 1;
3322
        if ($this->orientacao == 'P') {
3323
            $w = $this->wPrint-$w;
3324
        } else {
3325
            $w = $this->wPrint-$w-$this->wCanhoto;
3326
        }
3327
        $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>'B'];
3328
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 1, '');
3329
        //inserir texto informando caso de contingência
3330
        // 1 - Normal - emissão normal;
3331
        // 2 - Contingência FS - emissão em contingência com impressão do DANFE em Formulário de Segurança;
3332
        // 3 - Contingência SCAN - emissão em contingência no Sistema de Contingência do Ambiente Nacional;
3333
        // 4 - Contingência DPEC - emissão em contingência com envio da Declaração
3334
        //     Prévia de Emissão em Contingência;
3335
        // 5 - Contingência FS-DA - emissão em contingência com impressão do DANFE em Formulário de
3336
        //     Segurança para Impressão de Documento Auxiliar de Documento Fiscal Eletrônico (FS-DA);
3337
        // 6 - Contingência SVC-AN
3338
        // 7 - Contingência SVC-RS
3339
        $xJust = $this->getTagValue($this->ide, 'xJust', 'Justificativa: ');
3340
        $dhCont = $this->getTagValue($this->ide, 'dhCont', ' Entrada em contingência : ');
3341
        $texto = '';
3342
        switch ($this->tpEmis) {
3343
            case 2:
3344
                $texto = 'CONTINGÊNCIA FS' . $dhCont . $xJust;
3345
                break;
3346
            case 3:
3347
                $texto = 'CONTINGÊNCIA SCAN' . $dhCont . $xJust;
3348
                break;
3349
            case 4:
3350
                $texto = 'CONTINGÊNCIA DPEC' . $dhCont . $xJust;
3351
                break;
3352
            case 5:
3353
                $texto = 'CONTINGÊNCIA FSDA' . $dhCont . $xJust;
3354
                break;
3355
            case 6:
3356
                $texto = 'CONTINGÊNCIA SVC-AN' . $dhCont . $xJust;
3357
                break;
3358
            case 7:
3359
                $texto = 'CONTINGÊNCIA SVC-RS' . $dhCont . $xJust;
3360
                break;
3361
        }
3362
        $y += 2;
3363
        $aFont = ['font'=>$this->fontePadrao, 'size'=>7, 'style'=>''];
3364
        $this->pdf->textBox($x, $y, $w-2, $h-3, $texto, $aFont, 'T', 'L', 0, '', false);
3365
        return $y+$h;
3366
    }
3367
3368
    /**
3369
     * rodape
3370
     * Monta o rodapé no final da DANFE com a data/hora de impressão e informações
3371
     * sobre a API NfePHP
3372
     *
3373
     * @param  float $x  Posição horizontal canto esquerdo
3374
     *
3375
     * @return void
3376
     */
3377
    protected function rodape($x)
3378
    {
3379
        
3380
        $y = $this->maxH - 4;
3381
        if ($this->orientacao == 'P') {
3382
              $w = $this->wPrint;
3383
        } else {
3384
              $w = $this->wPrint-$this->wCanhoto;
3385
              $x = $this->wCanhoto;
3386
        }
3387
        $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>'I'];
3388
        $texto = "Impresso em ". date('d/m/Y') . " as " . date('H:i:s')
3389
            . '  ' . $this->creditos;
3390
        $this->pdf->textBox($x, $y, $w, 0, $texto, $aFont, 'T', 'L', false);
0 ignored issues
show
Documentation introduced by
false is of type boolean, but the function expects a integer.

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

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

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

function acceptsInteger($int) { }

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

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
3391
        $texto = "Powered by NFePHP®";
3392
        $this->pdf->textBox($x, $y, $w, 0, $texto, $aFont, 'T', 'R', false, '');
0 ignored issues
show
Documentation introduced by
false is of type boolean, but the function expects a integer.

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

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

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

function acceptsInteger($int) { }

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

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
3393
    }
3394
3395
    /**
3396
     * pCcanhotoDANFE
3397
     * Monta o canhoto da DANFE (retrato e paisagem)
3398
     *
3399
     * @name   canhotoDANFE
3400
     * @param  number $x Posição horizontal canto esquerdo
3401
     * @param  number $y Posição vertical canto superior
3402
     * @return number Posição vertical final
3403
     *
3404
     * TODO 21/07/14 fmertins: quando orientação L-paisagem, o canhoto está sendo gerado incorretamente
3405
     */
3406
    protected function canhoto($x, $y)
3407
    {
3408
        $oldX = $x;
3409
        $oldY = $y;
3410
        //#################################################################################
3411
        //canhoto
3412
        //identificação do tipo de nf entrada ou saida
3413
        $tpNF = $this->ide->getElementsByTagName('tpNF')->item(0)->nodeValue;
3414
        if ($tpNF == '0') {
3415
            //NFe de Entrada
3416
            $emitente = '';
3417
            $emitente .= $this->dest->getElementsByTagName("xNome")->item(0)->nodeValue . " - ";
3418
            $emitente .= $this->enderDest->getElementsByTagName("xLgr")->item(0)->nodeValue . ", ";
3419
            $emitente .= $this->enderDest->getElementsByTagName("nro")->item(0)->nodeValue . " - ";
3420
            $emitente .= $this->getTagValue($this->enderDest, "xCpl", " - ", " ");
3421
            $emitente .= $this->enderDest->getElementsByTagName("xBairro")->item(0)->nodeValue . " ";
3422
            $emitente .= $this->enderDest->getElementsByTagName("xMun")->item(0)->nodeValue . "-";
3423
            $emitente .= $this->enderDest->getElementsByTagName("UF")->item(0)->nodeValue . "";
3424
            $destinatario = $this->emit->getElementsByTagName("xNome")->item(0)->nodeValue . " ";
3425
        } else {
3426
            //NFe de Saída
3427
            $emitente = $this->emit->getElementsByTagName("xNome")->item(0)->nodeValue . " ";
3428
            $destinatario = '';
3429
            $destinatario .= $this->dest->getElementsByTagName("xNome")->item(0)->nodeValue . " - ";
3430
            $destinatario .= $this->enderDest->getElementsByTagName("xLgr")->item(0)->nodeValue . ", ";
3431
            $destinatario .= $this->enderDest->getElementsByTagName("nro")->item(0)->nodeValue . " ";
3432
            $destinatario .= $this->getTagValue($this->enderDest, "xCpl", " - ", " ");
3433
            $destinatario .= $this->enderDest->getElementsByTagName("xBairro")->item(0)->nodeValue . " ";
3434
            $destinatario .= $this->enderDest->getElementsByTagName("xMun")->item(0)->nodeValue . "-";
3435
            $destinatario .= $this->enderDest->getElementsByTagName("UF")->item(0)->nodeValue . " ";
3436
        }
3437
        //identificação do sistema emissor
3438
        //linha separadora do canhoto
3439
        if ($this->orientacao == 'P') {
3440
            $w = round($this->wPrint * 0.81, 0);
3441
        } else {
3442
            //linha separadora do canhoto - 238
3443
            //posicao altura
3444
            $y = $this->wPrint-85;
3445
            //altura
3446
            $w = $this->wPrint-85-24;
3447
        }
3448
        $h = 10;
3449
        //desenha caixa
3450
        $texto = '';
3451
        $aFont = ['font'=>$this->fontePadrao, 'size'=>7, 'style'=>''];
3452
        $aFontSmall = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
3453
        if ($this->orientacao == 'P') {
3454
            $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'C', 'L', 1, '', false);
3455
        } else {
3456
            $this->pdf->textBox90($x, $y, $w, $h, $texto, $aFont, 'C', 'L', 1, '', false);
3457
        }
3458
        $numNF = str_pad($this->ide->getElementsByTagName('nNF')->item(0)->nodeValue, 9, "0", STR_PAD_LEFT);
3459
        $serie = str_pad($this->ide->getElementsByTagName('serie')->item(0)->nodeValue, 3, "0", STR_PAD_LEFT);
3460
        $texto = "RECEBEMOS DE ";
3461
        $texto .= $emitente;
3462
        $texto .= " OS PRODUTOS E/OU SERVIÇOS CONSTANTES DA NOTA FISCAL ELETRÔNICA INDICADA ";
3463
        if ($this->orientacao == 'P') {
3464
            $texto .= "ABAIXO";
3465
        } else {
3466
            $texto .= "AO LADO";
3467
        }
3468
        $texto .= ". EMISSÃO: ";
3469
        $dEmi = ! empty($this->ide->getElementsByTagName("dEmi")->item(0)->nodeValue) ?
3470
                $this->ide->getElementsByTagName("dEmi")->item(0)->nodeValue : '';
3471
        if ($dEmi == '') {
3472
            $dEmi = ! empty($this->ide->getElementsByTagName("dhEmi")->item(0)->nodeValue) ?
3473
                    $this->ide->getElementsByTagName("dhEmi")->item(0)->nodeValue : '';
3474
            $aDemi = explode('T', $dEmi);
3475
            $dEmi = $aDemi[0];
3476
        }
3477
        $texto .= $this->ymdTodmy($dEmi) ." ";
3478
        $texto .= "VALOR TOTAL: R$ ";
3479
        $texto .= number_format($this->ICMSTot->getElementsByTagName("vNF")->item(0)->nodeValue, 2, ",", ".") . " ";
3480
        $texto .= "DESTINATÁRIO: ";
3481
        $texto .= $destinatario;
3482
        if ($this->orientacao == 'P') {
3483
            $this->pdf->textBox($x, $y, $w-1, $h, $texto, $aFont, 'C', 'L', 0, '', false);
3484
            $x1 = $x + $w;
3485
            $w1 = $this->wPrint - $w;
3486
            $texto = "NF-e";
3487
            $aFont = ['font'=>$this->fontePadrao, 'size'=>14, 'style'=>'B'];
3488
            $this->pdf->textBox($x1, $y, $w1, 18, $texto, $aFont, 'T', 'C', 0, '');
3489
            $texto = "Nº. " . $this->formatField($numNF, "###.###.###") . " \n";
3490
            $texto .= "Série $serie";
3491
            $aFont = ['font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B'];
3492
            $this->pdf->textBox($x1, $y, $w1, 18, $texto, $aFont, 'C', 'C', 1, '');
3493
            //DATA DE RECEBIMENTO
3494
            $texto = "DATA DE RECEBIMENTO";
3495
            $y += $h;
3496
            $w2 = round($this->wPrint*0.17, 0); //35;
3497
            $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
3498
            $this->pdf->textBox($x, $y, $w2, 8, $texto, $aFont, 'T', 'L', 1, '');
3499
            //IDENTIFICAÇÃO E ASSINATURA DO RECEBEDOR
3500
            $x += $w2;
3501
            $w3 = $w-$w2;
3502
            $texto = "IDENTIFICAÇÃO E ASSINATURA DO RECEBEDOR";
3503
            $this->pdf->textBox($x, $y, $w3, 8, $texto, $aFont, 'T', 'L', 1, '');
3504
            $x = $oldX;
3505
            $y += 9;
3506
            $this->pdf->dashedHLine($x, $y, $this->wPrint, 0.1, 80);
3507
            $y += 2;
3508
            return $y;
3509
        } else {
3510
            $x--;
3511
            $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...
3512
            //NUMERO DA NOTA FISCAL LOGO NFE
3513
            $w1 = 18;
3514
            $x1 = $oldX;
3515
            $y = $oldY;
3516
            $texto = "NF-e";
3517
            $aFont = ['font'=>$this->fontePadrao, 'size'=>14, 'style'=>'B'];
3518
            $this->pdf->textBox($x1, $y, $w1, 18, $texto, $aFont, 'T', 'C', 0, '');
3519
            $texto = "Nº.\n" . $this->formatField($numNF, "###.###.###") . " \n";
3520
            $texto .= "Série $serie";
3521
            $aFont = ['font'=>$this->fontePadrao, 'size'=>8, 'style'=>'B'];
3522
            $this->pdf->textBox($x1, $y, $w1, 18, $texto, $aFont, 'C', 'C', 1, '');
3523
            //DATA DO RECEBIMENTO
3524
            $texto = "DATA DO RECEBIMENTO";
3525
            $y = $this->wPrint-85;
3526
            $x = 12;
3527
            $w2 = round($this->wPrint*0.17, 0); //35;
3528
            $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
3529
            $this->pdf->textBox90($x, $y, $w2, 8, $texto, $aFont, 'T', 'L', 1, '');
3530
            //IDENTIFICAÇÃO E ASSINATURA DO RECEBEDOR
3531
            $y -= $w2;
3532
            $w3 = $w-$w2;
3533
            $texto = "IDENTIFICAÇÃO E ASSINATURA DO RECEBEDOR";
3534
            $aFont = ['font'=>$this->fontePadrao, 'size'=>5.7, 'style'=>''];
3535
            $x = $this->pdf->textBox90($x, $y, $w3, 8, $texto, $aFont, 'T', 'L', 1, '');
3536
            $this->pdf->dashedVLine(22, $oldY, 0.1, $this->wPrint, 69);
3537
            return $x;
3538
        }
3539
    }
3540
3541
    /**
3542
     * geraInformacoesDaTagCompra
3543
     * Devolve uma string contendo informação sobre as tag <compra><xNEmp>, <xPed> e <xCont> ou string vazia.
3544
     * Aviso: Esta função não leva em consideração dados na tag xPed do item.
3545
     *
3546
     * @name   pGeraInformacoesDaTagCompra
3547
     * @return string com as informacoes dos pedidos.
3548
     */
3549
    protected function geraInformacoesDaTagCompra()
3550
    {
3551
        $saida = "";
3552
        if (isset($this->compra)) {
3553
            if (! empty($this->compra->getElementsByTagName("xNEmp")->item(0)->nodeValue)) {
3554
                $saida .= " Nota de Empenho: " . $this->compra->getElementsByTagName("xNEmp")->item(0)->nodeValue;
3555
            }
3556
            if (! empty($this->compra->getElementsByTagName("xPed")->item(0)->nodeValue)) {
3557
                $saida .= " Pedido: " . $this->compra->getElementsByTagName("xPed")->item(0)->nodeValue;
3558
            }
3559
            if (! empty($this->compra->getElementsByTagName("xCont")->item(0)->nodeValue)) {
3560
                $saida .= " Contrato: " . $this->compra->getElementsByTagName("xCont")->item(0)->nodeValue;
3561
            }
3562
        }
3563
        return $saida;
3564
    }
3565
3566
    /**
3567
     * geraChaveAdicionalDeContingencia
3568
     *
3569
     * @name   geraChaveAdicionalDeContingencia
3570
     * @return string chave
3571
     */
3572
    protected function geraChaveAdicionalDeContingencia()
3573
    {
3574
        //cUF tpEmis CNPJ vNF ICMSp ICMSs DD  DV
3575
        // Quantidade de caracteres  02   01      14  14    01    01  02 01
3576
        $forma  = "%02d%d%s%014d%01d%01d%02d";
3577
        $cUF    = $this->ide->getElementsByTagName('cUF')->item(0)->nodeValue;
3578
        $CNPJ   = "00000000000000" . $this->emit->getElementsByTagName('CNPJ')->item(0)->nodeValue;
3579
        $CNPJ   = substr($CNPJ, -14);
3580
        $vNF    = $this->ICMSTot->getElementsByTagName("vNF")->item(0)->nodeValue * 100;
3581
        $vICMS  = $this->ICMSTot->getElementsByTagName("vICMS")->item(0)->nodeValue;
3582
        if ($vICMS > 0) {
3583
            $vICMS = 1;
3584
        }
3585
        $icmss  = $this->ICMSTot->getElementsByTagName("vBC")->item(0)->nodeValue;
3586
        if ($icmss > 0) {
3587
            $icmss = 1;
3588
        }
3589
        $dEmi = ! empty($this->ide->getElementsByTagName("dEmi")->item(0)->nodeValue) ?
3590
                $this->ide->getElementsByTagName("dEmi")->item(0)->nodeValue : '';
3591
        if ($dEmi == '') {
3592
            $dEmi = ! empty($this->ide->getElementsByTagName("dhEmi")->item(0)->nodeValue) ?
3593
                    $this->ide->getElementsByTagName("dhEmi")->item(0)->nodeValue : '';
3594
            $aDemi = explode('T', $dEmi);
3595
            $dEmi = $aDemi[0];
3596
        }
3597
        $dd  = $dEmi;
3598
        $rpos = strrpos($dd, '-');
3599
        $dd  = substr($dd, $rpos +1);
3600
        $chave = sprintf($forma, $cUF, $this->tpEmis, $CNPJ, $vNF, $vICMS, $icmss, $dd);
3601
        $chave = $chave . $this->modulo11($chave);
3602
        return $chave;
3603
    }
3604
3605
    /**
3606
     *  geraInformacoesDasNotasReferenciadas
3607
     * Devolve uma string contendo informação sobre as notas referenciadas. Suporta N notas, eletrônicas ou não
3608
     * Exemplo: NFe Ref.: série: 01 número: 01 emit: 11.111.111/0001-01
3609
     * em 10/2010 [0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000]
3610
     *
3611
     * @return string Informacoes a serem adicionadas no rodapé sobre notas referenciadas.
3612
     */
3613
    protected function geraInformacoesDasNotasReferenciadas()
3614
    {
3615
        $formaNfeRef = "\r\nNFe Ref.: série:%d número:%d emit:%s em %s [%s]";
3616
        $formaCTeRef = "\r\nCTe Ref.: série:%d número:%d emit:%s em %s [%s]";
3617
        $formaNfRef = "\r\nNF  Ref.: série:%d numero:%d emit:%s em %s modelo: %d";
3618
        $formaECFRef = "\r\nECF Ref.: modelo: %s ECF:%d COO:%d";
3619
        $formaNfpRef = "\r\nNFP Ref.: série:%d número:%d emit:%s em %s modelo: %d IE:%s";
3620
        $saida='';
3621
        $nfRefs = $this->ide->getElementsByTagName('NFref');
3622
        if (0 === $nfRefs->length) {
3623
            return $saida;
3624
        }
3625
        if ($nfRefs->length > 2) {
3626
            return 'Existem mais de 2 NF/NFe/ECF/NFP/CTe referenciadas, não serão exibidas na DANFE.';
3627
        }
3628
        foreach ($nfRefs as $nfRef) {
3629
            if (empty($nfRef)) {
3630
                continue;
3631
            }
3632
            $refNFe = $nfRef->getElementsByTagName('refNFe');
3633
            foreach ($refNFe as $chave_acessoRef) {
3634
                $chave_acesso = $chave_acessoRef->nodeValue;
3635
                $chave_acessoF = $this->formatField($chave_acesso, $this->formatoChave);
3636
                $data = substr($chave_acesso, 4, 2)."/20".substr($chave_acesso, 2, 2);
3637
                $cnpj = $this->formatField(substr($chave_acesso, 6, 14), "##.###.###/####-##");
3638
                $serie  = substr($chave_acesso, 22, 3);
3639
                $numero = substr($chave_acesso, 25, 9);
3640
                $saida .= sprintf($formaNfeRef, $serie, $numero, $cnpj, $data, $chave_acessoF);
3641
            }
3642
            $refNF = $nfRef->getElementsByTagName('refNF');
3643
            foreach ($refNF as $umaRefNFe) {
3644
                $data = $umaRefNFe->getElementsByTagName('AAMM')->item(0)->nodeValue;
3645
                $cnpj = $umaRefNFe->getElementsByTagName('CNPJ')->item(0)->nodeValue;
3646
                $mod = $umaRefNFe->getElementsByTagName('mod')->item(0)->nodeValue;
3647
                $serie = $umaRefNFe->getElementsByTagName('serie')->item(0)->nodeValue;
3648
                $numero = $umaRefNFe->getElementsByTagName('nNF')->item(0)->nodeValue;
3649
                $data = substr($data, 2, 2) . "/20" . substr($data, 0, 2);
3650
                $cnpj = $this->formatField($cnpj, "##.###.###/####-##");
3651
                $saida .= sprintf($formaNfRef, $serie, $numero, $cnpj, $data, $mod);
3652
            }
3653
            $refCTe = $nfRef->getElementsByTagName('refCTe');
3654
            foreach ($refCTe as $chave_acessoRef) {
3655
                $chave_acesso = $chave_acessoRef->nodeValue;
3656
                $chave_acessoF = $this->formatField($chave_acesso, $this->formatoChave);
3657
                $data = substr($chave_acesso, 4, 2)."/20".substr($chave_acesso, 2, 2);
3658
                $cnpj = $this->formatField(substr($chave_acesso, 6, 14), "##.###.###/####-##");
3659
                $serie  = substr($chave_acesso, 22, 3);
3660
                $numero = substr($chave_acesso, 25, 9);
3661
                $saida .= sprintf($formaCTeRef, $serie, $numero, $cnpj, $data, $chave_acessoF);
3662
            }
3663
            $refECF = $nfRef->getElementsByTagName('refECF');
3664
            foreach ($refECF as $umaRefNFe) {
3665
                $mod    = $umaRefNFe->getElementsByTagName('mod')->item(0)->nodeValue;
3666
                $nECF   = $umaRefNFe->getElementsByTagName('nECF')->item(0)->nodeValue;
3667
                $nCOO   = $umaRefNFe->getElementsByTagName('nCOO')->item(0)->nodeValue;
3668
                $saida .= sprintf($formaECFRef, $mod, $nECF, $nCOO);
3669
            }
3670
            $refNFP = $nfRef->getElementsByTagName('refNFP');
3671
            foreach ($refNFP as $umaRefNFe) {
3672
                $data = $umaRefNFe->getElementsByTagName('AAMM')->item(0)->nodeValue;
3673
                $cnpj = ! empty($umaRefNFe->getElementsByTagName('CNPJ')->item(0)->nodeValue) ?
3674
                    $umaRefNFe->getElementsByTagName('CNPJ')->item(0)->nodeValue :
3675
                    '';
3676
                $cpf = ! empty($umaRefNFe->getElementsByTagName('CPF')->item(0)->nodeValue) ?
3677
                        $umaRefNFe->getElementsByTagName('CPF')->item(0)->nodeValue : '';
3678
                $mod = $umaRefNFe->getElementsByTagName('mod')->item(0)->nodeValue;
3679
                $serie = $umaRefNFe->getElementsByTagName('serie')->item(0)->nodeValue;
3680
                $numero = $umaRefNFe->getElementsByTagName('nNF')->item(0)->nodeValue;
3681
                $ie = $umaRefNFe->getElementsByTagName('IE')->item(0)->nodeValue;
3682
                $data = substr($data, 2, 2) . "/20" . substr($data, 0, 2);
3683
                if ($cnpj == '') {
3684
                    $cpf_cnpj = $this->formatField($cpf, "###.###.###-##");
3685
                } else {
3686
                    $cpf_cnpj = $this->formatField($cnpj, "##.###.###/####-##");
3687
                }
3688
                $saida .= sprintf($formaNfpRef, $serie, $numero, $cpf_cnpj, $data, $mod, $ie);
3689
            }
3690
        }
3691
        return $saida;
3692
    }
3693
    
3694
    private function loadDoc($xml)
3695
    {
3696
        $this->xml = $xml;
3697
        if (!empty($xml)) {
3698
            $this->dom = new Dom();
3699
            $this->dom->loadXML($this->xml);
3700
            if (empty($this->dom->getElementsByTagName("infNFe")->item(0))) {
3701
                throw new \Exception('Isso não é um NFe.');
3702
            }
3703
            $this->nfeProc = $this->dom->getElementsByTagName("nfeProc")->item(0);
3704
            $this->infNFe = $this->dom->getElementsByTagName("infNFe")->item(0);
3705
            $this->ide = $this->dom->getElementsByTagName("ide")->item(0);
3706
            if ($this->getTagValue($this->ide, "mod") != '55') {
3707
                throw new \Exception("O xml deve ser NF-e modelo 55.");
3708
            }
3709
            $this->entrega = $this->dom->getElementsByTagName("entrega")->item(0);
3710
            $this->retirada = $this->dom->getElementsByTagName("retirada")->item(0);
3711
            $this->emit = $this->dom->getElementsByTagName("emit")->item(0);
3712
            $this->dest = $this->dom->getElementsByTagName("dest")->item(0);
3713
            $this->enderEmit = $this->dom->getElementsByTagName("enderEmit")->item(0);
3714
            $this->enderDest = $this->dom->getElementsByTagName("enderDest")->item(0);
3715
            $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<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...
3716
            $this->cobr = $this->dom->getElementsByTagName("cobr")->item(0);
3717
            $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<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...
3718
            $this->ICMSTot = $this->dom->getElementsByTagName("ICMSTot")->item(0);
3719
            $this->ISSQNtot = $this->dom->getElementsByTagName("ISSQNtot")->item(0);
3720
            $this->transp = $this->dom->getElementsByTagName("transp")->item(0);
3721
            $this->transporta = $this->dom->getElementsByTagName("transporta")->item(0);
3722
            $this->veicTransp = $this->dom->getElementsByTagName("veicTransp")->item(0);
3723
            $this->detPag = $this->dom->getElementsByTagName("detPag");
3724
            $this->reboque = $this->dom->getElementsByTagName("reboque")->item(0);
3725
            $this->infAdic = $this->dom->getElementsByTagName("infAdic")->item(0);
3726
            $this->compra = $this->dom->getElementsByTagName("compra")->item(0);
3727
            $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...
3728
            $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...
3729
            $this->infProt = $this->dom->getElementsByTagName("infProt")->item(0);
3730
        }
3731
    }
3732
    
3733
    private function imagePNGtoJPG($original)
3734
    {
3735
        $image = imagecreatefrompng($original);
3736
        ob_start();
3737
        imagejpeg($image, null, 100);
3738
        imagedestroy($image);
3739
        $stringdata = ob_get_contents(); // read from buffer
3740
        ob_end_clean();
3741
        return 'data://text/plain;base64,'.base64_encode($stringdata);
3742
    }
3743
}
3744