Passed
Push — master ( 573f47...7b057c )
by Roberto
02:08
created

Danfe::pAnfavea()   F

Complexity

Conditions 36
Paths > 20000

Size

Total Lines 139

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 1332

Importance

Changes 0
Metric Value
cc 36
nc 2519426
nop 1
dl 0
loc 139
ccs 0
cts 133
cp 0
crap 1332
rs 0
c 0
b 0
f 0

How to fix   Long Method    Complexity   

Long Method

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

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

Commonly applied refactorings include:

1
<?php
2
3
namespace NFePHP\DA\NFe;
4
5
use InvalidArgumentException;
6
use NFePHP\DA\Legacy\Dom;
7
use NFePHP\DA\Legacy\Pdf;
8
use NFePHP\DA\Legacy\Common;
9
10
class Danfe extends Common
11
{
12
    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 só tenha pagamento em boleto exibe as faturas ou invés das formas
748
        //caso tenha boleto e sem pagamento também exibir faturas pois deve ser devolução de
749
        //materiais do destinatário e não tem cobrança
750
        if ((count($formaPag)=='1' && isset($formaPag[15]) || count($formaPag)=='2'
0 ignored issues
show
Bug introduced by
Avoid IF statements that are always true or false
Loading history...
751
             && isset($formaPag[15]) && isset($formaPag[90])) {
752
            $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...
753
        } else {
754
            //Se somente tiver a forma de pagamento sem pagamento ou outros não imprimir nada
755
            if (count($formaPag)=='1' && (isset($formaPag[90]) || isset($formaPag[99]))) {
756
                $y = $y;
757
            } else {
758
                //Se somente tiver a forma de pagamento sem pagamento ou outros não imprimir nada
759
                if (count($formaPag)=='1' && (isset($formaPag[90]) || isset($formaPag[99]))) {
760
                    $y = $y;
761
                } else {
762
                    //caso tenha mais de uma forma de pagamento ou seja diferente de boleto exibe a
763
                    //forma de pagamento e o valor
764
                    $y = $this->pagamentoDANFE($x, $y+1);
765
                }
766
            }
767
        }
768
        //coloca os dados dos impostos e totais da NFe
769
        $y = $this->pImpostoDANFE($x, $y+1);
770
        //coloca os dados do trasnporte
771
        $y = $this->pTransporteDANFE($x, $y+1);
772
        //itens da DANFE
773
        $nInicial = 0;
774
        $y = $this->pItensDANFE($x, $y+1, $nInicial, $hDispo1, $pag, $totPag, $hCabecItens);
775
        //coloca os dados do ISSQN
776
        if ($linhaISSQN == 1) {
777
            $y = $this->pIssqnDANFE($x, $y+4);
778
        } else {
779
            $y += 4;
780
        }
781
        //coloca os dados adicionais da NFe
782
        $y = $this->pDadosAdicionaisDANFE($x, $y, $hdadosadic);
783
        //coloca o rodapé da página
784
        if ($this->orientacao == 'P') {
785
            $this->pRodape($xInic, $y-1);
786
        } else {
787
            $this->pRodape($xInic, $this->hPrint + 1);
788
        }
789
        //loop para páginas seguintes
790
        for ($n = 2; $n <= $totPag; $n++) {
791
            // fixa as margens
792
            $this->pdf->setMargins($margEsq, $margSup);
793
            //adiciona nova página
794
            $this->pdf->addPage($this->orientacao, $this->papel);
795
            //ajusta espessura das linhas
796
            $this->pdf->setLineWidth(0.1);
797
            //seta a cor do texto para petro
798
            $this->pdf->setTextColor(0, 0, 0);
799
            // posição inicial do relatorio
800
            $x = $xInic;
801
            $y = $yInic;
802
            //coloca o cabeçalho na página adicional
803
            $y = $this->pCabecalhoDANFE($x, $y, $n, $totPag);
804
            //coloca os itens na página adicional
805
            $y = $this->pItensDANFE($x, $y+1, $nInicial, $hDispo2, $n, $totPag, $hCabecItens);
806
            //coloca o rodapé da página
807
            if ($this->orientacao == 'P') {
808
                $this->pRodape($xInic, $y + 4);
809
            } else {
810
                $this->pRodape($xInic, $this->hPrint + 4);
811
            }
812
            //se estiver na última página e ainda restar itens para inserir, adiciona mais uma página
813
            if ($n == $totPag && $this->qtdeItensProc < $qtdeItens) {
814
                $totPag++;
815
            }
816
        }
817
        //retorna o ID na NFe
818
        if ($classPdf!==false) {
819
            $aR = array(
820
             'id'=>str_replace('NFe', '', $this->infNFe->getAttribute("Id")),
821
             'classe_PDF'=>$this->pdf);
822
            return $aR;
823
        } else {
824
            return str_replace('NFe', '', $this->infNFe->getAttribute("Id"));
825
        }
826
    }//fim da função montaDANFE
827
828
    /**
829
     * anfavea
830
     * Função para transformar o campo cdata do padrão ANFAVEA para
831
     * texto imprimível
832
     *
833
     * @param  string $cdata campo CDATA
834
     * @return string conteúdo do campo CDATA como string
835
     */
836
    protected function pAnfavea($cdata = '')
837
    {
838
        if ($cdata == '') {
839
            return '';
840
        }
841
        //remove qualquer texto antes ou depois da tag CDATA
842
        $cdata = str_replace('<![CDATA[', '<CDATA>', $cdata);
843
        $cdata = str_replace(']]>', '</CDATA>', $cdata);
844
        $cdata = preg_replace('/\s\s+/', ' ', $cdata);
845
        $cdata = str_replace("> <", "><", $cdata);
846
        $len = strlen($cdata);
847
        $startPos = strpos($cdata, '<');
848
        if ($startPos === false) {
849
            return $cdata;
850
        }
851
        for ($x=$len; $x>0; $x--) {
852
            if (substr($cdata, $x, 1) == '>') {
853
                $endPos = $x;
854
                break;
855
            }
856
        }
857
        if ($startPos > 0) {
858
            $parte1 = substr($cdata, 0, $startPos);
859
        } else {
860
            $parte1 = '';
861
        }
862
        $parte2 = substr($cdata, $startPos, $endPos-$startPos+1);
863
        if ($endPos < $len) {
864
            $parte3 = substr($cdata, $endPos + 1, $len - $endPos - 1);
865
        } else {
866
            $parte3 = '';
867
        }
868
        $texto = trim($parte1).' '.trim($parte3);
869
        if (strpos($parte2, '<CDATA>') === false) {
870
            $cdata = '<CDATA>'.$parte2.'</CDATA>';
871
        } else {
872
            $cdata = $parte2;
873
        }
874
        //Retira a tag <FONTE IBPT> (caso existir) pois não é uma estrutura válida XML
875
        $cdata = str_replace('<FONTE IBPT>', '', $cdata);
876
        //carrega o xml CDATA em um objeto DOM
877
        $dom = new Dom();
878
        $dom->loadXML($cdata, LIBXML_NOBLANKS | LIBXML_NOEMPTYTAG);
879
        //$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...
880
        //grupo CDATA infADprod
881
        $id = $dom->getElementsByTagName('id')->item(0);
882
        $div = $dom->getElementsByTagName('div')->item(0);
883
        $entg = $dom->getElementsByTagName('entg')->item(0);
884
        $dest = $dom->getElementsByTagName('dest')->item(0);
885
        $ctl = $dom->getElementsByTagName('ctl')->item(0);
886
        $ref = $dom->getElementsByTagName('ref')->item(0);
887
        if (isset($id)) {
888
            if ($id->hasAttributes()) {
889
                foreach ($id->attributes as $attr) {
890
                    $name = $attr->nodeName;
891
                    $value = $attr->nodeValue;
892
                    $texto .= " $name : $value";
893
                }
894
            }
895
        }
896
        if (isset($div)) {
897
            if ($div->hasAttributes()) {
898
                foreach ($div->attributes as $attr) {
899
                    $name = $attr->nodeName;
900
                    $value = $attr->nodeValue;
901
                    $texto .= " $name : $value";
902
                }
903
            }
904
        }
905
        if (isset($entg)) {
906
            if ($entg->hasAttributes()) {
907
                foreach ($entg->attributes as $attr) {
908
                    $name = $attr->nodeName;
909
                    $value = $attr->nodeValue;
910
                    $texto .= " $name : $value";
911
                }
912
            }
913
        }
914
        if (isset($dest)) {
915
            if ($dest->hasAttributes()) {
916
                foreach ($dest->attributes as $attr) {
917
                    $name = $attr->nodeName;
918
                    $value = $attr->nodeValue;
919
                    $texto .= " $name : $value";
920
                }
921
            }
922
        }
923
        if (isset($ctl)) {
924
            if ($ctl->hasAttributes()) {
925
                foreach ($ctl->attributes as $attr) {
926
                    $name = $attr->nodeName;
927
                    $value = $attr->nodeValue;
928
                    $texto .= " $name : $value";
929
                }
930
            }
931
        }
932
        if (isset($ref)) {
933
            if ($ref->hasAttributes()) {
934
                foreach ($ref->attributes as $attr) {
935
                    $name = $attr->nodeName;
936
                    $value = $attr->nodeValue;
937
                    $texto .= " $name : $value";
938
                }
939
            }
940
        }
941
        //grupo CADATA infCpl
942
        $t = $dom->getElementsByTagName('transmissor')->item(0);
943
        $r = $dom->getElementsByTagName('receptor')->item(0);
944
        $versao = ! empty($dom->getElementsByTagName('versao')->item(0)->nodeValue) ?
945
            'Versao:'.$dom->getElementsByTagName('versao')->item(0)->nodeValue.' ' : '';
946
        $especieNF = ! empty($dom->getElementsByTagName('especieNF')->item(0)->nodeValue) ?
947
            'Especie:'.$dom->getElementsByTagName('especieNF')->item(0)->nodeValue.' ' : '';
948
        $fabEntrega = ! empty($dom->getElementsByTagName('fabEntrega')->item(0)->nodeValue) ?
949
            'Entrega:'.$dom->getElementsByTagName('fabEntrega')->item(0)->nodeValue.' ' : '';
950
        $dca = ! empty($dom->getElementsByTagName('dca')->item(0)->nodeValue) ?
951
            'dca:'.$dom->getElementsByTagName('dca')->item(0)->nodeValue.' ' : '';
952
        $texto .= "".$versao.$especieNF.$fabEntrega.$dca;
953
        if (isset($t)) {
954
            if ($t->hasAttributes()) {
955
                $texto .= " Transmissor ";
956
                foreach ($t->attributes as $attr) {
957
                    $name = $attr->nodeName;
958
                    $value = $attr->nodeValue;
959
                    $texto .= " $name : $value";
960
                }
961
            }
962
        }
963
        if (isset($r)) {
964
            if ($r->hasAttributes()) {
965
                $texto .= " Receptor ";
966
                foreach ($r->attributes as $attr) {
967
                    $name = $attr->nodeName;
968
                    $value = $attr->nodeValue;
969
                    $texto .= " $name : $value";
970
                }
971
            }
972
        }
973
        return $texto;
974
    }
975
976
    /**
977
     * Dados brutos do PDF
978
     * @return string
979
     */
980
    public function render()
981
    {
982
        return $this->pdf->getPdf();
983
    }
984
985
    protected function pNotaCancelada()
986
    {
987
        if (!isset($this->nfeProc)) {
988
            return false;
989
        }
990
        $cStat = $this->pSimpleGetValue($this->nfeProc, "cStat");
991
        return $cStat == '101' ||
992
                $cStat == '151' ||
993
                $cStat == '135' ||
994
                $cStat == '155' ||
995
                $this->situacao_externa == self::SIT_CANCELADA;
996
    }
997
998
    protected function pNotaDPEC()
999
    {
1000
        return $this->situacao_externa == self::SIT_DPEC && $this->numero_registro_dpec != '';
1001
    }
1002
1003
    protected function pNotaDenegada()
1004
    {
1005
        if (!isset($this->nfeProc)) {
1006
            return false;
1007
        }
1008
        //NÃO ERA NECESSÁRIO ESSA FUNÇÃO POIS SÓ SE USA
1009
        //1 VEZ NO ARQUIVO INTEIRO
1010
        $cStat = $this->pSimpleGetValue($this->nfeProc, "cStat");
1011
        return $cStat == '110' ||
1012
               $cStat == '301' ||
1013
               $cStat == '302' ||
1014
               $this->situacao_externa == self::SIT_DENEGADA;
1015
    }
1016
1017
    /**
1018
     *cabecalhoDANFE
1019
     * Monta o cabelhalho da DANFE (retrato e paisagem)
1020
     *
1021
     * @param  number $x      Posição horizontal inicial, canto esquerdo
1022
     * @param  number $y      Posição vertical inicial, canto superior
1023
     * @param  number $pag    Número da Página
1024
     * @param  number $totPag Total de páginas
1025
     * @return number Posição vertical final
1026
     */
1027
    protected function pCabecalhoDANFE($x = 0, $y = 0, $pag = '1', $totPag = '1')
1028
    {
1029
        $oldX = $x;
1030
        $oldY = $y;
1031
        if ($this->orientacao == 'P') {
1032
              $maxW = $this->wPrint;
1033
        } else {
1034
            if ($pag == 1) { // primeira página
1035
                $maxW = $this->wPrint - $this->wCanhoto;
1036
            } else { // páginas seguintes
1037
                $maxW = $this->wPrint;
1038
            }
1039
        }
1040
        //####################################################################################
1041
        //coluna esquerda identificação do emitente
1042
        $w = round($maxW*0.41, 0);
1043
        if ($this->orientacao == 'P') {
1044
            $aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>'I');
1045
        } else {
1046
            $aFont = array('font'=>$this->fontePadrao, 'size'=>8, 'style'=>'B');
1047
        }
1048
        $w1 = $w;
1049
        $h=32;
1050
        $oldY += $h;
1051
        $this->pTextBox($x, $y, $w, $h);
1052
        $texto = 'IDENTIFICAÇÃO DO EMITENTE';
1053
        $this->pTextBox($x, $y, $w, 5, $texto, $aFont, 'T', 'C', 0, '');
1054
        //estabelecer o alinhamento
1055
        //pode ser left L, center C, right R, full logo L
1056
        //se for left separar 1/3 da largura para o tamanho da imagem
1057
        //os outros 2/3 serão usados para os dados do emitente
1058
        //se for center separar 1/2 da altura para o logo e 1/2 para os dados
1059
        //se for right separa 2/3 para os dados e o terço seguinte para o logo
1060
        //se não houver logo centraliza dos dados do emitente
1061
        // coloca o logo
1062
        if (!empty($this->logomarca)) {
1063
            $logoInfo = getimagesize($this->logomarca);
1064
            $type = strtolower(explode('/', $logoInfo['mime'])[1]);
1065
            if ($type == 'png') {
1066
                $this->logomarca = $this->imagePNGtoJPG($this->logomarca);
1067
                $type == 'jpg';
1068
            }
1069
            //largura da imagem em mm
1070
            $logoWmm = ($logoInfo[0]/72)*25.4;
1071
            //altura da imagem em mm
1072
            $logoHmm = ($logoInfo[1]/72)*25.4;
1073
            if ($this->logoAlign=='L') {
1074
                $nImgW = round($w/3, 0);
1075
                $nImgH = round($logoHmm * ($nImgW/$logoWmm), 0);
1076
                $xImg = $x+1;
1077
                $yImg = round(($h-$nImgH)/2, 0)+$y;
1078
                //estabelecer posições do texto
1079
                $x1 = round($xImg + $nImgW +1, 0);
1080
                $y1 = round($h/3+$y, 0);
1081
                $tw = round(2*$w/3, 0);
1082
            } elseif ($this->logoAlign=='C') {
1083
                $nImgH = round($h/3, 0);
1084
                $nImgW = round($logoWmm * ($nImgH/$logoHmm), 0);
1085
                $xImg = round(($w-$nImgW)/2+$x, 0);
1086
                $yImg = $y+3;
1087
                $x1 = $x;
1088
                $y1 = round($yImg + $nImgH + 1, 0);
1089
                $tw = $w;
1090
            } elseif ($this->logoAlign=='R') {
1091
                $nImgW = round($w/3, 0);
1092
                $nImgH = round($logoHmm * ($nImgW/$logoWmm), 0);
1093
                $xImg = round($x+($w-(1+$nImgW)), 0);
1094
                $yImg = round(($h-$nImgH)/2, 0)+$y;
1095
                $x1 = $x;
1096
                $y1 = round($h/3+$y, 0);
1097
                $tw = round(2*$w/3, 0);
1098
            } elseif ($this->logoAlign=='F') {
1099
                $nImgH = round($h-5, 0);
1100
                $nImgW = round($logoWmm * ($nImgH/$logoHmm), 0);
1101
                $xImg = round(($w-$nImgW)/2+$x, 0);
1102
                $yImg = $y+3;
1103
                $x1 = $x;
1104
                $y1 = round($yImg + $nImgH + 1, 0);
1105
                $tw = $w;
1106
            }
1107
            $type = (substr($this->logomarca, 0, 7) === 'data://') ? 'jpg' : null;
1108
            $this->pdf->Image($this->logomarca, $xImg, $yImg, $nImgW, $nImgH, $type);
1109
        } else {
1110
            $x1 = $x;
1111
            $y1 = round($h/3+$y, 0);
1112
            $tw = $w;
1113
        }
1114
        // monta as informações apenas se diferente de full logo
1115
        if ($this->logoAlign !== 'F') {
1116
            //Nome emitente
1117
            $aFont = array('font'=>$this->fontePadrao, 'size'=>12, 'style'=>'B');
1118
            $texto = $this->emit->getElementsByTagName("xNome")->item(0)->nodeValue;
1119
            $this->pTextBox($x1, $y1, $tw, 8, $texto, $aFont, 'T', 'C', 0, '');
1120
            //endereço
1121
            $y1 = $y1+5;
1122
            $aFont = array('font'=>$this->fontePadrao, 'size'=>8, 'style'=>'');
1123
            $fone = ! empty($this->enderEmit->getElementsByTagName("fone")->item(0)->nodeValue)
1124
                 ? $this->enderEmit->getElementsByTagName("fone")->item(0)->nodeValue
1125
                 : '';
1126
            $lgr = $this->pSimpleGetValue($this->enderEmit, "xLgr");
1127
            $nro = $this->pSimpleGetValue($this->enderEmit, "nro");
1128
            $cpl = $this->pSimpleGetValue($this->enderEmit, "xCpl", " - ");
1129
            $bairro = $this->pSimpleGetValue($this->enderEmit, "xBairro");
1130
            $CEP = $this->pSimpleGetValue($this->enderEmit, "CEP");
1131
            $CEP = $this->pFormat($CEP, "#####-###");
1132
            $mun = $this->pSimpleGetValue($this->enderEmit, "xMun");
1133
            $UF = $this->pSimpleGetValue($this->enderEmit, "UF");
1134
            $texto = $lgr . ", " . $nro . $cpl . "\n" . $bairro . " - "
1135
                    . $CEP . "\n" . $mun . " - " . $UF . " "
1136
                    . "Fone/Fax: " . $fone;
1137
            $this->pTextBox($x1, $y1, $tw, 8, $texto, $aFont, 'T', 'C', 0, '');
1138
        }
1139
1140
        //####################################################################################
1141
        //coluna central Danfe
1142
        $x += $w;
1143
        $w=round($maxW * 0.17, 0);//35;
1144
        $w2 = $w;
1145
        $h = 32;
1146
        $this->pTextBox($x, $y, $w, $h);
1147
1148
        if (! $this->pNotaCancelada()) {
1149
            // A PRINCIPIO NÃO PRECISAVA, POIS A NFE ESTÁ AUTORIZADA,
1150
            // SÓ SE RETIRA O DANFE PARA NOTAS NÃO AUTORIZADAS
1151
            $texto = "DANFE";
1152
            $aFont = array('font'=>$this->fontePadrao, 'size'=>14, 'style'=>'B');
1153
            $this->pTextBox($x, $y+1, $w, $h, $texto, $aFont, 'T', 'C', 0, '');
1154
            $aFont = array('font'=>$this->fontePadrao, 'size'=>8, 'style'=>'');
1155
            $texto = 'Documento Auxiliar da Nota Fiscal Eletrônica';
1156
            $h = 20;
1157
            $this->pTextBox($x, $y+6, $w, $h, $texto, $aFont, 'T', 'C', 0, '', false);
1158
        }
1159
1160
        $aFont = array('font'=>$this->fontePadrao, 'size'=>8, 'style'=>'');
1161
        $texto = '0 - ENTRADA';
1162
        $y1 = $y + 14;
1163
        $h = 8;
1164
        $this->pTextBox($x+2, $y1, $w, $h, $texto, $aFont, 'T', 'L', 0, '');
1165
        $texto = '1 - SAÍDA';
1166
        $y1 = $y + 17;
1167
        $this->pTextBox($x+2, $y1, $w, $h, $texto, $aFont, 'T', 'L', 0, '');
1168
        //tipo de nF
1169
        $aFont = array('font'=>$this->fontePadrao, 'size'=>12, 'style'=>'B');
1170
        $y1 = $y + 13;
1171
        $h = 7;
1172
        $texto = $this->ide->getElementsByTagName('tpNF')->item(0)->nodeValue;
1173
        $this->pTextBox($x+27, $y1, 5, $h, $texto, $aFont, 'C', 'C', 1, '');
1174
        //numero da NF
1175
        $aFont = array('font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B');
1176
        $y1 = $y + 20;
1177
        $numNF = str_pad($this->ide->getElementsByTagName('nNF')->item(0)->nodeValue, 9, "0", STR_PAD_LEFT);
1178
        $numNF = $this->pFormat($numNF, "###.###.###");
1179
        $texto = "Nº. " . $numNF;
1180
        $this->pTextBox($x, $y1, $w, $h, $texto, $aFont, 'C', 'C', 0, '');
1181
        //Série
1182
        $y1 = $y + 23;
1183
        $serie = str_pad($this->ide->getElementsByTagName('serie')->item(0)->nodeValue, 3, "0", STR_PAD_LEFT);
1184
        $texto = "Série " . $serie;
1185
        $this->pTextBox($x, $y1, $w, $h, $texto, $aFont, 'C', 'C', 0, '');
1186
        //numero paginas
1187
        $aFont = array('font'=>$this->fontePadrao, 'size'=>8, 'style'=>'I');
1188
        $y1 = $y + 26;
1189
        $texto = "Folha " . $pag . "/" . $totPag;
1190
        $this->pTextBox($x, $y1, $w, $h, $texto, $aFont, 'C', 'C', 0, '');
1191
1192
        //####################################################################################
1193
        //coluna codigo de barras
1194
        $x += $w;
1195
        $w = ($maxW-$w1-$w2);//85;
1196
        $w3 = $w;
1197
        $h = 32;
1198
        $this->pTextBox($x, $y, $w, $h);
1199
        $this->pdf->SetFillColor(0, 0, 0);
1200
        $chave_acesso = str_replace('NFe', '', $this->infNFe->getAttribute("Id"));
1201
        $bW = 75;
1202
        $bH = 12;
1203
        //codigo de barras
1204
        $this->pdf->Code128($x+(($w-$bW)/2), $y+2, $chave_acesso, $bW, $bH);
1205
        //linhas divisorias
1206
        $this->pdf->Line($x, $y+4+$bH, $x+$w, $y+4+$bH);
1207
        $this->pdf->Line($x, $y+12+$bH, $x+$w, $y+12+$bH);
1208
        $aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>'');
