Passed
Push — master ( f47aed...e4694f )
by Roberto
05:27
created

Danfe::creditsIntegratorFooter()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
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
13
    const FPDF_FONTPATH = 'font/';
14
    const SIT_CANCELADA = 1;
15
    const SIT_DENEGADA = 2;
16
    const SIT_DPEC = 3;
17
    const SIT_NONE = 0;
18
19
    /**
20
     * alinhamento padrão do logo (C-Center)
21
     *
22
     * @var string
23
     */
24
    public $logoAlign = 'C';
25
    /**
26
     * Posição
27
     * @var float
28
     */
29
    public $yDados = 0;
30
    /**
31
     * Situação
32
     * @var integer
33
     */
34
    public $situacaoExterna = 0;
35
    /**
36
     * Numero DPEC
37
     *
38
     * @var string
39
     */
40
    public $numero_registro_dpec = '';
41
    /**
42
     * quantidade de canhotos a serem montados, geralmente 1 ou 2
43
     *
44
     * @var integer
45
     */
46
    public $qCanhoto = 1;
47
48
    //###########################################################
49
    // INÍCIO ATRIBUTOS DE PARÂMETROS DE EXIBIÇÃO
50
    //###########################################################
51
52
    /**
53
     * Parâmetro para exibir ou ocultar os valores do PIS/COFINS.
54
     * @var boolean
55
     */
56
    public $exibirPIS = true;
57
    /**
58
     * Parâmetro para exibir ou ocultar os valores do ICMS Interestadual e Valor Total dos Impostos.
59
     * @var boolean
60
     */
61
    public $exibirIcmsInterestadual = true;
62
    /**
63
     * Parâmetro para exibir ou ocultar o texto sobre valor aproximado dos tributos.
64
     * @var boolean
65
     */
66
    public $exibirValorTributos = true;
67
    /**
68
     * Parâmetro para exibir ou ocultar o texto adicional sobre a forma de pagamento
69
     * e as informações de fatura/duplicata.
70
     * @var boolean
71
     */
72
    public $exibirTextoFatura = false;
73
    /**
74
     * Parâmetro do controle se deve concatenar automaticamente informações complementares
75
     * na descrição do produto, como por exemplo, informações sobre impostos.
76
     * @var boolean
77
     */
78
    public $descProdInfoComplemento = true;
79
    /**
80
     * Parâmetro do controle se deve gerar quebras de linha com "\n" a partir de ";" na descrição do produto.
81
     * @var boolean
82
     */
83
    public $descProdQuebraLinha = true;
84
85
    //###########################################################
86
    //PROPRIEDADES DA CLASSE
87
    //###########################################################
88
89
    /**
90
     * objeto fpdf()
91
     * @var object
92
     */
93
    protected $pdf;
94
    /**
95
     * XML NFe
96
     * @var string
97
     */
98
    protected $xml;
99
    /**
100
     * path para logomarca em jpg
101
     * @var string
102
     */
103
    protected $logomarca = '';
104
    /**
105
     * mesagens de erro
106
     * @var string
107
     */
108
    protected $errMsg = '';
109
    /**
110
     * status de erro true um erro ocorreu false sem erros
111
     * @var boolean
112
     */
113
    protected $errStatus = false;
114
    /**
115
     * orientação da DANFE
116
     * P-Retrato ou L-Paisagem
117
     * @var string
118
     */
119
    protected $orientacao = 'P';
120
    /**
121
     * formato do papel
122
     * @var string
123
     */
124
    protected $papel = 'A4';
125
    /**
126
     * destino do arquivo pdf
127
     * I-borwser, S-retorna o arquivo, D-força download, F-salva em arquivo local
128
     * @var string
129
     */
130
    protected $destino = 'I';
131
    /**
132
     * diretorio para salvar o pdf com a opção de destino = F
133
     * @var string
134
     */
135
    protected $pdfDir = '';
136
    /**
137
     * Nome da Fonte para gerar o DANFE
138
     * @var string
139
     */
140
    protected $fontePadrao = 'Times';
141
    /**
142
     * versão
143
     * @var string
144
     */
145
    protected $version = '2.2.8';
146
    /**
147
     * Texto
148
     * @var string
149
     */
150
    protected $textoAdic = '';
151
    /**
152
     * Largura
153
     * @var float
154
     */
155
    protected $wAdic = 0;
156
    /**
157
     * largura imprimivel, em milímetros
158
     * @var float
159
     */
160
    protected $wPrint;
161
    /**
162
     * Comprimento (altura) imprimivel, em milímetros
163
     * @var float
164
     */
165
    protected $hPrint;
166
    /**
167
     * largura do canhoto (25mm) apenas para a formatação paisagem
168
     * @var float
169
     */
170
    protected $wCanhoto = 25;
171
    /**
172
     * Formato chave
173
     * @var string
174
     */
175
    protected $formatoChave = "#### #### #### #### #### #### #### #### #### #### ####";
176
    /**
177
     * quantidade de itens já processados na montagem do DANFE
178
     * @var integer
179
     */
180
    protected $qtdeItensProc;
181
182
    /**
183
     * Document
184
     * @var DOMDocument
185
     */
186
    protected $dom;
187
    /**
188
     * Node
189
     * @var DOMNode
190
     */
191
    protected $infNFe;
192
    /**
193
     * Node
194
     * @var DOMNode
195
     */
196
    protected $ide;
197
    /**
198
     * Node
199
     * @var DOMNode
200
     */
201
    protected $entrega;
202
    /**
203
     * Node
204
     * @var DOMNode
205
     */
206
    protected $retirada;
207
    /**
208
     * Node
209
     * @var DOMNode
210
     */
211
    protected $emit;
212
    /**
213
     * Node
214
     * @var DOMNode
215
     */
216
    protected $dest;
217
    /**
218
     * Node
219
     * @var DOMNode
220
     */
221
    protected $enderEmit;
222
    /**
223
     * Node
224
     * @var DOMNode
225
     */
226
    protected $enderDest;
227
    /**
228
     * Node
229
     * @var DOMNode
230
     */
231
    protected $det;
232
    /**
233
     * Node
234
     * @var DOMNode
235
     */
236
    protected $cobr;
237
    /**
238
     * Node
239
     * @var DOMNode
240
     */
241
    protected $dup;
242
    /**
243
     * Node
244
     * @var DOMNode
245
     */
246
    protected $ICMSTot;
247
    /**
248
     * Node
249
     * @var DOMNode
250
     */
251
    protected $ISSQNtot;
252
    /**
253
     * Node
254
     * @var DOMNode
255
     */
256
    protected $transp;
257
    /**
258
     * Node
259
     * @var DOMNode
260
     */
261
    protected $transporta;
262
    /**
263
     * Node
264
     * @var DOMNode
265
     */
266
    protected $veicTransp;
267
    /**
268
     * Node reboque
269
     * @var DOMNode
270
     */
271
    protected $reboque;
272
    /**
273
     * Node infAdic
274
     * @var DOMNode
275
     */
276
    protected $infAdic;
277
    /**
278
     * Tipo de emissão
279
     * @var integer
280
     */
281
    protected $tpEmis;
282
    /**
283
     * Node infProt
284
     * @var DOMNode
285
     */
286
    protected $infProt;
287
    /**
288
     * 1-Retrato/ 2-Paisagem
289
     * @var integer
290
     */
291
    protected $tpImp;
292
    /**
293
     * Node compra
294
     * @var DOMNode
295
     */
296
    protected $compra;
297
    /**
298
     * ativa ou desativa o modo de debug
299
     * @var integer
300
     */
301
    protected $debugMode=2;
302
    /**
303
     * Creditos para integrador
304
     * @var string
305
     */
306
    protected $creditos = '';
307
308
    /**
309
     * __construct
310
     *
311
     * @name  __construct
312
     * @param string  $docXML      Conteúdo XML da NF-e (com ou sem a tag nfeProc)
313
     * @param string  $sOrientacao (Opcional) Orientação da impressão P-retrato L-Paisagem
314
     * @param string  $sPapel      Tamanho do papel (Ex. A4)
315
     * @param string  $sPathLogo   Caminho para o arquivo do logo
316
     * @param string  $sDestino    Estabelece a direção do envio do documento PDF I-browser D-browser com download S-
317
     * @param string  $sDirPDF     Caminho para o diretorio de armazenamento dos arquivos PDF
318
     * @param string  $fonteDANFE  Nome da fonte alternativa do DAnfe
319
     * @param integer $mododebug   0-Não 1-Sim e 2-nada (2 default)
320
     */
321
    public function __construct(
322
        $docXML = '',
323
        $sOrientacao = '',
324
        $sPapel = '',
325
        $sPathLogo = '',
326
        $sDestino = 'I',
327
        $sDirPDF = '',
328
        $fonteDANFE = '',
329
        $mododebug = 2
330
    ) {
331
        //set_time_limit(1800);
332
        if (is_numeric($mododebug)) {
333
            $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...
334
        }
335
        if ($mododebug == 1) {
336
            //ativar modo debug
337
            error_reporting(E_ALL);
338
            ini_set('display_errors', 'On');
339
        }
340
        if ($mododebug == 0) {
341
            //desativar modo debug
342
            error_reporting(0);
343
            ini_set('display_errors', 'Off');
344
        }
345
        $this->orientacao   = $sOrientacao;
346
        $this->papel        = $sPapel;
347
        $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...
348
        $this->xml          = $docXML;
349
        $this->logomarca    = $sPathLogo;
350
        $this->destino      = $sDestino;
351
        $this->pdfDir       = $sDirPDF;
352
        // verifica se foi passa a fonte a ser usada
353
        if (empty($fonteDANFE)) {
354
            $this->fontePadrao = 'Times';
355
        } else {
356
            $this->fontePadrao = $fonteDANFE;
357
        }
358
        //se for passado o xml
359
        if (! empty($this->xml)) {
360
            $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...
361
            $this->dom->loadXML($this->xml);
362
            $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...
363
            $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...
364
            $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...
365
            $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...
366
            $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...
367
            $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...
368
            $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...
369
            $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...
370
            $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...
371
            $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...
372
            $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...
373
            $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...
374
            $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...
375
            $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...
376
            $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...
377
            $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...
378
            $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...
379
            $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...
380
            $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...
381
            $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...
382
            $this->tpEmis     = $this->ide->getElementsByTagName("tpEmis")->item(0)->nodeValue;
383
            $this->tpImp      = $this->ide->getElementsByTagName("tpImp")->item(0)->nodeValue;
384
            $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...
385
            //valida se o XML é uma NF-e modelo 55, pois não pode ser 65 (NFC-e)
386
            if ($this->pSimpleGetValue($this->ide, "mod") != '55') {
387
                throw new InvalidArgumentException("O xml do DANFE deve ser uma NF-e modelo 55");
388
            }
389
        }
390
    }
391
392
    /**
393
     * Add the credits to the integrator in the footer message
394
     * @param string $message
395
     */
396
    public function creditsIntegratorFooter($message = '')
397
    {
398
        $this->creditos = trim($message);
399
    }
400
    
401
    /**
402
     * monta
403
     *
404
     * @name   monta
405
     * @param  string $orientacao
406
     * @param  string $papel
407
     * @param  string $logoAlign
408
     * @return string
409
     */
410
    public function monta(
411
        $orientacao = '',
412
        $papel = 'A4',
413
        $logoAlign = 'C',
414
        $situacaoExterna = self::SIT_NONE,
415
        $classPdf = false,
416
        $dpecNumReg = '',
417
        $margSup = 2,
418
        $margEsq = 2,
419
        $margInf = 2
420
    ) {
421
        return $this->montaDANFE(
422
            $orientacao,
423
            $papel,
424
            $logoAlign,
425
            $situacaoExterna,
426
            $classPdf,
427
            $dpecNumReg,
428
            $margSup,
429
            $margEsq,
430
            $margInf
431
        );
432
    }
433
434
    /**
435
     * printDocument
436
     *
437
     * @param  string $nome
438
     * @param  string $destino
439
     * @param  string $printer
440
     * @return object pdf
441
     */
442
    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...
443
    {
444
        $arq = $this->pdf->Output($nome, $destino);
445
        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...
446
            //aqui pode entrar a rotina de impressão direta
447
        }
448
        return $arq;
449
    }
450
451
    /**
452
     * montaDANFE
453
     * Monta a DANFE conforme as informações fornecidas para a classe durante sua
454
     * construção. Constroi DANFEs com até 3 páginas podendo conter até 56 itens.
455
     * A definição de margens e posições iniciais para a impressão são estabelecidas
456
     * pelo conteúdo da funçao e podem ser modificados.
457
     *
458
     * @param  string $orientacao (Opcional) Estabelece a orientação da impressão
459
     *  (ex. P-retrato), se nada for fornecido será usado o padrão da NFe
460
     * @param  string $papel      (Opcional) Estabelece o tamanho do papel (ex. A4)
461
     * @return string O ID da NFe numero de 44 digitos extraido do arquivo XML
462
     */
