Passed
Push — master ( f8305a...b6c7f7 )
by Roberto
03:01 queued 11s
created

Danfe::debugMode()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 16

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 20

Importance

Changes 0
Metric Value
cc 4
nc 4
nop 1
dl 0
loc 16
ccs 0
cts 14
cp 0
crap 20
rs 9.7333
c 0
b 0
f 0
1
<?php
2
3
namespace NFePHP\DA\NFe;
4
5
use InvalidArgumentException;
6
use NFePHP\DA\Legacy\Dom;
7
use NFePHP\DA\Legacy\Pdf;
8
use \NFePHP\DA\Common\DaCommon;
9
10
class Danfe extends DaCommon
11
{
12
13
    /**
14
     * alinhamento padrão do logo (C-Center)
15
     *
16
     * @var string
17
     */
18
    protected $logoAlign = 'C';
19
    /**
20
     * Posição
21
     * @var float
22
     */
23
    protected $yDados = 0;
24
    /**
25
     * Numero DPEC
26
     *
27
     * @var string
28
     */
29
    protected $numero_registro_dpec = '';
30
     /**
31
     * Parâmetro para exibir ou ocultar os valores do PIS/COFINS.
32
     * @var boolean
33
     */
34
    protected $qCanhoto = 1;
35
    /**
36
     * Define a exbição dos valores de PIS e Cofins
37
     * @var bool
38
     */
39
    protected $exibirPIS = true;
40
    /**
41
     * Parâmetro para exibir ou ocultar os valores do ICMS Interestadual e Valor Total dos Impostos.
42
     * @var boolean
43
     */
44
    protected $exibirIcmsInterestadual = true;
45
    /**
46
     * Parâmetro para exibir ou ocultar o texto sobre valor aproximado dos tributos.
47
     * @var boolean
48
     */
49
    protected $exibirValorTributos = true;
50
    /**
51
     * Parâmetro para exibir ou ocultar o texto adicional sobre a forma de pagamento
52
     * e as informações de fatura/duplicata.
53
     * @var boolean
54
     */
55
    protected $exibirTextoFatura = false;
56
    /**
57
     * Parâmetro do controle se deve concatenar automaticamente informações complementares
58
     * na descrição do produto, como por exemplo, informações sobre impostos.
59
     * @var boolean
60
     */
61
    public $descProdInfoComplemento = true;
62
    /**
63
     * Parâmetro do controle se deve gerar quebras de linha com "\n" a partir de ";" na descrição do produto.
64
     * @var boolean
65
     */
66
    protected $descProdQuebraLinha = true;
67
    /**
68
     * objeto fpdf()
69
     * @var \NFePHP\DA\Legacy\Pdf
70
     */
71
    protected $pdf;
72
    /**
73
     * XML NFe
74
     * @var string
75
     */
76
    protected $xml;
77
    /**
78
     * mesagens de erro
79
     * @var string
80
     */
81
    protected $errMsg = '';
82
    /**
83
     * status de erro true um erro ocorreu false sem erros
84
     * @var boolean
85
     */
86
    protected $errStatus = false;
87
    /**
88
     * orientação da DANFE
89
     * P-Retrato ou L-Paisagem
90
     * @var string
91
     */
92
    protected $orientacao = null;
93
    /**
94
     * formato do papel
95
     * @var string
96
     */
97
    protected $papel = 'A4';
98
    protected $margSup = 2;
99
    protected $margEsq = 2;
100
    protected $margInf = 2;
101
    /**
102
     * Nome da Fonte para gerar o DANFE
103
     * @var string
104
     */
105
    protected $fontePadrao = 'Times';
106
    /**
107
     * Texto adicional da DANFE
108
     * @var string
109
     */
110
    protected $textoAdic = '';
111
    /**
112
     * Largura
113
     * @var float
114
     */
115
    protected $wAdic = 0;
116
    /**
117
     * largura imprimivel, em milímetros
118
     * @var float
119
     */
120
    protected $wPrint;
121
    /**
122
     * Comprimento (altura) imprimivel, em milímetros
123
     * @var float
124
     */
125
    protected $hPrint;
126
    /**
127
     * Altura maxima
128
     * @var float
129
     */
130
    protected $maxH;
131
    /**
132
     * Largura maxima
133
     * @var float
134
     */
135
    protected $maxW;
136
    /**
137
     * largura do canhoto (25mm) apenas para a formatação paisagem
138
     * @var float
139
     */
140
    protected $wCanhoto = 25;
141
    /**
142
     * Formato chave
143
     * @var string
144
     */
145
    protected $formatoChave = "#### #### #### #### #### #### #### #### #### #### ####";
146
    /**
147
     * quantidade de itens já processados na montagem do DANFE
148
     * @var integer
149
     */
150
    protected $qtdeItensProc;
151
    /**
152
     * Dom Document
153
     * @var \NFePHP\DA\Legacy\Dom
154
     */
155
    protected $dom;
156
    /**
157
     * Node
158
     * @var \DOMNode
159
     */
160
    protected $infNFe;
161
    /**
162
     * Node
163
     * @var \DOMNode
164
     */
165
    protected $ide;
166
    /**
167
     * Node
168
     * @var \DOMNode
169
     */
170
    protected $entrega;
171
    /**
172
     * Node
173
     * @var \DOMNode
174
     */
175
    protected $retirada;
176
    /**
177
     * Node
178
     * @var \DOMNode
179
     */
180
    protected $emit;
181
    /**
182
     * Node
183
     * @var \DOMNode
184
     */
185
    protected $dest;
186
    /**
187
     * Node
188
     * @var \DOMNode
189
     */
190
    protected $enderEmit;
191
    /**
192
     * Node
193
     * @var \DOMNode
194
     */
195
    protected $enderDest;
196
    /**
197
     * Node
198
     * @var \DOMNode
199
     */
200
    protected $det;
201
    /**
202
     * Node
203
     * @var \DOMNode
204
     */
205
    protected $cobr;
206
    /**
207
     * Node
208
     * @var \DOMNode
209
     */
210
    protected $dup;
211
    /**
212
     * Node
213
     * @var \DOMNode
214
     */
215
    protected $ICMSTot;
216
    /**
217
     * Node
218
     * @var \DOMNode
219
     */
220
    protected $ISSQNtot;
221
    /**
222
     * Node
223
     * @var \DOMNode
224
     */
225
    protected $transp;
226
    /**
227
     * Node
228
     * @var \DOMNode
229
     */
230
    protected $transporta;
231
    /**
232
     * Node
233
     * @var \DOMNode
234
     */
235
    protected $veicTransp;
236
    /**
237
     * Node reboque
238
     * @var \DOMNode
239
     */
240
    protected $reboque;
241
    /**
242
     * Node infAdic
243
     * @var \DOMNode
244
     */
245
    protected $infAdic;
246
    /**
247
     * Tipo de emissão
248
     * @var integer
249
     */
250
    protected $tpEmis;
251
    /**
252
     * Node infProt
253
     * @var \DOMNode
254
     */
255
    protected $infProt;
256
    /**
257
     * 1-Retrato/ 2-Paisagem
258
     * @var integer
259
     */
260
    protected $tpImp;
261
    /**
262
     * Node compra
263
     * @var \DOMNode
264
     */
265
    protected $compra;
266
    /**
267
     * ativa ou desativa o modo de debug
268
     * @var integer
269
     */
270
    protected $debugmode = false;
271
    /**
272
     * Creditos para integrador
273
     * @var string
274
     */
275
    protected $creditos = '';
276
    
277
    protected $textadicfontsize;
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->loadDoc($xml);
288
    }
