Passed
Push — master ( 02874b...2c6a9c )
by Roberto
04:02
created

Danfe::render()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 0
loc 4
ccs 0
cts 4
cp 0
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace NFePHP\DA\NFe;
4
5
use InvalidArgumentException;
6
use NFePHP\DA\Legacy\Dom;
7
use NFePHP\DA\Legacy\Pdf;
8
use NFePHP\DA\Legacy\Common;
9
10
class Danfe extends Common
11
{
12
    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;
0 ignored issues
show
Documentation Bug introduced by
It seems like $mododebug can also be of type double or string. However, the property $debugMode is declared as type integer. Maybe add an additional type check?

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

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

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

class Id
{
    public $id;

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

}

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

$account_id = false;

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

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
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          = '';
0 ignored issues
show
Documentation Bug introduced by
It seems like '' of type string is incompatible with the declared type object of property $pdf.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
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();
0 ignored issues
show
Documentation Bug introduced by
It seems like new \NFePHP\DA\Legacy\Dom() of type object<NFePHP\DA\Legacy\Dom> is incompatible with the declared type object<NFePHP\DA\NFe\DOMDocument> of property $dom.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
360
            $this->dom->loadXML($this->xml);
361
            $this->nfeProc    = $this->dom->getElementsByTagName("nfeProc")->item(0);
0 ignored issues
show
Bug introduced by
The property nfeProc does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
362
            $this->infNFe     = $this->dom->getElementsByTagName("infNFe")->item(0);
0 ignored issues
show
Documentation Bug introduced by
It seems like $this->dom->getElementsB...Name('infNFe')->item(0) of type object<DOMNode> is incompatible with the declared type object<NFePHP\DA\NFe\DOMNode> of property $infNFe.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
363
            $this->ide        = $this->dom->getElementsByTagName("ide")->item(0);
0 ignored issues
show
Documentation Bug introduced by
It seems like $this->dom->getElementsByTagName('ide')->item(0) of type object<DOMNode> is incompatible with the declared type object<NFePHP\DA\NFe\DOMNode> of property $ide.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
364
            $this->entrega    = $this->dom->getElementsByTagName("entrega")->item(0);
0 ignored issues
show
Documentation Bug introduced by
It seems like $this->dom->getElementsB...ame('entrega')->item(0) of type object<DOMNode> is incompatible with the declared type object<NFePHP\DA\NFe\DOMNode> of property $entrega.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
365
            $this->retirada   = $this->dom->getElementsByTagName("retirada")->item(0);
0 ignored issues
show
Documentation Bug introduced by
It seems like $this->dom->getElementsB...me('retirada')->item(0) of type object<DOMNode> is incompatible with the declared type object<NFePHP\DA\NFe\DOMNode> of property $retirada.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
366
            $this->emit       = $this->dom->getElementsByTagName("emit")->item(0);
0 ignored issues
show
Documentation Bug introduced by
It seems like $this->dom->getElementsByTagName('emit')->item(0) of type object<DOMNode> is incompatible with the declared type object<NFePHP\DA\NFe\DOMNode> of property $emit.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
367
            $this->dest       = $this->dom->getElementsByTagName("dest")->item(0);
0 ignored issues
show
Documentation Bug introduced by
It seems like $this->dom->getElementsByTagName('dest')->item(0) of type object<DOMNode> is incompatible with the declared type object<NFePHP\DA\NFe\DOMNode> of property $dest.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
368
            $this->enderEmit  = $this->dom->getElementsByTagName("enderEmit")->item(0);
0 ignored issues
show
Documentation Bug introduced by
It seems like $this->dom->getElementsB...e('enderEmit')->item(0) of type object<DOMNode> is incompatible with the declared type object<NFePHP\DA\NFe\DOMNode> of property $enderEmit.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
369
            $this->enderDest  = $this->dom->getElementsByTagName("enderDest")->item(0);
0 ignored issues
show
Documentation Bug introduced by
It seems like $this->dom->getElementsB...e('enderDest')->item(0) of type object<DOMNode> is incompatible with the declared type object<NFePHP\DA\NFe\DOMNode> of property $enderDest.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
370
            $this->det        = $this->dom->getElementsByTagName("det");
0 ignored issues
show
Documentation Bug introduced by
It seems like $this->dom->getElementsByTagName('det') of type object<DOMNodeList> is incompatible with the declared type object<NFePHP\DA\NFe\DOMNode> of property $det.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
371
            $this->cobr       = $this->dom->getElementsByTagName("cobr")->item(0);
0 ignored issues
show
Documentation Bug introduced by
It seems like $this->dom->getElementsByTagName('cobr')->item(0) of type object<DOMNode> is incompatible with the declared type object<NFePHP\DA\NFe\DOMNode> of property $cobr.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
372
            $this->dup        = $this->dom->getElementsByTagName('dup');
0 ignored issues
show
Documentation Bug introduced by
It seems like $this->dom->getElementsByTagName('dup') of type object<DOMNodeList> is incompatible with the declared type object<NFePHP\DA\NFe\DOMNode> of property $dup.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
373
            $this->ICMSTot    = $this->dom->getElementsByTagName("ICMSTot")->item(0);
0 ignored issues
show
Documentation Bug introduced by
It seems like $this->dom->getElementsB...ame('ICMSTot')->item(0) of type object<DOMNode> is incompatible with the declared type object<NFePHP\DA\NFe\DOMNode> of property $ICMSTot.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
374
            $this->ISSQNtot   = $this->dom->getElementsByTagName("ISSQNtot")->item(0);
0 ignored issues
show
Documentation Bug introduced by
It seems like $this->dom->getElementsB...me('ISSQNtot')->item(0) of type object<DOMNode> is incompatible with the declared type object<NFePHP\DA\NFe\DOMNode> of property $ISSQNtot.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
375
            $this->transp     = $this->dom->getElementsByTagName("transp")->item(0);
0 ignored issues
show
Documentation Bug introduced by
It seems like $this->dom->getElementsB...Name('transp')->item(0) of type object<DOMNode> is incompatible with the declared type object<NFePHP\DA\NFe\DOMNode> of property $transp.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
376
            $this->transporta = $this->dom->getElementsByTagName("transporta")->item(0);
0 ignored issues
show
Documentation Bug introduced by
It seems like $this->dom->getElementsB...('transporta')->item(0) of type object<DOMNode> is incompatible with the declared type object<NFePHP\DA\NFe\DOMNode> of property $transporta.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
377
            $this->veicTransp = $this->dom->getElementsByTagName("veicTransp")->item(0);
0 ignored issues
show
Documentation Bug introduced by
It seems like $this->dom->getElementsB...('veicTransp')->item(0) of type object<DOMNode> is incompatible with the declared type object<NFePHP\DA\NFe\DOMNode> of property $veicTransp.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
378
            $this->reboque    = $this->dom->getElementsByTagName("reboque")->item(0);
0 ignored issues
show
Documentation Bug introduced by
It seems like $this->dom->getElementsB...ame('reboque')->item(0) of type object<DOMNode> is incompatible with the declared type object<NFePHP\DA\NFe\DOMNode> of property $reboque.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
379
            $this->infAdic    = $this->dom->getElementsByTagName("infAdic")->item(0);
0 ignored issues
show
Documentation Bug introduced by
It seems like $this->dom->getElementsB...ame('infAdic')->item(0) of type object<DOMNode> is incompatible with the declared type object<NFePHP\DA\NFe\DOMNode> of property $infAdic.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
380
            $this->compra     = $this->dom->getElementsByTagName("compra")->item(0);
0 ignored issues
show
Documentation Bug introduced by
It seems like $this->dom->getElementsB...Name('compra')->item(0) of type object<DOMNode> is incompatible with the declared type object<NFePHP\DA\NFe\DOMNode> of property $compra.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
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);
0 ignored issues
show
Documentation Bug introduced by
It seems like $this->dom->getElementsB...ame('infProt')->item(0) of type object<DOMNode> is incompatible with the declared type object<NFePHP\DA\NFe\DOMNode> of property $infProt.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
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 = '')
0 ignored issues
show
Unused Code introduced by
The parameter $printer is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
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;
0 ignored issues
show
Bug introduced by
The property situacao_externa does not seem to exist. Did you mean situacaoExterna?

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

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

Loading history...
485
        $this->numero_registro_dpec = $depecNumReg;
486
        //instancia a classe pdf
487
        if ($classPdf) {
488
            $this->pdf = $classPdf;
0 ignored issues
show
Documentation Bug introduced by
It seems like $classPdf of type boolean is incompatible with the declared type object of property $pdf.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
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;
0 ignored issues
show
Unused Code introduced by
$totPag is not used, you could remove the assignment.

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

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

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

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

Loading history...
513
        //largura imprimivel em mm: largura da folha menos as margens esq/direita
514
        $this->wPrint = $maxW-($margEsq*2);
0 ignored issues
show
Bug introduced by
The variable $maxW does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
Documentation Bug introduced by
The property $wPrint was declared of type double, but $maxW - $margEsq * 2 is of type integer. Maybe add a type cast?

This check looks for assignments to scalar types that may be of the wrong type.

To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.

$answer = 42;

$correct = false;

$correct = (bool) $answer;
Loading history...
515
        //comprimento (altura) imprimivel em mm: altura da folha menos as margens
516
        //superior e inferior
517
        $this->hPrint = $maxH-$margSup-$margInf;
0 ignored issues
show
Bug introduced by
The variable $maxH does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
Documentation Bug introduced by
The property $hPrint was declared of type double, but $maxH - $margSup - $margInf is of type integer. Maybe add a type cast?

This check looks for assignments to scalar types that may be of the wrong type.

To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.

$answer = 42;

$correct = false;

$correct = (bool) $answer;
Loading history...
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
0 ignored issues
show
Unused Code introduced by
$hcanhoto is not used, you could remove the assignment.

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

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

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

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

Loading history...
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;
0 ignored issues
show
Unused Code introduced by
$numlinhas is not used, you could remove the assignment.

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

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

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

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

Loading history...
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) ?
0 ignored issues
show
Bug introduced by
The property detPag does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
743
                    $this->detPag->item($k)->getElementsByTagName('tPag')->item(0)->nodeValue : '0';
744
                $formaPag[$fPag] = $fPag;
745
            }
746
        }
747
        //caso tenha boleto imprimir fatura
748
        if ($this->dup->length > 0) {
749
            $y = $this->pFaturaDANFE($x, $y+1);
750
        } else {
751
            //Se somente tiver a forma de pagamento sem pagamento ou outros não imprimir nada
752
            if (count($formaPag)=='1' && (isset($formaPag[90]) || isset($formaPag[99]))) {
753
                $y = $y;
0 ignored issues
show
Bug introduced by
Why assign $y to itself?

This checks looks for cases where a variable has been assigned to itself.

This assignement can be removed without consequences.

Loading history...
754
            } else {
755
                //caso tenha mais de uma forma de pagamento ou seja diferente de boleto exibe a
756
                //forma de pagamento e o valor
757
                $y = $this->pagamentoDANFE($x, $y+1);
758
            }
759
        }
760
        //coloca os dados dos impostos e totais da NFe
761
        $y = $this->pImpostoDANFE($x, $y+1);
762
        //coloca os dados do trasnporte
763
        $y = $this->pTransporteDANFE($x, $y+1);
764
        //itens da DANFE
765
        $nInicial = 0;
766
        $y = $this->pItensDANFE($x, $y+1, $nInicial, $hDispo1, $pag, $totPag, $hCabecItens);
767
        //coloca os dados do ISSQN
768
        if ($linhaISSQN == 1) {
769
            $y = $this->pIssqnDANFE($x, $y+4);
770
        } else {
771
            $y += 4;
772
        }
773
        //coloca os dados adicionais da NFe
774
        $y = $this->pDadosAdicionaisDANFE($x, $y, $hdadosadic);
775
        //coloca o rodapé da página
776
        if ($this->orientacao == 'P') {
777
            $this->pRodape($xInic, $y-1);
778
        } else {
779
            $this->pRodape($xInic, $this->hPrint + 1);
780
        }
781
        //loop para páginas seguintes
782
        for ($n = 2; $n <= $totPag; $n++) {
783
            // fixa as margens
784
            $this->pdf->setMargins($margEsq, $margSup);
785
            //adiciona nova página
786
            $this->pdf->addPage($this->orientacao, $this->papel);
787
            //ajusta espessura das linhas
788
            $this->pdf->setLineWidth(0.1);
789
            //seta a cor do texto para petro
790
            $this->pdf->setTextColor(0, 0, 0);
791
            // posição inicial do relatorio
792
            $x = $xInic;
793
            $y = $yInic;
794
            //coloca o cabeçalho na página adicional
795
            $y = $this->pCabecalhoDANFE($x, $y, $n, $totPag);
796
            //coloca os itens na página adicional
797
            $y = $this->pItensDANFE($x, $y+1, $nInicial, $hDispo2, $n, $totPag, $hCabecItens);
798
            //coloca o rodapé da página
799
            if ($this->orientacao == 'P') {
800
                $this->pRodape($xInic, $y + 4);
801
            } else {
802
                $this->pRodape($xInic, $this->hPrint + 4);
803
            }
804
            //se estiver na última página e ainda restar itens para inserir, adiciona mais uma página
805
            if ($n == $totPag && $this->qtdeItensProc < $qtdeItens) {
806
                $totPag++;
807
            }
808
        }
809
        //retorna o ID na NFe
810
        if ($classPdf!==false) {
811
            $aR = array(
812
             'id'=>str_replace('NFe', '', $this->infNFe->getAttribute("Id")),
813
             'classe_PDF'=>$this->pdf);
814
            return $aR;
0 ignored issues
show
Bug Best Practice introduced by
The return type of return $aR; (array) is incompatible with the return type documented by NFePHP\DA\NFe\Danfe::montaDANFE of type string.

If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design.

Let’s take a look at an example:

class Author {
    private $name;

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

    public function getName() {
        return $this->name;
    }
}

abstract class Post {
    public function getAuthor() {
        return 'Johannes';
    }
}

class BlogPost extends Post {
    public function getAuthor() {
        return new Author('Johannes');
    }
}

class ForumPost extends Post { /* ... */ }

function my_function(Post $post) {
    echo strtoupper($post->getAuthor());
}

Our function my_function expects a Post object, and outputs the author of the post. The base class Post returns a simple string and outputting a simple string will work just fine. However, the child class BlogPost which is a sub-type of Post instead decided to return an object, and is therefore violating the SOLID principles. If a BlogPost were passed to my_function, PHP would not complain, but ultimately fail when executing the strtoupper call in its body.

Loading history...
815
        } else {
816
            return str_replace('NFe', '', $this->infNFe->getAttribute("Id"));
817
        }
818
    }//fim da função montaDANFE
819
820
    /**
821
     * anfavea
822
     * Função para transformar o campo cdata do padrão ANFAVEA para
823
     * texto imprimível
824
     *
825
     * @param  string $cdata campo CDATA
826
     * @return string conteúdo do campo CDATA como string
827
     */
828
    protected function pAnfavea($cdata = '')
829
    {
830
        if ($cdata == '') {
831
            return '';
832
        }
833
        //remove qualquer texto antes ou depois da tag CDATA
834
        $cdata = str_replace('<![CDATA[', '<CDATA>', $cdata);
835
        $cdata = str_replace(']]>', '</CDATA>', $cdata);
836
        $cdata = preg_replace('/\s\s+/', ' ', $cdata);
837
        $cdata = str_replace("> <", "><", $cdata);
838
        $len = strlen($cdata);
839
        $startPos = strpos($cdata, '<');
840
        if ($startPos === false) {
841
            return $cdata;
842
        }
843
        for ($x=$len; $x>0; $x--) {
844
            if (substr($cdata, $x, 1) == '>') {
845
                $endPos = $x;
846
                break;
847
            }
848
        }
849
        if ($startPos > 0) {
850
            $parte1 = substr($cdata, 0, $startPos);
851
        } else {
852
            $parte1 = '';
853
        }
854
        $parte2 = substr($cdata, $startPos, $endPos-$startPos+1);
0 ignored issues
show
Bug introduced by
The variable $endPos does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
855
        if ($endPos < $len) {
856
            $parte3 = substr($cdata, $endPos + 1, $len - $endPos - 1);
857
        } else {
858
            $parte3 = '';
859
        }
860
        $texto = trim($parte1).' '.trim($parte3);
861
        if (strpos($parte2, '<CDATA>') === false) {
862
            $cdata = '<CDATA>'.$parte2.'</CDATA>';
863
        } else {
864
            $cdata = $parte2;
865
        }
866
        //Retira a tag <FONTE IBPT> (caso existir) pois não é uma estrutura válida XML
867
        $cdata = str_replace('<FONTE IBPT>', '', $cdata);
868
        //carrega o xml CDATA em um objeto DOM
869
        $dom = new Dom();
870
        $dom->loadXML($cdata, LIBXML_NOBLANKS | LIBXML_NOEMPTYTAG);
871
        //$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...
872
        //grupo CDATA infADprod
873
        $id = $dom->getElementsByTagName('id')->item(0);
874
        $div = $dom->getElementsByTagName('div')->item(0);
875
        $entg = $dom->getElementsByTagName('entg')->item(0);
876
        $dest = $dom->getElementsByTagName('dest')->item(0);
877
        $ctl = $dom->getElementsByTagName('ctl')->item(0);
878
        $ref = $dom->getElementsByTagName('ref')->item(0);
879
        if (isset($id)) {
880
            if ($id->hasAttributes()) {
881
                foreach ($id->attributes as $attr) {
882
                    $name = $attr->nodeName;
883
                    $value = $attr->nodeValue;
884
                    $texto .= " $name : $value";
885
                }
886
            }
887
        }
888
        if (isset($div)) {
889
            if ($div->hasAttributes()) {
890
                foreach ($div->attributes as $attr) {
891
                    $name = $attr->nodeName;
892
                    $value = $attr->nodeValue;
893
                    $texto .= " $name : $value";
894
                }
895
            }
896
        }
897
        if (isset($entg)) {
898
            if ($entg->hasAttributes()) {
899
                foreach ($entg->attributes as $attr) {
900
                    $name = $attr->nodeName;
901
                    $value = $attr->nodeValue;
902
                    $texto .= " $name : $value";
903
                }
904
            }
905
        }
906
        if (isset($dest)) {
907
            if ($dest->hasAttributes()) {
908
                foreach ($dest->attributes as $attr) {
909
                    $name = $attr->nodeName;
910
                    $value = $attr->nodeValue;
911
                    $texto .= " $name : $value";
912
                }
913
            }
914
        }
915
        if (isset($ctl)) {
916
            if ($ctl->hasAttributes()) {
917
                foreach ($ctl->attributes as $attr) {
918
                    $name = $attr->nodeName;
919
                    $value = $attr->nodeValue;
920
                    $texto .= " $name : $value";
921
                }
922
            }
923
        }
924
        if (isset($ref)) {
925
            if ($ref->hasAttributes()) {
926
                foreach ($ref->attributes as $attr) {
927
                    $name = $attr->nodeName;
928
                    $value = $attr->nodeValue;
929
                    $texto .= " $name : $value";
930
                }
931
            }
932
        }
933
        //grupo CADATA infCpl
934
        $t = $dom->getElementsByTagName('transmissor')->item(0);
935
        $r = $dom->getElementsByTagName('receptor')->item(0);
936
        $versao = ! empty($dom->getElementsByTagName('versao')->item(0)->nodeValue) ?
937
            'Versao:'.$dom->getElementsByTagName('versao')->item(0)->nodeValue.' ' : '';
938
        $especieNF = ! empty($dom->getElementsByTagName('especieNF')->item(0)->nodeValue) ?
939
            'Especie:'.$dom->getElementsByTagName('especieNF')->item(0)->nodeValue.' ' : '';
940
        $fabEntrega = ! empty($dom->getElementsByTagName('fabEntrega')->item(0)->nodeValue) ?
941
            'Entrega:'.$dom->getElementsByTagName('fabEntrega')->item(0)->nodeValue.' ' : '';
942
        $dca = ! empty($dom->getElementsByTagName('dca')->item(0)->nodeValue) ?
943
            'dca:'.$dom->getElementsByTagName('dca')->item(0)->nodeValue.' ' : '';
944
        $texto .= "".$versao.$especieNF.$fabEntrega.$dca;
945
        if (isset($t)) {
946
            if ($t->hasAttributes()) {
947
                $texto .= " Transmissor ";
948
                foreach ($t->attributes as $attr) {
949
                    $name = $attr->nodeName;
950
                    $value = $attr->nodeValue;
951
                    $texto .= " $name : $value";
952
                }
953
            }
954
        }
955
        if (isset($r)) {
956
            if ($r->hasAttributes()) {
957
                $texto .= " Receptor ";
958
                foreach ($r->attributes as $attr) {
959
                    $name = $attr->nodeName;
960
                    $value = $attr->nodeValue;
961
                    $texto .= " $name : $value";
962
                }
963
            }
964
        }
965
        return $texto;
966
    }