463
    public function montaDANFE(
464
        $orientacao = '',
465
        $papel = 'A4',
466
        $logoAlign = 'C',
467
        $situacaoExterna = self::SIT_NONE,
468
        $classPdf = false,
469
        $depecNumReg = '',
470
        $margSup = 2,
471
        $margEsq = 2,
472
        $margInf = 2
473
    ) {
474
        //se a orientação estiver em branco utilizar o padrão estabelecido na NF
475
        if ($orientacao == '') {
476
            if ($this->tpImp == '1') {
477
                $orientacao = 'P';
478
            } else {
479
                $orientacao = 'L';
480
            }
481
        }
482
        $this->orientacao = $orientacao;
483
        $this->pAdicionaLogoPeloCnpj();
484
        $this->papel = $papel;
485
        $this->logoAlign = $logoAlign;
486
        $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...
487
        $this->numero_registro_dpec = $depecNumReg;
488
        //instancia a classe pdf
489
        if ($classPdf) {
490
            $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...
491
        } else {
492
            $this->pdf = new Pdf($this->orientacao, 'mm', $this->papel);
493
        }
494
        //margens do PDF, em milímetros. Obs.: a margem direita é sempre igual à
495
        //margem esquerda. A margem inferior *não* existe na FPDF, é definida aqui
496
        //apenas para controle se necessário ser maior do que a margem superior
497
        // posição inicial do conteúdo, a partir do canto superior esquerdo da página
498
        $xInic = $margEsq;
499
        $yInic = $margSup;
500
        if ($this->orientacao == 'P') {
501
            if ($papel == 'A4') {
502
                $maxW = 210;
503
                $maxH = 297;
504
            }
505
        } else {
506
            if ($papel == 'A4') {
507
                $maxH = 210;
508
                $maxW = 297;
509
                //se paisagem multiplica a largura do canhoto pela quantidade de canhotos
510
                $this->wCanhoto *= $this->qCanhoto;
511
            }
512
        }
513
        //total inicial de paginas
514
        $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...
515
        //largura imprimivel em mm: largura da folha menos as margens esq/direita
516
        $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...
517
        //comprimento (altura) imprimivel em mm: altura da folha menos as margens
518
        //superior e inferior
519
        $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...
520
        // estabelece contagem de paginas
521
        $this->pdf->aliasNbPages();
522
        // fixa as margens
523
        $this->pdf->setMargins($margEsq, $margSup);
524
        $this->pdf->setDrawColor(0, 0, 0);
525
        $this->pdf->setFillColor(255, 255, 255);
526
        // inicia o documento
527
        $this->pdf->open();
528
        // adiciona a primeira página
529
        $this->pdf->addPage($this->orientacao, $this->papel);
530
        $this->pdf->setLineWidth(0.1);
531
        $this->pdf->setTextColor(0, 0, 0);
532
533
        //##################################################################
534
        // CALCULO DO NUMERO DE PAGINAS A SEREM IMPRESSAS
535
        //##################################################################
536
        //Verificando quantas linhas serão usadas para impressão das duplicatas
537
        $linhasDup = 0;
538
        if (($this->dup->length > 0) && ($this->dup->length <= 7)) {
539
            $linhasDup = 1;
540
        } elseif (($this->dup->length > 7) && ($this->dup->length <= 14)) {
541
            $linhasDup = 2;
542
        } elseif (($this->dup->length > 14) && ($this->dup->length <= 21)) {
543
            $linhasDup = 3;
544
        } elseif ($this->dup->length > 21) {
545
            // chinnonsantos 11/05/2016: Limite máximo de impressão de duplicatas na NFe,
546
            // só vai ser exibito as 21 primeiras duplicatas (parcelas de pagamento),
547
            // se não oculpa espaço d+, cada linha comporta até 7 duplicatas.
548
            $linhasDup = 3;
549
        }
550
        //verifica se será impressa a linha dos serviços ISSQN
551
        $linhaISSQN = 0;
552
        if ((isset($this->ISSQNtot)) && ($this->pSimpleGetValue($this->ISSQNtot, 'vServ') > 0)) {
553
            $linhaISSQN = 1;
554
        }
555
        //calcular a altura necessária para os dados adicionais
556
        if ($this->orientacao == 'P') {
557
            $this->wAdic = round($this->wPrint*0.66, 0);
558
        } else {
559
            $this->wAdic = round(($this->wPrint-$this->wCanhoto)*0.5, 0);
560
        }
561
        $fontProduto = array('font'=>$this->fontePadrao, 'size'=>7, 'style'=>'');
562
        $this->textoAdic = '';
563
        if (isset($this->retirada)) {
564
            $txRetCNPJ = ! empty($this->retirada->getElementsByTagName("CNPJ")->item(0)->nodeValue) ?
565
                $this->retirada->getElementsByTagName("CNPJ")->item(0)->nodeValue :
566
                '';
567
            $txRetxLgr = ! empty($this->retirada->getElementsByTagName("xLgr")->item(0)->nodeValue) ?
568
                $this->retirada->getElementsByTagName("xLgr")->item(0)->nodeValue :
569
                '';
570
            $txRetnro = ! empty($this->retirada->getElementsByTagName("nro")->item(0)->nodeValue) ?
571
                $this->retirada->getElementsByTagName("nro")->item(0)->nodeValue :
572
                's/n';
573
            $txRetxCpl = $this->pSimpleGetValue($this->retirada, "xCpl", " - ");
574
            $txRetxBairro = ! empty($this->retirada->getElementsByTagName("xBairro")->item(0)->nodeValue) ?
575
                $this->retirada->getElementsByTagName("xBairro")->item(0)->nodeValue :
576
                '';
577
            $txRetxMun = ! empty($this->retirada->getElementsByTagName("xMun")->item(0)->nodeValue) ?
578
                $this->retirada->getElementsByTagName("xMun")->item(0)->nodeValue :
579
                '';
580
            $txRetUF = ! empty($this->retirada->getElementsByTagName("UF")->item(0)->nodeValue) ?
581
                $this->retirada->getElementsByTagName("UF")->item(0)->nodeValue :
582
                '';
583
            $this->textoAdic .= "LOCAL DE RETIRADA : ".
584
                    $txRetCNPJ.
585
                    '-' .
586
                    $txRetxLgr .
587
                    ', ' .
588
                    $txRetnro .
589
                    ' ' .
590
                    $txRetxCpl .
591
                    ' - ' .
592
                    $txRetxBairro .
593
                    ' ' .
594
                    $txRetxMun .
595
                    ' - ' .
596
                    $txRetUF .
597
                    "\r\n";
598
        }
599
        //dados do local de entrega da mercadoria
600
        if (isset($this->entrega)) {
601
            $txRetCNPJ = ! empty($this->entrega->getElementsByTagName("CNPJ")->item(0)->nodeValue) ?
602
                $this->entrega->getElementsByTagName("CNPJ")->item(0)->nodeValue : '';
603
            $txRetxLgr = ! empty($this->entrega->getElementsByTagName("xLgr")->item(0)->nodeValue) ?
604
                $this->entrega->getElementsByTagName("xLgr")->item(0)->nodeValue : '';
605
            $txRetnro = ! empty($this->entrega->getElementsByTagName("nro")->item(0)->nodeValue) ?
606
                $this->entrega->getElementsByTagName("nro")->item(0)->nodeValue : 's/n';
607
            $txRetxCpl = $this->pSimpleGetValue($this->entrega, "xCpl", " - ");
608
            $txRetxBairro = ! empty($this->entrega->getElementsByTagName("xBairro")->item(0)->nodeValue) ?
609
                $this->entrega->getElementsByTagName("xBairro")->item(0)->nodeValue : '';
610
            $txRetxMun = ! empty($this->entrega->getElementsByTagName("xMun")->item(0)->nodeValue) ?
611
                $this->entrega->getElementsByTagName("xMun")->item(0)->nodeValue : '';
612
            $txRetUF = ! empty($this->entrega->getElementsByTagName("UF")->item(0)->nodeValue) ?
613
                $this->entrega->getElementsByTagName("UF")->item(0)->nodeValue : '';
614
            if ($this->textoAdic != '') {
615
                $this->textoAdic .= ". \r\n";
616
            }
617
            $this->textoAdic .= "LOCAL DE ENTREGA : ".$txRetCNPJ.'-'.$txRetxLgr.', '.$txRetnro.' '.$txRetxCpl.
618
               ' - '.$txRetxBairro.' '.$txRetxMun.' - '.$txRetUF."\r\n";
619
        }
620
        //informações adicionais
621
        $this->textoAdic .= $this->pGeraInformacoesDasNotasReferenciadas();
622
        if (isset($this->infAdic)) {
623
            $i = 0;
624
            if ($this->textoAdic != '') {
625
                $this->textoAdic .= ". \r\n";
626
            }
627
            $this->textoAdic .= ! empty($this->infAdic->getElementsByTagName("infCpl")->item(0)->nodeValue) ?
628
                'Inf. Contribuinte: ' .
629
                trim($this->pAnfavea($this->infAdic->getElementsByTagName("infCpl")->item(0)->nodeValue)) : '';
630
            $infPedido = $this->pGeraInformacoesDaTagCompra();
631
            if ($infPedido != "") {
632
                $this->textoAdic .= $infPedido;
633
            }
634
            $this->textoAdic .= $this->pSimpleGetValue($this->dest, "email", ' Email do Destinatário: ');
635
            $this->textoAdic .= ! empty($this->infAdic->getElementsByTagName("infAdFisco")->item(0)->nodeValue) ?
636
                "\r\n Inf. fisco: " .
637
                trim($this->infAdic->getElementsByTagName("infAdFisco")->item(0)->nodeValue) : '';
638
            $obsCont = $this->infAdic->getElementsByTagName("obsCont");
639
            if (isset($obsCont)) {
640
                foreach ($obsCont as $obs) {
641
                    $campo =  $obsCont->item($i)->getAttribute("xCampo");
642
                    $xTexto = ! empty($obsCont->item($i)->getElementsByTagName("xTexto")->item(0)->nodeValue) ?
643
                        $obsCont->item($i)->getElementsByTagName("xTexto")->item(0)->nodeValue : '';
644
                    $this->textoAdic .= "\r\n" . $campo . ':  ' . trim($xTexto);
645
                    $i++;
646
                }
647
            }
648
        }
649
        //INCLUSO pela NT 2013.003 Lei da Transparência
650
        //verificar se a informação sobre o valor aproximado dos tributos
651
        //já se encontra no campo de informações adicionais
652
        if ($this->exibirValorTributos) {
653
            $flagVTT = strpos(strtolower(trim($this->textoAdic)), 'valor');
654
            $flagVTT = $flagVTT || strpos(strtolower(trim($this->textoAdic)), 'vl');
655
            $flagVTT = $flagVTT && strpos(strtolower(trim($this->textoAdic)), 'aprox');
656
            $flagVTT = $flagVTT && (strpos(strtolower(trim($this->textoAdic)), 'trib') ||
657
                    strpos(strtolower(trim($this->textoAdic)), 'imp'));
658
            $vTotTrib = $this->pSimpleGetValue($this->ICMSTot, 'vTotTrib');
659
            if ($vTotTrib != '' && !$flagVTT) {
660
                $this->textoAdic .= "\n Valor Aproximado dos Tributos : R$ " . number_format($vTotTrib, 2, ",", ".");
661
            }
662
        }
663
        //fim da alteração NT 2013.003 Lei da Transparência
664
        $this->textoAdic = str_replace(";", "\n", $this->textoAdic);
665
        $alinhas = explode("\n", $this->textoAdic);
666
        $numlinhasdados = 0;
667
        foreach ($alinhas as $linha) {
668
            $numlinhasdados += $this->pGetNumLines($linha, $this->wAdic, $fontProduto);
669
        }
670
        $hdadosadic = round(($numlinhasdados+3) * $this->pdf->fontSize, 0);
671
        if ($hdadosadic < 10) {
672
            $hdadosadic = 10;
673
        }
674
        //altura disponivel para os campos da DANFE
675
        $hcabecalho = 47;//para cabeçalho
676
        $hdestinatario = 25;//para destinatario
677
        $hduplicatas = 12;//para cada grupo de 7 duplicatas
678
        $himposto = 18;// para imposto
679
        $htransporte = 25;// para transporte
680
        $hissqn = 11;// para issqn
681
        $hfooter = 5;// para rodape
682
        $hCabecItens = 4;//cabeçalho dos itens
683
        //alturas disponiveis para os dados
684
        $hDispo1 = $this->hPrint - 10 - ($hcabecalho +
685
            $hdestinatario + ($linhasDup * $hduplicatas) + $himposto + $htransporte +
686
            ($linhaISSQN * $hissqn) + $hdadosadic + $hfooter + $hCabecItens +
687
            $this->pSizeExtraTextoFatura());
688
        if ($this->orientacao == 'P') {
689
            $hDispo1 -= 23 * $this->qCanhoto;//para canhoto
690
            $w = $this->wPrint;
691
        } else {
692
            $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...
693
            $w = $this->wPrint - $this->wCanhoto;
694
        }
695
        $hDispo2 = $this->hPrint - 10 - ($hcabecalho + $hfooter + $hCabecItens)-4;
696
        //Contagem da altura ocupada para impressão dos itens
697
        $fontProduto = array('font'=>$this->fontePadrao, 'size'=>7, 'style'=>'');
698
        $i = 0;
699
        $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...
700
        $hUsado = $hCabecItens;
701
        $w2 = round($w*0.28, 0);
702
        $hDispo = $hDispo1;
703
        $totPag = 1;
704
        while ($i < $this->det->length) {
705
            $texto = $this->pDescricaoProduto($this->det->item($i));
706
            $numlinhas = $this->pGetNumLines($texto, $w2, $fontProduto);
707
            $hUsado += round(($numlinhas * $this->pdf->fontSize) + ($numlinhas * 0.5), 2);
708
            if ($hUsado > $hDispo) {
709
                $totPag++;
710
                $hDispo = $hDispo2;
711
                $hUsado = $hCabecItens;
712
                // Remove canhoto para páginas secundárias em modo paisagem ('L')
713
                $w2 = round($this->wPrint*0.28, 0);
714
                $i--; // decrementa para readicionar o item que não coube nessa pagina na outra.
715
            }
716
            $i++;
717
        } //fim da soma das areas de itens usadas
718
        $qtdeItens = $i; //controle da quantidade de itens no DANFE
719
        //montagem da primeira página
720
        $pag = 1;
721
        $x = $xInic;
722
        $y = $yInic;
723
        //coloca o(s) canhoto(s) da NFe
724
        if ($this->orientacao == 'P') {
725
            for ($i = 1; $i <= $this->qCanhoto; $i++) {
726
                $y = $this->pCanhoto($x, $y);
727
            }
728
        } else {
729
            for ($i = 1; $i <= $this->qCanhoto; $i++) {
730
                $this->pCanhoto($x, $y);
731
                $x = 25 * $i;
732
            }
733
        }
734
        //coloca o cabeçalho
735
        $y = $this->pCabecalhoDANFE($x, $y, $pag, $totPag);
736
        //coloca os dados do destinatário
737
        $y = $this->pDestinatarioDANFE($x, $y+1);
738
        //coloca os dados das faturas
739
        $y = $this->pFaturaDANFE($x, $y+1);
740
        //coloca os dados dos impostos e totais da NFe
741
        $y = $this->pImpostoDANFE($x, $y+1);
742
        //coloca os dados do trasnporte
743
        $y = $this->pTransporteDANFE($x, $y+1);
744
        //itens da DANFE
745
        $nInicial = 0;
746
        $y = $this->pItensDANFE($x, $y+1, $nInicial, $hDispo1, $pag, $totPag, $hCabecItens);
747
        //coloca os dados do ISSQN
748
        if ($linhaISSQN == 1) {
749
            $y = $this->pIssqnDANFE($x, $y+4);
750
        } else {
751
            $y += 4;
752
        }
753
        //coloca os dados adicionais da NFe
754
        $y = $this->pDadosAdicionaisDANFE($x, $y, $hdadosadic);
755
        //coloca o rodapé da página
756
        if ($this->orientacao == 'P') {
757
            $this->pRodape($xInic, $y-1);
758
        } else {
759
            $this->pRodape($xInic, $this->hPrint + 1);
760
        }
761
        //loop para páginas seguintes
762
        for ($n = 2; $n <= $totPag; $n++) {
763
            // fixa as margens
764
            $this->pdf->setMargins($margEsq, $margSup);
765
            //adiciona nova página
766
            $this->pdf->addPage($this->orientacao, $this->papel);
767
            //ajusta espessura das linhas
768
            $this->pdf->setLineWidth(0.1);
769
            //seta a cor do texto para petro
770
            $this->pdf->setTextColor(0, 0, 0);
771
            // posição inicial do relatorio
772
            $x = $xInic;
773
            $y = $yInic;
774
            //coloca o cabeçalho na página adicional
775
            $y = $this->pCabecalhoDANFE($x, $y, $n, $totPag);
776
            //coloca os itens na página adicional
777
            $y = $this->pItensDANFE($x, $y+1, $nInicial, $hDispo2, $n, $totPag, $hCabecItens);
778
            //coloca o rodapé da página
779
            if ($this->orientacao == 'P') {
780
                $this->pRodape($xInic, $y + 4);
781
            } else {
782
                $this->pRodape($xInic, $this->hPrint + 4);
783
            }
784
            //se estiver na última página e ainda restar itens para inserir, adiciona mais uma página
785
            if ($n == $totPag && $this->qtdeItensProc < $qtdeItens) {
786
                $totPag++;
787
            }
788
        }
789
        //retorna o ID na NFe
790
        if ($classPdf!==false) {
791
            $aR = array(
792
             'id'=>str_replace('NFe', '', $this->infNFe->getAttribute("Id")),
793
             'classe_PDF'=>$this->pdf);
794
            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...
795
        } else {
796
            return str_replace('NFe', '', $this->infNFe->getAttribute("Id"));
797
        }
798
    }//fim da função montaDANFE
799
800
    /**
801
     * anfavea
802
     * Função para transformar o campo cdata do padrão ANFAVEA para
803
     * texto imprimível
804
     *
805
     * @param  string $cdata campo CDATA
806
     * @return string conteúdo do campo CDATA como string
807
     */
808
    private function pAnfavea($cdata = '')
809
    {
810
        if ($cdata == '') {
811
            return '';
812
        }
813
        //remove qualquer texto antes ou depois da tag CDATA
814
        $cdata = str_replace('<![CDATA[', '<CDATA>', $cdata);
815
        $cdata = str_replace(']]>', '</CDATA>', $cdata);
816
        $cdata = preg_replace('/\s\s+/', ' ', $cdata);
817
        $cdata = str_replace("> <", "><", $cdata);
818
        $len = strlen($cdata);
819
        $startPos = strpos($cdata, '<');
820
        if ($startPos === false) {
821
            return $cdata;
822
        }
823
        for ($x=$len; $x>0; $x--) {
824
            if (substr($cdata, $x, 1) == '>') {
825
                $endPos = $x;
826
                break;
827
            }
828
        }
829
        if ($startPos > 0) {
830
            $parte1 = substr($cdata, 0, $startPos);
831
        } else {
832
            $parte1 = '';
833
        }
834
        $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...
835
        if ($endPos < $len) {
836
            $parte3 = substr($cdata, $endPos + 1, $len - $endPos - 1);
837
        } else {
838
            $parte3 = '';
839
        }
840
        $texto = trim($parte1).' '.trim($parte3);
841
        if (strpos($parte2, '<CDATA>') === false) {
842
            $cdata = '<CDATA>'.$parte2.'</CDATA>';
843
        } else {
844
            $cdata = $parte2;
845
        }
846
        //Retira a tag <FONTE IBPT> (caso existir) pois não é uma estrutura válida XML
847
        $cdata = str_replace('<FONTE IBPT>', '', $cdata);
848
        //carrega o xml CDATA em um objeto DOM
849
        $dom = new Dom();
850
        $dom->loadXML($cdata, LIBXML_NOBLANKS | LIBXML_NOEMPTYTAG);
851
        //$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...
852
        //grupo CDATA infADprod
853
        $id = $dom->getElementsByTagName('id')->item(0);
854
        $div = $dom->getElementsByTagName('div')->item(0);
855
        $entg = $dom->getElementsByTagName('entg')->item(0);
856
        $dest = $dom->getElementsByTagName('dest')->item(0);
857
        $ctl = $dom->getElementsByTagName('ctl')->item(0);
858
        $ref = $dom->getElementsByTagName('ref')->item(0);
859
        if (isset($id)) {
860
            if ($id->hasAttributes()) {
861
                foreach ($id->attributes as $attr) {
862
                    $name = $attr->nodeName;
863
                    $value = $attr->nodeValue;
864
                    $texto .= " $name : $value";
865
                }
866
            }
867
        }
868
        if (isset($div)) {
869
            if ($div->hasAttributes()) {
870
                foreach ($div->attributes as $attr) {
871
                    $name = $attr->nodeName;
872
                    $value = $attr->nodeValue;
873
                    $texto .= " $name : $value";
874
                }
875
            }
876
        }
877
        if (isset($entg)) {
878
            if ($entg->hasAttributes()) {
879
                foreach ($entg->attributes as $attr) {
880
                    $name = $attr->nodeName;
881
                    $value = $attr->nodeValue;
882
                    $texto .= " $name : $value";
883
                }
884
            }
885
        }
886
        if (isset($dest)) {
887
            if ($dest->hasAttributes()) {
888
                foreach ($dest->attributes as $attr) {
889
                    $name = $attr->nodeName;
890
                    $value = $attr->nodeValue;
891
                    $texto .= " $name : $value";
892
                }
893
            }
894
        }
895
        if (isset($ctl)) {
896
            if ($ctl->hasAttributes()) {
897
                foreach ($ctl->attributes as $attr) {
898
                    $name = $attr->nodeName;
899
                    $value = $attr->nodeValue;
900
                    $texto .= " $name : $value";
901
                }
902
            }
903
        }
904
        if (isset($ref)) {
905
            if ($ref->hasAttributes()) {
906
                foreach ($ref->attributes as $attr) {
907
                    $name = $attr->nodeName;
908
                    $value = $attr->nodeValue;
909
                    $texto .= " $name : $value";
910
                }
911
            }
912
        }
913
        //grupo CADATA infCpl
914
        $t = $dom->getElementsByTagName('transmissor')->item(0);
915
        $r = $dom->getElementsByTagName('receptor')->item(0);
916
        $versao = ! empty($dom->getElementsByTagName('versao')->item(0)->nodeValue) ?
917
            'Versao:'.$dom->getElementsByTagName('versao')->item(0)->nodeValue.' ' : '';
918
        $especieNF = ! empty($dom->getElementsByTagName('especieNF')->item(0)->nodeValue) ?
919
            'Especie:'.$dom->getElementsByTagName('especieNF')->item(0)->nodeValue.' ' : '';
920
        $fabEntrega = ! empty($dom->getElementsByTagName('fabEntrega')->item(0)->nodeValue) ?
921
            'Entrega:'.$dom->getElementsByTagName('fabEntrega')->item(0)->nodeValue.' ' : '';
922
        $dca = ! empty($dom->getElementsByTagName('dca')->item(0)->nodeValue) ?
923
            'dca:'.$dom->getElementsByTagName('dca')->item(0)->nodeValue.' ' : '';
924
        $texto .= "".$versao.$especieNF.$fabEntrega.$dca;
925
        if (isset($t)) {
926
            if ($t->hasAttributes()) {
927
                $texto .= " Transmissor ";
928
                foreach ($t->attributes as $attr) {
929
                    $name = $attr->nodeName;
930
                    $value = $attr->nodeValue;
931
                    $texto .= " $name : $value";
932
                }
933
            }
934
        }
935
        if (isset($r)) {
936
            if ($r->hasAttributes()) {
937
                $texto .= " Receptor ";
938
                foreach ($r->attributes as $attr) {
939
                    $name = $attr->nodeName;
940
                    $value = $attr->nodeValue;
941
                    $texto .= " $name : $value";
942
                }
943
            }
944
        }
945
        return $texto;
946
    }
947
948
    /**
949
     * Dados brutos do PDF
950
     * @return string
951
     */
952
    public function render()
953
    {
954
        return $this->pdf->getPdf();
955
    }
956
957
    protected function pNotaCancelada()