289
290
291
    /**
292
     * Add the credits to the integrator in the footer message
293
     * @param string $message
294
     */
295
    public function creditsIntegratorFooter($message = '')
296
    {
297
        $this->creditos = trim($message);
298
    }
299
300
    /**
301
     * monta
302
     * Monta a DANFE conforme as informações fornecidas para a classe durante sua
303
     * construção. Constroi DANFEs com até 3 páginas podendo conter até 56 itens.
304
     * A definição de margens e posições iniciais para a impressão são estabelecidas
305
     * pelo conteúdo da funçao e podem ser modificados.
306
     *
307
308
     * @return string O ID da NFe numero de 44 digitos extraido do arquivo XML
309
     */
310
    public function monta(
311
        $logo = '',
312
        $depecNumReg = null
313
    ) {
314
        $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...
315
        $this->logomarca = $this->adjustImage($logo);
316
        //se a orientação estiver em branco utilizar o padrão estabelecido na NF
317
        if (empty($this->orientacao)) {
318
            if ($this->tpImp == '2') {
319
                $this->orientacao = 'L';
320
            } else {
321
                $this->orientacao = 'P';
322
            }
323
        }
324
        $this->numero_registro_dpec = $depecNumReg;
325
        //instancia a classe pdf
326
        $this->pdf = new Pdf($this->orientacao, 'mm', $this->papel);
327
        //margens do PDF, em milímetros. Obs.: a margem direita é sempre igual à
328
        //margem esquerda. A margem inferior *não* existe na FPDF, é definida aqui
329
        //apenas para controle se necessário ser maior do que a margem superior
330
        // posição inicial do conteúdo, a partir do canto superior esquerdo da página
331
        $xInic = $this->margEsq;
332
        if ($this->orientacao == 'P') {
333
            if ($this->papel == 'A4') {
334
                $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...
335
                $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...
336
            }
337
        } else {
338
            if ($papel == 'A4') {
0 ignored issues
show
Bug introduced by
The variable $papel does not exist. Did you forget to declare it?

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

Loading history...
339
                $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...
340
                $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...
341
                $xInic = $this->margEsq+10;
342
                //se paisagem multiplica a largura do canhoto pela quantidade de canhotos
343
                //$this->wCanhoto *= $this->qCanhoto;
344
            }
345
        }
346
        //total inicial de paginas
347
        $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...
348
        //largura imprimivel em mm: largura da folha menos as margens esq/direita
349
        $this->wPrint = $this->maxW-($this->margEsq * 2);
0 ignored issues
show
Documentation Bug introduced by
It seems like $this->maxW - $this->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...
350
        //comprimento (altura) imprimivel em mm: altura da folha menos as margens
351
        //superior e inferior
352
        $this->hPrint = $this->maxH-$this->margSup-$this->margInf;
0 ignored issues
show
Documentation Bug introduced by
It seems like $this->maxH - $this->margSup - $this->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...
353
        // estabelece contagem de paginas
354
        $this->pdf->aliasNbPages();
355
        // fixa as margens
356
        $this->pdf->setMargins($this->margEsq, $this->margSup);
357
        $this->pdf->setDrawColor(0, 0, 0);
358
        $this->pdf->setFillColor(255, 255, 255);
359
        // inicia o documento
360
        $this->pdf->open();
361
        // adiciona a primeira página
362
        $this->pdf->addPage($this->orientacao, $this->papel);
363
        $this->pdf->setLineWidth(0.1);
364
        $this->pdf->settextcolor(0, 0, 0);
365
366
        //##################################################################
367
        // CALCULO DO NUMERO DE PAGINAS A SEREM IMPRESSAS
368
        //##################################################################
369
        //Verificando quantas linhas serão usadas para impressão das duplicatas
370
        $linhasDup = 0;
371
        $qtdPag = 0;
372
        if (isset($this->dup) && $this->dup->length > 0) {
373
            $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...
374
        } 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...
375
            $qtdPag = $this->detPag->length;
376
        }
