Completed
Push — master ( b72257...856dcc )
by Roberto
03:38 queued 40s
created

Danfe::localEntregaDANFE()   F

Complexity

Conditions 12
Paths 768

Size

Total Lines 140

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 156

Importance

Changes 0
Metric Value
cc 12
nc 768
nop 2
dl 0
loc 140
ccs 0
cts 128
cp 0
crap 156
rs 2.4977
c 0
b 0
f 0

How to fix   Long Method    Complexity   

Long Method

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

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

Commonly applied refactorings include:

1
<?php
2
3
namespace NFePHP\DA\NFe;
4
5
use InvalidArgumentException;
6
use NFePHP\DA\Legacy\Dom;
7
use NFePHP\DA\Legacy\Pdf;
8
use NFePHP\DA\Legacy\Common;
9
10
class Danfe extends Common
11
{
12
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
    protected $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
334
    /**
335
     * monta
336
     * Monta a DANFE conforme as informações fornecidas para a classe durante sua
337
     * construção. Constroi DANFEs com até 3 páginas podendo conter até 56 itens.
338
     * A definição de margens e posições iniciais para a impressão são estabelecidas
339
     * pelo conteúdo da funçao e podem ser modificados.
340
     *
341
     * @param  string $orientacao (Opcional) Estabelece a orientação da impressão
342
     *  (ex. P-retrato), se nada for fornecido será usado o padrão da NFe
343
     * @param  string $papel      (Opcional) Estabelece o tamanho do papel (ex. A4)
344
     * @return string O ID da NFe numero de 44 digitos extraido do arquivo XML
345
     */
346
    public function monta(
347
        $logo = '',
348
        $orientacao = '',
349
        $papel = 'A4',
350
        $logoAlign = 'C',
351
        $depecNumReg = '',
352
        $margSup = 2,
353
        $margEsq = 2,
354
        $margInf = 2
355
    ) {
356
        $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...
357
        $this->logomarca = $logo;
358
        //se a orientação estiver em branco utilizar o padrão estabelecido na NF
359
        if ($orientacao == '') {
360
            if ($this->tpImp == '2') {
361
                $orientacao = 'L';
362
            } else {
363
                $orientacao = 'P';
364
            }
365
        }
366
        $this->orientacao = $orientacao;
367
        $this->papel = $papel;
368
        $this->logoAlign = $logoAlign;
369
        $this->numero_registro_dpec = $depecNumReg;
370
        //instancia a classe pdf
371
        $this->pdf = new Pdf($this->orientacao, 'mm', $this->papel);
372
        //margens do PDF, em milímetros. Obs.: a margem direita é sempre igual à
373
        //margem esquerda. A margem inferior *não* existe na FPDF, é definida aqui
374
        //apenas para controle se necessário ser maior do que a margem superior
375
        // posição inicial do conteúdo, a partir do canto superior esquerdo da página
376
        $xInic = $margEsq;
377
        if ($this->orientacao == 'P') {
378
            if ($papel == 'A4') {
379
                $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...
380
                $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...
381
            }
382
        } else {
383
            if ($papel == 'A4') {
384
                $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...
385
                $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...
386
                $xInic = $margEsq+10;
387
                //se paisagem multiplica a largura do canhoto pela quantidade de canhotos
388
                //$this->wCanhoto *= $this->qCanhoto;
389
            }
390
        }
391
        //total inicial de paginas
392
        $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...
393
        //largura imprimivel em mm: largura da folha menos as margens esq/direita
394
        $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...
395
        //comprimento (altura) imprimivel em mm: altura da folha menos as margens
396
        //superior e inferior
397
        $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...
398
        // estabelece contagem de paginas
399
        $this->pdf->aliasNbPages();
400
        // fixa as margens
401
        $this->pdf->setMargins($margEsq, $margSup);
402
        $this->pdf->setDrawColor(0, 0, 0);
403
        $this->pdf->setFillColor(255, 255, 255);
404
        // inicia o documento
405
        $this->pdf->open();
406
        // adiciona a primeira página
407
        $this->pdf->addPage($this->orientacao, $this->papel);
408
        $this->pdf->setLineWidth(0.1);
409
        $this->pdf->settextcolor(0, 0, 0);
410
411
        //##################################################################
412
        // CALCULO DO NUMERO DE PAGINAS A SEREM IMPRESSAS
413
        //##################################################################
414
        //Verificando quantas linhas serão usadas para impressão das duplicatas
415
        $linhasDup = 0;
416
        $qtdPag = 0;
417
        if (isset($this->dup) && $this->dup->length > 0) {
418
            $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...
419
        } 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...
420
            $qtdPag = $this->detPag->length;
421
        }
422
        if (($qtdPag > 0) && ($qtdPag <= 7)) {
423
            $linhasDup = 1;
424
        } elseif (($qtdPag > 7) && ($qtdPag <= 14)) {
425
            $linhasDup = 2;
426
        } elseif (($qtdPag > 14) && ($qtdPag <= 21)) {
427
            $linhasDup = 3;
428
        } elseif ($qtdPag > 21) {
429
            // chinnonsantos 11/05/2016: Limite máximo de impressão de duplicatas na NFe,
430
            // só vai ser exibito as 21 primeiras duplicatas (parcelas de pagamento),
431
            // se não oculpa espaço d+, cada linha comporta até 7 duplicatas.
432
            $linhasDup = 3;
433
        }
434
        //verifica se será impressa a linha dos serviços ISSQN
435
        $linhaISSQN = 0;
436
        if ((isset($this->ISSQNtot)) && ($this->getTagValue($this->ISSQNtot, 'vServ') > 0)) {
437
            $linhaISSQN = 1;
438
        }
439
        //calcular a altura necessária para os dados adicionais
440
        if ($this->orientacao == 'P') {
441
            $this->wAdic = round($this->wPrint*0.66, 0);
442
        } else {
443
            $this->wAdic = round(($this->wPrint-$this->wCanhoto)*0.5, 0);
444
        }
445
        $fontProduto = ['font'=>$this->fontePadrao, 'size'=>7, 'style'=>''];
446
        $this->textoAdic = '';
447
        if (isset($this->retirada)) {
448
            $txRetCNPJ = $this->getTagValue($this->retirada, "CNPJ");
449
            $txRetxLgr = $this->getTagValue($this->retirada, "xLgr");
450
            $txRetnro = $this->getTagValue($this->retirada, "nro");
451
            $txRetxCpl = $this->getTagValue($this->retirada, "xCpl", " - ");
452
            $txRetxBairro = $this->getTagValue($this->retirada, "xBairro");
453
            $txRetxMun = $this->getTagValue($this->retirada, "xMun");
454
            $txRetUF = $this->getTagValue($this->retirada, "UF");
455
            $this->textoAdic .= "LOCAL DE RETIRADA : ".
456
                    $txRetCNPJ.
457
                    '-' .
458
                    $txRetxLgr .
459
                    ', ' .
460
                    $txRetnro .
461
                    ' ' .
462
                    $txRetxCpl .
463
                    ' - ' .
464
                    $txRetxBairro .
465
                    ' ' .
466
                    $txRetxMun .
467
                    ' - ' .
468
                    $txRetUF .
469
                    "\r\n";
470
        }
471
        //dados do local de entrega da mercadoria
472
        if (isset($this->entrega)) {
473
            $txRetCNPJ = $this->getTagValue($this->entrega, "CNPJ");
474
            $txRetxLgr = $this->getTagValue($this->entrega, "xLgr");
475
            $txRetnro = $this->getTagValue($this->entrega, "nro");
476
            $txRetxCpl = $this->getTagValue($this->entrega, "xCpl", " - ");
477
            $txRetxBairro = $this->getTagValue($this->entrega, "xBairro");
478
            $txRetxMun = $this->getTagValue($this->entrega, "xMun");
479
            $txRetUF = $this->getTagValue($this->entrega, "UF");
480
            if ($this->textoAdic != '') {
481
                $this->textoAdic .= ". \r\n";
482
            }
483
            $this->textoAdic .= "LOCAL DE ENTREGA : ".$txRetCNPJ.'-'.$txRetxLgr.', '.$txRetnro.' '.$txRetxCpl.
484
               ' - '.$txRetxBairro.' '.$txRetxMun.' - '.$txRetUF."\r\n";
485
        }
486
        //informações adicionais
487
        $this->textoAdic .= $this->geraInformacoesDasNotasReferenciadas();
488
        if (isset($this->infAdic)) {
489
            $i = 0;
490
            if ($this->textoAdic != '') {
491
                $this->textoAdic .= ". \r\n";
492
            }
493
            $this->textoAdic .= ! empty($this->getTagValue($this->infAdic, "infCpl"))
494
            ? 'Inf. Contribuinte: ' . $this->anfaveaDANFE($this->getTagValue($this->infAdic, "infCpl"))
495
            : '';
496
            $infPedido = $this->geraInformacoesDaTagCompra();
497
            if ($infPedido != "") {
498
                $this->textoAdic .= $infPedido;
499
            }
500
            $this->textoAdic .= $this->getTagValue($this->dest, "email", ' Email do Destinatário: ');
501
            $this->textoAdic .= ! empty($this->getTagValue($this->infAdic, "infAdFisco"))
502
            ? "\r\n Inf. fisco: " . $this->getTagValue($this->infAdic, "infAdFisco")
503
            : '';
504
            $obsCont = $this->infAdic->getElementsByTagName("obsCont");
505
            if (isset($obsCont)) {
506
                foreach ($obsCont as $obs) {
507
                    $campo =  $obsCont->item($i)->getAttribute("xCampo");
508
                    $xTexto = ! empty($obsCont->item($i)->getElementsByTagName("xTexto")->item(0)->nodeValue)
509
                    ? $obsCont->item($i)->getElementsByTagName("xTexto")->item(0)->nodeValue
510
                    : '';
511
                    $this->textoAdic .= "\r\n" . $campo . ':  ' . trim($xTexto);
512
                    $i++;
513
                }
514
            }
515
        }
516
        //INCLUSO pela NT 2013.003 Lei da Transparência
517
        //verificar se a informação sobre o valor aproximado dos tributos
518
        //já se encontra no campo de informações adicionais
519
        if ($this->exibirValorTributos) {
520
            $flagVTT = strpos(strtolower(trim($this->textoAdic)), 'valor');
521
            $flagVTT = $flagVTT || strpos(strtolower(trim($this->textoAdic)), 'vl');
522
            $flagVTT = $flagVTT && strpos(strtolower(trim($this->textoAdic)), 'aprox');
523
            $flagVTT = $flagVTT && (strpos(strtolower(trim($this->textoAdic)), 'trib') ||
524
                    strpos(strtolower(trim($this->textoAdic)), 'imp'));
525
            $vTotTrib = $this->getTagValue($this->ICMSTot, 'vTotTrib');
526
            if ($vTotTrib != '' && !$flagVTT) {
527
                $this->textoAdic .= "\n Valor Aproximado dos Tributos : R$ "
528
                    . number_format($vTotTrib, 2, ",", ".");
529
            }
530
        }
531
        //fim da alteração NT 2013.003 Lei da Transparência
532
        $this->textoAdic = str_replace(";", "\n", $this->textoAdic);
533
        $alinhas = explode("\n", $this->textoAdic);
534
        $numlinhasdados = 0;
535
        foreach ($alinhas as $linha) {
536
            $numlinhasdados += $this->pdf->getNumLines($linha, $this->wAdic, $fontProduto);
537
        }
538
        $hdadosadic = round(($numlinhasdados+3) * $this->pdf->fontSize, 0);
539
        if ($hdadosadic < 10) {
540
            $hdadosadic = 10;
541
        }
542
        //altura disponivel para os campos da DANFE
543
        $hcabecalho = 47;//para cabeçalho
544
        $hdestinatario = 25;//para destinatario
545
        $hduplicatas = 12;//para cada grupo de 7 duplicatas
546
        if (isset($this->entrega)) {
547
            $hlocalentrega = 25;
548
        } else {
549
            $hlocalentrega = 0;
550
        }
551
        if (isset($this->retirada)) {
552
            $hlocalretirada = 25;
553
        } else {
554
            $hlocalretirada = 0;
555
        }
556
        $himposto = 18;// para imposto
557
        $htransporte = 25;// para transporte
558
        $hissqn = 11;// para issqn
559
        $hfooter = 5;// para rodape
560
        $hCabecItens = 4;//cabeçalho dos itens
561
        //alturas disponiveis para os dados
562
        $hDispo1 = $this->hPrint - 10 - ($hcabecalho +
563
            //$hdestinatario + ($linhasDup * $hduplicatas) + $himposto + $htransporte +
564
            $hdestinatario + $hlocalentrega + $hlocalretirada +
565
            ($linhasDup * $hduplicatas) + $himposto + $htransporte +
566
            ($linhaISSQN * $hissqn) + $hdadosadic + $hfooter + $hCabecItens +
567
            $this->sizeExtraTextoFatura());
568
        if ($this->orientacao == 'P') {
569
            $hDispo1 -= 24 * $this->qCanhoto;//para canhoto
570
            $w = $this->wPrint;
571
        } else {
572
            $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...
573
            $w = $this->wPrint - $this->wCanhoto;
574
        }
575
        $hDispo2 = $this->hPrint - 10 - ($hcabecalho + $hfooter + $hCabecItens)-4;
576
        //Contagem da altura ocupada para impressão dos itens
577
        $fontProduto = ['font'=>$this->fontePadrao, 'size'=>7, 'style'=>''];
578
        $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...
579
        $hUsado = $hCabecItens;
580
        $w2 = round($w*0.28, 0);
581
        $hDispo = $hDispo1;
582
        $totPag = 1;
583
        $i = 0;
584
        while ($i < $this->det->length) {
585
            $texto = $this->descricaoProduto($this->det->item($i));
586
            $numlinhas = $this->pdf->getNumLines($texto, $w2, $fontProduto);
587
            $hUsado += round(($numlinhas * $this->pdf->fontSize) + ($numlinhas * 0.5), 2);
588
            if ($hUsado > $hDispo) {
589
                $totPag++;
590
                $hDispo = $hDispo2;
591
                $hUsado = $hCabecItens;
592
                // Remove canhoto para páginas secundárias em modo paisagem ('L')
593
                $w2 = round($this->wPrint*0.28, 0);
594
                $i--; // decrementa para readicionar o item que não coube nessa pagina na outra.
595
            }
596
            $i++;
597
        } //fim da soma das areas de itens usadas
598
        $qtdeItens = $i; //controle da quantidade de itens no DANFE
599
        //montagem da primeira página
600
        $pag = 1;
601
        
602
        $x = $margEsq;
603
        $y = $margSup;
604
        //coloca o(s) canhoto(s) da NFe
605
        if ($this->orientacao == 'P') {
606
            $y = $this->canhoto($margEsq, $margSup);
607
        } else {
608
            $this->canhoto($margEsq, $margSup);
609
            $x = 25;
610
        }
611
        //$x = $xInic;
612
        //$y = $yInic;
613
        
614
        //coloca o cabeçalho
615
        $y = $this->header($x, $y, $pag, $totPag);
616
        //coloca os dados do destinatário
617
        $y = $this->destinatarioDANFE($x, $y+1);
618
        
619
        //coloca os dados do local de retirada
620
        if (isset($this->retirada)) {
621
            $y = $this->localRetiradaDANFE($x, $y+1);
622
        }
623
        //coloca os dados do local de entrega
624
        if (isset($this->entrega)) {
625
            $y = $this->localEntregaDANFE($x, $y+1);
626
        }
627
        
628
        //Verifica as formas de pagamento da nota fiscal
629
        $formaPag = [];
630
        if (isset($this->detPag) && $this->detPag->length > 0) {
631
            foreach ($this->detPag as $k => $d) {
632
                $fPag = !empty($this->detPag->item($k)->getElementsByTagName('tPag')->item(0)->nodeValue)
633
                ? $this->detPag->item($k)->getElementsByTagName('tPag')->item(0)->nodeValue
634
                : '0';
635
                $formaPag[$fPag] = $fPag;
636
            }
637
        }
638
        //caso tenha boleto imprimir fatura
639
        if ($this->dup->length > 0) {
640
            $y = $this->fatura($x, $y+1);
641
        } else {
642
            //Se somente tiver a forma de pagamento sem pagamento ou outros não imprimir nada
643
            if (count($formaPag)=='1' && (isset($formaPag[90]) || isset($formaPag[99]))) {
644
                $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...
645
            } else {
646
                //caso tenha mais de uma forma de pagamento ou seja diferente de boleto exibe a
647
                //forma de pagamento e o valor
648
                $y = $this->pagamento($x, $y+1);
649
            }
650
        }
651
        //coloca os dados dos impostos e totais da NFe
652
        $y = $this->imposto($x, $y+1);
653
        //coloca os dados do trasnporte
654
        $y = $this->transporte($x, $y+1);
655
        //itens da DANFE
656
        $nInicial = 0;
657
658
        $y = $this->itens($x, $y+1, $nInicial, $hDispo1, $pag, $totPag, $hCabecItens);
659
660
        //coloca os dados do ISSQN
661
        if ($linhaISSQN == 1) {
662
            $y = $this->issqn($x, $y+4);
663
        } else {
664
            $y += 4;
665
        }
666
        //coloca os dados adicionais da NFe
667
        $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...
668
        //coloca o rodapé da página
669
        if ($this->orientacao == 'P') {
670
            $this->rodape($xInic);
671
        } else {
672
            $this->rodape($xInic);
673
        }
674
675
        //loop para páginas seguintes
676
        for ($n = 2; $n <= $totPag; $n++) {
677
            // fixa as margens
678
            $this->pdf->setMargins($margEsq, $margSup);
679
            //adiciona nova página
680
            $this->pdf->addPage($this->orientacao, $this->papel);
681
            //ajusta espessura das linhas
682
            $this->pdf->setLineWidth(0.1);
683
            //seta a cor do texto para petro
684
            $this->pdf->settextcolor(0, 0, 0);
685
            // posição inicial do relatorio
686
            $x = $margEsq;
687
            $y = $margSup;
688
            //coloca o cabeçalho na página adicional
689
            $y = $this->header($x, $y, $n, $totPag);
690
            //coloca os itens na página adicional
691
            $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...
692
            //coloca o rodapé da página
693
            if ($this->orientacao == 'P') {
694
                $this->rodape($margEsq);
695
            } else {
696
                $this->rodape($margEsq);
697
            }
698
            //se estiver na última página e ainda restar itens para inserir, adiciona mais uma página
699
            if ($n == $totPag && $this->qtdeItensProc < $qtdeItens) {
700
                $totPag++;
701
            }
702
        }
703
    }
704
705
    /**
706
     * anfavea
707
     * Função para transformar o campo cdata do padrão ANFAVEA para
708
     * texto imprimível
709
     *
710
     * @param  string $cdata campo CDATA
711
     * @return string conteúdo do campo CDATA como string
712
     */
713
    protected function anfaveaDANFE($cdata = '')