967
968
    /**
969
     * Dados brutos do PDF
970
     * @return string
971
     */
972
    public function render()
973
    {
974
        return $this->pdf->getPdf();
975
    }
976
977
    protected function pNotaCancelada()
978
    {
979
        if (!isset($this->nfeProc)) {
980
            return false;
981
        }
982
        $cStat = $this->pSimpleGetValue($this->nfeProc, "cStat");
983
        return $cStat == '101' ||
984
                $cStat == '151' ||
985
                $cStat == '135' ||
986
                $cStat == '155' ||
987
                $this->situacao_externa == self::SIT_CANCELADA;
0 ignored issues
show
Bug introduced by
The property situacao_externa does not seem to exist. Did you mean situacaoExterna?

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

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

Loading history...
988
    }
989
990
    protected function pNotaDPEC()
991
    {
992
        return $this->situacao_externa == self::SIT_DPEC && $this->numero_registro_dpec != '';
0 ignored issues
show
Bug introduced by
The property situacao_externa does not seem to exist. Did you mean situacaoExterna?

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

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

Loading history...
993
    }
994
995
    protected function pNotaDenegada()
996
    {
997
        if (!isset($this->nfeProc)) {
998
            return false;
999
        }
1000
        //NÃO ERA NECESSÁRIO ESSA FUNÇÃO POIS SÓ SE USA
1001
        //1 VEZ NO ARQUIVO INTEIRO
1002
        $cStat = $this->pSimpleGetValue($this->nfeProc, "cStat");
1003
        return $cStat == '110' ||
1004
               $cStat == '301' ||
1005
               $cStat == '302' ||
1006
               $this->situacao_externa == self::SIT_DENEGADA;
0 ignored issues
show
Bug introduced by
The property situacao_externa does not seem to exist. Did you mean situacaoExterna?

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

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

Loading history...
1007
    }
1008
1009
    /**
1010
     *cabecalhoDANFE
1011
     * Monta o cabelhalho da DANFE (retrato e paisagem)
1012
     *
1013
     * @param  number $x      Posição horizontal inicial, canto esquerdo
1014
     * @param  number $y      Posição vertical inicial, canto superior
1015
     * @param  number $pag    Número da Página
1016
     * @param  number $totPag Total de páginas
1017
     * @return number Posição vertical final
1018
     */
1019
    protected function pCabecalhoDANFE($x = 0, $y = 0, $pag = '1', $totPag = '1')
1020
    {
1021
        $oldX = $x;
1022
        $oldY = $y;
1023
        if ($this->orientacao == 'P') {
1024
              $maxW = $this->wPrint;
1025
        } else {
1026
            if ($pag == 1) { // primeira página
1027
                $maxW = $this->wPrint - $this->wCanhoto;
1028
            } else { // páginas seguintes
1029
                $maxW = $this->wPrint;
1030
            }
1031
        }
1032
        //####################################################################################
1033
        //coluna esquerda identificação do emitente
1034
        $w = round($maxW*0.41, 0);
1035
        if ($this->orientacao == 'P') {
1036
            $aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>'I');
1037
        } else {
1038
            $aFont = array('font'=>$this->fontePadrao, 'size'=>8, 'style'=>'B');
1039
        }
1040
        $w1 = $w;
1041
        $h=32;
1042
        $oldY += $h;
1043
        $this->pTextBox($x, $y, $w, $h);
1044
        $texto = 'IDENTIFICAÇÃO DO EMITENTE';
1045
        $this->pTextBox($x, $y, $w, 5, $texto, $aFont, 'T', 'C', 0, '');
1046
        //estabelecer o alinhamento
1047
        //pode ser left L, center C, right R, full logo L
1048
        //se for left separar 1/3 da largura para o tamanho da imagem
1049
        //os outros 2/3 serão usados para os dados do emitente
1050
        //se for center separar 1/2 da altura para o logo e 1/2 para os dados
1051
        //se for right separa 2/3 para os dados e o terço seguinte para o logo
1052
        //se não houver logo centraliza dos dados do emitente
1053
        // coloca o logo
1054
        if (!empty($this->logomarca)) {
1055
            $logoInfo = getimagesize($this->logomarca);
1056
            $type = strtolower(explode('/', $logoInfo['mime'])[1]);
1057
            if ($type == 'png') {
1058
                $this->logomarca = $this->imagePNGtoJPG($this->logomarca);
1059
                $type == 'jpg';
1060
            }
1061
            //largura da imagem em mm
1062
            $logoWmm = ($logoInfo[0]/72)*25.4;
1063
            //altura da imagem em mm
1064
            $logoHmm = ($logoInfo[1]/72)*25.4;
1065
            if ($this->logoAlign=='L') {
1066
                $nImgW = round($w/3, 0);
1067
                $nImgH = round($logoHmm * ($nImgW/$logoWmm), 0);
1068
                $xImg = $x+1;
1069
                $yImg = round(($h-$nImgH)/2, 0)+$y;
1070
                //estabelecer posições do texto
1071
                $x1 = round($xImg + $nImgW +1, 0);
1072
                $y1 = round($h/3+$y, 0);
1073
                $tw = round(2*$w/3, 0);
1074
            } elseif ($this->logoAlign=='C') {
1075
                $nImgH = round($h/3, 0);
1076
                $nImgW = round($logoWmm * ($nImgH/$logoHmm), 0);
1077
                $xImg = round(($w-$nImgW)/2+$x, 0);
1078
                $yImg = $y+3;
1079
                $x1 = $x;
1080
                $y1 = round($yImg + $nImgH + 1, 0);
1081
                $tw = $w;
1082
            } elseif ($this->logoAlign=='R') {
1083
                $nImgW = round($w/3, 0);
1084
                $nImgH = round($logoHmm * ($nImgW/$logoWmm), 0);
1085
                $xImg = round($x+($w-(1+$nImgW)), 0);
1086
                $yImg = round(($h-$nImgH)/2, 0)+$y;
1087
                $x1 = $x;
1088
                $y1 = round($h/3+$y, 0);
1089
                $tw = round(2*$w/3, 0);
1090
            } elseif ($this->logoAlign=='F') {
1091
                $nImgH = round($h-5, 0);
1092
                $nImgW = round($logoWmm * ($nImgH/$logoHmm), 0);
1093
                $xImg = round(($w-$nImgW)/2+$x, 0);
1094
                $yImg = $y+3;
1095
                $x1 = $x;
1096
                $y1 = round($yImg + $nImgH + 1, 0);
1097
                $tw = $w;
1098
            }
1099
            $type = (substr($this->logomarca, 0, 7) === 'data://') ? 'jpg' : null;
1100
            $this->pdf->Image($this->logomarca, $xImg, $yImg, $nImgW, $nImgH, $type);
0 ignored issues
show
Bug introduced by
The variable $xImg does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
Bug introduced by
The variable $yImg does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
Bug introduced by
The variable $nImgW does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
Bug introduced by
The variable $nImgH does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
1101
        } else {
1102
            $x1 = $x;
1103
            $y1 = round($h/3+$y, 0);
1104
            $tw = $w;
1105
        }
1106
        // monta as informações apenas se diferente de full logo
1107
        if ($this->logoAlign !== 'F') {
1108
            //Nome emitente
1109
            $aFont = array('font'=>$this->fontePadrao, 'size'=>12, 'style'=>'B');
1110
            $texto = $this->emit->getElementsByTagName("xNome")->item(0)->nodeValue;
1111
            $this->pTextBox($x1, $y1, $tw, 8, $texto, $aFont, 'T', 'C', 0, '');
0 ignored issues
show
Bug introduced by
The variable $x1 does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
Bug introduced by
The variable $y1 does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
Bug introduced by
The variable $tw does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
1112
            //endereço
1113
            $y1 = $y1+5;
1114
            $aFont = array('font'=>$this->fontePadrao, 'size'=>8, 'style'=>'');
1115
            $fone = ! empty($this->enderEmit->getElementsByTagName("fone")->item(0)->nodeValue)
1116
                 ? $this->enderEmit->getElementsByTagName("fone")->item(0)->nodeValue
1117
                 : '';
1118
            $lgr = $this->pSimpleGetValue($this->enderEmit, "xLgr");
1119
            $nro = $this->pSimpleGetValue($this->enderEmit, "nro");
1120
            $cpl = $this->pSimpleGetValue($this->enderEmit, "xCpl", " - ");
1121
            $bairro = $this->pSimpleGetValue($this->enderEmit, "xBairro");
1122
            $CEP = $this->pSimpleGetValue($this->enderEmit, "CEP");
1123
            $CEP = $this->pFormat($CEP, "#####-###");
1124
            $mun = $this->pSimpleGetValue($this->enderEmit, "xMun");
1125
            $UF = $this->pSimpleGetValue($this->enderEmit, "UF");
1126
            $texto = $lgr . ", " . $nro . $cpl . "\n" . $bairro . " - "
1127
                    . $CEP . "\n" . $mun . " - " . $UF . " "
1128
                    . "Fone/Fax: " . $fone;
1129
            $this->pTextBox($x1, $y1, $tw, 8, $texto, $aFont, 'T', 'C', 0, '');
1130
        }
1131
1132
        //####################################################################################
1133
        //coluna central Danfe
1134
        $x += $w;
1135
        $w=round($maxW * 0.17, 0);//35;
1136
        $w2 = $w;
1137
        $h = 32;
1138
        $this->pTextBox($x, $y, $w, $h);
1139
1140
        if (! $this->pNotaCancelada()) {
1141
            // A PRINCIPIO NÃO PRECISAVA, POIS A NFE ESTÁ AUTORIZADA,
1142
            // SÓ SE RETIRA O DANFE PARA NOTAS NÃO AUTORIZADAS
1143
            $texto = "DANFE";
1144
            $aFont = array('font'=>$this->fontePadrao, 'size'=>14, 'style'=>'B');
1145
            $this->pTextBox($x, $y+1, $w, $h, $texto, $aFont, 'T', 'C', 0, '');
1146
            $aFont = array('font'=>$this->fontePadrao, 'size'=>8, 'style'=>'');
1147
            $texto = 'Documento Auxiliar da Nota Fiscal Eletrônica';
1148
            $h = 20;
1149
            $this->pTextBox($x, $y+6, $w, $h, $texto, $aFont, 'T', 'C', 0, '', false);
1150
        }
1151
1152
        $aFont = array('font'=>$this->fontePadrao, 'size'=>8, 'style'=>'');
1153
        $texto = '0 - ENTRADA';
1154
        $y1 = $y + 14;
1155
        $h = 8;
1156
        $this->pTextBox($x+2, $y1, $w, $h, $texto, $aFont, 'T', 'L', 0, '');
1157
        $texto = '1 - SAÍDA';
1158
        $y1 = $y + 17;
1159
        $this->pTextBox($x+2, $y1, $w, $h, $texto, $aFont, 'T', 'L', 0, '');
1160
        //tipo de nF
1161
        $aFont = array('font'=>$this->fontePadrao, 'size'=>12, 'style'=>'B');
1162
        $y1 = $y + 13;
1163
        $h = 7;
1164
        $texto = $this->ide->getElementsByTagName('tpNF')->item(0)->nodeValue;
1165
        $this->pTextBox($x+27, $y1, 5, $h, $texto, $aFont, 'C', 'C', 1, '');
1166
        //numero da NF
1167
        $aFont = array('font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B');
1168
        $y1 = $y + 20;
1169
        $numNF = str_pad($this->ide->getElementsByTagName('nNF')->item(0)->nodeValue, 9, "0", STR_PAD_LEFT);
1170
        $numNF = $this->pFormat($numNF, "###.###.###");
1171
        $texto = "Nº. " . $numNF;
1172
        $this->pTextBox($x, $y1, $w, $h, $texto, $aFont, 'C', 'C', 0, '');
1173
        //Série
1174
        $y1 = $y + 23;
1175
        $serie = str_pad($this->ide->getElementsByTagName('serie')->item(0)->nodeValue, 3, "0", STR_PAD_LEFT);
1176
        $texto = "Série " . $serie;
1177
        $this->pTextBox($x, $y1, $w, $h, $texto, $aFont, 'C', 'C', 0, '');
1178
        //numero paginas
1179
        $aFont = array('font'=>$this->fontePadrao, 'size'=>8, 'style'=>'I');
1180
        $y1 = $y + 26;
1181
        $texto = "Folha " . $pag . "/" . $totPag;
1182
        $this->pTextBox($x, $y1, $w, $h, $texto, $aFont, 'C', 'C', 0, '');
1183
1184
        //####################################################################################
1185
        //coluna codigo de barras
1186
        $x += $w;
1187
        $w = ($maxW-$w1-$w2);//85;
1188
        $w3 = $w;
1189
        $h = 32;
1190
        $this->pTextBox($x, $y, $w, $h);
1191
        $this->pdf->SetFillColor(0, 0, 0);
1192
        $chave_acesso = str_replace('NFe', '', $this->infNFe->getAttribute("Id"));
1193
        $bW = 75;
1194
        $bH = 12;
1195
        //codigo de barras
1196
        $this->pdf->Code128($x+(($w-$bW)/2), $y+2, $chave_acesso, $bW, $bH);
1197
        //linhas divisorias
1198
        $this->pdf->Line($x, $y+4+$bH, $x+$w, $y+4+$bH);
1199
        $this->pdf->Line($x, $y+12+$bH, $x+$w, $y+12+$bH);
1200
        $aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>'');
1201
        $y1 = $y+4+$bH;
1202
        $h = 7;
1203
        $texto = 'CHAVE DE ACESSO';
1204
        $this->pTextBox($x, $y1, $w, $h, $texto, $aFont, 'T', 'L', 0, '');
1205
        $aFont = array('font'=>$this->fontePadrao, 'size'=>8, 'style'=>'B');
1206
        $y1 = $y+8+$bH;
1207
        $texto = $this->pFormat($chave_acesso, $this->formatoChave);
1208
        $this->pTextBox($x+2, $y1, $w-2, $h, $texto, $aFont, 'T', 'C', 0, '');
1209
        $y1 = $y+12+$bH;
1210
        $aFont = array('font'=>$this->fontePadrao, 'size'=>8, 'style'=>'');
1211
        $chaveContingencia="";
1212
        if ($this->pNotaDPEC()) {
1213
            $cabecalhoProtoAutorizacao = 'NÚMERO DE REGISTRO DPEC';
1214
        } else {
1215
            $cabecalhoProtoAutorizacao = 'PROTOCOLO DE AUTORIZAÇÃO DE USO';
1216
        }
1217
        if (($this->tpEmis == 2 || $this->tpEmis == 5) && !$this->pNotaDPEC()) {
1218
            $cabecalhoProtoAutorizacao = "DADOS DA NF-E";
1219
            $chaveContingencia = $this->pGeraChaveAdicionalDeContingencia();
1220
            $this->pdf->SetFillColor(0, 0, 0);
1221
            //codigo de barras
1222
            $this->pdf->Code128($x+11, $y1+1, $chaveContingencia, $bW*.9, $bH/2);
1223
        } else {
1224
            $texto = 'Consulta de autenticidade no portal nacional da NF-e';
1225
            $this->pTextBox($x+2, $y1, $w-2, $h, $texto, $aFont, 'T', 'C', 0, '');
1226
            $y1 = $y+16+$bH;
1227
            $texto = 'www.nfe.fazenda.gov.br/portal ou no site da Sefaz Autorizadora';
1228
            $this->pTextBox(
1229
                $x+2,
1230
                $y1,
1231
                $w-2,
1232
                $h,
1233
                $texto,
1234
                $aFont,
1235
                'T',
1236
                'C',
1237
                0,
1238
                'http://www.nfe.fazenda.gov.br/portal ou no site da Sefaz Autorizadora'
1239
            );
1240
        }
1241
1242
        //####################################################################################
1243
        //Dados da NF do cabeçalho
1244
        //natureza da operação
1245
        $texto = 'NATUREZA DA OPERAÇÃO';
1246
        $aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>'');
1247
        $w = $w1+$w2;
1248
        $y = $oldY;
1249
        $oldY += $h;
1250
        $x = $oldX;
1251
        $h = 7;
1252
        $this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 1, '');
1253
        $texto = $this->ide->getElementsByTagName("natOp")->item(0)->nodeValue;
1254
        $aFont = array('font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B');
1255
        $this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'B', 'C', 0, '');
1256
        $x += $w;
1257
        $w = $w3;
1258
        //PROTOCOLO DE AUTORIZAÇÃO DE USO ou DADOS da NF-E
1259
        $aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>'');
1260
        $this->pTextBox($x, $y, $w, $h, $cabecalhoProtoAutorizacao, $aFont, 'T', 'L', 1, '');
1261
        // algumas NFe podem estar sem o protocolo de uso portanto sua existencia deve ser
1262
        // testada antes de tentar obter a informação.
1263
        // NOTA : DANFE sem protocolo deve existir somente no caso de contingência !!!
1264
        // Além disso, existem várias NFes em contingência que eu recebo com protocolo de autorização.
1265
        // Na minha opinião, deveríamos mostra-lo, mas o  manual  da NFe v4.01 diz outra coisa...
1266
        if (($this->tpEmis == 2 || $this->tpEmis == 5) && !$this->pNotaDPEC()) {
1267
            $aFont = array('font'=>$this->fontePadrao, 'size'=>8, 'style'=>'B');
1268
            $texto = $this->pFormat($chaveContingencia, "#### #### #### #### #### #### #### #### ####");
1269
            $cStat = '';
0 ignored issues
show
Unused Code introduced by
$cStat is not used, you could remove the assignment.

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

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

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

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

Loading history...
1270
        } else {
1271
            $aFont = array('font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B');
1272
            if ($this->pNotaDPEC()) {
1273
                $texto = $this->numero_registro_dpec;
1274
                $cStat = '';
0 ignored issues
show
Unused Code introduced by
$cStat is not used, you could remove the assignment.

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

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

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

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

Loading history...
1275
            } else {
1276
                if (isset($this->nfeProc)) {
1277
                    $texto = ! empty($this->nfeProc->getElementsByTagName("nProt")->item(0)->nodeValue) ?
1278
                            $this->nfeProc->getElementsByTagName("nProt")->item(0)->nodeValue : '';
1279
                    $tsHora = $this->pConvertTime($this->nfeProc->getElementsByTagName("dhRecbto")->item(0)->nodeValue);
1280
                    if ($texto != '') {
1281
                        $texto .= "  -  " . date('d/m/Y H:i:s', $tsHora);
1282
                    }
1283
                    $cStat = $this->nfeProc->getElementsByTagName("cStat")->item(0)->nodeValue;
0 ignored issues
show
Unused Code introduced by
$cStat is not used, you could remove the assignment.

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

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

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

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

Loading history...
1284
                } else {
1285
                    $texto = '';
1286
                    $cStat = '';
0 ignored issues
show
Unused Code introduced by
$cStat is not used, you could remove the assignment.

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

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

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

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

Loading history...
1287
                }
1288
            }
1289
        }