958
    {
959
        if (!isset($this->nfeProc)) {
960
            return false;
961
        }
962
        $cStat = $this->pSimpleGetValue($this->nfeProc, "cStat");
963
        return $cStat == '101' ||
964
                $cStat == '151' ||
965
                $cStat == '135' ||
966
                $cStat == '155' ||
967
                $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...
968
    }
969
970
    protected function pNotaDPEC()
971
    {
972
        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...
973
    }
974
975
    protected function pNotaDenegada()
976
    {
977
        if (!isset($this->nfeProc)) {
978
            return false;
979
        }
980
        //NÃO ERA NECESSÁRIO ESSA FUNÇÃO POIS SÓ SE USA
981
        //1 VEZ NO ARQUIVO INTEIRO
982
        $cStat = $this->pSimpleGetValue($this->nfeProc, "cStat");
983
        return $cStat == '110' ||
984
               $cStat == '301' ||
985
               $cStat == '302' ||
986
               $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...
987
    }
988
989
    /**
990
     *cabecalhoDANFE
991
     * Monta o cabelhalho da DANFE (retrato e paisagem)
992
     *
993
     * @param  number $x      Posição horizontal inicial, canto esquerdo
994
     * @param  number $y      Posição vertical inicial, canto superior
995
     * @param  number $pag    Número da Página
996
     * @param  number $totPag Total de páginas
997
     * @return number Posição vertical final
998
     */
999
    protected function pCabecalhoDANFE($x = 0, $y = 0, $pag = '1', $totPag = '1')
1000
    {
1001
        $oldX = $x;
1002
        $oldY = $y;
1003
        if ($this->orientacao == 'P') {
1004
              $maxW = $this->wPrint;
1005
        } else {
1006
            if ($pag == 1) { // primeira página
1007
                $maxW = $this->wPrint - $this->wCanhoto;
1008
            } else { // páginas seguintes
1009
                $maxW = $this->wPrint;
1010
            }
1011
        }
1012
        //####################################################################################
1013
        //coluna esquerda identificação do emitente
1014
        $w = round($maxW*0.41, 0);
1015
        if ($this->orientacao == 'P') {
1016
            $aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>'I');
1017
        } else {
1018
            $aFont = array('font'=>$this->fontePadrao, 'size'=>8, 'style'=>'B');
1019
        }
1020
        $w1 = $w;
1021
        $h=32;
1022
        $oldY += $h;
1023
        $this->pTextBox($x, $y, $w, $h);
1024
        $texto = 'IDENTIFICAÇÃO DO EMITENTE';
1025
        $this->pTextBox($x, $y, $w, 5, $texto, $aFont, 'T', 'C', 0, '');
1026
        //estabelecer o alinhamento
1027
        //pode ser left L, center C, right R, full logo L
1028
        //se for left separar 1/3 da largura para o tamanho da imagem
1029
        //os outros 2/3 serão usados para os dados do emitente
1030
        //se for center separar 1/2 da altura para o logo e 1/2 para os dados
1031
        //se for right separa 2/3 para os dados e o terço seguinte para o logo
1032
        //se não houver logo centraliza dos dados do emitente
1033
        // coloca o logo
1034
        if (is_file($this->logomarca)) {
1035
            $logoInfo=getimagesize($this->logomarca);
1036
            //largura da imagem em mm
1037
            $logoWmm = ($logoInfo[0]/72)*25.4;
1038
            //altura da imagem em mm
1039
            $logoHmm = ($logoInfo[1]/72)*25.4;
1040
            if ($this->logoAlign=='L') {
1041
                $nImgW = round($w/3, 0);
1042
                $nImgH = round($logoHmm * ($nImgW/$logoWmm), 0);
1043
                $xImg = $x+1;
1044
                $yImg = round(($h-$nImgH)/2, 0)+$y;
1045
                //estabelecer posições do texto
1046
                $x1 = round($xImg + $nImgW +1, 0);
1047
                $y1 = round($h/3+$y, 0);
1048
                $tw = round(2*$w/3, 0);
1049
            } elseif ($this->logoAlign=='C') {
1050
                $nImgH = round($h/3, 0);
1051
                $nImgW = round($logoWmm * ($nImgH/$logoHmm), 0);
1052
                $xImg = round(($w-$nImgW)/2+$x, 0);
1053
                $yImg = $y+3;
1054
                $x1 = $x;
1055
                $y1 = round($yImg + $nImgH + 1, 0);
1056
                $tw = $w;
1057
            } elseif ($this->logoAlign=='R') {
1058
                $nImgW = round($w/3, 0);
1059
                $nImgH = round($logoHmm * ($nImgW/$logoWmm), 0);
1060
                $xImg = round($x+($w-(1+$nImgW)), 0);
1061
                $yImg = round(($h-$nImgH)/2, 0)+$y;
1062
                $x1 = $x;
1063
                $y1 = round($h/3+$y, 0);
1064
                $tw = round(2*$w/3, 0);
1065
            } elseif ($this->logoAlign=='F') {
1066
                $nImgH = round($h-5, 0);
1067
                $nImgW = round($logoWmm * ($nImgH/$logoHmm), 0);
1068
                $xImg = round(($w-$nImgW)/2+$x, 0);
1069
                $yImg = $y+3;
1070
                $x1 = $x;
1071
                $y1 = round($yImg + $nImgH + 1, 0);
1072
                $tw = $w;
1073
            }
1074
            $this->pdf->Image($this->logomarca, $xImg, $yImg, $nImgW, $nImgH);
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...
1075
        } else {
1076
            $x1 = $x;
1077
            $y1 = round($h/3+$y, 0);
1078
            $tw = $w;
1079
        }
1080
        // monta as informações apenas se diferente de full logo
1081
        if ($this->logoAlign !== 'F') {
1082
            //Nome emitente
1083
            $aFont = array('font'=>$this->fontePadrao, 'size'=>12, 'style'=>'B');
1084
            $texto = $this->emit->getElementsByTagName("xNome")->item(0)->nodeValue;
1085
            $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...
1086
            //endereço
1087
            $y1 = $y1+5;
1088
            $aFont = array('font'=>$this->fontePadrao, 'size'=>8, 'style'=>'');
1089
            $fone = ! empty($this->enderEmit->getElementsByTagName("fone")->item(0)->nodeValue)
1090
                 ? $this->enderEmit->getElementsByTagName("fone")->item(0)->nodeValue
1091
                 : '';
1092
            $lgr = $this->pSimpleGetValue($this->enderEmit, "xLgr");
1093
            $nro = $this->pSimpleGetValue($this->enderEmit, "nro");
1094
            $cpl = $this->pSimpleGetValue($this->enderEmit, "xCpl", " - ");
1095
            $bairro = $this->pSimpleGetValue($this->enderEmit, "xBairro");
1096
            $CEP = $this->pSimpleGetValue($this->enderEmit, "CEP");
1097
            $CEP = $this->pFormat($CEP, "#####-###");
1098
            $mun = $this->pSimpleGetValue($this->enderEmit, "xMun");
1099
            $UF = $this->pSimpleGetValue($this->enderEmit, "UF");
1100
            $texto = $lgr . ", " . $nro . $cpl . "\n" . $bairro . " - "
1101
                    . $CEP . "\n" . $mun . " - " . $UF . " "
1102
                    . "Fone/Fax: " . $fone;
1103
            $this->pTextBox($x1, $y1, $tw, 8, $texto, $aFont, 'T', 'C', 0, '');
1104
        }
1105
1106
        //####################################################################################
1107
        //coluna central Danfe
1108
        $x += $w;
1109
        $w=round($maxW * 0.17, 0);//35;
1110
        $w2 = $w;
1111
        $h = 32;
1112
        $this->pTextBox($x, $y, $w, $h);
1113
1114
        if (! $this->pNotaCancelada()) {
1115
            // A PRINCIPIO NÃO PRECISAVA, POIS A NFE ESTÁ AUTORIZADA,
1116
            // SÓ SE RETIRA O DANFE PARA NOTAS NÃO AUTORIZADAS
1117
            $texto = "DANFE";
1118
            $aFont = array('font'=>$this->fontePadrao, 'size'=>14, 'style'=>'B');
1119
            $this->pTextBox($x, $y+1, $w, $h, $texto, $aFont, 'T', 'C', 0, '');
1120
            $aFont = array('font'=>$this->fontePadrao, 'size'=>8, 'style'=>'');
1121
            $texto = 'Documento Auxiliar da Nota Fiscal Eletrônica';
1122
            $h = 20;
1123
            $this->pTextBox($x, $y+6, $w, $h, $texto, $aFont, 'T', 'C', 0, '', false);
1124
        }
1125
1126
        $aFont = array('font'=>$this->fontePadrao, 'size'=>8, 'style'=>'');
1127
        $texto = '0 - ENTRADA';
1128
        $y1 = $y + 14;
1129
        $h = 8;
1130
        $this->pTextBox($x+2, $y1, $w, $h, $texto, $aFont, 'T', 'L', 0, '');
1131
        $texto = '1 - SAÍDA';
1132
        $y1 = $y + 17;
1133
        $this->pTextBox($x+2, $y1, $w, $h, $texto, $aFont, 'T', 'L', 0, '');
1134
        //tipo de nF
1135
        $aFont = array('font'=>$this->fontePadrao, 'size'=>12, 'style'=>'B');
1136
        $y1 = $y + 13;
1137
        $h = 7;
1138
        $texto = $this->ide->getElementsByTagName('tpNF')->item(0)->nodeValue;
1139
        $this->pTextBox($x+27, $y1, 5, $h, $texto, $aFont, 'C', 'C', 1, '');
1140
        //numero da NF
1141
        $aFont = array('font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B');
1142
        $y1 = $y + 20;
1143
        $numNF = str_pad($this->ide->getElementsByTagName('nNF')->item(0)->nodeValue, 9, "0", STR_PAD_LEFT);
1144
        $numNF = $this->pFormat($numNF, "###.###.###");
1145
        $texto = "Nº. " . $numNF;
1146
        $this->pTextBox($x, $y1, $w, $h, $texto, $aFont, 'C', 'C', 0, '');
1147
        //Série
1148
        $y1 = $y + 23;
1149
        $serie = str_pad($this->ide->getElementsByTagName('serie')->item(0)->nodeValue, 3, "0", STR_PAD_LEFT);
1150
        $texto = "Série " . $serie;
1151
        $this->pTextBox($x, $y1, $w, $h, $texto, $aFont, 'C', 'C', 0, '');
1152
        //numero paginas
1153
        $aFont = array('font'=>$this->fontePadrao, 'size'=>8, 'style'=>'I');
1154
        $y1 = $y + 26;
1155
        $texto = "Folha " . $pag . "/" . $totPag;
1156
        $this->pTextBox($x, $y1, $w, $h, $texto, $aFont, 'C', 'C', 0, '');
1157
1158
        //####################################################################################
1159
        //coluna codigo de barras
1160
        $x += $w;
1161
        $w = ($maxW-$w1-$w2);//85;
1162
        $w3 = $w;
1163
        $h = 32;
1164
        $this->pTextBox($x, $y, $w, $h);
1165
        $this->pdf->SetFillColor(0, 0, 0);
1166
        $chave_acesso = str_replace('NFe', '', $this->infNFe->getAttribute("Id"));
1167
        $bW = 75;
1168
        $bH = 12;
1169
        //codigo de barras
1170
        $this->pdf->Code128($x+(($w-$bW)/2), $y+2, $chave_acesso, $bW, $bH);
1171
        //linhas divisorias
1172
        $this->pdf->Line($x, $y+4+$bH, $x+$w, $y+4+$bH);
1173
        $this->pdf->Line($x, $y+12+$bH, $x+$w, $y+12+$bH);
1174
        $aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>'');
1175
        $y1 = $y+4+$bH;
1176
        $h = 7;
1177
        $texto = 'CHAVE DE ACESSO';
1178
        $this->pTextBox($x, $y1, $w, $h, $texto, $aFont, 'T', 'L', 0, '');
1179
        $aFont = array('font'=>$this->fontePadrao, 'size'=>8, 'style'=>'B');
1180
        $y1 = $y+8+$bH;
1181
        $texto = $this->pFormat($chave_acesso, $this->formatoChave);
1182
        $this->pTextBox($x+2, $y1, $w-2, $h, $texto, $aFont, 'T', 'C', 0, '');
1183
        $y1 = $y+12+$bH;
1184
        $aFont = array('font'=>$this->fontePadrao, 'size'=>8, 'style'=>'');
1185
        $chaveContingencia="";
1186
        if ($this->pNotaDPEC()) {
1187
            $cabecalhoProtoAutorizacao = 'NÚMERO DE REGISTRO DPEC';
1188
        } else {
1189
            $cabecalhoProtoAutorizacao = 'PROTOCOLO DE AUTORIZAÇÃO DE USO';
1190
        }
1191
        if (($this->tpEmis == 2 || $this->tpEmis == 5) && !$this->pNotaDPEC()) {
1192
            $cabecalhoProtoAutorizacao = "DADOS DA NF-E";
1193
            $chaveContingencia = $this->pGeraChaveAdicionalDeContingencia();
1194
            $this->pdf->SetFillColor(0, 0, 0);
1195
            //codigo de barras
1196
            $this->pdf->Code128($x+11, $y1+1, $chaveContingencia, $bW*.9, $bH/2);
1197
        } else {
1198
            $texto = 'Consulta de autenticidade no portal nacional da NF-e';
1199
            $this->pTextBox($x+2, $y1, $w-2, $h, $texto, $aFont, 'T', 'C', 0, '');
1200
            $y1 = $y+16+$bH;
1201
            $texto = 'www.nfe.fazenda.gov.br/portal ou no site da Sefaz Autorizadora';
1202
            $this->pTextBox(
1203
                $x+2,
1204
                $y1,
1205
                $w-2,
1206
                $h,
1207
                $texto,
1208
                $aFont,
1209
                'T',
1210
                'C',
1211
                0,
1212
                'http://www.nfe.fazenda.gov.br/portal ou no site da Sefaz Autorizadora'
1213
            );
1214
        }
1215
1216
        //####################################################################################
1217
        //Dados da NF do cabeçalho
1218
        //natureza da operação
1219
        $texto = 'NATUREZA DA OPERAÇÃO';
1220
        $aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>'');
1221
        $w = $w1+$w2;
1222
        $y = $oldY;
1223
        $oldY += $h;
1224
        $x = $oldX;
1225
        $h = 7;
1226
        $this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 1, '');
1227
        $texto = $this->ide->getElementsByTagName("natOp")->item(0)->nodeValue;
1228
        $aFont = array('font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B');
1229
        $this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'B', 'C', 0, '');
1230
        $x += $w;
1231
        $w = $w3;
1232
        //PROTOCOLO DE AUTORIZAÇÃO DE USO ou DADOS da NF-E
1233
        $aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>'');
1234
        $this->pTextBox($x, $y, $w, $h, $cabecalhoProtoAutorizacao, $aFont, 'T', 'L', 1, '');
1235
        // algumas NFe podem estar sem o protocolo de uso portanto sua existencia deve ser
1236
        // testada antes de tentar obter a informação.
1237
        // NOTA : DANFE sem protocolo deve existir somente no caso de contingência !!!
1238
        // Além disso, existem várias NFes em contingência que eu recebo com protocolo de autorização.
1239
        // Na minha opinião, deveríamos mostra-lo, mas o  manual  da NFe v4.01 diz outra coisa...
1240
        if (($this->tpEmis == 2 || $this->tpEmis == 5) && !$this->pNotaDPEC()) {
1241
            $aFont = array('font'=>$this->fontePadrao, 'size'=>8, 'style'=>'B');
1242
            $texto = $this->pFormat($chaveContingencia, "#### #### #### #### #### #### #### #### ####");
1243
            $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...
1244
        } else {
1245
            $aFont = array('font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B');
1246
            if ($this->pNotaDPEC()) {
1247
                $texto = $this->numero_registro_dpec;
1248
                $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...
1249
            } else {
1250
                if (isset($this->nfeProc)) {
1251
                    $texto = ! empty($this->nfeProc->getElementsByTagName("nProt")->item(0)->nodeValue) ?
1252
                            $this->nfeProc->getElementsByTagName("nProt")->item(0)->nodeValue : '';
1253
                    $tsHora = $this->pConvertTime($this->nfeProc->getElementsByTagName("dhRecbto")->item(0)->nodeValue);
1254
                    if ($texto != '') {
1255
                        $texto .= "  -  " . date('d/m/Y H:i:s', $tsHora);
1256
                    }
1257
                    $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...
1258
                } else {
1259
                    $texto = '';
1260
                    $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...
1261
                }
1262
            }
1263
        }
1264
        $this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'B', 'C', 0, '');
1265
        //####################################################################################
1266
        //INSCRIÇÃO ESTADUAL
1267
        $w = round($maxW * 0.333, 0);
1268
        $y += $h;
1269
        $oldY += $h;
1270
        $x = $oldX;
1271
        $texto = 'INSCRIÇÃO ESTADUAL';
1272
        $aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>'');
1273
        $this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 1, '');
1274
        $texto = $this->pSimpleGetValue($this->emit, "IE");
1275
        $aFont = array('font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B');
1276
        $this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'B', 'C', 0, '');
1277
        //INSCRIÇÃO ESTADUAL DO SUBST. TRIBUT.
1278
        $x += $w;
1279
        $texto = 'INSCRIÇÃO ESTADUAL DO SUBST. TRIBUT.';
1280
        $aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>'');
1281
        $this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 1, '');
1282
        $texto = ! empty($this->emit->getElementsByTagName("IEST")->item(0)->nodeValue)
1283
             ? $this->emit->getElementsByTagName("IEST")->item(0)->nodeValue
1284
             : '';
1285
        $aFont = array('font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B');
1286
        $this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'B', 'C', 0, '');
1287
        //CNPJ
1288
        $x += $w;
1289
        $w = ($maxW-(2*$w));
1290
        $texto = 'CNPJ / CPF';
1291
        $aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>'');
1292
        $this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 1, '');
1293
        //Pegando valor do CPF/CNPJ
1294
        if (! empty($this->emit->getElementsByTagName("CNPJ")->item(0)->nodeValue)) {
1295
            $texto = $this->pFormat(
1296
                $this->emit->getElementsByTagName("CNPJ")->item(0)->nodeValue,
1297
                "###.###.###/####-##"
1298
            );
1299
        } else {
1300
            $texto = ! empty($this->emit->getElementsByTagName("CPF")->item(0)->nodeValue) ?
1301
                $this->pFormat(
1302
                    $this->emit->getElementsByTagName("CPF")->item(0)->nodeValue,
1303
                    "###.###.###-##"
1304
                ) : '';
1305
        }
1306
        $aFont = array('font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B');
1307
        $this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'B', 'C', 0, '');
1308
1309
        //####################################################################################