714
    {
715
        if ($cdata == '') {
716
            return '';
717
        }
718
        //remove qualquer texto antes ou depois da tag CDATA
719
        $cdata = str_replace('<![CDATA[', '<CDATA>', $cdata);
720
        $cdata = str_replace(']]>', '</CDATA>', $cdata);
721
        $cdata = preg_replace('/\s\s+/', ' ', $cdata);
722
        $cdata = str_replace("> <", "><", $cdata);
723
        $len = strlen($cdata);
724
        $startPos = strpos($cdata, '<');
725
        if ($startPos === false) {
726
            return $cdata;
727
        }
728
        for ($x=$len; $x>0; $x--) {
729
            if (substr($cdata, $x, 1) == '>') {
730
                $endPos = $x;
731
                break;
732
            }
733
        }
734
        if ($startPos > 0) {
735
            $parte1 = substr($cdata, 0, $startPos);
736
        } else {
737
            $parte1 = '';
738
        }
739
        $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...
740
        if ($endPos < $len) {
741
            $parte3 = substr($cdata, $endPos + 1, $len - $endPos - 1);
742
        } else {
743
            $parte3 = '';
744
        }
745
        $texto = trim($parte1).' '.trim($parte3);
746
        if (strpos($parte2, '<CDATA>') === false) {
747
            $cdata = '<CDATA>'.$parte2.'</CDATA>';
748
        } else {
749
            $cdata = $parte2;
750
        }
751
        //Retira a tag <FONTE IBPT> (caso existir) pois não é uma estrutura válida XML
752
        $cdata = str_replace('<FONTE IBPT>', '', $cdata);
753
        //carrega o xml CDATA em um objeto DOM
754
        $dom = new Dom();
755
        $dom->loadXML($cdata, LIBXML_NOBLANKS | LIBXML_NOEMPTYTAG);
756
        //$xml = $dom->saveXML();
757
        //grupo CDATA infADprod
758
        $id = $dom->getElementsByTagName('id')->item(0);
759
        $div = $dom->getElementsByTagName('div')->item(0);
760
        $entg = $dom->getElementsByTagName('entg')->item(0);
761
        $dest = $dom->getElementsByTagName('dest')->item(0);
762
        $ctl = $dom->getElementsByTagName('ctl')->item(0);
763
        $ref = $dom->getElementsByTagName('ref')->item(0);
764
        if (isset($id)) {
765
            if ($id->hasAttributes()) {
766
                foreach ($id->attributes as $attr) {
767
                    $name = $attr->nodeName;
768
                    $value = $attr->nodeValue;
769
                    $texto .= " $name : $value";
770
                }
771
            }
772
        }
773
        if (isset($div)) {
774
            if ($div->hasAttributes()) {
775
                foreach ($div->attributes as $attr) {
776
                    $name = $attr->nodeName;
777
                    $value = $attr->nodeValue;
778
                    $texto .= " $name : $value";
779
                }
780
            }
781
        }
782
        if (isset($entg)) {
783
            if ($entg->hasAttributes()) {
784
                foreach ($entg->attributes as $attr) {
785
                    $name = $attr->nodeName;
786
                    $value = $attr->nodeValue;
787
                    $texto .= " $name : $value";
788
                }
789
            }
790
        }
791
        if (isset($dest)) {
792
            if ($dest->hasAttributes()) {
793
                foreach ($dest->attributes as $attr) {
794
                    $name = $attr->nodeName;
795
                    $value = $attr->nodeValue;
796
                    $texto .= " $name : $value";
797
                }
798
            }
799
        }
800
        if (isset($ctl)) {
801
            if ($ctl->hasAttributes()) {
802
                foreach ($ctl->attributes as $attr) {
803
                    $name = $attr->nodeName;
804
                    $value = $attr->nodeValue;
805
                    $texto .= " $name : $value";
806
                }
807
            }
808
        }
809
        if (isset($ref)) {
810
            if ($ref->hasAttributes()) {
811
                foreach ($ref->attributes as $attr) {
812
                    $name = $attr->nodeName;
813
                    $value = $attr->nodeValue;
814
                    $texto .= " $name : $value";
815
                }
816
            }
817
        }
818
        //grupo CADATA infCpl
819
        $t = $dom->getElementsByTagName('transmissor')->item(0);
820
        $r = $dom->getElementsByTagName('receptor')->item(0);
821
        $versao = ! empty($dom->getElementsByTagName('versao')->item(0)->nodeValue) ?
822
            'Versao:'.$dom->getElementsByTagName('versao')->item(0)->nodeValue.' ' : '';
823
        $especieNF = ! empty($dom->getElementsByTagName('especieNF')->item(0)->nodeValue) ?
824
            'Especie:'.$dom->getElementsByTagName('especieNF')->item(0)->nodeValue.' ' : '';
825
        $fabEntrega = ! empty($dom->getElementsByTagName('fabEntrega')->item(0)->nodeValue) ?
826
            'Entrega:'.$dom->getElementsByTagName('fabEntrega')->item(0)->nodeValue.' ' : '';
827
        $dca = ! empty($dom->getElementsByTagName('dca')->item(0)->nodeValue) ?
828
            'dca:'.$dom->getElementsByTagName('dca')->item(0)->nodeValue.' ' : '';
829
        $texto .= "".$versao.$especieNF.$fabEntrega.$dca;
830
        if (isset($t)) {
831
            if ($t->hasAttributes()) {
832
                $texto .= " Transmissor ";
833
                foreach ($t->attributes as $attr) {
834
                    $name = $attr->nodeName;
835
                    $value = $attr->nodeValue;
836
                    $texto .= " $name : $value";
837
                }
838
            }
839
        }
840
        if (isset($r)) {
841
            if ($r->hasAttributes()) {
842
                $texto .= " Receptor ";
843
                foreach ($r->attributes as $attr) {
844
                    $name = $attr->nodeName;
845
                    $value = $attr->nodeValue;
846
                    $texto .= " $name : $value";
847
                }
848
            }
849
        }
850
        return $texto;
851
    }
852
853
    /**
854
     * Verifica o status da NFe
855
     *
856
     * @return array
857
     */
858
    protected function statusNFe()
859
    {
860
        if (!isset($this->nfeProc)) {
861
            return ['status' => false, 'message' => 'NFe NÃO PROTOCOLADA'];
862
        }
863
        if ($this->getTagValue($this->ide, "tpAmb") == '2') {
864
            return ['status' => false, 'message' => 'NFe EMITIDA EM HOMOLOGAÇÃO'];
865
        }
866
        $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...
867
        if ($cStat == '101'
868
            || $cStat == '151'
869
            || $cStat == '135'
870
            || $cStat == '155'
871
        ) {
872
            return ['status' => false, 'message' => 'NFe CANCELADA'];
873
        }
874
        
875
        if ($cStat == '110' ||
876
               $cStat == '301' ||
877
               $cStat == '302'
878
               
879
        ) {
880
            return ['status' => false, 'message' => 'NFe DENEGADA'];
881
        }
882
        return ['status' => true, 'message' => ''];
883
    }
884
885
    protected function notaDPEC()
886
    {
887
        return $this->numero_registro_dpec != '';
888
    }
889
890
    /**
891
     *header
892
     * Monta o cabelhalho da DANFE (retrato e paisagem)
893
     *
894
     * @param  number $x      Posição horizontal inicial, canto esquerdo
895
     * @param  number $y      Posição vertical inicial, canto superior
896
     * @param  number $pag    Número da Página
897
     * @param  number $totPag Total de páginas
898
     * @return number Posição vertical final
899
     */
900
    protected function header($x = 0, $y = 0, $pag = '1', $totPag = '1')
901
    {
902
        $oldX = $x;
903
        $oldY = $y;
904
        if ($this->orientacao == 'P') {
905
              $maxW = $this->wPrint;
906
        } else {
907
            if ($pag == 1) { // primeira página
908
                $maxW = $this->wPrint - $this->wCanhoto;
909
            } else { // páginas seguintes
910
                $maxW = $this->wPrint;
911
            }
912
        }
913
        //####################################################################################
914
        //coluna esquerda identificação do emitente
915
        $w = round($maxW*0.41, 0);
916
        if ($this->orientacao == 'P') {
917
            $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>'I'];
918
        } else {
919
            $aFont = ['font'=>$this->fontePadrao, 'size'=>8, 'style'=>'B'];
920
        }
921
        $w1 = $w;
922
        $h=32;
923
        $oldY += $h;
924
        $this->pdf->textBox($x, $y, $w, $h);
925
        $texto = 'IDENTIFICAÇÃO DO EMITENTE';
926
        $this->pdf->textBox($x, $y, $w, 5, $texto, $aFont, 'T', 'C', 0, '');
927
        //estabelecer o alinhamento
928
        //pode ser left L, center C, right R, full logo L
929
        //se for left separar 1/3 da largura para o tamanho da imagem
930
        //os outros 2/3 serão usados para os dados do emitente
931
        //se for center separar 1/2 da altura para o logo e 1/2 para os dados
932
        //se for right separa 2/3 para os dados e o terço seguinte para o logo
933
        //se não houver logo centraliza dos dados do emitente
934
        // coloca o logo
935
        if (!empty($this->logomarca)) {
936
            $logoInfo = getimagesize($this->logomarca);
937
            $type = strtolower(explode('/', $logoInfo['mime'])[1]);
938
            if ($type == 'png') {
939
                $this->logomarca = $this->imagePNGtoJPG($this->logomarca);
940
                $type == 'jpg';
941
            }
942
            //largura da imagem em mm
943
            $logoWmm = ($logoInfo[0]/72)*25.4;
944
            //altura da imagem em mm
945
            $logoHmm = ($logoInfo[1]/72)*25.4;
946
            if ($this->logoAlign=='L') {
947
                $nImgW = round($w/3, 0);
948
                $nImgH = round($logoHmm * ($nImgW/$logoWmm), 0);
949
                $xImg = $x+1;
950
                $yImg = round(($h-$nImgH)/2, 0)+$y;
951
                //estabelecer posições do texto
952
                $x1 = round($xImg + $nImgW +1, 0);
953
                $y1 = round($h/3+$y, 0);
954
                $tw = round(2*$w/3, 0);
955
            } elseif ($this->logoAlign=='C') {
956
                $nImgH = round($h/3, 0);
957
                $nImgW = round($logoWmm * ($nImgH/$logoHmm), 0);
958
                $xImg = round(($w-$nImgW)/2+$x, 0);
959
                $yImg = $y+3;
960
                $x1 = $x;
961
                $y1 = round($yImg + $nImgH + 1, 0);
962
                $tw = $w;
963
            } elseif ($this->logoAlign=='R') {
964
                $nImgW = round($w/3, 0);
965
                $nImgH = round($logoHmm * ($nImgW/$logoWmm), 0);
966
                $xImg = round($x+($w-(1+$nImgW)), 0);
967
                $yImg = round(($h-$nImgH)/2, 0)+$y;
968
                $x1 = $x;
969
                $y1 = round($h/3+$y, 0);
970
                $tw = round(2*$w/3, 0);
971
            } elseif ($this->logoAlign=='F') {
972
                $nImgH = round($h-5, 0);
973
                $nImgW = round($logoWmm * ($nImgH/$logoHmm), 0);
974
                $xImg = round(($w-$nImgW)/2+$x, 0);
975
                $yImg = $y+3;
976
                $x1 = $x;
977
                $y1 = round($yImg + $nImgH + 1, 0);
978
                $tw = $w;
979
            }
980
            $type = (substr($this->logomarca, 0, 7) === 'data://') ? 'jpg' : null;
981
            $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...
982
        } else {
983
            $x1 = $x;
984
            $y1 = round($h/3+$y, 0);
985
            $tw = $w;
986
        }
987
        // monta as informações apenas se diferente de full logo
988
        if ($this->logoAlign !== 'F') {
989
            //Nome emitente
990
            $aFont = ['font'=>$this->fontePadrao, 'size'=>12, 'style'=>'B'];
991
            $texto = $this->emit->getElementsByTagName("xNome")->item(0)->nodeValue;
992
            $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...
993
            //endereço
994
            $y1 = $y1+5;
995
            $aFont = ['font'=>$this->fontePadrao, 'size'=>8, 'style'=>''];
996
            $fone = ! empty($this->enderEmit->getElementsByTagName("fone")->item(0)->nodeValue)
997
            ? $this->enderEmit->getElementsByTagName("fone")->item(0)->nodeValue
998
            : '';
999
            $lgr = $this->getTagValue($this->enderEmit, "xLgr");
1000
            $nro = $this->getTagValue($this->enderEmit, "nro");
1001
            $cpl = $this->getTagValue($this->enderEmit, "xCpl", " - ");
1002
            $bairro = $this->getTagValue($this->enderEmit, "xBairro");
1003
            $CEP = $this->getTagValue($this->enderEmit, "CEP");
1004
            $CEP = $this->formatField($CEP, "#####-###");
1005
            $mun = $this->getTagValue($this->enderEmit, "xMun");
1006
            $UF = $this->getTagValue($this->enderEmit, "UF");
1007
            $texto = $lgr . ", " . $nro . $cpl . "\n" . $bairro . " - "
1008
                . $CEP . "\n" . $mun . " - " . $UF . " "
1009
                . "Fone/Fax: " . $fone;
1010
            $this->pdf->textBox($x1, $y1, $tw, 8, $texto, $aFont, 'T', 'C', 0, '');
1011
        }
1012
1013
        //####################################################################################
1014
        //coluna central Danfe
1015
        $x += $w;
1016
        $w=round($maxW * 0.17, 0);//35;
1017
        $w2 = $w;
1018
        $h = 32;
1019
        $this->pdf->textBox($x, $y, $w, $h);
1020
  
1021
        $texto = "DANFE";
1022
        $aFont = ['font'=>$this->fontePadrao, 'size'=>14, 'style'=>'B'];
1023
        $this->pdf->textBox($x, $y+1, $w, $h, $texto, $aFont, 'T', 'C', 0, '');
1024
        $aFont = ['font'=>$this->fontePadrao, 'size'=>8, 'style'=>''];
1025
        $texto = 'Documento Auxiliar da Nota Fiscal Eletrônica';
1026
        $h = 20;
1027
        $this->pdf->textBox($x, $y+6, $w, $h, $texto, $aFont, 'T', 'C', 0, '', false);
1028
1029
        $aFont = ['font'=>$this->fontePadrao, 'size'=>8, 'style'=>''];
1030
        $texto = '0 - ENTRADA';
1031
        $y1 = $y + 14;
1032
        $h = 8;
1033
        $this->pdf->textBox($x+2, $y1, $w, $h, $texto, $aFont, 'T', 'L', 0, '');
1034
        $texto = '1 - SAÍDA';
1035
        $y1 = $y + 17;
1036
        $this->pdf->textBox($x+2, $y1, $w, $h, $texto, $aFont, 'T', 'L', 0, '');
1037
        //tipo de nF
1038
        $aFont = ['font'=>$this->fontePadrao, 'size'=>12, 'style'=>'B'];
1039
        $y1 = $y + 13;
1040
        $h = 7;
1041
        $texto = $this->ide->getElementsByTagName('tpNF')->item(0)->nodeValue;
1042
        $this->pdf->textBox($x+27, $y1, 5, $h, $texto, $aFont, 'C', 'C', 1, '');
1043
        //numero da NF
1044
        $aFont = ['font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B'];
1045
        $y1 = $y + 20;
1046
        $numNF = str_pad(
1047
            $this->ide->getElementsByTagName('nNF')->item(0)->nodeValue,
1048
            9,
1049
            "0",
1050
            STR_PAD_LEFT
1051
        );
1052
        $numNF = $this->formatField($numNF, "###.###.###");
1053
        $texto = "Nº. " . $numNF;
1054
        $this->pdf->textBox($x, $y1, $w, $h, $texto, $aFont, 'C', 'C', 0, '');
1055
        //Série
1056
        $y1 = $y + 23;
1057
        $serie = str_pad(
1058
            $this->ide->getElementsByTagName('serie')->item(0)->nodeValue,
1059
            3,
1060
            "0",
1061
            STR_PAD_LEFT
1062
        );
1063
        $texto = "Série " . $serie;
1064
        $this->pdf->textBox($x, $y1, $w, $h, $texto, $aFont, 'C', 'C', 0, '');
1065
        //numero paginas
1066
        $aFont = ['font'=>$this->fontePadrao, 'size'=>8, 'style'=>'I'];
1067
        $y1 = $y + 26;
1068
        $texto = "Folha " . $pag . "/" . $totPag;
1069
        $this->pdf->textBox($x, $y1, $w, $h, $texto, $aFont, 'C', 'C', 0, '');
1070
1071
        //####################################################################################
1072
        //coluna codigo de barras
1073
        $x += $w;
1074
        $w = ($maxW-$w1-$w2);//85;
1075
        $w3 = $w;
1076
        $h = 32;
1077
        $this->pdf->textBox($x, $y, $w, $h);
1078
        $this->pdf->setFillColor(0, 0, 0);
1079
        $chave_acesso = str_replace('NFe', '', $this->infNFe->getAttribute("Id"));
1080
        $bW = 75;
1081
        $bH = 12;
1082
        //codigo de barras
1083
        $this->pdf->code128($x+(($w-$bW)/2), $y+2, $chave_acesso, $bW, $bH);
1084
        //linhas divisorias
1085
        $this->pdf->line($x, $y+4+$bH, $x+$w, $y+4+$bH);
1086
        $this->pdf->line($x, $y+12+$bH, $x+$w, $y+12+$bH);
1087
        $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
1088
        $y1 = $y+4+$bH;
1089
        $h = 7;
1090
        $texto = 'CHAVE DE ACESSO';
1091
        $this->pdf->textBox($x, $y1, $w, $h, $texto, $aFont, 'T', 'L', 0, '');
1092
        $aFont = ['font'=>$this->fontePadrao, 'size'=>8, 'style'=>'B'];
1093
        $y1 = $y+8+$bH;
1094
        $texto = $this->formatField($chave_acesso, $this->formatoChave);
1095
        $this->pdf->textBox($x+2, $y1, $w-2, $h, $texto, $aFont, 'T', 'C', 0, '');
1096
        $y1 = $y+12+$bH;
1097
        $aFont = ['font'=>$this->fontePadrao, 'size'=>8, 'style'=>''];
1098
        $chaveContingencia="";
1099
        if ($this->notaDpec()) {
1100
            $cabecalhoProtoAutorizacao = 'NÚMERO DE REGISTRO DPEC';
1101
        } else {
1102
            $cabecalhoProtoAutorizacao = 'PROTOCOLO DE AUTORIZAÇÃO DE USO';
1103
        }
1104
        if (($this->tpEmis == 2 || $this->tpEmis == 5) && !$this->notaDpec()) {
1105
            $cabecalhoProtoAutorizacao = "DADOS DA NF-E";
1106
            $chaveContingencia = $this->geraChaveAdicionalDeContingencia();
1107
            $this->pdf->setFillColor(0, 0, 0);
1108
            //codigo de barras
1109
            $this->pdf->code128($x+11, $y1+1, $chaveContingencia, $bW*.9, $bH/2);
1110
        } else {
1111
            $texto = 'Consulta de autenticidade no portal nacional da NF-e';
1112
            $this->pdf->textBox($x+2, $y1, $w-2, $h, $texto, $aFont, 'T', 'C', 0, '');
1113
            $y1 = $y+16+$bH;
1114
            $texto = 'www.nfe.fazenda.gov.br/portal ou no site da Sefaz Autorizadora';
1115
            $this->pdf->textBox(
1116
                $x+2,
1117
                $y1,
1118
                $w-2,
1119
                $h,
1120
                $texto,
1121
                $aFont,
1122
                'T',
1123
                'C',
1124
                0,
1125
                'http://www.nfe.fazenda.gov.br/portal ou no site da Sefaz Autorizadora'
1126
            );
1127
        }
1128
1129
        //####################################################################################
1130
        //Dados da NF do cabeçalho
1131
        //natureza da operação
1132
        $texto = 'NATUREZA DA OPERAÇÃO';
1133
        $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
1134
        $w = $w1+$w2;
1135
        $y = $oldY;
1136
        $oldY += $h;
1137
        $x = $oldX;
1138
        $h = 7;
1139
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 1, '');
1140
        $texto = $this->ide->getElementsByTagName("natOp")->item(0)->nodeValue;
1141
        $aFont = ['font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B'];
1142
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'B', 'C', 0, '');
1143
        $x += $w;
1144
        $w = $w3;
1145
        //PROTOCOLO DE AUTORIZAÇÃO DE USO ou DADOS da NF-E
1146
        $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
1147
        $this->pdf->textBox($x, $y, $w, $h, $cabecalhoProtoAutorizacao, $aFont, 'T', 'L', 1, '');
1148
        // algumas NFe podem estar sem o protocolo de uso portanto sua existencia deve ser
1149
        // testada antes de tentar obter a informação.
1150
        // NOTA : DANFE sem protocolo deve existir somente no caso de contingência !!!
1151
        // Além disso, existem várias NFes em contingência que eu recebo com protocolo de autorização.
1152
        // Na minha opinião, deveríamos mostra-lo, mas o  manual  da NFe v4.01 diz outra coisa...
1153
        if (($this->tpEmis == 2 || $this->tpEmis == 5) && !$this->notaDpec()) {
1154
            $aFont = ['font'=>$this->fontePadrao, 'size'=>8, 'style'=>'B'];
1155
            $texto = $this->formatField(
1156
                $chaveContingencia,
1157
                "#### #### #### #### #### #### #### #### ####"
1158
            );
1159
            $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...
1160
        } else {
1161
            $aFont = ['font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B'];
1162
            if ($this->notaDpec()) {
1163
                $texto = $this->numero_registro_dpec;
1164
                $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...
1165
            } else {
1166
                if (isset($this->nfeProc)) {
1167
                    $texto = ! empty($this->nfeProc->getElementsByTagName("nProt")->item(0)->nodeValue)
1168
                    ? $this->nfeProc->getElementsByTagName("nProt")->item(0)->nodeValue
1169
                    : '';
1170
                    $tsHora = $this->toTimestamp(
1171
                        $this->nfeProc->getElementsByTagName("dhRecbto")->item(0)->nodeValue
1172
                    );
1173
                    if ($texto != '') {
1174
                        $texto .= "  -  " . date('d/m/Y H:i:s', $tsHora);
1175
                    }
1176
                    $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...
1177
                } else {
1178
                    $texto = '';
1179
                    $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...
1180
                }
1181
            }
1182
        }
1183
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'B', 'C', 0, '');
1184
        //####################################################################################
1185
        //INSCRIÇÃO ESTADUAL
1186
        $w = round($maxW * 0.333, 0);
1187
        $y += $h;
1188
        $oldY += $h;
1189
        $x = $oldX;
1190
        $texto = 'INSCRIÇÃO ESTADUAL';
1191
        $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
1192
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 1, '');
1193
        $texto = $this->getTagValue($this->emit, "IE");
1194
        $aFont = ['font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B'];
1195
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'B', 'C', 0, '');
1196
        //INSCRIÇÃO ESTADUAL DO SUBST. TRIBUT.
1197
        $x += $w;
1198
        $texto = 'INSCRIÇÃO ESTADUAL DO SUBST. TRIBUT.';
1199
        $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
1200
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 1, '');
1201
        $texto = ! empty($this->emit->getElementsByTagName("IEST")->item(0)->nodeValue)
1202
        ? $this->emit->getElementsByTagName("IEST")->item(0)->nodeValue
1203
        : '';
1204
        $aFont = ['font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B'];
1205
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'B', 'C', 0, '');
1206
        //CNPJ
1207
        $x += $w;
1208
        $w = ($maxW-(2*$w));
1209
        $texto = 'CNPJ / CPF';
1210
        $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
1211
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 1, '');
1212
        //Pegando valor do CPF/CNPJ