1290
        $this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'B', 'C', 0, '');
1291
        //####################################################################################
1292
        //INSCRIÇÃO ESTADUAL
1293
        $w = round($maxW * 0.333, 0);
1294
        $y += $h;
1295
        $oldY += $h;
1296
        $x = $oldX;
1297
        $texto = 'INSCRIÇÃO ESTADUAL';
1298
        $aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>'');
1299
        $this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 1, '');
1300
        $texto = $this->pSimpleGetValue($this->emit, "IE");
1301
        $aFont = array('font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B');
1302
        $this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'B', 'C', 0, '');
1303
        //INSCRIÇÃO ESTADUAL DO SUBST. TRIBUT.
1304
        $x += $w;
1305
        $texto = 'INSCRIÇÃO ESTADUAL DO SUBST. TRIBUT.';
1306
        $aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>'');
1307
        $this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 1, '');
1308
        $texto = ! empty($this->emit->getElementsByTagName("IEST")->item(0)->nodeValue)
1309
             ? $this->emit->getElementsByTagName("IEST")->item(0)->nodeValue
1310
             : '';
1311
        $aFont = array('font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B');
1312
        $this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'B', 'C', 0, '');
1313
        //CNPJ
1314
        $x += $w;
1315
        $w = ($maxW-(2*$w));
1316
        $texto = 'CNPJ / CPF';
1317
        $aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>'');
1318
        $this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 1, '');
1319
        //Pegando valor do CPF/CNPJ
1320
        if (! empty($this->emit->getElementsByTagName("CNPJ")->item(0)->nodeValue)) {
1321
            $texto = $this->pFormat(
1322
                $this->emit->getElementsByTagName("CNPJ")->item(0)->nodeValue,
1323
                "###.###.###/####-##"
1324
            );
1325
        } else {
1326
            $texto = ! empty($this->emit->getElementsByTagName("CPF")->item(0)->nodeValue) ?
1327
                $this->pFormat(
1328
                    $this->emit->getElementsByTagName("CPF")->item(0)->nodeValue,
1329
                    "###.###.###-##"
1330
                ) : '';
1331
        }
1332
        $aFont = array('font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B');
1333
        $this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'B', 'C', 0, '');
1334
1335
        //####################################################################################
1336
        //Indicação de NF Homologação, cancelamento e falta de protocolo
1337
        $tpAmb = $this->ide->getElementsByTagName('tpAmb')->item(0)->nodeValue;
1338
        //indicar cancelamento
1339
        if ($this->pNotaCancelada()) {
1340
            //101 Cancelamento
1341
            $x = 10;
1342
            $y = $this->hPrint-130;
1343
            $h = 25;
1344
            $w = $maxW-(2*$x);
1345
            $this->pdf->SetTextColor(90, 90, 90);
1346
            $texto = "NFe CANCELADA";
1347
            $aFont = array('font'=>$this->fontePadrao, 'size'=>48, 'style'=>'B');
1348
            $this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'C', 'C', 0, '');
1349
            $this->pdf->SetTextColor(0, 0, 0);
1350
        }
1351
1352
        if ($this->pNotaDPEC() || $this->tpEmis == 4) {
1353
            //DPEC
1354
            $x = 10;
1355
            $y = $this->hPrint-130;
1356
            $h = 25;
1357
            $w = $maxW-(2*$x);
1358
            $this->pdf->SetTextColor(200, 200, 200);
1359
            $texto = "DANFE impresso em contingência -\n".
1360
                     "DPEC regularmente recebido pela Receita\n".
1361
                     "Federal do Brasil";
1362
            $aFont = array('font'=>$this->fontePadrao, 'size'=>48, 'style'=>'B');
1363
            $this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'C', 'C', 0, '');
1364
            $this->pdf->SetTextColor(0, 0, 0);
1365
        }
1366
        if ($this->pNotaDenegada()) {
1367
            //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...
1368
            $x = 10;
1369
            $y = $this->hPrint-130;
1370
            $h = 25;
1371
            $w = $maxW-(2*$x);
1372
            $this->pdf->SetTextColor(90, 90, 90);
1373
            $texto = "NFe USO DENEGADO";
1374
            $aFont = array('font'=>$this->fontePadrao, 'size'=>48, 'style'=>'B');
1375
            $this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'C', 'C', 0, '');
1376
            $y += $h;
1377
            $h = 5;
1378
            $w = $maxW-(2*$x);
1379
            if (isset($this->infProt)) {
1380
                $xMotivo = $this->infProt->getElementsByTagName("xMotivo")->item(0)->nodeValue;
1381
            } else {
1382
                $xMotivo = '';
1383
            }
1384
            $texto = "SEM VALOR FISCAL\n".$xMotivo;
1385
            $aFont = array('font'=>$this->fontePadrao, 'size'=>48, 'style'=>'B');
1386
            $this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'C', 'C', 0, '');
1387
            $this->pdf->SetTextColor(0, 0, 0);
1388
        }
1389
        //indicar sem valor
1390
        if ($tpAmb != 1) {
1391
            $x = 10;
1392
            if ($this->orientacao == 'P') {
1393
                $y = round($this->hPrint*2/3, 0);
1394
            } else {
1395
                $y = round($this->hPrint/2, 0);
1396
            }
1397
            $h = 5;
1398
            $w = $maxW-(2*$x);
1399
            $this->pdf->SetTextColor(90, 90, 90);
1400
            $texto = "SEM VALOR FISCAL";
1401
            $aFont = array('font'=>$this->fontePadrao, 'size'=>48, 'style'=>'B');
1402
            $this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'C', 'C', 0, '');
1403
            $aFont = array('font'=>$this->fontePadrao, 'size'=>30, 'style'=>'B');
1404
            $texto = "AMBIENTE DE HOMOLOGAÇÃO";
1405
            $this->pTextBox($x, $y+14, $w, $h, $texto, $aFont, 'C', 'C', 0, '');
1406
            $this->pdf->SetTextColor(0, 0, 0);
1407
        } else {
1408
            $x = 10;
1409
            if ($this->orientacao == 'P') {
1410
                $y = round($this->hPrint*2/3, 0);
1411
            } else {
1412
                $y = round($this->hPrint/2, 0);
1413
            }//fim orientacao
1414
            $h = 5;
1415
            $w = $maxW-(2*$x);
1416
            $this->pdf->SetTextColor(90, 90, 90);
1417
            //indicar FALTA DO PROTOCOLO se NFe não for em contingência
1418
            if (($this->tpEmis == 2 || $this->tpEmis == 5) && !$this->pNotaDPEC()) {
1419
                //Contingência
1420
                $texto = "DANFE Emitido em Contingência";
1421
                $aFont = array('font'=>$this->fontePadrao, 'size'=>48, 'style'=>'B');
1422
                $this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'C', 'C', 0, '');
1423
                $aFont = array('font'=>$this->fontePadrao, 'size'=>30, 'style'=>'B');
1424
                $texto = "devido à problemas técnicos";
1425
                $this->pTextBox($x, $y+12, $w, $h, $texto, $aFont, 'C', 'C', 0, '');
1426
            } else {
1427
                if (!isset($this->nfeProc)) {
1428
                    if (!$this->pNotaDPEC()) {
1429
                        $texto = "SEM VALOR FISCAL";
1430
                        $aFont = array('font'=>$this->fontePadrao, 'size'=>48, 'style'=>'B');
1431
                        $this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'C', 'C', 0, '');
1432
                    }
1433
                    $aFont = array('font'=>$this->fontePadrao, 'size'=>30, 'style'=>'B');
1434
                    $texto = "FALTA PROTOCOLO DE APROVAÇÃO DA SEFAZ";
1435
                    if (!$this->pNotaDPEC()) {
1436
                        $this->pTextBox($x, $y+12, $w, $h, $texto, $aFont, 'C', 'C', 0, '');
1437
                    } else {
1438
                        $this->pTextBox($x, $y+25, $w, $h, $texto, $aFont, 'C', 'C', 0, '');
1439
                    }
1440
                }//fim nefProc
1441
            }//fim tpEmis
1442
            $this->pdf->SetTextColor(0, 0, 0);
1443
        }
1444
        return $oldY;
1445
    } //fim cabecalhoDANFE
1446
1447
    /**
1448
     * destinatarioDANFE
1449
     * Monta o campo com os dados do destinatário na DANFE. (retrato e paisagem)
1450
     *
1451
     * @name   destinatarioDANFE
1452
     * @param  number $x Posição horizontal canto esquerdo
1453
     * @param  number $y Posição vertical canto superior
1454
     * @return number Posição vertical final
1455
     */
1456
    protected function pDestinatarioDANFE($x = 0, $y = 0)
1457
    {
1458
        //####################################################################################
1459
        //DESTINATÁRIO / REMETENTE
1460
        $oldX = $x;
1461
        $oldY = $y;
0 ignored issues
show
Unused Code introduced by
$oldY is not used, you could remove the assignment.

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

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

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

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

Loading history...
1462
        if ($this->orientacao == 'P') {
1463
            $maxW = $this->wPrint;
1464
        } else {
1465
            $maxW = $this->wPrint - $this->wCanhoto;
1466
        }
1467
        $w = $maxW;
1468
        $h = 7;
1469
        $texto = 'DESTINATÁRIO / REMETENTE';
1470
        $aFont = array('font'=>$this->fontePadrao, 'size'=>7, 'style'=>'B');
1471
        $this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 0, '');
1472
        //NOME / RAZÃO SOCIAL
1473
        $w = round($maxW*0.61, 0);
1474
        $w1 = $w;
1475
        $y += 3;
1476
        $texto = 'NOME / RAZÃO SOCIAL';
1477
        $aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>'');
1478
        $this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 1, '');
1479
        $texto = $this->dest->getElementsByTagName("xNome")->item(0)->nodeValue;
1480
        $aFont = array('font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B');
1481
        if ($this->orientacao == 'P') {
1482
            $this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'B', 'L', 0, '');
1483
        } else {
1484
            $this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'B', 'L', 1, '');
1485
        }
1486
        //CNPJ / CPF
1487
        $x += $w;
1488
        $w = round($maxW*0.23, 0);
1489
        $w2 = $w;
1490
        $texto = 'CNPJ / CPF';
1491
        $aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>'');
1492
        $this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 1, '');
1493
        //Pegando valor do CPF/CNPJ
1494
        if (! empty($this->dest->getElementsByTagName("CNPJ")->item(0)->nodeValue)) {
1495
            $texto = $this->pFormat(
1496
                $this->dest->getElementsByTagName("CNPJ")->item(0)->nodeValue,
1497
                "###.###.###/####-##"
1498
            );
1499
        } else {
1500
            $texto = ! empty($this->dest->getElementsByTagName("CPF")->item(0)->nodeValue) ?
1501
                    $this->pFormat(
1502
                        $this->dest->getElementsByTagName("CPF")->item(0)->nodeValue,
1503
                        "###.###.###-##"
1504
                    ) : '';
1505
        }
1506
        $aFont = array('font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B');
1507
        $this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'B', 'C', 0, '');
1508
        //DATA DA EMISSÃO
1509
        $x += $w;
1510
        $w = $maxW-($w1+$w2);
1511
        $wx = $w;
1512
        $texto = 'DATA DA EMISSÃO';
1513
        $aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>'');
1514
        $this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 1, '');
1515
        $dEmi = ! empty($this->ide->getElementsByTagName("dEmi")->item(0)->nodeValue) ?
1516
                $this->ide->getElementsByTagName("dEmi")->item(0)->nodeValue : '';
1517
        if ($dEmi == '') {
1518
            $dEmi = ! empty($this->ide->getElementsByTagName("dhEmi")->item(0)->nodeValue) ?
1519
                    $this->ide->getElementsByTagName("dhEmi")->item(0)->nodeValue : '';
1520
            $aDemi = explode('T', $dEmi);
1521
            $dEmi = $aDemi[0];
1522
        }
1523
        $texto = $this->pYmd2dmy($dEmi);
1524
        $aFont = array('font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B');
1525
        if ($this->orientacao == 'P') {
1526
            $this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'B', 'C', 0, '');
1527
        } else {
1528
            $this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'B', 'C', 1, '');
1529
        }
1530
        //ENDEREÇO
1531
        $w = round($maxW*0.47, 0);
1532
        $w1 = $w;
1533
        $y += $h;
1534
        $x = $oldX;
1535
        $texto = 'ENDEREÇO';
1536
        $aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>'');
1537
        $this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 1, '');
1538
        $texto = $this->dest->getElementsByTagName("xLgr")->item(0)->nodeValue;
1539
        $texto .= ', ' . $this->dest->getElementsByTagName("nro")->item(0)->nodeValue;
1540
        $texto .= $this->pSimpleGetValue($this->dest, "xCpl", " - ");
1541
1542
        $aFont = array('font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B');
1543
        $this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'B', 'L', 0, '', true);
1544
        //BAIRRO / DISTRITO
1545
        $x += $w;
1546
        $w = round($maxW*0.21, 0);
1547
        $w2 = $w;
1548
        $texto = 'BAIRRO / DISTRITO';
1549
        $aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>'');
1550
        $this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 1, '');
1551
        $texto = $this->dest->getElementsByTagName("xBairro")->item(0)->nodeValue;
1552
        $aFont = array('font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B');
1553
        $this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'B', 'C', 0, '');
1554
        //CEP
1555
        $x += $w;
1556
        $w = $maxW-$w1-$w2-$wx;
1557
        $w2 = $w;
0 ignored issues
show
Unused Code introduced by
$w2 is not used, you could remove the assignment.

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

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

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

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

Loading history...
1558
        $texto = 'CEP';
1559
        $aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>'');
1560
        $this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 1, '');
1561
        $texto = ! empty($this->dest->getElementsByTagName("CEP")->item(0)->nodeValue) ?
1562
                $this->dest->getElementsByTagName("CEP")->item(0)->nodeValue : '';
1563
        $texto = $this->pFormat($texto, "#####-###");
1564
        $aFont = array('font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B');
1565
        $this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'B', 'C', 0, '');
1566
        //DATA DA SAÍDA
1567
        $x += $w;
1568
        $w = $wx;
1569
        $texto = 'DATA DA SAÍDA/ENTRADA';
1570
        $aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>'');
1571
        $this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 1, '');
1572
        $dSaiEnt = ! empty($this->ide->getElementsByTagName("dSaiEnt")->item(0)->nodeValue) ?
1573
                $this->ide->getElementsByTagName("dSaiEnt")->item(0)->nodeValue : '';
1574
        if ($dSaiEnt == '') {
1575
            $dSaiEnt = ! empty($this->ide->getElementsByTagName("dhSaiEnt")->item(0)->nodeValue) ?
1576
                    $this->ide->getElementsByTagName("dhSaiEnt")->item(0)->nodeValue : '';
1577
            $aDsaient = explode('T', $dSaiEnt);
1578
            $dSaiEnt = $aDsaient[0];
1579
        }
1580
        $texto = $this->pYmd2dmy($dSaiEnt);
1581
        $aFont = array('font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B');
1582
        $this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'B', 'C', 0, '');
1583
        //MUNICÍPIO
1584
        $w = $w1;
1585
        $y += $h;
1586
        $x = $oldX;
1587
        $texto = 'MUNICÍPIO';
1588
        $aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>'');
1589
        $this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 1, '');
1590
        $texto = $this->dest->getElementsByTagName("xMun")->item(0)->nodeValue;
1591
        if (strtoupper(trim($texto)) == "EXTERIOR" && $this->dest->getElementsByTagName("xPais")->length > 0) {
1592
            $texto .= " - " .  $this->dest->getElementsByTagName("xPais")->item(0)->nodeValue;
1593
        }
1594
        $aFont = array('font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B');
1595
        $this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'B', 'L', 0, '');
1596
        //UF
1597
        $x += $w;
1598
        $w = 8;
1599
        $texto = 'UF';
1600
        $aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>'');
1601
        $this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 1, '');
1602
        $texto = $this->dest->getElementsByTagName("UF")->item(0)->nodeValue;
1603
        $aFont = array('font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B');
1604
        $this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'B', 'C', 0, '');
1605
        //FONE / FAX
1606
        $x += $w;
1607
        $w = round(($maxW -$w1-$wx-8)/2, 0);
1608
        $w3 = $w;
1609
        $texto = 'FONE / FAX';
1610
        $aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>'');
1611
        $this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 1, '');
1612
        $texto = ! empty($this->dest->getElementsByTagName("fone")->item(0)->nodeValue) ?
1613
                $this->dest->getElementsByTagName("fone")->item(0)->nodeValue : '';
1614
        $aFont = array('font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B');
1615
        $this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'B', 'C', 0, '');
1616
        //INSCRIÇÃO ESTADUAL
1617
        $x += $w;
1618
        $w = $maxW -$w1-$wx-8-$w3;
1619
        $texto = 'INSCRIÇÃO ESTADUAL';
1620
        $aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>'');
1621
        $this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 1, '');
1622
        $IE = $this->dest->getElementsByTagName("IE");
1623
        $texto = ($IE && $IE->length > 0) ? $IE->item(0)->nodeValue : '';
1624
        $aFont = array('font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B');
1625
        $this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'B', 'C', 0, '');
1626
        //HORA DA SAÍDA
1627
        $x += $w;
1628
        $w = $wx;
1629
        $texto = 'HORA DA SAÍDA/ENTRADA';
1630
        $aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>'');
1631
        $this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 1, '');
1632
        $hSaiEnt = ! empty($this->ide->getElementsByTagName("hSaiEnt")->item(0)->nodeValue) ?
1633
                $this->ide->getElementsByTagName("hSaiEnt")->item(0)->nodeValue : '';
1634
        if ($hSaiEnt == '') {
1635
            $dhSaiEnt = ! empty($this->ide->getElementsByTagName("dhSaiEnt")->item(0)->nodeValue) ?
1636
                    $this->ide->getElementsByTagName("dhSaiEnt")->item(0)->nodeValue : '';
1637
            $tsDhSaiEnt = $this->pConvertTime($dhSaiEnt);
1638
            if ($tsDhSaiEnt != '') {
1639
                $hSaiEnt = date('H:i:s', $tsDhSaiEnt);
1640
            }
1641
        }
1642
        $texto = $hSaiEnt;
1643
        $aFont = array('font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B');
1644
        $this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'B', 'C', 0, '');
1645
        return ($y + $h);
1646
    } //fim da função destinatarioDANFE
1647
1648
     /**
1649
     * pGetTextoFatura
1650
     * Gera a String do Texto da Fatura
1651
      *
1652
     * @name   getTextoFatura
1653
     * @return uma String com o texto ou "";
1654
     */
1655
    protected function pGetTextoFatura()
