Passed
Pull Request — master (#166)
by
unknown
03:48
created

Danfe   F

Complexity

Total Complexity 408

Size/Duplication

Total Lines 3391
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
dl 0
loc 3391
ccs 0
cts 2507
cp 0
rs 0.8
c 0
b 0
f 0
wmc 408
lcom 1
cbo 3

How to fix   Complexity   

Complex Class

Complex classes like Danfe often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

While breaking up the class, it is a good idea to analyze how other classes use Danfe, and based on these observations, apply Extract Interface, too.

1
<?php
2
3
namespace NFePHP\DA\NFe;
4
5
use InvalidArgumentException;
6
use NFePHP\DA\Legacy\Dom;
7
use NFePHP\DA\Legacy\Pdf;
8
use NFePHP\DA\Legacy\Common;
9
10
class Danfe extends Common
11
{
12
    const FPDF_FONTPATH = 'font/';
13
    const SIT_CANCELADA = 1;
14
    const SIT_DENEGADA = 2;
15
    const SIT_DPEC = 3;
16
    const SIT_NONE = 0;
17
18
    /**
19
     * alinhamento padrão do logo (C-Center)
20
     *
21
     * @var string
22
     */
23
    public $logoAlign = 'C';
24
    /**
25
     * Posição
26
     * @var float
27
     */
28
    public $yDados = 0;
29
    /**
30
     * Situação
31
     * @var integer
32
     */
33
    public $situacaoExterna = 0;
34
    /**
35
     * Numero DPEC
36
     *
37
     * @var string
38
     */
39
    public $numero_registro_dpec = '';
40
    /**
41
     * quantidade de canhotos a serem montados, geralmente 1 ou 2
42
     *
43
     * @var integer
44
     */
45
    public $qCanhoto = 1;
46
47
    //###########################################################
48
    // INÍCIO ATRIBUTOS DE PARÂMETROS DE EXIBIÇÃO
49
    //###########################################################
50
51
    /**
52
     * Parâmetro para exibir ou ocultar os valores do PIS/COFINS.
53
     * @var boolean
54
     */
55
    public $exibirPIS = true;
56
    /**
57
     * Parâmetro para exibir ou ocultar os valores do ICMS Interestadual e Valor Total dos Impostos.
58
     * @var boolean
59
     */
60
    public $exibirIcmsInterestadual = true;
61
    /**
62
     * Parâmetro para exibir ou ocultar o texto sobre valor aproximado dos tributos.
63
     * @var boolean
64
     */
65
    public $exibirValorTributos = true;
66
    /**
67
     * Parâmetro para exibir ou ocultar o texto adicional sobre a forma de pagamento
68
     * e as informações de fatura/duplicata.
69
     * @var boolean
70
     */
71
    public $exibirTextoFatura = false;
72
    /**
73
     * Parâmetro do controle se deve concatenar automaticamente informações complementares
74
     * na descrição do produto, como por exemplo, informações sobre impostos.
75
     * @var boolean
76
     */
77
    public $descProdInfoComplemento = true;
78
    /**
79
     * Parâmetro do controle se deve gerar quebras de linha com "\n" a partir de ";" na descrição do produto.
80
     * @var boolean
81
     */
82
    public $descProdQuebraLinha = true;
83
84
    //###########################################################
85
    //PROPRIEDADES DA CLASSE
86
    //###########################################################
87
88
    /**
89
     * objeto fpdf()
90
     * @var object
91
     */
92
    protected $pdf;
93
    /**
94
     * XML NFe
95
     * @var string
96
     */
97
    protected $xml;
98
    /**
99
     * path para logomarca em jpg
100
     * @var string
101
     */
102
    protected $logomarca = '';
103
    /**
104
     * mesagens de erro
105
     * @var string
106
     */
107
    protected $errMsg = '';
108
    /**
109
     * status de erro true um erro ocorreu false sem erros
110
     * @var boolean
111
     */
112
    protected $errStatus = false;
113
    /**
114
     * orientação da DANFE
115
     * P-Retrato ou L-Paisagem
116
     * @var string
117
     */
118
    protected $orientacao = 'P';
119
    /**
120
     * formato do papel
121
     * @var string
122
     */
123
    protected $papel = 'A4';
124
    /**
125
     * destino do arquivo pdf
126
     * I-borwser, S-retorna o arquivo, D-força download, F-salva em arquivo local
127
     * @var string
128
     */
129
    protected $destino = 'I';
130
    /**
131
     * diretorio para salvar o pdf com a opção de destino = F
132
     * @var string
133
     */
134
    protected $pdfDir = '';
135
    /**
136
     * Nome da Fonte para gerar o DANFE
137
     * @var string
138
     */
139
    protected $fontePadrao = 'Times';
140
    /**
141
     * versão
142
     * @var string
143
     */
144
    protected $version = '2.2.8';
145
    /**
146
     * Texto
147
     * @var string
148
     */
149
    protected $textoAdic = '';
150
    /**
151
     * Largura
152
     * @var float
153
     */
154
    protected $wAdic = 0;
155
    /**
156
     * largura imprimivel, em milímetros
157
     * @var float
158
     */
159
    protected $wPrint;
160
    /**
161
     * Comprimento (altura) imprimivel, em milímetros
162
     * @var float
163
     */
164
    protected $hPrint;
165
    /**
166
     * largura do canhoto (25mm) apenas para a formatação paisagem
167
     * @var float
168
     */
169
    protected $wCanhoto = 25;
170
    /**
171
     * Formato chave
172
     * @var string
173
     */
174
    protected $formatoChave = "#### #### #### #### #### #### #### #### #### #### ####";
175
    /**
176
     * quantidade de itens já processados na montagem do DANFE
177
     * @var integer
178
     */
179
    protected $qtdeItensProc;
180
181
    /**
182
     * Document
183
     * @var DOMDocument
184
     */
185
    protected $dom;
186
    /**
187
     * Node
188
     * @var DOMNode
189
     */
190
    protected $infNFe;
191
    /**
192
     * Node
193
     * @var DOMNode
194
     */
195
    protected $ide;
196
    /**
197
     * Node
198
     * @var DOMNode
199
     */
200
    protected $entrega;
201
    /**
202
     * Node
203
     * @var DOMNode
204
     */
205
    protected $retirada;
206
    /**
207
     * Node
208
     * @var DOMNode
209
     */
210
    protected $emit;
211
    /**
212
     * Node
213
     * @var DOMNode
214
     */
215
    protected $dest;
216
    /**
217
     * Node
218
     * @var DOMNode
219
     */
220
    protected $enderEmit;
221
    /**
222
     * Node
223
     * @var DOMNode
224
     */
225
    protected $enderDest;
226
    /**
227
     * Node
228
     * @var DOMNode
229
     */
230
    protected $det;
231
    /**
232
     * Node
233
     * @var DOMNode
234
     */
235
    protected $cobr;
236
    /**
237
     * Node
238
     * @var DOMNode
239
     */
240
    protected $dup;
241
    /**
242
     * Node
243
     * @var DOMNode
244
     */
245
    protected $ICMSTot;
246
    /**
247
     * Node
248
     * @var DOMNode
249
     */
250
    protected $ISSQNtot;
251
    /**
252
     * Node
253
     * @var DOMNode
254
     */
255
    protected $transp;
256
    /**
257
     * Node
258
     * @var DOMNode
259
     */
260
    protected $transporta;
261
    /**
262
     * Node
263
     * @var DOMNode
264
     */
265
    protected $veicTransp;
266
    /**
267
     * Node reboque
268
     * @var DOMNode
269
     */
270
    protected $reboque;
271
    /**
272
     * Node infAdic
273
     * @var DOMNode
274
     */
275
    protected $infAdic;
276
    /**
277
     * Tipo de emissão
278
     * @var integer
279
     */
280
    protected $tpEmis;
281
    /**
282
     * Node infProt
283
     * @var DOMNode
284
     */
285
    protected $infProt;
286
    /**
287
     * 1-Retrato/ 2-Paisagem
288
     * @var integer
289
     */
290
    protected $tpImp;
291
    /**
292
     * Node compra
293
     * @var DOMNode
294
     */
295
    protected $compra;
296
    /**
297
     * ativa ou desativa o modo de debug
298
     * @var integer
299
     */
300
    protected $debugMode=2;
301
    /**
302
     * Creditos para integrador
303
     * @var string
304
     */
305
    protected $creditos = '';
306
307
    /**
308
     * __construct
309
     *
310
     * @name  __construct
311
     * @param string  $docXML      Conteúdo XML da NF-e (com ou sem a tag nfeProc)
312
     * @param string  $sOrientacao (Opcional) Orientação da impressão P-retrato L-Paisagem
313
     * @param string  $sPapel      Tamanho do papel (Ex. A4)
314
     * @param string  $sPathLogo   Caminho para o arquivo do logo
315
     * @param string  $sDestino    Estabelece a direção do envio do documento PDF I-browser D-browser com download S-
316
     * @param string  $sDirPDF     Caminho para o diretorio de armazenamento dos arquivos PDF
317
     * @param string  $fonteDANFE  Nome da fonte alternativa do DAnfe
318
     * @param integer $mododebug   0-Não 1-Sim e 2-nada (2 default)
319
     */
320
    public function __construct(
321
        $docXML = '',
322
        $sOrientacao = '',
323
        $sPapel = '',
324
        $sPathLogo = '',
325
        $sDestino = 'I',
326
        $sDirPDF = '',
327
        $fonteDANFE = '',
328
        $mododebug = 2
329
    ) {
330
        //set_time_limit(1800);
331
        if (is_numeric($mododebug)) {
332
            $this->debugMode = $mododebug;
333
        }
334
        if ($mododebug == 1) {
335
            //ativar modo debug
336
            error_reporting(E_ALL);
337
            ini_set('display_errors', 'On');
338
        }
339
        if ($mododebug == 0) {
340
            //desativar modo debug
341
            error_reporting(0);
342
            ini_set('display_errors', 'Off');
343
        }
344
        $this->orientacao   = $sOrientacao;
345
        $this->papel        = $sPapel;
346
        $this->pdf          = '';
347
        $this->xml          = $docXML;
348
        $this->logomarca    = $sPathLogo;
349
        $this->destino      = $sDestino;
350
        $this->pdfDir       = $sDirPDF;
351
        // verifica se foi passa a fonte a ser usada
352
        if (empty($fonteDANFE)) {
353
            $this->fontePadrao = 'Times';
354
        } else {
355
            $this->fontePadrao = $fonteDANFE;
356
        }
357
        //se for passado o xml
358
        if (! empty($this->xml)) {
359
            $this->dom = new Dom();
360
            $this->dom->loadXML($this->xml);
361
            $this->nfeProc    = $this->dom->getElementsByTagName("nfeProc")->item(0);
362
            $this->infNFe     = $this->dom->getElementsByTagName("infNFe")->item(0);
363
            $this->ide        = $this->dom->getElementsByTagName("ide")->item(0);
364
            $this->entrega    = $this->dom->getElementsByTagName("entrega")->item(0);
365
            $this->retirada   = $this->dom->getElementsByTagName("retirada")->item(0);
366
            $this->emit       = $this->dom->getElementsByTagName("emit")->item(0);
367
            $this->dest       = $this->dom->getElementsByTagName("dest")->item(0);
368
            $this->enderEmit  = $this->dom->getElementsByTagName("enderEmit")->item(0);
369
            $this->enderDest  = $this->dom->getElementsByTagName("enderDest")->item(0);
370
            $this->det        = $this->dom->getElementsByTagName("det");
371
            $this->cobr       = $this->dom->getElementsByTagName("cobr")->item(0);
372
            $this->dup        = $this->dom->getElementsByTagName('dup');
373
            $this->ICMSTot    = $this->dom->getElementsByTagName("ICMSTot")->item(0);
374
            $this->ISSQNtot   = $this->dom->getElementsByTagName("ISSQNtot")->item(0);
375
            $this->transp     = $this->dom->getElementsByTagName("transp")->item(0);
376
            $this->transporta = $this->dom->getElementsByTagName("transporta")->item(0);
377
            $this->veicTransp = $this->dom->getElementsByTagName("veicTransp")->item(0);
378
            $this->reboque    = $this->dom->getElementsByTagName("reboque")->item(0);
379
            $this->infAdic    = $this->dom->getElementsByTagName("infAdic")->item(0);
380
            $this->compra     = $this->dom->getElementsByTagName("compra")->item(0);
381
            $this->tpEmis     = $this->ide->getElementsByTagName("tpEmis")->item(0)->nodeValue;
382
            $this->tpImp      = $this->ide->getElementsByTagName("tpImp")->item(0)->nodeValue;
383
            $this->infProt    = $this->dom->getElementsByTagName("infProt")->item(0);
384
            //valida se o XML é uma NF-e modelo 55, pois não pode ser 65 (NFC-e)
385
            if ($this->pSimpleGetValue($this->ide, "mod") != '55') {
386
                throw new InvalidArgumentException("O xml do DANFE deve ser uma NF-e modelo 55");
387
            }
388
        }
389
    }
390
391
    /**
392
     * Add the credits to the integrator in the footer message
393
     * @param string $message
394
     */
395
    public function creditsIntegratorFooter($message = '')
396
    {
397
        $this->creditos = trim($message);
398
    }
399
    
400
    /**
401
     * monta
402
     *
403
     * @name   monta
404
     * @param  string $orientacao
405
     * @param  string $papel
406
     * @param  string $logoAlign
407
     * @return string
408
     */
409
    public function monta(
410
        $orientacao = '',
411
        $papel = 'A4',
412
        $logoAlign = 'C',
413
        $situacaoExterna = self::SIT_NONE,
414
        $classPdf = false,
415
        $dpecNumReg = '',
416
        $margSup = 2,
417
        $margEsq = 2,
418
        $margInf = 2
419
    ) {
420
        return $this->montaDANFE(
421
            $orientacao,
422
            $papel,
423
            $logoAlign,
424
            $situacaoExterna,
425
            $classPdf,
426
            $dpecNumReg,
427
            $margSup,
428
            $margEsq,
429
            $margInf
430
        );
431
    }
432
433
    /**
434
     * printDocument
435
     *
436
     * @param  string $nome
437
     * @param  string $destino
438
     * @param  string $printer
439
     * @return object pdf
440
     */
441
    public function printDocument($nome = '', $destino = 'I', $printer = '')
442
    {
443
        $arq = $this->pdf->Output($nome, $destino);
444
        if ($destino == 'S') {
0 ignored issues
show
Unused Code introduced by
This if statement is empty and can be removed.

This check looks for the bodies of if statements that have no statements or where all statements have been commented out. This may be the result of changes for debugging or the code may simply be obsolete.

These if bodies can be removed. If you have an empty if but statements in the else branch, consider inverting the condition.

if (rand(1, 6) > 3) {
//print "Check failed";
} else {
    print "Check succeeded";
}

could be turned into

if (rand(1, 6) <= 3) {
    print "Check succeeded";
}

This is much more concise to read.

Loading history...
445
            //aqui pode entrar a rotina de impressão direta
446
        }
447
        return $arq;
448
    }
449
450
    /**
451
     * montaDANFE
452
     * Monta a DANFE conforme as informações fornecidas para a classe durante sua
453
     * construção. Constroi DANFEs com até 3 páginas podendo conter até 56 itens.
454
     * A definição de margens e posições iniciais para a impressão são estabelecidas
455
     * pelo conteúdo da funçao e podem ser modificados.
456
     *
457
     * @param  string $orientacao (Opcional) Estabelece a orientação da impressão
458
     *  (ex. P-retrato), se nada for fornecido será usado o padrão da NFe
459
     * @param  string $papel      (Opcional) Estabelece o tamanho do papel (ex. A4)
460
     * @return string O ID da NFe numero de 44 digitos extraido do arquivo XML
461
     */
462
    public function montaDANFE(
463
        $orientacao = '',
464
        $papel = 'A4',
465
        $logoAlign = 'C',
466
        $situacaoExterna = self::SIT_NONE,
467
        $classPdf = false,
468
        $depecNumReg = '',
469
        $margSup = 2,
470
        $margEsq = 2,
471
        $margInf = 2
472
    ) {
473
        //se a orientação estiver em branco utilizar o padrão estabelecido na NF
474
        if ($orientacao == '') {
475
            if ($this->tpImp == '1') {
476
                $orientacao = 'P';
477
            } else {
478
                $orientacao = 'L';
479
            }
480
        }
481
        $this->orientacao = $orientacao;
482
        $this->papel = $papel;
483
        $this->logoAlign = $logoAlign;
484
        $this->situacao_externa = $situacaoExterna;
485
        $this->numero_registro_dpec = $depecNumReg;
486
        //instancia a classe pdf
487
        if ($classPdf) {
488
            $this->pdf = $classPdf;
489
        } else {
490
            $this->pdf = new Pdf($this->orientacao, 'mm', $this->papel);
491
        }
492
        //margens do PDF, em milímetros. Obs.: a margem direita é sempre igual à
493
        //margem esquerda. A margem inferior *não* existe na FPDF, é definida aqui
494
        //apenas para controle se necessário ser maior do que a margem superior
495
        // posição inicial do conteúdo, a partir do canto superior esquerdo da página
496
        $xInic = $margEsq;
497
        $yInic = $margSup;
498
        if ($this->orientacao == 'P') {
499
            if ($papel == 'A4') {
500
                $maxW = 210;
501
                $maxH = 297;
502
            }
503
        } else {
504
            if ($papel == 'A4') {
505
                $maxH = 210;
506
                $maxW = 297;
507
                //se paisagem multiplica a largura do canhoto pela quantidade de canhotos
508
                $this->wCanhoto *= $this->qCanhoto;
509
            }
510
        }
511
        //total inicial de paginas
512
        $totPag = 1;
513
        //largura imprimivel em mm: largura da folha menos as margens esq/direita
514
        $this->wPrint = $maxW-($margEsq*2);
515
        //comprimento (altura) imprimivel em mm: altura da folha menos as margens
516
        //superior e inferior
517
        $this->hPrint = $maxH-$margSup-$margInf;
518
        // estabelece contagem de paginas
519
        $this->pdf->aliasNbPages();
520
        // fixa as margens
521
        $this->pdf->setMargins($margEsq, $margSup);
522
        $this->pdf->setDrawColor(0, 0, 0);
523
        $this->pdf->setFillColor(255, 255, 255);
524
        // inicia o documento
525
        $this->pdf->open();
526
        // adiciona a primeira página
527
        $this->pdf->addPage($this->orientacao, $this->papel);
528
        $this->pdf->setLineWidth(0.1);
529
        $this->pdf->setTextColor(0, 0, 0);
530
531
        //##################################################################
532
        // CALCULO DO NUMERO DE PAGINAS A SEREM IMPRESSAS
533
        //##################################################################
534
        //Verificando quantas linhas serão usadas para impressão das duplicatas
535
        $linhasDup = 0;
536
        if (($this->dup->length > 0) && ($this->dup->length <= 7)) {
537
            $linhasDup = 1;
538
        } elseif (($this->dup->length > 7) && ($this->dup->length <= 14)) {
539
            $linhasDup = 2;
540
        } elseif (($this->dup->length > 14) && ($this->dup->length <= 21)) {
541
            $linhasDup = 3;
542
        } elseif ($this->dup->length > 21) {
543
            // chinnonsantos 11/05/2016: Limite máximo de impressão de duplicatas na NFe,
544
            // só vai ser exibito as 21 primeiras duplicatas (parcelas de pagamento),
545
            // se não oculpa espaço d+, cada linha comporta até 7 duplicatas.
546
            $linhasDup = 3;
547
        }
548
        //verifica se será impressa a linha dos serviços ISSQN
549
        $linhaISSQN = 0;
550
        if ((isset($this->ISSQNtot)) && ($this->pSimpleGetValue($this->ISSQNtot, 'vServ') > 0)) {
551
            $linhaISSQN = 1;
552
        }
553
        //calcular a altura necessária para os dados adicionais
554
        if ($this->orientacao == 'P') {
555
            $this->wAdic = round($this->wPrint*0.66, 0);
556
        } else {
557
            $this->wAdic = round(($this->wPrint-$this->wCanhoto)*0.5, 0);
558
        }
559
        $fontProduto = array('font'=>$this->fontePadrao, 'size'=>7, 'style'=>'');
560
        $this->textoAdic = '';
561
        if (isset($this->retirada)) {
562
            $txRetCNPJ = ! empty($this->retirada->getElementsByTagName("CNPJ")->item(0)->nodeValue) ?
563
                $this->retirada->getElementsByTagName("CNPJ")->item(0)->nodeValue :
564
                '';
565
            $txRetxLgr = ! empty($this->retirada->getElementsByTagName("xLgr")->item(0)->nodeValue) ?
566
                $this->retirada->getElementsByTagName("xLgr")->item(0)->nodeValue :
567
                '';
568
            $txRetnro = ! empty($this->retirada->getElementsByTagName("nro")->item(0)->nodeValue) ?
569
                $this->retirada->getElementsByTagName("nro")->item(0)->nodeValue :
570
                's/n';
571
            $txRetxCpl = $this->pSimpleGetValue($this->retirada, "xCpl", " - ");
572
            $txRetxBairro = ! empty($this->retirada->getElementsByTagName("xBairro")->item(0)->nodeValue) ?
573
                $this->retirada->getElementsByTagName("xBairro")->item(0)->nodeValue :
574
                '';
575
            $txRetxMun = ! empty($this->retirada->getElementsByTagName("xMun")->item(0)->nodeValue) ?
576
                $this->retirada->getElementsByTagName("xMun")->item(0)->nodeValue :
577
                '';
578
            $txRetUF = ! empty($this->retirada->getElementsByTagName("UF")->item(0)->nodeValue) ?
579
                $this->retirada->getElementsByTagName("UF")->item(0)->nodeValue :
580
                '';
581
            $this->textoAdic .= "LOCAL DE RETIRADA : ".
582
                    $txRetCNPJ.
583
                    '-' .
584
                    $txRetxLgr .
585
                    ', ' .
586
                    $txRetnro .
587
                    ' ' .
588
                    $txRetxCpl .
589
                    ' - ' .
590
                    $txRetxBairro .
591
                    ' ' .
592
                    $txRetxMun .
593
                    ' - ' .
594
                    $txRetUF .
595
                    "\r\n";
596
        }
597
        //dados do local de entrega da mercadoria
598
        if (isset($this->entrega)) {
599
            $txRetCNPJ = ! empty($this->entrega->getElementsByTagName("CNPJ")->item(0)->nodeValue) ?
600
                $this->entrega->getElementsByTagName("CNPJ")->item(0)->nodeValue : '';
601
            $txRetxLgr = ! empty($this->entrega->getElementsByTagName("xLgr")->item(0)->nodeValue) ?
602
                $this->entrega->getElementsByTagName("xLgr")->item(0)->nodeValue : '';
603
            $txRetnro = ! empty($this->entrega->getElementsByTagName("nro")->item(0)->nodeValue) ?
604
                $this->entrega->getElementsByTagName("nro")->item(0)->nodeValue : 's/n';
605
            $txRetxCpl = $this->pSimpleGetValue($this->entrega, "xCpl", " - ");
606
            $txRetxBairro = ! empty($this->entrega->getElementsByTagName("xBairro")->item(0)->nodeValue) ?
607
                $this->entrega->getElementsByTagName("xBairro")->item(0)->nodeValue : '';
608
            $txRetxMun = ! empty($this->entrega->getElementsByTagName("xMun")->item(0)->nodeValue) ?
609
                $this->entrega->getElementsByTagName("xMun")->item(0)->nodeValue : '';
610
            $txRetUF = ! empty($this->entrega->getElementsByTagName("UF")->item(0)->nodeValue) ?
611
                $this->entrega->getElementsByTagName("UF")->item(0)->nodeValue : '';
612
            if ($this->textoAdic != '') {
613
                $this->textoAdic .= ". \r\n";
614
            }
615
            $this->textoAdic .= "LOCAL DE ENTREGA : ".$txRetCNPJ.'-'.$txRetxLgr.', '.$txRetnro.' '.$txRetxCpl.
616
               ' - '.$txRetxBairro.' '.$txRetxMun.' - '.$txRetUF."\r\n";
617
        }
618
        //informações adicionais
619
        $this->textoAdic .= $this->pGeraInformacoesDasNotasReferenciadas();
620
        if (isset($this->infAdic)) {
621
            $i = 0;
622
            if ($this->textoAdic != '') {
623
                $this->textoAdic .= ". \r\n";
624
            }
625
            $this->textoAdic .= ! empty($this->infAdic->getElementsByTagName("infCpl")->item(0)->nodeValue) ?
626
                'Inf. Contribuinte: ' .
627
                trim($this->pAnfavea($this->infAdic->getElementsByTagName("infCpl")->item(0)->nodeValue)) : '';
628
            $infPedido = $this->pGeraInformacoesDaTagCompra();
629
            if ($infPedido != "") {
630
                $this->textoAdic .= $infPedido;
631
            }
632
            $this->textoAdic .= $this->pSimpleGetValue($this->dest, "email", ' Email do Destinatário: ');
633
            $this->textoAdic .= ! empty($this->infAdic->getElementsByTagName("infAdFisco")->item(0)->nodeValue) ?
634
                "\r\n Inf. fisco: " .
635
                trim($this->infAdic->getElementsByTagName("infAdFisco")->item(0)->nodeValue) : '';
636
            $obsCont = $this->infAdic->getElementsByTagName("obsCont");
637
            if (isset($obsCont)) {
638
                foreach ($obsCont as $obs) {
639
                    $campo =  $obsCont->item($i)->getAttribute("xCampo");
640
                    $xTexto = ! empty($obsCont->item($i)->getElementsByTagName("xTexto")->item(0)->nodeValue) ?
641
                        $obsCont->item($i)->getElementsByTagName("xTexto")->item(0)->nodeValue : '';
642
                    $this->textoAdic .= "\r\n" . $campo . ':  ' . trim($xTexto);
643
                    $i++;
644
                }
645
            }
646
        }
647
        //INCLUSO pela NT 2013.003 Lei da Transparência
648
        //verificar se a informação sobre o valor aproximado dos tributos
649
        //já se encontra no campo de informações adicionais
650
        if ($this->exibirValorTributos) {
651
            $flagVTT = strpos(strtolower(trim($this->textoAdic)), 'valor');
652
            $flagVTT = $flagVTT || strpos(strtolower(trim($this->textoAdic)), 'vl');
653
            $flagVTT = $flagVTT && strpos(strtolower(trim($this->textoAdic)), 'aprox');
654
            $flagVTT = $flagVTT && (strpos(strtolower(trim($this->textoAdic)), 'trib') ||
655
                    strpos(strtolower(trim($this->textoAdic)), 'imp'));
656
            $vTotTrib = $this->pSimpleGetValue($this->ICMSTot, 'vTotTrib');
657
            if ($vTotTrib != '' && !$flagVTT) {
658
                $this->textoAdic .= "\n Valor Aproximado dos Tributos : R$ " . number_format($vTotTrib, 2, ",", ".");
659
            }
660
        }
661
        //fim da alteração NT 2013.003 Lei da Transparência
662
        $this->textoAdic = str_replace(";", "\n", $this->textoAdic);
663
        $alinhas = explode("\n", $this->textoAdic);
664
        $numlinhasdados = 0;
665
        foreach ($alinhas as $linha) {
666
            $numlinhasdados += $this->pGetNumLines($linha, $this->wAdic, $fontProduto);
667
        }
668
        $hdadosadic = round(($numlinhasdados+3) * $this->pdf->fontSize, 0);
669
        if ($hdadosadic < 10) {
670
            $hdadosadic = 10;
671
        }
672
        //altura disponivel para os campos da DANFE
673
        $hcabecalho = 47;//para cabeçalho
674
        $hdestinatario = 25;//para destinatario
675
        $hduplicatas = 12;//para cada grupo de 7 duplicatas
676
        $himposto = 18;// para imposto
677
        $htransporte = 25;// para transporte
678
        $hissqn = 11;// para issqn
679
        $hfooter = 5;// para rodape
680
        $hCabecItens = 4;//cabeçalho dos itens
681
        //alturas disponiveis para os dados
682
        $hDispo1 = $this->hPrint - 10 - ($hcabecalho +
683
            $hdestinatario + ($linhasDup * $hduplicatas) + $himposto + $htransporte +
684
            ($linhaISSQN * $hissqn) + $hdadosadic + $hfooter + $hCabecItens +
685
            $this->pSizeExtraTextoFatura());
686
        if ($this->orientacao == 'P') {
687
            $hDispo1 -= 23 * $this->qCanhoto;//para canhoto
688
            $w = $this->wPrint;
689
        } else {
690
            $hcanhoto = $this->hPrint;//para canhoto
691
            $w = $this->wPrint - $this->wCanhoto;
692
        }
693
        $hDispo2 = $this->hPrint - 10 - ($hcabecalho + $hfooter + $hCabecItens)-4;
694
        //Contagem da altura ocupada para impressão dos itens
695
        $fontProduto = array('font'=>$this->fontePadrao, 'size'=>7, 'style'=>'');
696
        $i = 0;
697
        $numlinhas = 0;
698
        $hUsado = $hCabecItens;
699
        $w2 = round($w*0.28, 0);
700
        $hDispo = $hDispo1;
701
        $totPag = 1;
702
        while ($i < $this->det->length) {
703
            $texto = $this->pDescricaoProduto($this->det->item($i));
704
            $numlinhas = $this->pGetNumLines($texto, $w2, $fontProduto);
705
            $hUsado += round(($numlinhas * $this->pdf->fontSize) + ($numlinhas * 0.5), 2);
706
            if ($hUsado > $hDispo) {
707
                $totPag++;
708
                $hDispo = $hDispo2;
709
                $hUsado = $hCabecItens;
710
                // Remove canhoto para páginas secundárias em modo paisagem ('L')
711
                $w2 = round($this->wPrint*0.28, 0);
712
                $i--; // decrementa para readicionar o item que não coube nessa pagina na outra.
713
            }
714
            $i++;
715
        } //fim da soma das areas de itens usadas
716
        $qtdeItens = $i; //controle da quantidade de itens no DANFE
717
        //montagem da primeira página
718
        $pag = 1;
719
        $x = $xInic;
720
        $y = $yInic;
721
        //coloca o(s) canhoto(s) da NFe
722
        if ($this->orientacao == 'P') {
723
            for ($i = 1; $i <= $this->qCanhoto; $i++) {
724
                $y = $this->pCanhoto($x, $y);
725
            }
726
        } else {
727
            for ($i = 1; $i <= $this->qCanhoto; $i++) {
728
                $this->pCanhoto($x, $y);
729
                $x = 25 * $i;
730
            }
731
        }
732
        //coloca o cabeçalho
733
        $y = $this->pCabecalhoDANFE($x, $y, $pag, $totPag);
734
        //coloca os dados do destinatário
735
        $y = $this->pDestinatarioDANFE($x, $y+1);
736
        
737
        
738
        //Verifica as formas de pagamento da nota fiscal
739
        $formaPag = array();
740
        if (isset($this->detPag) && $this->detPag->length > 0) {
741
            foreach ($this->detPag as $k => $d) {
742
                $fPag = !empty($this->detPag->item($k)->getElementsByTagName('tPag')->item(0)->nodeValue) ?
743
                    $this->detPag->item($k)->getElementsByTagName('tPag')->item(0)->nodeValue : '0';
744
                $formaPag[$fPag] = $fPag;
745
            }
746
        }
747
        //caso tenha boleto imprimir fatura
748
        if (($this->dup->length > 0) {
0 ignored issues
show
Bug introduced by
Avoid IF statements that are always true or false
Loading history...
749
            $y = $this->pFaturaDANFE($x, $y+1);
0 ignored issues
show
Bug introduced by
This code did not parse for me. Apparently, there is an error somewhere around this line:

Syntax error, unexpected ';'
Loading history...
750
        } else {
751
            //Se somente tiver a forma de pagamento sem pagamento ou outros não imprimir nada
752
            if (count($formaPag)=='1' && (isset($formaPag[90]) || isset($formaPag[99]))) {
753
                $y = $y;
754
            } else {
755
                //Se somente tiver a forma de pagamento sem pagamento ou outros não imprimir nada
756
                if (count($formaPag)=='1' && (isset($formaPag[90]) || isset($formaPag[99]))) {
757
                    $y = $y;
758
                } else {
759
                    //caso tenha mais de uma forma de pagamento ou seja diferente de boleto exibe a
760
                    //forma de pagamento e o valor
761
                    $y = $this->pagamentoDANFE($x, $y+1);
762
                }
763
            }
764
        }
765
        //coloca os dados dos impostos e totais da NFe
766
        $y = $this->pImpostoDANFE($x, $y+1);
767
        //coloca os dados do trasnporte
768
        $y = $this->pTransporteDANFE($x, $y+1);
769
        //itens da DANFE
770
        $nInicial = 0;
771
        $y = $this->pItensDANFE($x, $y+1, $nInicial, $hDispo1, $pag, $totPag, $hCabecItens);
772
        //coloca os dados do ISSQN
773
        if ($linhaISSQN == 1) {
774
            $y = $this->pIssqnDANFE($x, $y+4);
775
        } else {
776
            $y += 4;
777
        }
778
        //coloca os dados adicionais da NFe
779
        $y = $this->pDadosAdicionaisDANFE($x, $y, $hdadosadic);
780
        //coloca o rodapé da página
781
        if ($this->orientacao == 'P') {
782
            $this->pRodape($xInic, $y-1);
783
        } else {
784
            $this->pRodape($xInic, $this->hPrint + 1);
785
        }
786
        //loop para páginas seguintes
787
        for ($n = 2; $n <= $totPag; $n++) {
788
            // fixa as margens
789
            $this->pdf->setMargins($margEsq, $margSup);
790
            //adiciona nova página
791
            $this->pdf->addPage($this->orientacao, $this->papel);
792
            //ajusta espessura das linhas
793
            $this->pdf->setLineWidth(0.1);
794
            //seta a cor do texto para petro
795
            $this->pdf->setTextColor(0, 0, 0);
796
            // posição inicial do relatorio
797
            $x = $xInic;
798
            $y = $yInic;
799
            //coloca o cabeçalho na página adicional
800
            $y = $this->pCabecalhoDANFE($x, $y, $n, $totPag);
801
            //coloca os itens na página adicional
802
            $y = $this->pItensDANFE($x, $y+1, $nInicial, $hDispo2, $n, $totPag, $hCabecItens);
803
            //coloca o rodapé da página
804
            if ($this->orientacao == 'P') {
805
                $this->pRodape($xInic, $y + 4);
806
            } else {
807
                $this->pRodape($xInic, $this->hPrint + 4);
808
            }
809
            //se estiver na última página e ainda restar itens para inserir, adiciona mais uma página
810
            if ($n == $totPag && $this->qtdeItensProc < $qtdeItens) {
811
                $totPag++;
812
            }
813
        }
814
        //retorna o ID na NFe
815
        if ($classPdf!==false) {
816
            $aR = array(
817
             'id'=>str_replace('NFe', '', $this->infNFe->getAttribute("Id")),
818
             'classe_PDF'=>$this->pdf);
819
            return $aR;
820
        } else {
821
            return str_replace('NFe', '', $this->infNFe->getAttribute("Id"));
822
        }
823
    }//fim da função montaDANFE
824
825
    /**
826
     * anfavea
827
     * Função para transformar o campo cdata do padrão ANFAVEA para
828
     * texto imprimível
829
     *
830
     * @param  string $cdata campo CDATA
831
     * @return string conteúdo do campo CDATA como string
832
     */
833
    protected function pAnfavea($cdata = '')
834
    {
835
        if ($cdata == '') {
836
            return '';
837
        }
838
        //remove qualquer texto antes ou depois da tag CDATA
839
        $cdata = str_replace('<![CDATA[', '<CDATA>', $cdata);
840
        $cdata = str_replace(']]>', '</CDATA>', $cdata);
841
        $cdata = preg_replace('/\s\s+/', ' ', $cdata);
842
        $cdata = str_replace("> <", "><", $cdata);
843
        $len = strlen($cdata);
844
        $startPos = strpos($cdata, '<');
845
        if ($startPos === false) {
846
            return $cdata;
847
        }
848
        for ($x=$len; $x>0; $x--) {
849
            if (substr($cdata, $x, 1) == '>') {
850
                $endPos = $x;
851
                break;
852
            }
853
        }
854
        if ($startPos > 0) {
855
            $parte1 = substr($cdata, 0, $startPos);
856
        } else {
857
            $parte1 = '';
858
        }
859
        $parte2 = substr($cdata, $startPos, $endPos-$startPos+1);
860
        if ($endPos < $len) {
861
            $parte3 = substr($cdata, $endPos + 1, $len - $endPos - 1);
862
        } else {
863
            $parte3 = '';
864
        }
865
        $texto = trim($parte1).' '.trim($parte3);
866
        if (strpos($parte2, '<CDATA>') === false) {
867
            $cdata = '<CDATA>'.$parte2.'</CDATA>';
868
        } else {
869
            $cdata = $parte2;
870
        }
871
        //Retira a tag <FONTE IBPT> (caso existir) pois não é uma estrutura válida XML
872
        $cdata = str_replace('<FONTE IBPT>', '', $cdata);
873
        //carrega o xml CDATA em um objeto DOM
874
        $dom = new Dom();
875
        $dom->loadXML($cdata, LIBXML_NOBLANKS | LIBXML_NOEMPTYTAG);
876
        //$xml = $dom->saveXML();
0 ignored issues
show
Unused Code Comprehensibility introduced by
60% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
877
        //grupo CDATA infADprod
878
        $id = $dom->getElementsByTagName('id')->item(0);
879
        $div = $dom->getElementsByTagName('div')->item(0);
880
        $entg = $dom->getElementsByTagName('entg')->item(0);
881
        $dest = $dom->getElementsByTagName('dest')->item(0);
882
        $ctl = $dom->getElementsByTagName('ctl')->item(0);
883
        $ref = $dom->getElementsByTagName('ref')->item(0);
884
        if (isset($id)) {
885
            if ($id->hasAttributes()) {
886
                foreach ($id->attributes as $attr) {
887
                    $name = $attr->nodeName;
888
                    $value = $attr->nodeValue;
889
                    $texto .= " $name : $value";
890
                }
891
            }
892
        }
893
        if (isset($div)) {
894
            if ($div->hasAttributes()) {
895
                foreach ($div->attributes as $attr) {
896
                    $name = $attr->nodeName;
897
                    $value = $attr->nodeValue;
898
                    $texto .= " $name : $value";
899
                }
900
            }
901
        }
902
        if (isset($entg)) {
903
            if ($entg->hasAttributes()) {
904
                foreach ($entg->attributes as $attr) {
905
                    $name = $attr->nodeName;
906
                    $value = $attr->nodeValue;
907
                    $texto .= " $name : $value";
908
                }
909
            }
910
        }
911
        if (isset($dest)) {
912
            if ($dest->hasAttributes()) {
913
                foreach ($dest->attributes as $attr) {
914
                    $name = $attr->nodeName;
915
                    $value = $attr->nodeValue;
916
                    $texto .= " $name : $value";
917
                }
918
            }
919
        }
920
        if (isset($ctl)) {
921
            if ($ctl->hasAttributes()) {
922
                foreach ($ctl->attributes as $attr) {
923
                    $name = $attr->nodeName;
924
                    $value = $attr->nodeValue;
925
                    $texto .= " $name : $value";
926
                }
927
            }
928
        }
929
        if (isset($ref)) {
930
            if ($ref->hasAttributes()) {
931
                foreach ($ref->attributes as $attr) {
932
                    $name = $attr->nodeName;
933
                    $value = $attr->nodeValue;
934
                    $texto .= " $name : $value";
935
                }
936
            }
937
        }
938
        //grupo CADATA infCpl
939
        $t = $dom->getElementsByTagName('transmissor')->item(0);
940
        $r = $dom->getElementsByTagName('receptor')->item(0);
941
        $versao = ! empty($dom->getElementsByTagName('versao')->item(0)->nodeValue) ?
942
            'Versao:'.$dom->getElementsByTagName('versao')->item(0)->nodeValue.' ' : '';
943
        $especieNF = ! empty($dom->getElementsByTagName('especieNF')->item(0)->nodeValue) ?
944
            'Especie:'.$dom->getElementsByTagName('especieNF')->item(0)->nodeValue.' ' : '';
945
        $fabEntrega = ! empty($dom->getElementsByTagName('fabEntrega')->item(0)->nodeValue) ?
946
            'Entrega:'.$dom->getElementsByTagName('fabEntrega')->item(0)->nodeValue.' ' : '';
947
        $dca = ! empty($dom->getElementsByTagName('dca')->item(0)->nodeValue) ?
948
            'dca:'.$dom->getElementsByTagName('dca')->item(0)->nodeValue.' ' : '';
949
        $texto .= "".$versao.$especieNF.$fabEntrega.$dca;
950
        if (isset($t)) {
951
            if ($t->hasAttributes()) {
952
                $texto .= " Transmissor ";
953
                foreach ($t->attributes as $attr) {
954
                    $name = $attr->nodeName;
955
                    $value = $attr->nodeValue;
956
                    $texto .= " $name : $value";
957
                }
958
            }
959
        }
960
        if (isset($r)) {
961
            if ($r->hasAttributes()) {
962
                $texto .= " Receptor ";
963
                foreach ($r->attributes as $attr) {
964
                    $name = $attr->nodeName;
965
                    $value = $attr->nodeValue;
966
                    $texto .= " $name : $value";
967
                }
968
            }
969
        }
970
        return $texto;
971
    }
972
973
    /**
974
     * Dados brutos do PDF
975
     * @return string
976
     */
977
    public function render()
978
    {
979
        return $this->pdf->getPdf();
980
    }
981
982
    protected function pNotaCancelada()
983
    {
984
        if (!isset($this->nfeProc)) {
985
            return false;
986
        }
987
        $cStat = $this->pSimpleGetValue($this->nfeProc, "cStat");
988
        return $cStat == '101' ||
989
                $cStat == '151' ||
990
                $cStat == '135' ||
991
                $cStat == '155' ||
992
                $this->situacao_externa == self::SIT_CANCELADA;
993
    }
994
995
    protected function pNotaDPEC()
996
    {
997
        return $this->situacao_externa == self::SIT_DPEC && $this->numero_registro_dpec != '';
998
    }
999
1000
    protected function pNotaDenegada()
1001
    {
1002
        if (!isset($this->nfeProc)) {
1003
            return false;
1004
        }
1005
        //NÃO ERA NECESSÁRIO ESSA FUNÇÃO POIS SÓ SE USA
1006
        //1 VEZ NO ARQUIVO INTEIRO
1007
        $cStat = $this->pSimpleGetValue($this->nfeProc, "cStat");
1008
        return $cStat == '110' ||
1009
               $cStat == '301' ||
1010
               $cStat == '302' ||
1011
               $this->situacao_externa == self::SIT_DENEGADA;
1012
    }
1013
1014
    /**
1015
     *cabecalhoDANFE
1016
     * Monta o cabelhalho da DANFE (retrato e paisagem)
1017
     *
1018
     * @param  number $x      Posição horizontal inicial, canto esquerdo
1019
     * @param  number $y      Posição vertical inicial, canto superior
1020
     * @param  number $pag    Número da Página
1021
     * @param  number $totPag Total de páginas
1022
     * @return number Posição vertical final
1023
     */
1024
    protected function pCabecalhoDANFE($x = 0, $y = 0, $pag = '1', $totPag = '1')
1025
    {
1026
        $oldX = $x;
1027
        $oldY = $y;
1028
        if ($this->orientacao == 'P') {
1029
              $maxW = $this->wPrint;
1030
        } else {
1031
            if ($pag == 1) { // primeira página
1032
                $maxW = $this->wPrint - $this->wCanhoto;
1033
            } else { // páginas seguintes
1034
                $maxW = $this->wPrint;
1035
            }
1036
        }
1037
        //####################################################################################
1038
        //coluna esquerda identificação do emitente
1039
        $w = round($maxW*0.41, 0);
1040
        if ($this->orientacao == 'P') {
1041
            $aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>'I');
1042
        } else {
1043
            $aFont = array('font'=>$this->fontePadrao, 'size'=>8, 'style'=>'B');
1044
        }
1045
        $w1 = $w;
1046
        $h=32;
1047
        $oldY += $h;
1048
        $this->pTextBox($x, $y, $w, $h);
1049
        $texto = 'IDENTIFICAÇÃO DO EMITENTE';
1050
        $this->pTextBox($x, $y, $w, 5, $texto, $aFont, 'T', 'C', 0, '');
1051
        //estabelecer o alinhamento
1052
        //pode ser left L, center C, right R, full logo L
1053
        //se for left separar 1/3 da largura para o tamanho da imagem
1054
        //os outros 2/3 serão usados para os dados do emitente
1055
        //se for center separar 1/2 da altura para o logo e 1/2 para os dados
1056
        //se for right separa 2/3 para os dados e o terço seguinte para o logo
1057
        //se não houver logo centraliza dos dados do emitente
1058
        // coloca o logo
1059
        if (!empty($this->logomarca)) {
1060
            $logoInfo = getimagesize($this->logomarca);
1061
            $type = strtolower(explode('/', $logoInfo['mime'])[1]);
1062
            if ($type == 'png') {
1063
                $this->logomarca = $this->imagePNGtoJPG($this->logomarca);
1064
                $type == 'jpg';
1065
            }
1066
            //largura da imagem em mm
1067
            $logoWmm = ($logoInfo[0]/72)*25.4;
1068
            //altura da imagem em mm
1069
            $logoHmm = ($logoInfo[1]/72)*25.4;
1070
            if ($this->logoAlign=='L') {
1071
                $nImgW = round($w/3, 0);
1072
                $nImgH = round($logoHmm * ($nImgW/$logoWmm), 0);
1073
                $xImg = $x+1;
1074
                $yImg = round(($h-$nImgH)/2, 0)+$y;
1075
                //estabelecer posições do texto
1076
                $x1 = round($xImg + $nImgW +1, 0);
1077
                $y1 = round($h/3+$y, 0);
1078
                $tw = round(2*$w/3, 0);
1079
            } elseif ($this->logoAlign=='C') {
1080
                $nImgH = round($h/3, 0);
1081
                $nImgW = round($logoWmm * ($nImgH/$logoHmm), 0);
1082
                $xImg = round(($w-$nImgW)/2+$x, 0);
1083
                $yImg = $y+3;
1084
                $x1 = $x;
1085
                $y1 = round($yImg + $nImgH + 1, 0);
1086
                $tw = $w;
1087
            } elseif ($this->logoAlign=='R') {
1088
                $nImgW = round($w/3, 0);
1089
                $nImgH = round($logoHmm * ($nImgW/$logoWmm), 0);
1090
                $xImg = round($x+($w-(1+$nImgW)), 0);
1091
                $yImg = round(($h-$nImgH)/2, 0)+$y;
1092
                $x1 = $x;
1093
                $y1 = round($h/3+$y, 0);
1094
                $tw = round(2*$w/3, 0);
1095
            } elseif ($this->logoAlign=='F') {
1096
                $nImgH = round($h-5, 0);
1097
                $nImgW = round($logoWmm * ($nImgH/$logoHmm), 0);
1098
                $xImg = round(($w-$nImgW)/2+$x, 0);
1099
                $yImg = $y+3;
1100
                $x1 = $x;
1101
                $y1 = round($yImg + $nImgH + 1, 0);
1102
                $tw = $w;
1103
            }
1104
            $type = (substr($this->logomarca, 0, 7) === 'data://') ? 'jpg' : null;
1105
            $this->pdf->Image($this->logomarca, $xImg, $yImg, $nImgW, $nImgH, $type);
1106
        } else {
1107
            $x1 = $x;
1108
            $y1 = round($h/3+$y, 0);
1109
            $tw = $w;
1110
        }
1111
        // monta as informações apenas se diferente de full logo
1112
        if ($this->logoAlign !== 'F') {
1113
            //Nome emitente
1114
            $aFont = array('font'=>$this->fontePadrao, 'size'=>12, 'style'=>'B');
1115
            $texto = $this->emit->getElementsByTagName("xNome")->item(0)->nodeValue;
1116
            $this->pTextBox($x1, $y1, $tw, 8, $texto, $aFont, 'T', 'C', 0, '');
1117
            //endereço
1118
            $y1 = $y1+5;
1119
            $aFont = array('font'=>$this->fontePadrao, 'size'=>8, 'style'=>'');
1120
            $fone = ! empty($this->enderEmit->getElementsByTagName("fone")->item(0)->nodeValue)
1121
                 ? $this->enderEmit->getElementsByTagName("fone")->item(0)->nodeValue
1122
                 : '';
1123
            $lgr = $this->pSimpleGetValue($this->enderEmit, "xLgr");
1124
            $nro = $this->pSimpleGetValue($this->enderEmit, "nro");
1125
            $cpl = $this->pSimpleGetValue($this->enderEmit, "xCpl", " - ");
1126
            $bairro = $this->pSimpleGetValue($this->enderEmit, "xBairro");
1127
            $CEP = $this->pSimpleGetValue($this->enderEmit, "CEP");
1128
            $CEP = $this->pFormat($CEP, "#####-###");
1129
            $mun = $this->pSimpleGetValue($this->enderEmit, "xMun");
1130
            $UF = $this->pSimpleGetValue($this->enderEmit, "UF");
1131
            $texto = $lgr . ", " . $nro . $cpl . "\n" . $bairro . " - "
1132
                    . $CEP . "\n" . $mun . " - " . $UF . " "
1133
                    . "Fone/Fax: " . $fone;
1134
            $this->pTextBox($x1, $y1, $tw, 8, $texto, $aFont, 'T', 'C', 0, '');
1135
        }
1136
1137
        //####################################################################################
1138
        //coluna central Danfe
1139
        $x += $w;
1140
        $w=round($maxW * 0.17, 0);//35;
1141
        $w2 = $w;
1142
        $h = 32;
1143
        $this->pTextBox($x, $y, $w, $h);
1144
1145
        if (! $this->pNotaCancelada()) {
1146
            // A PRINCIPIO NÃO PRECISAVA, POIS A NFE ESTÁ AUTORIZADA,
1147
            // SÓ SE RETIRA O DANFE PARA NOTAS NÃO AUTORIZADAS
1148
            $texto = "DANFE";
1149
            $aFont = array('font'=>$this->fontePadrao, 'size'=>14, 'style'=>'B');
1150
            $this->pTextBox($x, $y+1, $w, $h, $texto, $aFont, 'T', 'C', 0, '');
1151
            $aFont = array('font'=>$this->fontePadrao, 'size'=>8, 'style'=>'');
1152
            $texto = 'Documento Auxiliar da Nota Fiscal Eletrônica';
1153
            $h = 20;
1154
            $this->pTextBox($x, $y+6, $w, $h, $texto, $aFont, 'T', 'C', 0, '', false);
1155
        }
1156
1157
        $aFont = array('font'=>$this->fontePadrao, 'size'=>8, 'style'=>'');
1158
        $texto = '0 - ENTRADA';
1159
        $y1 = $y + 14;
1160
        $h = 8;
1161
        $this->pTextBox($x+2, $y1, $w, $h, $texto, $aFont, 'T', 'L', 0, '');
1162
        $texto = '1 - SAÍDA';
1163
        $y1 = $y + 17;
1164
        $this->pTextBox($x+2, $y1, $w, $h, $texto, $aFont, 'T', 'L', 0, '');
1165
        //tipo de nF
1166
        $aFont = array('font'=>$this->fontePadrao, 'size'=>12, 'style'=>'B');
1167
        $y1 = $y + 13;
1168
        $h = 7;
1169
        $texto = $this->ide->getElementsByTagName('tpNF')->item(0)->nodeValue;
1170
        $this->pTextBox($x+27, $y1, 5, $h, $texto, $aFont, 'C', 'C', 1, '');
1171
        //numero da NF
1172
        $aFont = array('font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B');
1173
        $y1 = $y + 20;
1174
        $numNF = str_pad($this->ide->getElementsByTagName('nNF')->item(0)->nodeValue, 9, "0", STR_PAD_LEFT);
1175
        $numNF = $this->pFormat($numNF, "###.###.###");
1176
        $texto = "Nº. " . $numNF;
1177
        $this->pTextBox($x, $y1, $w, $h, $texto, $aFont, 'C', 'C', 0, '');
1178
        //Série
1179
        $y1 = $y + 23;
1180
        $serie = str_pad($this->ide->getElementsByTagName('serie')->item(0)->nodeValue, 3, "0", STR_PAD_LEFT);
1181
        $texto = "Série " . $serie;
1182
        $this->pTextBox($x, $y1, $w, $h, $texto, $aFont, 'C', 'C', 0, '');
1183
        //numero paginas
1184
        $aFont = array('font'=>$this->fontePadrao, 'size'=>8, 'style'=>'I');
1185
        $y1 = $y + 26;
1186
        $texto = "Folha " . $pag . "/" . $totPag;
1187
        $this->pTextBox($x, $y1, $w, $h, $texto, $aFont, 'C', 'C', 0, '');
1188
1189
        //####################################################################################
1190
        //coluna codigo de barras
1191
        $x += $w;
1192
        $w = ($maxW-$w1-$w2);//85;
1193
        $w3 = $w;
1194
        $h = 32;
1195
        $this->pTextBox($x, $y, $w, $h);
1196
        $this->pdf->SetFillColor(0, 0, 0);
1197
        $chave_acesso = str_replace('NFe', '', $this->infNFe->getAttribute("Id"));
1198
        $bW = 75;
1199
        $bH = 12;
1200
        //codigo de barras
1201
        $this->pdf->Code128($x+(($w-$bW)/2), $y+2, $chave_acesso, $bW, $bH);
1202
        //linhas divisorias
1203
        $this->pdf->Line($x, $y+4+$bH, $x+$w, $y+4+$bH);
1204
        $this->pdf->Line($x, $y+12+$bH, $x+$w, $y+12+$bH);
1205
        $aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>'');
1206
        $y1 = $y+4+$bH;
1207
        $h = 7;
1208
        $texto = 'CHAVE DE ACESSO';
1209
        $this->pTextBox($x, $y1, $w, $h, $texto, $aFont, 'T', 'L', 0, '');
1210
        $aFont = array('font'=>$this->fontePadrao, 'size'=>8, 'style'=>'B');
1211
        $y1 = $y+8+$bH;
1212
        $texto = $this->pFormat($chave_acesso, $this->formatoChave);
1213
        $this->pTextBox($x+2, $y1, $w-2, $h, $texto, $aFont, 'T', 'C', 0, '');
1214
        $y1 = $y+12+$bH;
1215
        $aFont = array('font'=>$this->fontePadrao, 'size'=>8, 'style'=>'');
1216
        $chaveContingencia="";
1217
        if ($this->pNotaDPEC()) {
1218
            $cabecalhoProtoAutorizacao = 'NÚMERO DE REGISTRO DPEC';
1219
        } else {
1220
            $cabecalhoProtoAutorizacao = 'PROTOCOLO DE AUTORIZAÇÃO DE USO';
1221
        }
1222
        if (($this->tpEmis == 2 || $this->tpEmis == 5) && !$this->pNotaDPEC()) {
1223
            $cabecalhoProtoAutorizacao = "DADOS DA NF-E";
1224
            $chaveContingencia = $this->pGeraChaveAdicionalDeContingencia();
1225
            $this->pdf->SetFillColor(0, 0, 0);
1226
            //codigo de barras
1227
            $this->pdf->Code128($x+11, $y1+1, $chaveContingencia, $bW*.9, $bH/2);
1228
        } else {
1229
            $texto = 'Consulta de autenticidade no portal nacional da NF-e';
1230
            $this->pTextBox($x+2, $y1, $w-2, $h, $texto, $aFont, 'T', 'C', 0, '');
1231
            $y1 = $y+16+$bH;
1232
            $texto = 'www.nfe.fazenda.gov.br/portal ou no site da Sefaz Autorizadora';
1233
            $this->pTextBox(
1234
                $x+2,
1235
                $y1,
1236
                $w-2,
1237
                $h,
1238
                $texto,
1239
                $aFont,
1240
                'T',
1241
                'C',
1242
                0,
1243
                'http://www.nfe.fazenda.gov.br/portal ou no site da Sefaz Autorizadora'
1244
            );
1245
        }
1246
1247
        //####################################################################################
1248
        //Dados da NF do cabeçalho
1249
        //natureza da operação
1250
        $texto = 'NATUREZA DA OPERAÇÃO';
1251
        $aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>'');
1252
        $w = $w1+$w2;
1253
        $y = $oldY;
1254
        $oldY += $h;
1255
        $x = $oldX;
1256
        $h = 7;
1257
        $this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 1, '');