1213
        if (! empty($this->emit->getElementsByTagName("CNPJ")->item(0)->nodeValue)) {
1214
            $texto = $this->formatField(
1215
                $this->emit->getElementsByTagName("CNPJ")->item(0)->nodeValue,
1216
                "###.###.###/####-##"
1217
            );
1218
        } else {
1219
            $texto = ! empty($this->emit->getElementsByTagName("CPF")->item(0)->nodeValue)
1220
            ? $this->formatField(
1221
                $this->emit->getElementsByTagName("CPF")->item(0)->nodeValue,
1222
                "###.###.###-##"
1223
            )
1224
            : '';
1225
        }
1226
        $aFont = ['font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B'];
1227
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'B', 'C', 0, '');
1228
1229
        //####################################################################################
1230
        //Indicação de NF Homologação, cancelamento e falta de protocolo
1231
        $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...
1232
        //indicar cancelamento
1233
        $resp = $this->statusNFe();
1234
        if (!$resp['status']) {
1235
            $x = 10;
1236
            $y = $this->hPrint-130;
1237
            $h = 25;
1238
            $w = $maxW-(2*$x);
1239
            $this->pdf->settextcolor(90, 90, 90);
1240
            $texto = $resp['message'];
1241
            $aFont = ['font'=>$this->fontePadrao, 'size'=>48, 'style'=>'B'];
1242
            $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'C', 'C', 0, '');
1243
            $y += $h;
1244
            $h = 5;
1245
            $w = $maxW-(2*$x);
1246
            if (isset($this->infProt) && $resp['status']) {
1247
                $xMotivo = $this->infProt->getElementsByTagName("xMotivo")->item(0)->nodeValue;
1248
            } else {
1249
                $xMotivo = '';
1250
            }
1251
            $texto = "SEM VALOR FISCAL\n".$xMotivo;
1252
            $aFont = ['font'=>$this->fontePadrao, 'size'=>48, 'style'=>'B'];
1253
            $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'C', 'C', 0, '');
1254
            $this->pdf->settextcolor(0, 0, 0);
1255
        }
1256
        
1257
        /*
1258
        if ($this->pNotaCancelada()) {
1259
            //101 Cancelamento
1260
            $x = 10;
1261
            $y = $this->hPrint-130;
1262
            $h = 25;
1263
            $w = $maxW-(2*$x);
1264
            $this->pdf->SetTextColor(90, 90, 90);
1265
            $texto = "NFe CANCELADA";
1266
            $aFont = ['font'=>$this->fontePadrao, 'size'=>48, 'style'=>'B'];
1267
            $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'C', 'C', 0, '');
1268
            $this->pdf->SetTextColor(0, 0, 0);
1269
        }*/
1270
1271
        if ($this->notaDpec() || $this->tpEmis == 4) {
1272
            //DPEC
1273
            $x = 10;
1274
            $y = $this->hPrint-130;
1275
            $h = 25;
1276
            $w = $maxW-(2*$x);
1277
            $this->pdf->SetTextColor(200, 200, 200);
1278
            $texto = "DANFE impresso em contingência -\n".
1279
                     "DPEC regularmente recebido pela Receita\n".
1280
                     "Federal do Brasil";
1281
            $aFont = ['font'=>$this->fontePadrao, 'size'=>48, 'style'=>'B'];
1282
            $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'C', 'C', 0, '');
1283
            $this->pdf->SetTextColor(0, 0, 0);
1284
        }
1285
        /*
1286
        if ($this->pNotaDenegada()) {
1287
            //110 301 302 Denegada
1288
            $x = 10;
1289
            $y = $this->hPrint-130;
1290
            $h = 25;
1291
            $w = $maxW-(2*$x);
1292
            $this->pdf->SetTextColor(90, 90, 90);
1293
            $texto = "NFe USO DENEGADO";
1294
            $aFont = ['font'=>$this->fontePadrao, 'size'=>48, 'style'=>'B'];
1295
            $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'C', 'C', 0, '');
1296
            $y += $h;
1297
            $h = 5;
1298
            $w = $maxW-(2*$x);
1299
            if (isset($this->infProt)) {
1300
                $xMotivo = $this->infProt->getElementsByTagName("xMotivo")->item(0)->nodeValue;
1301
            } else {
1302
                $xMotivo = '';
1303
            }
1304
            $texto = "SEM VALOR FISCAL\n".$xMotivo;
1305
            $aFont = ['font'=>$this->fontePadrao, 'size'=>48, 'style'=>'B'];
1306
            $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'C', 'C', 0, '');
1307
            $this->pdf->SetTextColor(0, 0, 0);
1308
        }
1309
         *
1310
         */
1311
        //indicar sem valor
1312
        /*
1313
        if ($tpAmb != 1) {
1314
            $x = 10;
1315
            if ($this->orientacao == 'P') {
1316
                $y = round($this->hPrint*2/3, 0);
1317
            } else {
1318
                $y = round($this->hPrint/2, 0);
1319
            }
1320
            $h = 5;
1321
            $w = $maxW-(2*$x);
1322
            $this->pdf->SetTextColor(90, 90, 90);
1323
            $texto = "SEM VALOR FISCAL";
1324
            $aFont = ['font'=>$this->fontePadrao, 'size'=>48, 'style'=>'B'];
1325
            $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'C', 'C', 0, '');
1326
            $aFont = ['font'=>$this->fontePadrao, 'size'=>30, 'style'=>'B'];
1327
            $texto = "AMBIENTE DE HOMOLOGAÇÃO";
1328
            $this->pdf->textBox($x, $y+14, $w, $h, $texto, $aFont, 'C', 'C', 0, '');
1329
            $this->pdf->SetTextColor(0, 0, 0);
1330
        } else {
1331
            $x = 10;
1332
            if ($this->orientacao == 'P') {
1333
                $y = round($this->hPrint*2/3, 0);
1334
            } else {
1335
                $y = round($this->hPrint/2, 0);
1336
            }//fim orientacao
1337
            $h = 5;
1338
            $w = $maxW-(2*$x);
1339
            $this->pdf->SetTextColor(90, 90, 90);
1340
            //indicar FALTA DO PROTOCOLO se NFe não for em contingência
1341
            if (($this->tpEmis == 2 || $this->tpEmis == 5) && !$this->notaDpec()) {
1342
                //Contingência
1343
                $texto = "DANFE Emitido em Contingência";
1344
                $aFont = ['font'=>$this->fontePadrao, 'size'=>48, 'style'=>'B'];
1345
                $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'C', 'C', 0, '');
1346
                $aFont = ['font'=>$this->fontePadrao, 'size'=>30, 'style'=>'B'];
1347
                $texto = "devido à problemas técnicos";
1348
                $this->pdf->textBox($x, $y+12, $w, $h, $texto, $aFont, 'C', 'C', 0, '');
1349
            } else {
1350
                if (!isset($this->nfeProc)) {
1351
                    if (!$this->notaDpec()) {
1352
                        $texto = "SEM VALOR FISCAL";
1353
                        $aFont = ['font'=>$this->fontePadrao, 'size'=>48, 'style'=>'B'];
1354
                        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'C', 'C', 0, '');
1355
                    }
1356
                    $aFont = ['font'=>$this->fontePadrao, 'size'=>30, 'style'=>'B'];
1357
                    $texto = "FALTA PROTOCOLO DE APROVAÇÃO DA SEFAZ";
1358
                    if (!$this->notaDpec()) {
1359
                        $this->pdf->textBox($x, $y+12, $w, $h, $texto, $aFont, 'C', 'C', 0, '');
1360
                    } else {
1361
                        $this->pdf->textBox($x, $y+25, $w, $h, $texto, $aFont, 'C', 'C', 0, '');
1362
                    }
1363
                }//fim nefProc
1364
            }//fim tpEmis
1365
            $this->pdf->SetTextColor(0, 0, 0);
1366
        }
1367
         *
1368
         */
1369
        return $oldY;
1370
    } //fim header
1371
1372
    /**
1373
     * destinatarioDANFE
1374
     * Monta o campo com os dados do destinatário na DANFE. (retrato e paisagem)
1375
     *
1376
     * @name   destinatarioDANFE
1377
     * @param  number $x Posição horizontal canto esquerdo
1378
     * @param  number $y Posição vertical canto superior
1379
     * @return number Posição vertical final
1380
     */
1381
    protected function destinatarioDANFE($x = 0, $y = 0)
1382
    {
1383
        //####################################################################################
1384
        //DESTINATÁRIO / REMETENTE
1385
        $oldX = $x;
1386
        $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...
1387
        if ($this->orientacao == 'P') {
1388
            $maxW = $this->wPrint;
1389
        } else {
1390
            $maxW = $this->wPrint - $this->wCanhoto;
1391
        }
1392
        $w = $maxW;
1393
        $h = 7;
1394
        $texto = 'DESTINATÁRIO / REMETENTE';
1395
        $aFont = ['font'=>$this->fontePadrao, 'size'=>7, 'style'=>'B'];
1396
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 0, '');
1397
        //NOME / RAZÃO SOCIAL
1398
        $w = round($maxW*0.61, 0);
1399
        $w1 = $w;
1400
        $y += 3;
1401
        $texto = 'NOME / RAZÃO SOCIAL';
1402
        $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
1403
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 1, '');
1404
        $texto = $this->dest->getElementsByTagName("xNome")->item(0)->nodeValue;
1405
        $aFont = ['font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B'];
1406
        if ($this->orientacao == 'P') {
1407
            $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'B', 'L', 0, '');
1408
        } else {
1409
            $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'B', 'L', 1, '');
1410
        }
1411
        //CNPJ / CPF
1412
        $x += $w;
1413
        $w = round($maxW*0.23, 0);
1414
        $w2 = $w;
1415
        $texto = 'CNPJ / CPF';
1416
        $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
1417
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 1, '');
1418
        //Pegando valor do CPF/CNPJ
1419
        if (! empty($this->dest->getElementsByTagName("CNPJ")->item(0)->nodeValue)) {
1420
            $texto = $this->formatField(
1421
                $this->dest->getElementsByTagName("CNPJ")->item(0)->nodeValue,
1422
                "###.###.###/####-##"
1423
            );
1424
        } else {
1425
            $texto = ! empty($this->dest->getElementsByTagName("CPF")->item(0)->nodeValue)
1426
            ? $this->formatField(
1427
                $this->dest->getElementsByTagName("CPF")->item(0)->nodeValue,
1428
                "###.###.###-##"
1429
            )
1430
            : '';
1431
        }
1432
        $aFont = ['font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B'];
1433
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'B', 'C', 0, '');
1434
        //DATA DA EMISSÃO
1435
        $x += $w;
1436
        $w = $maxW-($w1+$w2);
1437
        $wx = $w;
1438
        $texto = 'DATA DA EMISSÃO';
1439
        $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
1440
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 1, '');
1441
        $dEmi = ! empty($this->ide->getElementsByTagName("dEmi")->item(0)->nodeValue)
1442
        ? $this->ide->getElementsByTagName("dEmi")->item(0)->nodeValue
1443
        : '';
1444
        if ($dEmi == '') {
1445
            $dEmi = ! empty($this->ide->getElementsByTagName("dhEmi")->item(0)->nodeValue)
1446
            ? $this->ide->getElementsByTagName("dhEmi")->item(0)->nodeValue
1447
            : '';
1448
            $aDemi = explode('T', $dEmi);
1449
            $dEmi = $aDemi[0];
1450
        }
1451
        $texto = $this->ymdTodmy($dEmi);
1452
        $aFont = ['font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B'];
1453
        if ($this->orientacao == 'P') {
1454
            $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'B', 'C', 0, '');
1455
        } else {
1456
            $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'B', 'C', 1, '');
1457
        }
1458
        //ENDEREÇO
1459
        $w = round($maxW*0.47, 0);
1460
        $w1 = $w;
1461
        $y += $h;
1462
        $x = $oldX;
1463
        $texto = 'ENDEREÇO';
1464
        $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
1465
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 1, '');
1466
        $texto = $this->dest->getElementsByTagName("xLgr")->item(0)->nodeValue;
1467
        $texto .= ', ' . $this->dest->getElementsByTagName("nro")->item(0)->nodeValue;
1468
        $texto .= $this->getTagValue($this->dest, "xCpl", " - ");
1469
1470
        $aFont = ['font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B'];
1471
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'B', 'L', 0, '', true);
1472
        //BAIRRO / DISTRITO
1473
        $x += $w;
1474
        $w = round($maxW*0.21, 0);
1475
        $w2 = $w;
1476
        $texto = 'BAIRRO / DISTRITO';
1477
        $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
1478
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 1, '');
1479
        $texto = $this->dest->getElementsByTagName("xBairro")->item(0)->nodeValue;
1480
        $aFont = ['font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B'];
1481
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'B', 'C', 0, '');
1482
        //CEP
1483
        $x += $w;
1484
        $w = $maxW-$w1-$w2-$wx;
1485
        $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...
1486
        $texto = 'CEP';
1487
        $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
1488
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 1, '');
1489
        $texto = ! empty($this->dest->getElementsByTagName("CEP")->item(0)->nodeValue)
1490
        ? $this->dest->getElementsByTagName("CEP")->item(0)->nodeValue
1491
        : '';
1492
        $texto = $this->formatField($texto, "#####-###");
1493
        $aFont = ['font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B'];
1494
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'B', 'C', 0, '');
1495
        //DATA DA SAÍDA
1496
        $x += $w;
1497
        $w = $wx;
1498
        $texto = 'DATA DA SAÍDA/ENTRADA';
1499
        $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
1500
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 1, '');
1501
        $dSaiEnt = ! empty($this->ide->getElementsByTagName("dSaiEnt")->item(0)->nodeValue)
1502
            ? $this->ide->getElementsByTagName("dSaiEnt")->item(0)->nodeValue
1503
            : '';
1504
        if ($dSaiEnt == '') {
1505
            $dSaiEnt = ! empty($this->ide->getElementsByTagName("dhSaiEnt")->item(0)->nodeValue)
1506
                ? $this->ide->getElementsByTagName("dhSaiEnt")->item(0)->nodeValue
1507
                : '';
1508
            $aDsaient = explode('T', $dSaiEnt);
1509
            $dSaiEnt = $aDsaient[0];
1510
        }
1511
        $texto = $this->ymdTodmy($dSaiEnt);
1512
        $aFont = ['font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B'];
1513
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'B', 'C', 0, '');
1514
        //MUNICÍPIO
1515
        $w = $w1;
1516
        $y += $h;
1517
        $x = $oldX;
1518
        $texto = 'MUNICÍPIO';
1519
        $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
1520
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 1, '');
1521
        $texto = $this->dest->getElementsByTagName("xMun")->item(0)->nodeValue;
1522
        if (strtoupper(trim($texto)) == "EXTERIOR"
1523
            && $this->dest->getElementsByTagName("xPais")->length > 0
1524
        ) {
1525
            $texto .= " - " .  $this->dest->getElementsByTagName("xPais")->item(0)->nodeValue;
1526
        }
1527
        $aFont = ['font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B'];
1528
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'B', 'L', 0, '');
1529
        //UF
1530
        $x += $w;
1531
        $w = 8;
1532
        $texto = 'UF';
1533
        $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
1534
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 1, '');
1535
        $texto = $this->dest->getElementsByTagName("UF")->item(0)->nodeValue;
1536
        $aFont = ['font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B'];
1537
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'B', 'C', 0, '');
1538
        //FONE / FAX
1539
        $x += $w;
1540
        $w = round(($maxW -$w1-$wx-8)/2, 0);
1541
        $w3 = $w;
1542
        $texto = 'FONE / FAX';
1543
        $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
1544
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 1, '');
1545
        $texto = ! empty($this->dest->getElementsByTagName("fone")->item(0)->nodeValue)
1546
        ? $this->dest->getElementsByTagName("fone")->item(0)->nodeValue
1547
        : '';
1548
        $aFont = ['font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B'];
1549
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'B', 'C', 0, '');
1550
        //INSCRIÇÃO ESTADUAL
1551
        $x += $w;
1552
        $w = $maxW -$w1-$wx-8-$w3;
1553
        $texto = 'INSCRIÇÃO ESTADUAL';
1554
        $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
1555
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 1, '');
1556
        $IE = $this->dest->getElementsByTagName("IE");
1557
        $texto = ($IE && $IE->length > 0) ? $IE->item(0)->nodeValue : '';
1558
        $aFont = ['font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B'];
1559
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'B', 'C', 0, '');
1560
        //HORA DA SAÍDA
1561
        $x += $w;
1562
        $w = $wx;
1563
        $texto = 'HORA DA SAÍDA/ENTRADA';
1564
        $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
1565
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 1, '');
1566
        $hSaiEnt = ! empty($this->ide->getElementsByTagName("hSaiEnt")->item(0)->nodeValue)
1567
        ? $this->ide->getElementsByTagName("hSaiEnt")->item(0)->nodeValue
1568
        : '';
1569
        if ($hSaiEnt == '') {
1570
            $dhSaiEnt = ! empty($this->ide->getElementsByTagName("dhSaiEnt")->item(0)->nodeValue)
1571
            ? $this->ide->getElementsByTagName("dhSaiEnt")->item(0)->nodeValue
1572
            : '';
1573
            $tsDhSaiEnt = $this->toTimestamp($dhSaiEnt);
1574
            if ($tsDhSaiEnt != '') {
1575
                $hSaiEnt = date('H:i:s', $tsDhSaiEnt);
1576
            }
1577
        }
1578
        $texto = $hSaiEnt;
1579
        $aFont = ['font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B'];
1580
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'B', 'C', 0, '');
1581
        return ($y + $h);
1582
    } //fim da função destinatarioDANFE
1583
1584
    /**
1585
     * localEntregaDANFE
1586
     * Monta o campo com os dados do local de entrega na DANFE. (retrato e paisagem)
1587
     *
1588
     * @name   localEntregaDANFE
1589
     * @param  number $x Posição horizontal canto esquerdo
1590
     * @param  number $y Posição vertical canto superior
1591
     * @return number Posição vertical final
1592
     */
1593
    protected function localEntregaDANFE($x = 0, $y = 0)
1594
    {
1595
        //####################################################################################
1596
        //LOCAL DE ENTREGA
1597
        $oldX = $x;
1598
        if ($this->orientacao == 'P') {
1599
            $maxW = $this->wPrint;
1600
        } else {
1601
            $maxW = $this->wPrint - $this->wCanhoto;
1602
        }
1603
        $w = $maxW;
1604
        $h = 7;
1605
        $texto = 'INFORMAÇÕES DO LOCAL DE ENTREGA';
1606
        $aFont = array('font'=>$this->fontePadrao, 'size'=>7, 'style'=>'B');
1607
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 0, '');
1608
        //NOME / RAZÃO SOCIAL
1609
        $w = round($maxW*0.61, 0);
1610
        $w1 = $w;
1611
        $y += 3;
1612
        $texto = 'NOME / RAZÃO SOCIAL';
1613
        $aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>'');
1614
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 1, '');
1615
        $texto = '';
1616
        if ($this->entrega->getElementsByTagName("xNome")->item(0)) {
1617
            $texto = $this->entrega->getElementsByTagName("xNome")->item(0)->nodeValue;
1618
        }
1619
        $aFont = array('font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B');
1620
        if ($this->orientacao == 'P') {
1621
            $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'B', 'L', 0, '');
1622
        } else {
1623
            $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'B', 'L', 1, '');
1624
        }
1625
        //CNPJ / CPF
1626
        $x += $w;
1627
        $w = round($maxW*0.23, 0);
1628
        $w2 = $w;
1629
        $texto = 'CNPJ / CPF';
1630
        $aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>'');
1631
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 1, '');
1632
        //Pegando valor do CPF/CNPJ
1633
        if (! empty($this->entrega->getElementsByTagName("CNPJ")->item(0)->nodeValue)) {
1634
            $texto = $this->formatField(
1635
                $this->entrega->getElementsByTagName("CNPJ")->item(0)->nodeValue,
1636
                "###.###.###/####-##"
1637
            );
1638
        } else {
1639
            $texto = ! empty($this->entrega->getElementsByTagName("CPF")->item(0)->nodeValue) ?
1640
                    $this->formatField(
1641
                        $this->entrega->getElementsByTagName("CPF")->item(0)->nodeValue,
1642
                        "###.###.###-##"
1643
                    ) : '';
1644
        }
1645
        $aFont = array('font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B');
1646
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'B', 'C', 0, '');
1647
        //INSCRIÇÃO ESTADUAL
1648
        $x += $w;
1649
        $w = $maxW-($w1+$w2);
1650
        $wx = $w;
1651
        $texto = 'INSCRIÇÃO ESTADUAL';
1652
        $aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>'');
1653
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 1, '');
1654
        $texto = '';
1655
        if ($this->entrega->getElementsByTagName("IE")->item(0)) {
1656
            $texto = $this->entrega->getElementsByTagName("IE")->item(0)->nodeValue;
1657
        }
1658
        $aFont = array('font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B');
1659
        if ($this->orientacao == 'P') {
1660
            $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'B', 'C', 0, '');
1661
        } else {
1662
            $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'B', 'C', 1, '');
1663
        }
1664
        //ENDEREÇO
1665
        $w = round($maxW*0.355, 0) + $wx;
1666
        $w1 = $w;
1667
        $y += $h;
1668
        $x = $oldX;
1669
        $texto = 'ENDEREÇO';
1670
        $aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>'');
1671
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 1, '');
1672
        $texto = $this->entrega->getElementsByTagName("xLgr")->item(0)->nodeValue;
1673
        $texto .= ', ' . $this->entrega->getElementsByTagName("nro")->item(0)->nodeValue;
1674
        $texto .= $this->getTagValue($this->entrega, "xCpl", " - ");
1675
        $aFont = array('font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B');
1676
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'B', 'L', 0, '', true);
1677
        //BAIRRO / DISTRITO