377
        if (($qtdPag > 0) && ($qtdPag <= 7)) {
378
            $linhasDup = 1;
379
        } elseif (($qtdPag > 7) && ($qtdPag <= 14)) {
380
            $linhasDup = 2;
381
        } elseif (($qtdPag > 14) && ($qtdPag <= 21)) {
382
            $linhasDup = 3;
383
        } elseif ($qtdPag > 21) {
384
            // chinnonsantos 11/05/2016: Limite máximo de impressão de duplicatas na NFe,
385
            // só vai ser exibito as 21 primeiras duplicatas (parcelas de pagamento),
386
            // se não oculpa espaço d+, cada linha comporta até 7 duplicatas.
387
            $linhasDup = 3;
388
        }
389
        //verifica se será impressa a linha dos serviços ISSQN
390
        $linhaISSQN = 0;
391
        if ((isset($this->ISSQNtot)) && ($this->getTagValue($this->ISSQNtot, 'vServ') > 0)) {
392
            $linhaISSQN = 1;
393
        }
394
        //calcular a altura necessária para os dados adicionais
395
        if ($this->orientacao == 'P') {
396
            $this->wAdic = round($this->wPrint*0.66, 0);
397
        } else {
398
            $this->wAdic = round(($this->wPrint-$this->wCanhoto)*0.5, 0);
399
        }