1209
        $y1 = $y+4+$bH;
1210
        $h = 7;
1211
        $texto = 'CHAVE DE ACESSO';
1212
        $this->pTextBox($x, $y1, $w, $h, $texto, $aFont, 'T', 'L', 0, '');
1213
        $aFont = array('font'=>$this->fontePadrao, 'size'=>8, 'style'=>'B');
1214
        $y1 = $y+8+$bH;
1215
        $texto = $this->pFormat($chave_acesso, $this->formatoChave);
1216
        $this->pTextBox($x+2, $y1, $w-2, $h, $texto, $aFont, 'T', 'C', 0, '');
1217
        $y1 = $y+12+$bH;
1218
        $aFont = array('font'=>$this->fontePadrao, 'size'=>8, 'style'=>'');
1219
        $chaveContingencia="";
1220
        if ($this->pNotaDPEC()) {
1221
            $cabecalhoProtoAutorizacao = 'NÚMERO DE REGISTRO DPEC';
1222
        } else {
1223
            $cabecalhoProtoAutorizacao = 'PROTOCOLO DE AUTORIZAÇÃO DE USO';
1224
        }
1225
        if (($this->tpEmis == 2 || $this->tpEmis == 5) && !$this->pNotaDPEC()) {
1226
            $cabecalhoProtoAutorizacao = "DADOS DA NF-E";
1227
            $chaveContingencia = $this->pGeraChaveAdicionalDeContingencia();
1228
            $this->pdf->SetFillColor(0, 0, 0);
1229
            //codigo de barras
1230
            $this->pdf->Code128($x+11, $y1+1, $chaveContingencia, $bW*.9, $bH/2);
1231
        } else {
1232
            $texto = 'Consulta de autenticidade no portal nacional da NF-e';
1233
            $this->pTextBox($x+2, $y1, $w-2, $h, $texto, $aFont, 'T', 'C', 0, '');
1234
            $y1 = $y+16+$bH;
1235
            $texto = 'www.nfe.fazenda.gov.br/portal ou no site da Sefaz Autorizadora';
1236
            $this->pTextBox(
1237
                $x+2,
1238
                $y1,
1239
                $w-2,
1240
                $h,
1241
                $texto,
1242
                $aFont,
1243
                'T',
1244
                'C',
1245
                0,
1246
                'http://www.nfe.fazenda.gov.br/portal ou no site da Sefaz Autorizadora'
1247
            );
1248
        }
1249
1250
        //####################################################################################
1251
        //Dados da NF do cabeçalho
1252
        //natureza da operação
1253
        $texto = 'NATUREZA DA OPERAÇÃO';
1254
        $aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>'');
1255
        $w = $w1+$w2;
1256
        $y = $oldY;
1257
        $oldY += $h;
1258
        $x = $oldX;
1259
        $h = 7;
1260
        $this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 1, '');
1261
        $texto = $this->ide->getElementsByTagName("natOp")->item(0)->nodeValue;
1262
        $aFont = array('font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B');
1263
        $this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'B', 'C', 0, '');
1264
        $x += $w;
1265
        $w = $w3;
1266
        //PROTOCOLO DE AUTORIZAÇÃO DE USO ou DADOS da NF-E
1267
        $aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>'');
1268
        $this->pTextBox($x, $y, $w, $h, $cabecalhoProtoAutorizacao, $aFont, 'T', 'L', 1, '');
1269
        // algumas NFe podem estar sem o protocolo de uso portanto sua existencia deve ser
1270
        // testada antes de tentar obter a informação.
1271
        // NOTA : DANFE sem protocolo deve existir somente no caso de contingência !!!
1272
        // Além disso, existem várias NFes em contingência que eu recebo com protocolo de autorização.
1273
        // Na minha opinião, deveríamos mostra-lo, mas o  manual  da NFe v4.01 diz outra coisa...
1274
        if (($this->tpEmis == 2 || $this->tpEmis == 5) && !$this->pNotaDPEC()) {
1275
            $aFont = array('font'=>$this->fontePadrao, 'size'=>8, 'style'=>'B');
1276
            $texto = $this->pFormat($chaveContingencia, "#### #### #### #### #### #### #### #### ####");
1277
            $cStat = '';
1278
        } else {
1279
            $aFont = array('font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B');
1280
            if ($this->pNotaDPEC()) {
1281
                $texto = $this->numero_registro_dpec;
1282
                $cStat = '';
1283
            } else {
1284
                if (isset($this->nfeProc)) {
1285
                    $texto = ! empty($this->nfeProc->getElementsByTagName("nProt")->item(0)->nodeValue) ?
1286
                            $this->nfeProc->getElementsByTagName("nProt")->item(0)->nodeValue : '';
1287
                    $tsHora = $this->pConvertTime($this->nfeProc->getElementsByTagName("dhRecbto")->item(0)->nodeValue);
1288
                    if ($texto != '') {
1289
                        $texto .= "  -  " . date('d/m/Y H:i:s', $tsHora);
1290
                    }
1291
                    $cStat = $this->nfeProc->getElementsByTagName("cStat")->item(0)->nodeValue;
1292
                } else {
1293
                    $texto = '';
1294
                    $cStat = '';
1295
                }
1296
            }
1297
        }
1298
        $this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'B', 'C', 0, '');
1299
        //####################################################################################
1300
        //INSCRIÇÃO ESTADUAL
1301
        $w = round($maxW * 0.333, 0);
1302
        $y += $h;
1303
        $oldY += $h;
1304
        $x = $oldX;
1305
        $texto = 'INSCRIÇÃO ESTADUAL';
1306
        $aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>'');
1307
        $this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 1, '');
1308
        $texto = $this->pSimpleGetValue($this->emit, "IE");
1309
        $aFont = array('font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B');
1310
        $this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'B', 'C', 0, '');
1311
        //INSCRIÇÃO ESTADUAL DO SUBST. TRIBUT.
1312
        $x += $w;
1313
        $texto = 'INSCRIÇÃO ESTADUAL DO SUBST. TRIBUT.';
1314
        $aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>'');
1315
        $this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 1, '');
1316
        $texto = ! empty($this->emit->getElementsByTagName("IEST")->item(0)->nodeValue)
1317
             ? $this->emit->getElementsByTagName("IEST")->item(0)->nodeValue
1318
             : '';
1319
        $aFont = array('font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B');
1320
        $this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'B', 'C', 0, '');
1321
        //CNPJ
1322
        $x += $w;
1323
        $w = ($maxW-(2*$w));
1324
        $texto = 'CNPJ / CPF';
1325
        $aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>'');
1326
        $this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 1, '');
1327
        //Pegando valor do CPF/CNPJ
1328
        if (! empty($this->emit->getElementsByTagName("CNPJ")->item(0)->nodeValue)) {
1329
            $texto = $this->pFormat(
1330
                $this->emit->getElementsByTagName("CNPJ")->item(0)->nodeValue,
1331
                "###.###.###/####-##"
1332
            );
1333
        } else {
1334
            $texto = ! empty($this->emit->getElementsByTagName("CPF")->item(0)->nodeValue) ?
1335
                $this->pFormat(
1336
                    $this->emit->getElementsByTagName("CPF")->item(0)->nodeValue,
1337
                    "###.###.###-##"
1338
                ) : '';
1339
        }
1340
        $aFont = array('font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B');
1341
        $this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'B', 'C', 0, '');
1342
1343
        //####################################################################################
1344
        //Indicação de NF Homologação, cancelamento e falta de protocolo
1345
        $tpAmb = $this->ide->getElementsByTagName('tpAmb')->item(0)->nodeValue;
1346
        //indicar cancelamento
1347
        if ($this->pNotaCancelada()) {
1348
            //101 Cancelamento
1349
            $x = 10;
1350
            $y = $this->hPrint-130;
1351
            $h = 25;
1352
            $w = $maxW-(2*$x);
1353
            $this->pdf->SetTextColor(90, 90, 90);
1354
            $texto = "NFe CANCELADA";
1355
            $aFont = array('font'=>$this->fontePadrao, 'size'=>48, 'style'=>'B');
1356
            $this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'C', 'C', 0, '');
1357
            $this->pdf->SetTextColor(0, 0, 0);
1358
        }
1359
1360
        if ($this->pNotaDPEC() || $this->tpEmis == 4) {
1361
            //DPEC
1362
            $x = 10;
1363
            $y = $this->hPrint-130;
1364
            $h = 25;
1365
            $w = $maxW-(2*$x);
1366
            $this->pdf->SetTextColor(200, 200, 200);
1367
            $texto = "DANFE impresso em contingência -\n".
1368
                     "DPEC regularmente recebido pela Receita\n".
1369
                     "Federal do Brasil";
1370
            $aFont = array('font'=>$this->fontePadrao, 'size'=>48, 'style'=>'B');
1371
            $this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'C', 'C', 0, '');
1372
            $this->pdf->SetTextColor(0, 0, 0);
1373
        }
1374
        if ($this->pNotaDenegada()) {
1375
            //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...
1376
            $x = 10;
1377
            $y = $this->hPrint-130;
1378
            $h = 25;
1379
            $w = $maxW-(2*$x);
1380
            $this->pdf->SetTextColor(90, 90, 90);
1381
            $texto = "NFe USO DENEGADO";
1382
            $aFont = array('font'=>$this->fontePadrao, 'size'=>48, 'style'=>'B');
1383
            $this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'C', 'C', 0, '');
1384
            $y += $h;
1385
            $h = 5;
1386
            $w = $maxW-(2*$x);