1678
        $x += $w;
1679
        $w = round($maxW*0.335, 0);
1680
        $w2 = $w;
1681
        $texto = 'BAIRRO / DISTRITO';
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("xBairro")->item(0)->nodeValue;
1685
        $aFont = array('font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B');
1686
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'B', 'C', 0, '');
1687
        //CEP
1688
        $x += $w;
1689
        $w = $maxW-($w1+$w2);
1690
        $texto = 'CEP';
1691
        $aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>'');
1692
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 1, '');
1693
        $texto = ! empty($this->entrega->getElementsByTagName("CEP")->item(0)->nodeValue) ?
1694
                $this->entrega->getElementsByTagName("CEP")->item(0)->nodeValue : '';
1695
        $texto = $this->formatField($texto, "#####-###");
1696
        $aFont = array('font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B');
1697
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'B', 'C', 0, '');
1698
        //MUNICÍPIO
1699
        $w = round($maxW*0.805, 0);
1700
        $w1 = $w;
1701
        $y += $h;
1702
        $x = $oldX;
1703
        $texto = 'MUNICÍPIO';
1704
        $aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>'');
1705
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 1, '');
1706
        $texto = $this->entrega->getElementsByTagName("xMun")->item(0)->nodeValue;
1707
        if (strtoupper(trim($texto)) == "EXTERIOR" && $this->entrega->getElementsByTagName("xPais")->length > 0) {
1708
            $texto .= " - " .  $this->entrega->getElementsByTagName("xPais")->item(0)->nodeValue;
1709
        }
1710
        $aFont = array('font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B');
1711
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'B', 'L', 0, '');
1712
        //UF
1713
        $x += $w;
1714
        $w = 8;
1715
        $texto = 'UF';
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("UF")->item(0)->nodeValue;
1719
        $aFont = array('font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B');
1720
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'B', 'C', 0, '');
1721
        //FONE / FAX
1722
        $x += $w;
1723
        $w = $maxW-$w-$w1;
1724
        $texto = 'FONE / FAX';
1725
        $aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>'');
1726
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 1, '');
1727
        $texto = ! empty($this->entrega->getElementsByTagName("fone")->item(0)->nodeValue) ?
1728
                $this->entrega->getElementsByTagName("fone")->item(0)->nodeValue : '';
1729
        $aFont = array('font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B');
1730
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'B', 'C', 0, '');
1731
        return ($y + $h);
1732
    } //fim da função localEntregaDANFE
1733
    
1734
    /**
1735
     * localretiradaDANFE
1736
     * Monta o campo com os dados do local de entrega na DANFE. (retrato e paisagem)
1737
     *
1738
     * @name   localretiradaDANFE
1739
     * @param  number $x Posição horizontal canto esquerdo
1740
     * @param  number $y Posição vertical canto superior
1741
     * @return number Posição vertical final
1742
     */
1743
    protected function localRetiradaDANFE($x = 0, $y = 0)
1744
    {
1745
        //####################################################################################
1746
        //LOCAL DE RETIRADA
1747
        $oldX = $x;
1748
        if ($this->orientacao == 'P') {
1749
            $maxW = $this->wPrint;
1750
        } else {
1751
            $maxW = $this->wPrint - $this->wCanhoto;
1752
        }
1753
        $w = $maxW;
1754
        $h = 7;
1755
        $texto = 'INFORMAÇÕES DO LOCAL DE RETIRADA';
1756
        $aFont = array('font'=>$this->fontePadrao, 'size'=>7, 'style'=>'B');
1757
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 0, '');
1758
        //NOME / RAZÃO SOCIAL
1759
        $w = round($maxW*0.61, 0);
1760
        $w1 = $w;
1761
        $y += 3;
1762
        $texto = 'NOME / RAZÃO SOCIAL';
1763
        $aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>'');
1764
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 1, '');
1765
        $texto = '';
1766
        if ($this->retirada->getElementsByTagName("xNome")->item(0)) {
1767
            $texto = $this->retirada->getElementsByTagName("xNome")->item(0)->nodeValue;
1768
        }
1769
        $aFont = array('font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B');
1770
        if ($this->orientacao == 'P') {
1771
            $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'B', 'L', 0, '');
1772
        } else {
1773
            $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'B', 'L', 1, '');
1774
        }
1775
        //CNPJ / CPF
1776
        $x += $w;
1777
        $w = round($maxW*0.23, 0);
1778
        $w2 = $w;
1779
        $texto = 'CNPJ / CPF';
1780
        $aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>'');
1781
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 1, '');
1782
        //Pegando valor do CPF/CNPJ
1783
        if (! empty($this->retirada->getElementsByTagName("CNPJ")->item(0)->nodeValue)) {
1784
            $texto = $this->formatField(
1785
                $this->retirada->getElementsByTagName("CNPJ")->item(0)->nodeValue,
1786
                "###.###.###/####-##"
1787
            );
1788
        } else {
1789
            $texto = ! empty($this->retirada->getElementsByTagName("CPF")->item(0)->nodeValue) ?
1790
                    $this->formatField(
1791
                        $this->retirada->getElementsByTagName("CPF")->item(0)->nodeValue,
1792
                        "###.###.###-##"
1793
                    ) : '';
1794
        }
1795
        $aFont = array('font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B');
1796
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'B', 'C', 0, '');
1797
        //INSCRIÇÃO ESTADUAL
1798
        $x += $w;
1799
        $w = $maxW-($w1+$w2);
1800
        $wx = $w;
1801
        $texto = 'INSCRIÇÃO ESTADUAL';
1802
        $aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>'');
1803
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 1, '');
1804
        $texto = '';
1805
        if ($this->retirada->getElementsByTagName("IE")->item(0)) {
1806
            $texto = $this->retirada->getElementsByTagName("IE")->item(0)->nodeValue;
1807
        }
1808
        $aFont = array('font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B');
1809
        if ($this->orientacao == 'P') {
1810
            $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'B', 'C', 0, '');
1811
        } else {
1812
            $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'B', 'C', 1, '');
1813
        }
1814
        //ENDEREÇO
1815
        $w = round($maxW*0.355, 0) + $wx;
1816
        $w1 = $w;
1817
        $y += $h;
1818
        $x = $oldX;
1819
        $texto = 'ENDEREÇO';
1820
        $aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>'');
1821
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 1, '');
1822
        $texto = $this->retirada->getElementsByTagName("xLgr")->item(0)->nodeValue;
1823
        $texto .= ', ' . $this->retirada->getElementsByTagName("nro")->item(0)->nodeValue;
1824
        $texto .= $this->getTagValue($this->retirada, "xCpl", " - ");
1825
        $aFont = array('font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B');
1826
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'B', 'L', 0, '', true);
1827
        //BAIRRO / DISTRITO
1828
        $x += $w;
1829
        $w = round($maxW*0.335, 0);
1830
        $w2 = $w;
1831
        $texto = 'BAIRRO / DISTRITO';
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("xBairro")->item(0)->nodeValue;
1835
        $aFont = array('font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B');
1836
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'B', 'C', 0, '');
1837
        //CEP
1838
        $x += $w;
1839
        $w = $maxW-($w1+$w2);
1840
        $texto = 'CEP';
1841
        $aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>'');
1842
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 1, '');
1843
        $texto = ! empty($this->retirada->getElementsByTagName("CEP")->item(0)->nodeValue) ?
1844
                $this->retirada->getElementsByTagName("CEP")->item(0)->nodeValue : '';
1845
        $texto = $this->formatField($texto, "#####-###");
1846
        $aFont = array('font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B');
1847
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'B', 'C', 0, '');
1848
        //MUNICÍPIO
1849
        $w = round($maxW*0.805, 0);
1850
        $w1 = $w;
1851
        $y += $h;
1852
        $x = $oldX;
1853
        $texto = 'MUNICÍPIO';
1854
        $aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>'');
1855
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 1, '');
1856
        $texto = $this->retirada->getElementsByTagName("xMun")->item(0)->nodeValue;
1857
        if (strtoupper(trim($texto)) == "EXTERIOR" && $this->retirada->getElementsByTagName("xPais")->length > 0) {
1858
            $texto .= " - " .  $this->retirada->getElementsByTagName("xPais")->item(0)->nodeValue;
1859
        }
1860
        $aFont = array('font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B');
1861
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'B', 'L', 0, '');
1862
        //UF
1863
        $x += $w;
1864
        $w = 8;
1865
        $texto = 'UF';
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("UF")->item(0)->nodeValue;
1869
        $aFont = array('font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B');
1870
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'B', 'C', 0, '');
1871
        //FONE / FAX
1872
        $x += $w;
1873
        $w = $maxW-$w-$w1;
1874
        $texto = 'FONE / FAX';
1875
        $aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>'');
1876
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 1, '');
1877
        $texto = ! empty($this->retirada->getElementsByTagName("fone")->item(0)->nodeValue) ?
1878
                $this->retirada->getElementsByTagName("fone")->item(0)->nodeValue : '';
1879
        $aFont = array('font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B');
1880
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'B', 'C', 0, '');
1881
        return ($y + $h);
1882
    } //fim da função localRetiradaDANFE
1883
    
1884
     /**
1885
     * getTextoFatura
1886
     * Gera a String do Texto da Fatura
1887
      *
1888
     * @name   getTextoFatura
1889
     * @return uma String com o texto ou "";
1890
     */
1891
    protected function getTextoFatura()
1892
    {
1893
        if (isset($this->cobr)) {
1894
            $fat = $this->cobr->getElementsByTagName("fat")->item(0);
1895
            if (isset($fat)) {
1896
                if (!empty($this->getTagValue($this->ide, "indPag"))) {
1897
                    $textoIndPag = "";
1898
                    $indPag = $this->getTagValue($this->ide, "indPag");
1899
                    if ($indPag === "0") {
1900
                        $textoIndPag = "Pagamento à Vista - ";
1901
                    } elseif ($indPag === "1") {
1902
                        $textoIndPag = "Pagamento à Prazo - ";
1903
                    }
1904
                    $nFat = $this->getTagValue($fat, "nFat", "Fatura: ");
1905
                    $vOrig = $this->getTagValue($fat, "vOrig", " Valor Original: ");
1906
                    $vDesc = $this->getTagValue($fat, "vDesc", " Desconto: ");
1907
                    $vLiq = $this->getTagValue($fat, "vLiq", " Valor Líquido: ");
1908
                    $texto = $textoIndPag . $nFat . $vOrig . $vDesc . $vLiq;
1909
                    return $texto;
1910
                } else {
1911
                    $pag = $this->dom->getElementsByTagName("pag");
1912
                    if ($tPag = $this->getTagValue($pag->item(0), "tPag")) {
1913
                        return $this->tipoPag($tPag);
1914
                    }
1915
                }
1916
            }
1917
        }
1918
        return "";
1919
    }
1920
1921
     /**
1922
     * sizeExtraTextoFatura
1923
     * Calcula o espaço ocupado pelo texto da fatura. Este espaço só é utilizado quando não houver duplicata.
1924
      *
1925
     * @name   sizeExtraTextoFatura
1926
     * @return integer
1927
     */
1928
    protected function sizeExtraTextoFatura()
1929
    {
1930
        $textoFatura = $this->getTextoFatura();
1931
        //verificar se existem duplicatas
1932
        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...
1933
            return 10;
1934
        }
1935
        return 0;
1936
    }
1937
1938
    /**
1939
     * fatura
1940
     * Monta o campo de duplicatas da DANFE (retrato e paisagem)
1941
     *
1942
     * @name   fatura
1943
     * @param  number $x Posição horizontal canto esquerdo
1944
     * @param  number $y Posição vertical canto superior
1945
     * @return number Posição vertical final
1946
     */
1947
    protected function fatura($x, $y)
1948
    {
1949
        $linha = 1;
1950
        $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...
1951
        $oldx = $x;
1952
        $textoFatura = $this->getTextoFatura();
1953
        //verificar se existem duplicatas
1954
        if ($this->dup->length > 0 || $textoFatura !== "") {
1955
            //#####################################################################
1956
            //FATURA / DUPLICATA
1957
            $texto = "FATURA / DUPLICATA";
1958
            if ($this->orientacao == 'P') {
1959
                $w = $this->wPrint;
1960
            } else {
1961
                $w = 271;
1962
            }
1963
            $h = 8;
1964
            $aFont = ['font'=>$this->fontePadrao, 'size'=>7, 'style'=>'B'];
1965
            $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 0, '');
1966
            $y += 3;
1967
            $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...
1968
            $dupcont = 0;
1969
            $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...
1970
            if ($nFat > 7) {
1971
                $myH = 6;
1972
                $myW = $this->wPrint;
1973
                if ($this->orientacao == 'L') {
1974
                    $myW -= $this->wCanhoto;
1975
                }
1976
                $aFont = ['font' => $this->fontePadrao, 'size' => 9, 'style' => ''];
1977
                $texto = "Existem mais de 7 duplicatas registradas, portanto não "
1978
                    . "serão exibidas, confira diretamente pelo XML.";
1979
                $this->pdf->textBox($x, $y, $myW, $myH, $texto, $aFont, 'C', 'C', 1, '');
1980
                return ($y + $h - 3);
1981
            }
1982
            if ($textoFatura !== "" && $this->exibirTextoFatura) {
1983
                $myH=6;
1984
                $myW = $this->wPrint;
1985
                if ($this->orientacao == 'L') {
1986
                    $myW -= $this->wCanhoto;
1987
                }
1988
                $aFont = ['font'=>$this->fontePadrao, 'size'=>8, 'style'=>''];
1989
                $this->pdf->textBox($x, $y, $myW, $myH, $textoFatura, $aFont, 'C', 'L', 1, '');
1990
                $y+=$myH+1;
1991
            }
1992
            if ($this->orientacao == 'P') {
1993
                $w = round($this->wPrint/7.018, 0)-1;
1994
            } else {
1995
                $w = 28;
1996
            }
1997
            $increm = 1;
1998
            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...
1999
                $nDup = ! empty($this->dup->item($k)->getElementsByTagName('nDup')->item(0)->nodeValue)
2000
                ? $this->dup->item($k)->getElementsByTagName('nDup')->item(0)->nodeValue
2001
                : '';
2002
                $dDup = ! empty($this->dup->item($k)->getElementsByTagName('dVenc')->item(0)->nodeValue)
2003
                ? $this->ymdTodmy($this->dup->item($k)->getElementsByTagName('dVenc')->item(0)->nodeValue)
2004
                : '';
2005
                $vDup = ! empty($this->dup->item($k)->getElementsByTagName('vDup')->item(0)->nodeValue)
2006
                ? 'R$ ' . number_format(
2007
                    $this->dup->item($k)->getElementsByTagName('vDup')->item(0)->nodeValue,
2008
                    2,
2009
                    ",",
2010
                    "."
2011
                )
2012
                : '';
2013
                $h = 8;
2014
                $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...
2015
                if ($nDup!='0' && $nDup!='') {
2016
                    $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
2017
                    $this->pdf->textBox($x, $y, $w, $h, 'Num.', $aFont, 'T', 'L', 1, '');
2018
                    $aFont = ['font'=>$this->fontePadrao, 'size'=>7, 'style'=>'B'];
2019
                    $this->pdf->textBox($x, $y, $w, $h, $nDup, $aFont, 'T', 'R', 0, '');
2020
                } else {
2021
                    $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
2022
                    $this->pdf->textBox($x, $y, $w, $h, ($dupcont+1)."", $aFont, 'T', 'L', 1, '');
2023
                }
2024
                $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
2025
                $this->pdf->textBox($x, $y, $w, $h, 'Venc.', $aFont, 'C', 'L', 0, '');
2026
                $aFont = ['font'=>$this->fontePadrao, 'size'=>7, 'style'=>'B'];
2027
                $this->pdf->textBox($x, $y, $w, $h, $dDup, $aFont, 'C', 'R', 0, '');
2028
                $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
2029
                $this->pdf->textBox($x, $y, $w, $h, 'Valor', $aFont, 'B', 'L', 0, '');
2030
                $aFont = ['font'=>$this->fontePadrao, 'size'=>7, 'style'=>'B'];
2031
                $this->pdf->textBox($x, $y, $w, $h, $vDup, $aFont, 'B', 'R', 0, '');
2032
                $x += $w+$increm;
2033
                $dupcont += 1;
2034
                if ($this->orientacao == 'P') {
2035
                    $maxDupCont = 6;
2036
                } else {
2037
                    $maxDupCont = 8;
2038
                }
2039
                if ($dupcont > $maxDupCont) {
2040
                    $y += 9;
2041
                    $x = $oldx;
2042
                    $dupcont = 0;
2043
                    $linha += 1;
2044
                }
2045
                if ($linha == 5) {
2046
                    $linha = 4;
2047
                    break;
2048
                }
2049
            }
2050
            if ($dupcont == 0) {
2051
                $y -= 9;
2052
                $linha--;
2053
            }
2054
            return ($y+$h);
2055
        } else {
2056
            $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...
2057
            return ($y-2);
2058
        }
2059
    }
2060
2061
    /**
2062
     * pagamento
2063
     * Monta o campo de pagamentos da DANFE (retrato e paisagem) (foi baseada na fatura)
2064
     *
2065
     * @name   pagamento
2066
     * @param  number $x Posição horizontal canto esquerdo
2067
     * @param  number $y Posição vertical canto superior
2068
     * @return number Posição vertical final
2069
     */
2070
    protected function pagamento($x, $y)
2071
    {
2072
        $linha = 1;
2073
        $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...
2074
        $oldx = $x;
2075
        //verificar se existem cobranças definidas
2076
        if (isset($this->detPag) && $this->detPag->length > 0) {
2077
            //#####################################################################
2078
            //Tipo de pagamento
2079
            $texto = "PAGAMENTO";
2080
            if ($this->orientacao == 'P') {
2081
                $w = $this->wPrint;
2082
            } else {
2083
                $w = 271;
2084
            }
2085
            $h = 8;
2086
            $aFont = ['font'=>$this->fontePadrao, 'size'=>7, 'style'=>'B'];
2087
            $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 0, '');
2088
            $y += 3;
2089
            $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...
2090
            $dupcont = 0;
2091
            if ($this->orientacao == 'P') {
2092
                $w = round($this->wPrint/7.018, 0)-1;
2093
            } else {
2094
                $w = 28;
2095
            }
2096
            if ($this->orientacao == 'P') {
2097
                $maxDupCont = 6;
2098
            } else {
2099
                $maxDupCont = 8;
2100
            }
2101
            $increm = 1;
2102
            $formaPagamento = ['01'=>'Dinheiro','02'=>'Cheque','03'=>'Cartão de Crédito',
2103
                                    '04'=>'Cartão de Débito','05'=>'Crédito Loja','10'=>'Vale Alimentação',
2104
                                    '11'=>'Vale Refeição','12'=>'Vale Presente','13'=>'Vale Combustível',
2105
                                    '14'=>'Duplicata Mercantil','15'=>'Boleto','90'=>'Sem pagamento','99'=>'Outros'];
2106
            $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...
2107
                              '06'=>'Elo','07'=>'Hipercard','08'=>'Aura','09'=>'Cabal','99'=>'Outros'];
2108
            foreach ($this->detPag as $k => $d) {
2109
                $fPag = !empty($this->detPag->item($k)->getElementsByTagName('tPag')->item(0)->nodeValue)
2110
                ? $this->detPag->item($k)->getElementsByTagName('tPag')->item(0)->nodeValue
2111
                : '0';
2112
                $vPag = ! empty($this->detPag->item($k)->getElementsByTagName('vPag')->item(0)->nodeValue)
2113
                ? 'R$ ' . number_format(
2114
                    $this->detPag->item($k)->getElementsByTagName('vPag')->item(0)->nodeValue,
2115
                    2,
2116
                    ",",
2117
                    "."
2118
                )
2119
                : '';
2120
                $h = 6;
2121
                $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...
2122
                if (isset($formaPagamento[$fPag])) {
2123
                    /*Exibir Item sem pagamento ou outros?*/
2124
                    if ($fPag=='90' || $fPag=='99') {
2125
                        continue;
2126
                    }
2127
                    $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
2128
                    $this->pdf->textBox($x, $y, $w, $h, 'Forma', $aFont, 'T', 'L', 1, '');
2129
                    $aFont = ['font'=>$this->fontePadrao, 'size'=>7, 'style'=>'B'];
2130
                    $this->pdf->textBox($x, $y, $w, $h, $formaPagamento[$fPag], $aFont, 'T', 'R', 0, '');
2131
                } else {
2132
                    $aFont = ['font'=>$this->fontePadrao, 'size'=>7, 'style'=>''];
2133
                    $this->pdf->textBox($x, $y, $w, $h, "Forma ".$fPag." não encontrado", $aFont, 'T', 'L', 1, '');
2134
                }
2135
                $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
2136
                $this->pdf->textBox($x, $y, $w, $h, 'Valor', $aFont, 'B', 'L', 0, '');
2137
                $aFont = ['font'=>$this->fontePadrao, 'size'=>7, 'style'=>'B'];
2138
                $this->pdf->textBox($x, $y, $w, $h, $vPag, $aFont, 'B', 'R', 0, '');
2139
                $x += $w+$increm;
2140
                $dupcont += 1;
2141
2142
                if ($dupcont>$maxDupCont) {
2143
                    $y += 9;
2144
                    $x = $oldx;
2145
                    $dupcont = 0;
2146
                    $linha += 1;
2147
                }
2148
                if ($linha == 5) {
2149
                    $linha = 4;
2150
                    break;
2151
                }
2152
            }