1310
        //Indicação de NF Homologação, cancelamento e falta de protocolo
1311
        $tpAmb = $this->ide->getElementsByTagName('tpAmb')->item(0)->nodeValue;
1312
        //indicar cancelamento
1313
        if ($this->pNotaCancelada()) {
1314
            //101 Cancelamento
1315
            $x = 10;
1316
            $y = $this->hPrint-130;
1317
            $h = 25;
1318
            $w = $maxW-(2*$x);
1319
            $this->pdf->SetTextColor(90, 90, 90);
1320
            $texto = "NFe CANCELADA";
1321
            $aFont = array('font'=>$this->fontePadrao, 'size'=>48, 'style'=>'B');
1322
            $this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'C', 'C', 0, '');
1323
            $this->pdf->SetTextColor(0, 0, 0);
1324
        }
1325
1326
        if ($this->pNotaDPEC() || $this->tpEmis == 4) {
1327
            //DPEC
1328
            $x = 10;
1329
            $y = $this->hPrint-130;
1330
            $h = 25;
1331
            $w = $maxW-(2*$x);
1332
            $this->pdf->SetTextColor(200, 200, 200);
1333
            $texto = "DANFE impresso em contingência -\n".
1334
                     "DPEC regularmente recebido pela Receita\n".
1335
                     "Federal do Brasil";
1336
            $aFont = array('font'=>$this->fontePadrao, 'size'=>48, 'style'=>'B');
1337
            $this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'C', 'C', 0, '');
1338
            $this->pdf->SetTextColor(0, 0, 0);
1339
        }
1340
        if ($this->pNotaDenegada()) {
1341
            //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...
1342
            $x = 10;
1343
            $y = $this->hPrint-130;
1344
            $h = 25;
1345
            $w = $maxW-(2*$x);
1346
            $this->pdf->SetTextColor(90, 90, 90);
1347
            $texto = "NFe USO DENEGADO";
1348
            $aFont = array('font'=>$this->fontePadrao, 'size'=>48, 'style'=>'B');
1349
            $this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'C', 'C', 0, '');
1350
            $y += $h;
1351
            $h = 5;
1352
            $w = $maxW-(2*$x);
1353
            if (isset($this->infProt)) {
1354
                $xMotivo = $this->infProt->getElementsByTagName("xMotivo")->item(0)->nodeValue;
1355
            } else {
1356
                $xMotivo = '';
1357
            }
1358
            $texto = "SEM VALOR FISCAL\n".$xMotivo;
1359
            $aFont = array('font'=>$this->fontePadrao, 'size'=>48, 'style'=>'B');
1360
            $this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'C', 'C', 0, '');
1361
            $this->pdf->SetTextColor(0, 0, 0);
1362
        }
1363
        //indicar sem valor
1364
        if ($tpAmb != 1) {
1365
            $x = 10;
1366
            if ($this->orientacao == 'P') {
1367
                $y = round($this->hPrint*2/3, 0);
1368
            } else {
1369
                $y = round($this->hPrint/2, 0);
1370
            }
1371
            $h = 5;
1372
            $w = $maxW-(2*$x);
1373
            $this->pdf->SetTextColor(90, 90, 90);
1374
            $texto = "SEM VALOR FISCAL";
1375
            $aFont = array('font'=>$this->fontePadrao, 'size'=>48, 'style'=>'B');
1376
            $this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'C', 'C', 0, '');
1377
            $aFont = array('font'=>$this->fontePadrao, 'size'=>30, 'style'=>'B');
1378
            $texto = "AMBIENTE DE HOMOLOGAÇÃO";
1379
            $this->pTextBox($x, $y+14, $w, $h, $texto, $aFont, 'C', 'C', 0, '');
1380
            $this->pdf->SetTextColor(0, 0, 0);
1381
        } else {
1382
            $x = 10;
1383
            if ($this->orientacao == 'P') {
1384
                $y = round($this->hPrint*2/3, 0);
1385
            } else {
1386
                $y = round($this->hPrint/2, 0);
1387
            }//fim orientacao
1388
            $h = 5;
1389
            $w = $maxW-(2*$x);
1390
            $this->pdf->SetTextColor(90, 90, 90);
1391
            //indicar FALTA DO PROTOCOLO se NFe não for em contingência
1392
            if (($this->tpEmis == 2 || $this->tpEmis == 5) && !$this->pNotaDPEC()) {
1393
                //Contingência
1394
                $texto = "DANFE Emitido em Contingência";
1395
                $aFont = array('font'=>$this->fontePadrao, 'size'=>48, 'style'=>'B');
1396
                $this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'C', 'C', 0, '');
1397
                $aFont = array('font'=>$this->fontePadrao, 'size'=>30, 'style'=>'B');
1398
                $texto = "devido à problemas técnicos";
1399
                $this->pTextBox($x, $y+12, $w, $h, $texto, $aFont, 'C', 'C', 0, '');
1400
            } else {
1401
                if (!isset($this->nfeProc)) {
1402
                    if (!$this->pNotaDPEC()) {
1403
                        $texto = "SEM VALOR FISCAL";
1404
                        $aFont = array('font'=>$this->fontePadrao, 'size'=>48, 'style'=>'B');
1405
                        $this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'C', 'C', 0, '');
1406
                    }
1407
                    $aFont = array('font'=>$this->fontePadrao, 'size'=>30, 'style'=>'B');
1408
                    $texto = "FALTA PROTOCOLO DE APROVAÇÃO DA SEFAZ";
1409
                    if (!$this->pNotaDPEC()) {
1410
                        $this->pTextBox($x, $y+12, $w, $h, $texto, $aFont, 'C', 'C', 0, '');
1411
                    } else {
1412
                        $this->pTextBox($x, $y+25, $w, $h, $texto, $aFont, 'C', 'C', 0, '');
1413
                    }
1414
                }//fim nefProc
1415
            }//fim tpEmis
1416
            $this->pdf->SetTextColor(0, 0, 0);
1417
        }
1418
        return $oldY;
1419
    } //fim cabecalhoDANFE
1420
1421
    /**
1422
     * destinatarioDANFE
1423
     * Monta o campo com os dados do destinatário na DANFE. (retrato e paisagem)
1424
     *
1425
     * @name   destinatarioDANFE
1426
     * @param  number $x Posição horizontal canto esquerdo
1427
     * @param  number $y Posição vertical canto superior
1428
     * @return number Posição vertical final
1429
     */
1430
    protected function pDestinatarioDANFE($x = 0, $y = 0)
1431
    {
1432
        //####################################################################################
1433
        //DESTINATÁRIO / REMETENTE
1434
        $oldX = $x;
1435
        $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...
1436
        if ($this->orientacao == 'P') {
1437
            $maxW = $this->wPrint;
1438
        } else {
1439
            $maxW = $this->wPrint - $this->wCanhoto;
1440
        }
1441
        $w = $maxW;
1442
        $h = 7;
1443
        $texto = 'DESTINATÁRIO / REMETENTE';
1444
        $aFont = array('font'=>$this->fontePadrao, 'size'=>7, 'style'=>'B');
1445
        $this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 0, '');
1446
        //NOME / RAZÃO SOCIAL
1447
        $w = round($maxW*0.61, 0);
1448
        $w1 = $w;
1449
        $y += 3;
1450
        $texto = 'NOME / RAZÃO SOCIAL';
1451
        $aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>'');
1452
        $this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 1, '');
1453
        $texto = $this->dest->getElementsByTagName("xNome")->item(0)->nodeValue;
1454
        $aFont = array('font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B');
1455
        if ($this->orientacao == 'P') {
1456
            $this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'B', 'L', 0, '');
1457
        } else {
1458
            $this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'B', 'L', 1, '');
1459
        }
1460
        //CNPJ / CPF
1461
        $x += $w;
1462
        $w = round($maxW*0.23, 0);
1463
        $w2 = $w;
1464
        $texto = 'CNPJ / CPF';
1465
        $aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>'');
1466
        $this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 1, '');
1467
        //Pegando valor do CPF/CNPJ
1468
        if (! empty($this->dest->getElementsByTagName("CNPJ")->item(0)->nodeValue)) {
1469
            $texto = $this->pFormat(
1470
                $this->dest->getElementsByTagName("CNPJ")->item(0)->nodeValue,
1471
                "###.###.###/####-##"
1472
            );
1473
        } else {
1474
            $texto = ! empty($this->dest->getElementsByTagName("CPF")->item(0)->nodeValue) ?
1475
                    $this->pFormat(
1476
                        $this->dest->getElementsByTagName("CPF")->item(0)->nodeValue,
1477
                        "###.###.###-##"
1478
                    ) : '';
1479
        }
1480
        $aFont = array('font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B');
1481
        $this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'B', 'C', 0, '');
1482
        //DATA DA EMISSÃO
1483
        $x += $w;
1484
        $w = $maxW-($w1+$w2);
1485
        $wx = $w;
1486
        $texto = 'DATA DA EMISSÃO';
1487
        $aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>'');
1488
        $this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 1, '');
1489
        $dEmi = ! empty($this->ide->getElementsByTagName("dEmi")->item(0)->nodeValue) ?
1490
                $this->ide->getElementsByTagName("dEmi")->item(0)->nodeValue : '';
1491
        if ($dEmi == '') {
1492
            $dEmi = ! empty($this->ide->getElementsByTagName("dhEmi")->item(0)->nodeValue) ?
1493
                    $this->ide->getElementsByTagName("dhEmi")->item(0)->nodeValue : '';
1494
            $aDemi = explode('T', $dEmi);
1495
            $dEmi = $aDemi[0];
1496
        }
1497
        $texto = $this->pYmd2dmy($dEmi);
1498
        $aFont = array('font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B');
1499
        if ($this->orientacao == 'P') {
1500
            $this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'B', 'C', 0, '');
1501
        } else {
1502
            $this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'B', 'C', 1, '');
1503
        }
1504
        //ENDEREÇO
1505
        $w = round($maxW*0.47, 0);
1506
        $w1 = $w;
1507
        $y += $h;
1508
        $x = $oldX;
1509
        $texto = 'ENDEREÇO';
1510
        $aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>'');
1511
        $this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 1, '');
1512
        $texto = $this->dest->getElementsByTagName("xLgr")->item(0)->nodeValue;
1513
        $texto .= ', ' . $this->dest->getElementsByTagName("nro")->item(0)->nodeValue;
1514
        $texto .= $this->pSimpleGetValue($this->dest, "xCpl", " - ");
1515
1516
        $aFont = array('font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B');
1517
        $this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'B', 'L', 0, '', true);
1518
        //BAIRRO / DISTRITO
1519
        $x += $w;
1520
        $w = round($maxW*0.21, 0);
1521
        $w2 = $w;
1522
        $texto = 'BAIRRO / DISTRITO';
1523
        $aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>'');
1524
        $this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 1, '');
1525
        $texto = $this->dest->getElementsByTagName("xBairro")->item(0)->nodeValue;
1526
        $aFont = array('font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B');
1527
        $this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'B', 'C', 0, '');
1528
        //CEP
1529
        $x += $w;
1530
        $w = $maxW-$w1-$w2-$wx;
1531
        $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...
1532
        $texto = 'CEP';
1533
        $aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>'');
1534
        $this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 1, '');
1535
        $texto = ! empty($this->dest->getElementsByTagName("CEP")->item(0)->nodeValue) ?
1536
                $this->dest->getElementsByTagName("CEP")->item(0)->nodeValue : '';
1537
        $texto = $this->pFormat($texto, "#####-###");
1538
        $aFont = array('font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B');
1539
        $this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'B', 'C', 0, '');
1540
        //DATA DA SAÍDA
1541
        $x += $w;
1542
        $w = $wx;
1543
        $texto = 'DATA DA SAÍDA/ENTRADA';
1544
        $aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>'');
1545
        $this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 1, '');
1546
        $dSaiEnt = ! empty($this->ide->getElementsByTagName("dSaiEnt")->item(0)->nodeValue) ?
1547
                $this->ide->getElementsByTagName("dSaiEnt")->item(0)->nodeValue : '';
1548
        if ($dSaiEnt == '') {
1549
            $dSaiEnt = ! empty($this->ide->getElementsByTagName("dhSaiEnt")->item(0)->nodeValue) ?
1550
                    $this->ide->getElementsByTagName("dhSaiEnt")->item(0)->nodeValue : '';
1551
            $aDsaient = explode('T', $dSaiEnt);
1552
            $dSaiEnt = $aDsaient[0];
1553
        }
1554
        $texto = $this->pYmd2dmy($dSaiEnt);
1555
        $aFont = array('font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B');
1556
        $this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'B', 'C', 0, '');
1557
        //MUNICÍPIO
1558
        $w = $w1;
1559
        $y += $h;
1560
        $x = $oldX;
1561
        $texto = 'MUNICÍPIO';
1562
        $aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>'');
1563
        $this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 1, '');
1564
        $texto = $this->dest->getElementsByTagName("xMun")->item(0)->nodeValue;
1565
        if (strtoupper(trim($texto)) == "EXTERIOR" && $this->dest->getElementsByTagName("xPais")->length > 0) {
1566
            $texto .= " - " .  $this->dest->getElementsByTagName("xPais")->item(0)->nodeValue;
1567
        }
1568
        $aFont = array('font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B');
1569
        $this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'B', 'L', 0, '');
1570
        //UF
1571
        $x += $w;
1572
        $w = 8;
1573
        $texto = 'UF';
1574
        $aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>'');
1575
        $this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 1, '');
1576
        $texto = $this->dest->getElementsByTagName("UF")->item(0)->nodeValue;
1577
        $aFont = array('font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B');
1578
        $this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'B', 'C', 0, '');
1579
        //FONE / FAX
1580
        $x += $w;
1581
        $w = round(($maxW -$w1-$wx-8)/2, 0);
1582
        $w3 = $w;
1583
        $texto = 'FONE / FAX';
1584
        $aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>'');
1585
        $this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 1, '');
1586
        $texto = ! empty($this->dest->getElementsByTagName("fone")->item(0)->nodeValue) ?
1587
                $this->dest->getElementsByTagName("fone")->item(0)->nodeValue : '';
1588
        $aFont = array('font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B');
1589
        $this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'B', 'C', 0, '');
1590
        //INSCRIÇÃO ESTADUAL
1591
        $x += $w;
1592
        $w = $maxW -$w1-$wx-8-$w3;
1593
        $texto = 'INSCRIÇÃO ESTADUAL';
1594
        $aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>'');
1595
        $this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 1, '');
1596
        $IE = $this->dest->getElementsByTagName("IE");
1597
        $texto = ($IE && $IE->length > 0) ? $IE->item(0)->nodeValue : '';
1598
        $aFont = array('font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B');
1599
        $this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'B', 'C', 0, '');
1600
        //HORA DA SAÍDA
1601
        $x += $w;
1602
        $w = $wx;
1603
        $texto = 'HORA DA SAÍDA/ENTRADA';
1604
        $aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>'');
1605
        $this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 1, '');
1606
        $hSaiEnt = ! empty($this->ide->getElementsByTagName("hSaiEnt")->item(0)->nodeValue) ?
1607
                $this->ide->getElementsByTagName("hSaiEnt")->item(0)->nodeValue : '';
1608
        if ($hSaiEnt == '') {
1609
            $dhSaiEnt = ! empty($this->ide->getElementsByTagName("dhSaiEnt")->item(0)->nodeValue) ?
1610
                    $this->ide->getElementsByTagName("dhSaiEnt")->item(0)->nodeValue : '';
1611
            $tsDhSaiEnt = $this->pConvertTime($dhSaiEnt);
1612
            if ($tsDhSaiEnt != '') {
1613
                $hSaiEnt = date('H:i:s', $tsDhSaiEnt);
1614
            }
1615
        }
1616
        $texto = $hSaiEnt;
1617
        $aFont = array('font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B');
1618
        $this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'B', 'C', 0, '');
1619
        return ($y + $h);
1620
    } //fim da função destinatarioDANFE
1621
1622
     /**
1623
     * pGetTextoFatura
1624
     * Gera a String do Texto da Fatura
1625
      *
1626
     * @name   getTextoFatura
1627
     * @return a String com o texto ou "";
1628
     */
1629
    protected function pGetTextoFatura()
1630
    {
1631
        if (isset($this->cobr)) {
1632
            $fat = $this->cobr->getElementsByTagName("fat")->item(0);
1633
            if (isset($fat)) {
1634
                $textoIndPag="";
1635
                $indPag = $this->pSimpleGetValue($this->ide, "indPag");
1636
                if ($indPag === "0") {
1637
                    $textoIndPag = "Pagamento à Vista - ";
1638
                } elseif ($indPag === "1") {
1639
                    $textoIndPag = "Pagamento à Prazo - ";
1640
                }
1641
                $nFat = $this->pSimpleGetValue($fat, "nFat", "Fatura: ");
1642
                $vOrig = $this->pSimpleGetValue($fat, "vOrig", " Valor Original: ");
1643
                $vDesc = $this->pSimpleGetValue($fat, "vDesc", " Desconto: ");
1644
                $vLiq = $this->pSimpleGetValue($fat, "vLiq", " Valor Líquido: ");
1645
                $texto = $textoIndPag . $nFat . $vOrig . $vDesc . $vLiq;
1646
                return $texto;
1647
            }
1648
        }
1649
        return "";
1650
    } //fim getTextoFatura
1651
1652
     /**
1653
     * pSizeExtraTextoFatura
1654
     * Calcula o espaço ocupado pelo texto da fatura. Este espaço só é utilizado quando não houver duplicata.
1655
      *
1656
     * @name   pSizeExtraTextoFatura
1657
     * @return integer
1658
     */
1659
    protected function pSizeExtraTextoFatura()
1660
    {
1661
        $textoFatura = $this->pGetTextoFatura();
1662
        //verificar se existem duplicatas
1663
        if ($this->dup->length == 0 && $textoFatura !== "") {
1664
            return 10;
1665
        }
1666
        return 0;
1667
    }
1668
1669
    /**
1670
     * faturaDANFE
1671
     * Monta o campo de duplicatas da DANFE (retrato e paisagem)
1672
     *
1673
     * @name   faturaDANFE
1674
     * @param  number $x Posição horizontal canto esquerdo
1675
     * @param  number $y Posição vertical canto superior
1676
     * @return number Posição vertical final
1677
     */
1678
    protected function pFaturaDANFE($x, $y)