1387
            if (isset($this->infProt)) {
1388
                $xMotivo = $this->infProt->getElementsByTagName("xMotivo")->item(0)->nodeValue;
1389
            } else {
1390
                $xMotivo = '';
1391
            }
1392
            $texto = "SEM VALOR FISCAL\n".$xMotivo;
1393
            $aFont = array('font'=>$this->fontePadrao, 'size'=>48, 'style'=>'B');
1394
            $this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'C', 'C', 0, '');
1395
            $this->pdf->SetTextColor(0, 0, 0);
1396
        }
1397
        //indicar sem valor
1398
        if ($tpAmb != 1) {
1399
            $x = 10;
1400
            if ($this->orientacao == 'P') {
1401
                $y = round($this->hPrint*2/3, 0);
1402
            } else {
1403
                $y = round($this->hPrint/2, 0);
1404
            }
1405
            $h = 5;
1406
            $w = $maxW-(2*$x);
1407
            $this->pdf->SetTextColor(90, 90, 90);
1408
            $texto = "SEM VALOR FISCAL";
1409
            $aFont = array('font'=>$this->fontePadrao, 'size'=>48, 'style'=>'B');
1410
            $this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'C', 'C', 0, '');
1411
            $aFont = array('font'=>$this->fontePadrao, 'size'=>30, 'style'=>'B');
1412
            $texto = "AMBIENTE DE HOMOLOGAÇÃO";
1413
            $this->pTextBox($x, $y+14, $w, $h, $texto, $aFont, 'C', 'C', 0, '');
1414
            $this->pdf->SetTextColor(0, 0, 0);
1415
        } else {
1416
            $x = 10;
1417
            if ($this->orientacao == 'P') {
1418
                $y = round($this->hPrint*2/3, 0);
1419
            } else {
1420
                $y = round($this->hPrint/2, 0);
1421
            }//fim orientacao
1422
            $h = 5;
1423
            $w = $maxW-(2*$x);
1424
            $this->pdf->SetTextColor(90, 90, 90);
1425
            //indicar FALTA DO PROTOCOLO se NFe não for em contingência
1426
            if (($this->tpEmis == 2 || $this->tpEmis == 5) && !$this->pNotaDPEC()) {
1427
                //Contingência
1428
                $texto = "DANFE Emitido em Contingência";
1429
                $aFont = array('font'=>$this->fontePadrao, 'size'=>48, 'style'=>'B');
1430
                $this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'C', 'C', 0, '');
1431
                $aFont = array('font'=>$this->fontePadrao, 'size'=>30, 'style'=>'B');
1432
                $texto = "devido à problemas técnicos";
1433
                $this->pTextBox($x, $y+12, $w, $h, $texto, $aFont, 'C', 'C', 0, '');
1434
            } else {
1435
                if (!isset($this->nfeProc)) {
1436
                    if (!$this->pNotaDPEC()) {
1437
                        $texto = "SEM VALOR FISCAL";
1438
                        $aFont = array('font'=>$this->fontePadrao, 'size'=>48, 'style'=>'B');
1439
                        $this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'C', 'C', 0, '');
1440
                    }
1441
                    $aFont = array('font'=>$this->fontePadrao, 'size'=>30, 'style'=>'B');
1442
                    $texto = "FALTA PROTOCOLO DE APROVAÇÃO DA SEFAZ";
1443
                    if (!$this->pNotaDPEC()) {
1444
                        $this->pTextBox($x, $y+12, $w, $h, $texto, $aFont, 'C', 'C', 0, '');
1445
                    } else {
1446
                        $this->pTextBox($x, $y+25, $w, $h, $texto, $aFont, 'C', 'C', 0, '');
1447
                    }
1448
                }//fim nefProc
1449
            }//fim tpEmis
1450
            $this->pdf->SetTextColor(0, 0, 0);
1451
        }
1452
        return $oldY;
1453
    } //fim cabecalhoDANFE
1454
1455
    /**
1456
     * destinatarioDANFE
1457
     * Monta o campo com os dados do destinatário na DANFE. (retrato e paisagem)
1458
     *
1459
     * @name   destinatarioDANFE
1460
     * @param  number $x Posição horizontal canto esquerdo
1461
     * @param  number $y Posição vertical canto superior
1462
     * @return number Posição vertical final
1463
     */
1464
    protected function pDestinatarioDANFE($x = 0, $y = 0)
1465
    {
1466
        //####################################################################################
1467
        //DESTINATÁRIO / REMETENTE
1468
        $oldX = $x;
1469
        $oldY = $y;
1470
        if ($this->orientacao == 'P') {
1471
            $maxW = $this->wPrint;
1472
        } else {
1473
            $maxW = $this->wPrint - $this->wCanhoto;
1474
        }
1475
        $w = $maxW;
1476
        $h = 7;
1477
        $texto = 'DESTINATÁRIO / REMETENTE';
1478
        $aFont = array('font'=>$this->fontePadrao, 'size'=>7, 'style'=>'B');
1479
        $this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 0, '');
1480
        //NOME / RAZÃO SOCIAL
1481
        $w = round($maxW*0.61, 0);
1482
        $w1 = $w;
1483
        $y += 3;
1484
        $texto = 'NOME / RAZÃO SOCIAL';
1485
        $aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>'');
1486
        $this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 1, '');
1487
        $texto = $this->dest->getElementsByTagName("xNome")->item(0)->nodeValue;
1488
        $aFont = array('font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B');
1489
        if ($this->orientacao == 'P') {
1490
            $this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'B', 'L', 0, '');
1491
        } else {
1492
            $this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'B', 'L', 1, '');
1493
        }
1494
        //CNPJ / CPF
1495
        $x += $w;
1496
        $w = round($maxW*0.23, 0);
1497
        $w2 = $w;
1498
        $texto = 'CNPJ / CPF';
1499
        $aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>'');
1500
        $this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 1, '');
1501
        //Pegando valor do CPF/CNPJ
1502
        if (! empty($this->dest->getElementsByTagName("CNPJ")->item(0)->nodeValue)) {
1503
            $texto = $this->pFormat(
1504
                $this->dest->getElementsByTagName("CNPJ")->item(0)->nodeValue,
1505
                "###.###.###/####-##"
1506
            );
1507
        } else {
1508
            $texto = ! empty($this->dest->getElementsByTagName("CPF")->item(0)->nodeValue) ?
1509
                    $this->pFormat(
1510
                        $this->dest->getElementsByTagName("CPF")->item(0)->nodeValue,
1511
                        "###.###.###-##"
1512
                    ) : '';
1513
        }
1514
        $aFont = array('font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B');
1515
        $this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'B', 'C', 0, '');
1516
        //DATA DA EMISSÃO
1517
        $x += $w;
1518
        $w = $maxW-($w1+$w2);
1519
        $wx = $w;
1520
        $texto = 'DATA DA EMISSÃO';
1521
        $aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>'');
1522
        $this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 1, '');
1523
        $dEmi = ! empty($this->ide->getElementsByTagName("dEmi")->item(0)->nodeValue) ?
1524
                $this->ide->getElementsByTagName("dEmi")->item(0)->nodeValue : '';
1525
        if ($dEmi == '') {
1526
            $dEmi = ! empty($this->ide->getElementsByTagName("dhEmi")->item(0)->nodeValue) ?
1527
                    $this->ide->getElementsByTagName("dhEmi")->item(0)->nodeValue : '';
1528
            $aDemi = explode('T', $dEmi);
1529
            $dEmi = $aDemi[0];
1530
        }
1531
        $texto = $this->pYmd2dmy($dEmi);
1532
        $aFont = array('font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B');
1533
        if ($this->orientacao == 'P') {
1534
            $this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'B', 'C', 0, '');
1535
        } else {
1536
            $this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'B', 'C', 1, '');
1537
        }
1538
        //ENDEREÇO
1539
        $w = round($maxW*0.47, 0);
1540
        $w1 = $w;
1541
        $y += $h;
1542
        $x = $oldX;
1543
        $texto = 'ENDEREÇO';
1544
        $aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>'');
1545
        $this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 1, '');
1546
        $texto = $this->dest->getElementsByTagName("xLgr")->item(0)->nodeValue;
1547
        $texto .= ', ' . $this->dest->getElementsByTagName("nro")->item(0)->nodeValue;
1548
        $texto .= $this->pSimpleGetValue($this->dest, "xCpl", " - ");
1549
1550
        $aFont = array('font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B');
1551
        $this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'B', 'L', 0, '', true);
1552
        //BAIRRO / DISTRITO
1553
        $x += $w;
1554
        $w = round($maxW*0.21, 0);
1555
        $w2 = $w;
1556
        $texto = 'BAIRRO / DISTRITO';
1557
        $aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>'');
1558
        $this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 1, '');
1559
        $texto = $this->dest->getElementsByTagName("xBairro")->item(0)->nodeValue;
1560
        $aFont = array('font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B');
1561
        $this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'B', 'C', 0, '');
1562
        //CEP
1563
        $x += $w;
1564
        $w = $maxW-$w1-$w2-$wx;
1565
        $w2 = $w;
1566
        $texto = 'CEP';
1567
        $aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>'');
1568
        $this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 1, '');
1569
        $texto = ! empty($this->dest->getElementsByTagName("CEP")->item(0)->nodeValue) ?
1570
                $this->dest->getElementsByTagName("CEP")->item(0)->nodeValue : '';
1571
        $texto = $this->pFormat($texto, "#####-###");
1572
        $aFont = array('font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B');
1573
        $this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'B', 'C', 0, '');
1574
        //DATA DA SAÍDA
1575
        $x += $w;
1576
        $w = $wx;
1577
        $texto = 'DATA DA SAÍDA/ENTRADA';
1578
        $aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>'');
1579
        $this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 1, '');
1580
        $dSaiEnt = ! empty($this->ide->getElementsByTagName("dSaiEnt")->item(0)->nodeValue) ?
1581
                $this->ide->getElementsByTagName("dSaiEnt")->item(0)->nodeValue : '';
1582
        if ($dSaiEnt == '') {
1583
            $dSaiEnt = ! empty($this->ide->getElementsByTagName("dhSaiEnt")->item(0)->nodeValue) ?
1584
                    $this->ide->getElementsByTagName("dhSaiEnt")->item(0)->nodeValue : '';
1585
            $aDsaient = explode('T', $dSaiEnt);
1586
            $dSaiEnt = $aDsaient[0];
1587
        }
1588
        $texto = $this->pYmd2dmy($dSaiEnt);
1589
        $aFont = array('font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B');
1590
        $this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'B', 'C', 0, '');
1591
        //MUNICÍPIO
1592
        $w = $w1;
1593
        $y += $h;
1594
        $x = $oldX;
1595
        $texto = 'MUNICÍPIO';
1596
        $aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>'');
1597
        $this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 1, '');
1598
        $texto = $this->dest->getElementsByTagName("xMun")->item(0)->nodeValue;
1599
        if (strtoupper(trim($texto)) == "EXTERIOR" && $this->dest->getElementsByTagName("xPais")->length > 0) {
1600
            $texto .= " - " .  $this->dest->getElementsByTagName("xPais")->item(0)->nodeValue;
1601
        }
1602
        $aFont = array('font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B');
1603
        $this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'B', 'L', 0, '');
1604
        //UF
1605
        $x += $w;
1606
        $w = 8;
1607
        $texto = 'UF';
1608
        $aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>'');
1609
        $this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 1, '');
1610
        $texto = $this->dest->getElementsByTagName("UF")->item(0)->nodeValue;
1611
        $aFont = array('font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B');
1612
        $this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'B', 'C', 0, '');
1613
        //FONE / FAX
1614
        $x += $w;
1615
        $w = round(($maxW -$w1-$wx-8)/2, 0);
1616
        $w3 = $w;
1617
        $texto = 'FONE / FAX';
1618
        $aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>'');
1619
        $this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 1, '');
1620
        $texto = ! empty($this->dest->getElementsByTagName("fone")->item(0)->nodeValue) ?
1621
                $this->dest->getElementsByTagName("fone")->item(0)->nodeValue : '';
1622
        $aFont = array('font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B');
1623
        $this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'B', 'C', 0, '');
1624
        //INSCRIÇÃO ESTADUAL
1625
        $x += $w;
1626
        $w = $maxW -$w1-$wx-8-$w3;
1627
        $texto = 'INSCRIÇÃO ESTADUAL';
1628
        $aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>'');
1629
        $this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 1, '');
1630
        $IE = $this->dest->getElementsByTagName("IE");
1631
        $texto = ($IE && $IE->length > 0) ? $IE->item(0)->nodeValue : '';
1632
        $aFont = array('font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B');
1633
        $this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'B', 'C', 0, '');
1634
        //HORA DA SAÍDA
1635
        $x += $w;
1636
        $w = $wx;
1637
        $texto = 'HORA DA SAÍDA/ENTRADA';
1638
        $aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>'');
1639
        $this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 1, '');
1640
        $hSaiEnt = ! empty($this->ide->getElementsByTagName("hSaiEnt")->item(0)->nodeValue) ?
1641
                $this->ide->getElementsByTagName("hSaiEnt")->item(0)->nodeValue : '';
1642
        if ($hSaiEnt == '') {
1643
            $dhSaiEnt = ! empty($this->ide->getElementsByTagName("dhSaiEnt")->item(0)->nodeValue) ?
1644
                    $this->ide->getElementsByTagName("dhSaiEnt")->item(0)->nodeValue : '';
1645
            $tsDhSaiEnt = $this->pConvertTime($dhSaiEnt);
1646
            if ($tsDhSaiEnt != '') {
1647
                $hSaiEnt = date('H:i:s', $tsDhSaiEnt);
1648
            }
1649
        }
1650
        $texto = $hSaiEnt;
1651
        $aFont = array('font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B');
1652
        $this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'B', 'C', 0, '');
1653
        return ($y + $h);
1654
    } //fim da função destinatarioDANFE
1655
1656
     /**
1657
     * pGetTextoFatura
1658
     * Gera a String do Texto da Fatura
1659
      *
1660
     * @name   getTextoFatura
1661
     * @return uma String com o texto ou "";
1662
     */
1663
    protected function pGetTextoFatura()
1664
    {
1665
        if (isset($this->cobr)) {
1666
            $fat = $this->cobr->getElementsByTagName("fat")->item(0);
1667
            if (isset($fat)) {
1668
                if (!empty($this->pSimpleGetValue($this->ide, "indPag"))) {
1669
                    $textoIndPag = "";
1670
                    $indPag = $this->pSimpleGetValue($this->ide, "indPag");
1671
                    if ($indPag === "0") {
1672
                        $textoIndPag = "Pagamento à Vista - ";
1673
                    } elseif ($indPag === "1") {
1674
                        $textoIndPag = "Pagamento à Prazo - ";
1675
                    }
1676
                    $nFat = $this->pSimpleGetValue($fat, "nFat", "Fatura: ");
1677
                    $vOrig = $this->pSimpleGetValue($fat, "vOrig", " Valor Original: ");
1678
                    $vDesc = $this->pSimpleGetValue($fat, "vDesc", " Desconto: ");
1679
                    $vLiq = $this->pSimpleGetValue($fat, "vLiq", " Valor Líquido: ");
1680
                    $texto = $textoIndPag . $nFat . $vOrig . $vDesc . $vLiq;
1681
                    return $texto;
1682
                } else {
1683
                    $pag = $this->dom->getElementsByTagName("pag");
1684
                    if ($tPag = $this->pSimpleGetValue($pag->item(0), "tPag")) {
1685
                        return $this->tipoPag($tPag);
1686
                    }
1687
                }
1688
            }
1689
        }
1690
        return "";
1691
    } //fim getTextoFatura
1692
1693
     /**
1694
     * pSizeExtraTextoFatura
1695
     * Calcula o espaço ocupado pelo texto da fatura. Este espaço só é utilizado quando não houver duplicata.
1696
      *
1697
     * @name   pSizeExtraTextoFatura
1698
     * @return integer
1699
     */
1700
    protected function pSizeExtraTextoFatura()
1701
    {
1702
        $textoFatura = $this->pGetTextoFatura();
1703
        //verificar se existem duplicatas
1704
        if ($this->dup->length == 0 && $textoFatura !== "") {
1705
            return 10;
1706
        }
1707
        return 0;
1708
    }
1709
1710
    /**
1711
     * faturaDANFE
1712
     * Monta o campo de duplicatas da DANFE (retrato e paisagem)
1713
     *
1714
     * @name   faturaDANFE
1715
     * @param  number $x Posição horizontal canto esquerdo
1716
     * @param  number $y Posição vertical canto superior
1717
     * @return number Posição vertical final
1718
     */