2153
            if ($dupcont == 0) {
2154
                $y -= 9;
2155
                $linha--;
2156
            }
2157
            return ($y+$h);
2158
        } else {
2159
            $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...
2160
            return ($y-2);
2161
        }
2162
    } //fim da função pagamento
2163
    
2164
    /**
2165
     * impostoHelper
2166
     * Auxilia a montagem dos campos de impostos e totais da DANFE
2167
     *
2168
     * @name   impostoHelper
2169
     * @param  float $x Posição horizontal canto esquerdo
2170
     * @param  float $y Posição vertical canto superior
2171
     * @param  float $w Largura do campo
2172
     * @param  float $h Altura do campo
2173
     * @param  float $h Título do campo
2174
     * @param  float $h Valor do imposto
2175
     * @return float Sugestão do $x do próximo imposto
2176
     */
2177
    protected function impostoHelper($x, $y, $w, $h, $titulo, $campoImposto)
2178
    {
2179
        $valorImposto = '0, 00';
2180
        $the_field = $this->ICMSTot->getElementsByTagName($campoImposto)->item(0);
2181
        if (isset($the_field)) {
2182
            $the_value = $the_field->nodeValue;
2183
            if (!empty($the_value)) {
2184
                $valorImposto = number_format($the_value, 2, ",", ".");
2185
            }
2186
        }
2187
2188
        $fontTitulo = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
2189
        $fontValor = ['font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B'];
2190
        $this->pdf->textBox($x, $y, $w, $h, $titulo, $fontTitulo, 'T', 'L', 1, '');
2191
        $this->pdf->textBox($x, $y, $w, $h, $valorImposto, $fontValor, 'B', 'R', 0, '');
2192
2193
        $next_x = $x + $w;
2194
        return $next_x;
2195
    }
2196
2197
    /**
2198
     * imposto
2199
     * Monta o campo de impostos e totais da DANFE (retrato e paisagem)
2200
     *
2201
     * @param  number $x Posição horizontal canto esquerdo
2202
     * @param  number $y Posição vertical canto superior
2203
     * @return number Posição vertical final
2204
     */
2205
    protected function imposto($x, $y)
2206
    {
2207
        $x_inicial = $x;
2208
        //#####################################################################
2209
2210
2211
        $campos_por_linha = 9;
2212
        if (!$this->exibirPIS) {
2213
            $campos_por_linha--;
2214
        }
2215
        if (!$this->exibirIcmsInterestadual) {
2216
            $campos_por_linha -= 2;
2217
        }
2218
2219
        if ($this->orientacao == 'P') {
2220
            $maxW = $this->wPrint;
2221
            $title_size = 31;
2222
        } else {
2223
            $maxW = $this->wPrint - $this->wCanhoto;
2224
            $title_size = 40;
2225
        }
2226
        $w = $maxW / $campos_por_linha;
2227
2228
        $aFont = ['font'=>$this->fontePadrao, 'size'=>7, 'style'=>'B'];
2229
        $texto = "CÁLCULO DO IMPOSTO";
2230
        $this->pdf->textBox($x, $y, $title_size, 8, $texto, $aFont, 'T', 'L', 0, '');
2231
        $y += 3;
2232
        $h = 7;
2233
2234
        $x = $this->impostoHelper($x, $y, $w, $h, "BASE DE CÁLC. DO ICMS", "vBC");
2235
        $x = $this->impostoHelper($x, $y, $w, $h, "VALOR DO ICMS", "vICMS");
2236
        $x = $this->impostoHelper($x, $y, $w, $h, "BASE DE CÁLC. ICMS S.T.", "vBCST");
2237
        $x = $this->impostoHelper($x, $y, $w, $h, "VALOR DO ICMS SUBST.", "vST");
2238
        $x = $this->impostoHelper($x, $y, $w, $h, "V. IMP. IMPORTAÇÃO", "vII");
2239
2240
        if ($this->exibirIcmsInterestadual) {
2241
            $x = $this->impostoHelper($x, $y, $w, $h, "V. ICMS UF REMET.", "vICMSUFRemet");
2242
            $x = $this->impostoHelper($x, $y, $w, $h, "V. FCP UF DEST.", "vFCPUFDest");
2243
        }
2244
2245
        if ($this->exibirPIS) {
2246
            $x = $this->impostoHelper($x, $y, $w, $h, "VALOR DO PIS", "vPIS");
2247
        }
2248
2249
        $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...
2250
2251
        //
2252
2253
        $y += $h;
2254
        $x = $x_inicial;
2255
2256
        $x = $this->impostoHelper($x, $y, $w, $h, "VALOR DO FRETE", "vFrete");
2257
        $x = $this->impostoHelper($x, $y, $w, $h, "VALOR DO SEGURO", "vSeg");
2258
        $x = $this->impostoHelper($x, $y, $w, $h, "DESCONTO", "vDesc");
2259
        $x = $this->impostoHelper($x, $y, $w, $h, "OUTRAS DESPESAS", "vOutro");
2260
        $x = $this->impostoHelper($x, $y, $w, $h, "VALOR TOTAL IPI", "vIPI");
2261
2262
        if ($this->exibirIcmsInterestadual) {
2263
            $x = $this->impostoHelper($x, $y, $w, $h, "V. ICMS UF DEST.", "vICMSUFDest");
2264
            $x = $this->impostoHelper($x, $y, $w, $h, "V. TOT. TRIB.", "vTotTrib");
2265
        }
2266
2267
        if ($this->exibirPIS) {
2268
            $x = $this->impostoHelper($x, $y, $w, $h, "VALOR DA COFINS", "vCOFINS");
2269
        }
2270
        $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...
2271
2272
        return ($y+$h);
2273
    } //fim imposto
2274
2275
    /**
2276
     * transporte
2277
     * Monta o campo de transportes da DANFE (retrato e paisagem)
2278
     *
2279
     * @name   transporte
2280
     * @param  float $x Posição horizontal canto esquerdo
2281
     * @param  float $y Posição vertical canto superior
2282
     * @return float Posição vertical final
2283
     */
2284
    protected function transporte($x, $y)
2285
    {
2286
        $oldX = $x;
2287
        if ($this->orientacao == 'P') {
2288
            $maxW = $this->wPrint;
2289
        } else {
2290
            $maxW = $this->wPrint - $this->wCanhoto;
2291
        }
2292
        //#####################################################################
2293
        //TRANSPORTADOR / VOLUMES TRANSPORTADOS
2294
        $texto = "TRANSPORTADOR / VOLUMES TRANSPORTADOS";
2295
        $w = $maxW;
2296
        $h = 7;
2297
        $aFont = ['font'=>$this->fontePadrao, 'size'=>7, 'style'=>'B'];
2298
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 0, '');
2299
        //NOME / RAZÃO SOCIAL
2300
        $w1 = $maxW*0.29;
2301
        $y += 3;
2302
        $texto = 'NOME / RAZÃO SOCIAL';
2303
        $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
2304
        $this->pdf->textBox($x, $y, $w1, $h, $texto, $aFont, 'T', 'L', 1, '');
2305
        if (isset($this->transporta)) {
2306
            $texto = ! empty($this->transporta->getElementsByTagName("xNome")->item(0)->nodeValue)
2307
            ? $this->transporta->getElementsByTagName("xNome")->item(0)->nodeValue
2308
            : '';
2309
        } else {
2310
            $texto = '';
2311
        }
2312
        $aFont = ['font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B'];
2313
        $this->pdf->textBox($x, $y, $w1, $h, $texto, $aFont, 'B', 'L', 0, '');
2314
        //FRETE POR CONTA
2315
        $x += $w1;
2316
        $w2 = $maxW*0.15;
2317
        $texto = 'FRETE';
2318
        $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
2319
        $this->pdf->textBox($x, $y, $w2, $h, $texto, $aFont, 'T', 'L', 1, '');
2320
        $tipoFrete = ! empty($this->transp->getElementsByTagName("modFrete")->item(0)->nodeValue)
2321
        ? $this->transp->getElementsByTagName("modFrete")->item(0)->nodeValue
2322
        : '0';
2323
        switch ($tipoFrete) {
2324
            case 0:
2325
                $texto = "0-Por conta do Rem";
2326
                break;
2327
            case 1:
2328
                $texto = "1-Por conta do Dest";
2329
                break;
2330
            case 2:
2331
                $texto = "2-Por conta de Terceiros";
2332
                break;
2333
            case 3:
2334
                $texto = "3-Próprio por conta do Rem";
2335
                break;
2336
            case 4:
2337
                $texto = "4-Próprio por conta do Dest";
2338
                break;
2339
            case 9:
2340
                $texto = "9-Sem Transporte";
2341
                break;
2342
        }
2343
        $aFont = ['font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B'];
2344
        $this->pdf->textBox($x, $y, $w2, $h, $texto, $aFont, 'C', 'C', 1, '');
2345
        //CÓDIGO ANTT
2346
        $x += $w2;
2347
        $texto = 'CÓDIGO ANTT';
2348
        $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
2349
        $this->pdf->textBox($x, $y, $w2, $h, $texto, $aFont, 'T', 'L', 1, '');
2350
        if (isset($this->veicTransp)) {
2351
            $texto = ! empty($this->veicTransp->getElementsByTagName("RNTC")->item(0)->nodeValue)
2352
            ? $this->veicTransp->getElementsByTagName("RNTC")->item(0)->nodeValue
2353
            : '';
2354
        } else {
2355
            $texto = '';
2356
        }
2357
        $aFont = ['font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B'];
2358
        $this->pdf->textBox($x, $y, $w2, $h, $texto, $aFont, 'B', 'C', 0, '');
2359
        //PLACA DO VEÍC
2360
        $x += $w2;
2361
        $texto = 'PLACA DO VEÍCULO';
2362
        $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
2363
        $this->pdf->textBox($x, $y, $w2, $h, $texto, $aFont, 'T', 'L', 1, '');
2364
        if (isset($this->veicTransp)) {
2365
            $texto = ! empty($this->veicTransp->getElementsByTagName("placa")->item(0)->nodeValue)
2366
            ? $this->veicTransp->getElementsByTagName("placa")->item(0)->nodeValue
2367
            : '';
2368
        } elseif (isset($this->reboque)) {
2369
            $texto = ! empty($this->reboque->getElementsByTagName("placa")->item(0)->nodeValue)
2370
            ? $this->reboque->getElementsByTagName("placa")->item(0)->nodeValue
2371
            : '';
2372
        } else {
2373
            $texto = '';
2374
        }
2375
        $aFont = ['font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B'];
2376
        $this->pdf->textBox($x, $y, $w2, $h, $texto, $aFont, 'B', 'C', 0, '');
2377
        //UF
2378
        $x += $w2;
2379
        $w3 = round($maxW*0.04, 0);
2380
        $texto = 'UF';
2381
        $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
2382
        $this->pdf->textBox($x, $y, $w3, $h, $texto, $aFont, 'T', 'L', 1, '');
2383
        if (isset($this->veicTransp)) {
2384
            $texto = ! empty($this->veicTransp->getElementsByTagName("UF")->item(0)->nodeValue)
2385
            ? $this->veicTransp->getElementsByTagName("UF")->item(0)->nodeValue
2386
            : '';
2387
        } elseif (isset($this->reboque)) {
2388
            $texto = ! empty($this->reboque->getElementsByTagName("UF")->item(0)->nodeValue)
2389
            ? $this->reboque->getElementsByTagName("UF")->item(0)->nodeValue
2390
            : '';
2391
        } else {
2392
            $texto = '';
2393
        }
2394
        $aFont = ['font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B'];
2395
        $this->pdf->textBox($x, $y, $w3, $h, $texto, $aFont, 'B', 'C', 0, '');
2396
        //CNPJ / CPF
2397
        $x += $w3;
2398
        $w = $maxW-($w1+3*$w2+$w3);
2399
        $texto = 'CNPJ / CPF';
2400
        $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
2401
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 1, '');
2402
        if (isset($this->transporta)) {
2403
            $texto = ! empty($this->transporta->getElementsByTagName("CNPJ")->item(0)->nodeValue)
2404
            ? $this->formatField(
2405
                $this->transporta->getElementsByTagName("CNPJ")->item(0)->nodeValue,
2406
                "##.###.###/####-##"
2407
            )
2408
            : '';
2409
            if ($texto == '') {
2410
                $texto = ! empty($this->transporta->getElementsByTagName("CPF")->item(0)->nodeValue)
2411
                ? $this->formatField(
2412
                    $this->transporta->getElementsByTagName("CPF")->item(0)->nodeValue,
2413
                    "###.###.###-##"
2414
                )
2415
                : '';
2416
            }
2417
        } else {
2418
            $texto = '';
2419
        }
2420
        $aFont = ['font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B'];
2421
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'B', 'C', 0, '');
2422
        //#####################################################################
2423
        //ENDEREÇO
2424
        $y += $h;
2425
        $x = $oldX;
2426
        $h = 7;
2427
        $w1 = $maxW*0.44;
2428
        $texto = 'ENDEREÇO';
2429
        $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
2430
        $this->pdf->textBox($x, $y, $w1, $h, $texto, $aFont, 'T', 'L', 1, '');
2431
        if (isset($this->transporta)) {
2432
            $texto = ! empty($this->transporta->getElementsByTagName("xEnder")->item(0)->nodeValue)
2433
                ? $this->transporta->getElementsByTagName("xEnder")->item(0)->nodeValue
2434
                : '';
2435
        } else {
2436
            $texto = '';
2437
        }
2438
        $aFont = ['font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B'];
2439
        $this->pdf->textBox($x, $y, $w1, $h, $texto, $aFont, 'B', 'L', 0, '');
2440
        //MUNICÍPIO
2441
        $x += $w1;
2442
        $w2 = round($maxW*0.30, 0);
2443
        $texto = 'MUNICÍPIO';
2444
        $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
2445
        $this->pdf->textBox($x, $y, $w2, $h, $texto, $aFont, 'T', 'L', 1, '');
2446
        if (isset($this->transporta)) {
2447
            $texto = ! empty($this->transporta->getElementsByTagName("xMun")->item(0)->nodeValue)
2448
                ? $this->transporta->getElementsByTagName("xMun")->item(0)->nodeValue
2449
                : '';
2450
        } else {
2451
            $texto = '';
2452
        }
2453
        $aFont = ['font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B'];
2454
        $this->pdf->textBox($x, $y, $w2, $h, $texto, $aFont, 'B', 'C', 0, '');
2455
        //UF
2456
        $x += $w2;
2457
        $w3 = round($maxW*0.04, 0);
2458
        $texto = 'UF';
2459
        $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
2460
        $this->pdf->textBox($x, $y, $w3, $h, $texto, $aFont, 'T', 'L', 1, '');
2461
        if (isset($this->transporta)) {
2462
            $texto = ! empty($this->transporta->getElementsByTagName("UF")->item(0)->nodeValue)
2463
                ? $this->transporta->getElementsByTagName("UF")->item(0)->nodeValue
2464
                : '';
2465
        } else {
2466
            $texto = '';
2467
        }
2468
        $aFont = ['font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B'];
2469
        $this->pdf->textBox($x, $y, $w3, $h, $texto, $aFont, 'B', 'C', 0, '');
2470
        //INSCRIÇÃO ESTADUAL
2471
        $x += $w3;
2472
        $w = $maxW-($w1+$w2+$w3);
2473
        $texto = 'INSCRIÇÃO ESTADUAL';
2474
        $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
2475
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 1, '');
2476
        $texto = '';
2477
        if (isset($this->transporta)) {
2478
            if (! empty($this->transporta->getElementsByTagName("IE")->item(0)->nodeValue)) {
2479
                $texto = $this->transporta->getElementsByTagName("IE")->item(0)->nodeValue;
2480
            }
2481
        }
2482
        $aFont = ['font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B'];
2483
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'B', 'C', 0, '');
2484
        //Tratar Multiplos volumes
2485
        $volumes = $this->transp->getElementsByTagName('vol');
2486
        $quantidade = 0;
2487
        $especie = '';
2488
        $marca = '';
2489
        $numero = '';
2490
        $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...
2491
        $pesoBruto=0;
2492
        $pesoLiquido=0;
2493
        foreach ($volumes as $volume) {
2494
            $quantidade += ! empty($volume->getElementsByTagName("qVol")->item(0)->nodeValue) ?
2495
                    $volume->getElementsByTagName("qVol")->item(0)->nodeValue : 0;
2496
            $pesoBruto += ! empty($volume->getElementsByTagName("pesoB")->item(0)->nodeValue) ?
2497
                    $volume->getElementsByTagName("pesoB")->item(0)->nodeValue : 0;
2498
            $pesoLiquido += ! empty($volume->getElementsByTagName("pesoL")->item(0)->nodeValue) ?
2499
                    $volume->getElementsByTagName("pesoL")->item(0)->nodeValue : 0;
2500
            $texto = ! empty($this->transp->getElementsByTagName("esp")->item(0)->nodeValue) ?
2501
                    $this->transp->getElementsByTagName("esp")->item(0)->nodeValue : '';
2502
            if ($texto != $especie && $especie != '') {
2503
                //tem várias especies
2504
                $especie = 'VARIAS';
2505
            } else {
2506
                $especie = $texto;
2507
            }
2508
            $texto = ! empty($this->transp->getElementsByTagName("marca")->item(0)->nodeValue)
2509
                ? $this->transp->getElementsByTagName("marca")->item(0)->nodeValue
2510
                : '';
2511
            if ($texto != $marca && $marca != '') {
2512
                //tem várias especies
2513
                $marca = 'VARIAS';
2514
            } else {
2515
                $marca = $texto;
2516
            }
2517
            $texto = ! empty($this->transp->getElementsByTagName("nVol")->item(0)->nodeValue)
2518
                ? $this->transp->getElementsByTagName("nVol")->item(0)->nodeValue
2519
                : '';
2520
            if ($texto != $numero && $numero != '') {
2521
                //tem várias especies
2522
                $numero = 'VARIOS';
2523
            } else {
2524
                $numero = $texto;
2525
            }
2526
        }
2527
2528
        //#####################################################################
2529
        //QUANTIDADE
2530
        $y += $h;
2531
        $x = $oldX;
2532
        $h = 7;
2533
        $w1 = round($maxW*0.10, 0);
2534
        $texto = 'QUANTIDADE';
2535
        $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
2536
        $this->pdf->textBox($x, $y, $w1, $h, $texto, $aFont, 'T', 'L', 1, '');
2537
        if (!empty($quantidade)) {
2538
            $texto = $quantidade;
2539
            $aFont = ['font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B'];
2540
            $this->pdf->textBox($x, $y, $w1, $h, $texto, $aFont, 'B', 'C', 0, '');
2541
        }
2542
        //ESPÉCIE
2543
        $x += $w1;
2544
        $w2 = round($maxW*0.17, 0);
2545
        $texto = 'ESPÉCIE';
2546
        $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
2547
        $this->pdf->textBox($x, $y, $w2, $h, $texto, $aFont, 'T', 'L', 1, '');
2548
        $texto = $especie;
2549
        $aFont = ['font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B'];
2550
        $this->pdf->textBox($x, $y, $w2, $h, $texto, $aFont, 'B', 'C', 0, '');
2551
        //MARCA
2552
        $x += $w2;
2553
        $texto = 'MARCA';
2554
        $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
2555
        $this->pdf->textBox($x, $y, $w2, $h, $texto, $aFont, 'T', 'L', 1, '');
2556
        $texto = ! empty($this->transp->getElementsByTagName("marca")->item(0)->nodeValue) ?
2557
                $this->transp->getElementsByTagName("marca")->item(0)->nodeValue : '';
2558
        $aFont = ['font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B'];
2559
        $this->pdf->textBox($x, $y, $w2, $h, $texto, $aFont, 'B', 'C', 0, '');
2560
        //NUMERAÇÃO
2561
        $x += $w2;
2562
        $texto = 'NUMERAÇÃO';
2563
        $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
2564
        $this->pdf->textBox($x, $y, $w2, $h, $texto, $aFont, 'T', 'L', 1, '');
2565
        $texto = $numero;
2566
        $aFont = ['font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B'];
2567
        $this->pdf->textBox($x, $y, $w2, $h, $texto, $aFont, 'B', 'C', 0, '');
2568
        //PESO BRUTO
2569
        $x += $w2;
2570
        $w3 = round($maxW*0.20, 0);
2571
        $texto = 'PESO BRUTO';
2572
        $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
2573
        $this->pdf->textBox($x, $y, $w3, $h, $texto, $aFont, 'T', 'L', 1, '');
2574
        if (is_numeric($pesoBruto) && $pesoBruto > 0) {
2575
            $texto = number_format($pesoBruto, 3, ",", ".");
2576
        } else {
2577
            $texto = '';
2578
        }
2579
        $aFont = ['font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B'];
2580
        $this->pdf->textBox($x, $y, $w3, $h, $texto, $aFont, 'B', 'R', 0, '');
2581
        //PESO LÍQUIDO
2582
        $x += $w3;
2583
        $w = $maxW -($w1+3*$w2+$w3);
2584
        $texto = 'PESO LÍQUIDO';
2585
        $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
2586
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 1, '');
2587
        if (is_numeric($pesoLiquido) && $pesoLiquido > 0) {
2588
            $texto = number_format($pesoLiquido, 3, ",", ".");
2589
        } else {
2590
            $texto = '';
2591
        }
2592
        $aFont = ['font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B'];
2593
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'B', 'R', 0, '');
2594
        return ($y+$h);
2595
    } //fim transporte
2596
2597
2598
2599
    protected function descricaoProdutoHelper($origem, $campo, $formato)
