Passed
Push — master ( 7b057c...50e4f4 )
by Roberto
01:02
created

Danfe::pagamentoDANFE()   F

Complexity

Conditions 15
Paths 593

Size

Total Lines 91

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 240

Importance

Changes 0
Metric Value
cc 15
nc 593
nop 2
dl 0
loc 91
ccs 0
cts 86
cp 0
crap 240
rs 2.0485
c 0
b 0
f 0

How to fix   Long Method    Complexity   

Long Method

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

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

Commonly applied refactorings include:

1
<?php
2
3
namespace NFePHP\DA\NFe;
4
5
use InvalidArgumentException;
6
use NFePHP\DA\Legacy\Dom;
7
use NFePHP\DA\Legacy\Pdf;
8
use NFePHP\DA\Legacy\Common;
9
10
class Danfe extends Common
11
{
12
    const FPDF_FONTPATH = 'font/';
13
    const SIT_CANCELADA = 1;
14
    const SIT_DENEGADA = 2;
15
    const SIT_DPEC = 3;
16
    const SIT_NONE = 0;
17
18
    /**
19
     * alinhamento padrão do logo (C-Center)
20
     *
21
     * @var string
22
     */
23
    public $logoAlign = 'C';
24
    /**
25
     * Posição
26
     * @var float
27
     */
28
    public $yDados = 0;
29
    /**
30
     * Situação
31
     * @var integer
32
     */
33
    public $situacaoExterna = 0;
34
    /**
35
     * Numero DPEC
36
     *
37
     * @var string
38
     */
39
    public $numero_registro_dpec = '';
40
    /**
41
     * quantidade de canhotos a serem montados, geralmente 1 ou 2
42
     *
43
     * @var integer
44
     */
45
    public $qCanhoto = 1;
46
47
    //###########################################################
48
    // INÍCIO ATRIBUTOS DE PARÂMETROS DE EXIBIÇÃO
49
    //###########################################################
50
51
    /**
52
     * Parâmetro para exibir ou ocultar os valores do PIS/COFINS.
53
     * @var boolean
54
     */
55
    public $exibirPIS = true;
56
    /**
57
     * Parâmetro para exibir ou ocultar os valores do ICMS Interestadual e Valor Total dos Impostos.
58
     * @var boolean
59
     */
60
    public $exibirIcmsInterestadual = true;
61
    /**
62
     * Parâmetro para exibir ou ocultar o texto sobre valor aproximado dos tributos.
63
     * @var boolean
64
     */
65
    public $exibirValorTributos = true;
66
    /**
67
     * Parâmetro para exibir ou ocultar o texto adicional sobre a forma de pagamento
68
     * e as informações de fatura/duplicata.
69
     * @var boolean
70
     */
71
    public $exibirTextoFatura = false;
72
    /**
73
     * Parâmetro do controle se deve concatenar automaticamente informações complementares
74
     * na descrição do produto, como por exemplo, informações sobre impostos.
75
     * @var boolean
76
     */
77
    public $descProdInfoComplemento = true;
78
    /**
79
     * Parâmetro do controle se deve gerar quebras de linha com "\n" a partir de ";" na descrição do produto.
80
     * @var boolean
81
     */
82
    public $descProdQuebraLinha = true;
83
84
    //###########################################################
85
    //PROPRIEDADES DA CLASSE
86
    //###########################################################
87
88
    /**
89
     * objeto fpdf()
90
     * @var object
91
     */
92
    protected $pdf;
93
    /**
94
     * XML NFe
95
     * @var string
96
     */
97
    protected $xml;
98
    /**
99
     * path para logomarca em jpg
100
     * @var string
101
     */
102
    protected $logomarca = '';
103
    /**
104
     * mesagens de erro
105
     * @var string
106
     */
107
    protected $errMsg = '';
108
    /**
109
     * status de erro true um erro ocorreu false sem erros
110
     * @var boolean
111
     */
112
    protected $errStatus = false;
113
    /**
114
     * orientação da DANFE
115
     * P-Retrato ou L-Paisagem
116
     * @var string
117
     */
118
    protected $orientacao = 'P';
119
    /**
120
     * formato do papel
121
     * @var string
122
     */
123
    protected $papel = 'A4';
124
    /**
125
     * destino do arquivo pdf
126
     * I-borwser, S-retorna o arquivo, D-força download, F-salva em arquivo local
127
     * @var string
128
     */
129
    protected $destino = 'I';
130
    /**
131
     * diretorio para salvar o pdf com a opção de destino = F
132
     * @var string
133
     */
134
    protected $pdfDir = '';
135
    /**
136
     * Nome da Fonte para gerar o DANFE
137
     * @var string
138
     */
139
    protected $fontePadrao = 'Times';
140
    /**
141
     * versão
142
     * @var string
143
     */
144
    protected $version = '2.2.8';
145
    /**
146
     * Texto
147
     * @var string
148
     */
149
    protected $textoAdic = '';
150
    /**
151
     * Largura
152
     * @var float
153
     */
154
    protected $wAdic = 0;
155
    /**
156
     * largura imprimivel, em milímetros
157
     * @var float
158
     */
159
    protected $wPrint;
160
    /**
161
     * Comprimento (altura) imprimivel, em milímetros
162
     * @var float
163
     */
164
    protected $hPrint;
165
    /**
166
     * largura do canhoto (25mm) apenas para a formatação paisagem
167
     * @var float
168
     */
169
    protected $wCanhoto = 25;
170
    /**
171
     * Formato chave
172
     * @var string
173
     */
174
    protected $formatoChave = "#### #### #### #### #### #### #### #### #### #### ####";
175
    /**
176
     * quantidade de itens já processados na montagem do DANFE
177
     * @var integer
178
     */
179
    protected $qtdeItensProc;
180
181
    /**
182
     * Document
183
     * @var DOMDocument
184
     */
185
    protected $dom;
186
    /**
187
     * Node
188
     * @var DOMNode
189
     */
190
    protected $infNFe;
191
    /**
192
     * Node
193
     * @var DOMNode
194
     */
195
    protected $ide;
196
    /**
197
     * Node
198
     * @var DOMNode
199
     */
200
    protected $entrega;
201
    /**
202
     * Node
203
     * @var DOMNode
204
     */
205
    protected $retirada;
206
    /**
207
     * Node
208
     * @var DOMNode
209
     */
210
    protected $emit;
211
    /**
212
     * Node
213
     * @var DOMNode
214
     */
215
    protected $dest;
216
    /**
217
     * Node
218
     * @var DOMNode
219
     */
220
    protected $enderEmit;
221
    /**
222
     * Node
223
     * @var DOMNode
224
     */
225
    protected $enderDest;
226
    /**
227
     * Node
228
     * @var DOMNode
229
     */
230
    protected $det;
231
    /**
232
     * Node
233
     * @var DOMNode
234
     */
235
    protected $cobr;
236
    /**
237
     * Node
238
     * @var DOMNode
239
     */
240
    protected $dup;
241
    /**
242
     * Node
243
     * @var DOMNode
244
     */
245
    protected $ICMSTot;
246
    /**
247
     * Node
248
     * @var DOMNode
249
     */
250
    protected $ISSQNtot;
251
    /**
252
     * Node
253
     * @var DOMNode
254
     */
255
    protected $transp;
256
    /**
257
     * Node
258
     * @var DOMNode
259
     */
260
    protected $transporta;
261
    /**
262
     * Node
263
     * @var DOMNode
264
     */
265
    protected $veicTransp;
266
    /**
267
     * Node reboque
268
     * @var DOMNode
269
     */
270
    protected $reboque;
271
    /**
272
     * Node infAdic
273
     * @var DOMNode
274
     */
275
    protected $infAdic;
276
    /**
277
     * Tipo de emissão
278
     * @var integer
279
     */
280
    protected $tpEmis;
281
    /**
282
     * Node infProt
283
     * @var DOMNode
284
     */
285
    protected $infProt;
286
    /**
287
     * 1-Retrato/ 2-Paisagem
288
     * @var integer
289
     */
290
    protected $tpImp;
291
    /**
292
     * Node compra
293
     * @var DOMNode
294
     */
295
    protected $compra;
296
    /**
297
     * ativa ou desativa o modo de debug
298
     * @var integer
299
     */
300
    protected $debugMode=2;
301
    /**
302
     * Creditos para integrador
303
     * @var string
304
     */
305
    protected $creditos = '';
306
307
    /**
308
     * __construct
309
     *
310
     * @name  __construct
311
     * @param string  $docXML      Conteúdo XML da NF-e (com ou sem a tag nfeProc)
312
     * @param string  $sOrientacao (Opcional) Orientação da impressão P-retrato L-Paisagem
313
     * @param string  $sPapel      Tamanho do papel (Ex. A4)
314
     * @param string  $sPathLogo   Caminho para o arquivo do logo
315
     * @param string  $sDestino    Estabelece a direção do envio do documento PDF I-browser D-browser com download S-
316
     * @param string  $sDirPDF     Caminho para o diretorio de armazenamento dos arquivos PDF
317
     * @param string  $fonteDANFE  Nome da fonte alternativa do DAnfe
318
     * @param integer $mododebug   0-Não 1-Sim e 2-nada (2 default)
319
     */
320
    public function __construct(
321
        $docXML = '',
322
        $sOrientacao = '',
323
        $sPapel = '',
324
        $sPathLogo = '',
325
        $sDestino = 'I',
326
        $sDirPDF = '',
327
        $fonteDANFE = '',
328
        $mododebug = 2
329
    ) {
330
        //set_time_limit(1800);
331
        if (is_numeric($mododebug)) {
332
            $this->debugMode = $mododebug;
0 ignored issues
show
Documentation Bug introduced by
It seems like $mododebug can also be of type double or string. However, the property $debugMode is declared as type integer. Maybe add an additional type check?

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

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

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

class Id
{
    public $id;

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

}

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

$account_id = false;

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

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
333
        }
334
        if ($mododebug == 1) {
335
            //ativar modo debug
336
            error_reporting(E_ALL);
337
            ini_set('display_errors', 'On');
338
        }
339
        if ($mododebug == 0) {
340
            //desativar modo debug
341
            error_reporting(0);
342
            ini_set('display_errors', 'Off');
343
        }
344
        $this->orientacao   = $sOrientacao;
345
        $this->papel        = $sPapel;
346
        $this->pdf          = '';
0 ignored issues
show
Documentation Bug introduced by
It seems like '' of type string is incompatible with the declared type object of property $pdf.

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

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

Loading history...
347
        $this->xml          = $docXML;
348
        $this->logomarca    = $sPathLogo;
349
        $this->destino      = $sDestino;
350
        $this->pdfDir       = $sDirPDF;
351
        // verifica se foi passa a fonte a ser usada
352
        if (empty($fonteDANFE)) {
353
            $this->fontePadrao = 'Times';
354
        } else {
355
            $this->fontePadrao = $fonteDANFE;
356
        }
357
        //se for passado o xml
358
        if (! empty($this->xml)) {
359
            $this->dom = new Dom();
0 ignored issues
show
Documentation Bug introduced by
It seems like new \NFePHP\DA\Legacy\Dom() of type object<NFePHP\DA\Legacy\Dom> is incompatible with the declared type object<NFePHP\DA\NFe\DOMDocument> of property $dom.

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

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

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

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

class MyClass { }

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

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

class MyClass {
    public $foo;
}

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Loading history...
384
            //valida se o XML é uma NF-e modelo 55, pois não pode ser 65 (NFC-e)
385
            if ($this->pSimpleGetValue($this->ide, "mod") != '55') {
386
                throw new InvalidArgumentException("O xml do DANFE deve ser uma NF-e modelo 55");
387
            }
388
        }
389
    }
390
391
    /**
392
     * Add the credits to the integrator in the footer message
393
     * @param string $message
394
     */
395
    public function creditsIntegratorFooter($message = '')
396
    {
397
        $this->creditos = trim($message);
398
    }
399
    
400
    /**
401
     * monta
402
     *
403
     * @name   monta
404
     * @param  string $orientacao
405
     * @param  string $papel
406
     * @param  string $logoAlign
407
     * @return string
408
     */
409
    public function monta(
410
        $orientacao = '',
411
        $papel = 'A4',
412
        $logoAlign = 'C',
413
        $situacaoExterna = self::SIT_NONE,
414
        $classPdf = false,
415
        $dpecNumReg = '',
416
        $margSup = 2,
417
        $margEsq = 2,
418
        $margInf = 2
419
    ) {
420
        return $this->montaDANFE(
421
            $orientacao,
422
            $papel,
423
            $logoAlign,
424
            $situacaoExterna,
425
            $classPdf,
426
            $dpecNumReg,
427
            $margSup,
428
            $margEsq,
429
            $margInf
430
        );
431
    }
432
433
    /**
434
     * printDocument
435
     *
436
     * @param  string $nome
437
     * @param  string $destino
438
     * @param  string $printer
439
     * @return object pdf
440
     */
441
    public function printDocument($nome = '', $destino = 'I', $printer = '')
0 ignored issues
show
Unused Code introduced by
The parameter $printer is not used and could be removed.

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

Loading history...
442
    {
443
        $arq = $this->pdf->Output($nome, $destino);
444
        if ($destino == 'S') {
0 ignored issues
show
Unused Code introduced by
This if statement is empty and can be removed.

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

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

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

could be turned into

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

This is much more concise to read.

Loading history...
445
            //aqui pode entrar a rotina de impressão direta
446
        }
447
        return $arq;
448
    }
449
450
    /**
451
     * montaDANFE
452
     * Monta a DANFE conforme as informações fornecidas para a classe durante sua
453
     * construção. Constroi DANFEs com até 3 páginas podendo conter até 56 itens.
454
     * A definição de margens e posições iniciais para a impressão são estabelecidas
455
     * pelo conteúdo da funçao e podem ser modificados.
456
     *
457
     * @param  string $orientacao (Opcional) Estabelece a orientação da impressão
458
     *  (ex. P-retrato), se nada for fornecido será usado o padrão da NFe
459
     * @param  string $papel      (Opcional) Estabelece o tamanho do papel (ex. A4)
460
     * @return string O ID da NFe numero de 44 digitos extraido do arquivo XML
461
     */
462
    public function montaDANFE(
463
        $orientacao = '',
464
        $papel = 'A4',
465
        $logoAlign = 'C',
466
        $situacaoExterna = self::SIT_NONE,
467
        $classPdf = false,
468
        $depecNumReg = '',
469
        $margSup = 2,
470
        $margEsq = 2,
471
        $margInf = 2
472
    ) {
473
        //se a orientação estiver em branco utilizar o padrão estabelecido na NF
474
        if ($orientacao == '') {
475
            if ($this->tpImp == '1') {
476
                $orientacao = 'P';
477
            } else {
478
                $orientacao = 'L';
479
            }
480
        }
481
        $this->orientacao = $orientacao;
482
        $this->papel = $papel;
483
        $this->logoAlign = $logoAlign;
484
        $this->situacao_externa = $situacaoExterna;
0 ignored issues
show
Bug introduced by
The property situacao_externa does not seem to exist. Did you mean situacaoExterna?

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

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

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

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

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

Loading history...
489
        } else {
490
            $this->pdf = new Pdf($this->orientacao, 'mm', $this->papel);
491
        }
492
        //margens do PDF, em milímetros. Obs.: a margem direita é sempre igual à
493
        //margem esquerda. A margem inferior *não* existe na FPDF, é definida aqui
494
        //apenas para controle se necessário ser maior do que a margem superior
495
        // posição inicial do conteúdo, a partir do canto superior esquerdo da página
496
        $xInic = $margEsq;
497
        $yInic = $margSup;
498
        if ($this->orientacao == 'P') {
499
            if ($papel == 'A4') {
500
                $maxW = 210;
501
                $maxH = 297;
502
            }
503
        } else {
504
            if ($papel == 'A4') {
505
                $maxH = 210;
506
                $maxW = 297;
507
                //se paisagem multiplica a largura do canhoto pela quantidade de canhotos
508
                $this->wCanhoto *= $this->qCanhoto;
509
            }
510
        }
511
        //total inicial de paginas
512
        $totPag = 1;
0 ignored issues
show
Unused Code introduced by
$totPag is not used, you could remove the assignment.

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

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

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

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

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

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

Let’s take a look at an example:

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

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

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

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

Available Fixes

  1. Check for existence of the variable explicitly:

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

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

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

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

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

$answer = 42;

$correct = false;

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

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

Let’s take a look at an example:

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

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

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

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

Available Fixes

  1. Check for existence of the variable explicitly:

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

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

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

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

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

$answer = 42;

$correct = false;

$correct = (bool) $answer;
Loading history...
518
        // estabelece contagem de paginas
519
        $this->pdf->aliasNbPages();
520
        // fixa as margens
521
        $this->pdf->setMargins($margEsq, $margSup);
522
        $this->pdf->setDrawColor(0, 0, 0);
523
        $this->pdf->setFillColor(255, 255, 255);
524
        // inicia o documento
525
        $this->pdf->open();
526
        // adiciona a primeira página
527
        $this->pdf->addPage($this->orientacao, $this->papel);
528
        $this->pdf->setLineWidth(0.1);
529
        $this->pdf->setTextColor(0, 0, 0);
530
531
        //##################################################################
532
        // CALCULO DO NUMERO DE PAGINAS A SEREM IMPRESSAS
533
        //##################################################################
534
        //Verificando quantas linhas serão usadas para impressão das duplicatas
535
        $linhasDup = 0;
536
        if (($this->dup->length > 0) && ($this->dup->length <= 7)) {
537
            $linhasDup = 1;
538
        } elseif (($this->dup->length > 7) && ($this->dup->length <= 14)) {
539
            $linhasDup = 2;
540
        } elseif (($this->dup->length > 14) && ($this->dup->length <= 21)) {
541
            $linhasDup = 3;
542
        } elseif ($this->dup->length > 21) {
543
            // chinnonsantos 11/05/2016: Limite máximo de impressão de duplicatas na NFe,
544
            // só vai ser exibito as 21 primeiras duplicatas (parcelas de pagamento),
545
            // se não oculpa espaço d+, cada linha comporta até 7 duplicatas.
546
            $linhasDup = 3;
547
        }
548
        //verifica se será impressa a linha dos serviços ISSQN
549
        $linhaISSQN = 0;
550
        if ((isset($this->ISSQNtot)) && ($this->pSimpleGetValue($this->ISSQNtot, 'vServ') > 0)) {
551
            $linhaISSQN = 1;
552
        }
553
        //calcular a altura necessária para os dados adicionais
554
        if ($this->orientacao == 'P') {
555
            $this->wAdic = round($this->wPrint*0.66, 0);
556
        } else {
557
            $this->wAdic = round(($this->wPrint-$this->wCanhoto)*0.5, 0);
558
        }
559
        $fontProduto = array('font'=>$this->fontePadrao, 'size'=>7, 'style'=>'');
560
        $this->textoAdic = '';
561
        if (isset($this->retirada)) {
562
            $txRetCNPJ = ! empty($this->retirada->getElementsByTagName("CNPJ")->item(0)->nodeValue) ?
563
                $this->retirada->getElementsByTagName("CNPJ")->item(0)->nodeValue :
564
                '';
565
            $txRetxLgr = ! empty($this->retirada->getElementsByTagName("xLgr")->item(0)->nodeValue) ?
566
                $this->retirada->getElementsByTagName("xLgr")->item(0)->nodeValue :
567
                '';
568
            $txRetnro = ! empty($this->retirada->getElementsByTagName("nro")->item(0)->nodeValue) ?
569
                $this->retirada->getElementsByTagName("nro")->item(0)->nodeValue :
570
                's/n';
571
            $txRetxCpl = $this->pSimpleGetValue($this->retirada, "xCpl", " - ");
572
            $txRetxBairro = ! empty($this->retirada->getElementsByTagName("xBairro")->item(0)->nodeValue) ?
573
                $this->retirada->getElementsByTagName("xBairro")->item(0)->nodeValue :
574
                '';
575
            $txRetxMun = ! empty($this->retirada->getElementsByTagName("xMun")->item(0)->nodeValue) ?
576
                $this->retirada->getElementsByTagName("xMun")->item(0)->nodeValue :
577
                '';
578
            $txRetUF = ! empty($this->retirada->getElementsByTagName("UF")->item(0)->nodeValue) ?
579
                $this->retirada->getElementsByTagName("UF")->item(0)->nodeValue :
580
                '';
581
            $this->textoAdic .= "LOCAL DE RETIRADA : ".
582
                    $txRetCNPJ.
583
                    '-' .
584
                    $txRetxLgr .
585
                    ', ' .
586
                    $txRetnro .
587
                    ' ' .
588
                    $txRetxCpl .
589
                    ' - ' .
590
                    $txRetxBairro .
591
                    ' ' .
592
                    $txRetxMun .
593
                    ' - ' .
594
                    $txRetUF .
595
                    "\r\n";
596
        }
597
        //dados do local de entrega da mercadoria
598
        if (isset($this->entrega)) {
599
            $txRetCNPJ = ! empty($this->entrega->getElementsByTagName("CNPJ")->item(0)->nodeValue) ?
600
                $this->entrega->getElementsByTagName("CNPJ")->item(0)->nodeValue : '';
601
            $txRetxLgr = ! empty($this->entrega->getElementsByTagName("xLgr")->item(0)->nodeValue) ?
602
                $this->entrega->getElementsByTagName("xLgr")->item(0)->nodeValue : '';
603
            $txRetnro = ! empty($this->entrega->getElementsByTagName("nro")->item(0)->nodeValue) ?
604
                $this->entrega->getElementsByTagName("nro")->item(0)->nodeValue : 's/n';
605
            $txRetxCpl = $this->pSimpleGetValue($this->entrega, "xCpl", " - ");
606
            $txRetxBairro = ! empty($this->entrega->getElementsByTagName("xBairro")->item(0)->nodeValue) ?
607
                $this->entrega->getElementsByTagName("xBairro")->item(0)->nodeValue : '';
608
            $txRetxMun = ! empty($this->entrega->getElementsByTagName("xMun")->item(0)->nodeValue) ?
609
                $this->entrega->getElementsByTagName("xMun")->item(0)->nodeValue : '';
610
            $txRetUF = ! empty($this->entrega->getElementsByTagName("UF")->item(0)->nodeValue) ?
611
                $this->entrega->getElementsByTagName("UF")->item(0)->nodeValue : '';
612
            if ($this->textoAdic != '') {
613
                $this->textoAdic .= ". \r\n";
614
            }
615
            $this->textoAdic .= "LOCAL DE ENTREGA : ".$txRetCNPJ.'-'.$txRetxLgr.', '.$txRetnro.' '.$txRetxCpl.
616
               ' - '.$txRetxBairro.' '.$txRetxMun.' - '.$txRetUF."\r\n";
617
        }
618
        //informações adicionais
619
        $this->textoAdic .= $this->pGeraInformacoesDasNotasReferenciadas();
620
        if (isset($this->infAdic)) {
621
            $i = 0;
622
            if ($this->textoAdic != '') {
623
                $this->textoAdic .= ". \r\n";
624
            }
625
            $this->textoAdic .= ! empty($this->infAdic->getElementsByTagName("infCpl")->item(0)->nodeValue) ?
626
                'Inf. Contribuinte: ' .
627
                trim($this->pAnfavea($this->infAdic->getElementsByTagName("infCpl")->item(0)->nodeValue)) : '';
628
            $infPedido = $this->pGeraInformacoesDaTagCompra();
629
            if ($infPedido != "") {
630
                $this->textoAdic .= $infPedido;
631
            }
632
            $this->textoAdic .= $this->pSimpleGetValue($this->dest, "email", ' Email do Destinatário: ');
633
            $this->textoAdic .= ! empty($this->infAdic->getElementsByTagName("infAdFisco")->item(0)->nodeValue) ?
634
                "\r\n Inf. fisco: " .
635
                trim($this->infAdic->getElementsByTagName("infAdFisco")->item(0)->nodeValue) : '';
636
            $obsCont = $this->infAdic->getElementsByTagName("obsCont");
637
            if (isset($obsCont)) {
638
                foreach ($obsCont as $obs) {
639
                    $campo =  $obsCont->item($i)->getAttribute("xCampo");
640
                    $xTexto = ! empty($obsCont->item($i)->getElementsByTagName("xTexto")->item(0)->nodeValue) ?
641
                        $obsCont->item($i)->getElementsByTagName("xTexto")->item(0)->nodeValue : '';
642
                    $this->textoAdic .= "\r\n" . $campo . ':  ' . trim($xTexto);
643
                    $i++;
644
                }
645
            }
646
        }
647
        //INCLUSO pela NT 2013.003 Lei da Transparência
648
        //verificar se a informação sobre o valor aproximado dos tributos
649
        //já se encontra no campo de informações adicionais
650
        if ($this->exibirValorTributos) {
651
            $flagVTT = strpos(strtolower(trim($this->textoAdic)), 'valor');
652
            $flagVTT = $flagVTT || strpos(strtolower(trim($this->textoAdic)), 'vl');
653
            $flagVTT = $flagVTT && strpos(strtolower(trim($this->textoAdic)), 'aprox');
654
            $flagVTT = $flagVTT && (strpos(strtolower(trim($this->textoAdic)), 'trib') ||
655
                    strpos(strtolower(trim($this->textoAdic)), 'imp'));
656
            $vTotTrib = $this->pSimpleGetValue($this->ICMSTot, 'vTotTrib');
657
            if ($vTotTrib != '' && !$flagVTT) {
658
                $this->textoAdic .= "\n Valor Aproximado dos Tributos : R$ " . number_format($vTotTrib, 2, ",", ".");
659
            }
660
        }
661
        //fim da alteração NT 2013.003 Lei da Transparência
662
        $this->textoAdic = str_replace(";", "\n", $this->textoAdic);
663
        $alinhas = explode("\n", $this->textoAdic);
664
        $numlinhasdados = 0;
665
        foreach ($alinhas as $linha) {
666
            $numlinhasdados += $this->pGetNumLines($linha, $this->wAdic, $fontProduto);
667
        }
668
        $hdadosadic = round(($numlinhasdados+3) * $this->pdf->fontSize, 0);
669
        if ($hdadosadic < 10) {
670
            $hdadosadic = 10;
671
        }
672
        //altura disponivel para os campos da DANFE
673
        $hcabecalho = 47;//para cabeçalho
674
        $hdestinatario = 25;//para destinatario
675
        $hduplicatas = 12;//para cada grupo de 7 duplicatas
676
        $himposto = 18;// para imposto
677
        $htransporte = 25;// para transporte
678
        $hissqn = 11;// para issqn
679
        $hfooter = 5;// para rodape
680
        $hCabecItens = 4;//cabeçalho dos itens
681
        //alturas disponiveis para os dados
682
        $hDispo1 = $this->hPrint - 10 - ($hcabecalho +
683
            $hdestinatario + ($linhasDup * $hduplicatas) + $himposto + $htransporte +
684
            ($linhaISSQN * $hissqn) + $hdadosadic + $hfooter + $hCabecItens +
685
            $this->pSizeExtraTextoFatura());
686
        if ($this->orientacao == 'P') {
687
            $hDispo1 -= 23 * $this->qCanhoto;//para canhoto
688
            $w = $this->wPrint;
689
        } else {
690
            $hcanhoto = $this->hPrint;//para canhoto
0 ignored issues
show
Unused Code introduced by
$hcanhoto is not used, you could remove the assignment.

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

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

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

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

Loading history...
691
            $w = $this->wPrint - $this->wCanhoto;
692
        }
693
        $hDispo2 = $this->hPrint - 10 - ($hcabecalho + $hfooter + $hCabecItens)-4;
694
        //Contagem da altura ocupada para impressão dos itens
695
        $fontProduto = array('font'=>$this->fontePadrao, 'size'=>7, 'style'=>'');
696
        $i = 0;
697
        $numlinhas = 0;
0 ignored issues
show
Unused Code introduced by
$numlinhas is not used, you could remove the assignment.

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

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

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

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

Loading history...
698
        $hUsado = $hCabecItens;
699
        $w2 = round($w*0.28, 0);
700
        $hDispo = $hDispo1;
701
        $totPag = 1;
702
        while ($i < $this->det->length) {
703
            $texto = $this->pDescricaoProduto($this->det->item($i));
704
            $numlinhas = $this->pGetNumLines($texto, $w2, $fontProduto);
705
            $hUsado += round(($numlinhas * $this->pdf->fontSize) + ($numlinhas * 0.5), 2);
706
            if ($hUsado > $hDispo) {
707
                $totPag++;
708
                $hDispo = $hDispo2;
709
                $hUsado = $hCabecItens;
710
                // Remove canhoto para páginas secundárias em modo paisagem ('L')
711
                $w2 = round($this->wPrint*0.28, 0);
712
                $i--; // decrementa para readicionar o item que não coube nessa pagina na outra.
713
            }
714
            $i++;
715
        } //fim da soma das areas de itens usadas
716
        $qtdeItens = $i; //controle da quantidade de itens no DANFE
717
        //montagem da primeira página
718
        $pag = 1;
719
        $x = $xInic;
720
        $y = $yInic;
721
        //coloca o(s) canhoto(s) da NFe
722
        if ($this->orientacao == 'P') {
723
            for ($i = 1; $i <= $this->qCanhoto; $i++) {
724
                $y = $this->pCanhoto($x, $y);
725
            }
726
        } else {
727
            for ($i = 1; $i <= $this->qCanhoto; $i++) {
728
                $this->pCanhoto($x, $y);
729
                $x = 25 * $i;
730
            }
731
        }
732
        //coloca o cabeçalho
733
        $y = $this->pCabecalhoDANFE($x, $y, $pag, $totPag);
734
        //coloca os dados do destinatário
735
        $y = $this->pDestinatarioDANFE($x, $y+1);
736
        
737
        
738
        //Verifica as formas de pagamento da nota fiscal
739
        $formaPag = array();
740
        if (isset($this->detPag) && $this->detPag->length > 0) {
741
            foreach ($this->detPag as $k => $d) {
742
                $fPag = !empty($this->detPag->item($k)->getElementsByTagName('tPag')->item(0)->nodeValue) ?
0 ignored issues
show
Bug introduced by
The property detPag does not exist. Did you maybe forget to declare it?

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

class MyClass { }

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

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

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
743
                    $this->detPag->item($k)->getElementsByTagName('tPag')->item(0)->nodeValue : '0';
744
                $formaPag[$fPag] = $fPag;
745
            }
746
        }
747
        //Caso só tenha pagamento em boleto exibe as faturas ou invés das formas
748
        //caso tenha boleto e sem pagamento também exibir faturas pois deve ser devolução de
749
        //materiais do destinatário e não tem cobrança
750
        if ((count($formaPag)=='1' && isset($formaPag[15]) || count($formaPag)=='2'
751
             && isset($formaPag[15]) && isset($formaPag[90]))) {
752
            $y = $this->pFaturaDANFE($x, $y+1);
753
        } else {
754
            //Se somente tiver a forma de pagamento sem pagamento ou outros não imprimir nada
755
            if (count($formaPag)=='1' && (isset($formaPag[90]) || isset($formaPag[99]))) {
756
                $y = $y;
0 ignored issues
show
Bug introduced by
Why assign $y to itself?

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

This assignement can be removed without consequences.

Loading history...
757
            } else {
758
                //Se somente tiver a forma de pagamento sem pagamento ou outros não imprimir nada
759
                if (count($formaPag)=='1' && (isset($formaPag[90]) || isset($formaPag[99]))) {
760
                    $y = $y;
0 ignored issues
show
Bug introduced by
Why assign $y to itself?

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

This assignement can be removed without consequences.

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

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

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

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

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

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

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

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

Loading history...
1376
            $x = 10;
1377
            $y = $this->hPrint-130;
1378
            $h = 25;
1379
            $w = $maxW-(2*$x);
1380
            $this->pdf->SetTextColor(90, 90, 90);
1381
            $texto = "NFe USO DENEGADO";
1382
            $aFont = array('font'=>$this->fontePadrao, 'size'=>48, 'style'=>'B');
1383
            $this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'C', 'C', 0, '');
1384
            $y += $h;
1385
            $h = 5;
1386
            $w = $maxW-(2*$x);
1387
            if (isset($this->infProt)) {
1388
                $xMotivo = $this->infProt->getElementsByTagName("xMotivo")->item(0)->nodeValue;
1389
            } else {
1390
                $xMotivo = '';
1391
            }
1392
            $texto = "SEM VALOR FISCAL\n".$xMotivo;
1393
            $aFont = array('font'=>$this->fontePadrao, 'size'=>48, 'style'=>'B');
1394
            $this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'C', 'C', 0, '');
1395
            $this->pdf->SetTextColor(0, 0, 0);
1396
        }
1397
        //indicar sem valor
1398
        if ($tpAmb != 1) {
1399
            $x = 10;
1400
            if ($this->orientacao == 'P') {
1401
                $y = round($this->hPrint*2/3, 0);
1402
            } else {
1403
                $y = round($this->hPrint/2, 0);
1404
            }
1405
            $h = 5;
1406
            $w = $maxW-(2*$x);
1407
            $this->pdf->SetTextColor(90, 90, 90);
1408
            $texto = "SEM VALOR FISCAL";
1409
            $aFont = array('font'=>$this->fontePadrao, 'size'=>48, 'style'=>'B');
1410
            $this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'C', 'C', 0, '');
1411
            $aFont = array('font'=>$this->fontePadrao, 'size'=>30, 'style'=>'B');
1412
            $texto = "AMBIENTE DE HOMOLOGAÇÃO";
1413
            $this->pTextBox($x, $y+14, $w, $h, $texto, $aFont, 'C', 'C', 0, '');
1414
            $this->pdf->SetTextColor(0, 0, 0);
1415
        } else {
1416
            $x = 10;
1417
            if ($this->orientacao == 'P') {
1418
                $y = round($this->hPrint*2/3, 0);
1419
            } else {
1420
                $y = round($this->hPrint/2, 0);
1421
            }//fim orientacao
1422
            $h = 5;
1423
            $w = $maxW-(2*$x);
1424
            $this->pdf->SetTextColor(90, 90, 90);
1425
            //indicar FALTA DO PROTOCOLO se NFe não for em contingência
1426
            if (($this->tpEmis == 2 || $this->tpEmis == 5) && !$this->pNotaDPEC()) {
1427
                //Contingência
1428
                $texto = "DANFE Emitido em Contingência";
1429
                $aFont = array('font'=>$this->fontePadrao, 'size'=>48, 'style'=>'B');
1430
                $this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'C', 'C', 0, '');
1431
                $aFont = array('font'=>$this->fontePadrao, 'size'=>30, 'style'=>'B');
1432
                $texto = "devido à problemas técnicos";
1433
                $this->pTextBox($x, $y+12, $w, $h, $texto, $aFont, 'C', 'C', 0, '');
1434
            } else {
1435
                if (!isset($this->nfeProc)) {
1436
                    if (!$this->pNotaDPEC()) {
1437
                        $texto = "SEM VALOR FISCAL";
1438
                        $aFont = array('font'=>$this->fontePadrao, 'size'=>48, 'style'=>'B');
1439
                        $this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'C', 'C', 0, '');
1440
                    }
1441
                    $aFont = array('font'=>$this->fontePadrao, 'size'=>30, 'style'=>'B');
1442
                    $texto = "FALTA PROTOCOLO DE APROVAÇÃO DA SEFAZ";
1443
                    if (!$this->pNotaDPEC()) {
1444
                        $this->pTextBox($x, $y+12, $w, $h, $texto, $aFont, 'C', 'C', 0, '');
1445
                    } else {
1446
                        $this->pTextBox($x, $y+25, $w, $h, $texto, $aFont, 'C', 'C', 0, '');
1447
                    }
1448
                }//fim nefProc