400
        $fontProduto = ['font'=>$this->fontePadrao, 'size'=>7, 'style'=>''];
401
        $this->textoAdic = '';
402
        if (isset($this->retirada)) {
403
            $txRetCNPJ = $this->getTagValue($this->retirada, "CNPJ");
404
            $txRetxLgr = $this->getTagValue($this->retirada, "xLgr");
405
            $txRetnro = $this->getTagValue($this->retirada, "nro");
406
            $txRetxCpl = $this->getTagValue($this->retirada, "xCpl", " - ");
407
            $txRetxBairro = $this->getTagValue($this->retirada, "xBairro");
408
            $txRetxMun = $this->getTagValue($this->retirada, "xMun");
409
            $txRetUF = $this->getTagValue($this->retirada, "UF");
410
            $this->textoAdic .= "LOCAL DE RETIRADA : ".
411
                    $txRetCNPJ.
412
                    '-' .
413
                    $txRetxLgr .
414
                    ', ' .
415
                    $txRetnro .
416
                    ' ' .
417
                    $txRetxCpl .
418
                    ' - ' .
419
                    $txRetxBairro .
420
                    ' ' .
421
                    $txRetxMun .
422
                    ' - ' .
423
                    $txRetUF .
424
                    "\r\n";
425
        }
426
        //dados do local de entrega da mercadoria
427
        if (isset($this->entrega)) {
428
            $txRetCNPJ = $this->getTagValue($this->entrega, "CNPJ");
429
            $txRetxLgr = $this->getTagValue($this->entrega, "xLgr");
430
            $txRetnro = $this->getTagValue($this->entrega, "nro");
431
            $txRetxCpl = $this->getTagValue($this->entrega, "xCpl", " - ");
432
            $txRetxBairro = $this->getTagValue($this->entrega, "xBairro");
433
            $txRetxMun = $this->getTagValue($this->entrega, "xMun");
434
            $txRetUF = $this->getTagValue($this->entrega, "UF");
435
            if ($this->textoAdic != '') {
436
                $this->textoAdic .= ". \r\n";
437
            }
438
            $this->textoAdic .= "LOCAL DE ENTREGA : ".$txRetCNPJ.'-'.$txRetxLgr.', '.$txRetnro.' '.$txRetxCpl.
439
               ' - '.$txRetxBairro.' '.$txRetxMun.' - '.$txRetUF."\r\n";
440
        }
441
        //informações adicionais
442
        $this->textoAdic .= $this->geraInformacoesDasNotasReferenciadas();
443
        if (isset($this->infAdic)) {
444
            $i = 0;
445
            if ($this->textoAdic != '') {
446
                $this->textoAdic .= ". \r\n";
447
            }
448
            $this->textoAdic .= ! empty($this->getTagValue($this->infAdic, "infCpl"))
449
            ? 'Inf. Contribuinte: ' . $this->anfaveaDANFE($this->getTagValue($this->infAdic, "infCpl"))
450
            : '';
451
            $infPedido = $this->geraInformacoesDaTagCompra();
452
            if ($infPedido != "") {
453
                $this->textoAdic .= $infPedido;
454
            }
455
            $this->textoAdic .= $this->getTagValue($this->dest, "email", ' Email do Destinatário: ');
456
            $this->textoAdic .= ! empty($this->getTagValue($this->infAdic, "infAdFisco"))
457
            ? "\r\n Inf. fisco: " . $this->getTagValue($this->infAdic, "infAdFisco")
458
            : '';
459
            $obsCont = $this->infAdic->getElementsByTagName("obsCont");
460
            if (isset($obsCont)) {
461
                foreach ($obsCont as $obs) {
462
                    $campo =  $obsCont->item($i)->getAttribute("xCampo");
463
                    $xTexto = ! empty($obsCont->item($i)->getElementsByTagName("xTexto")->item(0)->nodeValue)
464
                    ? $obsCont->item($i)->getElementsByTagName("xTexto")->item(0)->nodeValue
465
                    : '';
466
                    $this->textoAdic .= "\r\n" . $campo . ':  ' . trim($xTexto);
467
                    $i++;
468
                }
469
            }
470
        }
471
        //INCLUSO pela NT 2013.003 Lei da Transparência
472
        //verificar se a informação sobre o valor aproximado dos tributos