1258
        $texto = $this->ide->getElementsByTagName("natOp")->item(0)->nodeValue;
1259
        $aFont = array('font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B');
1260
        $this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'B', 'C', 0, '');
1261
        $x += $w;
1262
        $w = $w3;
1263
        //PROTOCOLO DE AUTORIZAÇÃO DE USO ou DADOS da NF-E
1264
        $aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>'');
1265
        $this->pTextBox($x, $y, $w, $h, $cabecalhoProtoAutorizacao, $aFont, 'T', 'L', 1, '');
1266
        // algumas NFe podem estar sem o protocolo de uso portanto sua existencia deve ser
1267
        // testada antes de tentar obter a informação.
1268
        // NOTA : DANFE sem protocolo deve existir somente no caso de contingência !!!
1269
        // Além disso, existem várias NFes em contingência que eu recebo com protocolo de autorização.
1270
        // Na minha opinião, deveríamos mostra-lo, mas o  manual  da NFe v4.01 diz outra coisa...
1271
        if (($this->tpEmis == 2 || $this->tpEmis == 5) && !$this->pNotaDPEC()) {
1272
            $aFont = array('font'=>$this->fontePadrao, 'size'=>8, 'style'=>'B');
1273
            $texto = $this->pFormat($chaveContingencia, "#### #### #### #### #### #### #### #### ####");
1274
            $cStat = '';
1275
        } else {
1276
            $aFont = array('font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B');
1277
            if ($this->pNotaDPEC()) {
1278
                $texto = $this->numero_registro_dpec;
1279
                $cStat = '';
1280
            } else {
1281
                if (isset($this->nfeProc)) {
1282
                    $texto = ! empty($this->nfeProc->getElementsByTagName("nProt")->item(0)->nodeValue) ?
1283
                            $this->nfeProc->getElementsByTagName("nProt")->item(0)->nodeValue : '';
1284
                    $tsHora = $this->pConvertTime($this->nfeProc->getElementsByTagName("dhRecbto")->item(0)->nodeValue);
1285
                    if ($texto != '') {
1286
                        $texto .= "  -  " . date('d/m/Y H:i:s', $tsHora);
1287
                    }
1288
                    $cStat = $this->nfeProc->getElementsByTagName("cStat")->item(0)->nodeValue;
1289
                } else {
1290
                    $texto = '';
1291
                    $cStat = '';
1292
                }
1293
            }
1294
        }