1656
    {
1657
        if (isset($this->cobr)) {
1658
            $fat = $this->cobr->getElementsByTagName("fat")->item(0);
1659
            if (isset($fat)) {
1660
                if (!empty($this->pSimpleGetValue($this->ide, "indPag"))) {
1661
                    $textoIndPag = "";
1662
                    $indPag = $this->pSimpleGetValue($this->ide, "indPag");
1663
                    if ($indPag === "0") {
1664
                        $textoIndPag = "Pagamento à Vista - ";
1665
                    } elseif ($indPag === "1") {
1666
                        $textoIndPag = "Pagamento à Prazo - ";
1667
                    }
1668
                    $nFat = $this->pSimpleGetValue($fat, "nFat", "Fatura: ");
1669
                    $vOrig = $this->pSimpleGetValue($fat, "vOrig", " Valor Original: ");
1670
                    $vDesc = $this->pSimpleGetValue($fat, "vDesc", " Desconto: ");
1671
                    $vLiq = $this->pSimpleGetValue($fat, "vLiq", " Valor Líquido: ");
1672
                    $texto = $textoIndPag . $nFat . $vOrig . $vDesc . $vLiq;
1673
                    return $texto;
1674
                } else {
1675
                    $pag = $this->dom->getElementsByTagName("pag");
1676
                    if ($tPag = $this->pSimpleGetValue($pag->item(0), "tPag")) {
1677
                        return $this->tipoPag($tPag);
1678
                    }
1679
                }
1680
            }
1681
        }
1682
        return "";
1683
    } //fim getTextoFatura
1684
1685
     /**
1686
     * pSizeExtraTextoFatura
1687
     * Calcula o espaço ocupado pelo texto da fatura. Este espaço só é utilizado quando não houver duplicata.
1688
      *
1689
     * @name   pSizeExtraTextoFatura
1690
     * @return integer
1691
     */
1692
    protected function pSizeExtraTextoFatura()
1693
    {
1694
        $textoFatura = $this->pGetTextoFatura();
1695
        //verificar se existem duplicatas
1696
        if ($this->dup->length == 0 && $textoFatura !== "") {
1697
            return 10;
1698
        }
1699
        return 0;
1700
    }
1701
1702
    /**
1703
     * faturaDANFE
1704
     * Monta o campo de duplicatas da DANFE (retrato e paisagem)
1705
     *
1706
     * @name   faturaDANFE
1707
     * @param  number $x Posição horizontal canto esquerdo
1708
     * @param  number $y Posição vertical canto superior
1709
     * @return number Posição vertical final
1710
     */
1711
    protected function pFaturaDANFE($x, $y)
1712
    {
1713
        $linha = 1;
1714
        $h = 8+3;
0 ignored issues
show
Unused Code introduced by
$h is not used, you could remove the assignment.

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

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

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

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

Loading history...
1715
        $oldx = $x;
1716
        $textoFatura = $this->pGetTextoFatura();
1717
        //verificar se existem duplicatas
1718
        if ($this->dup->length > 0 || $textoFatura !== "") {
1719
            //#####################################################################
1720
            //FATURA / DUPLICATA
1721
            $texto = "FATURA / DUPLICATA";
1722
            if ($this->orientacao == 'P') {
1723
                $w = $this->wPrint;
1724
            } else {
1725
                $w = 271;
1726
            }
1727
            $h = 8;
1728
            $aFont = array('font'=>$this->fontePadrao, 'size'=>7, 'style'=>'B');
1729
            $this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 0, '');
1730
            $y += 3;
1731
            $dups = "";
0 ignored issues
show
Unused Code introduced by
$dups is not used, you could remove the assignment.

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

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

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

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

Loading history...
1732
            $dupcont = 0;
1733
            $nFat = $this->dup->length;
0 ignored issues
show
Unused Code introduced by
$nFat is not used, you could remove the assignment.

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

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

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

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

Loading history...
1734
            if ($textoFatura !== "" && $this->exibirTextoFatura) {
1735
                $myH=6;
1736
                $myW = $this->wPrint;
1737
                if ($this->orientacao == 'L') {
1738
                    $myW -= $this->wCanhoto;
1739
                }
1740
                $aFont = array('font'=>$this->fontePadrao, 'size'=>8, 'style'=>'');
1741
                $this->pTextBox($x, $y, $myW, $myH, $textoFatura, $aFont, 'C', 'L', 1, '');
1742
                $y+=$myH+1;
1743
            }
1744
            if ($this->orientacao == 'P') {
1745
                $w = round($this->wPrint/7.018, 0)-1;
1746
            } else {
1747
                $w = 28;
1748
            }
1749
            $increm = 1;
1750
            foreach ($this->dup as $k => $d) {
1751
                $nDup = ! empty($this->dup->item($k)->getElementsByTagName('nDup')->item(0)->nodeValue) ?
1752
                        $this->dup->item($k)->getElementsByTagName('nDup')->item(0)->nodeValue : '';
1753
                $dDup = ! empty($this->dup->item($k)->getElementsByTagName('dVenc')->item(0)->nodeValue) ?
1754
                        $this->pYmd2dmy($this->dup->item($k)->getElementsByTagName('dVenc')->item(0)->nodeValue) : '';
1755
                $vDup = ! empty($this->dup->item($k)->getElementsByTagName('vDup')->item(0)->nodeValue) ?
1756
                        'R$ ' . number_format(
1757
                            $this->dup->item($k)->getElementsByTagName('vDup')->item(0)->nodeValue,
1758
                            2,
1759
                            ",",
1760
                            "."
1761
                        ) : '';
1762
                $h = 8;
1763
                $texto = '';
0 ignored issues
show
Unused Code introduced by
$texto is not used, you could remove the assignment.

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

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

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

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

Loading history...
1764
                if ($nDup!='0' && $nDup!='') {
1765
                    $aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>'');
1766
                    $this->pTextBox($x, $y, $w, $h, 'Num.', $aFont, 'T', 'L', 1, '');
1767
                    $aFont = array('font'=>$this->fontePadrao, 'size'=>7, 'style'=>'B');
1768
                    $this->pTextBox($x, $y, $w, $h, $nDup, $aFont, 'T', 'R', 0, '');
1769
                } else {
1770
                    $aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>'');
1771
                    $this->pTextBox($x, $y, $w, $h, ($dupcont+1)."", $aFont, 'T', 'L', 1, '');
1772
                }
1773
                $aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>'');
1774
                $this->pTextBox($x, $y, $w, $h, 'Venc.', $aFont, 'C', 'L', 0, '');
1775
                $aFont = array('font'=>$this->fontePadrao, 'size'=>7, 'style'=>'B');
1776
                $this->pTextBox($x, $y, $w, $h, $dDup, $aFont, 'C', 'R', 0, '');
1777
                $aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>'');
1778
                $this->pTextBox($x, $y, $w, $h, 'Valor', $aFont, 'B', 'L', 0, '');
1779
                $aFont = array('font'=>$this->fontePadrao, 'size'=>7, 'style'=>'B');
1780
                $this->pTextBox($x, $y, $w, $h, $vDup, $aFont, 'B', 'R', 0, '');
1781
                $x += $w+$increm;
1782
                $dupcont += 1;
1783
                if ($this->orientacao == 'P') {
1784
                    $maxDupCont = 6;
1785
                } else {
1786
                    $maxDupCont = 8;
1787
                }
1788
                if ($dupcont > $maxDupCont) {
1789
                    $y += 9;
1790
                    $x = $oldx;
1791
                    $dupcont = 0;
1792
                    $linha += 1;
1793
                }
1794
                if ($linha == 5) {
1795
                    $linha = 4;
1796
                    break;
1797
                }
1798
            }
1799
            if ($dupcont == 0) {
1800
                $y -= 9;
1801
                $linha--;
1802
            }
1803
            return ($y+$h);
1804
        } else {
1805
            $linha = 0;
0 ignored issues
show
Unused Code introduced by
$linha is not used, you could remove the assignment.

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

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

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

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

Loading history...
1806
            return ($y-2);
1807
        }
1808
    } //fim da função faturaDANFE
1809
1810
    /**
1811
     * pagamentoDANFE
1812
     * Monta o campo de pagamentos da DANFE (retrato e paisagem) (foi baseada na faturaDANFE)
1813
     *
1814
     * @name   pagamentoDANFE
1815
     * @param  number $x Posição horizontal canto esquerdo
1816
     * @param  number $y Posição vertical canto superior
1817
     * @return number Posição vertical final
1818
     */
1819
    protected function pagamentoDANFE($x, $y)
1820
    {
1821
        $linha = 1;
1822
        $h = 8+3;
0 ignored issues
show
Unused Code introduced by
$h is not used, you could remove the assignment.

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

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

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

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

Loading history...
1823
        $oldx = $x;
1824
        //verificar se existem cobranças definidas
1825
        if (isset($this->detPag) && $this->detPag->length > 0) {
1826
            //#####################################################################
1827
            //Tipo de pagamento
1828
            $texto = "PAGAMENTO";
1829
            if ($this->orientacao == 'P') {
1830
                $w = $this->wPrint;
1831
            } else {
1832
                $w = 271;
1833
            }
1834
            $h = 8;
1835
            $aFont = array('font'=>$this->fontePadrao, 'size'=>7, 'style'=>'B');
1836
            $this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 0, '');
1837
            $y += 3;
1838
            $dups = "";
0 ignored issues
show
Unused Code introduced by
$dups is not used, you could remove the assignment.

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

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

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

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

Loading history...
1839
            $dupcont = 0;
1840
            if ($this->orientacao == 'P') {
1841
                $w = round($this->wPrint/7.018, 0)-1;
1842
            } else {
1843
                $w = 28;
1844
            }
1845
            if ($this->orientacao == 'P') {
1846
                $maxDupCont = 6;
1847
            } else {
1848
                $maxDupCont = 8;
1849
            }
1850
            $increm = 1;
1851
            $formaPagamento = array('01'=>'Dinheiro','02'=>'Cheque','03'=>'Cartão de Crédito',
1852
                                    '04'=>'Cartão de Débito','05'=>'Crédito Loja','10'=>'Vale Alimentação',
1853
                                    '11'=>'Vale Refeição','12'=>'Vale Presente','13'=>'Vale Combustível',
1854
                                    '14'=>'Duplicata Mercantil','15'=>'Boleto','90'=>'Sem pagamento','99'=>'Outros');
1855
            $bandeira = array('01'=>'Visa','02'=>'Mastercard','03'=>'American','04'=>'Sorocred','05'=>'Diners',
0 ignored issues
show
Unused Code introduced by
$bandeira is not used, you could remove the assignment.

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

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

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

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

Loading history...
1856
                              '06'=>'Elo','07'=>'Hipercard','08'=>'Aura','09'=>'Cabal','99'=>'Outros');
1857
            foreach ($this->detPag as $k => $d) {
1858
                $fPag = !empty($this->detPag->item($k)->getElementsByTagName('tPag')->item(0)->nodeValue)
1859
                    ? $this->detPag->item($k)->getElementsByTagName('tPag')->item(0)->nodeValue : '0';
1860
                $vPag = ! empty($this->detPag->item($k)->getElementsByTagName('vPag')->item(0)->nodeValue)
1861
                    ? 'R$ ' . number_format(
1862
                        $this->detPag->item($k)->getElementsByTagName('vPag')->item(0)->nodeValue,
1863
                        2,
1864
                        ",",
1865
                        "."
1866
                    ) : '';
1867
                $h = 6;
1868
                $texto = '';
0 ignored issues
show
Unused Code introduced by
$texto is not used, you could remove the assignment.

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

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

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

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

Loading history...
1869
                if (isset($formaPagamento[$fPag])) {
1870
                    /*Exibir Item sem pagamento ou outros?*/
1871
                    if ($fPag=='90' || $fPag=='99') {
1872
                        continue;
1873
                    }
1874
                    $aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>'');
1875
                    $this->pTextBox($x, $y, $w, $h, 'Forma', $aFont, 'T', 'L', 1, '');
1876
                    $aFont = array('font'=>$this->fontePadrao, 'size'=>7, 'style'=>'B');
1877
                    $this->pTextBox($x, $y, $w, $h, $formaPagamento[$fPag], $aFont, 'T', 'R', 0, '');
1878
                } else {
1879
                    $aFont = array('font'=>$this->fontePadrao, 'size'=>7, 'style'=>'');
1880
                    $this->pTextBox($x, $y, $w, $h, "Forma ".$fPag." não encontrado", $aFont, 'T', 'L', 1, '');
1881
                }
1882
                $aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>'');
1883
                $this->pTextBox($x, $y, $w, $h, 'Valor', $aFont, 'B', 'L', 0, '');
1884
                $aFont = array('font'=>$this->fontePadrao, 'size'=>7, 'style'=>'B');
1885
                $this->pTextBox($x, $y, $w, $h, $vPag, $aFont, 'B', 'R', 0, '');
1886
                $x += $w+$increm;
1887
                $dupcont += 1;
1888
1889
                if ($dupcont>$maxDupCont) {
1890
                    $y += 9;
1891
                    $x = $oldx;
1892
                    $dupcont = 0;
1893
                    $linha += 1;
1894
                }
1895
                if ($linha == 5) {
1896
                    $linha = 4;
1897
                    break;
1898
                }
1899
            }
1900
            if ($dupcont == 0) {
1901
                $y -= 9;
1902
                $linha--;
1903
            }
1904
            return ($y+$h);
1905
        } else {
1906
            $linha = 0;
0 ignored issues
show
Unused Code introduced by
$linha is not used, you could remove the assignment.

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

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

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

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

Loading history...
1907
            return ($y-2);
1908
        }
1909
    } //fim da função pagamentoDANFE
1910
    
1911
    /**
1912
     * impostoDanfeHelper
1913
     * Auxilia a montagem dos campos de impostos e totais da DANFE
1914
     *
1915
     * @name   impostoDanfeHelper
1916
     * @param  float $x Posição horizontal canto esquerdo
1917
     * @param  float $y Posição vertical canto superior
1918
     * @param  float $w Largura do campo
1919
     * @param  float $h Altura do campo
1920
     * @param  float $h Título do campo
1921
     * @param  float $h Valor do imposto
1922
     * @return float Sugestão do $x do próximo imposto
1923
     */
1924
    protected function pImpostoDanfeHelper($x, $y, $w, $h, $titulo, $campoImposto)
1925
    {
1926
        $valorImposto = '0, 00';
1927
        $the_field = $this->ICMSTot->getElementsByTagName($campoImposto)->item(0);
1928
        if (isset($the_field)) {
1929
            $the_value = $the_field->nodeValue;
1930
            if (!empty($the_value)) {
1931
                $valorImposto = number_format($the_value, 2, ",", ".");
1932
            }
1933
        }
1934
1935
        $fontTitulo = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>'');
1936
        $fontValor = array('font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B');
1937
        $this->pTextBox($x, $y, $w, $h, $titulo, $fontTitulo, 'T', 'L', 1, '');
1938
        $this->pTextBox($x, $y, $w, $h, $valorImposto, $fontValor, 'B', 'R', 0, '');
1939
1940
        $next_x = $x + $w;
1941
        return $next_x;
1942
    }
1943
1944
    /**
1945
     * impostoDANFE
1946
     * Monta o campo de impostos e totais da DANFE (retrato e paisagem)
1947
     *
1948
     * @param  number $x Posição horizontal canto esquerdo
1949
     * @param  number $y Posição vertical canto superior
1950
     * @return number Posição vertical final
1951
     */
1952
    protected function pImpostoDANFE($x, $y)
1953
    {
1954
        $x_inicial = $x;
1955
        //#####################################################################
1956
1957
1958
        $campos_por_linha = 9;
1959
        if (!$this->exibirPIS) {
1960
            $campos_por_linha--;
1961
        }
1962
        if (!$this->exibirIcmsInterestadual) {
1963
            $campos_por_linha -= 2;
1964
        }
1965
1966
        if ($this->orientacao == 'P') {
1967
            $maxW = $this->wPrint;
1968
            $title_size = 31;
1969
        } else {
1970
            $maxW = $this->wPrint - $this->wCanhoto;
1971
            $title_size = 40;
1972
        }
1973
        $w = $maxW / $campos_por_linha;
1974
1975
        $aFont = array('font'=>$this->fontePadrao, 'size'=>7, 'style'=>'B');
1976
        $texto = "CÁLCULO DO IMPOSTO";
1977
        $this->pTextBox($x, $y, $title_size, 8, $texto, $aFont, 'T', 'L', 0, '');
1978
        $y += 3;
1979
        $h = 7;
1980
1981
        $x = $this->pImpostoDanfeHelper($x, $y, $w, $h, "BASE DE CÁLC. DO ICMS", "vBC");
1982
        $x = $this->pImpostoDanfeHelper($x, $y, $w, $h, "VALOR DO ICMS", "vICMS");
1983
        $x = $this->pImpostoDanfeHelper($x, $y, $w, $h, "BASE DE CÁLC. ICMS S.T.", "vBCST");
1984
        $x = $this->pImpostoDanfeHelper($x, $y, $w, $h, "VALOR DO ICMS SUBST.", "vST");
1985
        $x = $this->pImpostoDanfeHelper($x, $y, $w, $h, "V. IMP. IMPORTAÇÃO", "vII");
1986
1987
        if ($this->exibirIcmsInterestadual) {
1988
            $x = $this->pImpostoDanfeHelper($x, $y, $w, $h, "V. ICMS UF REMET.", "vICMSUFRemet");
1989
            $x = $this->pImpostoDanfeHelper($x, $y, $w, $h, "V. FCP UF DEST.", "vFCPUFDest");
1990
        }
1991
1992
        if ($this->exibirPIS) {
1993
            $x = $this->pImpostoDanfeHelper($x, $y, $w, $h, "VALOR DO PIS", "vPIS");
1994
        }
1995
1996
        $x = $this->pImpostoDanfeHelper($x, $y, $w, $h, "V. TOTAL PRODUTOS", "vProd");
0 ignored issues
show
Unused Code introduced by
$x is not used, you could remove the assignment.

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

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

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

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

Loading history...
1997
1998
        //
1999
2000
        $y += $h;
2001
        $x = $x_inicial;
2002
2003
        $x = $this->pImpostoDanfeHelper($x, $y, $w, $h, "VALOR DO FRETE", "vFrete");
2004
        $x = $this->pImpostoDanfeHelper($x, $y, $w, $h, "VALOR DO SEGURO", "vSeg");
2005
        $x = $this->pImpostoDanfeHelper($x, $y, $w, $h, "DESCONTO", "vDesc");
2006
        $x = $this->pImpostoDanfeHelper($x, $y, $w, $h, "OUTRAS DESPESAS", "vOutro");
2007
        $x = $this->pImpostoDanfeHelper($x, $y, $w, $h, "VALOR TOTAL IPI", "vIPI");
2008
2009
        if ($this->exibirIcmsInterestadual) {
2010
            $x = $this->pImpostoDanfeHelper($x, $y, $w, $h, "V. ICMS UF DEST.", "vICMSUFDest");
2011
            $x = $this->pImpostoDanfeHelper($x, $y, $w, $h, "V. TOT. TRIB.", "vTotTrib");
2012
        }
2013
2014
        if ($this->exibirPIS) {
2015
            $x = $this->pImpostoDanfeHelper($x, $y, $w, $h, "VALOR DA COFINS", "vCOFINS");
2016
        }
2017
        $x = $this->pImpostoDanfeHelper($x, $y, $w, $h, "V. TOTAL DA NOTA", "vNF");
0 ignored issues
show
Unused Code introduced by
$x is not used, you could remove the assignment.

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

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

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

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

Loading history...
2018
2019
        return ($y+$h);
2020
    } //fim impostoDANFE
2021
2022
    /**
2023
     * transporteDANFE
2024
     * Monta o campo de transportes da DANFE (retrato e paisagem)
2025
     *
2026
     * @name   transporteDANFE
2027
     * @param  float $x Posição horizontal canto esquerdo
2028
     * @param  float $y Posição vertical canto superior
2029
     * @return float Posição vertical final
2030
     */