1679
    {
1680
        $linha = 1;
1681
        $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...
1682
        $oldx = $x;
1683
        $textoFatura = $this->pGetTextoFatura();
1684
        //verificar se existem duplicatas
1685
        if ($this->dup->length > 0 || $textoFatura !== "") {
1686
            //#####################################################################
1687
            //FATURA / DUPLICATA
1688
            $texto = "FATURA / DUPLICATA";
1689
            if ($this->orientacao == 'P') {
1690
                $w = $this->wPrint;
1691
            } else {
1692
                $w = 271;
1693
            }
1694
            $h = 8;
1695
            $aFont = array('font'=>$this->fontePadrao, 'size'=>7, 'style'=>'B');
1696
            $this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 0, '');
1697
            $y += 3;
1698
            $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...
1699
            $dupcont = 0;
1700
            $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...
1701
            if ($textoFatura !== "" && $this->exibirTextoFatura) {
1702
                $myH=6;
1703
                $myW = $this->wPrint;
1704
                if ($this->orientacao == 'L') {
1705
                    $myW -= $this->wCanhoto;
1706
                }
1707
                $aFont = array('font'=>$this->fontePadrao, 'size'=>8, 'style'=>'');
1708
                $this->pTextBox($x, $y, $myW, $myH, $textoFatura, $aFont, 'C', 'L', 1, '');
1709
                $y+=$myH+1;
1710
            }
1711
            if ($this->orientacao == 'P') {
1712
                $w = round($this->wPrint/7.018, 0)-1;
1713
            } else {
1714
                $w = 28;
1715
            }
1716
            $increm = 1;
1717
            foreach ($this->dup as $k => $d) {
1718
                $nDup = ! empty($this->dup->item($k)->getElementsByTagName('nDup')->item(0)->nodeValue) ?
1719
                        $this->dup->item($k)->getElementsByTagName('nDup')->item(0)->nodeValue : '';
1720
                $dDup = ! empty($this->dup->item($k)->getElementsByTagName('dVenc')->item(0)->nodeValue) ?
1721
                        $this->pYmd2dmy($this->dup->item($k)->getElementsByTagName('dVenc')->item(0)->nodeValue) : '';
1722
                $vDup = ! empty($this->dup->item($k)->getElementsByTagName('vDup')->item(0)->nodeValue) ?
1723
                        'R$ ' . number_format(
1724
                            $this->dup->item($k)->getElementsByTagName('vDup')->item(0)->nodeValue,
1725
                            2,
1726
                            ",",
1727
                            "."
1728
                        ) : '';
1729
                $h = 8;
1730
                $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...
1731
                if ($nDup!='0' && $nDup!='') {
1732
                    $aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>'');
1733
                    $this->pTextBox($x, $y, $w, $h, 'Num.', $aFont, 'T', 'L', 1, '');
1734
                    $aFont = array('font'=>$this->fontePadrao, 'size'=>7, 'style'=>'B');
1735
                    $this->pTextBox($x, $y, $w, $h, $nDup, $aFont, 'T', 'R', 0, '');
1736
                } else {
1737
                    $aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>'');
1738
                    $this->pTextBox($x, $y, $w, $h, ($dupcont+1)."", $aFont, 'T', 'L', 1, '');
1739
                }
1740
                $aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>'');
1741
                $this->pTextBox($x, $y, $w, $h, 'Venc.', $aFont, 'C', 'L', 0, '');
1742
                $aFont = array('font'=>$this->fontePadrao, 'size'=>7, 'style'=>'B');
1743
                $this->pTextBox($x, $y, $w, $h, $dDup, $aFont, 'C', 'R', 0, '');
1744
                $aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>'');
1745
                $this->pTextBox($x, $y, $w, $h, 'Valor', $aFont, 'B', 'L', 0, '');
1746
                $aFont = array('font'=>$this->fontePadrao, 'size'=>7, 'style'=>'B');
1747
                $this->pTextBox($x, $y, $w, $h, $vDup, $aFont, 'B', 'R', 0, '');
1748
                $x += $w+$increm;
1749
                $dupcont += 1;
1750
                if ($this->orientacao == 'P') {
1751
                    $maxDupCont = 6;
1752
                } else {
1753
                    $maxDupCont = 8;
1754
                }
1755
                if ($dupcont > $maxDupCont) {
1756
                    $y += 9;
1757
                    $x = $oldx;
1758
                    $dupcont = 0;
1759
                    $linha += 1;
1760
                }
1761
                if ($linha == 5) {
1762
                    $linha = 4;
1763
                    break;
1764
                }
1765
            }
1766
            if ($dupcont == 0) {
1767
                $y -= 9;
1768
                $linha--;
1769
            }
1770
            return ($y+$h);
1771
        } else {
1772
            $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...
1773
            return ($y-2);
1774
        }
1775
    } //fim da função faturaDANFE
1776
1777
    /**
1778
     * impostoDanfeHelper
1779
     * Auxilia a montagem dos campos de impostos e totais da DANFE
1780
     *
1781
     * @name   impostoDanfeHelper
1782
     * @param  float $x Posição horizontal canto esquerdo
1783
     * @param  float $y Posição vertical canto superior
1784
     * @param  float $w Largura do campo
1785
     * @param  float $h Altura do campo
1786
     * @param  float $h Título do campo
1787
     * @param  float $h Valor do imposto
1788
     * @return float Sugestão do $x do próximo imposto
1789
     */
1790
    protected function pImpostoDanfeHelper($x, $y, $w, $h, $titulo, $campoImposto)
1791
    {
1792
        $valorImposto = '0, 00';
1793
        $the_field = $this->ICMSTot->getElementsByTagName($campoImposto)->item(0);
1794
        if (isset($the_field)) {
1795
            $the_value = $the_field->nodeValue;
1796
            if (!empty($the_value)) {
1797
                $valorImposto = number_format($the_value, 2, ",", ".");
1798
            }
1799
        }
1800
1801
        $fontTitulo = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>'');
1802
        $fontValor = array('font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B');
1803
        $this->pTextBox($x, $y, $w, $h, $titulo, $fontTitulo, 'T', 'L', 1, '');
1804
        $this->pTextBox($x, $y, $w, $h, $valorImposto, $fontValor, 'B', 'R', 0, '');
1805
1806
        $next_x = $x + $w;
1807
        return $next_x;
1808
    }
1809
1810
    /**
1811
     * impostoDANFE
1812
     * Monta o campo de impostos e totais da DANFE (retrato e paisagem)
1813
     *
1814
     * @param  number $x Posição horizontal canto esquerdo
1815
     * @param  number $y Posição vertical canto superior
1816
     * @return number Posição vertical final
1817
     */
1818
    protected function pImpostoDANFE($x, $y)
1819
    {
1820
        $x_inicial = $x;
1821
        //#####################################################################
1822
1823
1824
        $campos_por_linha = 9;
1825
        if (!$this->exibirPIS) {
1826
            $campos_por_linha--;
1827
        }
1828
        if (!$this->exibirIcmsInterestadual) {
1829
            $campos_por_linha -= 2;
1830
        }
1831
1832
        if ($this->orientacao == 'P') {
1833
            $maxW = $this->wPrint;
1834
            $title_size = 31;
1835
        } else {
1836
            $maxW = $this->wPrint - $this->wCanhoto;
1837
            $title_size = 40;
1838
        }
1839
        $w = $maxW / $campos_por_linha;
1840
1841
        $aFont = array('font'=>$this->fontePadrao, 'size'=>7, 'style'=>'B');
1842
        $texto = "CÁLCULO DO IMPOSTO";
1843
        $this->pTextBox($x, $y, $title_size, 8, $texto, $aFont, 'T', 'L', 0, '');
1844
        $y += 3;
1845
        $h = 7;
1846
1847
        $x = $this->pImpostoDanfeHelper($x, $y, $w, $h, "BASE DE CÁLC. DO ICMS", "vBC");
1848
        $x = $this->pImpostoDanfeHelper($x, $y, $w, $h, "VALOR DO ICMS", "vICMS");
1849
        $x = $this->pImpostoDanfeHelper($x, $y, $w, $h, "BASE DE CÁLC. ICMS S.T.", "vBCST");
1850
        $x = $this->pImpostoDanfeHelper($x, $y, $w, $h, "VALOR DO ICMS SUBST.", "vST");
1851
        $x = $this->pImpostoDanfeHelper($x, $y, $w, $h, "V. IMP. IMPORTAÇÃO", "vII");
1852
1853
        if ($this->exibirIcmsInterestadual) {
1854
            $x = $this->pImpostoDanfeHelper($x, $y, $w, $h, "V. ICMS UF REMET.", "vICMSUFRemet");
1855
            $x = $this->pImpostoDanfeHelper($x, $y, $w, $h, "VALOR DO FCP", "vFCPUFDest");
1856
        }
1857
1858
        if ($this->exibirPIS) {
1859
            $x = $this->pImpostoDanfeHelper($x, $y, $w, $h, "VALOR DO PIS", "vPIS");
1860
        }
1861
1862
        $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...
1863
1864
        //
1865
1866
        $y += $h;
1867
        $x = $x_inicial;
1868
1869
        $x = $this->pImpostoDanfeHelper($x, $y, $w, $h, "VALOR DO FRETE", "vFrete");
1870
        $x = $this->pImpostoDanfeHelper($x, $y, $w, $h, "VALOR DO SEGURO", "vSeg");
1871
        $x = $this->pImpostoDanfeHelper($x, $y, $w, $h, "DESCONTO", "vDesc");
1872
        $x = $this->pImpostoDanfeHelper($x, $y, $w, $h, "OUTRAS DESPESAS", "vOutro");
1873
        $x = $this->pImpostoDanfeHelper($x, $y, $w, $h, "VALOR TOTAL IPI", "vIPI");
1874
1875
        if ($this->exibirIcmsInterestadual) {
1876
            $x = $this->pImpostoDanfeHelper($x, $y, $w, $h, "V. ICMS UF DEST.", "vICMSUFDest");
1877
            $x = $this->pImpostoDanfeHelper($x, $y, $w, $h, "V. TOT. TRIB.", "vTotTrib");
1878
        }
1879
1880
        if ($this->exibirPIS) {
1881
            $x = $this->pImpostoDanfeHelper($x, $y, $w, $h, "VALOR DA COFINS", "vCOFINS");
1882
        }
1883
        $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...
1884
1885
        return ($y+$h);
1886
    } //fim impostoDANFE
1887
1888
    /**
1889
     * transporteDANFE
1890
     * Monta o campo de transportes da DANFE (retrato e paisagem)
1891
     *
1892
     * @name   transporteDANFE
1893
     * @param  float $x Posição horizontal canto esquerdo
1894
     * @param  float $y Posição vertical canto superior
1895
     * @return float Posição vertical final
1896
     */
1897
    protected function pTransporteDANFE($x, $y)
1898
    {
1899
        $oldX = $x;
1900
        if ($this->orientacao == 'P') {
1901
            $maxW = $this->wPrint;
1902
        } else {
1903
            $maxW = $this->wPrint - $this->wCanhoto;
1904
        }
1905
        //#####################################################################
1906
        //TRANSPORTADOR / VOLUMES TRANSPORTADOS
1907
        $texto = "TRANSPORTADOR / VOLUMES TRANSPORTADOS";
1908
        $w = $maxW;
1909
        $h = 7;
1910
        $aFont = array('font'=>$this->fontePadrao, 'size'=>7, 'style'=>'B');
1911
        $this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 0, '');
1912
        //NOME / RAZÃO SOCIAL
1913
        $w1 = $maxW*0.29;
1914
        $y += 3;
1915
        $texto = 'NOME / RAZÃO SOCIAL';
1916
        $aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>'');
1917
        $this->pTextBox($x, $y, $w1, $h, $texto, $aFont, 'T', 'L', 1, '');
1918
        if (isset($this->transporta)) {
1919
            $texto = ! empty($this->transporta->getElementsByTagName("xNome")->item(0)->nodeValue) ?
1920
                    $this->transporta->getElementsByTagName("xNome")->item(0)->nodeValue : '';
1921
        } else {
1922
            $texto = '';
1923
        }
1924
        $aFont = array('font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B');
1925
        $this->pTextBox($x, $y, $w1, $h, $texto, $aFont, 'B', 'L', 0, '');
1926
        //FRETE POR CONTA
1927
        $x += $w1;
1928
        $w2 = $maxW*0.15;
1929
        $texto = 'FRETE POR CONTA';
1930
        $aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>'');
1931
        $this->pTextBox($x, $y, $w2, $h, $texto, $aFont, 'T', 'L', 1, '');
1932
        $tipoFrete = ! empty($this->transp->getElementsByTagName("modFrete")->item(0)->nodeValue) ?
1933
                $this->transp->getElementsByTagName("modFrete")->item(0)->nodeValue : '0';
1934
        switch ($tipoFrete) {
1935
            case 0:
1936
                $texto = "(0) Emitente";
1937
                break;
1938
            case 1:
1939
                $texto = "(1) Dest/Rem";
1940
                break;
1941
            case 2:
1942
                $texto = "(2) Terceiros";
1943
                break;
1944
            case 9:
1945
                $texto = "(9) Sem Frete";
1946
                break;
1947
        }
1948
        $aFont = array('font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B');
1949
        $this->pTextBox($x, $y, $w2, $h, $texto, $aFont, 'C', 'C', 1, '');
1950
        //CÓDIGO ANTT
1951
        $x += $w2;
1952
        $texto = 'CÓDIGO ANTT';
1953
        $aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>'');
1954
        $this->pTextBox($x, $y, $w2, $h, $texto, $aFont, 'T', 'L', 1, '');
1955
        if (isset($this->veicTransp)) {
1956
            $texto = ! empty($this->veicTransp->getElementsByTagName("RNTC")->item(0)->nodeValue) ?
1957
                    $this->veicTransp->getElementsByTagName("RNTC")->item(0)->nodeValue : '';
1958
        } else {
1959
            $texto = '';
1960
        }
1961
        $aFont = array('font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B');
1962
        $this->pTextBox($x, $y, $w2, $h, $texto, $aFont, 'B', 'C', 0, '');
1963
        //PLACA DO VEÍC
1964
        $x += $w2;
1965
        $texto = 'PLACA DO VEÍCULO';
1966
        $aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>'');
1967
        $this->pTextBox($x, $y, $w2, $h, $texto, $aFont, 'T', 'L', 1, '');
1968
        if (isset($this->veicTransp)) {
1969
            $texto = ! empty($this->veicTransp->getElementsByTagName("placa")->item(0)->nodeValue) ?
1970
                    $this->veicTransp->getElementsByTagName("placa")->item(0)->nodeValue : '';
1971
        } elseif (isset($this->reboque)) {
1972
            $texto = ! empty($this->reboque->getElementsByTagName("placa")->item(0)->nodeValue) ?
1973
                    $this->reboque->getElementsByTagName("placa")->item(0)->nodeValue : '';
1974
        } else {
1975
            $texto = '';
1976
        }
1977
        $aFont = array('font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B');
1978
        $this->pTextBox($x, $y, $w2, $h, $texto, $aFont, 'B', 'C', 0, '');
1979
        //UF
1980
        $x += $w2;
1981
        $w3 = round($maxW*0.04, 0);
1982
        $texto = 'UF';
1983
        $aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>'');
1984
        $this->pTextBox($x, $y, $w3, $h, $texto, $aFont, 'T', 'L', 1, '');
1985
        if (isset($this->veicTransp)) {
1986
            $texto = ! empty($this->veicTransp->getElementsByTagName("UF")->item(0)->nodeValue) ?
1987
                    $this->veicTransp->getElementsByTagName("UF")->item(0)->nodeValue : '';
1988
        } elseif (isset($this->reboque)) {
1989
            $texto = ! empty($this->reboque->getElementsByTagName("UF")->item(0)->nodeValue) ?
1990
                    $this->reboque->getElementsByTagName("UF")->item(0)->nodeValue : '';
1991
        } else {
1992
            $texto = '';
1993
        }
1994
        $aFont = array('font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B');
1995
        $this->pTextBox($x, $y, $w3, $h, $texto, $aFont, 'B', 'C', 0, '');
1996
        //CNPJ / CPF
1997
        $x += $w3;
1998
        $w = $maxW-($w1+3*$w2+$w3);
1999
        $texto = 'CNPJ / CPF';
2000
        $aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>'');
2001
        $this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 1, '');
2002
        if (isset($this->transporta)) {
2003
            $texto = ! empty($this->transporta->getElementsByTagName("CNPJ")->item(0)->nodeValue) ?
2004
                    $this->pFormat(
2005
                        $this->transporta->getElementsByTagName("CNPJ")->item(0)->nodeValue,
2006
                        "##.###.###/####-##"
2007
                    ) : '';
2008
            if ($texto == '') {
2009
                $texto = ! empty($this->transporta->getElementsByTagName("CPF")->item(0)->nodeValue) ?
2010
                        $this->pFormat(
2011
                            $this->transporta->getElementsByTagName("CPF")->item(0)->nodeValue,
2012
                            "###.###.###-##"
2013
                        ) : '';
2014
            }
2015
        } else {
2016
            $texto = '';
2017
        }
2018
        $aFont = array('font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B');
2019
        $this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'B', 'C', 0, '');
2020
        //#####################################################################
2021
        //ENDEREÇO
2022
        $y += $h;
2023
        $x = $oldX;
2024
        $h = 7;
2025
        $w1 = $maxW*0.44;
2026
        $texto = 'ENDEREÇO';
2027
        $aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>'');
2028
        $this->pTextBox($x, $y, $w1, $h, $texto, $aFont, 'T', 'L', 1, '');
2029
        if (isset($this->transporta)) {
2030
            $texto = ! empty($this->transporta->getElementsByTagName("xEnder")->item(0)->nodeValue) ?
2031
                    $this->transporta->getElementsByTagName("xEnder")->item(0)->nodeValue : '';
2032
        } else {
2033
            $texto = '';
2034
        }
2035
        $aFont = array('font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B');
2036
        $this->pTextBox($x, $y, $w1, $h, $texto, $aFont, 'B', 'L', 0, '');
2037
        //MUNICÍPIO
2038
        $x += $w1;
2039
        $w2 = round($maxW*0.30, 0);
2040
        $texto = 'MUNICÍPIO';
2041
        $aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>'');
2042
        $this->pTextBox($x, $y, $w2, $h, $texto, $aFont, 'T', 'L', 1, '');
2043
        if (isset($this->transporta)) {
2044
            $texto = ! empty($this->transporta->getElementsByTagName("xMun")->item(0)->nodeValue) ?
2045
                    $this->transporta->getElementsByTagName("xMun")->item(0)->nodeValue : '';
2046
        } else {
2047
            $texto = '';
2048
        }
2049
        $aFont = array('font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B');
2050
        $this->pTextBox($x, $y, $w2, $h, $texto, $aFont, 'B', 'C', 0, '');
2051
        //UF
2052
        $x += $w2;
2053
        $w3 = round($maxW*0.04, 0);
2054
        $texto = 'UF';
2055
        $aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>'');