1295
        $this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'B', 'C', 0, '');
1296
        //####################################################################################
1297
        //INSCRIÇÃO ESTADUAL
1298
        $w = round($maxW * 0.333, 0);
1299
        $y += $h;
1300
        $oldY += $h;
1301
        $x = $oldX;
1302
        $texto = 'INSCRIÇÃO ESTADUAL';
1303
        $aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>'');
1304
        $this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 1, '');
1305
        $texto = $this->pSimpleGetValue($this->emit, "IE");
1306
        $aFont = array('font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B');
1307
        $this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'B', 'C', 0, '');
1308
        //INSCRIÇÃO ESTADUAL DO SUBST. TRIBUT.
1309
        $x += $w;
1310
        $texto = 'INSCRIÇÃO ESTADUAL DO SUBST. TRIBUT.';
1311
        $aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>'');
1312
        $this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 1, '');
1313
        $texto = ! empty($this->emit->getElementsByTagName("IEST")->item(0)->nodeValue)
1314
             ? $this->emit->getElementsByTagName("IEST")->item(0)->nodeValue
1315
             : '';
1316
        $aFont = array('font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B');
1317
        $this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'B', 'C', 0, '');
1318
        //CNPJ
1319
        $x += $w;
1320
        $w = ($maxW-(2*$w));
1321
        $texto = 'CNPJ / CPF';
1322
        $aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>'');
1323
        $this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 1, '');
1324
        //Pegando valor do CPF/CNPJ
1325
        if (! empty($this->emit->getElementsByTagName("CNPJ")->item(0)->nodeValue)) {
1326
            $texto = $this->pFormat(
1327
                $this->emit->getElementsByTagName("CNPJ")->item(0)->nodeValue,
1328
                "###.###.###/####-##"
1329
            );
1330
        } else {
1331
            $texto = ! empty($this->emit->getElementsByTagName("CPF")->item(0)->nodeValue) ?
1332
                $this->pFormat(
1333
                    $this->emit->getElementsByTagName("CPF")->item(0)->nodeValue,
1334
                    "###.###.###-##"
1335
                ) : '';
1336
        }
1337
        $aFont = array('font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B');
1338
        $this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'B', 'C', 0, '');
1339
1340
        //####################################################################################
1341
        //Indicação de NF Homologação, cancelamento e falta de protocolo
1342
        $tpAmb = $this->ide->getElementsByTagName('tpAmb')->item(0)->nodeValue;
1343
        //indicar cancelamento
1344
        if ($this->pNotaCancelada()) {
1345
            //101 Cancelamento
1346
            $x = 10;
1347
            $y = $this->hPrint-130;
1348
            $h = 25;
1349
            $w = $maxW-(2*$x);
1350
            $this->pdf->SetTextColor(90, 90, 90);
1351
            $texto = "NFe CANCELADA";
1352
            $aFont = array('font'=>$this->fontePadrao, 'size'=>48, 'style'=>'B');
1353
            $this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'C', 'C', 0, '');
1354
            $this->pdf->SetTextColor(0, 0, 0);
1355
        }
1356
1357
        if ($this->pNotaDPEC() || $this->tpEmis == 4) {
1358
            //DPEC
1359
            $x = 10;
1360
            $y = $this->hPrint-130;
1361
            $h = 25;
1362
            $w = $maxW-(2*$x);
1363
            $this->pdf->SetTextColor(200, 200, 200);
1364
            $texto = "DANFE impresso em contingência -\n".
1365
                     "DPEC regularmente recebido pela Receita\n".
1366
                     "Federal do Brasil";
1367
            $aFont = array('font'=>$this->fontePadrao, 'size'=>48, 'style'=>'B');
1368
            $this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'C', 'C', 0, '');
1369
            $this->pdf->SetTextColor(0, 0, 0);
1370
        }
1371
        if ($this->pNotaDenegada()) {
1372
            //110 301 302 Denegada
0 ignored issues
show
Unused Code Comprehensibility introduced by
43% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
1373
            $x = 10;
1374
            $y = $this->hPrint-130;
1375
            $h = 25;
1376
            $w = $maxW-(2*$x);
1377
            $this->pdf->SetTextColor(90, 90, 90);
1378
            $texto = "NFe USO DENEGADO";
1379
            $aFont = array('font'=>$this->fontePadrao, 'size'=>48, 'style'=>'B');
1380
            $this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'C', 'C', 0, '');
1381
            $y += $h;
1382
            $h = 5;
1383
            $w = $maxW-(2*$x);
1384
            if (isset($this->infProt)) {
1385
                $xMotivo = $this->infProt->getElementsByTagName("xMotivo")->item(0)->nodeValue;
1386
            } else {
1387
                $xMotivo = '';
1388
            }
1389
            $texto = "SEM VALOR FISCAL\n".$xMotivo;
1390
            $aFont = array('font'=>$this->fontePadrao, 'size'=>48, 'style'=>'B');
1391
            $this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'C', 'C', 0, '');
1392
            $this->pdf->SetTextColor(0, 0, 0);
1393
        }
1394
        //indicar sem valor
1395
        if ($tpAmb != 1) {
1396
            $x = 10;
1397
            if ($this->orientacao == 'P') {
1398
                $y = round($this->hPrint*2/3, 0);
1399
            } else {
1400
                $y = round($this->hPrint/2, 0);
1401
            }
1402
            $h = 5;
1403
            $w = $maxW-(2*$x);
1404
            $this->pdf->SetTextColor(90, 90, 90);
1405
            $texto = "SEM VALOR FISCAL";
1406
            $aFont = array('font'=>$this->fontePadrao, 'size'=>48, 'style'=>'B');
1407
            $this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'C', 'C', 0, '');
1408
            $aFont = array('font'=>$this->fontePadrao, 'size'=>30, 'style'=>'B');
1409
            $texto = "AMBIENTE DE HOMOLOGAÇÃO";
1410
            $this->pTextBox($x, $y+14, $w, $h, $texto, $aFont, 'C', 'C', 0, '');