1449
            }//fim tpEmis
1450
            $this->pdf->SetTextColor(0, 0, 0);
1451
        }
1452
        return $oldY;
1453
    } //fim cabecalhoDANFE
1454
1455
    /**
1456
     * destinatarioDANFE
1457
     * Monta o campo com os dados do destinatário na DANFE. (retrato e paisagem)
1458
     *
1459
     * @name   destinatarioDANFE
1460
     * @param  number $x Posição horizontal canto esquerdo
1461
     * @param  number $y Posição vertical canto superior
1462
     * @return number Posição vertical final
1463
     */
1464
    protected function pDestinatarioDANFE($x = 0, $y = 0)
1465
    {
1466
        //####################################################################################
1467
        //DESTINATÁRIO / REMETENTE
1468
        $oldX = $x;
1469
        $oldY = $y;
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...
1470
        if ($this->orientacao == 'P') {
1471
            $maxW = $this->wPrint;
1472
        } else {
1473
            $maxW = $this->wPrint - $this->wCanhoto;
1474
        }
1475
        $w = $maxW;
1476
        $h = 7;
1477
        $texto = 'DESTINATÁRIO / REMETENTE';
1478
        $aFont = array('font'=>$this->fontePadrao, 'size'=>7, 'style'=>'B');
1479
        $this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 0, '');