1719
    protected function pFaturaDANFE($x, $y)
1720
    {
1721
        $linha = 1;
1722
        $h = 8+3;
1723
        $oldx = $x;
1724
        $textoFatura = $this->pGetTextoFatura();
1725
        //verificar se existem duplicatas
1726
        if ($this->dup->length > 0 || $textoFatura !== "") {
1727
            //#####################################################################
1728
            //FATURA / DUPLICATA
1729
            $texto = "FATURA / DUPLICATA";
1730
            if ($this->orientacao == 'P') {
1731
                $w = $this->wPrint;
1732
            } else {
1733
                $w = 271;
1734
            }
1735
            $h = 8;
1736
            $aFont = array('font'=>$this->fontePadrao, 'size'=>7, 'style'=>'B');
1737
            $this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 0, '');
1738
            $y += 3;
1739
            $dups = "";
1740
            $dupcont = 0;
1741
            $nFat = $this->dup->length;
1742
            if ($textoFatura !== "" && $this->exibirTextoFatura) {
1743
                $myH=6;
1744
                $myW = $this->wPrint;
1745
                if ($this->orientacao == 'L') {
1746
                    $myW -= $this->wCanhoto;
1747
                }
1748
                $aFont = array('font'=>$this->fontePadrao, 'size'=>8, 'style'=>'');
1749
                $this->pTextBox($x, $y, $myW, $myH, $textoFatura, $aFont, 'C', 'L', 1, '');
1750
                $y+=$myH+1;
1751
            }
1752
            if ($this->orientacao == 'P') {
1753
                $w = round($this->wPrint/7.018, 0)-1;
1754
            } else {
1755
                $w = 28;
1756
            }
1757
            $increm = 1;
1758
            foreach ($this->dup as $k => $d) {
1759
                $nDup = ! empty($this->dup->item($k)->getElementsByTagName('nDup')->item(0)->nodeValue) ?
1760
                        $this->dup->item($k)->getElementsByTagName('nDup')->item(0)->nodeValue : '';
1761
                $dDup = ! empty($this->dup->item($k)->getElementsByTagName('dVenc')->item(0)->nodeValue) ?
1762
                        $this->pYmd2dmy($this->dup->item($k)->getElementsByTagName('dVenc')->item(0)->nodeValue) : '';
1763
                $vDup = ! empty($this->dup->item($k)->getElementsByTagName('vDup')->item(0)->nodeValue) ?
1764
                        'R$ ' . number_format(
1765
                            $this->dup->item($k)->getElementsByTagName('vDup')->item(0)->nodeValue,
1766
                            2,
1767
                            ",",
1768
                            "."
1769
                        ) : '';
1770
                $h = 8;
1771
                $texto = '';
1772
                if ($nDup!='0' && $nDup!='') {
1773
                    $aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>'');
1774
                    $this->pTextBox($x, $y, $w, $h, 'Num.', $aFont, 'T', 'L', 1, '');
1775
                    $aFont = array('font'=>$this->fontePadrao, 'size'=>7, 'style'=>'B');
1776
                    $this->pTextBox($x, $y, $w, $h, $nDup, $aFont, 'T', 'R', 0, '');
1777
                } else {
1778
                    $aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>'');
1779
                    $this->pTextBox($x, $y, $w, $h, ($dupcont+1)."", $aFont, 'T', 'L', 1, '');
1780
                }
1781
                $aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>'');
1782
                $this->pTextBox($x, $y, $w, $h, 'Venc.', $aFont, 'C', 'L', 0, '');
1783
                $aFont = array('font'=>$this->fontePadrao, 'size'=>7, 'style'=>'B');
1784
                $this->pTextBox($x, $y, $w, $h, $dDup, $aFont, 'C', 'R', 0, '');
1785
                $aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>'');
1786
                $this->pTextBox($x, $y, $w, $h, 'Valor', $aFont, 'B', 'L', 0, '');
1787
                $aFont = array('font'=>$this->fontePadrao, 'size'=>7, 'style'=>'B');
1788
                $this->pTextBox($x, $y, $w, $h, $vDup, $aFont, 'B', 'R', 0, '');
1789
                $x += $w+$increm;
1790
                $dupcont += 1;
1791
                if ($this->orientacao == 'P') {
1792
                    $maxDupCont = 6;
1793
                } else {
1794
                    $maxDupCont = 8;
1795
                }
1796
                if ($dupcont > $maxDupCont) {
1797
                    $y += 9;
1798
                    $x = $oldx;
1799
                    $dupcont = 0;
1800
                    $linha += 1;
1801
                }
1802
                if ($linha == 5) {
1803
                    $linha = 4;
1804
                    break;
1805
                }
1806
            }
1807
            if ($dupcont == 0) {
1808
                $y -= 9;
1809
                $linha--;
1810
            }
1811
            return ($y+$h);
1812
        } else {
1813
            $linha = 0;
1814
            return ($y-2);
1815
        }
1816
    } //fim da função faturaDANFE
1817
1818
    /**
1819
     * pagamentoDANFE
1820
     * Monta o campo de pagamentos da DANFE (retrato e paisagem) (foi baseada na faturaDANFE)
1821
     *
1822
     * @name   pagamentoDANFE
1823
     * @param  number $x Posição horizontal canto esquerdo
1824
     * @param  number $y Posição vertical canto superior
1825
     * @return number Posição vertical final
1826
     */
1827
    protected function pagamentoDANFE($x, $y)
1828
    {
1829
        $linha = 1;
1830
        $h = 8+3;
1831
        $oldx = $x;
1832
        //verificar se existem cobranças definidas
1833
        if (isset($this->detPag) && $this->detPag->length > 0) {
1834
            //#####################################################################
1835
            //Tipo de pagamento
1836
            $texto = "PAGAMENTO";
1837
            if ($this->orientacao == 'P') {
1838
                $w = $this->wPrint;
1839
            } else {
1840
                $w = 271;
1841
            }
1842
            $h = 8;
1843
            $aFont = array('font'=>$this->fontePadrao, 'size'=>7, 'style'=>'B');
1844
            $this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 0, '');
1845
            $y += 3;
1846
            $dups = "";
1847
            $dupcont = 0;
1848
            if ($this->orientacao == 'P') {
1849
                $w = round($this->wPrint/7.018, 0)-1;
1850
            } else {
1851
                $w = 28;
1852
            }
1853
            if ($this->orientacao == 'P') {
1854
                $maxDupCont = 6;
1855
            } else {
1856
                $maxDupCont = 8;
1857
            }
1858
            $increm = 1;
1859
            $formaPagamento = array('01'=>'Dinheiro','02'=>'Cheque','03'=>'Cartão de Crédito',
1860
                                    '04'=>'Cartão de Débito','05'=>'Crédito Loja','10'=>'Vale Alimentação',
1861
                                    '11'=>'Vale Refeição','12'=>'Vale Presente','13'=>'Vale Combustível',
1862
                                    '14'=>'Duplicata Mercantil','15'=>'Boleto','90'=>'Sem pagamento','99'=>'Outros');
1863
            $bandeira = array('01'=>'Visa','02'=>'Mastercard','03'=>'American','04'=>'Sorocred','05'=>'Diners',
1864
                              '06'=>'Elo','07'=>'Hipercard','08'=>'Aura','09'=>'Cabal','99'=>'Outros');
1865
            foreach ($this->detPag as $k => $d) {
1866
                $fPag = !empty($this->detPag->item($k)->getElementsByTagName('tPag')->item(0)->nodeValue)
1867
                    ? $this->detPag->item($k)->getElementsByTagName('tPag')->item(0)->nodeValue : '0';
1868
                $vPag = ! empty($this->detPag->item($k)->getElementsByTagName('vPag')->item(0)->nodeValue)
1869
                    ? 'R$ ' . number_format(
1870
                        $this->detPag->item($k)->getElementsByTagName('vPag')->item(0)->nodeValue,
1871
                        2,
1872
                        ",",
1873
                        "."
1874
                    ) : '';
1875
                $h = 6;
1876
                $texto = '';
1877
                if (isset($formaPagamento[$fPag])) {
1878
                    /*Exibir Item sem pagamento ou outros?*/
1879
                    if ($fPag=='90' || $fPag=='99') {
1880
                        continue;
1881
                    }
1882
                    $aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>'');
1883
                    $this->pTextBox($x, $y, $w, $h, 'Forma', $aFont, 'T', 'L', 1, '');
1884
                    $aFont = array('font'=>$this->fontePadrao, 'size'=>7, 'style'=>'B');
1885
                    $this->pTextBox($x, $y, $w, $h, $formaPagamento[$fPag], $aFont, 'T', 'R', 0, '');
1886
                } else {
1887
                    $aFont = array('font'=>$this->fontePadrao, 'size'=>7, 'style'=>'');
1888
                    $this->pTextBox($x, $y, $w, $h, "Forma ".$fPag." não encontrado", $aFont, 'T', 'L', 1, '');
1889
                }
1890
                $aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>'');
1891
                $this->pTextBox($x, $y, $w, $h, 'Valor', $aFont, 'B', 'L', 0, '');
1892
                $aFont = array('font'=>$this->fontePadrao, 'size'=>7, 'style'=>'B');
1893
                $this->pTextBox($x, $y, $w, $h, $vPag, $aFont, 'B', 'R', 0, '');
1894
                $x += $w+$increm;
1895
                $dupcont += 1;
1896
1897
                if ($dupcont>$maxDupCont) {
1898
                    $y += 9;
1899
                    $x = $oldx;
1900
                    $dupcont = 0;
1901
                    $linha += 1;
1902
                }
1903
                if ($linha == 5) {
1904
                    $linha = 4;
1905
                    break;
1906
                }
1907
            }
1908
            if ($dupcont == 0) {
1909
                $y -= 9;
1910
                $linha--;
1911
            }
1912
            return ($y+$h);
1913
        } else {
1914
            $linha = 0;
1915
            return ($y-2);
1916
        }
1917
    } //fim da função pagamentoDANFE
1918
    
1919
    /**
1920
     * impostoDanfeHelper
1921
     * Auxilia a montagem dos campos de impostos e totais da DANFE
1922
     *
1923
     * @name   impostoDanfeHelper
1924
     * @param  float $x Posição horizontal canto esquerdo
1925
     * @param  float $y Posição vertical canto superior
1926
     * @param  float $w Largura do campo
1927
     * @param  float $h Altura do campo
1928
     * @param  float $h Título do campo
1929
     * @param  float $h Valor do imposto
1930
     * @return float Sugestão do $x do próximo imposto
1931
     */
1932
    protected function pImpostoDanfeHelper($x, $y, $w, $h, $titulo, $campoImposto)
1933
    {
1934
        $valorImposto = '0, 00';
1935
        $the_field = $this->ICMSTot->getElementsByTagName($campoImposto)->item(0);
1936
        if (isset($the_field)) {
1937
            $the_value = $the_field->nodeValue;
1938
            if (!empty($the_value)) {
1939
                $valorImposto = number_format($the_value, 2, ",", ".");
1940
            }
1941
        }
1942
1943
        $fontTitulo = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>'');
1944
        $fontValor = array('font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B');
1945
        $this->pTextBox($x, $y, $w, $h, $titulo, $fontTitulo, 'T', 'L', 1, '');
1946
        $this->pTextBox($x, $y, $w, $h, $valorImposto, $fontValor, 'B', 'R', 0, '');
1947
1948
        $next_x = $x + $w;
1949
        return $next_x;
1950
    }
1951
1952
    /**
1953
     * impostoDANFE
1954
     * Monta o campo de impostos e totais da DANFE (retrato e paisagem)
1955
     *
1956
     * @param  number $x Posição horizontal canto esquerdo
1957
     * @param  number $y Posição vertical canto superior
1958
     * @return number Posição vertical final
1959
     */
1960
    protected function pImpostoDANFE($x, $y)
1961
    {
1962
        $x_inicial = $x;
1963
        //#####################################################################
1964
1965
1966
        $campos_por_linha = 9;
1967
        if (!$this->exibirPIS) {
1968
            $campos_por_linha--;
1969
        }
1970
        if (!$this->exibirIcmsInterestadual) {
1971
            $campos_por_linha -= 2;
1972
        }
1973
1974
        if ($this->orientacao == 'P') {
1975
            $maxW = $this->wPrint;
1976
            $title_size = 31;
1977
        } else {
1978
            $maxW = $this->wPrint - $this->wCanhoto;
1979
            $title_size = 40;
1980
        }
1981
        $w = $maxW / $campos_por_linha;
1982
1983
        $aFont = array('font'=>$this->fontePadrao, 'size'=>7, 'style'=>'B');
1984
        $texto = "CÁLCULO DO IMPOSTO";
1985
        $this->pTextBox($x, $y, $title_size, 8, $texto, $aFont, 'T', 'L', 0, '');
1986
        $y += 3;
1987
        $h = 7;
1988
1989
        $x = $this->pImpostoDanfeHelper($x, $y, $w, $h, "BASE DE CÁLC. DO ICMS", "vBC");
1990
        $x = $this->pImpostoDanfeHelper($x, $y, $w, $h, "VALOR DO ICMS", "vICMS");
1991
        $x = $this->pImpostoDanfeHelper($x, $y, $w, $h, "BASE DE CÁLC. ICMS S.T.", "vBCST");
1992
        $x = $this->pImpostoDanfeHelper($x, $y, $w, $h, "VALOR DO ICMS SUBST.", "vST");
1993
        $x = $this->pImpostoDanfeHelper($x, $y, $w, $h, "V. IMP. IMPORTAÇÃO", "vII");
1994
1995
        if ($this->exibirIcmsInterestadual) {
1996
            $x = $this->pImpostoDanfeHelper($x, $y, $w, $h, "V. ICMS UF REMET.", "vICMSUFRemet");
1997
            $x = $this->pImpostoDanfeHelper($x, $y, $w, $h, "V. FCP UF DEST.", "vFCPUFDest");
1998
        }
1999
2000
        if ($this->exibirPIS) {
2001
            $x = $this->pImpostoDanfeHelper($x, $y, $w, $h, "VALOR DO PIS", "vPIS");
2002
        }
2003
2004
        $x = $this->pImpostoDanfeHelper($x, $y, $w, $h, "V. TOTAL PRODUTOS", "vProd");
2005
2006
        //
2007
2008
        $y += $h;
2009
        $x = $x_inicial;
2010
2011
        $x = $this->pImpostoDanfeHelper($x, $y, $w, $h, "VALOR DO FRETE", "vFrete");
2012
        $x = $this->pImpostoDanfeHelper($x, $y, $w, $h, "VALOR DO SEGURO", "vSeg");
2013
        $x = $this->pImpostoDanfeHelper($x, $y, $w, $h, "DESCONTO", "vDesc");
2014
        $x = $this->pImpostoDanfeHelper($x, $y, $w, $h, "OUTRAS DESPESAS", "vOutro");
2015
        $x = $this->pImpostoDanfeHelper($x, $y, $w, $h, "VALOR TOTAL IPI", "vIPI");
2016
2017
        if ($this->exibirIcmsInterestadual) {
2018
            $x = $this->pImpostoDanfeHelper($x, $y, $w, $h, "V. ICMS UF DEST.", "vICMSUFDest");
2019
            $x = $this->pImpostoDanfeHelper($x, $y, $w, $h, "V. TOT. TRIB.", "vTotTrib");
2020
        }
2021
2022
        if ($this->exibirPIS) {
2023
            $x = $this->pImpostoDanfeHelper($x, $y, $w, $h, "VALOR DA COFINS", "vCOFINS");
2024
        }
2025
        $x = $this->pImpostoDanfeHelper($x, $y, $w, $h, "V. TOTAL DA NOTA", "vNF");
2026
2027
        return ($y+$h);
2028
    } //fim impostoDANFE
2029
2030
    /**
2031
     * transporteDANFE
2032
     * Monta o campo de transportes da DANFE (retrato e paisagem)
2033
     *
2034
     * @name   transporteDANFE
2035
     * @param  float $x Posição horizontal canto esquerdo
2036
     * @param  float $y Posição vertical canto superior
2037
     * @return float Posição vertical final
2038
     */
2039
    protected function pTransporteDANFE($x, $y)