1411
            $this->pdf->SetTextColor(0, 0, 0);
1412
        } else {
1413
            $x = 10;
1414
            if ($this->orientacao == 'P') {
1415
                $y = round($this->hPrint*2/3, 0);
1416
            } else {
1417
                $y = round($this->hPrint/2, 0);
1418
            }//fim orientacao
1419
            $h = 5;
1420
            $w = $maxW-(2*$x);
1421
            $this->pdf->SetTextColor(90, 90, 90);
1422
            //indicar FALTA DO PROTOCOLO se NFe não for em contingência
1423
            if (($this->tpEmis == 2 || $this->tpEmis == 5) && !$this->pNotaDPEC()) {
1424
                //Contingência
1425
                $texto = "DANFE Emitido em Contingência";
1426
                $aFont = array('font'=>$this->fontePadrao, 'size'=>48, 'style'=>'B');
1427
                $this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'C', 'C', 0, '');
1428
                $aFont = array('font'=>$this->fontePadrao, 'size'=>30, 'style'=>'B');
1429
                $texto = "devido à problemas técnicos";
1430
                $this->pTextBox($x, $y+12, $w, $h, $texto, $aFont, 'C', 'C', 0, '');
1431
            } else {
1432
                if (!isset($this->nfeProc)) {
1433
                    if (!$this->pNotaDPEC()) {
1434
                        $texto = "SEM VALOR FISCAL";
1435
                        $aFont = array('font'=>$this->fontePadrao, 'size'=>48, 'style'=>'B');
1436
                        $this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'C', 'C', 0, '');
1437
                    }
1438
                    $aFont = array('font'=>$this->fontePadrao, 'size'=>30, 'style'=>'B');
1439
                    $texto = "FALTA PROTOCOLO DE APROVAÇÃO DA SEFAZ";
1440
                    if (!$this->pNotaDPEC()) {
1441
                        $this->pTextBox($x, $y+12, $w, $h, $texto, $aFont, 'C', 'C', 0, '');
1442
                    } else {
1443
                        $this->pTextBox($x, $y+25, $w, $h, $texto, $aFont, 'C', 'C', 0, '');
1444
                    }
1445
                }//fim nefProc
1446
            }//fim tpEmis
1447
            $this->pdf->SetTextColor(0, 0, 0);
1448
        }
1449
        return $oldY;
1450
    } //fim cabecalhoDANFE
1451
1452
    /**
1453
     * destinatarioDANFE
1454
     * Monta o campo com os dados do destinatário na DANFE. (retrato e paisagem)
1455
     *
1456
     * @name   destinatarioDANFE
1457
     * @param  number $x Posição horizontal canto esquerdo
1458
     * @param  number $y Posição vertical canto superior
1459
     * @return number Posição vertical final
1460
     */
1461
    protected function pDestinatarioDANFE($x = 0, $y = 0)
1462
    {
1463
        //####################################################################################
1464
        //DESTINATÁRIO / REMETENTE
1465
        $oldX = $x;
1466
        $oldY = $y;
1467
        if ($this->orientacao == 'P') {
1468
            $maxW = $this->wPrint;
1469
        } else {
1470
            $maxW = $this->wPrint - $this->wCanhoto;
1471
        }
1472
        $w = $maxW;
1473
        $h = 7;
1474
        $texto = 'DESTINATÁRIO / REMETENTE';
1475
        $aFont = array('font'=>$this->fontePadrao, 'size'=>7, 'style'=>'B');
1476
        $this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 0, '');
1477
        //NOME / RAZÃO SOCIAL
1478
        $w = round($maxW*0.61, 0);
1479
        $w1 = $w;
1480
        $y += 3;
1481
        $texto = 'NOME / RAZÃO SOCIAL';
1482
        $aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>'');
1483
        $this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 1, '');
1484
        $texto = $this->dest->getElementsByTagName("xNome")->item(0)->nodeValue;
1485
        $aFont = array('font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B');
1486
        if ($this->orientacao == 'P') {
1487
            $this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'B', 'L', 0, '');
1488
        } else {
1489
            $this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'B', 'L', 1, '');
1490
        }
1491
        //CNPJ / CPF
1492
        $x += $w;
1493
        $w = round($maxW*0.23, 0);
1494
        $w2 = $w;
1495
        $texto = 'CNPJ / CPF';
1496
        $aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>'');
1497
        $this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 1, '');
1498
        //Pegando valor do CPF/CNPJ
1499
        if (! empty($this->dest->getElementsByTagName("CNPJ")->item(0)->nodeValue)) {
1500
            $texto = $this->pFormat(
1501
                $this->dest->getElementsByTagName("CNPJ")->item(0)->nodeValue,
1502
                "###.###.###/####-##"
1503
            );
1504
        } else {
1505
            $texto = ! empty($this->dest->getElementsByTagName("CPF")->item(0)->nodeValue) ?
1506
                    $this->pFormat(
1507
                        $this->dest->getElementsByTagName("CPF")->item(0)->nodeValue,
1508
                        "###.###.###-##"
1509
                    ) : '';
1510
        }
1511
        $aFont = array('font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B');
1512
        $this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'B', 'C', 0, '');
1513
        //DATA DA EMISSÃO
1514
        $x += $w;
1515
        $w = $maxW-($w1+$w2);
1516
        $wx = $w;
1517
        $texto = 'DATA DA EMISSÃO';
1518
        $aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>'');
1519
        $this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 1, '');
1520
        $dEmi = ! empty($this->ide->getElementsByTagName("dEmi")->item(0)->nodeValue) ?
1521
                $this->ide->getElementsByTagName("dEmi")->item(0)->nodeValue : '';
1522
        if ($dEmi == '') {
1523
            $dEmi = ! empty($this->ide->getElementsByTagName("dhEmi")->item(0)->nodeValue) ?
1524
                    $this->ide->getElementsByTagName("dhEmi")->item(0)->nodeValue : '';
1525
            $aDemi = explode('T', $dEmi);
1526
            $dEmi = $aDemi[0];
1527
        }
1528
        $texto = $this->pYmd2dmy($dEmi);
1529
        $aFont = array('font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B');
1530
        if ($this->orientacao == 'P') {
1531
            $this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'B', 'C', 0, '');
1532
        } else {
1533
            $this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'B', 'C', 1, '');
1534
        }
1535
        //ENDEREÇO
1536
        $w = round($maxW*0.47, 0);
1537
        $w1 = $w;
1538
        $y += $h;
1539
        $x = $oldX;
1540
        $texto = 'ENDEREÇO';
1541
        $aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>'');
1542
        $this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 1, '');
1543
        $texto = $this->dest->getElementsByTagName("xLgr")->item(0)->nodeValue;
1544
        $texto .= ', ' . $this->dest->getElementsByTagName("nro")->item(0)->nodeValue;
1545
        $texto .= $this->pSimpleGetValue($this->dest, "xCpl", " - ");
1546
1547
        $aFont = array('font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B');
1548
        $this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'B', 'L', 0, '', true);
1549
        //BAIRRO / DISTRITO
1550
        $x += $w;
1551
        $w = round($maxW*0.21, 0);
1552
        $w2 = $w;
1553
        $texto = 'BAIRRO / DISTRITO';
1554
        $aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>'');
1555
        $this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 1, '');
1556
        $texto = $this->dest->getElementsByTagName("xBairro")->item(0)->nodeValue;
1557
        $aFont = array('font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B');
1558
        $this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'B', 'C', 0, '');
1559
        //CEP
1560
        $x += $w;
1561
        $w = $maxW-$w1-$w2-$wx;
1562
        $w2 = $w;
1563
        $texto = 'CEP';
1564
        $aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>'');
1565
        $this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 1, '');
1566
        $texto = ! empty($this->dest->getElementsByTagName("CEP")->item(0)->nodeValue) ?
1567
                $this->dest->getElementsByTagName("CEP")->item(0)->nodeValue : '';
1568
        $texto = $this->pFormat($texto, "#####-###");
1569
        $aFont = array('font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B');
1570
        $this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'B', 'C', 0, '');
1571
        //DATA DA SAÍDA
1572
        $x += $w;
1573
        $w = $wx;
1574
        $texto = 'DATA DA SAÍDA/ENTRADA';
1575
        $aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>'');
1576
        $this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 1, '');
1577
        $dSaiEnt = ! empty($this->ide->getElementsByTagName("dSaiEnt")->item(0)->nodeValue) ?
1578
                $this->ide->getElementsByTagName("dSaiEnt")->item(0)->nodeValue : '';
1579
        if ($dSaiEnt == '') {
1580
            $dSaiEnt = ! empty($this->ide->getElementsByTagName("dhSaiEnt")->item(0)->nodeValue) ?
1581
                    $this->ide->getElementsByTagName("dhSaiEnt")->item(0)->nodeValue : '';
1582
            $aDsaient = explode('T', $dSaiEnt);
1583
            $dSaiEnt = $aDsaient[0];
1584
        }
1585
        $texto = $this->pYmd2dmy($dSaiEnt);
1586
        $aFont = array('font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B');
1587
        $this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'B', 'C', 0, '');
1588
        //MUNICÍPIO
1589
        $w = $w1;
1590
        $y += $h;
1591
        $x = $oldX;
1592
        $texto = 'MUNICÍPIO';
1593
        $aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>'');
1594
        $this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 1, '');
1595
        $texto = $this->dest->getElementsByTagName("xMun")->item(0)->nodeValue;
1596
        if (strtoupper(trim($texto)) == "EXTERIOR" && $this->dest->getElementsByTagName("xPais")->length > 0) {
1597
            $texto .= " - " .  $this->dest->getElementsByTagName("xPais")->item(0)->nodeValue;
1598
        }
1599
        $aFont = array('font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B');
1600
        $this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'B', 'L', 0, '');
1601
        //UF
1602
        $x += $w;
1603
        $w = 8;
1604
        $texto = 'UF';
1605
        $aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>'');
1606
        $this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 1, '');
1607
        $texto = $this->dest->getElementsByTagName("UF")->item(0)->nodeValue;
1608
        $aFont = array('font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B');
1609
        $this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'B', 'C', 0, '');
1610
        //FONE / FAX
1611
        $x += $w;
1612
        $w = round(($maxW -$w1-$wx-8)/2, 0);
1613
        $w3 = $w;
1614
        $texto = 'FONE / FAX';
1615
        $aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>'');
1616
        $this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 1, '');
1617
        $texto = ! empty($this->dest->getElementsByTagName("fone")->item(0)->nodeValue) ?
1618
                $this->dest->getElementsByTagName("fone")->item(0)->nodeValue : '';
1619
        $aFont = array('font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B');
1620
        $this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'B', 'C', 0, '');
1621
        //INSCRIÇÃO ESTADUAL
1622
        $x += $w;
1623
        $w = $maxW -$w1-$wx-8-$w3;
1624
        $texto = 'INSCRIÇÃO ESTADUAL';
1625
        $aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>'');
1626
        $this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 1, '');
1627
        $IE = $this->dest->getElementsByTagName("IE");
1628
        $texto = ($IE && $IE->length > 0) ? $IE->item(0)->nodeValue : '';
1629
        $aFont = array('font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B');
1630
        $this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'B', 'C', 0, '');
1631
        //HORA DA SAÍDA
1632
        $x += $w;
1633
        $w = $wx;
1634
        $texto = 'HORA DA SAÍDA/ENTRADA';
1635
        $aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>'');
1636
        $this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 1, '');
1637
        $hSaiEnt = ! empty($this->ide->getElementsByTagName("hSaiEnt")->item(0)->nodeValue) ?
1638
                $this->ide->getElementsByTagName("hSaiEnt")->item(0)->nodeValue : '';
1639
        if ($hSaiEnt == '') {
1640
            $dhSaiEnt = ! empty($this->ide->getElementsByTagName("dhSaiEnt")->item(0)->nodeValue) ?
1641
                    $this->ide->getElementsByTagName("dhSaiEnt")->item(0)->nodeValue : '';
1642
            $tsDhSaiEnt = $this->pConvertTime($dhSaiEnt);
1643
            if ($tsDhSaiEnt != '') {
1644
                $hSaiEnt = date('H:i:s', $tsDhSaiEnt);
1645
            }
1646
        }
1647
        $texto = $hSaiEnt;
1648
        $aFont = array('font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B');
1649
        $this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'B', 'C', 0, '');
1650
        return ($y + $h);
1651
    } //fim da função destinatarioDANFE
1652
1653
     /**
1654
     * pGetTextoFatura
1655
     * Gera a String do Texto da Fatura
1656
      *
1657
     * @name   getTextoFatura
1658
     * @return uma String com o texto ou "";
1659
     */
1660
    protected function pGetTextoFatura()
1661
    {
1662
        if (isset($this->cobr)) {
1663
            $fat = $this->cobr->getElementsByTagName("fat")->item(0);
1664
            if (isset($fat)) {
1665
                if (!empty($this->pSimpleGetValue($this->ide, "indPag"))) {
1666
                    $textoIndPag = "";
1667
                    $indPag = $this->pSimpleGetValue($this->ide, "indPag");
1668
                    if ($indPag === "0") {
1669
                        $textoIndPag = "Pagamento à Vista - ";
1670
                    } elseif ($indPag === "1") {
1671
                        $textoIndPag = "Pagamento à Prazo - ";
1672
                    }
1673
                    $nFat = $this->pSimpleGetValue($fat, "nFat", "Fatura: ");
1674
                    $vOrig = $this->pSimpleGetValue($fat, "vOrig", " Valor Original: ");
1675
                    $vDesc = $this->pSimpleGetValue($fat, "vDesc", " Desconto: ");
1676
                    $vLiq = $this->pSimpleGetValue($fat, "vLiq", " Valor Líquido: ");
1677
                    $texto = $textoIndPag . $nFat . $vOrig . $vDesc . $vLiq;
1678
                    return $texto;
1679
                } else {
1680
                    $pag = $this->dom->getElementsByTagName("pag");
1681
                    if ($tPag = $this->pSimpleGetValue($pag->item(0), "tPag")) {
1682
                        return $this->tipoPag($tPag);
1683
                    }
1684
                }
1685
            }
1686
        }
1687
        return "";
1688
    } //fim getTextoFatura
1689
1690
     /**
1691
     * pSizeExtraTextoFatura
1692
     * Calcula o espaço ocupado pelo texto da fatura. Este espaço só é utilizado quando não houver duplicata.
1693
      *
1694
     * @name   pSizeExtraTextoFatura
1695
     * @return integer
1696
     */
1697
    protected function pSizeExtraTextoFatura()
1698
    {
1699
        $textoFatura = $this->pGetTextoFatura();
1700
        //verificar se existem duplicatas
1701
        if ($this->dup->length == 0 && $textoFatura !== "") {
1702
            return 10;
1703
        }
1704
        return 0;
1705
    }
1706
1707
    /**
1708
     * faturaDANFE
1709
     * Monta o campo de duplicatas da DANFE (retrato e paisagem)
1710
     *
1711
     * @name   faturaDANFE
1712
     * @param  number $x Posição horizontal canto esquerdo
1713
     * @param  number $y Posição vertical canto superior
1714
     * @return number Posição vertical final
1715
     */
1716
    protected function pFaturaDANFE($x, $y)
1717
    {
1718
        $linha = 1;
1719
        $h = 8+3;
1720
        $oldx = $x;
1721
        $textoFatura = $this->pGetTextoFatura();
1722
        //verificar se existem duplicatas
1723
        if ($this->dup->length > 0 || $textoFatura !== "") {
1724
            //#####################################################################
1725
            //FATURA / DUPLICATA
1726
            $texto = "FATURA / DUPLICATA";
1727
            if ($this->orientacao == 'P') {
1728
                $w = $this->wPrint;
1729
            } else {
1730
                $w = 271;
1731
            }
1732
            $h = 8;
1733
            $aFont = array('font'=>$this->fontePadrao, 'size'=>7, 'style'=>'B');
1734
            $this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 0, '');
1735
            $y += 3;
1736
            $dups = "";
1737
            $dupcont = 0;
1738
            $nFat = $this->dup->length;
1739
            if ($textoFatura !== "" && $this->exibirTextoFatura) {
1740
                $myH=6;
1741
                $myW = $this->wPrint;
1742
                if ($this->orientacao == 'L') {
1743
                    $myW -= $this->wCanhoto;
1744
                }
1745
                $aFont = array('font'=>$this->fontePadrao, 'size'=>8, 'style'=>'');
1746
                $this->pTextBox($x, $y, $myW, $myH, $textoFatura, $aFont, 'C', 'L', 1, '');
1747
                $y+=$myH+1;
1748
            }
1749
            if ($this->orientacao == 'P') {
1750
                $w = round($this->wPrint/7.018, 0)-1;
1751
            } else {
1752
                $w = 28;
1753
            }
1754
            $increm = 1;
1755
            foreach ($this->dup as $k => $d) {
1756
                $nDup = ! empty($this->dup->item($k)->getElementsByTagName('nDup')->item(0)->nodeValue) ?
1757
                        $this->dup->item($k)->getElementsByTagName('nDup')->item(0)->nodeValue : '';
1758
                $dDup = ! empty($this->dup->item($k)->getElementsByTagName('dVenc')->item(0)->nodeValue) ?
1759
                        $this->pYmd2dmy($this->dup->item($k)->getElementsByTagName('dVenc')->item(0)->nodeValue) : '';
1760
                $vDup = ! empty($this->dup->item($k)->getElementsByTagName('vDup')->item(0)->nodeValue) ?
1761
                        'R$ ' . number_format(
1762
                            $this->dup->item($k)->getElementsByTagName('vDup')->item(0)->nodeValue,
1763
                            2,
1764
                            ",",
1765
                            "."
1766
                        ) : '';
1767
                $h = 8;
1768
                $texto = '';
1769
                if ($nDup!='0' && $nDup!='') {
1770
                    $aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>'');
1771
                    $this->pTextBox($x, $y, $w, $h, 'Num.', $aFont, 'T', 'L', 1, '');
1772
                    $aFont = array('font'=>$this->fontePadrao, 'size'=>7, 'style'=>'B');
1773
                    $this->pTextBox($x, $y, $w, $h, $nDup, $aFont, 'T', 'R', 0, '');
1774
                } else {
1775
                    $aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>'');
1776
                    $this->pTextBox($x, $y, $w, $h, ($dupcont+1)."", $aFont, 'T', 'L', 1, '');
1777
                }
1778
                $aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>'');
1779
                $this->pTextBox($x, $y, $w, $h, 'Venc.', $aFont, 'C', 'L', 0, '');
1780
                $aFont = array('font'=>$this->fontePadrao, 'size'=>7, 'style'=>'B');
1781
                $this->pTextBox($x, $y, $w, $h, $dDup, $aFont, 'C', 'R', 0, '');
1782
                $aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>'');
1783
                $this->pTextBox($x, $y, $w, $h, 'Valor', $aFont, 'B', 'L', 0, '');
1784
                $aFont = array('font'=>$this->fontePadrao, 'size'=>7, 'style'=>'B');
1785
                $this->pTextBox($x, $y, $w, $h, $vDup, $aFont, 'B', 'R', 0, '');
1786
                $x += $w+$increm;
1787
                $dupcont += 1;
1788
                if ($this->orientacao == 'P') {
1789
                    $maxDupCont = 6;
1790
                } else {
1791
                    $maxDupCont = 8;
1792
                }
1793
                if ($dupcont > $maxDupCont) {
1794
                    $y += 9;
1795
                    $x = $oldx;
1796
                    $dupcont = 0;
1797
                    $linha += 1;
1798
                }
1799
                if ($linha == 5) {
1800
                    $linha = 4;
1801
                    break;
1802
                }
1803
            }
1804
            if ($dupcont == 0) {
1805
                $y -= 9;
1806
                $linha--;
1807
            }
1808
            return ($y+$h);
1809
        } else {
1810
            $linha = 0;
1811
            return ($y-2);
1812
        }
1813
    } //fim da função faturaDANFE
1814
1815
    /**
1816
     * pagamentoDANFE
1817
     * Monta o campo de pagamentos da DANFE (retrato e paisagem) (foi baseada na faturaDANFE)
1818
     *
1819
     * @name   pagamentoDANFE
1820
     * @param  number $x Posição horizontal canto esquerdo
1821
     * @param  number $y Posição vertical canto superior
1822
     * @return number Posição vertical final
1823
     */
1824
    protected function pagamentoDANFE($x, $y)