1480
        //NOME / RAZÃO SOCIAL
1481
        $w = round($maxW*0.61, 0);
1482
        $w1 = $w;
1483
        $y += 3;
1484
        $texto = 'NOME / RAZÃO SOCIAL';
1485
        $aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>'');
1486
        $this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 1, '');
1487
        $texto = $this->dest->getElementsByTagName("xNome")->item(0)->nodeValue;
1488
        $aFont = array('font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B');
1489
        if ($this->orientacao == 'P') {
1490
            $this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'B', 'L', 0, '');
1491
        } else {
1492
            $this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'B', 'L', 1, '');
1493
        }
1494
        //CNPJ / CPF
1495
        $x += $w;
1496
        $w = round($maxW*0.23, 0);
1497
        $w2 = $w;
1498
        $texto = 'CNPJ / CPF';
1499
        $aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>'');
1500
        $this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 1, '');
1501
        //Pegando valor do CPF/CNPJ
1502
        if (! empty($this->dest->getElementsByTagName("CNPJ")->item(0)->nodeValue)) {
1503
            $texto = $this->pFormat(
1504
                $this->dest->getElementsByTagName("CNPJ")->item(0)->nodeValue,
1505
                "###.###.###/####-##"
1506
            );
1507
        } else {
1508
            $texto = ! empty($this->dest->getElementsByTagName("CPF")->item(0)->nodeValue) ?
1509
                    $this->pFormat(
1510
                        $this->dest->getElementsByTagName("CPF")->item(0)->nodeValue,
1511
                        "###.###.###-##"
1512
                    ) : '';
1513
        }
1514
        $aFont = array('font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B');
1515
        $this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'B', 'C', 0, '');
1516
        //DATA DA EMISSÃO
1517
        $x += $w;
1518
        $w = $maxW-($w1+$w2);
1519
        $wx = $w;
1520
        $texto = 'DATA DA EMISSÃO';
1521
        $aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>'');
1522
        $this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 1, '');
1523
        $dEmi = ! empty($this->ide->getElementsByTagName("dEmi")->item(0)->nodeValue) ?
1524
                $this->ide->getElementsByTagName("dEmi")->item(0)->nodeValue : '';
1525
        if ($dEmi == '') {
1526
            $dEmi = ! empty($this->ide->getElementsByTagName("dhEmi")->item(0)->nodeValue) ?
1527
                    $this->ide->getElementsByTagName("dhEmi")->item(0)->nodeValue : '';
1528
            $aDemi = explode('T', $dEmi);
1529
            $dEmi = $aDemi[0];
1530
        }
1531
        $texto = $this->pYmd2dmy($dEmi);
1532
        $aFont = array('font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B');
1533
        if ($this->orientacao == 'P') {
1534
            $this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'B', 'C', 0, '');
1535
        } else {
1536
            $this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'B', 'C', 1, '');
1537
        }
1538
        //ENDEREÇO
1539
        $w = round($maxW*0.47, 0);
1540
        $w1 = $w;
1541
        $y += $h;
1542
        $x = $oldX;
1543
        $texto = 'ENDEREÇO';
1544
        $aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>'');
1545
        $this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 1, '');
1546
        $texto = $this->dest->getElementsByTagName("xLgr")->item(0)->nodeValue;
1547
        $texto .= ', ' . $this->dest->getElementsByTagName("nro")->item(0)->nodeValue;
1548
        $texto .= $this->pSimpleGetValue($this->dest, "xCpl", " - ");
1549
1550
        $aFont = array('font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B');
1551
        $this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'B', 'L', 0, '', true);
1552
        //BAIRRO / DISTRITO
1553
        $x += $w;
1554
        $w = round($maxW*0.21, 0);
1555
        $w2 = $w;
1556
        $texto = 'BAIRRO / DISTRITO';
1557
        $aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>'');
1558
        $this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 1, '');
1559
        $texto = $this->dest->getElementsByTagName("xBairro")->item(0)->nodeValue;
1560
        $aFont = array('font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B');
1561
        $this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'B', 'C', 0, '');
1562
        //CEP
1563
        $x += $w;
1564
        $w = $maxW-$w1-$w2-$wx;
1565
        $w2 = $w;
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...
1566
        $texto = 'CEP';
1567
        $aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>'');
1568
        $this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 1, '');
1569
        $texto = ! empty($this->dest->getElementsByTagName("CEP")->item(0)->nodeValue) ?
1570
                $this->dest->getElementsByTagName("CEP")->item(0)->nodeValue : '';
1571
        $texto = $this->pFormat($texto, "#####-###");
1572
        $aFont = array('font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B');
1573
        $this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'B', 'C', 0, '');
1574
        //DATA DA SAÍDA
1575
        $x += $w;
1576
        $w = $wx;
1577
        $texto = 'DATA DA SAÍDA/ENTRADA';
1578
        $aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>'');
1579
        $this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 1, '');
1580
        $dSaiEnt = ! empty($this->ide->getElementsByTagName("dSaiEnt")->item(0)->nodeValue) ?
1581
                $this->ide->getElementsByTagName("dSaiEnt")->item(0)->nodeValue : '';
1582
        if ($dSaiEnt == '') {
1583
            $dSaiEnt = ! empty($this->ide->getElementsByTagName("dhSaiEnt")->item(0)->nodeValue) ?
1584
                    $this->ide->getElementsByTagName("dhSaiEnt")->item(0)->nodeValue : '';
1585
            $aDsaient = explode('T', $dSaiEnt);
1586
            $dSaiEnt = $aDsaient[0];
1587
        }
1588
        $texto = $this->pYmd2dmy($dSaiEnt);
1589
        $aFont = array('font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B');
1590
        $this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'B', 'C', 0, '');
1591
        //MUNICÍPIO
1592
        $w = $w1;
1593
        $y += $h;
1594
        $x = $oldX;
1595
        $texto = 'MUNICÍPIO';
1596
        $aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>'');
1597
        $this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 1, '');
1598
        $texto = $this->dest->getElementsByTagName("xMun")->item(0)->nodeValue;
1599
        if (strtoupper(trim($texto)) == "EXTERIOR" && $this->dest->getElementsByTagName("xPais")->length > 0) {
1600
            $texto .= " - " .  $this->dest->getElementsByTagName("xPais")->item(0)->nodeValue;
1601
        }
1602
        $aFont = array('font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B');
1603
        $this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'B', 'L', 0, '');
1604
        //UF
1605
        $x += $w;
1606
        $w = 8;
1607
        $texto = 'UF';
1608
        $aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>'');
1609
        $this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 1, '');
1610
        $texto = $this->dest->getElementsByTagName("UF")->item(0)->nodeValue;
1611
        $aFont = array('font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B');
1612
        $this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'B', 'C', 0, '');
1613
        //FONE / FAX
1614
        $x += $w;
1615
        $w = round(($maxW -$w1-$wx-8)/2, 0);
1616
        $w3 = $w;
1617
        $texto = 'FONE / FAX';
1618
        $aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>'');
1619
        $this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 1, '');
1620
        $texto = ! empty($this->dest->getElementsByTagName("fone")->item(0)->nodeValue) ?
1621
                $this->dest->getElementsByTagName("fone")->item(0)->nodeValue : '';
1622
        $aFont = array('font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B');
1623
        $this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'B', 'C', 0, '');
1624
        //INSCRIÇÃO ESTADUAL
1625
        $x += $w;
1626
        $w = $maxW -$w1-$wx-8-$w3;
1627
        $texto = 'INSCRIÇÃO ESTADUAL';
1628
        $aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>'');
1629
        $this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 1, '');
1630
        $IE = $this->dest->getElementsByTagName("IE");
1631
        $texto = ($IE && $IE->length > 0) ? $IE->item(0)->nodeValue : '';
1632
        $aFont = array('font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B');
1633
        $this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'B', 'C', 0, '');
1634
        //HORA DA SAÍDA
1635
        $x += $w;
1636
        $w = $wx;
1637
        $texto = 'HORA DA SAÍDA/ENTRADA';
1638
        $aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>'');
1639
        $this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 1, '');
1640
        $hSaiEnt = ! empty($this->ide->getElementsByTagName("hSaiEnt")->item(0)->nodeValue) ?
1641
                $this->ide->getElementsByTagName("hSaiEnt")->item(0)->nodeValue : '';
1642
        if ($hSaiEnt == '') {
1643
            $dhSaiEnt = ! empty($this->ide->getElementsByTagName("dhSaiEnt")->item(0)->nodeValue) ?
1644
                    $this->ide->getElementsByTagName("dhSaiEnt")->item(0)->nodeValue : '';
1645
            $tsDhSaiEnt = $this->pConvertTime($dhSaiEnt);
1646
            if ($tsDhSaiEnt != '') {
1647
                $hSaiEnt = date('H:i:s', $tsDhSaiEnt);
1648
            }
1649
        }
1650
        $texto = $hSaiEnt;
1651
        $aFont = array('font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B');
1652
        $this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'B', 'C', 0, '');
1653
        return ($y + $h);
1654
    } //fim da função destinatarioDANFE
1655
1656
     /**
1657
     * pGetTextoFatura
1658
     * Gera a String do Texto da Fatura
1659
      *
1660
     * @name   getTextoFatura
1661
     * @return uma String com o texto ou "";
1662
     */
1663
    protected function pGetTextoFatura()
1664
    {
1665
        if (isset($this->cobr)) {
1666
            $fat = $this->cobr->getElementsByTagName("fat")->item(0);
1667
            if (isset($fat)) {
1668
                if (!empty($this->pSimpleGetValue($this->ide, "indPag"))) {
1669
                    $textoIndPag = "";
1670
                    $indPag = $this->pSimpleGetValue($this->ide, "indPag");
1671
                    if ($indPag === "0") {
1672
                        $textoIndPag = "Pagamento à Vista - ";
1673
                    } elseif ($indPag === "1") {
1674
                        $textoIndPag = "Pagamento à Prazo - ";
1675
                    }
1676
                    $nFat = $this->pSimpleGetValue($fat, "nFat", "Fatura: ");
1677
                    $vOrig = $this->pSimpleGetValue($fat, "vOrig", " Valor Original: ");
1678
                    $vDesc = $this->pSimpleGetValue($fat, "vDesc", " Desconto: ");
1679
                    $vLiq = $this->pSimpleGetValue($fat, "vLiq", " Valor Líquido: ");
1680
                    $texto = $textoIndPag . $nFat . $vOrig . $vDesc . $vLiq;
1681
                    return $texto;
1682
                } else {
1683
                    $pag = $this->dom->getElementsByTagName("pag");
1684
                    if ($tPag = $this->pSimpleGetValue($pag->item(0), "tPag")) {
1685
                        return $this->tipoPag($tPag);
1686
                    }
1687
                }
1688
            }
1689
        }
1690
        return "";
1691
    } //fim getTextoFatura
1692
1693
     /**
1694
     * pSizeExtraTextoFatura
1695
     * Calcula o espaço ocupado pelo texto da fatura. Este espaço só é utilizado quando não houver duplicata.
1696
      *
1697
     * @name   pSizeExtraTextoFatura
1698
     * @return integer
1699
     */
1700
    protected function pSizeExtraTextoFatura()
1701
    {
1702
        $textoFatura = $this->pGetTextoFatura();
1703
        //verificar se existem duplicatas
1704
        if ($this->dup->length == 0 && $textoFatura !== "") {
1705
            return 10;
1706
        }
1707
        return 0;
1708
    }
1709
1710
    /**
1711
     * faturaDANFE
1712
     * Monta o campo de duplicatas da DANFE (retrato e paisagem)
1713
     *
1714
     * @name   faturaDANFE
1715
     * @param  number $x Posição horizontal canto esquerdo
1716
     * @param  number $y Posição vertical canto superior
1717
     * @return number Posição vertical final
1718
     */
1719
    protected function pFaturaDANFE($x, $y)
1720
    {
1721
        $linha = 1;
1722
        $h = 8+3;
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...
1723
        $oldx = $x;
1724
        $textoFatura = $this->pGetTextoFatura();
1725
        //verificar se existem duplicatas
1726
        if ($this->dup->length > 0 || $textoFatura !== "") {
1727
            //#####################################################################
1728
            //FATURA / DUPLICATA
1729
            $texto = "FATURA / DUPLICATA";
1730
            if ($this->orientacao == 'P') {
1731
                $w = $this->wPrint;
1732
            } else {
1733
                $w = 271;
1734
            }
1735
            $h = 8;
1736
            $aFont = array('font'=>$this->fontePadrao, 'size'=>7, 'style'=>'B');
1737
            $this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 0, '');
1738
            $y += 3;
1739
            $dups = "";
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...
1740
            $dupcont = 0;
1741
            $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...
1742
            if ($textoFatura !== "" && $this->exibirTextoFatura) {
1743
                $myH=6;
1744
                $myW = $this->wPrint;
1745
                if ($this->orientacao == 'L') {
1746
                    $myW -= $this->wCanhoto;
1747
                }
1748
                $aFont = array('font'=>$this->fontePadrao, 'size'=>8, 'style'=>'');
1749
                $this->pTextBox($x, $y, $myW, $myH, $textoFatura, $aFont, 'C', 'L', 1, '');
1750
                $y+=$myH+1;
1751
            }
1752
            if ($this->orientacao == 'P') {
1753
                $w = round($this->wPrint/7.018, 0)-1;
1754
            } else {
1755
                $w = 28;
1756
            }
1757
            $increm = 1;
1758
            foreach ($this->dup as $k => $d) {
1759
                $nDup = ! empty($this->dup->item($k)->getElementsByTagName('nDup')->item(0)->nodeValue) ?
1760
                        $this->dup->item($k)->getElementsByTagName('nDup')->item(0)->nodeValue : '';
1761
                $dDup = ! empty($this->dup->item($k)->getElementsByTagName('dVenc')->item(0)->nodeValue) ?
1762
                        $this->pYmd2dmy($this->dup->item($k)->getElementsByTagName('dVenc')->item(0)->nodeValue) : '';
1763
                $vDup = ! empty($this->dup->item($k)->getElementsByTagName('vDup')->item(0)->nodeValue) ?
1764
                        'R$ ' . number_format(
1765
                            $this->dup->item($k)->getElementsByTagName('vDup')->item(0)->nodeValue,
1766
                            2,
1767
                            ",",
1768
                            "."
1769
                        ) : '';
1770
                $h = 8;
1771
                $texto = '';
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...
1772
                if ($nDup!='0' && $nDup!='') {
1773
                    $aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>'');
1774
                    $this->pTextBox($x, $y, $w, $h, 'Num.', $aFont, 'T', 'L', 1, '');
1775
                    $aFont = array('font'=>$this->fontePadrao, 'size'=>7, 'style'=>'B');
1776
                    $this->pTextBox($x, $y, $w, $h, $nDup, $aFont, 'T', 'R', 0, '');
1777
                } else {
1778
                    $aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>'');
1779
                    $this->pTextBox($x, $y, $w, $h, ($dupcont+1)."", $aFont, 'T', 'L', 1, '');
1780
                }