2600
    {
2601
        $valor_original = $origem->getElementsByTagName($campo)->item(0);
2602
        if (!isset($valor_original)) {
2603
            return "";
2604
        }
2605
        $valor_original = $valor_original->nodeValue;
2606
        $valor = ! empty($valor_original) ? number_format($valor_original, 2, ",", ".") : '';
2607
2608
        if ($valor != "") {
2609
            return sprintf($formato, $valor);
2610
        }
2611
        return "";
2612
    }
2613
2614
    /**
2615
     * descricaoProduto
2616
     * Monta a string de descrição de cada Produto
2617
     *
2618
     * @name   descricaoProduto
2619
     * @param  DOMNode itemProd
2620
     * @return string descricao do produto
2621
     */
2622
    protected function descricaoProduto($itemProd)
2623
    {
2624
        $prod = $itemProd->getElementsByTagName('prod')->item(0);
2625
        $ICMS = $itemProd->getElementsByTagName("ICMS")->item(0);
2626
        $ICMSUFDest = $itemProd->getElementsByTagName("ICMSUFDest")->item(0);
2627
        $impostos = '';
2628
2629
        if (!empty($ICMS)) {
2630
            $impostos .= $this->descricaoProdutoHelper($ICMS, "vBCFCP", " BcFcp=%s");
2631
            $impostos .= $this->descricaoProdutoHelper($ICMS, "pFCP", " pFcp=%s%%");
2632
            $impostos .= $this->descricaoProdutoHelper($ICMS, "vFCP", " vFcp=%s");
2633
            $impostos .= $this->descricaoProdutoHelper($ICMS, "pRedBC", " pRedBC=%s%%");
2634
            $impostos .= $this->descricaoProdutoHelper($ICMS, "pMVAST", " IVA/MVA=%s%%");
2635
            $impostos .= $this->descricaoProdutoHelper($ICMS, "pICMSST", " pIcmsSt=%s%%");
2636
            $impostos .= $this->descricaoProdutoHelper($ICMS, "vBCST", " BcIcmsSt=%s");
2637
            $impostos .= $this->descricaoProdutoHelper($ICMS, "vICMSST", " vIcmsSt=%s");
2638
            $impostos .= $this->descricaoProdutoHelper($ICMS, "vBCFCPST", " BcFcpSt=%s");
2639
            $impostos .= $this->descricaoProdutoHelper($ICMS, "pFCPST", " pFcpSt=%s%%");
2640
            $impostos .= $this->descricaoProdutoHelper($ICMS, "vFCPST", " vFcpSt=%s");
2641
            $impostos .= $this->descricaoProdutoHelper($ICMS, "vBCSTRet", " vBcStRet=%s");
2642
            $impostos .= $this->descricaoProdutoHelper($ICMS, "pST", " pSt=%s");
2643
            $impostos .= $this->descricaoProdutoHelper($ICMS, "vICMSSTRet", " vIcmsStRet=%s");
2644
        }
2645
        if (!empty($ICMSUFDest)) {
2646
            $impostos .= $this->descricaoProdutoHelper($ICMSUFDest, "pFCPUFDest", " pFCPUFDest=%s%%");
2647
            $impostos .= $this->descricaoProdutoHelper($ICMSUFDest, "pICMSUFDest", " pICMSUFDest=%s%%");
2648
            $impostos .= $this->descricaoProdutoHelper($ICMSUFDest, "pICMSInterPart", " pICMSInterPart=%s%%");
2649
            $impostos .= $this->descricaoProdutoHelper($ICMSUFDest, "vFCPUFDest", " vFCPUFDest=%s");
2650
            $impostos .= $this->descricaoProdutoHelper($ICMSUFDest, "vICMSUFDest", " vICMSUFDest=%s");
2651
            $impostos .= $this->descricaoProdutoHelper($ICMSUFDest, "vICMSUFRemet", " vICMSUFRemet=%s");
2652
        }
2653
        $infAdProd = ! empty($itemProd->getElementsByTagName('infAdProd')->item(0)->nodeValue)
2654
        ? substr(
2655
            $this->anfaveaDANFE($itemProd->getElementsByTagName('infAdProd')->item(0)->nodeValue),
2656
            0,
2657
            500
2658
        )
2659
        : '';
2660
        if (! empty($infAdProd)) {
2661
            $infAdProd = trim($infAdProd);
2662
            $infAdProd .= ' ';
2663
        }
2664
        $loteTxt ='';
2665
        $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...
2666
        if (!empty($prod->getElementsByTagName("rastro"))) {
2667
            $rastro = $prod->getElementsByTagName("rastro");
2668
            $i = 0;
2669
            while ($i < $rastro->length) {
2670
                $loteTxt .= $this->getTagValue($rastro->item($i), 'nLote', ' Lote: ');
2671
                $loteTxt .= $this->getTagValue($rastro->item($i), 'qLote', ' Quant: ');
2672
                $loteTxt .= $this->getTagDate($rastro->item($i), 'dFab', ' Fab: ');
2673
                $loteTxt .= $this->getTagDate($rastro->item($i), 'dVal', ' Val: ');
2674
                $loteTxt .= $this->getTagValue($rastro->item($i), 'vPMC', ' PMC: ');
2675
                $i++;
2676
            }
2677
            if ($loteTxt != '') {
2678
                $loteTxt.= ' ';
2679
            }
2680
        }
2681
        //NT2013.006 FCI
2682
        $nFCI = (! empty($itemProd->getElementsByTagName('nFCI')->item(0)->nodeValue)) ?
2683
                ' FCI:'.$itemProd->getElementsByTagName('nFCI')->item(0)->nodeValue : '';
2684
        $tmp_ad=$infAdProd . ($this->descProdInfoComplemento ? $loteTxt . $impostos . $nFCI : '');
2685
        $texto = $prod->getElementsByTagName("xProd")->item(0)->nodeValue
2686
            . (strlen($tmp_ad)!=0?"\n    ".$tmp_ad:'');
2687
        //decodifica os caracteres html no xml
2688
        $texto = html_entity_decode($texto);
2689
        if ($this->descProdQuebraLinha) {
2690
            $texto = str_replace(";", "\n", $texto);
2691
        }
2692
        return $texto;
2693
    }
2694
2695
    /**
2696
     * itens
2697
     * Monta o campo de itens da DANFE (retrato e paisagem)
2698
     *
2699
     * @name   itens
2700
     * @param  float $x       Posição horizontal canto esquerdo
2701
     * @param  float $y       Posição vertical canto superior
2702
     * @param  float $nInicio Número do item inicial
2703
     * @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...
2704
     * @param  float $hmax    Altura máxima do campo de itens em mm
2705
     * @return float Posição vertical final
2706
     */
2707
    protected function itens($x, $y, &$nInicio, $hmax, $pag = 0, $totpag = 0, $hCabecItens = 7)
2708
    {
2709
        $oldX = $x;
2710
        $oldY = $y;
2711
        $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...
2712
        //#####################################################################
2713
        //DADOS DOS PRODUTOS / SERVIÇOS
2714
        $texto = "DADOS DOS PRODUTOS / SERVIÇOS ";
2715
        if ($this->orientacao == 'P') {
2716
            $w = $this->wPrint;
2717
        } else {
2718
            if ($nInicio < 2) { // primeira página
2719
                $w = $this->wPrint - $this->wCanhoto;
2720
            } else { // páginas seguintes
2721
                $w = $this->wPrint;
2722
            }
2723
        }
2724
        $h = 4;
2725
        $aFont = ['font'=>$this->fontePadrao, 'size'=>7, 'style'=>'B'];
2726
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 0, '');
2727
        $y += 3;
2728
        //desenha a caixa dos dados dos itens da NF
2729
        $hmax += 1;
2730
        $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...
2731
        $this->pdf->textBox($x, $y, $w, $hmax);
2732
        //##################################################################################
2733
        // cabecalho LOOP COM OS DADOS DOS PRODUTOS
2734
        //CÓDIGO PRODUTO
2735
        $texto = "CÓDIGO PRODUTO";
2736
        $w1 = round($w*0.09, 0);
2737
        $h = 4;
2738
        $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
2739
        $this->pdf->textBox($x, $y, $w1, $h, $texto, $aFont, 'C', 'C', 0, '', false);
2740
        $this->pdf->line($x+$w1, $y, $x+$w1, $y+$hmax);
2741
        //DESCRIÇÃO DO PRODUTO / SERVIÇO
2742
        $x += $w1;
2743
        $w2 = round($w*0.28, 0);
2744
        $texto = 'DESCRIÇÃO DO PRODUTO / SERVIÇO';
2745
        $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
2746
        $this->pdf->textBox($x, $y, $w2, $h, $texto, $aFont, 'C', 'C', 0, '', false);
2747
        $this->pdf->line($x+$w2, $y, $x+$w2, $y+$hmax);
2748
        //NCM/SH
2749
        $x += $w2;
2750
        $w3 = round($w*0.06, 0);
2751
        $texto = 'NCM/SH';
2752
        $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
2753
        $this->pdf->textBox($x, $y, $w3, $h, $texto, $aFont, 'C', 'C', 0, '', false);
2754
        $this->pdf->line($x+$w3, $y, $x+$w3, $y+$hmax);
2755
        //O/CST ou O/CSOSN
2756
        $x += $w3;
2757
        $w4 = round($w*0.05, 0);
2758
        $texto = 'O/CSOSN';//Regime do Simples CRT = 1 ou CRT = 2
2759
        if ($this->getTagValue($this->emit, 'CRT') == '3') {
2760
             $texto = 'O/CST';//Regime Normal
2761
        }
2762
        $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
2763
        $this->pdf->textBox($x, $y, $w4, $h, $texto, $aFont, 'C', 'C', 0, '', false);
2764
        $this->pdf->line($x+$w4, $y, $x+$w4, $y+$hmax);
2765
        //CFOP
2766
        $x += $w4;
2767
        $w5 = round($w*0.04, 0);
2768
        $texto = 'CFOP';
2769
        $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
2770
        $this->pdf->textBox($x, $y, $w5, $h, $texto, $aFont, 'C', 'C', 0, '', false);
2771
        $this->pdf->line($x+$w5, $y, $x+$w5, $y+$hmax);
2772
        //UN
2773
        $x += $w5;
2774
        $w6 = round($w*0.03, 0);
2775
        $texto = 'UN';
2776
        $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
2777
        $this->pdf->textBox($x, $y, $w6, $h, $texto, $aFont, 'C', 'C', 0, '', false);
2778
        $this->pdf->line($x+$w6, $y, $x+$w6, $y+$hmax);
2779
        //QUANT
2780
        $x += $w6;
2781
        $w7 = round($w*0.07, 0);
2782
        $texto = 'QUANT';
2783
        $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
2784
        $this->pdf->textBox($x, $y, $w7, $h, $texto, $aFont, 'C', 'C', 0, '', false);
2785
        $this->pdf->line($x+$w7, $y, $x+$w7, $y+$hmax);
2786
        //VALOR UNIT
2787
        $x += $w7;
2788
        $w8 = round($w*0.06, 0);
2789
        $texto = 'VALOR UNIT';
2790
        $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
2791
        $this->pdf->textBox($x, $y, $w8, $h, $texto, $aFont, 'C', 'C', 0, '', false);
2792
        $this->pdf->line($x+$w8, $y, $x+$w8, $y+$hmax);
2793
        //VALOR TOTAL
2794
        $x += $w8;
2795
        $w9 = round($w*0.06, 0);
2796
        $texto = 'VALOR TOTAL';
2797
        $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
2798
        $this->pdf->textBox($x, $y, $w9, $h, $texto, $aFont, 'C', 'C', 0, '', false);
2799
        $this->pdf->line($x+$w9, $y, $x+$w9, $y+$hmax);
2800
        //B.CÁLC ICMS
2801
        $x += $w9;
2802
        $w10 = round($w*0.06, 0);
2803
        $texto = 'B.CÁLC ICMS';
2804
        $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
2805
        $this->pdf->textBox($x, $y, $w10, $h, $texto, $aFont, 'C', 'C', 0, '', false);
2806
        $this->pdf->line($x+$w10, $y, $x+$w10, $y+$hmax);
2807
        //VALOR ICMS
2808
        $x += $w10;
2809
        $w11 = round($w*0.06, 0);
2810
        $texto = 'VALOR ICMS';
2811
        $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
2812
        $this->pdf->textBox($x, $y, $w11, $h, $texto, $aFont, 'C', 'C', 0, '', false);
2813
        $this->pdf->line($x+$w11, $y, $x+$w11, $y+$hmax);
2814
        //VALOR IPI
2815
        $x += $w11;
2816
        $w12 = round($w*0.05, 0);
2817
        $texto = 'VALOR IPI';
2818
        $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
2819
        $this->pdf->textBox($x, $y, $w12, $h, $texto, $aFont, 'C', 'C', 0, '', false);
2820
        $this->pdf->line($x+$w12, $y, $x+$w12, $y+$hmax);
2821
        //ALÍQ. ICMS
2822
        $x += $w12;
2823
        $w13 = round($w*0.035, 0);
2824
        $texto = 'ALÍQ. ICMS';
2825
        $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
2826
        $this->pdf->textBox($x, $y, $w13, $h, $texto, $aFont, 'C', 'C', 0, '', false);
2827
        $this->pdf->line($x+$w13, $y, $x+$w13, $y+$hmax);
2828
        //ALÍQ. IPI
2829
        $x += $w13;
2830
        $w14 = $w-($w1+$w2+$w3+$w4+$w5+$w6+$w7+$w8+$w9+$w10+$w11+$w12+$w13);
2831
        $texto = 'ALÍQ. IPI';
2832
        $this->pdf->textBox($x, $y, $w14, $h, $texto, $aFont, 'C', 'C', 0, '', false);
2833
        $this->pdf->line($oldX, $y+$h+1, $oldX + $w, $y+$h+1);
2834
        $y += 5;
2835
        //##################################################################################
2836
        // LOOP COM OS DADOS DOS PRODUTOS
2837
        $i = 0;
2838
        $hUsado = $hCabecItens;
2839
        $aFont = ['font'=>$this->fontePadrao, 'size'=>7, 'style'=>''];
2840
        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...
2841
            if ($i >= $nInicio) {
2842
                $thisItem = $this->det->item($i);
2843
                //carrega as tags do item
2844
                $prod = $thisItem->getElementsByTagName("prod")->item(0);
2845
                $imposto = $this->det->item($i)->getElementsByTagName("imposto")->item(0);
2846
                $ICMS = $imposto->getElementsByTagName("ICMS")->item(0);
2847
                $IPI  = $imposto->getElementsByTagName("IPI")->item(0);
2848
                $textoProduto = trim($this->descricaoProduto($thisItem));
2849
2850
                $linhaDescr = $this->pdf->getNumLines($textoProduto, $w2, $aFont);
2851
                $h = round(($linhaDescr * $this->pdf->fontSize)+ ($linhaDescr * 0.5), 2);
2852
                $hUsado += $h;
2853
2854
                $diffH = $hmax - $hUsado;
2855
2856
                if ($pag != $totpag) {
2857
                    if (1 > $diffH && $i < $totItens) {
2858
                        //ultrapassa a capacidade para uma única página
2859
                        //o restante dos dados serão usados nas proximas paginas
2860
                        $nInicio = $i;
2861
                        break;
2862
                    }
2863
                }
2864
                $y_linha=$y+$h;
2865
                // linha entre itens
2866
                $this->pdf->dashedHLine($oldX, $y_linha, $w, 0.1, 120);
2867
                //corrige o x
2868
                $x=$oldX;
2869
                //codigo do produto
2870
                $texto = $prod->getElementsByTagName("cProd")->item(0)->nodeValue;
2871
                $this->pdf->textBox($x, $y, $w1, $h, $texto, $aFont, 'T', 'C', 0, '');
2872
                $x += $w1;
2873
                //DESCRIÇÃO
2874
                if ($this->orientacao == 'P') {
2875
                    $this->pdf->textBox($x, $y, $w2, $h, $textoProduto, $aFont, 'T', 'L', 0, '', false);
2876
                } else {
2877
                    $this->pdf->textBox($x, $y, $w2, $h, $textoProduto, $aFont, 'T', 'L', 0, '', false);
2878
                }
2879
                $x += $w2;
2880
                //NCM
2881
                $texto = ! empty($prod->getElementsByTagName("NCM")->item(0)->nodeValue) ?
2882
                        $prod->getElementsByTagName("NCM")->item(0)->nodeValue : '';
2883
                $this->pdf->textBox($x, $y, $w3, $h, $texto, $aFont, 'T', 'C', 0, '');
2884
                $x += $w3;
2885
                //CST
2886
                if (isset($ICMS)) {
2887
                    $origem =  $this->getTagValue($ICMS, "orig");
2888
                    $cst =  $this->getTagValue($ICMS, "CST");
2889
                    $csosn =  $this->getTagValue($ICMS, "CSOSN");
2890
                    $texto = $origem.$cst.$csosn;
2891
                    $this->pdf->textBox($x, $y, $w4, $h, $texto, $aFont, 'T', 'C', 0, '');
2892
                }
2893
                //CFOP
2894
                $x += $w4;
2895
                $texto = $prod->getElementsByTagName("CFOP")->item(0)->nodeValue;
2896
                $this->pdf->textBox($x, $y, $w5, $h, $texto, $aFont, 'T', 'C', 0, '');
2897
                //Unidade
2898
                $x += $w5;
2899
                $texto = $prod->getElementsByTagName("uCom")->item(0)->nodeValue;
2900
                $this->pdf->textBox($x, $y, $w6, $h, $texto, $aFont, 'T', 'C', 0, '');
2901
                $x += $w6;
2902
                if ($this->orientacao == 'P') {
2903
                    $alinhamento = 'R';
2904
                } else {
2905
                    $alinhamento = 'R';
2906
                }
2907
                // QTDADE
2908
                $texto = number_format($prod->getElementsByTagName("qCom")->item(0)->nodeValue, 4, ",", ".");
2909
                $this->pdf->textBox($x, $y, $w7, $h, $texto, $aFont, 'T', $alinhamento, 0, '');
2910
                $x += $w7;
2911
                // Valor Unitário
2912
                $texto = number_format($prod->getElementsByTagName("vUnCom")->item(0)->nodeValue, 4, ",", ".");
2913
                $this->pdf->textBox($x, $y, $w8, $h, $texto, $aFont, 'T', $alinhamento, 0, '');
2914
                $x += $w8;
2915
                // Valor do Produto
2916
                $texto = "";
2917
                if (is_numeric($prod->getElementsByTagName("vProd")->item(0)->nodeValue)) {
2918
                    $texto = number_format($prod->getElementsByTagName("vProd")->item(0)->nodeValue, 2, ",", ".");
2919
                }
2920
                $this->pdf->textBox($x, $y, $w9, $h, $texto, $aFont, 'T', $alinhamento, 0, '');
2921
                //Valor da Base de calculo
2922
                $x += $w9;
2923
                if (isset($ICMS)) {
2924
                    $texto = ! empty($ICMS->getElementsByTagName("vBC")->item(0)->nodeValue)
2925
                    ? number_format(
2926
                        $ICMS->getElementsByTagName("vBC")->item(0)->nodeValue,
2927
                        2,
2928
                        ",",
2929
                        "."
2930
                    )
2931
                    : '0, 00';
2932
                    $this->pdf->textBox($x, $y, $w10, $h, $texto, $aFont, 'T', $alinhamento, 0, '');
2933
                }
2934
                //Valor do ICMS
2935
                $x += $w10;
2936
                if (isset($ICMS)) {
2937
                    $texto = ! empty($ICMS->getElementsByTagName("vICMS")->item(0)->nodeValue)
2938
                    ? number_format(
2939
                        $ICMS->getElementsByTagName("vICMS")->item(0)->nodeValue,
2940
                        2,
2941
                        ",",
2942
                        "."
2943
                    )
2944
                    : '0, 00';
2945
                    $this->pdf->textBox($x, $y, $w11, $h, $texto, $aFont, 'T', $alinhamento, 0, '');
2946
                }
2947
                //Valor do IPI
2948
                $x += $w11;
2949
                if (isset($IPI)) {
2950
                    $texto = ! empty($IPI->getElementsByTagName("vIPI")->item(0)->nodeValue)
2951
                    ? number_format(
2952
                        $IPI->getElementsByTagName("vIPI")->item(0)->nodeValue,
2953
                        2,
2954
                        ",",
2955
                        "."
2956
                    )
2957
                    :'';
2958
                } else {
2959
                    $texto = '';
2960
                }
2961
                $this->pdf->textBox($x, $y, $w12, $h, $texto, $aFont, 'T', $alinhamento, 0, '');
2962
                // %ICMS
2963
                $x += $w12;
2964
                if (isset($ICMS)) {
2965
                    $texto = ! empty($ICMS->getElementsByTagName("pICMS")->item(0)->nodeValue)
2966
                    ? number_format(
2967
                        $ICMS->getElementsByTagName("pICMS")->item(0)->nodeValue,
2968
                        2,
2969
                        ",",
2970
                        "."
2971
                    )
2972
                    : '0, 00';
2973
                    $this->pdf->textBox($x, $y, $w13, $h, $texto, $aFont, 'T', 'C', 0, '');
2974
                }
2975
                //%IPI
2976
                $x += $w13;
2977
                if (isset($IPI)) {
2978
                    $texto = ! empty($IPI->getElementsByTagName("pIPI")->item(0)->nodeValue)
2979
                    ? number_format(
2980
                        $IPI->getElementsByTagName("pIPI")->item(0)->nodeValue,
2981
                        2,
2982
                        ",",
2983
                        "."
2984
                    )
2985
                    : '';
2986
                } else {
2987
                    $texto = '';
2988
                }
2989
                $this->pdf->textBox($x, $y, $w14, $h, $texto, $aFont, 'T', 'C', 0, '');
2990
2991
2992
                // Dados do Veiculo Somente para veiculo 0 Km
2993
                $veicProd = $prod->getElementsByTagName("veicProd")->item(0);
2994
                // Tag somente é gerada para veiculo 0k, e só é permitido um veiculo por NF-e por conta do detran
2995
                // Verifica se a Tag existe
2996
                if (!empty($veicProd)) {
2997
                    $this->dadosItenVeiculoDANFE($oldX, $y, $nInicio, $h, $prod);
2998
                }
2999
3000
3001
                $y += $h;
3002
                $i++;
3003
                //incrementa o controle dos itens processados.
3004
                $this->qtdeItensProc++;
3005
            } else {
3006
                $i++;
3007
            }