1825
    {
1826
        $linha = 1;
1827
        $h = 8+3;
1828
        $oldx = $x;
1829
        //verificar se existem cobranças definidas
1830
        if (isset($this->detPag) && $this->detPag->length > 0) {
1831
            //#####################################################################
1832
            //Tipo de pagamento
1833
            $texto = "PAGAMENTO";
1834
            if ($this->orientacao == 'P') {
1835
                $w = $this->wPrint;
1836
            } else {
1837
                $w = 271;
1838
            }
1839
            $h = 8;
1840
            $aFont = array('font'=>$this->fontePadrao, 'size'=>7, 'style'=>'B');
1841
            $this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 0, '');
1842
            $y += 3;
1843
            $dups = "";
1844
            $dupcont = 0;
1845
            if ($this->orientacao == 'P') {
1846
                $w = round($this->wPrint/7.018, 0)-1;
1847
            } else {
1848
                $w = 28;
1849
            }
1850
            if ($this->orientacao == 'P') {
1851
                $maxDupCont = 6;
1852
            } else {
1853
                $maxDupCont = 8;
1854
            }
1855
            $increm = 1;
1856
            $formaPagamento = array('01'=>'Dinheiro','02'=>'Cheque','03'=>'Cartão de Crédito',
1857
                                    '04'=>'Cartão de Débito','05'=>'Crédito Loja','10'=>'Vale Alimentação',
1858
                                    '11'=>'Vale Refeição','12'=>'Vale Presente','13'=>'Vale Combustível',
1859
                                    '14'=>'Duplicata Mercantil','15'=>'Boleto','90'=>'Sem pagamento','99'=>'Outros');
1860
            $bandeira = array('01'=>'Visa','02'=>'Mastercard','03'=>'American','04'=>'Sorocred','05'=>'Diners',
1861
                              '06'=>'Elo','07'=>'Hipercard','08'=>'Aura','09'=>'Cabal','99'=>'Outros');
1862
            foreach ($this->detPag as $k => $d) {
1863
                $fPag = !empty($this->detPag->item($k)->getElementsByTagName('tPag')->item(0)->nodeValue)
1864
                    ? $this->detPag->item($k)->getElementsByTagName('tPag')->item(0)->nodeValue : '0';
1865
                $vPag = ! empty($this->detPag->item($k)->getElementsByTagName('vPag')->item(0)->nodeValue)
1866
                    ? 'R$ ' . number_format(
1867
                        $this->detPag->item($k)->getElementsByTagName('vPag')->item(0)->nodeValue,
1868
                        2,
1869
                        ",",
1870
                        "."
1871
                    ) : '';
1872
                $h = 6;
1873
                $texto = '';
1874
                if (isset($formaPagamento[$fPag])) {
1875
                    /*Exibir Item sem pagamento ou outros?*/
1876
                    if ($fPag=='90' || $fPag=='99') {
1877
                        continue;
1878
                    }
1879
                    $aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>'');
1880
                    $this->pTextBox($x, $y, $w, $h, 'Forma', $aFont, 'T', 'L', 1, '');
1881
                    $aFont = array('font'=>$this->fontePadrao, 'size'=>7, 'style'=>'B');
1882
                    $this->pTextBox($x, $y, $w, $h, $formaPagamento[$fPag], $aFont, 'T', 'R', 0, '');
1883
                } else {
1884
                    $aFont = array('font'=>$this->fontePadrao, 'size'=>7, 'style'=>'');
1885
                    $this->pTextBox($x, $y, $w, $h, "Forma ".$fPag." não encontrado", $aFont, 'T', 'L', 1, '');
1886
                }
1887
                $aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>'');
1888
                $this->pTextBox($x, $y, $w, $h, 'Valor', $aFont, 'B', 'L', 0, '');
1889
                $aFont = array('font'=>$this->fontePadrao, 'size'=>7, 'style'=>'B');
1890
                $this->pTextBox($x, $y, $w, $h, $vPag, $aFont, 'B', 'R', 0, '');
1891
                $x += $w+$increm;
1892
                $dupcont += 1;
1893
1894
                if ($dupcont>$maxDupCont) {
1895
                    $y += 9;
1896
                    $x = $oldx;
1897
                    $dupcont = 0;
1898
                    $linha += 1;
1899
                }
1900
                if ($linha == 5) {
1901
                    $linha = 4;
1902
                    break;
1903
                }
1904
            }
1905
            if ($dupcont == 0) {
1906
                $y -= 9;
1907
                $linha--;
1908
            }
1909
            return ($y+$h);
1910
        } else {
1911
            $linha = 0;
1912
            return ($y-2);
1913
        }
1914
    } //fim da função pagamentoDANFE
1915
    
1916
    /**
1917
     * impostoDanfeHelper
1918
     * Auxilia a montagem dos campos de impostos e totais da DANFE
1919
     *
1920
     * @name   impostoDanfeHelper
1921
     * @param  float $x Posição horizontal canto esquerdo
1922
     * @param  float $y Posição vertical canto superior
1923
     * @param  float $w Largura do campo
1924
     * @param  float $h Altura do campo
1925
     * @param  float $h Título do campo
1926
     * @param  float $h Valor do imposto
1927
     * @return float Sugestão do $x do próximo imposto
1928
     */
1929
    protected function pImpostoDanfeHelper($x, $y, $w, $h, $titulo, $campoImposto)
1930
    {
1931
        $valorImposto = '0, 00';
1932
        $the_field = $this->ICMSTot->getElementsByTagName($campoImposto)->item(0);
1933
        if (isset($the_field)) {
1934
            $the_value = $the_field->nodeValue;
1935
            if (!empty($the_value)) {
1936
                $valorImposto = number_format($the_value, 2, ",", ".");
1937
            }
1938
        }
1939
1940
        $fontTitulo = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>'');
1941
        $fontValor = array('font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B');
1942
        $this->pTextBox($x, $y, $w, $h, $titulo, $fontTitulo, 'T', 'L', 1, '');
1943
        $this->pTextBox($x, $y, $w, $h, $valorImposto, $fontValor, 'B', 'R', 0, '');
1944
1945
        $next_x = $x + $w;
1946
        return $next_x;
1947
    }
1948
1949
    /**
1950
     * impostoDANFE
1951
     * Monta o campo de impostos e totais da DANFE (retrato e paisagem)
1952
     *
1953
     * @param  number $x Posição horizontal canto esquerdo
1954
     * @param  number $y Posição vertical canto superior
1955
     * @return number Posição vertical final
1956
     */
1957
    protected function pImpostoDANFE($x, $y)
1958
    {
1959
        $x_inicial = $x;
1960
        //#####################################################################
1961
1962
1963
        $campos_por_linha = 9;
1964
        if (!$this->exibirPIS) {
1965
            $campos_por_linha--;
1966
        }
1967
        if (!$this->exibirIcmsInterestadual) {
1968
            $campos_por_linha -= 2;
1969
        }
1970
1971
        if ($this->orientacao == 'P') {
1972
            $maxW = $this->wPrint;
1973
            $title_size = 31;
1974
        } else {
1975
            $maxW = $this->wPrint - $this->wCanhoto;
1976
            $title_size = 40;
1977
        }
1978
        $w = $maxW / $campos_por_linha;
1979
1980
        $aFont = array('font'=>$this->fontePadrao, 'size'=>7, 'style'=>'B');
1981
        $texto = "CÁLCULO DO IMPOSTO";
1982
        $this->pTextBox($x, $y, $title_size, 8, $texto, $aFont, 'T', 'L', 0, '');
1983
        $y += 3;
1984
        $h = 7;
1985
1986
        $x = $this->pImpostoDanfeHelper($x, $y, $w, $h, "BASE DE CÁLC. DO ICMS", "vBC");
1987
        $x = $this->pImpostoDanfeHelper($x, $y, $w, $h, "VALOR DO ICMS", "vICMS");
1988
        $x = $this->pImpostoDanfeHelper($x, $y, $w, $h, "BASE DE CÁLC. ICMS S.T.", "vBCST");
1989
        $x = $this->pImpostoDanfeHelper($x, $y, $w, $h, "VALOR DO ICMS SUBST.", "vST");
1990
        $x = $this->pImpostoDanfeHelper($x, $y, $w, $h, "V. IMP. IMPORTAÇÃO", "vII");
1991
1992
        if ($this->exibirIcmsInterestadual) {
1993
            $x = $this->pImpostoDanfeHelper($x, $y, $w, $h, "V. ICMS UF REMET.", "vICMSUFRemet");
1994
            $x = $this->pImpostoDanfeHelper($x, $y, $w, $h, "V. FCP UF DEST.", "vFCPUFDest");
1995
        }
1996
1997
        if ($this->exibirPIS) {
1998
            $x = $this->pImpostoDanfeHelper($x, $y, $w, $h, "VALOR DO PIS", "vPIS");
1999
        }
2000
2001
        $x = $this->pImpostoDanfeHelper($x, $y, $w, $h, "V. TOTAL PRODUTOS", "vProd");
2002
2003
        //
2004
2005
        $y += $h;
2006
        $x = $x_inicial;
2007
2008
        $x = $this->pImpostoDanfeHelper($x, $y, $w, $h, "VALOR DO FRETE", "vFrete");
2009
        $x = $this->pImpostoDanfeHelper($x, $y, $w, $h, "VALOR DO SEGURO", "vSeg");
2010
        $x = $this->pImpostoDanfeHelper($x, $y, $w, $h, "DESCONTO", "vDesc");
2011
        $x = $this->pImpostoDanfeHelper($x, $y, $w, $h, "OUTRAS DESPESAS", "vOutro");
2012
        $x = $this->pImpostoDanfeHelper($x, $y, $w, $h, "VALOR TOTAL IPI", "vIPI");
2013
2014
        if ($this->exibirIcmsInterestadual) {
2015
            $x = $this->pImpostoDanfeHelper($x, $y, $w, $h, "V. ICMS UF DEST.", "vICMSUFDest");
2016
            $x = $this->pImpostoDanfeHelper($x, $y, $w, $h, "V. TOT. TRIB.", "vTotTrib");
2017
        }
2018
2019
        if ($this->exibirPIS) {
2020
            $x = $this->pImpostoDanfeHelper($x, $y, $w, $h, "VALOR DA COFINS", "vCOFINS");
2021
        }
2022
        $x = $this->pImpostoDanfeHelper($x, $y, $w, $h, "V. TOTAL DA NOTA", "vNF");
2023
2024
        return ($y+$h);
2025
    } //fim impostoDANFE
2026
2027
    /**
2028
     * transporteDANFE
2029
     * Monta o campo de transportes da DANFE (retrato e paisagem)
2030
     *
2031
     * @name   transporteDANFE
2032
     * @param  float $x Posição horizontal canto esquerdo
2033
     * @param  float $y Posição vertical canto superior
2034
     * @return float Posição vertical final
2035
     */
2036
    protected function pTransporteDANFE($x, $y)
2037
    {
2038
        $oldX = $x;
2039
        if ($this->orientacao == 'P') {
2040
            $maxW = $this->wPrint;
2041
        } else {
2042
            $maxW = $this->wPrint - $this->wCanhoto;
2043
        }
2044
        //#####################################################################
2045
        //TRANSPORTADOR / VOLUMES TRANSPORTADOS
2046
        $texto = "TRANSPORTADOR / VOLUMES TRANSPORTADOS";
2047
        $w = $maxW;
2048
        $h = 7;
2049
        $aFont = array('font'=>$this->fontePadrao, 'size'=>7, 'style'=>'B');
2050
        $this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 0, '');
2051
        //NOME / RAZÃO SOCIAL
2052
        $w1 = $maxW*0.29;
2053
        $y += 3;
2054
        $texto = 'NOME / RAZÃO SOCIAL';
2055
        $aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>'');
2056
        $this->pTextBox($x, $y, $w1, $h, $texto, $aFont, 'T', 'L', 1, '');
2057
        if (isset($this->transporta)) {
2058
            $texto = ! empty($this->transporta->getElementsByTagName("xNome")->item(0)->nodeValue) ?
2059
                    $this->transporta->getElementsByTagName("xNome")->item(0)->nodeValue : '';
2060
        } else {
2061
            $texto = '';
2062
        }
2063
        $aFont = array('font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B');
2064
        $this->pTextBox($x, $y, $w1, $h, $texto, $aFont, 'B', 'L', 0, '');
2065
        //FRETE POR CONTA
2066
        $x += $w1;
2067
        $w2 = $maxW*0.15;
2068
        $texto = 'FRETE';
2069
        $aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>'');
2070
        $this->pTextBox($x, $y, $w2, $h, $texto, $aFont, 'T', 'L', 1, '');
2071
        $tipoFrete = ! empty($this->transp->getElementsByTagName("modFrete")->item(0)->nodeValue) ?
2072
                $this->transp->getElementsByTagName("modFrete")->item(0)->nodeValue : '0';
2073
        switch ($tipoFrete) {
2074
            case 0:
2075
                $texto = "0-Por conta do Rem";
2076
                break;
2077
            case 1:
2078
                $texto = "1-Por conta do Dest";
2079
                break;
2080
            case 2:
2081
                $texto = "2-Por conta de Terceiros";
2082
                break;
2083
            case 3:
2084
                $texto = "3-Próprio por conta do Rem";
2085
                break;
2086
            case 4:
2087
                $texto = "4-Próprio por conta do Dest";
2088
                break;
2089
            case 9:
2090
                $texto = "9-Sem Transporte";
2091
                break;
2092
        }
2093
        $aFont = array('font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B');
2094
        $this->pTextBox($x, $y, $w2, $h, $texto, $aFont, 'C', 'C', 1, '');
2095
        //CÓDIGO ANTT
2096
        $x += $w2;
2097
        $texto = 'CÓDIGO ANTT';
2098
        $aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>'');
2099
        $this->pTextBox($x, $y, $w2, $h, $texto, $aFont, 'T', 'L', 1, '');
2100
        if (isset($this->veicTransp)) {
2101
            $texto = ! empty($this->veicTransp->getElementsByTagName("RNTC")->item(0)->nodeValue) ?
2102
                    $this->veicTransp->getElementsByTagName("RNTC")->item(0)->nodeValue : '';
2103
        } else {
2104
            $texto = '';
2105
        }
2106
        $aFont = array('font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B');
2107
        $this->pTextBox($x, $y, $w2, $h, $texto, $aFont, 'B', 'C', 0, '');
2108
        //PLACA DO VEÍC
2109
        $x += $w2;
2110
        $texto = 'PLACA DO VEÍCULO';
2111
        $aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>'');
2112
        $this->pTextBox($x, $y, $w2, $h, $texto, $aFont, 'T', 'L', 1, '');
2113
        if (isset($this->veicTransp)) {
2114
            $texto = ! empty($this->veicTransp->getElementsByTagName("placa")->item(0)->nodeValue) ?
2115
                    $this->veicTransp->getElementsByTagName("placa")->item(0)->nodeValue : '';
2116
        } elseif (isset($this->reboque)) {
2117
            $texto = ! empty($this->reboque->getElementsByTagName("placa")->item(0)->nodeValue) ?
2118
                    $this->reboque->getElementsByTagName("placa")->item(0)->nodeValue : '';
2119
        } else {
2120
            $texto = '';
2121
        }
2122
        $aFont = array('font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B');
2123
        $this->pTextBox($x, $y, $w2, $h, $texto, $aFont, 'B', 'C', 0, '');
2124
        //UF
2125
        $x += $w2;
2126
        $w3 = round($maxW*0.04, 0);
2127
        $texto = 'UF';
2128
        $aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>'');
2129
        $this->pTextBox($x, $y, $w3, $h, $texto, $aFont, 'T', 'L', 1, '');
2130
        if (isset($this->veicTransp)) {
2131
            $texto = ! empty($this->veicTransp->getElementsByTagName("UF")->item(0)->nodeValue) ?
2132
                    $this->veicTransp->getElementsByTagName("UF")->item(0)->nodeValue : '';
2133
        } elseif (isset($this->reboque)) {
2134
            $texto = ! empty($this->reboque->getElementsByTagName("UF")->item(0)->nodeValue) ?
2135
                    $this->reboque->getElementsByTagName("UF")->item(0)->nodeValue : '';
2136
        } else {
2137
            $texto = '';
2138
        }
2139
        $aFont = array('font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B');
2140
        $this->pTextBox($x, $y, $w3, $h, $texto, $aFont, 'B', 'C', 0, '');
2141
        //CNPJ / CPF
2142
        $x += $w3;
2143
        $w = $maxW-($w1+3*$w2+$w3);
2144
        $texto = 'CNPJ / CPF';
2145
        $aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>'');
2146
        $this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 1, '');
2147
        if (isset($this->transporta)) {
2148
            $texto = ! empty($this->transporta->getElementsByTagName("CNPJ")->item(0)->nodeValue) ?
2149
                    $this->pFormat(
2150
                        $this->transporta->getElementsByTagName("CNPJ")->item(0)->nodeValue,
2151
                        "##.###.###/####-##"
2152
                    ) : '';
2153
            if ($texto == '') {
2154
                $texto = ! empty($this->transporta->getElementsByTagName("CPF")->item(0)->nodeValue) ?
2155
                        $this->pFormat(
2156
                            $this->transporta->getElementsByTagName("CPF")->item(0)->nodeValue,
2157
                            "###.###.###-##"
2158
                        ) : '';
2159
            }
2160
        } else {
2161
            $texto = '';
2162
        }
2163
        $aFont = array('font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B');
2164
        $this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'B', 'C', 0, '');
2165
        //#####################################################################
2166
        //ENDEREÇO
2167
        $y += $h;
2168
        $x = $oldX;
2169
        $h = 7;
2170
        $w1 = $maxW*0.44;
2171
        $texto = 'ENDEREÇO';
2172
        $aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>'');
2173
        $this->pTextBox($x, $y, $w1, $h, $texto, $aFont, 'T', 'L', 1, '');
2174
        if (isset($this->transporta)) {
2175
            $texto = ! empty($this->transporta->getElementsByTagName("xEnder")->item(0)->nodeValue) ?
2176
                    $this->transporta->getElementsByTagName("xEnder")->item(0)->nodeValue : '';
2177
        } else {
2178
            $texto = '';
2179
        }
2180
        $aFont = array('font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B');
2181
        $this->pTextBox($x, $y, $w1, $h, $texto, $aFont, 'B', 'L', 0, '');
2182
        //MUNICÍPIO
2183
        $x += $w1;
2184
        $w2 = round($maxW*0.30, 0);
2185
        $texto = 'MUNICÍPIO';
2186
        $aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>'');
2187
        $this->pTextBox($x, $y, $w2, $h, $texto, $aFont, 'T', 'L', 1, '');
2188
        if (isset($this->transporta)) {
2189
            $texto = ! empty($this->transporta->getElementsByTagName("xMun")->item(0)->nodeValue) ?
2190
                    $this->transporta->getElementsByTagName("xMun")->item(0)->nodeValue : '';
2191
        } else {
2192
            $texto = '';
2193
        }
2194
        $aFont = array('font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B');
2195
        $this->pTextBox($x, $y, $w2, $h, $texto, $aFont, 'B', 'C', 0, '');
2196
        //UF
2197
        $x += $w2;
2198
        $w3 = round($maxW*0.04, 0);
2199
        $texto = 'UF';
2200
        $aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>'');
2201
        $this->pTextBox($x, $y, $w3, $h, $texto, $aFont, 'T', 'L', 1, '');
2202
        if (isset($this->transporta)) {
2203
            $texto = ! empty($this->transporta->getElementsByTagName("UF")->item(0)->nodeValue) ?
2204
                    $this->transporta->getElementsByTagName("UF")->item(0)->nodeValue : '';
2205
        } else {
2206
            $texto = '';
2207
        }
2208
        $aFont = array('font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B');
2209
        $this->pTextBox($x, $y, $w3, $h, $texto, $aFont, 'B', 'C', 0, '');
2210
        //INSCRIÇÃO ESTADUAL
2211
        $x += $w3;
2212
        $w = $maxW-($w1+$w2+$w3);
2213
        $texto = 'INSCRIÇÃO ESTADUAL';
2214
        $aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>'');
2215
        $this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 1, '');
2216
        $texto = '';
2217
        if (isset($this->transporta)) {
2218
            if (! empty($this->transporta->getElementsByTagName("IE")->item(0)->nodeValue)) {
2219
                $texto = $this->transporta->getElementsByTagName("IE")->item(0)->nodeValue;
2220
            }
2221
        }
2222
        $aFont = array('font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B');
2223
        $this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'B', 'C', 0, '');
2224
        //Tratar Multiplos volumes
2225
        $volumes = $this->transp->getElementsByTagName('vol');
2226
        $quantidade = 0;
2227
        $especie = '';
2228
        $marca = '';
2229
        $numero = '';
2230
        $texto = '';
2231
        $pesoBruto=0;
2232
        $pesoLiquido=0;
2233
        foreach ($volumes as $volume) {
2234
            $quantidade += ! empty($volume->getElementsByTagName("qVol")->item(0)->nodeValue) ?
2235
                    $volume->getElementsByTagName("qVol")->item(0)->nodeValue : 0;
2236
            $pesoBruto += ! empty($volume->getElementsByTagName("pesoB")->item(0)->nodeValue) ?
2237
                    $volume->getElementsByTagName("pesoB")->item(0)->nodeValue : 0;
2238
            $pesoLiquido += ! empty($volume->getElementsByTagName("pesoL")->item(0)->nodeValue) ?
2239
                    $volume->getElementsByTagName("pesoL")->item(0)->nodeValue : 0;
2240
            $texto = ! empty($this->transp->getElementsByTagName("esp")->item(0)->nodeValue) ?
2241
                    $this->transp->getElementsByTagName("esp")->item(0)->nodeValue : '';
2242
            if ($texto != $especie && $especie != '') {
2243
                //tem várias especies
2244
                $especie = 'VARIAS';
2245
            } else {
2246
                $especie = $texto;
2247
            }
2248
            $texto = ! empty($this->transp->getElementsByTagName("marca")->item(0)->nodeValue) ?
2249
                    $this->transp->getElementsByTagName("marca")->item(0)->nodeValue : '';
2250
            if ($texto != $marca && $marca != '') {
2251
                //tem várias especies
2252
                $marca = 'VARIAS';
2253
            } else {
2254
                $marca = $texto;
2255
            }
2256
            $texto = ! empty($this->transp->getElementsByTagName("nVol")->item(0)->nodeValue) ?
2257
                    $this->transp->getElementsByTagName("nVol")->item(0)->nodeValue : '';
2258
            if ($texto != $numero && $numero != '') {
2259
                //tem várias especies
2260
                $numero = 'VARIOS';
2261
            } else {
2262
                $numero = $texto;
2263
            }
2264
        }
2265
2266
        //#####################################################################
2267
        //QUANTIDADE
2268
        $y += $h;
2269
        $x = $oldX;
2270
        $h = 7;
2271
        $w1 = round($maxW*0.10, 0);
2272
        $texto = 'QUANTIDADE';
2273
        $aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>'');