1781
                $aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>'');
1782
                $this->pTextBox($x, $y, $w, $h, 'Venc.', $aFont, 'C', 'L', 0, '');
1783
                $aFont = array('font'=>$this->fontePadrao, 'size'=>7, 'style'=>'B');
1784
                $this->pTextBox($x, $y, $w, $h, $dDup, $aFont, 'C', 'R', 0, '');
1785
                $aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>'');
1786
                $this->pTextBox($x, $y, $w, $h, 'Valor', $aFont, 'B', 'L', 0, '');
1787
                $aFont = array('font'=>$this->fontePadrao, 'size'=>7, 'style'=>'B');
1788
                $this->pTextBox($x, $y, $w, $h, $vDup, $aFont, 'B', 'R', 0, '');
1789
                $x += $w+$increm;
1790
                $dupcont += 1;
1791
                if ($this->orientacao == 'P') {
1792
                    $maxDupCont = 6;
1793
                } else {
1794
                    $maxDupCont = 8;
1795
                }
1796
                if ($dupcont > $maxDupCont) {
1797
                    $y += 9;
1798
                    $x = $oldx;
1799
                    $dupcont = 0;
1800
                    $linha += 1;
1801
                }
1802
                if ($linha == 5) {
1803
                    $linha = 4;
1804
                    break;
1805
                }
1806
            }
1807
            if ($dupcont == 0) {
1808
                $y -= 9;
1809
                $linha--;
1810
            }
1811
            return ($y+$h);
1812
        } else {
1813
            $linha = 0;
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...
1814
            return ($y-2);
1815
        }
1816
    } //fim da função faturaDANFE
1817
1818
    /**
1819
     * pagamentoDANFE
1820
     * Monta o campo de pagamentos da DANFE (retrato e paisagem) (foi baseada na faturaDANFE)
1821
     *
1822
     * @name   pagamentoDANFE
1823
     * @param  number $x Posição horizontal canto esquerdo
1824
     * @param  number $y Posição vertical canto superior
1825
     * @return number Posição vertical final
1826
     */
1827
    protected function pagamentoDANFE($x, $y)
1828
    {
1829
        $linha = 1;
1830
        $h = 8+3;
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...
1831
        $oldx = $x;
1832
        //verificar se existem cobranças definidas
1833
        if (isset($this->detPag) && $this->detPag->length > 0) {
1834
            //#####################################################################
1835
            //Tipo de pagamento
1836
            $texto = "PAGAMENTO";
1837
            if ($this->orientacao == 'P') {
1838
                $w = $this->wPrint;
1839
            } else {
1840
                $w = 271;
1841
            }
1842
            $h = 8;
1843
            $aFont = array('font'=>$this->fontePadrao, 'size'=>7, 'style'=>'B');
1844
            $this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 0, '');
1845
            $y += 3;
1846
            $dups = "";
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...
1847
            $dupcont = 0;
1848
            if ($this->orientacao == 'P') {
1849
                $w = round($this->wPrint/7.018, 0)-1;
1850
            } else {
1851
                $w = 28;
1852
            }
1853
            if ($this->orientacao == 'P') {
1854
                $maxDupCont = 6;
1855
            } else {
1856
                $maxDupCont = 8;
1857
            }
1858
            $increm = 1;
1859
            $formaPagamento = array('01'=>'Dinheiro','02'=>'Cheque','03'=>'Cartão de Crédito',
1860
                                    '04'=>'Cartão de Débito','05'=>'Crédito Loja','10'=>'Vale Alimentação',
1861
                                    '11'=>'Vale Refeição','12'=>'Vale Presente','13'=>'Vale Combustível',
1862
                                    '14'=>'Duplicata Mercantil','15'=>'Boleto','90'=>'Sem pagamento','99'=>'Outros');
1863
            $bandeira = array('01'=>'Visa','02'=>'Mastercard','03'=>'American','04'=>'Sorocred','05'=>'Diners',
0 ignored issues
show
Unused Code introduced by
$bandeira is not used, you could remove the assignment.

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

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

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

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

Loading history...
1864
                              '06'=>'Elo','07'=>'Hipercard','08'=>'Aura','09'=>'Cabal','99'=>'Outros');
1865
            foreach ($this->detPag as $k => $d) {
1866
                $fPag = !empty($this->detPag->item($k)->getElementsByTagName('tPag')->item(0)->nodeValue)
1867
                    ? $this->detPag->item($k)->getElementsByTagName('tPag')->item(0)->nodeValue : '0';
1868
                $vPag = ! empty($this->detPag->item($k)->getElementsByTagName('vPag')->item(0)->nodeValue)
1869
                    ? 'R$ ' . number_format(
1870
                        $this->detPag->item($k)->getElementsByTagName('vPag')->item(0)->nodeValue,
1871
                        2,
1872
                        ",",
1873
                        "."
1874
                    ) : '';
1875
                $h = 6;
1876
                $texto = '';
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...
1877
                if (isset($formaPagamento[$fPag])) {
1878
                    /*Exibir Item sem pagamento ou outros?*/
1879
                    if ($fPag=='90' || $fPag=='99') {
1880
                        continue;
1881
                    }
1882
                    $aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>'');
1883
                    $this->pTextBox($x, $y, $w, $h, 'Forma', $aFont, 'T', 'L', 1, '');
1884
                    $aFont = array('font'=>$this->fontePadrao, 'size'=>7, 'style'=>'B');
1885
                    $this->pTextBox($x, $y, $w, $h, $formaPagamento[$fPag], $aFont, 'T', 'R', 0, '');
1886
                } else {
1887
                    $aFont = array('font'=>$this->fontePadrao, 'size'=>7, 'style'=>'');
1888
                    $this->pTextBox($x, $y, $w, $h, "Forma ".$fPag." não encontrado", $aFont, 'T', 'L', 1, '');
1889
                }
1890
                $aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>'');
1891
                $this->pTextBox($x, $y, $w, $h, 'Valor', $aFont, 'B', 'L', 0, '');
1892
                $aFont = array('font'=>$this->fontePadrao, 'size'=>7, 'style'=>'B');
1893
                $this->pTextBox($x, $y, $w, $h, $vPag, $aFont, 'B', 'R', 0, '');
1894
                $x += $w+$increm;
1895
                $dupcont += 1;
1896
1897
                if ($dupcont>$maxDupCont) {
1898
                    $y += 9;
1899
                    $x = $oldx;
1900
                    $dupcont = 0;
1901
                    $linha += 1;
1902
                }
1903
                if ($linha == 5) {
1904
                    $linha = 4;
1905
                    break;
1906
                }
1907
            }
1908
            if ($dupcont == 0) {
1909
                $y -= 9;
1910
                $linha--;
1911
            }
1912
            return ($y+$h);
1913
        } else {
1914
            $linha = 0;
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...
1915
            return ($y-2);
1916
        }
1917
    } //fim da função pagamentoDANFE
1918
    
1919
    /**
1920
     * impostoDanfeHelper
1921
     * Auxilia a montagem dos campos de impostos e totais da DANFE
1922
     *
1923
     * @name   impostoDanfeHelper
1924
     * @param  float $x Posição horizontal canto esquerdo
1925
     * @param  float $y Posição vertical canto superior
1926
     * @param  float $w Largura do campo
1927
     * @param  float $h Altura do campo
1928
     * @param  float $h Título do campo
1929
     * @param  float $h Valor do imposto
1930
     * @return float Sugestão do $x do próximo imposto
1931
     */
1932
    protected function pImpostoDanfeHelper($x, $y, $w, $h, $titulo, $campoImposto)
1933
    {
1934
        $valorImposto = '0, 00';
1935
        $the_field = $this->ICMSTot->getElementsByTagName($campoImposto)->item(0);
1936
        if (isset($the_field)) {
1937
            $the_value = $the_field->nodeValue;
1938
            if (!empty($the_value)) {
1939
                $valorImposto = number_format($the_value, 2, ",", ".");
1940
            }
1941
        }
1942
1943
        $fontTitulo = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>'');
1944
        $fontValor = array('font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B');
1945
        $this->pTextBox($x, $y, $w, $h, $titulo, $fontTitulo, 'T', 'L', 1, '');
1946
        $this->pTextBox($x, $y, $w, $h, $valorImposto, $fontValor, 'B', 'R', 0, '');
1947
1948
        $next_x = $x + $w;
1949
        return $next_x;
1950
    }
1951
1952
    /**
1953
     * impostoDANFE
1954
     * Monta o campo de impostos e totais da DANFE (retrato e paisagem)
1955
     *
1956
     * @param  number $x Posição horizontal canto esquerdo
1957
     * @param  number $y Posição vertical canto superior
1958
     * @return number Posição vertical final
1959
     */
1960
    protected function pImpostoDANFE($x, $y)
1961
    {
1962
        $x_inicial = $x;
1963
        //#####################################################################
1964
1965
1966
        $campos_por_linha = 9;
1967
        if (!$this->exibirPIS) {
1968
            $campos_por_linha--;
1969
        }
1970
        if (!$this->exibirIcmsInterestadual) {
1971
            $campos_por_linha -= 2;
1972
        }
1973
1974
        if ($this->orientacao == 'P') {
1975
            $maxW = $this->wPrint;
1976
            $title_size = 31;
1977
        } else {
1978
            $maxW = $this->wPrint - $this->wCanhoto;
1979
            $title_size = 40;
1980
        }
1981
        $w = $maxW / $campos_por_linha;
1982
1983
        $aFont = array('font'=>$this->fontePadrao, 'size'=>7, 'style'=>'B');
1984
        $texto = "CÁLCULO DO IMPOSTO";
1985
        $this->pTextBox($x, $y, $title_size, 8, $texto, $aFont, 'T', 'L', 0, '');
1986
        $y += 3;
1987
        $h = 7;
1988
1989
        $x = $this->pImpostoDanfeHelper($x, $y, $w, $h, "BASE DE CÁLC. DO ICMS", "vBC");
1990
        $x = $this->pImpostoDanfeHelper($x, $y, $w, $h, "VALOR DO ICMS", "vICMS");
1991
        $x = $this->pImpostoDanfeHelper($x, $y, $w, $h, "BASE DE CÁLC. ICMS S.T.", "vBCST");
1992
        $x = $this->pImpostoDanfeHelper($x, $y, $w, $h, "VALOR DO ICMS SUBST.", "vST");
1993
        $x = $this->pImpostoDanfeHelper($x, $y, $w, $h, "V. IMP. IMPORTAÇÃO", "vII");
1994
1995
        if ($this->exibirIcmsInterestadual) {
1996
            $x = $this->pImpostoDanfeHelper($x, $y, $w, $h, "V. ICMS UF REMET.", "vICMSUFRemet");
1997
            $x = $this->pImpostoDanfeHelper($x, $y, $w, $h, "V. FCP UF DEST.", "vFCPUFDest");
1998
        }
1999
2000
        if ($this->exibirPIS) {
2001
            $x = $this->pImpostoDanfeHelper($x, $y, $w, $h, "VALOR DO PIS", "vPIS");
2002
        }
2003
2004
        $x = $this->pImpostoDanfeHelper($x, $y, $w, $h, "V. TOTAL PRODUTOS", "vProd");
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...
2005
2006
        //
2007
2008
        $y += $h;
2009
        $x = $x_inicial;
2010
2011
        $x = $this->pImpostoDanfeHelper($x, $y, $w, $h, "VALOR DO FRETE", "vFrete");
2012
        $x = $this->pImpostoDanfeHelper($x, $y, $w, $h, "VALOR DO SEGURO", "vSeg");
2013
        $x = $this->pImpostoDanfeHelper($x, $y, $w, $h, "DESCONTO", "vDesc");
2014
        $x = $this->pImpostoDanfeHelper($x, $y, $w, $h, "OUTRAS DESPESAS", "vOutro");
2015
        $x = $this->pImpostoDanfeHelper($x, $y, $w, $h, "VALOR TOTAL IPI", "vIPI");
2016
2017
        if ($this->exibirIcmsInterestadual) {
2018
            $x = $this->pImpostoDanfeHelper($x, $y, $w, $h, "V. ICMS UF DEST.", "vICMSUFDest");
2019
            $x = $this->pImpostoDanfeHelper($x, $y, $w, $h, "V. TOT. TRIB.", "vTotTrib");
2020
        }
2021
2022
        if ($this->exibirPIS) {
2023
            $x = $this->pImpostoDanfeHelper($x, $y, $w, $h, "VALOR DA COFINS", "vCOFINS");
2024
        }
2025
        $x = $this->pImpostoDanfeHelper($x, $y, $w, $h, "V. TOTAL DA NOTA", "vNF");
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...
2026
2027
        return ($y+$h);
2028
    } //fim impostoDANFE
2029
2030
    /**
2031
     * transporteDANFE
2032
     * Monta o campo de transportes da DANFE (retrato e paisagem)
2033
     *
2034
     * @name   transporteDANFE
2035
     * @param  float $x Posição horizontal canto esquerdo
2036
     * @param  float $y Posição vertical canto superior
2037
     * @return float Posição vertical final
2038
     */
2039
    protected function pTransporteDANFE($x, $y)
2040
    {
2041
        $oldX = $x;
2042
        if ($this->orientacao == 'P') {
2043
            $maxW = $this->wPrint;
2044
        } else {
2045
            $maxW = $this->wPrint - $this->wCanhoto;
2046
        }
2047
        //#####################################################################
2048
        //TRANSPORTADOR / VOLUMES TRANSPORTADOS
2049
        $texto = "TRANSPORTADOR / VOLUMES TRANSPORTADOS";
2050
        $w = $maxW;
2051
        $h = 7;
2052
        $aFont = array('font'=>$this->fontePadrao, 'size'=>7, 'style'=>'B');
2053
        $this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 0, '');
2054
        //NOME / RAZÃO SOCIAL
2055
        $w1 = $maxW*0.29;
2056
        $y += 3;
2057
        $texto = 'NOME / RAZÃO SOCIAL';
2058
        $aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>'');
2059
        $this->pTextBox($x, $y, $w1, $h, $texto, $aFont, 'T', 'L', 1, '');
2060
        if (isset($this->transporta)) {
2061
            $texto = ! empty($this->transporta->getElementsByTagName("xNome")->item(0)->nodeValue) ?
2062
                    $this->transporta->getElementsByTagName("xNome")->item(0)->nodeValue : '';
2063
        } else {
2064
            $texto = '';
2065
        }
2066
        $aFont = array('font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B');
2067
        $this->pTextBox($x, $y, $w1, $h, $texto, $aFont, 'B', 'L', 0, '');
2068
        //FRETE POR CONTA
2069
        $x += $w1;
2070
        $w2 = $maxW*0.15;
2071
        $texto = 'FRETE';
2072
        $aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>'');
2073
        $this->pTextBox($x, $y, $w2, $h, $texto, $aFont, 'T', 'L', 1, '');
2074
        $tipoFrete = ! empty($this->transp->getElementsByTagName("modFrete")->item(0)->nodeValue) ?
2075
                $this->transp->getElementsByTagName("modFrete")->item(0)->nodeValue : '0';
2076
        switch ($tipoFrete) {
2077
            case 0:
2078
                $texto = "0-Por conta do Rem";
2079
                break;
2080
            case 1:
2081
                $texto = "1-Por conta do Dest";
2082
                break;
2083
            case 2:
2084
                $texto = "2-Por conta de Terceiros";
2085
                break;
2086
            case 3:
2087
                $texto = "3-Próprio por conta do Rem";
2088
                break;
2089
            case 4:
2090
                $texto = "4-Próprio por conta do Dest";
2091
                break;
2092
            case 9:
2093
                $texto = "9-Sem Transporte";
2094
                break;
2095
        }
2096
        $aFont = array('font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B');
2097
        $this->pTextBox($x, $y, $w2, $h, $texto, $aFont, 'C', 'C', 1, '');
2098
        //CÓDIGO ANTT
2099
        $x += $w2;
2100
        $texto = 'CÓDIGO ANTT';
2101
        $aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>'');
2102
        $this->pTextBox($x, $y, $w2, $h, $texto, $aFont, 'T', 'L', 1, '');
2103
        if (isset($this->veicTransp)) {
2104
            $texto = ! empty($this->veicTransp->getElementsByTagName("RNTC")->item(0)->nodeValue) ?
2105
                    $this->veicTransp->getElementsByTagName("RNTC")->item(0)->nodeValue : '';
2106
        } else {
2107
            $texto = '';
2108
        }
2109
        $aFont = array('font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B');
2110
        $this->pTextBox($x, $y, $w2, $h, $texto, $aFont, 'B', 'C', 0, '');
2111
        //PLACA DO VEÍC
2112
        $x += $w2;
2113
        $texto = 'PLACA DO VEÍCULO';
2114
        $aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>'');
2115
        $this->pTextBox($x, $y, $w2, $h, $texto, $aFont, 'T', 'L', 1, '');