2040
    {
2041
        $oldX = $x;
2042
        if ($this->orientacao == 'P') {
2043
            $maxW = $this->wPrint;
2044
        } else {
2045
            $maxW = $this->wPrint - $this->wCanhoto;
2046
        }
2047
        //#####################################################################
2048
        //TRANSPORTADOR / VOLUMES TRANSPORTADOS
2049
        $texto = "TRANSPORTADOR / VOLUMES TRANSPORTADOS";
2050
        $w = $maxW;
2051
        $h = 7;
2052
        $aFont = array('font'=>$this->fontePadrao, 'size'=>7, 'style'=>'B');
2053
        $this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 0, '');
2054
        //NOME / RAZÃO SOCIAL
2055
        $w1 = $maxW*0.29;
2056
        $y += 3;
2057
        $texto = 'NOME / RAZÃO SOCIAL';
2058
        $aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>'');
2059
        $this->pTextBox($x, $y, $w1, $h, $texto, $aFont, 'T', 'L', 1, '');
2060
        if (isset($this->transporta)) {
2061
            $texto = ! empty($this->transporta->getElementsByTagName("xNome")->item(0)->nodeValue) ?
2062
                    $this->transporta->getElementsByTagName("xNome")->item(0)->nodeValue : '';
2063
        } else {
2064
            $texto = '';
2065
        }
2066
        $aFont = array('font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B');
2067
        $this->pTextBox($x, $y, $w1, $h, $texto, $aFont, 'B', 'L', 0, '');
2068
        //FRETE POR CONTA
2069
        $x += $w1;
2070
        $w2 = $maxW*0.15;
2071
        $texto = 'FRETE';
2072
        $aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>'');
2073
        $this->pTextBox($x, $y, $w2, $h, $texto, $aFont, 'T', 'L', 1, '');
2074
        $tipoFrete = ! empty($this->transp->getElementsByTagName("modFrete")->item(0)->nodeValue) ?
2075
                $this->transp->getElementsByTagName("modFrete")->item(0)->nodeValue : '0';
2076
        switch ($tipoFrete) {
2077
            case 0:
2078
                $texto = "0-Por conta do Rem";
2079
                break;
2080
            case 1:
2081
                $texto = "1-Por conta do Dest";
2082
                break;
2083
            case 2:
2084
                $texto = "2-Por conta de Terceiros";
2085
                break;
2086
            case 3:
2087
                $texto = "3-Próprio por conta do Rem";
2088
                break;
2089
            case 4:
2090
                $texto = "4-Próprio por conta do Dest";
2091
                break;
2092
            case 9:
2093
                $texto = "9-Sem Transporte";
2094
                break;
2095
        }
2096
        $aFont = array('font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B');
2097
        $this->pTextBox($x, $y, $w2, $h, $texto, $aFont, 'C', 'C', 1, '');
2098
        //CÓDIGO ANTT
2099
        $x += $w2;
2100
        $texto = 'CÓDIGO ANTT';
2101
        $aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>'');
2102
        $this->pTextBox($x, $y, $w2, $h, $texto, $aFont, 'T', 'L', 1, '');
2103
        if (isset($this->veicTransp)) {
2104
            $texto = ! empty($this->veicTransp->getElementsByTagName("RNTC")->item(0)->nodeValue) ?
2105
                    $this->veicTransp->getElementsByTagName("RNTC")->item(0)->nodeValue : '';
2106
        } else {
2107
            $texto = '';
2108
        }
2109
        $aFont = array('font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B');
2110
        $this->pTextBox($x, $y, $w2, $h, $texto, $aFont, 'B', 'C', 0, '');
2111
        //PLACA DO VEÍC
2112
        $x += $w2;
2113
        $texto = 'PLACA DO VEÍCULO';
2114
        $aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>'');
2115
        $this->pTextBox($x, $y, $w2, $h, $texto, $aFont, 'T', 'L', 1, '');
2116
        if (isset($this->veicTransp)) {
2117
            $texto = ! empty($this->veicTransp->getElementsByTagName("placa")->item(0)->nodeValue) ?
2118
                    $this->veicTransp->getElementsByTagName("placa")->item(0)->nodeValue : '';
2119
        } elseif (isset($this->reboque)) {
2120
            $texto = ! empty($this->reboque->getElementsByTagName("placa")->item(0)->nodeValue) ?
2121
                    $this->reboque->getElementsByTagName("placa")->item(0)->nodeValue : '';
2122
        } else {
2123
            $texto = '';
2124
        }
2125
        $aFont = array('font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B');
2126
        $this->pTextBox($x, $y, $w2, $h, $texto, $aFont, 'B', 'C', 0, '');
2127
        //UF
2128
        $x += $w2;
2129
        $w3 = round($maxW*0.04, 0);
2130
        $texto = 'UF';
2131
        $aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>'');
2132
        $this->pTextBox($x, $y, $w3, $h, $texto, $aFont, 'T', 'L', 1, '');
2133
        if (isset($this->veicTransp)) {
2134
            $texto = ! empty($this->veicTransp->getElementsByTagName("UF")->item(0)->nodeValue) ?
2135
                    $this->veicTransp->getElementsByTagName("UF")->item(0)->nodeValue : '';
2136
        } elseif (isset($this->reboque)) {
2137
            $texto = ! empty($this->reboque->getElementsByTagName("UF")->item(0)->nodeValue) ?
2138
                    $this->reboque->getElementsByTagName("UF")->item(0)->nodeValue : '';
2139
        } else {
2140
            $texto = '';
2141
        }
2142
        $aFont = array('font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B');
2143
        $this->pTextBox($x, $y, $w3, $h, $texto, $aFont, 'B', 'C', 0, '');
2144
        //CNPJ / CPF
2145
        $x += $w3;
2146
        $w = $maxW-($w1+3*$w2+$w3);
2147
        $texto = 'CNPJ / CPF';
2148
        $aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>'');
2149
        $this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 1, '');
2150
        if (isset($this->transporta)) {
2151
            $texto = ! empty($this->transporta->getElementsByTagName("CNPJ")->item(0)->nodeValue) ?
2152
                    $this->pFormat(
2153
                        $this->transporta->getElementsByTagName("CNPJ")->item(0)->nodeValue,
2154
                        "##.###.###/####-##"
2155
                    ) : '';
2156
            if ($texto == '') {
2157
                $texto = ! empty($this->transporta->getElementsByTagName("CPF")->item(0)->nodeValue) ?
2158
                        $this->pFormat(
2159
                            $this->transporta->getElementsByTagName("CPF")->item(0)->nodeValue,
2160
                            "###.###.###-##"
2161
                        ) : '';
2162
            }
2163
        } else {
2164
            $texto = '';
2165
        }
2166
        $aFont = array('font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B');
2167
        $this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'B', 'C', 0, '');
2168
        //#####################################################################
2169
        //ENDEREÇO
2170
        $y += $h;
2171
        $x = $oldX;
2172
        $h = 7;
2173
        $w1 = $maxW*0.44;
2174
        $texto = 'ENDEREÇO';
2175
        $aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>'');
2176
        $this->pTextBox($x, $y, $w1, $h, $texto, $aFont, 'T', 'L', 1, '');
2177
        if (isset($this->transporta)) {
2178
            $texto = ! empty($this->transporta->getElementsByTagName("xEnder")->item(0)->nodeValue) ?
2179
                    $this->transporta->getElementsByTagName("xEnder")->item(0)->nodeValue : '';
2180
        } else {
2181
            $texto = '';
2182
        }
2183
        $aFont = array('font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B');
2184
        $this->pTextBox($x, $y, $w1, $h, $texto, $aFont, 'B', 'L', 0, '');
2185
        //MUNICÍPIO
2186
        $x += $w1;
2187
        $w2 = round($maxW*0.30, 0);
2188
        $texto = 'MUNICÍPIO';
2189
        $aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>'');
2190
        $this->pTextBox($x, $y, $w2, $h, $texto, $aFont, 'T', 'L', 1, '');
2191
        if (isset($this->transporta)) {
2192
            $texto = ! empty($this->transporta->getElementsByTagName("xMun")->item(0)->nodeValue) ?
2193
                    $this->transporta->getElementsByTagName("xMun")->item(0)->nodeValue : '';
2194
        } else {
2195
            $texto = '';
2196
        }
2197
        $aFont = array('font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B');
2198
        $this->pTextBox($x, $y, $w2, $h, $texto, $aFont, 'B', 'C', 0, '');
2199
        //UF
2200
        $x += $w2;
2201
        $w3 = round($maxW*0.04, 0);
2202
        $texto = 'UF';
2203
        $aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>'');
2204
        $this->pTextBox($x, $y, $w3, $h, $texto, $aFont, 'T', 'L', 1, '');
2205
        if (isset($this->transporta)) {
2206
            $texto = ! empty($this->transporta->getElementsByTagName("UF")->item(0)->nodeValue) ?
2207
                    $this->transporta->getElementsByTagName("UF")->item(0)->nodeValue : '';
2208
        } else {
2209
            $texto = '';
2210
        }
2211
        $aFont = array('font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B');
2212
        $this->pTextBox($x, $y, $w3, $h, $texto, $aFont, 'B', 'C', 0, '');
2213
        //INSCRIÇÃO ESTADUAL
2214
        $x += $w3;
2215
        $w = $maxW-($w1+$w2+$w3);
2216
        $texto = 'INSCRIÇÃO ESTADUAL';
2217
        $aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>'');
2218
        $this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 1, '');
2219
        $texto = '';
2220
        if (isset($this->transporta)) {
2221
            if (! empty($this->transporta->getElementsByTagName("IE")->item(0)->nodeValue)) {
2222
                $texto = $this->transporta->getElementsByTagName("IE")->item(0)->nodeValue;
2223
            }
2224
        }
2225
        $aFont = array('font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B');
2226
        $this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'B', 'C', 0, '');
2227
        //Tratar Multiplos volumes
2228
        $volumes = $this->transp->getElementsByTagName('vol');
2229
        $quantidade = 0;
2230
        $especie = '';
2231
        $marca = '';
2232
        $numero = '';
2233
        $texto = '';
2234
        $pesoBruto=0;
2235
        $pesoLiquido=0;
2236
        foreach ($volumes as $volume) {
2237
            $quantidade += ! empty($volume->getElementsByTagName("qVol")->item(0)->nodeValue) ?
2238
                    $volume->getElementsByTagName("qVol")->item(0)->nodeValue : 0;
2239
            $pesoBruto += ! empty($volume->getElementsByTagName("pesoB")->item(0)->nodeValue) ?
2240
                    $volume->getElementsByTagName("pesoB")->item(0)->nodeValue : 0;
2241
            $pesoLiquido += ! empty($volume->getElementsByTagName("pesoL")->item(0)->nodeValue) ?
2242
                    $volume->getElementsByTagName("pesoL")->item(0)->nodeValue : 0;
2243
            $texto = ! empty($this->transp->getElementsByTagName("esp")->item(0)->nodeValue) ?
2244
                    $this->transp->getElementsByTagName("esp")->item(0)->nodeValue : '';
2245
            if ($texto != $especie && $especie != '') {
2246
                //tem várias especies
2247
                $especie = 'VARIAS';
2248
            } else {
2249
                $especie = $texto;
2250
            }
2251
            $texto = ! empty($this->transp->getElementsByTagName("marca")->item(0)->nodeValue) ?
2252
                    $this->transp->getElementsByTagName("marca")->item(0)->nodeValue : '';
2253
            if ($texto != $marca && $marca != '') {
2254
                //tem várias especies
2255
                $marca = 'VARIAS';
2256
            } else {
2257
                $marca = $texto;
2258
            }
2259
            $texto = ! empty($this->transp->getElementsByTagName("nVol")->item(0)->nodeValue) ?
2260
                    $this->transp->getElementsByTagName("nVol")->item(0)->nodeValue : '';
2261
            if ($texto != $numero && $numero != '') {
2262
                //tem várias especies
2263
                $numero = 'VARIOS';
2264
            } else {
2265
                $numero = $texto;
2266
            }
2267
        }
2268
2269
        //#####################################################################
2270
        //QUANTIDADE
2271
        $y += $h;
2272
        $x = $oldX;
2273
        $h = 7;
2274
        $w1 = round($maxW*0.10, 0);
2275
        $texto = 'QUANTIDADE';
2276
        $aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>'');
2277
        $this->pTextBox($x, $y, $w1, $h, $texto, $aFont, 'T', 'L', 1, '');
2278
        if (!empty($quantidade)) {
2279
            $texto = $quantidade;
2280
            $aFont = array('font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B');
2281
            $this->pTextBox($x, $y, $w1, $h, $texto, $aFont, 'B', 'C', 0, '');
2282
        }
2283
        //ESPÉCIE
2284
        $x += $w1;
2285
        $w2 = round($maxW*0.17, 0);
2286
        $texto = 'ESPÉCIE';
2287
        $aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>'');
2288
        $this->pTextBox($x, $y, $w2, $h, $texto, $aFont, 'T', 'L', 1, '');
2289
        $texto = $especie;
2290
        $aFont = array('font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B');
2291
        $this->pTextBox($x, $y, $w2, $h, $texto, $aFont, 'B', 'C', 0, '');
2292
        //MARCA
2293
        $x += $w2;
2294
        $texto = 'MARCA';
2295
        $aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>'');
2296
        $this->pTextBox($x, $y, $w2, $h, $texto, $aFont, 'T', 'L', 1, '');
2297
        $texto = ! empty($this->transp->getElementsByTagName("marca")->item(0)->nodeValue) ?
2298
                $this->transp->getElementsByTagName("marca")->item(0)->nodeValue : '';
2299
        $aFont = array('font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B');
2300
        $this->pTextBox($x, $y, $w2, $h, $texto, $aFont, 'B', 'C', 0, '');
2301
        //NUMERAÇÃO
2302
        $x += $w2;
2303
        $texto = 'NUMERAÇÃO';
2304
        $aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>'');
2305
        $this->pTextBox($x, $y, $w2, $h, $texto, $aFont, 'T', 'L', 1, '');
2306
        $texto = $numero;
2307
        $aFont = array('font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B');
2308
        $this->pTextBox($x, $y, $w2, $h, $texto, $aFont, 'B', 'C', 0, '');
2309
        //PESO BRUTO
2310
        $x += $w2;
2311
        $w3 = round($maxW*0.20, 0);
2312
        $texto = 'PESO BRUTO';
2313
        $aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>'');
2314
        $this->pTextBox($x, $y, $w3, $h, $texto, $aFont, 'T', 'L', 1, '');
2315
        if (is_numeric($pesoBruto) && $pesoBruto > 0) {
2316
            $texto = number_format($pesoBruto, 3, ",", ".");
2317
        } else {
2318
            $texto = '';
2319
        }
2320
        $aFont = array('font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B');
2321
        $this->pTextBox($x, $y, $w3, $h, $texto, $aFont, 'B', 'R', 0, '');
2322
        //PESO LÍQUIDO
2323
        $x += $w3;
2324
        $w = $maxW -($w1+3*$w2+$w3);
2325
        $texto = 'PESO LÍQUIDO';
2326
        $aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>'');
2327
        $this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 1, '');
2328
        if (is_numeric($pesoLiquido) && $pesoLiquido > 0) {
2329
            $texto = number_format($pesoLiquido, 3, ",", ".");
2330
        } else {
2331
            $texto = '';
2332
        }
2333
        $aFont = array('font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B');
2334
        $this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'B', 'R', 0, '');
2335
        return ($y+$h);
2336
    } //fim transporteDANFE
2337
2338
2339
2340
    protected function pDescricaoProdutoHelper($origem, $campo, $formato)
2341
    {
2342
        $valor_original = $origem->getElementsByTagName($campo)->item(0);
2343
        if (!isset($valor_original)) {
2344
            return "";
2345
        }
2346
        $valor_original = $valor_original->nodeValue;
2347
        $valor = ! empty($valor_original) ? number_format($valor_original, 2, ",", ".") : '';
2348
2349
        if ($valor != "") {
2350
            return sprintf($formato, $valor);
2351
        }
2352
        return "";
2353
    }
2354
2355
    /**
2356
     * descricaoProduto
2357
     * Monta a string de descrição de cada Produto
2358
     *
2359
     * @name   descricaoProduto
2360
     * @param  DOMNode itemProd
2361
     * @return string descricao do produto
2362
     */
2363
    protected function pDescricaoProduto($itemProd)