3008
        }
3009
        return $oldY+$hmax;
3010
    }
3011
3012
3013
    /**
3014
     * dadosItenVeiculoDANFE
3015
     * Coloca os dados do veiculo abaixo do item da NFe. (retrato e paisagem)
3016
     *
3017
     * @param float  $x    Posição horizontal
3018
     *                     canto esquerdo
3019
     * @param float  $y    Posição vertical
3020
     *                     canto superior
3021
     * @param        $nInicio
3022
     * @param float  $h    altura do campo
3023
     * @param object $prod Contendo todos os dados do item
3024
     */
3025
3026
    protected function dadosItenVeiculoDANFE($x, $y, &$nInicio, $h, $prod)
3027
    {
3028
        $oldX = $x;
3029
        $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...
3030
3031
        if ($this->orientacao == 'P') {
3032
            $w = $this->wPrint;
3033
        } else {
3034
            if ($nInicio < 2) { // primeira página
3035
                $w = $this->wPrint - $this->wCanhoto;
3036
            } else { // páginas seguintes
3037
                $w = $this->wPrint;
3038
            }
3039
        }
3040
3041
        $aFont = ['font'=>$this->fontePadrao, 'size'=>7, 'style'=>''];
3042
3043
        $w1 = round($w*0.09, 0);
3044
3045
        // Tabela Renavam Combustivel
3046
        $renavamCombustivel = [
3047
            1=>'ALCOOL',
3048
            2=>'GASOLINA',
3049
            3=>'DIESEL',
3050
            4=>'GASOGENIO',
3051
            5=>'GAS METANO',
3052
            6=>'ELETRICO/FONTE INTERNA',
3053
            7=>'ELETRICO/FONTE EXTERNA',
3054
            8=>'GASOL/GAS NATURAL COMBUSTIVEL',
3055
            9=>'ALCOOL/GAS NATURAL COMBUSTIVEL',
3056
            10=>'DIESEL/GAS NATURAL COMBUSTIVEL',
3057
            11=>'VIDE/CAMPO/OBSERVACAO',
3058
            12=>'ALCOOL/GAS NATURAL VEICULAR',
3059
            13=>'GASOLINA/GAS NATURAL VEICULAR',
3060
            14=>'DIESEL/GAS NATURAL VEICULAR',
3061
            15=>'GAS NATURAL VEICULAR',
3062
            16=>'ALCOOL/GASOLINA',
3063
            17=>'GASOLINA/ALCOOL/GAS NATURAL',
3064
            18=>'GASOLINA/ELETRICO'
3065
        ];
3066
3067
        $renavamEspecie = [
3068
            1=>'PASSAGEIRO',
3069
            2=>'CARGA',
3070
            3=>'MISTO',
3071
            4=>'CORRIDA',
3072
            5=>'TRACAO',
3073
            6=>'ESPECIAL',
3074
            7=>'COLECAO'
3075
        ];
3076
3077
        $renavamTiposVeiculos = [
3078
            1=>'BICICLETA',
3079
            2=>'CICLOMOTOR',
3080
            3=>'MOTONETA',
3081
            4=>'MOTOCICLETA',
3082
            5=>'TRICICLO',
3083
            6=>'AUTOMOVEL',
3084
            7=>'MICROONIBUS',
3085
            8=>'ONIBUS',
3086
            9=>'BONDE',
3087
            10=>'REBOQUE',
3088
            11=>'SEMI-REBOQUE',
3089
            12=>'CHARRETE',
3090
            13=>'CAMIONETA',
3091
            14=>'CAMINHAO',
3092
            15=>'CARROCA',
3093
            16=>'CARRO DE MAO',
3094
            17=>'CAMINHAO TRATOR',
3095
            18=>'TRATOR DE RODAS',
3096
            19=>'TRATOR DE ESTEIRAS',
3097
            20=>'TRATOR MISTO',
3098
            21=>'QUADRICICLO',
3099
            22=>'CHASSI/PLATAFORMA',
3100
            23=>'CAMINHONETE',
3101
            24=>'SIDE-CAR',
3102
            25=>'UTILITARIO',
3103
            26=>'MOTOR-CASA'
3104
        ];
3105
3106
        $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...
3107
            'F'=>'FOSCA',
3108
            'S'=>'SÓLIDA',
3109
            'P'=>'PEROLIZADA',
3110
            'M'=>'METALICA',
3111
        ];
3112
3113
        $veicProd = $prod->getElementsByTagName("veicProd")->item(0);
3114
3115
        $veiculoChassi = $veicProd->getElementsByTagName("chassi")->item(0)->nodeValue;
3116
        $veiculoCor = $veicProd->getElementsByTagName("xCor")->item(0)->nodeValue;
3117
        $veiculoCilindrada = $veicProd->getElementsByTagName("cilin")->item(0)->nodeValue;
3118
        $veiculoCmkg = $veicProd->getElementsByTagName("CMT")->item(0)->nodeValue;
3119
        $veiculoTipo = $veicProd->getElementsByTagName("tpVeic")->item(0)->nodeValue;
3120
3121
        $veiculoMotor = $veicProd->getElementsByTagName("nMotor")->item(0)->nodeValue;
3122
        $veiculoRenavam = $veicProd->getElementsByTagName("cMod")->item(0)->nodeValue;
3123
        $veiculoHp = $veicProd->getElementsByTagName("pot")->item(0)->nodeValue;
3124
        $veiculoPlaca = ''; //$veiculo->getElementsByTagName("CMT")->item(0)->nodeValue;
3125
        $veiculoTipoPintura = $veicProd->getElementsByTagName("tpPint")->item(0)->nodeValue;
3126
        $veiculoMarcaModelo = $prod->getElementsByTagName("xProd")->item(0)->nodeValue;
3127
        $veiculoEspecie = $veicProd->getElementsByTagName("espVeic")->item(0)->nodeValue;
3128
        $veiculoCombustivel = $veicProd->getElementsByTagName("tpComb")->item(0)->nodeValue;
3129
        $veiculoSerial = $veicProd->getElementsByTagName("nSerie")->item(0)->nodeValue;
3130
        $veiculoFabricacao = $veicProd->getElementsByTagName("anoFab")->item(0)->nodeValue;
3131
        $veiculoModelo = $veicProd->getElementsByTagName("anoMod")->item(0)->nodeValue;
3132
        $veiculoDistancia = $veicProd->getElementsByTagName("dist")->item(0)->nodeValue;
3133
3134
        $x = $oldX;
3135
3136
        $yVeic = $y + $h;
3137
        $texto = 'Chassi: ............: ' . $veiculoChassi;
3138
        $this->pdf->textBox($x, $yVeic, $w1+40, $h, $texto, $aFont, 'T', 'L', 0, '');
3139
        $yVeic += $h;
3140
        $texto = 'Cor...................: ' . $veiculoCor;
3141
        $this->pdf->textBox($x, $yVeic, $w1+40, $h, $texto, $aFont, 'T', 'L', 0, '');
3142
        $yVeic += $h;
3143
        $texto = 'Cilindrada........: ' . $veiculoCilindrada;
3144
        $this->pdf->textBox($x, $yVeic, $w1+40, $h, $texto, $aFont, 'T', 'L', 0, '');
3145
        $yVeic += $h;
3146
        $texto = 'Cmkg...............: ' . $veiculoCmkg;
3147
        $this->pdf->textBox($x, $yVeic, $w1+40, $h, $texto, $aFont, 'T', 'L', 0, '');
3148
        $yVeic += $h;
3149
        $texto = 'Tipo.................: ' . ($renavamTiposVeiculos[intval($veiculoTipo)] ?? $veiculoTipo);
3150
         $this->pdf->textBox($x, $yVeic, $w1+40, $h, $texto, $aFont, 'T', 'L', 0, '');
3151
        $yVeic = $y + $h;
3152
        $xVeic = $x + 65;
3153
        $texto = 'Nº Motor: .........: ' . $veiculoMotor;
3154
        $this->pdf->textBox($xVeic, $yVeic, $w1+50, $h, $texto, $aFont, 'T', 'L', 0, '');
3155
        $yVeic += $h;
3156
        $texto = 'Renavam...........: ' . $veiculoRenavam;
3157
        $this->pdf->textBox($xVeic, $yVeic, $w1+50, $h, $texto, $aFont, 'T', 'L', 0, '');
3158
        $yVeic += $h;
3159
        $texto = 'HP.....................: ' . $veiculoHp;
3160
        $this->pdf->textBox($xVeic, $yVeic, $w1+50, $h, $texto, $aFont, 'T', 'L', 0, '');
3161
        $yVeic += $h;
3162
        $texto = 'Placa.................: ' . $veiculoPlaca;
3163
        $this->pdf->textBox($xVeic, $yVeic, $w1+50, $h, $texto, $aFont, 'T', 'L', 0, '');
3164
        $yVeic += $h;
3165
        $texto = 'Tipo Pintura......: ' . ($renavamEspecie[intval($veiculoTipoPintura)] ?? $veiculoTipoPintura);
3166
        $this->pdf->textBox($xVeic, $yVeic, $w1+50, $h, $texto, $aFont, 'T', 'L', 0, '');
3167
        $yVeic = $y + $h;
3168
        $xVeic = $xVeic + 55;
3169
        $texto = 'Marca / Modelo.....: ' . $veiculoMarcaModelo;
3170
        $this->pdf->textBox($xVeic, $yVeic, $w1+50, $h, $texto, $aFont, 'T', 'L', 0, '');
3171
        $yVeic += $h;
3172
        $texto = 'Especie..................: ' . ($renavamEspecie[intval($veiculoEspecie)] ?? $veiculoEspecie);
3173
        $this->pdf->textBox($xVeic, $yVeic, $w1+50, $h, $texto, $aFont, 'T', 'L', 0, '');
3174
        $yVeic += $h;
3175
        $texto = 'Combustivel..........: ' . ($renavamCombustivel[intval($veiculoCombustivel)] ?? $veiculoCombustivel);
3176
        $this->pdf->textBox($xVeic, $yVeic, $w1+50, $h, $texto, $aFont, 'T', 'L', 0, '');
3177
        $yVeic += $h;
3178
        $texto = 'Serial.....................: ' . $veiculoSerial;
3179
        $this->pdf->textBox($xVeic, $yVeic, $w1+50, $h, $texto, $aFont, 'T', 'L', 0, '');
3180
        $yVeic += $h;
3181
        $texto = 'Ano Fab/Mod........: '. $veiculoFabricacao . '/' . $veiculoModelo;
3182
        $this->pdf->textBox($xVeic, $yVeic, $w1+50, $h, $texto, $aFont, 'T', 'L', 0, '');
3183
        $yVeic += $h;
3184
        $texto = 'Distancia Entre Eixos(mm)..: '. $veiculoDistancia;
3185
        $this->pdf->textBox($xVeic, $yVeic, $w1+50, $h, $texto, $aFont, 'T', 'L', 0, '');
3186
    }
3187
3188
    /**
3189
     * issqn
3190
     * Monta o campo de serviços do DANFE
3191
     *
3192
     * @name   issqn (retrato e paisagem)
3193
     * @param  float $x Posição horizontal canto esquerdo
3194
     * @param  float $y Posição vertical canto superior
3195
     * @return float Posição vertical final
3196
     */
3197
    protected function issqn($x, $y)
3198
    {
3199
        $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...
3200
        //#####################################################################
3201
        //CÁLCULO DO ISSQN
3202
        $texto = "CÁLCULO DO ISSQN";
3203
        $w = $this->wPrint;
3204
        $h = 7;
3205
        $aFont = ['font'=>$this->fontePadrao, 'size'=>7, 'style'=>'B'];
3206
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 0, '');
3207
        //INSCRIÇÃO MUNICIPAL
3208
        $y += 3;
3209
        $w = round($this->wPrint*0.23, 0);
3210
        $texto = 'INSCRIÇÃO MUNICIPAL';
3211
        $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
3212
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 1, '');
3213
        //inscrição municipal
3214
        $texto = ! empty($this->emit->getElementsByTagName("IM")->item(0)->nodeValue) ?
3215
                $this->emit->getElementsByTagName("IM")->item(0)->nodeValue : '';
3216
        $aFont = ['font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B'];
3217
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'B', 'L', 0, '');
3218
        //VALOR TOTAL DOS SERVIÇOS
3219
        $x += $w;
3220
        $texto = 'VALOR TOTAL DOS SERVIÇOS';
3221
        $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
3222
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 1, '');
3223
        if (isset($this->ISSQNtot)) {
3224
            $texto = ! empty($this->ISSQNtot->getElementsByTagName("vServ")->item(0)->nodeValue) ?
3225
                    $this->ISSQNtot->getElementsByTagName("vServ")->item(0)->nodeValue : '';
3226
            $texto = number_format($texto, 2, ",", ".");
3227
        } else {
3228
            $texto = '';
3229
        }
3230
        $aFont = ['font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B'];
3231
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'B', 'R', 0, '');
3232
        //BASE DE CÁLCULO DO ISSQN
3233
        $x += $w;
3234
        $texto = 'BASE DE CÁLCULO DO ISSQN';
3235
        $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
3236
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 1, '');
3237
        if (isset($this->ISSQNtot)) {
3238
            $texto = ! empty($this->ISSQNtot->getElementsByTagName("vBC")->item(0)->nodeValue) ?
3239
                    $this->ISSQNtot->getElementsByTagName("vBC")->item(0)->nodeValue : '';
3240
            $texto = ! empty($texto) ? number_format($texto, 2, ",", ".") : '';
3241
        } else {
3242
            $texto = '';
3243
        }
3244
        $aFont = ['font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B'];
3245
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'B', 'R', 0, '');
3246
        //VALOR TOTAL DO ISSQN
3247
        $x += $w;
3248
        if ($this->orientacao == 'P') {
3249
            $w = $this->wPrint - (3 * $w);
3250
        } else {
3251
            $w = $this->wPrint - (3 * $w)-$this->wCanhoto;
3252
        }
3253
        $texto = 'VALOR TOTAL DO ISSQN';
3254
        $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
3255
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 1, '');
3256
        if (isset($this->ISSQNtot)) {
3257
            $texto = ! empty($this->ISSQNtot->getElementsByTagName("vISS")->item(0)->nodeValue) ?
3258
                    $this->ISSQNtot->getElementsByTagName("vISS")->item(0)->nodeValue : '';
3259
            $texto = ! empty($texto) ? number_format($texto, 2, ",", ".") : '';
3260
        } else {
3261
            $texto = '';
3262
        }
3263
        $aFont = ['font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B'];
3264
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'B', 'R', 0, '');
3265
        return ($y+$h+1);
3266
    }
3267
3268
    /**
3269
     *dadosAdicionais
3270
     * Coloca o grupo de dados adicionais da NFe. (retrato e paisagem)
3271
     *
3272
     * @name   dadosAdicionais
3273
     * @param  float $x Posição horizontal canto esquerdo
3274
     * @param  float $y Posição vertical canto superior
3275
     * @param  float $h altura do campo
3276
     * @return float Posição vertical final (eixo Y)
3277
     */
3278
    protected function dadosAdicionais($x, $y, $h)
3279
    {
3280
        //##################################################################################
3281
        //DADOS ADICIONAIS
3282
        $texto = "DADOS ADICIONAIS";
3283
        if ($this->orientacao == 'P') {
3284
              $w = $this->wPrint;
3285
        } else {
3286
              $w = $this->wPrint-$this->wCanhoto;
3287
        }
3288
        $aFont = ['font'=>$this->fontePadrao, 'size'=>7, 'style'=>'B'];
3289
        $this->pdf->textBox($x, $y, $w, 8, $texto, $aFont, 'T', 'L', 0, '');
3290
        //INFORMAÇÕES COMPLEMENTARES
3291
        $texto = "INFORMAÇÕES COMPLEMENTARES";
3292
        $y += 3;
3293
        $w = $this->wAdic;
3294
        $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>'B'];
3295
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 1, '');
3296
        //o texto com os dados adicionais foi obtido na função montaDANFE
3297
        //e carregado em uma propriedade privada da classe
3298
        //$this->wAdic com a largura do campo
3299
        //$this->textoAdic com o texto completo do campo
3300
        $y += 1;
3301
        $aFont = ['font'=>$this->fontePadrao, 'size'=>7, 'style'=>''];
3302
        $this->pdf->textBox($x, $y+2, $w-2, $h-3, $this->textoAdic, $aFont, 'T', 'L', 0, '', false);
3303
        //RESERVADO AO FISCO
3304
        $texto = "RESERVADO AO FISCO";
3305
        $x += $w;
3306
        $y -= 1;
3307
        if ($this->orientacao == 'P') {
3308
            $w = $this->wPrint-$w;
3309
        } else {
3310
            $w = $this->wPrint-$w-$this->wCanhoto;
3311
        }
3312
        $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>'B'];
3313
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 1, '');
3314
        //inserir texto informando caso de contingência
3315
        // 1 - Normal - emissão normal;
3316
        // 2 - Contingência FS - emissão em contingência com impressão do DANFE em Formulário de Segurança;
3317
        // 3 - Contingência SCAN - emissão em contingência no Sistema de Contingência do Ambiente Nacional;
3318
        // 4 - Contingência DPEC - emissão em contingência com envio da Declaração
3319
        //     Prévia de Emissão em Contingência;
3320
        // 5 - Contingência FS-DA - emissão em contingência com impressão do DANFE em Formulário de
3321
        //     Segurança para Impressão de Documento Auxiliar de Documento Fiscal Eletrônico (FS-DA);
3322
        // 6 - Contingência SVC-AN
3323
        // 7 - Contingência SVC-RS
3324
        $xJust = $this->getTagValue($this->ide, 'xJust', 'Justificativa: ');
3325
        $dhCont = $this->getTagValue($this->ide, 'dhCont', ' Entrada em contingência : ');
3326
        $texto = '';
3327
        switch ($this->tpEmis) {
3328
            case 2:
3329
                $texto = 'CONTINGÊNCIA FS' . $dhCont . $xJust;
3330
                break;
3331
            case 3:
3332
                $texto = 'CONTINGÊNCIA SCAN' . $dhCont . $xJust;
3333
                break;
3334
            case 4:
3335
                $texto = 'CONTINGÊNCIA DPEC' . $dhCont . $xJust;
3336
                break;
3337
            case 5:
3338
                $texto = 'CONTINGÊNCIA FSDA' . $dhCont . $xJust;
3339
                break;
3340
            case 6:
3341
                $texto = 'CONTINGÊNCIA SVC-AN' . $dhCont . $xJust;
3342
                break;
3343
            case 7:
3344
                $texto = 'CONTINGÊNCIA SVC-RS' . $dhCont . $xJust;
3345
                break;
3346
        }
3347
        $y += 2;
3348
        $aFont = ['font'=>$this->fontePadrao, 'size'=>7, 'style'=>''];
3349
        $this->pdf->textBox($x, $y, $w-2, $h-3, $texto, $aFont, 'T', 'L', 0, '', false);
3350
        return $y+$h;
3351
    }
3352
3353
    /**
3354
     * rodape
3355
     * Monta o rodapé no final da DANFE com a data/hora de impressão e informações
3356
     * sobre a API NfePHP
3357
     *
3358
     * @param  float $x  Posição horizontal canto esquerdo
3359
     *
3360
     * @return void
3361
     */
3362
    protected function rodape($x)
3363
    {
3364
        
3365
        $y = $this->maxH - 4;
3366
        if ($this->orientacao == 'P') {
3367
              $w = $this->wPrint;
3368
        } else {
3369
              $w = $this->wPrint-$this->wCanhoto;
3370
              $x = $this->wCanhoto;
3371
        }
3372
        $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>'I'];
3373
        $texto = "Impresso em ". date('d/m/Y') . " as " . date('H:i:s')
3374
            . '  ' . $this->creditos;
3375
        $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...
3376
        $texto = "Powered by NFePHP®";
3377
        $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...
3378
    }
3379
3380
    /**
3381
     * pCcanhotoDANFE
3382
     * Monta o canhoto da DANFE (retrato e paisagem)
3383
     *
3384
     * @name   canhotoDANFE
3385
     * @param  number $x Posição horizontal canto esquerdo
3386
     * @param  number $y Posição vertical canto superior
3387
     * @return number Posição vertical final
3388
     *
3389
     * TODO 21/07/14 fmertins: quando orientação L-paisagem, o canhoto está sendo gerado incorretamente
3390
     */
3391
    protected function canhoto($x, $y)