2116
        if (isset($this->veicTransp)) {
2117
            $texto = ! empty($this->veicTransp->getElementsByTagName("placa")->item(0)->nodeValue) ?
2118
                    $this->veicTransp->getElementsByTagName("placa")->item(0)->nodeValue : '';
2119
        } elseif (isset($this->reboque)) {
2120
            $texto = ! empty($this->reboque->getElementsByTagName("placa")->item(0)->nodeValue) ?
2121
                    $this->reboque->getElementsByTagName("placa")->item(0)->nodeValue : '';
2122
        } else {
2123
            $texto = '';
2124
        }
2125
        $aFont = array('font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B');
2126
        $this->pTextBox($x, $y, $w2, $h, $texto, $aFont, 'B', 'C', 0, '');
2127
        //UF
2128
        $x += $w2;
2129
        $w3 = round($maxW*0.04, 0);
2130
        $texto = 'UF';
2131
        $aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>'');
2132
        $this->pTextBox($x, $y, $w3, $h, $texto, $aFont, 'T', 'L', 1, '');
2133
        if (isset($this->veicTransp)) {
2134
            $texto = ! empty($this->veicTransp->getElementsByTagName("UF")->item(0)->nodeValue) ?
2135
                    $this->veicTransp->getElementsByTagName("UF")->item(0)->nodeValue : '';
2136
        } elseif (isset($this->reboque)) {
2137
            $texto = ! empty($this->reboque->getElementsByTagName("UF")->item(0)->nodeValue) ?
2138
                    $this->reboque->getElementsByTagName("UF")->item(0)->nodeValue : '';
2139
        } else {
2140
            $texto = '';
2141
        }
2142
        $aFont = array('font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B');
2143
        $this->pTextBox($x, $y, $w3, $h, $texto, $aFont, 'B', 'C', 0, '');
2144
        //CNPJ / CPF
2145
        $x += $w3;
2146
        $w = $maxW-($w1+3*$w2+$w3);
2147
        $texto = 'CNPJ / CPF';
2148
        $aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>'');
2149
        $this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 1, '');
2150
        if (isset($this->transporta)) {
2151
            $texto = ! empty($this->transporta->getElementsByTagName("CNPJ")->item(0)->nodeValue) ?
2152
                    $this->pFormat(
2153
                        $this->transporta->getElementsByTagName("CNPJ")->item(0)->nodeValue,
2154
                        "##.###.###/####-##"
2155
                    ) : '';
2156
            if ($texto == '') {
2157
                $texto = ! empty($this->transporta->getElementsByTagName("CPF")->item(0)->nodeValue) ?
2158
                        $this->pFormat(
2159
                            $this->transporta->getElementsByTagName("CPF")->item(0)->nodeValue,
2160
                            "###.###.###-##"
2161
                        ) : '';
2162
            }
2163
        } else {
2164
            $texto = '';
2165
        }
2166
        $aFont = array('font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B');
2167
        $this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'B', 'C', 0, '');
2168
        //#####################################################################
2169
        //ENDEREÇO
2170
        $y += $h;
2171
        $x = $oldX;
2172
        $h = 7;
2173
        $w1 = $maxW*0.44;
2174
        $texto = 'ENDEREÇO';
2175
        $aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>'');
2176
        $this->pTextBox($x, $y, $w1, $h, $texto, $aFont, 'T', 'L', 1, '');
2177
        if (isset($this->transporta)) {
2178
            $texto = ! empty($this->transporta->getElementsByTagName("xEnder")->item(0)->nodeValue) ?
2179
                    $this->transporta->getElementsByTagName("xEnder")->item(0)->nodeValue : '';
2180
        } else {
2181
            $texto = '';
2182
        }
2183
        $aFont = array('font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B');
2184
        $this->pTextBox($x, $y, $w1, $h, $texto, $aFont, 'B', 'L', 0, '');
2185
        //MUNICÍPIO
2186
        $x += $w1;
2187
        $w2 = round($maxW*0.30, 0);
2188
        $texto = 'MUNICÍPIO';
2189
        $aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>'');
2190
        $this->pTextBox($x, $y, $w2, $h, $texto, $aFont, 'T', 'L', 1, '');
2191
        if (isset($this->transporta)) {
2192
            $texto = ! empty($this->transporta->getElementsByTagName("xMun")->item(0)->nodeValue) ?
2193
                    $this->transporta->getElementsByTagName("xMun")->item(0)->nodeValue : '';
2194
        } else {
2195
            $texto = '';
2196
        }
2197
        $aFont = array('font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B');
2198
        $this->pTextBox($x, $y, $w2, $h, $texto, $aFont, 'B', 'C', 0, '');
2199
        //UF
2200
        $x += $w2;
2201
        $w3 = round($maxW*0.04, 0);
2202
        $texto = 'UF';
2203
        $aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>'');
2204
        $this->pTextBox($x, $y, $w3, $h, $texto, $aFont, 'T', 'L', 1, '');
2205
        if (isset($this->transporta)) {
2206
            $texto = ! empty($this->transporta->getElementsByTagName("UF")->item(0)->nodeValue) ?
2207
                    $this->transporta->getElementsByTagName("UF")->item(0)->nodeValue : '';
2208
        } else {
2209
            $texto = '';
2210
        }
2211
        $aFont = array('font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B');
2212
        $this->pTextBox($x, $y, $w3, $h, $texto, $aFont, 'B', 'C', 0, '');
2213
        //INSCRIÇÃO ESTADUAL
2214
        $x += $w3;
2215
        $w = $maxW-($w1+$w2+$w3);
2216
        $texto = 'INSCRIÇÃO ESTADUAL';
2217
        $aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>'');
2218
        $this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 1, '');
2219
        $texto = '';
2220
        if (isset($this->transporta)) {
2221
            if (! empty($this->transporta->getElementsByTagName("IE")->item(0)->nodeValue)) {
2222
                $texto = $this->transporta->getElementsByTagName("IE")->item(0)->nodeValue;
2223
            }
2224
        }
2225
        $aFont = array('font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B');
2226
        $this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'B', 'C', 0, '');
2227
        //Tratar Multiplos volumes
2228
        $volumes = $this->transp->getElementsByTagName('vol');
2229
        $quantidade = 0;
2230
        $especie = '';
2231
        $marca = '';
2232
        $numero = '';
2233
        $texto = '';
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...
2234
        $pesoBruto=0;
2235
        $pesoLiquido=0;
2236
        foreach ($volumes as $volume) {
2237
            $quantidade += ! empty($volume->getElementsByTagName("qVol")->item(0)->nodeValue) ?
2238
                    $volume->getElementsByTagName("qVol")->item(0)->nodeValue : 0;
2239
            $pesoBruto += ! empty($volume->getElementsByTagName("pesoB")->item(0)->nodeValue) ?
2240
                    $volume->getElementsByTagName("pesoB")->item(0)->nodeValue : 0;
2241
            $pesoLiquido += ! empty($volume->getElementsByTagName("pesoL")->item(0)->nodeValue) ?
2242
                    $volume->getElementsByTagName("pesoL")->item(0)->nodeValue : 0;
2243
            $texto = ! empty($this->transp->getElementsByTagName("esp")->item(0)->nodeValue) ?
2244
                    $this->transp->getElementsByTagName("esp")->item(0)->nodeValue : '';
2245
            if ($texto != $especie && $especie != '') {
2246
                //tem várias especies
2247
                $especie = 'VARIAS';
2248
            } else {
2249
                $especie = $texto;
2250
            }
2251
            $texto = ! empty($this->transp->getElementsByTagName("marca")->item(0)->nodeValue) ?
2252
                    $this->transp->getElementsByTagName("marca")->item(0)->nodeValue : '';
2253
            if ($texto != $marca && $marca != '') {
2254
                //tem várias especies
2255
                $marca = 'VARIAS';
2256
            } else {
2257
                $marca = $texto;
2258
            }
2259
            $texto = ! empty($this->transp->getElementsByTagName("nVol")->item(0)->nodeValue) ?
2260
                    $this->transp->getElementsByTagName("nVol")->item(0)->nodeValue : '';
2261
            if ($texto != $numero && $numero != '') {
2262
                //tem várias especies
2263
                $numero = 'VARIOS';
2264
            } else {
2265
                $numero = $texto;
2266
            }
2267
        }
2268
2269
        //#####################################################################
2270
        //QUANTIDADE
2271
        $y += $h;
2272
        $x = $oldX;
2273
        $h = 7;
2274
        $w1 = round($maxW*0.10, 0);
2275
        $texto = 'QUANTIDADE';
2276
        $aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>'');
2277
        $this->pTextBox($x, $y, $w1, $h, $texto, $aFont, 'T', 'L', 1, '');
2278
        if (!empty($quantidade)) {
2279
            $texto = $quantidade;
2280
            $aFont = array('font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B');
2281
            $this->pTextBox($x, $y, $w1, $h, $texto, $aFont, 'B', 'C', 0, '');
2282
        }
2283
        //ESPÉCIE
2284
        $x += $w1;
2285
        $w2 = round($maxW*0.17, 0);
2286
        $texto = 'ESPÉCIE';
2287
        $aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>'');
2288
        $this->pTextBox($x, $y, $w2, $h, $texto, $aFont, 'T', 'L', 1, '');
2289
        $texto = $especie;
2290
        $aFont = array('font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B');
2291
        $this->pTextBox($x, $y, $w2, $h, $texto, $aFont, 'B', 'C', 0, '');
2292
        //MARCA
2293
        $x += $w2;
2294
        $texto = 'MARCA';
2295
        $aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>'');
2296
        $this->pTextBox($x, $y, $w2, $h, $texto, $aFont, 'T', 'L', 1, '');
2297
        $texto = ! empty($this->transp->getElementsByTagName("marca")->item(0)->nodeValue) ?
2298
                $this->transp->getElementsByTagName("marca")->item(0)->nodeValue : '';
2299
        $aFont = array('font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B');
2300
        $this->pTextBox($x, $y, $w2, $h, $texto, $aFont, 'B', 'C', 0, '');
2301
        //NUMERAÇÃO
2302
        $x += $w2;
2303
        $texto = 'NUMERAÇÃO';
2304
        $aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>'');
2305
        $this->pTextBox($x, $y, $w2, $h, $texto, $aFont, 'T', 'L', 1, '');
2306
        $texto = $numero;
2307
        $aFont = array('font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B');
2308
        $this->pTextBox($x, $y, $w2, $h, $texto, $aFont, 'B', 'C', 0, '');
2309
        //PESO BRUTO
2310
        $x += $w2;
2311
        $w3 = round($maxW*0.20, 0);
2312
        $texto = 'PESO BRUTO';
2313
        $aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>'');
2314
        $this->pTextBox($x, $y, $w3, $h, $texto, $aFont, 'T', 'L', 1, '');
2315
        if (is_numeric($pesoBruto) && $pesoBruto > 0) {
2316
            $texto = number_format($pesoBruto, 3, ",", ".");
2317
        } else {
2318
            $texto = '';
2319
        }
2320
        $aFont = array('font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B');
2321
        $this->pTextBox($x, $y, $w3, $h, $texto, $aFont, 'B', 'R', 0, '');
2322
        //PESO LÍQUIDO
2323
        $x += $w3;
2324
        $w = $maxW -($w1+3*$w2+$w3);
2325
        $texto = 'PESO LÍQUIDO';
2326
        $aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>'');
2327
        $this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 1, '');
2328
        if (is_numeric($pesoLiquido) && $pesoLiquido > 0) {
2329
            $texto = number_format($pesoLiquido, 3, ",", ".");
2330
        } else {
2331
            $texto = '';
2332
        }
2333
        $aFont = array('font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B');
2334
        $this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'B', 'R', 0, '');
2335
        return ($y+$h);
2336
    } //fim transporteDANFE
2337
2338
2339
2340
    protected function pDescricaoProdutoHelper($origem, $campo, $formato)
2341
    {
2342
        $valor_original = $origem->getElementsByTagName($campo)->item(0);
2343
        if (!isset($valor_original)) {
2344
            return "";
2345
        }
2346
        $valor_original = $valor_original->nodeValue;
2347
        $valor = ! empty($valor_original) ? number_format($valor_original, 2, ",", ".") : '';
2348
2349
        if ($valor != "") {
2350
            return sprintf($formato, $valor);
2351
        }
2352
        return "";
2353
    }
2354
2355
    /**
2356
     * descricaoProduto
2357
     * Monta a string de descrição de cada Produto
2358
     *
2359
     * @name   descricaoProduto
2360
     * @param  DOMNode itemProd
2361
     * @return string descricao do produto
2362
     */
2363
    protected function pDescricaoProduto($itemProd)
2364
    {
2365
        $prod = $itemProd->getElementsByTagName('prod')->item(0);
2366
        $ICMS = $itemProd->getElementsByTagName("ICMS")->item(0);
2367
        $ICMSUFDest = $itemProd->getElementsByTagName("ICMSUFDest")->item(0);
2368
        $impostos = '';
2369
2370
        if (!empty($ICMS)) {
2371
            $impostos .= $this->pDescricaoProdutoHelper($ICMS, "vBCFCP", " BcFcp=%s");
2372
            $impostos .= $this->pDescricaoProdutoHelper($ICMS, "pFCP", " pFcp=%s%%");
2373
            $impostos .= $this->pDescricaoProdutoHelper($ICMS, "vFCP", " vFcp=%s");
2374
            $impostos .= $this->pDescricaoProdutoHelper($ICMS, "pRedBC", " pRedBC=%s%%");
2375
            $impostos .= $this->pDescricaoProdutoHelper($ICMS, "pMVAST", " IVA/MVA=%s%%");
2376
            $impostos .= $this->pDescricaoProdutoHelper($ICMS, "pICMSST", " pIcmsSt=%s%%");
2377
            $impostos .= $this->pDescricaoProdutoHelper($ICMS, "vBCST", " BcIcmsSt=%s");
2378
            $impostos .= $this->pDescricaoProdutoHelper($ICMS, "vICMSST", " vIcmsSt=%s");
2379
            $impostos .= $this->pDescricaoProdutoHelper($ICMS, "vBCFCPST", " BcFcpSt=%s");
2380
            $impostos .= $this->pDescricaoProdutoHelper($ICMS, "pFCPST", " pFcpSt=%s%%");
2381
            $impostos .= $this->pDescricaoProdutoHelper($ICMS, "vFCPST", " vFcpSt=%s");
2382
        }
2383
        if (!empty($ICMSUFDest)) {
2384
            $impostos .= $this->pDescricaoProdutoHelper($ICMSUFDest, "pFCPUFDest", " pFCPUFDest=%s%%");
2385
            $impostos .= $this->pDescricaoProdutoHelper($ICMSUFDest, "pICMSUFDest", " pICMSUFDest=%s%%");
2386
            $impostos .= $this->pDescricaoProdutoHelper($ICMSUFDest, "pICMSInterPart", " pICMSInterPart=%s%%");
2387
            $impostos .= $this->pDescricaoProdutoHelper($ICMSUFDest, "vFCPUFDest", " vFCPUFDest=%s");
2388
            $impostos .= $this->pDescricaoProdutoHelper($ICMSUFDest, "vICMSUFDest", " vICMSUFDest=%s");
2389
            $impostos .= $this->pDescricaoProdutoHelper($ICMSUFDest, "vICMSUFRemet", " vICMSUFRemet=%s");
2390
        }
2391
        $infAdProd = ! empty($itemProd->getElementsByTagName('infAdProd')->item(0)->nodeValue) ?
2392
                substr($this->pAnfavea($itemProd->getElementsByTagName('infAdProd')->item(0)->nodeValue), 0, 500) : '';
2393
        if (! empty($infAdProd)) {
2394
            $infAdProd = trim($infAdProd);
2395
            $infAdProd .= ' ';
2396
        }
2397
        $loteTxt ='';
2398
        $rastro = $prod->getElementsByTagName("med");
2399
        if (!isset($rastro)) {
2400
            $rastro = $prod->getElementsByTagName("rastro");
2401
        }
2402
        if (isset($rastro)) {
2403
            $i = 0;
2404
            while ($i < $rastro->length) {
2405
                $loteTxt .= $this->pSimpleGetValue($rastro->item($i), 'nLote', ' Lote: ');
2406
                $loteTxt .= $this->pSimpleGetValue($rastro->item($i), 'qLote', ' Quant: ');
2407
                $loteTxt .= $this->pSimpleGetDate($rastro->item($i), 'dFab', ' Fab: ');
2408
                $loteTxt .= $this->pSimpleGetDate($rastro->item($i), 'dVal', ' Val: ');
2409
                $loteTxt .= $this->pSimpleGetValue($rastro->item($i), 'vPMC', ' PMC: ');
2410
                $i++;
2411
            }
2412
            if ($loteTxt != '') {
2413
                $loteTxt.= ' ';
2414
            }
2415
        }
2416
        //NT2013.006 FCI
2417
        $nFCI = (! empty($itemProd->getElementsByTagName('nFCI')->item(0)->nodeValue)) ?
2418
                ' FCI:'.$itemProd->getElementsByTagName('nFCI')->item(0)->nodeValue : '';
2419
        $tmp_ad=$infAdProd . ($this->descProdInfoComplemento ? $loteTxt . $impostos . $nFCI : '');
2420
        $texto = $prod->getElementsByTagName("xProd")->item(0)->nodeValue . (strlen($tmp_ad)!=0?"\n    ".$tmp_ad:'');
2421
        if ($this->descProdQuebraLinha) {
2422
            $texto = str_replace(";", "\n", $texto);
2423
        }
2424
        return $texto;
2425
    }