2364
    {
2365
        $prod = $itemProd->getElementsByTagName('prod')->item(0);
2366
        $ICMS = $itemProd->getElementsByTagName("ICMS")->item(0);
2367
        $ICMSUFDest = $itemProd->getElementsByTagName("ICMSUFDest")->item(0);
2368
        $impostos = '';
2369
2370
        if (!empty($ICMS)) {
2371
            $impostos .= $this->pDescricaoProdutoHelper($ICMS, "vBCFCP", " BcFcp=%s");
2372
            $impostos .= $this->pDescricaoProdutoHelper($ICMS, "pFCP", " pFcp=%s%%");
2373
            $impostos .= $this->pDescricaoProdutoHelper($ICMS, "vFCP", " vFcp=%s");
2374
            $impostos .= $this->pDescricaoProdutoHelper($ICMS, "pRedBC", " pRedBC=%s%%");
2375
            $impostos .= $this->pDescricaoProdutoHelper($ICMS, "pMVAST", " IVA/MVA=%s%%");
2376
            $impostos .= $this->pDescricaoProdutoHelper($ICMS, "pICMSST", " pIcmsSt=%s%%");
2377
            $impostos .= $this->pDescricaoProdutoHelper($ICMS, "vBCST", " BcIcmsSt=%s");
2378
            $impostos .= $this->pDescricaoProdutoHelper($ICMS, "vICMSST", " vIcmsSt=%s");
2379
            $impostos .= $this->pDescricaoProdutoHelper($ICMS, "vBCFCPST", " BcFcpSt=%s");
2380
            $impostos .= $this->pDescricaoProdutoHelper($ICMS, "pFCPST", " pFcpSt=%s%%");
2381
            $impostos .= $this->pDescricaoProdutoHelper($ICMS, "vFCPST", " vFcpSt=%s");
2382
        }
2383
        if (!empty($ICMSUFDest)) {
2384
            $impostos .= $this->pDescricaoProdutoHelper($ICMSUFDest, "pFCPUFDest", " pFCPUFDest=%s%%");
2385
            $impostos .= $this->pDescricaoProdutoHelper($ICMSUFDest, "pICMSUFDest", " pICMSUFDest=%s%%");
2386
            $impostos .= $this->pDescricaoProdutoHelper($ICMSUFDest, "pICMSInterPart", " pICMSInterPart=%s%%");
2387
            $impostos .= $this->pDescricaoProdutoHelper($ICMSUFDest, "vFCPUFDest", " vFCPUFDest=%s");
2388
            $impostos .= $this->pDescricaoProdutoHelper($ICMSUFDest, "vICMSUFDest", " vICMSUFDest=%s");
2389
            $impostos .= $this->pDescricaoProdutoHelper($ICMSUFDest, "vICMSUFRemet", " vICMSUFRemet=%s");
2390
        }
2391
        $infAdProd = ! empty($itemProd->getElementsByTagName('infAdProd')->item(0)->nodeValue) ?
2392
                substr($this->pAnfavea($itemProd->getElementsByTagName('infAdProd')->item(0)->nodeValue), 0, 500) : '';
2393
        if (! empty($infAdProd)) {
2394
            $infAdProd = trim($infAdProd);
2395
            $infAdProd .= ' ';
2396
        }
2397
        $loteTxt ='';
2398
        $rastro = $prod->getElementsByTagName("med");
2399
        if (!isset($rastro)) {
2400
            $rastro = $prod->getElementsByTagName("rastro");
2401
        }
2402
        if (isset($rastro)) {
2403
            $i = 0;
2404
            while ($i < $rastro->length) {
2405
                $loteTxt .= $this->pSimpleGetValue($rastro->item($i), 'nLote', ' Lote: ');
2406
                $loteTxt .= $this->pSimpleGetValue($rastro->item($i), 'qLote', ' Quant: ');
2407
                $loteTxt .= $this->pSimpleGetDate($rastro->item($i), 'dFab', ' Fab: ');
2408
                $loteTxt .= $this->pSimpleGetDate($rastro->item($i), 'dVal', ' Val: ');
2409
                $loteTxt .= $this->pSimpleGetValue($rastro->item($i), 'vPMC', ' PMC: ');
2410
                $i++;
2411
            }
2412
            if ($loteTxt != '') {
2413
                $loteTxt.= ' ';
2414
            }
2415
        }
2416
        //NT2013.006 FCI
2417
        $nFCI = (! empty($itemProd->getElementsByTagName('nFCI')->item(0)->nodeValue)) ?
2418
                ' FCI:'.$itemProd->getElementsByTagName('nFCI')->item(0)->nodeValue : '';
2419
        $tmp_ad=$infAdProd . ($this->descProdInfoComplemento ? $loteTxt . $impostos . $nFCI : '');
2420
        $texto = $prod->getElementsByTagName("xProd")->item(0)->nodeValue . (strlen($tmp_ad)!=0?"\n    ".$tmp_ad:'');
2421
        if ($this->descProdQuebraLinha) {
2422
            $texto = str_replace(";", "\n", $texto);
2423
        }
2424
        return $texto;
2425
    }
2426
2427
    /**
2428
     * itensDANFE
2429
     * Monta o campo de itens da DANFE (retrato e paisagem)
2430
     *
2431
     * @name   itensDANFE
2432
     * @param  float $x       Posição horizontal canto esquerdo
2433
     * @param  float $y       Posição vertical canto superior
2434
     * @param  float $nInicio Número do item inicial
2435
     * @param  float $max     Número do item final
2436
     * @param  float $hmax    Altura máxima do campo de itens em mm
2437
     * @return float Posição vertical final
2438
     */
2439
    protected function pItensDANFE($x, $y, &$nInicio, $hmax, $pag = 0, $totpag = 0, $hCabecItens = 7)
2440
    {
2441
        $oldX = $x;
2442
        $oldY = $y;
2443
        $totItens = $this->det->length;
2444
        //#####################################################################
2445
        //DADOS DOS PRODUTOS / SERVIÇOS
2446
        $texto = "DADOS DOS PRODUTOS / SERVIÇOS ";
2447
        if ($this->orientacao == 'P') {
2448
            $w = $this->wPrint;
2449
        } else {
2450
            if ($nInicio < 2) { // primeira página
2451
                $w = $this->wPrint - $this->wCanhoto;
2452
            } else { // páginas seguintes
2453
                $w = $this->wPrint;
2454
            }
2455
        }
2456
        $h = 4;
2457
        $aFont = array('font'=>$this->fontePadrao, 'size'=>7, 'style'=>'B');
2458
        $this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 0, '');
2459
        $y += 3;
2460
        //desenha a caixa dos dados dos itens da NF
2461
        $hmax += 1;
2462
        $texto = '';
2463
        $this->pTextBox($x, $y, $w, $hmax);
2464
        //##################################################################################
2465
        // cabecalho LOOP COM OS DADOS DOS PRODUTOS
2466
        //CÓDIGO PRODUTO
2467
        $texto = "CÓDIGO PRODUTO";
2468
        $w1 = round($w*0.09, 0);
2469
        $h = 4;
2470
        $aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>'');
2471
        $this->pTextBox($x, $y, $w1, $h, $texto, $aFont, 'C', 'C', 0, '', false);
2472
        $this->pdf->Line($x+$w1, $y, $x+$w1, $y+$hmax);
2473
        //DESCRIÇÃO DO PRODUTO / SERVIÇO
2474
        $x += $w1;
2475
        $w2 = round($w*0.28, 0);
2476
        $texto = 'DESCRIÇÃO DO PRODUTO / SERVIÇO';
2477
        $aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>'');
2478
        $this->pTextBox($x, $y, $w2, $h, $texto, $aFont, 'C', 'C', 0, '', false);
2479
        $this->pdf->Line($x+$w2, $y, $x+$w2, $y+$hmax);
2480
        //NCM/SH
2481
        $x += $w2;
2482
        $w3 = round($w*0.06, 0);
2483
        $texto = 'NCM/SH';
2484
        $aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>'');
2485
        $this->pTextBox($x, $y, $w3, $h, $texto, $aFont, 'C', 'C', 0, '', false);
2486
        $this->pdf->Line($x+$w3, $y, $x+$w3, $y+$hmax);
2487
        //O/CST ou O/CSOSN
2488
        $x += $w3;
2489
        $w4 = round($w*0.05, 0);
2490
        $texto = 'O/CSOSN';//Regime do Simples CRT = 1 ou CRT = 2
2491
        if ($this->pSimpleGetValue($this->emit, 'CRT') == '3') {
2492
             $texto = 'O/CST';//Regime Normal
2493
        }
2494
        $aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>'');
2495
        $this->pTextBox($x, $y, $w4, $h, $texto, $aFont, 'C', 'C', 0, '', false);
2496
        $this->pdf->Line($x+$w4, $y, $x+$w4, $y+$hmax);
2497
        //CFOP
2498
        $x += $w4;
2499
        $w5 = round($w*0.04, 0);
2500
        $texto = 'CFOP';
2501
        $aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>'');
2502
        $this->pTextBox($x, $y, $w5, $h, $texto, $aFont, 'C', 'C', 0, '', false);
2503
        $this->pdf->Line($x+$w5, $y, $x+$w5, $y+$hmax);
2504
        //UN
2505
        $x += $w5;
2506
        $w6 = round($w*0.03, 0);
2507
        $texto = 'UN';
2508
        $aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>'');
2509
        $this->pTextBox($x, $y, $w6, $h, $texto, $aFont, 'C', 'C', 0, '', false);
2510
        $this->pdf->Line($x+$w6, $y, $x+$w6, $y+$hmax);
2511
        //QUANT
2512
        $x += $w6;
2513
        $w7 = round($w*0.07, 0);
2514
        $texto = 'QUANT';
2515
        $aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>'');
2516
        $this->pTextBox($x, $y, $w7, $h, $texto, $aFont, 'C', 'C', 0, '', false);
2517
        $this->pdf->Line($x+$w7, $y, $x+$w7, $y+$hmax);
2518
        //VALOR UNIT
2519
        $x += $w7;
2520
        $w8 = round($w*0.06, 0);
2521
        $texto = 'VALOR UNIT';
2522
        $aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>'');
2523
        $this->pTextBox($x, $y, $w8, $h, $texto, $aFont, 'C', 'C', 0, '', false);
2524
        $this->pdf->Line($x+$w8, $y, $x+$w8, $y+$hmax);
2525
        //VALOR TOTAL
2526
        $x += $w8;
2527
        $w9 = round($w*0.06, 0);
2528
        $texto = 'VALOR TOTAL';
2529
        $aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>'');
2530
        $this->pTextBox($x, $y, $w9, $h, $texto, $aFont, 'C', 'C', 0, '', false);
2531
        $this->pdf->Line($x+$w9, $y, $x+$w9, $y+$hmax);
2532
        //B.CÁLC ICMS
2533
        $x += $w9;
2534
        $w10 = round($w*0.06, 0);
2535
        $texto = 'B.CÁLC ICMS';
2536
        $aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>'');
2537
        $this->pTextBox($x, $y, $w10, $h, $texto, $aFont, 'C', 'C', 0, '', false);
2538
        $this->pdf->Line($x+$w10, $y, $x+$w10, $y+$hmax);
2539
        //VALOR ICMS
2540
        $x += $w10;
2541
        $w11 = round($w*0.06, 0);
2542
        $texto = 'VALOR ICMS';
2543
        $aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>'');
2544
        $this->pTextBox($x, $y, $w11, $h, $texto, $aFont, 'C', 'C', 0, '', false);
2545
        $this->pdf->Line($x+$w11, $y, $x+$w11, $y+$hmax);
2546
        //VALOR IPI
2547
        $x += $w11;
2548
        $w12 = round($w*0.05, 0);
2549
        $texto = 'VALOR IPI';
2550
        $aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>'');
2551
        $this->pTextBox($x, $y, $w12, $h, $texto, $aFont, 'C', 'C', 0, '', false);
2552
        $this->pdf->Line($x+$w12, $y, $x+$w12, $y+$hmax);
2553
        //ALÍQ. ICMS
2554
        $x += $w12;
2555
        $w13 = round($w*0.035, 0);
2556
        $texto = 'ALÍQ. ICMS';
2557
        $aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>'');
2558
        $this->pTextBox($x, $y, $w13, $h, $texto, $aFont, 'C', 'C', 0, '', false);
2559
        $this->pdf->Line($x+$w13, $y, $x+$w13, $y+$hmax);
2560
        //ALÍQ. IPI
2561
        $x += $w13;
2562
        $w14 = $w-($w1+$w2+$w3+$w4+$w5+$w6+$w7+$w8+$w9+$w10+$w11+$w12+$w13);
2563
        $texto = 'ALÍQ. IPI';
2564
        $this->pTextBox($x, $y, $w14, $h, $texto, $aFont, 'C', 'C', 0, '', false);
2565
        $this->pdf->Line($oldX, $y+$h+1, $oldX + $w, $y+$h+1);
2566
        $y += 5;
2567
        //##################################################################################
2568
        // LOOP COM OS DADOS DOS PRODUTOS
2569
        $i = 0;
2570
        $hUsado = $hCabecItens;
2571
        $aFont = array('font'=>$this->fontePadrao, 'size'=>7, 'style'=>'');