3392
    {
3393
        $oldX = $x;
3394
        $oldY = $y;
3395
        //#################################################################################
3396
        //canhoto
3397
        //identificação do tipo de nf entrada ou saida
3398
        $tpNF = $this->ide->getElementsByTagName('tpNF')->item(0)->nodeValue;
3399
        if ($tpNF == '0') {
3400
            //NFe de Entrada
3401
            $emitente = '';
3402
            $emitente .= $this->dest->getElementsByTagName("xNome")->item(0)->nodeValue . " - ";
3403
            $emitente .= $this->enderDest->getElementsByTagName("xLgr")->item(0)->nodeValue . ", ";
3404
            $emitente .= $this->enderDest->getElementsByTagName("nro")->item(0)->nodeValue . " - ";
3405
            $emitente .= $this->getTagValue($this->enderDest, "xCpl", " - ", " ");
3406
            $emitente .= $this->enderDest->getElementsByTagName("xBairro")->item(0)->nodeValue . " ";
3407
            $emitente .= $this->enderDest->getElementsByTagName("xMun")->item(0)->nodeValue . "-";
3408
            $emitente .= $this->enderDest->getElementsByTagName("UF")->item(0)->nodeValue . "";
3409
            $destinatario = $this->emit->getElementsByTagName("xNome")->item(0)->nodeValue . " ";
3410
        } else {
3411
            //NFe de Saída
3412
            $emitente = $this->emit->getElementsByTagName("xNome")->item(0)->nodeValue . " ";
3413
            $destinatario = '';
3414
            $destinatario .= $this->dest->getElementsByTagName("xNome")->item(0)->nodeValue . " - ";
3415
            $destinatario .= $this->enderDest->getElementsByTagName("xLgr")->item(0)->nodeValue . ", ";
3416
            $destinatario .= $this->enderDest->getElementsByTagName("nro")->item(0)->nodeValue . " ";
3417
            $destinatario .= $this->getTagValue($this->enderDest, "xCpl", " - ", " ");
3418
            $destinatario .= $this->enderDest->getElementsByTagName("xBairro")->item(0)->nodeValue . " ";
3419
            $destinatario .= $this->enderDest->getElementsByTagName("xMun")->item(0)->nodeValue . "-";
3420
            $destinatario .= $this->enderDest->getElementsByTagName("UF")->item(0)->nodeValue . " ";
3421
        }
3422
        //identificação do sistema emissor
3423
        //linha separadora do canhoto
3424
        if ($this->orientacao == 'P') {
3425
            $w = round($this->wPrint * 0.81, 0);
3426
        } else {
3427
            //linha separadora do canhoto - 238
3428
            //posicao altura
3429
            $y = $this->wPrint-85;
3430
            //altura
3431
            $w = $this->wPrint-85-24;
3432
        }
3433
        $h = 10;
3434
        //desenha caixa
3435
        $texto = '';
3436
        $aFont = ['font'=>$this->fontePadrao, 'size'=>7, 'style'=>''];
3437
        $aFontSmall = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
3438
        if ($this->orientacao == 'P') {
3439
            $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'C', 'L', 1, '', false);
3440
        } else {
3441
            $this->pdf->textBox90($x, $y, $w, $h, $texto, $aFont, 'C', 'L', 1, '', false);
3442
        }
3443
        $numNF = str_pad($this->ide->getElementsByTagName('nNF')->item(0)->nodeValue, 9, "0", STR_PAD_LEFT);
3444
        $serie = str_pad($this->ide->getElementsByTagName('serie')->item(0)->nodeValue, 3, "0", STR_PAD_LEFT);
3445
        $texto = "RECEBEMOS DE ";
3446
        $texto .= $emitente;
3447
        $texto .= " OS PRODUTOS E/OU SERVIÇOS CONSTANTES DA NOTA FISCAL ELETRÔNICA INDICADA ";
3448
        if ($this->orientacao == 'P') {
3449
            $texto .= "ABAIXO";
3450
        } else {
3451
            $texto .= "AO LADO";
3452
        }
3453
        $texto .= ". EMISSÃO: ";
3454
        $dEmi = ! empty($this->ide->getElementsByTagName("dEmi")->item(0)->nodeValue) ?
3455
                $this->ide->getElementsByTagName("dEmi")->item(0)->nodeValue : '';
3456
        if ($dEmi == '') {
3457
            $dEmi = ! empty($this->ide->getElementsByTagName("dhEmi")->item(0)->nodeValue) ?
3458
                    $this->ide->getElementsByTagName("dhEmi")->item(0)->nodeValue : '';
3459
            $aDemi = explode('T', $dEmi);
3460
            $dEmi = $aDemi[0];
3461
        }
3462
        $texto .= $this->ymdTodmy($dEmi) ." ";
3463
        $texto .= "VALOR TOTAL: R$ ";
3464
        $texto .= number_format($this->ICMSTot->getElementsByTagName("vNF")->item(0)->nodeValue, 2, ",", ".") . " ";
3465
        $texto .= "DESTINATÁRIO: ";
3466
        $texto .= $destinatario;
3467
        if ($this->orientacao == 'P') {
3468
            $this->pdf->textBox($x, $y, $w-1, $h, $texto, $aFont, 'C', 'L', 0, '', false);
3469
            $x1 = $x + $w;
3470
            $w1 = $this->wPrint - $w;
3471
            $texto = "NF-e";
3472
            $aFont = ['font'=>$this->fontePadrao, 'size'=>14, 'style'=>'B'];
3473
            $this->pdf->textBox($x1, $y, $w1, 18, $texto, $aFont, 'T', 'C', 0, '');
3474
            $texto = "Nº. " . $this->formatField($numNF, "###.###.###") . " \n";
3475
            $texto .= "Série $serie";
3476
            $aFont = ['font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B'];
3477
            $this->pdf->textBox($x1, $y, $w1, 18, $texto, $aFont, 'C', 'C', 1, '');
3478
            //DATA DE RECEBIMENTO
3479
            $texto = "DATA DE RECEBIMENTO";
3480
            $y += $h;
3481
            $w2 = round($this->wPrint*0.17, 0); //35;
3482
            $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
3483
            $this->pdf->textBox($x, $y, $w2, 8, $texto, $aFont, 'T', 'L', 1, '');
3484
            //IDENTIFICAÇÃO E ASSINATURA DO RECEBEDOR
3485
            $x += $w2;
3486
            $w3 = $w-$w2;
3487
            $texto = "IDENTIFICAÇÃO E ASSINATURA DO RECEBEDOR";
3488
            $this->pdf->textBox($x, $y, $w3, 8, $texto, $aFont, 'T', 'L', 1, '');
3489
            $x = $oldX;
3490
            $y += 9;
3491
            $this->pdf->dashedHLine($x, $y, $this->wPrint, 0.1, 80);
3492
            $y += 2;
3493
            return $y;
3494
        } else {
3495
            $x--;
3496
            $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...
3497
            //NUMERO DA NOTA FISCAL LOGO NFE
3498
            $w1 = 18;
3499
            $x1 = $oldX;
3500
            $y = $oldY;
3501
            $texto = "NF-e";
3502
            $aFont = ['font'=>$this->fontePadrao, 'size'=>14, 'style'=>'B'];
3503
            $this->pdf->textBox($x1, $y, $w1, 18, $texto, $aFont, 'T', 'C', 0, '');
3504
            $texto = "Nº.\n" . $this->formatField($numNF, "###.###.###") . " \n";
3505
            $texto .= "Série $serie";
3506
            $aFont = ['font'=>$this->fontePadrao, 'size'=>8, 'style'=>'B'];
3507
            $this->pdf->textBox($x1, $y, $w1, 18, $texto, $aFont, 'C', 'C', 1, '');
3508
            //DATA DO RECEBIMENTO
3509
            $texto = "DATA DO RECEBIMENTO";
3510
            $y = $this->wPrint-85;
3511
            $x = 12;
3512
            $w2 = round($this->wPrint*0.17, 0); //35;
3513
            $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
3514
            $this->pdf->textBox90($x, $y, $w2, 8, $texto, $aFont, 'T', 'L', 1, '');
3515
            //IDENTIFICAÇÃO E ASSINATURA DO RECEBEDOR
3516
            $y -= $w2;
3517
            $w3 = $w-$w2;
3518
            $texto = "IDENTIFICAÇÃO E ASSINATURA DO RECEBEDOR";
3519
            $aFont = ['font'=>$this->fontePadrao, 'size'=>5.7, 'style'=>''];
3520
            $x = $this->pdf->textBox90($x, $y, $w3, 8, $texto, $aFont, 'T', 'L', 1, '');
3521
            $this->pdf->dashedVLine(22, $oldY, 0.1, $this->wPrint, 69);
3522
            return $x;
3523
        }
3524
    }
3525
3526
    /**
3527
     * geraInformacoesDaTagCompra
3528
     * Devolve uma string contendo informação sobre as tag <compra><xNEmp>, <xPed> e <xCont> ou string vazia.
3529
     * Aviso: Esta função não leva em consideração dados na tag xPed do item.
3530
     *
3531
     * @name   pGeraInformacoesDaTagCompra
3532
     * @return string com as informacoes dos pedidos.
3533
     */
3534
    protected function geraInformacoesDaTagCompra()
3535
    {
3536
        $saida = "";
3537
        if (isset($this->compra)) {
3538
            if (! empty($this->compra->getElementsByTagName("xNEmp")->item(0)->nodeValue)) {
3539
                $saida .= " Nota de Empenho: " . $this->compra->getElementsByTagName("xNEmp")->item(0)->nodeValue;
3540
            }
3541
            if (! empty($this->compra->getElementsByTagName("xPed")->item(0)->nodeValue)) {
3542
                $saida .= " Pedido: " . $this->compra->getElementsByTagName("xPed")->item(0)->nodeValue;
3543
            }
3544
            if (! empty($this->compra->getElementsByTagName("xCont")->item(0)->nodeValue)) {
3545
                $saida .= " Contrato: " . $this->compra->getElementsByTagName("xCont")->item(0)->nodeValue;
3546
            }
3547
        }
3548
        return $saida;
3549
    }
3550
3551
    /**
3552
     * geraChaveAdicionalDeContingencia
3553
     *
3554
     * @name   geraChaveAdicionalDeContingencia
3555
     * @return string chave
3556
     */
3557
    protected function geraChaveAdicionalDeContingencia()
3558
    {
3559
        //cUF tpEmis CNPJ vNF ICMSp ICMSs DD  DV
3560
        // Quantidade de caracteres  02   01      14  14    01    01  02 01
3561
        $forma  = "%02d%d%s%014d%01d%01d%02d";
3562
        $cUF    = $this->ide->getElementsByTagName('cUF')->item(0)->nodeValue;
3563
        $CNPJ   = "00000000000000" . $this->emit->getElementsByTagName('CNPJ')->item(0)->nodeValue;
3564
        $CNPJ   = substr($CNPJ, -14);
3565
        $vNF    = $this->ICMSTot->getElementsByTagName("vNF")->item(0)->nodeValue * 100;
3566
        $vICMS  = $this->ICMSTot->getElementsByTagName("vICMS")->item(0)->nodeValue;
3567
        if ($vICMS > 0) {
3568
            $vICMS = 1;
3569
        }
3570
        $icmss  = $this->ICMSTot->getElementsByTagName("vBC")->item(0)->nodeValue;
3571
        if ($icmss > 0) {
3572
            $icmss = 1;
3573
        }
3574
        $dEmi = ! empty($this->ide->getElementsByTagName("dEmi")->item(0)->nodeValue) ?
3575
                $this->ide->getElementsByTagName("dEmi")->item(0)->nodeValue : '';
3576
        if ($dEmi == '') {
3577
            $dEmi = ! empty($this->ide->getElementsByTagName("dhEmi")->item(0)->nodeValue) ?
3578
                    $this->ide->getElementsByTagName("dhEmi")->item(0)->nodeValue : '';
3579
            $aDemi = explode('T', $dEmi);
3580
            $dEmi = $aDemi[0];
3581
        }
3582
        $dd  = $dEmi;
3583
        $rpos = strrpos($dd, '-');
3584
        $dd  = substr($dd, $rpos +1);
3585
        $chave = sprintf($forma, $cUF, $this->tpEmis, $CNPJ, $vNF, $vICMS, $icmss, $dd);
3586
        $chave = $chave . $this->modulo11($chave);
3587
        return $chave;
3588
    }
3589
3590
    /**
3591
     *  geraInformacoesDasNotasReferenciadas
3592
     * Devolve uma string contendo informação sobre as notas referenciadas. Suporta N notas, eletrônicas ou não
3593
     * Exemplo: NFe Ref.: série: 01 número: 01 emit: 11.111.111/0001-01
3594
     * em 10/2010 [0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000]
3595
     *
3596
     * @return string Informacoes a serem adicionadas no rodapé sobre notas referenciadas.
3597
     */
3598
    protected function geraInformacoesDasNotasReferenciadas()
3599
    {
3600
        $formaNfeRef = "\r\nNFe Ref.: série:%d número:%d emit:%s em %s [%s]";
3601
        $formaCTeRef = "\r\nCTe Ref.: série:%d número:%d emit:%s em %s [%s]";
3602
        $formaNfRef = "\r\nNF  Ref.: série:%d numero:%d emit:%s em %s modelo: %d";
3603
        $formaECFRef = "\r\nECF Ref.: modelo: %s ECF:%d COO:%d";
3604
        $formaNfpRef = "\r\nNFP Ref.: série:%d número:%d emit:%s em %s modelo: %d IE:%s";
3605
        $saida='';
3606
        $nfRefs = $this->ide->getElementsByTagName('NFref');
3607
        if (0 === $nfRefs->length) {
3608
            return $saida;
3609
        }
3610
        if ($nfRefs->length > 2) {
3611
            return 'Existem mais de 2 NF/NFe/ECF/NFP/CTe referenciadas, não serão exibidas na DANFE.';
3612
        }
3613
        foreach ($nfRefs as $nfRef) {
3614
            if (empty($nfRef)) {
3615
                continue;
3616
            }
3617
            $refNFe = $nfRef->getElementsByTagName('refNFe');
3618
            foreach ($refNFe as $chave_acessoRef) {
3619
                $chave_acesso = $chave_acessoRef->nodeValue;
3620
                $chave_acessoF = $this->formatField($chave_acesso, $this->formatoChave);
3621
                $data = substr($chave_acesso, 4, 2)."/20".substr($chave_acesso, 2, 2);
3622
                $cnpj = $this->formatField(substr($chave_acesso, 6, 14), "##.###.###/####-##");
3623
                $serie  = substr($chave_acesso, 22, 3);
3624
                $numero = substr($chave_acesso, 25, 9);
3625
                $saida .= sprintf($formaNfeRef, $serie, $numero, $cnpj, $data, $chave_acessoF);
3626
            }
3627
            $refNF = $nfRef->getElementsByTagName('refNF');
3628
            foreach ($refNF as $umaRefNFe) {
3629
                $data = $umaRefNFe->getElementsByTagName('AAMM')->item(0)->nodeValue;
3630
                $cnpj = $umaRefNFe->getElementsByTagName('CNPJ')->item(0)->nodeValue;
3631
                $mod = $umaRefNFe->getElementsByTagName('mod')->item(0)->nodeValue;
3632
                $serie = $umaRefNFe->getElementsByTagName('serie')->item(0)->nodeValue;
3633
                $numero = $umaRefNFe->getElementsByTagName('nNF')->item(0)->nodeValue;
3634
                $data = substr($data, 2, 2) . "/20" . substr($data, 0, 2);
3635
                $cnpj = $this->formatField($cnpj, "##.###.###/####-##");
3636
                $saida .= sprintf($formaNfRef, $serie, $numero, $cnpj, $data, $mod);
3637
            }
3638
            $refCTe = $nfRef->getElementsByTagName('refCTe');
3639
            foreach ($refCTe as $chave_acessoRef) {
3640
                $chave_acesso = $chave_acessoRef->nodeValue;
3641
                $chave_acessoF = $this->formatField($chave_acesso, $this->formatoChave);
3642
                $data = substr($chave_acesso, 4, 2)."/20".substr($chave_acesso, 2, 2);
3643
                $cnpj = $this->formatField(substr($chave_acesso, 6, 14), "##.###.###/####-##");
3644
                $serie  = substr($chave_acesso, 22, 3);
3645
                $numero = substr($chave_acesso, 25, 9);
3646
                $saida .= sprintf($formaCTeRef, $serie, $numero, $cnpj, $data, $chave_acessoF);
3647
            }
3648
            $refECF = $nfRef->getElementsByTagName('refECF');
3649
            foreach ($refECF as $umaRefNFe) {
3650
                $mod    = $umaRefNFe->getElementsByTagName('mod')->item(0)->nodeValue;
3651
                $nECF   = $umaRefNFe->getElementsByTagName('nECF')->item(0)->nodeValue;
3652
                $nCOO   = $umaRefNFe->getElementsByTagName('nCOO')->item(0)->nodeValue;
3653
                $saida .= sprintf($formaECFRef, $mod, $nECF, $nCOO);
3654
            }
3655
            $refNFP = $nfRef->getElementsByTagName('refNFP');
3656
            foreach ($refNFP as $umaRefNFe) {
3657
                $data = $umaRefNFe->getElementsByTagName('AAMM')->item(0)->nodeValue;
3658
                $cnpj = ! empty($umaRefNFe->getElementsByTagName('CNPJ')->item(0)->nodeValue) ?
3659
                    $umaRefNFe->getElementsByTagName('CNPJ')->item(0)->nodeValue :
3660
                    '';
3661
                $cpf = ! empty($umaRefNFe->getElementsByTagName('CPF')->item(0)->nodeValue) ?
3662
                        $umaRefNFe->getElementsByTagName('CPF')->item(0)->nodeValue : '';
3663
                $mod = $umaRefNFe->getElementsByTagName('mod')->item(0)->nodeValue;
3664
                $serie = $umaRefNFe->getElementsByTagName('serie')->item(0)->nodeValue;
3665
                $numero = $umaRefNFe->getElementsByTagName('nNF')->item(0)->nodeValue;
3666
                $ie = $umaRefNFe->getElementsByTagName('IE')->item(0)->nodeValue;
3667
                $data = substr($data, 2, 2) . "/20" . substr($data, 0, 2);
3668
                if ($cnpj == '') {
3669
                    $cpf_cnpj = $this->formatField($cpf, "###.###.###-##");
3670
                } else {
3671
                    $cpf_cnpj = $this->formatField($cnpj, "##.###.###/####-##");
3672
                }
3673
                $saida .= sprintf($formaNfpRef, $serie, $numero, $cpf_cnpj, $data, $mod, $ie);
3674
            }
3675
        }
3676
        return $saida;
3677
    }
3678
    
3679
    private function loadDoc($xml)
3680
    {
3681
        $this->xml = $xml;
3682
        if (!empty($xml)) {
3683
            $this->dom = new Dom();
3684
            $this->dom->loadXML($this->xml);
3685
            if (empty($this->dom->getElementsByTagName("infNFe")->item(0))) {
3686
                throw new \Exception('Isso não é um NFe.');
3687
            }
3688
            $this->nfeProc = $this->dom->getElementsByTagName("nfeProc")->item(0);
3689
            $this->infNFe = $this->dom->getElementsByTagName("infNFe")->item(0);
3690
            $this->ide = $this->dom->getElementsByTagName("ide")->item(0);
3691
            if ($this->getTagValue($this->ide, "mod") != '55') {
3692
                throw new \Exception("O xml deve ser NF-e modelo 55.");
3693
            }
3694
            $this->entrega = $this->dom->getElementsByTagName("entrega")->item(0);
3695
            $this->retirada = $this->dom->getElementsByTagName("retirada")->item(0);
3696
            $this->emit = $this->dom->getElementsByTagName("emit")->item(0);
3697
            $this->dest = $this->dom->getElementsByTagName("dest")->item(0);
3698
            $this->enderEmit = $this->dom->getElementsByTagName("enderEmit")->item(0);
3699
            $this->enderDest = $this->dom->getElementsByTagName("enderDest")->item(0);
3700
            $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...
3701
            $this->cobr = $this->dom->getElementsByTagName("cobr")->item(0);
3702
            $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...
3703
            $this->ICMSTot = $this->dom->getElementsByTagName("ICMSTot")->item(0);
3704
            $this->ISSQNtot = $this->dom->getElementsByTagName("ISSQNtot")->item(0);
3705
            $this->transp = $this->dom->getElementsByTagName("transp")->item(0);
3706
            $this->transporta = $this->dom->getElementsByTagName("transporta")->item(0);
3707
            $this->veicTransp = $this->dom->getElementsByTagName("veicTransp")->item(0);
3708
            $this->detPag = $this->dom->getElementsByTagName("detPag");
3709
            $this->reboque = $this->dom->getElementsByTagName("reboque")->item(0);
3710
            $this->infAdic = $this->dom->getElementsByTagName("infAdic")->item(0);
3711
            $this->compra = $this->dom->getElementsByTagName("compra")->item(0);
3712
            $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...
3713
            $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...
3714
            $this->infProt = $this->dom->getElementsByTagName("infProt")->item(0);
3715
        }
3716
    }
3717
    
3718
    private function imagePNGtoJPG($original)
3719
    {
3720
        $image = imagecreatefrompng($original);
3721
        ob_start();
3722
        imagejpeg($image, null, 100);
3723
        imagedestroy($image);
3724
        $stringdata = ob_get_contents(); // read from buffer
3725
        ob_end_clean();
3726
        return 'data://text/plain;base64,'.base64_encode($stringdata);
3727
    }
3728
}
3729