2426
2427
    /**
2428
     * itensDANFE
2429
     * Monta o campo de itens da DANFE (retrato e paisagem)
2430
     *
2431
     * @name   itensDANFE
2432
     * @param  float $x       Posição horizontal canto esquerdo
2433
     * @param  float $y       Posição vertical canto superior
2434
     * @param  float $nInicio Número do item inicial
2435
     * @param  float $max     Número do item final
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...
2436
     * @param  float $hmax    Altura máxima do campo de itens em mm
2437
     * @return float Posição vertical final
2438
     */
2439
    protected function pItensDANFE($x, $y, &$nInicio, $hmax, $pag = 0, $totpag = 0, $hCabecItens = 7)
2440
    {
2441
        $oldX = $x;
2442
        $oldY = $y;
2443
        $totItens = $this->det->length;
2444
        //#####################################################################
2445
        //DADOS DOS PRODUTOS / SERVIÇOS
2446
        $texto = "DADOS DOS PRODUTOS / SERVIÇOS ";
2447
        if ($this->orientacao == 'P') {
2448
            $w = $this->wPrint;
2449
        } else {
2450
            if ($nInicio < 2) { // primeira página
2451
                $w = $this->wPrint - $this->wCanhoto;
2452
            } else { // páginas seguintes
2453
                $w = $this->wPrint;
2454
            }
2455
        }
2456
        $h = 4;
2457
        $aFont = array('font'=>$this->fontePadrao, 'size'=>7, 'style'=>'B');
2458
        $this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 0, '');
2459
        $y += 3;
2460
        //desenha a caixa dos dados dos itens da NF
2461
        $hmax += 1;
2462
        $texto = '';
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...
2463
        $this->pTextBox($x, $y, $w, $hmax);
2464
        //##################################################################################
2465
        // cabecalho LOOP COM OS DADOS DOS PRODUTOS
2466
        //CÓDIGO PRODUTO
2467
        $texto = "CÓDIGO PRODUTO";
2468
        $w1 = round($w*0.09, 0);
2469
        $h = 4;
2470
        $aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>'');
2471
        $this->pTextBox($x, $y, $w1, $h, $texto, $aFont, 'C', 'C', 0, '', false);
2472
        $this->pdf->Line($x+$w1, $y, $x+$w1, $y+$hmax);
2473
        //DESCRIÇÃO DO PRODUTO / SERVIÇO
2474
        $x += $w1;
2475
        $w2 = round($w*0.28, 0);
2476
        $texto = 'DESCRIÇÃO DO PRODUTO / SERVIÇO';
2477
        $aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>'');
2478
        $this->pTextBox($x, $y, $w2, $h, $texto, $aFont, 'C', 'C', 0, '', false);
2479
        $this->pdf->Line($x+$w2, $y, $x+$w2, $y+$hmax);
2480
        //NCM/SH
2481
        $x += $w2;
2482
        $w3 = round($w*0.06, 0);
2483
        $texto = 'NCM/SH';
2484
        $aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>'');
2485
        $this->pTextBox($x, $y, $w3, $h, $texto, $aFont, 'C', 'C', 0, '', false);
2486
        $this->pdf->Line($x+$w3, $y, $x+$w3, $y+$hmax);
2487
        //O/CST ou O/CSOSN
2488
        $x += $w3;
2489
        $w4 = round($w*0.05, 0);
2490
        $texto = 'O/CSOSN';//Regime do Simples CRT = 1 ou CRT = 2
2491
        if ($this->pSimpleGetValue($this->emit, 'CRT') == '3') {
2492
             $texto = 'O/CST';//Regime Normal
2493
        }
2494
        $aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>'');
2495
        $this->pTextBox($x, $y, $w4, $h, $texto, $aFont, 'C', 'C', 0, '', false);
2496
        $this->pdf->Line($x+$w4, $y, $x+$w4, $y+$hmax);
2497
        //CFOP
2498
        $x += $w4;
2499
        $w5 = round($w*0.04, 0);
2500
        $texto = 'CFOP';
2501
        $aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>'');
2502
        $this->pTextBox($x, $y, $w5, $h, $texto, $aFont, 'C', 'C', 0, '', false);
2503
        $this->pdf->Line($x+$w5, $y, $x+$w5, $y+$hmax);
2504
        //UN
2505
        $x += $w5;
2506
        $w6 = round($w*0.03, 0);
2507
        $texto = 'UN';
2508
        $aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>'');
2509
        $this->pTextBox($x, $y, $w6, $h, $texto, $aFont, 'C', 'C', 0, '', false);
2510
        $this->pdf->Line($x+$w6, $y, $x+$w6, $y+$hmax);
2511
        //QUANT
2512
        $x += $w6;
2513
        $w7 = round($w*0.07, 0);
2514
        $texto = 'QUANT';
2515
        $aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>'');
2516
        $this->pTextBox($x, $y, $w7, $h, $texto, $aFont, 'C', 'C', 0, '', false);
2517
        $this->pdf->Line($x+$w7, $y, $x+$w7, $y+$hmax);
2518
        //VALOR UNIT
2519
        $x += $w7;
2520
        $w8 = round($w*0.06, 0);
2521
        $texto = 'VALOR UNIT';
2522
        $aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>'');
2523
        $this->pTextBox($x, $y, $w8, $h, $texto, $aFont, 'C', 'C', 0, '', false);
2524
        $this->pdf->Line($x+$w8, $y, $x+$w8, $y+$hmax);
2525
        //VALOR TOTAL
2526
        $x += $w8;
2527
        $w9 = round($w*0.06, 0);
2528
        $texto = 'VALOR TOTAL';
2529
        $aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>'');
2530
        $this->pTextBox($x, $y, $w9, $h, $texto, $aFont, 'C', 'C', 0, '', false);
2531
        $this->pdf->Line($x+$w9, $y, $x+$w9, $y+$hmax);
2532
        //B.CÁLC ICMS
2533
        $x += $w9;
2534
        $w10 = round($w*0.06, 0);
2535
        $texto = 'B.CÁLC ICMS';
2536
        $aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>'');
2537
        $this->pTextBox($x, $y, $w10, $h, $texto, $aFont, 'C', 'C', 0, '', false);
2538
        $this->pdf->Line($x+$w10, $y, $x+$w10, $y+$hmax);
2539
        //VALOR ICMS
2540
        $x += $w10;
2541
        $w11 = round($w*0.06, 0);
2542
        $texto = 'VALOR ICMS';
2543
        $aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>'');
2544
        $this->pTextBox($x, $y, $w11, $h, $texto, $aFont, 'C', 'C', 0, '', false);
2545
        $this->pdf->Line($x+$w11, $y, $x+$w11, $y+$hmax);
2546
        //VALOR IPI
2547
        $x += $w11;
2548
        $w12 = round($w*0.05, 0);
2549
        $texto = 'VALOR IPI';
2550
        $aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>'');
2551
        $this->pTextBox($x, $y, $w12, $h, $texto, $aFont, 'C', 'C', 0, '', false);
2552
        $this->pdf->Line($x+$w12, $y, $x+$w12, $y+$hmax);
2553
        //ALÍQ. ICMS
2554
        $x += $w12;
2555
        $w13 = round($w*0.035, 0);
2556
        $texto = 'ALÍQ. ICMS';
2557
        $aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>'');
2558
        $this->pTextBox($x, $y, $w13, $h, $texto, $aFont, 'C', 'C', 0, '', false);
2559
        $this->pdf->Line($x+$w13, $y, $x+$w13, $y+$hmax);
2560
        //ALÍQ. IPI
2561
        $x += $w13;
2562
        $w14 = $w-($w1+$w2+$w3+$w4+$w5+$w6+$w7+$w8+$w9+$w10+$w11+$w12+$w13);
2563
        $texto = 'ALÍQ. IPI';
2564
        $this->pTextBox($x, $y, $w14, $h, $texto, $aFont, 'C', 'C', 0, '', false);
2565
        $this->pdf->Line($oldX, $y+$h+1, $oldX + $w, $y+$h+1);
2566
        $y += 5;
2567
        //##################################################################################
2568
        // LOOP COM OS DADOS DOS PRODUTOS
2569
        $i = 0;
2570
        $hUsado = $hCabecItens;
2571
        $aFont = array('font'=>$this->fontePadrao, 'size'=>7, 'style'=>'');
2572
        foreach ($this->det as $d) {
2573
            if ($i >= $nInicio) {
2574
                $thisItem = $this->det->item($i);
2575
                //carrega as tags do item
2576
                $prod = $thisItem->getElementsByTagName("prod")->item(0);
2577
                $imposto = $this->det->item($i)->getElementsByTagName("imposto")->item(0);
2578
                $ICMS = $imposto->getElementsByTagName("ICMS")->item(0);
2579
                $IPI  = $imposto->getElementsByTagName("IPI")->item(0);
2580
                $textoProduto = $this->pDescricaoProduto($thisItem);
2581
                $linhaDescr = $this->pGetNumLines($textoProduto, $w2, $aFont);
2582
                $h = round(($linhaDescr * $this->pdf->fontSize)+ ($linhaDescr * 0.5), 2);
2583
                $hUsado += $h;
2584
                if ($pag != $totpag) {
2585
                    if ($hUsado >= $hmax && $i < $totItens) {
2586
                        //ultrapassa a capacidade para uma única página
2587
                        //o restante dos dados serão usados nas proximas paginas
2588
                        $nInicio = $i;
2589
                        break;
2590
                    }
2591
                }
2592
                $y_linha=$y+$h;
2593
                // linha entre itens
2594
                $this->pdf->DashedHLine($oldX, $y_linha, $w, 0.1, 120);
2595
                //corrige o x
2596
                $x=$oldX;
2597
                //codigo do produto
2598
                $texto = $prod->getElementsByTagName("cProd")->item(0)->nodeValue;
2599
                $this->pTextBox($x, $y, $w1, $h, $texto, $aFont, 'T', 'C', 0, '');
2600
                $x += $w1;
2601
                //DESCRIÇÃO
2602
                if ($this->orientacao == 'P') {
2603
                    $this->pTextBox($x, $y, $w2, $h, $textoProduto, $aFont, 'T', 'L', 0, '', false);
2604
                } else {
2605
                    $this->pTextBox($x, $y, $w2, $h, $textoProduto, $aFont, 'T', 'L', 0, '', false);
2606
                }
2607
                $x += $w2;
2608
                //NCM
2609
                $texto = ! empty($prod->getElementsByTagName("NCM")->item(0)->nodeValue) ?
2610
                        $prod->getElementsByTagName("NCM")->item(0)->nodeValue : '';
2611
                $this->pTextBox($x, $y, $w3, $h, $texto, $aFont, 'T', 'C', 0, '');
2612
                $x += $w3;
2613
                //CST
2614
                if (isset($ICMS)) {
2615
                    $origem =  $this->pSimpleGetValue($ICMS, "orig");
2616
                    $cst =  $this->pSimpleGetValue($ICMS, "CST");
2617
                    $csosn =  $this->pSimpleGetValue($ICMS, "CSOSN");
2618
                    $texto = $origem.$cst.$csosn;
2619
                    $this->pTextBox($x, $y, $w4, $h, $texto, $aFont, 'T', 'C', 0, '');
2620
                }
2621
                //CFOP
2622
                $x += $w4;
2623
                $texto = $prod->getElementsByTagName("CFOP")->item(0)->nodeValue;
2624
                $this->pTextBox($x, $y, $w5, $h, $texto, $aFont, 'T', 'C', 0, '');
2625
                //Unidade
2626
                $x += $w5;
2627
                $texto = $prod->getElementsByTagName("uCom")->item(0)->nodeValue;
2628
                $this->pTextBox($x, $y, $w6, $h, $texto, $aFont, 'T', 'C', 0, '');
2629
                $x += $w6;
2630
                if ($this->orientacao == 'P') {
2631
                    $alinhamento = 'R';
2632
                } else {
2633
                    $alinhamento = 'R';
2634
                }
2635
                // QTDADE
2636
                $texto = number_format($prod->getElementsByTagName("qCom")->item(0)->nodeValue, 4, ",", ".");
2637
                $this->pTextBox($x, $y, $w7, $h, $texto, $aFont, 'T', $alinhamento, 0, '');
2638
                $x += $w7;
2639
                // Valor Unitário
2640
                $texto = number_format($prod->getElementsByTagName("vUnCom")->item(0)->nodeValue, 4, ",", ".");
2641
                $this->pTextBox($x, $y, $w8, $h, $texto, $aFont, 'T', $alinhamento, 0, '');
2642
                $x += $w8;
2643
                // Valor do Produto
2644
                $texto = "";
2645
                if (is_numeric($prod->getElementsByTagName("vProd")->item(0)->nodeValue)) {
2646
                    $texto = number_format($prod->getElementsByTagName("vProd")->item(0)->nodeValue, 2, ",", ".");
2647
                }
2648
                $this->pTextBox($x, $y, $w9, $h, $texto, $aFont, 'T', $alinhamento, 0, '');
2649
                //Valor da Base de calculo
2650
                $x += $w9;
2651
                if (isset($ICMS)) {
2652
                    $texto = ! empty($ICMS->getElementsByTagName("vBC")->item(0)->nodeValue) ?
2653
                            number_format(
2654
                                $ICMS->getElementsByTagName("vBC")->item(0)->nodeValue,
2655
                                2,
2656
                                ",",
2657
                                "."
2658
                            ) : '0, 00';
2659
                    $this->pTextBox($x, $y, $w10, $h, $texto, $aFont, 'T', $alinhamento, 0, '');
2660
                }
2661
                //Valor do ICMS
2662
                $x += $w10;
2663
                if (isset($ICMS)) {
2664
                    $texto = ! empty($ICMS->getElementsByTagName("vICMS")->item(0)->nodeValue) ?
2665
                            number_format(
2666
                                $ICMS->getElementsByTagName("vICMS")->item(0)->nodeValue,
2667
                                2,
2668
                                ",",
2669
                                "."
2670
                            ) : '0, 00';
2671
                    $this->pTextBox($x, $y, $w11, $h, $texto, $aFont, 'T', $alinhamento, 0, '');
2672
                }
2673
                //Valor do IPI
2674
                $x += $w11;
2675
                if (isset($IPI)) {
2676
                    $texto = ! empty($IPI->getElementsByTagName("vIPI")->item(0)->nodeValue) ?
2677
                            number_format($IPI->getElementsByTagName("vIPI")->item(0)->nodeValue, 2, ",", ".") :'';
2678
                } else {
2679
                    $texto = '';
2680
                }
2681
                $this->pTextBox($x, $y, $w12, $h, $texto, $aFont, 'T', $alinhamento, 0, '');
2682
                // %ICMS
2683
                $x += $w12;
2684
                if (isset($ICMS)) {
2685
                    $texto = ! empty($ICMS->getElementsByTagName("pICMS")->item(0)->nodeValue) ?
2686
                            number_format(
2687
                                $ICMS->getElementsByTagName("pICMS")->item(0)->nodeValue,
2688
                                2,
2689
                                ",",
2690
                                "."
2691
                            ) : '0, 00';
2692
                    $this->pTextBox($x, $y, $w13, $h, $texto, $aFont, 'T', 'C', 0, '');
2693
                }
2694
                //%IPI
2695
                $x += $w13;
2696
                if (isset($IPI)) {
2697
                    $texto = ! empty($IPI->getElementsByTagName("pIPI")->item(0)->nodeValue) ?
2698
                            number_format($IPI->getElementsByTagName("pIPI")->item(0)->nodeValue, 2, ",", ".") : '';
2699
                } else {
2700
                    $texto = '';
2701
                }
2702
                $this->pTextBox($x, $y, $w14, $h, $texto, $aFont, 'T', 'C', 0, '');
2703
2704
2705
                // Dados do Veiculo Somente para veiculo 0 Km
2706
                $veicProd = $prod->getElementsByTagName("veicProd")->item(0);
2707
                // Tag somente é gerada para veiculo 0k, e só é permitido um veiculo por NF-e por conta do detran
2708
                // Verifica se a Tag existe
2709
                if (!empty($veicProd)) {
2710
                    $this->pDadosItenVeiculoDANFE($oldX, $y, $h, $prod);
2711
                }
2712
2713
2714
                $y += $h;
2715
                $i++;
2716
                //incrementa o controle dos itens processados.
2717
                $this->qtdeItensProc++;
2718
            } else {
2719
                $i++;
2720
            }
2721
        }
2722
        return $oldY+$hmax;
2723
    }
2724
2725
2726
    /**
2727
     * pDadosItenVeiculoDANFE
2728
     * Coloca os dados do veiculo abaixo do item da NFe. (retrato e paisagem)
2729
     *
2730
     * @name  dadosAdicionaisDANFE
2731
     * @param float  $x    Posição horizontal
2732
     *                     canto esquerdo
2733
     * @param float  $y    Posição vertical
2734
     *                     canto superior
2735
     * @param float  $h    altura do campo
2736
     * @param object $prod Contendo todos os dados do item
2737
     */