2274
        $this->pTextBox($x, $y, $w1, $h, $texto, $aFont, 'T', 'L', 1, '');
2275
        if (!empty($quantidade)) {
2276
            $texto = $quantidade;
2277
            $aFont = array('font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B');
2278
            $this->pTextBox($x, $y, $w1, $h, $texto, $aFont, 'B', 'C', 0, '');
2279
        }
2280
        //ESPÉCIE
2281
        $x += $w1;
2282
        $w2 = round($maxW*0.17, 0);
2283
        $texto = 'ESPÉCIE';
2284
        $aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>'');
2285
        $this->pTextBox($x, $y, $w2, $h, $texto, $aFont, 'T', 'L', 1, '');
2286
        $texto = $especie;
2287
        $aFont = array('font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B');
2288
        $this->pTextBox($x, $y, $w2, $h, $texto, $aFont, 'B', 'C', 0, '');
2289
        //MARCA
2290
        $x += $w2;
2291
        $texto = 'MARCA';
2292
        $aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>'');
2293
        $this->pTextBox($x, $y, $w2, $h, $texto, $aFont, 'T', 'L', 1, '');
2294
        $texto = ! empty($this->transp->getElementsByTagName("marca")->item(0)->nodeValue) ?
2295
                $this->transp->getElementsByTagName("marca")->item(0)->nodeValue : '';
2296
        $aFont = array('font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B');
2297
        $this->pTextBox($x, $y, $w2, $h, $texto, $aFont, 'B', 'C', 0, '');
2298
        //NUMERAÇÃO
2299
        $x += $w2;
2300
        $texto = 'NUMERAÇÃO';
2301
        $aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>'');
2302
        $this->pTextBox($x, $y, $w2, $h, $texto, $aFont, 'T', 'L', 1, '');
2303
        $texto = $numero;
2304
        $aFont = array('font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B');
2305
        $this->pTextBox($x, $y, $w2, $h, $texto, $aFont, 'B', 'C', 0, '');
2306
        //PESO BRUTO
2307
        $x += $w2;
2308
        $w3 = round($maxW*0.20, 0);
2309
        $texto = 'PESO BRUTO';
2310
        $aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>'');
2311
        $this->pTextBox($x, $y, $w3, $h, $texto, $aFont, 'T', 'L', 1, '');
2312
        if (is_numeric($pesoBruto) && $pesoBruto > 0) {
2313
            $texto = number_format($pesoBruto, 3, ",", ".");
2314
        } else {
2315
            $texto = '';
2316
        }
2317
        $aFont = array('font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B');
2318
        $this->pTextBox($x, $y, $w3, $h, $texto, $aFont, 'B', 'R', 0, '');
2319
        //PESO LÍQUIDO
2320
        $x += $w3;
2321
        $w = $maxW -($w1+3*$w2+$w3);
2322
        $texto = 'PESO LÍQUIDO';
2323
        $aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>'');
2324
        $this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 1, '');
2325
        if (is_numeric($pesoLiquido) && $pesoLiquido > 0) {
2326
            $texto = number_format($pesoLiquido, 3, ",", ".");
2327
        } else {
2328
            $texto = '';
2329
        }
2330
        $aFont = array('font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B');
2331
        $this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'B', 'R', 0, '');
2332
        return ($y+$h);
2333
    } //fim transporteDANFE
2334
2335
2336
2337
    protected function pDescricaoProdutoHelper($origem, $campo, $formato)
2338
    {
2339
        $valor_original = $origem->getElementsByTagName($campo)->item(0);
2340
        if (!isset($valor_original)) {
2341
            return "";
2342
        }
2343
        $valor_original = $valor_original->nodeValue;
2344
        $valor = ! empty($valor_original) ? number_format($valor_original, 2, ",", ".") : '';
2345
2346
        if ($valor != "") {
2347
            return sprintf($formato, $valor);
2348
        }
2349
        return "";
2350
    }
2351
2352
    /**
2353
     * descricaoProduto
2354
     * Monta a string de descrição de cada Produto
2355
     *
2356
     * @name   descricaoProduto
2357
     * @param  DOMNode itemProd
2358
     * @return string descricao do produto
2359
     */
2360
    protected function pDescricaoProduto($itemProd)
2361
    {
2362
        $prod = $itemProd->getElementsByTagName('prod')->item(0);
2363
        $ICMS = $itemProd->getElementsByTagName("ICMS")->item(0);
2364
        $ICMSUFDest = $itemProd->getElementsByTagName("ICMSUFDest")->item(0);
2365
        $impostos = '';
2366
2367
        if (!empty($ICMS)) {
2368
            $impostos .= $this->pDescricaoProdutoHelper($ICMS, "vBCFCP", " BcFcp=%s");
2369
            $impostos .= $this->pDescricaoProdutoHelper($ICMS, "pFCP", " pFcp=%s%%");
2370
            $impostos .= $this->pDescricaoProdutoHelper($ICMS, "vFCP", " vFcp=%s");
2371
            $impostos .= $this->pDescricaoProdutoHelper($ICMS, "pRedBC", " pRedBC=%s%%");
2372
            $impostos .= $this->pDescricaoProdutoHelper($ICMS, "pMVAST", " IVA/MVA=%s%%");
2373
            $impostos .= $this->pDescricaoProdutoHelper($ICMS, "pICMSST", " pIcmsSt=%s%%");
2374
            $impostos .= $this->pDescricaoProdutoHelper($ICMS, "vBCST", " BcIcmsSt=%s");
2375
            $impostos .= $this->pDescricaoProdutoHelper($ICMS, "vICMSST", " vIcmsSt=%s");
2376
            $impostos .= $this->pDescricaoProdutoHelper($ICMS, "vBCFCPST", " BcFcpSt=%s");
2377
            $impostos .= $this->pDescricaoProdutoHelper($ICMS, "pFCPST", " pFcpSt=%s%%");
2378
            $impostos .= $this->pDescricaoProdutoHelper($ICMS, "vFCPST", " vFcpSt=%s");
2379
        }
2380
        if (!empty($ICMSUFDest)) {
2381
            $impostos .= $this->pDescricaoProdutoHelper($ICMSUFDest, "pFCPUFDest", " pFCPUFDest=%s%%");
2382
            $impostos .= $this->pDescricaoProdutoHelper($ICMSUFDest, "pICMSUFDest", " pICMSUFDest=%s%%");
2383
            $impostos .= $this->pDescricaoProdutoHelper($ICMSUFDest, "pICMSInterPart", " pICMSInterPart=%s%%");
2384
            $impostos .= $this->pDescricaoProdutoHelper($ICMSUFDest, "vFCPUFDest", " vFCPUFDest=%s");
2385
            $impostos .= $this->pDescricaoProdutoHelper($ICMSUFDest, "vICMSUFDest", " vICMSUFDest=%s");
2386
            $impostos .= $this->pDescricaoProdutoHelper($ICMSUFDest, "vICMSUFRemet", " vICMSUFRemet=%s");
2387
        }
2388
        $infAdProd = ! empty($itemProd->getElementsByTagName('infAdProd')->item(0)->nodeValue) ?
2389
                substr($this->pAnfavea($itemProd->getElementsByTagName('infAdProd')->item(0)->nodeValue), 0, 500) : '';
2390
        if (! empty($infAdProd)) {
2391
            $infAdProd = trim($infAdProd);
2392
            $infAdProd .= ' ';
2393
        }
2394
        $loteTxt ='';
2395
        $rastro = $prod->getElementsByTagName("med");
2396
        if (!isset($rastro)) {
2397
            $rastro = $prod->getElementsByTagName("rastro");
2398
        }
2399
        if (isset($rastro)) {
2400
            $i = 0;
2401
            while ($i < $rastro->length) {
2402
                $loteTxt .= $this->pSimpleGetValue($rastro->item($i), 'nLote', ' Lote: ');
2403
                $loteTxt .= $this->pSimpleGetValue($rastro->item($i), 'qLote', ' Quant: ');
2404
                $loteTxt .= $this->pSimpleGetDate($rastro->item($i), 'dFab', ' Fab: ');
2405
                $loteTxt .= $this->pSimpleGetDate($rastro->item($i), 'dVal', ' Val: ');
2406
                $loteTxt .= $this->pSimpleGetValue($rastro->item($i), 'vPMC', ' PMC: ');
2407
                $i++;
2408
            }
2409
            if ($loteTxt != '') {
2410
                $loteTxt.= ' ';
2411
            }
2412
        }
2413
        //NT2013.006 FCI
2414
        $nFCI = (! empty($itemProd->getElementsByTagName('nFCI')->item(0)->nodeValue)) ?
2415
                ' FCI:'.$itemProd->getElementsByTagName('nFCI')->item(0)->nodeValue : '';
2416
        $tmp_ad=$infAdProd . ($this->descProdInfoComplemento ? $loteTxt . $impostos . $nFCI : '');
2417
        $texto = $prod->getElementsByTagName("xProd")->item(0)->nodeValue . (strlen($tmp_ad)!=0?"\n    ".$tmp_ad:'');
2418
        if ($this->descProdQuebraLinha) {
2419
            $texto = str_replace(";", "\n", $texto);
2420
        }
2421
        return $texto;
2422
    }
2423
2424
    /**
2425
     * itensDANFE
2426
     * Monta o campo de itens da DANFE (retrato e paisagem)
2427
     *
2428
     * @name   itensDANFE
2429
     * @param  float $x       Posição horizontal canto esquerdo
2430
     * @param  float $y       Posição vertical canto superior
2431
     * @param  float $nInicio Número do item inicial
2432
     * @param  float $max     Número do item final
2433
     * @param  float $hmax    Altura máxima do campo de itens em mm
2434
     * @return float Posição vertical final
2435
     */
2436
    protected function pItensDANFE($x, $y, &$nInicio, $hmax, $pag = 0, $totpag = 0, $hCabecItens = 7)
2437
    {
2438
        $oldX = $x;
2439
        $oldY = $y;
2440
        $totItens = $this->det->length;
2441
        //#####################################################################
2442
        //DADOS DOS PRODUTOS / SERVIÇOS
2443
        $texto = "DADOS DOS PRODUTOS / SERVIÇOS ";
2444
        if ($this->orientacao == 'P') {
2445
            $w = $this->wPrint;
2446
        } else {
2447
            if ($nInicio < 2) { // primeira página
2448
                $w = $this->wPrint - $this->wCanhoto;
2449
            } else { // páginas seguintes
2450
                $w = $this->wPrint;
2451
            }
2452
        }
2453
        $h = 4;
2454
        $aFont = array('font'=>$this->fontePadrao, 'size'=>7, 'style'=>'B');
2455
        $this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 0, '');
2456
        $y += 3;
2457
        //desenha a caixa dos dados dos itens da NF
2458
        $hmax += 1;
2459
        $texto = '';
2460
        $this->pTextBox($x, $y, $w, $hmax);
2461
        //##################################################################################
2462
        // cabecalho LOOP COM OS DADOS DOS PRODUTOS
2463
        //CÓDIGO PRODUTO
2464
        $texto = "CÓDIGO PRODUTO";
2465
        $w1 = round($w*0.09, 0);
2466
        $h = 4;
2467
        $aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>'');
2468
        $this->pTextBox($x, $y, $w1, $h, $texto, $aFont, 'C', 'C', 0, '', false);
2469
        $this->pdf->Line($x+$w1, $y, $x+$w1, $y+$hmax);
2470
        //DESCRIÇÃO DO PRODUTO / SERVIÇO
2471
        $x += $w1;
2472
        $w2 = round($w*0.28, 0);
2473
        $texto = 'DESCRIÇÃO DO PRODUTO / SERVIÇO';
2474
        $aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>'');
2475
        $this->pTextBox($x, $y, $w2, $h, $texto, $aFont, 'C', 'C', 0, '', false);
2476
        $this->pdf->Line($x+$w2, $y, $x+$w2, $y+$hmax);
2477
        //NCM/SH
2478
        $x += $w2;
2479
        $w3 = round($w*0.06, 0);
2480
        $texto = 'NCM/SH';
2481
        $aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>'');
2482
        $this->pTextBox($x, $y, $w3, $h, $texto, $aFont, 'C', 'C', 0, '', false);
2483
        $this->pdf->Line($x+$w3, $y, $x+$w3, $y+$hmax);
2484
        //O/CST ou O/CSOSN
2485
        $x += $w3;
2486
        $w4 = round($w*0.05, 0);
2487
        $texto = 'O/CSOSN';//Regime do Simples CRT = 1 ou CRT = 2
2488
        if ($this->pSimpleGetValue($this->emit, 'CRT') == '3') {
2489
             $texto = 'O/CST';//Regime Normal
2490
        }
2491
        $aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>'');
2492
        $this->pTextBox($x, $y, $w4, $h, $texto, $aFont, 'C', 'C', 0, '', false);
2493
        $this->pdf->Line($x+$w4, $y, $x+$w4, $y+$hmax);
2494
        //CFOP
2495
        $x += $w4;
2496
        $w5 = round($w*0.04, 0);
2497
        $texto = 'CFOP';
2498
        $aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>'');
2499
        $this->pTextBox($x, $y, $w5, $h, $texto, $aFont, 'C', 'C', 0, '', false);
2500
        $this->pdf->Line($x+$w5, $y, $x+$w5, $y+$hmax);
2501
        //UN
2502
        $x += $w5;
2503
        $w6 = round($w*0.03, 0);
2504
        $texto = 'UN';
2505
        $aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>'');
2506
        $this->pTextBox($x, $y, $w6, $h, $texto, $aFont, 'C', 'C', 0, '', false);
2507
        $this->pdf->Line($x+$w6, $y, $x+$w6, $y+$hmax);
2508
        //QUANT
2509
        $x += $w6;
2510
        $w7 = round($w*0.07, 0);
2511
        $texto = 'QUANT';
2512
        $aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>'');
2513
        $this->pTextBox($x, $y, $w7, $h, $texto, $aFont, 'C', 'C', 0, '', false);
2514
        $this->pdf->Line($x+$w7, $y, $x+$w7, $y+$hmax);
2515
        //VALOR UNIT
2516
        $x += $w7;
2517
        $w8 = round($w*0.06, 0);
2518
        $texto = 'VALOR UNIT';
2519
        $aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>'');
2520
        $this->pTextBox($x, $y, $w8, $h, $texto, $aFont, 'C', 'C', 0, '', false);
2521
        $this->pdf->Line($x+$w8, $y, $x+$w8, $y+$hmax);
2522
        //VALOR TOTAL
2523
        $x += $w8;
2524
        $w9 = round($w*0.06, 0);
2525
        $texto = 'VALOR TOTAL';
2526
        $aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>'');
2527
        $this->pTextBox($x, $y, $w9, $h, $texto, $aFont, 'C', 'C', 0, '', false);
2528
        $this->pdf->Line($x+$w9, $y, $x+$w9, $y+$hmax);
2529
        //B.CÁLC ICMS
2530
        $x += $w9;
2531
        $w10 = round($w*0.06, 0);
2532
        $texto = 'B.CÁLC ICMS';
2533
        $aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>'');
2534
        $this->pTextBox($x, $y, $w10, $h, $texto, $aFont, 'C', 'C', 0, '', false);
2535
        $this->pdf->Line($x+$w10, $y, $x+$w10, $y+$hmax);
2536
        //VALOR ICMS
2537
        $x += $w10;
2538
        $w11 = round($w*0.06, 0);
2539
        $texto = 'VALOR ICMS';
2540
        $aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>'');
2541
        $this->pTextBox($x, $y, $w11, $h, $texto, $aFont, 'C', 'C', 0, '', false);
2542
        $this->pdf->Line($x+$w11, $y, $x+$w11, $y+$hmax);
2543
        //VALOR IPI
2544
        $x += $w11;
2545
        $w12 = round($w*0.05, 0);
2546
        $texto = 'VALOR IPI';
2547
        $aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>'');
2548
        $this->pTextBox($x, $y, $w12, $h, $texto, $aFont, 'C', 'C', 0, '', false);
2549
        $this->pdf->Line($x+$w12, $y, $x+$w12, $y+$hmax);
2550
        //ALÍQ. ICMS
2551
        $x += $w12;
2552
        $w13 = round($w*0.035, 0);
2553
        $texto = 'ALÍQ. ICMS';
2554
        $aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>'');
2555
        $this->pTextBox($x, $y, $w13, $h, $texto, $aFont, 'C', 'C', 0, '', false);
2556
        $this->pdf->Line($x+$w13, $y, $x+$w13, $y+$hmax);
2557
        //ALÍQ. IPI
2558
        $x += $w13;
2559
        $w14 = $w-($w1+$w2+$w3+$w4+$w5+$w6+$w7+$w8+$w9+$w10+$w11+$w12+$w13);
2560
        $texto = 'ALÍQ. IPI';
2561
        $this->pTextBox($x, $y, $w14, $h, $texto, $aFont, 'C', 'C', 0, '', false);
2562
        $this->pdf->Line($oldX, $y+$h+1, $oldX + $w, $y+$h+1);
2563
        $y += 5;
2564
        //##################################################################################
2565
        // LOOP COM OS DADOS DOS PRODUTOS
2566
        $i = 0;
2567
        $hUsado = $hCabecItens;
2568
        $aFont = array('font'=>$this->fontePadrao, 'size'=>7, 'style'=>'');
2569
        foreach ($this->det as $d) {
2570
            if ($i >= $nInicio) {
2571
                $thisItem = $this->det->item($i);
2572
                //carrega as tags do item
2573
                $prod = $thisItem->getElementsByTagName("prod")->item(0);
2574
                $imposto = $this->det->item($i)->getElementsByTagName("imposto")->item(0);
2575
                $ICMS = $imposto->getElementsByTagName("ICMS")->item(0);
2576
                $IPI  = $imposto->getElementsByTagName("IPI")->item(0);
2577
                $textoProduto = $this->pDescricaoProduto($thisItem);
2578
                $linhaDescr = $this->pGetNumLines($textoProduto, $w2, $aFont);
2579
                $h = round(($linhaDescr * $this->pdf->fontSize)+ ($linhaDescr * 0.5), 2);
2580
                $hUsado += $h;
2581
                if ($pag != $totpag) {
2582
                    if ($hUsado >= $hmax && $i < $totItens) {
2583
                        //ultrapassa a capacidade para uma única página
2584
                        //o restante dos dados serão usados nas proximas paginas
2585
                        $nInicio = $i;
2586
                        break;
2587
                    }
2588
                }
2589
                $y_linha=$y+$h;
2590
                // linha entre itens
2591
                $this->pdf->DashedHLine($oldX, $y_linha, $w, 0.1, 120);
2592
                //corrige o x
2593
                $x=$oldX;
2594
                //codigo do produto
2595
                $texto = $prod->getElementsByTagName("cProd")->item(0)->nodeValue;
2596
                $this->pTextBox($x, $y, $w1, $h, $texto, $aFont, 'T', 'C', 0, '');
2597
                $x += $w1;
2598
                //DESCRIÇÃO
2599
                if ($this->orientacao == 'P') {
2600
                    $this->pTextBox($x, $y, $w2, $h, $textoProduto, $aFont, 'T', 'L', 0, '', false);
2601
                } else {
2602
                    $this->pTextBox($x, $y, $w2, $h, $textoProduto, $aFont, 'T', 'L', 0, '', false);
2603
                }
2604
                $x += $w2;
2605
                //NCM
2606
                $texto = ! empty($prod->getElementsByTagName("NCM")->item(0)->nodeValue) ?
2607
                        $prod->getElementsByTagName("NCM")->item(0)->nodeValue : '';
2608
                $this->pTextBox($x, $y, $w3, $h, $texto, $aFont, 'T', 'C', 0, '');
2609
                $x += $w3;
2610
                //CST
2611
                if (isset($ICMS)) {
2612
                    $origem =  $this->pSimpleGetValue($ICMS, "orig");
2613
                    $cst =  $this->pSimpleGetValue($ICMS, "CST");
2614
                    $csosn =  $this->pSimpleGetValue($ICMS, "CSOSN");
2615
                    $texto = $origem.$cst.$csosn;
2616
                    $this->pTextBox($x, $y, $w4, $h, $texto, $aFont, 'T', 'C', 0, '');
2617
                }
2618
                //CFOP
2619
                $x += $w4;
2620
                $texto = $prod->getElementsByTagName("CFOP")->item(0)->nodeValue;
2621
                $this->pTextBox($x, $y, $w5, $h, $texto, $aFont, 'T', 'C', 0, '');
2622
                //Unidade
2623
                $x += $w5;
2624
                $texto = $prod->getElementsByTagName("uCom")->item(0)->nodeValue;
2625
                $this->pTextBox($x, $y, $w6, $h, $texto, $aFont, 'T', 'C', 0, '');
2626
                $x += $w6;
2627
                if ($this->orientacao == 'P') {
2628
                    $alinhamento = 'R';
2629
                } else {
2630
                    $alinhamento = 'R';
2631
                }
2632
                // QTDADE
2633
                $texto = number_format($prod->getElementsByTagName("qCom")->item(0)->nodeValue, 4, ",", ".");
2634
                $this->pTextBox($x, $y, $w7, $h, $texto, $aFont, 'T', $alinhamento, 0, '');
2635
                $x += $w7;
2636
                // Valor Unitário
2637
                $texto = number_format($prod->getElementsByTagName("vUnCom")->item(0)->nodeValue, 4, ",", ".");
2638
                $this->pTextBox($x, $y, $w8, $h, $texto, $aFont, 'T', $alinhamento, 0, '');
2639
                $x += $w8;
2640
                // Valor do Produto
2641
                $texto = "";
2642
                if (is_numeric($prod->getElementsByTagName("vProd")->item(0)->nodeValue)) {
2643
                    $texto = number_format($prod->getElementsByTagName("vProd")->item(0)->nodeValue, 2, ",", ".");
2644
                }
2645
                $this->pTextBox($x, $y, $w9, $h, $texto, $aFont, 'T', $alinhamento, 0, '');
2646
                //Valor da Base de calculo
2647
                $x += $w9;
2648
                if (isset($ICMS)) {
2649
                    $texto = ! empty($ICMS->getElementsByTagName("vBC")->item(0)->nodeValue) ?
2650
                            number_format(
2651
                                $ICMS->getElementsByTagName("vBC")->item(0)->nodeValue,
2652
                                2,
2653
                                ",",
2654
                                "."
2655
                            ) : '0, 00';
2656
                    $this->pTextBox($x, $y, $w10, $h, $texto, $aFont, 'T', $alinhamento, 0, '');
2657
                }
2658
                //Valor do ICMS
2659
                $x += $w10;
2660
                if (isset($ICMS)) {
2661
                    $texto = ! empty($ICMS->getElementsByTagName("vICMS")->item(0)->nodeValue) ?
2662
                            number_format(
2663
                                $ICMS->getElementsByTagName("vICMS")->item(0)->nodeValue,
2664
                                2,
2665
                                ",",
2666
                                "."
2667
                            ) : '0, 00';
2668
                    $this->pTextBox($x, $y, $w11, $h, $texto, $aFont, 'T', $alinhamento, 0, '');
2669
                }
2670
                //Valor do IPI
2671
                $x += $w11;
2672
                if (isset($IPI)) {
2673
                    $texto = ! empty($IPI->getElementsByTagName("vIPI")->item(0)->nodeValue) ?
2674
                            number_format($IPI->getElementsByTagName("vIPI")->item(0)->nodeValue, 2, ",", ".") :'';
2675
                } else {
2676
                    $texto = '';
2677
                }
2678
                $this->pTextBox($x, $y, $w12, $h, $texto, $aFont, 'T', $alinhamento, 0, '');
2679
                // %ICMS
2680
                $x += $w12;
2681
                if (isset($ICMS)) {
2682
                    $texto = ! empty($ICMS->getElementsByTagName("pICMS")->item(0)->nodeValue) ?
2683
                            number_format(
2684
                                $ICMS->getElementsByTagName("pICMS")->item(0)->nodeValue,
2685
                                2,
2686
                                ",",
2687
                                "."
2688
                            ) : '0, 00';
2689
                    $this->pTextBox($x, $y, $w13, $h, $texto, $aFont, 'T', 'C', 0, '');
2690
                }
2691
                //%IPI
2692
                $x += $w13;
2693
                if (isset($IPI)) {
2694
                    $texto = ! empty($IPI->getElementsByTagName("pIPI")->item(0)->nodeValue) ?
2695
                            number_format($IPI->getElementsByTagName("pIPI")->item(0)->nodeValue, 2, ",", ".") : '';
2696
                } else {
2697
                    $texto = '';
2698
                }
2699
                $this->pTextBox($x, $y, $w14, $h, $texto, $aFont, 'T', 'C', 0, '');
2700
2701
2702
                // Dados do Veiculo Somente para veiculo 0 Km
2703
                $veicProd = $prod->getElementsByTagName("veicProd")->item(0);
2704
                // Tag somente é gerada para veiculo 0k, e só é permitido um veiculo por NF-e por conta do detran
2705
                // Verifica se a Tag existe
2706
                if (!empty($veicProd)) {
2707
                    $this->pDadosItenVeiculoDANFE($oldX, $y, $h, $prod);
2708
                }
2709
2710
2711
                $y += $h;
2712
                $i++;
2713
                //incrementa o controle dos itens processados.
2714
                $this->qtdeItensProc++;
2715
            } else {
2716
                $i++;
2717
            }
2718
        }