2056
        $this->pTextBox($x, $y, $w3, $h, $texto, $aFont, 'T', 'L', 1, '');
2057
        if (isset($this->transporta)) {
2058
            $texto = ! empty($this->transporta->getElementsByTagName("UF")->item(0)->nodeValue) ?
2059
                    $this->transporta->getElementsByTagName("UF")->item(0)->nodeValue : '';
2060
        } else {
2061
            $texto = '';
2062
        }
2063
        $aFont = array('font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B');
2064
        $this->pTextBox($x, $y, $w3, $h, $texto, $aFont, 'B', 'C', 0, '');
2065
        //INSCRIÇÃO ESTADUAL
2066
        $x += $w3;
2067
        $w = $maxW-($w1+$w2+$w3);
2068
        $texto = 'INSCRIÇÃO ESTADUAL';
2069
        $aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>'');
2070
        $this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 1, '');
2071
        $texto = '';
2072
        if (isset($this->transporta)) {
2073
            if (! empty($this->transporta->getElementsByTagName("IE")->item(0)->nodeValue)) {
2074
                $texto = $this->transporta->getElementsByTagName("IE")->item(0)->nodeValue;
2075
            }
2076
        }
2077
        $aFont = array('font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B');
2078
        $this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'B', 'C', 0, '');
2079
        //Tratar Multiplos volumes
2080
        $volumes = $this->transp->getElementsByTagName('vol');
2081
        $quantidade = 0;
2082
        $especie = '';
2083
        $marca = '';
2084
        $numero = '';
2085
        $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...
2086
        $pesoBruto=0;
2087
        $pesoLiquido=0;
2088
        foreach ($volumes as $volume) {
2089
            $quantidade += ! empty($volume->getElementsByTagName("qVol")->item(0)->nodeValue) ?
2090
                    $volume->getElementsByTagName("qVol")->item(0)->nodeValue : 0;
2091
            $pesoBruto += ! empty($volume->getElementsByTagName("pesoB")->item(0)->nodeValue) ?
2092
                    $volume->getElementsByTagName("pesoB")->item(0)->nodeValue : 0;
2093
            $pesoLiquido += ! empty($volume->getElementsByTagName("pesoL")->item(0)->nodeValue) ?
2094
                    $volume->getElementsByTagName("pesoL")->item(0)->nodeValue : 0;
2095
            $texto = ! empty($this->transp->getElementsByTagName("esp")->item(0)->nodeValue) ?
2096
                    $this->transp->getElementsByTagName("esp")->item(0)->nodeValue : '';
2097
            if ($texto != $especie && $especie != '') {
2098
                //tem várias especies
2099
                $especie = 'VARIAS';
2100
            } else {
2101
                $especie = $texto;
2102
            }
2103
            $texto = ! empty($this->transp->getElementsByTagName("marca")->item(0)->nodeValue) ?
2104
                    $this->transp->getElementsByTagName("marca")->item(0)->nodeValue : '';
2105
            if ($texto != $marca && $marca != '') {
2106
                //tem várias especies
2107
                $marca = 'VARIAS';
2108
            } else {
2109
                $marca = $texto;
2110
            }
2111
            $texto = ! empty($this->transp->getElementsByTagName("nVol")->item(0)->nodeValue) ?
2112
                    $this->transp->getElementsByTagName("nVol")->item(0)->nodeValue : '';
2113
            if ($texto != $numero && $numero != '') {
2114
                //tem várias especies
2115
                $numero = 'VARIOS';
2116
            } else {
2117
                $numero = $texto;
2118
            }
2119
        }
2120
2121
        //#####################################################################
2122
        //QUANTIDADE
2123
        $y += $h;
2124
        $x = $oldX;
2125
        $h = 7;
2126
        $w1 = round($maxW*0.10, 0);
2127
        $texto = 'QUANTIDADE';
2128
        $aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>'');
2129
        $this->pTextBox($x, $y, $w1, $h, $texto, $aFont, 'T', 'L', 1, '');
2130
        if (!empty($quantidade)) {
2131
            $texto = $quantidade;
2132
            $aFont = array('font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B');
2133
            $this->pTextBox($x, $y, $w1, $h, $texto, $aFont, 'B', 'C', 0, '');
2134
        }
2135
        //ESPÉCIE
2136
        $x += $w1;
2137
        $w2 = round($maxW*0.17, 0);
2138
        $texto = 'ESPÉCIE';
2139
        $aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>'');
2140
        $this->pTextBox($x, $y, $w2, $h, $texto, $aFont, 'T', 'L', 1, '');
2141
        $texto = $especie;
2142
        $aFont = array('font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B');
2143
        $this->pTextBox($x, $y, $w2, $h, $texto, $aFont, 'B', 'C', 0, '');
2144
        //MARCA
2145
        $x += $w2;
2146
        $texto = 'MARCA';
2147
        $aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>'');
2148
        $this->pTextBox($x, $y, $w2, $h, $texto, $aFont, 'T', 'L', 1, '');
2149
        $texto = ! empty($this->transp->getElementsByTagName("marca")->item(0)->nodeValue) ?
2150
                $this->transp->getElementsByTagName("marca")->item(0)->nodeValue : '';
2151
        $aFont = array('font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B');
2152
        $this->pTextBox($x, $y, $w2, $h, $texto, $aFont, 'B', 'C', 0, '');
2153
        //NUMERAÇÃO
2154
        $x += $w2;
2155
        $texto = 'NUMERAÇÃO';
2156
        $aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>'');
2157
        $this->pTextBox($x, $y, $w2, $h, $texto, $aFont, 'T', 'L', 1, '');
2158
        $texto = $numero;
2159
        $aFont = array('font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B');
2160
        $this->pTextBox($x, $y, $w2, $h, $texto, $aFont, 'B', 'C', 0, '');
2161
        //PESO BRUTO
2162
        $x += $w2;
2163
        $w3 = round($maxW*0.20, 0);
2164
        $texto = 'PESO BRUTO';
2165
        $aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>'');
2166
        $this->pTextBox($x, $y, $w3, $h, $texto, $aFont, 'T', 'L', 1, '');
2167
        if (is_numeric($pesoBruto) && $pesoBruto > 0) {
2168
            $texto = number_format($pesoBruto, 3, ",", ".");
2169
        } else {
2170
            $texto = '';
2171
        }
2172
        $aFont = array('font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B');
2173
        $this->pTextBox($x, $y, $w3, $h, $texto, $aFont, 'B', 'R', 0, '');
2174
        //PESO LÍQUIDO
2175
        $x += $w3;
2176
        $w = $maxW -($w1+3*$w2+$w3);
2177
        $texto = 'PESO LÍQUIDO';
2178
        $aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>'');
2179
        $this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 1, '');
2180
        if (is_numeric($pesoLiquido) && $pesoLiquido > 0) {
2181
            $texto = number_format($pesoLiquido, 3, ",", ".");
2182
        } else {
2183
            $texto = '';
2184
        }
2185
        $aFont = array('font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B');
2186
        $this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'B', 'R', 0, '');
2187
        return ($y+$h);
2188
    } //fim transporteDANFE
2189
2190
2191
2192
    protected function pDescricaoProdutoHelper($origem, $campo, $formato)
2193
    {
2194
        $valor_original = $origem->getElementsByTagName($campo)->item(0);
2195
        if (!isset($valor_original)) {
2196
            return "";
2197
        }
2198
        $valor_original = $valor_original->nodeValue;
2199
        $valor = ! empty($valor_original) ? number_format($valor_original, 2, ",", ".") : '';
2200
2201
        if ($valor != "") {
2202
            return sprintf($formato, $valor);
2203
        }
2204
        return "";
2205
    }
2206
2207
    /**
2208
     * descricaoProduto
2209
     * Monta a string de descrição de cada Produto
2210
     *
2211
     * @name   descricaoProduto
2212
     * @param  DOMNode itemProd
2213
     * @return string descricao do produto
2214
     */
2215
    protected function pDescricaoProduto($itemProd)
2216
    {
2217
        $prod = $itemProd->getElementsByTagName('prod')->item(0);
2218
        $ICMS = $itemProd->getElementsByTagName("ICMS")->item(0);
2219
        $ICMSUFDest = $itemProd->getElementsByTagName("ICMSUFDest")->item(0);
2220
        $impostos = '';
2221
2222
        if (!empty($ICMS)) {
2223
            $impostos .= $this->pDescricaoProdutoHelper($ICMS, "pRedBC", " pRedBC=%s%%");
2224
            $impostos .= $this->pDescricaoProdutoHelper($ICMS, "pMVAST", " IVA=%s%%");
2225
            $impostos .= $this->pDescricaoProdutoHelper($ICMS, "pICMSST", " pIcmsSt=%s%%");
2226
            $impostos .= $this->pDescricaoProdutoHelper($ICMS, "vBCST", " BcIcmsSt=%s");
2227
            $impostos .= $this->pDescricaoProdutoHelper($ICMS, "vICMSST", " vIcmsSt=%s");
2228
        }
2229
        if (!empty($ICMSUFDest)) {
2230
            $impostos .= $this->pDescricaoProdutoHelper($ICMSUFDest, "pFCPUFDest", " pFCPUFDest=%s%%");
2231
            $impostos .= $this->pDescricaoProdutoHelper($ICMSUFDest, "pICMSUFDest", " pICMSUFDest=%s%%");
2232
            $impostos .= $this->pDescricaoProdutoHelper($ICMSUFDest, "pICMSInterPart", " pICMSInterPart=%s%%");
2233
            $impostos .= $this->pDescricaoProdutoHelper($ICMSUFDest, "vFCPUFDest", " vFCPUFDest=%s");
2234
            $impostos .= $this->pDescricaoProdutoHelper($ICMSUFDest, "vICMSUFDest", " vICMSUFDest=%s");
2235
            $impostos .= $this->pDescricaoProdutoHelper($ICMSUFDest, "vICMSUFRemet", " vICMSUFRemet=%s");
2236
        }
2237
        $infAdProd = ! empty($itemProd->getElementsByTagName('infAdProd')->item(0)->nodeValue) ?
2238
                substr($this->pAnfavea($itemProd->getElementsByTagName('infAdProd')->item(0)->nodeValue), 0, 500) : '';
2239
        if (! empty($infAdProd)) {
2240
            $infAdProd = trim($infAdProd);
2241
            $infAdProd .= ' ';
2242
        }
2243
        $medTxt='';
2244
        $med = $prod->getElementsByTagName("med");
2245
        if (isset($med)) {
2246
            $i = 0;
2247
            while ($i < $med->length) {
2248
                $medTxt .= $this->pSimpleGetValue($med->item($i), 'nLote', ' Lote: ');
2249
                $medTxt .= $this->pSimpleGetValue($med->item($i), 'qLote', ' Quant: ');
2250
                $medTxt .= $this->pSimpleGetDate($med->item($i), 'dFab', ' Fab: ');
2251
                $medTxt .= $this->pSimpleGetDate($med->item($i), 'dVal', ' Val: ');
2252
                $medTxt .= $this->pSimpleGetValue($med->item($i), 'vPMC', ' PMC: ');
2253
                $i++;
2254
            }
2255
            if ($medTxt != '') {
2256
                $medTxt.= ' ';
2257
            }
2258
        }
2259
        //NT2013.006 FCI
2260
        $nFCI = (! empty($itemProd->getElementsByTagName('nFCI')->item(0)->nodeValue)) ?
2261
                ' FCI:'.$itemProd->getElementsByTagName('nFCI')->item(0)->nodeValue : '';
2262
        $tmp_ad=$infAdProd . ($this->descProdInfoComplemento ? $medTxt . $impostos . $nFCI : '');
2263
        $texto = $prod->getElementsByTagName("xProd")->item(0)->nodeValue . (strlen($tmp_ad)!=0?"\n    ".$tmp_ad:'');
2264
        if ($this->descProdQuebraLinha) {
2265
            $texto = str_replace(";", "\n", $texto);
2266
        }
2267
        return $texto;
2268
    }
2269
2270
    /**
2271
     * itensDANFE
2272
     * Monta o campo de itens da DANFE (retrato e paisagem)
2273
     *
2274
     * @name   itensDANFE
2275
     * @param  float $x       Posição horizontal canto esquerdo
2276
     * @param  float $y       Posição vertical canto superior
2277
     * @param  float $nInicio Número do item inicial
2278
     * @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...
2279
     * @param  float $hmax    Altura máxima do campo de itens em mm
2280
     * @return float Posição vertical final
2281
     */
2282
    protected function pItensDANFE($x, $y, &$nInicio, $hmax, $pag = 0, $totpag = 0, $hCabecItens = 7)
2283
    {
2284
        $oldX = $x;
2285
        $oldY = $y;
2286
        $totItens = $this->det->length;
2287
        //#####################################################################
2288
        //DADOS DOS PRODUTOS / SERVIÇOS
2289
        $texto = "DADOS DOS PRODUTOS / SERVIÇOS ";
2290
        if ($this->orientacao == 'P') {
2291
            $w = $this->wPrint;
2292
        } else {
2293
            if ($nInicio < 2) { // primeira página
2294
                $w = $this->wPrint - $this->wCanhoto;
2295
            } else { // páginas seguintes
2296
                $w = $this->wPrint;
2297
            }
2298
        }
2299
        $h = 4;
2300
        $aFont = array('font'=>$this->fontePadrao, 'size'=>7, 'style'=>'B');
2301
        $this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 0, '');
2302
        $y += 3;
2303
        //desenha a caixa dos dados dos itens da NF
2304
        $hmax += 1;
2305
        $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...
2306
        $this->pTextBox($x, $y, $w, $hmax);
2307
        //##################################################################################
2308
        // cabecalho LOOP COM OS DADOS DOS PRODUTOS
2309
        //CÓDIGO PRODUTO
2310
        $texto = "CÓDIGO PRODUTO";
2311
        $w1 = round($w*0.09, 0);
2312
        $h = 4;
2313
        $aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>'');
2314
        $this->pTextBox($x, $y, $w1, $h, $texto, $aFont, 'C', 'C', 0, '', false);
2315
        $this->pdf->Line($x+$w1, $y, $x+$w1, $y+$hmax);
2316
        //DESCRIÇÃO DO PRODUTO / SERVIÇO
2317
        $x += $w1;
2318
        $w2 = round($w*0.28, 0);
2319
        $texto = 'DESCRIÇÃO DO PRODUTO / SERVIÇO';
2320
        $aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>'');
2321
        $this->pTextBox($x, $y, $w2, $h, $texto, $aFont, 'C', 'C', 0, '', false);
2322
        $this->pdf->Line($x+$w2, $y, $x+$w2, $y+$hmax);
2323
        //NCM/SH
2324
        $x += $w2;
2325
        $w3 = round($w*0.06, 0);
2326
        $texto = 'NCM/SH';
2327
        $aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>'');
2328
        $this->pTextBox($x, $y, $w3, $h, $texto, $aFont, 'C', 'C', 0, '', false);
2329
        $this->pdf->Line($x+$w3, $y, $x+$w3, $y+$hmax);
2330
        //O/CST ou O/CSOSN
2331
        $x += $w3;
2332
        $w4 = round($w*0.05, 0);
2333
        $texto = 'O/CSOSN';//Regime do Simples CRT = 1 ou CRT = 2
2334
        if ($this->pSimpleGetValue($this->emit, 'CRT') == '3') {
2335
             $texto = 'O/CST';//Regime Normal
2336
        }
2337
        $aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>'');
2338
        $this->pTextBox($x, $y, $w4, $h, $texto, $aFont, 'C', 'C', 0, '', false);
2339
        $this->pdf->Line($x+$w4, $y, $x+$w4, $y+$hmax);
2340
        //CFOP
2341
        $x += $w4;
2342
        $w5 = round($w*0.04, 0);
2343
        $texto = 'CFOP';
2344
        $aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>'');
2345
        $this->pTextBox($x, $y, $w5, $h, $texto, $aFont, 'C', 'C', 0, '', false);
2346
        $this->pdf->Line($x+$w5, $y, $x+$w5, $y+$hmax);
2347
        //UN
2348
        $x += $w5;
2349
        $w6 = round($w*0.03, 0);
2350
        $texto = 'UN';
2351
        $aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>'');
2352
        $this->pTextBox($x, $y, $w6, $h, $texto, $aFont, 'C', 'C', 0, '', false);
2353
        $this->pdf->Line($x+$w6, $y, $x+$w6, $y+$hmax);
2354
        //QUANT
2355
        $x += $w6;
2356
        $w7 = round($w*0.07, 0);
2357
        $texto = 'QUANT';
2358
        $aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>'');
2359
        $this->pTextBox($x, $y, $w7, $h, $texto, $aFont, 'C', 'C', 0, '', false);
2360
        $this->pdf->Line($x+$w7, $y, $x+$w7, $y+$hmax);
2361
        //VALOR UNIT
2362
        $x += $w7;
2363
        $w8 = round($w*0.06, 0);
2364
        $texto = 'VALOR UNIT';
2365
        $aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>'');
2366
        $this->pTextBox($x, $y, $w8, $h, $texto, $aFont, 'C', 'C', 0, '', false);
2367
        $this->pdf->Line($x+$w8, $y, $x+$w8, $y+$hmax);
2368
        //VALOR TOTAL
2369
        $x += $w8;
2370
        $w9 = round($w*0.06, 0);
2371
        $texto = 'VALOR TOTAL';
2372
        $aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>'');
2373
        $this->pTextBox($x, $y, $w9, $h, $texto, $aFont, 'C', 'C', 0, '', false);
2374
        $this->pdf->Line($x+$w9, $y, $x+$w9, $y+$hmax);
2375
        //B.CÁLC ICMS
2376
        $x += $w9;
2377
        $w10 = round($w*0.06, 0);
2378
        $texto = 'B.CÁLC ICMS';
2379
        $aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>'');
2380
        $this->pTextBox($x, $y, $w10, $h, $texto, $aFont, 'C', 'C', 0, '', false);
2381
        $this->pdf->Line($x+$w10, $y, $x+$w10, $y+$hmax);
2382
        //VALOR ICMS
2383
        $x += $w10;
2384
        $w11 = round($w*0.06, 0);
2385
        $texto = 'VALOR ICMS';
2386
        $aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>'');
2387
        $this->pTextBox($x, $y, $w11, $h, $texto, $aFont, 'C', 'C', 0, '', false);
2388
        $this->pdf->Line($x+$w11, $y, $x+$w11, $y+$hmax);
2389
        //VALOR IPI
2390
        $x += $w11;
2391
        $w12 = round($w*0.05, 0);
2392
        $texto = 'VALOR IPI';
2393
        $aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>'');
2394
        $this->pTextBox($x, $y, $w12, $h, $texto, $aFont, 'C', 'C', 0, '', false);