2738
2739
    protected function pDadosItenVeiculoDANFE($x, $y, $h, $prod)
2740
    {
2741
        $oldX = $x;
2742
        $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...
2743
2744
        if ($this->orientacao == 'P') {
2745
            $w = $this->wPrint;
2746
        } else {
2747
            if ($nInicio < 2) { // primeira página
0 ignored issues
show
Bug introduced by
The variable $nInicio does not exist. Did you forget to declare it?

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

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

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

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

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

Loading history...
2839
        $veiculoTipoPintura = $veicProd->getElementsByTagName("tpPint")->item(0)->nodeValue;
2840
2841
        $veiculoMarcaModelo = $prod->getElementsByTagName("xProd")->item(0)->nodeValue;
2842
        $veiculoEspecie = $veicProd->getElementsByTagName("espVeic")->item(0)->nodeValue;
2843
        $veiculoCombustivel = $veicProd->getElementsByTagName("tpComb")->item(0)->nodeValue;
2844
        $veiculoSerial = $veicProd->getElementsByTagName("nSerie")->item(0)->nodeValue;
2845
        $veiculoFabricacao = $veicProd->getElementsByTagName("anoFab")->item(0)->nodeValue;
2846
        $veiculoModelo = $veicProd->getElementsByTagName("anoMod")->item(0)->nodeValue;
2847
2848
        $veiculoDistancia = $veicProd->getElementsByTagName("dist")->item(0)->nodeValue;
2849
2850
        $x = $oldX;
2851
2852
        $yVeic = $y + $h;
2853
        $texto = 'Chassi: ............: ' . $veiculoChassi;
2854
        $this->pTextBox($x, $yVeic, $w1+40, $h, $texto, $aFont, 'T', 'L', 0, '');
2855
        $yVeic += $h;
2856
        $texto = 'Cor...................: ' . $veiculoCor;
2857
        $this->pTextBox($x, $yVeic, $w1+40, $h, $texto, $aFont, 'T', 'L', 0, '');
2858
        $yVeic += $h;
2859
        $texto = 'Cilindrada........: ' . $veiculoCilindrada;
2860
        $this->pTextBox($x, $yVeic, $w1+40, $h, $texto, $aFont, 'T', 'L', 0, '');
2861
        $yVeic += $h;
2862
        $texto = 'Cmkg...............: ' . $veiculoCmkg;
2863
        $this->pTextBox($x, $yVeic, $w1+40, $h, $texto, $aFont, 'T', 'L', 0, '');
2864
        $yVeic += $h;
2865
        $texto = 'Tipo.................: ' . $renavamTiposVeiculos[intval($veiculoTipo)];
2866
        $this->pTextBox($x, $yVeic, $w1+40, $h, $texto, $aFont, 'T', 'L', 0, '');
2867
        $yVeic = $y + $h;
2868
        $xVeic = $x + 65;
2869
        $texto = 'Nº Motor: .........: ' . $veiculoMotor;
2870
        $this->pTextBox($xVeic, $yVeic, $w1+50, $h, $texto, $aFont, 'T', 'L', 0, '');
2871
        $yVeic += $h;
2872
        $texto = 'Renavam...........: ' . $veiculoRenavam;
2873
        $this->pTextBox($xVeic, $yVeic, $w1+50, $h, $texto, $aFont, 'T', 'L', 0, '');
2874
        $yVeic += $h;
2875
        $texto = 'HP.....................: ' . $veiculoHp;
2876
        $this->pTextBox($xVeic, $yVeic, $w1+50, $h, $texto, $aFont, 'T', 'L', 0, '');
2877
        $yVeic += $h;
2878
        $texto = 'Placa.................: ' . $veiculoPlaca;
2879
        $this->pTextBox($xVeic, $yVeic, $w1+50, $h, $texto, $aFont, 'T', 'L', 0, '');
2880
        $yVeic += $h;
2881
        $texto = 'Tipo Pintura......: ' . $renavamTipoPintura[$veiculoTipoPintura];
2882
        $this->pTextBox($xVeic, $yVeic, $w1+50, $h, $texto, $aFont, 'T', 'L', 0, '');
2883
        $yVeic = $y + $h;
2884
        $xVeic = $xVeic + 55;
2885
        $texto = 'Marca / Modelo.....: ' . $veiculoMarcaModelo;
2886
        $this->pTextBox($xVeic, $yVeic, $w1+50, $h, $texto, $aFont, 'T', 'L', 0, '');
2887
        $yVeic += $h;
2888
        $texto = 'Especie..................: ' . $renavamEspecie[intval($veiculoEspecie)];
2889
        $this->pTextBox($xVeic, $yVeic, $w1+50, $h, $texto, $aFont, 'T', 'L', 0, '');
2890
        $yVeic += $h;
2891
        $texto = 'Combustivel..........: ' . $renavamCombustivel[intval($veiculoCombustivel)];
2892
        $this->pTextBox($xVeic, $yVeic, $w1+50, $h, $texto, $aFont, 'T', 'L', 0, '');
2893
        $yVeic += $h;
2894
        $texto = 'Serial.....................: ' . $veiculoSerial;
2895
        $this->pTextBox($xVeic, $yVeic, $w1+50, $h, $texto, $aFont, 'T', 'L', 0, '');
2896
        $yVeic += $h;
2897
        $texto = 'Ano Fab/Mod........: '. $veiculoFabricacao . '/' . $veiculoModelo;
2898
        $this->pTextBox($xVeic, $yVeic, $w1+50, $h, $texto, $aFont, 'T', 'L', 0, '');
2899
        $yVeic += $h;
2900
        $texto = 'Distancia Entre Eixos(mm)..: '. $veiculoDistancia;
2901
        $this->pTextBox($xVeic, $yVeic, $w1+50, $h, $texto, $aFont, 'T', 'L', 0, '');
2902
    }
2903
2904
    /**
2905
     * issqnDANFE
2906
     * Monta o campo de serviços do DANFE
2907
     *
2908
     * @name   issqnDANFE (retrato e paisagem)
2909
     * @param  float $x Posição horizontal canto esquerdo
2910
     * @param  float $y Posição vertical canto superior
2911
     * @return float Posição vertical final
2912
     */
2913
    protected function pIssqnDANFE($x, $y)
2914
    {
2915
        $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...
2916
        //#####################################################################
2917
        //CÁLCULO DO ISSQN
2918
        $texto = "CÁLCULO DO ISSQN";
2919
        $w = $this->wPrint;
2920
        $h = 7;
2921
        $aFont = array('font'=>$this->fontePadrao, 'size'=>7, 'style'=>'B');
2922
        $this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 0, '');
2923
        //INSCRIÇÃO MUNICIPAL
2924
        $y += 3;
2925
        $w = round($this->wPrint*0.23, 0);
2926
        $texto = 'INSCRIÇÃO MUNICIPAL';
2927
        $aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>'');
2928
        $this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 1, '');
2929
        //inscrição municipal
2930
        $texto = ! empty($this->emit->getElementsByTagName("IM")->item(0)->nodeValue) ?
2931
                $this->emit->getElementsByTagName("IM")->item(0)->nodeValue : '';
2932
        $aFont = array('font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B');
2933
        $this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'B', 'L', 0, '');
2934
        //VALOR TOTAL DOS SERVIÇOS
2935
        $x += $w;
2936
        $texto = 'VALOR TOTAL DOS SERVIÇOS';
2937
        $aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>'');
2938
        $this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 1, '');
2939
        if (isset($this->ISSQNtot)) {
2940
            $texto = ! empty($this->ISSQNtot->getElementsByTagName("vServ")->item(0)->nodeValue) ?
2941
                    $this->ISSQNtot->getElementsByTagName("vServ")->item(0)->nodeValue : '';
2942
            $texto = number_format($texto, 2, ",", ".");
2943
        } else {
2944
            $texto = '';
2945
        }
2946
        $aFont = array('font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B');
2947
        $this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'B', 'R', 0, '');
2948
        //BASE DE CÁLCULO DO ISSQN
2949
        $x += $w;
2950
        $texto = 'BASE DE CÁLCULO DO ISSQN';
2951
        $aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>'');
2952
        $this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 1, '');
2953
        if (isset($this->ISSQNtot)) {
2954
            $texto = ! empty($this->ISSQNtot->getElementsByTagName("vBC")->item(0)->nodeValue) ?
2955
                    $this->ISSQNtot->getElementsByTagName("vBC")->item(0)->nodeValue : '';
2956
            $texto = ! empty($texto) ? number_format($texto, 2, ",", ".") : '';
2957
        } else {
2958
            $texto = '';
2959
        }
2960
        $aFont = array('font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B');
2961
        $this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'B', 'R', 0, '');
2962
        //VALOR TOTAL DO ISSQN
2963
        $x += $w;
2964
        if ($this->orientacao == 'P') {
2965
            $w = $this->wPrint - (3 * $w);
2966
        } else {
2967
            $w = $this->wPrint - (3 * $w)-$this->wCanhoto;
2968
        }
2969
        $texto = 'VALOR TOTAL DO ISSQN';
2970
        $aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>'');
2971
        $this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 1, '');
2972
        if (isset($this->ISSQNtot)) {
2973
            $texto = ! empty($this->ISSQNtot->getElementsByTagName("vISS")->item(0)->nodeValue) ?
2974
                    $this->ISSQNtot->getElementsByTagName("vISS")->item(0)->nodeValue : '';
2975
            $texto = ! empty($texto) ? number_format($texto, 2, ",", ".") : '';
2976
        } else {
2977
            $texto = '';
2978
        }
2979
        $aFont = array('font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B');
2980
        $this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'B', 'R', 0, '');
2981
        return ($y+$h+1);
2982
    }
2983
2984
    /**
2985
     *dadosAdicionaisDANFE
2986
     * Coloca o grupo de dados adicionais da NFe. (retrato e paisagem)
2987
     *
2988
     * @name   dadosAdicionaisDANFE
2989
     * @param  float $x Posição horizontal canto esquerdo
2990
     * @param  float $y Posição vertical canto superior
2991
     * @param  float $h altura do campo
2992
     * @return float Posição vertical final (eixo Y)
2993
     */
2994
    protected function pDadosAdicionaisDANFE($x, $y, $h)
2995
    {
2996
        //##################################################################################
2997
        //DADOS ADICIONAIS
2998
        $texto = "DADOS ADICIONAIS";
2999
        if ($this->orientacao == 'P') {
3000
              $w = $this->wPrint;
3001
        } else {
3002
              $w = $this->wPrint-$this->wCanhoto;
3003
        }
3004
        $aFont = array('font'=>$this->fontePadrao, 'size'=>7, 'style'=>'B');
3005
        $this->pTextBox($x, $y, $w, 8, $texto, $aFont, 'T', 'L', 0, '');
3006
        //INFORMAÇÕES COMPLEMENTARES
3007
        $texto = "INFORMAÇÕES COMPLEMENTARES";
3008
        $y += 3;
3009
        $w = $this->wAdic;
3010
        $aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>'B');
3011
        $this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 1, '');
3012
        //o texto com os dados adicionais foi obtido na função montaDANFE
3013
        //e carregado em uma propriedade privada da classe
3014
        //$this->wAdic com a largura do campo
3015
        //$this->textoAdic com o texto completo do campo
3016
        $y += 1;
3017
        $aFont = array('font'=>$this->fontePadrao, 'size'=>7, 'style'=>'');
3018
        $this->pTextBox($x, $y+2, $w-2, $h-3, $this->textoAdic, $aFont, 'T', 'L', 0, '', false);
3019
        //RESERVADO AO FISCO
3020
        $texto = "RESERVADO AO FISCO";
3021
        $x += $w;
3022
        $y -= 1;
3023
        if ($this->orientacao == 'P') {
3024
            $w = $this->wPrint-$w;
3025
        } else {
3026
            $w = $this->wPrint-$w-$this->wCanhoto;
3027
        }
3028
        $aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>'B');
3029
        $this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 1, '');
3030
        //inserir texto informando caso de contingência
3031
        // 1 - Normal - emissão normal;
3032
        // 2 - Contingência FS - emissão em contingência com impressão do DANFE em Formulário de Segurança;
3033
        // 3 - Contingência SCAN - emissão em contingência no Sistema de Contingência do Ambiente Nacional;
3034
        // 4 - Contingência DPEC - emissão em contingência com envio da Declaração
3035
        //     Prévia de Emissão em Contingência;
3036
        // 5 - Contingência FS-DA - emissão em contingência com impressão do DANFE em Formulário de
3037
        //     Segurança para Impressão de Documento Auxiliar de Documento Fiscal Eletrônico (FS-DA);
3038
        // 6 - Contingência SVC-AN
3039
        // 7 - Contingência SVC-RS
3040
        $xJust = $this->pSimpleGetValue($this->ide, 'xJust', 'Justificativa: ');
3041
        $dhCont = $this->pSimpleGetValue($this->ide, 'dhCont', ' Entrada em contingência : ');
3042
        $texto = '';
3043
        switch ($this->tpEmis) {
3044
            case 2:
3045
                $texto = 'CONTINGÊNCIA FS' . $dhCont . $xJust;
3046
                break;
3047
            case 3:
3048
                $texto = 'CONTINGÊNCIA SCAN' . $dhCont . $xJust;
3049
                break;
3050
            case 4:
3051
                $texto = 'CONTINGÊNCIA DPEC' . $dhCont . $xJust;
3052
                break;
3053
            case 5:
3054
                $texto = 'CONTINGÊNCIA FSDA' . $dhCont . $xJust;
3055
                break;
3056
            case 6:
3057
                $texto = 'CONTINGÊNCIA SVC-AN' . $dhCont . $xJust;
3058
                break;
3059
            case 7:
3060
                $texto = 'CONTINGÊNCIA SVC-RS' . $dhCont . $xJust;
3061
                break;
3062
        }
3063
        $y += 2;
3064
        $aFont = array('font'=>$this->fontePadrao, 'size'=>7, 'style'=>'');
3065
        $this->pTextBox($x, $y, $w-2, $h-3, $texto, $aFont, 'T', 'L', 0, '', false);
3066
        return $y+$h;
3067
    }
3068
3069
    /**
3070
     * pRodape
3071
     * Monta o rodapé no final da DANFE com a data/hora de impressão e informações
3072
     * sobre a API NfePHP
3073
     *
3074
     * @name   pRodape
3075
     * @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...
3076
     * @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...
3077
     * @return void
3078
     */
3079
    protected function pRodape($x, $y)
3080
    {
3081
        if ($this->orientacao == 'P') {
3082
              $w = $this->wPrint;
3083
        } else {
3084
              $w = $this->wPrint-$this->wCanhoto;
3085
              $x = $this->wCanhoto;
3086
        }
3087
        $aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>'I');
3088
        $texto = "Impresso em ". date('d/m/Y') . " as " . date('H:i:s');
3089
        $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...
3090
        $texto = $this->creditos .  "  Powered by NFePHP";
3091
        $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...
3092
    }
3093
3094
    /**
3095
     * pCcanhotoDANFE
3096
     * Monta o canhoto da DANFE (retrato e paisagem)
3097
     *
3098
     * @name   canhotoDANFE
3099
     * @param  number $x Posição horizontal canto esquerdo
3100
     * @param  number $y Posição vertical canto superior
3101
     * @return number Posição vertical final
3102
     *
3103
     * TODO 21/07/14 fmertins: quando orientação L-paisagem, o canhoto está sendo gerado incorretamente
3104
     */
3105
    protected function pCanhoto($x, $y)
3106
    {
3107
        $oldX = $x;
3108
        $oldY = $y;
3109
        //#################################################################################
3110
        //canhoto
3111
        //identificação do tipo de nf entrada ou saida
3112
        $tpNF = $this->ide->getElementsByTagName('tpNF')->item(0)->nodeValue;
3113
        if ($tpNF == '0') {
3114
            //NFe de Entrada
3115
            $emitente = '';
3116
            $emitente .= $this->dest->getElementsByTagName("xNome")->item(0)->nodeValue . " - ";
3117
            $emitente .= $this->enderDest->getElementsByTagName("xLgr")->item(0)->nodeValue . ", ";
3118
            $emitente .= $this->enderDest->getElementsByTagName("nro")->item(0)->nodeValue . " - ";
3119
            $emitente .= $this->pSimpleGetValue($this->enderDest, "xCpl", " - ", " ");
3120
            $emitente .= $this->enderDest->getElementsByTagName("xBairro")->item(0)->nodeValue . " ";
3121
            $emitente .= $this->enderDest->getElementsByTagName("xMun")->item(0)->nodeValue . "-";
3122
            $emitente .= $this->enderDest->getElementsByTagName("UF")->item(0)->nodeValue . "";
3123
            $destinatario = $this->emit->getElementsByTagName("xNome")->item(0)->nodeValue . " ";
3124
        } else {
3125
            //NFe de Saída
3126
            $emitente = $this->emit->getElementsByTagName("xNome")->item(0)->nodeValue . " ";
3127
            $destinatario = '';
3128
            $destinatario .= $this->dest->getElementsByTagName("xNome")->item(0)->nodeValue . " - ";
3129
            $destinatario .= $this->enderDest->getElementsByTagName("xLgr")->item(0)->nodeValue . ", ";
3130
            $destinatario .= $this->enderDest->getElementsByTagName("nro")->item(0)->nodeValue . " ";
3131
            $destinatario .= $this->pSimpleGetValue($this->enderDest, "xCpl", " - ", " ");
3132
            $destinatario .= $this->enderDest->getElementsByTagName("xBairro")->item(0)->nodeValue . " ";
3133
            $destinatario .= $this->enderDest->getElementsByTagName("xMun")->item(0)->nodeValue . "-";
3134
            $destinatario .= $this->enderDest->getElementsByTagName("UF")->item(0)->nodeValue . " ";
3135
        }
3136
        //identificação do sistema emissor
3137
        //linha separadora do canhoto
3138
        if ($this->orientacao == 'P') {
3139
            $w = round($this->wPrint * 0.81, 0);
3140
        } else {
3141
            //linha separadora do canhoto - 238
3142
            //posicao altura
3143
            $y = $this->wPrint-85;
3144
            //altura
3145
            $w = $this->wPrint-85-24;
3146
        }
3147
        $h = 10;
3148
        //desenha caixa
3149
        $texto = '';
3150
        $aFont = array('font'=>$this->fontePadrao, 'size'=>7, 'style'=>'');
3151
        $aFontSmall = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>'');