2719
        return $oldY+$hmax;
2720
    }
2721
2722
2723
    /**
2724
     * pDadosItenVeiculoDANFE
2725
     * Coloca os dados do veiculo abaixo do item da NFe. (retrato e paisagem)
2726
     *
2727
     * @name  dadosAdicionaisDANFE
2728
     * @param float  $x    Posição horizontal
2729
     *                     canto esquerdo
2730
     * @param float  $y    Posição vertical
2731
     *                     canto superior
2732
     * @param float  $h    altura do campo
2733
     * @param object $prod Contendo todos os dados do item
2734
     */
2735
2736
    protected function pDadosItenVeiculoDANFE($x, $y, $h, $prod)
2737
    {
2738
        $oldX = $x;
2739
        $oldY = $y;
2740
2741
        if ($this->orientacao == 'P') {
2742
            $w = $this->wPrint;
2743
        } else {
2744
            if ($nInicio < 2) { // primeira página
2745
                $w = $this->wPrint - $this->wCanhoto;
2746
            } else { // páginas seguintes
2747
                $w = $this->wPrint;
2748
            }
2749
        }
2750
2751
        $aFont = array('font'=>$this->fontePadrao, 'size'=>7, 'style'=>'');
2752
2753
        $w1 = round($w*0.09, 0);
2754
2755
        // Tabela Renavam Combustivel
2756
        $renavamCombustivel = array(
2757
            1=>'ALCOOL',
2758
            2=>'GASOLINA',
2759
            3=>'DIESEL',
2760
            4=>'GASOGENIO',
2761
            5=>'GAS METANO',
2762
            6=>'ELETRICO/FONTE INTERNA',
2763
            7=>'ELETRICO/FONTE EXTERNA',
2764
            8=>'GASOL/GAS NATURAL COMBUSTIVEL',
2765
            9=>'ALCOOL/GAS NATURAL COMBUSTIVEL',
2766
            10=>'DIESEL/GAS NATURAL COMBUSTIVEL',
2767
            11=>'VIDE/CAMPO/OBSERVACAO',
2768
            12=>'ALCOOL/GAS NATURAL VEICULAR',
2769
            13=>'GASOLINA/GAS NATURAL VEICULAR',
2770
            14=>'DIESEL/GAS NATURAL VEICULAR',
2771
            15=>'GAS NATURAL VEICULAR',
2772
            16=>'ALCOOL/GASOLINA',
2773
            17=>'GASOLINA/ALCOOL/GAS NATURAL',
2774
            18=>'GASOLINA/ELETRICO'
2775
        );
2776
2777
        $renavamEspecie = array(
2778
            1=>'PASSAGEIRO',
2779
            2=>'CARGA',
2780
            3=>'MISTO',
2781
            4=>'CORRIDA',
2782
            5=>'TRACAO',
2783
            6=>'ESPECIAL',
2784
            7=>'COLECAO'
2785
        );
2786
2787
        $renavamTiposVeiculos = array(
2788
            1=>'BICICLETA',
2789
            2=>'CICLOMOTOR',
2790
            3=>'MOTONETA',
2791
            4=>'MOTOCICLETA',
2792
            5=>'TRICICLO',
2793
            6=>'AUTOMOVEL',
2794
            7=>'MICROONIBUS',
2795
            8=>'ONIBUS',
2796
            9=>'BONDE',
2797
            10=>'REBOQUE',
2798
            11=>'SEMI-REBOQUE',
2799
            12=>'CHARRETE',
2800
            13=>'CAMIONETA',
2801
            14=>'CAMINHAO',
2802
            15=>'CARROCA',
2803
            16=>'CARRO DE MAO',
2804
            17=>'CAMINHAO TRATOR',
2805
            18=>'TRATOR DE RODAS',
2806
            19=>'TRATOR DE ESTEIRAS',
2807
            20=>'TRATOR MISTO',
2808
            21=>'QUADRICICLO',
2809
            22=>'CHASSI/PLATAFORMA',
2810
            23=>'CAMINHONETE',
2811
            24=>'SIDE-CAR',
2812
            25=>'UTILITARIO',
2813
            26=>'MOTOR-CASA'
2814
        );
2815
2816
        $renavamTipoPintura = array(
2817
            'F'=>'FOSCA',
2818
            'S'=>'SÓLIDA',
2819
            'P'=>'PEROLIZADA'
2820
        );
2821
2822
2823
2824
        $veicProd = $prod->getElementsByTagName("veicProd")->item(0);
2825
2826
        $veiculoChassi = $veicProd->getElementsByTagName("chassi")->item(0)->nodeValue;
2827
        $veiculoCor = $veicProd->getElementsByTagName("xCor")->item(0)->nodeValue;
2828
        $veiculoCilindrada = $veicProd->getElementsByTagName("cilin")->item(0)->nodeValue;
2829
        $veiculoCmkg = $veicProd->getElementsByTagName("CMT")->item(0)->nodeValue;
2830
        $veiculoTipo = $veicProd->getElementsByTagName("tpVeic")->item(0)->nodeValue;
2831
2832
        $veiculoMotor = $veicProd->getElementsByTagName("nMotor")->item(0)->nodeValue;
2833
        $veiculoRenavam = $veicProd->getElementsByTagName("cMod")->item(0)->nodeValue;
2834
        $veiculoHp = $veicProd->getElementsByTagName("pot")->item(0)->nodeValue;
2835
        $veiculoPlaca = ''; //$veiculo->getElementsByTagName("CMT")->item(0)->nodeValue;
0 ignored issues
show
Unused Code Comprehensibility introduced by
79% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
2836
        $veiculoTipoPintura = $veicProd->getElementsByTagName("tpPint")->item(0)->nodeValue;
2837
2838
        $veiculoMarcaModelo = $prod->getElementsByTagName("xProd")->item(0)->nodeValue;
2839
        $veiculoEspecie = $veicProd->getElementsByTagName("espVeic")->item(0)->nodeValue;
2840
        $veiculoCombustivel = $veicProd->getElementsByTagName("tpComb")->item(0)->nodeValue;
2841
        $veiculoSerial = $veicProd->getElementsByTagName("nSerie")->item(0)->nodeValue;
2842
        $veiculoFabricacao = $veicProd->getElementsByTagName("anoFab")->item(0)->nodeValue;
2843
        $veiculoModelo = $veicProd->getElementsByTagName("anoMod")->item(0)->nodeValue;
2844
2845
        $veiculoDistancia = $veicProd->getElementsByTagName("dist")->item(0)->nodeValue;
2846
2847
        $x = $oldX;
2848
2849
        $yVeic = $y + $h;
2850
        $texto = 'Chassi: ............: ' . $veiculoChassi;
2851
        $this->pTextBox($x, $yVeic, $w1+40, $h, $texto, $aFont, 'T', 'L', 0, '');
2852
        $yVeic += $h;
2853
        $texto = 'Cor...................: ' . $veiculoCor;
2854
        $this->pTextBox($x, $yVeic, $w1+40, $h, $texto, $aFont, 'T', 'L', 0, '');
2855
        $yVeic += $h;
2856
        $texto = 'Cilindrada........: ' . $veiculoCilindrada;
2857
        $this->pTextBox($x, $yVeic, $w1+40, $h, $texto, $aFont, 'T', 'L', 0, '');
2858
        $yVeic += $h;
2859
        $texto = 'Cmkg...............: ' . $veiculoCmkg;
2860
        $this->pTextBox($x, $yVeic, $w1+40, $h, $texto, $aFont, 'T', 'L', 0, '');
2861
        $yVeic += $h;
2862
        $texto = 'Tipo.................: ' . $renavamTiposVeiculos[intval($veiculoTipo)];
2863
        $this->pTextBox($x, $yVeic, $w1+40, $h, $texto, $aFont, 'T', 'L', 0, '');
2864
        $yVeic = $y + $h;
2865
        $xVeic = $x + 65;
2866
        $texto = 'Nº Motor: .........: ' . $veiculoMotor;
2867
        $this->pTextBox($xVeic, $yVeic, $w1+50, $h, $texto, $aFont, 'T', 'L', 0, '');
2868
        $yVeic += $h;
2869
        $texto = 'Renavam...........: ' . $veiculoRenavam;
2870
        $this->pTextBox($xVeic, $yVeic, $w1+50, $h, $texto, $aFont, 'T', 'L', 0, '');
2871
        $yVeic += $h;
2872
        $texto = 'HP.....................: ' . $veiculoHp;
2873
        $this->pTextBox($xVeic, $yVeic, $w1+50, $h, $texto, $aFont, 'T', 'L', 0, '');
2874
        $yVeic += $h;
2875
        $texto = 'Placa.................: ' . $veiculoPlaca;
2876
        $this->pTextBox($xVeic, $yVeic, $w1+50, $h, $texto, $aFont, 'T', 'L', 0, '');
2877
        $yVeic += $h;
2878
        $texto = 'Tipo Pintura......: ' . $renavamTipoPintura[$veiculoTipoPintura];
2879
        $this->pTextBox($xVeic, $yVeic, $w1+50, $h, $texto, $aFont, 'T', 'L', 0, '');
2880
        $yVeic = $y + $h;
2881
        $xVeic = $xVeic + 55;
2882
        $texto = 'Marca / Modelo.....: ' . $veiculoMarcaModelo;
2883
        $this->pTextBox($xVeic, $yVeic, $w1+50, $h, $texto, $aFont, 'T', 'L', 0, '');
2884
        $yVeic += $h;
2885
        $texto = 'Especie..................: ' . $renavamEspecie[intval($veiculoEspecie)];
2886
        $this->pTextBox($xVeic, $yVeic, $w1+50, $h, $texto, $aFont, 'T', 'L', 0, '');
2887
        $yVeic += $h;
2888
        $texto = 'Combustivel..........: ' . $renavamCombustivel[intval($veiculoCombustivel)];
2889
        $this->pTextBox($xVeic, $yVeic, $w1+50, $h, $texto, $aFont, 'T', 'L', 0, '');
2890
        $yVeic += $h;
2891
        $texto = 'Serial.....................: ' . $veiculoSerial;
2892
        $this->pTextBox($xVeic, $yVeic, $w1+50, $h, $texto, $aFont, 'T', 'L', 0, '');
2893
        $yVeic += $h;
2894
        $texto = 'Ano Fab/Mod........: '. $veiculoFabricacao . '/' . $veiculoModelo;
2895
        $this->pTextBox($xVeic, $yVeic, $w1+50, $h, $texto, $aFont, 'T', 'L', 0, '');
2896
        $yVeic += $h;
2897
        $texto = 'Distancia Entre Eixos(mm)..: '. $veiculoDistancia;
2898
        $this->pTextBox($xVeic, $yVeic, $w1+50, $h, $texto, $aFont, 'T', 'L', 0, '');
2899
    }
2900
2901
    /**
2902
     * issqnDANFE
2903
     * Monta o campo de serviços do DANFE
2904
     *
2905
     * @name   issqnDANFE (retrato e paisagem)
2906
     * @param  float $x Posição horizontal canto esquerdo
2907
     * @param  float $y Posição vertical canto superior
2908
     * @return float Posição vertical final
2909
     */
2910
    protected function pIssqnDANFE($x, $y)
2911
    {
2912
        $oldX = $x;
2913
        //#####################################################################
2914
        //CÁLCULO DO ISSQN
2915
        $texto = "CÁLCULO DO ISSQN";
2916
        $w = $this->wPrint;
2917
        $h = 7;
2918
        $aFont = array('font'=>$this->fontePadrao, 'size'=>7, 'style'=>'B');
2919
        $this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 0, '');
2920
        //INSCRIÇÃO MUNICIPAL
2921
        $y += 3;
2922
        $w = round($this->wPrint*0.23, 0);
2923
        $texto = 'INSCRIÇÃO MUNICIPAL';
2924
        $aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>'');
2925
        $this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 1, '');
2926
        //inscrição municipal
2927
        $texto = ! empty($this->emit->getElementsByTagName("IM")->item(0)->nodeValue) ?
2928
                $this->emit->getElementsByTagName("IM")->item(0)->nodeValue : '';
2929
        $aFont = array('font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B');
2930
        $this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'B', 'L', 0, '');
2931
        //VALOR TOTAL DOS SERVIÇOS
2932
        $x += $w;
2933
        $texto = 'VALOR TOTAL DOS SERVIÇOS';
2934
        $aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>'');
2935
        $this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 1, '');
2936
        if (isset($this->ISSQNtot)) {
2937
            $texto = ! empty($this->ISSQNtot->getElementsByTagName("vServ")->item(0)->nodeValue) ?
2938
                    $this->ISSQNtot->getElementsByTagName("vServ")->item(0)->nodeValue : '';
2939
            $texto = number_format($texto, 2, ",", ".");
2940
        } else {
2941
            $texto = '';
2942
        }
2943
        $aFont = array('font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B');
2944
        $this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'B', 'R', 0, '');
2945
        //BASE DE CÁLCULO DO ISSQN
2946
        $x += $w;
2947
        $texto = 'BASE DE CÁLCULO DO ISSQN';
2948
        $aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>'');
2949
        $this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 1, '');
2950
        if (isset($this->ISSQNtot)) {
2951
            $texto = ! empty($this->ISSQNtot->getElementsByTagName("vBC")->item(0)->nodeValue) ?
2952
                    $this->ISSQNtot->getElementsByTagName("vBC")->item(0)->nodeValue : '';
2953
            $texto = ! empty($texto) ? number_format($texto, 2, ",", ".") : '';
2954
        } else {
2955
            $texto = '';
2956
        }
2957
        $aFont = array('font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B');
2958
        $this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'B', 'R', 0, '');
2959
        //VALOR TOTAL DO ISSQN
2960
        $x += $w;
2961
        if ($this->orientacao == 'P') {
2962
            $w = $this->wPrint - (3 * $w);
2963
        } else {
2964
            $w = $this->wPrint - (3 * $w)-$this->wCanhoto;
2965
        }
2966
        $texto = 'VALOR TOTAL DO ISSQN';
2967
        $aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>'');
2968
        $this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 1, '');
2969
        if (isset($this->ISSQNtot)) {
2970
            $texto = ! empty($this->ISSQNtot->getElementsByTagName("vISS")->item(0)->nodeValue) ?
2971
                    $this->ISSQNtot->getElementsByTagName("vISS")->item(0)->nodeValue : '';
2972
            $texto = ! empty($texto) ? number_format($texto, 2, ",", ".") : '';
2973
        } else {
2974
            $texto = '';
2975
        }
2976
        $aFont = array('font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B');
2977
        $this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'B', 'R', 0, '');
2978
        return ($y+$h+1);
2979
    }
2980
2981
    /**
2982
     *dadosAdicionaisDANFE
2983
     * Coloca o grupo de dados adicionais da NFe. (retrato e paisagem)
2984
     *
2985
     * @name   dadosAdicionaisDANFE
2986
     * @param  float $x Posição horizontal canto esquerdo
2987
     * @param  float $y Posição vertical canto superior
2988
     * @param  float $h altura do campo
2989
     * @return float Posição vertical final (eixo Y)
2990
     */
2991
    protected function pDadosAdicionaisDANFE($x, $y, $h)
2992
    {
2993
        //##################################################################################
2994
        //DADOS ADICIONAIS
2995
        $texto = "DADOS ADICIONAIS";
2996
        if ($this->orientacao == 'P') {
2997
              $w = $this->wPrint;
2998
        } else {
2999
              $w = $this->wPrint-$this->wCanhoto;
3000
        }
3001
        $aFont = array('font'=>$this->fontePadrao, 'size'=>7, 'style'=>'B');
3002
        $this->pTextBox($x, $y, $w, 8, $texto, $aFont, 'T', 'L', 0, '');
3003
        //INFORMAÇÕES COMPLEMENTARES
3004
        $texto = "INFORMAÇÕES COMPLEMENTARES";
3005
        $y += 3;
3006
        $w = $this->wAdic;
3007
        $aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>'B');
3008
        $this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 1, '');
3009
        //o texto com os dados adicionais foi obtido na função montaDANFE
3010
        //e carregado em uma propriedade privada da classe
3011
        //$this->wAdic com a largura do campo
3012
        //$this->textoAdic com o texto completo do campo
3013
        $y += 1;
3014
        $aFont = array('font'=>$this->fontePadrao, 'size'=>7, 'style'=>'');
3015
        $this->pTextBox($x, $y+2, $w-2, $h-3, $this->textoAdic, $aFont, 'T', 'L', 0, '', false);
3016
        //RESERVADO AO FISCO
3017
        $texto = "RESERVADO AO FISCO";
3018
        $x += $w;
3019
        $y -= 1;
3020
        if ($this->orientacao == 'P') {
3021
            $w = $this->wPrint-$w;
3022
        } else {
3023
            $w = $this->wPrint-$w-$this->wCanhoto;
3024
        }
3025
        $aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>'B');
3026
        $this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 1, '');
3027
        //inserir texto informando caso de contingência
3028
        // 1 - Normal - emissão normal;
3029
        // 2 - Contingência FS - emissão em contingência com impressão do DANFE em Formulário de Segurança;
3030
        // 3 - Contingência SCAN - emissão em contingência no Sistema de Contingência do Ambiente Nacional;
3031
        // 4 - Contingência DPEC - emissão em contingência com envio da Declaração
3032
        //     Prévia de Emissão em Contingência;
3033
        // 5 - Contingência FS-DA - emissão em contingência com impressão do DANFE em Formulário de
3034
        //     Segurança para Impressão de Documento Auxiliar de Documento Fiscal Eletrônico (FS-DA);
3035
        // 6 - Contingência SVC-AN
3036
        // 7 - Contingência SVC-RS
3037
        $xJust = $this->pSimpleGetValue($this->ide, 'xJust', 'Justificativa: ');
3038
        $dhCont = $this->pSimpleGetValue($this->ide, 'dhCont', ' Entrada em contingência : ');
3039
        $texto = '';