2031
    protected function pTransporteDANFE($x, $y)
2032
    {
2033
        $oldX = $x;
2034
        if ($this->orientacao == 'P') {
2035
            $maxW = $this->wPrint;
2036
        } else {
2037
            $maxW = $this->wPrint - $this->wCanhoto;
2038
        }
2039
        //#####################################################################
2040
        //TRANSPORTADOR / VOLUMES TRANSPORTADOS
2041
        $texto = "TRANSPORTADOR / VOLUMES TRANSPORTADOS";
2042
        $w = $maxW;
2043
        $h = 7;
2044
        $aFont = array('font'=>$this->fontePadrao, 'size'=>7, 'style'=>'B');
2045
        $this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 0, '');
2046
        //NOME / RAZÃO SOCIAL
2047
        $w1 = $maxW*0.29;
2048
        $y += 3;
2049
        $texto = 'NOME / RAZÃO SOCIAL';
2050
        $aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>'');
2051
        $this->pTextBox($x, $y, $w1, $h, $texto, $aFont, 'T', 'L', 1, '');
2052
        if (isset($this->transporta)) {
2053
            $texto = ! empty($this->transporta->getElementsByTagName("xNome")->item(0)->nodeValue) ?
2054
                    $this->transporta->getElementsByTagName("xNome")->item(0)->nodeValue : '';
2055
        } else {
2056
            $texto = '';
2057
        }
2058
        $aFont = array('font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B');
2059
        $this->pTextBox($x, $y, $w1, $h, $texto, $aFont, 'B', 'L', 0, '');
2060
        //FRETE POR CONTA
2061
        $x += $w1;
2062
        $w2 = $maxW*0.15;
2063
        $texto = 'FRETE';
2064
        $aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>'');
2065
        $this->pTextBox($x, $y, $w2, $h, $texto, $aFont, 'T', 'L', 1, '');
2066
        $tipoFrete = ! empty($this->transp->getElementsByTagName("modFrete")->item(0)->nodeValue) ?
2067
                $this->transp->getElementsByTagName("modFrete")->item(0)->nodeValue : '0';
2068
        switch ($tipoFrete) {
2069
            case 0:
2070
                $texto = "0-Por conta do Rem";
2071
                break;
2072
            case 1:
2073
                $texto = "1-Por conta do Dest";
2074
                break;
2075
            case 2:
2076
                $texto = "2-Por conta de Terceiros";
2077
                break;
2078
            case 3:
2079
                $texto = "3-Próprio por conta do Rem";
2080
                break;
2081
            case 4:
2082
                $texto = "4-Próprio por conta do Dest";
2083
                break;
2084
            case 9:
2085
                $texto = "9-Sem Transporte";
2086
                break;
2087
        }
2088
        $aFont = array('font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B');
2089
        $this->pTextBox($x, $y, $w2, $h, $texto, $aFont, 'C', 'C', 1, '');
2090
        //CÓDIGO ANTT
2091
        $x += $w2;
2092
        $texto = 'CÓDIGO ANTT';
2093
        $aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>'');
2094
        $this->pTextBox($x, $y, $w2, $h, $texto, $aFont, 'T', 'L', 1, '');
2095
        if (isset($this->veicTransp)) {
2096
            $texto = ! empty($this->veicTransp->getElementsByTagName("RNTC")->item(0)->nodeValue) ?
2097
                    $this->veicTransp->getElementsByTagName("RNTC")->item(0)->nodeValue : '';
2098
        } else {
2099
            $texto = '';
2100
        }
2101
        $aFont = array('font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B');
2102
        $this->pTextBox($x, $y, $w2, $h, $texto, $aFont, 'B', 'C', 0, '');
2103
        //PLACA DO VEÍC
2104
        $x += $w2;
2105
        $texto = 'PLACA DO VEÍCULO';
2106
        $aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>'');
2107
        $this->pTextBox($x, $y, $w2, $h, $texto, $aFont, 'T', 'L', 1, '');
2108
        if (isset($this->veicTransp)) {
2109
            $texto = ! empty($this->veicTransp->getElementsByTagName("placa")->item(0)->nodeValue) ?
2110
                    $this->veicTransp->getElementsByTagName("placa")->item(0)->nodeValue : '';
2111
        } elseif (isset($this->reboque)) {
2112
            $texto = ! empty($this->reboque->getElementsByTagName("placa")->item(0)->nodeValue) ?
2113
                    $this->reboque->getElementsByTagName("placa")->item(0)->nodeValue : '';
2114
        } else {
2115
            $texto = '';
2116
        }
2117
        $aFont = array('font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B');
2118
        $this->pTextBox($x, $y, $w2, $h, $texto, $aFont, 'B', 'C', 0, '');
2119
        //UF
2120
        $x += $w2;
2121
        $w3 = round($maxW*0.04, 0);
2122
        $texto = 'UF';
2123
        $aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>'');
2124
        $this->pTextBox($x, $y, $w3, $h, $texto, $aFont, 'T', 'L', 1, '');
2125
        if (isset($this->veicTransp)) {
2126
            $texto = ! empty($this->veicTransp->getElementsByTagName("UF")->item(0)->nodeValue) ?
2127
                    $this->veicTransp->getElementsByTagName("UF")->item(0)->nodeValue : '';
2128
        } elseif (isset($this->reboque)) {
2129
            $texto = ! empty($this->reboque->getElementsByTagName("UF")->item(0)->nodeValue) ?
2130
                    $this->reboque->getElementsByTagName("UF")->item(0)->nodeValue : '';
2131
        } else {
2132
            $texto = '';
2133
        }
2134
        $aFont = array('font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B');
2135
        $this->pTextBox($x, $y, $w3, $h, $texto, $aFont, 'B', 'C', 0, '');
2136
        //CNPJ / CPF
2137
        $x += $w3;
2138
        $w = $maxW-($w1+3*$w2+$w3);
2139
        $texto = 'CNPJ / CPF';
2140
        $aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>'');
2141
        $this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 1, '');
2142
        if (isset($this->transporta)) {
2143
            $texto = ! empty($this->transporta->getElementsByTagName("CNPJ")->item(0)->nodeValue) ?
2144
                    $this->pFormat(
2145
                        $this->transporta->getElementsByTagName("CNPJ")->item(0)->nodeValue,
2146
                        "##.###.###/####-##"
2147
                    ) : '';
2148
            if ($texto == '') {
2149
                $texto = ! empty($this->transporta->getElementsByTagName("CPF")->item(0)->nodeValue) ?
2150
                        $this->pFormat(
2151
                            $this->transporta->getElementsByTagName("CPF")->item(0)->nodeValue,
2152
                            "###.###.###-##"
2153
                        ) : '';
2154
            }
2155
        } else {
2156
            $texto = '';
2157
        }
2158
        $aFont = array('font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B');
2159
        $this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'B', 'C', 0, '');
2160
        //#####################################################################
2161
        //ENDEREÇO
2162
        $y += $h;
2163
        $x = $oldX;
2164
        $h = 7;
2165
        $w1 = $maxW*0.44;
2166
        $texto = 'ENDEREÇO';
2167
        $aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>'');
2168
        $this->pTextBox($x, $y, $w1, $h, $texto, $aFont, 'T', 'L', 1, '');
2169
        if (isset($this->transporta)) {
2170
            $texto = ! empty($this->transporta->getElementsByTagName("xEnder")->item(0)->nodeValue) ?
2171
                    $this->transporta->getElementsByTagName("xEnder")->item(0)->nodeValue : '';
2172
        } else {
2173
            $texto = '';
2174
        }
2175
        $aFont = array('font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B');
2176
        $this->pTextBox($x, $y, $w1, $h, $texto, $aFont, 'B', 'L', 0, '');
2177
        //MUNICÍPIO
2178
        $x += $w1;
2179
        $w2 = round($maxW*0.30, 0);
2180
        $texto = 'MUNICÍPIO';
2181
        $aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>'');
2182
        $this->pTextBox($x, $y, $w2, $h, $texto, $aFont, 'T', 'L', 1, '');
2183
        if (isset($this->transporta)) {
2184
            $texto = ! empty($this->transporta->getElementsByTagName("xMun")->item(0)->nodeValue) ?
2185
                    $this->transporta->getElementsByTagName("xMun")->item(0)->nodeValue : '';
2186
        } else {
2187
            $texto = '';
2188
        }
2189
        $aFont = array('font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B');
2190
        $this->pTextBox($x, $y, $w2, $h, $texto, $aFont, 'B', 'C', 0, '');
2191
        //UF
2192
        $x += $w2;
2193
        $w3 = round($maxW*0.04, 0);
2194
        $texto = 'UF';
2195
        $aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>'');
2196
        $this->pTextBox($x, $y, $w3, $h, $texto, $aFont, 'T', 'L', 1, '');
2197
        if (isset($this->transporta)) {
2198
            $texto = ! empty($this->transporta->getElementsByTagName("UF")->item(0)->nodeValue) ?
2199
                    $this->transporta->getElementsByTagName("UF")->item(0)->nodeValue : '';
2200
        } else {
2201
            $texto = '';
2202
        }
2203
        $aFont = array('font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B');
2204
        $this->pTextBox($x, $y, $w3, $h, $texto, $aFont, 'B', 'C', 0, '');
2205
        //INSCRIÇÃO ESTADUAL
2206
        $x += $w3;
2207
        $w = $maxW-($w1+$w2+$w3);
2208
        $texto = 'INSCRIÇÃO ESTADUAL';
2209
        $aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>'');
2210
        $this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 1, '');
2211
        $texto = '';
2212
        if (isset($this->transporta)) {
2213
            if (! empty($this->transporta->getElementsByTagName("IE")->item(0)->nodeValue)) {
2214
                $texto = $this->transporta->getElementsByTagName("IE")->item(0)->nodeValue;
2215
            }
2216
        }
2217
        $aFont = array('font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B');
2218
        $this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'B', 'C', 0, '');
2219
        //Tratar Multiplos volumes
2220
        $volumes = $this->transp->getElementsByTagName('vol');
2221
        $quantidade = 0;
2222
        $especie = '';
2223
        $marca = '';
2224
        $numero = '';
2225
        $texto = '';
0 ignored issues
show
Unused Code introduced by
$texto is not used, you could remove the assignment.

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

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

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

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

Loading history...
2226
        $pesoBruto=0;
2227
        $pesoLiquido=0;
2228
        foreach ($volumes as $volume) {
2229
            $quantidade += ! empty($volume->getElementsByTagName("qVol")->item(0)->nodeValue) ?
2230
                    $volume->getElementsByTagName("qVol")->item(0)->nodeValue : 0;
2231
            $pesoBruto += ! empty($volume->getElementsByTagName("pesoB")->item(0)->nodeValue) ?
2232
                    $volume->getElementsByTagName("pesoB")->item(0)->nodeValue : 0;
2233
            $pesoLiquido += ! empty($volume->getElementsByTagName("pesoL")->item(0)->nodeValue) ?
2234
                    $volume->getElementsByTagName("pesoL")->item(0)->nodeValue : 0;
2235
            $texto = ! empty($this->transp->getElementsByTagName("esp")->item(0)->nodeValue) ?
2236
                    $this->transp->getElementsByTagName("esp")->item(0)->nodeValue : '';
2237
            if ($texto != $especie && $especie != '') {
2238
                //tem várias especies
2239
                $especie = 'VARIAS';
2240
            } else {
2241
                $especie = $texto;
2242
            }
2243
            $texto = ! empty($this->transp->getElementsByTagName("marca")->item(0)->nodeValue) ?
2244
                    $this->transp->getElementsByTagName("marca")->item(0)->nodeValue : '';
2245
            if ($texto != $marca && $marca != '') {
2246
                //tem várias especies
2247
                $marca = 'VARIAS';
2248
            } else {
2249
                $marca = $texto;
2250
            }
2251
            $texto = ! empty($this->transp->getElementsByTagName("nVol")->item(0)->nodeValue) ?
2252
                    $this->transp->getElementsByTagName("nVol")->item(0)->nodeValue : '';
2253
            if ($texto != $numero && $numero != '') {
2254
                //tem várias especies
2255
                $numero = 'VARIOS';
2256
            } else {
2257
                $numero = $texto;
2258
            }
2259
        }
2260
2261
        //#####################################################################
2262
        //QUANTIDADE
2263
        $y += $h;
2264
        $x = $oldX;
2265
        $h = 7;
2266
        $w1 = round($maxW*0.10, 0);
2267
        $texto = 'QUANTIDADE';
2268
        $aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>'');
2269
        $this->pTextBox($x, $y, $w1, $h, $texto, $aFont, 'T', 'L', 1, '');
2270
        if (!empty($quantidade)) {
2271
            $texto = $quantidade;
2272
            $aFont = array('font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B');
2273
            $this->pTextBox($x, $y, $w1, $h, $texto, $aFont, 'B', 'C', 0, '');
2274
        }
2275
        //ESPÉCIE
2276
        $x += $w1;
2277
        $w2 = round($maxW*0.17, 0);
2278
        $texto = 'ESPÉCIE';
2279
        $aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>'');
2280
        $this->pTextBox($x, $y, $w2, $h, $texto, $aFont, 'T', 'L', 1, '');
2281
        $texto = $especie;
2282
        $aFont = array('font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B');
2283
        $this->pTextBox($x, $y, $w2, $h, $texto, $aFont, 'B', 'C', 0, '');
2284
        //MARCA
2285
        $x += $w2;
2286
        $texto = 'MARCA';
2287
        $aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>'');
2288
        $this->pTextBox($x, $y, $w2, $h, $texto, $aFont, 'T', 'L', 1, '');
2289
        $texto = ! empty($this->transp->getElementsByTagName("marca")->item(0)->nodeValue) ?
2290
                $this->transp->getElementsByTagName("marca")->item(0)->nodeValue : '';
2291
        $aFont = array('font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B');
2292
        $this->pTextBox($x, $y, $w2, $h, $texto, $aFont, 'B', 'C', 0, '');
2293
        //NUMERAÇÃO
2294
        $x += $w2;
2295
        $texto = 'NUMERAÇÃO';
2296
        $aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>'');
2297
        $this->pTextBox($x, $y, $w2, $h, $texto, $aFont, 'T', 'L', 1, '');
2298
        $texto = $numero;
2299
        $aFont = array('font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B');
2300
        $this->pTextBox($x, $y, $w2, $h, $texto, $aFont, 'B', 'C', 0, '');
2301
        //PESO BRUTO
2302
        $x += $w2;
2303
        $w3 = round($maxW*0.20, 0);
2304
        $texto = 'PESO BRUTO';
2305
        $aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>'');
2306
        $this->pTextBox($x, $y, $w3, $h, $texto, $aFont, 'T', 'L', 1, '');
2307
        if (is_numeric($pesoBruto) && $pesoBruto > 0) {
2308
            $texto = number_format($pesoBruto, 3, ",", ".");
2309
        } else {
2310
            $texto = '';
2311
        }
2312
        $aFont = array('font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B');
2313
        $this->pTextBox($x, $y, $w3, $h, $texto, $aFont, 'B', 'R', 0, '');
2314
        //PESO LÍQUIDO
2315
        $x += $w3;
2316
        $w = $maxW -($w1+3*$w2+$w3);
2317
        $texto = 'PESO LÍQUIDO';
2318
        $aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>'');
2319
        $this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 1, '');
2320
        if (is_numeric($pesoLiquido) && $pesoLiquido > 0) {
2321
            $texto = number_format($pesoLiquido, 3, ",", ".");
2322
        } else {
2323
            $texto = '';
2324
        }
2325
        $aFont = array('font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B');
2326
        $this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'B', 'R', 0, '');
2327
        return ($y+$h);
2328
    } //fim transporteDANFE
2329
2330
2331
2332
    protected function pDescricaoProdutoHelper($origem, $campo, $formato)
2333
    {
2334
        $valor_original = $origem->getElementsByTagName($campo)->item(0);
2335
        if (!isset($valor_original)) {
2336
            return "";
2337
        }
2338
        $valor_original = $valor_original->nodeValue;
2339
        $valor = ! empty($valor_original) ? number_format($valor_original, 2, ",", ".") : '';
2340
2341
        if ($valor != "") {
2342
            return sprintf($formato, $valor);
2343
        }
2344
        return "";
2345
    }
2346
2347
    /**
2348
     * descricaoProduto
2349
     * Monta a string de descrição de cada Produto
2350
     *
2351
     * @name   descricaoProduto
2352
     * @param  DOMNode itemProd
2353
     * @return string descricao do produto
2354
     */
2355
    protected function pDescricaoProduto($itemProd)
2356
    {
2357
        $prod = $itemProd->getElementsByTagName('prod')->item(0);
2358
        $ICMS = $itemProd->getElementsByTagName("ICMS")->item(0);
2359
        $ICMSUFDest = $itemProd->getElementsByTagName("ICMSUFDest")->item(0);
2360
        $impostos = '';
2361
2362
        if (!empty($ICMS)) {
2363
            $impostos .= $this->pDescricaoProdutoHelper($ICMS, "vBCFCP", " BcFcp=%s");
2364
            $impostos .= $this->pDescricaoProdutoHelper($ICMS, "pFCP", " pFcp=%s%%");
2365
            $impostos .= $this->pDescricaoProdutoHelper($ICMS, "vFCP", " vFcp=%s");
2366
            $impostos .= $this->pDescricaoProdutoHelper($ICMS, "pRedBC", " pRedBC=%s%%");
2367
            $impostos .= $this->pDescricaoProdutoHelper($ICMS, "pMVAST", " IVA/MVA=%s%%");
2368
            $impostos .= $this->pDescricaoProdutoHelper($ICMS, "pICMSST", " pIcmsSt=%s%%");
2369
            $impostos .= $this->pDescricaoProdutoHelper($ICMS, "vBCST", " BcIcmsSt=%s");
2370
            $impostos .= $this->pDescricaoProdutoHelper($ICMS, "vICMSST", " vIcmsSt=%s");
2371
            $impostos .= $this->pDescricaoProdutoHelper($ICMS, "vBCFCPST", " BcFcpSt=%s");
2372
            $impostos .= $this->pDescricaoProdutoHelper($ICMS, "pFCPST", " pFcpSt=%s%%");
2373
            $impostos .= $this->pDescricaoProdutoHelper($ICMS, "vFCPST", " vFcpSt=%s");
2374
        }
2375
        if (!empty($ICMSUFDest)) {
2376
            $impostos .= $this->pDescricaoProdutoHelper($ICMSUFDest, "pFCPUFDest", " pFCPUFDest=%s%%");
2377
            $impostos .= $this->pDescricaoProdutoHelper($ICMSUFDest, "pICMSUFDest", " pICMSUFDest=%s%%");
2378
            $impostos .= $this->pDescricaoProdutoHelper($ICMSUFDest, "pICMSInterPart", " pICMSInterPart=%s%%");
2379
            $impostos .= $this->pDescricaoProdutoHelper($ICMSUFDest, "vFCPUFDest", " vFCPUFDest=%s");
2380
            $impostos .= $this->pDescricaoProdutoHelper($ICMSUFDest, "vICMSUFDest", " vICMSUFDest=%s");
2381
            $impostos .= $this->pDescricaoProdutoHelper($ICMSUFDest, "vICMSUFRemet", " vICMSUFRemet=%s");
2382
        }
2383
        $infAdProd = ! empty($itemProd->getElementsByTagName('infAdProd')->item(0)->nodeValue) ?
2384
                substr($this->pAnfavea($itemProd->getElementsByTagName('infAdProd')->item(0)->nodeValue), 0, 500) : '';
2385
        if (! empty($infAdProd)) {
2386
            $infAdProd = trim($infAdProd);
2387
            $infAdProd .= ' ';
2388
        }
2389
        $loteTxt ='';
2390
        $rastro = $prod->getElementsByTagName("med");
2391
        if (!isset($rastro)) {
2392
            $rastro = $prod->getElementsByTagName("rastro");
2393
        }
2394
        if (isset($rastro)) {
2395
            $i = 0;
2396
            while ($i < $rastro->length) {
2397
                $loteTxt .= $this->pSimpleGetValue($rastro->item($i), 'nLote', ' Lote: ');
2398
                $loteTxt .= $this->pSimpleGetValue($rastro->item($i), 'qLote', ' Quant: ');
2399
                $loteTxt .= $this->pSimpleGetDate($rastro->item($i), 'dFab', ' Fab: ');
2400
                $loteTxt .= $this->pSimpleGetDate($rastro->item($i), 'dVal', ' Val: ');
2401
                $loteTxt .= $this->pSimpleGetValue($rastro->item($i), 'vPMC', ' PMC: ');
2402
                $i++;
2403
            }
2404
            if ($loteTxt != '') {
2405
                $loteTxt.= ' ';
2406
            }
2407
        }
2408
        //NT2013.006 FCI
2409
        $nFCI = (! empty($itemProd->getElementsByTagName('nFCI')->item(0)->nodeValue)) ?
2410
                ' FCI:'.$itemProd->getElementsByTagName('nFCI')->item(0)->nodeValue : '';
2411
        $tmp_ad=$infAdProd . ($this->descProdInfoComplemento ? $loteTxt . $impostos . $nFCI : '');
2412
        $texto = $prod->getElementsByTagName("xProd")->item(0)->nodeValue . (strlen($tmp_ad)!=0?"\n    ".$tmp_ad:'');
2413
        if ($this->descProdQuebraLinha) {
2414
            $texto = str_replace(";", "\n", $texto);
2415
        }
2416
        return $texto;
2417
    }