3152
        if ($this->orientacao == 'P') {
3153
            $this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'C', 'L', 1, '', false);
3154
        } else {
3155
            $this->pTextBox90($x, $y, $w, $h, $texto, $aFont, 'C', 'L', 1, '', false);
3156
        }
3157
        $numNF = str_pad($this->ide->getElementsByTagName('nNF')->item(0)->nodeValue, 9, "0", STR_PAD_LEFT);
3158
        $serie = str_pad($this->ide->getElementsByTagName('serie')->item(0)->nodeValue, 3, "0", STR_PAD_LEFT);
3159
        $texto = "RECEBEMOS DE ";
3160
        $texto .= $emitente;
3161
        $texto .= " OS PRODUTOS E/OU SERVIÇOS CONSTANTES DA NOTA FISCAL ELETRÔNICA INDICADA ";
3162
        if ($this->orientacao == 'P') {
3163
            $texto .= "ABAIXO";
3164
        } else {
3165
            $texto .= "AO LADO";
3166
        }
3167
        $texto .= ". EMISSÃO: ";
3168
        $dEmi = ! empty($this->ide->getElementsByTagName("dEmi")->item(0)->nodeValue) ?
3169
                $this->ide->getElementsByTagName("dEmi")->item(0)->nodeValue : '';
3170
        if ($dEmi == '') {
3171
            $dEmi = ! empty($this->ide->getElementsByTagName("dhEmi")->item(0)->nodeValue) ?
3172
                    $this->ide->getElementsByTagName("dhEmi")->item(0)->nodeValue : '';
3173
            $aDemi = explode('T', $dEmi);
3174
            $dEmi = $aDemi[0];
3175
        }
3176
        $texto .= $this->pYmd2dmy($dEmi) ." ";
3177
        $texto .= "VALOR TOTAL: R$ ";
3178
        $texto .= number_format($this->ICMSTot->getElementsByTagName("vNF")->item(0)->nodeValue, 2, ",", ".") . " ";
3179
        $texto .= "DESTINATÁRIO: ";
3180
        $texto .= $destinatario;
3181
        if ($this->orientacao == 'P') {
3182
            $this->pTextBox($x, $y, $w-1, $h, $texto, $aFont, 'C', 'L', 0, '', false);
3183
            $x1 = $x + $w;
3184
            $w1 = $this->wPrint - $w;
3185
            $texto = "NF-e";
3186
            $aFont = array('font'=>$this->fontePadrao, 'size'=>14, 'style'=>'B');
3187
            $this->pTextBox($x1, $y, $w1, 18, $texto, $aFont, 'T', 'C', 0, '');
3188
            $texto = "Nº. " . $this->pFormat($numNF, "###.###.###") . " \n";
3189
            $texto .= "Série $serie";
3190
            $aFont = array('font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B');
3191
            $this->pTextBox($x1, $y, $w1, 18, $texto, $aFont, 'C', 'C', 1, '');
3192
            //DATA DE RECEBIMENTO
3193
            $texto = "DATA DE RECEBIMENTO";
3194
            $y += $h;
3195
            $w2 = round($this->wPrint*0.17, 0); //35;
3196
            $aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>'');
3197
            $this->pTextBox($x, $y, $w2, 8, $texto, $aFont, 'T', 'L', 1, '');
3198
            //IDENTIFICAÇÃO E ASSINATURA DO RECEBEDOR
3199
            $x += $w2;
3200
            $w3 = $w-$w2;
3201
            $texto = "IDENTIFICAÇÃO E ASSINATURA DO RECEBEDOR";
3202
            $this->pTextBox($x, $y, $w3, 8, $texto, $aFont, 'T', 'L', 1, '');
3203
            $x = $oldX;
3204
            $y += 9;
3205
            $this->pdf->DashedHLine($x, $y, $this->wPrint, 0.1, 80);
3206
            $y += 2;
3207
            return $y;
3208
        } else {
3209
            $x--;
3210
            $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...
3211
            //NUMERO DA NOTA FISCAL LOGO NFE
3212
            $w1 = 16;
3213
            $x1 = $oldX;
3214
            $y = $oldY;
3215
            $texto = "NF-e";
3216
            $aFont = array('font'=>$this->fontePadrao, 'size'=>14, 'style'=>'B');
3217
            $this->pTextBox($x1, $y, $w1, 18, $texto, $aFont, 'T', 'C', 0, '');
3218
            $texto = "Nº.\n" . $this->pFormat($numNF, "###.###.###") . " \n";
3219
            $texto .= "Série $serie";
3220
            $aFont = array('font'=>$this->fontePadrao, 'size'=>8, 'style'=>'B');
3221
            $this->pTextBox($x1, $y, $w1, 18, $texto, $aFont, 'C', 'C', 1, '');
3222
            //DATA DO RECEBIMENTO
3223
            $texto = "DATA DO RECEBIMENTO";
3224
            $y = $this->wPrint-85;
3225
            $x = 12;
3226
            $w2 = round($this->wPrint*0.17, 0); //35;
3227
            $aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>'');
3228
            $this->pTextBox90($x, $y, $w2, 8, $texto, $aFont, 'T', 'L', 1, '');
3229
            //IDENTIFICAÇÃO E ASSINATURA DO RECEBEDOR
3230
            $y -= $w2;
3231
            $w3 = $w-$w2;
3232
            $texto = "IDENTIFICAÇÃO E ASSINATURA DO RECEBEDOR";
3233
            $aFont = array('font'=>$this->fontePadrao, 'size'=>5.7, 'style'=>'');
3234
            $x = $this->pTextBox90($x, $y, $w3, 8, $texto, $aFont, 'T', 'L', 1, '');
3235
            $this->pdf->DashedVLine(23, $oldY, 0.1, $this->wPrint-20, 67);
3236
            return $x;
3237
        }
3238
    }
3239
3240
    /**
3241
     * pGeraInformacoesDaTagCompra
3242
     * Devolve uma string contendo informação sobre as tag <compra><xNEmp>, <xPed> e <xCont> ou string vazia.
3243
     * Aviso: Esta função não leva em consideração dados na tag xPed do item.
3244
     *
3245
     * @name   pGeraInformacoesDaTagCompra
3246
     * @return string com as informacoes dos pedidos.
3247
     */
3248
    protected function pGeraInformacoesDaTagCompra()
3249
    {
3250
        $saida = "";
3251
        if (isset($this->compra)) {
3252
            if (! empty($this->compra->getElementsByTagName("xNEmp")->item(0)->nodeValue)) {
3253
                $saida .= " Nota de Empenho: " . $this->compra->getElementsByTagName("xNEmp")->item(0)->nodeValue;
3254
            }
3255
            if (! empty($this->compra->getElementsByTagName("xPed")->item(0)->nodeValue)) {
3256
                $saida .= " Pedido: " . $this->compra->getElementsByTagName("xPed")->item(0)->nodeValue;
3257
            }
3258
            if (! empty($this->compra->getElementsByTagName("xCont")->item(0)->nodeValue)) {
3259
                $saida .= " Contrato: " . $this->compra->getElementsByTagName("xCont")->item(0)->nodeValue;
3260
            }
3261
        }
3262
        return $saida;
3263
    }
3264
3265
    /**
3266
     * pGeraChaveAdicionalDeContingencia
3267
     *
3268
     * @name   pGeraChaveAdicionalDeContingencia
3269
     * @return string chave
3270
     */
3271
    protected function pGeraChaveAdicionalDeContingencia()
3272
    {
3273
        //cUF tpEmis CNPJ vNF ICMSp ICMSs DD  DV
3274
        // 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...
3275
        $forma  = "%02d%d%s%014d%01d%01d%02d";
3276
        $cUF    = $this->ide->getElementsByTagName('cUF')->item(0)->nodeValue;
3277
        $CNPJ   = "00000000000000" . $this->emit->getElementsByTagName('CNPJ')->item(0)->nodeValue;
3278
        $CNPJ   = substr($CNPJ, -14);
3279
        $vNF    = $this->ICMSTot->getElementsByTagName("vNF")->item(0)->nodeValue * 100;
3280
        $vICMS  = $this->ICMSTot->getElementsByTagName("vICMS")->item(0)->nodeValue;
3281
        if ($vICMS > 0) {
3282
            $vICMS = 1;
3283
        }
3284
        $icmss  = $this->ICMSTot->getElementsByTagName("vBC")->item(0)->nodeValue;
3285
        if ($icmss > 0) {
3286
            $icmss = 1;
3287
        }
3288
        $dEmi = ! empty($this->ide->getElementsByTagName("dEmi")->item(0)->nodeValue) ?
3289
                $this->ide->getElementsByTagName("dEmi")->item(0)->nodeValue : '';
3290
        if ($dEmi == '') {
3291
            $dEmi = ! empty($this->ide->getElementsByTagName("dhEmi")->item(0)->nodeValue) ?
3292
                    $this->ide->getElementsByTagName("dhEmi")->item(0)->nodeValue : '';
3293
            $aDemi = explode('T', $dEmi);
3294
            $dEmi = $aDemi[0];
3295
        }
3296
        $dd  = $dEmi;
3297
        $rpos = strrpos($dd, '-');
3298
        $dd  = substr($dd, $rpos +1);
3299
        $chave = sprintf($forma, $cUF, $this->tpEmis, $CNPJ, $vNF, $vICMS, $icmss, $dd);
3300
        $chave = $chave . $this->pModulo11($chave);
3301
        return $chave;
3302
    }
3303
3304
    /**
3305
     * pGeraInformacoesDasNotasReferenciadas
3306
     * Devolve uma string contendo informação sobre as notas referenciadas. Suporta N notas, eletrônicas ou não
3307
     * Exemplo: NFe Ref.: série: 01 número: 01 emit: 11.111.111/0001-01
3308
     * em 10/2010 [0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000]
3309
     *
3310
     * @return string Informacoes a serem adicionadas no rodapé sobre notas referenciadas.
3311
     */
3312
    protected function pGeraInformacoesDasNotasReferenciadas()
3313
    {
3314
        $formaNfeRef = "\r\nNFe Ref.: série:%d número:%d emit:%s em %s [%s]";
3315
        $formaCTeRef = "\r\nCTe Ref.: série:%d número:%d emit:%s em %s [%s]";
3316
        $formaNfRef = "\r\nNF  Ref.: série:%d numero:%d emit:%s em %s modelo: %d";
3317
        $formaECFRef = "\r\nECF Ref.: modelo: %s ECF:%d COO:%d";
3318
        $formaNfpRef = "\r\nNFP Ref.: série:%d número:%d emit:%s em %s modelo: %d IE:%s";
3319
        $saida='';
3320
        $nfRefs = $this->ide->getElementsByTagName('NFref');
3321
        if (0 === $nfRefs->length) {
3322
            return $saida;
3323
        }
3324
        foreach ($nfRefs as $nfRef) {
3325
            if (empty($nfRef)) {
3326
                continue;
3327
            }
3328
            $refNFe = $nfRef->getElementsByTagName('refNFe');
3329
            foreach ($refNFe as $chave_acessoRef) {
3330
                $chave_acesso = $chave_acessoRef->nodeValue;
3331
                $chave_acessoF = $this->pFormat($chave_acesso, $this->formatoChave);
3332
                $data = substr($chave_acesso, 4, 2)."/20".substr($chave_acesso, 2, 2);
3333
                $cnpj = $this->pFormat(substr($chave_acesso, 6, 14), "##.###.###/####-##");
3334
                $serie  = substr($chave_acesso, 22, 3);
3335
                $numero = substr($chave_acesso, 25, 9);
3336
                $saida .= sprintf($formaNfeRef, $serie, $numero, $cnpj, $data, $chave_acessoF);
3337
            }
3338
            $refNF = $nfRef->getElementsByTagName('refNF');
3339
            foreach ($refNF as $umaRefNFe) {
3340
                $data = $umaRefNFe->getElementsByTagName('AAMM')->item(0)->nodeValue;
3341
                $cnpj = $umaRefNFe->getElementsByTagName('CNPJ')->item(0)->nodeValue;
3342
                $mod = $umaRefNFe->getElementsByTagName('mod')->item(0)->nodeValue;
3343
                $serie = $umaRefNFe->getElementsByTagName('serie')->item(0)->nodeValue;
3344
                $numero = $umaRefNFe->getElementsByTagName('nNF')->item(0)->nodeValue;
3345
                $data = substr($data, 2, 2) . "/20" . substr($data, 0, 2);
3346
                $cnpj = $this->pFormat($cnpj, "##.###.###/####-##");
3347
                $saida .= sprintf($formaNfRef, $serie, $numero, $cnpj, $data, $mod);
3348
            }
3349
            $refCTe = $nfRef->getElementsByTagName('refCTe');
3350
            foreach ($refCTe as $chave_acessoRef) {
3351
                $chave_acesso = $chave_acessoRef->nodeValue;
3352
                $chave_acessoF = $this->pFormat($chave_acesso, $this->formatoChave);
3353
                $data = substr($chave_acesso, 4, 2)."/20".substr($chave_acesso, 2, 2);
3354
                $cnpj = $this->pFormat(substr($chave_acesso, 6, 14), "##.###.###/####-##");
3355
                $serie  = substr($chave_acesso, 22, 3);
3356
                $numero = substr($chave_acesso, 25, 9);
3357
                $saida .= sprintf($formaCTeRef, $serie, $numero, $cnpj, $data, $chave_acessoF);
3358
            }
3359
            $refECF = $nfRef->getElementsByTagName('refECF');
3360
            foreach ($refECF as $umaRefNFe) {
3361
                $mod    = $umaRefNFe->getElementsByTagName('mod')->item(0)->nodeValue;
3362
                $nECF   = $umaRefNFe->getElementsByTagName('nECF')->item(0)->nodeValue;
3363
                $nCOO   = $umaRefNFe->getElementsByTagName('nCOO')->item(0)->nodeValue;
3364
                $saida .= sprintf($formaECFRef, $mod, $nECF, $nCOO);
3365
            }
3366
            $refNFP = $nfRef->getElementsByTagName('refNFP');
3367
            foreach ($refNFP as $umaRefNFe) {
3368
                $data = $umaRefNFe->getElementsByTagName('AAMM')->item(0)->nodeValue;
3369
                $cnpj = ! empty($umaRefNFe->getElementsByTagName('CNPJ')->item(0)->nodeValue) ?
3370
                    $umaRefNFe->getElementsByTagName('CNPJ')->item(0)->nodeValue :
3371
                    '';
3372
                $cpf = ! empty($umaRefNFe->getElementsByTagName('CPF')->item(0)->nodeValue) ?
3373
                        $umaRefNFe->getElementsByTagName('CPF')->item(0)->nodeValue : '';
3374
                $mod = $umaRefNFe->getElementsByTagName('mod')->item(0)->nodeValue;
3375
                $serie = $umaRefNFe->getElementsByTagName('serie')->item(0)->nodeValue;
3376
                $numero = $umaRefNFe->getElementsByTagName('nNF')->item(0)->nodeValue;
3377
                $ie = $umaRefNFe->getElementsByTagName('IE')->item(0)->nodeValue;
3378
                $data = substr($data, 2, 2) . "/20" . substr($data, 0, 2);
3379
                if ($cnpj == '') {
3380
                    $cpf_cnpj = $this->pFormat($cpf, "###.###.###-##");
3381
                } else {
3382
                    $cpf_cnpj = $this->pFormat($cnpj, "##.###.###/####-##");
3383
                }
3384
                $saida .= sprintf($formaNfpRef, $serie, $numero, $cpf_cnpj, $data, $mod, $ie);
3385
            }
3386
        }
3387
        return $saida;
3388
    }
3389
    
3390
    private function imagePNGtoJPG($original)
3391
    {
3392
        $image = imagecreatefrompng($original);
3393
        ob_start();
3394
        imagejpeg($image, null, 100);
3395
        imagedestroy($image);
3396
        $stringdata = ob_get_contents(); // read from buffer
3397
        ob_end_clean();
3398
        return 'data://text/plain;base64,'.base64_encode($stringdata);
3399
    }
3400
}
3401