3040
        switch ($this->tpEmis) {
3041
            case 2:
3042
                $texto = 'CONTINGÊNCIA FS' . $dhCont . $xJust;
3043
                break;
3044
            case 3:
3045
                $texto = 'CONTINGÊNCIA SCAN' . $dhCont . $xJust;
3046
                break;
3047
            case 4:
3048
                $texto = 'CONTINGÊNCIA DPEC' . $dhCont . $xJust;
3049
                break;
3050
            case 5:
3051
                $texto = 'CONTINGÊNCIA FSDA' . $dhCont . $xJust;
3052
                break;
3053
            case 6:
3054
                $texto = 'CONTINGÊNCIA SVC-AN' . $dhCont . $xJust;
3055
                break;
3056
            case 7:
3057
                $texto = 'CONTINGÊNCIA SVC-RS' . $dhCont . $xJust;
3058
                break;
3059
        }
3060
        $y += 2;
3061
        $aFont = array('font'=>$this->fontePadrao, 'size'=>7, 'style'=>'');
3062
        $this->pTextBox($x, $y, $w-2, $h-3, $texto, $aFont, 'T', 'L', 0, '', false);
3063
        return $y+$h;
3064
    }
3065
3066
    /**
3067
     * pRodape
3068
     * Monta o rodapé no final da DANFE com a data/hora de impressão e informações
3069
     * sobre a API NfePHP
3070
     *
3071
     * @name   pRodape
3072
     * @param  float $xInic  Posição horizontal canto esquerdo
3073
     * @param  float $yFinal Posição vertical final para impressão
3074
     * @return void
3075
     */
3076
    protected function pRodape($x, $y)
3077
    {
3078
        if ($this->orientacao == 'P') {
3079
              $w = $this->wPrint;
3080
        } else {
3081
              $w = $this->wPrint-$this->wCanhoto;
3082
              $x = $this->wCanhoto;
3083
        }
3084
        $aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>'I');
3085
        $texto = "Impresso em ". date('d/m/Y') . " as " . date('H:i:s');
3086
        $this->pTextBox($x, $y, $w, 0, $texto, $aFont, 'T', 'L', false);
3087
        $texto = $this->creditos .  "  Powered by NFePHP";
3088
        $this->pTextBox($x, $y, $w, 0, $texto, $aFont, 'T', 'R', false, '');
3089
    }
3090
3091
    /**
3092
     * pCcanhotoDANFE
3093
     * Monta o canhoto da DANFE (retrato e paisagem)
3094
     *
3095
     * @name   canhotoDANFE
3096
     * @param  number $x Posição horizontal canto esquerdo
3097
     * @param  number $y Posição vertical canto superior
3098
     * @return number Posição vertical final
3099
     *
3100
     * TODO 21/07/14 fmertins: quando orientação L-paisagem, o canhoto está sendo gerado incorretamente
3101
     */
3102
    protected function pCanhoto($x, $y)
3103
    {
3104
        $oldX = $x;
3105
        $oldY = $y;
3106
        //#################################################################################
3107
        //canhoto
3108
        //identificação do tipo de nf entrada ou saida
3109
        $tpNF = $this->ide->getElementsByTagName('tpNF')->item(0)->nodeValue;
3110
        if ($tpNF == '0') {
3111
            //NFe de Entrada
3112
            $emitente = '';
3113
            $emitente .= $this->dest->getElementsByTagName("xNome")->item(0)->nodeValue . " - ";
3114
            $emitente .= $this->enderDest->getElementsByTagName("xLgr")->item(0)->nodeValue . ", ";
3115
            $emitente .= $this->enderDest->getElementsByTagName("nro")->item(0)->nodeValue . " - ";
3116
            $emitente .= $this->pSimpleGetValue($this->enderDest, "xCpl", " - ", " ");
3117
            $emitente .= $this->enderDest->getElementsByTagName("xBairro")->item(0)->nodeValue . " ";
3118
            $emitente .= $this->enderDest->getElementsByTagName("xMun")->item(0)->nodeValue . "-";
3119
            $emitente .= $this->enderDest->getElementsByTagName("UF")->item(0)->nodeValue . "";
3120
            $destinatario = $this->emit->getElementsByTagName("xNome")->item(0)->nodeValue . " ";
3121
        } else {
3122
            //NFe de Saída
3123
            $emitente = $this->emit->getElementsByTagName("xNome")->item(0)->nodeValue . " ";
3124
            $destinatario = '';
3125
            $destinatario .= $this->dest->getElementsByTagName("xNome")->item(0)->nodeValue . " - ";
3126
            $destinatario .= $this->enderDest->getElementsByTagName("xLgr")->item(0)->nodeValue . ", ";
3127
            $destinatario .= $this->enderDest->getElementsByTagName("nro")->item(0)->nodeValue . " ";
3128
            $destinatario .= $this->pSimpleGetValue($this->enderDest, "xCpl", " - ", " ");
3129
            $destinatario .= $this->enderDest->getElementsByTagName("xBairro")->item(0)->nodeValue . " ";
3130
            $destinatario .= $this->enderDest->getElementsByTagName("xMun")->item(0)->nodeValue . "-";
3131
            $destinatario .= $this->enderDest->getElementsByTagName("UF")->item(0)->nodeValue . " ";
3132
        }
3133
        //identificação do sistema emissor
3134
        //linha separadora do canhoto
3135
        if ($this->orientacao == 'P') {
3136
            $w = round($this->wPrint * 0.81, 0);
3137
        } else {
3138
            //linha separadora do canhoto - 238
3139
            //posicao altura
3140
            $y = $this->wPrint-85;
3141
            //altura
3142
            $w = $this->wPrint-85-24;
3143
        }
3144
        $h = 10;
3145
        //desenha caixa
3146
        $texto = '';
3147
        $aFont = array('font'=>$this->fontePadrao, 'size'=>7, 'style'=>'');
3148
        $aFontSmall = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>'');
3149
        if ($this->orientacao == 'P') {
3150
            $this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'C', 'L', 1, '', false);
3151
        } else {
3152
            $this->pTextBox90($x, $y, $w, $h, $texto, $aFont, 'C', 'L', 1, '', false);
3153
        }
3154
        $numNF = str_pad($this->ide->getElementsByTagName('nNF')->item(0)->nodeValue, 9, "0", STR_PAD_LEFT);
3155
        $serie = str_pad($this->ide->getElementsByTagName('serie')->item(0)->nodeValue, 3, "0", STR_PAD_LEFT);
3156
        $texto = "RECEBEMOS DE ";
3157
        $texto .= $emitente;
3158
        $texto .= " OS PRODUTOS E/OU SERVIÇOS CONSTANTES DA NOTA FISCAL ELETRÔNICA INDICADA ";
3159
        if ($this->orientacao == 'P') {
3160
            $texto .= "ABAIXO";
3161
        } else {
3162
            $texto .= "AO LADO";
3163
        }
3164
        $texto .= ". EMISSÃO: ";
3165
        $dEmi = ! empty($this->ide->getElementsByTagName("dEmi")->item(0)->nodeValue) ?
3166
                $this->ide->getElementsByTagName("dEmi")->item(0)->nodeValue : '';
3167
        if ($dEmi == '') {
3168
            $dEmi = ! empty($this->ide->getElementsByTagName("dhEmi")->item(0)->nodeValue) ?
3169
                    $this->ide->getElementsByTagName("dhEmi")->item(0)->nodeValue : '';
3170
            $aDemi = explode('T', $dEmi);
3171
            $dEmi = $aDemi[0];
3172
        }
3173
        $texto .= $this->pYmd2dmy($dEmi) ." ";
3174
        $texto .= "VALOR TOTAL: R$ ";
3175
        $texto .= number_format($this->ICMSTot->getElementsByTagName("vNF")->item(0)->nodeValue, 2, ",", ".") . " ";
3176
        $texto .= "DESTINATÁRIO: ";
3177
        $texto .= $destinatario;
3178
        if ($this->orientacao == 'P') {
3179
            $this->pTextBox($x, $y, $w-1, $h, $texto, $aFont, 'C', 'L', 0, '', false);
3180
            $x1 = $x + $w;
3181
            $w1 = $this->wPrint - $w;
3182
            $texto = "NF-e";
3183
            $aFont = array('font'=>$this->fontePadrao, 'size'=>14, 'style'=>'B');
3184
            $this->pTextBox($x1, $y, $w1, 18, $texto, $aFont, 'T', 'C', 0, '');
3185
            $texto = "Nº. " . $this->pFormat($numNF, "###.###.###") . " \n";
3186
            $texto .= "Série $serie";
3187
            $aFont = array('font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B');
3188
            $this->pTextBox($x1, $y, $w1, 18, $texto, $aFont, 'C', 'C', 1, '');
3189
            //DATA DE RECEBIMENTO
3190
            $texto = "DATA DE RECEBIMENTO";
3191
            $y += $h;
3192
            $w2 = round($this->wPrint*0.17, 0); //35;
3193
            $aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>'');
3194
            $this->pTextBox($x, $y, $w2, 8, $texto, $aFont, 'T', 'L', 1, '');
3195
            //IDENTIFICAÇÃO E ASSINATURA DO RECEBEDOR
3196
            $x += $w2;
3197
            $w3 = $w-$w2;
3198
            $texto = "IDENTIFICAÇÃO E ASSINATURA DO RECEBEDOR";
3199
            $this->pTextBox($x, $y, $w3, 8, $texto, $aFont, 'T', 'L', 1, '');
3200
            $x = $oldX;
3201
            $y += 9;
3202
            $this->pdf->DashedHLine($x, $y, $this->wPrint, 0.1, 80);
3203
            $y += 2;
3204
            return $y;
3205
        } else {
3206
            $x--;
3207
            $x = $this->pTextBox90($x, $y, $w-1, $h, $texto, $aFontSmall, 'C', 'L', 0, '', false);
3208
            //NUMERO DA NOTA FISCAL LOGO NFE
3209
            $w1 = 16;
3210
            $x1 = $oldX;
3211
            $y = $oldY;
3212
            $texto = "NF-e";
3213
            $aFont = array('font'=>$this->fontePadrao, 'size'=>14, 'style'=>'B');
3214
            $this->pTextBox($x1, $y, $w1, 18, $texto, $aFont, 'T', 'C', 0, '');
3215
            $texto = "Nº.\n" . $this->pFormat($numNF, "###.###.###") . " \n";
3216
            $texto .= "Série $serie";
3217
            $aFont = array('font'=>$this->fontePadrao, 'size'=>8, 'style'=>'B');
3218
            $this->pTextBox($x1, $y, $w1, 18, $texto, $aFont, 'C', 'C', 1, '');
3219
            //DATA DO RECEBIMENTO
3220
            $texto = "DATA DO RECEBIMENTO";
3221
            $y = $this->wPrint-85;
3222
            $x = 12;
3223
            $w2 = round($this->wPrint*0.17, 0); //35;
3224
            $aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>'');
3225
            $this->pTextBox90($x, $y, $w2, 8, $texto, $aFont, 'T', 'L', 1, '');
3226
            //IDENTIFICAÇÃO E ASSINATURA DO RECEBEDOR
3227
            $y -= $w2;
3228
            $w3 = $w-$w2;
3229
            $texto = "IDENTIFICAÇÃO E ASSINATURA DO RECEBEDOR";
3230
            $aFont = array('font'=>$this->fontePadrao, 'size'=>5.7, 'style'=>'');
3231
            $x = $this->pTextBox90($x, $y, $w3, 8, $texto, $aFont, 'T', 'L', 1, '');
3232
            $this->pdf->DashedVLine(23, $oldY, 0.1, $this->wPrint-20, 67);
3233
            return $x;
3234
        }
3235
    }
3236
3237
    /**
3238
     * pGeraInformacoesDaTagCompra
3239
     * Devolve uma string contendo informação sobre as tag <compra><xNEmp>, <xPed> e <xCont> ou string vazia.
3240
     * Aviso: Esta função não leva em consideração dados na tag xPed do item.
3241
     *
3242
     * @name   pGeraInformacoesDaTagCompra
3243
     * @return string com as informacoes dos pedidos.
3244
     */
3245
    protected function pGeraInformacoesDaTagCompra()
3246
    {
3247
        $saida = "";
3248
        if (isset($this->compra)) {
3249
            if (! empty($this->compra->getElementsByTagName("xNEmp")->item(0)->nodeValue)) {
3250
                $saida .= " Nota de Empenho: " . $this->compra->getElementsByTagName("xNEmp")->item(0)->nodeValue;
3251
            }
3252
            if (! empty($this->compra->getElementsByTagName("xPed")->item(0)->nodeValue)) {
3253
                $saida .= " Pedido: " . $this->compra->getElementsByTagName("xPed")->item(0)->nodeValue;
3254
            }
3255
            if (! empty($this->compra->getElementsByTagName("xCont")->item(0)->nodeValue)) {
3256
                $saida .= " Contrato: " . $this->compra->getElementsByTagName("xCont")->item(0)->nodeValue;
3257
            }
3258
        }
3259
        return $saida;
3260
    }
3261
3262
    /**
3263
     * pGeraChaveAdicionalDeContingencia
3264
     *
3265
     * @name   pGeraChaveAdicionalDeContingencia
3266
     * @return string chave
3267
     */
3268
    protected function pGeraChaveAdicionalDeContingencia()
3269
    {
3270
        //cUF tpEmis CNPJ vNF ICMSp ICMSs DD  DV
3271
        // Quantidade de caracteres  02   01      14  14    01    01  02 01
0 ignored issues
show
Unused Code Comprehensibility introduced by
37% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
3272
        $forma  = "%02d%d%s%014d%01d%01d%02d";
3273
        $cUF    = $this->ide->getElementsByTagName('cUF')->item(0)->nodeValue;
3274
        $CNPJ   = "00000000000000" . $this->emit->getElementsByTagName('CNPJ')->item(0)->nodeValue;
3275
        $CNPJ   = substr($CNPJ, -14);
3276
        $vNF    = $this->ICMSTot->getElementsByTagName("vNF")->item(0)->nodeValue * 100;
3277
        $vICMS  = $this->ICMSTot->getElementsByTagName("vICMS")->item(0)->nodeValue;
3278
        if ($vICMS > 0) {
3279
            $vICMS = 1;
3280
        }
3281
        $icmss  = $this->ICMSTot->getElementsByTagName("vBC")->item(0)->nodeValue;
3282
        if ($icmss > 0) {
3283
            $icmss = 1;
3284
        }
3285
        $dEmi = ! empty($this->ide->getElementsByTagName("dEmi")->item(0)->nodeValue) ?
3286
                $this->ide->getElementsByTagName("dEmi")->item(0)->nodeValue : '';
3287
        if ($dEmi == '') {
3288
            $dEmi = ! empty($this->ide->getElementsByTagName("dhEmi")->item(0)->nodeValue) ?
3289
                    $this->ide->getElementsByTagName("dhEmi")->item(0)->nodeValue : '';
3290
            $aDemi = explode('T', $dEmi);
3291
            $dEmi = $aDemi[0];
3292
        }
3293
        $dd  = $dEmi;
3294
        $rpos = strrpos($dd, '-');
3295
        $dd  = substr($dd, $rpos +1);
3296
        $chave = sprintf($forma, $cUF, $this->tpEmis, $CNPJ, $vNF, $vICMS, $icmss, $dd);
3297
        $chave = $chave . $this->pModulo11($chave);
3298
        return $chave;
3299
    }
3300
3301
    /**
3302
     * pGeraInformacoesDasNotasReferenciadas
3303
     * Devolve uma string contendo informação sobre as notas referenciadas. Suporta N notas, eletrônicas ou não
3304
     * Exemplo: NFe Ref.: série: 01 número: 01 emit: 11.111.111/0001-01
3305
     * em 10/2010 [0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000]
3306
     *
3307
     * @return string Informacoes a serem adicionadas no rodapé sobre notas referenciadas.
3308
     */
3309
    protected function pGeraInformacoesDasNotasReferenciadas()
3310
    {
3311
        $formaNfeRef = "\r\nNFe Ref.: série:%d número:%d emit:%s em %s [%s]";
3312
        $formaCTeRef = "\r\nCTe Ref.: série:%d número:%d emit:%s em %s [%s]";
3313
        $formaNfRef = "\r\nNF  Ref.: série:%d numero:%d emit:%s em %s modelo: %d";
3314
        $formaECFRef = "\r\nECF Ref.: modelo: %s ECF:%d COO:%d";
3315
        $formaNfpRef = "\r\nNFP Ref.: série:%d número:%d emit:%s em %s modelo: %d IE:%s";
3316
        $saida='';
3317
        $nfRefs = $this->ide->getElementsByTagName('NFref');
3318
        if (0 === $nfRefs->length) {
3319
            return $saida;
3320
        }
3321
        foreach ($nfRefs as $nfRef) {
3322
            if (empty($nfRef)) {
3323
                continue;
3324
            }
3325
            $refNFe = $nfRef->getElementsByTagName('refNFe');
3326
            foreach ($refNFe as $chave_acessoRef) {
3327
                $chave_acesso = $chave_acessoRef->nodeValue;
3328
                $chave_acessoF = $this->pFormat($chave_acesso, $this->formatoChave);
3329
                $data = substr($chave_acesso, 4, 2)."/20".substr($chave_acesso, 2, 2);
3330
                $cnpj = $this->pFormat(substr($chave_acesso, 6, 14), "##.###.###/####-##");
3331
                $serie  = substr($chave_acesso, 22, 3);
3332
                $numero = substr($chave_acesso, 25, 9);
3333
                $saida .= sprintf($formaNfeRef, $serie, $numero, $cnpj, $data, $chave_acessoF);
3334
            }
3335
            $refNF = $nfRef->getElementsByTagName('refNF');
3336
            foreach ($refNF as $umaRefNFe) {
3337
                $data = $umaRefNFe->getElementsByTagName('AAMM')->item(0)->nodeValue;
3338
                $cnpj = $umaRefNFe->getElementsByTagName('CNPJ')->item(0)->nodeValue;
3339
                $mod = $umaRefNFe->getElementsByTagName('mod')->item(0)->nodeValue;
3340
                $serie = $umaRefNFe->getElementsByTagName('serie')->item(0)->nodeValue;
3341
                $numero = $umaRefNFe->getElementsByTagName('nNF')->item(0)->nodeValue;
3342
                $data = substr($data, 2, 2) . "/20" . substr($data, 0, 2);
3343
                $cnpj = $this->pFormat($cnpj, "##.###.###/####-##");
3344
                $saida .= sprintf($formaNfRef, $serie, $numero, $cnpj, $data, $mod);
3345
            }
3346
            $refCTe = $nfRef->getElementsByTagName('refCTe');
3347
            foreach ($refCTe as $chave_acessoRef) {
3348
                $chave_acesso = $chave_acessoRef->nodeValue;
3349
                $chave_acessoF = $this->pFormat($chave_acesso, $this->formatoChave);
3350
                $data = substr($chave_acesso, 4, 2)."/20".substr($chave_acesso, 2, 2);
3351
                $cnpj = $this->pFormat(substr($chave_acesso, 6, 14), "##.###.###/####-##");
3352
                $serie  = substr($chave_acesso, 22, 3);
3353
                $numero = substr($chave_acesso, 25, 9);
3354
                $saida .= sprintf($formaCTeRef, $serie, $numero, $cnpj, $data, $chave_acessoF);
3355
            }
3356
            $refECF = $nfRef->getElementsByTagName('refECF');
3357
            foreach ($refECF as $umaRefNFe) {
3358
                $mod    = $umaRefNFe->getElementsByTagName('mod')->item(0)->nodeValue;
3359
                $nECF   = $umaRefNFe->getElementsByTagName('nECF')->item(0)->nodeValue;
3360
                $nCOO   = $umaRefNFe->getElementsByTagName('nCOO')->item(0)->nodeValue;
3361
                $saida .= sprintf($formaECFRef, $mod, $nECF, $nCOO);
3362
            }
3363
            $refNFP = $nfRef->getElementsByTagName('refNFP');
3364
            foreach ($refNFP as $umaRefNFe) {
3365
                $data = $umaRefNFe->getElementsByTagName('AAMM')->item(0)->nodeValue;
3366
                $cnpj = ! empty($umaRefNFe->getElementsByTagName('CNPJ')->item(0)->nodeValue) ?
3367
                    $umaRefNFe->getElementsByTagName('CNPJ')->item(0)->nodeValue :
3368
                    '';
3369
                $cpf = ! empty($umaRefNFe->getElementsByTagName('CPF')->item(0)->nodeValue) ?
3370
                        $umaRefNFe->getElementsByTagName('CPF')->item(0)->nodeValue : '';
3371
                $mod = $umaRefNFe->getElementsByTagName('mod')->item(0)->nodeValue;
3372
                $serie = $umaRefNFe->getElementsByTagName('serie')->item(0)->nodeValue;
3373
                $numero = $umaRefNFe->getElementsByTagName('nNF')->item(0)->nodeValue;
3374
                $ie = $umaRefNFe->getElementsByTagName('IE')->item(0)->nodeValue;
3375
                $data = substr($data, 2, 2) . "/20" . substr($data, 0, 2);
3376
                if ($cnpj == '') {
3377
                    $cpf_cnpj = $this->pFormat($cpf, "###.###.###-##");
3378
                } else {
3379
                    $cpf_cnpj = $this->pFormat($cnpj, "##.###.###/####-##");
3380
                }
3381
                $saida .= sprintf($formaNfpRef, $serie, $numero, $cpf_cnpj, $data, $mod, $ie);
3382
            }
3383
        }
3384
        return $saida;
3385
    }
3386
    
3387
    private function imagePNGtoJPG($original)
3388
    {
3389
        $image = imagecreatefrompng($original);
3390
        ob_start();
3391
        imagejpeg($image, null, 100);
3392
        imagedestroy($image);
3393
        $stringdata = ob_get_contents(); // read from buffer
3394
        ob_end_clean();
3395
        return 'data://text/plain;base64,'.base64_encode($stringdata);
3396
    }
3397
}
3398