473
        //já se encontra no campo de informações adicionais
474
        if ($this->exibirValorTributos) {
475
            $flagVTT = strpos(strtolower(trim($this->textoAdic)), 'valor');
476
            $flagVTT = $flagVTT || strpos(strtolower(trim($this->textoAdic)), 'vl');
477
            $flagVTT = $flagVTT && strpos(strtolower(trim($this->textoAdic)), 'aprox');
478
            $flagVTT = $flagVTT && (strpos(strtolower(trim($this->textoAdic)), 'trib') ||
479
                    strpos(strtolower(trim($this->textoAdic)), 'imp'));
480
            $vTotTrib = $this->getTagValue($this->ICMSTot, 'vTotTrib');
481
            if ($vTotTrib != '' && !$flagVTT) {
482
                $this->textoAdic .= "\n Valor Aproximado dos Tributos : R$ "
483
                    . number_format($vTotTrib, 2, ",", ".");
484
            }
485
        }
486
        //fim da alteração NT 2013.003 Lei da Transparência
487
        $this->textoAdic = str_replace(";", "\n", $this->textoAdic);
488
        $alinhas = explode("\n", $this->textoAdic);
489
        $numlinhasdados = 0;
490
        foreach ($alinhas as $linha) {
491
            $numlinhasdados += $this->pdf->getNumLines($linha, $this->wAdic, $fontProduto);
492
        }
493
        $this->textadicfontsize = $this->pdf->fontSize;
494
        $hdadosadic = round(($numlinhasdados+3) * $this->textadicfontsize, 0);
495
        if ($hdadosadic > 70) {
496
            for ($per=1; $per>=0.01; $per=$per-0.01) {
497
                $this->textadicfontsize = $this->pdf->fontSize*$per;
498
                $hdadosadic = round(($numlinhasdados+3) * $this->textadicfontsize, 0);
499
                if ($hdadosadic <= 90) {
500
                    $hdadosadic = 70;
501
                    break;
502
                }
503
            }
504
        }
505
        
506
        if ($hdadosadic < 10) {
507
            $hdadosadic = 10;
508
        }
509
        //altura disponivel para os campos da DANFE
510
        $hcabecalho = 47;//para cabeçalho
511
        $hdestinatario = 25;//para destinatario
512
        $hduplicatas = 12;//para cada grupo de 7 duplicatas
513
        if (isset($this->entrega)) {
514
            $hlocalentrega = 25;
515
        } else {
516
            $hlocalentrega = 0;
517
        }
518
        if (isset($this->retirada)) {
519
            $hlocalretirada = 25;
520
        } else {
521
            $hlocalretirada = 0;
522
        }
523
        $himposto = 18;// para imposto
524
        $htransporte = 25;// para transporte
525
        $hissqn = 11;// para issqn
526
        $hfooter = 5;// para rodape
527
        $hCabecItens = 4;//cabeçalho dos itens
528
        //alturas disponiveis para os dados
529
        $hDispo1 = $this->hPrint - 10 - ($hcabecalho +
530
            //$hdestinatario + ($linhasDup * $hduplicatas) + $himposto + $htransporte +
531
            $hdestinatario + $hlocalentrega + $hlocalretirada +
532
            ($linhasDup * $hduplicatas) + $himposto + $htransporte +
533
            ($linhaISSQN * $hissqn) + $hdadosadic + $hfooter + $hCabecItens +
534
            $this->sizeExtraTextoFatura());
535
        if ($this->orientacao == 'P') {
536
            $hDispo1 -= 24 * $this->qCanhoto;//para canhoto
537
            $w = $this->wPrint;
538
        } else {
539
            $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...
540
            $w = $this->wPrint - $this->wCanhoto;
541
        }
542
        $hDispo2 = $this->hPrint - 10 - ($hcabecalho + $hfooter + $hCabecItens)-4;
543
        //Contagem da altura ocupada para impressão dos itens
544
        $fontProduto = ['font'=>$this->fontePadrao, 'size'=>7, 'style'=>''];
545
        $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...
546
        $hUsado = $hCabecItens;
547
        $w2 = round($w*0.28, 0);
548
        $hDispo = $hDispo1;
549
        $totPag = 1;
550
        $i = 0;