2395
        $this->pdf->Line($x+$w12, $y, $x+$w12, $y+$hmax);
2396
        //ALÍQ. ICMS
2397
        $x += $w12;
2398
        $w13 = round($w*0.035, 0);
2399
        $texto = 'ALÍQ. ICMS';
2400
        $aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>'');
2401
        $this->pTextBox($x, $y, $w13, $h, $texto, $aFont, 'C', 'C', 0, '', false);
2402
        $this->pdf->Line($x+$w13, $y, $x+$w13, $y+$hmax);
2403
        //ALÍQ. IPI
2404
        $x += $w13;
2405
        $w14 = $w-($w1+$w2+$w3+$w4+$w5+$w6+$w7+$w8+$w9+$w10+$w11+$w12+$w13);
2406
        $texto = 'ALÍQ. IPI';
2407
        $this->pTextBox($x, $y, $w14, $h, $texto, $aFont, 'C', 'C', 0, '', false);
2408
        $this->pdf->Line($oldX, $y+$h+1, $oldX + $w, $y+$h+1);
2409
        $y += 5;
2410
        //##################################################################################
2411
        // LOOP COM OS DADOS DOS PRODUTOS
2412
        $i = 0;
2413
        $hUsado = $hCabecItens;
2414
        $aFont = array('font'=>$this->fontePadrao, 'size'=>7, 'style'=>'');
2415
        foreach ($this->det as $d) {
2416
            if ($i >= $nInicio) {
2417
                $thisItem = $this->det->item($i);
2418
                //carrega as tags do item
2419
                $prod = $thisItem->getElementsByTagName("prod")->item(0);
2420
                $imposto = $this->det->item($i)->getElementsByTagName("imposto")->item(0);
2421
                $ICMS = $imposto->getElementsByTagName("ICMS")->item(0);
2422
                $IPI  = $imposto->getElementsByTagName("IPI")->item(0);
2423
                $textoProduto = $this->pDescricaoProduto($thisItem);
2424
                $linhaDescr = $this->pGetNumLines($textoProduto, $w2, $aFont);
2425
                $h = round(($linhaDescr * $this->pdf->fontSize)+ ($linhaDescr * 0.5), 2);
2426
                $hUsado += $h;
2427
                if ($pag != $totpag) {
2428
                    if ($hUsado >= $hmax && $i < $totItens) {
2429
                        //ultrapassa a capacidade para uma única página
2430
                        //o restante dos dados serão usados nas proximas paginas
2431
                        $nInicio = $i;
2432
                        break;
2433
                    }
2434
                }
2435
                $y_linha=$y+$h;
2436
                // linha entre itens
2437
                $this->pdf->DashedHLine($oldX, $y_linha, $w, 0.1, 120);
2438
                //corrige o x
2439
                $x=$oldX;
2440
                //codigo do produto
2441
                $texto = $prod->getElementsByTagName("cProd")->item(0)->nodeValue;
2442
                $this->pTextBox($x, $y, $w1, $h, $texto, $aFont, 'T', 'C', 0, '');
2443
                $x += $w1;
2444
                //DESCRIÇÃO
2445
                if ($this->orientacao == 'P') {
2446
                    $this->pTextBox($x, $y, $w2, $h, $textoProduto, $aFont, 'T', 'L', 0, '', false);
2447
                } else {
2448
                    $this->pTextBox($x, $y, $w2, $h, $textoProduto, $aFont, 'T', 'L', 0, '', false);
2449
                }
2450
                $x += $w2;
2451
                //NCM
2452
                $texto = ! empty($prod->getElementsByTagName("NCM")->item(0)->nodeValue) ?
2453
                        $prod->getElementsByTagName("NCM")->item(0)->nodeValue : '';
2454
                $this->pTextBox($x, $y, $w3, $h, $texto, $aFont, 'T', 'C', 0, '');
2455
                $x += $w3;
2456
                //CST
2457
                if (isset($ICMS)) {
2458
                    $origem =  $this->pSimpleGetValue($ICMS, "orig");
2459
                    $cst =  $this->pSimpleGetValue($ICMS, "CST");
2460
                    $csosn =  $this->pSimpleGetValue($ICMS, "CSOSN");
2461
                    $texto = $origem.$cst.$csosn;
2462
                    $this->pTextBox($x, $y, $w4, $h, $texto, $aFont, 'T', 'C', 0, '');
2463
                }
2464
                //CFOP
2465
                $x += $w4;
2466
                $texto = $prod->getElementsByTagName("CFOP")->item(0)->nodeValue;
2467
                $this->pTextBox($x, $y, $w5, $h, $texto, $aFont, 'T', 'C', 0, '');
2468
                //Unidade
2469
                $x += $w5;
2470
                $texto = $prod->getElementsByTagName("uCom")->item(0)->nodeValue;
2471
                $this->pTextBox($x, $y, $w6, $h, $texto, $aFont, 'T', 'C', 0, '');
2472
                $x += $w6;
2473
                if ($this->orientacao == 'P') {
2474
                    $alinhamento = 'R';
2475
                } else {
2476
                    $alinhamento = 'R';
2477
                }
2478
                // QTDADE
2479
                $texto = number_format($prod->getElementsByTagName("qCom")->item(0)->nodeValue, 4, ",", ".");
2480
                $this->pTextBox($x, $y, $w7, $h, $texto, $aFont, 'T', $alinhamento, 0, '');
2481
                $x += $w7;
2482
                // Valor Unitário
2483
                $texto = number_format($prod->getElementsByTagName("vUnCom")->item(0)->nodeValue, 4, ",", ".");
2484
                $this->pTextBox($x, $y, $w8, $h, $texto, $aFont, 'T', $alinhamento, 0, '');
2485
                $x += $w8;
2486
                // Valor do Produto
2487
                $texto = "";
2488
                if (is_numeric($prod->getElementsByTagName("vProd")->item(0)->nodeValue)) {
2489
                    $texto = number_format($prod->getElementsByTagName("vProd")->item(0)->nodeValue, 2, ",", ".");
2490
                }
2491
                $this->pTextBox($x, $y, $w9, $h, $texto, $aFont, 'T', $alinhamento, 0, '');
2492
                //Valor da Base de calculo
2493
                $x += $w9;
2494
                if (isset($ICMS)) {
2495
                    $texto = ! empty($ICMS->getElementsByTagName("vBC")->item(0)->nodeValue) ?
2496
                            number_format(
2497
                                $ICMS->getElementsByTagName("vBC")->item(0)->nodeValue,
2498
                                2,
2499
                                ",",
2500
                                "."
2501
                            ) : '0, 00';
2502
                    $this->pTextBox($x, $y, $w10, $h, $texto, $aFont, 'T', $alinhamento, 0, '');
2503
                }
2504
                //Valor do ICMS
2505
                $x += $w10;
2506
                if (isset($ICMS)) {
2507
                    $texto = ! empty($ICMS->getElementsByTagName("vICMS")->item(0)->nodeValue) ?
2508
                            number_format(
2509
                                $ICMS->getElementsByTagName("vICMS")->item(0)->nodeValue,
2510
                                2,
2511
                                ",",
2512
                                "."
2513
                            ) : '0, 00';
2514
                    $this->pTextBox($x, $y, $w11, $h, $texto, $aFont, 'T', $alinhamento, 0, '');
2515
                }
2516
                //Valor do IPI
2517
                $x += $w11;
2518
                if (isset($IPI)) {
2519
                    $texto = ! empty($IPI->getElementsByTagName("vIPI")->item(0)->nodeValue) ?
2520
                            number_format($IPI->getElementsByTagName("vIPI")->item(0)->nodeValue, 2, ",", ".") :'';
2521
                } else {
2522
                    $texto = '';
2523
                }
2524
                $this->pTextBox($x, $y, $w12, $h, $texto, $aFont, 'T', $alinhamento, 0, '');
2525
                // %ICMS
2526
                $x += $w12;
2527
                if (isset($ICMS)) {
2528
                    $texto = ! empty($ICMS->getElementsByTagName("pICMS")->item(0)->nodeValue) ?
2529
                            number_format(
2530
                                $ICMS->getElementsByTagName("pICMS")->item(0)->nodeValue,
2531
                                2,
2532
                                ",",
2533
                                "."
2534
                            ) : '0, 00';
2535
                    $this->pTextBox($x, $y, $w13, $h, $texto, $aFont, 'T', 'C', 0, '');
2536
                }
2537
                //%IPI
2538
                $x += $w13;
2539
                if (isset($IPI)) {
2540
                    $texto = ! empty($IPI->getElementsByTagName("pIPI")->item(0)->nodeValue) ?
2541
                            number_format($IPI->getElementsByTagName("pIPI")->item(0)->nodeValue, 2, ",", ".") : '';
2542
                } else {
2543
                    $texto = '';
2544
                }
2545
                $this->pTextBox($x, $y, $w14, $h, $texto, $aFont, 'T', 'C', 0, '');
2546
                $y += $h;
2547
                $i++;
2548
                //incrementa o controle dos itens processados.
2549
                $this->qtdeItensProc++;
2550
            } else {
2551
                $i++;
2552
            }
2553
        }
2554
        return $oldY+$hmax;
2555
    }
2556
2557
    /**
2558
     * issqnDANFE
2559
     * Monta o campo de serviços do DANFE
2560
     *
2561
     * @name   issqnDANFE (retrato e paisagem)
2562
     * @param  float $x Posição horizontal canto esquerdo
2563
     * @param  float $y Posição vertical canto superior
2564
     * @return float Posição vertical final
2565
     */
2566
    protected function pIssqnDANFE($x, $y)
2567
    {
2568
        $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...
2569
        //#####################################################################
2570
        //CÁLCULO DO ISSQN
2571
        $texto = "CÁLCULO DO ISSQN";
2572
        $w = $this->wPrint;
2573
        $h = 7;
2574
        $aFont = array('font'=>$this->fontePadrao, 'size'=>7, 'style'=>'B');
2575
        $this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 0, '');
2576
        //INSCRIÇÃO MUNICIPAL
2577
        $y += 3;
2578
        $w = round($this->wPrint*0.23, 0);
2579
        $texto = 'INSCRIÇÃO MUNICIPAL';
2580
        $aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>'');
2581
        $this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 1, '');
2582
        //inscrição municipal
2583
        $texto = ! empty($this->emit->getElementsByTagName("IM")->item(0)->nodeValue) ?
2584
                $this->emit->getElementsByTagName("IM")->item(0)->nodeValue : '';
2585
        $aFont = array('font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B');
2586
        $this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'B', 'L', 0, '');
2587
        //VALOR TOTAL DOS SERVIÇOS
2588
        $x += $w;
2589
        $texto = 'VALOR TOTAL DOS SERVIÇOS';
2590
        $aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>'');
2591
        $this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 1, '');
2592
        if (isset($this->ISSQNtot)) {
2593
            $texto = ! empty($this->ISSQNtot->getElementsByTagName("vServ")->item(0)->nodeValue) ?
2594
                    $this->ISSQNtot->getElementsByTagName("vServ")->item(0)->nodeValue : '';
2595
            $texto = number_format($texto, 2, ",", ".");
2596
        } else {
2597
            $texto = '';
2598
        }
2599
        $aFont = array('font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B');
2600
        $this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'B', 'R', 0, '');
2601
        //BASE DE CÁLCULO DO ISSQN
2602
        $x += $w;
2603
        $texto = 'BASE DE CÁLCULO DO ISSQN';
2604
        $aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>'');
2605
        $this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 1, '');
2606
        if (isset($this->ISSQNtot)) {
2607
            $texto = ! empty($this->ISSQNtot->getElementsByTagName("vBC")->item(0)->nodeValue) ?
2608
                    $this->ISSQNtot->getElementsByTagName("vBC")->item(0)->nodeValue : '';
2609
            $texto = ! empty($texto) ? number_format($texto, 2, ",", ".") : '';
2610
        } else {
2611
            $texto = '';
2612
        }
2613
        $aFont = array('font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B');
2614
        $this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'B', 'R', 0, '');
2615
        //VALOR TOTAL DO ISSQN
2616
        $x += $w;
2617
        if ($this->orientacao == 'P') {
2618
            $w = $this->wPrint - (3 * $w);
2619
        } else {
2620
            $w = $this->wPrint - (3 * $w)-$this->wCanhoto;
2621
        }
2622
        $texto = 'VALOR TOTAL DO ISSQN';
2623
        $aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>'');
2624
        $this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 1, '');
2625
        if (isset($this->ISSQNtot)) {
2626
            $texto = ! empty($this->ISSQNtot->getElementsByTagName("vISS")->item(0)->nodeValue) ?
2627
                    $this->ISSQNtot->getElementsByTagName("vISS")->item(0)->nodeValue : '';
2628
            $texto = ! empty($texto) ? number_format($texto, 2, ",", ".") : '';
2629
        } else {
2630
            $texto = '';
2631
        }
2632
        $aFont = array('font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B');
2633
        $this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'B', 'R', 0, '');
2634
        return ($y+$h+1);
2635
    }
2636
2637
    /**
2638
     *dadosAdicionaisDANFE
2639
     * Coloca o grupo de dados adicionais da NFe. (retrato e paisagem)
2640
     *
2641
     * @name   dadosAdicionaisDANFE
2642
     * @param  float $x Posição horizontal canto esquerdo
2643
     * @param  float $y Posição vertical canto superior
2644
     * @param  float $h altura do campo
2645
     * @return float Posição vertical final (eixo Y)
2646
     */
2647
    protected function pDadosAdicionaisDANFE($x, $y, $h)
2648
    {
2649
        //##################################################################################
2650
        //DADOS ADICIONAIS
2651
        $texto = "DADOS ADICIONAIS";
2652
        if ($this->orientacao == 'P') {
2653
              $w = $this->wPrint;
2654
        } else {
2655
              $w = $this->wPrint-$this->wCanhoto;
2656
        }
2657
        $aFont = array('font'=>$this->fontePadrao, 'size'=>7, 'style'=>'B');
2658
        $this->pTextBox($x, $y, $w, 8, $texto, $aFont, 'T', 'L', 0, '');
2659
        //INFORMAÇÕES COMPLEMENTARES
2660
        $texto = "INFORMAÇÕES COMPLEMENTARES";
2661
        $y += 3;
2662
        $w = $this->wAdic;
2663
        $aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>'B');
2664
        $this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 1, '');
2665
        //o texto com os dados adicionais foi obtido na função montaDANFE
2666
        //e carregado em uma propriedade privada da classe
2667
        //$this->wAdic com a largura do campo
2668
        //$this->textoAdic com o texto completo do campo
2669
        $y += 1;
2670
        $aFont = array('font'=>$this->fontePadrao, 'size'=>7, 'style'=>'');
2671
        $this->pTextBox($x, $y+2, $w-2, $h-3, $this->textoAdic, $aFont, 'T', 'L', 0, '', false);
2672
        //RESERVADO AO FISCO
2673
        $texto = "RESERVADO AO FISCO";
2674
        $x += $w;
2675
        $y -= 1;
2676
        if ($this->orientacao == 'P') {
2677
            $w = $this->wPrint-$w;
2678
        } else {
2679
            $w = $this->wPrint-$w-$this->wCanhoto;
2680
        }
2681
        $aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>'B');
2682
        $this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 1, '');
2683
        //inserir texto informando caso de contingência
2684
        // 1 - Normal - emissão normal;
2685
        // 2 - Contingência FS - emissão em contingência com impressão do DANFE em Formulário de Segurança;
2686
        // 3 - Contingência SCAN - emissão em contingência no Sistema de Contingência do Ambiente Nacional;
2687
        // 4 - Contingência DPEC - emissão em contingência com envio da Declaração
2688
        //     Prévia de Emissão em Contingência;
2689
        // 5 - Contingência FS-DA - emissão em contingência com impressão do DANFE em Formulário de
2690
        //     Segurança para Impressão de Documento Auxiliar de Documento Fiscal Eletrônico (FS-DA);
2691
        // 6 - Contingência SVC-AN
2692
        // 7 - Contingência SVC-RS
2693
        $xJust = $this->pSimpleGetValue($this->ide, 'xJust', 'Justificativa: ');
2694
        $dhCont = $this->pSimpleGetValue($this->ide, 'dhCont', ' Entrada em contingência : ');
2695
        $texto = '';
2696
        switch ($this->tpEmis) {
2697
            case 2:
2698
                $texto = 'CONTINGÊNCIA FS' . $dhCont . $xJust;
2699
                break;
2700
            case 3:
2701
                $texto = 'CONTINGÊNCIA SCAN' . $dhCont . $xJust;
2702
                break;
2703
            case 4:
2704
                $texto = 'CONTINGÊNCIA DPEC' . $dhCont . $xJust;
2705
                break;
2706
            case 5:
2707
                $texto = 'CONTINGÊNCIA FSDA' . $dhCont . $xJust;
2708
                break;
2709
            case 6:
2710
                $texto = 'CONTINGÊNCIA SVC-AN' . $dhCont . $xJust;
2711
                break;
2712
            case 7:
2713
                $texto = 'CONTINGÊNCIA SVC-RS' . $dhCont . $xJust;
2714
                break;
2715
        }
2716
        $y += 2;
2717
        $aFont = array('font'=>$this->fontePadrao, 'size'=>7, 'style'=>'');
2718
        $this->pTextBox($x, $y, $w-2, $h-3, $texto, $aFont, 'T', 'L', 0, '', false);
2719
        return $y+$h;
2720
    }
2721
2722
    /**
2723
     * pRodape
2724
     * Monta o rodapé no final da DANFE com a data/hora de impressão e informações
2725
     * sobre a API NfePHP
2726
     *
2727
     * @name   pRodape
2728
     * @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...
2729
     * @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...
2730
     * @return void
2731
     */
2732
    protected function pRodape($x, $y)
2733
    {
2734
        if ($this->orientacao == 'P') {
2735
              $w = $this->wPrint;
2736
        } else {
2737
              $w = $this->wPrint-$this->wCanhoto;
2738
              $x = $this->wCanhoto;
2739
        }
2740
        $aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>'I');
2741
        $texto = "Impresso em ". date('d/m/Y') . " as " . date('H:i:s');
2742
        $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...
2743
        $texto = $this->creditos .  "  Powered by NFePHP";
2744
        $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...
2745
    }
2746
2747
    /**
2748
     * pCcanhotoDANFE
2749
     * Monta o canhoto da DANFE (retrato e paisagem)
2750
     *
2751
     * @name   canhotoDANFE
2752
     * @param  number $x Posição horizontal canto esquerdo
2753
     * @param  number $y Posição vertical canto superior
2754
     * @return number Posição vertical final
2755
     *
2756
     * TODO 21/07/14 fmertins: quando orientação L-paisagem, o canhoto está sendo gerado incorretamente
2757
     */