2418
2419
    /**
2420
     * itensDANFE
2421
     * Monta o campo de itens da DANFE (retrato e paisagem)
2422
     *
2423
     * @name   itensDANFE
2424
     * @param  float $x       Posição horizontal canto esquerdo
2425
     * @param  float $y       Posição vertical canto superior
2426
     * @param  float $nInicio Número do item inicial
2427
     * @param  float $max     Número do item final
0 ignored issues
show
Bug introduced by
There is no parameter named $max. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
2428
     * @param  float $hmax    Altura máxima do campo de itens em mm
2429
     * @return float Posição vertical final
2430
     */
2431
    protected function pItensDANFE($x, $y, &$nInicio, $hmax, $pag = 0, $totpag = 0, $hCabecItens = 7)
2432
    {
2433
        $oldX = $x;
2434
        $oldY = $y;
2435
        $totItens = $this->det->length;
2436
        //#####################################################################
2437
        //DADOS DOS PRODUTOS / SERVIÇOS
2438
        $texto = "DADOS DOS PRODUTOS / SERVIÇOS ";
2439
        if ($this->orientacao == 'P') {
2440
            $w = $this->wPrint;
2441
        } else {
2442
            if ($nInicio < 2) { // primeira página
2443
                $w = $this->wPrint - $this->wCanhoto;
2444
            } else { // páginas seguintes
2445
                $w = $this->wPrint;
2446
            }
2447
        }
2448
        $h = 4;
2449
        $aFont = array('font'=>$this->fontePadrao, 'size'=>7, 'style'=>'B');
2450
        $this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 0, '');
2451
        $y += 3;
2452
        //desenha a caixa dos dados dos itens da NF
2453
        $hmax += 1;
2454
        $texto = '';
0 ignored issues
show
Unused Code introduced by
$texto is not used, you could remove the assignment.

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

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

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

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

Loading history...
2455
        $this->pTextBox($x, $y, $w, $hmax);
2456
        //##################################################################################
2457
        // cabecalho LOOP COM OS DADOS DOS PRODUTOS
2458
        //CÓDIGO PRODUTO
2459
        $texto = "CÓDIGO PRODUTO";
2460
        $w1 = round($w*0.09, 0);
2461
        $h = 4;
2462
        $aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>'');
2463
        $this->pTextBox($x, $y, $w1, $h, $texto, $aFont, 'C', 'C', 0, '', false);
2464
        $this->pdf->Line($x+$w1, $y, $x+$w1, $y+$hmax);
2465
        //DESCRIÇÃO DO PRODUTO / SERVIÇO
2466
        $x += $w1;
2467
        $w2 = round($w*0.28, 0);
2468
        $texto = 'DESCRIÇÃO DO PRODUTO / SERVIÇO';
2469
        $aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>'');
2470
        $this->pTextBox($x, $y, $w2, $h, $texto, $aFont, 'C', 'C', 0, '', false);
2471
        $this->pdf->Line($x+$w2, $y, $x+$w2, $y+$hmax);
2472
        //NCM/SH
2473
        $x += $w2;
2474
        $w3 = round($w*0.06, 0);
2475
        $texto = 'NCM/SH';
2476
        $aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>'');
2477
        $this->pTextBox($x, $y, $w3, $h, $texto, $aFont, 'C', 'C', 0, '', false);
2478
        $this->pdf->Line($x+$w3, $y, $x+$w3, $y+$hmax);
2479
        //O/CST ou O/CSOSN
2480
        $x += $w3;
2481
        $w4 = round($w*0.05, 0);
2482
        $texto = 'O/CSOSN';//Regime do Simples CRT = 1 ou CRT = 2
2483
        if ($this->pSimpleGetValue($this->emit, 'CRT') == '3') {
2484
             $texto = 'O/CST';//Regime Normal
2485
        }
2486
        $aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>'');
2487
        $this->pTextBox($x, $y, $w4, $h, $texto, $aFont, 'C', 'C', 0, '', false);
2488
        $this->pdf->Line($x+$w4, $y, $x+$w4, $y+$hmax);
2489
        //CFOP
2490
        $x += $w4;
2491
        $w5 = round($w*0.04, 0);
2492
        $texto = 'CFOP';
2493
        $aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>'');
2494
        $this->pTextBox($x, $y, $w5, $h, $texto, $aFont, 'C', 'C', 0, '', false);
2495
        $this->pdf->Line($x+$w5, $y, $x+$w5, $y+$hmax);
2496
        //UN
2497
        $x += $w5;
2498
        $w6 = round($w*0.03, 0);
2499
        $texto = 'UN';
2500
        $aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>'');
2501
        $this->pTextBox($x, $y, $w6, $h, $texto, $aFont, 'C', 'C', 0, '', false);
2502
        $this->pdf->Line($x+$w6, $y, $x+$w6, $y+$hmax);
2503
        //QUANT
2504
        $x += $w6;
2505
        $w7 = round($w*0.07, 0);
2506
        $texto = 'QUANT';
2507
        $aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>'');
2508
        $this->pTextBox($x, $y, $w7, $h, $texto, $aFont, 'C', 'C', 0, '', false);
2509
        $this->pdf->Line($x+$w7, $y, $x+$w7, $y+$hmax);
2510
        //VALOR UNIT
2511
        $x += $w7;
2512
        $w8 = round($w*0.06, 0);
2513
        $texto = 'VALOR UNIT';
2514
        $aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>'');
2515
        $this->pTextBox($x, $y, $w8, $h, $texto, $aFont, 'C', 'C', 0, '', false);
2516
        $this->pdf->Line($x+$w8, $y, $x+$w8, $y+$hmax);
2517
        //VALOR TOTAL
2518
        $x += $w8;
2519
        $w9 = round($w*0.06, 0);
2520
        $texto = 'VALOR TOTAL';
2521
        $aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>'');
2522
        $this->pTextBox($x, $y, $w9, $h, $texto, $aFont, 'C', 'C', 0, '', false);
2523
        $this->pdf->Line($x+$w9, $y, $x+$w9, $y+$hmax);
2524
        //B.CÁLC ICMS
2525
        $x += $w9;
2526
        $w10 = round($w*0.06, 0);
2527
        $texto = 'B.CÁLC ICMS';
2528
        $aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>'');
2529
        $this->pTextBox($x, $y, $w10, $h, $texto, $aFont, 'C', 'C', 0, '', false);
2530
        $this->pdf->Line($x+$w10, $y, $x+$w10, $y+$hmax);
2531
        //VALOR ICMS
2532
        $x += $w10;
2533
        $w11 = round($w*0.06, 0);
2534
        $texto = 'VALOR ICMS';
2535
        $aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>'');
2536
        $this->pTextBox($x, $y, $w11, $h, $texto, $aFont, 'C', 'C', 0, '', false);
2537
        $this->pdf->Line($x+$w11, $y, $x+$w11, $y+$hmax);
2538
        //VALOR IPI
2539
        $x += $w11;
2540
        $w12 = round($w*0.05, 0);
2541
        $texto = 'VALOR IPI';
2542
        $aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>'');
2543
        $this->pTextBox($x, $y, $w12, $h, $texto, $aFont, 'C', 'C', 0, '', false);
2544
        $this->pdf->Line($x+$w12, $y, $x+$w12, $y+$hmax);
2545
        //ALÍQ. ICMS
2546
        $x += $w12;
2547
        $w13 = round($w*0.035, 0);
2548
        $texto = 'ALÍQ. ICMS';
2549
        $aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>'');
2550
        $this->pTextBox($x, $y, $w13, $h, $texto, $aFont, 'C', 'C', 0, '', false);
2551
        $this->pdf->Line($x+$w13, $y, $x+$w13, $y+$hmax);
2552
        //ALÍQ. IPI
2553
        $x += $w13;
2554
        $w14 = $w-($w1+$w2+$w3+$w4+$w5+$w6+$w7+$w8+$w9+$w10+$w11+$w12+$w13);
2555
        $texto = 'ALÍQ. IPI';
2556
        $this->pTextBox($x, $y, $w14, $h, $texto, $aFont, 'C', 'C', 0, '', false);
2557
        $this->pdf->Line($oldX, $y+$h+1, $oldX + $w, $y+$h+1);
2558
        $y += 5;
2559
        //##################################################################################
2560
        // LOOP COM OS DADOS DOS PRODUTOS
2561
        $i = 0;
2562
        $hUsado = $hCabecItens;
2563
        $aFont = array('font'=>$this->fontePadrao, 'size'=>7, 'style'=>'');
2564
        foreach ($this->det as $d) {
2565
            if ($i >= $nInicio) {
2566
                $thisItem = $this->det->item($i);
2567
                //carrega as tags do item
2568
                $prod = $thisItem->getElementsByTagName("prod")->item(0);
2569
                $imposto = $this->det->item($i)->getElementsByTagName("imposto")->item(0);
2570
                $ICMS = $imposto->getElementsByTagName("ICMS")->item(0);
2571
                $IPI  = $imposto->getElementsByTagName("IPI")->item(0);
2572
                $textoProduto = $this->pDescricaoProduto($thisItem);
2573
                $linhaDescr = $this->pGetNumLines($textoProduto, $w2, $aFont);
2574
                $h = round(($linhaDescr * $this->pdf->fontSize)+ ($linhaDescr * 0.5), 2);
2575
                $hUsado += $h;
2576
                if ($pag != $totpag) {
2577
                    if ($hUsado >= $hmax && $i < $totItens) {
2578
                        //ultrapassa a capacidade para uma única página
2579
                        //o restante dos dados serão usados nas proximas paginas
2580
                        $nInicio = $i;
2581
                        break;
2582
                    }
2583
                }
2584
                $y_linha=$y+$h;
2585
                // linha entre itens
2586
                $this->pdf->DashedHLine($oldX, $y_linha, $w, 0.1, 120);
2587
                //corrige o x
2588
                $x=$oldX;
2589
                //codigo do produto
2590
                $texto = $prod->getElementsByTagName("cProd")->item(0)->nodeValue;
2591
                $this->pTextBox($x, $y, $w1, $h, $texto, $aFont, 'T', 'C', 0, '');
2592
                $x += $w1;
2593
                //DESCRIÇÃO
2594
                if ($this->orientacao == 'P') {
2595
                    $this->pTextBox($x, $y, $w2, $h, $textoProduto, $aFont, 'T', 'L', 0, '', false);
2596
                } else {
2597
                    $this->pTextBox($x, $y, $w2, $h, $textoProduto, $aFont, 'T', 'L', 0, '', false);
2598
                }
2599
                $x += $w2;
2600
                //NCM
2601
                $texto = ! empty($prod->getElementsByTagName("NCM")->item(0)->nodeValue) ?
2602
                        $prod->getElementsByTagName("NCM")->item(0)->nodeValue : '';
2603
                $this->pTextBox($x, $y, $w3, $h, $texto, $aFont, 'T', 'C', 0, '');
2604
                $x += $w3;
2605
                //CST
2606
                if (isset($ICMS)) {
2607
                    $origem =  $this->pSimpleGetValue($ICMS, "orig");
2608
                    $cst =  $this->pSimpleGetValue($ICMS, "CST");
2609
                    $csosn =  $this->pSimpleGetValue($ICMS, "CSOSN");
2610
                    $texto = $origem.$cst.$csosn;
2611
                    $this->pTextBox($x, $y, $w4, $h, $texto, $aFont, 'T', 'C', 0, '');
2612
                }
2613
                //CFOP
2614
                $x += $w4;
2615
                $texto = $prod->getElementsByTagName("CFOP")->item(0)->nodeValue;
2616
                $this->pTextBox($x, $y, $w5, $h, $texto, $aFont, 'T', 'C', 0, '');
2617
                //Unidade
2618
                $x += $w5;
2619
                $texto = $prod->getElementsByTagName("uCom")->item(0)->nodeValue;
2620
                $this->pTextBox($x, $y, $w6, $h, $texto, $aFont, 'T', 'C', 0, '');
2621
                $x += $w6;
2622
                if ($this->orientacao == 'P') {
2623
                    $alinhamento = 'R';
2624
                } else {
2625
                    $alinhamento = 'R';
2626
                }
2627
                // QTDADE
2628
                $texto = number_format($prod->getElementsByTagName("qCom")->item(0)->nodeValue, 4, ",", ".");
2629
                $this->pTextBox($x, $y, $w7, $h, $texto, $aFont, 'T', $alinhamento, 0, '');
2630
                $x += $w7;
2631
                // Valor Unitário
2632
                $texto = number_format($prod->getElementsByTagName("vUnCom")->item(0)->nodeValue, 4, ",", ".");
2633
                $this->pTextBox($x, $y, $w8, $h, $texto, $aFont, 'T', $alinhamento, 0, '');
2634
                $x += $w8;
2635
                // Valor do Produto
2636
                $texto = "";
2637
                if (is_numeric($prod->getElementsByTagName("vProd")->item(0)->nodeValue)) {
2638
                    $texto = number_format($prod->getElementsByTagName("vProd")->item(0)->nodeValue, 2, ",", ".");
2639
                }
2640
                $this->pTextBox($x, $y, $w9, $h, $texto, $aFont, 'T', $alinhamento, 0, '');
2641
                //Valor da Base de calculo
2642
                $x += $w9;
2643
                if (isset($ICMS)) {
2644
                    $texto = ! empty($ICMS->getElementsByTagName("vBC")->item(0)->nodeValue) ?
2645
                            number_format(
2646
                                $ICMS->getElementsByTagName("vBC")->item(0)->nodeValue,
2647
                                2,
2648
                                ",",
2649
                                "."
2650
                            ) : '0, 00';
2651
                    $this->pTextBox($x, $y, $w10, $h, $texto, $aFont, 'T', $alinhamento, 0, '');
2652
                }
2653
                //Valor do ICMS
2654
                $x += $w10;
2655
                if (isset($ICMS)) {
2656
                    $texto = ! empty($ICMS->getElementsByTagName("vICMS")->item(0)->nodeValue) ?
2657
                            number_format(
2658
                                $ICMS->getElementsByTagName("vICMS")->item(0)->nodeValue,
2659
                                2,
2660
                                ",",
2661
                                "."
2662
                            ) : '0, 00';
2663
                    $this->pTextBox($x, $y, $w11, $h, $texto, $aFont, 'T', $alinhamento, 0, '');
2664
                }
2665
                //Valor do IPI
2666
                $x += $w11;
2667
                if (isset($IPI)) {
2668
                    $texto = ! empty($IPI->getElementsByTagName("vIPI")->item(0)->nodeValue) ?
2669
                            number_format($IPI->getElementsByTagName("vIPI")->item(0)->nodeValue, 2, ",", ".") :'';
2670
                } else {
2671
                    $texto = '';
2672
                }
2673
                $this->pTextBox($x, $y, $w12, $h, $texto, $aFont, 'T', $alinhamento, 0, '');
2674
                // %ICMS
2675
                $x += $w12;
2676
                if (isset($ICMS)) {
2677
                    $texto = ! empty($ICMS->getElementsByTagName("pICMS")->item(0)->nodeValue) ?
2678
                            number_format(
2679
                                $ICMS->getElementsByTagName("pICMS")->item(0)->nodeValue,
2680
                                2,
2681
                                ",",
2682
                                "."
2683
                            ) : '0, 00';
2684
                    $this->pTextBox($x, $y, $w13, $h, $texto, $aFont, 'T', 'C', 0, '');
2685
                }
2686
                //%IPI
2687
                $x += $w13;
2688
                if (isset($IPI)) {
2689
                    $texto = ! empty($IPI->getElementsByTagName("pIPI")->item(0)->nodeValue) ?
2690
                            number_format($IPI->getElementsByTagName("pIPI")->item(0)->nodeValue, 2, ",", ".") : '';
2691
                } else {
2692
                    $texto = '';
2693
                }
2694
                $this->pTextBox($x, $y, $w14, $h, $texto, $aFont, 'T', 'C', 0, '');
2695
2696
2697
                // Dados do Veiculo Somente para veiculo 0 Km
2698
                $veicProd = $prod->getElementsByTagName("veicProd")->item(0);
2699
                // Tag somente é gerada para veiculo 0k, e só é permitido um veiculo por NF-e por conta do detran
2700
                // Verifica se a Tag existe
2701
                if (!empty($veicProd)) {
2702
                    $this->pDadosItenVeiculoDANFE($oldX, $y, $h, $prod);
2703
                }
2704
2705
2706
                $y += $h;
2707
                $i++;
2708
                //incrementa o controle dos itens processados.
2709
                $this->qtdeItensProc++;
2710
            } else {
2711
                $i++;
2712
            }
2713
        }
2714
        return $oldY+$hmax;
2715
    }
2716
2717
2718
    /**
2719
     * pDadosItenVeiculoDANFE
2720
     * Coloca os dados do veiculo abaixo do item da NFe. (retrato e paisagem)
2721
     *
2722
     * @name  dadosAdicionaisDANFE
2723
     * @param float  $x    Posição horizontal
2724
     *                     canto esquerdo
2725
     * @param float  $y    Posição vertical
2726
     *                     canto superior
2727
     * @param float  $h    altura do campo
2728
     * @param object $prod Contendo todos os dados do item
2729
     */
2730
2731
    protected function pDadosItenVeiculoDANFE($x, $y, $h, $prod)