551
        while ($i < $this->det->length) {
552
            $texto = $this->descricaoProduto($this->det->item($i));
553
            $numlinhas = $this->pdf->getNumLines($texto, $w2, $fontProduto);
554
            $hUsado += round(($numlinhas * $this->pdf->fontSize) + ($numlinhas * 0.5), 2);
555
            if ($hUsado > $hDispo) {
556
                $totPag++;
557
                $hDispo = $hDispo2;
558
                $hUsado = $hCabecItens;
559
                // Remove canhoto para páginas secundárias em modo paisagem ('L')
560
                $w2 = round($this->wPrint*0.28, 0);
561
                $i--; // decrementa para readicionar o item que não coube nessa pagina na outra.
562
            }
563
            $i++;
564
        } //fim da soma das areas de itens usadas
565
        $qtdeItens = $i; //controle da quantidade de itens no DANFE
566
        //montagem da primeira página
567
        $pag = 1;
568
        
569
        $x = $this->margEsq;
570
        $y = $this->margSup;
571
        //coloca o(s) canhoto(s) da NFe
572
        if ($this->orientacao == 'P') {
573
            $y = $this->canhoto($this->margEsq, $this->margSup);
574
        } else {
575
            $this->canhoto($this->margEsq, $this->margSup);
576
            $x = 25;
577
        }
578
        //$x = $xInic;
579
        //$y = $yInic;
580
        
581
        //coloca o cabeçalho
582
        $y = $this->header($x, $y, $pag, $totPag);
583
        //coloca os dados do destinatário
584
        $y = $this->destinatarioDANFE($x, $y+1);
585
        
586
        //coloca os dados do local de retirada
587
        if (isset($this->retirada)) {
588
            $y = $this->localRetiradaDANFE($x, $y+1);
589
        }
590
        //coloca os dados do local de entrega
591
        if (isset($this->entrega)) {
592
            $y = $this->localEntregaDANFE($x, $y+1);
593
        }
594
        
595
        //Verifica as formas de pagamento da nota fiscal
596
        $formaPag = [];
597
        if (isset($this->detPag) && $this->detPag->length > 0) {
598
            foreach ($this->detPag as $k => $d) {
599
                $fPag = !empty($this->detPag->item($k)->getElementsByTagName('tPag')->item(0)->nodeValue)
600
                ? $this->detPag->item($k)->getElementsByTagName('tPag')->item(0)->nodeValue
601
                : '0';
602
                $formaPag[$fPag] = $fPag;
603
            }
604
        }
605
        //caso tenha boleto imprimir fatura
606
        if ($this->dup->length > 0) {
607
            $y = $this->fatura($x, $y+1);
608
        } else {
609
            //Se somente tiver a forma de pagamento sem pagamento ou outros não imprimir nada
610
            if (count($formaPag)=='1' && (isset($formaPag[90]) || isset($formaPag[99]))) {
611
                $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...
612
            } else {
613
                //caso tenha mais de uma forma de pagamento ou seja diferente de boleto exibe a
614
                //forma de pagamento e o valor
615
                $y = $this->pagamento($x, $y+1);
616
            }
617
        }
618
        //coloca os dados dos impostos e totais da NFe
619
        $y = $this->imposto($x, $y+1);
620
        //coloca os dados do trasnporte
621
        $y = $this->transporte($x, $y+1);
622
        //itens da DANFE
623
        $nInicial = 0;
624
625
        $y = $this->itens($x, $y+1, $nInicial, $hDispo1, $pag, $totPag, $hCabecItens);
626
627
        //coloca os dados do ISSQN
628
        if ($linhaISSQN == 1) {
629
            $y = $this->issqn($x, $y+4);
630
        } else {
631
            $y += 4;
632
        }
633
        //coloca os dados adicionais da NFe
634
        $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...
635
        //coloca o rodapé da página
636
        if ($this->orientacao == 'P') {
637
            $this->rodape($xInic);
638
        } else {
639
            $this->rodape($xInic);
640
        }
641
642
        //loop para páginas seguintes
643
        for ($n = 2; $n <= $totPag; $n++) {
644
            // fixa as margens
645
            $this->pdf->setMargins($margEsq, $margSup);
0 ignored issues
show
Bug introduced by
The variable $margEsq does not exist. Did you forget to declare it?

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

Loading history...
Bug introduced by
The variable $margSup does not exist. Did you forget to declare it?

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

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