2572
        foreach ($this->det as $d) {
2573
            if ($i >= $nInicio) {
2574
                $thisItem = $this->det->item($i);
2575
                //carrega as tags do item
2576
                $prod = $thisItem->getElementsByTagName("prod")->item(0);
2577
                $imposto = $this->det->item($i)->getElementsByTagName("imposto")->item(0);
2578
                $ICMS = $imposto->getElementsByTagName("ICMS")->item(0);
2579
                $IPI  = $imposto->getElementsByTagName("IPI")->item(0);
2580
                $textoProduto = $this->pDescricaoProduto($thisItem);
2581
                $linhaDescr = $this->pGetNumLines($textoProduto, $w2, $aFont);
2582
                $h = round(($linhaDescr * $this->pdf->fontSize)+ ($linhaDescr * 0.5), 2);
2583
                $hUsado += $h;
2584
                if ($pag != $totpag) {
2585
                    if ($hUsado >= $hmax && $i < $totItens) {
2586
                        //ultrapassa a capacidade para uma única página
2587
                        //o restante dos dados serão usados nas proximas paginas
2588
                        $nInicio = $i;
2589
                        break;
2590
                    }
2591
                }
2592
                $y_linha=$y+$h;
2593
                // linha entre itens
2594
                $this->pdf->DashedHLine($oldX, $y_linha, $w, 0.1, 120);
2595
                //corrige o x
2596
                $x=$oldX;
2597
                //codigo do produto
2598
                $texto = $prod->getElementsByTagName("cProd")->item(0)->nodeValue;
2599
                $this->pTextBox($x, $y, $w1, $h, $texto, $aFont, 'T', 'C', 0, '');
2600
                $x += $w1;
2601
                //DESCRIÇÃO
2602
                if ($this->orientacao == 'P') {
2603
                    $this->pTextBox($x, $y, $w2, $h, $textoProduto, $aFont, 'T', 'L', 0, '', false);
2604
                } else {
2605
                    $this->pTextBox($x, $y, $w2, $h, $textoProduto, $aFont, 'T', 'L', 0, '', false);
2606
                }
2607
                $x += $w2;
2608
                //NCM
2609
                $texto = ! empty($prod->getElementsByTagName("NCM")->item(0)->nodeValue) ?
2610
                        $prod->getElementsByTagName("NCM")->item(0)->nodeValue : '';
2611
                $this->pTextBox($x, $y, $w3, $h, $texto, $aFont, 'T', 'C', 0, '');
2612
                $x += $w3;
2613
                //CST
2614
                if (isset($ICMS)) {
2615
                    $origem =  $this->pSimpleGetValue($ICMS, "orig");
2616
                    $cst =  $this->pSimpleGetValue($ICMS, "CST");
2617
                    $csosn =  $this->pSimpleGetValue($ICMS, "CSOSN");
2618
                    $texto = $origem.$cst.$csosn;
2619
                    $this->pTextBox($x, $y, $w4, $h, $texto, $aFont, 'T', 'C', 0, '');
2620
                }
2621
                //CFOP
2622
                $x += $w4;
2623
                $texto = $prod->getElementsByTagName("CFOP")->item(0)->nodeValue;
2624
                $this->pTextBox($x, $y, $w5, $h, $texto, $aFont, 'T', 'C', 0, '');
2625
                //Unidade
2626
                $x += $w5;
2627
                $texto = $prod->getElementsByTagName("uCom")->item(0)->nodeValue;
2628
                $this->pTextBox($x, $y, $w6, $h, $texto, $aFont, 'T', 'C', 0, '');
2629
                $x += $w6;
2630
                if ($this->orientacao == 'P') {
2631
                    $alinhamento = 'R';
2632
                } else {
2633
                    $alinhamento = 'R';
2634
                }
2635
                // QTDADE
2636
                $texto = number_format($prod->getElementsByTagName("qCom")->item(0)->nodeValue, 4, ",", ".");
2637
                $this->pTextBox($x, $y, $w7, $h, $texto, $aFont, 'T', $alinhamento, 0, '');
2638
                $x += $w7;
2639
                // Valor Unitário
2640
                $texto = number_format($prod->getElementsByTagName("vUnCom")->item(0)->nodeValue, 4, ",", ".");
2641
                $this->pTextBox($x, $y, $w8, $h, $texto, $aFont, 'T', $alinhamento, 0, '');
2642
                $x += $w8;
2643
                // Valor do Produto
2644
                $texto = "";
2645
                if (is_numeric($prod->getElementsByTagName("vProd")->item(0)->nodeValue)) {
2646
                    $texto = number_format($prod->getElementsByTagName("vProd")->item(0)->nodeValue, 2, ",", ".");
2647
                }
2648
                $this->pTextBox($x, $y, $w9, $h, $texto, $aFont, 'T', $alinhamento, 0, '');
2649
                //Valor da Base de calculo
2650
                $x += $w9;
2651
                if (isset($ICMS)) {
2652
                    $texto = ! empty($ICMS->getElementsByTagName("vBC")->item(0)->nodeValue) ?
2653
                            number_format(
2654
                                $ICMS->getElementsByTagName("vBC")->item(0)->nodeValue,
2655
                                2,
2656
                                ",",
2657
                                "."
2658
                            ) : '0, 00';
2659
                    $this->pTextBox($x, $y, $w10, $h, $texto, $aFont, 'T', $alinhamento, 0, '');
2660
                }
2661
                //Valor do ICMS
2662
                $x += $w10;
2663
                if (isset($ICMS)) {
2664
                    $texto = ! empty($ICMS->getElementsByTagName("vICMS")->item(0)->nodeValue) ?
2665
                            number_format(
2666
                                $ICMS->getElementsByTagName("vICMS")->item(0)->nodeValue,
2667
                                2,
2668
                                ",",
2669
                                "."
2670
                            ) : '0, 00';
2671
                    $this->pTextBox($x, $y, $w11, $h, $texto, $aFont, 'T', $alinhamento, 0, '');
2672
                }
2673
                //Valor do IPI
2674
                $x += $w11;
2675
                if (isset($IPI)) {
2676
                    $texto = ! empty($IPI->getElementsByTagName("vIPI")->item(0)->nodeValue) ?
2677
                            number_format($IPI->getElementsByTagName("vIPI")->item(0)->nodeValue, 2, ",", ".") :'';
2678
                } else {
2679
                    $texto = '';
2680
                }
2681
                $this->pTextBox($x, $y, $w12, $h, $texto, $aFont, 'T', $alinhamento, 0, '');
2682
                // %ICMS
2683
                $x += $w12;
2684
                if (isset($ICMS)) {
2685
                    $texto = ! empty($ICMS->getElementsByTagName("pICMS")->item(0)->nodeValue) ?
2686
                            number_format(
2687
                                $ICMS->getElementsByTagName("pICMS")->item(0)->nodeValue,
2688
                                2,
2689
                                ",",
2690
                                "."
2691
                            ) : '0, 00';
2692
                    $this->pTextBox($x, $y, $w13, $h, $texto, $aFont, 'T', 'C', 0, '');
2693
                }
2694
                //%IPI
2695
                $x += $w13;
2696
                if (isset($IPI)) {
2697
                    $texto = ! empty($IPI->getElementsByTagName("pIPI")->item(0)->nodeValue) ?
2698
                            number_format($IPI->getElementsByTagName("pIPI")->item(0)->nodeValue, 2, ",", ".") : '';
2699
                } else {
2700
                    $texto = '';
2701
                }
2702
                $this->pTextBox($x, $y, $w14, $h, $texto, $aFont, 'T', 'C', 0, '');
2703
                $y += $h;
2704
                $i++;
2705
                //incrementa o controle dos itens processados.
2706
                $this->qtdeItensProc++;
2707
            } else {
2708
                $i++;
2709
            }
2710
        }
2711
        return $oldY+$hmax;
2712
    }
2713
2714
    /**
2715
     * issqnDANFE
2716
     * Monta o campo de serviços do DANFE
2717
     *
2718
     * @name   issqnDANFE (retrato e paisagem)
2719
     * @param  float $x Posição horizontal canto esquerdo
2720
     * @param  float $y Posição vertical canto superior
2721
     * @return float Posição vertical final
2722
     */
2723
    protected function pIssqnDANFE($x, $y)
2724
    {
2725
        $oldX = $x;
2726
        //#####################################################################
2727
        //CÁLCULO DO ISSQN
2728
        $texto = "CÁLCULO DO ISSQN";
2729
        $w = $this->wPrint;
2730
        $h = 7;
2731
        $aFont = array('font'=>$this->fontePadrao, 'size'=>7, 'style'=>'B');
2732
        $this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 0, '');
2733
        //INSCRIÇÃO MUNICIPAL
2734
        $y += 3;
2735
        $w = round($this->wPrint*0.23, 0);
2736
        $texto = 'INSCRIÇÃO MUNICIPAL';
2737
        $aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>'');
2738
        $this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 1, '');
2739
        //inscrição municipal
2740
        $texto = ! empty($this->emit->getElementsByTagName("IM")->item(0)->nodeValue) ?
2741
                $this->emit->getElementsByTagName("IM")->item(0)->nodeValue : '';
2742
        $aFont = array('font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B');
2743
        $this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'B', 'L', 0, '');
2744
        //VALOR TOTAL DOS SERVIÇOS
2745
        $x += $w;
2746
        $texto = 'VALOR TOTAL DOS SERVIÇOS';
2747
        $aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>'');
2748
        $this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 1, '');
2749
        if (isset($this->ISSQNtot)) {
2750
            $texto = ! empty($this->ISSQNtot->getElementsByTagName("vServ")->item(0)->nodeValue) ?
2751
                    $this->ISSQNtot->getElementsByTagName("vServ")->item(0)->nodeValue : '';
2752
            $texto = number_format($texto, 2, ",", ".");
2753
        } else {
2754
            $texto = '';
2755
        }
2756
        $aFont = array('font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B');
2757
        $this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'B', 'R', 0, '');
2758
        //BASE DE CÁLCULO DO ISSQN
2759
        $x += $w;
2760
        $texto = 'BASE DE CÁLCULO DO ISSQN';
2761
        $aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>'');
2762
        $this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 1, '');
2763
        if (isset($this->ISSQNtot)) {
2764
            $texto = ! empty($this->ISSQNtot->getElementsByTagName("vBC")->item(0)->nodeValue) ?
2765
                    $this->ISSQNtot->getElementsByTagName("vBC")->item(0)->nodeValue : '';
2766
            $texto = ! empty($texto) ? number_format($texto, 2, ",", ".") : '';
2767
        } else {
2768
            $texto = '';
2769
        }
2770
        $aFont = array('font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B');
2771
        $this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'B', 'R', 0, '');
2772
        //VALOR TOTAL DO ISSQN
2773
        $x += $w;
2774
        if ($this->orientacao == 'P') {
2775
            $w = $this->wPrint - (3 * $w);
2776
        } else {
2777
            $w = $this->wPrint - (3 * $w)-$this->wCanhoto;
2778
        }
2779
        $texto = 'VALOR TOTAL DO ISSQN';
2780
        $aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>'');
2781
        $this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 1, '');
2782
        if (isset($this->ISSQNtot)) {
2783
            $texto = ! empty($this->ISSQNtot->getElementsByTagName("vISS")->item(0)->nodeValue) ?
2784
                    $this->ISSQNtot->getElementsByTagName("vISS")->item(0)->nodeValue : '';
2785
            $texto = ! empty($texto) ? number_format($texto, 2, ",", ".") : '';
2786
        } else {
2787
            $texto = '';
2788
        }
2789
        $aFont = array('font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B');
2790
        $this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'B', 'R', 0, '');
2791
        return ($y+$h+1);
2792
    }
2793
2794
    /**
2795
     *dadosAdicionaisDANFE
2796
     * Coloca o grupo de dados adicionais da NFe. (retrato e paisagem)
2797
     *
2798
     * @name   dadosAdicionaisDANFE
2799
     * @param  float $x Posição horizontal canto esquerdo
2800
     * @param  float $y Posição vertical canto superior
2801
     * @param  float $h altura do campo
2802
     * @return float Posição vertical final (eixo Y)
2803
     */
2804
    protected function pDadosAdicionaisDANFE($x, $y, $h)
2805
    {
2806
        //##################################################################################
2807
        //DADOS ADICIONAIS
2808
        $texto = "DADOS ADICIONAIS";
2809
        if ($this->orientacao == 'P') {
2810
              $w = $this->wPrint;
2811
        } else {
2812
              $w = $this->wPrint-$this->wCanhoto;
2813
        }
2814
        $aFont = array('font'=>$this->fontePadrao, 'size'=>7, 'style'=>'B');
2815
        $this->pTextBox($x, $y, $w, 8, $texto, $aFont, 'T', 'L', 0, '');
2816
        //INFORMAÇÕES COMPLEMENTARES
2817
        $texto = "INFORMAÇÕES COMPLEMENTARES";
2818
        $y += 3;
2819
        $w = $this->wAdic;
2820
        $aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>'B');
2821
        $this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 1, '');
2822
        //o texto com os dados adicionais foi obtido na função montaDANFE
2823
        //e carregado em uma propriedade privada da classe
2824
        //$this->wAdic com a largura do campo
2825
        //$this->textoAdic com o texto completo do campo
2826
        $y += 1;
2827
        $aFont = array('font'=>$this->fontePadrao, 'size'=>7, 'style'=>'');
2828
        $this->pTextBox($x, $y+2, $w-2, $h-3, $this->textoAdic, $aFont, 'T', 'L', 0, '', false);
2829
        //RESERVADO AO FISCO
2830
        $texto = "RESERVADO AO FISCO";
2831
        $x += $w;
2832
        $y -= 1;
2833
        if ($this->orientacao == 'P') {
2834
            $w = $this->wPrint-$w;
2835
        } else {
2836
            $w = $this->wPrint-$w-$this->wCanhoto;
2837
        }
2838
        $aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>'B');
2839
        $this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 1, '');
2840
        //inserir texto informando caso de contingência
2841
        // 1 - Normal - emissão normal;
2842
        // 2 - Contingência FS - emissão em contingência com impressão do DANFE em Formulário de Segurança;
2843
        // 3 - Contingência SCAN - emissão em contingência no Sistema de Contingência do Ambiente Nacional;
2844
        // 4 - Contingência DPEC - emissão em contingência com envio da Declaração
2845
        //     Prévia de Emissão em Contingência;
2846
        // 5 - Contingência FS-DA - emissão em contingência com impressão do DANFE em Formulário de
2847
        //     Segurança para Impressão de Documento Auxiliar de Documento Fiscal Eletrônico (FS-DA);
2848
        // 6 - Contingência SVC-AN
2849
        // 7 - Contingência SVC-RS
2850
        $xJust = $this->pSimpleGetValue($this->ide, 'xJust', 'Justificativa: ');
2851
        $dhCont = $this->pSimpleGetValue($this->ide, 'dhCont', ' Entrada em contingência : ');
2852
        $texto = '';
2853
        switch ($this->tpEmis) {
2854
            case 2:
2855
                $texto = 'CONTINGÊNCIA FS' . $dhCont . $xJust;
2856
                break;
2857
            case 3:
2858
                $texto = 'CONTINGÊNCIA SCAN' . $dhCont . $xJust;
2859
                break;
2860
            case 4:
2861
                $texto = 'CONTINGÊNCIA DPEC' . $dhCont . $xJust;
2862
                break;
2863
            case 5:
2864
                $texto = 'CONTINGÊNCIA FSDA' . $dhCont . $xJust;
2865
                break;
2866
            case 6:
2867
                $texto = 'CONTINGÊNCIA SVC-AN' . $dhCont . $xJust;
2868
                break;
2869
            case 7:
2870
                $texto = 'CONTINGÊNCIA SVC-RS' . $dhCont . $xJust;
2871
                break;
2872
        }
2873
        $y += 2;
2874
        $aFont = array('font'=>$this->fontePadrao, 'size'=>7, 'style'=>'');
2875
        $this->pTextBox($x, $y, $w-2, $h-3, $texto, $aFont, 'T', 'L', 0, '', false);
2876
        return $y+$h;
2877
    }
2878
2879
    /**
2880
     * pRodape
2881
     * Monta o rodapé no final da DANFE com a data/hora de impressão e informações
2882
     * sobre a API NfePHP
2883
     *
2884
     * @name   pRodape
2885
     * @param  float $xInic  Posição horizontal canto esquerdo
2886
     * @param  float $yFinal Posição vertical final para impressão
2887
     * @return void
2888
     */
2889
    protected function pRodape($x, $y)
2890
    {
2891
        if ($this->orientacao == 'P') {
2892
              $w = $this->wPrint;
2893
        } else {
2894
              $w = $this->wPrint-$this->wCanhoto;
2895
              $x = $this->wCanhoto;
2896
        }
2897
        $aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>'I');
2898
        $texto = "Impresso em ". date('d/m/Y') . " as " . date('H:i:s');
2899
        $this->pTextBox($x, $y, $w, 0, $texto, $aFont, 'T', 'L', false);
2900
        $texto = $this->creditos .  "  Powered by NFePHP";
2901
        $this->pTextBox($x, $y, $w, 0, $texto, $aFont, 'T', 'R', false, '');
2902
    }
2903
2904
    /**
2905
     * pCcanhotoDANFE
2906
     * Monta o canhoto da DANFE (retrato e paisagem)
2907
     *
2908
     * @name   canhotoDANFE
2909
     * @param  number $x Posição horizontal canto esquerdo
2910
     * @param  number $y Posição vertical canto superior
2911
     * @return number Posição vertical final
2912
     *
2913
     * TODO 21/07/14 fmertins: quando orientação L-paisagem, o canhoto está sendo gerado incorretamente
2914
     */
2915
    protected function pCanhoto($x, $y)
2916
    {
2917
        $oldX = $x;
2918
        $oldY = $y;
2919
        //#################################################################################
2920
        //canhoto
2921
        //identificação do tipo de nf entrada ou saida
2922
        $tpNF = $this->ide->getElementsByTagName('tpNF')->item(0)->nodeValue;
2923
        if ($tpNF == '0') {
2924
            //NFe de Entrada
2925
            $emitente = '';
2926
            $emitente .= $this->dest->getElementsByTagName("xNome")->item(0)->nodeValue . " - ";
2927
            $emitente .= $this->enderDest->getElementsByTagName("xLgr")->item(0)->nodeValue . ", ";
2928
            $emitente .= $this->enderDest->getElementsByTagName("nro")->item(0)->nodeValue . " - ";
2929
            $emitente .= $this->pSimpleGetValue($this->enderDest, "xCpl", " - ", " ");
2930
            $emitente .= $this->enderDest->getElementsByTagName("xBairro")->item(0)->nodeValue . " ";
2931
            $emitente .= $this->enderDest->getElementsByTagName("xMun")->item(0)->nodeValue . "-";
2932
            $emitente .= $this->enderDest->getElementsByTagName("UF")->item(0)->nodeValue . "";
2933
            $destinatario = $this->emit->getElementsByTagName("xNome")->item(0)->nodeValue . " ";
2934
        } else {
2935
            //NFe de Saída
2936
            $emitente = $this->emit->getElementsByTagName("xNome")->item(0)->nodeValue . " ";
2937
            $destinatario = '';
2938
            $destinatario .= $this->dest->getElementsByTagName("xNome")->item(0)->nodeValue . " - ";
2939
            $destinatario .= $this->enderDest->getElementsByTagName("xLgr")->item(0)->nodeValue . ", ";
2940
            $destinatario .= $this->enderDest->getElementsByTagName("nro")->item(0)->nodeValue . " ";
2941
            $destinatario .= $this->pSimpleGetValue($this->enderDest, "xCpl", " - ", " ");
2942
            $destinatario .= $this->enderDest->getElementsByTagName("xBairro")->item(0)->nodeValue . " ";
2943
            $destinatario .= $this->enderDest->getElementsByTagName("xMun")->item(0)->nodeValue . "-";
2944
            $destinatario .= $this->enderDest->getElementsByTagName("UF")->item(0)->nodeValue . " ";
2945
        }
2946
        //identificação do sistema emissor
2947
        //linha separadora do canhoto
2948
        if ($this->orientacao == 'P') {
2949
            $w = round($this->wPrint * 0.81, 0);
2950
        } else {
2951
            //linha separadora do canhoto - 238
2952
            //posicao altura
2953
            $y = $this->wPrint-85;
2954
            //altura
2955
            $w = $this->wPrint-85-24;
2956
        }
2957
        $h = 10;
2958
        //desenha caixa
2959
        $texto = '';
2960
        $aFont = array('font'=>$this->fontePadrao, 'size'=>7, 'style'=>'');
2961
        $aFontSmall = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>'');