2758
    protected function pCanhoto($x, $y)
2759
    {
2760
        $oldX = $x;
2761
        $oldY = $y;
2762
        //#################################################################################
2763
        //canhoto
2764
        //identificação do tipo de nf entrada ou saida
2765
        $tpNF = $this->ide->getElementsByTagName('tpNF')->item(0)->nodeValue;
2766
        if ($tpNF == '0') {
2767
            //NFe de Entrada
2768
            $emitente = '';
2769
            $emitente .= $this->dest->getElementsByTagName("xNome")->item(0)->nodeValue . " - ";
2770
            $emitente .= $this->enderDest->getElementsByTagName("xLgr")->item(0)->nodeValue . ", ";
2771
            $emitente .= $this->enderDest->getElementsByTagName("nro")->item(0)->nodeValue . " - ";
2772
            $emitente .= $this->pSimpleGetValue($this->enderDest, "xCpl", " - ", " ");
2773
            $emitente .= $this->enderDest->getElementsByTagName("xBairro")->item(0)->nodeValue . " ";
2774
            $emitente .= $this->enderDest->getElementsByTagName("xMun")->item(0)->nodeValue . "-";
2775
            $emitente .= $this->enderDest->getElementsByTagName("UF")->item(0)->nodeValue . "";
2776
            $destinatario = $this->emit->getElementsByTagName("xNome")->item(0)->nodeValue . " ";
2777
        } else {
2778
            //NFe de Saída
2779
            $emitente = $this->emit->getElementsByTagName("xNome")->item(0)->nodeValue . " ";
2780
            $destinatario = '';
2781
            $destinatario .= $this->dest->getElementsByTagName("xNome")->item(0)->nodeValue . " - ";
2782
            $destinatario .= $this->enderDest->getElementsByTagName("xLgr")->item(0)->nodeValue . ", ";
2783
            $destinatario .= $this->enderDest->getElementsByTagName("nro")->item(0)->nodeValue . " ";
2784
            $destinatario .= $this->pSimpleGetValue($this->enderDest, "xCpl", " - ", " ");
2785
            $destinatario .= $this->enderDest->getElementsByTagName("xBairro")->item(0)->nodeValue . " ";
2786
            $destinatario .= $this->enderDest->getElementsByTagName("xMun")->item(0)->nodeValue . "-";
2787
            $destinatario .= $this->enderDest->getElementsByTagName("UF")->item(0)->nodeValue . " ";
2788
        }
2789
        //identificação do sistema emissor
2790
        //linha separadora do canhoto
2791
        if ($this->orientacao == 'P') {
2792
            $w = round($this->wPrint * 0.81, 0);
2793
        } else {
2794
            //linha separadora do canhoto - 238
2795
            //posicao altura
2796
            $y = $this->wPrint-85;
2797
            //altura
2798
            $w = $this->wPrint-85-24;
2799
        }
2800
        $h = 10;
2801
        //desenha caixa
2802
        $texto = '';
2803
        $aFont = array('font'=>$this->fontePadrao, 'size'=>7, 'style'=>'');
2804
        $aFontSmall = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>'');
2805
        if ($this->orientacao == 'P') {
2806
            $this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'C', 'L', 1, '', false);
2807
        } else {
2808
            $this->pTextBox90($x, $y, $w, $h, $texto, $aFont, 'C', 'L', 1, '', false);
2809
        }
2810
        $numNF = str_pad($this->ide->getElementsByTagName('nNF')->item(0)->nodeValue, 9, "0", STR_PAD_LEFT);
2811
        $serie = str_pad($this->ide->getElementsByTagName('serie')->item(0)->nodeValue, 3, "0", STR_PAD_LEFT);
2812
        $texto = "RECEBEMOS DE ";
2813
        $texto .= $emitente;
2814
        $texto .= " OS PRODUTOS E/OU SERVIÇOS CONSTANTES DA NOTA FISCAL ELETRÔNICA INDICADA ";
2815
        if ($this->orientacao == 'P') {
2816
            $texto .= "ABAIXO";
2817
        } else {
2818
            $texto .= "AO LADO";
2819
        }
2820
        $texto .= ". EMISSÃO: ";
2821
        $dEmi = ! empty($this->ide->getElementsByTagName("dEmi")->item(0)->nodeValue) ?
2822
                $this->ide->getElementsByTagName("dEmi")->item(0)->nodeValue : '';
2823
        if ($dEmi == '') {
2824
            $dEmi = ! empty($this->ide->getElementsByTagName("dhEmi")->item(0)->nodeValue) ?
2825
                    $this->ide->getElementsByTagName("dhEmi")->item(0)->nodeValue : '';
2826
            $aDemi = explode('T', $dEmi);
2827
            $dEmi = $aDemi[0];
2828
        }
2829
        $texto .= $this->pYmd2dmy($dEmi) ." ";
2830
        $texto .= "VALOR TOTAL: R$ ";
2831
        $texto .= number_format($this->ICMSTot->getElementsByTagName("vNF")->item(0)->nodeValue, 2, ",", ".") . " ";
2832
        $texto .= "DESTINATÁRIO: ";
2833
        $texto .= $destinatario;
2834
        if ($this->orientacao == 'P') {
2835
            $this->pTextBox($x, $y, $w-1, $h, $texto, $aFont, 'C', 'L', 0, '', false);
2836
            $x1 = $x + $w;
2837
            $w1 = $this->wPrint - $w;
2838
            $texto = "NF-e";
2839
            $aFont = array('font'=>$this->fontePadrao, 'size'=>14, 'style'=>'B');
2840
            $this->pTextBox($x1, $y, $w1, 18, $texto, $aFont, 'T', 'C', 0, '');
2841
            $texto = "Nº. " . $this->pFormat($numNF, "###.###.###") . " \n";
2842
            $texto .= "Série $serie";
2843
            $aFont = array('font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B');
2844
            $this->pTextBox($x1, $y, $w1, 18, $texto, $aFont, 'C', 'C', 1, '');
2845
            //DATA DE RECEBIMENTO
2846
            $texto = "DATA DE RECEBIMENTO";
2847
            $y += $h;
2848
            $w2 = round($this->wPrint*0.17, 0); //35;
2849
            $aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>'');
2850
            $this->pTextBox($x, $y, $w2, 8, $texto, $aFont, 'T', 'L', 1, '');
2851
            //IDENTIFICAÇÃO E ASSINATURA DO RECEBEDOR
2852
            $x += $w2;
2853
            $w3 = $w-$w2;
2854
            $texto = "IDENTIFICAÇÃO E ASSINATURA DO RECEBEDOR";
2855
            $this->pTextBox($x, $y, $w3, 8, $texto, $aFont, 'T', 'L', 1, '');
2856
            $x = $oldX;
2857
            $y += 9;
2858
            $this->pdf->DashedHLine($x, $y, $this->wPrint, 0.1, 80);
2859
            $y += 2;
2860
            return $y;
2861
        } else {
2862
            $x--;
2863
            $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...
2864
            //NUMERO DA NOTA FISCAL LOGO NFE
2865
            $w1 = 16;
2866
            $x1 = $oldX;
2867
            $y = $oldY;
2868
            $texto = "NF-e";
2869
            $aFont = array('font'=>$this->fontePadrao, 'size'=>14, 'style'=>'B');
2870
            $this->pTextBox($x1, $y, $w1, 18, $texto, $aFont, 'T', 'C', 0, '');
2871
            $texto = "Nº.\n" . $this->pFormat($numNF, "###.###.###") . " \n";
2872
            $texto .= "Série $serie";
2873
            $aFont = array('font'=>$this->fontePadrao, 'size'=>8, 'style'=>'B');
2874
            $this->pTextBox($x1, $y, $w1, 18, $texto, $aFont, 'C', 'C', 1, '');
2875
            //DATA DO RECEBIMENTO
2876
            $texto = "DATA DO RECEBIMENTO";
2877
            $y = $this->wPrint-85;
2878
            $x = 12;
2879
            $w2 = round($this->wPrint*0.17, 0); //35;
2880
            $aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>'');
2881
            $this->pTextBox90($x, $y, $w2, 8, $texto, $aFont, 'T', 'L', 1, '');
2882
            //IDENTIFICAÇÃO E ASSINATURA DO RECEBEDOR
2883
            $y -= $w2;
2884
            $w3 = $w-$w2;
2885
            $texto = "IDENTIFICAÇÃO E ASSINATURA DO RECEBEDOR";
2886
            $aFont = array('font'=>$this->fontePadrao, 'size'=>5.7, 'style'=>'');
2887
            $x = $this->pTextBox90($x, $y, $w3, 8, $texto, $aFont, 'T', 'L', 1, '');
2888
            $this->pdf->DashedVLine(23, $oldY, 0.1, $this->wPrint-20, 67);
2889
            return $x;
2890
        }
2891
    }
2892
2893
    /**
2894
     * pGeraInformacoesDaTagCompra
2895
     * Devolve uma string contendo informação sobre as tag <compra><xNEmp>, <xPed> e <xCont> ou string vazia.
2896
     * Aviso: Esta função não leva em consideração dados na tag xPed do item.
2897
     *
2898
     * @name   pGeraInformacoesDaTagCompra
2899
     * @return string com as informacoes dos pedidos.
2900
     */
2901
    protected function pGeraInformacoesDaTagCompra()
2902
    {
2903
        $saida = "";
2904
        if (isset($this->compra)) {
2905
            if (! empty($this->compra->getElementsByTagName("xNEmp")->item(0)->nodeValue)) {
2906
                $saida .= " Nota de Empenho: " . $this->compra->getElementsByTagName("xNEmp")->item(0)->nodeValue;
2907
            }
2908
            if (! empty($this->compra->getElementsByTagName("xPed")->item(0)->nodeValue)) {
2909
                $saida .= " Pedido: " . $this->compra->getElementsByTagName("xPed")->item(0)->nodeValue;
2910
            }
2911
            if (! empty($this->compra->getElementsByTagName("xCont")->item(0)->nodeValue)) {
2912
                $saida .= " Contrato: " . $this->compra->getElementsByTagName("xCont")->item(0)->nodeValue;
2913
            }
2914
        }
2915
        return $saida;
2916
    }
2917
2918
    /**
2919
     * pGeraChaveAdicionalDeContingencia
2920
     *
2921
     * @name   pGeraChaveAdicionalDeContingencia
2922
     * @return string chave
2923
     */
2924
    protected function pGeraChaveAdicionalDeContingencia()
2925
    {
2926
        //cUF tpEmis CNPJ vNF ICMSp ICMSs DD  DV
2927
        // 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...
2928
        $forma  = "%02d%d%s%014d%01d%01d%02d";
2929
        $cUF    = $this->ide->getElementsByTagName('cUF')->item(0)->nodeValue;
2930
        $CNPJ   = "00000000000000" . $this->emit->getElementsByTagName('CNPJ')->item(0)->nodeValue;
2931
        $CNPJ   = substr($CNPJ, -14);
2932
        $vNF    = $this->ICMSTot->getElementsByTagName("vNF")->item(0)->nodeValue * 100;
2933
        $vICMS  = $this->ICMSTot->getElementsByTagName("vICMS")->item(0)->nodeValue;
2934
        if ($vICMS > 0) {
2935
            $vICMS = 1;
2936
        }
2937
        $icmss  = $this->ICMSTot->getElementsByTagName("vBC")->item(0)->nodeValue;
2938
        if ($icmss > 0) {
2939
            $icmss = 1;
2940
        }
2941
        $dEmi = ! empty($this->ide->getElementsByTagName("dEmi")->item(0)->nodeValue) ?
2942
                $this->ide->getElementsByTagName("dEmi")->item(0)->nodeValue : '';
2943
        if ($dEmi == '') {
2944
            $dEmi = ! empty($this->ide->getElementsByTagName("dhEmi")->item(0)->nodeValue) ?
2945
                    $this->ide->getElementsByTagName("dhEmi")->item(0)->nodeValue : '';
2946
            $aDemi = explode('T', $dEmi);
2947
            $dEmi = $aDemi[0];
2948
        }
2949
        $dd  = $dEmi;
2950
        $rpos = strrpos($dd, '-');
2951
        $dd  = substr($dd, $rpos +1);
2952
        $chave = sprintf($forma, $cUF, $this->tpEmis, $CNPJ, $vNF, $vICMS, $icmss, $dd);
2953
        $chave = $chave . $this->pModulo11($chave);
2954
        return $chave;
2955
    }
2956
2957
    /**
2958
     * pGeraInformacoesDasNotasReferenciadas
2959
     * Devolve uma string contendo informação sobre as notas referenciadas. Suporta N notas, eletrônicas ou não
2960
     * Exemplo: NFe Ref.: série: 01 número: 01 emit: 11.111.111/0001-01
2961
     * em 10/2010 [0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000]
2962
     *
2963
     * @return string Informacoes a serem adicionadas no rodapé sobre notas referenciadas.
2964
     */
2965
    protected function pGeraInformacoesDasNotasReferenciadas()
2966
    {
2967
        $formaNfeRef = "\r\nNFe Ref.: série:%d número:%d emit:%s em %s [%s]";
2968
        $formaCTeRef = "\r\nCTe Ref.: série:%d número:%d emit:%s em %s [%s]";
2969
        $formaNfRef = "\r\nNF  Ref.: série:%d numero:%d emit:%s em %s modelo: %d";
2970
        $formaECFRef = "\r\nECF Ref.: modelo: %s ECF:%d COO:%d";
2971
        $formaNfpRef = "\r\nNFP Ref.: série:%d número:%d emit:%s em %s modelo: %d IE:%s";
2972
        $saida='';
2973
        $nfRefs = $this->ide->getElementsByTagName('NFref');
2974
        if (0 === $nfRefs->length) {
2975
            return $saida;
2976
        }
2977
        foreach ($nfRefs as $nfRef) {
2978
            if (empty($nfRef)) {
2979
                continue;
2980
            }
2981
            $refNFe = $nfRef->getElementsByTagName('refNFe');
2982
            foreach ($refNFe as $chave_acessoRef) {
2983
                $chave_acesso = $chave_acessoRef->nodeValue;
2984
                $chave_acessoF = $this->pFormat($chave_acesso, $this->formatoChave);
2985
                $data = substr($chave_acesso, 4, 2)."/20".substr($chave_acesso, 2, 2);
2986
                $cnpj = $this->pFormat(substr($chave_acesso, 6, 14), "##.###.###/####-##");
2987
                $serie  = substr($chave_acesso, 22, 3);
2988
                $numero = substr($chave_acesso, 25, 9);
2989
                $saida .= sprintf($formaNfeRef, $serie, $numero, $cnpj, $data, $chave_acessoF);
2990
            }
2991
            $refNF = $nfRef->getElementsByTagName('refNF');
2992
            foreach ($refNF as $umaRefNFe) {
2993
                $data = $umaRefNFe->getElementsByTagName('AAMM')->item(0)->nodeValue;
2994
                $cnpj = $umaRefNFe->getElementsByTagName('CNPJ')->item(0)->nodeValue;
2995
                $mod = $umaRefNFe->getElementsByTagName('mod')->item(0)->nodeValue;
2996
                $serie = $umaRefNFe->getElementsByTagName('serie')->item(0)->nodeValue;
2997
                $numero = $umaRefNFe->getElementsByTagName('nNF')->item(0)->nodeValue;
2998
                $data = substr($data, 2, 2) . "/20" . substr($data, 0, 2);
2999
                $cnpj = $this->pFormat($cnpj, "##.###.###/####-##");
3000
                $saida .= sprintf($formaNfRef, $serie, $numero, $cnpj, $data, $mod);
3001
            }
3002
            $refCTe = $nfRef->getElementsByTagName('refCTe');
3003
            foreach ($refCTe as $chave_acessoRef) {
3004
                $chave_acesso = $chave_acessoRef->nodeValue;
3005
                $chave_acessoF = $this->pFormat($chave_acesso, $this->formatoChave);
3006
                $data = substr($chave_acesso, 4, 2)."/20".substr($chave_acesso, 2, 2);
3007
                $cnpj = $this->pFormat(substr($chave_acesso, 6, 14), "##.###.###/####-##");
3008
                $serie  = substr($chave_acesso, 22, 3);
3009
                $numero = substr($chave_acesso, 25, 9);
3010
                $saida .= sprintf($formaCTeRef, $serie, $numero, $cnpj, $data, $chave_acessoF);
3011
            }
3012
            $refECF = $nfRef->getElementsByTagName('refECF');
3013
            foreach ($refECF as $umaRefNFe) {
3014
                $mod    = $umaRefNFe->getElementsByTagName('mod')->item(0)->nodeValue;
3015
                $nECF   = $umaRefNFe->getElementsByTagName('nECF')->item(0)->nodeValue;
3016
                $nCOO   = $umaRefNFe->getElementsByTagName('nCOO')->item(0)->nodeValue;
3017
                $saida .= sprintf($formaECFRef, $mod, $nECF, $nCOO);
3018
            }
3019
            $refNFP = $nfRef->getElementsByTagName('refNFP');
3020
            foreach ($refNFP as $umaRefNFe) {
3021
                $data = $umaRefNFe->getElementsByTagName('AAMM')->item(0)->nodeValue;
3022
                $cnpj = ! empty($umaRefNFe->getElementsByTagName('CNPJ')->item(0)->nodeValue) ?
3023
                    $umaRefNFe->getElementsByTagName('CNPJ')->item(0)->nodeValue :
3024
                    '';
3025
                $cpf = ! empty($umaRefNFe->getElementsByTagName('CPF')->item(0)->nodeValue) ?
3026
                        $umaRefNFe->getElementsByTagName('CPF')->item(0)->nodeValue : '';
3027
                $mod = $umaRefNFe->getElementsByTagName('mod')->item(0)->nodeValue;
3028
                $serie = $umaRefNFe->getElementsByTagName('serie')->item(0)->nodeValue;
3029
                $numero = $umaRefNFe->getElementsByTagName('nNF')->item(0)->nodeValue;
3030
                $ie = $umaRefNFe->getElementsByTagName('IE')->item(0)->nodeValue;
3031
                $data = substr($data, 2, 2) . "/20" . substr($data, 0, 2);
3032
                if ($cnpj == '') {
3033
                    $cpf_cnpj = $this->pFormat($cpf, "###.###.###-##");
3034
                } else {
3035
                    $cpf_cnpj = $this->pFormat($cnpj, "##.###.###/####-##");
3036
                }
3037
                $saida .= sprintf($formaNfpRef, $serie, $numero, $cpf_cnpj, $data, $mod, $ie);
3038
            }
3039
        }
3040
        return $saida;
3041
    }
3042
}
3043