2732
    {
2733
        $oldX = $x;
2734
        $oldY = $y;
0 ignored issues
show
Unused Code introduced by
$oldY is not used, you could remove the assignment.

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

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

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

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

Loading history...
2735
2736
        if ($this->orientacao == 'P') {
2737
            $w = $this->wPrint;
2738
        } else {
2739
            if ($nInicio < 2) { // primeira página
0 ignored issues
show
Bug introduced by
The variable $nInicio does not exist. Did you forget to declare it?

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

Loading history...
2740
                $w = $this->wPrint - $this->wCanhoto;
2741
            } else { // páginas seguintes
2742
                $w = $this->wPrint;
2743
            }
2744
        }
2745
2746
        $aFont = array('font'=>$this->fontePadrao, 'size'=>7, 'style'=>'');
2747
2748
        $w1 = round($w*0.09, 0);
2749
2750
        // Tabela Renavam Combustivel
2751
        $renavamCombustivel = array(
2752
            1=>'ALCOOL',
2753
            2=>'GASOLINA',
2754
            3=>'DIESEL',
2755
            4=>'GASOGENIO',
2756
            5=>'GAS METANO',
2757
            6=>'ELETRICO/FONTE INTERNA',
2758
            7=>'ELETRICO/FONTE EXTERNA',
2759
            8=>'GASOL/GAS NATURAL COMBUSTIVEL',
2760
            9=>'ALCOOL/GAS NATURAL COMBUSTIVEL',
2761
            10=>'DIESEL/GAS NATURAL COMBUSTIVEL',
2762
            11=>'VIDE/CAMPO/OBSERVACAO',
2763
            12=>'ALCOOL/GAS NATURAL VEICULAR',
2764
            13=>'GASOLINA/GAS NATURAL VEICULAR',
2765
            14=>'DIESEL/GAS NATURAL VEICULAR',
2766
            15=>'GAS NATURAL VEICULAR',
2767
            16=>'ALCOOL/GASOLINA',
2768
            17=>'GASOLINA/ALCOOL/GAS NATURAL',
2769
            18=>'GASOLINA/ELETRICO'
2770
        );
2771
2772
        $renavamEspecie = array(
2773
            1=>'PASSAGEIRO',
2774
            2=>'CARGA',
2775
            3=>'MISTO',
2776
            4=>'CORRIDA',
2777
            5=>'TRACAO',
2778
            6=>'ESPECIAL',
2779
            7=>'COLECAO'
2780
        );
2781
2782
        $renavamTiposVeiculos = array(
2783
            1=>'BICICLETA',
2784
            2=>'CICLOMOTOR',
2785
            3=>'MOTONETA',
2786
            4=>'MOTOCICLETA',
2787
            5=>'TRICICLO',
2788
            6=>'AUTOMOVEL',
2789
            7=>'MICROONIBUS',
2790
            8=>'ONIBUS',
2791
            9=>'BONDE',
2792
            10=>'REBOQUE',
2793
            11=>'SEMI-REBOQUE',
2794
            12=>'CHARRETE',
2795
            13=>'CAMIONETA',
2796
            14=>'CAMINHAO',
2797
            15=>'CARROCA',
2798
            16=>'CARRO DE MAO',
2799
            17=>'CAMINHAO TRATOR',
2800
            18=>'TRATOR DE RODAS',
2801
            19=>'TRATOR DE ESTEIRAS',
2802
            20=>'TRATOR MISTO',
2803
            21=>'QUADRICICLO',
2804
            22=>'CHASSI/PLATAFORMA',
2805
            23=>'CAMINHONETE',
2806
            24=>'SIDE-CAR',
2807
            25=>'UTILITARIO',
2808
            26=>'MOTOR-CASA'
2809
        );
2810
2811
        $renavamTipoPintura = array(
2812
            'F'=>'FOSCA',
2813
            'S'=>'SÓLIDA',
2814
            'P'=>'PEROLIZADA'
2815
        );
2816
2817
2818
2819
        $veicProd = $prod->getElementsByTagName("veicProd")->item(0);
2820
2821
        $veiculoChassi = $veicProd->getElementsByTagName("chassi")->item(0)->nodeValue;
2822
        $veiculoCor = $veicProd->getElementsByTagName("xCor")->item(0)->nodeValue;
2823
        $veiculoCilindrada = $veicProd->getElementsByTagName("cilin")->item(0)->nodeValue;
2824
        $veiculoCmkg = $veicProd->getElementsByTagName("CMT")->item(0)->nodeValue;
2825
        $veiculoTipo = $veicProd->getElementsByTagName("tpVeic")->item(0)->nodeValue;
2826
2827
        $veiculoMotor = $veicProd->getElementsByTagName("nMotor")->item(0)->nodeValue;
2828
        $veiculoRenavam = $veicProd->getElementsByTagName("cMod")->item(0)->nodeValue;
2829
        $veiculoHp = $veicProd->getElementsByTagName("pot")->item(0)->nodeValue;
2830
        $veiculoPlaca = ''; //$veiculo->getElementsByTagName("CMT")->item(0)->nodeValue;
0 ignored issues
show
Unused Code Comprehensibility introduced by
79% of this comment could be valid code. Did you maybe forget this after debugging?

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

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

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

Loading history...
2831
        $veiculoTipoPintura = $veicProd->getElementsByTagName("tpPint")->item(0)->nodeValue;
2832
2833
        $veiculoMarcaModelo = $prod->getElementsByTagName("xProd")->item(0)->nodeValue;
2834
        $veiculoEspecie = $veicProd->getElementsByTagName("espVeic")->item(0)->nodeValue;
2835
        $veiculoCombustivel = $veicProd->getElementsByTagName("tpComb")->item(0)->nodeValue;
2836
        $veiculoSerial = $veicProd->getElementsByTagName("nSerie")->item(0)->nodeValue;
2837
        $veiculoFabricacao = $veicProd->getElementsByTagName("anoFab")->item(0)->nodeValue;
2838
        $veiculoModelo = $veicProd->getElementsByTagName("anoMod")->item(0)->nodeValue;
2839
2840
        $veiculoDistancia = $veicProd->getElementsByTagName("dist")->item(0)->nodeValue;
2841
2842
        $x = $oldX;
2843
2844
        $yVeic = $y + $h;
2845
        $texto = 'Chassi: ............: ' . $veiculoChassi;
2846
        $this->pTextBox($x, $yVeic, $w1+40, $h, $texto, $aFont, 'T', 'L', 0, '');
2847
        $yVeic += $h;
2848
        $texto = 'Cor...................: ' . $veiculoCor;
2849
        $this->pTextBox($x, $yVeic, $w1+40, $h, $texto, $aFont, 'T', 'L', 0, '');
2850
        $yVeic += $h;
2851
        $texto = 'Cilindrada........: ' . $veiculoCilindrada;
2852
        $this->pTextBox($x, $yVeic, $w1+40, $h, $texto, $aFont, 'T', 'L', 0, '');
2853
        $yVeic += $h;
2854
        $texto = 'Cmkg...............: ' . $veiculoCmkg;
2855
        $this->pTextBox($x, $yVeic, $w1+40, $h, $texto, $aFont, 'T', 'L', 0, '');
2856
        $yVeic += $h;
2857
        $texto = 'Tipo.................: ' . $renavamTiposVeiculos[intval($veiculoTipo)];
2858
        $this->pTextBox($x, $yVeic, $w1+40, $h, $texto, $aFont, 'T', 'L', 0, '');
2859
        $yVeic = $y + $h;
2860
        $xVeic = $x + 65;
2861
        $texto = 'Nº Motor: .........: ' . $veiculoMotor;
2862
        $this->pTextBox($xVeic, $yVeic, $w1+50, $h, $texto, $aFont, 'T', 'L', 0, '');
2863
        $yVeic += $h;
2864
        $texto = 'Renavam...........: ' . $veiculoRenavam;
2865
        $this->pTextBox($xVeic, $yVeic, $w1+50, $h, $texto, $aFont, 'T', 'L', 0, '');
2866
        $yVeic += $h;
2867
        $texto = 'HP.....................: ' . $veiculoHp;
2868
        $this->pTextBox($xVeic, $yVeic, $w1+50, $h, $texto, $aFont, 'T', 'L', 0, '');
2869
        $yVeic += $h;
2870
        $texto = 'Placa.................: ' . $veiculoPlaca;
2871
        $this->pTextBox($xVeic, $yVeic, $w1+50, $h, $texto, $aFont, 'T', 'L', 0, '');
2872
        $yVeic += $h;
2873
        $texto = 'Tipo Pintura......: ' . $renavamTipoPintura[$veiculoTipoPintura];
2874
        $this->pTextBox($xVeic, $yVeic, $w1+50, $h, $texto, $aFont, 'T', 'L', 0, '');
2875
        $yVeic = $y + $h;
2876
        $xVeic = $xVeic + 55;
2877
        $texto = 'Marca / Modelo.....: ' . $veiculoMarcaModelo;
2878
        $this->pTextBox($xVeic, $yVeic, $w1+50, $h, $texto, $aFont, 'T', 'L', 0, '');
2879
        $yVeic += $h;
2880
        $texto = 'Especie..................: ' . $renavamEspecie[intval($veiculoEspecie)];
2881
        $this->pTextBox($xVeic, $yVeic, $w1+50, $h, $texto, $aFont, 'T', 'L', 0, '');
2882
        $yVeic += $h;
2883
        $texto = 'Combustivel..........: ' . $renavamCombustivel[intval($veiculoCombustivel)];
2884
        $this->pTextBox($xVeic, $yVeic, $w1+50, $h, $texto, $aFont, 'T', 'L', 0, '');
2885
        $yVeic += $h;
2886
        $texto = 'Serial.....................: ' . $veiculoSerial;
2887
        $this->pTextBox($xVeic, $yVeic, $w1+50, $h, $texto, $aFont, 'T', 'L', 0, '');
2888
        $yVeic += $h;
2889
        $texto = 'Ano Fab/Mod........: '. $veiculoFabricacao . '/' . $veiculoModelo;
2890
        $this->pTextBox($xVeic, $yVeic, $w1+50, $h, $texto, $aFont, 'T', 'L', 0, '');
2891
        $yVeic += $h;
2892
        $texto = 'Distancia Entre Eixos(mm)..: '. $veiculoDistancia;
2893
        $this->pTextBox($xVeic, $yVeic, $w1+50, $h, $texto, $aFont, 'T', 'L', 0, '');
2894
    }
2895
2896
    /**
2897
     * issqnDANFE
2898
     * Monta o campo de serviços do DANFE
2899
     *
2900
     * @name   issqnDANFE (retrato e paisagem)
2901
     * @param  float $x Posição horizontal canto esquerdo
2902
     * @param  float $y Posição vertical canto superior
2903
     * @return float Posição vertical final
2904
     */
2905
    protected function pIssqnDANFE($x, $y)
2906
    {
2907
        $oldX = $x;
0 ignored issues
show
Unused Code introduced by
$oldX is not used, you could remove the assignment.

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

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

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

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

Loading history...
2908
        //#####################################################################
2909
        //CÁLCULO DO ISSQN
2910
        $texto = "CÁLCULO DO ISSQN";
2911
        $w = $this->wPrint;
2912
        $h = 7;
2913
        $aFont = array('font'=>$this->fontePadrao, 'size'=>7, 'style'=>'B');
2914
        $this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 0, '');
2915
        //INSCRIÇÃO MUNICIPAL
2916
        $y += 3;
2917
        $w = round($this->wPrint*0.23, 0);
2918
        $texto = 'INSCRIÇÃO MUNICIPAL';
2919
        $aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>'');
2920
        $this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 1, '');
2921
        //inscrição municipal
2922
        $texto = ! empty($this->emit->getElementsByTagName("IM")->item(0)->nodeValue) ?
2923
                $this->emit->getElementsByTagName("IM")->item(0)->nodeValue : '';
2924
        $aFont = array('font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B');
2925
        $this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'B', 'L', 0, '');
2926
        //VALOR TOTAL DOS SERVIÇOS
2927
        $x += $w;
2928
        $texto = 'VALOR TOTAL DOS SERVIÇOS';
2929
        $aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>'');
2930
        $this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 1, '');
2931
        if (isset($this->ISSQNtot)) {
2932
            $texto = ! empty($this->ISSQNtot->getElementsByTagName("vServ")->item(0)->nodeValue) ?
2933
                    $this->ISSQNtot->getElementsByTagName("vServ")->item(0)->nodeValue : '';
2934
            $texto = number_format($texto, 2, ",", ".");
2935
        } else {
2936
            $texto = '';
2937
        }
2938
        $aFont = array('font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B');
2939
        $this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'B', 'R', 0, '');
2940
        //BASE DE CÁLCULO DO ISSQN
2941
        $x += $w;
2942
        $texto = 'BASE DE CÁLCULO DO ISSQN';
2943
        $aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>'');
2944
        $this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 1, '');
2945
        if (isset($this->ISSQNtot)) {
2946
            $texto = ! empty($this->ISSQNtot->getElementsByTagName("vBC")->item(0)->nodeValue) ?
2947
                    $this->ISSQNtot->getElementsByTagName("vBC")->item(0)->nodeValue : '';
2948
            $texto = ! empty($texto) ? number_format($texto, 2, ",", ".") : '';
2949
        } else {
2950
            $texto = '';
2951
        }
2952
        $aFont = array('font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B');
2953
        $this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'B', 'R', 0, '');
2954
        //VALOR TOTAL DO ISSQN
2955
        $x += $w;
2956
        if ($this->orientacao == 'P') {
2957
            $w = $this->wPrint - (3 * $w);
2958
        } else {
2959
            $w = $this->wPrint - (3 * $w)-$this->wCanhoto;
2960
        }
2961
        $texto = 'VALOR TOTAL DO ISSQN';
2962
        $aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>'');
2963
        $this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 1, '');
2964
        if (isset($this->ISSQNtot)) {
2965
            $texto = ! empty($this->ISSQNtot->getElementsByTagName("vISS")->item(0)->nodeValue) ?
2966
                    $this->ISSQNtot->getElementsByTagName("vISS")->item(0)->nodeValue : '';
2967
            $texto = ! empty($texto) ? number_format($texto, 2, ",", ".") : '';
2968
        } else {
2969
            $texto = '';
2970
        }
2971
        $aFont = array('font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B');
2972
        $this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'B', 'R', 0, '');
2973
        return ($y+$h+1);
2974
    }
2975
2976
    /**
2977
     *dadosAdicionaisDANFE
2978
     * Coloca o grupo de dados adicionais da NFe. (retrato e paisagem)
2979
     *
2980
     * @name   dadosAdicionaisDANFE
2981
     * @param  float $x Posição horizontal canto esquerdo
2982
     * @param  float $y Posição vertical canto superior
2983
     * @param  float $h altura do campo
2984
     * @return float Posição vertical final (eixo Y)
2985
     */
2986
    protected function pDadosAdicionaisDANFE($x, $y, $h)
2987
    {
2988
        //##################################################################################
2989
        //DADOS ADICIONAIS
2990
        $texto = "DADOS ADICIONAIS";
2991
        if ($this->orientacao == 'P') {
2992
              $w = $this->wPrint;
2993
        } else {
2994
              $w = $this->wPrint-$this->wCanhoto;
2995
        }
2996
        $aFont = array('font'=>$this->fontePadrao, 'size'=>7, 'style'=>'B');
2997
        $this->pTextBox($x, $y, $w, 8, $texto, $aFont, 'T', 'L', 0, '');
2998
        //INFORMAÇÕES COMPLEMENTARES
2999
        $texto = "INFORMAÇÕES COMPLEMENTARES";
3000
        $y += 3;
3001
        $w = $this->wAdic;
3002
        $aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>'B');
3003
        $this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 1, '');
3004
        //o texto com os dados adicionais foi obtido na função montaDANFE
3005
        //e carregado em uma propriedade privada da classe
3006
        //$this->wAdic com a largura do campo
3007
        //$this->textoAdic com o texto completo do campo
3008
        $y += 1;
3009
        $aFont = array('font'=>$this->fontePadrao, 'size'=>7, 'style'=>'');
3010
        $this->pTextBox($x, $y+2, $w-2, $h-3, $this->textoAdic, $aFont, 'T', 'L', 0, '', false);
3011
        //RESERVADO AO FISCO
3012
        $texto = "RESERVADO AO FISCO";
3013
        $x += $w;
3014
        $y -= 1;
3015
        if ($this->orientacao == 'P') {
3016
            $w = $this->wPrint-$w;
3017
        } else {
3018
            $w = $this->wPrint-$w-$this->wCanhoto;
3019
        }
3020
        $aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>'B');
3021
        $this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 1, '');
3022
        //inserir texto informando caso de contingência
3023
        // 1 - Normal - emissão normal;
3024
        // 2 - Contingência FS - emissão em contingência com impressão do DANFE em Formulário de Segurança;
3025
        // 3 - Contingência SCAN - emissão em contingência no Sistema de Contingência do Ambiente Nacional;
3026
        // 4 - Contingência DPEC - emissão em contingência com envio da Declaração
3027
        //     Prévia de Emissão em Contingência;
3028
        // 5 - Contingência FS-DA - emissão em contingência com impressão do DANFE em Formulário de
3029
        //     Segurança para Impressão de Documento Auxiliar de Documento Fiscal Eletrônico (FS-DA);
3030
        // 6 - Contingência SVC-AN
3031
        // 7 - Contingência SVC-RS
3032
        $xJust = $this->pSimpleGetValue($this->ide, 'xJust', 'Justificativa: ');
3033
        $dhCont = $this->pSimpleGetValue($this->ide, 'dhCont', ' Entrada em contingência : ');
3034
        $texto = '';
3035
        switch ($this->tpEmis) {
3036
            case 2:
3037
                $texto = 'CONTINGÊNCIA FS' . $dhCont . $xJust;
3038
                break;
3039
            case 3:
3040
                $texto = 'CONTINGÊNCIA SCAN' . $dhCont . $xJust;
3041
                break;
3042
            case 4:
3043
                $texto = 'CONTINGÊNCIA DPEC' . $dhCont . $xJust;
3044
                break;
3045
            case 5:
3046
                $texto = 'CONTINGÊNCIA FSDA' . $dhCont . $xJust;
3047
                break;
3048
            case 6:
3049
                $texto = 'CONTINGÊNCIA SVC-AN' . $dhCont . $xJust;
3050
                break;
3051
            case 7:
3052
                $texto = 'CONTINGÊNCIA SVC-RS' . $dhCont . $xJust;
3053
                break;
3054
        }
3055
        $y += 2;
3056
        $aFont = array('font'=>$this->fontePadrao, 'size'=>7, 'style'=>'');
3057
        $this->pTextBox($x, $y, $w-2, $h-3, $texto, $aFont, 'T', 'L', 0, '', false);
3058
        return $y+$h;
3059
    }
3060
3061
    /**
3062
     * pRodape
3063
     * Monta o rodapé no final da DANFE com a data/hora de impressão e informações
3064
     * sobre a API NfePHP
3065
     *
3066
     * @name   pRodape
3067
     * @param  float $xInic  Posição horizontal canto esquerdo
0 ignored issues
show
Bug introduced by
There is no parameter named $xInic. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
3068
     * @param  float $yFinal Posição vertical final para impressão
0 ignored issues
show
Bug introduced by
There is no parameter named $yFinal. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
3069
     * @return void
3070
     */
3071
    protected function pRodape($x, $y)
3072
    {
3073
        if ($this->orientacao == 'P') {
3074
              $w = $this->wPrint;
3075
        } else {
3076
              $w = $this->wPrint-$this->wCanhoto;
3077
              $x = $this->wCanhoto;
3078
        }
3079
        $aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>'I');
3080
        $texto = "Impresso em ". date('d/m/Y') . " as " . date('H:i:s');
3081
        $this->pTextBox($x, $y, $w, 0, $texto, $aFont, 'T', 'L', false);
0 ignored issues
show
Documentation introduced by
false is of type boolean, but the function expects a integer.

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

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

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

function acceptsInteger($int) { }

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

// Instead of
acceptsInteger($x);

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

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

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

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

function acceptsInteger($int) { }

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

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
3084
    }