2962
        if ($this->orientacao == 'P') {
2963
            $this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'C', 'L', 1, '', false);
2964
        } else {
2965
            $this->pTextBox90($x, $y, $w, $h, $texto, $aFont, 'C', 'L', 1, '', false);
2966
        }
2967
        $numNF = str_pad($this->ide->getElementsByTagName('nNF')->item(0)->nodeValue, 9, "0", STR_PAD_LEFT);
2968
        $serie = str_pad($this->ide->getElementsByTagName('serie')->item(0)->nodeValue, 3, "0", STR_PAD_LEFT);
2969
        $texto = "RECEBEMOS DE ";
2970
        $texto .= $emitente;
2971
        $texto .= " OS PRODUTOS E/OU SERVIÇOS CONSTANTES DA NOTA FISCAL ELETRÔNICA INDICADA ";
2972
        if ($this->orientacao == 'P') {
2973
            $texto .= "ABAIXO";
2974
        } else {
2975
            $texto .= "AO LADO";
2976
        }
2977
        $texto .= ". EMISSÃO: ";
2978
        $dEmi = ! empty($this->ide->getElementsByTagName("dEmi")->item(0)->nodeValue) ?
2979
                $this->ide->getElementsByTagName("dEmi")->item(0)->nodeValue : '';
2980
        if ($dEmi == '') {
2981
            $dEmi = ! empty($this->ide->getElementsByTagName("dhEmi")->item(0)->nodeValue) ?
2982
                    $this->ide->getElementsByTagName("dhEmi")->item(0)->nodeValue : '';
2983
            $aDemi = explode('T', $dEmi);
2984
            $dEmi = $aDemi[0];
2985
        }
2986
        $texto .= $this->pYmd2dmy($dEmi) ." ";
2987
        $texto .= "VALOR TOTAL: R$ ";
2988
        $texto .= number_format($this->ICMSTot->getElementsByTagName("vNF")->item(0)->nodeValue, 2, ",", ".") . " ";
2989
        $texto .= "DESTINATÁRIO: ";
2990
        $texto .= $destinatario;
2991
        if ($this->orientacao == 'P') {
2992
            $this->pTextBox($x, $y, $w-1, $h, $texto, $aFont, 'C', 'L', 0, '', false);
2993
            $x1 = $x + $w;
2994
            $w1 = $this->wPrint - $w;
2995
            $texto = "NF-e";
2996
            $aFont = array('font'=>$this->fontePadrao, 'size'=>14, 'style'=>'B');
2997
            $this->pTextBox($x1, $y, $w1, 18, $texto, $aFont, 'T', 'C', 0, '');
2998
            $texto = "Nº. " . $this->pFormat($numNF, "###.###.###") . " \n";
2999
            $texto .= "Série $serie";
3000
            $aFont = array('font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B');
3001
            $this->pTextBox($x1, $y, $w1, 18, $texto, $aFont, 'C', 'C', 1, '');
3002
            //DATA DE RECEBIMENTO
3003
            $texto = "DATA DE RECEBIMENTO";
3004
            $y += $h;
3005
            $w2 = round($this->wPrint*0.17, 0); //35;
3006
            $aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>'');
3007
            $this->pTextBox($x, $y, $w2, 8, $texto, $aFont, 'T', 'L', 1, '');
3008
            //IDENTIFICAÇÃO E ASSINATURA DO RECEBEDOR
3009
            $x += $w2;
3010
            $w3 = $w-$w2;
3011
            $texto = "IDENTIFICAÇÃO E ASSINATURA DO RECEBEDOR";
3012
            $this->pTextBox($x, $y, $w3, 8, $texto, $aFont, 'T', 'L', 1, '');
3013
            $x = $oldX;
3014
            $y += 9;
3015
            $this->pdf->DashedHLine($x, $y, $this->wPrint, 0.1, 80);
3016
            $y += 2;
3017
            return $y;
3018
        } else {
3019
            $x--;
3020
            $x = $this->pTextBox90($x, $y, $w-1, $h, $texto, $aFontSmall, 'C', 'L', 0, '', false);
3021
            //NUMERO DA NOTA FISCAL LOGO NFE
3022
            $w1 = 16;
3023
            $x1 = $oldX;
3024
            $y = $oldY;
3025
            $texto = "NF-e";
3026
            $aFont = array('font'=>$this->fontePadrao, 'size'=>14, 'style'=>'B');
3027
            $this->pTextBox($x1, $y, $w1, 18, $texto, $aFont, 'T', 'C', 0, '');
3028
            $texto = "Nº.\n" . $this->pFormat($numNF, "###.###.###") . " \n";
3029
            $texto .= "Série $serie";
3030
            $aFont = array('font'=>$this->fontePadrao, 'size'=>8, 'style'=>'B');
3031
            $this->pTextBox($x1, $y, $w1, 18, $texto, $aFont, 'C', 'C', 1, '');
3032
            //DATA DO RECEBIMENTO
3033
            $texto = "DATA DO RECEBIMENTO";
3034
            $y = $this->wPrint-85;
3035
            $x = 12;
3036
            $w2 = round($this->wPrint*0.17, 0); //35;
3037
            $aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>'');
3038
            $this->pTextBox90($x, $y, $w2, 8, $texto, $aFont, 'T', 'L', 1, '');
3039
            //IDENTIFICAÇÃO E ASSINATURA DO RECEBEDOR
3040
            $y -= $w2;
3041
            $w3 = $w-$w2;
3042
            $texto = "IDENTIFICAÇÃO E ASSINATURA DO RECEBEDOR";
3043
            $aFont = array('font'=>$this->fontePadrao, 'size'=>5.7, 'style'=>'');
3044
            $x = $this->pTextBox90($x, $y, $w3, 8, $texto, $aFont, 'T', 'L', 1, '');
3045
            $this->pdf->DashedVLine(23, $oldY, 0.1, $this->wPrint-20, 67);
3046
            return $x;
3047
        }
3048
    }
3049
3050
    /**
3051
     * pGeraInformacoesDaTagCompra
3052
     * Devolve uma string contendo informação sobre as tag <compra><xNEmp>, <xPed> e <xCont> ou string vazia.
3053
     * Aviso: Esta função não leva em consideração dados na tag xPed do item.
3054
     *
3055
     * @name   pGeraInformacoesDaTagCompra
3056
     * @return string com as informacoes dos pedidos.
3057
     */
3058
    protected function pGeraInformacoesDaTagCompra()
3059
    {
3060
        $saida = "";
3061
        if (isset($this->compra)) {
3062
            if (! empty($this->compra->getElementsByTagName("xNEmp")->item(0)->nodeValue)) {
3063
                $saida .= " Nota de Empenho: " . $this->compra->getElementsByTagName("xNEmp")->item(0)->nodeValue;
3064
            }
3065
            if (! empty($this->compra->getElementsByTagName("xPed")->item(0)->nodeValue)) {
3066
                $saida .= " Pedido: " . $this->compra->getElementsByTagName("xPed")->item(0)->nodeValue;
3067
            }
3068
            if (! empty($this->compra->getElementsByTagName("xCont")->item(0)->nodeValue)) {
3069
                $saida .= " Contrato: " . $this->compra->getElementsByTagName("xCont")->item(0)->nodeValue;
3070
            }
3071
        }
3072
        return $saida;
3073
    }
3074
3075
    /**
3076
     * pGeraChaveAdicionalDeContingencia
3077
     *
3078
     * @name   pGeraChaveAdicionalDeContingencia
3079
     * @return string chave
3080
     */
3081
    protected function pGeraChaveAdicionalDeContingencia()
3082
    {
3083
        //cUF tpEmis CNPJ vNF ICMSp ICMSs DD  DV
3084
        // 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...
3085
        $forma  = "%02d%d%s%014d%01d%01d%02d";
3086
        $cUF    = $this->ide->getElementsByTagName('cUF')->item(0)->nodeValue;
3087
        $CNPJ   = "00000000000000" . $this->emit->getElementsByTagName('CNPJ')->item(0)->nodeValue;
3088
        $CNPJ   = substr($CNPJ, -14);
3089
        $vNF    = $this->ICMSTot->getElementsByTagName("vNF")->item(0)->nodeValue * 100;
3090
        $vICMS  = $this->ICMSTot->getElementsByTagName("vICMS")->item(0)->nodeValue;
3091
        if ($vICMS > 0) {
3092
            $vICMS = 1;
3093
        }
3094
        $icmss  = $this->ICMSTot->getElementsByTagName("vBC")->item(0)->nodeValue;
3095
        if ($icmss > 0) {
3096
            $icmss = 1;
3097
        }
3098
        $dEmi = ! empty($this->ide->getElementsByTagName("dEmi")->item(0)->nodeValue) ?
3099
                $this->ide->getElementsByTagName("dEmi")->item(0)->nodeValue : '';
3100
        if ($dEmi == '') {
3101
            $dEmi = ! empty($this->ide->getElementsByTagName("dhEmi")->item(0)->nodeValue) ?
3102
                    $this->ide->getElementsByTagName("dhEmi")->item(0)->nodeValue : '';
3103
            $aDemi = explode('T', $dEmi);
3104
            $dEmi = $aDemi[0];
3105
        }
3106
        $dd  = $dEmi;
3107
        $rpos = strrpos($dd, '-');
3108
        $dd  = substr($dd, $rpos +1);
3109
        $chave = sprintf($forma, $cUF, $this->tpEmis, $CNPJ, $vNF, $vICMS, $icmss, $dd);
3110
        $chave = $chave . $this->pModulo11($chave);
3111
        return $chave;
3112
    }
3113
3114
    /**
3115
     * pGeraInformacoesDasNotasReferenciadas
3116
     * Devolve uma string contendo informação sobre as notas referenciadas. Suporta N notas, eletrônicas ou não
3117
     * Exemplo: NFe Ref.: série: 01 número: 01 emit: 11.111.111/0001-01
3118
     * em 10/2010 [0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000]
3119
     *
3120
     * @return string Informacoes a serem adicionadas no rodapé sobre notas referenciadas.
3121
     */
3122
    protected function pGeraInformacoesDasNotasReferenciadas()
3123
    {
3124
        $formaNfeRef = "\r\nNFe Ref.: série:%d número:%d emit:%s em %s [%s]";
3125
        $formaCTeRef = "\r\nCTe Ref.: série:%d número:%d emit:%s em %s [%s]";
3126
        $formaNfRef = "\r\nNF  Ref.: série:%d numero:%d emit:%s em %s modelo: %d";
3127
        $formaECFRef = "\r\nECF Ref.: modelo: %s ECF:%d COO:%d";
3128
        $formaNfpRef = "\r\nNFP Ref.: série:%d número:%d emit:%s em %s modelo: %d IE:%s";
3129
        $saida='';
3130
        $nfRefs = $this->ide->getElementsByTagName('NFref');
3131
        if (0 === $nfRefs->length) {
3132
            return $saida;
3133
        }
3134
        foreach ($nfRefs as $nfRef) {
3135
            if (empty($nfRef)) {
3136
                continue;
3137
            }
3138
            $refNFe = $nfRef->getElementsByTagName('refNFe');
3139
            foreach ($refNFe as $chave_acessoRef) {
3140
                $chave_acesso = $chave_acessoRef->nodeValue;
3141
                $chave_acessoF = $this->pFormat($chave_acesso, $this->formatoChave);
3142
                $data = substr($chave_acesso, 4, 2)."/20".substr($chave_acesso, 2, 2);
3143
                $cnpj = $this->pFormat(substr($chave_acesso, 6, 14), "##.###.###/####-##");
3144
                $serie  = substr($chave_acesso, 22, 3);
3145
                $numero = substr($chave_acesso, 25, 9);
3146
                $saida .= sprintf($formaNfeRef, $serie, $numero, $cnpj, $data, $chave_acessoF);
3147
            }
3148
            $refNF = $nfRef->getElementsByTagName('refNF');
3149
            foreach ($refNF as $umaRefNFe) {
3150
                $data = $umaRefNFe->getElementsByTagName('AAMM')->item(0)->nodeValue;
3151
                $cnpj = $umaRefNFe->getElementsByTagName('CNPJ')->item(0)->nodeValue;
3152
                $mod = $umaRefNFe->getElementsByTagName('mod')->item(0)->nodeValue;
3153
                $serie = $umaRefNFe->getElementsByTagName('serie')->item(0)->nodeValue;
3154
                $numero = $umaRefNFe->getElementsByTagName('nNF')->item(0)->nodeValue;
3155
                $data = substr($data, 2, 2) . "/20" . substr($data, 0, 2);
3156
                $cnpj = $this->pFormat($cnpj, "##.###.###/####-##");
3157
                $saida .= sprintf($formaNfRef, $serie, $numero, $cnpj, $data, $mod);
3158
            }
3159
            $refCTe = $nfRef->getElementsByTagName('refCTe');
3160
            foreach ($refCTe as $chave_acessoRef) {
3161
                $chave_acesso = $chave_acessoRef->nodeValue;
3162
                $chave_acessoF = $this->pFormat($chave_acesso, $this->formatoChave);
3163
                $data = substr($chave_acesso, 4, 2)."/20".substr($chave_acesso, 2, 2);
3164
                $cnpj = $this->pFormat(substr($chave_acesso, 6, 14), "##.###.###/####-##");
3165
                $serie  = substr($chave_acesso, 22, 3);
3166
                $numero = substr($chave_acesso, 25, 9);
3167
                $saida .= sprintf($formaCTeRef, $serie, $numero, $cnpj, $data, $chave_acessoF);
3168
            }
3169
            $refECF = $nfRef->getElementsByTagName('refECF');
3170
            foreach ($refECF as $umaRefNFe) {
3171
                $mod    = $umaRefNFe->getElementsByTagName('mod')->item(0)->nodeValue;
3172
                $nECF   = $umaRefNFe->getElementsByTagName('nECF')->item(0)->nodeValue;
3173
                $nCOO   = $umaRefNFe->getElementsByTagName('nCOO')->item(0)->nodeValue;
3174
                $saida .= sprintf($formaECFRef, $mod, $nECF, $nCOO);
3175
            }
3176
            $refNFP = $nfRef->getElementsByTagName('refNFP');
3177
            foreach ($refNFP as $umaRefNFe) {
3178
                $data = $umaRefNFe->getElementsByTagName('AAMM')->item(0)->nodeValue;
3179
                $cnpj = ! empty($umaRefNFe->getElementsByTagName('CNPJ')->item(0)->nodeValue) ?
3180
                    $umaRefNFe->getElementsByTagName('CNPJ')->item(0)->nodeValue :
3181
                    '';
3182
                $cpf = ! empty($umaRefNFe->getElementsByTagName('CPF')->item(0)->nodeValue) ?
3183
                        $umaRefNFe->getElementsByTagName('CPF')->item(0)->nodeValue : '';
3184
                $mod = $umaRefNFe->getElementsByTagName('mod')->item(0)->nodeValue;
3185
                $serie = $umaRefNFe->getElementsByTagName('serie')->item(0)->nodeValue;
3186
                $numero = $umaRefNFe->getElementsByTagName('nNF')->item(0)->nodeValue;
3187
                $ie = $umaRefNFe->getElementsByTagName('IE')->item(0)->nodeValue;
3188
                $data = substr($data, 2, 2) . "/20" . substr($data, 0, 2);
3189
                if ($cnpj == '') {
3190
                    $cpf_cnpj = $this->pFormat($cpf, "###.###.###-##");
3191
                } else {
3192
                    $cpf_cnpj = $this->pFormat($cnpj, "##.###.###/####-##");
3193
                }
3194
                $saida .= sprintf($formaNfpRef, $serie, $numero, $cpf_cnpj, $data, $mod, $ie);
3195
            }
3196
        }
3197
        return $saida;
3198
    }
3199
    
3200
    private function imagePNGtoJPG($original)
3201
    {
3202
        $image = imagecreatefrompng($original);
3203
        ob_start();
3204
        imagejpeg($image, null, 100);
3205
        imagedestroy($image);
3206
        $stringdata = ob_get_contents(); // read from buffer
3207
        ob_end_clean();
3208
        return 'data://text/plain;base64,'.base64_encode($stringdata);
3209
    }
3210
}
3211