3085
3086
    /**
3087
     * pCcanhotoDANFE
3088
     * Monta o canhoto da DANFE (retrato e paisagem)
3089
     *
3090
     * @name   canhotoDANFE
3091
     * @param  number $x Posição horizontal canto esquerdo
3092
     * @param  number $y Posição vertical canto superior
3093
     * @return number Posição vertical final
3094
     *
3095
     * TODO 21/07/14 fmertins: quando orientação L-paisagem, o canhoto está sendo gerado incorretamente
3096
     */
3097
    protected function pCanhoto($x, $y)
3098
    {
3099
        $oldX = $x;
3100
        $oldY = $y;
3101
        //#################################################################################
3102
        //canhoto
3103
        //identificação do tipo de nf entrada ou saida
3104
        $tpNF = $this->ide->getElementsByTagName('tpNF')->item(0)->nodeValue;
3105
        if ($tpNF == '0') {
3106
            //NFe de Entrada
3107
            $emitente = '';
3108
            $emitente .= $this->dest->getElementsByTagName("xNome")->item(0)->nodeValue . " - ";
3109
            $emitente .= $this->enderDest->getElementsByTagName("xLgr")->item(0)->nodeValue . ", ";
3110
            $emitente .= $this->enderDest->getElementsByTagName("nro")->item(0)->nodeValue . " - ";
3111
            $emitente .= $this->pSimpleGetValue($this->enderDest, "xCpl", " - ", " ");
3112
            $emitente .= $this->enderDest->getElementsByTagName("xBairro")->item(0)->nodeValue . " ";
3113
            $emitente .= $this->enderDest->getElementsByTagName("xMun")->item(0)->nodeValue . "-";
3114
            $emitente .= $this->enderDest->getElementsByTagName("UF")->item(0)->nodeValue . "";
3115
            $destinatario = $this->emit->getElementsByTagName("xNome")->item(0)->nodeValue . " ";
3116
        } else {
3117
            //NFe de Saída
3118
            $emitente = $this->emit->getElementsByTagName("xNome")->item(0)->nodeValue . " ";
3119
            $destinatario = '';
3120
            $destinatario .= $this->dest->getElementsByTagName("xNome")->item(0)->nodeValue . " - ";
3121
            $destinatario .= $this->enderDest->getElementsByTagName("xLgr")->item(0)->nodeValue . ", ";
3122
            $destinatario .= $this->enderDest->getElementsByTagName("nro")->item(0)->nodeValue . " ";
3123
            $destinatario .= $this->pSimpleGetValue($this->enderDest, "xCpl", " - ", " ");
3124
            $destinatario .= $this->enderDest->getElementsByTagName("xBairro")->item(0)->nodeValue . " ";
3125
            $destinatario .= $this->enderDest->getElementsByTagName("xMun")->item(0)->nodeValue . "-";
3126
            $destinatario .= $this->enderDest->getElementsByTagName("UF")->item(0)->nodeValue . " ";
3127
        }
3128
        //identificação do sistema emissor
3129
        //linha separadora do canhoto
3130
        if ($this->orientacao == 'P') {
3131
            $w = round($this->wPrint * 0.81, 0);
3132
        } else {
3133
            //linha separadora do canhoto - 238
3134
            //posicao altura
3135
            $y = $this->wPrint-85;
3136
            //altura
3137
            $w = $this->wPrint-85-24;
3138
        }
3139
        $h = 10;
3140
        //desenha caixa
3141
        $texto = '';
3142
        $aFont = array('font'=>$this->fontePadrao, 'size'=>7, 'style'=>'');
3143
        $aFontSmall = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>'');
3144
        if ($this->orientacao == 'P') {
3145
            $this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'C', 'L', 1, '', false);
3146
        } else {
3147
            $this->pTextBox90($x, $y, $w, $h, $texto, $aFont, 'C', 'L', 1, '', false);
3148
        }
3149
        $numNF = str_pad($this->ide->getElementsByTagName('nNF')->item(0)->nodeValue, 9, "0", STR_PAD_LEFT);
3150
        $serie = str_pad($this->ide->getElementsByTagName('serie')->item(0)->nodeValue, 3, "0", STR_PAD_LEFT);
3151
        $texto = "RECEBEMOS DE ";
3152
        $texto .= $emitente;
3153
        $texto .= " OS PRODUTOS E/OU SERVIÇOS CONSTANTES DA NOTA FISCAL ELETRÔNICA INDICADA ";
3154
        if ($this->orientacao == 'P') {
3155
            $texto .= "ABAIXO";
3156
        } else {
3157
            $texto .= "AO LADO";
3158
        }
3159
        $texto .= ". EMISSÃO: ";
3160
        $dEmi = ! empty($this->ide->getElementsByTagName("dEmi")->item(0)->nodeValue) ?
3161
                $this->ide->getElementsByTagName("dEmi")->item(0)->nodeValue : '';
3162
        if ($dEmi == '') {
3163
            $dEmi = ! empty($this->ide->getElementsByTagName("dhEmi")->item(0)->nodeValue) ?
3164
                    $this->ide->getElementsByTagName("dhEmi")->item(0)->nodeValue : '';
3165
            $aDemi = explode('T', $dEmi);
3166
            $dEmi = $aDemi[0];
3167
        }
3168
        $texto .= $this->pYmd2dmy($dEmi) ." ";
3169
        $texto .= "VALOR TOTAL: R$ ";
3170
        $texto .= number_format($this->ICMSTot->getElementsByTagName("vNF")->item(0)->nodeValue, 2, ",", ".") . " ";
3171
        $texto .= "DESTINATÁRIO: ";
3172
        $texto .= $destinatario;
3173
        if ($this->orientacao == 'P') {
3174
            $this->pTextBox($x, $y, $w-1, $h, $texto, $aFont, 'C', 'L', 0, '', false);
3175
            $x1 = $x + $w;
3176
            $w1 = $this->wPrint - $w;
3177
            $texto = "NF-e";
3178
            $aFont = array('font'=>$this->fontePadrao, 'size'=>14, 'style'=>'B');
3179
            $this->pTextBox($x1, $y, $w1, 18, $texto, $aFont, 'T', 'C', 0, '');
3180
            $texto = "Nº. " . $this->pFormat($numNF, "###.###.###") . " \n";
3181
            $texto .= "Série $serie";
3182
            $aFont = array('font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B');
3183
            $this->pTextBox($x1, $y, $w1, 18, $texto, $aFont, 'C', 'C', 1, '');
3184
            //DATA DE RECEBIMENTO
3185
            $texto = "DATA DE RECEBIMENTO";
3186
            $y += $h;
3187
            $w2 = round($this->wPrint*0.17, 0); //35;
3188
            $aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>'');
3189
            $this->pTextBox($x, $y, $w2, 8, $texto, $aFont, 'T', 'L', 1, '');
3190
            //IDENTIFICAÇÃO E ASSINATURA DO RECEBEDOR
3191
            $x += $w2;
3192
            $w3 = $w-$w2;
3193
            $texto = "IDENTIFICAÇÃO E ASSINATURA DO RECEBEDOR";
3194
            $this->pTextBox($x, $y, $w3, 8, $texto, $aFont, 'T', 'L', 1, '');
3195
            $x = $oldX;
3196
            $y += 9;
3197
            $this->pdf->DashedHLine($x, $y, $this->wPrint, 0.1, 80);
3198
            $y += 2;
3199
            return $y;
3200
        } else {
3201
            $x--;
3202
            $x = $this->pTextBox90($x, $y, $w-1, $h, $texto, $aFontSmall, 'C', 'L', 0, '', false);
0 ignored issues
show
Unused Code introduced by
$x is not used, you could remove the assignment.

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

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

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

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

Loading history...
3203
            //NUMERO DA NOTA FISCAL LOGO NFE
3204
            $w1 = 16;
3205
            $x1 = $oldX;
3206
            $y = $oldY;
3207
            $texto = "NF-e";
3208
            $aFont = array('font'=>$this->fontePadrao, 'size'=>14, 'style'=>'B');
3209
            $this->pTextBox($x1, $y, $w1, 18, $texto, $aFont, 'T', 'C', 0, '');
3210
            $texto = "Nº.\n" . $this->pFormat($numNF, "###.###.###") . " \n";
3211
            $texto .= "Série $serie";
3212
            $aFont = array('font'=>$this->fontePadrao, 'size'=>8, 'style'=>'B');
3213
            $this->pTextBox($x1, $y, $w1, 18, $texto, $aFont, 'C', 'C', 1, '');
3214
            //DATA DO RECEBIMENTO
3215
            $texto = "DATA DO RECEBIMENTO";
3216
            $y = $this->wPrint-85;
3217
            $x = 12;
3218
            $w2 = round($this->wPrint*0.17, 0); //35;
3219
            $aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>'');
3220
            $this->pTextBox90($x, $y, $w2, 8, $texto, $aFont, 'T', 'L', 1, '');
3221
            //IDENTIFICAÇÃO E ASSINATURA DO RECEBEDOR
3222
            $y -= $w2;
3223
            $w3 = $w-$w2;
3224
            $texto = "IDENTIFICAÇÃO E ASSINATURA DO RECEBEDOR";
3225
            $aFont = array('font'=>$this->fontePadrao, 'size'=>5.7, 'style'=>'');
3226
            $x = $this->pTextBox90($x, $y, $w3, 8, $texto, $aFont, 'T', 'L', 1, '');
3227
            $this->pdf->DashedVLine(23, $oldY, 0.1, $this->wPrint-20, 67);
3228
            return $x;
3229
        }
3230
    }
3231
3232
    /**
3233
     * pGeraInformacoesDaTagCompra
3234
     * Devolve uma string contendo informação sobre as tag <compra><xNEmp>, <xPed> e <xCont> ou string vazia.
3235
     * Aviso: Esta função não leva em consideração dados na tag xPed do item.
3236
     *
3237
     * @name   pGeraInformacoesDaTagCompra
3238
     * @return string com as informacoes dos pedidos.
3239
     */
3240
    protected function pGeraInformacoesDaTagCompra()
3241
    {
3242
        $saida = "";
3243
        if (isset($this->compra)) {
3244
            if (! empty($this->compra->getElementsByTagName("xNEmp")->item(0)->nodeValue)) {
3245
                $saida .= " Nota de Empenho: " . $this->compra->getElementsByTagName("xNEmp")->item(0)->nodeValue;
3246
            }
3247
            if (! empty($this->compra->getElementsByTagName("xPed")->item(0)->nodeValue)) {
3248
                $saida .= " Pedido: " . $this->compra->getElementsByTagName("xPed")->item(0)->nodeValue;
3249
            }
3250
            if (! empty($this->compra->getElementsByTagName("xCont")->item(0)->nodeValue)) {
3251
                $saida .= " Contrato: " . $this->compra->getElementsByTagName("xCont")->item(0)->nodeValue;
3252
            }
3253
        }
3254
        return $saida;
3255
    }
3256
3257
    /**
3258
     * pGeraChaveAdicionalDeContingencia
3259
     *
3260
     * @name   pGeraChaveAdicionalDeContingencia
3261
     * @return string chave
3262
     */
3263
    protected function pGeraChaveAdicionalDeContingencia()
3264
    {
3265
        //cUF tpEmis CNPJ vNF ICMSp ICMSs DD  DV
3266
        // 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...
3267
        $forma  = "%02d%d%s%014d%01d%01d%02d";
3268
        $cUF    = $this->ide->getElementsByTagName('cUF')->item(0)->nodeValue;
3269
        $CNPJ   = "00000000000000" . $this->emit->getElementsByTagName('CNPJ')->item(0)->nodeValue;
3270
        $CNPJ   = substr($CNPJ, -14);
3271
        $vNF    = $this->ICMSTot->getElementsByTagName("vNF")->item(0)->nodeValue * 100;
3272
        $vICMS  = $this->ICMSTot->getElementsByTagName("vICMS")->item(0)->nodeValue;
3273
        if ($vICMS > 0) {
3274
            $vICMS = 1;
3275
        }
3276
        $icmss  = $this->ICMSTot->getElementsByTagName("vBC")->item(0)->nodeValue;
3277
        if ($icmss > 0) {
3278
            $icmss = 1;
3279
        }
3280
        $dEmi = ! empty($this->ide->getElementsByTagName("dEmi")->item(0)->nodeValue) ?
3281
                $this->ide->getElementsByTagName("dEmi")->item(0)->nodeValue : '';
3282
        if ($dEmi == '') {
3283
            $dEmi = ! empty($this->ide->getElementsByTagName("dhEmi")->item(0)->nodeValue) ?
3284
                    $this->ide->getElementsByTagName("dhEmi")->item(0)->nodeValue : '';
3285
            $aDemi = explode('T', $dEmi);
3286
            $dEmi = $aDemi[0];
3287
        }
3288
        $dd  = $dEmi;
3289
        $rpos = strrpos($dd, '-');
3290
        $dd  = substr($dd, $rpos +1);
3291
        $chave = sprintf($forma, $cUF, $this->tpEmis, $CNPJ, $vNF, $vICMS, $icmss, $dd);
3292
        $chave = $chave . $this->pModulo11($chave);
3293
        return $chave;
3294
    }
3295
3296
    /**
3297
     * pGeraInformacoesDasNotasReferenciadas
3298
     * Devolve uma string contendo informação sobre as notas referenciadas. Suporta N notas, eletrônicas ou não
3299
     * Exemplo: NFe Ref.: série: 01 número: 01 emit: 11.111.111/0001-01
3300
     * em 10/2010 [0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000]
3301
     *
3302
     * @return string Informacoes a serem adicionadas no rodapé sobre notas referenciadas.
3303
     */
3304
    protected function pGeraInformacoesDasNotasReferenciadas()
3305
    {
3306
        $formaNfeRef = "\r\nNFe Ref.: série:%d número:%d emit:%s em %s [%s]";
3307
        $formaCTeRef = "\r\nCTe Ref.: série:%d número:%d emit:%s em %s [%s]";
3308
        $formaNfRef = "\r\nNF  Ref.: série:%d numero:%d emit:%s em %s modelo: %d";
3309
        $formaECFRef = "\r\nECF Ref.: modelo: %s ECF:%d COO:%d";
3310
        $formaNfpRef = "\r\nNFP Ref.: série:%d número:%d emit:%s em %s modelo: %d IE:%s";
3311
        $saida='';
3312
        $nfRefs = $this->ide->getElementsByTagName('NFref');
3313
        if (0 === $nfRefs->length) {
3314
            return $saida;
3315
        }
3316
        foreach ($nfRefs as $nfRef) {
3317
            if (empty($nfRef)) {
3318
                continue;
3319
            }
3320
            $refNFe = $nfRef->getElementsByTagName('refNFe');
3321
            foreach ($refNFe as $chave_acessoRef) {
3322
                $chave_acesso = $chave_acessoRef->nodeValue;
3323
                $chave_acessoF = $this->pFormat($chave_acesso, $this->formatoChave);
3324
                $data = substr($chave_acesso, 4, 2)."/20".substr($chave_acesso, 2, 2);
3325
                $cnpj = $this->pFormat(substr($chave_acesso, 6, 14), "##.###.###/####-##");
3326
                $serie  = substr($chave_acesso, 22, 3);
3327
                $numero = substr($chave_acesso, 25, 9);
3328
                $saida .= sprintf($formaNfeRef, $serie, $numero, $cnpj, $data, $chave_acessoF);
3329
            }
3330
            $refNF = $nfRef->getElementsByTagName('refNF');
3331
            foreach ($refNF as $umaRefNFe) {
3332
                $data = $umaRefNFe->getElementsByTagName('AAMM')->item(0)->nodeValue;
3333
                $cnpj = $umaRefNFe->getElementsByTagName('CNPJ')->item(0)->nodeValue;
3334
                $mod = $umaRefNFe->getElementsByTagName('mod')->item(0)->nodeValue;
3335
                $serie = $umaRefNFe->getElementsByTagName('serie')->item(0)->nodeValue;
3336
                $numero = $umaRefNFe->getElementsByTagName('nNF')->item(0)->nodeValue;
3337
                $data = substr($data, 2, 2) . "/20" . substr($data, 0, 2);
3338
                $cnpj = $this->pFormat($cnpj, "##.###.###/####-##");
3339
                $saida .= sprintf($formaNfRef, $serie, $numero, $cnpj, $data, $mod);
3340
            }
3341
            $refCTe = $nfRef->getElementsByTagName('refCTe');
3342
            foreach ($refCTe as $chave_acessoRef) {
3343
                $chave_acesso = $chave_acessoRef->nodeValue;
3344
                $chave_acessoF = $this->pFormat($chave_acesso, $this->formatoChave);
3345
                $data = substr($chave_acesso, 4, 2)."/20".substr($chave_acesso, 2, 2);
3346
                $cnpj = $this->pFormat(substr($chave_acesso, 6, 14), "##.###.###/####-##");
3347
                $serie  = substr($chave_acesso, 22, 3);
3348
                $numero = substr($chave_acesso, 25, 9);
3349
                $saida .= sprintf($formaCTeRef, $serie, $numero, $cnpj, $data, $chave_acessoF);
3350
            }
3351
            $refECF = $nfRef->getElementsByTagName('refECF');
3352
            foreach ($refECF as $umaRefNFe) {
3353
                $mod    = $umaRefNFe->getElementsByTagName('mod')->item(0)->nodeValue;
3354
                $nECF   = $umaRefNFe->getElementsByTagName('nECF')->item(0)->nodeValue;
3355
                $nCOO   = $umaRefNFe->getElementsByTagName('nCOO')->item(0)->nodeValue;
3356
                $saida .= sprintf($formaECFRef, $mod, $nECF, $nCOO);
3357
            }
3358
            $refNFP = $nfRef->getElementsByTagName('refNFP');
3359
            foreach ($refNFP as $umaRefNFe) {
3360
                $data = $umaRefNFe->getElementsByTagName('AAMM')->item(0)->nodeValue;
3361
                $cnpj = ! empty($umaRefNFe->getElementsByTagName('CNPJ')->item(0)->nodeValue) ?
3362
                    $umaRefNFe->getElementsByTagName('CNPJ')->item(0)->nodeValue :
3363
                    '';
3364
                $cpf = ! empty($umaRefNFe->getElementsByTagName('CPF')->item(0)->nodeValue) ?
3365
                        $umaRefNFe->getElementsByTagName('CPF')->item(0)->nodeValue : '';
3366
                $mod = $umaRefNFe->getElementsByTagName('mod')->item(0)->nodeValue;
3367
                $serie = $umaRefNFe->getElementsByTagName('serie')->item(0)->nodeValue;
3368
                $numero = $umaRefNFe->getElementsByTagName('nNF')->item(0)->nodeValue;
3369
                $ie = $umaRefNFe->getElementsByTagName('IE')->item(0)->nodeValue;
3370
                $data = substr($data, 2, 2) . "/20" . substr($data, 0, 2);
3371
                if ($cnpj == '') {
3372
                    $cpf_cnpj = $this->pFormat($cpf, "###.###.###-##");
3373
                } else {
3374
                    $cpf_cnpj = $this->pFormat($cnpj, "##.###.###/####-##");
3375
                }
3376
                $saida .= sprintf($formaNfpRef, $serie, $numero, $cpf_cnpj, $data, $mod, $ie);
3377
            }
3378
        }
3379
        return $saida;
3380
    }
3381
    
3382
    private function imagePNGtoJPG($original)
3383
    {
3384
        $image = imagecreatefrompng($original);
3385
        ob_start();
3386
        imagejpeg($image, null, 100);
3387
        imagedestroy($image);
3388
        $stringdata = ob_get_contents(); // read from buffer
3389
        ob_end_clean();
3390
        return 'data://text/plain;base64,'.base64_encode($stringdata);
3391
    }
3392
}
3393